Bug 5463 : Fixing datapath-id changing behaviour seen while testing with mininet 60/37860/2
authorFaseela K <faseela.k@ericsson.com>
Thu, 17 Mar 2016 12:22:11 +0000 (17:52 +0530)
committerFaseela K <faseela.k@ericsson.com>
Wed, 20 Apr 2016 09:33:18 +0000 (09:33 +0000)
Description : With mininet, when a switch is started, the initial
datapath-id assigned by OVS gets updated by mininet in between, which was
not handled properly in interface-manager. Fixing this, so that any
datapath-node-id updates of a bridge can be handled.

Change-Id: Ib8fa81f37731ed903971f4e2ce15172a341163fd
Signed-off-by: Faseela K <faseela.k@ericsson.com>
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceMetaUtils.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/listeners/InterfaceTopologyStateListener.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateAddHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateRemoveHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateUpdateHelper.java [new file with mode: 0644]
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/utilities/SouthboundUtils.java

index 797e5597c73e737e9f1bd36b8b61af0a3781727a..396a470bbeed6be1babe8d119d2e7cc8ee3e99e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -57,6 +57,7 @@ public class InterfaceMetaUtils {
         return bridgeRefEntryInstanceIdentifierBuilder.build();
     }
 
+
     public static BridgeRefEntry getBridgeRefEntryFromOperDS(InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid,
                                                              DataBroker dataBroker) {
         Optional<BridgeRefEntry> bridgeRefEntryOptional =
@@ -73,6 +74,15 @@ public class InterfaceMetaUtils {
         return bridgeEntryIdBuilder.build();
     }
 
+    public static BridgeEntry getBridgeEntryFromConfigDS(BigInteger dpnId,
+                                                         DataBroker dataBroker) {
+        BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpnId);
+        InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier =
+                InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
+        return getBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier,
+                        dataBroker);
+    }
+
     public static BridgeEntry getBridgeEntryFromConfigDS(InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier,
                                                          DataBroker dataBroker) {
         Optional<BridgeEntry> bridgeEntryOptional =
@@ -186,6 +196,8 @@ public class InterfaceMetaUtils {
 
     public static void createBridgeRefEntry(BigInteger dpnId, InstanceIdentifier<?> bridgeIid,
                                             WriteTransaction tx){
+        LOG.debug("Creating bridge ref entry for dpn: {} bridge: {}",
+                dpnId, bridgeIid);
         BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
         InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
                 InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
@@ -194,4 +206,14 @@ public class InterfaceMetaUtils {
                         .setBridgeReference(new OvsdbBridgeRef(bridgeIid));
         tx.put(LogicalDatastoreType.OPERATIONAL, bridgeEntryId, tunnelDpnBridgeEntryBuilder.build(), true);
     }
+
+    public static void deleteBridgeRefEntry(BigInteger dpnId,
+                                            WriteTransaction tx) {
+        LOG.debug("Deleting bridge ref entry for dpn: {}",
+                dpnId);
+        BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
+        InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
+                InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
+        tx.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
+    }
 }
\ No newline at end of file
index 81203c7a58440974092c77b42559f14b8d5ac613..cf6005324fbe81caa31d392f08c3bd6691e3289c 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase;
 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceTopologyStateAddHelper;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceTopologyStateRemoveHelper;
+import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceTopologyStateUpdateHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -68,7 +69,11 @@ public class InterfaceTopologyStateListener extends AsyncDataChangeListenerBase<
         if(bridgeOld.getDatapathId()== null && bridgeNew.getDatapathId()!= null){
             DataStoreJobCoordinator jobCoordinator = DataStoreJobCoordinator.getInstance();
             RendererStateAddWorker rendererStateAddWorker = new RendererStateAddWorker(identifier, bridgeNew);
-            jobCoordinator.enqueueJob(bridgeNew.getBridgeName().getValue() + bridgeNew.getDatapathId(), rendererStateAddWorker);
+            jobCoordinator.enqueueJob(bridgeNew.getBridgeName().getValue(), rendererStateAddWorker);
+        } else if(bridgeOld.getDatapathId() != bridgeNew.getDatapathId()){
+            DataStoreJobCoordinator jobCoordinator = DataStoreJobCoordinator.getInstance();
+            RendererStateUpdateWorker rendererStateAddWorker = new RendererStateUpdateWorker(identifier, bridgeNew, bridgeOld);
+            jobCoordinator.enqueueJob(bridgeNew.getBridgeName().getValue(), rendererStateAddWorker);
         }
     }
 
@@ -120,4 +125,25 @@ public class InterfaceTopologyStateListener extends AsyncDataChangeListenerBase<
                     bridgeNew, dataBroker);
         }
     }
