CORD-1015 CPR bridging alternative

- Remove workaround introduced in gerrit #12604
- Add ability to respond to IPv6 solicited-node multicast address of gateway IPs

Change-Id: I7d1c9840a51e35d471303a8f723245a5bbc809ff
diff --git a/apps/segmentrouting/BUCK b/apps/segmentrouting/BUCK
index 3fc42e7..2c26e54 100644
--- a/apps/segmentrouting/BUCK
+++ b/apps/segmentrouting/BUCK
@@ -7,7 +7,6 @@
     '//core/store/serializers:onos-core-serializers',
     '//incubator/api:onos-incubator-api',
     '//utils/rest:onlab-rest',
-    '//apps/routing-api:onos-apps-routing-api'
 ]
 
 BUNDLES = [
diff --git a/apps/segmentrouting/pom.xml b/apps/segmentrouting/pom.xml
index 9b6895d..5775b86 100644
--- a/apps/segmentrouting/pom.xml
+++ b/apps/segmentrouting/pom.xml
@@ -106,11 +106,6 @@
             <scope>test</scope>
             <classifier>tests</classifier>
         </dependency>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-app-routing-api</artifactId>
-            <version>${project.version}</version>
-        </dependency>
     </dependencies>
 
     <build>
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
index a1327c0..a42a806 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
@@ -36,15 +36,14 @@
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.host.HostService;
 import org.onosproject.net.packet.DefaultOutboundPacket;
-import org.onosproject.net.packet.InboundPacket;
 import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.packet.PacketContext;
 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
 import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 import java.util.Set;
 
 /**
@@ -404,11 +403,13 @@
         } catch (DeviceConfigNotFoundException e) {
             log.warn(e.getMessage() + " Aborting check for router IP in processing ndp");
         }
-        if (gatewayIpAddresses != null &&
-                gatewayIpAddresses.contains(pkt.target())) {
-            return true;
-        }
-        return false;
+
+        return gatewayIpAddresses != null && gatewayIpAddresses.stream()
+                .filter(IpAddress::isIp6)
+                .anyMatch(gatewayIp -> gatewayIp.equals(pkt.target()) ||
+                        Arrays.equals(IPv6.getSolicitNodeAddress(gatewayIp.toOctets()),
+                                pkt.target().toOctets())
+        );
     }
 
     /**
@@ -447,34 +448,4 @@
         );
         flood(ndpRequest, inPort, targetAddress);
     }
-
-    /////////////////////////////////////////////////////////////////
-    //    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, 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 (srManager.vRouterCP == null || srManager.upstreamCP == null) {
-            return false;
-        }
-        if (pkt.receivedFrom().equals(srManager.upstreamCP)) {
-            sendTo(ByteBuffer.wrap(ethernet.serialize()), srManager.vRouterCP);
-            return true;
-        }
-        return false;
-    }
-
-    // XXX Neigbour hack. To send out a packet
-    private void sendTo(ByteBuffer packet, ConnectPoint outPort) {
-        TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
-        builder.setOutput(outPort.port());
-        srManager.packetService.emit(new DefaultOutboundPacket(outPort.deviceId(),
-                                                     builder.build(), packet));
-    }
-
 }
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 3bdde77..02623e2 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -35,8 +35,6 @@
 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;
@@ -77,7 +75,6 @@
 import org.onosproject.net.packet.PacketService;
 import org.onosproject.net.topology.PathService;
 import org.onosproject.net.topology.TopologyService;
-import org.onosproject.routing.config.RouterConfig;
 import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
 import org.onosproject.segmentrouting.config.DeviceConfiguration;
 import org.onosproject.segmentrouting.config.PwaasConfig;
@@ -725,14 +722,8 @@
                             icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
                         icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
                     } else {
-                        // XXX Neigbour hacking, to handle the ICMPv6 packet
-                        // not under our control
-                        if (icmpHandler.handleUPstreamPackets(context)) {
-                            log.debug("Rcvd pktin from UpStream: {}", ipv6Packet);
-                        } else {
-                            log.debug("Received ICMPv6 0x{} - not handled",
-                                     Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
-                        }
+                        log.debug("Received ICMPv6 0x{} - not handled",
+                                Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
                     }
                 } else {
                    // NOTE: We don't support IP learning at this moment so this
@@ -1157,35 +1148,6 @@
                     default:
                         break;
                 }
-                // XXX Neighbour hacking. This method is looking for
-                // the Internet-Router interface. In order to retrieve
-                // the upstream port.
-            } else if (event.configClass().equals(InterfaceConfig.class)) {
-                switch (event.type()) {
-                    case CONFIG_ADDED:
-                    case CONFIG_UPDATED:
-                        updateUPstreamCP();
-                    case CONFIG_REGISTERED:
-                    case CONFIG_UNREGISTERED:
-                    case CONFIG_REMOVED:
-                        break;
-                    default:
-                        break;
-                }
-                // XXX Neighbour hacking. This method is looking for
-                // the vrouter port.
-            } else if (event.configClass().equals(RouterConfig.class)) {
-                switch (event.type()) {
-                    case CONFIG_ADDED:
-                    case CONFIG_UPDATED:
-                        updateVRouterCP(event);
-                    case CONFIG_REGISTERED:
-                    case CONFIG_UNREGISTERED:
-                    case CONFIG_REMOVED:
-                        break;
-                    default:
-                        break;
-                }
             } else if (event.configClass().equals(PwaasConfig.class)) {
                 checkState(l2TunnelHandler != null, "L2TunnelHandler is not initialized");
                 switch (event.type()) {
@@ -1205,50 +1167,6 @@
         }
     }
 
-    /////////////////////////////////////////////////////////////////
-    //    XXX Neighbour hacking, temporary workaround will be      //
-    //    removed as soon as possible, when bridging based         //
-    //    control plane redirect is implemented.                   //
-    /////////////////////////////////////////////////////////////////
-
-    // 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) {