/* * Copyright (c) 2015 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.ovsdb.southbound.it; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.ops4j.pax.exam.CoreOptions.composite; import static org.ops4j.pax.exam.CoreOptions.maven; import static org.ops4j.pax.exam.CoreOptions.vmOption; import static org.ops4j.pax.exam.CoreOptions.when; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.io.File; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import javax.inject.Inject; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase; import org.opendaylight.ovsdb.southbound.SouthboundConstants; import org.opendaylight.ovsdb.southbound.SouthboundMapper; import org.opendaylight.ovsdb.southbound.SouthboundProvider; import org.opendaylight.ovsdb.southbound.SouthboundUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbFailModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIdsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.DatapathTypeEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.InterfaceTypeEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIdsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceOtherConfigsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIdsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortOtherConfigs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortOtherConfigsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Trunks; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.TrunksBuilder; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; import org.ops4j.pax.exam.karaf.options.LogLevelOption; import org.ops4j.pax.exam.options.MavenUrlReference; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerClass; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Integration tests for southbound-impl * * @author Sam Hague (shague@redhat.com) */ @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) public class SouthboundIT extends AbstractMdsalTestBase { private static final String EXPECTED_VALUES_KEY = "ExpectedValuesKey"; private static final String INPUT_VALUES_KEY = "InputValuesKey"; private static final String NETDEV_DP_TYPE = "netdev"; private static final Logger LOG = LoggerFactory.getLogger(SouthboundIT.class); private static final int OVSDB_UPDATE_TIMEOUT = 1000; public static final int NUM_THREADS = 4; private static DataBroker dataBroker = null; private static String addressStr; private static String portStr; private static String connectionType; private static Boolean setup = false; private static MdsalUtils mdsalUtils = null; // TODO Constants copied frmo AbstractConfigTestBase, need to be removed (see TODO below) private static final String PAX_EXAM_UNPACK_DIRECTORY = "target/exam"; private static final String KARAF_DEBUG_PORT = "5005"; private static final String KARAF_DEBUG_PROP = "karaf.debug"; private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack"; @Inject private BundleContext bundleContext; @Configuration public Option[] config() { // TODO Figure out how to use the parent Karaf setup, then just use super.config() Option[] options = new Option[] { when(Boolean.getBoolean(KARAF_DEBUG_PROP)) .useOptions(KarafDistributionOption.debugConfiguration(KARAF_DEBUG_PORT, true)), karafDistributionConfiguration().frameworkUrl(getKarafDistro()) .unpackDirectory(new File(PAX_EXAM_UNPACK_DIRECTORY)) .useDeployFolder(false), when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()), // Works only if we don't specify the feature repo and name getLoggingOption()}; Option[] propertyOptions = getPropertiesOptions(); Option[] otherOptions = getOtherOptions(); Option[] combinedOptions = new Option[options.length + propertyOptions.length + otherOptions.length]; System.arraycopy(options, 0, combinedOptions, 0, options.length); System.arraycopy(propertyOptions, 0, combinedOptions, options.length, propertyOptions.length); System.arraycopy(otherOptions, 0, combinedOptions, options.length + propertyOptions.length, otherOptions.length); return combinedOptions; } private Option[] getOtherOptions() { return new Option[] { vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"), keepRuntimeFolder() }; } @Override public String getKarafDistro() { return maven() .groupId("org.opendaylight.ovsdb") .artifactId("southbound-karaf") .versionAsInProject() .type("zip") .getURL(); } @Override public String getModuleName() { return "southbound-impl"; } @Override public String getInstanceName() { return "southbound-default"; } @Override public MavenUrlReference getFeatureRepo() { return maven() .groupId("org.opendaylight.ovsdb") .artifactId("southbound-features") .classifier("features") .type("xml") .versionAsInProject(); } @Override public String getFeatureName() { return "odl-ovsdb-southbound-impl-ui"; } protected String usage() { return "Integration Test needs a valid connection configuration as follows :\n" + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n" + "passive connection : mvn -Dovsdbserver.connection=passive verify\n"; } @Override public Option getLoggingOption() { return composite( editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG, "log4j.logger.org.opendaylight.ovsdb", LogLevelOption.LogLevel.TRACE.name()), super.getLoggingOption()); } private Option[] getPropertiesOptions() { Properties props = new Properties(System.getProperties()); String addressStr = props.getProperty(SouthboundITConstants.SERVER_IPADDRESS, SouthboundITConstants.DEFAULT_SERVER_IPADDRESS); String portStr = props.getProperty(SouthboundITConstants.SERVER_PORT, SouthboundITConstants.DEFAULT_SERVER_PORT); String connectionType = props.getProperty(SouthboundITConstants.CONNECTION_TYPE, SouthboundITConstants.CONNECTION_TYPE_ACTIVE); LOG.info("getPropertiesOptions: Using the following properties: mode= {}, ip:port= {}:{}", connectionType, addressStr, portStr); Option[] options = new Option[] { editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES, SouthboundITConstants.SERVER_IPADDRESS, addressStr), editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES, SouthboundITConstants.SERVER_PORT, portStr), editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES, SouthboundITConstants.CONNECTION_TYPE, connectionType), }; return options; } @Before @Override public void setup() throws InterruptedException { if (setup) { LOG.info("Skipping setUp, already initialized"); return; } try { super.setup(); } catch (Exception e) { e.printStackTrace(); } //dataBroker = getSession().getSALService(DataBroker.class); Thread.sleep(3000); dataBroker = SouthboundProvider.getDb(); Assert.assertNotNull("db should not be null", dataBroker); addressStr = bundleContext.getProperty(SouthboundITConstants.SERVER_IPADDRESS); portStr = bundleContext.getProperty(SouthboundITConstants.SERVER_PORT); connectionType = bundleContext.getProperty(SouthboundITConstants.CONNECTION_TYPE); LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}", connectionType, addressStr, portStr); if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_ACTIVE)) { if (addressStr == null) { fail(usage()); } } mdsalUtils = new MdsalUtils(dataBroker); setup = true; } /** * Test passive connection mode. The southbound starts in a listening mode waiting for connections on port * 6640. This test will wait for incoming connections for {@link SouthboundITConstants.CONNECTION_INIT_TIMEOUT} ms. * * @throws InterruptedException */ @Test public void testPassiveNode() throws InterruptedException { if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_PASSIVE)) { //Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server. Thread.sleep(SouthboundITConstants.CONNECTION_INIT_TIMEOUT); } } private ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) { InetAddress inetAddress = null; try { inetAddress = InetAddress.getByName(addressStr); } catch (UnknownHostException e) { fail("Could not allocate InetAddress: " + e); } IpAddress address = SouthboundMapper.createIpAddress(inetAddress); PortNumber port = new PortNumber(Integer.parseInt(portStr)); LOG.info("connectionInfo: {}", new ConnectionInfoBuilder() .setRemoteIp(address) .setRemotePort(port) .build()); return new ConnectionInfoBuilder() .setRemoteIp(address) .setRemotePort(port) .build(); } private String connectionInfoToString(final ConnectionInfo connectionInfo) { return new String(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue(); } @Test public void testNetworkTopology() throws InterruptedException { NetworkTopology networkTopology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(NetworkTopology.class)); Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.CONFIGURATION, networkTopology); networkTopology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(NetworkTopology.class)); Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.OPERATIONAL, networkTopology); } @Test public void testOvsdbTopology() throws InterruptedException { InstanceIdentifier path = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)); Topology topology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path); Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.CONFIGURATION, topology); topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path); Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.OPERATIONAL, topology); } private boolean addOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException { InstanceIdentifier iid = createInstanceIdentifier(connectionInfo); // Check that the node doesn't already exist (we don't support connecting twice) Assert.assertNull("The OVSDB node has already been added", mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, iid)); boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, iid, createNode(connectionInfo)); Thread.sleep(OVSDB_UPDATE_TIMEOUT); return result; } private InstanceIdentifier createInstanceIdentifier( ConnectionInfo connectionInfo) { return InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) .child(Node.class, createNodeKey(connectionInfo.getRemoteIp(),connectionInfo.getRemotePort())); } private Node getOvsdbNode(final ConnectionInfo connectionInfo) { Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, createInstanceIdentifier(connectionInfo)); return node; } private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException { boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, createInstanceIdentifier(connectionInfo)); Thread.sleep(OVSDB_UPDATE_TIMEOUT); return result; } private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException { Assert.assertTrue(addOvsdbNode(connectionInfo)); Node node = getOvsdbNode(connectionInfo); Assert.assertNotNull(node); LOG.info("Connected to {}", connectionInfoToString(connectionInfo)); return node; } private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException { Assert.assertTrue(deleteOvsdbNode(connectionInfo)); Node node = getOvsdbNode(connectionInfo); Assert.assertNull(node); //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo)); return true; } @Test public void testAddDeleteOvsdbNode() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); Node ovsdbNode = connectOvsdbNode(connectionInfo); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testDpdkSwitch() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); Node ovsdbNode = connectOvsdbNode(connectionInfo); List datapathTypeEntries = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class) .getDatapathTypeEntry(); if (datapathTypeEntries == null) { LOG.info("DPDK not supported on this node."); } else { Class dpType = null; String dpTypeStr = null; for (DatapathTypeEntry dpTypeEntry : datapathTypeEntries) { dpType = dpTypeEntry.getDatapathType(); dpTypeStr = SouthboundConstants.DATAPATH_TYPE_MAP.get(dpType); LOG.info("dp type is {}", dpTypeStr); if (dpTypeStr.equals(NETDEV_DP_TYPE)) { LOG.info("Found a DPDK node; adding a corresponding netdev device"); InstanceIdentifier bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME)); NodeId bridgeNodeId = createManagedNodeId(bridgeIid); addBridge(connectionInfo, bridgeIid, SouthboundITConstants.BRIDGE_NAME, bridgeNodeId, false, null, true, dpType, null, null, null); // Verify that the device is netdev OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); Assert.assertEquals(dpTypeStr, bridge.getDatapathType()); // Add dpdk port final String TEST_PORT_NAME = "testDPDKPort"; OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericDpdkOvsdbTerminationPointAugmentationBuilder(TEST_PORT_NAME); Assert.assertTrue(addTerminationPoint(bridgeNodeId, TEST_PORT_NAME, ovsdbTerminationBuilder)); // Verify that DPDK port was created InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); Assert.assertNotNull(terminationPointNode); // Verify that each termination point has DPDK ifType Class dpdkIfType = SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP .get("dpdk"); Class opPort = null; List terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint .getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(TEST_PORT_NAME)) { opPort = ovsdbTerminationPointAugmentation .getInterfaceType(); Assert.assertEquals(dpdkIfType, opPort); } } Assert.assertTrue(deleteBridge(connectionInfo)); break; } } } Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testOvsdbNodeOvsVersion() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); Node ovsdbNode = connectOvsdbNode(connectionInfo); OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class); Assert.assertNotNull(ovsdbNodeAugmentation); assertNotNull(ovsdbNodeAugmentation.getOvsVersion()); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testOpenVSwitchOtherConfig() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); Node ovsdbNode = connectOvsdbNode(connectionInfo); OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class); Assert.assertNotNull(ovsdbNodeAugmentation); List otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs(); if (otherConfigsList != null) { for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) { if (otherConfig.getOtherConfigKey().equals("local_ip")) { LOG.info("local_ip: {}", otherConfig.getOtherConfigValue()); break; } else { LOG.info("other_config {}:{}", otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue()); } } } else { LOG.info("other_config is not present"); } Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testOvsdbBridgeControllerInfo() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr,portStr); Node ovsdbNode = connectOvsdbNode(connectionInfo); String controllerTarget = SouthboundUtil.getControllerTarget(ovsdbNode); assertNotNull("Failed to get controller target", controllerTarget); List setControllerEntry = createControllerEntry(controllerTarget); Uri setUri = new Uri(controllerTarget); Assert.assertTrue(addBridge(connectionInfo, null, SouthboundITConstants.BRIDGE_NAME,null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, setControllerEntry, null)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull("bridge was not found: " + SouthboundITConstants.BRIDGE_NAME, bridge); Assert.assertNotNull("ControllerEntry was not found: " + setControllerEntry.iterator().next(), bridge.getControllerEntry()); List getControllerEntries = bridge.getControllerEntry(); for (ControllerEntry entry : getControllerEntries) { if (entry.getTarget() != null) { Assert.assertEquals(setUri.toString(), entry.getTarget().toString()); } } Assert.assertTrue(deleteBridge(connectionInfo)); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } private List createControllerEntry(String controllerTarget) { List controllerEntriesList = new ArrayList(); controllerEntriesList.add(new ControllerEntryBuilder() .setTarget(new Uri(controllerTarget)) .build()); return controllerEntriesList; } private void setManagedBy(final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, final ConnectionInfo connectionInfo) { InstanceIdentifier connectionNodePath = createInstanceIdentifier(connectionInfo); ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath)); } private List createMdsalProtocols() { List protocolList = new ArrayList(); ImmutableBiMap> mapper = SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse(); protocolList.add(new ProtocolEntryBuilder(). setProtocol((Class) mapper.get("OpenFlow13")).build()); return protocolList; } private OvsdbTerminationPointAugmentationBuilder createGenericOvsdbTerminationPointAugmentationBuilder() { OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); ovsdbTerminationPointAugmentationBuilder.setInterfaceType( new InterfaceTypeEntryBuilder() .setInterfaceType( SouthboundMapper.createInterfaceType("internal")) .build().getInterfaceType()); return ovsdbTerminationPointAugmentationBuilder; } private OvsdbTerminationPointAugmentationBuilder createGenericDpdkOvsdbTerminationPointAugmentationBuilder( final String portName) { OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); ovsdbTerminationBuilder.setName(portName); Class ifType = SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP .get("dpdk"); ovsdbTerminationBuilder.setInterfaceType(ifType); return ovsdbTerminationBuilder; } private boolean addTerminationPoint(final NodeId bridgeNodeId, final String portName, final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder) throws InterruptedException { InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId); NodeBuilder portNodeBuilder = new NodeBuilder(); NodeId portNodeId = SouthboundMapper.createManagedNodeId(portIid); portNodeBuilder.setNodeId(portNodeId); TerminationPointBuilder entry = new TerminationPointBuilder(); entry.setKey(new TerminationPointKey(new TpId(portName))); entry.addAugmentation( OvsdbTerminationPointAugmentation.class, ovsdbTerminationPointAugmentationBuilder.build()); portNodeBuilder.setTerminationPoint(Lists.newArrayList(entry.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); return result; } /* * base method for adding test bridges. Other helper methods used to create bridges should utilize this method. * * @param connectionInfo * @param bridgeIid if passed null, one is created * @param bridgeName cannot be null * @param bridgeNodeId if passed null, one is created based on bridgeIid * @param setProtocolEntries toggles whether default protocol entries are set for the bridge * @param failMode toggles whether default fail mode is set for the bridge * @param setManagedBy toggles whether to setManagedBy for the bridge * @param dpType if passed null, this parameter is ignored * @param externalIds if passed null, this parameter is ignored * @param otherConfig if passed null, this parameter is ignored * @return success of bridge addition * @throws InterruptedException */ private boolean addBridge(final ConnectionInfo connectionInfo, InstanceIdentifier bridgeIid, final String bridgeName, NodeId bridgeNodeId, final boolean setProtocolEntries, final Class failMode, final boolean setManagedBy, final Class dpType, final List externalIds, final List controllerEntries, final List otherConfigs) throws InterruptedException { NodeBuilder bridgeNodeBuilder = new NodeBuilder(); if (bridgeIid == null) { bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); } if (bridgeNodeId == null) { bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid); } bridgeNodeBuilder.setNodeId(bridgeNodeId); OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder(); ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName)); if (setProtocolEntries) { ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols()); } if (failMode != null) { ovsdbBridgeAugmentationBuilder.setFailMode(failMode); } if (setManagedBy) { setManagedBy(ovsdbBridgeAugmentationBuilder, connectionInfo); } if (dpType != null) { ovsdbBridgeAugmentationBuilder.setDatapathType(dpType); } if (externalIds != null) { ovsdbBridgeAugmentationBuilder.setBridgeExternalIds(externalIds); } if (controllerEntries != null) { ovsdbBridgeAugmentationBuilder.setControllerEntry(controllerEntries); } if (otherConfigs != null) { ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(otherConfigs); } bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build()); LOG.debug("Built with the intent to store bridge data {}", ovsdbBridgeAugmentationBuilder.toString()); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); return result; } private boolean addBridge(final ConnectionInfo connectionInfo, final String bridgeName) throws InterruptedException { return addBridge(connectionInfo, null, bridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null); } private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo) { return getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME); } /** * Extract the store type data store contents for the particular bridge identified by * bridgeName. * * @param connectionInfo * @param bridgeName * @param store defined by the LogicalDatastoreType enumeration * @return store type data store contents */ private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) { Node bridgeNode = getBridgeNode(connectionInfo, bridgeName, store); Assert.assertNotNull(bridgeNode); OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class); Assert.assertNotNull(ovsdbBridgeAugmentation); return ovsdbBridgeAugmentation; } /** * extract the LogicalDataStoreType.OPERATIONAL type data store contents for the particular bridge * identified by bridgeName * * @param connectionInfo * @param bridgeName * @see SouthboundIT.getBridge(ConnectionInfo, String, LogicalDatastoreType) * @return LogicalDatastoreType.OPERATIONAL type data store contents */ private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName) { return getBridge(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL); } /** * Extract the node contents from store type data store for the * bridge identified by bridgeName * * @param connectionInfo * @param bridgeName * @param store defined by the LogicalDatastoreType enumeration * @return store type data store contents */ private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) { InstanceIdentifier bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); return mdsalUtils.read(store, bridgeIid); } /** * Extract the node contents from LogicalDataStoreType.OPERATIONAL data store for the * bridge identified by bridgeName * * @param connectionInfo * @param bridgeName * @return LogicalDatastoreType.OPERATIONAL type data store contents */ private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName) { return getBridgeNode(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL); } private boolean deleteBridge(ConnectionInfo connectionInfo) throws InterruptedException { return deleteBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME); } private boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName) throws InterruptedException { boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName))); Thread.sleep(OVSDB_UPDATE_TIMEOUT); return result; } @Test public void testAddDeleteBridge() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); Node ovsdbNode = connectOvsdbNode(connectionInfo); Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); LOG.info("bridge: {}", bridge); Assert.assertTrue(deleteBridge(connectionInfo)); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo)); } private InstanceIdentifier getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) { return createInstanceIdentifier(connectionInfo, bridge.getBridgeName()); } /** * Extracts the TerminationPointAugmentation for the index TerminationPoint * on bridgeName * * @param connectionInfo * @param bridgeName * @param store * @param index * @return */ private OvsdbTerminationPointAugmentation getOvsdbTerminationPointAugmentation( ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store, int index ) { List tpList = getBridgeNode(connectionInfo, bridgeName, store).getTerminationPoint(); if (tpList == null) { return null; } return ((OvsdbTerminationPointAugmentation) tpList.get(index) .getAugmentation(OvsdbTerminationPointAugmentation.class)); } @Test public void testCRDTerminationPointOfPort() throws InterruptedException { final Long OFPORT_EXPECTED = new Long(45002); ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // CREATE Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); LOG.info("bridge: {}", bridge); NodeId nodeId = SouthboundMapper.createManagedNodeId(createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); String portName = "testOfPort"; ovsdbTerminationBuilder.setName(portName); ovsdbTerminationBuilder.setOfport(OFPORT_EXPECTED); Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder)); InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); Assert.assertNotNull(terminationPointNode); // READ List terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { Long ofPort = ovsdbTerminationPointAugmentation.getOfport(); // if ephemeral port 45002 is in use, ofPort is set to 1 Assert.assertTrue(ofPort.equals(OFPORT_EXPECTED) || ofPort.equals(new Long(1))); LOG.info("ofPort: {}", ofPort); } } // UPDATE- Not Applicable. From the OpenVSwitch Documentation: // "A client should ideally set this column’s value in the same database transaction that it uses to create // the interface." // DELETE Assert.assertTrue(deleteBridge(connectionInfo)); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testCRDTerminationPointOfPortRequest() throws InterruptedException { final Long OFPORT_EXPECTED = new Long(45008); final Long OFPORT_INPUT = new Long(45008); ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // CREATE Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); NodeId nodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); String portName = "testOfPortRequest"; ovsdbTerminationBuilder.setName(portName); Integer ofPortRequestExpected = OFPORT_EXPECTED.intValue(); ovsdbTerminationBuilder.setOfport(OFPORT_INPUT); ovsdbTerminationBuilder.setOfportRequest(ofPortRequestExpected); Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder)); InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); Assert.assertNotNull(terminationPointNode); // READ List terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { Long ofPort = ovsdbTerminationPointAugmentation.getOfport(); // if ephemeral port 45008 is in use, ofPort is set to 1 Assert.assertTrue(ofPort.equals(OFPORT_EXPECTED) || ofPort.equals(new Long(1))); LOG.info("ofPort: {}", ofPort); Integer ofPortRequest = ovsdbTerminationPointAugmentation.getOfportRequest(); Assert.assertTrue(ofPortRequest.equals(ofPortRequestExpected)); LOG.info("ofPortRequest: {}", ofPortRequest); } } // UPDATE- Not Applicable. From the OpenVSwitch documentation: // "A client should ideally set this column’s value in the same database transaction that it uses to create // the interface. " // DELETE Assert.assertTrue(deleteBridge(connectionInfo)); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } /* * Generates the test cases involved in testing PortExternalIds. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT port external_ids, or EXPECTED port external_ids * INPUT is the List we use when calling * TerminationPointAugmentationBuilder.setPortExternalIds() * EXPECTED is the List we expect to receive after calling * TerminationPointAugmentationBuilder.getPortExternalIds() */ private Map>> generatePortExternalIdsTestCases() { Map>> testMap = new HashMap>>(); final String PORT_EXTERNAL_ID_KEY = "PortExternalIdKey"; final String PORT_EXTERNAL_ID_VALUE = "PortExternalIdValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneExternalId // Test Type: Positive // Description: Create a termination point with one PortExternalIds // Expected: A port is created with the single external_ids specified below final String testOneExternalIdName = "TestOneExternalId"; int externalIdCounter = 0; List oneExternalId = (List) Lists.newArrayList( (new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneExternalIdName, PORT_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testOneExternalIdName, PORT_EXTERNAL_ID_VALUE, externalIdCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneExternalId); testCase.put(INPUT_VALUES_KEY, oneExternalId); testMap.put(testOneExternalIdName, testCase); // Test Case 2: TestFiveExternalId // Test Type: Positive // Description: Create a termination point with multiple (five) PortExternalIds // Expected: A port is created with the five external_ids specified below final String testFiveExternalIdName = "TestFiveExternalId"; externalIdCounter = 0; List fiveExternalId = (List) Lists.newArrayList( (new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, PORT_EXTERNAL_ID_VALUE, externalIdCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fiveExternalId); testCase.put(INPUT_VALUES_KEY, fiveExternalId); testMap.put(testFiveExternalIdName, testCase); // Test Case 3: TestOneGoodExternalIdOneMalformedExternalIdValue // Test Type: Negative // Description: // One perfectly fine PortExternalId // (TestOneGoodExternalIdOneMalformedExternalIdValue_PortExternalIdKey_1, // TestOneGoodExternalIdOneMalformedExternalId_PortExternalIdValue_1) // and one malformed PortExternalId which only has key specified // (TestOneGoodExternalIdOneMalformedExternalIdValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A port is created without any external_ids final String testOneGoodExternalIdOneMalformedExternalIdValueName = "TestOneGoodExternalIdOneMalformedExternalIdValue"; externalIdCounter = 0; PortExternalIds oneGood = new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, GOOD_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, GOOD_VALUE, externalIdCounter)) .build(); PortExternalIds oneBad = new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, NO_VALUE_FOR_KEY, ++externalIdCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodExternalIdOneMalformedExternalIdValueName, testCase); // Test Case 4: TestOneGoodExternalIdOneMalformedExternalIdKey // Test Type: Negative // Description: // One perfectly fine PortExternalId // (TestOneGoodExternalIdOneMalformedExternalIdValue_PortExternalIdKey_1, // TestOneGoodExternalIdOneMalformedExternalId_PortExternalIdValue_1) // and one malformed PortExternalId which only has key specified // (UNSPECIFIED, // TestOneGoodExternalIdOneMalformedExternalIdKey_NoKeyForValue_2) // Expected: A port is created without any external_ids final String testOneGoodExternalIdOneMalformedExternalIdKeyName = "TestOneGoodExternalIdOneMalformedExternalIdKey"; externalIdCounter = 0; oneGood = new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, GOOD_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, GOOD_VALUE, externalIdCounter)) .build(); oneBad = new PortExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, NO_KEY_FOR_VALUE, ++externalIdCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodExternalIdOneMalformedExternalIdKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDPortExternalIds() * This is helper test method to compare a test "set" of BridgeExternalIds against an expected "set" */ private void assertExpectedPortExternalIdsExist( List expected, List test ) { if (expected != null) { for (PortExternalIds expectedExternalId : expected) { Assert.assertTrue(test.contains(expectedExternalId)); } } } /* * Tests the CRUD operations for Port * external_ids. * * @see SouthboundIT.generatePortExternalIdsTestCases() for * specific test case information */ @Test public void testCRUDTerminationPointPortExternalIds() throws InterruptedException, ExecutionException { final String TEST_PREFIX = "CRUDTPPortExternalIds"; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. // updateToTestCases represent the new value after the update has been // performed. Map>> updateFromTestCases = generatePortExternalIdsTestCases(); Map>> updateToTestCases = generatePortExternalIdsTestCases(); Map> updateFromTestCase; List updateFromInputExternalIds; List updateFromExpectedExternalIds; Map> updateToTestCase; List updateToInputExternalIds; List updateToExpectedExternalIds; String testBridgeName; String testPortName; int counter = 1; // multihreads the test using NUM_THREADS ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get( updateFromTestCaseKey); updateFromInputExternalIds = updateFromTestCase.get( INPUT_VALUES_KEY); updateFromExpectedExternalIds = updateFromTestCase.get( EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testPortName = testBridgeName = String.format("%s_%s_%d", TEST_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputExternalIds = updateToTestCase.get( INPUT_VALUES_KEY); updateToExpectedExternalIds = updateToTestCase.get( EXPECTED_VALUES_KEY); TestCRUDTerminationPointPortExternalIdsRunnable testRunnable = new TestCRUDTerminationPointPortExternalIdsRunnable( connectionInfo, testBridgeName, testPortName, updateFromInputExternalIds, updateFromExpectedExternalIds, updateToInputExternalIds, updateToExpectedExternalIds); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDTerminationPointPortExternalIdsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; String testPortName; List updateFromInputExternalIds; List updateFromExpectedExternalIds; List updateToInputExternalIds; List updateToExpectedExternalIds; public TestCRUDTerminationPointPortExternalIdsRunnable( ConnectionInfo connectionInfo, String testBridgeName, String testPortName, List updateFromInputExternalIds, List updateFromExpectedExternalIds, List updateToInputExternalIds, List updateToExpectedExternalIds) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.testPortName = testPortName; this.updateFromInputExternalIds = updateFromInputExternalIds; this.updateFromExpectedExternalIds = updateFromExpectedExternalIds; this.updateToInputExternalIds = updateToInputExternalIds; this.updateToExpectedExternalIds = updateToExpectedExternalIds; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } private void test() throws InterruptedException { final int TERMINATION_POINT_TEST_INDEX = 0; // CREATE: Create the test bridge Assert.assertTrue(addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null)); NodeId testBridgeNodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, new OvsdbBridgeName(testBridgeName))); OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); tpCreateAugmentationBuilder.setName(testPortName); tpCreateAugmentationBuilder.setPortExternalIds(updateFromInputExternalIds); Assert.assertTrue(addTerminationPoint(testBridgeNodeId, testPortName, tpCreateAugmentationBuilder)); // READ: Read the test port and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateFromConfigurationExternalIds = updateFromConfigurationTerminationPointAugmentation .getPortExternalIds(); assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds); OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateFromOperationalExternalIds = updateFromOperationalTerminationPointAugmenation .getPortExternalIds(); assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateFromOperationalExternalIds); // UPDATE: update the external_ids testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setPortExternalIds(updateToInputExternalIds); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test port and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateToConfigurationExternalIds = updateToConfigurationTerminationPointAugmentation .getPortExternalIds(); assertExpectedPortExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds); assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds); OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateToOperationalExternalIds = updateToOperationalTerminationPointAugmentation.getPortExternalIds(); if (updateFromExpectedExternalIds != null) { assertExpectedPortExternalIdsExist(updateToExpectedExternalIds, updateToOperationalExternalIds); assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateToOperationalExternalIds); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } /* * Generates the test cases involved in testing InterfaceExternalIds. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT interface external_ids, or EXPECTED interface external_ids * INPUT is the List we use when calling * TerminationPointAugmentationBuilder.setInterfaceExternalIds() * EXPECTED is the List we expect to receive after calling * TerminationPointAugmentationBuilder.getInterfaceExternalIds() */ private Map>> generateInterfaceExternalIdsTestCases() { Map>> testMap = new HashMap>>(); final String INTERFACE_EXTERNAL_ID_KEY = "IntExternalIdKey"; final String INTERFACE_EXTERNAL_ID_VALUE = "IntExternalIdValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneExternalId // Test Type: Positive // Description: Create a termination point with one InterfaceExternalIds // Expected: A termination point is created with the single external_ids specified below final String testOneExternalIdName = "TestOneExternalId"; int externalIdCounter = 0; List oneExternalId = (List) Lists.newArrayList( (new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneExternalIdName, INTERFACE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testOneExternalIdName, INTERFACE_EXTERNAL_ID_VALUE, externalIdCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneExternalId); testCase.put(INPUT_VALUES_KEY, oneExternalId); testMap.put(testOneExternalIdName, testCase); // Test Case 2: TestFiveExternalId // Test Type: Positive // Description: Create a termination point with multiple (five) InterfaceExternalIds // Expected: A termination point is created with the five external_ids specified below final String testFiveExternalIdName = "TestFiveExternalId"; externalIdCounter = 0; List fiveExternalId = (List) Lists.newArrayList( (new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, INTERFACE_EXTERNAL_ID_VALUE, externalIdCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fiveExternalId); testCase.put(INPUT_VALUES_KEY, fiveExternalId); testMap.put(testFiveExternalIdName, testCase); // Test Case 3: TestOneGoodExternalIdOneMalformedExternalIdValue // Test Type: Negative // Description: // One perfectly fine InterfaceExternalId // (TestOneGoodExternalIdOneMalformedExternalIdValue_IntExternalIdKey_1, // TestOneGoodExternalIdOneMalformedExternalId_IntExternalIdValue_1) // and one malformed PortExternalId which only has key specified // (TestOneGoodExternalIdOneMalformedExternalIdValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A termination point is created without any external_ids final String testOneGoodExternalIdOneMalformedExternalIdValueName = "TestOneGoodExternalIdOneMalformedExternalIdValue"; externalIdCounter = 0; InterfaceExternalIds oneGood = new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, GOOD_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, GOOD_VALUE, externalIdCounter)) .build(); InterfaceExternalIds oneBad = new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, NO_VALUE_FOR_KEY, ++externalIdCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodExternalIdOneMalformedExternalIdValueName, testCase); // Test Case 4: TestOneGoodExternalIdOneMalformedExternalIdKey // Test Type: Negative // Description: // One perfectly fine InterfaceExternalId // (TestOneGoodExternalIdOneMalformedExternalIdValue_IntExternalIdKey_1, // TestOneGoodExternalIdOneMalformedExternalId_IntExternalIdValue_1) // and one malformed BridgeExternalId which only has key specified // (UNSPECIFIED, // TestOneGoodExternalIdOneMalformedExternalIdKey_NoKeyForValue_2) // Expected: A termination point is created without any external_ids final String testOneGoodExternalIdOneMalformedExternalIdKeyName = "TestOneGoodExternalIdOneMalformedExternalIdKey"; externalIdCounter = 0; oneGood = new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, GOOD_KEY, ++externalIdCounter)) .setExternalIdValue(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, GOOD_VALUE, externalIdCounter)) .build(); oneBad = new InterfaceExternalIdsBuilder() .setExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, NO_KEY_FOR_VALUE, ++externalIdCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodExternalIdOneMalformedExternalIdKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDInterfaceExternalIds() * This is helper test method to compare a test "set" of InterfaceExternalIds against an expected "set" */ private void assertExpectedInterfaceExternalIdsExist( List expected, List test ) { if (expected != null) { for (InterfaceExternalIds expectedExternalId : expected) { Assert.assertTrue(test.contains(expectedExternalId)); } } } /* * Tests the CRUD operations for Interface external_ids. * * @see SouthboundIT.generateInterfaceExternalIdsTestCases() for specific test case information */ @Test public void testCRUDTerminationPointInterfaceExternalIds() throws InterruptedException, ExecutionException { final String TEST_PREFIX = "CRUDTPInterfaceExternalIds"; final int TERMINATION_POINT_TEST_INDEX = 0; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after // the update has been performed. Map>> updateFromTestCases = generateInterfaceExternalIdsTestCases(); Map>> updateToTestCases = generateInterfaceExternalIdsTestCases(); Map> updateFromTestCase; List updateFromInputExternalIds; List updateFromExpectedExternalIds; Map> updateToTestCase; List updateToInputExternalIds; List updateToExpectedExternalIds; String testBridgeName; String testPortName; int counter = 1; // multihreads the test using NUM_THREADS ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); updateFromInputExternalIds = updateFromTestCase.get(INPUT_VALUES_KEY); updateFromExpectedExternalIds = updateFromTestCase.get(EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testPortName = testBridgeName = String.format("%s_%s_%d", TEST_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputExternalIds = updateToTestCase.get(INPUT_VALUES_KEY); updateToExpectedExternalIds = updateToTestCase.get(EXPECTED_VALUES_KEY); TestCRUDTerminationPointInterfaceExternalIdsRunnable testRunnable = new TestCRUDTerminationPointInterfaceExternalIdsRunnable( connectionInfo, testBridgeName, testPortName, updateFromInputExternalIds, updateFromExpectedExternalIds, updateToInputExternalIds, updateToExpectedExternalIds); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDTerminationPointInterfaceExternalIdsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; String testPortName; List updateFromInputExternalIds; List updateFromExpectedExternalIds; List updateToInputExternalIds; List updateToExpectedExternalIds; TestCRUDTerminationPointInterfaceExternalIdsRunnable( ConnectionInfo connectionInfo, String testBridgeName, String testPortName, List updateFromInputExternalIds, List updateFromExpectedExternalIds, List updateToInputExternalIds, List updateToExpectedExternalIds) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.testPortName = testPortName; this.updateFromInputExternalIds = updateFromInputExternalIds; this.updateFromExpectedExternalIds = updateFromExpectedExternalIds; this.updateToInputExternalIds = updateToInputExternalIds; this.updateToExpectedExternalIds = updateToExpectedExternalIds; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } public void test() throws InterruptedException { final int TERMINATION_POINT_TEST_INDEX = 0; // CREATE: Create the test interface Assert.assertTrue(addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null)); NodeId testBridgeNodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, new OvsdbBridgeName(testBridgeName))); OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); tpCreateAugmentationBuilder.setName(testPortName); tpCreateAugmentationBuilder.setInterfaceExternalIds(updateFromInputExternalIds); Assert.assertTrue(addTerminationPoint(testBridgeNodeId, testPortName, tpCreateAugmentationBuilder)); // READ: Read the test interface and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateFromConfigurationExternalIds = updateFromConfigurationTerminationPointAugmentation .getInterfaceExternalIds(); assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds); OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateFromOperationalExternalIds = updateFromOperationalTerminationPointAugmenation .getInterfaceExternalIds(); assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds, updateFromOperationalExternalIds); // UPDATE: update the external_ids testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setInterfaceExternalIds(updateToInputExternalIds); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test interface and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateToConfigurationExternalIds = updateToConfigurationTerminationPointAugmentation .getInterfaceExternalIds(); assertExpectedInterfaceExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds); assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds); OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateToOperationalExternalIds = updateToOperationalTerminationPointAugmentation .getInterfaceExternalIds(); if (updateFromExpectedExternalIds != null) { assertExpectedInterfaceExternalIdsExist(updateToExpectedExternalIds, updateToOperationalExternalIds); assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds, updateToOperationalExternalIds); } else { Assert.assertNull(updateToOperationalExternalIds); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } /* * Generates the test cases involved in testing TP Options. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT TP Options, or EXPECTED TP Options * INPUT is the List we use when calling * TerminationPointAugmentationBuilder.setOptions() * EXPECTED is the List we expect to receive after calling * TerminationPointAugmentationBuilder.getOptions() */ private Map>> generateTerminationPointOptionsTestCases() { Map>> testMap = new HashMap>>(); final String TP_OPTIONS_KEY = "TPOptionsKey"; final String TP_OPTIONS_VALUE = "TPOptionsValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneOptions // Test Type: Positive // Description: Create a termination point with one Options // Expected: A termination point is created with the single Options specified below final String testOneOptionsName = "TestOneOptions"; int optionsCounter = 0; List oneOptions = (List) Lists.newArrayList( (new OptionsBuilder() .setOption(String.format(FORMAT_STR, testOneOptionsName, TP_OPTIONS_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testOneOptionsName, TP_OPTIONS_VALUE, optionsCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneOptions); testCase.put(INPUT_VALUES_KEY, oneOptions); testMap.put(testOneOptionsName, testCase); // Test Case 2: TestFiveOptions // Test Type: Positive // Description: Create a termination point with multiple (five) Options // Expected: A termination point is created with the five options specified below final String testFiveOptionsName = "TestFiveOptions"; optionsCounter = 0; List fiveOptions = (List) Lists.newArrayList( (new OptionsBuilder() .setOption(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_VALUE, optionsCounter)) .build()), (new OptionsBuilder() .setOption(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_VALUE, optionsCounter)) .build()), (new OptionsBuilder() .setOption(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_VALUE, optionsCounter)) .build()), (new OptionsBuilder() .setOption(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_VALUE, optionsCounter)) .build()), (new OptionsBuilder() .setOption(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testFiveOptionsName, TP_OPTIONS_VALUE, optionsCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fiveOptions); testCase.put(INPUT_VALUES_KEY, fiveOptions); testMap.put(testFiveOptionsName, testCase); // Test Case 3: TestOneGoodOptionsOneMalformedOptionsValue // Test Type: Negative // Description: // One perfectly fine Options // (TestOneGoodOptionsOneMalformedOptionsValue_OptionsKey_1, // TestOneGoodOptionsOneMalformedOptions_OptionsValue_1) // and one malformed Options which only has key specified // (TestOneGoodOptionsOneMalformedOptionsValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A termination point is created without any options final String testOneGoodOptionsOneMalformedOptionsValueName = "TestOneGoodOptionsOneMalformedOptionsValue"; optionsCounter = 0; Options oneGood = new OptionsBuilder() .setOption(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsValueName, GOOD_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsValueName, GOOD_VALUE, optionsCounter)) .build(); Options oneBad = new OptionsBuilder() .setOption(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsValueName, NO_VALUE_FOR_KEY, ++optionsCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodOptionsOneMalformedOptionsValueName, testCase); // Test Case 4: TestOneGoodOptionsOneMalformedOptionsKey // Test Type: Negative // Description: // One perfectly fine Options // (TestOneGoodOptionsOneMalformedOptionsValue_OptionsKey_1, // TestOneGoodOptionsOneMalformedOptions_OptionsValue_1) // and one malformed Options which only has key specified // (UNSPECIFIED, // TestOneGoodOptionsOneMalformedOptionsKey_NoKeyForValue_2) // Expected: A termination point is created without any options final String testOneGoodOptionsOneMalformedOptionsKeyName = "TestOneGoodOptionsOneMalformedOptionsKey"; optionsCounter = 0; oneGood = new OptionsBuilder() .setOption(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsKeyName, GOOD_KEY, ++optionsCounter)) .setValue(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsKeyName, GOOD_VALUE, optionsCounter)) .build(); oneBad = new OptionsBuilder() .setOption(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsKeyName, NO_KEY_FOR_VALUE, ++optionsCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodOptionsOneMalformedOptionsKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDTerminationPointOptions() * This is helper test method to compare a test "set" of Options against an expected "set" */ private void assertExpectedOptionsExist( List expected, List test ) { if (expected != null) { for (Options expectedOption : expected) { Assert.assertTrue(test.contains(expectedOption)); } } } /* * Tests the CRUD operations for TerminationPoint options. * * @see SouthboundIT.generateTerminationPointOptions() for specific test case information */ @Test public void testCRUDTerminationPointOptions() throws InterruptedException { final String TEST_PREFIX = "CRUDTPOptions"; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after // the update has been performed. Map>> updateFromTestCases = generateTerminationPointOptionsTestCases(); Map>> updateToTestCases = generateTerminationPointOptionsTestCases(); Map> updateFromTestCase; List updateFromInputOptions; List updateFromExpectedOptions; Map> updateToTestCase; List updateToInputOptions; List updateToExpectedOptions; String testBridgeName; String testPortName; int counter = 1; ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); updateFromInputOptions = updateFromTestCase.get(INPUT_VALUES_KEY); updateFromExpectedOptions = updateFromTestCase.get(EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testPortName = testBridgeName = String.format("%s_%s_%d", TEST_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputOptions = updateToTestCase.get(INPUT_VALUES_KEY); updateToExpectedOptions = updateToTestCase.get(EXPECTED_VALUES_KEY); TestCRUDTerminationPointOptionsRunnable testRunnable = new TestCRUDTerminationPointOptionsRunnable( connectionInfo, testBridgeName, testPortName, updateFromInputOptions, updateFromExpectedOptions, updateToInputOptions, updateToExpectedOptions); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDTerminationPointOptionsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; String testPortName; List updateFromInputOptions; List updateFromExpectedOptions; List updateToInputOptions; List updateToExpectedOptions; TestCRUDTerminationPointOptionsRunnable( ConnectionInfo connectionInfo, String testBridgeName, String testPortName, List updateFromInputOptions, List updateFromExpectedOptions, List updateToInputOptions, List updateToExpectedOptions) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.testPortName = testPortName; this.updateFromInputOptions = updateFromInputOptions; this.updateFromExpectedOptions = updateFromExpectedOptions; this.updateToInputOptions = updateToInputOptions; this.updateToExpectedOptions = updateToExpectedOptions; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } public void test() throws InterruptedException { final int TERMINATION_POINT_TEST_INDEX = 0; // CREATE: Create the test interface Assert.assertTrue(addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null)); NodeId testBridgeNodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, new OvsdbBridgeName(testBridgeName))); OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); tpCreateAugmentationBuilder.setName(testPortName); tpCreateAugmentationBuilder.setOptions(updateFromInputOptions); Assert.assertTrue(addTerminationPoint(testBridgeNodeId, testPortName, tpCreateAugmentationBuilder)); // READ: Read the test interface and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateFromConfigurationOptions = updateFromConfigurationTerminationPointAugmentation .getOptions(); assertExpectedOptionsExist(updateFromExpectedOptions, updateFromConfigurationOptions); OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateFromOperationalOptions = updateFromOperationalTerminationPointAugmenation .getOptions(); assertExpectedOptionsExist(updateFromExpectedOptions, updateFromOperationalOptions); // UPDATE: update the external_ids testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setOptions(updateToInputOptions); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test interface and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateToConfigurationOptions = updateToConfigurationTerminationPointAugmentation .getOptions(); assertExpectedOptionsExist(updateToExpectedOptions, updateToConfigurationOptions); assertExpectedOptionsExist(updateFromExpectedOptions, updateToConfigurationOptions); OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateToOperationalOptions = updateToOperationalTerminationPointAugmentation .getOptions(); if (updateFromExpectedOptions != null) { assertExpectedOptionsExist(updateToExpectedOptions, updateToOperationalOptions); assertExpectedOptionsExist(updateFromExpectedOptions, updateToOperationalOptions); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } /* * Generates the test cases involved in testing Interface other_configs. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT interface other_configs, or EXPECTED interface other_configs * INPUT is the List we use when calling * TerminationPointAugmentationBuilder.setInterfaceOtherConfigs() * EXPECTED is the List we expect to receive after calling * TerminationPointAugmentationBuilder.getInterfaceOtherConfigs() */ private Map>> generateInterfaceOtherConfigsTestCases() { Map>> testMap = new HashMap>>(); final String INT_OTHER_CONFIGS_KEY = "IntOtherConfigsKey"; final String INT_OTHER_CONFIGS_VALUE = "IntOtherConfigsValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneOtherConfigs // Test Type: Positive // Description: Create an interface with one other_Configs // Expected: An interface is created with the single other_configs specified below final String testOneOtherConfigsName = "TestOneInterfaceOtherConfigs"; int otherConfigsCounter = 0; List oneOtherConfigs = (List) Lists.newArrayList( (new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneOtherConfigsName, INT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testOneOtherConfigsName, INT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneOtherConfigs); testCase.put(INPUT_VALUES_KEY, oneOtherConfigs); testMap.put(testOneOtherConfigsName, testCase); // Test Case 2: TestFiveInterfaceOtherConfigs // Test Type: Positive // Description: Create a termination point with multiple (five) InterfaceOtherConfigs // Expected: A termination point is created with the five InterfaceOtherConfigs specified below final String testFiveInterfaceOtherConfigsName = "TestFiveInterfaceOtherConfigs"; otherConfigsCounter = 0; List fiveInterfaceOtherConfigs = (List) Lists.newArrayList( (new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFiveInterfaceOtherConfigsName, INT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fiveInterfaceOtherConfigs); testCase.put(INPUT_VALUES_KEY, fiveInterfaceOtherConfigs); testMap.put(testFiveInterfaceOtherConfigsName, testCase); // Test Case 3: TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValue // Test Type: Negative // Description: // One perfectly fine InterfaceOtherConfigs // (TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValue_InterfaceOtherConfigsKey_1, // TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigs_InterfaceOtherConfigsValue_1) // and one malformed InterfaceOtherConfigs which only has key specified // (TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A termination point is created without any InterfaceOtherConfigs final String testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValueName = "TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValue"; otherConfigsCounter = 0; InterfaceOtherConfigs oneGood = new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValueName, GOOD_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValueName, GOOD_VALUE, otherConfigsCounter)) .build(); InterfaceOtherConfigs oneBad = new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValueName, NO_VALUE_FOR_KEY, ++otherConfigsCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValueName, testCase); // Test Case 4: TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKey // Test Type: Negative // Description: // One perfectly fine InterfaceOtherConfigs // (TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsValue_InterfaceOtherConfigsKey_1, // TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigs_InterfaceOtherConfigsValue_1) // and one malformed InterfaceOtherConfigs which only has key specified // (UNSPECIFIED, // TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKey_NoKeyForValue_2) // Expected: A termination point is created without any InterfaceOtherConfigs final String testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKeyName = "TestOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKey"; otherConfigsCounter = 0; oneGood = new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKeyName, GOOD_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKeyName, GOOD_VALUE, otherConfigsCounter)) .build(); oneBad = new InterfaceOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKeyName, NO_KEY_FOR_VALUE, ++otherConfigsCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodInterfaceOtherConfigsOneMalformedInterfaceOtherConfigsKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDInterfaceOtherConfigs() * This is helper test method to compare a test "set" of Options against an expected "set" */ private void assertExpectedInterfaceOtherConfigsExist( List expected, List test ) { if (expected != null && test != null) { for (InterfaceOtherConfigs expectedOtherConfigs : expected) { Assert.assertTrue(test.contains(expectedOtherConfigs)); } } } /* * Tests the CRUD operations for Interface other_configs. * * @see SouthboundIT.generateInterfaceExternalIdsTestCases() for specific test case information */ @Test public void testCRUDTerminationPointInterfaceOtherConfigs() throws InterruptedException { final String TEST_PREFIX = "CRUDTPInterfaceOtherConfigs"; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after // the update has been performed. Map>> updateFromTestCases = generateInterfaceOtherConfigsTestCases(); Map>> updateToTestCases = generateInterfaceOtherConfigsTestCases(); Map> updateFromTestCase; List updateFromInputOtherConfigs; List updateFromExpectedOtherConfigs; Map> updateToTestCase; List updateToInputOtherConfigs; List updateToExpectedOtherConfigs; String testBridgeName; String testPortName; int counter = 1; ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); updateFromInputOtherConfigs = updateFromTestCase.get(INPUT_VALUES_KEY); updateFromExpectedOtherConfigs = updateFromTestCase.get(EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testPortName = testBridgeName = String.format("%s_%s_%d", TEST_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputOtherConfigs = updateToTestCase.get(INPUT_VALUES_KEY); updateToExpectedOtherConfigs = updateToTestCase.get(EXPECTED_VALUES_KEY); TestCRUDTerminationPointInterfaceOtherConfigsRunnable testRunnable = new TestCRUDTerminationPointInterfaceOtherConfigsRunnable( connectionInfo, testBridgeName, testPortName, updateFromInputOtherConfigs, updateFromExpectedOtherConfigs, updateToInputOtherConfigs, updateToExpectedOtherConfigs); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDTerminationPointInterfaceOtherConfigsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; String testPortName; List updateFromInputOtherConfigs; List updateFromExpectedOtherConfigs; List updateToInputOtherConfigs; List updateToExpectedOtherConfigs; TestCRUDTerminationPointInterfaceOtherConfigsRunnable( ConnectionInfo connectionInfo, String testBridgeName, String testPortName, List updateFromInputOtherConfigs, List updateFromExpectedOtherConfigs, List updateToInputOtherConfigs, List updateToExpectedOtherConfigs) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.testPortName = testPortName; this.updateFromInputOtherConfigs = updateFromInputOtherConfigs; this.updateFromExpectedOtherConfigs = updateFromExpectedOtherConfigs; this.updateToInputOtherConfigs = updateToInputOtherConfigs; this.updateToExpectedOtherConfigs = updateToExpectedOtherConfigs; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } public void test() throws InterruptedException { final int TERMINATION_POINT_TEST_INDEX = 0; // CREATE: Create the test interface Assert.assertTrue(addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null)); NodeId testBridgeNodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, new OvsdbBridgeName(testBridgeName))); OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); tpCreateAugmentationBuilder.setName(testPortName); tpCreateAugmentationBuilder.setInterfaceOtherConfigs(updateFromInputOtherConfigs); Assert.assertTrue(addTerminationPoint(testBridgeNodeId, testPortName, tpCreateAugmentationBuilder)); // READ: Read the test interface and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateFromConfigurationOtherConfigs; if (updateFromConfigurationTerminationPointAugmentation != null) { updateFromConfigurationOtherConfigs = updateFromConfigurationTerminationPointAugmentation .getInterfaceOtherConfigs(); } else { updateFromConfigurationOtherConfigs = null; } assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs, updateFromConfigurationOtherConfigs); OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateFromOperationalOtherConfigs = updateFromOperationalTerminationPointAugmenation.getInterfaceOtherConfigs(); if (updateFromOperationalOtherConfigs != null) { updateFromOperationalOtherConfigs = updateFromOperationalTerminationPointAugmenation .getInterfaceOtherConfigs(); } else { updateFromOperationalOtherConfigs = null; } assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs, updateFromOperationalOtherConfigs); // UPDATE: update the other_configs testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setInterfaceOtherConfigs(updateToInputOtherConfigs); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test interface and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateToConfigurationOtherConfigs = updateToConfigurationTerminationPointAugmentation .getInterfaceOtherConfigs(); assertExpectedInterfaceOtherConfigsExist(updateToExpectedOtherConfigs, updateToConfigurationOtherConfigs); assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs, updateToConfigurationOtherConfigs); OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateToOperationalOtherConfigs = updateToOperationalTerminationPointAugmentation .getInterfaceOtherConfigs(); if (updateFromExpectedOtherConfigs != null) { assertExpectedInterfaceOtherConfigsExist(updateToExpectedOtherConfigs, updateToOperationalOtherConfigs); assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs, updateToOperationalOtherConfigs); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } /* * Generates the test cases involved in testing Port other_configs. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT port other_configs, or EXPECTED port other_configs * INPUT is the List we use when calling * TerminationPointAugmentationBuilder.setPortOtherConfigs() * EXPECTED is the List we expect to receive after calling * TerminationPointAugmentationBuilder.getPortOtherConfigs() */ private Map>> generatePortOtherConfigsTestCases() { Map>> testMap = new HashMap>>(); final String PORT_OTHER_CONFIGS_KEY = "PortOtherConfigsKey"; final String PORT_OTHER_CONFIGS_VALUE = "PortOtherConfigsValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneOtherConfigs // Test Type: Positive // Description: Create an port with one other_Configs // Expected: A port is created with the single other_configs specified below final String testOneOtherConfigsName = "TestOnePortOtherConfigs"; int otherConfigsCounter = 0; List oneOtherConfigs = (List) Lists.newArrayList( (new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneOtherConfigsName, PORT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testOneOtherConfigsName, PORT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneOtherConfigs); testCase.put(INPUT_VALUES_KEY, oneOtherConfigs); testMap.put(testOneOtherConfigsName, testCase); // Test Case 2: TestFivePortOtherConfigs // Test Type: Positive // Description: Create a termination point with multiple (five) PortOtherConfigs // Expected: A termination point is created with the five PortOtherConfigs specified below final String testFivePortOtherConfigsName = "TestFivePortOtherConfigs"; otherConfigsCounter = 0; List fivePortOtherConfigs = (List) Lists.newArrayList( (new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build()), (new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testFivePortOtherConfigsName, PORT_OTHER_CONFIGS_VALUE, otherConfigsCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fivePortOtherConfigs); testCase.put(INPUT_VALUES_KEY, fivePortOtherConfigs); testMap.put(testFivePortOtherConfigsName, testCase); // Test Case 3: TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValue // Test Type: Negative // Description: // One perfectly fine PortOtherConfigs // (TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValue_PortOtherConfigsKey_1, // TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigs_PortOtherConfigsValue_1) // and one malformed PortOtherConfigs which only has key specified // (TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A termination point is created without any PortOtherConfigs final String testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValueName = "TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValue"; otherConfigsCounter = 0; PortOtherConfigs oneGood = new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValueName, GOOD_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValueName, GOOD_VALUE, otherConfigsCounter)) .build(); PortOtherConfigs oneBad = new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValueName, NO_VALUE_FOR_KEY, ++otherConfigsCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValueName, testCase); // Test Case 4: TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKey // Test Type: Negative // Description: // One perfectly fine PortOtherConfigs // (TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsValue_PortOtherConfigsKey_1, // TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigs_PortOtherConfigsValue_1) // and one malformed PortOtherConfigs which only has key specified // (UNSPECIFIED, // TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKey_NoKeyForValue_2) // Expected: A termination point is created without any PortOtherConfigs final String testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKeyName = "TestOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKey"; otherConfigsCounter = 0; oneGood = new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKeyName, GOOD_KEY, ++otherConfigsCounter)) .setOtherConfigValue(String.format(FORMAT_STR, testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKeyName, GOOD_VALUE, otherConfigsCounter)) .build(); oneBad = new PortOtherConfigsBuilder() .setOtherConfigKey(String.format(FORMAT_STR, testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKeyName, NO_KEY_FOR_VALUE, ++otherConfigsCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodPortOtherConfigsOneMalformedPortOtherConfigsKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDPortOtherConfigs() * This is helper test method to compare a test "set" of Options against an expected "set" */ private void assertExpectedPortOtherConfigsExist( List expected, List test ) { if (expected != null && test != null) { for (PortOtherConfigs expectedOtherConfigs : expected) { Assert.assertTrue(test.contains(expectedOtherConfigs)); } } } /* * Tests the CRUD operations for Port other_configs. * * @see SouthboundIT.generatePortExternalIdsTestCases() for specific test case information */ @Test public void testCRUDTerminationPointPortOtherConfigs() throws InterruptedException { final String TEST_PREFIX = "CRUDTPPortOtherConfigs"; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after // the update has been performed. Map>> updateFromTestCases = generatePortOtherConfigsTestCases(); Map>> updateToTestCases = generatePortOtherConfigsTestCases(); Map> updateFromTestCase; List updateFromInputOtherConfigs; List updateFromExpectedOtherConfigs; Map> updateToTestCase; List updateToInputOtherConfigs; List updateToExpectedOtherConfigs; String testBridgeName; String testPortName; int counter = 1; ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); updateFromInputOtherConfigs = updateFromTestCase.get(INPUT_VALUES_KEY); updateFromExpectedOtherConfigs = updateFromTestCase.get(EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testPortName = testBridgeName = String.format("%s_%s_%d", TEST_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputOtherConfigs = updateToTestCase.get(INPUT_VALUES_KEY); updateToExpectedOtherConfigs = updateToTestCase.get(EXPECTED_VALUES_KEY); TestCRUDTerminationPointPortOtherConfigsRunnable testRunnable = new TestCRUDTerminationPointPortOtherConfigsRunnable( connectionInfo, testBridgeName, testPortName, updateFromInputOtherConfigs, updateFromExpectedOtherConfigs, updateToInputOtherConfigs, updateToExpectedOtherConfigs); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDTerminationPointPortOtherConfigsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; String testPortName; List updateFromInputOtherConfigs; List updateFromExpectedOtherConfigs; List updateToInputOtherConfigs; List updateToExpectedOtherConfigs; TestCRUDTerminationPointPortOtherConfigsRunnable( ConnectionInfo connectionInfo, String testBridgeName, String testPortName, List updateFromInputOtherConfigs, List updateFromExpectedOtherConfigs, List updateToInputOtherConfigs, List updateToExpectedOtherConfigs) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.testPortName = testPortName; this.updateFromInputOtherConfigs = updateFromInputOtherConfigs; this.updateFromExpectedOtherConfigs = updateFromExpectedOtherConfigs; this.updateToInputOtherConfigs = updateToInputOtherConfigs; this.updateToExpectedOtherConfigs = updateToExpectedOtherConfigs; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } public void test() throws InterruptedException { final int TERMINATION_POINT_TEST_INDEX = 0; // CREATE: Create the test port Assert.assertTrue(addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null)); NodeId testBridgeNodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, new OvsdbBridgeName(testBridgeName))); OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); tpCreateAugmentationBuilder.setName(testPortName); tpCreateAugmentationBuilder.setPortOtherConfigs(updateFromInputOtherConfigs); Assert.assertTrue(addTerminationPoint(testBridgeNodeId, testPortName, tpCreateAugmentationBuilder)); // READ: Read the test port and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateFromConfigurationOtherConfigs; if (updateFromConfigurationTerminationPointAugmentation != null) { updateFromConfigurationOtherConfigs = updateFromConfigurationTerminationPointAugmentation .getPortOtherConfigs(); } else { updateFromConfigurationOtherConfigs = null; } assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs, updateFromConfigurationOtherConfigs); OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateFromOperationalOtherConfigs = updateFromOperationalTerminationPointAugmenation.getPortOtherConfigs(); if (updateFromOperationalOtherConfigs != null) { updateFromOperationalOtherConfigs = updateFromOperationalTerminationPointAugmenation .getPortOtherConfigs(); } else { updateFromOperationalOtherConfigs = null; } assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs, updateFromOperationalOtherConfigs); // UPDATE: update the other_configs testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setPortOtherConfigs(updateToInputOtherConfigs); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test port and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); List updateToConfigurationOtherConfigs = updateToConfigurationTerminationPointAugmentation .getPortOtherConfigs(); assertExpectedPortOtherConfigsExist(updateToExpectedOtherConfigs, updateToConfigurationOtherConfigs); assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs, updateToConfigurationOtherConfigs); OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); List updateToOperationalOtherConfigs = updateToOperationalTerminationPointAugmentation .getPortOtherConfigs(); if (updateFromExpectedOtherConfigs != null) { assertExpectedPortOtherConfigsExist(updateToExpectedOtherConfigs, updateToOperationalOtherConfigs); assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs, updateToOperationalOtherConfigs); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } @Test public void testCRUDTerminationPointVlan() throws InterruptedException { final Integer CREATED_VLAN_ID = new Integer(4000); final Integer UPDATED_VLAN_ID = new Integer(4001); ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // CREATE Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME); Assert.assertNotNull(bridge); NodeId nodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); String portName = "testTerminationPointVlanId"; ovsdbTerminationBuilder.setName(portName); ovsdbTerminationBuilder.setVlanTag(new VlanId(CREATED_VLAN_ID)); Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder)); InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); Assert.assertNotNull(terminationPointNode); // READ List terminationPoints = terminationPointNode.getTerminationPoint(); OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = null; for (TerminationPoint terminationPoint : terminationPoints) { ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation( OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { VlanId actualVlanId = ovsdbTerminationPointAugmentation.getVlanTag(); Assert.assertNotNull(actualVlanId); Integer actualVlanIdInt = actualVlanId.getValue(); Assert.assertEquals(CREATED_VLAN_ID, actualVlanIdInt); } } // UPDATE NodeId testBridgeNodeId = getBridgeNode(connectionInfo, SouthboundITConstants.BRIDGE_NAME).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setVlanTag(new VlanId(UPDATED_VLAN_ID)); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); tpUpdateBuilder.setTpId(new TpId(portName)); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Assert.assertTrue(result); Thread.sleep(OVSDB_UPDATE_TIMEOUT); terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation( OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { VlanId actualVlanId = ovsdbTerminationPointAugmentation.getVlanTag(); Assert.assertNotNull(actualVlanId); Integer actualVlanIdInt = actualVlanId.getValue(); Assert.assertEquals(UPDATED_VLAN_ID, actualVlanIdInt); } } // DELETE Assert.assertTrue(deleteBridge(connectionInfo)); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testCRUDTerminationPointVlanModes() throws InterruptedException { final VlanMode UPDATED_VLAN_MODE = VlanMode.Access; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); VlanMode []vlanModes = VlanMode.values(); for (VlanMode vlanMode : vlanModes) { // CREATE Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); NodeId nodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); String portName = "testTerminationPointVlanMode" + vlanMode.toString(); ovsdbTerminationBuilder.setName(portName); ovsdbTerminationBuilder.setVlanMode(vlanMode); Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder)); InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); Assert.assertNotNull(terminationPointNode); // READ List terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { //test Assert.assertTrue(ovsdbTerminationPointAugmentation.getVlanMode().equals(vlanMode)); } } // UPDATE NodeId testBridgeNodeId = getBridgeNode(connectionInfo, SouthboundITConstants.BRIDGE_NAME).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setVlanMode(UPDATED_VLAN_MODE); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); tpUpdateBuilder.setTpId(new TpId(portName)); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Assert.assertTrue(result); Thread.sleep(OVSDB_UPDATE_TIMEOUT); terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { //test Assert.assertEquals(UPDATED_VLAN_MODE, ovsdbTerminationPointAugmentation.getVlanMode()); } } // DELETE Assert.assertTrue(deleteBridge(connectionInfo)); } Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } private ArrayList> generateVlanSets() { ArrayList> vlanSets = new ArrayList>(); Set emptySet = new HashSet(); vlanSets.add(emptySet); Set singleSet = new HashSet(); Integer single = new Integer(2222); singleSet.add(single); vlanSets.add(singleSet); Set minMaxMiddleSet = new HashSet(); Integer min = new Integer(0); minMaxMiddleSet.add(min); Integer max = new Integer(4095); minMaxMiddleSet.add(max); Integer minPlusOne = new Integer(min + 1); minMaxMiddleSet.add(minPlusOne); Integer maxMinusOne = new Integer(max - 1); minMaxMiddleSet.add(maxMinusOne); Integer middle = new Integer((max - min) / 2); minMaxMiddleSet.add(middle); vlanSets.add(minMaxMiddleSet); return vlanSets; } private List buildTrunkList(Set trunkSet) { List trunkList = Lists.newArrayList(); for (Integer trunk : trunkSet) { TrunksBuilder trunkBuilder = new TrunksBuilder(); trunkBuilder.setTrunk(new VlanId(trunk)); trunkList.add(trunkBuilder.build()); } return trunkList; } @Test public void testCRUDTerminationPointVlanTrunks() throws InterruptedException { final List UPDATED_TRUNKS = buildTrunkList(Sets.newHashSet(2011)); ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); Iterable> vlanSets = generateVlanSets(); int testCase = 0; for (Set vlanSet : vlanSets) { ++testCase; // CREATE Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); NodeId nodeId = createManagedNodeId(createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); String portName = "testTerminationPointVlanTrunks" + testCase; ovsdbTerminationBuilder.setName(portName); List trunks = buildTrunkList(vlanSet); ovsdbTerminationBuilder.setTrunks(trunks); Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder)); InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); Assert.assertNotNull(terminationPointNode); // READ List terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { List actualTrunks = ovsdbTerminationPointAugmentation.getTrunks(); for (Trunks trunk : trunks) { Assert.assertTrue(actualTrunks.contains(trunk)); } } } // UPDATE NodeId testBridgeNodeId = getBridgeNode(connectionInfo, SouthboundITConstants.BRIDGE_NAME).getNodeId(); OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpUpdateAugmentationBuilder.setTrunks(UPDATED_TRUNKS); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); NodeId portUpdateNodeId = createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName))); tpUpdateBuilder.addAugmentation( OvsdbTerminationPointAugmentation.class, tpUpdateAugmentationBuilder.build()); tpUpdateBuilder.setTpId(new TpId(portName)); portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()); Assert.assertTrue(result); Thread.sleep(OVSDB_UPDATE_TIMEOUT); terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); terminationPoints = terminationPointNode.getTerminationPoint(); for (TerminationPoint terminationPoint : terminationPoints) { OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { //test Assert.assertEquals(UPDATED_TRUNKS, ovsdbTerminationPointAugmentation.getTrunks()); } } // DELETE Assert.assertTrue(deleteBridge(connectionInfo)); } Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } @Test public void testGetOvsdbNodes() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); InstanceIdentifier topologyPath = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)); Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyPath); InstanceIdentifier expectedNodeIid = createInstanceIdentifier(connectionInfo); NodeId expectedNodeId = expectedNodeIid.firstKeyOf(Node.class, NodeKey.class).getNodeId(); Node foundNode = null; Assert.assertNotNull("Expected to find topology: " + topologyPath, topology); Assert.assertNotNull("Expected to find some nodes" + topology.getNode()); LOG.info("expectedNodeId: {}, getNode: {}", expectedNodeId, topology.getNode()); for (Node node : topology.getNode()) { if (node.getNodeId().getValue().equals(expectedNodeId.getValue())) { foundNode = node; break; } } Assert.assertNotNull("Expected to find Node: " + expectedNodeId, foundNode); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } /* * Generates the test cases involved in testing BridgeOtherConfigs. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT bridge other_configs, or EXPECTED bridge other_configs * INPUT is the List we use when calling BridgeAugmentationBuilder.setBridgeOtherConfigs() * EXPECTED is the List we expect to receive after calling BridgeAugmentationBuilder.getBridgeOtherConfigs() */ private Map>> generateBridgeOtherConfigsTestCases() { Map>> testMap = new HashMap>>(); final String BRIDGE_OTHER_CONFIGS_KEY = "BridgeOtherConfigKey"; final String BRIDGE_OTHER_CONFIGS_VALUE = "BridgeOtherConfigValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneOtherConfig // Test Type: Positive // Description: Create a bridge with one other_config // Expected: A bridge is created with the single other_config specified below final String testOneOtherConfigName = "TestOneOtherConfig"; int otherConfigCounter = 0; List oneOtherConfig = (List) Lists.newArrayList( (new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testOneOtherConfigName, BRIDGE_OTHER_CONFIGS_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testOneOtherConfigName, BRIDGE_OTHER_CONFIGS_VALUE, otherConfigCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneOtherConfig); testCase.put(INPUT_VALUES_KEY, oneOtherConfig); testMap.put(testOneOtherConfigName, testCase); // Test Case 2: TestFiveOtherConfig // Test Type: Positive // Description: Create a bridge with multiple (five) other_configs // Expected: A bridge is created with the five other_configs specified below final String testFiveOtherConfigName = "TestFiveOtherConfig"; otherConfigCounter = 0; List fiveOtherConfig = (List) Lists.newArrayList( (new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_VALUE, otherConfigCounter)) .build()), (new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_VALUE, otherConfigCounter)) .build()), (new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_VALUE, otherConfigCounter)) .build()), (new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_VALUE, otherConfigCounter)) .build()), (new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testFiveOtherConfigName, BRIDGE_OTHER_CONFIGS_VALUE, otherConfigCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fiveOtherConfig); testCase.put(INPUT_VALUES_KEY, fiveOtherConfig); testMap.put(testFiveOtherConfigName, testCase); // Test Case 3: TestOneGoodOtherConfigOneMalformedOtherConfigValue // Test Type: Negative // Description: // One perfectly fine BridgeOtherConfig // (TestOneGoodOtherConfigOneMalformedOtherConfigValue_BridgeOtherConfigKey_1, // TestOneGoodOtherConfigOneMalformedOtherConfig_BridgeOtherConfigValue_1) // and one malformed BridgeOtherConfig which only has key specified // (TestOneGoodOtherConfigOneMalformedOtherConfigValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A bridge is created without any other_config final String testOneGoodOtherConfigOneMalformedOtherConfigValueName = "TestOneGoodOtherConfigOneMalformedOtherConfigValue"; otherConfigCounter = 0; BridgeOtherConfigs oneGood = new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testOneGoodOtherConfigOneMalformedOtherConfigValueName, GOOD_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testOneGoodOtherConfigOneMalformedOtherConfigValueName, GOOD_VALUE, otherConfigCounter)) .build(); BridgeOtherConfigs oneBad = new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testOneGoodOtherConfigOneMalformedOtherConfigValueName, NO_VALUE_FOR_KEY, ++otherConfigCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodOtherConfigOneMalformedOtherConfigValueName, testCase); // Test Case 4: TestOneGoodOtherConfigOneMalformedOtherConfigKey // Test Type: Negative // Description: // One perfectly fine BridgeOtherConfig // (TestOneGoodOtherConfigOneMalformedOtherConfigValue_BridgeOtherConfigKey_1, // TestOneGoodOtherConfigOneMalformedOtherConfig_BridgeOtherConfigValue_1) // and one malformed BridgeOtherConfig which only has key specified // (UNSPECIFIED, // TestOneGoodOtherConfigOneMalformedOtherConfigKey_NoKeyForValue_2) // Expected: A bridge is created without any other_config final String testOneGoodOtherConfigOneMalformedOtherConfigKeyName = "TestOneGoodOtherConfigOneMalformedOtherConfigIdKey"; otherConfigCounter = 0; oneGood = new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testOneGoodOtherConfigOneMalformedOtherConfigKeyName, GOOD_KEY, ++otherConfigCounter)) .setBridgeOtherConfigValue(String.format(FORMAT_STR, testOneGoodOtherConfigOneMalformedOtherConfigKeyName, GOOD_VALUE, otherConfigCounter)) .build(); oneBad = new BridgeOtherConfigsBuilder() .setBridgeOtherConfigKey(String.format(FORMAT_STR, testOneGoodOtherConfigOneMalformedOtherConfigKeyName, NO_KEY_FOR_VALUE, ++otherConfigCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodOtherConfigOneMalformedOtherConfigKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDBridgeOtherConfigs() * This is helper test method to compare a test "set" of BridgeExternalIds against an expected "set" */ private void assertExpectedBridgeOtherConfigsExist( List expected, List test ) { if (expected != null) { for (BridgeOtherConfigs expectedOtherConfig : expected) { Assert.assertTrue(test.contains(expectedOtherConfig)); } } } /* * @see SouthboundIT.generateBridgeOtherConfigsTestCases() for specific test case information. */ @Test public void testCRUDBridgeOtherConfigs() throws InterruptedException { final String TEST_BRIDGE_PREFIX = "CRUDBridgeOtherConfigs"; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after // the update has been performed. Map>> updateFromTestCases = generateBridgeOtherConfigsTestCases(); Map>> updateToTestCases = generateBridgeOtherConfigsTestCases(); Map> updateFromTestCase; Map> updateToTestCase; List updateFromInputOtherConfigs; List updateFromExpectedOtherConfigs; List updateToInputOtherConfigs; List updateToExpectedOtherConfigs; String testBridgeName; int counter = 1; ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); updateFromInputOtherConfigs = updateFromTestCase.get(INPUT_VALUES_KEY); updateFromExpectedOtherConfigs = updateFromTestCase.get(EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testBridgeName = String.format("%s_%s_%d", TEST_BRIDGE_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputOtherConfigs = updateToTestCase.get(INPUT_VALUES_KEY); updateToExpectedOtherConfigs = updateToTestCase.get(EXPECTED_VALUES_KEY); TestCRUDBridgeOtherConfigsRunnable testRunnable = new TestCRUDBridgeOtherConfigsRunnable( connectionInfo, testBridgeName, updateFromInputOtherConfigs, updateFromExpectedOtherConfigs, updateToInputOtherConfigs, updateToExpectedOtherConfigs); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDBridgeOtherConfigsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; List updateFromInputOtherConfigs; List updateFromExpectedOtherConfigs; List updateToInputOtherConfigs; List updateToExpectedOtherConfigs; TestCRUDBridgeOtherConfigsRunnable( ConnectionInfo connectionInfo, String testBridgeName, List updateFromInputOtherConfigs, List updateFromExpectedOtherConfigs, List updateToInputOtherConfigs, List updateToExpectedOtherConfigs) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.updateFromInputOtherConfigs = updateFromInputOtherConfigs; this.updateFromExpectedOtherConfigs = updateFromExpectedOtherConfigs; this.updateToInputOtherConfigs = updateToInputOtherConfigs; this.updateToExpectedOtherConfigs = updateToExpectedOtherConfigs; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } public void test() throws InterruptedException { // CREATE: Create the test bridge boolean bridgeAdded = addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, updateFromInputOtherConfigs); Assert.assertTrue(bridgeAdded); // READ: Read the test bridge and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store List updateFromConfigurationOtherConfigs = getBridge(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION).getBridgeOtherConfigs(); assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs, updateFromConfigurationOtherConfigs); List updateFromOperationalOtherConfigs = getBridge(connectionInfo, testBridgeName) .getBridgeOtherConfigs(); assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs, updateFromOperationalOtherConfigs); // UPDATE: update the external_ids OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder(); bridgeAugmentationBuilder.setBridgeOtherConfigs(updateToInputOtherConfigs); InstanceIdentifier bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(testBridgeName)); NodeBuilder bridgeNodeBuilder = new NodeBuilder(); Node bridgeNode = getBridgeNode(connectionInfo, testBridgeName); bridgeNodeBuilder.setNodeId(bridgeNode.getNodeId()); bridgeNodeBuilder.setKey(bridgeNode.getKey()); bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, bridgeAugmentationBuilder.build()); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test bridge and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store List updateToConfigurationOtherConfigs = getBridge(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION).getBridgeOtherConfigs(); assertExpectedBridgeOtherConfigsExist(updateToExpectedOtherConfigs, updateToConfigurationOtherConfigs); assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs, updateToConfigurationOtherConfigs); List updateToOperationalOtherConfigs = getBridge(connectionInfo, testBridgeName) .getBridgeOtherConfigs(); if (updateFromExpectedOtherConfigs != null) { assertExpectedBridgeOtherConfigsExist(updateToExpectedOtherConfigs, updateToOperationalOtherConfigs); assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs, updateToOperationalOtherConfigs); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } /* * Generates the test cases involved in testing BridgeExternalIds. See inline comments for descriptions of * the particular cases considered. * * The return value is a Map in the form (K,V)=(testCaseName,testCase). * - testCaseName is a String * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of * either corresponding INPUT bridge external ids, or EXPECTED bridge external ids * INPUT is the List we use when calling BridgeAugmentationBuilder.setBridgeExternalIds() * EXPECTED is the List we expect to receive after calling BridgeAugmentationBuilder.getBridgeExternalIds() */ private Map>> generateBridgeExternalIdsTestCases() { Map>> testMap = new HashMap>>(); final String BRIDGE_EXTERNAL_ID_KEY = "BridgeExternalIdKey"; final String BRIDGE_EXTERNAL_ID_VALUE = "BridgeExternalIdValue"; final String FORMAT_STR = "%s_%s_%d"; final String GOOD_KEY = "GoodKey"; final String GOOD_VALUE = "GoodValue"; final String NO_VALUE_FOR_KEY = "NoValueForKey"; final String NO_KEY_FOR_VALUE = "NoKeyForValue"; // Test Case 1: TestOneExternalId // Test Type: Positive // Description: Create a bridge with one BridgeExternalIds // Expected: A bridge is created with the single external_ids specified below final String testOneExternalIdName = "TestOneExternalId"; int externalIdCounter = 0; List oneExternalId = (List) Lists.newArrayList( (new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testOneExternalIdName, BRIDGE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testOneExternalIdName, BRIDGE_EXTERNAL_ID_VALUE, externalIdCounter)) .build())); Map> testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, oneExternalId); testCase.put(INPUT_VALUES_KEY, oneExternalId); testMap.put(testOneExternalIdName, testCase); // Test Case 2: TestFiveExternalId // Test Type: Positive // Description: Create a bridge with multiple (five) BridgeExternalIds // Expected: A bridge is created with the five external_ids specified below final String testFiveExternalIdName = "TestFiveExternalId"; externalIdCounter = 0; List fiveExternalId = (List) Lists.newArrayList( (new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_VALUE, externalIdCounter)) .build()), (new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testFiveExternalIdName, BRIDGE_EXTERNAL_ID_VALUE, externalIdCounter)) .build())); testCase = Maps.newHashMap(); testCase.put(EXPECTED_VALUES_KEY, fiveExternalId); testCase.put(INPUT_VALUES_KEY, fiveExternalId); testMap.put(testFiveExternalIdName, testCase); // Test Case 3: TestOneGoodExternalIdOneMalformedExternalIdValue // Test Type: Negative // Description: // One perfectly fine BridgeExternalId // (TestOneGoodExternalIdOneMalformedExternalIdValue_BridgeExternalIdKey_1, // TestOneGoodExternalIdOneMalformedExternalId_BridgeExternalIdValue_1) // and one malformed BridgeExternalId which only has key specified // (TestOneGoodExternalIdOneMalformedExternalIdValue_NoValueForKey_2, // UNSPECIFIED) // Expected: A bridge is created without any external_ids final String testOneGoodExternalIdOneMalformedExternalIdValueName = "TestOneGoodExternalIdOneMalformedExternalIdValue"; externalIdCounter = 0; BridgeExternalIds oneGood = new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, GOOD_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, GOOD_VALUE, externalIdCounter)) .build(); BridgeExternalIds oneBad = new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdValueName, NO_VALUE_FOR_KEY, ++externalIdCounter)) .build(); List oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); List oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodExternalIdOneMalformedExternalIdValueName, testCase); // Test Case 4: TestOneGoodExternalIdOneMalformedExternalIdKey // Test Type: Negative // Description: // One perfectly fine BridgeExternalId // (TestOneGoodExternalIdOneMalformedExternalIdValue_BridgeExternalIdKey_1, // TestOneGoodExternalIdOneMalformedExternalId_BridgeExternalIdValue_1) // and one malformed BridgeExternalId which only has key specified // (UNSPECIFIED, // TestOneGoodExternalIdOneMalformedExternalIdKey_NoKeyForValue_2) // Expected: A bridge is created without any external_ids final String testOneGoodExternalIdOneMalformedExternalIdKeyName = "TestOneGoodExternalIdOneMalformedExternalIdKey"; externalIdCounter = 0; oneGood = new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, GOOD_KEY, ++externalIdCounter)) .setBridgeExternalIdValue(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, GOOD_VALUE, externalIdCounter)) .build(); oneBad = new BridgeExternalIdsBuilder() .setBridgeExternalIdKey(String.format(FORMAT_STR, testOneGoodExternalIdOneMalformedExternalIdKeyName, NO_KEY_FOR_VALUE, ++externalIdCounter)) .build(); oneGoodOneBadInput = (List) Lists.newArrayList( oneGood, oneBad); oneGoodOneBadExpected = null; testCase = Maps.newHashMap(); testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); testMap.put(testOneGoodExternalIdOneMalformedExternalIdKeyName, testCase); return testMap; } /* * @see SouthboundIT.testCRUDBridgeExternalIds() * This is helper test method to compare a test "set" of BridgeExternalIds against an expected "set" */ private void assertExpectedBridgeExternalIdsExist( List expected, List test ) { if (expected != null) { for (BridgeExternalIds expectedExternalId : expected) { Assert.assertTrue(test.contains(expectedExternalId)); } } } /* * @see SouthboundIT.generateBridgeExternalIdsTestCases() for specific test case information */ @Test public void testCRUDBridgeExternalIds() throws InterruptedException { final String TEST_BRIDGE_PREFIX = "CRUDBridgeExternalIds"; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after // the update has been performed. Map>> updateFromTestCases = generateBridgeExternalIdsTestCases(); Map>> updateToTestCases = generateBridgeExternalIdsTestCases(); Map> updateFromTestCase; List updateFromInputExternalIds; List updateFromExpectedExternalIds; Map> updateToTestCase; List updateToInputExternalIds; List updateToExpectedExternalIds; String testBridgeName; int counter = 1; ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); updateFromInputExternalIds = updateFromTestCase.get(INPUT_VALUES_KEY); updateFromExpectedExternalIds = updateFromTestCase.get(EXPECTED_VALUES_KEY); for (String testCaseKey : updateToTestCases.keySet()) { testBridgeName = String.format("%s_%s_d", TEST_BRIDGE_PREFIX, testCaseKey, counter); counter += 1; updateToTestCase = updateToTestCases.get(testCaseKey); updateToInputExternalIds = updateToTestCase.get(INPUT_VALUES_KEY); updateToExpectedExternalIds = updateToTestCase.get(EXPECTED_VALUES_KEY); TestCRUDBridgeExternalIdsRunnable testRunnable = new TestCRUDBridgeExternalIdsRunnable( connectionInfo, testBridgeName, updateFromInputExternalIds, updateFromExpectedExternalIds, updateToInputExternalIds, updateToExpectedExternalIds); executor.submit(testRunnable); } } executor.shutdown(); executor.awaitTermination(5, TimeUnit.MINUTES); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } class TestCRUDBridgeExternalIdsRunnable implements Runnable { ConnectionInfo connectionInfo; String testBridgeName; List updateFromInputExternalIds; List updateFromExpectedExternalIds; List updateToInputExternalIds; List updateToExpectedExternalIds; TestCRUDBridgeExternalIdsRunnable( ConnectionInfo connectionInfo, String testBridgeName, List updateFromInputExternalIds, List updateFromExpectedExternalIds, List updateToInputExternalIds, List updateToExpectedExternalIds) { this.connectionInfo = connectionInfo; this.testBridgeName = testBridgeName; this.updateFromInputExternalIds = updateFromInputExternalIds; this.updateFromExpectedExternalIds = updateFromExpectedExternalIds; this.updateToInputExternalIds = updateToInputExternalIds; this.updateToExpectedExternalIds = updateToExpectedExternalIds; } @Override public void run() { try { test(); } catch (InterruptedException e) { e.printStackTrace(); } } public void test() throws InterruptedException { // CREATE: Create the test bridge boolean bridgeAdded = addBridge(connectionInfo, null, testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, updateFromInputExternalIds, null, null); Assert.assertTrue(bridgeAdded); // READ: Read the test bridge and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store List updateFromConfigurationExternalIds = getBridge(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION).getBridgeExternalIds(); assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds); List updateFromOperationalExternalIds = getBridge(connectionInfo, testBridgeName) .getBridgeExternalIds(); assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateFromOperationalExternalIds); // UPDATE: update the external_ids OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder(); bridgeAugmentationBuilder.setBridgeExternalIds(updateToInputExternalIds); InstanceIdentifier bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(testBridgeName)); NodeBuilder bridgeNodeBuilder = new NodeBuilder(); Node bridgeNode = getBridgeNode(connectionInfo, testBridgeName); bridgeNodeBuilder.setNodeId(bridgeNode.getNodeId()); bridgeNodeBuilder.setKey(bridgeNode.getKey()); bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, bridgeAugmentationBuilder.build()); boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build()); Thread.sleep(OVSDB_UPDATE_TIMEOUT); Assert.assertTrue(result); // READ: the test bridge and ensure changes are propagated to the CONFIGURATION data store, // then repeat for OPERATIONAL data store List updateToConfigurationExternalIds = getBridge(connectionInfo, testBridgeName, LogicalDatastoreType.CONFIGURATION).getBridgeExternalIds(); assertExpectedBridgeExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds); assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds); List updateToOperationalExternalIds = getBridge(connectionInfo, testBridgeName) .getBridgeExternalIds(); if (updateFromExpectedExternalIds != null) { assertExpectedBridgeExternalIdsExist(updateToExpectedExternalIds, updateToOperationalExternalIds); assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateToOperationalExternalIds); } // DELETE Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } public static InstanceIdentifier createInstanceIdentifier(ConnectionInfo key,OvsdbBridgeName bridgeName) { return SouthboundMapper.createInstanceIdentifier(createManagedNodeId(key, bridgeName)); } public static NodeId createManagedNodeId(ConnectionInfo key, OvsdbBridgeName bridgeName) { return createManagedNodeId(key.getRemoteIp(),key.getRemotePort(),bridgeName); } public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) { return new NodeId(createNodeId(ip,port).getValue() + "/" + SouthboundConstants.BRIDGE_URI_PREFIX + "/" + bridgeName.getValue()); } public static NodeId createNodeId(IpAddress ip, PortNumber port) { String uriString = SouthboundConstants.OVSDB_URI_PREFIX + "://" + new String(ip.getValue()) + ":" + port.getValue(); Uri uri = new Uri(uriString); NodeId nodeId = new NodeId(uri); return nodeId; } public static NodeKey createNodeKey(IpAddress ip, PortNumber port) { return new NodeKey(createNodeId(ip,port)); } public static Node createNode(ConnectionInfo key) { NodeBuilder nodeBuilder = new NodeBuilder(); nodeBuilder.setNodeId(createNodeId(key.getRemoteIp(),key.getRemotePort())); nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, createOvsdbAugmentation(key)); return nodeBuilder.build(); } public static OvsdbNodeAugmentation createOvsdbAugmentation(ConnectionInfo key) { OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder(); ovsdbNodeBuilder.setConnectionInfo(key); return ovsdbNodeBuilder.build(); } public static NodeId createManagedNodeId(InstanceIdentifier iid) { NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class); return nodeKey.getNodeId(); } }