+    private class RendererStateUpdateWorker implements Callable<List<ListenableFuture<Void>>> {
+        InstanceIdentifier<OvsdbBridgeAugmentation> instanceIdentifier;
+        OvsdbBridgeAugmentation bridgeNew;
+        OvsdbBridgeAugmentation bridgeOld;
+
+
+        public RendererStateUpdateWorker(InstanceIdentifier<OvsdbBridgeAugmentation> instanceIdentifier,
+                                      OvsdbBridgeAugmentation bridgeNew, OvsdbBridgeAugmentation bridgeOld) {
+            this.instanceIdentifier = instanceIdentifier;
+            this.bridgeNew = bridgeNew;
+            this.bridgeOld = bridgeOld;
+        }
+
+        @Override
+        public List<ListenableFuture<Void>> call() throws Exception {
+            // If another renderer(for eg : CSS) needs to be supported, check can be performed here
+            // to call the respective helpers.
+            return OvsInterfaceTopologyStateUpdateHelper.updateBridgeRefEntry(instanceIdentifier,
+                    bridgeNew, bridgeOld, dataBroker);
+        }
+    }
 }
\ No newline at end of file
index c4babcdab6654f7fa9727ae600d9f8e47879b7fa..95f9e91ff3deb42d1479da2c05038d4a02eaab89 100644 (file)
@@ -47,7 +47,6 @@ public class OvsInterfaceTopologyStateAddHelper {
             LOG.warn("DataPathId found as null for Bridge Augmentation: {}... returning...", bridgeNew);
             return futures;
         }
-        String bridgeName = bridgeNew.getBridgeName().getValue();
         BigInteger dpnId = IfmUtil.getDpnId(bridgeNew.getDatapathId());
 
         // create bridge reference entry in interface meta operational DS
@@ -56,26 +55,13 @@ public class OvsInterfaceTopologyStateAddHelper {
         // 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(dpnId);
-        InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier =
-                InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
-        BridgeEntry bridgeEntry =
-                InterfaceMetaUtils.getBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier,
-                        dataBroker);
+        // handle pre-provisioning of tunnels for the newly connected dpn
+        BridgeEntry bridgeEntry = InterfaceMetaUtils.getBridgeEntryFromConfigDS(dpnId, dataBroker);
         if (bridgeEntry == null) {
             futures.add(writeTransaction.submit());
             return futures;
         }
-
-        List<BridgeInterfaceEntry> bridgeInterfaceEntries = bridgeEntry.getBridgeInterfaceEntry();
-        for (BridgeInterfaceEntry bridgeInterfaceEntry : bridgeInterfaceEntries) {
-            String portName = bridgeInterfaceEntry.getInterfaceName();
-            InterfaceKey interfaceKey = new InterfaceKey(portName);
-            Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
-            if (iface.getAugmentation(IfTunnel.class) != null) {
-                SouthboundUtils.addPortToBridge(bridgeIid, iface, bridgeNew, bridgeName, portName, dataBroker, futures);
-            }
-        }
+        SouthboundUtils.addAllPortsToBridge(bridgeEntry, dataBroker, bridgeIid, bridgeNew, writeTransaction);
 
         futures.add(writeTransaction.submit());
         return futures;
index dd4f25db0712bd1c118d37175d63a1bd7f21e866..ca03320cfd43e56aab62c37d2e6aef7a1cf7cf3d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -31,22 +31,21 @@ public class OvsInterfaceTopologyStateRemoveHelper {
     public static List<ListenableFuture<Void>> removePortFromBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
                                                                OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
-        WriteTransaction t = dataBroker.newWriteOnlyTransaction();;
+        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();;
         BigInteger dpnId = IfmUtil.getDpnId(bridgeOld.getDatapathId());
 
         if (dpnId == null) {
             LOG.warn("Got Null DPID for Bridge: {}", bridgeOld);
             return futures;
         }
-        BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId);
-        InstanceIdentifier<BridgeRefEntry> bridgeEntryId =
-                InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
-        t.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
+
+        //delete bridge reference entry in interface meta operational DS
+        InterfaceMetaUtils.deleteBridgeRefEntry(dpnId, transaction);
 
         // FIX for ovsdb bug for delete TEP
         SouthboundUtils.deleteBridge(bridgeIid, dataBroker, futures);
 
