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.NetvirtProvidersProvider;
48 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
49 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
50 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
51 import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
52 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.InterfaceTypeEntryBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
76 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
77 import org.ops4j.pax.exam.Configuration;
78 import org.ops4j.pax.exam.Option;
79 import org.ops4j.pax.exam.junit.PaxExam;
80 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
81 import org.ops4j.pax.exam.options.MavenUrlReference;
82 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
83 import org.ops4j.pax.exam.spi.reactors.PerClass;
84 import org.slf4j.Logger;
85 import org.slf4j.LoggerFactory;
88 * Integration tests for netvirt
90 * @author Sam Hague (shague@redhat.com)
92 @RunWith(PaxExam.class)
93 @ExamReactorStrategy(PerClass.class)
94 public class NetvirtIT extends AbstractMdsalTestBase {
95 private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
96 private static final int OVSDB_UPDATE_TIMEOUT = 1000;
97 private static DataBroker dataBroker = null;
98 private static String addressStr;
99 private static String portStr;
100 private static String connectionType;
101 private static String controllerStr;
102 private static AtomicBoolean setup = new AtomicBoolean(false);
103 private static MdsalUtils mdsalUtils = null;
104 private static Southbound southbound = null;
105 private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
108 public String getModuleName() {
109 return "netvirt-providers-impl";
113 public String getInstanceName() {
114 return "netvirt-providers-default";
118 public MavenUrlReference getFeatureRepo() {
120 .groupId("org.opendaylight.ovsdb")
121 .artifactId("features-ovsdb")
122 .classifier("features")
124 .versionAsInProject();
128 public String getFeatureName() {
129 return "odl-ovsdb-openstack";
134 public Option[] config() {
135 Option[] parentOptions = super.config();
136 Option[] propertiesOptions = getPropertiesOptions();
137 Option[] otherOptions = getOtherOptions();
138 Option[] options = new Option[parentOptions.length + propertiesOptions.length + otherOptions.length];
139 System.arraycopy(parentOptions, 0, options, 0, parentOptions.length);
140 System.arraycopy(propertiesOptions, 0, options, parentOptions.length, propertiesOptions.length);
141 System.arraycopy(otherOptions, 0, options, parentOptions.length + propertiesOptions.length,
142 otherOptions.length);
146 private Option[] getOtherOptions() {
147 return new Option[] {
149 mavenBundle("org.opendaylight.ovsdb", "utils.mdsal-openflow")
150 .version(asInProject())
153 mavenBundle("org.opendaylight.ovsdb", "utils.config")
154 .version(asInProject())
156 configureConsole().startLocalConsole(),
157 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
162 public Option[] getPropertiesOptions() {
163 return new Option[] {
164 propagateSystemProperties(NetvirtITConstants.SERVER_IPADDRESS,
165 NetvirtITConstants.SERVER_PORT, NetvirtITConstants.CONNECTION_TYPE,
166 NetvirtITConstants.CONTROLLER_IPADDRESS,
167 NetvirtITConstants.USERSPACE_ENABLED)
172 public Option getLoggingOption() {
174 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
175 "log4j.logger.org.opendaylight.ovsdb",
176 LogLevelOption.LogLevel.TRACE.name()),
177 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
178 logConfiguration(NetvirtIT.class),
179 LogLevelOption.LogLevel.INFO.name()),
180 editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
181 "log4j.logger.org.opendaylight.ovsdb.lib",
182 LogLevelOption.LogLevel.INFO.name()),
183 super.getLoggingOption());
186 protected String usage() {
187 return "Integration Test needs a valid connection configuration as follows :\n"
188 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
189 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
192 private void getProperties() {
193 Properties props = System.getProperties();
194 addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS);
195 portStr = props.getProperty(NetvirtITConstants.SERVER_PORT, NetvirtITConstants.DEFAULT_SERVER_PORT);
196 connectionType = props.getProperty(NetvirtITConstants.CONNECTION_TYPE, "active");
197 controllerStr = props.getProperty(NetvirtITConstants.CONTROLLER_IPADDRESS, "0.0.0.0");
198 String userSpaceEnabled = props.getProperty(NetvirtITConstants.USERSPACE_ENABLED, "no");
199 LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}, " +
200 "userspace.enabled: {}",
201 connectionType, addressStr, portStr, controllerStr, userSpaceEnabled);
202 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
203 if (addressStr == null) {
211 public void setup() throws InterruptedException {
213 LOG.info("Skipping setUp, already initialized");
219 } catch (Exception e) {
225 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_ACTIVE)) {
226 if (addressStr == null) {
231 dataBroker = getDatabroker(getProviderContext());
232 mdsalUtils = new MdsalUtils(dataBroker);
233 assertNotNull("mdsalUtils should not be null", mdsalUtils);
234 assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
235 southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
236 assertNotNull("southbound should not be null", southbound);
240 private BindingAwareBroker.ProviderContext getProviderContext() {
241 BindingAwareBroker.ProviderContext providerContext = null;
242 for (int i=0; i < 60; i++) {
243 providerContext = getSession();
244 if (providerContext != null) {
249 } catch (InterruptedException e) {
254 assertNotNull("providercontext should not be null", providerContext);
255 /* One more second to let the provider finish initialization */
258 } catch (InterruptedException e) {
261 return providerContext;
264 private DataBroker getDatabroker(BindingAwareBroker.ProviderContext providerContext) {
265 DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
266 assertNotNull("dataBroker should not be null", dataBroker);
270 private Boolean getNetvirtTopology() {
271 LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
272 Boolean found = false;
273 final TopologyId topologyId = new TopologyId(new Uri(NETVIRT_TOPOLOGY_ID));
274 InstanceIdentifier<Topology> path =
275 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
276 for (int i = 0; i < 60; i++) {
277 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
278 if (topology != null) {
279 LOG.info("getNetvirtTopology: found {}...", NETVIRT_TOPOLOGY_ID);
283 LOG.info("getNetvirtTopology: still looking ({})...", i);
286 } catch (InterruptedException e) {
295 * Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
296 * 6640. This test will wait for incoming connections for {@link NetvirtITConstants#CONNECTION_INIT_TIMEOUT} ms.
298 * @throws InterruptedException
302 public void testPassiveNode() throws InterruptedException {
303 if (connectionType.equalsIgnoreCase(NetvirtITConstants.CONNECTION_TYPE_PASSIVE)) {
304 //Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server.
305 Thread.sleep(NetvirtITConstants.CONNECTION_INIT_TIMEOUT);
309 private ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
310 InetAddress inetAddress = null;
312 inetAddress = InetAddress.getByName(addressStr);
313 } catch (UnknownHostException e) {
314 fail("Could not allocate InetAddress: " + e);
317 IpAddress address = SouthboundMapper.createIpAddress(inetAddress);
318 PortNumber port = new PortNumber(Integer.parseInt(portStr));
320 LOG.info("connectionInfo: {}", new ConnectionInfoBuilder()
321 .setRemoteIp(address)
324 return new ConnectionInfoBuilder()
325 .setRemoteIp(address)
330 private String connectionInfoToString(final ConnectionInfo connectionInfo) {
331 return String.valueOf(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
334 private boolean addOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
335 boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
336 SouthboundMapper.createInstanceIdentifier(connectionInfo),
337 SouthboundMapper.createNode(connectionInfo));
338 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
342 private Node getOvsdbNode(final ConnectionInfo connectionInfo) {
343 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
344 SouthboundMapper.createInstanceIdentifier(connectionInfo));
347 private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
348 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
349 SouthboundMapper.createInstanceIdentifier(connectionInfo));
350 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
354 private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
355 Assert.assertTrue(addOvsdbNode(connectionInfo));
356 Node node = getOvsdbNode(connectionInfo);
357 Assert.assertNotNull("Should find OVSDB node after connect", node);
358 LOG.info("Connected to {}", connectionInfoToString(connectionInfo));
362 private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
363 Assert.assertTrue(deleteOvsdbNode(connectionInfo));
364 Node node = getOvsdbNode(connectionInfo);
365 Assert.assertNull("Should not find OVSDB node after disconnect", node);
366 //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull
367 LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo));
371 private String getControllerIPAddress() {
372 String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
373 if (addressString != null) {
375 if (InetAddress.getByName(addressString) != null) {
376 return addressString;
378 } catch (UnknownHostException e) {
379 LOG.error("Host {} is invalid", addressString);
383 addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
384 if (addressString != null) {
386 if (InetAddress.getByName(addressString) != null) {
387 return addressString;
389 } catch (UnknownHostException e) {
390 LOG.error("Host {} is invalid", addressString);
397 private short getControllerOFPort() {
398 short openFlowPort = Constants.OPENFLOW_PORT;
399 String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort");
400 if (portString != null) {
402 openFlowPort = Short.parseShort(portString);
403 } catch (NumberFormatException e) {
404 LOG.warn("Invalid port:{}, use default({})", portString,
411 private List<String> getControllersFromOvsdbNode(Node node) {
412 List<String> controllersStr = new ArrayList<>();
414 String controllerIpStr = getControllerIPAddress();
415 if (controllerIpStr != null) {
416 // If codepath makes it here, the ip address to be used was explicitly provided.
417 // Being so, also fetch openflowPort provided via ConfigProperties.
418 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
419 + ":" + controllerIpStr + ":" + getControllerOFPort());
421 // Check if ovsdb node has manager entries
422 OvsdbNodeAugmentation ovsdbNodeAugmentation = southbound.extractOvsdbNode(node);
423 if (ovsdbNodeAugmentation != null) {
424 List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
425 if (managerEntries != null && !managerEntries.isEmpty()) {
426 for (ManagerEntry managerEntry : managerEntries) {
427 if (managerEntry == null || managerEntry.getTarget() == null) {
430 String[] tokens = managerEntry.getTarget().getValue().split(":");
431 if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
432 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
433 + ":" + tokens[1] + ":" + getControllerOFPort());
434 } else if (tokens[0].equalsIgnoreCase("ptcp")) {
435 ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
436 if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
437 controllerIpStr = String.valueOf(connectionInfo.getLocalIp().getValue());
438 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
439 + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
441 LOG.warn("Ovsdb Node does not contain connection info: {}", node);
444 LOG.trace("Skipping manager entry {} for node {}",
445 managerEntry.getTarget(), node.getNodeId().getValue());
449 LOG.warn("Ovsdb Node does not contain manager entries : {}", node);
454 if (controllersStr.isEmpty()) {
455 // Neither user provided ip nor ovsdb node has manager entries. Lets use local machine ip address.
456 LOG.debug("Use local machine ip address as a OpenFlow Controller ip address");
457 controllerIpStr = getLocalControllerHostIpAddress();
458 if (controllerIpStr != null) {
459 controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
460 + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
464 if (controllersStr.isEmpty()) {
465 LOG.warn("Failed to determine OpenFlow controller ip address");
466 } else if (LOG.isDebugEnabled()) {
467 controllerIpStr = "";
468 for (String currControllerIpStr : controllersStr) {
469 controllerIpStr += " " + currControllerIpStr;
471 LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
474 return controllersStr;
477 private String getLocalControllerHostIpAddress() {
478 String ipaddress = null;
480 for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();ifaces.hasMoreElements();){
481 NetworkInterface iface = ifaces.nextElement();
483 for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
484 InetAddress inetAddr = inetAddrs.nextElement();
485 if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
486 ipaddress = inetAddr.getHostAddress();
491 }catch (Exception e){
492 LOG.warn("Exception while fetching local host ip address ", e);
497 private String getControllerTarget(Node ovsdbNode) {
498 return getControllersFromOvsdbNode(ovsdbNode).get(0);
502 public void testAddDeleteOvsdbNode() throws InterruptedException {
503 LOG.info("testAddDeleteOvsdbNode enter 3");
504 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
505 connectOvsdbNode(connectionInfo);
506 ControllerEntry controllerEntry;
507 for (int i = 0; i < 10; i++) {
508 LOG.info("testAddDeleteOvsdbNode ({}): looking for controller", i);
509 Node ovsdbNode = getOvsdbNode(connectionInfo);
510 Assert.assertNotNull("ovsdb node not found", ovsdbNode);
511 String controllerTarget = getControllerTarget(ovsdbNode);
512 Assert.assertNotNull("Failed to get controller target", controllerTarget);
513 OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
514 Assert.assertNotNull(bridge);
515 Assert.assertNotNull(bridge.getControllerEntry());
516 controllerEntry = bridge.getControllerEntry().iterator().next();
517 Assert.assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
518 if (controllerEntry.isIsConnected()) {
519 Assert.assertTrue(controllerEntry.isIsConnected());
525 Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
527 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
532 public void testOpenVSwitchOtherConfig() throws InterruptedException {
533 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
534 Node ovsdbNode = connectOvsdbNode(connectionInfo);
535 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
536 Assert.assertNotNull(ovsdbNodeAugmentation);
537 List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
538 if (otherConfigsList != null) {
539 for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) {
540 if (otherConfig.getOtherConfigKey().equals("local_ip")) {
541 LOG.info("local_ip: {}", otherConfig.getOtherConfigValue());
544 LOG.info("other_config {}:{}", otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
548 LOG.info("other_config is not present");
550 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
551 //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
554 private OvsdbTerminationPointAugmentationBuilder createGenericOvsdbTerminationPointAugmentationBuilder() {
555 OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder =
556 new OvsdbTerminationPointAugmentationBuilder();
557 ovsdbTerminationPointAugmentationBuilder.setInterfaceType(
558 new InterfaceTypeEntryBuilder()
560 SouthboundMapper.createInterfaceType("internal"))
561 .build().getInterfaceType());
562 return ovsdbTerminationPointAugmentationBuilder;
565 private boolean addTerminationPoint(final NodeId bridgeNodeId, final String portName,
566 final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder)
567 throws InterruptedException {
569 InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId);
570 NodeBuilder portNodeBuilder = new NodeBuilder();
571 NodeId portNodeId = SouthboundMapper.createManagedNodeId(portIid);
572 portNodeBuilder.setNodeId(portNodeId);
573 TerminationPointBuilder entry = new TerminationPointBuilder();
574 entry.setKey(new TerminationPointKey(new TpId(portName)));
575 entry.addAugmentation(
576 OvsdbTerminationPointAugmentation.class,
577 ovsdbTerminationPointAugmentationBuilder.build());
578 portNodeBuilder.setTerminationPoint(Lists.newArrayList(entry.build()));
579 boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
580 portIid, portNodeBuilder.build());
581 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
586 * Extract the <code>store</code> type data store contents for the particular bridge identified by
587 * <code>bridgeName</code>.
589 * @param connectionInfo The connection information.
590 * @param bridgeName The bridge name.
591 * @param store defined by the <code>LogicalDatastoreType</code> enumeration
592 * @return <code>store</code> type data store contents
594 private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName,
595 LogicalDatastoreType store) {
596 Node bridgeNode = getBridgeNode(connectionInfo, bridgeName, store);
597 Assert.assertNotNull(bridgeNode);
598 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
599 Assert.assertNotNull(ovsdbBridgeAugmentation);
600 return ovsdbBridgeAugmentation;
604 * extract the <code>LogicalDataStoreType.OPERATIONAL</code> type data store contents for the particular bridge
605 * identified by <code>bridgeName</code>
607 * @param connectionInfo The connection information.
608 * @param bridgeName The bridge name.
609 * @see <code>NetvirtIT.getBridge(ConnectionInfo, String, LogicalDatastoreType)</code>
610 * @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
612 private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName) {
613 return getBridge(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL);
617 * Extract the node contents from <code>store</code> type data store for the
618 * bridge identified by <code>bridgeName</code>
620 * @param connectionInfo The connection information.
621 * @param bridgeName The bridge name.
622 * @param store defined by the <code>LogicalDatastoreType</code> enumeration
623 * @return <code>store</code> type data store contents
625 private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) {
626 InstanceIdentifier<Node> bridgeIid =
627 SouthboundMapper.createInstanceIdentifier(connectionInfo,
628 new OvsdbBridgeName(bridgeName));
629 return mdsalUtils.read(store, bridgeIid);
632 private boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName)
633 throws InterruptedException {
635 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
636 SouthboundMapper.createInstanceIdentifier(connectionInfo,
637 new OvsdbBridgeName(bridgeName)));
638 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
642 private InstanceIdentifier<Node> getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) {
643 return SouthboundMapper.createInstanceIdentifier(connectionInfo,
644 bridge.getBridgeName());
647 private void netVirtAddPort(ConnectionInfo connectionInfo) throws InterruptedException {
648 OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
649 Assert.assertNotNull(bridge);
650 NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
651 connectionInfo, bridge.getBridgeName()));
652 OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
653 createGenericOvsdbTerminationPointAugmentationBuilder();
654 String portName = NetvirtITConstants.PORT_NAME;
655 ovsdbTerminationBuilder.setName(portName);
656 Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
657 InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
658 Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
659 Assert.assertNotNull(terminationPointNode);
663 * Test for basic southbound events to netvirt.
664 * <pre>The test will:
665 * - connect to an OVSDB node and verify it is added to operational
666 * - then verify that br-int was created on the node and stored in operational
667 * - a port is then added to the bridge to verify that it is ignored by netvirt
668 * - remove the bridge
669 * - remove the node and verify it is not in operational
671 * @throws InterruptedException
674 public void testNetVirt() throws InterruptedException {
675 LOG.info("testNetVirt: starting test 2");
676 ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
677 Node ovsdbNode = connectOvsdbNode(connectionInfo);
678 LOG.info("testNetVirt: should be connected");
681 LOG.info("testNetVirt: should really be connected after sleep");
682 // Verify the pipeline flows were installed
683 PipelineOrchestrator pipelineOrchestrator =
684 (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
685 assertNotNull("Could not find PipelineOrchestrator Service", pipelineOrchestrator);
686 Node bridgeNode = southbound.getBridgeNode(ovsdbNode, NetvirtITConstants.INTEGRATION_BRIDGE_NAME);
687 assertNotNull("bridge " + NetvirtITConstants.INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
688 LOG.info("testNetVirt: bridgeNode: {}", bridgeNode);
689 long datapathId = southbound.getDataPathId(bridgeNode);
690 assertNotEquals("datapathId was not found", datapathId, 0);
692 //TODO add check for controller connection
693 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
694 FlowUtils.createNodeBuilder(datapathId);
696 List<Service> staticPipeline = pipelineOrchestrator.getStaticPipeline();
697 List<Service> staticPipelineFound = Lists.newArrayList();
698 for (Service service : pipelineOrchestrator.getServiceRegistry().keySet()) {
699 if (staticPipeline.contains(service)) {
700 staticPipelineFound.add(service);
702 FlowBuilder flowBuilder = FlowUtils.getPipelineFlow(service.getTable(), (short)0);
703 Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
704 assertNotNull("Could not find flow in config", flow);
705 //Thread.sleep(1000);
706 //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
707 //assertNotNull("Could not find flow in operational", flow);
709 assertEquals("did not find all expected flows in static pipeline",
710 staticPipeline.size(), staticPipelineFound.size());
712 netVirtAddPort(connectionInfo);
714 Assert.assertTrue(deleteBridge(connectionInfo, NetvirtITConstants.INTEGRATION_BRIDGE_NAME));
716 Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
721 public void testNetVirt2() throws InterruptedException {
727 public void testReadOvsdbTopologyNodes() throws InterruptedException {
729 List<Node> ovsdbNodes = southbound.readOvsdbTopologyNodes();
730 for (Node node : ovsdbNodes) {
731 LOG.info(">>>>> node: {}", node);
735 private Flow getFlow (
736 FlowBuilder flowBuilder,
737 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder,
738 LogicalDatastoreType store)
739 throws InterruptedException {
742 for (int i = 0; i < 10; i++) {
743 LOG.info("getFlow {}-{}: looking for flowBuilder: {}, nodeBuilder: {}",
744 i, store, flowBuilder.build(), nodeBuilder.build());
745 flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
747 LOG.info("getFlow: found flow({}): {}", store, flow);