Stale MIP FIB/Flow entries present upon deletion of VRRP master
[netvirt.git] / vpnmanager / impl / src / main / java / org / opendaylight / netvirt / vpnmanager / VpnUtil.java
index 92a2bb6c000e6c8a060f3ccb46fce6556639b962..2c47b7e560a68590faf3917f92e92e380dcc6937 100644 (file)
@@ -966,8 +966,8 @@ public final class VpnUtil {
                 new LearntVpnVipToPortKey(fixedIp, vpnName)).build();
     }
 
-    void removeLearntVpnVipToPort(String vpnName, String fixedIp,
-                                  @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
+    public void removeLearntVpnVipToPort(String vpnName, String fixedIp,
+                                         @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
         final InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
         final ReentrantLock lock = lockFor(vpnName, fixedIp);
         lock.lock();
@@ -984,7 +984,7 @@ public final class VpnUtil {
         }
     }
 
-    protected static void removeVpnPortFixedIpToPort(DataBroker broker, String vpnName, String fixedIp,
+    public static void removeVpnPortFixedIpToPort(DataBroker broker, String vpnName, String fixedIp,
                                                      @Nullable TypedWriteTransaction<Configuration> writeConfigTxn) {
         final InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
         final ReentrantLock lock = lockFor(vpnName, fixedIp);
@@ -1071,11 +1071,29 @@ public final class VpnUtil {
         VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, prefix, null);
     }
 
+    public void removeMipAdjacency(String vpnName, String vpnInterface, String prefix,
+                                   TypedWriteTransaction<Configuration> writeConfigTxn) {
+        String ip = VpnUtil.getIpPrefix(prefix);
+        LOG.trace("Removing {} adjacency from Old VPN Interface {} ", ip, vpnInterface);
+        InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
+        InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
+        //TODO: Remove synchronized?
+
+        Optional<Adjacencies> adjacencies = read(LogicalDatastoreType.OPERATIONAL, path);
+        if (adjacencies.isPresent()) {
+            InstanceIdentifier<Adjacency> adjacencyIdentifier = getAdjacencyIdentifier(vpnInterface, prefix);
+            writeConfigTxn.delete(adjacencyIdentifier);
+            LOG.error("removeMipAdjacency: Successfully Deleted Adjacency {} from interface {} vpn {}", ip,
+                    vpnInterface, vpnName);
+        }
+    }
+
     public void removeMipAdjacency(String vpnInterface, String ipAddress) {
         String prefix = VpnUtil.getIpPrefix(ipAddress);
         InstanceIdentifier<Adjacency> adjacencyIdentifier = getAdjacencyIdentifier(vpnInterface, prefix);
         try {
-            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
+            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    adjacencyIdentifier);
         } catch (TransactionCommitFailedException e) {
             if (e.getCause() instanceof ModifiedNodeDoesNotExistException) {
                 LOG.debug("vpnInterface {} is already deleted. prefix={}", vpnInterface, prefix);