Small updates to SR to get it to ignore devices not configured as routers
Change-Id: I2c0f695af1a6eab10607a8117faae5f6161a66d9
diff --git a/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java b/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
index 5014811..9844106 100644
--- a/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
@@ -191,29 +191,29 @@
updatedEcmpSpgMap = new HashMap<>();
Set<EdgePair> edgePairs = new HashSet<>();
Set<ArrayList<DeviceId>> routeChanges = new HashSet<>();
- for (Device dstSw : srManager.deviceService.getDevices()) {
+ for (DeviceId dstSw : srManager.deviceConfiguration.getRouters()) {
EcmpShortestPathGraph ecmpSpgUpdated =
- new EcmpShortestPathGraph(dstSw.id(), srManager);
- updatedEcmpSpgMap.put(dstSw.id(), ecmpSpgUpdated);
- DeviceId pairDev = getPairDev(dstSw.id());
+ new EcmpShortestPathGraph(dstSw, srManager);
+ updatedEcmpSpgMap.put(dstSw, ecmpSpgUpdated);
+ DeviceId pairDev = getPairDev(dstSw);
if (pairDev != null) {
// pairDev may not be available yet, but we still need to add
ecmpSpgUpdated = new EcmpShortestPathGraph(pairDev, srManager);
updatedEcmpSpgMap.put(pairDev, ecmpSpgUpdated);
- edgePairs.add(new EdgePair(dstSw.id(), pairDev));
+ edgePairs.add(new EdgePair(dstSw, pairDev));
}
- DeviceId ret = shouldHandleRouting(dstSw.id());
+ DeviceId ret = shouldHandleRouting(dstSw);
if (ret == null) {
continue;
}
- Set<DeviceId> devsToProcess = Sets.newHashSet(dstSw.id(), ret);
+ Set<DeviceId> devsToProcess = Sets.newHashSet(dstSw, ret);
// To do a full reroute, assume all routes have changed
for (DeviceId dev : devsToProcess) {
- for (Device targetSw : srManager.deviceService.getDevices()) {
- if (targetSw.id().equals(dev)) {
+ for (DeviceId targetSw : srManager.deviceConfiguration.getRouters()) {
+ if (targetSw.equals(dev)) {
continue;
}
- routeChanges.add(Lists.newArrayList(targetSw.id(), dev));
+ routeChanges.add(Lists.newArrayList(targetSw, dev));
}
}
}
diff --git a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 1d1cc4e..a9c2f04 100644
--- a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -15,23 +15,11 @@
*/
package org.onosproject.segmentrouting;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.stream.Collectors;
-
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -121,10 +109,21 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkState;
import static org.onlab.packet.Ethernet.TYPE_ARP;
@@ -581,9 +580,8 @@
@Override
public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
- deviceService.getAvailableDevices().forEach(device -> {
- deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id()));
- });
+ deviceConfiguration.getRouters().forEach(device ->
+ deviceSubnetMap.put(device, deviceConfiguration.getSubnets(device)));
return deviceSubnetMap;
}
diff --git a/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java b/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
index 321cf40..b7d32a1 100644
--- a/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
+++ b/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
@@ -27,18 +27,19 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
-import org.onosproject.net.config.ConfigException;
-import org.onosproject.net.config.basics.InterfaceConfig;
-import org.onosproject.net.intf.Interface;
import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.ConfigException;
+import org.onosproject.net.config.basics.InterfaceConfig;
+import org.onosproject.net.host.InterfaceIpAddress;
+import org.onosproject.net.intf.Interface;
import org.onosproject.segmentrouting.SegmentRoutingManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -126,7 +127,9 @@
// Read gatewayIps and subnets from port subject. Ignore suppressed ports.
Set<ConnectPoint> portSubjects = srManager.cfgService
.getSubjects(ConnectPoint.class, InterfaceConfig.class);
- portSubjects.stream().filter(subject -> !isSuppressedPort(subject)).forEach(subject -> {
+ portSubjects.stream()
+ .filter(subject -> deviceConfigMap.containsKey(subject.deviceId()))
+ .filter(subject -> !isSuppressedPort(subject)).forEach(subject -> {
InterfaceConfig config =
srManager.cfgService.getConfig(subject, InterfaceConfig.class);
Set<Interface> networkInterfaces;
@@ -181,6 +184,9 @@
});
}
+ public Collection<DeviceId> getRouters() {
+ return deviceConfigMap.keySet();
+ }
@Override
public boolean isConfigured(DeviceId deviceId) {