Small fixes to SR

Change-Id: I4dfdbea082048bd48ea9be0a3bfea381ca395962
diff --git a/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
index ecaa77d..c924929 100644
--- a/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
@@ -28,16 +28,12 @@
 import org.onlab.packet.MacAddress;
 import org.onlab.packet.VlanId;
 import org.onlab.packet.ndp.NeighborSolicitation;
-import org.onosproject.incubator.net.config.basics.ConfigException;
-import org.onosproject.incubator.net.config.basics.InterfaceConfig;
-import org.onosproject.incubator.net.intf.Interface;
 import org.onosproject.incubator.net.neighbour.NeighbourMessageContext;
 import org.onosproject.incubator.net.neighbour.NeighbourMessageType;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Host;
 import org.onosproject.net.HostId;
-import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.host.HostService;
@@ -45,7 +41,6 @@
 import org.onosproject.net.packet.InboundPacket;
 import org.onosproject.net.packet.OutboundPacket;
 import org.onosproject.net.packet.PacketContext;
-import org.onosproject.routing.config.RouterConfig;
 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
 import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
 import org.slf4j.Logger;
@@ -468,59 +463,21 @@
     //    be implemented. For now, it's fine to leave this         //
     /////////////////////////////////////////////////////////////////
 
-    // XXX Neighbour hacking. To store upstream connect
-    // point and vRouter connect point
-    private ConnectPoint upstreamCP = null;
-    private ConnectPoint vRouterCP = null;
-
     // XXX Neighbour hacking, this method is used to handle
     // the ICMPv6 protocols for the upstream port
     public boolean handleUPstreamPackets(PacketContext packetContext) {
         InboundPacket pkt = packetContext.inPacket();
         Ethernet ethernet = pkt.parsed();
-        if (vRouterCP == null || upstreamCP == null) {
+        if (srManager.vRouterCP == null || srManager.upstreamCP == null) {
             return false;
         }
-        if (pkt.receivedFrom().equals(upstreamCP)) {
-            sendTo(ByteBuffer.wrap(ethernet.serialize()), vRouterCP);
+        if (pkt.receivedFrom().equals(srManager.upstreamCP)) {
+            sendTo(ByteBuffer.wrap(ethernet.serialize()), srManager.vRouterCP);
             return true;
         }
         return false;
     }
 
-    // XXX Neighbour hacking. To update the Upstream CP
-    public void updateUPstreamCP(NetworkConfigEvent event) {
-        Set<ConnectPoint> portSubjects = srManager.cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
-        upstreamCP = null;
-        portSubjects.stream().forEach(subject -> {
-            InterfaceConfig config = srManager.cfgService.getConfig(subject, InterfaceConfig.class);
-            Set<Interface> networkInterfaces;
-            try {
-                networkInterfaces = config.getInterfaces();
-            } catch (ConfigException e) {
-                log.error("Error loading port configuration");
-                return;
-            }
-            networkInterfaces.forEach(networkInterface -> {
-                if (networkInterface.name().equals("internet-router")) {
-                    upstreamCP = subject;
-                }
-            });
-        });
-
-    }
-
-    // XXX Neighbour hacking. To update the Upstream CP
-    public void updateVRouterCP(NetworkConfigEvent event) {
-        RouterConfig config = (RouterConfig) event.config().get();
-        if (config == null) {
-            log.warn("Router config not available");
-            vRouterCP = null;
-            return;
-        }
-        vRouterCP = config.getControlPlaneConnectPoint();
-    }
-
     // XXX Neigbour hack. To send out a packet
     private void sendTo(ByteBuffer packet, ConnectPoint outPort) {
         TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
diff --git a/src/main/java/org/onosproject/segmentrouting/RouteHandler.java b/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
index 1741608..6838af5 100644
--- a/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
@@ -81,8 +81,8 @@
         MacAddress nextHopMac = route.nextHopMac();
         ConnectPoint location = route.location();
 
-        srManager.deviceConfiguration.removeSubnet(location, prefix.getIp4Prefix());
-        srManager.defaultRoutingHandler.revokeSubnet(ImmutableSet.of(prefix.getIp4Prefix()));
+        srManager.deviceConfiguration.removeSubnet(location, prefix);
+        srManager.defaultRoutingHandler.revokeSubnet(ImmutableSet.of(prefix));
         srManager.routingRulePopulator.revokeRoute(
                 location.deviceId(), prefix, nextHopMac, location.port());
     }
diff --git a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index c356f5e..fc9304a 100644
--- a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -34,8 +34,10 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.event.Event;
+import org.onosproject.incubator.net.config.basics.ConfigException;
 import org.onosproject.incubator.net.config.basics.InterfaceConfig;
 import org.onosproject.incubator.net.config.basics.McastConfig;
+import org.onosproject.incubator.net.intf.Interface;
 import org.onosproject.incubator.net.intf.InterfaceService;
 import org.onosproject.incubator.net.routing.RouteEvent;
 import org.onosproject.incubator.net.routing.RouteListener;
@@ -1108,7 +1110,7 @@
                 switch (event.type()) {
                     case CONFIG_ADDED:
                     case CONFIG_UPDATED:
-                        icmpHandler.updateUPstreamCP(event);
+                        updateUPstreamCP();
                     case CONFIG_REGISTERED:
                     case CONFIG_UNREGISTERED:
                     case CONFIG_REMOVED:
@@ -1122,7 +1124,7 @@
                 switch (event.type()) {
                     case CONFIG_ADDED:
                     case CONFIG_UPDATED:
-                        icmpHandler.updateVRouterCP(event);
+                        updateVRouterCP(event);
                     case CONFIG_REGISTERED:
                     case CONFIG_UNREGISTERED:
                     case CONFIG_REMOVED:
@@ -1134,6 +1136,50 @@
         }
     }
 
+    /////////////////////////////////////////////////////////////////
+    //    XXX Neighbour hacking, temporary workaround will be      //
+    //    removed as soon as possible, when the bridging will      //
+    //    be implemented. For now, it's fine to leave this         //
+    /////////////////////////////////////////////////////////////////
+
+    // XXX Neighbour hacking. To store upstream connect
+    // point and vRouter connect point
+    ConnectPoint upstreamCP = null;
+    ConnectPoint vRouterCP = null;
+
+    // XXX Neighbour hacking. To update the Upstream CP
+    public void updateUPstreamCP() {
+        Set<ConnectPoint> portSubjects = cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
+        upstreamCP = null;
+        portSubjects.stream().forEach(subject -> {
+            InterfaceConfig config = cfgService.getConfig(subject, InterfaceConfig.class);
+            Set<Interface> networkInterfaces;
+            try {
+                networkInterfaces = config.getInterfaces();
+            } catch (ConfigException e) {
+                log.error("Error loading port configuration");
+                return;
+            }
+            networkInterfaces.forEach(networkInterface -> {
+                if (networkInterface.name().equals("internet-router")) {
+                    upstreamCP = subject;
+                }
+            });
+        });
+
+    }
+
+    // XXX Neighbour hacking. To update the Upstream CP
+    public void updateVRouterCP(NetworkConfigEvent event) {
+        RouterConfig config = (RouterConfig) event.config().get();
+        if (config == null) {
+            log.warn("Router config not available");
+            vRouterCP = null;
+            return;
+        }
+        vRouterCP = config.getControlPlaneConnectPoint();
+    }
+
     private class InternalHostListener implements HostListener {
         @Override
         public void event(HostEvent event) {