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.when;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import java.io.File;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import javax.annotation.Nullable;
import javax.inject.Inject;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
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.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
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.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.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.ManagedNodeEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIdsBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
import org.ops4j.pax.exam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
@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;
- private static DataBroker dataBroker = null;
+ private static final int OVSDB_ROUNDTRIP_TIMEOUT = 10000;
+ private static final String FORMAT_STR = "%s_%s_%d";
private static String addressStr;
- private static String portStr;
+ private static int portNumber;
private static String connectionType;
- private static Boolean setup = false;
+ private static boolean setup = false;
private static MdsalUtils mdsalUtils = null;
-
- // TODO Constants copied frmo AbstractConfigTestBase, need to be removed (see TODO below)
- private static final String PAX_EXAM_UNPACK_DIRECTORY = "target/exam";
- private static final String KARAF_DEBUG_PORT = "5005";
- private static final String KARAF_DEBUG_PROP = "karaf.debug";
- private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack";
+ private static Node ovsdbNode;
+ private static int testMethodsRemaining;
@Inject
private BundleContext bundleContext;
+ private static final NotifyingDataChangeListener CONFIGURATION_LISTENER =
+ new NotifyingDataChangeListener(LogicalDatastoreType.CONFIGURATION);
+ private static final NotifyingDataChangeListener OPERATIONAL_LISTENER =
+ new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL);
+
+ private static class NotifyingDataChangeListener implements DataChangeListener {
+ private final LogicalDatastoreType type;
+ private final Set<InstanceIdentifier<?>> createdIids = new HashSet<>();
+ private final Set<InstanceIdentifier<?>> removedIids = new HashSet<>();
+ private final Set<InstanceIdentifier<?>> updatedIids = new HashSet<>();
+
+ private NotifyingDataChangeListener(LogicalDatastoreType type) {
+ this.type = type;
+ }
+
+ @Override
+ public void onDataChanged(
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> asyncDataChangeEvent) {
+ LOG.info("{} DataChanged: created {}", type, asyncDataChangeEvent.getCreatedData().keySet());
+ LOG.info("{} DataChanged: removed {}", type, asyncDataChangeEvent.getRemovedPaths());
+ LOG.info("{} DataChanged: updated {}", type, asyncDataChangeEvent.getUpdatedData().keySet());
+ createdIids.addAll(asyncDataChangeEvent.getCreatedData().keySet());
+ removedIids.addAll(asyncDataChangeEvent.getRemovedPaths());
+ updatedIids.addAll(asyncDataChangeEvent.getUpdatedData().keySet());
+ // Handled managed iids
+ for (DataObject obj : asyncDataChangeEvent.getCreatedData().values()) {
+ if (obj instanceof ManagedNodeEntry) {
+ ManagedNodeEntry managedNodeEntry = (ManagedNodeEntry) obj;
+ LOG.info("{} DataChanged: created managed {}", managedNodeEntry.getBridgeRef().getValue());
+ createdIids.add(managedNodeEntry.getBridgeRef().getValue());
+ }
+ }
+ synchronized(this) {
+ notifyAll();
+ }
+ }
+
+ public boolean isCreated(InstanceIdentifier<?> iid) {
+ return createdIids.remove(iid);
+ }
+
+ public boolean isRemoved(InstanceIdentifier<?> iid) {
+ return removedIids.remove(iid);
+ }
+
+ public boolean isUpdated(InstanceIdentifier<?> iid) {
+ return updatedIids.remove(iid);
+ }
+ }
+
@Configuration
public Option[] config() {
- // TODO Figure out how to use the parent Karaf setup, then just use super.config()
- Option[] options = new Option[] {
- when(Boolean.getBoolean(KARAF_DEBUG_PROP))
- .useOptions(KarafDistributionOption.debugConfiguration(KARAF_DEBUG_PORT, true)),
- karafDistributionConfiguration().frameworkUrl(getKarafDistro())
- .unpackDirectory(new File(PAX_EXAM_UNPACK_DIRECTORY))
- .useDeployFolder(false),
- when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()),
- // Works only if we don't specify the feature repo and name
- getLoggingOption()};
+ Option[] options = super.config();
Option[] propertyOptions = getPropertiesOptions();
- Option[] combinedOptions = new Option[options.length + propertyOptions.length];
+ 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()
@Override
public String getFeatureName() {
- return "odl-ovsdb-southbound-impl-ui";
+ return "odl-ovsdb-southbound-test";
}
protected String usage() {
LOG.info("getPropertiesOptions: Using the following properties: mode= {}, ip:port= {}:{}",
connectionType, addressStr, portStr);
- Option[] options = new Option[] {
+ return new Option[] {
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
SouthboundITConstants.SERVER_IPADDRESS, addressStr),
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
SouthboundITConstants.CONNECTION_TYPE, connectionType),
};
- return options;
}
@Before
@Override
public void setup() throws InterruptedException {
if (setup) {
- LOG.info("Skipping setUp, already initialized");
+ LOG.info("Skipping setup, already initialized");
return;
}
}
//dataBroker = getSession().getSALService(DataBroker.class);
Thread.sleep(3000);
- dataBroker = SouthboundProvider.getDb();
+ DataBroker dataBroker = SouthboundProvider.getDb();
Assert.assertNotNull("db should not be null", dataBroker);
addressStr = bundleContext.getProperty(SouthboundITConstants.SERVER_IPADDRESS);
- portStr = bundleContext.getProperty(SouthboundITConstants.SERVER_PORT);
+ String portStr = bundleContext.getProperty(SouthboundITConstants.SERVER_PORT);
+ try {
+ portNumber = Integer.parseInt(portStr);
+ } catch (NumberFormatException e) {
+ fail("Invalid port number " + portStr + System.lineSeparator() + usage());
+ }
connectionType = bundleContext.getProperty(SouthboundITConstants.CONNECTION_TYPE);
LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}",
- connectionType, addressStr, portStr);
+ connectionType, addressStr, portNumber);
if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_ACTIVE)) {
if (addressStr == null) {
fail(usage());
}
mdsalUtils = new MdsalUtils(dataBroker);
+ final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
+ final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
+ dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+ iid, CONFIGURATION_LISTENER, AsyncDataBroker.DataChangeScope.SUBTREE);
+ dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ iid, OPERATIONAL_LISTENER, AsyncDataBroker.DataChangeScope.SUBTREE);
+
+ ovsdbNode = connectOvsdbNode(connectionInfo);
+
+ // Let's count the test methods (we need to use this instead of @AfterClass on teardown() since the latter is
+ // useless with pax-exam)
+ for (Method method : getClass().getMethods()) {
+ boolean testMethod = false;
+ boolean ignoreMethod = false;
+ for (Annotation annotation : method.getAnnotations()) {
+ if (Test.class.equals(annotation.annotationType())) {
+ testMethod = true;
+ }
+ if (Ignore.class.equals(annotation.annotationType())) {
+ ignoreMethod = true;
+ }
+ }
+ if (testMethod && !ignoreMethod) {
+ testMethodsRemaining++;
+ }
+ }
+ LOG.info("{} test methods to run", testMethodsRemaining);
+
setup = true;
}
+ @After
+ public void teardown() {
+ testMethodsRemaining--;
+ LOG.info("{} test methods remaining", testMethodsRemaining);
+ if (testMethodsRemaining == 0) {
+ try {
+ disconnectOvsdbNode(getConnectionInfo(addressStr, portNumber));
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while disconnecting", e);
+ }
+ }
+ }
+
/**
* Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
- * 6640. This test will wait for incoming connections for {@link SouthboundITConstants.CONNECTION_INIT_TIMEOUT} ms.
+ * 6640. This test will wait for incoming connections for {@link SouthboundITConstants#CONNECTION_INIT_TIMEOUT} ms.
*
* @throws InterruptedException
*/
}
}
- private ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) {
+ private static ConnectionInfo getConnectionInfo(final String addressStr, final int portNumber) {
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(addressStr);
} catch (UnknownHostException e) {
- fail("Could not allocate InetAddress: " + e);
+ fail("Could not resolve " + addressStr + ": " + e);
}
IpAddress address = SouthboundMapper.createIpAddress(inetAddress);
- PortNumber port = new PortNumber(Integer.parseInt(portStr));
+ PortNumber port = new PortNumber(portNumber);
- LOG.info("connectionInfo: {}", new ConnectionInfoBuilder()
+ final ConnectionInfo connectionInfo = new ConnectionInfoBuilder()
.setRemoteIp(address)
.setRemotePort(port)
- .build());
- return new ConnectionInfoBuilder()
- .setRemoteIp(address)
- .setRemotePort(port)
- .build();
- }
-
- private String connectionInfoToString(final ConnectionInfo connectionInfo) {
- return new String(connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue();
+ .build();
+ LOG.info("connectionInfo: {}", connectionInfo);
+ return connectionInfo;
}
@Test
topology);
}
- 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,
- iid,
- createNode(connectionInfo));
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
- }
-
- 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 connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
+ final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
+ Assert.assertTrue(
+ mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, iid, SouthboundUtils.createNode(connectionInfo)));
+ waitForOperationalCreation(iid);
+ Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid);
+ Assert.assertNotNull(node);
+ LOG.info("Connected to {}", SouthboundUtils.connectionInfoToString(connectionInfo));
+ return node;
}
- private Node getOvsdbNode(final ConnectionInfo connectionInfo) {
- Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
- createInstanceIdentifier(connectionInfo));
- return node;
+ private void waitForOperationalCreation(InstanceIdentifier<Node> iid) throws InterruptedException {
+ synchronized (OPERATIONAL_LISTENER) {
+ long _start = System.currentTimeMillis();
+ LOG.info("Waiting for OPERATIONAL DataChanged creation on {}", iid);
+ while (!OPERATIONAL_LISTENER.isCreated(
+ iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
+ OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
+ }
+ LOG.info("Woke up, waited {} for creation of {}", (System.currentTimeMillis() - _start), iid);
+ }
}
- private boolean deleteOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION,
- createInstanceIdentifier(connectionInfo));
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
+ private static void waitForOperationalDeletion(InstanceIdentifier<Node> iid) throws InterruptedException {
+ synchronized (OPERATIONAL_LISTENER) {
+ long _start = System.currentTimeMillis();
+ LOG.info("Waiting for OPERATIONAL DataChanged deletion on {}", iid);
+ while (!OPERATIONAL_LISTENER.isRemoved(
+ iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
+ OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
+ }
+ LOG.info("Woke up, waited {} for deletion of {}", (System.currentTimeMillis() - _start), iid);
+ }
}
- private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- Assert.assertTrue(addOvsdbNode(connectionInfo));
- Node node = getOvsdbNode(connectionInfo);
- Assert.assertNotNull(node);
- LOG.info("Connected to {}", connectionInfoToString(connectionInfo));
- return node;
+ private void waitForOperationalUpdate(InstanceIdentifier<Node> iid) throws InterruptedException {
+ synchronized (OPERATIONAL_LISTENER) {
+ long _start = System.currentTimeMillis();
+ LOG.info("Waiting for OPERATIONAL DataChanged update on {}", iid);
+ while (!OPERATIONAL_LISTENER.isUpdated(
+ iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
+ OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
+ }
+ LOG.info("Woke up, waited {} for update of {}", (System.currentTimeMillis() - _start), iid);
+ }
}
- private boolean disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
- Assert.assertTrue(deleteOvsdbNode(connectionInfo));
- Node node = getOvsdbNode(connectionInfo);
+ private static void disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException {
+ final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
+ Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
+ waitForOperationalDeletion(iid);
+ Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid);
Assert.assertNull(node);
- //Assume.assumeNotNull(node); // Using assumeNotNull because there is no assumeNull
- LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo));
- return true;
+ LOG.info("Disconnected from {}", SouthboundUtils.connectionInfoToString(connectionInfo));
}
@Test
public void testAddDeleteOvsdbNode() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- Node ovsdbNode = connectOvsdbNode(connectionInfo);
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
+ // At this point we're connected, disconnect and reconnect (the connection will be removed at the very end)
+ disconnectOvsdbNode(connectionInfo);
+ connectOvsdbNode(connectionInfo);
}
@Test
public void testDpdkSwitch() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- Node ovsdbNode = connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
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);
+ Class<? extends DatapathTypeBase> dpType = dpTypeEntry.getDatapathType();
+ String 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,
+ InstanceIdentifier<Node> bridgeIid = SouthboundUtils.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);
+ NodeId bridgeNodeId = SouthboundUtils.createManagedNodeId(bridgeIid);
+ try (TestBridge testBridge = new TestBridge(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(dpType, bridge.getDatapathType());
+
+ // Add port for all dpdk interface types (dpdkvhost not supported in existing dpdk ovs)
+ List<String> dpdkTypes = new ArrayList<String>();
+ dpdkTypes.add("dpdk");
+ dpdkTypes.add("dpdkr");
+ dpdkTypes.add("dpdkvhostuser");
+ //dpdkTypes.add("dpdkvhost");
+
+ for (String dpdkType : dpdkTypes) {
+ String testPortname = "test"+dpdkType+"port";
+ LOG.info("DPDK portname and type is {}, {}", testPortname, dpdkType);
+ Class<? extends InterfaceTypeBase> dpdkIfType = SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP
+ .get(dpdkType);
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationpointBuilder =
+ createSpecificDpdkOvsdbTerminationPointAugmentationBuilder(testPortname,
+ dpdkIfType);
+ Assert.assertTrue(
+ addTerminationPoint(bridgeNodeId, testPortname, ovsdbTerminationpointBuilder));
+ }
+
+ // Verify that all DPDK ports are created
+ InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
+ Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
+ terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
+
+ // Verify that each termination point has the specific DPDK ifType
+ for (String dpdkType : dpdkTypes) {
+ String testPortname = "test"+dpdkType+"port";
+ Class<? extends InterfaceTypeBase> dpdkIfType = SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP
+ .get(dpdkType);
+ List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
+ for (TerminationPoint terminationPoint : terminationPoints) {
+ OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = terminationPoint
+ .getAugmentation(OvsdbTerminationPointAugmentation.class);
+ if (ovsdbTerminationPointAugmentation.getName().equals(testPortname)) {
+ Class<? extends InterfaceTypeBase> opPort = ovsdbTerminationPointAugmentation
+ .getInterfaceType();
+ Assert.assertEquals(dpdkIfType, opPort);
+ }
+ }
}
}
- Assert.assertTrue(deleteBridge(connectionInfo));
- break;
}
+ break;
}
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
@Test
public void testOvsdbNodeOvsVersion() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- Node ovsdbNode = connectOvsdbNode(connectionInfo);
OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
Assert.assertNotNull(ovsdbNodeAugmentation);
assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
}
@Test
public void testOpenVSwitchOtherConfig() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- Node ovsdbNode = connectOvsdbNode(connectionInfo);
OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
Assert.assertNotNull(ovsdbNodeAugmentation);
List<OpenvswitchOtherConfigs> otherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
} else {
LOG.info("other_config is not present");
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
}
@Test
public void testOvsdbBridgeControllerInfo() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr,portStr);
- Node ovsdbNode = connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr,portNumber);
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,
+ try (TestBridge testBridge = new TestBridge(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());
+ 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>();
+ List<ControllerEntry> controllerEntriesList = new ArrayList<>();
controllerEntriesList.add(new ControllerEntryBuilder()
.setTarget(new Uri(controllerTarget))
.build());
return controllerEntriesList;
}
- private void setManagedBy(final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
+ private static void setManagedBy(final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
final ConnectionInfo connectionInfo) {
- InstanceIdentifier<Node> connectionNodePath = createInstanceIdentifier(connectionInfo);
+ InstanceIdentifier<Node> connectionNodePath = SouthboundUtils.createInstanceIdentifier(connectionInfo);
ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
}
- private List<ProtocolEntry> createMdsalProtocols() {
- List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
+ private static List<ProtocolEntry> createMdsalProtocols() {
+ List<ProtocolEntry> protocolList = new ArrayList<>();
ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
- protocolList.add(new ProtocolEntryBuilder().
- setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build());
+ protocolList.add(new ProtocolEntryBuilder().setProtocol(mapper.get("OpenFlow13")).build());
return protocolList;
}
return ovsdbTerminationBuilder;
}
+ private OvsdbTerminationPointAugmentationBuilder createSpecificDpdkOvsdbTerminationPointAugmentationBuilder(
+ String testPortname,Class<? extends InterfaceTypeBase> dpdkIfType) {
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ ovsdbTerminationBuilder.setName(testPortname);
+ ovsdbTerminationBuilder.setInterfaceType(dpdkIfType);
+ return ovsdbTerminationBuilder;
+ }
+
private boolean addTerminationPoint(final NodeId bridgeNodeId, final String portName,
- final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointAugmentationBuilder)
- throws InterruptedException {
+ final OvsdbTerminationPointAugmentationBuilder
+ ovsdbTerminationPointAugmentationBuilder)
+ throws InterruptedException {
InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(bridgeNodeId);
NodeBuilder portNodeBuilder = new NodeBuilder();
return result;
}
- /*
- * base method for adding test bridges. Other helper methods used to create bridges should utilize this method.
- *
- * @param connectionInfo
- * @param bridgeIid if passed null, one is created
- * @param bridgeName cannot be null
- * @param bridgeNodeId if passed null, one is created based on <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();
- if (bridgeIid == null) {
- bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
- }
- if (bridgeNodeId == null) {
- bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
- }
- bridgeNodeBuilder.setNodeId(bridgeNodeId);
- OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
- ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
- if (setProtocolEntries) {
- ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
- }
- if (failMode != null) {
+ private static class TestBridge implements AutoCloseable {
+ private final ConnectionInfo connectionInfo;
+ private final String bridgeName;
+
+ /**
+ * Creates a test bridge which can be automatically removed when no longer necessary.
+ *
+ * @param connectionInfo The connection information.
+ * @param bridgeIid The bridge identifier; if {@code null}, one is created based on {@code bridgeName}.
+ * @param bridgeName The bridge name; must be provided.
+ * @param bridgeNodeId The bridge node identifier; if {@code null}, one is created based on {@code bridgeIid}.
+ * @param setProtocolEntries {@code true} to set default protocol entries for the bridge.
+ * @param failMode The fail mode to set for the bridge.
+ * @param setManagedBy {@code true} to specify {@code setManagedBy} for the bridge.
+ * @param dpType The datapath type.
+ * @param externalIds The external identifiers if any.
+ * @param otherConfigs The other configuration items if any.
+ */
+ public TestBridge(final ConnectionInfo connectionInfo, @Nullable InstanceIdentifier<Node> bridgeIid,
+ final String bridgeName, NodeId bridgeNodeId, final boolean setProtocolEntries,
+ final Class<? extends OvsdbFailModeBase> failMode, final boolean setManagedBy,
+ @Nullable final Class<? extends DatapathTypeBase> dpType,
+ @Nullable final List<BridgeExternalIds> externalIds,
+ @Nullable final List<ControllerEntry> controllerEntries,
+ @Nullable final List<BridgeOtherConfigs> otherConfigs) {
+ this.connectionInfo = connectionInfo;
+ this.bridgeName = bridgeName;
+ NodeBuilder bridgeNodeBuilder = new NodeBuilder();
+ if (bridgeIid == null) {
+ bridgeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
+ }
+ if (bridgeNodeId == null) {
+ bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
+ }
+ bridgeNodeBuilder.setNodeId(bridgeNodeId);
+ OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
+ ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
+ if (setProtocolEntries) {
+ ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
+ }
ovsdbBridgeAugmentationBuilder.setFailMode(failMode);
- }
- if (setManagedBy) {
- setManagedBy(ovsdbBridgeAugmentationBuilder, connectionInfo);
- }
- if (dpType != null) {
+ if (setManagedBy) {
+ setManagedBy(ovsdbBridgeAugmentationBuilder, connectionInfo);
+ }
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());
+ Assert.assertTrue(
+ mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build()));
+ try {
+ Thread.sleep(OVSDB_UPDATE_TIMEOUT);
+ } catch (InterruptedException e) {
+ LOG.warn("Sleep interrupted while waiting for bridge creation (bridge {})", bridgeName, e);
+ }
}
- 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 {
+ public TestBridge(final ConnectionInfo connectionInfo, final String bridgeName) {
+ this(connectionInfo, null, bridgeName, null, true,
+ SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null);
+ }
- return addBridge(connectionInfo, null, bridgeName, null, true,
- SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null);
+ @Override
+ public void close() {
+ final InstanceIdentifier<Node> iid =
+ SouthboundUtils.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
+ Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
+ try {
+ Thread.sleep(OVSDB_UPDATE_TIMEOUT);
+ } catch (InterruptedException e) {
+ LOG.warn("Sleep interrupted while waiting for bridge deletion (bridge {})", bridgeName, e);
+ }
+ }
}
private OvsdbBridgeAugmentation getBridge(ConnectionInfo connectionInfo) {
* Extract the <code>store</code> type data store contents for the particular bridge identified by
* <code>bridgeName</code>.
*
- * @param connectionInfo
- * @param bridgeName
+ * @param connectionInfo the connection information
+ * @param bridgeName the bridge name
* @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) {
+ LogicalDatastoreType store) {
Node bridgeNode = getBridgeNode(connectionInfo, bridgeName, store);
Assert.assertNotNull(bridgeNode);
OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
* extract the <code>LogicalDataStoreType.OPERATIONAL</code> type data store contents for the particular bridge
* identified by <code>bridgeName</code>
*
- * @param connectionInfo
- * @param bridgeName
+ * @param connectionInfo the connection information
+ * @param bridgeName the bridge name
* @see <code>SouthboundIT.getBridge(ConnectionInfo, String, LogicalDatastoreType)</code>
* @return <code>LogicalDatastoreType.OPERATIONAL</code> type data store contents
*/
* Extract the node contents from <code>store</code> type data store for the
* bridge identified by <code>bridgeName</code>
*
- * @param connectionInfo
- * @param bridgeName
+ * @param connectionInfo the connection information
+ * @param bridgeName the bridge name
* @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));
+ SouthboundUtils.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
+ * @param connectionInfo the connection information
+ * @param bridgeName the bridge name
* @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,
- createInstanceIdentifier(connectionInfo,
- new OvsdbBridgeName(bridgeName)));
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- return result;
- }
-
@Test
public void testAddDeleteBridge() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- Node ovsdbNode = connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- LOG.info("bridge: {}", bridge);
-
- Assert.assertTrue(deleteBridge(connectionInfo));
-
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- //Assume.assumeTrue(disconnectOvsdbNode(connectionInfo));
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ Assert.assertNotNull(bridge);
+ LOG.info("bridge: {}", bridge);
+ }
}
private InstanceIdentifier<Node> getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) {
- return createInstanceIdentifier(connectionInfo,
- bridge.getBridgeName());
+ return SouthboundUtils.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
+ * @param connectionInfo the connection information
+ * @param bridgeName the bridge name
+ * @param store defined by the <code>LogicalDatastoreType</code> enumeration
+ * @param index the index we're interested in
+ * @return the augmentation (or {@code null} if none)
*/
- private OvsdbTerminationPointAugmentation getOvsdbTerminationPointAugmentation(ConnectionInfo connectionInfo,
- String bridgeName, LogicalDatastoreType store, int index ) {
+ 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));
+ return tpList.get(index).getAugmentation(OvsdbTerminationPointAugmentation.class);
}
@Test
public void testCRDTerminationPointOfPort() throws InterruptedException {
- final Long OFPORT_EXPECTED = new Long(45002);
+ final Long OFPORT_EXPECTED = 45002L;
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
// CREATE
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- LOG.info("bridge: {}", bridge);
- NodeId nodeId = SouthboundMapper.createManagedNodeId(createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testOfPort";
- ovsdbTerminationBuilder.setName(portName);
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ Assert.assertNotNull(bridge);
+ LOG.info("bridge: {}", bridge);
+ NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
+ connectionInfo, bridge.getBridgeName()));
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ String portName = "testOfPort";
+ ovsdbTerminationBuilder.setName(portName);
+
+ 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);
- 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 =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- Long ofPort = ovsdbTerminationPointAugmentation.getOfport();
- // if ephemeral port 45002 is in use, ofPort is set to 1
- Assert.assertTrue(ofPort.equals(OFPORT_EXPECTED) || ofPort.equals(new Long(1)));
- LOG.info("ofPort: {}", ofPort);
+ // 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(OFPORT_EXPECTED) || ofPort.equals(1L));
+ 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."
+ // 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));
+ // DELETE handled by TestBridge
+ }
}
@Test
public void testCRDTerminationPointOfPortRequest() throws InterruptedException {
- final Long OFPORT_EXPECTED = new Long(45008);
- final Long OFPORT_INPUT = new Long(45008);
- final Long OFPORT_UPDATE = new Long(45009);
+ final Long OFPORT_EXPECTED = 45008L;
+ final Long OFPORT_INPUT = 45008L;
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
// CREATE
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testOfPortRequest";
- ovsdbTerminationBuilder.setName(portName);
- Integer ofPortRequestExpected = OFPORT_EXPECTED.intValue();
- ovsdbTerminationBuilder.setOfport(OFPORT_INPUT);
- ovsdbTerminationBuilder.setOfportRequest(ofPortRequestExpected);
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<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 45008 is in use, ofPort is set to 1
- Assert.assertTrue(ofPort.equals(OFPORT_EXPECTED) || ofPort.equals(new Long(1)));
- LOG.info("ofPort: {}", ofPort);
-
- Integer ofPortRequest = ovsdbTerminationPointAugmentation.getOfportRequest();
- Assert.assertTrue(ofPortRequest.equals(ofPortRequestExpected));
- LOG.info("ofPortRequest: {}", ofPortRequest);
- }
- }
-
- // UPDATE- Not Applicable. From the OpenVSwitch documentation:
- // "A client should ideally set this column’s value in the same database transaction that it uses to create
- // the interface. "
-
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo));
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- }
-
- /*
- * Generates the test cases involved in testing PortExternalIds. See inline comments for descriptions of
- * the particular cases considered.
- *
- * The return value is a Map in the form (K,V)=(testCaseName,testCase).
- * - testCaseName is a String
- * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of
- * either corresponding INPUT port external_ids, or EXPECTED port external_ids
- * INPUT is the List we use when calling
- * <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>>>();
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ Assert.assertNotNull(bridge);
+ NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
+ connectionInfo, bridge.getBridgeName()));
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ String portName = "testOfPortRequest";
+ ovsdbTerminationBuilder.setName(portName);
+ Integer ofPortRequestExpected = OFPORT_EXPECTED.intValue();
+ ovsdbTerminationBuilder.setOfport(OFPORT_INPUT);
+ ovsdbTerminationBuilder.setOfportRequest(ofPortRequestExpected);
+ Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
+ InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
+ Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
- 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";
+ // 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 45008 is in use, ofPort is set to 1
+ Assert.assertTrue(ofPort.equals(OFPORT_EXPECTED) || ofPort.equals(1L));
+ LOG.info("ofPort: {}", ofPort);
+
+ Integer ofPortRequest = ovsdbTerminationPointAugmentation.getOfportRequest();
+ Assert.assertTrue(ofPortRequest.equals(ofPortRequestExpected));
+ LOG.info("ofPortRequest: {}", ofPortRequest);
+ }
+ }
- // 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);
+ // 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. "
- return testMap;
+ // DELETE handled by TestBridge
+ }
}
- /*
- * @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));
+ private <T> void assertExpectedExist(List<T> expected, List<T> test) {
+ if (expected != null && test != null) {
+ for (T exp : expected) {
+ Assert.assertTrue("The retrieved values don't contain " + exp, test.contains(exp));
}
}
}
+ private interface SouthboundTerminationPointHelper<T> {
+ void writeValues(OvsdbTerminationPointAugmentationBuilder builder, List<T> values);
+ List<T> readValues(OvsdbTerminationPointAugmentation augmentation);
+ }
+
/*
* 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 testCRUDTerminationPointPortExternalIds() throws InterruptedException {
- final String TEST_PREFIX = "CRUDTPPortExternalIds";
+ private <T> void testCRUDTerminationPoint(
+ KeyValueBuilder<T> builder, String prefix, SouthboundTerminationPointHelper<T> helper)
+ throws InterruptedException {
final int TERMINATION_POINT_TEST_INDEX = 0;
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
// 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 = null;
- List<PortExternalIds> updateFromInputExternalIds = null;
- List<PortExternalIds> updateFromExpectedExternalIds = null;
- List<PortExternalIds> updateFromConfigurationExternalIds = null;
- List<PortExternalIds> updateFromOperationalExternalIds = null;
- Map<String, List<PortExternalIds>> updateToTestCase = null;
- List<PortExternalIds> updateToInputExternalIds = null;
- List<PortExternalIds> updateToExpectedExternalIds = null;
- List<PortExternalIds> updateToConfigurationExternalIds = null;
- List<PortExternalIds> updateToOperationalExternalIds = null;
- String testBridgeName = null;
- String testPortName = null;
- OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = null;
- OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = null;
- OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = null;
- TerminationPointBuilder tpUpdateBuilder = null;
- NodeBuilder portUpdateNodeBuilder = null;
- NodeId testBridgeNodeId = null;
- NodeId portUpdateNodeId = null;
- InstanceIdentifier<Node> portIid = null;
- boolean result = false;
-
- 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", TEST_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputExternalIds = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedExternalIds = updateToTestCase.get(EXPECTED_VALUES_KEY);
+ List<SouthboundTestCase<T>> updateFromTestCases = generateKeyValueTestCases(builder, prefix + "From");
+ List<SouthboundTestCase<T>> updateToTestCases = generateKeyValueTestCases(builder, prefix + "To");
+
+ for (SouthboundTestCase<T> updateFromTestCase : updateFromTestCases) {
+ for (SouthboundTestCase<T> updateToTestCase : updateToTestCases) {
+ String testBridgeAndPortName = String.format("%s_%s", prefix, updateToTestCase.name);
// 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));
- testBridgeNodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, new OvsdbBridgeName(testBridgeName)));
- 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
- updateFromConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateFromConfigurationExternalIds = updateFromConfigurationTerminationPointAugmentation
- .getPortExternalIds();
- assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds);
- updateFromOperationalTerminationPointAugmenation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateFromOperationalExternalIds = updateFromOperationalTerminationPointAugmenation
- .getPortExternalIds();
- assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateFromOperationalExternalIds);
-
- // UPDATE: update the external_ids
- testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
- tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setPortExternalIds(updateToInputExternalIds);
- portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
- portUpdateNodeBuilder = new NodeBuilder();
- portUpdateNodeId = createManagedNodeId(portIid);
- portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
- tpUpdateBuilder = new TerminationPointBuilder();
- tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName)));
- tpUpdateBuilder.addAugmentation(
- OvsdbTerminationPointAugmentation.class,
- tpUpdateAugmentationBuilder.build());
- portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build()));
- result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
- portIid, portUpdateNodeBuilder.build());
- Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- Assert.assertTrue(result);
+ try (TestBridge testBridge = new TestBridge(connectionInfo, null, testBridgeAndPortName, null, true,
+ SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null,
+ null)) {
+ NodeId testBridgeNodeId = SouthboundUtils.createManagedNodeId(
+ SouthboundUtils.createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(testBridgeAndPortName)));
+ OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ tpCreateAugmentationBuilder.setName(testBridgeAndPortName);
+ helper.writeValues(tpCreateAugmentationBuilder, updateFromTestCase.inputValues);
+ Assert.assertTrue(
+ addTerminationPoint(testBridgeNodeId, testBridgeAndPortName, 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, testBridgeAndPortName,
+ LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
+ if (updateFromConfigurationTerminationPointAugmentation != null) {
+ List<T> updateFromConfigurationValues =
+ helper.readValues(updateFromConfigurationTerminationPointAugmentation);
+ assertExpectedExist(updateFromTestCase.expectedValues, updateFromConfigurationValues);
+ }
+ OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeAndPortName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ if (updateFromOperationalTerminationPointAugmentation != null) {
+ List<T> updateFromOperationalValues =
+ helper.readValues(updateFromOperationalTerminationPointAugmentation);
+ assertExpectedExist(updateFromTestCase.expectedValues, updateFromOperationalValues);
+ }
- // READ: the test port and ensure changes are propagated to the CONFIGURATION data store,
- // then repeat for OPERATIONAL data store
- updateToConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateToConfigurationExternalIds = updateToConfigurationTerminationPointAugmentation
- .getPortExternalIds();
- assertExpectedPortExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds);
- assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds);
- updateToOperationalTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateToOperationalExternalIds = updateToOperationalTerminationPointAugmentation.getPortExternalIds();
- if (updateFromExpectedExternalIds != null) {
- assertExpectedPortExternalIdsExist(updateToExpectedExternalIds, updateToOperationalExternalIds);
- assertExpectedPortExternalIdsExist(updateFromExpectedExternalIds, updateToOperationalExternalIds);
- }
+ // UPDATE: update the values
+ testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeAndPortName).getNodeId();
+ OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder =
+ new OvsdbTerminationPointAugmentationBuilder();
+ helper.writeValues(tpUpdateAugmentationBuilder, updateToTestCase.inputValues);
+ InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
+ NodeBuilder portUpdateNodeBuilder = new NodeBuilder();
+ NodeId portUpdateNodeId = SouthboundUtils.createManagedNodeId(portIid);
+ portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
+ TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder();
+ tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testBridgeAndPortName)));
+ tpUpdateBuilder.addAugmentation(
+ OvsdbTerminationPointAugmentation.class,
+ tpUpdateAugmentationBuilder.build());
+ portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build()));
+ Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
+ portIid, portUpdateNodeBuilder.build()));
+ Thread.sleep(OVSDB_UPDATE_TIMEOUT);
+
+ // READ: the test port and ensure changes are propagated to the CONFIGURATION data store,
+ // then repeat for OPERATIONAL data store
+ OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeAndPortName,
+ LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
+ if (updateToConfigurationTerminationPointAugmentation != null) {
+ List<T> updateToConfigurationValues =
+ helper.readValues(updateToConfigurationTerminationPointAugmentation);
+ assertExpectedExist(updateToTestCase.expectedValues, updateToConfigurationValues);
+ assertExpectedExist(updateFromTestCase.expectedValues, updateToConfigurationValues);
+ }
+ OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation =
+ getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeAndPortName,
+ LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
+ if (updateToOperationalTerminationPointAugmentation != null) {
+ List<T> updateToOperationalValues =
+ helper.readValues(updateToOperationalTerminationPointAugmentation);
+ if (updateFromTestCase.expectedValues != null) {
+ assertExpectedExist(updateToTestCase.expectedValues, updateToOperationalValues);
+ assertExpectedExist(updateFromTestCase.expectedValues, updateToOperationalValues);
+ }
+ }
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
+ // DELETE handled by TestBridge
+ }
}
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
/*
- * Generates the test cases involved in testing InterfaceExternalIds. See inline comments for descriptions of
- * the particular cases considered.
+ * Tests the CRUD operations for <code>Port</code> <code>external_ids</code>.
*
- * 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"
+ * @see <code>SouthboundIT.generatePortExternalIdsTestCases()</code> for specific test case information
*/
- private void assertExpectedInterfaceExternalIdsExist( List<InterfaceExternalIds> expected,
- List<InterfaceExternalIds> test ) {
-
- if (expected != null) {
- for (InterfaceExternalIds expectedExternalId : expected) {
- Assert.assertTrue(test.contains(expectedExternalId));
- }
- }
+ @Test
+ public void testCRUDTerminationPointPortExternalIds() throws InterruptedException {
+ testCRUDTerminationPoint(new SouthboundPortExternalIdsBuilder(), "TPPortExternalIds",
+ new PortExternalIdsSouthboundHelper());
}
/*
*/
@Test
public void testCRUDTerminationPointInterfaceExternalIds() throws InterruptedException {
- final String TEST_PREFIX = "CRUDTPInterfaceExternalIds";
- final int TERMINATION_POINT_TEST_INDEX = 0;
-
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
-
- // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
- // the update has been performed.
- Map<String, Map<String, List<InterfaceExternalIds>>> updateFromTestCases =
- generateInterfaceExternalIdsTestCases();
- Map<String, Map<String, List<InterfaceExternalIds>>> updateToTestCases =
- generateInterfaceExternalIdsTestCases();
- Map<String, List<InterfaceExternalIds>> updateFromTestCase = null;
- List<InterfaceExternalIds> updateFromInputExternalIds = null;
- List<InterfaceExternalIds> updateFromExpectedExternalIds = null;
- List<InterfaceExternalIds> updateFromConfigurationExternalIds = null;
- List<InterfaceExternalIds> updateFromOperationalExternalIds = null;
- Map<String, List<InterfaceExternalIds>> updateToTestCase = null;
- List<InterfaceExternalIds> updateToInputExternalIds = null;
- List<InterfaceExternalIds> updateToExpectedExternalIds = null;
- List<InterfaceExternalIds> updateToConfigurationExternalIds = null;
- List<InterfaceExternalIds> updateToOperationalExternalIds = null;
- String testBridgeName = null;
- String testPortName = null;
- OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = null;
- OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = null;
- OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = null;
- TerminationPointBuilder tpUpdateBuilder = null;
- NodeBuilder portUpdateNodeBuilder = null;
- NodeId testBridgeNodeId = null;
- NodeId portUpdateNodeId = null;
- InstanceIdentifier<Node> portIid = null;
- boolean result = false;
-
- 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", TEST_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputExternalIds = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedExternalIds = updateToTestCase.get(EXPECTED_VALUES_KEY);
-
- // 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));
- testBridgeNodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, new OvsdbBridgeName(testBridgeName)));
- 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
- updateFromConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateFromConfigurationExternalIds = updateFromConfigurationTerminationPointAugmentation
- .getInterfaceExternalIds();
- assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
- updateFromConfigurationExternalIds);
- updateFromOperationalTerminationPointAugmenation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateFromOperationalExternalIds = updateFromOperationalTerminationPointAugmenation
- .getInterfaceExternalIds();
- assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
- updateFromOperationalExternalIds);
-
- // UPDATE: update the external_ids
- testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
- tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setInterfaceExternalIds(updateToInputExternalIds);
- portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
- portUpdateNodeBuilder = new NodeBuilder();
- portUpdateNodeId = createManagedNodeId(portIid);
- portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
- tpUpdateBuilder = new TerminationPointBuilder();
- tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName)));
- tpUpdateBuilder.addAugmentation(
- OvsdbTerminationPointAugmentation.class,
- tpUpdateAugmentationBuilder.build());
- portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build()));
- 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
- updateToConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateToConfigurationExternalIds = updateToConfigurationTerminationPointAugmentation
- .getInterfaceExternalIds();
- assertExpectedInterfaceExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds);
- assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
- updateToConfigurationExternalIds);
- updateToOperationalTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateToOperationalExternalIds = updateToOperationalTerminationPointAugmentation
- .getInterfaceExternalIds();
- if (updateFromExpectedExternalIds != null) {
- assertExpectedInterfaceExternalIdsExist(updateToExpectedExternalIds,
- updateToOperationalExternalIds);
- assertExpectedInterfaceExternalIdsExist(updateFromExpectedExternalIds,
- updateToOperationalExternalIds);
- } else {
- Assert.assertNull(updateToOperationalExternalIds);
- }
-
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
- }
- }
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ testCRUDTerminationPoint(new SouthboundInterfaceExternalIdsBuilder(), "TPInterfaceExternalIds",
+ new InterfaceExternalIdsSouthboundHelper());
}
/*
- * Generates the test cases involved in testing TP Options. See inline comments for descriptions of
- * the particular cases considered.
+ * Tests the CRUD operations for <code>TerminationPoint</code> <code>options</code>.
*
- * 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
+ * @see <code>SouthboundIT.generateTerminationPointOptions()</code> for specific test case information
*/
@Test
public void testCRUDTerminationPointOptions() throws InterruptedException {
- final String TEST_PREFIX = "CRUDTPOptions";
- final int TERMINATION_POINT_TEST_INDEX = 0;
-
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
-
- // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
- // the update has been performed.
- Map<String, Map<String, List<Options>>> updateFromTestCases =
- generateTerminationPointOptionsTestCases();
- Map<String, Map<String, List<Options>>> updateToTestCases =
- generateTerminationPointOptionsTestCases();
- Map<String, List<Options>> updateFromTestCase = null;
- List<Options> updateFromInputOptions = null;
- List<Options> updateFromExpectedOptions = null;
- List<Options> updateFromConfigurationOptions = null;
- List<Options> updateFromOperationalOptions = null;
- Map<String, List<Options>> updateToTestCase = null;
- List<Options> updateToInputOptions = null;
- List<Options> updateToExpectedOptions = null;
- List<Options> updateToConfigurationOptions = null;
- List<Options> updateToOperationalOptions = null;
- String testBridgeName = null;
- String testPortName = null;
- OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = null;
- OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = null;
- OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = null;
- TerminationPointBuilder tpUpdateBuilder = null;
- NodeBuilder portUpdateNodeBuilder = null;
- NodeId testBridgeNodeId = null;
- NodeId portUpdateNodeId = null;
- InstanceIdentifier<Node> portIid = null;
- boolean result = false;
-
- 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", TEST_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputOptions = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedOptions = updateToTestCase.get(EXPECTED_VALUES_KEY);
-
- // 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));
- testBridgeNodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, new OvsdbBridgeName(testBridgeName)));
- 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
- updateFromConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateFromConfigurationOptions = updateFromConfigurationTerminationPointAugmentation
- .getOptions();
- assertExpectedOptionsExist(updateFromExpectedOptions,
- updateFromConfigurationOptions);
- updateFromOperationalTerminationPointAugmenation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateFromOperationalOptions = updateFromOperationalTerminationPointAugmenation
- .getOptions();
- assertExpectedOptionsExist(updateFromExpectedOptions,
- updateFromOperationalOptions);
-
- // UPDATE: update the external_ids
- testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
- tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setOptions(updateToInputOptions);
- portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
- portUpdateNodeBuilder = new NodeBuilder();
- portUpdateNodeId = createManagedNodeId(portIid);
- portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
- tpUpdateBuilder = new TerminationPointBuilder();
- tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName)));
- tpUpdateBuilder.addAugmentation(
- OvsdbTerminationPointAugmentation.class,
- tpUpdateAugmentationBuilder.build());
- portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build()));
- 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
- updateToConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateToConfigurationOptions = updateToConfigurationTerminationPointAugmentation
- .getOptions();
- assertExpectedOptionsExist(updateToExpectedOptions, updateToConfigurationOptions);
- assertExpectedOptionsExist(updateFromExpectedOptions, updateToConfigurationOptions);
- updateToOperationalTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateToOperationalOptions = updateToOperationalTerminationPointAugmentation
- .getOptions();
- if (updateFromExpectedOptions != null) {
- assertExpectedOptionsExist(updateToExpectedOptions, updateToOperationalOptions);
- assertExpectedOptionsExist(updateFromExpectedOptions, updateToOperationalOptions);
- }
-
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
- }
- }
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- }
-
- /*
- * 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));
- }
- }
+ testCRUDTerminationPoint(new SouthboundOptionsBuilder(), "TPOptions", new OptionsSouthboundHelper());
}
/*
*/
@Test
public void testCRUDTerminationPointInterfaceOtherConfigs() throws InterruptedException {
- final String TEST_PREFIX = "CRUDTPInterfaceOtherConfigs";
- final int TERMINATION_POINT_TEST_INDEX = 0;
-
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
-
- // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
- // the update has been performed.
- Map<String, Map<String, List<InterfaceOtherConfigs>>> updateFromTestCases =
- generateInterfaceOtherConfigsTestCases();
- Map<String, Map<String, List<InterfaceOtherConfigs>>> updateToTestCases =
- generateInterfaceOtherConfigsTestCases();
- Map<String, List<InterfaceOtherConfigs>> updateFromTestCase = null;
- List<InterfaceOtherConfigs> updateFromInputOtherConfigs = null;
- List<InterfaceOtherConfigs> updateFromExpectedOtherConfigs = null;
- List<InterfaceOtherConfigs> updateFromConfigurationOtherConfigs = null;
- List<InterfaceOtherConfigs> updateFromOperationalOtherConfigs = null;
- Map<String, List<InterfaceOtherConfigs>> updateToTestCase = null;
- List<InterfaceOtherConfigs> updateToInputOtherConfigs = null;
- List<InterfaceOtherConfigs> updateToExpectedOtherConfigs = null;
- List<InterfaceOtherConfigs> updateToConfigurationOtherConfigs = null;
- List<InterfaceOtherConfigs> updateToOperationalOtherConfigs = null;
- String testBridgeName = null;
- String testPortName = null;
- OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = null;
- OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = null;
- OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = null;
- TerminationPointBuilder tpUpdateBuilder = null;
- NodeBuilder portUpdateNodeBuilder = null;
- NodeId testBridgeNodeId = null;
- NodeId portUpdateNodeId = null;
- InstanceIdentifier<Node> portIid = null;
- boolean result = false;
-
- 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", TEST_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputOtherConfigs = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedOtherConfigs = updateToTestCase.get(EXPECTED_VALUES_KEY);
-
- // 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));
- testBridgeNodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, new OvsdbBridgeName(testBridgeName)));
- 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
- updateFromConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- if (updateFromConfigurationTerminationPointAugmentation != null) {
- updateFromConfigurationOtherConfigs = updateFromConfigurationTerminationPointAugmentation
- .getInterfaceOtherConfigs();
- } else {
- updateFromConfigurationOtherConfigs = null;
- }
- assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateFromConfigurationOtherConfigs);
- updateFromOperationalTerminationPointAugmenation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- if (updateFromOperationalOtherConfigs != null) {
- updateFromOperationalOtherConfigs = updateFromOperationalTerminationPointAugmenation
- .getInterfaceOtherConfigs();
- } else {
- updateFromOperationalOtherConfigs = null;
- }
- assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateFromOperationalOtherConfigs);
-
- // UPDATE: update the other_configs
- testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
- tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setInterfaceOtherConfigs(updateToInputOtherConfigs);
- portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
- portUpdateNodeBuilder = new NodeBuilder();
- portUpdateNodeId = createManagedNodeId(portIid);
- portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
- tpUpdateBuilder = new TerminationPointBuilder();
- tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName)));
- tpUpdateBuilder.addAugmentation(
- OvsdbTerminationPointAugmentation.class,
- tpUpdateAugmentationBuilder.build());
- portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build()));
- 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
- updateToConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateToConfigurationOtherConfigs = updateToConfigurationTerminationPointAugmentation
- .getInterfaceOtherConfigs();
- assertExpectedInterfaceOtherConfigsExist(updateToExpectedOtherConfigs,
- updateToConfigurationOtherConfigs);
- assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateToConfigurationOtherConfigs);
- updateToOperationalTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateToOperationalOtherConfigs = updateToOperationalTerminationPointAugmentation
- .getInterfaceOtherConfigs();
- if (updateFromExpectedOtherConfigs != null) {
- assertExpectedInterfaceOtherConfigsExist(updateToExpectedOtherConfigs,
- updateToOperationalOtherConfigs);
- assertExpectedInterfaceOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateToOperationalOtherConfigs);
- }
-
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
- }
- }
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- }
-
- /*
- * 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));
- }
- }
+ testCRUDTerminationPoint(new SouthboundInterfaceOtherConfigsBuilder(), "TPInterfaceOtherConfigs",
+ new InterfaceOtherConfigsSouthboundHelper());
}
/*
*/
@Test
public void testCRUDTerminationPointPortOtherConfigs() throws InterruptedException {
- final String TEST_PREFIX = "CRUDTPPortOtherConfigs";
- final int TERMINATION_POINT_TEST_INDEX = 0;
-
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
-
- // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after
- // the update has been performed.
- Map<String, Map<String, List<PortOtherConfigs>>> updateFromTestCases =
- generatePortOtherConfigsTestCases();
- Map<String, Map<String, List<PortOtherConfigs>>> updateToTestCases =
- generatePortOtherConfigsTestCases();
- Map<String, List<PortOtherConfigs>> updateFromTestCase = null;
- List<PortOtherConfigs> updateFromInputOtherConfigs = null;
- List<PortOtherConfigs> updateFromExpectedOtherConfigs = null;
- List<PortOtherConfigs> updateFromConfigurationOtherConfigs = null;
- List<PortOtherConfigs> updateFromOperationalOtherConfigs = null;
- Map<String, List<PortOtherConfigs>> updateToTestCase = null;
- List<PortOtherConfigs> updateToInputOtherConfigs = null;
- List<PortOtherConfigs> updateToExpectedOtherConfigs = null;
- List<PortOtherConfigs> updateToConfigurationOtherConfigs = null;
- List<PortOtherConfigs> updateToOperationalOtherConfigs = null;
- String testBridgeName = null;
- String testPortName = null;
- OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = null;
- OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = null;
- OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = null;
- OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = null;
- TerminationPointBuilder tpUpdateBuilder = null;
- NodeBuilder portUpdateNodeBuilder = null;
- NodeId testBridgeNodeId = null;
- NodeId portUpdateNodeId = null;
- InstanceIdentifier<Node> portIid = null;
- boolean result = false;
-
- 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", TEST_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputOtherConfigs = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedOtherConfigs = updateToTestCase.get(EXPECTED_VALUES_KEY);
-
- // 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));
- testBridgeNodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, new OvsdbBridgeName(testBridgeName)));
- 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
- updateFromConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- if (updateFromConfigurationTerminationPointAugmentation != null) {
- updateFromConfigurationOtherConfigs = updateFromConfigurationTerminationPointAugmentation
- .getPortOtherConfigs();
- } else {
- updateFromConfigurationOtherConfigs = null;
- }
- assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateFromConfigurationOtherConfigs);
- updateFromOperationalTerminationPointAugmenation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- if (updateFromOperationalOtherConfigs != null) {
- updateFromOperationalOtherConfigs = updateFromOperationalTerminationPointAugmenation
- .getPortOtherConfigs();
- } else {
- updateFromOperationalOtherConfigs = null;
- }
- assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateFromOperationalOtherConfigs);
-
- // UPDATE: update the other_configs
- testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId();
- tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setPortOtherConfigs(updateToInputOtherConfigs);
- portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
- portUpdateNodeBuilder = new NodeBuilder();
- portUpdateNodeId = createManagedNodeId(portIid);
- portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
- tpUpdateBuilder = new TerminationPointBuilder();
- tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName)));
- tpUpdateBuilder.addAugmentation(
- OvsdbTerminationPointAugmentation.class,
- tpUpdateAugmentationBuilder.build());
- portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build()));
- 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
- updateToConfigurationTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX);
- updateToConfigurationOtherConfigs = updateToConfigurationTerminationPointAugmentation
- .getPortOtherConfigs();
- assertExpectedPortOtherConfigsExist(updateToExpectedOtherConfigs,
- updateToConfigurationOtherConfigs);
- assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateToConfigurationOtherConfigs);
- updateToOperationalTerminationPointAugmentation =
- getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName,
- LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX);
- updateToOperationalOtherConfigs = updateToOperationalTerminationPointAugmentation
- .getPortOtherConfigs();
- if (updateFromExpectedOtherConfigs != null) {
- assertExpectedPortOtherConfigsExist(updateToExpectedOtherConfigs,
- updateToOperationalOtherConfigs);
- assertExpectedPortOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateToOperationalOtherConfigs);
- }
-
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
- }
- }
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
+ testCRUDTerminationPoint(new SouthboundPortOtherConfigsBuilder(), "TPPortOtherConfigs",
+ new PortOtherConfigsSouthboundHelper());
}
@Test
public void testCRUDTerminationPointVlan() throws InterruptedException {
- final Integer CREATED_VLAN_ID = new Integer(4000);
- final Integer UPDATED_VLAN_ID = new Integer(4001);
+ final Integer CREATED_VLAN_ID = 4000;
+ final Integer UPDATED_VLAN_ID = 4001;
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
// CREATE
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME);
- Assert.assertNotNull(bridge);
- NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testTerminationPointVlanId";
- ovsdbTerminationBuilder.setName(portName);
- ovsdbTerminationBuilder.setVlanTag(new VlanId(CREATED_VLAN_ID));
- Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
- InstanceIdentifier<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 = 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)) {
- VlanId actualVlanId = ovsdbTerminationPointAugmentation.getVlanTag();
- Assert.assertNotNull(actualVlanId);
- Integer actualVlanIdInt = actualVlanId.getValue();
- Assert.assertEquals(UPDATED_VLAN_ID, actualVlanIdInt);
- }
- }
-
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo));
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
- }
-
- @Test
- public void testCRUDTerminationPointVlanModes() throws InterruptedException {
- final VlanMode UPDATED_VLAN_MODE = VlanMode.Access;
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
- VlanMode []vlanModes = VlanMode.values();
- for (VlanMode vlanMode : vlanModes) {
- // CREATE
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME);
Assert.assertNotNull(bridge);
- NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
+ NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
connectionInfo, bridge.getBridgeName()));
OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testTerminationPointVlanMode" + vlanMode.toString();
+ String portName = "testTerminationPointVlanId";
ovsdbTerminationBuilder.setName(portName);
- ovsdbTerminationBuilder.setVlanMode(vlanMode);
+ 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);
// READ
List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
+ OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation;
for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
+ ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(
+ OvsdbTerminationPointAugmentation.class);
if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- //test
- Assert.assertTrue(ovsdbTerminationPointAugmentation.getVlanMode().equals(vlanMode));
+ VlanId actualVlanId = ovsdbTerminationPointAugmentation.getVlanTag();
+ Assert.assertNotNull(actualVlanId);
+ Integer actualVlanIdInt = actualVlanId.getValue();
+ Assert.assertEquals(CREATED_VLAN_ID, actualVlanIdInt);
}
}
NodeId testBridgeNodeId = getBridgeNode(connectionInfo, SouthboundITConstants.BRIDGE_NAME).getNodeId();
OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder =
new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setVlanMode(UPDATED_VLAN_MODE);
+ tpUpdateAugmentationBuilder.setVlanTag(new VlanId(UPDATED_VLAN_ID));
InstanceIdentifier<Node> portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId);
NodeBuilder portUpdateNodeBuilder = new NodeBuilder();
- NodeId portUpdateNodeId = createManagedNodeId(portIid);
+ NodeId portUpdateNodeId = SouthboundUtils.createManagedNodeId(portIid);
portUpdateNodeBuilder.setNodeId(portUpdateNodeId);
TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder();
tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName)));
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);
+ Assert.assertTrue(
+ mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()));
Thread.sleep(OVSDB_UPDATE_TIMEOUT);
terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
terminationPoints = terminationPointNode.getTerminationPoint();
for (TerminationPoint terminationPoint : terminationPoints) {
- OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
- terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
+ ovsdbTerminationPointAugmentation = terminationPoint.getAugmentation(
+ OvsdbTerminationPointAugmentation.class);
if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
- //test
- Assert.assertEquals(UPDATED_VLAN_MODE, ovsdbTerminationPointAugmentation.getVlanMode());
+ VlanId actualVlanId = ovsdbTerminationPointAugmentation.getVlanTag();
+ Assert.assertNotNull(actualVlanId);
+ Integer actualVlanIdInt = actualVlanId.getValue();
+ Assert.assertEquals(UPDATED_VLAN_ID, actualVlanIdInt);
}
}
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo));
+ // DELETE handled by TestBridge
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
- private ArrayList<Set<Integer>> generateVlanSets() {
- ArrayList<Set<Integer>> vlanSets = new ArrayList<Set<Integer>>();
+ @Test
+ public void testCRUDTerminationPointVlanModes() throws InterruptedException {
+ final VlanMode UPDATED_VLAN_MODE = VlanMode.Access;
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
+ VlanMode []vlanModes = VlanMode.values();
+ for (VlanMode vlanMode : vlanModes) {
+ // CREATE
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ Assert.assertNotNull(bridge);
+ NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
+ connectionInfo, bridge.getBridgeName()));
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ String portName = "testTerminationPointVlanMode" + vlanMode.toString();
+ ovsdbTerminationBuilder.setName(portName);
+ ovsdbTerminationBuilder.setVlanMode(vlanMode);
+ Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
+ InstanceIdentifier<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)) {
+ //test
+ Assert.assertTrue(ovsdbTerminationPointAugmentation.getVlanMode().equals(vlanMode));
+ }
+ }
- Set<Integer> emptySet = new HashSet<Integer>();
- vlanSets.add(emptySet);
+ // 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 = SouthboundUtils.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()));
+ Assert.assertTrue(
+ mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()));
+ Thread.sleep(OVSDB_UPDATE_TIMEOUT);
- Set<Integer> singleSet = new HashSet<Integer>();
- Integer single = new Integer(2222);
- singleSet.add(single);
- vlanSets.add(singleSet);
+ 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());
+ }
+ }
- Set<Integer> minMaxMiddleSet = new HashSet<Integer>();
- Integer min = new Integer(0);
- minMaxMiddleSet.add(min);
- Integer max = new Integer(4095);
- minMaxMiddleSet.add(max);
- Integer minPlusOne = new Integer(min + 1);
- minMaxMiddleSet.add(minPlusOne);
- Integer maxMinusOne = new Integer(max - 1);
- minMaxMiddleSet.add(maxMinusOne);
- Integer middle = new Integer((max - min) / 2);
- minMaxMiddleSet.add(middle);
- vlanSets.add(minMaxMiddleSet);
+ // DELETE handled by TestBridge
+ }
+ }
+ }
- return vlanSets;
+ @SuppressWarnings("unchecked")
+ private List<Set<Integer>> generateVlanSets() {
+ int min = 0;
+ int max = 4095;
+ return Lists.newArrayList(
+ Collections.<Integer>emptySet(),
+ Sets.newHashSet(2222),
+ Sets.newHashSet(min, max, min + 1, max - 1, (max - min) / 2));
}
private List<Trunks> buildTrunkList(Set<Integer> trunkSet) {
@Test
public void testCRUDTerminationPointVlanTrunks() throws InterruptedException {
final List<Trunks> UPDATED_TRUNKS = buildTrunkList(Sets.newHashSet(2011));
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
Iterable<Set<Integer>> vlanSets = generateVlanSets();
int testCase = 0;
for (Set<Integer> vlanSet : vlanSets) {
++testCase;
// CREATE
- Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME));
- OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
- Assert.assertNotNull(bridge);
- NodeId nodeId = createManagedNodeId(createInstanceIdentifier(
- connectionInfo, bridge.getBridgeName()));
- OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
- createGenericOvsdbTerminationPointAugmentationBuilder();
- String portName = "testTerminationPointVlanTrunks" + testCase;
- ovsdbTerminationBuilder.setName(portName);
- List<Trunks> trunks = buildTrunkList(vlanSet);
- ovsdbTerminationBuilder.setTrunks(trunks);
- 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)) {
- List<Trunks> actualTrunks = ovsdbTerminationPointAugmentation.getTrunks();
- for (Trunks trunk : trunks) {
- Assert.assertTrue(actualTrunks.contains(trunk));
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ Assert.assertNotNull(bridge);
+ NodeId nodeId = SouthboundUtils.createManagedNodeId(connectionInfo, bridge.getBridgeName());
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ String portName = "testTerminationPointVlanTrunks" + testCase;
+ ovsdbTerminationBuilder.setName(portName);
+ List<Trunks> trunks = buildTrunkList(vlanSet);
+ ovsdbTerminationBuilder.setTrunks(trunks);
+ 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)) {
+ List<Trunks> actualTrunks = ovsdbTerminationPointAugmentation.getTrunks();
+ for (Trunks trunk : trunks) {
+ Assert.assertTrue(actualTrunks.contains(trunk));
+ }
}
}
- }
- // UPDATE
- NodeId testBridgeNodeId = getBridgeNode(connectionInfo, SouthboundITConstants.BRIDGE_NAME).getNodeId();
- OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder =
- new OvsdbTerminationPointAugmentationBuilder();
- tpUpdateAugmentationBuilder.setTrunks(UPDATED_TRUNKS);
- InstanceIdentifier<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);
+ // 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 = SouthboundUtils.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()));
+ Assert.assertTrue(
+ mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, portIid, portUpdateNodeBuilder.build()));
+ 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());
+ 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));
+ // DELETE handled by TestBridge
+ }
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
@Test
public void testGetOvsdbNodes() throws InterruptedException {
- ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr);
- connectOvsdbNode(connectionInfo);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
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);
+ InstanceIdentifier<Node> expectedNodeIid = SouthboundUtils.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 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()
+ * @see <code>SouthboundIT.generateBridgeOtherConfigsTestCases()</code> for specific test case information.
*/
- 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;
+ @Test
+ public void testCRUDBridgeOtherConfigs() throws InterruptedException {
+ testCRUDBridge("BridgeOtherConfigs", new SouthboundBridgeOtherConfigsBuilder(),
+ new BridgeOtherConfigsSouthboundHelper());
}
- /*
- * @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));
- }
- }
+ private interface SouthboundBridgeHelper<T> {
+ void writeValues(OvsdbBridgeAugmentationBuilder builder, List<T> values);
+ List<T> readValues(OvsdbBridgeAugmentation augmentation);
}
- /*
- * @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);
+ private <T> void testCRUDBridge(String prefix, KeyValueBuilder<T> builder, SouthboundBridgeHelper<T> helper)
+ throws InterruptedException {
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
// 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 = null;
- List<BridgeOtherConfigs> updateFromInputOtherConfigs = null;
- List<BridgeOtherConfigs> updateFromExpectedOtherConfigs = null;
- List<BridgeOtherConfigs> updateFromConfigurationOtherConfigs = null;
- List<BridgeOtherConfigs> updateFromOperationalOtherConfigs = null;
- Map<String, List<BridgeOtherConfigs>> updateToTestCase = null;
- List<BridgeOtherConfigs> updateToInputOtherConfigs = null;
- List<BridgeOtherConfigs> updateToExpectedOtherConfigs = null;
- List<BridgeOtherConfigs> updateToConfigurationOtherConfigs = null;
- List<BridgeOtherConfigs> updateToOperationalOtherConfigs = null;
- String testBridgeName = null;
- 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", TEST_BRIDGE_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputOtherConfigs = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedOtherConfigs = updateToTestCase.get(EXPECTED_VALUES_KEY);
+ List<SouthboundTestCase<T>> updateFromTestCases = generateKeyValueTestCases(builder, prefix + "From");
+ List<SouthboundTestCase<T>> updateToTestCases = generateKeyValueTestCases(builder, prefix + "To");
+ for (SouthboundTestCase<T> updateFromTestCase : updateFromTestCases) {
+ for (SouthboundTestCase<T> updateToTestCase : updateToTestCases) {
+ String testBridgeName = String.format("%s_%s", prefix, updateToTestCase.name);
// 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);
+ final OvsdbBridgeName ovsdbBridgeName = new OvsdbBridgeName(testBridgeName);
+ final InstanceIdentifier<Node> bridgeIid =
+ SouthboundUtils.createInstanceIdentifier(connectionInfo, ovsdbBridgeName);
+ final NodeId bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
+ final NodeBuilder bridgeCreateNodeBuilder = new NodeBuilder();
+ bridgeCreateNodeBuilder.setNodeId(bridgeNodeId);
+ OvsdbBridgeAugmentationBuilder bridgeCreateAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
+ bridgeCreateAugmentationBuilder.setBridgeName(ovsdbBridgeName);
+ bridgeCreateAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
+ bridgeCreateAugmentationBuilder.setFailMode(
+ SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
+ setManagedBy(bridgeCreateAugmentationBuilder, connectionInfo);
+ helper.writeValues(bridgeCreateAugmentationBuilder, updateFromTestCase.inputValues);
+ bridgeCreateNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class,
+ bridgeCreateAugmentationBuilder.build());
+ LOG.debug("Built with the intent to store bridge data {}", bridgeCreateAugmentationBuilder.toString());
+ Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid,
+ bridgeCreateNodeBuilder.build()));
+ Thread.sleep(OVSDB_UPDATE_TIMEOUT);
// READ: Read the test bridge and ensure changes are propagated to the CONFIGURATION data store,
// then repeat for OPERATIONAL data store
- updateFromConfigurationOtherConfigs = getBridge(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION).getBridgeOtherConfigs();
- assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateFromConfigurationOtherConfigs);
- 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());
+ List<T> updateFromConfigurationExternalIds = helper.readValues(getBridge(connectionInfo, testBridgeName,
+ LogicalDatastoreType.CONFIGURATION));
+ assertExpectedExist(updateFromTestCase.expectedValues, updateFromConfigurationExternalIds);
+ List<T> updateFromOperationalExternalIds = helper.readValues(getBridge(connectionInfo, testBridgeName));
+ assertExpectedExist(updateFromTestCase.expectedValues, updateFromOperationalExternalIds);
+
+ // UPDATE: update the values
+ final OvsdbBridgeAugmentationBuilder bridgeUpdateAugmentationBuilder =
+ new OvsdbBridgeAugmentationBuilder();
+ helper.writeValues(bridgeUpdateAugmentationBuilder, updateToTestCase.inputValues);
+ final NodeBuilder bridgeUpdateNodeBuilder = new NodeBuilder();
+ final Node bridgeNode = getBridgeNode(connectionInfo, testBridgeName);
+ bridgeUpdateNodeBuilder.setNodeId(bridgeNode.getNodeId());
+ bridgeUpdateNodeBuilder.setKey(bridgeNode.getKey());
+ bridgeUpdateNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class,
+ bridgeUpdateAugmentationBuilder.build());
+ Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, bridgeIid,
+ bridgeUpdateNodeBuilder.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
- updateToConfigurationOtherConfigs = getBridge(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION).getBridgeOtherConfigs();
- assertExpectedBridgeOtherConfigsExist(updateToExpectedOtherConfigs, updateToConfigurationOtherConfigs);
- assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateToConfigurationOtherConfigs);
- updateToOperationalOtherConfigs = getBridge(connectionInfo, testBridgeName)
- .getBridgeOtherConfigs();
- if (updateFromExpectedOtherConfigs != null) {
- assertExpectedBridgeOtherConfigsExist(updateToExpectedOtherConfigs,
- updateToOperationalOtherConfigs);
- assertExpectedBridgeOtherConfigsExist(updateFromExpectedOtherConfigs,
- updateToOperationalOtherConfigs);
+ List<T> updateToConfigurationExternalIds = helper.readValues(getBridge(connectionInfo, testBridgeName,
+ LogicalDatastoreType.CONFIGURATION));
+ assertExpectedExist(updateToTestCase.expectedValues, updateToConfigurationExternalIds);
+ assertExpectedExist(updateFromTestCase.expectedValues, updateToConfigurationExternalIds);
+ List<T> updateToOperationalExternalIds = helper.readValues(getBridge(connectionInfo, testBridgeName));
+ if (updateFromTestCase.expectedValues != null) {
+ assertExpectedExist(updateToTestCase.expectedValues, updateToOperationalExternalIds);
+ assertExpectedExist(updateFromTestCase.expectedValues, updateToOperationalExternalIds);
}
// DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
+ Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, bridgeIid));
+ Thread.sleep(OVSDB_UPDATE_TIMEOUT);
}
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
/*
- * Generates the test cases involved in testing BridgeExternalIds. See inline comments for descriptions of
- * the particular cases considered.
+ * @see <code>SouthboundIT.generateBridgeExternalIdsTestCases()</code> for specific test case information
+ */
+ @Test
+ public void testCRUDBridgeExternalIds() throws InterruptedException {
+ testCRUDBridge("BridgeExternalIds", new SouthboundBridgeExternalIdsBuilder(),
+ new BridgeExternalIdsSouthboundHelper());
+ }
+
+ /**
+ * <p>
+ * Representation of a southbound test case. Each test case has a name, a list of input values and a list of
+ * expected values. The input values are provided to the augmentation builder, and the expected values are checked
+ * against the output of the resulting augmentation.
+ * </p>
+ * <p>
+ * Instances of this class are immutable.
+ * </p>
*
- * 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()
+ * @param <T> The type of data used for the test case.
+ */
+ private static final class SouthboundTestCase<T> {
+ private final String name;
+ private final List<T> inputValues;
+ private final List<T> expectedValues;
+
+ /**
+ * Creates an instance of a southbound test case.
+ *
+ * @param name The test case's name.
+ * @param inputValues The input values (provided as input to the underlying augmentation builder).
+ * @param expectedValues The expected values (checked against the output of the underlying augmentation).
+ */
+ public SouthboundTestCase(
+ final String name, final List<T> inputValues, final List<T> expectedValues) {
+ this.name = name;
+ this.inputValues = inputValues;
+ this.expectedValues = expectedValues;
+ }
+ }
+
+ /**
+ * Southbound test case builder.
+ *
+ * @param <T> The type of data used for the test case.
+ */
+ private static final class SouthboundTestCaseBuilder<T> {
+ private String name;
+ private List<T> inputValues;
+ private List<T> expectedValues;
+
+ /**
+ * Creates a builder. Builders may be reused, the generated immutable instances are independent of the
+ * builders. There are no default values.
+ */
+ public SouthboundTestCaseBuilder() {
+ // Nothing to do
+ }
+
+ /**
+ * Sets the test case's name.
+ *
+ * @param name The test case's name.
+ * @return The builder.
+ */
+ public SouthboundTestCaseBuilder<T> name(final String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * Sets the input values.
+ *
+ * @param inputValues The input values.
+ * @return The builder.
+ */
+ @SafeVarargs
+ public final SouthboundTestCaseBuilder<T> input(final T... inputValues) {
+ this.inputValues = Lists.newArrayList(inputValues);
+ return this;
+ }
+
+ /**
+ * Indicates that the provided input values should be expected as output values.
+ *
+ * @return The builder.
+ */
+ public SouthboundTestCaseBuilder<T> expectInputAsOutput() {
+ this.expectedValues = this.inputValues;
+ return this;
+ }
+
+ /**
+ * Indicates that no output should be expected.
+ *
+ * @return The builder.
+ */
+ public SouthboundTestCaseBuilder<T> expectNoOutput() {
+ this.expectedValues = null;
+ return this;
+ }
+
+ /**
+ * Builds an immutable instance representing the test case.
+ *
+ * @return The test case.
+ */
+ @SuppressWarnings("unchecked")
+ public SouthboundTestCase<T> build() {
+ return new SouthboundTestCase<>(name, inputValues, expectedValues);
+ }
+ }
+
+ private abstract static class KeyValueBuilder<T> {
+ private static final int COUNTER_START = 0;
+ private int counter = COUNTER_START;
+
+ protected abstract Builder<T> builder();
+
+ protected abstract void setKey(Builder<T> builder, String key);
+
+ protected abstract void setValue(Builder<T> builder, String value);
+
+ public final T build(final String testName, final String key, final String value) {
+ final Builder<T> builder = builder();
+ this.counter++;
+ if (key != null) {
+ setKey(builder, String.format(FORMAT_STR, testName, key, this.counter));
+ }
+ if (value != null) {
+ setValue(builder, String.format(FORMAT_STR, testName, value, this.counter));
+ }
+ return builder.build();
+ }
+
+ public final void reset() {
+ this.counter = COUNTER_START;
+ }
+ }
+
+ private static final class SouthboundPortExternalIdsBuilder extends KeyValueBuilder<PortExternalIds> {
+ @Override
+ protected Builder<PortExternalIds> builder() {
+ return new PortExternalIdsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<PortExternalIds> builder, String key) {
+ ((PortExternalIdsBuilder) builder).setExternalIdKey(key);
+ }
+
+ @Override
+ protected void setValue(Builder<PortExternalIds> builder, String value) {
+ ((PortExternalIdsBuilder) builder).setExternalIdValue(value);
+ }
+ }
+
+ private static final class SouthboundInterfaceExternalIdsBuilder extends KeyValueBuilder<InterfaceExternalIds> {
+ @Override
+ protected Builder<InterfaceExternalIds> builder() {
+ return new InterfaceExternalIdsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<InterfaceExternalIds> builder, String key) {
+ ((InterfaceExternalIdsBuilder) builder).setExternalIdKey(key);
+ }
+
+ @Override
+ protected void setValue(Builder<InterfaceExternalIds> builder, String value) {
+ ((InterfaceExternalIdsBuilder) builder).setExternalIdValue(value);
+ }
+ }
+
+ private static final class SouthboundOptionsBuilder extends KeyValueBuilder<Options> {
+ @Override
+ protected Builder<Options> builder() {
+ return new OptionsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<Options> builder, String key) {
+ ((OptionsBuilder) builder).setOption(key);
+ }
+
+ @Override
+ protected void setValue(Builder<Options> builder, String value) {
+ ((OptionsBuilder) builder).setValue(value);
+ }
+ }
+
+ private static final class SouthboundInterfaceOtherConfigsBuilder extends KeyValueBuilder<InterfaceOtherConfigs> {
+ @Override
+ protected Builder<InterfaceOtherConfigs> builder() {
+ return new InterfaceOtherConfigsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<InterfaceOtherConfigs> builder, String key) {
+ ((InterfaceOtherConfigsBuilder) builder).setOtherConfigKey(key);
+ }
+
+ @Override
+ protected void setValue(Builder<InterfaceOtherConfigs> builder, String value) {
+ ((InterfaceOtherConfigsBuilder) builder).setOtherConfigValue(value);
+ }
+ }
+
+ private static final class SouthboundPortOtherConfigsBuilder extends KeyValueBuilder<PortOtherConfigs> {
+ @Override
+ protected Builder<PortOtherConfigs> builder() {
+ return new PortOtherConfigsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<PortOtherConfigs> builder, String key) {
+ ((PortOtherConfigsBuilder) builder).setOtherConfigKey(key);
+ }
+
+ @Override
+ protected void setValue(Builder<PortOtherConfigs> builder, String value) {
+ ((PortOtherConfigsBuilder) builder).setOtherConfigValue(value);
+ }
+ }
+
+ private static final class SouthboundBridgeOtherConfigsBuilder extends KeyValueBuilder<BridgeOtherConfigs> {
+ @Override
+ protected Builder<BridgeOtherConfigs> builder() {
+ return new BridgeOtherConfigsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<BridgeOtherConfigs> builder, String key) {
+ ((BridgeOtherConfigsBuilder) builder).setBridgeOtherConfigKey(key);
+ }
+
+ @Override
+ protected void setValue(Builder<BridgeOtherConfigs> builder, String value) {
+ ((BridgeOtherConfigsBuilder) builder).setBridgeOtherConfigValue(value);
+ }
+ }
+
+ private static final class SouthboundBridgeExternalIdsBuilder extends KeyValueBuilder<BridgeExternalIds> {
+ @Override
+ protected Builder<BridgeExternalIds> builder() {
+ return new BridgeExternalIdsBuilder();
+ }
+
+ @Override
+ protected void setKey(Builder<BridgeExternalIds> builder, String key) {
+ ((BridgeExternalIdsBuilder) builder).setBridgeExternalIdKey(key);
+ }
+
+ @Override
+ protected void setValue(Builder<BridgeExternalIds> builder, String value) {
+ ((BridgeExternalIdsBuilder) builder).setBridgeExternalIdValue(value);
+ }
+ }
+
+ /*
+ * Generates the test cases involved in testing key-value-based data. See inline comments for descriptions of
+ * the particular cases considered.
*/
- private Map<String, Map<String, List<BridgeExternalIds>>> generateBridgeExternalIdsTestCases() {
- Map<String, Map<String, List<BridgeExternalIds>>> testMap =
- new HashMap<String, Map<String, List<BridgeExternalIds>>>();
+ private static <T> List<SouthboundTestCase<T>> generateKeyValueTestCases(
+ KeyValueBuilder<T> builder, String testName) {
+ List<SouthboundTestCase<T>> testCases = new ArrayList<>();
- 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
+ final String idKey = testName + "Key";
+ final String idValue = testName + "Value";
+
+ // Test Case 1: TestOne
// 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
+ // Description: Create a termination point with one value
+ // Expected: A port is created with the single value specified below
+ final String testOneName = "TestOne" + testName;
+ testCases.add(new SouthboundTestCaseBuilder<T>()
+ .name(testOneName)
+ .input(builder.build(testOneName, idKey, idValue))
+ .expectInputAsOutput()
+ .build());
+
+ // Test Case 2: TestFive
// 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
+ // Description: Create a termination point with multiple (five) values
+ // Expected: A port is created with the five values specified below
+ final String testFiveName = "TestFive" + testName;
+ builder.reset();
+ testCases.add(new SouthboundTestCaseBuilder<T>()
+ .name(testFiveName)
+ .input(
+ builder.build(testFiveName, idKey, idValue),
+ builder.build(testFiveName, idKey, idValue),
+ builder.build(testFiveName, idKey, idValue),
+ builder.build(testFiveName, idKey, idValue),
+ builder.build(testFiveName, idKey, idValue))
+ .expectInputAsOutput()
+ .build());
+
+ if ((builder instanceof SouthboundBridgeExternalIdsBuilder) ||
+ (builder instanceof SouthboundInterfaceExternalIdsBuilder) ||
+ (builder instanceof SouthboundPortExternalIdsBuilder)) {
+ LOG.info("generateKeyValueTestCases: instance skipping test case 3 TestOneGoodOneMalformedValue");
+ builder.reset();
+
+ return testCases;
+ }
+
+ // Test Case 3: TestOneGoodOneMalformedValue
// 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,
+ // One perfectly fine input
+ // (TestOneGoodOneMalformedValue_GoodKey_1,
+ // TestOneGoodOneMalformedValue_GoodValue_1)
+ // and one malformed input which only has key specified
+ // (TestOneGoodOneMalformedValue_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;
+ // Expected: A port is created without any values
+ final String testOneGoodOneMalformedValueName = "TestOneGoodOneMalformedValue" + testName;
+ builder.reset();
+ testCases.add(new SouthboundTestCaseBuilder<T>()
+ .name(testOneGoodOneMalformedValueName)
+ .input(
+ builder.build(testOneGoodOneMalformedValueName, GOOD_KEY, GOOD_VALUE),
+ builder.build(testOneGoodOneMalformedValueName, NO_VALUE_FOR_KEY, null))
+ .expectNoOutput()
+ .build());
+ builder.reset();
+
+ return testCases;
}
- /*
- * @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 ) {
+ private static class PortExternalIdsSouthboundHelper implements SouthboundTerminationPointHelper<PortExternalIds> {
+ @Override
+ public void writeValues(OvsdbTerminationPointAugmentationBuilder builder, List<PortExternalIds> values) {
+ builder.setPortExternalIds(values);
+ }
- if (expected != null) {
- for (BridgeExternalIds expectedExternalId : expected) {
- Assert.assertTrue(test.contains(expectedExternalId));
- }
+ @Override
+ public List<PortExternalIds> readValues(OvsdbTerminationPointAugmentation augmentation) {
+ return augmentation.getPortExternalIds();
}
}
- /*
- * @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 = null;
- List<BridgeExternalIds> updateFromInputExternalIds = null;
- List<BridgeExternalIds> updateFromExpectedExternalIds = null;
- List<BridgeExternalIds> updateFromConfigurationExternalIds = null;
- List<BridgeExternalIds> updateFromOperationalExternalIds = null;
- Map<String, List<BridgeExternalIds>> updateToTestCase = null;
- List<BridgeExternalIds> updateToInputExternalIds = null;
- List<BridgeExternalIds> updateToExpectedExternalIds = null;
- List<BridgeExternalIds> updateToConfigurationExternalIds = null;
- List<BridgeExternalIds> updateToOperationalExternalIds = null;
- String testBridgeName = null;
- 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", TEST_BRIDGE_PREFIX, testCaseKey);
- updateToTestCase = updateToTestCases.get(testCaseKey);
- updateToInputExternalIds = updateToTestCase.get(INPUT_VALUES_KEY);
- updateToExpectedExternalIds = updateToTestCase.get(EXPECTED_VALUES_KEY);
-
- // 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);
+ private static class InterfaceExternalIdsSouthboundHelper implements
+ SouthboundTerminationPointHelper<InterfaceExternalIds> {
+ @Override
+ public void writeValues(
+ OvsdbTerminationPointAugmentationBuilder builder, List<InterfaceExternalIds> values) {
+ builder.setInterfaceExternalIds(values);
+ }
- // READ: Read the test bridge and ensure changes are propagated to the CONFIGURATION data store,
- // then repeat for OPERATIONAL data store
- updateFromConfigurationExternalIds = getBridge(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION).getBridgeExternalIds();
- assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateFromConfigurationExternalIds);
- 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);
+ @Override
+ public List<InterfaceExternalIds> readValues(OvsdbTerminationPointAugmentation augmentation) {
+ return augmentation.getInterfaceExternalIds();
+ }
+ }
- // READ: the test bridge and ensure changes are propagated to the CONFIGURATION data store,
- // then repeat for OPERATIONAL data store
- updateToConfigurationExternalIds = getBridge(connectionInfo, testBridgeName,
- LogicalDatastoreType.CONFIGURATION).getBridgeExternalIds();
- assertExpectedBridgeExternalIdsExist(updateToExpectedExternalIds, updateToConfigurationExternalIds);
- assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateToConfigurationExternalIds);
- updateToOperationalExternalIds = getBridge(connectionInfo, testBridgeName)
- .getBridgeExternalIds();
- if (updateFromExpectedExternalIds != null) {
- assertExpectedBridgeExternalIdsExist(updateToExpectedExternalIds, updateToOperationalExternalIds);
- assertExpectedBridgeExternalIdsExist(updateFromExpectedExternalIds, updateToOperationalExternalIds);
- }
+ private static class OptionsSouthboundHelper implements SouthboundTerminationPointHelper<Options> {
+ @Override
+ public void writeValues(
+ OvsdbTerminationPointAugmentationBuilder builder, List<Options> values) {
+ builder.setOptions(values);
+ }
- // DELETE
- Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName));
- }
+ @Override
+ public List<Options> readValues(OvsdbTerminationPointAugmentation augmentation) {
+ return augmentation.getOptions();
}
- Assert.assertTrue(disconnectOvsdbNode(connectionInfo));
}
- public static InstanceIdentifier<Node> createInstanceIdentifier(ConnectionInfo key,OvsdbBridgeName bridgeName) {
- return SouthboundMapper.createInstanceIdentifier(createManagedNodeId(key, bridgeName));
- }
+ private static class InterfaceOtherConfigsSouthboundHelper implements
+ SouthboundTerminationPointHelper<InterfaceOtherConfigs> {
+ @Override
+ public void writeValues(
+ OvsdbTerminationPointAugmentationBuilder builder, List<InterfaceOtherConfigs> values) {
+ builder.setInterfaceOtherConfigs(values);
+ }
- public static NodeId createManagedNodeId(ConnectionInfo key, OvsdbBridgeName bridgeName) {
- return createManagedNodeId(key.getRemoteIp(),key.getRemotePort(),bridgeName);
+ @Override
+ public List<InterfaceOtherConfigs> readValues(OvsdbTerminationPointAugmentation augmentation) {
+ return augmentation.getInterfaceOtherConfigs();
+ }
}
- public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) {
- return new NodeId(createNodeId(ip,port).getValue()
- + "/" + SouthboundConstants.BRIDGE_URI_PREFIX + "/" + bridgeName.getValue());
- }
+ private static class PortOtherConfigsSouthboundHelper implements
+ SouthboundTerminationPointHelper<PortOtherConfigs> {
+ @Override
+ public void writeValues(
+ OvsdbTerminationPointAugmentationBuilder builder, List<PortOtherConfigs> values) {
+ builder.setPortOtherConfigs(values);
+ }
- 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;
+ @Override
+ public List<PortOtherConfigs> readValues(OvsdbTerminationPointAugmentation augmentation) {
+ return augmentation.getPortOtherConfigs();
+ }
}
- public static NodeKey createNodeKey(IpAddress ip, PortNumber port) {
- return new NodeKey(createNodeId(ip,port));
- }
+ private static class BridgeExternalIdsSouthboundHelper implements SouthboundBridgeHelper<BridgeExternalIds> {
+ @Override
+ public void writeValues(
+ OvsdbBridgeAugmentationBuilder builder, List<BridgeExternalIds> values) {
+ builder.setBridgeExternalIds(values);
+ }
- 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();
+ @Override
+ public List<BridgeExternalIds> readValues(OvsdbBridgeAugmentation augmentation) {
+ return augmentation.getBridgeExternalIds();
+ }
}
- public static OvsdbNodeAugmentation createOvsdbAugmentation(ConnectionInfo key) {
- OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
- ovsdbNodeBuilder.setConnectionInfo(key);
- return ovsdbNodeBuilder.build();
- }
+ private static class BridgeOtherConfigsSouthboundHelper implements SouthboundBridgeHelper<BridgeOtherConfigs> {
+ @Override
+ public void writeValues(
+ OvsdbBridgeAugmentationBuilder builder, List<BridgeOtherConfigs> values) {
+ builder.setBridgeOtherConfigs(values);
+ }
- public static NodeId createManagedNodeId(InstanceIdentifier<Node> iid) {
- NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class);
- return nodeKey.getNodeId();
+ @Override
+ public List<BridgeOtherConfigs> readValues(OvsdbBridgeAugmentation augmentation) {
+ return augmentation.getBridgeOtherConfigs();
+ }
}
}
-