-        futures.add(t.submit());
+        futures.add(transaction.submit());
         return futures;
     }
 }
\ No newline at end of file
diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateUpdateHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateUpdateHelper.java
new file mode 100644 (file)
index 0000000..b2dcb4a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
+import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
+import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
+import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.utilities.SouthboundUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.bridge.entry.BridgeInterfaceEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OvsInterfaceTopologyStateUpdateHelper {
+    private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceTopologyStateUpdateHelper.class);
+    /*
+     *  This code is used to handle only a dpnId change scenario for a particular change,
+     * which is not expected to happen in usual cases.
+     */
+    public static List<ListenableFuture<Void>> updateBridgeRefEntry(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
+                                                                    OvsdbBridgeAugmentation bridgeNew,
+                                                                    OvsdbBridgeAugmentation bridgeOld,
+                                                                    DataBroker dataBroker) {
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+
+        BigInteger dpnIdNew = IfmUtil.getDpnId(bridgeNew.getDatapathId());
+        BigInteger dpnIdOld = IfmUtil.getDpnId(bridgeOld.getDatapathId());
+
+        //delete bridge reference entry for the old dpn in interface meta operational DS
+        InterfaceMetaUtils.deleteBridgeRefEntry(dpnIdOld, writeTransaction);
+
+        // create bridge reference entry in interface meta operational DS
+        InterfaceMetaUtils.createBridgeRefEntry(dpnIdNew, bridgeIid, writeTransaction);
+
+        // handle pre-provisioning of tunnels for the newly connected dpn
+        BridgeEntry bridgeEntry = InterfaceMetaUtils.getBridgeEntryFromConfigDS(dpnIdNew, dataBroker);
+        if (bridgeEntry == null) {
+            futures.add(writeTransaction.submit());
+            return futures;
+        }
+        SouthboundUtils.addAllPortsToBridge(bridgeEntry, dataBroker, bridgeIid, bridgeNew, writeTransaction);
+
+        futures.add(writeTransaction.submit());
+        return futures;
+    }
+}
\ No newline at end of file
index 12100561eecde8d26a1c466953839736cbf44396..5f79a83b2694c3a57246550dcf4c1ee8c765e008 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,12 +12,16 @@ import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.bridge.entry.BridgeInterfaceEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.*;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -54,6 +58,27 @@ public class SouthboundUtils {
         futures.add(tx.submit());
     }
 
+    /*
+     *  add all tunnels ports corresponding to the bridge to the topology config DS
+     */
+    public static void addAllPortsToBridge(BridgeEntry bridgeEntry, DataBroker dataBroker,
+                                           InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
+                                           OvsdbBridgeAugmentation bridgeNew,
+                                           WriteTransaction writeTransaction){
+        String bridgeName = bridgeNew.getBridgeName().getValue();
+        LOG.debug("adding all ports to bridge: {}", bridgeName);
+        List<BridgeInterfaceEntry> bridgeInterfaceEntries = bridgeEntry.getBridgeInterfaceEntry();
+        for (BridgeInterfaceEntry bridgeInterfaceEntry : bridgeInterfaceEntries) {
+            String portName = bridgeInterfaceEntry.getInterfaceName();
+            InterfaceKey interfaceKey = new InterfaceKey(portName);
+            Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
+            IfTunnel ifTunnel = iface.getAugmentation(IfTunnel.class);
+            if (ifTunnel != null) {
+                addTunnelPortToBridge(ifTunnel, bridgeIid, iface, bridgeNew, bridgeName, portName, dataBroker, writeTransaction);
+            }
+        }
+    }
+
     public static void addBridge(InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid,
                                  OvsdbBridgeAugmentation bridgeAugmentation,
                                  DataBroker dataBroker, List<ListenableFuture<Void>> futures){