/*
- * Copyright (c) 2015 Red Hat, Inc. and others. All rights reserved.
+ * Copyright (c) 2015 - 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,
*/
package org.opendaylight.ovsdb.openstack.netvirt.it;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+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.when;
+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.features;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
-import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Lists;
-import com.google.common.collect.ObjectArrays;
+import com.google.common.collect.Maps;
-import java.io.File;
-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 java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.inject.Inject;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
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.INeutronPortCRUD;
+import org.opendaylight.neutron.spi.INeutronSecurityGroupCRUD;
+import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
+import org.opendaylight.neutron.spi.NeutronPort;
+import org.opendaylight.neutron.spi.NeutronSecurityGroup;
+import org.opendaylight.neutron.spi.NeutronSecurityRule;
+import org.opendaylight.neutron.spi.NeutronNetwork;
+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.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.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.PortNumber;
+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.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.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.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.InterfaceTypeEntryBuilder;
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.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+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.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
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.KarafDistributionOption;
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.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ExamReactorStrategy(PerClass.class)
public class NetvirtIT extends AbstractMdsalTestBase {
private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
- private static final int OVSDB_UPDATE_TIMEOUT = 1000;
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 Southbound southbound = null;
- private static final String NETVIRT = "org.opendaylight.ovsdb.openstack.net-virt";
- private static final String NETVIRTPROVIDERS = "org.opendaylight.ovsdb.openstack.net-virt-providers";
-
- // TODO Constants copied frmo AbstractConfigTestBase, need to be removed (see TODO below)
- private static final String PAX_EXAM_UNPACK_DIRECTORY = "target/exam";
- private static final String KARAF_DEBUG_PORT = "5005";
- private static final String KARAF_DEBUG_PROP = "karaf.debug";
- private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack";
-
- @Inject
- private BundleContext bundleContext;
-
- @Configuration
- public Option[] config() {
- // TODO Figure out how to use the parent Karaf setup, then just use super.config()
- Option[] options = new Option[] {
- when(Boolean.getBoolean(KARAF_DEBUG_PROP))
- .useOptions(KarafDistributionOption.debugConfiguration(KARAF_DEBUG_PORT, true)),
- karafDistributionConfiguration().frameworkUrl(getKarafDistro())
- .unpackDirectory(new File(PAX_EXAM_UNPACK_DIRECTORY))
- .useDeployFolder(false),
- when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()),
- // Works only if we don't specify the feature repo and name
- getLoggingOption()};
- Option[] propertyOptions = getPropertiesOptions();
- Option[] otherOptions = getOtherOptions();
- Option[] combinedOptions = new Option[options.length + propertyOptions.length + otherOptions.length];
- System.arraycopy(options, 0, combinedOptions, 0, options.length);
- System.arraycopy(propertyOptions, 0, combinedOptions, options.length, propertyOptions.length);
- System.arraycopy(otherOptions, 0, combinedOptions, options.length + propertyOptions.length,
- otherOptions.length);
- return combinedOptions;
- }
-
- private Option[] getOtherOptions() {
- return new Option[] {
- vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
- keepRuntimeFolder()
- };
- }
-
- @Override
- public String getKarafDistro() {
- return maven()
- .groupId("org.opendaylight.ovsdb")
- .artifactId("karaf")
- .versionAsInProject()
- .type("zip")
- .getURL();
- }
+ private static PipelineOrchestrator pipelineOrchestrator = null;
+ private static SouthboundUtils southboundUtils;
+ private static NeutronUtils neutronUtils = new NeutronUtils();
+ private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
@Override
public String getModuleName() {
- return "openstack.net-virt-providers";
+ return "netvirt-providers-impl";
}
@Override
public String getInstanceName() {
- return "net-virt-providers-default";
+ return "netvirt-providers-default";
}
@Override
@Override
public String getFeatureName() {
- return "odl-ovsdb-openstack";
+ return "odl-ovsdb-openstack-it";
}
- 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";
+ @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")),
+ wrappedBundle(
+ mavenBundle("org.opendaylight.ovsdb", "utils.config")
+ .version(asInProject())
+ .type("jar")),
+ configureConsole().startLocalConsole(),
+ vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
+ keepRuntimeFolder()
+ };
+ }
+
+ public Option[] getPropertiesOptions() {
+ return new Option[] {
+ propagateSystemProperties(NetvirtITConstants.SERVER_IPADDRESS,
+ NetvirtITConstants.SERVER_PORT, NetvirtITConstants.CONNECTION_TYPE,
+ NetvirtITConstants.CONTROLLER_IPADDRESS,
+ NetvirtITConstants.USERSPACE_ENABLED)
+ };
}
@Override
public Option getLoggingOption() {
return composite(
+ //editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+ // "log4j.logger.org.opendaylight.controller",
+ // LogLevelOption.LogLevel.TRACE.name()),
editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
"log4j.logger.org.opendaylight.ovsdb",
- LogLevelOption.LogLevel.DEBUG.name()),
+ LogLevelOption.LogLevel.TRACE.name()),
+ editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
+ logConfiguration(NetvirtIT.class),
+ LogLevelOption.LogLevel.INFO.name()),
editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
"log4j.logger.org.opendaylight.ovsdb.lib",
LogLevelOption.LogLevel.INFO.name()),
+ editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+ "log4j.logger.org.opendaylight.openflowjava",
+ LogLevelOption.LogLevel.INFO.name()),
+ editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+ "log4j.logger.org.opendaylight.openflowplugin",
+ LogLevelOption.LogLevel.INFO.name()),
super.getLoggingOption());
- /*editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
- "log4j.logger.org.opendaylight.ovsdb.openstack.net-virt",
- LogLevelOption.LogLevel.DEBUG.name())*/
}
- private Option[] getPropertiesOptions() {
- Properties props = new Properties(System.getProperties());
- String addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS,
- NetvirtITConstants.DEFAULT_SERVER_IPADDRESS);
- String portStr = props.getProperty(NetvirtITConstants.SERVER_PORT,
- NetvirtITConstants.DEFAULT_SERVER_PORT);
- String connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE,
- NetvirtITConstants.CONNECTION_TYPE_ACTIVE);
-
- LOG.info("getPropertiesOptions: Using the following properties: mode= {}, ip:port= {}:{}",
- connectionType, addressStr, portStr);
-
- Option[] options = new Option[] {
- editConfigurationFilePut(NetvirtITConstants.CUSTOM_PROPERTIES,
- NetvirtITConstants.SERVER_IPADDRESS, addressStr),
- editConfigurationFilePut(NetvirtITConstants.CUSTOM_PROPERTIES,
- NetvirtITConstants.SERVER_PORT, portStr),
- editConfigurationFilePut(NetvirtITConstants.CUSTOM_PROPERTIES,
- NetvirtITConstants.CONNECTION_TYPE, connectionType),
- };
- return options;
+ 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(NetvirtITConstants.SERVER_IPADDRESS);
+ portStr = props.getProperty(NetvirtITConstants.SERVER_PORT, NetvirtITConstants.DEFAULT_SERVER_PORT);
+ connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE, "active");
+ controllerStr = props.getProperty(NetvirtITConstants.CONTROLLER_IPADDRESS, "0.0.0.0");
+ String userSpaceEnabled = props.getProperty(NetvirtITConstants.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(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
+ if (addressStr == null) {
+ fail(usage());
+ }
+ }
}
@Before
try {
super.setup();
} catch (Exception e) {
- e.printStackTrace();
+ LOG.warn("Failed to setup test", e);
+ fail("Failed to setup test: " + e);
}
- addressStr = bundleContext.getProperty(NetvirtITConstants.SERVER_IPADDRESS);
- portStr = bundleContext.getProperty(NetvirtITConstants.SERVER_PORT);
- connectionType = bundleContext.getProperty(NetvirtITConstants.CONNECTION_TYPE);
+ getProperties();
- LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}",
- connectionType, addressStr, portStr);
if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
if (addressStr == null) {
fail(usage());
}
}
- isBundleReady(bundleContext, NETVIRT);
- isBundleReady(bundleContext, NETVIRTPROVIDERS);
-
- //dataBroker = getSession().getSALService(DataBroker.class);
- //Thread.sleep(3000);
- //dataBroker = OvsdbInventoryServiceImpl.getDataBroker();
- for (int i=0; i<20; i++) {
- southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
- if (southbound != null) {
- dataBroker = southbound.getDatabroker();
- if (dataBroker != null) {
- break;
+ dataBroker = getDatabroker(getProviderContext());
+ itUtils = new ItUtils(dataBroker);
+ mdsalUtils = new MdsalUtils(dataBroker);
+ assertNotNull("mdsalUtils should not be null", mdsalUtils);
+ assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
+ southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
+ assertNotNull("southbound should not be null", southbound);
+ southboundUtils = new SouthboundUtils(mdsalUtils);
+ pipelineOrchestrator =
+ (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
+ assertNotNull("pipelineOrchestrator should not be null", pipelineOrchestrator);
+ 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);
}
}
- LOG.warn("NetvirtIT: dataBroker is null");
- Thread.sleep(5000);
}
- Assert.assertNotNull("dataBroker should not be null", dataBroker);
- Thread.sleep(5000);
-
- mdsalUtils = new MdsalUtils(dataBroker);
- setup.set(true);
+ 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;
+ }
+
+ private DataBroker getDatabroker(BindingAwareBroker.ProviderContext providerContext) {
+ DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
+ assertNotNull("dataBroker should not be null", dataBroker);
+ return dataBroker;
+ }
+
+ private Boolean getNetvirtTopology() {
+ LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
+ Boolean found = false;
+ final TopologyId topologyId = new TopologyId(new Uri(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 {}...", NETVIRT_TOPOLOGY_ID);
+ found = true;
+ break;
+ } else {
+ LOG.info("getNetvirtTopology: still looking ({})...", i);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for {}", NETVIRT_TOPOLOGY_ID, e);
+ }
+ }
+ }
+ return found;
}
/**
* Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
- * 6640. This test will wait for incoming connections for {@link NetvirtITConstants.CONNECTION_INIT_TIMEOUT} ms.
+ * 6640. This test will wait for incoming connections for {@link NetvirtITConstants#CONNECTION_INIT_TIMEOUT} ms.
*
* @throws InterruptedException
*/
+ @Ignore
@Test
public void testPassiveNode() throws InterruptedException {
if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_PASSIVE)) {
}
}
- private ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
- InetAddress inetAddress = null;
- try {
- inetAddress = InetAddress.getByName(addressStr);
- } catch (UnknownHostException e) {
- fail("Could not allocate InetAddress: " + e);
- }
-
- IpAddress address = SouthboundMapper.createIpAddress(inetAddress);
- PortNumber port = new PortNumber(Integer.parseInt(portStr));
-
- LOG.info("connectionInfo: {}", new ConnectionInfoBuilder()
- .setRemoteIp(address)
- .setRemotePort(port)
- .build());
- return new ConnectionInfoBuilder()
- .setRemoteIp(address)
- .setRemotePort(port)
- .build();
- }
-
- private String connectionInfoToString(final ConnectionInfo connectionInfo) {
- return new String(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
- }
-
- private boolean addOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
- SouthboundMapper.createInstanceIdentifier(connectionInfo),
- SouthboundMapper.createNode(connectionInfo));
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
- }
-
- private Node getOvsdbNode(final ConnectionInfo connectionInfo) {
- Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
- SouthboundMapper.createInstanceIdentifier(connectionInfo));
- return node;
- }
-
- private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
- SouthboundMapper.createInstanceIdentifier(connectionInfo));
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
- }
-
private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- Assert.assertTrue(addOvsdbNode(connectionInfo));
- Node node = getOvsdbNode(connectionInfo);
+ LOG.info("connectOvsdbNode enter");
+ Assert.assertTrue(southboundUtils.addOvsdbNode(connectionInfo));
+ Node node = southboundUtils.getOvsdbNode(connectionInfo);
Assert.assertNotNull("Should find OVSDB node after connect", node);
- LOG.info("Connected to {}", connectionInfoToString(connectionInfo));
+ LOG.info("Connected to {}", SouthboundUtils.connectionInfoToString(connectionInfo));
return node;
}
private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- Assert.assertTrue(deleteOvsdbNode(connectionInfo));
- Node node = getOvsdbNode(connectionInfo);
+ LOG.info("disconnectOvsdbNode enter");
+ Assert.assertTrue(southboundUtils.deleteOvsdbNode(connectionInfo));
+ Node node = southboundUtils.getOvsdbNode(connectionInfo);
Assert.assertNull("Should not find OVSDB node after disconnect", node);
- //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull
- LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo));
+ LOG.info("Disconnected from {}", SouthboundUtils.connectionInfoToString(connectionInfo));
return true;
}
- private String getLocalControllerHostIpAddress() {
- String ipaddress = null;
- try{
- for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
- ifaces.hasMoreElements();) {
- NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
-
- for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
- InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
- if (!inetAddr.isLoopbackAddress()) {
- if (inetAddr.isSiteLocalAddress()) {
- ipaddress = inetAddr.getHostAddress();
- break;
- }
- }
- }
- }
- }catch (Exception e){
- LOG.warn("Exception while fetching local host ip address ",e);
- }
- return ipaddress;
- }
-
- private String getControllerTarget(Node ovsdbNode) {
- String target = null;
- String ipAddr = null;
- OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
- ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
- LOG.info("connectionInfo: {}", connectionInfo);
- if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
- ipAddr = new String(connectionInfo.getLocalIp().getValue());
- }
- if (ipAddr == null) {
- ipAddr = getLocalControllerHostIpAddress();
- }
+ // This is an extra test for local testing and testNetVirt covers this is more detail
+ @Ignore
+ @Test
+ public void testAddDeleteOvsdbNode() throws InterruptedException {
+ LOG.info("testAddDeleteOvsdbNode enter");
+ ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
+ Node ovsdbNode = connectOvsdbNode(connectionInfo);
+ assertNotNull("connection failed", ovsdbNode);
+ LOG.info("testNetVirt: should be connected: {}", ovsdbNode.getNodeId());
- if (ipAddr != null) {
- target = NetvirtITConstants.OPENFLOW_CONNECTION_PROTOCOL + ":"
- + ipAddr + ":" + NetvirtITConstants.DEFAULT_OPENFLOW_PORT;
- }
+ assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
+ + " is not connected", itUtils.isControllerConnected(connectionInfo));
- return target;
+ Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
+ Thread.sleep(1000);
+ Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ LOG.info("testAddDeleteOvsdbNode exit");
}
- //@Ignore//
+ // TODO add tests for when L3 is enabled and check for br-ex
+
+ // This is an extra test for local testing and testNetVirt covers this is more detail
+ @Ignore
@Test
- public void testAddDeleteOvsdbNode() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
- ControllerEntry controllerEntry;
- for (int i = 0; i < 10; i++) {
- Node ovsdbNode = getOvsdbNode(connectionInfo);
- Assert.assertNotNull("ovsdb node not found", ovsdbNode);
- String controllerTarget = getControllerTarget(ovsdbNode);
- Assert.assertNotNull("Failed to get controller target", controllerTarget);
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
- Assert.assertNotNull(bridge);
- Assert.assertNotNull(bridge.getControllerEntry());
- controllerEntry = bridge.getControllerEntry().iterator().next();
- Assert.assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
- if (controllerEntry.isIsConnected()) {
- Assert.assertTrue(controllerEntry.isIsConnected());
- break;
+ public void testAddDeleteOvsdbNodeWithTableOffset() throws InterruptedException {
+ LOG.info("testAddDeleteOvsdbNodeWithTableOffset enter");
+ NetvirtProvidersProvider.setTableOffset((short)1);
+ ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
+ Node ovsdbNode = connectOvsdbNode(connectionInfo);
+ assertNotNull("connection failed", ovsdbNode);
+ LOG.info("testNetVirt: should be connected: {}", ovsdbNode.getNodeId());
+
+ assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
+ + " is not connected", itUtils.isControllerConnected(connectionInfo));
+
+ // Verify the pipeline flows were installed
+ Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
+ assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
+ long datapathId = southbound.getDataPathId(bridgeNode);
+ String datapathIdString = southbound.getDatapathId(bridgeNode);
+ LOG.info("testNetVirt: bridgeNode: {}, datapathId: {} - {}", bridgeNode, datapathIdString, datapathId);
+ assertNotEquals("datapathId was not found", datapathId, 0);
+
+ List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
+ List<Service> staticPipelineFound = Lists.newArrayList();
+ for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
+ if (staticPipeline.contains(service)) {
+ staticPipelineFound.add(service);
}
- Thread.sleep(1000);
+ String flowId = "DEFAULT_PIPELINE_FLOW_" + pipelineOrchestrator.getTable(service);
+ verifyFlow(datapathId, flowId, service);
}
+ assertEquals("did not find all expected flows in static pipeline",
+ staticPipeline.size(), staticPipelineFound.size());
+
+ String flowId = "TableOffset_" + pipelineOrchestrator.getTable(Service.CLASSIFIER);
+ verifyFlow(datapathId, flowId, Service.CLASSIFIER.getTable());
- Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
+ Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
Thread.sleep(1000);
Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ LOG.info("testAddDeleteOvsdbNodeWithTableOffset exit");
}
@Ignore
@Test
public void testOpenVSwitchOtherConfig() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
+ ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
Node ovsdbNode = connectOvsdbNode(connectionInfo);
OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
Assert.assertNotNull(ovsdbNodeAugmentation);
LOG.info("other_config is not present");
}
Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
}
- private void setManagedBy(final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
- final ConnectionInfo connectionInfo) {
- InstanceIdentifier<Node> connectionNodePath = SouthboundMapper.createInstanceIdentifier(connectionInfo);
- ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
- }
-
- private List<ProtocolEntry> createMdsalProtocols() {
- List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
- ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
- SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
- protocolList.add(new ProtocolEntryBuilder().
- setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build());
- return protocolList;
- }
-
- private OvsdbTerminationPointAugmentationBuilder createGenericOvsdbTerminationPointAugmentationBuilder() {
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder =
- new OvsdbTerminationPointAugmentationBuilder();
- ovsdbTerminationPointAugmentationBuilder.setInterfaceType(
- new InterfaceTypeEntryBuilder()
- .setInterfaceType(
- SouthboundMapper.createInterfaceType("internal"))
- .build().getInterfaceType());
- return ovsdbTerminationPointAugmentationBuilder;
- }
-
- private boolean addTerminationPoint(final NodeId bridgeNodeId, final String portName,
- final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder)
- throws InterruptedException {
-
- InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId);
- NodeBuilder portNodeBuilder = new NodeBuilder();
- NodeId portNodeId = SouthboundMapper.createManagedNodeId(portIid);
- portNodeBuilder.setNodeId(portNodeId);
- TerminationPointBuilder entry = new TerminationPointBuilder();
- entry.setKey(new TerminationPointKey(new TpId(portName)));
- entry.addAugmentation(
- OvsdbTerminationPointAugmentation.class,
- ovsdbTerminationPointAugmentationBuilder.build());
- portNodeBuilder.setTerminationPoint(Lists.newArrayList(entry.build()));
- boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
- portIid, portNodeBuilder.build());
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
- }
-
- /*
- * base method for adding test bridges. Other helper methods used to create bridges should utilize this method.
- *
- * @param connectionInfo
- * @param bridgeIid if passed null, one is created
- * @param bridgeName cannot be null
- * @param bridgeNodeId if passed null, one is created based on <code>bridgeIid</code>
- * @param setProtocolEntries toggles whether default protocol entries are set for the bridge
- * @param failMode toggles whether default fail mode is set for the bridge
- * @param setManagedBy toggles whether to setManagedBy for the bridge
- * @param dpType if passed null, this parameter is ignored
- * @param externalIds if passed null, this parameter is ignored
- * @param otherConfig if passed null, this parameter is ignored
- * @return success of bridge addition
+ /**
+ * Test for basic southbound events to netvirt.
+ * <pre>The test will:
+ * - connect to an OVSDB node and verify it is added to operational
+ * - then verify that br-int was created on the node and stored in operational
+ * - a port is then added to the bridge to verify that it is ignored by netvirt
+ * - remove the bridge
+ * - remove the node and verify it is not in operational
+ * </pre>
* @throws InterruptedException
*/
- private boolean addBridge(final ConnectionInfo connectionInfo, InstanceIdentifier<Node> bridgeIid,
- final String bridgeName, NodeId bridgeNodeId, final boolean setProtocolEntries,
- final Class<? extends OvsdbFailModeBase> failMode, final boolean setManagedBy,
- final Class<? extends DatapathTypeBase> dpType,
- final List<BridgeExternalIds> externalIds,
- final List<BridgeOtherConfigs> otherConfigs) throws InterruptedException {
-
- NodeBuilder bridgeNodeBuilder = new NodeBuilder();
- if (bridgeIid == null) {
- bridgeIid = SouthboundMapper.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
- }
- if (bridgeNodeId == null) {
- bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
- }
- bridgeNodeBuilder.setNodeId(bridgeNodeId);
- OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
- ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
- if (setProtocolEntries) {
- ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
- }
- if (failMode != null) {
- ovsdbBridgeAugmentationBuilder.setFailMode(failMode);
- }
- if (setManagedBy) {
- setManagedBy(ovsdbBridgeAugmentationBuilder, connectionInfo);
- }
- if (dpType != null) {
- ovsdbBridgeAugmentationBuilder.setDatapathType(dpType);
- }
- if (externalIds != null) {
- ovsdbBridgeAugmentationBuilder.setBridgeExternalIds(externalIds);
- }
- if (otherConfigs != null) {
- ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(otherConfigs);
+ @Test
+ public void testNetVirt() throws InterruptedException {
+ LOG.info("testNetVirt: starting test");
+ ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
+ NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
+ nodeInfo.connect();
+ LOG.info("testNetVirt: should be connected: {}", nodeInfo.ovsdbNode.getNodeId());
+
+ List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
+ List<Service> staticPipelineFound = Lists.newArrayList();
+ for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
+ if (staticPipeline.contains(service)) {
+ staticPipelineFound.add(service);
+ }
+ String flowId = "DEFAULT_PIPELINE_FLOW_" + pipelineOrchestrator.getTable(service);
+ verifyFlow(nodeInfo.datapathId, flowId, service);
}
- bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
- LOG.debug("Built with the intent to store bridge data {}",
- ovsdbBridgeAugmentationBuilder.toString());
- boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
- bridgeIid, bridgeNodeBuilder.build());
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
- }
+ assertEquals("did not find all expected flows in static pipeline",
+ staticPipeline.size(), staticPipelineFound.size());
- private boolean addBridge(final ConnectionInfo connectionInfo, final String bridgeName)
- throws InterruptedException {
+ southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, NetvirtITConstants.PORT_NAME, "internal", null, null, 0L);
+ Thread.sleep(1000);
+ OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
+ southbound.getTerminationPointOfBridge(nodeInfo.bridgeNode, NetvirtITConstants.PORT_NAME);
+ Assert.assertNotNull("Did not find " + NetvirtITConstants.PORT_NAME, ovsdbTerminationPointAugmentation);
- return addBridge(connectionInfo, null, bridgeName, null, true,
- SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null);
+ nodeInfo.disconnect();
}
- private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo) {
- return getBridge(connectionInfo, NetvirtITConstants.BRIDGE_NAME);
- }
+ @Test
+ public void testNetVirtFixedSG() throws InterruptedException {
+ final Version minSGOvsVersion = Version.fromString("1.10.2");
+ final String portName = "sg1";
+ final String networkId = "521e29d6-67b8-4b3c-8633-027d21195111";
+ final String tenantId = "521e29d6-67b8-4b3c-8633-027d21195100";
+ final String subnetId = "521e29d6-67b8-4b3c-8633-027d21195112";
+ final String portId = "521e29d6-67b8-4b3c-8633-027d21195113";
+ final String dhcpPortId ="521e29d6-67b8-4b3c-8633-027d21195115";
+
+ ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
+ NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
+ nodeInfo.connect();
+ LOG.info("testNetVirtFixedSG: should be connected: {}", nodeInfo.ovsdbNode.getNodeId());
+
+ // Verify the minimum version required for this test
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = nodeInfo.ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+ Assert.assertNotNull(ovsdbNodeAugmentation);
+ assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
+ String ovsVersion = ovsdbNodeAugmentation.getOvsVersion();
+ Version version = Version.fromString(ovsVersion);
+ if (version.compareTo(minSGOvsVersion) < 0) {
+ LOG.warn("{} minimum version is required", minSGOvsVersion);
+ Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo,
+ NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
+ Thread.sleep(1000);
+ Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ return;
+ }
- /**
- * Extract the <code>store</code> type data store contents for the particular bridge identified by
- * <code>bridgeName</code>.
- *
- * @param connectionInfo
- * @param bridgeName
- * @param store defined by the <code>LogicalDatastoreType</code> enumeration
- * @return <code>store</code> type data store contents
- */
- private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName,
- LogicalDatastoreType store) {
- Node bridgeNode = getBridgeNode(connectionInfo, bridgeName, store);
- Assert.assertNotNull(bridgeNode);
- OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
- Assert.assertNotNull(ovsdbBridgeAugmentation);
- return ovsdbBridgeAugmentation;
- }
+ NeutronNetwork nn = neutronUtils.createNeutronNetwork(networkId, tenantId,
+ NetworkHandler.NETWORK_TYPE_VXLAN, "100");
+ NeutronSubnet ns = neutronUtils.createNeutronSubnet(subnetId, tenantId, networkId, "10.0.0.0/24");
+ NeutronPort nport = neutronUtils.createNeutronPort(networkId, subnetId, portId,
+ "compute", "10.0.0.10", "f6:00:00:0f:00:01");
+ NeutronPort dhcp = neutronUtils.createNeutronPort(networkId, subnetId, dhcpPortId,
+ "dhcp", "10.0.0.1", "f6:00:00:0f:00:02");
- /**
- * extract the <code>LogicalDataStoreType.OPERATIONAL</code> type data store contents for the particular bridge
- * identified by <code>bridgeName</code>
- *
- * @param connectionInfo
- * @param bridgeName
- * @see <code>NetvirtIT.getBridge(ConnectionInfo, String, LogicalDatastoreType)</code>
- * @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
- */
- private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName) {
- return getBridge(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL);
- }
-
- /**
- * Extract the node contents from <code>store</code> type data store for the
- * bridge identified by <code>bridgeName</code>
- *
- * @param connectionInfo
- * @param bridgeName
- * @param store defined by the <code>LogicalDatastoreType</code> enumeration
- * @return <code>store</code> type data store contents
- */
- private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) {
- InstanceIdentifier<Node> bridgeIid =
- SouthboundMapper.createInstanceIdentifier(connectionInfo,
- new OvsdbBridgeName(bridgeName));
- return mdsalUtils.read(store, bridgeIid);
- }
+ Thread.sleep(1000);
+ Map<String, String> externalIds = Maps.newHashMap();
+ externalIds.put("attached-mac", "f6:00:00:0f:00:01");
+ externalIds.put("iface-id", portId);
+ southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, portName, "internal", null, externalIds, 3L);
+ southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vm1", "internal", null, null, 0L);
+ southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vm2", "internal", null, null, 0L);
+ Map<String, String> options = Maps.newHashMap();
+ options.put("key", "flow");
+ options.put("remote_ip", "192.168.120.32");
+ southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vx", "vxlan", options, null, 4L);
+ Thread.sleep(1000);
- /**
- * Extract the node contents from <code>LogicalDataStoreType.OPERATIONAL</code> data store for the
- * bridge identified by <code>bridgeName</code>
- *
- * @param connectionInfo
- * @param bridgeName
- * @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
- */
- private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName) {
- return getBridgeNode(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL);
- }
+ String flowId = "Egress_DHCP_Client" + "_Permit_";
+ verifyFlow(nodeInfo.datapathId, flowId, Service.EGRESS_ACL);
- private boolean deleteBridge(ConnectionInfo connectionInfo) throws InterruptedException {
- return deleteBridge(connectionInfo, NetvirtITConstants.BRIDGE_NAME);
- }
+ testDefaultSG(nport, nodeInfo.datapathId, nn, tenantId, portId);
+ Thread.sleep(1000);
- private boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName)
- throws InterruptedException {
+ nodeInfo.disconnect();
+ }
+
+ private void testDefaultSG(NeutronPort nport, long datapathId, NeutronNetwork nn, String tenantId, String portId)
+ throws InterruptedException {
+ INeutronSecurityGroupCRUD ineutronSecurityGroupCRUD =
+ (INeutronSecurityGroupCRUD) ServiceHelper.getGlobalInstance(INeutronSecurityGroupCRUD.class, this);
+ assertNotNull("Could not find ineutronSecurityGroupCRUD Service", ineutronSecurityGroupCRUD);
+ INeutronSecurityRuleCRUD ineutronSecurityRuleCRUD =
+ (INeutronSecurityRuleCRUD) ServiceHelper.getGlobalInstance(INeutronSecurityRuleCRUD.class, this);
+ assertNotNull("Could not find ineutronSecurityRuleCRUD Service", ineutronSecurityRuleCRUD);
+
+ NeutronSecurityGroup neutronSG = new NeutronSecurityGroup();
+ neutronSG.setSecurityGroupDescription("testig defaultSG-IT");
+ neutronSG.setSecurityGroupName("DefaultSG");
+ neutronSG.setSecurityGroupUUID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
+ neutronSG.setTenantID(tenantId);
+
+ List<NeutronSecurityRule> nsrs = new ArrayList<>();
+ NeutronSecurityRule nsrIN = new NeutronSecurityRule();
+ nsrIN.setSecurityRemoteGroupID(null);
+ nsrIN.setSecurityRuleDirection("ingress");
+ nsrIN.setSecurityRuleEthertype("IPv4");
+ nsrIN.setSecurityRuleGroupID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
+ nsrIN.setSecurityRuleProtocol("TCP");
+ nsrIN.setSecurityRuleRemoteIpPrefix("10.0.0.0/24");
+ nsrIN.setSecurityRuleUUID("823faaf7-175d-4f01-a271-0bf56fb1e7e6");
+ nsrIN.setTenantID(tenantId);
+
+ NeutronSecurityRule nsrEG = new NeutronSecurityRule();
+ nsrEG.setSecurityRemoteGroupID(null);
+ nsrEG.setSecurityRuleDirection("egress");
+ nsrEG.setSecurityRuleEthertype("IPv4");
+ nsrEG.setSecurityRuleGroupID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
+ nsrEG.setSecurityRuleProtocol("TCP");
+ nsrEG.setSecurityRuleRemoteIpPrefix("10.0.0.0/24");
+ nsrEG.setSecurityRuleUUID("823faaf7-175d-4f01-a271-0bf56fb1e7e1");
+ nsrEG.setTenantID(tenantId);
+
+ nsrs.add(nsrIN);
+ nsrs.add(nsrEG);
+
+ neutronSG.setSecurityRules(nsrs);
+ ineutronSecurityRuleCRUD.addNeutronSecurityRule(nsrIN);
+ ineutronSecurityRuleCRUD.addNeutronSecurityRule(nsrEG);
+ ineutronSecurityGroupCRUD.add(neutronSG);
+
+ List<NeutronSecurityGroup> sgs = new ArrayList<>();
+ sgs.add(neutronSG);
+ nport.setSecurityGroups(sgs);
+
+ INeutronPortCRUD iNeutronPortCRUD =
+ (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
+ iNeutronPortCRUD.update(portId, nport);
+
+ LOG.info("Neutron ports have been added");
+ Thread.sleep(10000);
+ String flowId = "Egress_IP" + nn.getProviderSegmentationID() + "_" + nport.getMacAddress() + "_Permit_";
+ verifyFlow(datapathId, flowId, Service.EGRESS_ACL);
- boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
- SouthboundMapper.createInstanceIdentifier(connectionInfo,
- new OvsdbBridgeName(bridgeName)));
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
+ flowId = "Ingress_IP" + nn.getProviderSegmentationID() + "_" + nport.getMacAddress() + "_Permit_";
+ verifyFlow(datapathId, flowId, Service.INGRESS_ACL);
}
- private InstanceIdentifier<Node> getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) {
- return SouthboundMapper.createInstanceIdentifier(connectionInfo,
- bridge.getBridgeName());
- }
+ private Flow getFlow (
+ FlowBuilder flowBuilder,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder,
+ LogicalDatastoreType store) throws InterruptedException {
- /**
- * isBundleReady is used to check if the requested bundle is Active
- */
- public void isBundleReady(BundleContext bundleContext, String bundleName) throws InterruptedException {
- boolean ready = false;
-
- while (!ready) {
- int state = Bundle.UNINSTALLED;
- Bundle[] bundles = bundleContext.getBundles();
- for (Bundle element : bundles) {
- if (element.getSymbolicName().equals(bundleName)) {
- state = element.getState();
- LOG.info(">>>>> bundle is ready {}", bundleName);
- break;
- }
- }
- if (state != Bundle.ACTIVE) {
- LOG.info(">>>>> bundle not ready {}", bundleName);
- Thread.sleep(5000);
- } else {
- ready = true;
+ Flow flow = null;
+ for (int i = 0; i < 10; i++) {
+ LOG.info("getFlow try {} from {}: looking for flow: {}, node: {}",
+ i, store, flowBuilder.build(), nodeBuilder.build());
+ flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
+ if (flow != null) {
+ LOG.info("getFlow try {} from {}: found flow: {}", i, store, flow);
+ break;
}
+ Thread.sleep(1000);
}
+ return flow;
}
- private void netVirtAddPort(ConnectionInfo connectionInfo) throws InterruptedException {
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
- Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = NetvirtITConstants.PORT_NAME;
- ovsdbTerminationBuilder.setName(portName);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
- Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
- Assert.assertNotNull(terminationPointNode);
+ private void verifyFlow(long datapathId, String flowId, short table) throws InterruptedException {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
+ FlowUtils.createNodeBuilder(datapathId);
+ FlowBuilder flowBuilder =
+ FlowUtils.initFlowBuilder(new FlowBuilder(), flowId, table);
+ Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
+ assertNotNull("Could not find flow in config: " + flowBuilder.build() + "--" + nodeBuilder.build(), flow);
+ flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
+ assertNotNull("Could not find flow in operational: " + flowBuilder.build() + "--" + nodeBuilder.build(),
+ flow);
}
- /**
- * Test for basic southbound events to netvirt.
- * <pre>The test will:
- * - connect to an OVSDB node and verify it is added to operational
- * - then verify that br-int was created on the node and stored in operational
- * - a port is then added to the bridge to verify that it is ignored by netvirt
- * - remove the bridge
- * - remove the node and verify it is not in operational
- * </pre>
- * @throws InterruptedException
- */
- // TODO add verification of flows
- //@Ignore //
- @Test
- public void testNetVirt() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
- Thread.sleep(10000);
- netVirtAddPort(connectionInfo);
- Thread.sleep(10000);
- Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
- Thread.sleep(10000);
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- }
-
- @Ignore
- @Test
- public void testNetVirt2() throws InterruptedException {
- Thread.sleep(60000);
- }
-
- @Test
- public void testReadOvsdbTopologyNodes() throws InterruptedException {
- Thread.sleep(10000);
- List<Node> ovsdbNodes = southbound.readOvsdbTopologyNodes();
- for (Node node : ovsdbNodes) {
- LOG.info(">>>>> node: {}", node);
- }
+ private void verifyFlow(long datapathId, String flowId, Service service) throws InterruptedException {
+ verifyFlow(datapathId, flowId, pipelineOrchestrator.getTable(service));
}
}