Add VPP to bridge domain. 87/187/2
authorJozef Gloncak <jgloncak@cisco.com>
Tue, 2 Feb 2016 14:16:06 +0000 (15:16 +0100)
committerJozef Gloncak <jgloncak@cisco.com>
Tue, 2 Feb 2016 14:37:20 +0000 (15:37 +0100)
Request for adding VPP to bridge domain is received by
VPP application which send this requirement to mounted VPP.
It means that information about membership of VPP is
resend to VPP and stored to its datastore.

Change-Id: Idc44b4d0bd505597cfb89b537eb9d17eaac50391
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
vbd/api/src/main/yang/vbridge-topology.yang
vbd/impl/pom.xml
vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java

index f105b5e..9019073 100644 (file)
@@ -91,8 +91,10 @@ module vbridge-topology {
     }
 
     augment "/nt:network-topology/nt:topology/nt:node" {
+        ext:augment-identifier "node-vbridge-augment";
         when "../nt:topology-types/vbridge-topology";
 
+
         container bridge-member {
             presence "Indicates this node is part of the bridge domain";
 
index d4ac30d..6f966b8 100644 (file)
       <artifactId>vbd-api</artifactId>
     </dependency>
 
+      <dependency>
+          <groupId>io.fd.honeycomb.v3po</groupId>
+          <artifactId>v3po-api</artifactId>
+          <version>1.0.0-SNAPSHOT</version>
+      </dependency>
+
     <!-- Testing Dependencies -->
     <dependency>
       <groupId>junit</groupId>
index 9cea658..e7652aa 100644 (file)
@@ -8,6 +8,7 @@
 
 package io.fd.honeycomb.vbd.impl;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.Collection;
 import javax.annotation.concurrent.GuardedBy;
@@ -18,15 +19,26 @@ import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.Mod
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.MountPoint;
 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyVbridgeAugment;
+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.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 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.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,12 +50,14 @@ import org.slf4j.LoggerFactory;
 final class BridgeDomain implements DataTreeChangeListener<Topology> {
     private static final Logger LOG = LoggerFactory.getLogger(BridgeDomain.class);
     private final KeyedInstanceIdentifier<Topology, TopologyKey> topology;
-
     @GuardedBy("this")
+
     private final BindingTransactionChain chain;
     private final ListenerRegistration<?> reg;
     private final MountPointService mountService;
     private TopologyVbridgeAugment config;
+    private final String bridgeDomainName;
+    private final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain> iiBridgeDomainOnVPP;
 
     private BridgeDomain(final DataBroker dataBroker, final MountPointService mountService, final KeyedInstanceIdentifier<Topology, TopologyKey> topology,
             final BindingTransactionChain chain) {
@@ -51,6 +65,11 @@ final class BridgeDomain implements DataTreeChangeListener<Topology> {
         this.chain = Preconditions.checkNotNull(chain);
         this.mountService = mountService;
 
+        this.bridgeDomainName = topology.getKey().getTopologyId().getValue();
+        this.iiBridgeDomainOnVPP = InstanceIdentifier.create(Vpp.class)
+                .child(BridgeDomains.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain.class, new BridgeDomainKey(bridgeDomainName));
+
         reg = dataBroker.registerDataTreeChangeListener(
             new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, topology), this);
     }
@@ -110,7 +129,7 @@ final class BridgeDomain implements DataTreeChangeListener<Topology> {
                         LOG.debug("Topology {} modified child {}", topology, child);
 
                         if (Node.class.isAssignableFrom(child.getDataType())) {
-                            modifyNode((DataObjectModification<Node>) child);
+                            modifyNode((DataObjectModification<Node>) child, newConfig.getDataAfter());
                         }
                     }
 
@@ -136,7 +155,7 @@ final class BridgeDomain implements DataTreeChangeListener<Topology> {
         }
     }
 
-    private void modifyNode(final DataObjectModification<Node> child) {
+    private void modifyNode(final DataObjectModification<Node> child, final TopologyVbridgeAugment topologyVbridgeAugment) {
         switch (child.getModificationType()) {
             case DELETE:
                 LOG.debug("Topology {} node {} deleted", topology, child.getIdentifier());
@@ -148,7 +167,7 @@ final class BridgeDomain implements DataTreeChangeListener<Topology> {
                 break;
             case WRITE:
                 LOG.debug("Topology {} node {} created", topology, child.getIdentifier());
-                // FIXME: do something
+                createNode(child.getDataAfter(), topologyVbridgeAugment);
                 break;
             default:
                 LOG.warn("Unhandled node modification {} in topology {}", child, topology);
@@ -156,6 +175,40 @@ final class BridgeDomain implements DataTreeChangeListener<Topology> {
         }
     }
 
+    private void createNode(final Node node, final TopologyVbridgeAugment topologyVbridgeAugment) {
+        for (SupportingNode supportingNode : node.getSupportingNode()) {
+            final NodeId nodeMount = supportingNode.getNodeRef();
+            final TopologyId topologyMount = supportingNode.getTopologyRef();
+
+            final KeyedInstanceIdentifier<Node, NodeKey> iiToMount = InstanceIdentifier
+                    .create(NetworkTopology.class)
+                    .child(Topology.class, new TopologyKey(topologyMount))
+                    .child(Node.class, new NodeKey(nodeMount));
+            final Optional<MountPoint> vppMountOption = mountService.getMountPoint(iiToMount);
+            if (vppMountOption.isPresent()) {
+                final MountPoint vppMount = vppMountOption.get();
+                addVppToBridgeDomain(topologyVbridgeAugment, vppMount);
+            }
+        }
+    }
+
+    private void addVppToBridgeDomain(TopologyVbridgeAugment topologyVbridgeAugment, MountPoint vppMount) {
+        final Optional<DataBroker> dataBrokerOpt = vppMount.getService(DataBroker.class);
+        if (dataBrokerOpt.isPresent()) {
+            final DataBroker vppDataBroker = dataBrokerOpt.get();
+            final WriteTransaction wTx = vppDataBroker.newWriteOnlyTransaction();
+            wTx.put(LogicalDatastoreType.OPERATIONAL, iiBridgeDomainOnVPP, prepareNewBridgeDomainData(topologyVbridgeAugment));
+            wTx.submit();
+        }
+    }
+
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain
+        prepareNewBridgeDomainData(TopologyVbridgeAugment topologyVbridgeAugment) {
+            final BridgeDomainBuilder bridgeDomainBuilder = new BridgeDomainBuilder(topologyVbridgeAugment);
+            bridgeDomainBuilder.setName(topology.getKey().getTopologyId().getValue());
+            return bridgeDomainBuilder.build();
+    }
+
     private void setConfiguration(final TopologyVbridgeAugment config) {
         LOG.debug("Topology {} configuration set to {}", topology, config);