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.features;
+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.ObjectArrays;
+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.Assume;
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.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.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.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@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;
- private static String extras = "false";
- private static final String NETVIRT = "org.opendaylight.ovsdb.openstack.net-virt";
- private static final String NETVIRTPROVIDERS = "org.opendaylight.ovsdb.openstack.net-virt-providers";
+
+ // 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() {
- return super.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
@Override
public String getFeatureName() {
- setExtras();
return "odl-ovsdb-southbound-impl-ui";
}
}
@Override
- public Option[] getFeaturesOptions() {
- if (extras.equals("true")) {
- Option[] options = new Option[] {
- features("mvn:org.opendaylight.ovsdb/features-ovsdb/1.1.0-SNAPSHOT/xml/features",
- "odl-ovsdb-openstack-sb")};
- return options;
- } else {
- return new Option[]{};
- }
- }
-
- @Override
- public Option[] getLoggingOptions() {
- Option[] options = new Option[] {
- /*editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
- "log4j.logger.org.opendaylight.ovsdb",
- LogLevelOption.LogLevel.DEBUG.name()),*/
- editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
- "log4j.logger.org.opendaylight.ovsdb.southbound-impl",
- LogLevelOption.LogLevel.DEBUG.name())
- };
-
- if (extras.equals("true")) {
- Option[] extraOptions = new Option[] {
+ public Option getLoggingOption() {
+ return composite(
editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
"log4j.logger.org.opendaylight.ovsdb",
- LogLevelOption.LogLevel.DEBUG.name()),
- editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
- "log4j.logger.org.opendaylight.ovsdb.openstack.net-virt",
- LogLevelOption.LogLevel.DEBUG.name())
- };
- options = ObjectArrays.concat(options, extraOptions, Option.class);
- }
-
- options = ObjectArrays.concat(options, super.getLoggingOptions(), Option.class);
- return options;
+ LogLevelOption.LogLevel.TRACE.name()),
+ super.getLoggingOption());
}
- @Override
- public Option[] getPropertiesOptions() {
+ private Option[] getPropertiesOptions() {
Properties props = new Properties(System.getProperties());
String addressStr = props.getProperty(SouthboundITConstants.SERVER_IPADDRESS,
SouthboundITConstants.DEFAULT_SERVER_IPADDRESS);
String connectionType = props.getProperty(SouthboundITConstants.CONNECTION_TYPE,
SouthboundITConstants.CONNECTION_TYPE_ACTIVE);
- LOG.info("Using the following properties: mode= {}, ip:port= {}:{}",
+ LOG.info("getPropertiesOptions: Using the following properties: mode= {}, ip:port= {}:{}",
connectionType, addressStr, portStr);
Option[] options = new Option[] {
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
SouthboundITConstants.SERVER_PORT, portStr),
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
- SouthboundITConstants.CONNECTION_TYPE, connectionType)
+ SouthboundITConstants.CONNECTION_TYPE, connectionType),
};
return options;
}
- private void setExtras() {
- Properties props = new Properties(System.getProperties());
- extras = props.getProperty(SouthboundITConstants.SERVER_EXTRAS,
- SouthboundITConstants.DEFAULT_SERVER_EXTRAS);
- LOG.info("extras: {}", extras);
- System.out.println("extras: " + extras);
- }
-
@Before
- public void setUp() throws InterruptedException {
- if (setup == true) {
+ @Override
+ public void setup() throws InterruptedException {
+ if (setup) {
LOG.info("Skipping setUp, already initialized");
return;
}
portStr = bundleContext.getProperty(SouthboundITConstants.SERVER_PORT);
connectionType = bundleContext.getProperty(SouthboundITConstants.CONNECTION_TYPE);
- LOG.info("Using the following properties: mode= {}, ip:port= {}:{}",
+ LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}",
connectionType, addressStr, portStr);
if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_ACTIVE)) {
if (addressStr == null) {
mdsalUtils = new MdsalUtils(dataBroker);
setup = true;
-
- if (extras.equals("true")) {
- isBundleReady(bundleContext, NETVIRT);
- isBundleReady(bundleContext, NETVIRTPROVIDERS);
- }
}
/**
}
}
- private ConnectionInfo getConnectionInfo(String addressStr, String portStr) {
+ private ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(addressStr);
.setRemotePort(port)
.build());
return new ConnectionInfoBuilder()
- .setRemoteIp(address)
- .setRemotePort(port)
- .build();
+ .setRemoteIp(address)
+ .setRemotePort(port)
+ .build();
}
- private String connectionInfoToString(ConnectionInfo connectionInfo) {
+ private String connectionInfoToString(final ConnectionInfo connectionInfo) {
return new String(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
}
topology);
}
- private boolean addOvsdbNode(ConnectionInfo connectionInfo) throws InterruptedException {
+ private boolean addOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
+ InstanceIdentifier<Node> 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,
- SouthboundMapper.createInstanceIdentifier(connectionInfo),
- SouthboundMapper.createNode(connectionInfo));
+ iid,
+ createNode(connectionInfo));
Thread.sleep(OVSDB_UPDATE_TIMEOUT);
return result;
}
- private Node getOvsdbNode(ConnectionInfo connectionInfo) {
+ private InstanceIdentifier<Node> 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,
- SouthboundMapper.createInstanceIdentifier(connectionInfo));
+ createInstanceIdentifier(connectionInfo));
return node;
}
- private boolean deleteOvsdbNode(ConnectionInfo connectionInfo) throws InterruptedException {
+ private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
- SouthboundMapper.createInstanceIdentifier(connectionInfo));
+ createInstanceIdentifier(connectionInfo));
Thread.sleep(OVSDB_UPDATE_TIMEOUT);
return result;
}
- private Node connectOvsdbNode(ConnectionInfo connectionInfo) throws InterruptedException {
+ private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
Assert.assertTrue(addOvsdbNode(connectionInfo));
Node node = getOvsdbNode(connectionInfo);
Assert.assertNotNull(node);
return node;
}
- private boolean disconnectOvsdbNode(ConnectionInfo connectionInfo) throws InterruptedException {
+ private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
Assert.assertTrue(deleteOvsdbNode(connectionInfo));
Node node = getOvsdbNode(connectionInfo);
- //Assert.assertNull(node);
- Assume.assumeNotNull(node);
+ Assert.assertNull(node);
+ //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull
LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo));
return true;
}
public void testAddDeleteOvsdbNode() throws InterruptedException {
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
Node ovsdbNode = connectOvsdbNode(connectionInfo);
- //Assert.assertFalse(disconnectOvsdbNode(connectionInfo));
- Assume.assumeTrue(disconnectOvsdbNode(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<DatapathTypeEntry> datapathTypeEntries = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class)
+ .getDatapathTypeEntry();
+ if (datapathTypeEntries == null) {
+ LOG.info("DPDK not supported on this node.");
+ } else {
+ Class<? extends DatapathTypeBase> 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<Node> 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<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
+ Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
+ terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
+
+ // Verify that each termination point has DPDK ifType
+ Class<? extends InterfaceTypeBase> dpdkIfType = SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP
+ .get("dpdk");
+ Class<? extends InterfaceTypeBase> opPort = null;
+ List<TerminationPoint> 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 augment = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
- assertNotNull(augment.getOvsVersion());
- Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+ Assert.assertNotNull(ovsdbNodeAugmentation);
+ assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
+ Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
}
@Test
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
Node ovsdbNode = connectOvsdbNode(connectionInfo);
OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
- assertNotNull(ovsdbNodeAugmentation);
+ Assert.assertNotNull(ovsdbNodeAugmentation);
List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
if (otherConfigsList != null) {
for (OpenvswitchOtherConfigs otherConfig : otherConfigsList) {
} else {
LOG.info("other_config is not present");
}
- //Assert.assertFalse(disconnectOvsdbNode(connectionInfo));
- Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
+ 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<ControllerEntry> 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<ControllerEntry> 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<ControllerEntry> createControllerEntry(String controllerTarget) {
+ List<ControllerEntry> controllerEntriesList = new ArrayList<ControllerEntry>();
+ controllerEntriesList.add(new ControllerEntryBuilder()
+ .setTarget(new Uri(controllerTarget))
+ .build());
+ return controllerEntriesList;
}
- private void setManagedBy(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
- ConnectionInfo connectionInfo) {
- InstanceIdentifier<Node> connectionNodePath = SouthboundMapper.createInstanceIdentifier(connectionInfo);
+ private void setManagedBy(final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
+ final ConnectionInfo connectionInfo) {
+ InstanceIdentifier<Node> connectionNodePath = createInstanceIdentifier(connectionInfo);
ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
}
new OvsdbTerminationPointAugmentationBuilder();
ovsdbTerminationPointAugmentationBuilder.setInterfaceType(
new InterfaceTypeEntryBuilder()
- .setInterfaceType(
- SouthboundMapper.createInterfaceType("internal"))
+ .setInterfaceType(
+ SouthboundMapper.createInterfaceType("internal"))
.build().getInterfaceType());
return ovsdbTerminationPointAugmentationBuilder;
}
- private boolean addTerminationPoint(NodeId bridgeNodeId, String portName,
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder)
- throws InterruptedException {
+ private OvsdbTerminationPointAugmentationBuilder createGenericDpdkOvsdbTerminationPointAugmentationBuilder(
+ final String portName) {
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ ovsdbTerminationBuilder.setName(portName);
+ Class<? extends InterfaceTypeBase> 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<Node> portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId);
NodeBuilder portNodeBuilder = new NodeBuilder();
return result;
}
- private boolean addBridge(ConnectionInfo connectionInfo, String bridgeName) throws InterruptedException {
- //Node node = SouthboundMapper.createNode(connectionInfo);
+ /*
+ * 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 <code>bridgeIid</code>
+ * @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<Node> bridgeIid,
+ final String bridgeName, NodeId bridgeNodeId, final boolean setProtocolEntries,
+ final Class<? extends OvsdbFailModeBase> failMode, final boolean setManagedBy,
+ final Class<? extends DatapathTypeBase> dpType,
+ final List<BridgeExternalIds> externalIds,
+ final List<ControllerEntry> controllerEntries,
+ final List<BridgeOtherConfigs> otherConfigs) throws InterruptedException {
+
NodeBuilder bridgeNodeBuilder = new NodeBuilder();
- InstanceIdentifier<Node> bridgeIid =
- SouthboundMapper.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
- NodeId bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
+ 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));
- ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
- ovsdbBridgeAugmentationBuilder.setFailMode(
- SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
- setManagedBy(ovsdbBridgeAugmentationBuilder, connectionInfo);
+ 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) {
- InstanceIdentifier<Node> bridgeIid =
- SouthboundMapper.createInstanceIdentifier(connectionInfo,
- new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME));
- Node bridgeNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
+ return getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME);
+ }
+
+ /**
+ * Extract the <code>store</code> type data store contents for the particular bridge identified by
+ * <code>bridgeName</code>.
+ *
+ * @param connectionInfo
+ * @param bridgeName
+ * @param store defined by the <code>LogicalDatastoreType</code> enumeration
+ * @return <code>store</code> 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 <code>LogicalDataStoreType.OPERATIONAL</code> type data store contents for the particular bridge
+ * identified by <code>bridgeName</code>
+ *
+ * @param connectionInfo
+ * @param bridgeName
+ * @see <code>SouthboundIT.getBridge(ConnectionInfo, String, LogicalDatastoreType)</code>
+ * @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
+ */
+ private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo, String bridgeName) {
+ return getBridge(connectionInfo, bridgeName, LogicalDatastoreType.OPERATIONAL);
+ }
+
+ /**
+ * Extract the node contents from <code>store</code> type data store for the
+ * bridge identified by <code>bridgeName</code>
+ *
+ * @param connectionInfo
+ * @param bridgeName
+ * @param store defined by the <code>LogicalDatastoreType</code> enumeration
+ * @return <code>store</code> type data store contents
+ */
+ private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) {
+ InstanceIdentifier<Node> bridgeIid =
+ createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(bridgeName));
+ return mdsalUtils.read(store, bridgeIid);
+ }
+
+ /**
+ * Extract the node contents from <code>LogicalDataStoreType.OPERATIONAL</code> data store for the
+ * bridge identified by <code>bridgeName</code>
+ *
+ * @param connectionInfo
+ * @param bridgeName
+ * @return <code>LogicalDatastoreType.OPERATIONAL</code> 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,
- SouthboundMapper.createInstanceIdentifier(connectionInfo,
- new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME)));
+ createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(bridgeName)));
Thread.sleep(OVSDB_UPDATE_TIMEOUT);
return result;
}
Assert.assertTrue(deleteBridge(connectionInfo));
- //Assert.assertFalse(disconnectOvsdbNode(connectionInfo));
- Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
+ Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
}
private InstanceIdentifier<Node> getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) {
- return SouthboundMapper.createInstanceIdentifier(connectionInfo,
- bridge.getBridgeName());
+ return createInstanceIdentifier(connectionInfo,
+ bridge.getBridgeName());
+ }
+
+ /**
+ * Extracts the <code>TerminationPointAugmentation</code> for the <code>index</code> <code>TerminationPoint</code>
+ * on <code>bridgeName</code>
+ *
+ * @param connectionInfo
+ * @param bridgeName
+ * @param store
+ * @param index
+ * @return
+ */
+ private OvsdbTerminationPointAugmentation getOvsdbTerminationPointAugmentation(
+ ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store, int index ) {
+
+ List<TerminationPoint> tpList = getBridgeNode(connectionInfo, bridgeName, store).getTerminationPoint();
+ if (tpList == null) {
+ return null;
+ }
+ return ((OvsdbTerminationPointAugmentation)
+ tpList.get(index)
+ .getAugmentation(OvsdbTerminationPointAugmentation.class));
}
@Test
- public void testTerminationPointOfPort() throws InterruptedException {
+ 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(SouthboundMapper.createInstanceIdentifier(
+ NodeId nodeId = SouthboundMapper.createManagedNodeId(createInstanceIdentifier(
connectionInfo, bridge.getBridgeName()));
OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
createGenericOvsdbTerminationPointAugmentationBuilder();
String portName = "testOfPort";
ovsdbTerminationBuilder.setName(portName);
- Long ofPortExpected = new Long(45002);
- ovsdbTerminationBuilder.setOfport(ofPortExpected);
+
+ ovsdbTerminationBuilder.setOfport(OFPORT_EXPECTED);
Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
Assert.assertNotNull(terminationPointNode);
+ // READ
List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
for (TerminationPoint terminationPoint : terminationPoints) {
OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
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(ofPortExpected) || ofPort.equals(new Long(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 testTerminationPointOfPortRequest() throws InterruptedException {
+ 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 = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
+ NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
connectionInfo, bridge.getBridgeName()));
OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
createGenericOvsdbTerminationPointAugmentationBuilder();
String portName = "testOfPortRequest";
ovsdbTerminationBuilder.setName(portName);
- Long ofPortExpected = new Long(45008);
- Integer ofPortRequestExpected = ofPortExpected.intValue();
- Long ofPortInput = new Long(45008);
- ovsdbTerminationBuilder.setOfport(ofPortInput);
+ Integer ofPortRequestExpected = OFPORT_EXPECTED.intValue();
+ ovsdbTerminationBuilder.setOfport(OFPORT_INPUT);
ovsdbTerminationBuilder.setOfportRequest(ofPortRequestExpected);
Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
Assert.assertNotNull(terminationPointNode);
+ // READ
List<TerminationPoint> 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(ofPortExpected) || ofPort.equals(new Long(1)));
+ // 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();
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
+ * <code>TerminationPointAugmentationBuilder.setPortExternalIds()</code>
+ * EXPECTED is the List we expect to receive after calling
+ * <code>TerminationPointAugmentationBuilder.getPortExternalIds()</code>
+ */
+ private Map<String, Map<String, List<PortExternalIds>>> generatePortExternalIdsTestCases() {
+ Map<String, Map<String, List<PortExternalIds>>> testMap =
+ new HashMap<String, Map<String, List<PortExternalIds>>>();
+
+ 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<PortExternalIds> oneExternalId = (List<PortExternalIds>) 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<String,List<PortExternalIds>> 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<PortExternalIds> fiveExternalId = (List<PortExternalIds>) 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<PortExternalIds> oneGoodOneBadInput = (List<PortExternalIds>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<PortExternalIds> 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<PortExternalIds>) 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 <code>SouthboundIT.testCRUDPortExternalIds()</code>
+ * This is helper test method to compare a test "set" of BridgeExternalIds against an expected "set"
+ */
+ private void assertExpectedPortExternalIdsExist( List<PortExternalIds> expected,
+ List<PortExternalIds> test ) {
+
+ if (expected != null) {
+ for (PortExternalIds expectedExternalId : expected) {
+ Assert.assertTrue(test.contains(expectedExternalId));
+ }
+ }
}
+ /*
+ * Tests the CRUD operations for <code>Port</code>
+ * <code>external_ids</code>.
+ *
+ * @see <code>SouthboundIT.generatePortExternalIdsTestCases()</code> for
+ * specific test case information
+ */
@Test
- public void testTerminationPointPortExternalIds() throws InterruptedException {
+ public void testCRUDTerminationPointPortExternalIds()
+ throws InterruptedException, ExecutionException {
+
+ final String TEST_PREFIX = "CRUDTPPortExternalIds";
+
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
connectOvsdbNode(connectionInfo);
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testPortExternalIds";
- ovsdbTerminationBuilder.setName(portName);
- //setup
- PortExternalIdsBuilder externalIdsBuilder1 = new PortExternalIdsBuilder();
- externalIdsBuilder1.setExternalIdKey("portExternalIdKey1");
- externalIdsBuilder1.setExternalIdValue("portExternalIdValue1");
- PortExternalIdsBuilder externalIdsBuilder2 = new PortExternalIdsBuilder();
- externalIdsBuilder2.setExternalIdKey("portExternalIdKey2");
- externalIdsBuilder2.setExternalIdValue("portExternalIdValue2");
- List<PortExternalIds> portExternalIds = Lists.newArrayList(externalIdsBuilder1.build(),
- externalIdsBuilder2.build());
- ovsdbTerminationBuilder.setPortExternalIds(portExternalIds);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
- Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
- Assert.assertNotNull(terminationPointNode);
+ // updateFromTestCases represent the original test case value.
+ // updateToTestCases represent the new value after the update has been
+ // performed.
+ Map<String, Map<String, List<PortExternalIds>>> updateFromTestCases =
+ generatePortExternalIdsTestCases();
+ Map<String, Map<String, List<PortExternalIds>>> updateToTestCases =
+ generatePortExternalIdsTestCases();
+ Map<String, List<PortExternalIds>> updateFromTestCase;
+ List<PortExternalIds> updateFromInputExternalIds;
+ List<PortExternalIds> updateFromExpectedExternalIds;
+ Map<String, List<PortExternalIds>> updateToTestCase;
+ List<PortExternalIds> updateToInputExternalIds;
+ List<PortExternalIds> 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));
+ }
- List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
- for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- List<PortExternalIds> actualPortExternalIds = ovsdbTerminationPointAugmentation.getPortExternalIds();
- Assert.assertTrue((portExternalIds.size() == actualPortExternalIds.size()));
- for (PortExternalIds portExternalId : portExternalIds) {
- Assert.assertTrue(actualPortExternalIds.contains(portExternalId));
- }
+ class TestCRUDTerminationPointPortExternalIdsRunnable implements Runnable {
+ ConnectionInfo connectionInfo;
+ String testBridgeName;
+ String testPortName;
+ List<PortExternalIds> updateFromInputExternalIds;
+ List<PortExternalIds> updateFromExpectedExternalIds;
+ List<PortExternalIds> updateToInputExternalIds;
+ List<PortExternalIds> updateToExpectedExternalIds;
+
+ public TestCRUDTerminationPointPortExternalIdsRunnable(
+ ConnectionInfo connectionInfo,
+ String testBridgeName, String testPortName,
+ List<PortExternalIds> updateFromInputExternalIds,
+ List<PortExternalIds> updateFromExpectedExternalIds,
+ List<PortExternalIds> updateToInputExternalIds,
+ List<PortExternalIds> 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();
}
}
- Assert.assertTrue(deleteBridge(connectionInfo));
+
+ 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<PortExternalIds> updateFromConfigurationExternalIds =
+ updateFromConfigurationTerminationPointAugmentation
+ .getPortExternalIds();
+ assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds);
+ OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<PortExternalIds> 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<PortExternalIds> updateToConfigurationExternalIds = updateToConfigurationTerminationPointAugmentation
+ .getPortExternalIds();
+ assertExpectedPortExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds);
+ assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds);
+ OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<PortExternalIds> 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
+ * <code>TerminationPointAugmentationBuilder.setInterfaceExternalIds()</code>
+ * EXPECTED is the List we expect to receive after calling
+ * <code>TerminationPointAugmentationBuilder.getInterfaceExternalIds()</code>
+ */
+ private Map<String, Map<String, List<InterfaceExternalIds>>> generateInterfaceExternalIdsTestCases() {
+ Map<String, Map<String, List<InterfaceExternalIds>>> testMap =
+ new HashMap<String, Map<String, List<InterfaceExternalIds>>>();
+
+ 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<InterfaceExternalIds> oneExternalId = (List<InterfaceExternalIds>) 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<String,List<InterfaceExternalIds>> 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<InterfaceExternalIds> fiveExternalId = (List<InterfaceExternalIds>) 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<InterfaceExternalIds> oneGoodOneBadInput = (List<InterfaceExternalIds>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<InterfaceExternalIds> 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<InterfaceExternalIds>) 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 <code>SouthboundIT.testCRUDInterfaceExternalIds()</code>
+ * This is helper test method to compare a test "set" of InterfaceExternalIds against an expected "set"
+ */
+ private void assertExpectedInterfaceExternalIdsExist( List<InterfaceExternalIds> expected,
+ List<InterfaceExternalIds> test ) {
+
+ if (expected != null) {
+ for (InterfaceExternalIds expectedExternalId : expected) {
+ Assert.assertTrue(test.contains(expectedExternalId));
+ }
+ }
+ }
+
+ /*
+ * Tests the CRUD operations for <code>Interface</code> <code>external_ids</code>.
+ *
+ * @see <code>SouthboundIT.generateInterfaceExternalIdsTestCases()</code> for specific test case information
+ */
@Test
- public void testTerminationPointInterfaceExternalIds() throws InterruptedException {
+ 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);
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testInterfaceExternalIds";
- ovsdbTerminationBuilder.setName(portName);
- //setup
- InterfaceExternalIdsBuilder externalIdsBuilder1 = new InterfaceExternalIdsBuilder();
- externalIdsBuilder1.setExternalIdKey("interfaceExternalIdKey1");
- externalIdsBuilder1.setExternalIdValue("interfaceExternalIdValue1");
- InterfaceExternalIdsBuilder externalIdsBuilder2 = new InterfaceExternalIdsBuilder();
- externalIdsBuilder2.setExternalIdKey("interfaceExternalIdKey2");
- externalIdsBuilder2.setExternalIdValue("interfaceExternalIdValue2");
- List<InterfaceExternalIds> interfaceExternalIds = Lists.newArrayList(externalIdsBuilder1.build(),
- externalIdsBuilder2.build());
- ovsdbTerminationBuilder.setInterfaceExternalIds(interfaceExternalIds);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
- Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
- Assert.assertNotNull(terminationPointNode);
+ // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
+ // the update has been performed.
+ Map<String, Map<String, List<InterfaceExternalIds>>> updateFromTestCases =
+ generateInterfaceExternalIdsTestCases();
+ Map<String, Map<String, List<InterfaceExternalIds>>> updateToTestCases =
+ generateInterfaceExternalIdsTestCases();
+ Map<String, List<InterfaceExternalIds>> updateFromTestCase;
+ List<InterfaceExternalIds> updateFromInputExternalIds;
+ List<InterfaceExternalIds> updateFromExpectedExternalIds;
+ Map<String, List<InterfaceExternalIds>> updateToTestCase;
+ List<InterfaceExternalIds> updateToInputExternalIds;
+ List<InterfaceExternalIds> 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));
+ }
- List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
- for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- List<InterfaceExternalIds> actualInterfaceExternalIds = ovsdbTerminationPointAugmentation.
- getInterfaceExternalIds();
- Assert.assertTrue((interfaceExternalIds.size() == actualInterfaceExternalIds.size()));
- for (InterfaceExternalIds interfaceExternalId : interfaceExternalIds) {
- Assert.assertTrue(actualInterfaceExternalIds.contains(interfaceExternalId));
- }
+ class TestCRUDTerminationPointInterfaceExternalIdsRunnable implements Runnable {
+
+ ConnectionInfo connectionInfo;
+ String testBridgeName;
+ String testPortName;
+ List<InterfaceExternalIds> updateFromInputExternalIds;
+ List<InterfaceExternalIds> updateFromExpectedExternalIds;
+ List<InterfaceExternalIds> updateToInputExternalIds;
+ List<InterfaceExternalIds> updateToExpectedExternalIds;
+
+ TestCRUDTerminationPointInterfaceExternalIdsRunnable(
+ ConnectionInfo connectionInfo, String testBridgeName,
+ String testPortName,
+ List<InterfaceExternalIds> updateFromInputExternalIds,
+ List<InterfaceExternalIds> updateFromExpectedExternalIds,
+ List<InterfaceExternalIds> updateToInputExternalIds,
+ List<InterfaceExternalIds> 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();
}
}
- Assert.assertTrue(deleteBridge(connectionInfo));
+
+ 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<InterfaceExternalIds> updateFromConfigurationExternalIds =
+ updateFromConfigurationTerminationPointAugmentation
+ .getInterfaceExternalIds();
+ assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
+ updateFromConfigurationExternalIds);
+ OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<InterfaceExternalIds> updateFromOperationalExternalIds =
+ updateFromOperationalTerminationPointAugmenation
+ .getInterfaceExternalIds();
+ assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
+ updateFromOperationalExternalIds);
+
+ // UPDATE: update the external_ids
+ testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
+ OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder =
+ new OvsdbTerminationPointAugmentationBuilder();
+ tpUpdateAugmentationBuilder.setInterfaceExternalIds(updateToInputExternalIds);
+ InstanceIdentifier<Node> 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<InterfaceExternalIds> updateToConfigurationExternalIds =
+ updateToConfigurationTerminationPointAugmentation
+ .getInterfaceExternalIds();
+ assertExpectedInterfaceExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds);
+ assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
+ updateToConfigurationExternalIds);
+ OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<InterfaceExternalIds> 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
+ * <code>TerminationPointAugmentationBuilder.setOptions()</code>
+ * EXPECTED is the List we expect to receive after calling
+ * <code>TerminationPointAugmentationBuilder.getOptions()</code>
+ */
+ private Map<String, Map<String, List<Options>>> generateTerminationPointOptionsTestCases() {
+ Map<String, Map<String, List<Options>>> testMap =
+ new HashMap<String, Map<String, List<Options>>>();
+
+ 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<Options> oneOptions = (List<Options>) 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<String,List<Options>> 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<Options> fiveOptions = (List<Options>) 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<Options> oneGoodOneBadInput = (List<Options>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<Options> 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<Options>) 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 <code>SouthboundIT.testCRUDTerminationPointOptions()</code>
+ * This is helper test method to compare a test "set" of Options against an expected "set"
+ */
+ private void assertExpectedOptionsExist( List<Options> expected,
+ List<Options> test ) {
+
+ if (expected != null) {
+ for (Options expectedOption : expected) {
+ Assert.assertTrue(test.contains(expectedOption));
+ }
+ }
+ }
+
+ /*
+ * Tests the CRUD operations for <code>TerminationPoint</code> <code>options</code>.
+ *
+ * @see <code>SouthboundIT.generateTerminationPointOptions()</code> for specific test case information
+ */
@Test
- public void testTerminationPointOptions() throws InterruptedException {
+ public void testCRUDTerminationPointOptions() throws InterruptedException {
+ final String TEST_PREFIX = "CRUDTPOptions";
+
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
connectOvsdbNode(connectionInfo);
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testInterfaceOptions";
- ovsdbTerminationBuilder.setName(portName);
- //setup
- OptionsBuilder optionsBuilder1 = new OptionsBuilder();
- optionsBuilder1.setOption("option1");
- optionsBuilder1.setValue("optionValue1");
- OptionsBuilder optionsBuilder2 = new OptionsBuilder();
- optionsBuilder2.setOption("option2");
- optionsBuilder2.setValue("optionValue2");
- List<Options> options = Lists.newArrayList(optionsBuilder1.build(),
- optionsBuilder2.build());
- ovsdbTerminationBuilder.setOptions(options);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
- Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
- Assert.assertNotNull(terminationPointNode);
+ // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
+ // the update has been performed.
+ Map<String, Map<String, List<Options>>> updateFromTestCases =
+ generateTerminationPointOptionsTestCases();
+ Map<String, Map<String, List<Options>>> updateToTestCases =
+ generateTerminationPointOptionsTestCases();
+ Map<String, List<Options>> updateFromTestCase;
+ List<Options> updateFromInputOptions;
+ List<Options> updateFromExpectedOptions;
+ Map<String, List<Options>> updateToTestCase;
+ List<Options> updateToInputOptions;
+ List<Options> 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));
+ }
- List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
- for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- List<Options> actualOptions = ovsdbTerminationPointAugmentation.
- getOptions();
- Assert.assertTrue((options.size() == actualOptions.size()));
- for (Options option : options) {
- Assert.assertTrue(actualOptions.contains(option));
- }
+ class TestCRUDTerminationPointOptionsRunnable implements Runnable {
+
+ ConnectionInfo connectionInfo;
+ String testBridgeName;
+ String testPortName;
+ List<Options> updateFromInputOptions;
+ List<Options> updateFromExpectedOptions;
+ List<Options> updateToInputOptions;
+ List<Options> updateToExpectedOptions;
+
+ TestCRUDTerminationPointOptionsRunnable(
+ ConnectionInfo connectionInfo, String testBridgeName,
+ String testPortName,
+ List<Options> updateFromInputOptions,
+ List<Options> updateFromExpectedOptions,
+ List<Options> updateToInputOptions,
+ List<Options> 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();
}
}
- Assert.assertTrue(deleteBridge(connectionInfo));
+
+ 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<Options> updateFromConfigurationOptions = updateFromConfigurationTerminationPointAugmentation
+ .getOptions();
+ assertExpectedOptionsExist(updateFromExpectedOptions,
+ updateFromConfigurationOptions);
+ OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<Options> updateFromOperationalOptions = updateFromOperationalTerminationPointAugmenation
+ .getOptions();
+ assertExpectedOptionsExist(updateFromExpectedOptions,
+ updateFromOperationalOptions);
+
+ // UPDATE: update the external_ids
+ testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
+ OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder =
+ new OvsdbTerminationPointAugmentationBuilder();
+ tpUpdateAugmentationBuilder.setOptions(updateToInputOptions);
+ InstanceIdentifier<Node> 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<Options> updateToConfigurationOptions = updateToConfigurationTerminationPointAugmentation
+ .getOptions();
+ assertExpectedOptionsExist(updateToExpectedOptions, updateToConfigurationOptions);
+ assertExpectedOptionsExist(updateFromExpectedOptions, updateToConfigurationOptions);
+ OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<Options> 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
+ * <code>TerminationPointAugmentationBuilder.setInterfaceOtherConfigs()</code>
+ * EXPECTED is the List we expect to receive after calling
+ * <code>TerminationPointAugmentationBuilder.getInterfaceOtherConfigs()</code>
+ */
+ private Map<String, Map<String, List<InterfaceOtherConfigs>>> generateInterfaceOtherConfigsTestCases() {
+ Map<String, Map<String, List<InterfaceOtherConfigs>>> testMap =
+ new HashMap<String, Map<String, List<InterfaceOtherConfigs>>>();
+
+ 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<InterfaceOtherConfigs> oneOtherConfigs = (List<InterfaceOtherConfigs>) 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<String,List<InterfaceOtherConfigs>> 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<InterfaceOtherConfigs> fiveInterfaceOtherConfigs = (List<InterfaceOtherConfigs>) 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<InterfaceOtherConfigs> oneGoodOneBadInput = (List<InterfaceOtherConfigs>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<InterfaceOtherConfigs> 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<InterfaceOtherConfigs>) 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 <code>SouthboundIT.testCRUDInterfaceOtherConfigs()</code>
+ * This is helper test method to compare a test "set" of Options against an expected "set"
+ */
+ private void assertExpectedInterfaceOtherConfigsExist( List<InterfaceOtherConfigs> expected,
+ List<InterfaceOtherConfigs> test ) {
+
+ if (expected != null && test != null) {
+ for (InterfaceOtherConfigs expectedOtherConfigs : expected) {
+ Assert.assertTrue(test.contains(expectedOtherConfigs));
+ }
+ }
+ }
+
+ /*
+ * Tests the CRUD operations for <code>Interface</code> <code>other_configs</code>.
+ *
+ * @see <code>SouthboundIT.generateInterfaceExternalIdsTestCases()</code> for specific test case information
+ */
@Test
- public void testTerminationPointInterfaceOtherConfigs() throws InterruptedException {
+ public void testCRUDTerminationPointInterfaceOtherConfigs() throws InterruptedException {
+ final String TEST_PREFIX = "CRUDTPInterfaceOtherConfigs";
+
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
connectOvsdbNode(connectionInfo);
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testInterfaceOtherConfigs";
- ovsdbTerminationBuilder.setName(portName);
- //setup
- InterfaceOtherConfigsBuilder interfaceBuilder1 = new InterfaceOtherConfigsBuilder();
- interfaceBuilder1.setOtherConfigKey("interfaceOtherConfigsKey1");
- interfaceBuilder1.setOtherConfigValue("interfaceOtherConfigsValue1");
- InterfaceOtherConfigsBuilder interfaceBuilder2 = new InterfaceOtherConfigsBuilder();
- interfaceBuilder2.setOtherConfigKey("interfaceOtherConfigsKey2");
- interfaceBuilder2.setOtherConfigValue("interfaceOtherConfigsValue2");
- List<InterfaceOtherConfigs> interfaceOtherConfigs = Lists.newArrayList(interfaceBuilder1.build(),
- interfaceBuilder2.build());
- ovsdbTerminationBuilder.setInterfaceOtherConfigs(interfaceOtherConfigs);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- Thread.sleep(1000);
- InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
- Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
- Assert.assertNotNull(terminationPointNode);
+ // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
+ // the update has been performed.
+ Map<String, Map<String, List<InterfaceOtherConfigs>>> updateFromTestCases =
+ generateInterfaceOtherConfigsTestCases();
+ Map<String, Map<String, List<InterfaceOtherConfigs>>> updateToTestCases =
+ generateInterfaceOtherConfigsTestCases();
+ Map<String, List<InterfaceOtherConfigs>> updateFromTestCase;
+ List<InterfaceOtherConfigs> updateFromInputOtherConfigs;
+ List<InterfaceOtherConfigs> updateFromExpectedOtherConfigs;
+ Map<String, List<InterfaceOtherConfigs>> updateToTestCase;
+ List<InterfaceOtherConfigs> updateToInputOtherConfigs;
+ List<InterfaceOtherConfigs> 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));
+ }
- List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
- for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- List<InterfaceOtherConfigs> actualInterfaceOtherConfigs = ovsdbTerminationPointAugmentation.
- getInterfaceOtherConfigs();
- Assert.assertNotNull(actualInterfaceOtherConfigs);
- Assert.assertNotNull(interfaceOtherConfigs);
- Assert.assertTrue(interfaceOtherConfigs.size() == actualInterfaceOtherConfigs.size());
- for (InterfaceOtherConfigs interfaceOtherConfig : interfaceOtherConfigs) {
- Assert.assertTrue(actualInterfaceOtherConfigs.contains(interfaceOtherConfig));
- }
+ class TestCRUDTerminationPointInterfaceOtherConfigsRunnable implements Runnable {
+
+ ConnectionInfo connectionInfo;
+ String testBridgeName;
+ String testPortName;
+ List<InterfaceOtherConfigs> updateFromInputOtherConfigs;
+ List<InterfaceOtherConfigs> updateFromExpectedOtherConfigs;
+ List<InterfaceOtherConfigs> updateToInputOtherConfigs;
+ List<InterfaceOtherConfigs> updateToExpectedOtherConfigs;
+
+ TestCRUDTerminationPointInterfaceOtherConfigsRunnable(
+ ConnectionInfo connectionInfo, String testBridgeName,
+ String testPortName,
+ List<InterfaceOtherConfigs> updateFromInputOtherConfigs,
+ List<InterfaceOtherConfigs> updateFromExpectedOtherConfigs,
+ List<InterfaceOtherConfigs> updateToInputOtherConfigs,
+ List<InterfaceOtherConfigs> 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<InterfaceOtherConfigs> 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<InterfaceOtherConfigs> 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<Node> 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<InterfaceOtherConfigs> updateToConfigurationOtherConfigs =
+ updateToConfigurationTerminationPointAugmentation
+ .getInterfaceOtherConfigs();
+ assertExpectedInterfaceOtherConfigsExist(updateToExpectedOtherConfigs,
+ updateToConfigurationOtherConfigs);
+ assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs,
+ updateToConfigurationOtherConfigs);
+ OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<InterfaceOtherConfigs> 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
+ * <code>TerminationPointAugmentationBuilder.setPortOtherConfigs()</code>
+ * EXPECTED is the List we expect to receive after calling
+ * <code>TerminationPointAugmentationBuilder.getPortOtherConfigs()</code>
+ */
+ private Map<String, Map<String, List<PortOtherConfigs>>> generatePortOtherConfigsTestCases() {
+ Map<String, Map<String, List<PortOtherConfigs>>> testMap =
+ new HashMap<String, Map<String, List<PortOtherConfigs>>>();
+
+ 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<PortOtherConfigs> oneOtherConfigs = (List<PortOtherConfigs>) 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<String,List<PortOtherConfigs>> 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<PortOtherConfigs> fivePortOtherConfigs = (List<PortOtherConfigs>) 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<PortOtherConfigs> oneGoodOneBadInput = (List<PortOtherConfigs>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<PortOtherConfigs> 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<PortOtherConfigs>) 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 <code>SouthboundIT.testCRUDPortOtherConfigs()</code>
+ * This is helper test method to compare a test "set" of Options against an expected "set"
+ */
+ private void assertExpectedPortOtherConfigsExist( List<PortOtherConfigs> expected,
+ List<PortOtherConfigs> test ) {
+
+ if (expected != null && test != null) {
+ for (PortOtherConfigs expectedOtherConfigs : expected) {
+ Assert.assertTrue(test.contains(expectedOtherConfigs));
}
}
- Assert.assertTrue(deleteBridge(connectionInfo));
}
+ /*
+ * Tests the CRUD operations for <code>Port</code> <code>other_configs</code>.
+ *
+ * @see <code>SouthboundIT.generatePortExternalIdsTestCases()</code> for specific test case information
+ */
@Test
- public void testTerminationPointPortOtherConfigs() throws InterruptedException {
+ public void testCRUDTerminationPointPortOtherConfigs() throws InterruptedException {
+ final String TEST_PREFIX = "CRUDTPPortOtherConfigs";
+
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
connectOvsdbNode(connectionInfo);
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testPortOtherConfigs";
- ovsdbTerminationBuilder.setName(portName);
- //setup
- PortOtherConfigsBuilder portBuilder1 = new PortOtherConfigsBuilder();
- portBuilder1.setOtherConfigKey("portOtherConfigsKey1");
- portBuilder1.setOtherConfigValue("portOtherConfigsValue1");
- PortOtherConfigsBuilder portBuilder2 = new PortOtherConfigsBuilder();
- portBuilder2.setOtherConfigKey("portOtherConfigsKey2");
- portBuilder2.setOtherConfigValue("portOtherConfigsValue2");
- List<PortOtherConfigs> portOtherConfigs = Lists.newArrayList(portBuilder1.build(),
- portBuilder2.build());
- ovsdbTerminationBuilder.setPortOtherConfigs(portOtherConfigs);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
- Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
- Assert.assertNotNull(terminationPointNode);
+ // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
+ // the update has been performed.
+ Map<String, Map<String, List<PortOtherConfigs>>> updateFromTestCases =
+ generatePortOtherConfigsTestCases();
+ Map<String, Map<String, List<PortOtherConfigs>>> updateToTestCases =
+ generatePortOtherConfigsTestCases();
+ Map<String, List<PortOtherConfigs>> updateFromTestCase;
+ List<PortOtherConfigs> updateFromInputOtherConfigs;
+ List<PortOtherConfigs> updateFromExpectedOtherConfigs;
+ Map<String, List<PortOtherConfigs>> updateToTestCase;
+ List<PortOtherConfigs> updateToInputOtherConfigs;
+ List<PortOtherConfigs> 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));
+ }
- List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
- for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- List<PortOtherConfigs> actualPortOtherConfigs = ovsdbTerminationPointAugmentation.
- getPortOtherConfigs();
- Assert.assertTrue((portOtherConfigs.size() == actualPortOtherConfigs.size()));
- for (PortOtherConfigs portOtherConfig : portOtherConfigs) {
- Assert.assertTrue(actualPortOtherConfigs.contains(portOtherConfig));
- }
+ class TestCRUDTerminationPointPortOtherConfigsRunnable implements Runnable {
+ ConnectionInfo connectionInfo;
+ String testBridgeName;
+ String testPortName;
+ List<PortOtherConfigs> updateFromInputOtherConfigs;
+ List<PortOtherConfigs> updateFromExpectedOtherConfigs;
+ List<PortOtherConfigs> updateToInputOtherConfigs;
+ List<PortOtherConfigs> updateToExpectedOtherConfigs;
+
+ TestCRUDTerminationPointPortOtherConfigsRunnable(
+ ConnectionInfo connectionInfo, String testBridgeName,
+ String testPortName,
+ List<PortOtherConfigs> updateFromInputOtherConfigs,
+ List<PortOtherConfigs> updateFromExpectedOtherConfigs,
+ List<PortOtherConfigs> updateToInputOtherConfigs,
+ List<PortOtherConfigs> 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();
}
}
- Assert.assertTrue(deleteBridge(connectionInfo));
+
+ 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<PortOtherConfigs> 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<PortOtherConfigs> 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<Node> 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<PortOtherConfigs> updateToConfigurationOtherConfigs = updateToConfigurationTerminationPointAugmentation
+ .getPortOtherConfigs();
+ assertExpectedPortOtherConfigsExist(updateToExpectedOtherConfigs,
+ updateToConfigurationOtherConfigs);
+ assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs,
+ updateToConfigurationOtherConfigs);
+ OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ List<PortOtherConfigs> updateToOperationalOtherConfigs = updateToOperationalTerminationPointAugmentation
+ .getPortOtherConfigs();
+ if (updateFromExpectedOtherConfigs != null) {
+ assertExpectedPortOtherConfigsExist(updateToExpectedOtherConfigs,
+ updateToOperationalOtherConfigs);
+ assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs,
+ updateToOperationalOtherConfigs);
+ }
+
+ // DELETE
+ Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
+ }
}
@Test
- public void testTerminationPointVlan() throws InterruptedException {
+ 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);
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME);
Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
+ NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
connectionInfo, bridge.getBridgeName()));
OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
createGenericOvsdbTerminationPointAugmentationBuilder();
String portName = "testTerminationPointVlanId";
ovsdbTerminationBuilder.setName(portName);
- //setup
- Integer vlanId = new Integer(4000);
- ovsdbTerminationBuilder.setVlanTag(new VlanId(vlanId));
-
+ ovsdbTerminationBuilder.setVlanTag(new VlanId(CREATED_VLAN_ID));
Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
Assert.assertNotNull(terminationPointNode);
+ // READ
List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
+ OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = null;
for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
+ 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<Node> 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)) {
- //test
VlanId actualVlanId = ovsdbTerminationPointAugmentation.getVlanTag();
Assert.assertNotNull(actualVlanId);
Integer actualVlanIdInt = actualVlanId.getValue();
- Assert.assertTrue(actualVlanIdInt.equals(vlanId));
+ Assert.assertEquals(UPDATED_VLAN_ID, actualVlanIdInt);
}
}
+
+ // DELETE
Assert.assertTrue(deleteBridge(connectionInfo));
+ Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
@Test
- public void testTerminationPointVlanModes() throws InterruptedException {
+ 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) {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ // CREATE
Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
+ NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
connectionInfo, bridge.getBridgeName()));
OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
createGenericOvsdbTerminationPointAugmentationBuilder();
String portName = "testTerminationPointVlanMode" + vlanMode.toString();
ovsdbTerminationBuilder.setName(portName);
- //setup
ovsdbTerminationBuilder.setVlanMode(vlanMode);
Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
Assert.assertNotNull(terminationPointNode);
+ // READ
List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
for (TerminationPoint terminationPoint : terminationPoints) {
OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
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<Node> 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<Set<Integer>> generateVlanSets() {
}
@Test
- public void testTerminationPointVlanTrunks() throws InterruptedException {
- ArrayList<Set<Integer>> vlanSets = generateVlanSets();
+ public void testCRUDTerminationPointVlanTrunks() throws InterruptedException {
+ final List<Trunks> UPDATED_TRUNKS = buildTrunkList(Sets.newHashSet(2011));
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
+ connectOvsdbNode(connectionInfo);
+ Iterable<Set<Integer>> vlanSets = generateVlanSets();
int testCase = 0;
for (Set<Integer> vlanSet : vlanSets) {
++testCase;
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ // CREATE
Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
Assert.assertNotNull(bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier(
+ NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
connectionInfo, bridge.getBridgeName()));
OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
createGenericOvsdbTerminationPointAugmentationBuilder();
String portName = "testTerminationPointVlanTrunks" + testCase;
ovsdbTerminationBuilder.setName(portName);
- //setup
List<Trunks> trunks = buildTrunkList(vlanSet);
ovsdbTerminationBuilder.setTrunks(trunks);
Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
Assert.assertNotNull(terminationPointNode);
+ // READ
List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
for (TerminationPoint terminationPoint : terminationPoints) {
OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
}
}
}
+
+
+ // UPDATE
+ NodeId testBridgeNodeId = getBridgeNode(connectionInfo, SouthboundITConstants.BRIDGE_NAME).getNodeId();
+ OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder =
+ new OvsdbTerminationPointAugmentationBuilder();
+ tpUpdateAugmentationBuilder.setTrunks(UPDATED_TRUNKS);
+ InstanceIdentifier<Node> 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));
}
- /**
- * isBundleReady is used to check if the requested bundle is Active
+ @Test
+ public void testGetOvsdbNodes() throws InterruptedException {
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
+ connectOvsdbNode(connectionInfo);
+ InstanceIdentifier<Topology> topologyPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
+
+ Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyPath);
+ InstanceIdentifier<Node> 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()
*/
- public void isBundleReady(BundleContext bundleContext, String bundleName) throws InterruptedException {
- boolean ready = false;
-
- while (!ready) {
- int state = Bundle.UNINSTALLED;
- Bundle[] bundles = bundleContext.getBundles();
- for (Bundle element : bundles) {
- if (element.getSymbolicName().equals(bundleName)) {
- state = element.getState();
- LOG.info(">>>>> bundle is ready {}", bundleName);
- break;
- }
+ private Map<String, Map<String, List<BridgeOtherConfigs>>> generateBridgeOtherConfigsTestCases() {
+ Map<String, Map<String, List<BridgeOtherConfigs>>> testMap =
+ new HashMap<String, Map<String, List<BridgeOtherConfigs>>>();
+
+ 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<BridgeOtherConfigs> oneOtherConfig = (List<BridgeOtherConfigs>) 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<String,List<BridgeOtherConfigs>> 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<BridgeOtherConfigs> fiveOtherConfig = (List<BridgeOtherConfigs>) 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<BridgeOtherConfigs> oneGoodOneBadInput = (List<BridgeOtherConfigs>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<BridgeOtherConfigs> 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<BridgeOtherConfigs>) 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 <code>SouthboundIT.testCRUDBridgeOtherConfigs()</code>
+ * This is helper test method to compare a test "set" of BridgeExternalIds against an expected "set"
+ */
+ private void assertExpectedBridgeOtherConfigsExist( List<BridgeOtherConfigs> expected,
+ List<BridgeOtherConfigs> test ) {
+
+ if (expected != null) {
+ for (BridgeOtherConfigs expectedOtherConfig : expected) {
+ Assert.assertTrue(test.contains(expectedOtherConfig));
}
- if (state != Bundle.ACTIVE) {
- LOG.info(">>>>> bundle not ready {}", bundleName);
- Thread.sleep(5000);
- } else {
- ready = true;
+ }
+ }
+
+ /*
+ * @see <code>SouthboundIT.generateBridgeOtherConfigsTestCases()</code> 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<String, Map<String, List<BridgeOtherConfigs>>> updateFromTestCases = generateBridgeOtherConfigsTestCases();
+ Map<String, Map<String, List<BridgeOtherConfigs>>> updateToTestCases = generateBridgeOtherConfigsTestCases();
+ Map<String, List<BridgeOtherConfigs>> updateFromTestCase;
+ Map<String, List<BridgeOtherConfigs>> updateToTestCase;
+ List<BridgeOtherConfigs> updateFromInputOtherConfigs;
+ List<BridgeOtherConfigs> updateFromExpectedOtherConfigs;
+ List<BridgeOtherConfigs> updateToInputOtherConfigs;
+ List<BridgeOtherConfigs> 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<BridgeOtherConfigs> updateFromInputOtherConfigs;
+ List<BridgeOtherConfigs> updateFromExpectedOtherConfigs;
+ List<BridgeOtherConfigs> updateToInputOtherConfigs;
+ List<BridgeOtherConfigs> updateToExpectedOtherConfigs;
+
+ TestCRUDBridgeOtherConfigsRunnable(
+ ConnectionInfo connectionInfo, String testBridgeName,
+ List<BridgeOtherConfigs> updateFromInputOtherConfigs,
+ List<BridgeOtherConfigs> updateFromExpectedOtherConfigs,
+ List<BridgeOtherConfigs> updateToInputOtherConfigs,
+ List<BridgeOtherConfigs> 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<BridgeOtherConfigs> updateFromConfigurationOtherConfigs = getBridge(connectionInfo, testBridgeName,
+ LogicalDatastoreType.CONFIGURATION).getBridgeOtherConfigs();
+ assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs,
+ updateFromConfigurationOtherConfigs);
+ List<BridgeOtherConfigs> updateFromOperationalOtherConfigs = getBridge(connectionInfo, testBridgeName)
+ .getBridgeOtherConfigs();
+ assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs,
+ updateFromOperationalOtherConfigs);
+
+ // UPDATE: update the external_ids
+ OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
+ bridgeAugmentationBuilder.setBridgeOtherConfigs(updateToInputOtherConfigs);
+ InstanceIdentifier<Node> 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<BridgeOtherConfigs> updateToConfigurationOtherConfigs = getBridge(connectionInfo, testBridgeName,
+ LogicalDatastoreType.CONFIGURATION).getBridgeOtherConfigs();
+ assertExpectedBridgeOtherConfigsExist(updateToExpectedOtherConfigs, updateToConfigurationOtherConfigs);
+ assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs,
+ updateToConfigurationOtherConfigs);
+ List<BridgeOtherConfigs> 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<String, Map<String, List<BridgeExternalIds>>> generateBridgeExternalIdsTestCases() {
+ Map<String, Map<String, List<BridgeExternalIds>>> testMap =
+ new HashMap<String, Map<String, List<BridgeExternalIds>>>();
+
+ 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<BridgeExternalIds> oneExternalId = (List<BridgeExternalIds>) 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<String,List<BridgeExternalIds>> 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<BridgeExternalIds> fiveExternalId = (List<BridgeExternalIds>) 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<BridgeExternalIds> oneGoodOneBadInput = (List<BridgeExternalIds>) Lists.newArrayList(
+ oneGood, oneBad);
+ List<BridgeExternalIds> 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<BridgeExternalIds>) 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 <code>SouthboundIT.testCRUDBridgeExternalIds()</code>
+ * This is helper test method to compare a test "set" of BridgeExternalIds against an expected "set"
+ */
+ private void assertExpectedBridgeExternalIdsExist( List<BridgeExternalIds> expected,
+ List<BridgeExternalIds> test ) {
+
+ if (expected != null) {
+ for (BridgeExternalIds expectedExternalId : expected) {
+ Assert.assertTrue(test.contains(expectedExternalId));
+ }
+ }
+ }
+
+ /*
+ * @see <code>SouthboundIT.generateBridgeExternalIdsTestCases()</code> 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<String, Map<String, List<BridgeExternalIds>>> updateFromTestCases = generateBridgeExternalIdsTestCases();
+ Map<String, Map<String, List<BridgeExternalIds>>> updateToTestCases = generateBridgeExternalIdsTestCases();
+ Map<String, List<BridgeExternalIds>> updateFromTestCase;
+ List<BridgeExternalIds> updateFromInputExternalIds;
+ List<BridgeExternalIds> updateFromExpectedExternalIds;
+ Map<String, List<BridgeExternalIds>> updateToTestCase;
+ List<BridgeExternalIds> updateToInputExternalIds;
+ List<BridgeExternalIds> 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<BridgeExternalIds> updateFromInputExternalIds;
+ List<BridgeExternalIds> updateFromExpectedExternalIds;
+ List<BridgeExternalIds> updateToInputExternalIds;
+ List<BridgeExternalIds> updateToExpectedExternalIds;
+
+ TestCRUDBridgeExternalIdsRunnable(
+ ConnectionInfo connectionInfo, String testBridgeName,
+ List<BridgeExternalIds> updateFromInputExternalIds,
+ List<BridgeExternalIds> updateFromExpectedExternalIds,
+ List<BridgeExternalIds> updateToInputExternalIds,
+ List<BridgeExternalIds> 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<BridgeExternalIds> updateFromConfigurationExternalIds = getBridge(connectionInfo, testBridgeName,
+ LogicalDatastoreType.CONFIGURATION).getBridgeExternalIds();
+ assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds);
+ List<BridgeExternalIds> updateFromOperationalExternalIds = getBridge(connectionInfo, testBridgeName)
+ .getBridgeExternalIds();
+ assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateFromOperationalExternalIds);
+
+ // UPDATE: update the external_ids
+ OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
+ bridgeAugmentationBuilder.setBridgeExternalIds(updateToInputExternalIds);
+ InstanceIdentifier<Node> 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<BridgeExternalIds> updateToConfigurationExternalIds = getBridge(connectionInfo, testBridgeName,
+ LogicalDatastoreType.CONFIGURATION).getBridgeExternalIds();
+ assertExpectedBridgeExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds);
+ assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds);
+ List<BridgeExternalIds> updateToOperationalExternalIds = getBridge(connectionInfo, testBridgeName)
+ .getBridgeExternalIds();
+ if (updateFromExpectedExternalIds != null) {
+ assertExpectedBridgeExternalIdsExist(updateToExpectedExternalIds, updateToOperationalExternalIds);
+ assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateToOperationalExternalIds);
+ }
+
+ // DELETE
+ Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
+ }
+ }
+
+ public static InstanceIdentifier<Node> 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<Node> iid) {
+ NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class);
+ return nodeKey.getNodeId();
}
}