Bug 5463 : Fixing datapath-id changing behaviour seen while testing with mininet
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / utilities / SouthboundUtils.java
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){