2 * Copyright (c) 2015 - 2016 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.openstack.netvirt.it;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15 import static org.ops4j.pax.exam.CoreOptions.composite;
16 import static org.ops4j.pax.exam.CoreOptions.maven;
17 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
18 import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperties;
19 import static org.ops4j.pax.exam.CoreOptions.vmOption;
20 import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
21 import static org.ops4j.pax.exam.MavenUtils.asInProject;
22 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
23 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
24 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
26 import com.google.common.collect.Lists;
27 import com.google.common.collect.Maps;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.List;
33 import java.util.Properties;
34 import java.util.UUID;
35 import java.util.concurrent.atomic.AtomicBoolean;
37 import org.junit.Assert;
38 import org.junit.Before;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
43 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
44 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
45 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
46 import org.opendaylight.netvirt.utils.netvirt.it.utils.NetvirtItUtils;
47 import org.opendaylight.netvirt.utils.netvirt.it.utils.NeutronNetItUtil;
48 import org.opendaylight.netvirt.utils.neutron.utils.NeutronUtils;
49 import org.opendaylight.neutron.spi.INeutronPortCRUD;
50 import org.opendaylight.neutron.spi.INeutronSecurityGroupCRUD;
51 import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
52 import org.opendaylight.neutron.spi.NeutronPort;
53 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
54 import org.opendaylight.neutron.spi.NeutronSecurityRule;
55 import org.opendaylight.neutron.spi.NeutronNetwork;
56 import org.opendaylight.neutron.spi.NeutronSubnet;
57 import org.opendaylight.ovsdb.lib.notation.Version;
58 import org.opendaylight.netvirt.openstack.netvirt.NetworkHandler;
59 import org.opendaylight.netvirt.openstack.netvirt.api.Southbound;
60 import org.opendaylight.netvirt.openstack.netvirt.providers.NetvirtProvidersProvider;
61 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
62 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
63 import org.opendaylight.ovsdb.utils.ovsdb.it.utils.DockerOvs;
64 import org.opendaylight.ovsdb.utils.ovsdb.it.utils.ItConstants;
65 import org.opendaylight.ovsdb.utils.ovsdb.it.utils.OvsdbItUtils;
66 import org.opendaylight.ovsdb.utils.ovsdb.it.utils.NodeInfo;
67 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
68 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
69 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
81 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
82 import org.ops4j.pax.exam.Configuration;
83 import org.ops4j.pax.exam.Option;
84 import org.ops4j.pax.exam.junit.PaxExam;
85 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
86 import org.ops4j.pax.exam.options.MavenUrlReference;
87 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
88 import org.ops4j.pax.exam.spi.reactors.PerClass;
89 import org.slf4j.Logger;
90 import org.slf4j.LoggerFactory;
93 * Integration tests for netvirt
95 * @author Sam Hague (shague@redhat.com)
97 @RunWith(PaxExam.class)
98 @ExamReactorStrategy(PerClass.class)
99 public class NetvirtIT extends AbstractMdsalTestBase {
100 private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
101 private static DataBroker dataBroker = null;
102 private static OvsdbItUtils itUtils;
103 private static NetvirtItUtils nvItUtils;
104 private static String addressStr;
105 private static String portStr;
106 private static String connectionType;
107 private static String controllerStr;
108 private static AtomicBoolean setup = new AtomicBoolean(false);
109 private static MdsalUtils mdsalUtils = null;
110 private static Southbound southbound = null;
111 private static PipelineOrchestrator pipelineOrchestrator = null;
112 private static SouthboundUtils southboundUtils;
113 private static NeutronUtils neutronUtils = new NeutronUtils();
114 private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
117 public String getModuleName() {
118 return "netvirt-providers-impl";
122 public String getInstanceName() {
123 return "netvirt-providers-default";
127 public MavenUrlReference getFeatureRepo() {
129 .groupId("org.opendaylight.netvirt")
130 .artifactId("features-netvirt")
131 .classifier("features")
133 .versionAsInProject();
137 public String getFeatureName() {
138 return "odl-ovsdb-openstack-it";
143 public Option[] config() {
144 Option[] ovsProps = super.config();
145 Option[] propertiesOptions = DockerOvs.getSysPropOptions();
146 Option[] otherOptions = getOtherOptions();
147 Option[] options = new Option[ovsProps.length + propertiesOptions.length + otherOptions.length];
148 System.arraycopy(ovsProps, 0, options, 0, ovsProps.length);
149 System.arraycopy(propertiesOptions, 0, options, ovsProps.length, propertiesOptions.length);
150 System.arraycopy(otherOptions, 0, options, ovsProps.length + propertiesOptions.length,
151 otherOptions.length);
155 private Option[] getOtherOptions() {
156 return new Option[] {
158 mavenBundle("org.opendaylight.netvirt", "utils.mdsal-openflow")
159 .version(asInProject())
162 mavenBundle("org.opendaylight.netvirt", "utils.config")
163 .version(asInProject())
165 configureConsole().startLocalConsole(),
166 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
172 public Option getLoggingOption() {
174 //editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
175 // "log4j.logger.org.opendaylight.controller",
176 // LogLevelOption.LogLevel.TRACE.name()),
177 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
178 "log4j.logger.org.opendaylight.ovsdb",
179 LogLevelOption.LogLevel.TRACE.name()),
180 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
181 logConfiguration(NetvirtIT.class),
182 LogLevelOption.LogLevel.INFO.name()),
183 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
184 "log4j.logger.org.opendaylight.ovsdb.lib",
185 LogLevelOption.LogLevel.INFO.name()),
186 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
187 "log4j.logger.org.opendaylight.openflowjava",
188 LogLevelOption.LogLevel.INFO.name()),
189 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
190 "log4j.logger.org.opendaylight.openflowplugin",
191 LogLevelOption.LogLevel.INFO.name()),
192 super.getLoggingOption());
195 protected String usage() {
196 return "Integration Test needs a valid connection configuration as follows :\n"
197 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
198 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
201 private void getProperties() {
202 Properties props = System.getProperties();
203 addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS);
204 portStr = props.getProperty(NetvirtITConstants.SERVER_PORT, NetvirtITConstants.DEFAULT_SERVER_PORT);
205 connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE, "active");
206 controllerStr = props.getProperty(NetvirtITConstants.CONTROLLER_IPADDRESS, "0.0.0.0");
207 String userSpaceEnabled = props.getProperty(NetvirtITConstants.USERSPACE_ENABLED, "no");
208 LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}, " +
209 "userspace.enabled: {}",
210 connectionType, addressStr, portStr, controllerStr, userSpaceEnabled);
215 public void setup() throws InterruptedException {
217 LOG.info("Skipping setUp, already initialized");
223 } catch (Exception e) {
224 LOG.warn("Failed to setup test", e);
225 fail("Failed to setup test: " + e);
230 dataBroker = NetvirtItUtils.getDatabroker(getProviderContext());
231 itUtils = new OvsdbItUtils(dataBroker);
232 nvItUtils = new NetvirtItUtils(dataBroker);
233 mdsalUtils = new MdsalUtils(dataBroker);
234 assertNotNull("mdsalUtils should not be null", mdsalUtils);
235 assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
236 southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
237 assertNotNull("southbound should not be null", southbound);
238 southboundUtils = new SouthboundUtils(mdsalUtils);
239 pipelineOrchestrator =
240 (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
241 assertNotNull("pipelineOrchestrator should not be null", pipelineOrchestrator);
245 private BindingAwareBroker.ProviderContext getProviderContext() {
246 BindingAwareBroker.ProviderContext providerContext = null;
247 for (int i=0; i < 60; i++) {
248 providerContext = getSession();
249 if (providerContext != null) {
254 } catch (InterruptedException e) {
255 LOG.warn("Interrupted while waiting for provider context", e);
259 assertNotNull("providercontext should not be null", providerContext);
260 /* One more second to let the provider finish initialization */
263 } catch (InterruptedException e) {
264 LOG.warn("Interrupted while waiting for other provider", e);
266 return providerContext;
269 private Boolean getNetvirtTopology() {
270 LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
271 Boolean found = false;
272 final TopologyId topologyId = new TopologyId(new Uri(NETVIRT_TOPOLOGY_ID));
273 InstanceIdentifier<Topology> path =
274 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
275 for (int i = 0; i < 60; i++) {
276 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
277 if (topology != null) {
278 LOG.info("getNetvirtTopology: found {}...", NETVIRT_TOPOLOGY_ID);
282 LOG.info("getNetvirtTopology: still looking ({})...", i);
285 } catch (InterruptedException e) {
286 LOG.warn("Interrupted while waiting for {}", NETVIRT_TOPOLOGY_ID, e);
294 * Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
295 * 6640. This test will wait for incoming connections for {@link NetvirtITConstants#CONNECTION_INIT_TIMEOUT} ms.
297 * @throws InterruptedException
301 public void testPassiveNode() throws InterruptedException {
302 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_PASSIVE)) {
303 //Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server.
304 Thread.sleep(NetvirtITConstants.CONNECTION_INIT_TIMEOUT);
308 private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
309 LOG.info("connectOvsdbNode enter");
310 Assert.assertTrue(southboundUtils.addOvsdbNode(connectionInfo));
311 Node node = southboundUtils.getOvsdbNode(connectionInfo);
312 Assert.assertNotNull("Should find OVSDB node after connect", node);
313 LOG.info("Connected to {}", SouthboundUtils.connectionInfoToString(connectionInfo));
317 private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
318 LOG.info("disconnectOvsdbNode enter");
319 Assert.assertTrue(southboundUtils.deleteOvsdbNode(connectionInfo));
320 Node node = southboundUtils.getOvsdbNode(connectionInfo);
321 Assert.assertNull("Should not find OVSDB node after disconnect", node);
322 LOG.info("Disconnected from {}", SouthboundUtils.connectionInfoToString(connectionInfo));
326 // This is an extra test for local testing and testNetVirt covers this is more detail
329 public void testAddDeleteOvsdbNode() throws InterruptedException {
330 LOG.info("testAddDeleteOvsdbNode enter");
331 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
332 Node ovsdbNode = connectOvsdbNode(connectionInfo);
333 assertNotNull("connection failed", ovsdbNode);
334 LOG.info("testNetVirt: should be connected: {}", ovsdbNode.getNodeId());
336 assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
337 + " is not connected", itUtils.isControllerConnected(connectionInfo));
339 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
341 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
342 LOG.info("testAddDeleteOvsdbNode exit");
345 // TODO add tests for when L3 is enabled and check for br-ex
347 // This is an extra test for local testing and testNetVirt covers this is more detail
350 public void testAddDeleteOvsdbNodeWithTableOffset() throws InterruptedException {
351 LOG.info("testAddDeleteOvsdbNodeWithTableOffset enter");
352 NetvirtProvidersProvider.setTableOffset((short)1);
353 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
354 Node ovsdbNode = connectOvsdbNode(connectionInfo);
355 assertNotNull("connection failed", ovsdbNode);
356 LOG.info("testNetVirt: should be connected: {}", ovsdbNode.getNodeId());
358 assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
359 + " is not connected", itUtils.isControllerConnected(connectionInfo));
361 // Verify the pipeline flows were installed
362 Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
363 assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
364 long datapathId = southbound.getDataPathId(bridgeNode);
365 String datapathIdString = southbound.getDatapathId(bridgeNode);
366 LOG.info("testNetVirt: bridgeNode: {}, datapathId: {} - {}", bridgeNode, datapathIdString, datapathId);
367 assertNotEquals("datapathId was not found", datapathId, 0);
369 List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
370 List<Service> staticPipelineFound = Lists.newArrayList();
371 for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
372 if (staticPipeline.contains(service)) {
373 staticPipelineFound.add(service);
375 String flowId = "DEFAULT_PIPELINE_FLOW_" + pipelineOrchestrator.getTable(service);
376 nvItUtils.verifyFlow(datapathId, flowId, pipelineOrchestrator.getTable(service));
378 assertEquals("did not find all expected flows in static pipeline",
379 staticPipeline.size(), staticPipelineFound.size());
381 String flowId = "TableOffset_" + pipelineOrchestrator.getTable(Service.CLASSIFIER);
382 nvItUtils.verifyFlow(datapathId, flowId, Service.CLASSIFIER.getTable());
384 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
386 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
387 LOG.info("testAddDeleteOvsdbNodeWithTableOffset exit");
392 public void testOpenVSwitchOtherConfig() throws InterruptedException {
393 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
394 Node ovsdbNode = connectOvsdbNode(connectionInfo);
395 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
396 Assert.assertNotNull(ovsdbNodeAugmentation);
397 List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
398 if (otherConfigsList != null) {
399 for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) {
400 if (otherConfig.getOtherConfigKey().equals("local_ip")) {
401 LOG.info("local_ip: {}", otherConfig.getOtherConfigValue());
404 LOG.info("other_config {}:{}", otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
408 LOG.info("other_config is not present");
410 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
414 * Test for basic southbound events to netvirt.
415 * <pre>The test will:
416 * - connect to an OVSDB node and verify it is added to operational
417 * - then verify that br-int was created on the node and stored in operational
418 * - a port is then added to the bridge to verify that it is ignored by netvirt
419 * - remove the bridge
420 * - remove the node and verify it is not in operational
422 * @throws InterruptedException
425 public void testNetVirt() throws InterruptedException {
426 LOG.info("testNetVirt: starting test");
427 try(DockerOvs ovs = new DockerOvs()) {
428 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(ovs.getOvsdbAddress(0), ovs.getOvsdbPort(0));
429 NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
431 LOG.info("testNetVirt: should be connected: {}", nodeInfo.ovsdbNode.getNodeId());
433 List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
434 List<Service> staticPipelineFound = Lists.newArrayList();
435 for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
436 if (staticPipeline.contains(service)) {
437 staticPipelineFound.add(service);
439 String flowId = "DEFAULT_PIPELINE_FLOW_" + pipelineOrchestrator.getTable(service);
440 nvItUtils.verifyFlow(nodeInfo.datapathId, flowId, pipelineOrchestrator.getTable(service));
442 assertEquals("did not find all expected flows in static pipeline",
443 staticPipeline.size(), staticPipelineFound.size());
445 southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, NetvirtITConstants.PORT_NAME, "internal", null, null, 0L);
447 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
448 southbound.getTerminationPointOfBridge(nodeInfo.bridgeNode, NetvirtITConstants.PORT_NAME);
449 Assert.assertNotNull("Did not find " + NetvirtITConstants.PORT_NAME, ovsdbTerminationPointAugmentation);
451 nodeInfo.disconnect();
452 } catch (Exception e) {
453 LOG.warn("testNetVirt: Exception thrown by OvsDocker.OvsDocker()", e);
458 public void testNetVirtFixedSG() throws InterruptedException {
459 final Version minSGOvsVersion = Version.fromString("1.10.2");
460 final String portName = "sg1";
461 final String networkId = "521e29d6-67b8-4b3c-8633-027d21195111";
462 final String tenantId = "521e29d6-67b8-4b3c-8633-027d21195100";
463 final String subnetId = "521e29d6-67b8-4b3c-8633-027d21195112";
464 final String portId = "521e29d6-67b8-4b3c-8633-027d21195113";
465 final String dhcpPortId ="521e29d6-67b8-4b3c-8633-027d21195115";
467 try(DockerOvs ovs = new DockerOvs()) {
468 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(ovs.getOvsdbAddress(0), ovs.getOvsdbPort(0));
469 NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
471 LOG.info("testNetVirtFixedSG: should be connected: {}", nodeInfo.ovsdbNode.getNodeId());
473 //TBD: This should be a utility function
474 // Verify the minimum version required for this test
475 OvsdbNodeAugmentation ovsdbNodeAugmentation = nodeInfo.ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
476 Assert.assertNotNull(ovsdbNodeAugmentation);
477 assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
478 String ovsVersion = ovsdbNodeAugmentation.getOvsVersion();
479 Version version = Version.fromString(ovsVersion);
480 if (version.compareTo(minSGOvsVersion) < 0) {
481 LOG.warn("{} minimum version is required", minSGOvsVersion);
482 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo,
483 NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
485 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
489 //TBD: Use NeutronNetItUtil
490 NeutronNetwork nn = neutronUtils.createNeutronNetwork(networkId, tenantId,
491 NetworkHandler.NETWORK_TYPE_VXLAN, "100");
492 NeutronSubnet ns = neutronUtils.createNeutronSubnet(subnetId, tenantId, networkId, "10.0.0.0/24");
493 NeutronPort nport = neutronUtils.createNeutronPort(networkId, subnetId, portId,
494 "compute", "10.0.0.10", "f6:00:00:0f:00:01");
495 NeutronPort dhcp = neutronUtils.createNeutronPort(networkId, subnetId, dhcpPortId,
496 "dhcp", "10.0.0.1", "f6:00:00:0f:00:02");
499 Map<String, String> externalIds = Maps.newHashMap();
500 externalIds.put("attached-mac", "f6:00:00:0f:00:01");
501 externalIds.put("iface-id", portId);
502 southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, portName, "internal", null, externalIds, 3L);
503 southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vm1", "internal", null, null, 0L);
504 southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vm2", "internal", null, null, 0L);
505 Map<String, String> options = Maps.newHashMap();
506 options.put("key", "flow");
507 options.put("remote_ip", "192.168.120.32");
508 southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vx", "vxlan", options, null, 4L);
511 String flowId = "Egress_DHCP_Client" + "_Permit_";
512 nvItUtils.verifyFlow(nodeInfo.datapathId, flowId, pipelineOrchestrator.getTable(Service.EGRESS_ACL));
514 testDefaultSG(nport, nodeInfo.datapathId, nn, tenantId, portId);
517 assertTrue(neutronUtils.removeNeutronPort(dhcp.getID()));
518 assertTrue(neutronUtils.removeNeutronPort(nport.getID()));
519 assertTrue(neutronUtils.removeNeutronSubnet(ns.getID()));
520 assertTrue(neutronUtils.removeNeutronNetwork(nn.getID()));
522 nodeInfo.disconnect();
523 } catch (Exception e) {
524 LOG.warn("testNetVirtFixedSG: Exception thrown by OvsDocker.OvsDocker()", e);
528 private void testDefaultSG(NeutronPort nport, long datapathId, NeutronNetwork nn, String tenantId, String portId)
529 throws InterruptedException {
530 INeutronSecurityGroupCRUD ineutronSecurityGroupCRUD =
531 (INeutronSecurityGroupCRUD) ServiceHelper.getGlobalInstance(INeutronSecurityGroupCRUD.class, this);
532 assertNotNull("Could not find ineutronSecurityGroupCRUD Service", ineutronSecurityGroupCRUD);
533 INeutronSecurityRuleCRUD ineutronSecurityRuleCRUD =
534 (INeutronSecurityRuleCRUD) ServiceHelper.getGlobalInstance(INeutronSecurityRuleCRUD.class, this);
535 assertNotNull("Could not find ineutronSecurityRuleCRUD Service", ineutronSecurityRuleCRUD);
537 NeutronSecurityGroup neutronSG = new NeutronSecurityGroup();
538 neutronSG.setSecurityGroupDescription("testig defaultSG-IT");
539 neutronSG.setSecurityGroupName("DefaultSG");
540 neutronSG.setSecurityGroupUUID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
541 neutronSG.setTenantID(tenantId);
543 List<NeutronSecurityRule> nsrs = new ArrayList<>();
544 NeutronSecurityRule nsrIN = new NeutronSecurityRule();
545 nsrIN.setSecurityRemoteGroupID(null);
546 nsrIN.setSecurityRuleDirection("ingress");
547 nsrIN.setSecurityRuleEthertype("IPv4");
548 nsrIN.setSecurityRuleGroupID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
549 nsrIN.setSecurityRuleProtocol("TCP");
550 nsrIN.setSecurityRuleRemoteIpPrefix("10.0.0.0/24");
551 nsrIN.setSecurityRuleUUID("823faaf7-175d-4f01-a271-0bf56fb1e7e6");
552 nsrIN.setTenantID(tenantId);
554 NeutronSecurityRule nsrEG = new NeutronSecurityRule();
555 nsrEG.setSecurityRemoteGroupID(null);
556 nsrEG.setSecurityRuleDirection("egress");
557 nsrEG.setSecurityRuleEthertype("IPv4");
558 nsrEG.setSecurityRuleGroupID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
559 nsrEG.setSecurityRuleProtocol("TCP");
560 nsrEG.setSecurityRuleRemoteIpPrefix("10.0.0.0/24");
561 nsrEG.setSecurityRuleUUID("823faaf7-175d-4f01-a271-0bf56fb1e7e1");
562 nsrEG.setTenantID(tenantId);
567 neutronSG.setSecurityRules(nsrs);
568 ineutronSecurityRuleCRUD.addNeutronSecurityRule(nsrIN);
569 ineutronSecurityRuleCRUD.addNeutronSecurityRule(nsrEG);
570 ineutronSecurityGroupCRUD.add(neutronSG);
572 List<NeutronSecurityGroup> sgs = new ArrayList<>();
574 nport.setSecurityGroups(sgs);
576 INeutronPortCRUD iNeutronPortCRUD =
577 (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
578 iNeutronPortCRUD.update(portId, nport);
580 LOG.info("Neutron ports have been added");
582 String flowId = "Egress_IP" + nn.getProviderSegmentationID() + "_" + nport.getMacAddress() + "_Permit_";
583 nvItUtils.verifyFlow(datapathId, flowId, pipelineOrchestrator.getTable(Service.EGRESS_ACL));
585 flowId = "Ingress_IP" + nn.getProviderSegmentationID() + "_" + nport.getMacAddress() + "_Permit_";
586 nvItUtils.verifyFlow(datapathId, flowId, pipelineOrchestrator.getTable(Service.INGRESS_ACL));
588 ineutronSecurityGroupCRUD.remove(neutronSG.getID());
589 ineutronSecurityRuleCRUD.removeNeutronSecurityRule(nsrEG.getID());
590 ineutronSecurityRuleCRUD.removeNeutronSecurityRule(nsrIN.getID());
594 * Test a basic neutron use case. This test constructs a Neutron network, subnet, dhcp port, and two "vm" ports
595 * and validates that the correct flows are installed on OVS.
596 * @throws InterruptedException if we're interrupted while waiting for some mdsal operation to complete
599 public void testNeutronNet() throws InterruptedException {
600 LOG.warn("testNeutronNet: starting test");
601 try(DockerOvs ovs = new DockerOvs()) {
602 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(ovs.getOvsdbAddress(0), ovs.getOvsdbPort(0));
603 NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
605 LOG.warn("testNeutronNet: should be connected: {}", nodeInfo.ovsdbNode.getNodeId());
607 // Create the objects
608 NeutronNetItUtil net = new NeutronNetItUtil(southboundUtils, UUID.randomUUID().toString());
610 net.createPort(nodeInfo.bridgeNode, "dhcp", "network:dhcp");
611 net.createPort(nodeInfo.bridgeNode, "vm1");
612 net.createPort(nodeInfo.bridgeNode, "vm2");
615 // Check flows created for all ports
616 for (int i = 1; i <= net.neutronPorts.size(); i++) {
617 nvItUtils.verifyFlow(nodeInfo.datapathId, "DropFilter_" + i,
618 pipelineOrchestrator.getTable(Service.CLASSIFIER));
619 nvItUtils.verifyFlow(nodeInfo.datapathId, "LocalMac_" + net.segId + "_" + i + "_" + net.macFor(i),
620 pipelineOrchestrator.getTable(Service.CLASSIFIER));
621 nvItUtils.verifyFlow(nodeInfo.datapathId, "ArpResponder_" + net.segId + "_" + net.ipFor(i),
622 pipelineOrchestrator.getTable(Service.ARP_RESPONDER));
623 nvItUtils.verifyFlow(nodeInfo.datapathId, "UcastOut_" + net.segId + "_" + i + "_" + net.macFor(i),
624 pipelineOrchestrator.getTable(Service.L2_FORWARDING));
627 // Check flows created for vm ports only
628 for (int i = 2; i <= net.neutronPorts.size(); i++) {
629 nvItUtils.verifyFlow(nodeInfo.datapathId, "Ingress_ARP_" + net.segId + "_" + i + "_",
630 pipelineOrchestrator.getTable(Service.INGRESS_ACL));
632 nvItUtils.verifyFlow(nodeInfo.datapathId, "Egress_Allow_VM_IP_MAC_" + i + net.macFor(i) + "_Permit_",
633 pipelineOrchestrator.getTable(Service.EGRESS_ACL));
634 nvItUtils.verifyFlow(nodeInfo.datapathId, "Egress_ARP_" + net.segId + "_" + i + "_",
635 pipelineOrchestrator.getTable(Service.EGRESS_ACL));
636 nvItUtils.verifyFlow(nodeInfo.datapathId, "Egress_DHCP_Server_" + i + "_DROP_",
637 pipelineOrchestrator.getTable(Service.EGRESS_ACL));
638 nvItUtils.verifyFlow(nodeInfo.datapathId, "Egress_DHCPv6_Server_" + i + "_DROP_",
639 pipelineOrchestrator.getTable(Service.EGRESS_ACL));
642 // Check ingress/egress acl flows for DHCP
643 nvItUtils.verifyFlow(nodeInfo.datapathId, "Egress_DHCP_Client_Permit_",
644 pipelineOrchestrator.getTable(Service.EGRESS_ACL));
645 nvItUtils.verifyFlow(nodeInfo.datapathId, "Egress_DHCPv6_Client_Permit_",
646 pipelineOrchestrator.getTable(Service.EGRESS_ACL));
647 nvItUtils.verifyFlow(nodeInfo.datapathId, "Ingress_DHCPv6_Server" + net.segId + "_"
648 + net.macFor(1) + "_Permit_", pipelineOrchestrator.getTable(Service.INGRESS_ACL));
649 nvItUtils.verifyFlow(nodeInfo.datapathId, "Ingress_DHCP_Server" + net.segId + "_"
650 + net.macFor(1) + "_Permit_", pipelineOrchestrator.getTable(Service.INGRESS_ACL));
652 // Check l2 broadcast flows
653 nvItUtils.verifyFlow(nodeInfo.datapathId, "TunnelFloodOut_" + net.segId,
654 pipelineOrchestrator.getTable(Service.L2_FORWARDING));
655 nvItUtils.verifyFlow(nodeInfo.datapathId, "BcastOut_" + net.segId,
656 pipelineOrchestrator.getTable(Service.L2_FORWARDING));
658 //TBD Figure out why this does not work:
659 //nvItUtils.verifyFlow(nodeInfo.datapathId, "TunnelMiss_" + net.segId,
660 // pipelineOrchestrator.getTable(Service.L2_FORWARDING));
663 nodeInfo.disconnect();
664 } catch (Exception e) {
665 LOG.warn("testNeutronNet: Exception thrown by OvsDocker.OvsDocker()", e);
670 public void twoNodes() throws InterruptedException {
672 System.getProperties().setProperty(ItConstants.DOCKER_COMPOSE_FILE_NAME, "two_dockers-ovs-2.5.1.yml");
673 try(DockerOvs ovs = new DockerOvs()) {
674 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(ovs.getOvsdbAddress(0), ovs.getOvsdbPort(0));
675 NodeInfo nodeInfo0 = itUtils.createNodeInfo(connectionInfo, null);
677 LOG.warn("testTwoNodes: should be connected: {}", nodeInfo0.ovsdbNode.getNodeId());
678 connectionInfo = SouthboundUtils.getConnectionInfo(ovs.getOvsdbAddress(1), ovs.getOvsdbPort(1));
679 NodeInfo nodeInfo1 = itUtils.createNodeInfo(connectionInfo, null);
681 LOG.warn("testTwoNodes: should be connected: {}", nodeInfo1.ovsdbNode.getNodeId());
683 nodeInfo0.disconnect();
684 nodeInfo1.disconnect();
685 } catch (Exception e) {
686 LOG.warn("testTwoNodes: Exception thrown by OvsDocker.OvsDocker()", e);