From 3ee450a938e9a98c46fab07955f7f34e84c0cba9 Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Thu, 4 Feb 2016 10:34:38 +0100 Subject: Adding automatic creation of tunnel. Initial code for adding code for interconnecting of virtual bridge domain (via tunnel) which is spread on several VPPs. Change-Id: I0da88c977e820b0b8edc565d261d3d8fb0629a1a Signed-off-by: Jozef Gloncak --- .../io/fd/honeycomb/vbd/impl/BridgeDomain.java | 60 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'vbd/impl/src/main') 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 82558684f..1bbac451a 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 @@ -16,6 +16,7 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import java.util.Collection; +import java.util.Map; import javax.annotation.concurrent.GuardedBy; import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; import org.opendaylight.controller.md.sal.binding.api.DataBroker; @@ -26,10 +27,13 @@ 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.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; 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.external.reference.rev160129.ExternalReference; @@ -81,7 +85,7 @@ final class BridgeDomain implements DataTreeChangeListener { private final InstanceIdentifier iiBridgeDomainOnVPP; private final String iiBridgeDomainOnVPPRest; private final DataBroker dataBroker; - private Multimap> nodesToVpps = ArrayListMultimap.create(); + private Multimap> nodesToVpps = ArrayListMultimap.create(); private BridgeDomain(final DataBroker dataBroker, final MountPointService mountService, final KeyedInstanceIdentifier topology, final BindingTransactionChain chain) { @@ -204,7 +208,13 @@ final class BridgeDomain implements DataTreeChangeListener { break; case WRITE: LOG.debug("Topology {} node {} created", topology, nodeMod.getIdentifier()); - createNode(nodeMod.getDataAfter()); + final int numberVppsBeforeAddition = nodesToVpps.keySet().size(); + final Node newNode = nodeMod.getDataAfter(); + createNode(newNode); + final int numberVppsAfterAddition = nodesToVpps.keySet().size(); + if ((numberVppsBeforeAddition < numberVppsAfterAddition) && (numberVppsBeforeAddition >= 1)) { + addTunnel(newNode.getNodeId()); + } break; default: LOG.warn("Unhandled node modification {} in topology {}", nodeMod, topology); @@ -212,11 +222,55 @@ final class BridgeDomain implements DataTreeChangeListener { } } + private void addTunnel(final NodeId newNode) { + for (Map.Entry> entryToVpp : nodesToVpps.entries()) { + if (!entryToVpp.getKey().equals(newNode)) { + createTunnelEndPoint(entryToVpp.getValue()); + createTunnelEndPoint(nodesToVpps.get(newNode)); + } + + + } + } + + private void createTunnelEndPoint(Collection> keyedInstanceIdentifiers) { + for (KeyedInstanceIdentifier iiToVpp : keyedInstanceIdentifiers) { + createTunnelEndPoint(iiToVpp); + } + } + + private void createTunnelEndPoint(final KeyedInstanceIdentifier iiToVpp) { + final DataBroker vppDataBroker = resolveDataBrokerForMountPoint(iiToVpp); + final ReadOnlyTransaction rTx = vppDataBroker.newReadOnlyTransaction(); + + final CheckedFuture, ReadFailedException> interfaceStateFuture + = rTx.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class)); + Futures.addCallback(interfaceStateFuture, new FutureCallback>() { + @Override + public void onSuccess(Optional optInterfacesState) { + if (optInterfacesState.isPresent()) { + for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface intf : optInterfacesState.get().getInterface()) { + //TODO find interface with IP address set + } + } + + } + + @Override + public void onFailure(Throwable t) { + + } + }); + + + } + + private void modifyTerminationPoint(final DataObjectModification nodeChild, final NodeId nodeId) { final TerminationPoint terminationPoint = nodeChild.getDataAfter(); final TerminationPointVbridgeAugment termPointVbridgeAug = terminationPoint.getAugmentation(TerminationPointVbridgeAugment.class); if (termPointVbridgeAug != null) { - final Collection> instanceIdentifiersVPP = nodesToVpps.get(nodeId); + final Collection> instanceIdentifiersVPP = nodesToVpps.get(nodeId); //TODO: probably iterate via all instance identifiers. if (!instanceIdentifiersVPP.isEmpty()) { final DataBroker dataBroker = resolveDataBrokerForMountPoint(instanceIdentifiersVPP.iterator().next()); -- cgit 1.2.3-korg