NETVIRT-1065 Handle new bridges 99/67399/4
authorJosh <jhershbe@redhat.com>
Tue, 16 Jan 2018 15:59:35 +0000 (17:59 +0200)
committerSam Hague <shague@redhat.com>
Mon, 22 Jan 2018 22:20:05 +0000 (22:20 +0000)
If a provider network's value is a bridge name we
patch it to br-int. If the bridge does not exist prior
to the discovery of the provider mapping ODL will assume
the provider net is a local port and add it to br-int.
However, a user can remove that port and then add the bridge
and now the code will detect that addition and create the
patch ports.

Change-Id: Ieae1a37ccf90caa51566864be14d840319429e61
Signed-off-by: Josh <jhershbe@redhat.com>
(cherry picked from commit 216a424f69d254cbafe86a06cd90a42ed7fb6d2e)

vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanBridgeManager.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanOvsdbNodeListener.java

index a2f591247f76834e5f17a8cb87d8cfca8e96ab1e..edf744eee6b73c2607ce0127da802e98b174e448 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -39,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
 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;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -177,6 +179,55 @@ public class ElanBridgeManager implements IElanBridgeManager {
 
     }
 
+    public void handleNewProviderNetBridges(Node originalNode, Node updatedNode) {
+        if (!isOvsdbNode(updatedNode)) {
+            return;
+        }
+
+        List<ManagedNodeEntry> originalManagedNodes = getManagedNodeEntries(originalNode);
+        if (originalManagedNodes == null) {
+            return;
+        }
+        List<ManagedNodeEntry> updatedManagedNodes = getManagedNodeEntries(updatedNode);
+        if (updatedManagedNodes == null) {
+            return;
+        }
+        updatedManagedNodes.removeAll(originalManagedNodes);
+        if (updatedManagedNodes.isEmpty()) {
+            return;
+        }
+        LOG.debug("handleNewProviderNetBridges checking if any of these are provider nets {}", updatedManagedNodes);
+
+        Node brInt = southboundUtils.readBridgeNode(updatedNode, INTEGRATION_BRIDGE);
+        if (brInt == null) {
+            LOG.info("handleNewProviderNetBridges, br-int not found");
+            return;
+        }
+
+        Collection<String> providerVals = getOpenvswitchOtherConfigMap(updatedNode, PROVIDER_MAPPINGS_KEY).values();
+        for (ManagedNodeEntry nodeEntry : updatedManagedNodes) {
+            String bridgeName = nodeEntry.getBridgeRef().getValue().firstKeyOf(Node.class).getNodeId().getValue();
+            bridgeName = bridgeName.substring(bridgeName.lastIndexOf('/') + 1);
+            if (bridgeName.equals(INTEGRATION_BRIDGE)) {
+                continue;
+            }
+            if (providerVals.contains(bridgeName)) {
+                patchBridgeToBrInt(brInt, southboundUtils.readBridgeNode(updatedNode, bridgeName), bridgeName);
+            }
+        }
+
+
+    }
+
+    private List<ManagedNodeEntry> getManagedNodeEntries(Node node) {
+        OvsdbNodeAugmentation ovsdbNode = southboundUtils.extractNodeAugmentation(node);
+        if (ovsdbNode == null) {
+            return null;
+        }
+
+        return ovsdbNode.getManagedNodeEntry();
+    }
+
     private void prepareIntegrationBridge(Node ovsdbNode, Node brIntNode) {
         if (southboundUtils.getBridgeFromConfig(ovsdbNode, INTEGRATION_BRIDGE) == null) {
             LOG.debug("br-int in operational but not config, copying into config");
index 8135957d313c86517a46ef95d6ea115c54cdf787..4fb4ace555fc851f91ddb2dcb8b75ca20ee870a3 100644 (file)
@@ -86,6 +86,7 @@ public class ElanOvsdbNodeListener extends AsyncDataTreeChangeListenerBase<Node,
                 && !integrationBridgeExist)) {
             doNodeUpdate(update);
         }
+        bridgeMgr.handleNewProviderNetBridges(original, update);
         if (integrationBridgeExist) {
             tzUtil.handleOvsdbNodeUpdate(original, update, identifier.firstKeyOf(Node.class).getNodeId().getValue());
         }