From 95588dfe07b685ef6ccd3c9dc3697e7baab49712 Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Tue, 2 Feb 2016 15:16:06 +0100 Subject: Add VPP to bridge domain. 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 --- vbd/api/src/main/yang/vbridge-topology.yang | 2 + vbd/impl/pom.xml | 6 +++ .../io/fd/honeycomb/vbd/impl/BridgeDomain.java | 61 ++++++++++++++++++++-- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/vbd/api/src/main/yang/vbridge-topology.yang b/vbd/api/src/main/yang/vbridge-topology.yang index f105b5e41..901907387 100644 --- a/vbd/api/src/main/yang/vbridge-topology.yang +++ b/vbd/api/src/main/yang/vbridge-topology.yang @@ -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"; diff --git a/vbd/impl/pom.xml b/vbd/impl/pom.xml index d4ac30d62..6f966b8c8 100644 --- a/vbd/impl/pom.xml +++ b/vbd/impl/pom.xml @@ -51,6 +51,12 @@ vbd-api + + io.fd.honeycomb.v3po + v3po-api + 1.0.0-SNAPSHOT + + junit diff --git a/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java index 9cea6589f..e7652aa32 100644 --- a/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java +++ b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java @@ -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 { private static final Logger LOG = LoggerFactory.getLogger(BridgeDomain.class); private final KeyedInstanceIdentifier 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 iiBridgeDomainOnVPP; private BridgeDomain(final DataBroker dataBroker, final MountPointService mountService, final KeyedInstanceIdentifier topology, final BindingTransactionChain chain) { @@ -51,6 +65,11 @@ final class BridgeDomain implements DataTreeChangeListener { 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 { LOG.debug("Topology {} modified child {}", topology, child); if (Node.class.isAssignableFrom(child.getDataType())) { - modifyNode((DataObjectModification) child); + modifyNode((DataObjectModification) child, newConfig.getDataAfter()); } } @@ -136,7 +155,7 @@ final class BridgeDomain implements DataTreeChangeListener { } } - private void modifyNode(final DataObjectModification child) { + private void modifyNode(final DataObjectModification 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 { 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 { } } + 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 iiToMount = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, new TopologyKey(topologyMount)) + .child(Node.class, new NodeKey(nodeMount)); + final Optional vppMountOption = mountService.getMountPoint(iiToMount); + if (vppMountOption.isPresent()) { + final MountPoint vppMount = vppMountOption.get(); + addVppToBridgeDomain(topologyVbridgeAugment, vppMount); + } + } + } + + private void addVppToBridgeDomain(TopologyVbridgeAugment topologyVbridgeAugment, MountPoint vppMount) { + final Optional 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); -- cgit 1.2.3-korg