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;
28 import java.net.InetAddress;
29 import java.net.NetworkInterface;
30 import java.net.UnknownHostException;
31 import java.util.ArrayList;
32 import java.util.Enumeration;
33 import java.util.List;
34 import java.util.Properties;
35 import java.util.concurrent.atomic.AtomicBoolean;
36 import org.junit.Assert;
37 import org.junit.Before;
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
42 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
43 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
44 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
45 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
46 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
47 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
48 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
49 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
50 import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
51 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.InterfaceTypeEntryBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
75 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
76 import org.ops4j.pax.exam.Configuration;
77 import org.ops4j.pax.exam.Option;
78 import org.ops4j.pax.exam.junit.PaxExam;
79 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
80 import org.ops4j.pax.exam.options.MavenUrlReference;
81 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
82 import org.ops4j.pax.exam.spi.reactors.PerClass;
83 import org.slf4j.Logger;
84 import org.slf4j.LoggerFactory;
87 * Integration tests for netvirt
89 * @author Sam Hague (shague@redhat.com)
91 @RunWith(PaxExam.class)
92 @ExamReactorStrategy(PerClass.class)
93 public class NetvirtIT extends AbstractMdsalTestBase {
94 private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
95 private static final int OVSDB_UPDATE_TIMEOUT = 1000;
96 private static DataBroker dataBroker = null;
97 private static String addressStr;
98 private static String portStr;
99 private static String connectionType;
100 private static String controllerStr;
101 private static AtomicBoolean setup = new AtomicBoolean(false);
102 private static MdsalUtils mdsalUtils = null;
103 private static Southbound southbound = null;
104 private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
107 public String getModuleName() {
108 return "netvirt-providers-impl";
112 public String getInstanceName() {
113 return "netvirt-providers-default";
117 public MavenUrlReference getFeatureRepo() {
119 .groupId("org.opendaylight.ovsdb")
120 .artifactId("features-ovsdb")
121 .classifier("features")
123 .versionAsInProject();
127 public String getFeatureName() {
128 return "odl-ovsdb-openstack";
133 public Option[] config() {
134 Option[] parentOptions = super.config();
135 Option[] propertiesOptions = getPropertiesOptions();
136 Option[] otherOptions = getOtherOptions();
137 Option[] options = new Option[parentOptions.length + propertiesOptions.length + otherOptions.length];
138 System.arraycopy(parentOptions, 0, options, 0, parentOptions.length);
139 System.arraycopy(propertiesOptions, 0, options, parentOptions.length, propertiesOptions.length);
140 System.arraycopy(otherOptions, 0, options, parentOptions.length + propertiesOptions.length,
141 otherOptions.length);
145 private Option[] getOtherOptions() {
146 return new Option[] {
148 mavenBundle("org.opendaylight.ovsdb", "utils.mdsal-openflow")
149 .version(asInProject())
152 mavenBundle("org.opendaylight.ovsdb", "utils.config")
153 .version(asInProject())
155 configureConsole().startLocalConsole(),
156 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
161 public Option[] getPropertiesOptions() {
162 return new Option[] {
163 propagateSystemProperties(NetvirtITConstants.SERVER_IPADDRESS,
164 NetvirtITConstants.SERVER_PORT, NetvirtITConstants.CONNECTION_TYPE,
165 NetvirtITConstants.CONTROLLER_IPADDRESS),
170 public Option getLoggingOption() {
172 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
173 "log4j.logger.org.opendaylight.ovsdb",
174 LogLevelOption.LogLevel.TRACE.name()),
175 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
176 logConfiguration(NetvirtIT.class),
177 LogLevelOption.LogLevel.INFO.name()),
178 //editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
179 // "log4j.logger.org.opendaylight.ovsdb.lib",
180 // LogLevelOption.LogLevel.INFO.name()),
181 super.getLoggingOption());
184 protected String usage() {
185 return "Integration Test needs a valid connection configuration as follows :\n"
186 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
187 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
190 private void getProperties() {
191 Properties props = System.getProperties();
192 addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS);
193 portStr = props.getProperty(NetvirtITConstants.SERVER_PORT, NetvirtITConstants.DEFAULT_SERVER_PORT);
194 connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE, "active");
195 controllerStr = props.getProperty(NetvirtITConstants.CONTROLLER_IPADDRESS);
196 LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}",
197 connectionType, addressStr, portStr, controllerStr);
198 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
199 if (addressStr == null) {
207 public void setup() throws InterruptedException {
209 LOG.info("Skipping setUp, already initialized");
215 } catch (Exception e) {
221 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
222 if (addressStr == null) {
227 dataBroker = getDatabroker(getProviderContext());
228 mdsalUtils = new MdsalUtils(dataBroker);
229 assertNotNull("mdsalUtils should not be null", mdsalUtils);
230 assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
231 southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
232 assertNotNull("southbound should not be null", southbound);
236 private BindingAwareBroker.ProviderContext getProviderContext() {
237 BindingAwareBroker.ProviderContext providerContext = null;
238 for (int i=0; i < 60; i++) {
239 providerContext = getSession();
240 if (providerContext != null) {
245 } catch (InterruptedException e) {
250 assertNotNull("providercontext should not be null", providerContext);
251 /* One more second to let the provider finish initialization */
254 } catch (InterruptedException e) {
257 return providerContext;
260 private DataBroker getDatabroker(BindingAwareBroker.ProviderContext providerContext) {
261 DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
262 assertNotNull("dataBroker should not be null", dataBroker);
266 private Boolean getNetvirtTopology() {
267 LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
268 Boolean found = false;
269 final TopologyId topologyId = new TopologyId(new Uri(NETVIRT_TOPOLOGY_ID));
270 InstanceIdentifier<Topology> path =
271 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
272 for (int i = 0; i < 60; i++) {
273 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
274 if (topology != null) {
275 LOG.info("getNetvirtTopology: found {}...", NETVIRT_TOPOLOGY_ID);
279 LOG.info("getNetvirtTopology: still looking ({})...", i);
282 } catch (InterruptedException e) {
291 * Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
292 * 6640. This test will wait for incoming connections for {@link NetvirtITConstants#CONNECTION_INIT_TIMEOUT} ms.
294 * @throws InterruptedException
298 public void testPassiveNode() throws InterruptedException {
299 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_PASSIVE)) {
300 //Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server.
301 Thread.sleep(NetvirtITConstants.CONNECTION_INIT_TIMEOUT);
305 private ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
306 InetAddress inetAddress = null;
308 inetAddress = InetAddress.getByName(addressStr);
309 } catch (UnknownHostException e) {
310 fail("Could not allocate InetAddress: " + e);
313 IpAddress address = SouthboundMapper.createIpAddress(inetAddress);
314 PortNumber port = new PortNumber(Integer.parseInt(portStr));
316 LOG.info("connectionInfo: {}", new ConnectionInfoBuilder()
317 .setRemoteIp(address)
320 return new ConnectionInfoBuilder()
321 .setRemoteIp(address)
326 private String connectionInfoToString(final ConnectionInfo connectionInfo) {
327 return String.valueOf(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
330 private boolean addOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
331 boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
332 SouthboundMapper.createInstanceIdentifier(connectionInfo),
333 SouthboundMapper.createNode(connectionInfo));
334 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
338 private Node getOvsdbNode(final ConnectionInfo connectionInfo) {
339 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
340 SouthboundMapper.createInstanceIdentifier(connectionInfo));
343 private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
344 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
345 SouthboundMapper.createInstanceIdentifier(connectionInfo));
346 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
350 private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
351 Assert.assertTrue(addOvsdbNode(connectionInfo));
352 Node node = getOvsdbNode(connectionInfo);
353 Assert.assertNotNull("Should find OVSDB node after connect", node);
354 LOG.info("Connected to {}", connectionInfoToString(connectionInfo));
358 private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
359 Assert.assertTrue(deleteOvsdbNode(connectionInfo));
360 Node node = getOvsdbNode(connectionInfo);
361 Assert.assertNull("Should not find OVSDB node after disconnect", node);
362 //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull
363 LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo));
367 private String getControllerIPAddress() {
368 String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
369 if (addressString != null) {
371 if (InetAddress.getByName(addressString) != null) {
372 return addressString;
374 } catch (UnknownHostException e) {
375 LOG.error("Host {} is invalid", addressString);
379 addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
380 if (addressString != null) {
382 if (InetAddress.getByName(addressString) != null) {
383 return addressString;
385 } catch (UnknownHostException e) {
386 LOG.error("Host {} is invalid", addressString);
393 private short getControllerOFPort() {
394 short openFlowPort = Constants.OPENFLOW_PORT;
395 String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort");
396 if (portString != null) {
398 openFlowPort = Short.parseShort(portString);
399 } catch (NumberFormatException e) {
400 LOG.warn("Invalid port:{}, use default({})", portString,
407 private List<String> getControllersFromOvsdbNode(Node node) {
408 List<String> controllersStr = new ArrayList<>();
410 String controllerIpStr = getControllerIPAddress();
411 if (controllerIpStr != null) {
412 // If codepath makes it here, the ip address to be used was explicitly provided.
413 // Being so, also fetch openflowPort provided via ConfigProperties.
414 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
415 + ":" + controllerIpStr + ":" + getControllerOFPort());
417 // Check if ovsdb node has manager entries
418 OvsdbNodeAugmentation ovsdbNodeAugmentation = southbound.extractOvsdbNode(node);
419 if (ovsdbNodeAugmentation != null) {
420 List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
421 if (managerEntries != null && !managerEntries.isEmpty()) {
422 for (ManagerEntry managerEntry : managerEntries) {
423 if (managerEntry == null || managerEntry.getTarget() == null) {
426 String[] tokens = managerEntry.getTarget().getValue().split(":");
427 if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
428 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
429 + ":" + tokens[1] + ":" + getControllerOFPort());
430 } else if (tokens[0].equalsIgnoreCase("ptcp")) {
431 ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
432 if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
433 controllerIpStr = String.valueOf(connectionInfo.getLocalIp().getValue());
434 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
435 + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
437 LOG.warn("Ovsdb Node does not contain connection info: {}", node);
440 LOG.trace("Skipping manager entry {} for node {}",
441 managerEntry.getTarget(), node.getNodeId().getValue());
445 LOG.warn("Ovsdb Node does not contain manager entries : {}", node);
450 if (controllersStr.isEmpty()) {
451 // Neither user provided ip nor ovsdb node has manager entries. Lets use local machine ip address.
452 LOG.debug("Use local machine ip address as a OpenFlow Controller ip address");
453 controllerIpStr = getLocalControllerHostIpAddress();
454 if (controllerIpStr != null) {
455 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
456 + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
460 if (controllersStr.isEmpty()) {
461 LOG.warn("Failed to determine OpenFlow controller ip address");
462 } else if (LOG.isDebugEnabled()) {
463 controllerIpStr = "";
464 for (String currControllerIpStr : controllersStr) {
465 controllerIpStr += " " + currControllerIpStr;
467 LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
470 return controllersStr;
473 private String getLocalControllerHostIpAddress() {
474 String ipaddress = null;
476 for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();ifaces.hasMoreElements();){
477 NetworkInterface iface = ifaces.nextElement();
479 for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
480 InetAddress inetAddr = inetAddrs.nextElement();
481 if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
482 ipaddress = inetAddr.getHostAddress();
487 }catch (Exception e){
488 LOG.warn("Exception while fetching local host ip address ", e);
493 private String getControllerTarget(Node ovsdbNode) {
494 return getControllersFromOvsdbNode(ovsdbNode).get(0);
498 public void testAddDeleteOvsdbNode() throws InterruptedException {
499 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
500 connectOvsdbNode(connectionInfo);
501 ControllerEntry controllerEntry;
502 for (int i = 0; i < 10; i++) {
503 Node ovsdbNode = getOvsdbNode(connectionInfo);
504 Assert.assertNotNull("ovsdb node not found", ovsdbNode);
505 String controllerTarget = getControllerTarget(ovsdbNode);
506 Assert.assertNotNull("Failed to get controller target", controllerTarget);
507 OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
508 Assert.assertNotNull(bridge);
509 Assert.assertNotNull(bridge.getControllerEntry());
510 controllerEntry = bridge.getControllerEntry().iterator().next();
511 Assert.assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
512 if (controllerEntry.isIsConnected()) {
513 Assert.assertTrue(controllerEntry.isIsConnected());
519 Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
521 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
526 public void testOpenVSwitchOtherConfig() throws InterruptedException {
527 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
528 Node ovsdbNode = connectOvsdbNode(connectionInfo);
529 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
530 Assert.assertNotNull(ovsdbNodeAugmentation);
531 List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
532 if (otherConfigsList != null) {
533 for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) {
534 if (otherConfig.getOtherConfigKey().equals("local_ip")) {
535 LOG.info("local_ip: {}", otherConfig.getOtherConfigValue());
538 LOG.info("other_config {}:{}", otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
542 LOG.info("other_config is not present");
544 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
545 //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
548 private OvsdbTerminationPointAugmentationBuilder createGenericOvsdbTerminationPointAugmentationBuilder() {
549 OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder =
550 new OvsdbTerminationPointAugmentationBuilder();
551 ovsdbTerminationPointAugmentationBuilder.setInterfaceType(
552 new InterfaceTypeEntryBuilder()
554 SouthboundMapper.createInterfaceType("internal"))
555 .build().getInterfaceType());
556 return ovsdbTerminationPointAugmentationBuilder;
559 private boolean addTerminationPoint(final NodeId bridgeNodeId, final String portName,
560 final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder)
561 throws InterruptedException {
563 InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId);
564 NodeBuilder portNodeBuilder = new NodeBuilder();
565 NodeId portNodeId = SouthboundMapper.createManagedNodeId(portIid);
566 portNodeBuilder.setNodeId(portNodeId);
567 TerminationPointBuilder entry = new TerminationPointBuilder();
568 entry.setKey(new TerminationPointKey(new TpId(portName)));
569 entry.addAugmentation(
570 OvsdbTerminationPointAugmentation.class,
571 ovsdbTerminationPointAugmentationBuilder.build());
572 portNodeBuilder.setTerminationPoint(Lists.newArrayList(entry.build()));
573 boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
574 portIid, portNodeBuilder.build());
575 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
580 * Extract the <code>store</code> type data store contents for the particular bridge identified by
581 * <code>bridgeName</code>.
583 * @param connectionInfo The connection information.
584 * @param bridgeName The bridge name.
585 * @param store defined by the <code>LogicalDatastoreType</code> enumeration
586 * @return <code>store</code> type data store contents
588 private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName,
589 LogicalDatastoreType store) {
590 Node bridgeNode = getBridgeNode(connectionInfo, bridgeName, store);
591 Assert.assertNotNull(bridgeNode);
592 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
593 Assert.assertNotNull(ovsdbBridgeAugmentation);
594 return ovsdbBridgeAugmentation;
598 * extract the <code>LogicalDataStoreType.OPERATIONAL</code> type data store contents for the particular bridge
599 * identified by <code>bridgeName</code>
601 * @param connectionInfo The connection information.
602 * @param bridgeName The bridge name.
603 * @see <code>NetvirtIT.getBridge(ConnectionInfo, String, LogicalDatastoreType)</code>
604 * @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
606 private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName) {
607 return getBridge(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL);
611 * Extract the node contents from <code>store</code> type data store for the
612 * bridge identified by <code>bridgeName</code>
614 * @param connectionInfo The connection information.
615 * @param bridgeName The bridge name.
616 * @param store defined by the <code>LogicalDatastoreType</code> enumeration
617 * @return <code>store</code> type data store contents
619 private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) {
620 InstanceIdentifier<Node> bridgeIid =
621 SouthboundMapper.createInstanceIdentifier(connectionInfo,
622 new OvsdbBridgeName(bridgeName));
623 return mdsalUtils.read(store, bridgeIid);
626 private boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName)
627 throws InterruptedException {
629 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
630 SouthboundMapper.createInstanceIdentifier(connectionInfo,
631 new OvsdbBridgeName(bridgeName)));
632 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
636 private InstanceIdentifier<Node> getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) {
637 return SouthboundMapper.createInstanceIdentifier(connectionInfo,
638 bridge.getBridgeName());
641 private void netVirtAddPort(ConnectionInfo connectionInfo) throws InterruptedException {
642 OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
643 Assert.assertNotNull(bridge);
644 NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
645 connectionInfo, bridge.getBridgeName()));
646 OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
647 createGenericOvsdbTerminationPointAugmentationBuilder();
648 String portName = NetvirtITConstants.PORT_NAME;
649 ovsdbTerminationBuilder.setName(portName);
650 Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
651 InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
652 Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
653 Assert.assertNotNull(terminationPointNode);
657 * Test for basic southbound events to netvirt.
658 * <pre>The test will:
659 * - connect to an OVSDB node and verify it is added to operational
660 * - then verify that br-int was created on the node and stored in operational
661 * - a port is then added to the bridge to verify that it is ignored by netvirt
662 * - remove the bridge
663 * - remove the node and verify it is not in operational
665 * @throws InterruptedException
669 public void testNetVirt() throws InterruptedException {
670 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
671 Node ovsdbNode = connectOvsdbNode(connectionInfo);
674 // Verify the pipeline flows were installed
675 PipelineOrchestrator pipelineOrchestrator =
676 (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
677 assertNotNull("Could not find PipelineOrchestrator Service", pipelineOrchestrator);
678 Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
679 assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
680 LOG.info("testNetVirt: bridgeNode: {}", bridgeNode);
681 long datapathId = southbound.getDataPathId(bridgeNode);
682 assertNotEquals("datapathId was not found", datapathId, 0);
683 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
684 FlowUtils.createNodeBuilder(datapathId);
686 List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
687 List<Service> staticPipelineFound = Lists.newArrayList();
688 for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
689 if (staticPipeline.contains(service)) {
690 staticPipelineFound.add(service);
692 FlowBuilder flowBuilder = FlowUtils.getPipelineFlow(service.getTable(), (short)0);
693 Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
694 assertNotNull("Could not find flow in config", flow);
695 flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
696 assertNotNull("Could not find flow in operational", flow);
698 assertEquals("did not find all expected flows in static pipeline",
699 staticPipeline.size(), staticPipelineFound.size());
701 netVirtAddPort(connectionInfo);
703 Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
705 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
710 public void testNetVirt2() throws InterruptedException {
716 public void testReadOvsdbTopologyNodes() throws InterruptedException {
718 List<Node> ovsdbNodes = southbound.readOvsdbTopologyNodes();
719 for (Node node : ovsdbNodes) {
720 LOG.info(">>>>> node: {}", node);
724 private Flow getFlow (
725 FlowBuilder flowBuilder,
726 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder,
727 LogicalDatastoreType store)
728 throws InterruptedException {
731 for (int i = 0; i < 10; i++) {
732 flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
734 LOG.info("getFlow: flow({}): {}", store, flow);