<bundle>mvn:org.opendaylight.ovsdb/utils.neutron-utils/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.ovsdb/utils.mdsal-utils/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.ovsdb/utils.southbound-utils/{{VERSION}}</bundle>
-
<bundle>mvn:org.opendaylight.ovsdb/openstack.net-virt/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.ovsdb/openstack.net-virt-providers/{{VERSION}}</bundle>
<bundle>mvn:commons-net/commons-net/{{VERSION}}</bundle>
<feature version="${dlux.version}">odl-dlux-core</feature>
<bundle>mvn:org.opendaylight.ovsdb/ovsdb-ui-bundle/{{VERSION}}</bundle>
</feature>
+
<feature name='odl-netvirt-api' version='${project.version}' description='OpenDaylight :: netvirt :: api'>
<feature version='${mdsal.model.version}'>odl-mdsal-models</feature>
<bundle>mvn:org.opendaylight.ovsdb/netvirt-api/{{VERSION}}</bundle>
</feature>
+
<feature name='odl-netvirt-rest' version='${project.version}' description='OpenDaylight :: netvirt :: REST'>
<feature version="${project.version}">odl-netvirt-api</feature>
<feature version="${restconf.version}">odl-restconf</feature>
</feature>
+
<feature name='odl-netvirt-ui' version='${project.version}' description='OpenDaylight :: netvirt :: UI'>
<feature version="${project.version}">odl-netvirt-rest</feature>
<feature version="${restconf.version}">odl-mdsal-apidocs</feature>
<feature version="${controller.mdsal.version}">odl-mdsal-xsql</feature>
</feature>
+
<feature name='odl-netvirt-hwgw' version='${project.version}' description='OpenDaylight :: netvirt :: Hardware Gateway'>
<feature version="${project.version}">odl-netvirt-api</feature>
<feature version='${project.version}'>odl-ovsdb-hwvtepsouthbound</feature>
<bundle>mvn:org.opendaylight.ovsdb/hwgw/{{VERSION}}</bundle>
<configfile finalname="etc/opendaylight/karaf/hwgw-default-config.xml">mvn:org.opendaylight.ovsdb/hwgw/{{VERSION}}/xml/config</configfile>
</feature>
+
<feature name='odl-netvirt-neutron' version='${project.version}' description='OpenDaylight :: netvirt :: Neutron Renderer'>
<feature version="${neutron.version}">odl-neutron-service</feature>
<feature version="${project.version}">odl-netvirt-ui</feature>
<configfile finalname="etc/opendaylight/karaf/netvirt-neutron-default-config.xml">mvn:org.opendaylight.ovsdb/neutron/{{VERSION}}/xml/config</configfile>
</feature>
+ <feature name='odl-netvirt-it' version='${project.version}' description='OpenDaylight :: netvirt :: IT'>
+ <feature version='${controller.mdsal.version}'>odl-mdsal-broker</feature>
+ <feature version="${neutron.version}">odl-neutron-service</feature>
+ <feature version="${project.version}">odl-netvirt-neutron</feature>
+ <feature version="${project.version}">odl-ovsdb-southbound-api</feature>
+ <bundle>mvn:org.opendaylight.ovsdb/utils.it-utils/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.ovsdb/utils.mdsal-utils/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.ovsdb/utils.neutron-utils/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.ovsdb/utils.servicehelper/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.ovsdb/utils.southbound-utils/{{VERSION}}</bundle>
+ </feature>
</features>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright © 2016 Red Hat, 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
+-->
+
+<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>org.opendaylight.ovsdb</groupId>
+ <artifactId>it</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <relativePath>../../commons/it</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>netvirt-it</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <controller.mdsal.version>1.4.0-SNAPSHOT</controller.mdsal.version>
+ <karaf.distro.groupId>org.opendaylight.ovsdb</karaf.distro.groupId>
+ <karaf.distro.artifactId>karaf</karaf.distro.artifactId>
+ <karaf.distro.version>${project.version}</karaf.distro.version>
+ <karaf.distro.type>zip</karaf.distro.type>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-common-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>features-ovsdb</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>southbound-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>utils.it-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>utils.mdsal-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>utils.neutron-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>utils.southbound-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar-plugins.java</groupId>
+ <artifactId>sonar-jacoco-listeners</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <!--<excludes>
+ <exclude>**/NetvirtIT.java</exclude>
+ </excludes>-->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
--- /dev/null
+/*
+ * Copyright © 2016 Red Hat, 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 org.opendaylight.ovsdb.netvirt.it;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperties;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
+import org.opendaylight.ovsdb.utils.it.utils.ItConstants;
+import org.opendaylight.ovsdb.utils.it.utils.ItUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
+import org.opendaylight.ovsdb.utils.neutron.utils.NeutronModelsDataStoreHelper;
+import org.opendaylight.ovsdb.utils.neutron.utils.NeutronUtils;
+import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption;
+import org.ops4j.pax.exam.options.MavenUrlReference;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class NetvirtIT extends AbstractMdsalTestBase {
+ private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
+ private static final String FEATURE = "odl-netvirt-it";
+ private static DataBroker dataBroker = null;
+ private static ItUtils itUtils;
+ private static String addressStr;
+ private static String portStr;
+ private static String connectionType;
+ private static String controllerStr;
+ private static AtomicBoolean setup = new AtomicBoolean(false);
+ private static MdsalUtils mdsalUtils = null;
+ private static SouthboundUtils southboundUtils;
+ private static NeutronUtils neutronUtils = new NeutronUtils();
+ private static NeutronModelsDataStoreHelper neutronModelsDataStoreHelper;
+
+ @Override
+ public String getModuleName() {
+ return "netvirt-neutron";
+ }
+
+ @Override
+ public String getInstanceName() {
+ return "netvirt-neutron-default";
+ }
+
+ @Override
+ public MavenUrlReference getFeatureRepo() {
+ return maven()
+ .groupId("org.opendaylight.ovsdb")
+ .artifactId("features-ovsdb")
+ .classifier("features")
+ .type("xml")
+ .versionAsInProject();
+ }
+
+ @Override
+ public String getFeatureName() {
+ return FEATURE;
+ }
+
+ @Configuration
+ @Override
+ public Option[] config() {
+ Option[] parentOptions = super.config();
+ Option[] propertiesOptions = getPropertiesOptions();
+ Option[] otherOptions = getOtherOptions();
+ Option[] options = new Option[parentOptions.length + propertiesOptions.length + otherOptions.length];
+ System.arraycopy(parentOptions, 0, options, 0, parentOptions.length);
+ System.arraycopy(propertiesOptions, 0, options, parentOptions.length, propertiesOptions.length);
+ System.arraycopy(otherOptions, 0, options, parentOptions.length + propertiesOptions.length,
+ otherOptions.length);
+ return options;
+ }
+
+ private Option[] getOtherOptions() {
+ return new Option[] {
+ wrappedBundle(
+ mavenBundle("org.opendaylight.ovsdb", "utils.mdsal-openflow")
+ .version(asInProject())
+ .type("jar")),
+ configureConsole().startLocalConsole(),
+ //vmOption("-verbose:class"),
+ vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
+ keepRuntimeFolder()
+ };
+ }
+
+ private Option[] getPropertiesOptions() {
+ return new Option[] {
+ propagateSystemProperties(ItConstants.SERVER_IPADDRESS, ItConstants.SERVER_PORT,
+ ItConstants.CONNECTION_TYPE, ItConstants.CONTROLLER_IPADDRESS,
+ ItConstants.USERSPACE_ENABLED),
+ };
+ }
+
+ @Override
+ public Option getLoggingOption() {
+ return composite(
+ editConfigurationFilePut(ItConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+ "log4j.logger.org.opendaylight.ovsdb",
+ LogLevelOption.LogLevel.TRACE.name()),
+ editConfigurationFilePut(ItConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+ logConfiguration(NetvirtIT.class),
+ LogLevelOption.LogLevel.INFO.name()),
+ editConfigurationFilePut(ItConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+ "log4j.logger.org.opendaylight.neutron",
+ LogLevelOption.LogLevel.TRACE.name()),
+ super.getLoggingOption());
+ }
+
+ protected String usage() {
+ return "Integration Test needs a valid connection configuration as follows :\n"
+ + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
+ + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
+ }
+
+ private void getProperties() {
+ Properties props = System.getProperties();
+ addressStr = props.getProperty(ItConstants.SERVER_IPADDRESS);
+ portStr = props.getProperty(ItConstants.SERVER_PORT, ItConstants.DEFAULT_SERVER_PORT);
+ connectionType = props.getProperty(ItConstants.CONNECTION_TYPE, "active");
+ controllerStr = props.getProperty(ItConstants.CONTROLLER_IPADDRESS, "0.0.0.0");
+ String userSpaceEnabled = props.getProperty(ItConstants.USERSPACE_ENABLED, "no");
+ LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}, " +
+ "userspace.enabled: {}",
+ connectionType, addressStr, portStr, controllerStr, userSpaceEnabled);
+ if (connectionType.equalsIgnoreCase(ItConstants.CONNECTION_TYPE_ACTIVE)) {
+ if (addressStr == null) {
+ fail(usage());
+ }
+ }
+ }
+
+ @After
+ public void teardown() {
+ closeWaitFors();
+ }
+
+ @Before
+ @Override
+ public void setup() throws InterruptedException {
+ if (setup.get()) {
+ LOG.info("Skipping setUp, already initialized");
+ return;
+ }
+
+ try {
+ super.setup();
+ } catch (Exception e) {
+ LOG.warn("Failed to setup test", e);
+ fail("Failed to setup test: " + e);
+ }
+
+ getProperties();
+
+ if (connectionType.equalsIgnoreCase(ItConstants.CONNECTION_TYPE_ACTIVE)) {
+ if (addressStr == null) {
+ fail(usage());
+ }
+ }
+
+ dataBroker = ItUtils.getDatabroker(getProviderContext());
+ itUtils = new ItUtils(dataBroker);
+ mdsalUtils = new MdsalUtils(dataBroker);
+ assertNotNull("mdsalUtils should not be null", mdsalUtils);
+ // TODO: Not used yet since openstack is not running to write the netvirt:1 to mdsal
+ // Only need neutron northbound right now
+ //assertTrue("Did not find " + ItConstants.NETVIRT_TOPOLOGY_ID, itUtils.getNetvirtTopology());
+ southboundUtils = new SouthboundUtils(mdsalUtils);
+ neutronModelsDataStoreHelper = new NeutronModelsDataStoreHelper(dataBroker);
+ setup.set(true);
+ }
+
+ private BindingAwareBroker.ProviderContext getProviderContext() {
+ BindingAwareBroker.ProviderContext providerContext = null;
+ for (int i=0; i < 60; i++) {
+ providerContext = getSession();
+ if (providerContext != null) {
+ break;
+ } else {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for provider context", e);
+ }
+ }
+ }
+ assertNotNull("providercontext should not be null", providerContext);
+ /* One more second to let the provider finish initialization */
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for other provider", e);
+ }
+ return providerContext;
+ }
+
+ @Test
+ public void testNetvirtFeatureLoad() {
+ assertTrue("Feature " + FEATURE + " was not loaded", true);
+ }
+
+ private List<NotifyingDataChangeListener> waitList = new ArrayList<>();
+ private void closeWaitFors() {
+ for (Iterator<NotifyingDataChangeListener> iterator = waitList.iterator(); iterator.hasNext();) {
+ NotifyingDataChangeListener listener = iterator.next();
+ iterator.remove();
+ try {
+ listener.close();
+ } catch (Exception ex) {
+ LOG.warn("Failed to close registration {}", listener, ex);
+ }
+ }
+ LOG.info("waitList size {}", waitList.size());
+ }
+
+ @Test
+ public void testNetvirtNeutron() throws InterruptedException {
+ final String networkId = "521e29d6-67b8-4b3c-8633-027d21195111";
+ final String tenantId = "521e29d6-67b8-4b3c-8633-027d21195100";
+
+ InstanceIdentifier<Network> path = neutronModelsDataStoreHelper.getNeutronNetworkPath(new Uuid(networkId));
+ final NotifyingDataChangeListener networkOperationalListener =
+ new NotifyingDataChangeListener(LogicalDatastoreType.CONFIGURATION, path, waitList);
+ networkOperationalListener.registerDataChangeListener(dataBroker);
+
+ NeutronNetwork nn = neutronUtils.createNeutronNetwork(networkId, tenantId,
+ NetworkHandler.NETWORK_TYPE_VXLAN, "100");
+
+ networkOperationalListener.waitForCreation();
+
+ Network network = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path);
+ assertNotNull("the network was not found in mdsal", network);
+ }
+}
import org.opendaylight.neutron.spi.NeutronSubnet;
import org.opendaylight.ovsdb.lib.notation.Version;
import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
-import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
import org.opendaylight.ovsdb.openstack.netvirt.providers.NetvirtProvidersProvider;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
-import org.opendaylight.ovsdb.utils.it.ItUtils;
-import org.opendaylight.ovsdb.utils.it.NodeInfo;
+import org.opendaylight.ovsdb.utils.it.utils.ItUtils;
+import org.opendaylight.ovsdb.utils.it.utils.NodeInfo;
import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
import org.opendaylight.ovsdb.openstack.netvirt.sfc.it.utils.NetvirtSfcUtils;
import org.opendaylight.ovsdb.openstack.netvirt.sfc.workaround.services.FlowNames;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
-import org.opendaylight.ovsdb.utils.it.ItUtils;
+import org.opendaylight.ovsdb.utils.it.utils.ItUtils;
import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
-import org.opendaylight.ovsdb.utils.it.NodeInfo;
+import org.opendaylight.ovsdb.utils.it.utils.NodeInfo;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
import org.opendaylight.sfc.provider.api.SfcProviderRenderedPathAPI;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.RspName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.sffs.SffBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev150105.Sfc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev150105.SfcBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (C) 2016 Red Hat, 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
+-->
<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">
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.ovsdb</groupId>
- <artifactId>openstack.net-virt</artifactId>
- <version>${project.version}</version>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-inet-types</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.ovsdb</groupId>
- <artifactId>utils.servicehelper</artifactId>
- <version>${project.version}</version>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-topology</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<scope>compile</scope>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>
- org.opendaylight.ovsdb.utils.it
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
</project>
--- /dev/null
+/*
+ * Copyright (c) 2015 Red Hat, 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 org.opendaylight.ovsdb.utils.it.utils;
+
+/**
+ * Constants for SouthboundIT
+ */
+public final class ItConstants {
+ private ItConstants() {
+ throw new AssertionError("This class should not be instantiated.");
+ }
+
+ public static final String ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
+ public static final String CUSTOM_PROPERTIES = "etc/custom.properties";
+ public static final String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
+ public static final String SERVER_PORT = "ovsdbserver.port";
+ public static final String CONTROLLER_IPADDRESS = "ovsdb.controller.address";
+ public static final String USERSPACE_ENABLED = "ovsdb.userspace.enabled";
+ public static final String SERVER_EXTRAS = "ovsdbserver.extras";
+ public static final String CONNECTION_TYPE = "ovsdbserver.connection";
+ public static final String CONNECTION_TYPE_ACTIVE = "active";
+ public static final String CONNECTION_TYPE_PASSIVE = "passive";
+ public static final int CONNECTION_INIT_TIMEOUT = 10000;
+ public static final String DEFAULT_SERVER_IPADDRESS = "127.0.0.1";
+ public static final String DEFAULT_SERVER_PORT = "6640";
+ public static final String DEFAULT_OPENFLOW_PORT = "6653";
+ public static final String DEFAULT_SERVER_EXTRAS = "false";
+ public static final String BRIDGE_NAME = "brtest";
+ public static final String PORT_NAME = "porttest";
+ public static final String INTEGRATION_BRIDGE_NAME = "br-int";
+ public static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
+ public static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.ovsdb.utils.it;
+package org.opendaylight.ovsdb.utils.it.utils;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.List;
-
-import org.junit.Assert;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
-import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
-import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+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.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.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
*/
public class ItUtils {
private static final Logger LOG = LoggerFactory.getLogger(ItUtils.class);
-
MdsalUtils mdsalUtils;
SouthboundUtils southboundUtils;
DataBroker dataBroker;
- Southbound southbound;
/**
* Create a new ItUtils instance
this.dataBroker = dataBroker;
mdsalUtils = new MdsalUtils(dataBroker);
southboundUtils = new SouthboundUtils(mdsalUtils);
- southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
}
/**
Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
assertNotNull("ovsdb node not found", ovsdbNode);
- BridgeConfigurationManager bridgeConfigurationManager =
- (BridgeConfigurationManager) ServiceHelper.getGlobalInstance(BridgeConfigurationManager.class, this);
- assertNotNull("Could not find BridgeConfigurationManager Service", bridgeConfigurationManager);
- String controllerTarget = bridgeConfigurationManager.getControllersFromOvsdbNode(ovsdbNode).get(0);
- Assert.assertNotNull("Failed to get controller target", controllerTarget);
+ String controllerTarget = southboundUtils.getControllersFromOvsdbNode(ovsdbNode).get(0);
+ assertNotNull("Failed to get controller target", controllerTarget);
for (int i = 0; i < 10; i++) {
LOG.info("isControllerConnected try {}: looking for controller: {}", i, controllerTarget);
southboundUtils.getBridge(connectionInfo, "br-int");
if (bridge != null && bridge.getControllerEntry() != null) {
controllerEntry = bridge.getControllerEntry().iterator().next();
- Assert.assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
+ assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
if (controllerEntry.isIsConnected()) {
LOG.info("isControllerConnected exit: true {}", controllerTarget);
return true;
LOG.info("isControllerConnected exit: false {}", controllerTarget);
return false;
}
+
+ public static DataBroker getDatabroker(BindingAwareBroker.ProviderContext providerContext) {
+ DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
+ assertNotNull("dataBroker should not be null", dataBroker);
+ return dataBroker;
+ }
+
+ public Boolean getNetvirtTopology() {
+ LOG.info("getNetvirtTopology: looking for {}...", ItConstants.NETVIRT_TOPOLOGY_ID);
+ Boolean found = false;
+ final TopologyId topologyId = new TopologyId(new Uri(ItConstants.NETVIRT_TOPOLOGY_ID));
+ InstanceIdentifier<Topology> path =
+ InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
+ for (int i = 0; i < 60; i++) {
+ Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
+ if (topology != null) {
+ LOG.info("getNetvirtTopology: found {}...", ItConstants.NETVIRT_TOPOLOGY_ID);
+ found = true;
+ break;
+ } else {
+ LOG.info("getNetvirtTopology: still looking (try {})...", i);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for {}", ItConstants.NETVIRT_TOPOLOGY_ID, e);
+ }
+ }
+ }
+ return found;
+ }
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.ovsdb.utils.it;
+package org.opendaylight.ovsdb.utils.it.utils;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.List;
-
-import org.junit.Assert;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
bridgeWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, bridgeIid, waitList);
bridgeWaiter.registerDataChangeListener(itUtils.dataBroker);
- Assert.assertNotNull("connection failed", itUtils.southboundUtils.addOvsdbNode(connectionInfo, 0));
+ assertNotNull("connection failed", itUtils.southboundUtils.addOvsdbNode(connectionInfo, 0));
ovsdbWaiter.waitForCreation();
ovsdbNode = itUtils.southboundUtils.getOvsdbNode(connectionInfo);
- Assert.assertNotNull("node is not connected", ovsdbNode);
+ assertNotNull("node is not connected", ovsdbNode);
bridgeWaiter.waitForCreation();
- Assert.assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
+ assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
+ " is not connected", itUtils.isControllerConnected(connectionInfo));
- bridgeNode = itUtils.southbound.getBridgeNode(ovsdbNode, INTEGRATION_BRIDGE_NAME);
- Assert.assertNotNull("bridge " + INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
- datapathId = itUtils.southbound.getDataPathId(bridgeNode);
- String datapathIdString = itUtils.southbound.getDatapathId(bridgeNode);
+ bridgeNode = itUtils.southboundUtils.getBridgeNode(ovsdbNode, INTEGRATION_BRIDGE_NAME);
+ assertNotNull("bridge " + INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
+ datapathId = itUtils.southboundUtils.getDataPathId(bridgeNode);
+ String datapathIdString = itUtils.southboundUtils.getDatapathId(bridgeNode);
LOG.info("testNetVirt: bridgeNode: {}, datapathId: {} - {}", bridgeNode, datapathIdString, datapathId);
- Assert.assertNotEquals("datapathId was not found", datapathId, 0);
+ assertNotEquals("datapathId was not found", datapathId, 0);
}
/**
* @throws InterruptedException
*/
public void disconnect() throws InterruptedException {
- Assert.assertTrue(itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0));
+ assertTrue(itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0));
itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0);
bridgeWaiter.waitForDeletion();
Node bridgeNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
- Assert.assertNull("Bridge should not be found", bridgeNode);
- Assert.assertTrue(itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0));
+ assertNull("Bridge should not be found", bridgeNode);
+ assertTrue(itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0));
itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0);
ovsdbWaiter.waitForDeletion();
Node ovsdbNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbIid);
- Assert.assertNull("Ovsdb node should not be found", ovsdbNode);
+ assertNull("Ovsdb node should not be found", ovsdbNode);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright © 2015 Red Hat, 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
- -->
+Copyright (C) 2015 Red Hat, 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
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<version>1.3.0-SNAPSHOT</version>
<packaging>bundle</packaging>
+ <properties>
+ <neutron.version>0.7.0-SNAPSHOT</neutron.version>
+ </properties>
+
<dependencies>
<!-- project specific dependencies -->
<dependency>
<artifactId>utils.mdsal-utils</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>utils.servicehelper</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- neutron dependencies -->
<dependency>
<groupId>org.opendaylight.neutron</groupId>
<artifactId>model</artifactId>
<version>0.7.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.neutron</groupId>
+ <artifactId>neutron-spi</artifactId>
+ <version>${neutron.version}</version>
+ </dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
return mdsalPort;
}
- private InstanceIdentifier<Routers> getNeutrounRoutersPath() {
+ public InstanceIdentifier<Routers> getNeutrounRoutersPath() {
return InstanceIdentifier
.create(Neutron.class)
.child(Routers.class);
}
- private InstanceIdentifier<Ports> getNeutrounPortsPath() {
+ public InstanceIdentifier<Ports> getNeutrounPortsPath() {
return InstanceIdentifier
.create(Neutron.class)
.child(Ports.class);
}
- private InstanceIdentifier<Port> getNeutronPortPath(Uuid portId) {
+ public InstanceIdentifier<Port> getNeutronPortPath(Uuid portId) {
return InstanceIdentifier
.create(Neutron.class)
.child(Ports.class)
.child(Port.class,new PortKey(portId));
}
+
+ public InstanceIdentifier<Network> getNeutronNetworkPath(Uuid networkId) {
+ return InstanceIdentifier
+ .create(Neutron.class)
+ .child(Networks.class)
+ .child(Network.class,new NetworkKey(networkId));
+ }
}
--- /dev/null
+/*
+ * Copyright © 2016 Red Hat, 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 org.opendaylight.ovsdb.utils.neutron.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
+import org.opendaylight.neutron.spi.INeutronPortCRUD;
+import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
+import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.neutron.spi.NeutronPort;
+import org.opendaylight.neutron.spi.NeutronSecurityGroup;
+import org.opendaylight.neutron.spi.NeutronSubnet;
+import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
+
+public class NeutronUtils {
+ public NeutronPort createNeutronPort(String networkId, String subnetId,
+ String id, String owner, String ipaddr, String mac) {
+ INeutronPortCRUD iNeutronPortCRUD =
+ (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
+ NeutronPort np = new NeutronPort();
+ np.initDefaults();
+ np.setID(id);
+ np.setDeviceOwner(owner);
+ np.setMacAddress(mac);
+ np.setNetworkUUID(networkId);
+ List<org.opendaylight.neutron.spi.Neutron_IPs> srcAddressList =
+ new ArrayList<>();
+ org.opendaylight.neutron.spi.Neutron_IPs nip = new org.opendaylight.neutron.spi.Neutron_IPs();
+ nip.setIpAddress(ipaddr);
+ nip.setSubnetUUID(subnetId);
+ srcAddressList.add(nip);
+ np.setFixedIPs(srcAddressList);
+ List<NeutronSecurityGroup> nsgs = new ArrayList<>();
+ np.setSecurityGroups(nsgs);
+ iNeutronPortCRUD.add(np);
+ return np;
+ }
+
+ public NeutronSubnet createNeutronSubnet(String subnetId, String tenantId,
+ String networkId, String cidr) {
+ INeutronSubnetCRUD iNeutronSubnetCRUD =
+ (INeutronSubnetCRUD) ServiceHelper.getGlobalInstance(INeutronSubnetCRUD.class, this);
+ NeutronSubnet ns = new NeutronSubnet();
+ ns.setID(subnetId);
+ ns.setCidr(cidr);
+ ns.initDefaults();
+ ns.setNetworkUUID(networkId);
+ ns.setTenantID(tenantId);
+ iNeutronSubnetCRUD.add(ns);
+ return ns;
+ }
+
+ public NeutronNetwork createNeutronNetwork(String uuid, String tenantID, String networkTypeVxlan, String segId) {
+ INeutronNetworkCRUD iNeutronNetworkCRUD =
+ (INeutronNetworkCRUD) ServiceHelper.getGlobalInstance(INeutronNetworkCRUD.class, this);
+ NeutronNetwork nn = new NeutronNetwork();
+ nn.setID(uuid);
+ nn.initDefaults();
+ nn.setTenantID(tenantID);
+ nn.setProviderNetworkType(networkTypeVxlan);
+ nn.setProviderSegmentationID(segId);
+ iNeutronNetworkCRUD.addNetwork(nn);
+ return nn;
+ }
+}
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>southbound-impl</artifactId>
+ <artifactId>utils.mdsal-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>utils.mdsal-utils</artifactId>
+ <artifactId>utils.config</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-inet-types</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-topology</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>
\ No newline at end of file
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Embed-Dependency>utils.config;type=!pom;inline=false</Embed-Dependency>
+ <Embed-Transitive>true</Embed-Transitive>
+ <Export-Package>
+ org.opendaylight.ovsdb.utils.southbound.utils
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
package org.opendaylight.ovsdb.utils.southbound.utils;
import com.google.common.collect.ImmutableBiMap;
+import java.math.BigInteger;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
import java.net.InetAddress;
+import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.ovsdb.southbound.SouthboundConstants;
-import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.utils.config.ConfigProperties;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
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.ControllerEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIdsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIdsKey;
private static final int OVSDB_UPDATE_TIMEOUT = 1000;
public static final TopologyId OVSDB_TOPOLOGY_ID = new TopologyId(new Uri("ovsdb:1"));
private final MdsalUtils mdsalUtils;
+ public static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
+ public static short OPENFLOW_PORT = 6653;
+ public static final String OVSDB_URI_PREFIX = "ovsdb";
+ public static final String BRIDGE_URI_PREFIX = "bridge";
public SouthboundUtils(MdsalUtils mdsalUtils) {
this.mdsalUtils = mdsalUtils;
.put("dpdkvhostuser", InterfaceTypeDpdkvhostuser.class)
.build();
+ public static final ImmutableBiMap<Class<? extends OvsdbBridgeProtocolBase>,String> OVSDB_PROTOCOL_MAP
+ = new ImmutableBiMap.Builder<Class<? extends OvsdbBridgeProtocolBase>,String>()
+ .put(OvsdbBridgeProtocolOpenflow10.class,"OpenFlow10")
+ .put(OvsdbBridgeProtocolOpenflow11.class,"OpenFlow11")
+ .put(OvsdbBridgeProtocolOpenflow12.class,"OpenFlow12")
+ .put(OvsdbBridgeProtocolOpenflow13.class,"OpenFlow13")
+ .put(OvsdbBridgeProtocolOpenflow14.class,"OpenFlow14")
+ .put(OvsdbBridgeProtocolOpenflow15.class,"OpenFlow15")
+ .build();
+
public static NodeId createNodeId(IpAddress ip, PortNumber port) {
- String uriString = SouthboundConstants.OVSDB_URI_PREFIX + "://"
+ String uriString = OVSDB_URI_PREFIX + "://"
+ String.valueOf(ip.getValue()) + ":" + port.getValue();
Uri uri = new Uri(uriString);
return new NodeId(uri);
return ovsdbNodeBuilder.build();
}
+ public static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
+ return InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID))
+ .child(Node.class,new NodeKey(nodeId));
+ }
+
+ public static InstanceIdentifier<Node> createInstanceIdentifier(NodeKey ovsdbNodeKey, String bridgeName) {
+ return createInstanceIdentifier(createManagedNodeId(ovsdbNodeKey.getNodeId(), bridgeName));
+ }
+
+ public static NodeId createManagedNodeId(NodeId ovsdbNodeId, String bridgeName) {
+ return new NodeId(ovsdbNodeId.getValue()
+ + "/" + BRIDGE_URI_PREFIX + "/" + bridgeName);
+ }
+
public static InstanceIdentifier<Node> createInstanceIdentifier(ConnectionInfo key) {
return createInstanceIdentifier(key.getRemoteIp(), key.getRemotePort());
}
public static InstanceIdentifier<Node> createInstanceIdentifier(IpAddress ip, PortNumber port) {
InstanceIdentifier<Node> path = InstanceIdentifier
.create(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
+ .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID))
.child(Node.class,createNodeKey(ip,port));
LOG.debug("Created ovsdb path: {}",path);
return path;
}
public static InstanceIdentifier<Node> createInstanceIdentifier(ConnectionInfo key,OvsdbBridgeName bridgeName) {
- return SouthboundMapper.createInstanceIdentifier(createManagedNodeId(key, bridgeName));
+ return createInstanceIdentifier(createManagedNodeId(key, bridgeName));
}
public static InstanceIdentifier<Node> createInstanceIdentifier(ConnectionInfo key, String bridgeName) {
public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) {
return new NodeId(createNodeId(ip,port).getValue()
- + "/" + SouthboundConstants.BRIDGE_URI_PREFIX + "/" + bridgeName.getValue());
+ + "/" + BRIDGE_URI_PREFIX + "/" + bridgeName.getValue());
}
public static NodeId createManagedNodeId(InstanceIdentifier<Node> iid) {
return nodeKey.getNodeId();
}
+ public ConnectionInfo getConnectionInfo(Node ovsdbNode) {
+ ConnectionInfo connectionInfo = null;
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(ovsdbNode);
+ if (ovsdbNodeAugmentation != null) {
+ connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
+ }
+ return connectionInfo;
+ }
+
+ public OvsdbNodeAugmentation extractOvsdbNode(Node node) {
+ return node.getAugmentation(OvsdbNodeAugmentation.class);
+ }
+
+ public static IpAddress createIpAddress(InetAddress address) {
+ IpAddress ip = null;
+ if (address instanceof Inet4Address) {
+ ip = createIpAddress((Inet4Address)address);
+ } else if (address instanceof Inet6Address) {
+ ip = createIpAddress((Inet6Address)address);
+ }
+ return ip;
+ }
+
+ public static IpAddress createIpAddress(Inet4Address address) {
+ return IetfInetUtil.INSTANCE.ipAddressFor(address);
+ }
+
+ public static IpAddress createIpAddress(Inet6Address address) {
+ Ipv6Address ipv6 = new Ipv6Address(address.getHostAddress());
+ return new IpAddress(ipv6);
+ }
+
public static ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
InetAddress inetAddress = null;
try {
LOG.warn("Could not allocate InetAddress", e);
}
- IpAddress address = SouthboundMapper.createIpAddress(inetAddress);
+ IpAddress address = createIpAddress(inetAddress);
PortNumber port = new PortNumber(Integer.parseInt(portStr));
LOG.info("connectionInfo: {}", new ConnectionInfoBuilder()
return mdsalUtils.read(store, bridgeIid);
}
+ public Node getBridgeNode(Node node, String bridgeName) {
+ OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
+ if (bridge != null && bridge.getBridgeName().getValue().equals(bridgeName)) {
+ return node;
+ } else {
+ return readBridgeNode(node, bridgeName);
+ }
+ }
+
+ public Node readBridgeNode(Node node, String name) {
+ Node ovsdbNode = node;
+ if (extractNodeAugmentation(ovsdbNode) == null) {
+ ovsdbNode = readOvsdbNode(node);
+ if (ovsdbNode == null) {
+ return null;
+ }
+ }
+ Node bridgeNode = null;
+ ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
+ if (connectionInfo != null) {
+ InstanceIdentifier<Node> bridgeIid =
+ createInstanceIdentifier(node.getKey(), name);
+ bridgeNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
+ }
+ return bridgeNode;
+ }
+
+ public OvsdbNodeAugmentation extractNodeAugmentation(Node node) {
+ return node.getAugmentation(OvsdbNodeAugmentation.class);
+ }
+
+ public OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
+ if (node == null) {
+ return null;
+ }
+ return node.getAugmentation(OvsdbBridgeAugmentation.class);
+ }
+
+ public Node readOvsdbNode(Node bridgeNode) {
+ Node ovsdbNode = null;
+ OvsdbBridgeAugmentation bridgeAugmentation = extractBridgeAugmentation(bridgeNode);
+ if (bridgeAugmentation != null) {
+ InstanceIdentifier<Node> ovsdbNodeIid =
+ (InstanceIdentifier<Node>) bridgeAugmentation.getManagedBy().getValue();
+ ovsdbNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbNodeIid);
+ }else{
+ LOG.debug("readOvsdbNode: Provided node is not a bridge node : {}",bridgeNode);
+ }
+ return ovsdbNode;
+ }
+
public boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName) {
return deleteBridge(connectionInfo, bridgeName, OVSDB_UPDATE_TIMEOUT);
}
public List<ProtocolEntry> createMdsalProtocols() {
List<ProtocolEntry> protocolList = new ArrayList<>();
ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
- SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
+ OVSDB_PROTOCOL_MAP.inverse();
protocolList.add(new ProtocolEntryBuilder().setProtocol(mapper.get("OpenFlow13")).build());
return protocolList;
}
bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
}
if (bridgeNodeId == null) {
- bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
+ bridgeNodeId = createManagedNodeId(bridgeIid);
}
bridgeNodeBuilder.setNodeId(bridgeNodeId);
OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
public Boolean addTerminationPoint(Node bridgeNode, String portName, String type) {
return addTerminationPoint(bridgeNode, portName, type, null, null);
}
+
+ private String getControllerIPAddress() {
+ String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
+ if (addressString != null) {
+ try {
+ if (InetAddress.getByName(addressString) != null) {
+ return addressString;
+ }
+ } catch (UnknownHostException e) {
+ LOG.error("Host {} is invalid", addressString, e);
+ }
+ }
+
+ addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
+ if (addressString != null) {
+ try {
+ if (InetAddress.getByName(addressString) != null) {
+ return addressString;
+ }
+ } catch (UnknownHostException e) {
+ LOG.error("Host {} is invalid", addressString, e);
+ }
+ }
+
+ return null;
+ }
+
+ private short getControllerOFPort() {
+ short openFlowPort = OPENFLOW_PORT;
+ String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort");
+ if (portString != null) {
+ try {
+ openFlowPort = Short.parseShort(portString);
+ } catch (NumberFormatException e) {
+ LOG.warn("Invalid port:{}, use default({})", portString,
+ openFlowPort, e);
+ }
+ }
+ return openFlowPort;
+ }
+
+ public List<String> getControllersFromOvsdbNode(Node node) {
+ List<String> controllersStr = new ArrayList<>();
+
+ String controllerIpStr = getControllerIPAddress();
+ if (controllerIpStr != null) {
+ // If codepath makes it here, the ip address to be used was explicitly provided.
+ // Being so, also fetch openflowPort provided via ConfigProperties.
+ controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL
+ + ":" + controllerIpStr + ":" + getControllerOFPort());
+ } else {
+ // Check if ovsdb node has manager entries
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(node);
+ if (ovsdbNodeAugmentation != null) {
+ List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
+ if (managerEntries != null && !managerEntries.isEmpty()) {
+ for (ManagerEntry managerEntry : managerEntries) {
+ if (managerEntry == null || managerEntry.getTarget() == null) {
+ continue;
+ }
+ String[] tokens = managerEntry.getTarget().getValue().split(":");
+ if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
+ controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL
+ + ":" + tokens[1] + ":" + getControllerOFPort());
+ } else if (tokens[0].equalsIgnoreCase("ptcp")) {
+ ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
+ if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
+ controllerIpStr = String.valueOf(connectionInfo.getLocalIp().getValue());
+ controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL
+ + ":" + controllerIpStr + ":" + OPENFLOW_PORT);
+ } else {
+ LOG.warn("Ovsdb Node does not contain connection info: {}", node);
+ }
+ } else {
+ LOG.trace("Skipping manager entry {} for node {}",
+ managerEntry.getTarget(), node.getNodeId().getValue());
+ }
+ }
+ } else {
+ LOG.warn("Ovsdb Node does not contain manager entries : {}", node);
+ }
+ }
+ }
+
+ if (controllersStr.isEmpty()) {
+ // Neither user provided ip nor ovsdb node has manager entries. Lets use local machine ip address.
+ LOG.debug("Use local machine ip address as a OpenFlow Controller ip address");
+ controllerIpStr = getLocalControllerHostIpAddress();
+ if (controllerIpStr != null) {
+ controllersStr.add(OPENFLOW_CONNECTION_PROTOCOL
+ + ":" + controllerIpStr + ":" + OPENFLOW_PORT);
+ }
+ }
+
+ if (controllersStr.isEmpty()) {
+ LOG.warn("Failed to determine OpenFlow controller ip address");
+ } else if (LOG.isDebugEnabled()) {
+ controllerIpStr = "";
+ for (String currControllerIpStr : controllersStr) {
+ controllerIpStr += " " + currControllerIpStr;
+ }
+ LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
+ }
+
+ return controllersStr;
+ }
+
+ private String getLocalControllerHostIpAddress() {
+ String ipaddress = null;
+ try{
+ for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements();){
+ NetworkInterface iface = ifaces.nextElement();
+
+ for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
+ InetAddress inetAddr = inetAddrs.nextElement();
+ if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
+ ipaddress = inetAddr.getHostAddress();
+ break;
+ }
+ }
+ }
+ }catch (Exception e){
+ LOG.warn("Exception while fetching local host ip address ", e);
+ }
+ return ipaddress;
+ }
+
+ public long getDataPathId(Node node) {
+ long dpid = 0L;
+ String datapathId = getDatapathId(node);
+ if (datapathId != null) {
+ dpid = new BigInteger(datapathId.replaceAll(":", ""), 16).longValue();
+ }
+ return dpid;
+ }
+
+ public String getDatapathId(Node node) {
+ OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
+ return getDatapathId(ovsdbBridgeAugmentation);
+ }
+
+ public String getDatapathId(OvsdbBridgeAugmentation ovsdbBridgeAugmentation) {
+ String datapathId = null;
+ if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
+ datapathId = ovsdbBridgeAugmentation.getDatapathId().getValue();
+ }
+ return datapathId;
+ }
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-import static org.junit.Assert.assertTrue;
+package org.opendaylight.ovsdb.utils.southbound.utils;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class SouthboundUtilsTest {