Fixes to add vni selector in setRulesToGatewayWithDstIp method.

Change-Id: I21c0307deebb3e31e2e4d77d1debfabbe07afa34
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
index 7f1ecd6..28697ed 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
@@ -276,7 +276,7 @@
         }
 
         setInternalRoutes(osRouter, osSubnet, true);
-        setGatewayIcmp(osSubnet, true);
+        setGatewayIcmp(osSubnet, osRouter, true);
         ExternalGateway exGateway = osRouter.getExternalGatewayInfo();
         if (exGateway != null && exGateway.isEnableSnat()) {
             setSourceNat(osRouterIface, true);
@@ -300,7 +300,7 @@
         }
 
         setInternalRoutes(osRouter, osSubnet, false);
-        setGatewayIcmp(osSubnet, false);
+        setGatewayIcmp(osSubnet, osRouter, false);
         ExternalGateway exGateway = osRouter.getExternalGatewayInfo();
         if (exGateway != null && exGateway.isEnableSnat()) {
             setSourceNat(osRouterIface, false);
@@ -419,7 +419,7 @@
         }
     }
 
-    private void setGatewayIcmp(Subnet osSubnet, boolean install) {
+    private void setGatewayIcmp(Subnet osSubnet, Router osRouter, boolean install) {
         OpenstackNode sourceNatGateway = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
 
         if (sourceNatGateway == null) {
@@ -433,26 +433,30 @@
 
         // take ICMP request to a subnet gateway through gateway node group
         Network network = osNetworkAdminService.network(osSubnet.getNetworkId());
+        Set<Subnet> routableSubnets = routableSubnets(osRouter, osSubnet.getId());
+
         switch (network.getNetworkType()) {
             case VXLAN:
                 osNodeService.completeNodes(COMPUTE).stream()
                         .filter(cNode -> cNode.dataIp() != null)
-                        .forEach(cNode -> setRulesToGatewayWithDstIp(
+                        .forEach(cNode -> setRulesToGatewayWithRoutableSubnets(
                                 cNode,
                                 sourceNatGateway,
                                 network.getProviderSegID(),
-                                IpAddress.valueOf(osSubnet.getGateway()),
+                                osSubnet,
+                                routableSubnets,
                                 NetworkMode.VXLAN,
                                 install));
                 break;
             case VLAN:
                 osNodeService.completeNodes(COMPUTE).stream()
                         .filter(cNode -> cNode.vlanPortNum() != null)
-                        .forEach(cNode -> setRulesToGatewayWithDstIp(
+                        .forEach(cNode -> setRulesToGatewayWithRoutableSubnets(
                                 cNode,
                                 sourceNatGateway,
                                 network.getProviderSegID(),
-                                IpAddress.valueOf(osSubnet.getGateway()),
+                                osSubnet,
+                                routableSubnets,
                                 NetworkMode.VLAN,
                                 install));
                 break;
@@ -659,7 +663,6 @@
 
     private void setRulesToGateway(OpenstackNode osNode, String segmentId, IpPrefix srcSubnet,
                                    NetworkType networkType, boolean install) {
-        TrafficTreatment treatment;
         OpenstackNode sourceNatGateway = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
 
         if (sourceNatGateway == null) {
@@ -743,6 +746,26 @@
                 install);
     }
 
+    private void setRulesToGatewayWithRoutableSubnets(OpenstackNode osNode, OpenstackNode sourceNatGateway,
+                                                      String segmentId, Subnet updatedSubnet,
+                                                      Set<Subnet> routableSubnets, NetworkMode networkMode,
+                                                      boolean install) {
+        //At first we install flow rules to gateway with segId and gatewayIp of updated subnet
+        setRulesToGatewayWithDstIp(osNode, sourceNatGateway, segmentId, IpAddress.valueOf(updatedSubnet.getGateway()),
+                networkMode, install);
+
+        routableSubnets.forEach(subnet -> {
+            setRulesToGatewayWithDstIp(osNode, sourceNatGateway,
+                    segmentId, IpAddress.valueOf(subnet.getGateway()),
+                    networkMode, install);
+
+            Network network = osNetworkAdminService.network(subnet.getNetworkId());
+            setRulesToGatewayWithDstIp(osNode, sourceNatGateway,
+                    network.getProviderSegID(), IpAddress.valueOf(updatedSubnet.getGateway()),
+                    networkMode, install);
+        });
+    }
+
     private void setRulesToGatewayWithDstIp(OpenstackNode osNode, OpenstackNode sourceNatGateway,
                                             String segmentId, IpAddress dstIp,
                                             NetworkMode networkMode, boolean install) {
@@ -754,6 +777,7 @@
 
         switch (networkMode) {
             case VXLAN:
+                sBuilder.matchTunnelId(Long.parseLong(segmentId));
                 tBuilder.extension(buildExtension(
                         deviceService,
                         osNode.intgBridge(),
@@ -763,6 +787,7 @@
                 break;
 
             case VLAN:
+                sBuilder.matchVlanId(VlanId.vlanId(segmentId));
                 tBuilder.setOutput(osNode.vlanPortNum());
                 break;