Bugfix and improvement of SR config loading

Change-Id: If17af7ff1fbd3cb712e59cce930ef11146bdbf2e
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigEventHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigEventHandler.java
index afb7ec9..f32cd2d9 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigEventHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/NetworkConfigEventHandler.java
@@ -137,12 +137,7 @@
         if (config == null) {
             return ImmutableSet.of();
         }
-
-        HashSet<MacAddress> macAddresses = new HashSet<>();
-        config.vRouterMacs().forEach(mac -> {
-            macAddresses.add(mac);
-        });
-        return ImmutableSet.copyOf(macAddresses);
+        return ImmutableSet.copyOf(config.vRouterMacs());
     }
 
     private boolean isEdge(DeviceId deviceId) {
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 1beed32..5d48b6d 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
@@ -59,7 +59,6 @@
     private final Map<VlanId, List<ConnectPoint>> xConnects = new ConcurrentHashMap<>();
     private ApplicationId appId;
     private NetworkConfigService cfgService;
-    private SegmentRoutingAppConfig appConfig;
 
     private class SegmentRouterInfo {
         int nodeSid;
@@ -107,9 +106,6 @@
             allSegmentIds.add(info.nodeSid);
         });
 
-        // Read SegmentRoutingAppConfig
-        appConfig = cfgService.getConfig(appId, SegmentRoutingAppConfig.class);
-
         // Read gatewayIps and subnets from port subject.
         Set<ConnectPoint> portSubjects =
             cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
@@ -367,8 +363,12 @@
 
             ImmutableSet.Builder<Ip4Prefix> builder = ImmutableSet.builder();
             builder.addAll(srinfo.subnets.values());
-            if (appConfig != null && deviceId.equals(appConfig.vRouterId())) {
-                builder.add(Ip4Prefix.valueOf("0.0.0.0/0"));
+            SegmentRoutingAppConfig appConfig =
+                    cfgService.getConfig(appId, SegmentRoutingAppConfig.class);
+            if (appConfig != null) {
+                if (deviceId.equals(appConfig.vRouterId().orElse(null))) {
+                    builder.add(Ip4Prefix.valueOf("0.0.0.0/0"));
+                }
             }
             return builder.build();
         }
@@ -493,10 +493,14 @@
     }
 
     public Set<ConnectPoint> suppressSubnet() {
+        SegmentRoutingAppConfig appConfig =
+                cfgService.getConfig(appId, SegmentRoutingAppConfig.class);
         return (appConfig != null) ? appConfig.suppressSubnet() : ImmutableSet.of();
     }
 
     public Set<ConnectPoint> suppressHost() {
+        SegmentRoutingAppConfig appConfig =
+                cfgService.getConfig(appId, SegmentRoutingAppConfig.class);
         return (appConfig != null) ? appConfig.suppressHost() : ImmutableSet.of();
     }
 }