Removes local gatewayIp set in OpenstackSwitchingArpHandler.

Change-Id: I79d2585bc74f794811dc643dc8874845428b0734
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java
index dceb7ca..f64adc0 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingArpHandler.java
@@ -16,7 +16,6 @@
 package org.onosproject.openstacknetworking.impl;
 
 import com.google.common.base.Strings;
-import com.google.common.collect.Sets;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -149,7 +148,6 @@
     private final InstancePortListener instancePortListener = new InternalInstancePortListener();
     private final OpenstackNodeListener osNodeListener = new InternalNodeEventListener();
 
-    private final Set<IpAddress> gateways = Sets.newConcurrentHashSet();
 
     private ApplicationId appId;
     private NodeId localNodeId;
@@ -166,16 +164,6 @@
 
         instancePortService.addListener(instancePortListener);
 
-        osNetworkService.networks().forEach(n -> {
-            if (n.getNetworkType() != NetworkType.FLAT) {
-                osNetworkService.subnets().forEach(s -> {
-                    if (s.getNetworkId().equals(n.getId())) {
-                        addSubnetGateway(s);
-                    }
-                });
-            }
-        });
-
         log.info("Started");
     }
 
@@ -203,24 +191,6 @@
         return getPropertyValue(properties, ARP_MODE);
     }
 
-    private void addSubnetGateway(Subnet osSubnet) {
-        if (Strings.isNullOrEmpty(osSubnet.getGateway())) {
-            return;
-        }
-        IpAddress gatewayIp = IpAddress.valueOf(osSubnet.getGateway());
-        gateways.add(gatewayIp);
-        log.debug("Added ARP proxy entry IP:{}", gatewayIp);
-    }
-
-    private void removeSubnetGateway(Subnet osSubnet) {
-        if (Strings.isNullOrEmpty(osSubnet.getGateway())) {
-            return;
-        }
-        IpAddress gatewayIp = IpAddress.valueOf(osSubnet.getGateway());
-        gateways.remove(gatewayIp);
-        log.debug("Removed ARP proxy entry IP:{}", gatewayIp);
-    }
-
     /**
      * Processes ARP request packets.
      * It checks if the target IP is owned by a known host first and then ask to
@@ -249,7 +219,8 @@
         }
 
         IpAddress targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
-        MacAddress replyMac = gateways.contains(targetIp) ? MacAddress.valueOf(gatewayMac) :
+
+        MacAddress replyMac = gatewayIp(targetIp) ? MacAddress.valueOf(gatewayMac) :
                 getMacFromHostOpenstack(targetIp, srcInstPort.networkId());
         if (replyMac == MacAddress.NONE) {
             log.trace("Failed to find MAC address for {}", targetIp);
@@ -271,6 +242,11 @@
                 ByteBuffer.wrap(ethReply.serialize())));
     }
 
+    private boolean gatewayIp(IpAddress targetIp) {
+        return osNetworkService.subnets().stream()
+                .anyMatch(subnet -> subnet.getGateway().equals(targetIp.toString()));
+    }
+
     /**
      * Returns MAC address of a host with a given target IP address by asking to
      * instance port service.
@@ -580,11 +556,9 @@
             switch (event.type()) {
                 case OPENSTACK_SUBNET_CREATED:
                 case OPENSTACK_SUBNET_UPDATED:
-                    addSubnetGateway(event.subnet());
                     setFakeGatewayArpRule(event.subnet(), true, null);
                     break;
                 case OPENSTACK_SUBNET_REMOVED:
-                    removeSubnetGateway(event.subnet());
                     setFakeGatewayArpRule(event.subnet(), false, null);
                     break;
                 case OPENSTACK_NETWORK_CREATED:
@@ -610,11 +584,6 @@
         @Override
         public boolean isRelevant(OpenstackNodeEvent event) {
 
-            // add subnet gateway to local storage in all cluster nodes
-            // TODO: need to persistent the gateway collection into eventually
-            // consistent map sooner or later
-            addAllSubnetGateways();
-
             // do not allow to proceed without leadership
             NodeId leader = leadershipService.getLeader(appId.name());
             return Objects.equals(localNodeId, leader) && event.subject().type() == COMPUTE;
@@ -637,19 +606,6 @@
             }
         }
 
-        private void addAllSubnetGateways() {
-            osNetworkService.networks().forEach(n -> {
-                if (n.getNetworkType() != NetworkType.FLAT) {
-                    osNetworkService.subnets()
-                            .stream()
-                            .filter(s -> s.getNetworkId().equals(n.getId()))
-                            .filter(s -> !Strings.isNullOrEmpty(s.getGateway()))
-                            .filter(s -> !gateways.contains(IpAddress.valueOf(s.getGateway())))
-                            .forEach(OpenstackSwitchingArpHandler.this::addSubnetGateway);
-                }
-            });
-        }
-
         private void setDefaultArpRule(OpenstackNode osNode, boolean install) {
 
             if (getArpMode() == null) {