Merge "Use ClusteredDataTreeListener in hwvtepsb"
[netvirt.git] / openstack / net-virt-providers / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / providers / openflow13 / services / arp / GatewayMacResolverService.java
index be01ac5a0cb6668a369d0890575fac2e958ef27a..af75afb5da777d40349a261cf96cfdf94d9314a1 100644 (file)
@@ -93,7 +93,6 @@ public class GatewayMacResolverService extends AbstractServiceInstance
                                         implements ConfigInterface, GatewayMacResolver,PacketProcessingListener {
 
     private static final Logger LOG = LoggerFactory.getLogger(GatewayMacResolverService.class);
-    private static final short TABLE_FOR_ARP_FLOW = 0;
     private static final String ARP_REPLY_TO_CONTROLLER_FLOW_NAME = "GatewayArpReplyRouter";
     private static final int ARP_REPLY_TO_CONTROLLER_FLOW_PRIORITY = 10000;
     private static final Instruction SEND_TO_CONTROLLER_INSTRUCTION;
@@ -151,7 +150,8 @@ public class GatewayMacResolverService extends AbstractServiceInstance
                         for(final Entry<Ipv4Address, ArpResolverMetadata> gatewayToArpMetadataEntry : gatewayToArpMetadataMap.entrySet()){
                             final Ipv4Address gatewayIp = gatewayToArpMetadataEntry.getKey();
                             final ArpResolverMetadata gatewayMetaData =
-                                    checkAndGetExternalBridgeDpid(gatewayToArpMetadataEntry.getValue());
+                                    checkAndGetExternalBridgeDpid(
+                                            resetFlowToRemove(gatewayIp, gatewayToArpMetadataEntry.getValue()));
                             gatewayMacRefresherPool.schedule(new Runnable(){
 
                                 @Override
@@ -370,6 +370,7 @@ public class GatewayMacResolverService extends AbstractServiceInstance
                     ArpResolverMetadata arpResolverMetadata = gatewayToArpMetadataMap.get(gatewayIp);
                     if(arpResolverMetadata != null && arpResolverMetadata.getGatewayMacAddress() != null){
                         if(!arpResolverMetadata.isPeriodicRefresh()){
+                            resetFlowToRemove(gatewayIp, arpResolverMetadata);
                             return gatewayToArpMetadataMap.remove(gatewayIp).getGatewayMacAddress();
                         }
                         return arpResolverMetadata.getGatewayMacAddress();
@@ -383,7 +384,7 @@ public class GatewayMacResolverService extends AbstractServiceInstance
     private Flow createArpReplyToControllerFlow(final ArpMessageAddress senderAddress, final Ipv4Address ipForRequestedMac) {
         checkNotNull(senderAddress);
         checkNotNull(ipForRequestedMac);
-        FlowBuilder arpFlow = new FlowBuilder().setTableId(TABLE_FOR_ARP_FLOW)
+        FlowBuilder arpFlow = new FlowBuilder().setTableId(Service.CLASSIFIER.getTable())
             .setFlowName(ARP_REPLY_TO_CONTROLLER_FLOW_NAME)
             .setPriority(ARP_REPLY_TO_CONTROLLER_FLOW_PRIORITY)
             .setBufferId(OFConstants.OFP_NO_BUFFER)
@@ -453,7 +454,7 @@ public class GatewayMacResolverService extends AbstractServiceInstance
             if(candidateGatewayIp != null){
                 LOG.debug("Resolved MAC for Gateway Ip {} is {}",gatewayIpAddress.getValue(),gatewayMacAddress.getValue());
                 candidateGatewayIp.setGatewayMacAddress(gatewayMacAddress);
-                flowService.removeFlow(candidateGatewayIp.getFlowToRemove());
+                resetFlowToRemove(gatewayIpAddress, candidateGatewayIp);
             }
         }
     }
@@ -477,7 +478,25 @@ public class GatewayMacResolverService extends AbstractServiceInstance
     @Override
     public void stopPeriodicRefresh(Ipv4Address gatewayIp) {
         init();
+        resetFlowToRemove(gatewayIp, null);
         gatewayToArpMetadataMap.remove(gatewayIp);
     }
 
+    private ArpResolverMetadata resetFlowToRemove(
+            final Ipv4Address gatewayIp, ArpResolverMetadata gatewayArpMetadata) {
+        checkNotNull(gatewayIp);
+
+        // If gatewayArpMetadata was not provided, look it up
+        if (gatewayArpMetadata == null) {
+            gatewayArpMetadata = gatewayToArpMetadataMap.get(gatewayIp);
+        }
+        if (gatewayArpMetadata != null && gatewayArpMetadata.getFlowToRemove() != null) {
+            LOG.debug("Flow to route ARP Reply to Controller from {} being removed from node {}",
+                    gatewayIp, gatewayArpMetadata.getFlowToRemove().getNode());
+            flowService.removeFlow(gatewayArpMetadata.getFlowToRemove());
+            gatewayArpMetadata.setFlowToRemove(null);
+        }
+        return gatewayArpMetadata;
+    }
+
 }