diff options
author | Robert Varga <nite@hq.sk> | 2016-01-30 15:25:19 +0100 |
---|---|---|
committer | Robert Varga <nite@hq.sk> | 2016-01-31 18:21:24 +0100 |
commit | 42887f769a3ac57963110925a1c2965c2b25bac6 (patch) | |
tree | 4d5f47c3ad19767c99964dc5a8c80391e9242c99 /vbd/impl | |
parent | cb22508bc344123078a1caea7d39da49583f0ab0 (diff) |
Add Virtual Bridge Domain implementation
Change-Id: I427b709ac0af1ade365bc60148ddf778f7be458a
Signed-off-by: Robert Varga <nite@hq.sk>
Diffstat (limited to 'vbd/impl')
-rw-r--r-- | vbd/impl/pom.xml | 63 | ||||
-rw-r--r-- | vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java | 169 | ||||
-rw-r--r-- | vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/TopologyMonitor.java | 159 | ||||
-rw-r--r-- | vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/VirtualBridgeDomainManager.java | 65 | ||||
-rw-r--r-- | vbd/impl/vbridge-workflow.txt | 106 |
5 files changed, 562 insertions, 0 deletions
diff --git a/vbd/impl/pom.xml b/vbd/impl/pom.xml new file mode 100644 index 000000000..3d6d55aea --- /dev/null +++ b/vbd/impl/pom.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- vi: set et smarttab sw=4 tabstop=4: --> +<!-- + Copyright (c) 2015 Cisco and/or its affiliates. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>io.fd.honeycomb.common</groupId> + <artifactId>impl-parent</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>../../common/impl-parent</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>io.fd.honeycomb.vbd</groupId> + <artifactId>vbd-impl</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>bundle</packaging> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>io.fd.honeycomb.vbd</groupId> + <artifactId>vbd-artifacts</artifactId> + <version>1.0.0-SNAPSHOT</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vbd-api</artifactId> + </dependency> + + <!-- Testing Dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> 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 new file mode 100644 index 000000000..aff03b2a6 --- /dev/null +++ b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/BridgeDomain.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package io.fd.honeycomb.vbd.impl; + +import com.google.common.base.Preconditions; +import java.util.Collection; +import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; +import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; +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.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.Topology1; +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.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Implementation of a single Virtual Bridge Domain. It is bound to a particular network topology instance, manages + * bridge members and projects state into the operational data store. + */ +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 Topology1 config; + + private BridgeDomain(final DataBroker dataBroker, final KeyedInstanceIdentifier<Topology, TopologyKey> topology, + final BindingTransactionChain chain) { + this.topology = Preconditions.checkNotNull(topology); + this.chain = Preconditions.checkNotNull(chain); + + reg = dataBroker.registerDataTreeChangeListener( + new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, topology), this); + } + + static BridgeDomain create(final DataBroker dataBroker, + final KeyedInstanceIdentifier<Topology, TopologyKey> topology, final BindingTransactionChain chain) { + + LOG.debug("Wiping operational state of {}", topology); + + final WriteTransaction tx = chain.newWriteOnlyTransaction(); + tx.delete(LogicalDatastoreType.OPERATIONAL, topology); + tx.submit(); + + return new BridgeDomain(dataBroker, topology, chain); + } + + synchronized void forceStop() { + LOG.info("Bridge domain {} for {} going down", this, topology); + reg.close(); + chain.close(); + LOG.info("Bridge domain {} for {} is down", this, topology); + } + + synchronized void stop() { + LOG.debug("Bridge domain {} for {} shutting down", this, topology); + + final WriteTransaction tx = chain.newWriteOnlyTransaction(); + tx.delete(LogicalDatastoreType.OPERATIONAL, topology); + tx.submit(); + chain.close(); + } + + @Override + public synchronized void onDataTreeChanged(final Collection<DataTreeModification<Topology>> changes) { + for (DataTreeModification<Topology> c : changes) { + LOG.debug("Domain {} for {} processing change {}", this, topology, c); + + final DataObjectModification<Topology> mod = c.getRootNode(); + switch (mod.getModificationType()) { + case DELETE: + LOG.debug("Topology {} deleted, expecting shutdown", topology); + break; + case SUBTREE_MODIFIED: + // First check if the configuration has changed + final DataObjectModification<Topology1> newConfig = mod.getModifiedAugmentation(Topology1.class); + if (newConfig != null) { + if (newConfig.getModificationType() != ModificationType.DELETE) { + LOG.debug("Topology {} modified configuration {}", topology, newConfig); + updateConfiguration(newConfig); + } else { + // FIXME: okay, what can we do about this one? + LOG.error("Topology {} configuration deleted, good luck!", topology); + } + } + + for (DataObjectModification<? extends DataObject> child : mod.getModifiedChildren()) { + LOG.debug("Topology {} modified child {}", topology, child); + + if (Node.class.isAssignableFrom(child.getDataType())) { + modifyNode((DataObjectModification<Node>) child); + } + } + + break; + case WRITE: + final Topology data = mod.getDataAfter(); + + // Read configuration + final Topology1 config = data.getAugmentation(Topology1.class); + if (config != null) { + setConfiguration(config); + } else { + LOG.error("Topology {} has no configuration, good luck!", topology); + } + + // FIXME: deal with nodes + + break; + default: + LOG.warn("Unhandled topology modification {}", mod); + break; + } + } + } + + private void modifyNode(final DataObjectModification<Node> child) { + switch (child.getModificationType()) { + case DELETE: + LOG.debug("Topology {} node {} deleted", topology, child.getIdentifier()); + // FIXME: do something + break; + case SUBTREE_MODIFIED: + LOG.debug("Topology {} node {} modified", topology, child.getIdentifier()); + // FIXME: do something + break; + case WRITE: + LOG.debug("Topology {} node {} created", topology, child.getIdentifier()); + // FIXME: do something + break; + default: + LOG.warn("Unhandled node modification {} in topology {}", child, topology); + break; + } + } + + private void setConfiguration(final Topology1 config) { + LOG.debug("Topology {} configuration set to {}", topology, config); + + this.config = config; + } + + @GuardedBy("this") + private void updateConfiguration(final DataObjectModification<Topology1> mod) { + LOG.debug("Topology {} configuration changed", topology); + + // FIXME: do something smarter + setConfiguration(mod.getDataAfter()); + } +} diff --git a/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/TopologyMonitor.java b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/TopologyMonitor.java new file mode 100644 index 000000000..b2e52c37e --- /dev/null +++ b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/TopologyMonitor.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package io.fd.honeycomb.vbd.impl; + +import com.google.common.base.Preconditions; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; +import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.network.topology.topology.topology.types.VbridgeTopology; +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.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class responsible for monitoring /network-topology/topology and activating a {@link BridgeDomain} when a particular + * topology is marked as a bridge domain. + */ +final class TopologyMonitor implements DataTreeChangeListener<VbridgeTopology>, AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(TopologyMonitor.class); + + @GuardedBy("this") + private final Map<TopologyKey, BridgeDomain> domains = new HashMap<>(); + private final DataBroker dataBroker; + + TopologyMonitor(final DataBroker dataBroker) { + this.dataBroker = Preconditions.checkNotNull(dataBroker); + } + + @Override + public synchronized void onDataTreeChanged(final Collection<DataTreeModification<VbridgeTopology>> changes) { + for (DataTreeModification<VbridgeTopology> c : changes) { + @SuppressWarnings("unchecked") + final KeyedInstanceIdentifier<Topology, TopologyKey> topology = + (KeyedInstanceIdentifier<Topology, TopologyKey>) c.getRootPath().getRootIdentifier() + .firstIdentifierOf(Topology.class); + + Preconditions.checkArgument(!topology.isWildcarded(), "Wildcard topology %s is not supported", topology); + + final DataObjectModification<VbridgeTopology> mod = c.getRootNode(); + switch (mod.getModificationType()) { + case DELETE: + LOG.debug("Topology {} removed", topology); + stopDomain(topology); + break; + case WRITE: + LOG.debug("Topology {} added", topology); + startDomain(topology); + break; + default: + LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType()); + break; + } + } + } + + private synchronized void completeDomain(final KeyedInstanceIdentifier<Topology, TopologyKey> topology) { + LOG.debug("Bridge domain for {} completed operation", topology); + domains.remove(topology); + + synchronized (domains) { + domains.notify(); + } + } + + private synchronized void restartDomain(final KeyedInstanceIdentifier<Topology, TopologyKey> topology) { + final BridgeDomain prev = domains.remove(topology); + if (prev == null) { + LOG.warn("No domain for {}, not restarting", topology); + return; + } + + prev.forceStop(); + startDomain(topology); + } + + @GuardedBy("this") + private void startDomain(final KeyedInstanceIdentifier<Topology, TopologyKey> topology) { + final BridgeDomain prev = domains.get(topology.getKey()); + if (prev != null) { + LOG.warn("Bridge domain {} for {} already started", prev, topology); + return; + } + + LOG.debug("Starting bridge domain for {}", topology); + + final BindingTransactionChain chain = dataBroker.createTransactionChain(new TransactionChainListener() { + @Override + public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) { + completeDomain(topology); + } + + @Override + public void onTransactionChainFailed(final TransactionChain<?, ?> chain, + final AsyncTransaction<?, ?> transaction, final Throwable cause) { + LOG.warn("Bridge domain for {} failed, restarting it", cause); + restartDomain(topology); + } + }); + + final BridgeDomain domain = BridgeDomain.create(dataBroker, topology, chain); + domains.put(topology.getKey(), domain); + + LOG.debug("Bridge domain {} for {} started", domain, topology); + } + + @GuardedBy("this") + private void stopDomain(final KeyedInstanceIdentifier<Topology, TopologyKey> topology) { + final BridgeDomain domain = domains.remove(topology.getKey()); + if (domain == null) { + LOG.warn("Bridge domain for {} not present", topology); + return; + } + + domain.stop(); + } + + @Override + public synchronized void close() { + LOG.debug("Topology monitor {} shut down started", this); + + for (Entry<TopologyKey, BridgeDomain> e : domains.entrySet()) { + LOG.debug("Shutting down bridge domain {} (key {})", e.getValue(), e.getKey()); + e.getValue().stop(); + } + + while (!domains.isEmpty()) { + LOG.debug("Waiting for domains for {} to complete", domains.keySet()); + synchronized (domains) { + try { + domains.wait(); + } catch (InterruptedException e) { + LOG.warn("Interrupted while waiting for domain shutdown, {} have not completed yet", + domains.keySet(), e); + break; + } + } + } + + LOG.debug("Topology monitor {} shut down completed", this); + } +} diff --git a/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/VirtualBridgeDomainManager.java b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/VirtualBridgeDomainManager.java new file mode 100644 index 000000000..37da73159 --- /dev/null +++ b/vbd/impl/src/main/java/io/fd/honeycomb/vbd/impl/VirtualBridgeDomainManager.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package io.fd.honeycomb.vbd.impl; + +import com.google.common.base.Preconditions; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyTypes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.network.topology.topology.topology.types.VbridgeTopology; +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.network.topology.Topology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tip for the Virtual Bridge Domain implementation. This class is instantiated when the application is started + * and {@link #close()}d when it is shut down. + */ +public final class VirtualBridgeDomainManager implements AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(VirtualBridgeDomainManager.class); + private static final DataTreeIdentifier<VbridgeTopology> LISTEN_TREE = + new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, + InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class).child(TopologyTypes.class) + .augmentation(TopologyTypes1.class).child(VbridgeTopology.class).build()); + + private final ListenerRegistration<TopologyMonitor> reg; + private boolean closed; + + private VirtualBridgeDomainManager(final ListenerRegistration<TopologyMonitor> reg) { + this.reg = Preconditions.checkNotNull(reg); + } + + public static VirtualBridgeDomainManager create(@Nonnull final DataBroker dataBroker) { + final ListenerRegistration<TopologyMonitor> reg = + dataBroker.registerDataTreeChangeListener(LISTEN_TREE, new TopologyMonitor(dataBroker)); + + return new VirtualBridgeDomainManager(reg); + } + + @Override + public void close() { + if (!closed) { + LOG.debug("Virtual Bridge Domain manager shut down started"); + + final TopologyMonitor monitor = reg.getInstance(); + reg.close(); + LOG.debug("Topology monitor {} unregistered", monitor); + monitor.close(); + + closed = true; + LOG.debug("Virtual Bridge Domain manager shut down completed"); + } + } +} diff --git a/vbd/impl/vbridge-workflow.txt b/vbd/impl/vbridge-workflow.txt new file mode 100644 index 000000000..86ba544f4 --- /dev/null +++ b/vbd/impl/vbridge-workflow.txt @@ -0,0 +1,106 @@ +VPP Inventory/Topology +---------------------- + +- VPP management done through netconf-node-topology +- Mount point management done by sal-netconf-connector + + +Virtual Bridge Domain management +-------------------------------- + +Prerequisite: configured netconf-node-topology + +1) Create a Virtual Bridge Domain: + + A) The UI creates a network topology instance in Controller Data Store + with: + + - topology-types/vbridge-topology container + - tunnel-type set to tunnel-type-vxlan + - tunnel-parameters/vxlan/vni set to appropriate value + - any bridge domain parameters from v3po:bridge-domain-attributes + + B) The Controller App receives a DataTreeChangeNotification about the + topology instance being created + +2) Assign a VPP into a Virtual Bridge Domain + Prerequisite: Virtual Bridge Domain exists + + A) The UI creates a 'node' within the VBD network topology in the + Controller Data Store with: + + - bridge-member container + - supporting-node pointing to the VPP node in the + netconf-node-topology + + B) The Controller App receives a DataTreeChangeNotification about the + node being added, and: + + - it looks at the supporting-node in the netconf topology and if the + node is connected: + - it creates a bridge domain with the name matching this VBD name, + copying bridge domain parameters from VBD Topology configuration + into the VPP + - once that succeeds it creates the corresponding + supporting-bridge-domain leaf in the Controller's operational + datastore. The leaf contains a RESTCONF-encoded instance + identifier of the bridge domain created in the VPP, relative to + that VPP's mount point. + +3) Assigning a physical VPP interface into a Virtual Bridge Domain + Prerequisite: The VPP itself has been added to the Virtual Bridge + Domain + + A) The UI creates a 'termination-point' inside the 'node' added in 2), + with: + + - user-interface, containing RESTCONF-encoded instance identifier + of the VPP interface, relative to that VPP's mount point in config + data store. + + B) The Controller App receives a notification of this being done and: + - looks if the VPP is connected, if it is, the app will: + - add the interface into the VPP's bridge domain configuration + +Inverse operations are achieved by the UI deleting the corresponding nodes in +the Controller's configuration data store. + + +Virtual Bridge Domain tunnel management +--------------------------------------- + +Operation is triggered by adding more than one VPP into the virtual bridge +domain, for sake of clarity this describes only one-way tunnel setup. The +process is repeated until a full mesh is achieved (FUTURE: spanning tree?). +The process is also simplified for demo purposes, real-world deployment would +deal with day-1 configuration and multi-provider setups. + +Demo assumption: there is exactly one interface with a VRF and IP address +assined, which is the interface to be used for tunnels + +The Controller App looks at the Source VPP: +- it finds the only interface with VRF and IP addresses. It will use this VRF + as the vxlan tunnel VRF. It will use the IP address as the vxlan tunnel + source. + +The Controller App looks at the Destination VPP: +- it finds the only interface with VRF and IP addresses. It will use the IP + address as the vxlan tunnel destination. + +The Controller App sets up the tunnel on the source VPP, using the VNI +configured for this Virtual Bridge Domain and IP addresses as detailed above. + +The controller app creates a new termination point within the VBD's the +controller's operational data store, under the +node representing the source VPP, with a generated ID (mechanism is TBD, must +not conflict with VPP names) and 'tunnel-interface' leaf, which points to the +vxlan interface created on the source VPP (e.g. VPP config state). + +This process is repeated in the reverse direction. + +Once that is done, the controller app will create a link from the newly-created +source TP to the newly-created destination TP in the controller's operational +data store, with leaf 'tunnel' pointing to the source VPP's interface operation +state (e.g. VPP vxlan oper state). A reverse link will be created, with the +'tunnel' leaf pointing to the destination VPP's interface state. + |