use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method handleLeaseQuery6ReplyMsg.
public void handleLeaseQuery6ReplyMsg(PacketContext context, DHCP6 dhcp6Payload) {
ConnectPoint inPort = context.inPacket().receivedFrom();
log.info("Got LQV6-REPLY on port {}", inPort);
List<Dhcp6Option> lopt = dhcp6Payload.getOptions();
log.info("Options list: {}", lopt);
// find out if this lease is known is
Dhcp6ClientDataOption clientDataOption = dhcp6Payload.getOptions().stream().filter(opt -> opt instanceof Dhcp6ClientDataOption).map(pld -> (Dhcp6ClientDataOption) pld).findFirst().orElse(null);
if (clientDataOption == null) {
log.warn("clientDataOption option is not present, " + "lease is UNKNOWN - not adding any new route...");
} else {
Dhcp6IaAddressOption aiAddressOption = clientDataOption.getOptions().stream().filter(opt -> opt instanceof Dhcp6IaAddressOption).map(pld -> (Dhcp6IaAddressOption) pld).findFirst().orElse(null);
Dhcp6ClientIdOption clientIdOption = clientDataOption.getOptions().stream().filter(opt -> opt instanceof Dhcp6ClientIdOption).map(pld -> (Dhcp6ClientIdOption) pld).findFirst().orElse(null);
if (aiAddressOption == null) {
log.warn("clientDataOption from DHCP server does not " + "contains Dhcp6IaAddressOption for the client - giving up...");
} else {
Ip6Address clientAddress = aiAddressOption.getIp6Address();
MacAddress clientMacAddress = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
Ethernet packet = context.inPacket().parsed();
VlanId vlanId = VlanId.vlanId(packet.getVlanID());
MacAddress potentialNextHopMac = findNextHopMacForIp6FromRelayStore(clientAddress, clientMacAddress, vlanId);
if (potentialNextHopMac == null) {
log.warn("Can't find next hop host mac for client {} mac:{}/{}", clientAddress, clientMacAddress, vlanId);
return;
} else {
log.info("Next hop mac for {}/{}/{} is {}", clientAddress, clientMacAddress, vlanId, potentialNextHopMac.toString());
}
// search the next hop in the hosts store
HostId gwHostId = HostId.hostId(potentialNextHopMac, vlanId);
Host gwHost = hostService.getHost(gwHostId);
if (gwHost == null) {
log.warn("Can't find next hop host ID {}", gwHostId);
return;
}
Ip6Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp6).filter(IpAddress::isLinkLocal).map(IpAddress::getIp6Address).findFirst().orElse(null);
if (nextHopIp == null) {
log.warn("Can't find IP6 address of next hop {}", gwHost);
return;
}
log.info("client " + clientAddress + " is known !");
Route routeForIP6 = new Route(Route.Source.DHCP, clientAddress.toIpPrefix(), nextHopIp);
log.debug("updating route of Client for indirectly connected.");
log.debug("client ip: " + clientAddress + ", next hop ip6: " + nextHopIp);
routeStore.updateRoute(routeForIP6);
}
}
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method handleLeaseQueryActivateMsg.
private void handleLeaseQueryActivateMsg(Ethernet packet, DHCP dhcpPayload) {
log.debug("LQ: Got DHCPLEASEACTIVE packet!");
if (learnRouteFromLeasequery) {
// TODO: release the ip address from client
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 processing DHCPLEASEACTIVE", hostId);
return;
}
// need to update routes
log.debug("Lease Query for Client results in DHCPLEASEACTIVE - route needs to be modified");
// get current route
// find the ip of that client with the DhcpRelay store
Ip4Address clientIP = record.ip4Address().orElse(null);
log.debug("LQ: IP of host is " + clientIP.getIp4Address());
MacAddress nextHopMac = record.nextHop().orElse(null);
log.debug("LQ: MAC of resulting *OLD* NH for that host is " + nextHopMac.toString());
// find the new NH by looking at the src MAC of the dhcp request
// from the LQ store
MacAddress newNextHopMac = record.nextHopTemp().orElse(null);
log.debug("LQ: MAC of resulting *NEW* NH for that host is " + newNextHopMac.toString());
log.debug("LQ: updating dhcp relay record with new NH");
record.nextHop(newNextHopMac);
// find the next hop IP from its mac
HostId gwHostId = HostId.hostId(newNextHopMac, 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: *NEW* NH IP for host is " + nextHopIp.getIp4Address());
Route route = new Route(Route.Source.DHCP, clientIP.toIpPrefix(), nextHopIp);
routeStore.updateRoute(route);
}
// and forward to client
InternalPacket ethernetPacket = processLeaseQueryFromServer(packet);
if (ethernetPacket != null) {
sendResponseToClient(ethernetPacket, dhcpPayload);
}
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class SdnIpReactiveRouting method packetReactiveProcessor.
/**
* Routes packet reactively.
*
* @param dstIpAddress the destination IP address of a packet
* @param srcIpAddress the source IP address of a packet
* @param srcConnectPoint the connect point where a packet comes from
* @param srcMacAddress the source MAC address of a packet
*/
private void packetReactiveProcessor(IpAddress dstIpAddress, IpAddress srcIpAddress, ConnectPoint srcConnectPoint, MacAddress srcMacAddress) {
checkNotNull(dstIpAddress);
checkNotNull(srcIpAddress);
checkNotNull(srcConnectPoint);
checkNotNull(srcMacAddress);
//
// Step1: Try to update the existing intent first if it exists.
//
IpPrefix ipPrefix = null;
Route route = null;
if (config.isIpAddressLocal(dstIpAddress)) {
if (dstIpAddress.isIp4()) {
ipPrefix = IpPrefix.valueOf(dstIpAddress, Ip4Address.BIT_LENGTH);
} else {
ipPrefix = IpPrefix.valueOf(dstIpAddress, Ip6Address.BIT_LENGTH);
}
} else {
// Get IP prefix from BGP route table
route = routeService.longestPrefixMatch(dstIpAddress);
if (route != null) {
ipPrefix = route.prefix();
}
}
if (ipPrefix != null && intentRequestListener.mp2pIntentExists(ipPrefix)) {
intentRequestListener.updateExistingMp2pIntent(ipPrefix, srcConnectPoint);
return;
}
//
// Step2: There is no existing intent for the destination IP address.
// Check whether it is necessary to create a new one. If necessary then
// create a new one.
//
TrafficType trafficType = trafficTypeClassifier(srcConnectPoint, dstIpAddress);
switch(trafficType) {
case HOST_TO_INTERNET:
// The Step 1 has already handled it. We do not need to do anything here.
if (route != null) {
intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress, ipPrefix, route.nextHop());
}
break;
case INTERNET_TO_HOST:
intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress);
break;
case HOST_TO_HOST:
intentRequestListener.setUpConnectivityHostToHost(dstIpAddress, srcIpAddress, srcMacAddress, srcConnectPoint);
break;
case INTERNET_TO_INTERNET:
log.trace("This is transit traffic, " + "the intent should be preinstalled already");
break;
case DROP:
// We need a new type of intent here.
break;
case UNKNOWN:
log.trace("This is unknown traffic, so we do nothing");
break;
default:
break;
}
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class DistributedRouteStore method computeRouteTablesFromRoutes.
private Map<RouteTableId, Set<Route>> computeRouteTablesFromRoutes(Collection<Route> routes) {
Map<RouteTableId, Set<Route>> computedTables = new HashMap<>();
routes.forEach(route -> {
RouteTableId routeTableId = (route.prefix().address().isIp4()) ? IPV4 : IPV6;
Set<Route> tempRoutes = computedTables.computeIfAbsent(routeTableId, k -> Sets.newHashSet());
tempRoutes.add(route);
});
return computedTables;
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RouteManagerTest method testRouteAdd.
/**
* Tests adding routes to the route manager.
*/
@Test
public void testRouteAdd() {
Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
ResolvedRoute resolvedRoute = new ResolvedRoute(route, MAC1);
verifyRouteAdd(route, resolvedRoute);
route = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
resolvedRoute = new ResolvedRoute(route, MAC3);
verifyRouteAdd(route, resolvedRoute);
}
Aggregations