2 * Copyright (c) 2015 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.ovsdb.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.net.InetAddress;
30 import java.net.NetworkInterface;
31 import java.net.UnknownHostException;
32 import java.util.ArrayList;
33 import java.util.Enumeration;
34 import java.util.List;
36 import java.util.Properties;
37 import java.util.concurrent.atomic.AtomicBoolean;
39 import org.junit.Assert;
40 import org.junit.Before;
41 import org.junit.Ignore;
42 import org.junit.Test;
43 import org.junit.runner.RunWith;
44 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
45 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
46 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
47 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
48 import org.opendaylight.neutron.spi.INeutronPortCRUD;
49 import org.opendaylight.neutron.spi.INeutronSecurityGroupCRUD;
50 import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
51 import org.opendaylight.neutron.spi.NeutronPort;
52 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
53 import org.opendaylight.neutron.spi.NeutronSecurityRule;
54 import org.opendaylight.neutron.spi.NeutronNetwork;
55 import org.opendaylight.neutron.spi.NeutronSubnet;
56 import org.opendaylight.ovsdb.lib.notation.Version;
57 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
58 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
59 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
60 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
61 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
62 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
63 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
64 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
65 import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
66 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
67 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
68 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
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.InterfaceTypeEntryBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
88 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
89 import org.ops4j.pax.exam.Configuration;
90 import org.ops4j.pax.exam.Option;
91 import org.ops4j.pax.exam.junit.PaxExam;
92 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
93 import org.ops4j.pax.exam.options.MavenUrlReference;
94 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
95 import org.ops4j.pax.exam.spi.reactors.PerClass;
96 import org.slf4j.Logger;
97 import org.slf4j.LoggerFactory;
100 * Integration tests for netvirt
102 * @author Sam Hague (shague@redhat.com)
104 @RunWith(PaxExam.class)
105 @ExamReactorStrategy(PerClass.class)
106 public class NetvirtIT extends AbstractMdsalTestBase {
107 private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
108 private static final int OVSDB_UPDATE_TIMEOUT = 1000;
109 private static DataBroker dataBroker = null;
110 private static String addressStr;
111 private static String portStr;
112 private static String connectionType;
113 private static String controllerStr;
114 private static AtomicBoolean setup = new AtomicBoolean(false);
115 private static MdsalUtils mdsalUtils = null;
116 private static Southbound southbound = null;
117 private static SouthboundUtils southboundUtils;
118 private static NeutronUtils neutronUtils = new NeutronUtils();
119 private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
122 public String getModuleName() {
123 return "netvirt-providers-impl";
127 public String getInstanceName() {
128 return "netvirt-providers-default";
132 public MavenUrlReference getFeatureRepo() {
134 .groupId("org.opendaylight.ovsdb")
135 .artifactId("features-ovsdb")
136 .classifier("features")
138 .versionAsInProject();
142 public String getFeatureName() {
143 return "odl-ovsdb-openstack";
148 public Option[] config() {
149 Option[] parentOptions = super.config();
150 Option[] propertiesOptions = getPropertiesOptions();
151 Option[] otherOptions = getOtherOptions();
152 Option[] options = new Option[parentOptions.length + propertiesOptions.length + otherOptions.length];
153 System.arraycopy(parentOptions, 0, options, 0, parentOptions.length);
154 System.arraycopy(propertiesOptions, 0, options, parentOptions.length, propertiesOptions.length);
155 System.arraycopy(otherOptions, 0, options, parentOptions.length + propertiesOptions.length,
156 otherOptions.length);
160 private Option[] getOtherOptions() {
161 return new Option[] {
163 mavenBundle("org.opendaylight.ovsdb", "utils.mdsal-openflow")
164 .version(asInProject())
167 mavenBundle("org.opendaylight.ovsdb", "utils.config")
168 .version(asInProject())
170 configureConsole().startLocalConsole(),
171 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
176 public Option[] getPropertiesOptions() {
177 return new Option[] {
178 propagateSystemProperties(NetvirtITConstants.SERVER_IPADDRESS,
179 NetvirtITConstants.SERVER_PORT, NetvirtITConstants.CONNECTION_TYPE,
180 NetvirtITConstants.CONTROLLER_IPADDRESS,
181 NetvirtITConstants.USERSPACE_ENABLED)
186 public Option getLoggingOption() {
188 //editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
189 // "log4j.logger.org.opendaylight.controller",
190 // LogLevelOption.LogLevel.TRACE.name()),
191 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
192 "log4j.logger.org.opendaylight.ovsdb",
193 LogLevelOption.LogLevel.TRACE.name()),
194 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
195 logConfiguration(NetvirtIT.class),
196 LogLevelOption.LogLevel.INFO.name()),
197 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
198 "log4j.logger.org.opendaylight.ovsdb.lib",
199 LogLevelOption.LogLevel.INFO.name()),
200 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
201 "log4j.logger.org.opendaylight.openflowjava",
202 LogLevelOption.LogLevel.INFO.name()),
203 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
204 "log4j.logger.org.opendaylight.openflowplugin",
205 LogLevelOption.LogLevel.INFO.name()),
206 super.getLoggingOption());
209 protected String usage() {
210 return "Integration Test needs a valid connection configuration as follows :\n"
211 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
212 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
215 private void getProperties() {
216 Properties props = System.getProperties();
217 addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS);
218 portStr = props.getProperty(NetvirtITConstants.SERVER_PORT, NetvirtITConstants.DEFAULT_SERVER_PORT);
219 connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE, "active");
220 controllerStr = props.getProperty(NetvirtITConstants.CONTROLLER_IPADDRESS, "0.0.0.0");
221 String userSpaceEnabled = props.getProperty(NetvirtITConstants.USERSPACE_ENABLED, "no");
222 LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}, " +
223 "userspace.enabled: {}",
224 connectionType, addressStr, portStr, controllerStr, userSpaceEnabled);
225 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
226 if (addressStr == null) {
234 public void setup() throws InterruptedException {
236 LOG.info("Skipping setUp, already initialized");
242 } catch (Exception e) {
248 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
249 if (addressStr == null) {
254 dataBroker = getDatabroker(getProviderContext());
255 mdsalUtils = new MdsalUtils(dataBroker);
256 assertNotNull("mdsalUtils should not be null", mdsalUtils);
257 assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
258 southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
259 assertNotNull("southbound should not be null", southbound);
260 southboundUtils = new SouthboundUtils(mdsalUtils);
264 private BindingAwareBroker.ProviderContext getProviderContext() {
265 BindingAwareBroker.ProviderContext providerContext = null;
266 for (int i=0; i < 60; i++) {
267 providerContext = getSession();
268 if (providerContext != null) {
273 } catch (InterruptedException e) {
278 assertNotNull("providercontext should not be null", providerContext);
279 /* One more second to let the provider finish initialization */
282 } catch (InterruptedException e) {
285 return providerContext;
288 private DataBroker getDatabroker(BindingAwareBroker.ProviderContext providerContext) {
289 DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
290 assertNotNull("dataBroker should not be null", dataBroker);
294 private Boolean getNetvirtTopology() {
295 LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
296 Boolean found = false;
297 final TopologyId topologyId = new TopologyId(new Uri(NETVIRT_TOPOLOGY_ID));
298 InstanceIdentifier<Topology> path =
299 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
300 for (int i = 0; i < 60; i++) {
301 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
302 if (topology != null) {
303 LOG.info("getNetvirtTopology: found {}...", NETVIRT_TOPOLOGY_ID);
307 LOG.info("getNetvirtTopology: still looking ({})...", i);
310 } catch (InterruptedException e) {
319 * Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
320 * 6640. This test will wait for incoming connections for {@link NetvirtITConstants#CONNECTION_INIT_TIMEOUT} ms.
322 * @throws InterruptedException
326 public void testPassiveNode() throws InterruptedException {
327 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_PASSIVE)) {
328 //Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server.
329 Thread.sleep(NetvirtITConstants.CONNECTION_INIT_TIMEOUT);
333 private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
334 LOG.info("connectOvsdbNode enter");
335 Assert.assertTrue(southboundUtils.addOvsdbNode(connectionInfo));
336 Node node = southboundUtils.getOvsdbNode(connectionInfo);
337 Assert.assertNotNull("Should find OVSDB node after connect", node);
338 LOG.info("Connected to {}", SouthboundUtils.connectionInfoToString(connectionInfo));
342 private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
343 LOG.info("disconnectOvsdbNode enter");
344 Assert.assertTrue(southboundUtils.deleteOvsdbNode(connectionInfo));
345 Node node = southboundUtils.getOvsdbNode(connectionInfo);
346 Assert.assertNull("Should not find OVSDB node after disconnect", node);
347 LOG.info("Disconnected from {}", SouthboundUtils.connectionInfoToString(connectionInfo));
352 public void testAddDeleteOvsdbNode() throws InterruptedException {
353 LOG.info("testAddDeleteOvsdbNode enter");
354 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
355 connectOvsdbNode(connectionInfo);
357 assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
358 + " is not connected", isControllerConnected(connectionInfo));
360 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
362 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
363 LOG.info("testAddDeleteOvsdbNode exit");
366 private boolean isControllerConnected(ConnectionInfo connectionInfo) throws InterruptedException {
367 LOG.info("isControllerConnected enter");
368 Boolean connected = false;
369 ControllerEntry controllerEntry;
370 Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
371 assertNotNull("ovsdb node not found", ovsdbNode);
373 BridgeConfigurationManager bridgeConfigurationManager =
374 (BridgeConfigurationManager) ServiceHelper.getGlobalInstance(BridgeConfigurationManager.class, this);
375 assertNotNull("Could not find PipelineOrchestrator Service", bridgeConfigurationManager);
376 String controllerTarget = bridgeConfigurationManager.getControllersFromOvsdbNode(ovsdbNode).get(0);
377 Assert.assertNotNull("Failed to get controller target", controllerTarget);
379 for (int i = 0; i < 10; i++) {
380 LOG.info("isControllerConnected try {}: looking for controller", i);
381 OvsdbBridgeAugmentation bridge =
382 southboundUtils.getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
383 Assert.assertNotNull(bridge);
384 Assert.assertNotNull(bridge.getControllerEntry());
385 controllerEntry = bridge.getControllerEntry().iterator().next();
386 Assert.assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
387 if (controllerEntry.isIsConnected()) {
388 Assert.assertTrue("Controller is not connected", controllerEntry.isIsConnected());
394 LOG.info("isControllerConnected exit: {}", connected);
400 public void testOpenVSwitchOtherConfig() throws InterruptedException {
401 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
402 Node ovsdbNode = connectOvsdbNode(connectionInfo);
403 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
404 Assert.assertNotNull(ovsdbNodeAugmentation);
405 List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
406 if (otherConfigsList != null) {
407 for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) {
408 if (otherConfig.getOtherConfigKey().equals("local_ip")) {
409 LOG.info("local_ip: {}", otherConfig.getOtherConfigValue());
412 LOG.info("other_config {}:{}", otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
416 LOG.info("other_config is not present");
418 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
422 * Test for basic southbound events to netvirt.
423 * <pre>The test will:
424 * - connect to an OVSDB node and verify it is added to operational
425 * - then verify that br-int was created on the node and stored in operational
426 * - a port is then added to the bridge to verify that it is ignored by netvirt
427 * - remove the bridge
428 * - remove the node and verify it is not in operational
430 * @throws InterruptedException
433 public void testNetVirt() throws InterruptedException {
434 LOG.info("testNetVirt: starting test");
435 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
436 Node ovsdbNode = connectOvsdbNode(connectionInfo);
437 LOG.info("testNetVirt: should be connected");
439 assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
440 + " is not connected", isControllerConnected(connectionInfo));
442 // Verify the pipeline flows were installed
443 PipelineOrchestrator pipelineOrchestrator =
444 (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
445 assertNotNull("Could not find PipelineOrchestrator Service", pipelineOrchestrator);
446 Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
447 assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
448 LOG.info("testNetVirt: bridgeNode: {}", bridgeNode);
449 long datapathId = southbound.getDataPathId(bridgeNode);
450 assertNotEquals("datapathId was not found", datapathId, 0);
452 List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
453 List<Service> staticPipelineFound = Lists.newArrayList();
454 for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
455 if (staticPipeline.contains(service)) {
456 staticPipelineFound.add(service);
458 String flowId = "DEFAULT_PIPELINE_FLOW_" + service.getTable();
459 verifyFlow(datapathId, flowId, service.getTable());
461 assertEquals("did not find all expected flows in static pipeline",
462 staticPipeline.size(), staticPipelineFound.size());
464 southboundUtils.addTerminationPoint(bridgeNode, NetvirtITConstants.PORT_NAME, "internal", null, null, 0L);
466 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
467 southbound.getTerminationPointOfBridge(bridgeNode, NetvirtITConstants.PORT_NAME);
468 Assert.assertNotNull("Did not find " + NetvirtITConstants.PORT_NAME, ovsdbTerminationPointAugmentation);
470 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
472 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
476 public void testNetVirtFixedSG() throws InterruptedException {
477 final Version minSGOvsVersion = Version.fromString("1.10.2");
478 final String portName = "sg1";
479 final String networkId = "521e29d6-67b8-4b3c-8633-027d21195111";
480 final String tenantId = "521e29d6-67b8-4b3c-8633-027d21195100";
481 final String subnetId = "521e29d6-67b8-4b3c-8633-027d21195112";
482 final String portId = "521e29d6-67b8-4b3c-8633-027d21195113";
483 final String dhcpPortId ="521e29d6-67b8-4b3c-8633-027d21195115";
485 ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
486 assertNotNull("connection failed", southboundUtils.connectOvsdbNode(connectionInfo));
487 Node ovsdbNode = connectOvsdbNode(connectionInfo);
488 assertNotNull("node is not connected", ovsdbNode);
490 // Verify the minimum version required for this test
491 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
492 Assert.assertNotNull(ovsdbNodeAugmentation);
493 assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
494 String ovsVersion = ovsdbNodeAugmentation.getOvsVersion();
495 Version version = Version.fromString(ovsVersion);
496 if (version.compareTo(minSGOvsVersion) < 0) {
497 LOG.warn("{} minimum version is required", minSGOvsVersion);
498 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo,
499 NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
501 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
505 assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
506 + " is not connected", isControllerConnected(connectionInfo));
508 Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
509 assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
510 long datapathId = southbound.getDataPathId(bridgeNode);
511 assertNotEquals("datapathId was not found", datapathId, 0);
513 NeutronNetwork nn = neutronUtils.createNeutronNetwork(networkId, tenantId,
514 NetworkHandler.NETWORK_TYPE_VXLAN, "100");
515 NeutronSubnet ns = neutronUtils.createNeutronSubnet(subnetId, tenantId, networkId, "10.0.0.0/24");
516 NeutronPort nport = neutronUtils.createNeutronPort(networkId, subnetId, portId,
517 "compute", "10.0.0.10", "f6:00:00:0f:00:01");
518 NeutronPort dhcp = neutronUtils.createNeutronPort(networkId, subnetId, dhcpPortId,
519 "dhcp", "10.0.0.1", "f6:00:00:0f:00:02");
522 Map<String, String> externalIds = Maps.newHashMap();
523 externalIds.put("attached-mac", "f6:00:00:0f:00:01");
524 externalIds.put("iface-id", portId);
525 southboundUtils.addTerminationPoint(bridgeNode, portName, "internal", null, externalIds, 3L);
526 southboundUtils.addTerminationPoint(bridgeNode, "vm1", "internal", null, null, 0L);
527 southboundUtils.addTerminationPoint(bridgeNode, "vm2", "internal", null, null, 0L);
528 Map<String, String> options = Maps.newHashMap();
529 options.put("key", "flow");
530 options.put("remote_ip", "192.168.120.32");
531 southboundUtils.addTerminationPoint(bridgeNode, "vx", "vxlan", options, null, 4L);
534 String flowId = "Egress_DHCP_Client" + "_Permit_";
535 verifyFlow(datapathId, flowId, Service.EGRESS_ACL.getTable());
537 testDefaultSG(nport, datapathId, nn, tenantId, portId);
539 Assert.assertTrue(southboundUtils.deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
541 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
544 private void testDefaultSG(NeutronPort nport, long datapathId, NeutronNetwork nn, String tenantId, String portId)
545 throws InterruptedException {
546 INeutronSecurityGroupCRUD ineutronSecurityGroupCRUD =
547 (INeutronSecurityGroupCRUD) ServiceHelper.getGlobalInstance(INeutronSecurityGroupCRUD.class, this);
548 assertNotNull("Could not find ineutronSecurityGroupCRUD Service", ineutronSecurityGroupCRUD);
549 INeutronSecurityRuleCRUD ineutronSecurityRuleCRUD =
550 (INeutronSecurityRuleCRUD) ServiceHelper.getGlobalInstance(INeutronSecurityRuleCRUD.class, this);
551 assertNotNull("Could not find ineutronSecurityRuleCRUD Service", ineutronSecurityRuleCRUD);
553 NeutronSecurityGroup neutronSG = new NeutronSecurityGroup();
554 neutronSG.setSecurityGroupDescription("testig defaultSG-IT");
555 neutronSG.setSecurityGroupName("DefaultSG");
556 neutronSG.setSecurityGroupUUID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
557 neutronSG.setTenantID(tenantId);
559 List<NeutronSecurityRule> nsrs = new ArrayList<>();
560 NeutronSecurityRule nsrIN = new NeutronSecurityRule();
561 nsrIN.setSecurityRemoteGroupID(null);
562 nsrIN.setSecurityRuleDirection("ingress");
563 nsrIN.setSecurityRuleEthertype("IPv4");
564 nsrIN.setSecurityRuleGroupID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
565 nsrIN.setSecurityRuleProtocol("TCP");
566 nsrIN.setSecurityRuleRemoteIpPrefix("10.0.0.0/24");
567 nsrIN.setSecurityRuleUUID("823faaf7-175d-4f01-a271-0bf56fb1e7e6");
568 nsrIN.setTenantID(tenantId);
570 NeutronSecurityRule nsrEG = new NeutronSecurityRule();
571 nsrEG.setSecurityRemoteGroupID(null);
572 nsrEG.setSecurityRuleDirection("egress");
573 nsrEG.setSecurityRuleEthertype("IPv4");
574 nsrEG.setSecurityRuleGroupID("d3329053-bae5-4bf4-a2d1-7330f11ba5db");
575 nsrEG.setSecurityRuleProtocol("TCP");
576 nsrEG.setSecurityRuleRemoteIpPrefix("10.0.0.0/24");
577 nsrEG.setSecurityRuleUUID("823faaf7-175d-4f01-a271-0bf56fb1e7e1");
578 nsrEG.setTenantID(tenantId);
583 neutronSG.setSecurityRules(nsrs);
584 ineutronSecurityRuleCRUD.addNeutronSecurityRule(nsrIN);
585 ineutronSecurityRuleCRUD.addNeutronSecurityRule(nsrEG);
586 ineutronSecurityGroupCRUD.add(neutronSG);
588 List<NeutronSecurityGroup> sgs = new ArrayList<>();
590 nport.setSecurityGroups(sgs);
592 INeutronPortCRUD iNeutronPortCRUD =
593 (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this);
594 iNeutronPortCRUD.update(portId, nport);
597 String flowId = "Egress_IP" + nn.getProviderSegmentationID() + "_" + nport.getMacAddress() + "_Permit_";
598 verifyFlow(datapathId, flowId, Service.EGRESS_ACL.getTable());
600 flowId = "Ingress_IP" + nn.getProviderSegmentationID() + "_" + nport.getMacAddress() + "_Permit_";
601 verifyFlow(datapathId, flowId, Service.INGRESS_ACL.getTable());
604 private Flow getFlow (
605 FlowBuilder flowBuilder,
606 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder,
607 LogicalDatastoreType store) throws InterruptedException {
610 for (int i = 0; i < 10; i++) {
611 LOG.info("getFlow try {} from {}: looking for flow: {}, node: {}",
612 i, store, flowBuilder.build(), nodeBuilder.build());
613 flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
615 LOG.info("getFlow try {} from {}: found flow: {}", i, store, flow);
623 private void verifyFlow(long datapathId, String flowId, short table) throws InterruptedException {
624 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
625 FlowUtils.createNodeBuilder(datapathId);
626 FlowBuilder flowBuilder =
627 FlowUtils.initFlowBuilder(new FlowBuilder(), flowId, table);
628 Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
629 assertNotNull("Could not find flow in config: " + flowBuilder.build() + "--" + nodeBuilder.build(), flow);
630 flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
631 assertNotNull("Could not find flow in operational: " + flowBuilder.build() + "--" + nodeBuilder.build(), flow);