use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class PimInterfaceManager method getSourceInterface.
private PimInterface getSourceInterface(McastRoute route) {
Route unicastRoute = unicastRouteService.longestPrefixMatch(route.source());
if (unicastRoute == null) {
log.warn("No route to source {}", route.source());
return null;
}
Interface intf = interfaceService.getMatchingInterface(unicastRoute.nextHop());
if (intf == null) {
log.warn("No interface with route to next hop {}", unicastRoute.nextHop());
return null;
}
PimInterface pimInterface = pimInterfaces.get(intf.connectPoint());
if (pimInterface == null) {
log.warn("PIM is not enabled on interface {}", intf);
return null;
}
Set<Host> hosts = hostService.getHostsByIp(unicastRoute.nextHop());
Host host = null;
for (Host h : hosts) {
if (h.vlan().equals(intf.vlan())) {
host = h;
}
}
if (host == null) {
log.warn("Next hop host entry not found: {}", unicastRoute.nextHop());
return null;
}
pimInterface.addRoute(route, unicastRoute.nextHop(), host.mac());
return pimInterface;
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method removeHostOrRoute.
/**
* remove host or route and update dhcp relay record attributes.
*
* @param directConnFlag flag to show that packet is from directly connected client
* @param location client side connect point
* @param dhcp6Packet the dhcp6 payload
* @param clientPacket client's ethernet packet
* @param clientIpv6 client's Ipv6 packet
* @param clientInterface client interfaces
*/
private void removeHostOrRoute(boolean directConnFlag, ConnectPoint location, DHCP6 dhcp6Packet, Ethernet clientPacket, IPv6 clientIpv6, Interface clientInterface) {
log.debug("removeHostOrRoute enters {}", dhcp6Packet);
VlanId vlanId = clientInterface.vlan();
// could be gw or host
MacAddress srcMac = clientPacket.getSourceMAC();
MacAddress leafClientMac;
byte leafMsgType;
log.debug("client mac {} client vlan {}", HexString.toHexString(srcMac.toBytes(), ":"), vlanId);
Dhcp6ClientIdOption clientIdOption = Dhcp6HandlerUtil.extractClientId(directConnFlag, dhcp6Packet);
if (clientIdOption != null) {
if ((clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LLT) || (clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LL)) {
leafClientMac = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
} else {
log.warn("Link-Layer Address not supported in CLIENTID option. No DhcpRelay Record created.");
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_FAIL);
return;
}
} else {
log.warn("CLIENTID option NOT found. Don't create DhcpRelay Record.");
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENTID_FAIL);
return;
}
HostId leafHostId = HostId.hostId(leafClientMac, vlanId);
DhcpRecord record = dhcpRelayStore.getDhcpRecord(leafHostId).orElse(null);
if (record == null) {
record = new DhcpRecord(leafHostId);
} else {
record = record.clone();
}
Boolean isMsgRelease = Dhcp6HandlerUtil.isDhcp6Release(dhcp6Packet);
IpAddressInfo ipInfo;
PdPrefixInfo pdInfo = null;
if (directConnFlag) {
// Add to host store if it is connected to network directly
ipInfo = extractIpAddress(dhcp6Packet);
if (ipInfo != null) {
if (isMsgRelease) {
HostId hostId = HostId.hostId(srcMac, vlanId);
log.debug("remove Host {} ip for directly connected.", hostId.toString());
providerService.removeIpFromHost(hostId, ipInfo.ip6Address);
}
} else {
log.debug("ipAddress not found. Do not remove Host {} for directly connected.", HostId.hostId(srcMac, vlanId).toString());
}
leafMsgType = dhcp6Packet.getMsgType();
} else {
// Remove from route store if it is not connected to network directly
// pick out the first link-local ip address
IpAddress nextHopIp = getFirstIpByHost(directConnFlag, srcMac, vlanId);
if (nextHopIp == null) {
log.warn("Can't find link-local IP address of gateway mac {} vlanId {}", srcMac, vlanId);
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_GW);
return;
}
DHCP6 leafDhcp = Dhcp6HandlerUtil.getDhcp6Leaf(dhcp6Packet);
ipInfo = extractIpAddress(leafDhcp);
if (ipInfo == null) {
log.debug("ip is null");
} else {
if (isMsgRelease) {
Route routeForIP = new Route(Route.Source.DHCP, ipInfo.ip6Address.toIpPrefix(), nextHopIp);
log.debug("removing route of 128 address for indirectly connected.");
log.debug("128 ip {}, nexthop {}", HexString.toHexString(ipInfo.ip6Address.toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
routeStore.removeRoute(routeForIP);
}
}
pdInfo = extractPrefix(leafDhcp);
if (pdInfo == null) {
log.debug("ipPrefix is null ");
} else {
if (isMsgRelease) {
Route routeForPrefix = new Route(Route.Source.DHCP, pdInfo.pdPrefix, nextHopIp);
log.debug("removing route of PD for indirectly connected.");
log.debug("pd ip {}, nexthop {}", HexString.toHexString(pdInfo.pdPrefix.address().toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
routeStore.removeRoute(routeForPrefix);
if (this.dhcpFpmEnabled) {
dhcpFpmPrefixStore.removeFpmRecord(pdInfo.pdPrefix);
}
}
}
leafMsgType = leafDhcp.getMsgType();
}
if (isMsgRelease) {
log.debug("DHCP6 RELEASE msg.");
if (record != null) {
if (ipInfo != null) {
log.debug("DhcpRelay Record ip6Address is set to null.");
record.ip6Address(null);
}
if (pdInfo != null) {
log.debug("DhcpRelay Record pdPrefix is set to null.");
}
if (!record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
log.warn("IP6 address and IP6 PD both are null. Remove record.");
// do not remove a record. Let timer task handler it.
// dhcpRelayStore.removeDhcpRecord(HostId.hostId(leafClientMac, vlanId));
}
}
}
if (record != null) {
record.getV6Counters().incrementCounter(Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
record.addLocation(new HostLocation(location, System.currentTimeMillis()));
record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
record.setDirectlyConnected(directConnFlag);
if (!directConnFlag) {
// Update gateway mac address if the host is not directly connected
record.nextHop(srcMac);
}
record.updateLastSeen();
}
dhcpRelayStore.updateDhcpRecord(leafHostId, record);
/*
// TODO Use AtomicInteger for the counters
try {
recordSemaphore.acquire();
try {
dhcpRelayCountersStore.incrementCounter(gCount, Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
} finally {
// calling release() after a successful acquire()
recordSemaphore.release();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
*/
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method timeTick.
/**
* Find lease-expired ipaddresses and pd prefixes.
* Removing host/route/fpm entries.
*/
public void timeTick() {
long currentTime = System.currentTimeMillis();
Collection<DhcpRecord> records = dhcpRelayStore.getDhcpRecords();
log.debug("timeTick called currenttime {} records num {} ", currentTime, records.size());
records.forEach(record -> {
boolean addrOrPdRemoved = false;
DHCP6.MsgType ip6Status = record.ip6Status().orElse(null);
if (ip6Status == null) {
log.debug("record is not valid v6 record.");
return;
}
if ((currentTime - record.getLastIp6Update()) > ((record.addrPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
// remove ipaddress from host/route table
IpAddress ip = record.ip6Address().orElse(null);
if (ip != null) {
if (record.directlyConnected()) {
providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), ip);
} else {
MacAddress gwMac = record.nextHop().orElse(null);
if (gwMac == null) {
log.warn("Can't find gateway mac address from record {} for ip6Addr", record);
return;
}
IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
routeStore.removeRoute(route);
}
record.updateAddrPrefTime(0);
record.ip6Address(null);
addrOrPdRemoved = true;
dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
log.warn("IP6 address is set to null. delta {} lastUpdate {} addrPrefTime {}", (currentTime - record.getLastIp6Update()), record.getLastIp6Update(), record.addrPrefTime());
}
}
if ((currentTime - record.getLastPdUpdate()) > ((record.pdPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
// remove PD from route/fpm table
IpPrefix pdIpPrefix = record.pdPrefix().orElse(null);
if (pdIpPrefix != null) {
if (record.directlyConnected()) {
providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), pdIpPrefix.address().getIp6Address());
} else {
MacAddress gwMac = record.nextHop().orElse(null);
if (gwMac == null) {
log.warn("Can't find gateway mac address from record {} for PD prefix", record);
return;
}
IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
Route route = new Route(Route.Source.DHCP, pdIpPrefix, nextHopIp);
routeStore.removeRoute(route);
if (this.dhcpFpmEnabled) {
dhcpFpmPrefixStore.removeFpmRecord(pdIpPrefix);
}
}
record.updatePdPrefTime(0);
record.pdPrefix(null);
addrOrPdRemoved = true;
dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
log.warn("PD prefix is set to null.delta {} pdPrefTime {}", (currentTime - record.getLastPdUpdate()), record.pdPrefTime());
}
}
if (addrOrPdRemoved && !record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
log.warn("ip6Status {} IP6 address and IP6 PD both are null. Remove record.", ip6Status);
dhcpRelayStore.removeDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()));
}
});
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method handleDhcpAck.
/**
* Send the DHCP ack to the requester host.
* Modify Host or Route store according to the type of DHCP.
*
* @param ethernetPacketAck the packet
* @param dhcpPayload the DHCP data
*/
private void handleDhcpAck(Ethernet ethernetPacketAck, DHCP dhcpPayload) {
Optional<Interface> outInterface = getClientInterface(ethernetPacketAck, dhcpPayload);
if (!outInterface.isPresent()) {
log.warn("Can't find output interface for dhcp: {}", dhcpPayload);
return;
}
Interface outIface = outInterface.get();
ConnectPoint location = outIface.connectPoint();
if (!location.port().hasName()) {
location = translateSwitchPort(location);
}
HostLocation hostLocation = new HostLocation(location, System.currentTimeMillis());
MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
VlanId vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
if (vlanId == null) {
vlanId = outIface.vlan();
}
HostId hostId = HostId.hostId(macAddress, vlanId);
Ip4Address ip = Ip4Address.valueOf(dhcpPayload.getYourIPAddress());
if (directlyConnected(dhcpPayload)) {
// Add to host store if it connect to network directly
Set<IpAddress> ips = Sets.newHashSet(ip);
Host host = hostService.getHost(hostId);
Set<HostLocation> hostLocations = Sets.newHashSet(hostLocation);
if (host != null) {
// Dual homing support:
// if host exists, use old locations and new location
hostLocations.addAll(host.locations());
}
HostDescription desc = new DefaultHostDescription(macAddress, vlanId, hostLocations, ips, false);
// Add IP address when dhcp server give the host new ip address
providerService.hostDetected(hostId, desc, false);
} else {
// Add to route store if it does not connect to network directly
// Get gateway host IP according to host mac address
// TODO: remove relay store here
DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
if (record == null) {
log.warn("Can't find DHCP record of host {}", hostId);
return;
}
MacAddress gwMac = record.nextHop().orElse(null);
if (gwMac == null) {
log.warn("Can't find gateway mac address from record {}", record);
return;
}
HostId gwHostId = HostId.hostId(gwMac, record.vlanId());
Host gwHost = hostService.getHost(gwHostId);
if (gwHost == null) {
log.warn("Can't find gateway host {}", gwHostId);
return;
}
Ip4Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp4).map(IpAddress::getIp4Address).findFirst().orElse(null);
if (nextHopIp == null) {
log.warn("Can't find IP address of gateway {}", gwHost);
return;
}
Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
routeStore.replaceRoute(route);
}
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method handleLeaseQueryUnknown.
private void handleLeaseQueryUnknown(Ethernet packet, DHCP dhcpPayload) {
log.debug("Lease Query for Client results in DHCPLEASEUNASSIGNED or " + "DHCPLEASEUNKNOWN - removing route & forwarding reply to originator");
if (learnRouteFromLeasequery) {
MacAddress clientMacAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
VlanId vlanId = VlanId.vlanId(packet.getVlanID());
HostId hostId = HostId.hostId(clientMacAddress, vlanId);
DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
if (record == null) {
log.warn("Can't find record for host {} when handling LQ UNKNOWN/UNASSIGNED message", hostId);
return;
}
Ip4Address clientIP = record.ip4Address().orElse(null);
log.debug("LQ: IP of host is " + clientIP.getIp4Address());
// find the new NH by looking at the src MAC of the dhcp request
// from the LQ store
MacAddress nextHopMac = record.nextHop().orElse(null);
log.debug("LQ: MAC of resulting *Existing* NH for that route is " + nextHopMac.toString());
// find the next hop IP from its mac
HostId gwHostId = HostId.hostId(nextHopMac, vlanId);
Host gwHost = hostService.getHost(gwHostId);
if (gwHost == null) {
log.warn("Can't find gateway for new NH host " + gwHostId);
return;
}
Ip4Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp4).map(IpAddress::getIp4Address).findFirst().orElse(null);
if (nextHopIp == null) {
log.warn("Can't find IP address of gateway {}", gwHost);
return;
}
log.debug("LQ: *Existing* NH IP for host is " + nextHopIp.getIp4Address() + " removing route for it");
Route route = new Route(Route.Source.DHCP, clientIP.toIpPrefix(), nextHopIp);
routeStore.removeRoute(route);
// remove from temp store
dhcpRelayStore.removeDhcpRecord(hostId);
}
// and forward to client
InternalPacket ethernetPacket = processLeaseQueryFromServer(packet);
if (ethernetPacket != null) {
sendResponseToClient(ethernetPacket, dhcpPayload);
}
}
Aggregations