Bug 5064 - Deletion of tunnel interfaces not removing the TEP from switch
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / statehelpers / OvsInterfaceTopologyStateAddHelper.java
index 4b426a09f7a9282a582cf37350649fa05ae9fb17..ae9dccf33575c3886974a88a126d30514564157c 100644 (file)
@@ -28,8 +28,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.met
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,7 +41,7 @@ public class OvsInterfaceTopologyStateAddHelper {
     public static List<ListenableFuture<Void>> addPortToBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
                                                                OvsdbBridgeAugmentation bridgeNew, DataBroker dataBroker) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
-        WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+        WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
 
         if (bridgeNew.getDatapathId() == null) {
             LOG.warn("DataPathId found as null for Bridge Augmentation: {}... retrying...", bridgeNew);
@@ -56,36 +54,28 @@ public class OvsInterfaceTopologyStateAddHelper {
                 return futures;
             }
         }
-
-        String dpId = bridgeNew.getDatapathId().getValue();
         String bridgeName = bridgeNew.getBridgeName().getValue();
-        LOG.info("adding dpId {} to bridge reference {}", dpId, bridgeNew);
+        BigInteger dpnId = IfmUtil.getDpnId(bridgeNew.getDatapathId());
 
-        if (dpId == null) {
-            LOG.error("Optained null dpid for bridge: {}", bridgeNew);
+        if (dpnId == null) {
+            LOG.warn("Got Null DPID for Bridge: {}", bridgeNew);
             return futures;
         }
 
-        String datapathId = dpId.replaceAll("[^\\d.]", "");
-        BigInteger ovsdbDpId = new BigInteger(datapathId, 16);
+        // create bridge reference entry in interface meta operational DS
+        InterfaceMetaUtils.createBridgeRefEntry(dpnId, bridgeIid, writeTransaction);
 
-        LOG.info("adding dpId {} to bridge reference {}", datapathId, bridgeName);
-        BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(ovsdbDpId);
-        InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
-                InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
-        BridgeRefEntryBuilder tunnelDpnBridgeEntryBuilder =
-                new BridgeRefEntryBuilder().setKey(bridgeRefEntryKey).setDpid(ovsdbDpId)
-                        .setBridgeReference(new OvsdbBridgeRef(bridgeIid));
-        t.put(LogicalDatastoreType.OPERATIONAL, bridgeEntryId, tunnelDpnBridgeEntryBuilder.build(), true);
+        // FIX for OVSDB Bug - manually copying the bridge info from topology operational DS to config DS
+        SouthboundUtils.addBridge(bridgeIid, bridgeNew, dataBroker, futures);
 
-        BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(ovsdbDpId);
+        BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpnId);
         InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier =
                 InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
         BridgeEntry bridgeEntry =
                 InterfaceMetaUtils.getBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier,
                         dataBroker);
         if (bridgeEntry == null) {
-            futures.add(t.submit());
+            futures.add(writeTransaction.submit());
             return futures;
         }
 
@@ -96,12 +86,10 @@ public class OvsInterfaceTopologyStateAddHelper {
             Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
             if (iface.getAugmentation(IfTunnel.class) != null) {
                 SouthboundUtils.addPortToBridge(bridgeIid, iface, bridgeNew, bridgeName, portName, dataBroker, futures);
-                InterfaceMetaUtils.createBridgeInterfaceEntryInConfigDS(bridgeEntryKey,
-                        new BridgeInterfaceEntryKey(portName), portName, t);
             }
         }
 
-        futures.add(t.submit());
+        futures.add(writeTransaction.submit());
         return futures;
     }
 }
\ No newline at end of file