Improve SegmentRoutingAppConfig

- Separate host and subnet suppression
- Use port instead of interface to specify which SR should ignore

Change-Id: Ie6491950cddf0860924565f081504b4f4d788179
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
index 932b8ad..1beed32 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
@@ -18,7 +18,6 @@
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.SetMultimap;
-import com.google.common.collect.Sets;
 import org.onlab.packet.Ip4Address;
 import org.onlab.packet.Ip4Prefix;
 import org.onlab.packet.IpPrefix;
@@ -30,6 +29,7 @@
 import org.onosproject.incubator.net.intf.Interface;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
 import org.onosproject.net.host.InterfaceIpAddress;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
@@ -57,7 +57,8 @@
     private final List<Integer> allSegmentIds = new ArrayList<>();
     private final Map<DeviceId, SegmentRouterInfo> deviceConfigMap = new ConcurrentHashMap<>();
     private final Map<VlanId, List<ConnectPoint>> xConnects = new ConcurrentHashMap<>();
-    private final Set<ConnectPoint> excludedPorts = Sets.newConcurrentHashSet();
+    private ApplicationId appId;
+    private NetworkConfigService cfgService;
     private SegmentRoutingAppConfig appConfig;
 
     private class SegmentRouterInfo {
@@ -85,6 +86,9 @@
      */
     public DeviceConfiguration(ApplicationId appId,
             NetworkConfigRegistry cfgService) {
+        this.appId = appId;
+        this.cfgService = cfgService;
+
         // Read config from device subject, excluding gatewayIps and subnets.
         Set<DeviceId> deviceSubjects =
                 cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class);
@@ -103,15 +107,18 @@
             allSegmentIds.add(info.nodeSid);
         });
 
-        // Read excluded port names from config
+        // Read SegmentRoutingAppConfig
         appConfig = cfgService.getConfig(appId, SegmentRoutingAppConfig.class);
-        Set<String> excludePorts = (appConfig != null) ?
-                appConfig.excludePorts() : ImmutableSet.of();
 
         // Read gatewayIps and subnets from port subject.
         Set<ConnectPoint> portSubjects =
             cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
         portSubjects.forEach(subject -> {
+            // Do not process excluded ports
+            if (suppressSubnet().contains(subject)) {
+                return;
+            }
+
             InterfaceConfig config =
                     cfgService.getConfig(subject, InterfaceConfig.class);
             Set<Interface> networkInterfaces;
@@ -122,12 +129,6 @@
                 return;
             }
             networkInterfaces.forEach(networkInterface -> {
-                // Do not process excluded ports
-                if (excludePorts.contains(networkInterface.name())) {
-                    excludedPorts.add(subject);
-                    return;
-                }
-
                 VlanId vlanId = networkInterface.vlan();
                 ConnectPoint connectPoint = networkInterface.connectPoint();
                 DeviceId dpid = connectPoint.deviceId();
@@ -366,7 +367,7 @@
 
             ImmutableSet.Builder<Ip4Prefix> builder = ImmutableSet.builder();
             builder.addAll(srinfo.subnets.values());
-            if (deviceId.equals(appConfig.vRouterId())) {
+            if (appConfig != null && deviceId.equals(appConfig.vRouterId())) {
                 builder.add(Ip4Prefix.valueOf("0.0.0.0/0"));
             }
             return builder.build();
@@ -491,12 +492,11 @@
         return srinfo != null && srinfo.adjacencySids.containsKey(sid);
     }
 
-    /**
-     * Returns a set of excluded ports.
-     *
-     * @return excluded ports
-     */
-    public Set<ConnectPoint> excludedPorts() {
-        return excludedPorts;
+    public Set<ConnectPoint> suppressSubnet() {
+        return (appConfig != null) ? appConfig.suppressSubnet() : ImmutableSet.of();
+    }
+
+    public Set<ConnectPoint> suppressHost() {
+        return (appConfig != null) ? appConfig.suppressHost() : ImmutableSet.of();
     }
 }