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,
166 NetvirtITConstants.USERSPACE_ENABLED)
171 public Option getLoggingOption() {
173 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
174 "log4j.logger.org.opendaylight.ovsdb",
175 LogLevelOption.LogLevel.TRACE.name()),
176 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
177 logConfiguration(NetvirtIT.class),
178 LogLevelOption.LogLevel.INFO.name()),
179 //editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
180 // "log4j.logger.org.opendaylight.ovsdb.lib",
181 // LogLevelOption.LogLevel.INFO.name()),
182 super.getLoggingOption());
185 protected String usage() {
186 return "Integration Test needs a valid connection configuration as follows :\n"
187 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
188 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
191 private void getProperties() {
192 Properties props = System.getProperties();
193 addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS);
194 portStr = props.getProperty(NetvirtITConstants.SERVER_PORT, NetvirtITConstants.DEFAULT_SERVER_PORT);
195 connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE, "active");
196 controllerStr = props.getProperty(NetvirtITConstants.CONTROLLER_IPADDRESS, "0.0.0.0");
197 String userSpaceEnabled = props.getProperty(NetvirtITConstants.USERSPACE_ENABLED, "no");
198 LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}, " +
199 "userspace.enabled: {}",
200 connectionType, addressStr, portStr, controllerStr, userSpaceEnabled);
201 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
202 if (addressStr == null) {
210 public void setup() throws InterruptedException {
212 LOG.info("Skipping setUp, already initialized");
218 } catch (Exception e) {
224 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
225 if (addressStr == null) {
230 dataBroker = getDatabroker(getProviderContext());
231 mdsalUtils = new MdsalUtils(dataBroker);
232 assertNotNull("mdsalUtils should not be null", mdsalUtils);
233 assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
234 southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
235 assertNotNull("southbound should not be null", southbound);
239 private BindingAwareBroker.ProviderContext getProviderContext() {
240 BindingAwareBroker.ProviderContext providerContext = null;
241 for (int i=0; i < 60; i++) {
242 providerContext = getSession();
243 if (providerContext != null) {
248 } catch (InterruptedException e) {
253 assertNotNull("providercontext should not be null", providerContext);
254 /* One more second to let the provider finish initialization */
257 } catch (InterruptedException e) {
260 return providerContext;
263 private DataBroker getDatabroker(BindingAwareBroker.ProviderContext providerContext) {
264 DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
265 assertNotNull("dataBroker should not be null", dataBroker);
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) {
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 ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
309 InetAddress inetAddress = null;
311 inetAddress = InetAddress.getByName(addressStr);
312 } catch (UnknownHostException e) {
313 fail("Could not allocate InetAddress: " + e);
316 IpAddress address = SouthboundMapper.createIpAddress(inetAddress);
317 PortNumber port = new PortNumber(Integer.parseInt(portStr));
319 LOG.info("connectionInfo: {}", new ConnectionInfoBuilder()
320 .setRemoteIp(address)
323 return new ConnectionInfoBuilder()
324 .setRemoteIp(address)
329 private String connectionInfoToString(final ConnectionInfo connectionInfo) {
330 return String.valueOf(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
333 private boolean addOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
334 boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
335 SouthboundMapper.createInstanceIdentifier(connectionInfo),
336 SouthboundMapper.createNode(connectionInfo));
337 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
341 private Node getOvsdbNode(final ConnectionInfo connectionInfo) {
342 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
343 SouthboundMapper.createInstanceIdentifier(connectionInfo));
346 private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
347 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
348 SouthboundMapper.createInstanceIdentifier(connectionInfo));
349 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
353 private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
354 Assert.assertTrue(addOvsdbNode(connectionInfo));
355 Node node = getOvsdbNode(connectionInfo);
356 Assert.assertNotNull("Should find OVSDB node after connect", node);
357 LOG.info("Connected to {}", connectionInfoToString(connectionInfo));
361 private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
362 Assert.assertTrue(deleteOvsdbNode(connectionInfo));
363 Node node = getOvsdbNode(connectionInfo);
364 Assert.assertNull("Should not find OVSDB node after disconnect", node);
365 //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull
366 LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo));
370 private String getControllerIPAddress() {
371 String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
372 if (addressString != null) {
374 if (InetAddress.getByName(addressString) != null) {
375 return addressString;
377 } catch (UnknownHostException e) {
378 LOG.error("Host {} is invalid", addressString);
382 addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
383 if (addressString != null) {
385 if (InetAddress.getByName(addressString) != null) {
386 return addressString;
388 } catch (UnknownHostException e) {
389 LOG.error("Host {} is invalid", addressString);
396 private short getControllerOFPort() {
397 short openFlowPort = Constants.OPENFLOW_PORT;
398 String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort");
399 if (portString != null) {
401 openFlowPort = Short.parseShort(portString);
402 } catch (NumberFormatException e) {
403 LOG.warn("Invalid port:{}, use default({})", portString,
410 private List<String> getControllersFromOvsdbNode(Node node) {
411 List<String> controllersStr = new ArrayList<>();
413 String controllerIpStr = getControllerIPAddress();
414 if (controllerIpStr != null) {
415 // If codepath makes it here, the ip address to be used was explicitly provided.
416 // Being so, also fetch openflowPort provided via ConfigProperties.
417 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
418 + ":" + controllerIpStr + ":" + getControllerOFPort());
420 // Check if ovsdb node has manager entries
421 OvsdbNodeAugmentation ovsdbNodeAugmentation = southbound.extractOvsdbNode(node);
422 if (ovsdbNodeAugmentation != null) {
423 List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
424 if (managerEntries != null && !managerEntries.isEmpty()) {
425 for (ManagerEntry managerEntry : managerEntries) {
426 if (managerEntry == null || managerEntry.getTarget() == null) {
429 String[] tokens = managerEntry.getTarget().getValue().split(":");
430 if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
431 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
432 + ":" + tokens[1] + ":" + getControllerOFPort());
433 } else if (tokens[0].equalsIgnoreCase("ptcp")) {
434 ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
435 if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
436 controllerIpStr = String.valueOf(connectionInfo.getLocalIp().getValue());
437 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
438 + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
440 LOG.warn("Ovsdb Node does not contain connection info: {}", node);
443 LOG.trace("Skipping manager entry {} for node {}",
444 managerEntry.getTarget(), node.getNodeId().getValue());
448 LOG.warn("Ovsdb Node does not contain manager entries : {}", node);
453 if (controllersStr.isEmpty()) {
454 // Neither user provided ip nor ovsdb node has manager entries. Lets use local machine ip address.
455 LOG.debug("Use local machine ip address as a OpenFlow Controller ip address");
456 controllerIpStr = getLocalControllerHostIpAddress();
457 if (controllerIpStr != null) {
458 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
459 + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
463 if (controllersStr.isEmpty()) {
464 LOG.warn("Failed to determine OpenFlow controller ip address");
465 } else if (LOG.isDebugEnabled()) {
466 controllerIpStr = "";
467 for (String currControllerIpStr : controllersStr) {
468 controllerIpStr += " " + currControllerIpStr;
470 LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
473 return controllersStr;
476 private String getLocalControllerHostIpAddress() {
477 String ipaddress = null;
479 for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();ifaces.hasMoreElements();){
480 NetworkInterface iface = ifaces.nextElement();
482 for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
483 InetAddress inetAddr = inetAddrs.nextElement();
484 if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
485 ipaddress = inetAddr.getHostAddress();
490 }catch (Exception e){
491 LOG.warn("Exception while fetching local host ip address ", e);
496 private String getControllerTarget(Node ovsdbNode) {
497 return getControllersFromOvsdbNode(ovsdbNode).get(0);
501 public void testAddDeleteOvsdbNode() throws InterruptedException {
502 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
503 connectOvsdbNode(connectionInfo);
504 ControllerEntry controllerEntry;
505 for (int i = 0; i < 10; i++) {
506 Node ovsdbNode = getOvsdbNode(connectionInfo);
507 Assert.assertNotNull("ovsdb node not found", ovsdbNode);
508 String controllerTarget = getControllerTarget(ovsdbNode);
509 Assert.assertNotNull("Failed to get controller target", controllerTarget);
510 OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
511 Assert.assertNotNull(bridge);
512 Assert.assertNotNull(bridge.getControllerEntry());
513 controllerEntry = bridge.getControllerEntry().iterator().next();
514 Assert.assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
515 if (controllerEntry.isIsConnected()) {
516 Assert.assertTrue(controllerEntry.isIsConnected());
522 Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
524 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
529 public void testOpenVSwitchOtherConfig() throws InterruptedException {
530 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
531 Node ovsdbNode = connectOvsdbNode(connectionInfo);
532 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
533 Assert.assertNotNull(ovsdbNodeAugmentation);
534 List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
535 if (otherConfigsList != null) {
536 for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) {
537 if (otherConfig.getOtherConfigKey().equals("local_ip")) {
538 LOG.info("local_ip: {}", otherConfig.getOtherConfigValue());
541 LOG.info("other_config {}:{}", otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
545 LOG.info("other_config is not present");
547 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
548 //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
551 private OvsdbTerminationPointAugmentationBuilder createGenericOvsdbTerminationPointAugmentationBuilder() {
552 OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder =
553 new OvsdbTerminationPointAugmentationBuilder();
554 ovsdbTerminationPointAugmentationBuilder.setInterfaceType(
555 new InterfaceTypeEntryBuilder()
557 SouthboundMapper.createInterfaceType("internal"))
558 .build().getInterfaceType());
559 return ovsdbTerminationPointAugmentationBuilder;
562 private boolean addTerminationPoint(final NodeId bridgeNodeId, final String portName,
563 final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder)
564 throws InterruptedException {
566 InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId);
567 NodeBuilder portNodeBuilder = new NodeBuilder();
568 NodeId portNodeId = SouthboundMapper.createManagedNodeId(portIid);
569 portNodeBuilder.setNodeId(portNodeId);
570 TerminationPointBuilder entry = new TerminationPointBuilder();
571 entry.setKey(new TerminationPointKey(new TpId(portName)));
572 entry.addAugmentation(
573 OvsdbTerminationPointAugmentation.class,
574 ovsdbTerminationPointAugmentationBuilder.build());
575 portNodeBuilder.setTerminationPoint(Lists.newArrayList(entry.build()));
576 boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
577 portIid, portNodeBuilder.build());
578 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
583 * Extract the <code>store</code> type data store contents for the particular bridge identified by
584 * <code>bridgeName</code>.
586 * @param connectionInfo The connection information.
587 * @param bridgeName The bridge name.
588 * @param store defined by the <code>LogicalDatastoreType</code> enumeration
589 * @return <code>store</code> type data store contents
591 private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName,
592 LogicalDatastoreType store) {
593 Node bridgeNode = getBridgeNode(connectionInfo, bridgeName, store);
594 Assert.assertNotNull(bridgeNode);
595 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
596 Assert.assertNotNull(ovsdbBridgeAugmentation);
597 return ovsdbBridgeAugmentation;
601 * extract the <code>LogicalDataStoreType.OPERATIONAL</code> type data store contents for the particular bridge
602 * identified by <code>bridgeName</code>
604 * @param connectionInfo The connection information.
605 * @param bridgeName The bridge name.
606 * @see <code>NetvirtIT.getBridge(ConnectionInfo, String, LogicalDatastoreType)</code>
607 * @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
609 private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName) {
610 return getBridge(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL);
614 * Extract the node contents from <code>store</code> type data store for the
615 * bridge identified by <code>bridgeName</code>
617 * @param connectionInfo The connection information.
618 * @param bridgeName The bridge name.
619 * @param store defined by the <code>LogicalDatastoreType</code> enumeration
620 * @return <code>store</code> type data store contents
622 private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) {
623 InstanceIdentifier<Node> bridgeIid =
624 SouthboundMapper.createInstanceIdentifier(connectionInfo,
625 new OvsdbBridgeName(bridgeName));
626 return mdsalUtils.read(store, bridgeIid);
629 private boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName)
630 throws InterruptedException {
632 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
633 SouthboundMapper.createInstanceIdentifier(connectionInfo,
634 new OvsdbBridgeName(bridgeName)));
635 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
639 private InstanceIdentifier<Node> getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) {
640 return SouthboundMapper.createInstanceIdentifier(connectionInfo,
641 bridge.getBridgeName());
644 private void netVirtAddPort(ConnectionInfo connectionInfo) throws InterruptedException {
645 OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
646 Assert.assertNotNull(bridge);
647 NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
648 connectionInfo, bridge.getBridgeName()));
649 OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
650 createGenericOvsdbTerminationPointAugmentationBuilder();
651 String portName = NetvirtITConstants.PORT_NAME;
652 ovsdbTerminationBuilder.setName(portName);
653 Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
654 InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
655 Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
656 Assert.assertNotNull(terminationPointNode);
660 * Test for basic southbound events to netvirt.
661 * <pre>The test will:
662 * - connect to an OVSDB node and verify it is added to operational
663 * - then verify that br-int was created on the node and stored in operational
664 * - a port is then added to the bridge to verify that it is ignored by netvirt
665 * - remove the bridge
666 * - remove the node and verify it is not in operational
668 * @throws InterruptedException
671 public void testNetVirt() throws InterruptedException {
672 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
673 Node ovsdbNode = connectOvsdbNode(connectionInfo);
676 // Verify the pipeline flows were installed
677 PipelineOrchestrator pipelineOrchestrator =
678 (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
679 assertNotNull("Could not find PipelineOrchestrator Service", pipelineOrchestrator);
680 Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
681 assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
682 LOG.info("testNetVirt: bridgeNode: {}", bridgeNode);
683 long datapathId = southbound.getDataPathId(bridgeNode);
684 assertNotEquals("datapathId was not found", datapathId, 0);
685 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
686 FlowUtils.createNodeBuilder(datapathId);
688 List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
689 List<Service> staticPipelineFound = Lists.newArrayList();
690 for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
691 if (staticPipeline.contains(service)) {
692 staticPipelineFound.add(service);
694 FlowBuilder flowBuilder = FlowUtils.getPipelineFlow(service.getTable(), (short)0);
695 Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
696 assertNotNull("Could not find flow in config", flow);
697 flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
698 assertNotNull("Could not find flow in operational", flow);
700 assertEquals("did not find all expected flows in static pipeline",
701 staticPipeline.size(), staticPipelineFound.size());
703 netVirtAddPort(connectionInfo);
705 Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
707 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
712 public void testNetVirt2() throws InterruptedException {
718 public void testReadOvsdbTopologyNodes() throws InterruptedException {
720 List<Node> ovsdbNodes = southbound.readOvsdbTopologyNodes();
721 for (Node node : ovsdbNodes) {
722 LOG.info(">>>>> node: {}", node);
726 private Flow getFlow (
727 FlowBuilder flowBuilder,
728 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder,
729 LogicalDatastoreType store)
730 throws InterruptedException {
733 for (int i = 0; i < 10; i++) {
734 flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
736 LOG.info("getFlow: flow({}): {}", store, flow);