Remove next hop location from resolved route
The next hop location should be obtained from host service
Change-Id: I8652e6b8b1367097ffbfcb1651538c34819f67d6
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
index c82b39b..214ba6b 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
@@ -22,9 +22,9 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
+import org.onosproject.net.ConnectPoint;
import org.onosproject.routeservice.ResolvedRoute;
import org.onosproject.routeservice.RouteEvent;
-import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,22 +38,24 @@
private static final Logger log = LoggerFactory.getLogger(RouteHandler.class);
private final SegmentRoutingManager srManager;
- public RouteHandler(SegmentRoutingManager srManager) {
+ RouteHandler(SegmentRoutingManager srManager) {
this.srManager = srManager;
}
protected void init(DeviceId deviceId) {
- srManager.routeService.getRouteTables().forEach(routeTableId -> {
- srManager.routeService.getRoutes(routeTableId).forEach(routeInfo -> {
- routeInfo.allRoutes().stream()
- .filter(resolvedRoute -> resolvedRoute.location() != null &&
- resolvedRoute.location().deviceId().equals(deviceId))
- .forEach(this::processRouteAddedInternal);
- });
- });
+ srManager.routeService.getRouteTables().forEach(routeTableId ->
+ srManager.routeService.getRoutes(routeTableId).forEach(routeInfo ->
+ routeInfo.allRoutes().forEach(resolvedRoute ->
+ srManager.nextHopLocations(resolvedRoute).stream()
+ .filter(location -> deviceId.equals(location.deviceId()))
+ .forEach(location -> processRouteAddedInternal(resolvedRoute)
+ )
+ )
+ )
+ );
}
- protected void processRouteAdded(RouteEvent event) {
+ void processRouteAdded(RouteEvent event) {
log.info("processRouteAdded {}", event);
processRouteAddedInternal(event.subject());
}
@@ -67,7 +69,12 @@
IpPrefix prefix = route.prefix();
MacAddress nextHopMac = route.nextHopMac();
VlanId nextHopVlan = route.nextHopVlan();
- ConnectPoint location = route.location();
+ ConnectPoint location = srManager.nextHopLocations(route).stream().findFirst().orElse(null);
+
+ if (location == null) {
+ log.info("{} ignored. Cannot find nexthop location", prefix);
+ return;
+ }
srManager.deviceConfiguration.addSubnet(location, prefix);
// XXX need to handle the case where there are two connectpoints
@@ -77,13 +84,13 @@
nextHopMac, nextHopVlan, location.port());
}
- protected void processRouteUpdated(RouteEvent event) {
+ void processRouteUpdated(RouteEvent event) {
log.info("processRouteUpdated {}", event);
processRouteRemovedInternal(event.prevSubject());
processRouteAddedInternal(event.subject());
}
- protected void processRouteRemoved(RouteEvent event) {
+ void processRouteRemoved(RouteEvent event) {
log.info("processRouteRemoved {}", event);
processRouteRemovedInternal(event.subject());
}
@@ -97,7 +104,12 @@
IpPrefix prefix = route.prefix();
MacAddress nextHopMac = route.nextHopMac();
VlanId nextHopVlan = route.nextHopVlan();
- ConnectPoint location = route.location();
+ ConnectPoint location = srManager.nextHopLocations(route).stream().findFirst().orElse(null);
+
+ if (location == null) {
+ log.info("{} ignored. Cannot find nexthop location", prefix);
+ return;
+ }
srManager.deviceConfiguration.removeSubnet(location, prefix);
srManager.defaultRoutingHandler.revokeSubnet(ImmutableSet.of(prefix));