<excludes>
<!-- Exclude integration tests -->
<exclude>**/*IT*</exclude>
+ <exclude>**/*TestCases*</exclude>
</excludes>
</configuration>
</plugin>
--- /dev/null
+/*
+ * Copyright (C) 2014 Matt Oswalt
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Matt Oswalt
+ */
+
+package org.opendaylight.ovsdb.schema.hardwarevtep;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ MonitorTestCases.class,
+ ManagerTestCases.class
+})
+
+public class HardwareVtepSchemaSuiteIT {
+ // Keep this data between test runs
+ static OvsdbClient ovsdbClient;
+ static DatabaseSchema dbSchema;
+ static UUID testManagerUuid;
+ static UUID testLogicalSwitchUuid;
+ static Map<String, Map<UUID, Row>> tableCache = new HashMap<String, Map<UUID, Row>>();
+
+ public static OvsdbClient getOvsdbClient() {
+ return ovsdbClient;
+ }
+
+ public static void setOvsdbClient(OvsdbClient ovsdbClient) {
+ HardwareVtepSchemaSuiteIT.ovsdbClient = ovsdbClient;
+ }
+
+ public static UUID getTestManagerUuid() {
+ return testManagerUuid;
+ }
+
+ public static void setTestManagerUuid(UUID testManagerUuid) {
+ HardwareVtepSchemaSuiteIT.testManagerUuid = testManagerUuid;
+ }
+
+ public static UUID getTestLogicalSwitchUuid() {
+ return testLogicalSwitchUuid;
+ }
+
+ public static void setTestLogicalSwitchUuid(UUID testLogicalSwitchUuid) {
+ HardwareVtepSchemaSuiteIT.testLogicalSwitchUuid = testLogicalSwitchUuid;
+ }
+
+ public static Map<String, Map<UUID, Row>> getTableCache() {
+ return tableCache;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Madhu Venugopal, Matt Oswalt
+ */
+
+package org.opendaylight.ovsdb.schema.hardwarevtep;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.OvsdbConnection;
+import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
+import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
+import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+
+import com.google.common.util.concurrent.ListenableFuture;
+
+public abstract class HardwareVtepSchemaTestBase implements OvsdbRPC.Callback{
+ private final static String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
+ private final static String SERVER_PORT = "ovsdbserver.port";
+ private final static String DEFAULT_SERVER_PORT = "6640";
+ private final static String CONNECTION_TYPE = "ovsdbserver.connection";
+ private final static String CONNECTION_TYPE_ACTIVE = "active";
+ private final static String CONNECTION_TYPE_PASSIVE = "passive";
+ private final static String TEST_MANAGER_TARGET = "ptcp:10.12.0.15:6640"; //TODO: for future use
+
+ /**
+ * Represents the Hardware VTEP Schema
+ */
+ public final static String HARDWARE_VTEP_SCHEMA = "hardware_vtep";
+ protected OvsdbClient ovs = null;
+ Boolean supportsHardwareVtepSchema;
+
+ DatabaseSchema dbSchema = null;
+
+ public Properties loadProperties() {
+ Properties props = new Properties(System.getProperties());
+ return props;
+ }
+
+ @Before
+ public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
+
+ this.ovs = HardwareVtepSchemaSuiteIT.getOvsdbClient();
+
+ if (this.ovs == null) {
+ this.ovs = getTestConnection();
+ HardwareVtepSchemaSuiteIT.setOvsdbClient(this.ovs);
+ }
+ //retrieve list of databases from OVSDB server
+ ListenableFuture<List<String>> databases = ovs.getDatabases();
+ List<String> dbNames = databases.get();
+ Assert.assertNotNull(dbNames);
+
+ if (supportsHardwareVtepSchema == null) {
+ supportsHardwareVtepSchema = false;
+
+ //verify that HW VTEP schema is in the list of supported databases
+ for (String dbName : dbNames) {
+ if (dbName.equals(HARDWARE_VTEP_SCHEMA)) {
+ supportsHardwareVtepSchema = true;
+ break;
+ }
+ }
+ }
+
+ if (supportsHardwareVtepSchema) {
+ //desired schema exists, retrieve contents of specified database
+ dbSchema = this.ovs.getSchema(HARDWARE_VTEP_SCHEMA).get();
+ }
+
+ }
+
+ public boolean checkSchema() {
+ return supportsHardwareVtepSchema;
+ }
+
+ public OvsdbClient getTestConnection() throws IOException, InterruptedException, ExecutionException, TimeoutException {
+ Properties props = loadProperties();
+ String addressStr = props.getProperty(SERVER_IPADDRESS);
+ String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
+ String connectionType = props.getProperty(CONNECTION_TYPE, "active");
+
+ // If the connection type is active, controller connects to the ovsdb-server
+ if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
+ if (addressStr == null) {
+ Assert.fail(usage());
+ }
+
+ InetAddress address;
+ try {
+ address = InetAddress.getByName(addressStr);
+ } catch (Exception e) {
+ System.out.println("Unable to resolve " + addressStr);
+ e.printStackTrace();
+ return null;
+ }
+
+ Integer port;
+ try {
+ port = Integer.parseInt(portStr);
+ } catch (NumberFormatException e) {
+ System.out.println("Invalid port number : " + portStr);
+ e.printStackTrace();
+ return null;
+ }
+
+ OvsdbConnection connection = OvsdbConnectionService.getService();
+ return connection.connect(address, port);
+ } else if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_PASSIVE)) {
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ Future<OvsdbClient> passiveConnection = executor.submit(new PassiveListener());
+ return passiveConnection.get(60, TimeUnit.SECONDS);
+ }
+ Assert.fail("Connection parameter ("+CONNECTION_TYPE+") must be either active or passive");
+ return null;
+ }
+
+ public UUID getGlobalTableUuid(OvsdbClient ovs, Map<String, Map<UUID, Row>> tableCache) {
+ Global glbl = ovs.getTypedRowWrapper(Global.class, null);
+ Map<UUID, Row> glblTbl = tableCache.get(glbl.getSchema().getName());
+ if (glblTbl != null) {
+ if (glblTbl.keySet().size() >= 1) {
+ return (UUID)glblTbl.keySet().toArray()[0];
+ }
+ }
+ return null;
+ }
+
+ private String usage() {
+ return "Integration Test needs a valid connection configuration as follows :\n" +
+ "active connection : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"+
+ "passive connection : mvn -Pintegrationtest -Dovsdbserver.connection=passive verify\n";
+ }
+
+ public class PassiveListener implements Callable<OvsdbClient>, OvsdbConnectionListener {
+ OvsdbClient client = null;
+ @Override
+ public OvsdbClient call() throws Exception {
+ OvsdbConnection connection = OvsdbConnectionService.getService();
+ connection.registerForPassiveConnection(this);
+ while (client == null) {
+ Thread.sleep(500);
+ }
+ return client;
+ }
+
+ @Override
+ public void connected(OvsdbClient client) {
+ this.client = client;
+ }
+
+ @Override
+ public void disconnected(OvsdbClient client) {
+ Assert.assertEquals(this.client.getConnectionInfo(), client.getConnectionInfo());
+ this.client = null;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Matt Oswalt
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Matt Oswalt
+ */
+
+package org.opendaylight.ovsdb.schema.hardwarevtep;
+
+import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+import junit.framework.Assert;
+
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.ovsdb.lib.message.UpdateNotification;
+import org.opendaylight.ovsdb.lib.notation.Mutator;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.operations.OperationResult;
+import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.ListenableFuture;
+
+public class ManagerTestCases extends HardwareVtepSchemaTestBase {
+ Logger logger = LoggerFactory.getLogger(ManagerTestCases.class);
+
+ @Before
+ public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
+ super.setUp();
+ }
+
+ /**
+ * Create a new manager string in addition to whatever is already there
+ * Will modify the Global table to include the UUID to the new Manager row
+ */
+ @Test
+ public void createManager() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, TimeoutException {
+ //Ensure test only proceeds if HW VTEP is supported
+ Assume.assumeTrue(super.checkSchema());
+
+ //proceed only if schema was already retrieved successfully
+ Assert.assertNotNull(HardwareVtepSchemaSuiteIT.dbSchema);
+
+ //create new manager and set target string
+ Manager mgr = ovs.createTypedRowWrapper(Manager.class);
+ mgr.setTarget("ptcp:6641");
+
+ String transactionUuidStr = "foobar";
+ int insertOperationIndex = 0;
+
+ Global glbl = this.ovs.createTypedRowWrapper(Global.class);
+ glbl.setManagers(Sets.newHashSet(new UUID(transactionUuidStr)));
+
+ TransactionBuilder transactionBuilder = ovs.transactBuilder(HardwareVtepSchemaSuiteIT.dbSchema)
+ .add(op.insert(mgr.getSchema())
+ .withId(transactionUuidStr)
+ .value(mgr.getTargetColumn()))
+ .add(op.mutate(glbl.getSchema())
+ .addMutation(glbl.getManagersColumn().getSchema(), Mutator.INSERT,
+ glbl.getManagersColumn().getData()));
+
+
+ ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
+ List<OperationResult> operationResults = results.get();
+
+ //ensure we received the results of the operation
+ Assert.assertFalse(operationResults.isEmpty());
+ // Check if Results matches the number of operations in transaction
+ Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
+
+ logger.info("Insert & Mutate operation results for new manager = " + operationResults);
+
+ // Check for any errors
+ for (OperationResult result : operationResults) {
+ Assert.assertNull(result.getError());
+ }
+
+ HardwareVtepSchemaSuiteIT.setTestManagerUuid(operationResults.get(insertOperationIndex).getUuid());
+
+ Thread.sleep(3000); // Wait for cache to catchup
+
+ Row managerRow = HardwareVtepSchemaSuiteIT.getTableCache().get(mgr.getSchema().getName()).get(HardwareVtepSchemaSuiteIT.getTestManagerUuid());
+ Manager monitoredManager = ovs.getTypedRowWrapper(Manager.class, managerRow);
+ Assert.assertEquals(monitoredManager.getTargetColumn().getData(), mgr.getTargetColumn().getData());
+ Assert.assertNotNull(monitoredManager.getUuid());
+ Assert.assertNotNull(monitoredManager.getVersion());
+ Assert.assertNotNull(this.getGlobalTableUuid(ovs, HardwareVtepSchemaSuiteIT.getTableCache()));
+ }
+
+ @Override
+ public void update(Object context, UpdateNotification upadateNotification) {
+
+ }
+
+ @Override
+ public void locked(Object context, List<String> ids) {
+
+ }
+
+ @Override
+ public void stolen(Object context, List<String> ids) {
+
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Madhu Venugopal, Dave Tucker, Matt Oswalt
+ */
+
+package org.opendaylight.ovsdb.schema.hardwarevtep;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+import junit.framework.Assert;
+
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.ovsdb.lib.MonitorCallBack;
+import org.opendaylight.ovsdb.lib.message.MonitorRequest;
+import org.opendaylight.ovsdb.lib.message.MonitorRequestBuilder;
+import org.opendaylight.ovsdb.lib.message.MonitorSelect;
+import org.opendaylight.ovsdb.lib.message.TableUpdate;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.message.UpdateNotification;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+public class MonitorTestCases extends HardwareVtepSchemaTestBase {
+
+ Logger logger = LoggerFactory.getLogger(MonitorTestCases.class);
+
+ @Override
+ @Before
+ public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
+ super.setUp();
+ }
+
+ @Test
+ public void monitorTables() throws ExecutionException, InterruptedException, IOException, TimeoutException {
+ //Ensure test only proceeds if HW VTEP is supported
+ Assume.assumeTrue(super.checkSchema());
+ HardwareVtepSchemaSuiteIT.dbSchema = this.ovs.getSchema(HARDWARE_VTEP_SCHEMA).get();
+ Assert.assertNotNull(HardwareVtepSchemaSuiteIT.dbSchema);
+
+ List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
+ monitorRequests.add(this.getAllColumnsMonitorRequest(Manager.class));
+ monitorRequests.add(this.getAllColumnsMonitorRequest(Global.class));
+
+ TableUpdates updates = ovs.monitor(HardwareVtepSchemaSuiteIT.dbSchema, monitorRequests, new UpdateMonitor());
+ Assert.assertNotNull(updates);
+ this.updateTableCache(updates);
+ }
+
+ /**
+ * As per RFC 7047, section 4.1.5, if a Monitor request is sent without any columns, the update response will not include
+ * the _uuid column.
+ * ----------------------------------------------------------------------------------------------------------------------------------
+ * Each <monitor-request> specifies one or more columns and the manner in which the columns (or the entire table) are to be monitored.
+ * The "columns" member specifies the columns whose values are monitored. It MUST NOT contain duplicates.
+ * If "columns" is omitted, all columns in the table, except for "_uuid", are monitored.
+ * ----------------------------------------------------------------------------------------------------------------------------------
+ * In order to overcome this limitation, this method
+ *
+ * @return MonitorRequest that includes all the Bridge Columns including _uuid
+ */
+ public <T extends TypedBaseTable<GenericTableSchema>> MonitorRequest<GenericTableSchema> getAllColumnsMonitorRequest (Class <T> klazz) { //TODO: Needs updated for HW VTEP
+ TypedBaseTable<GenericTableSchema> table = ovs.createTypedRowWrapper(klazz);
+ GenericTableSchema bridgeSchema = table.getSchema();
+ Set<String> columns = bridgeSchema.getColumns();
+ MonitorRequestBuilder<GenericTableSchema> bridgeBuilder = MonitorRequestBuilder.builder(table.getSchema());
+ for (String column : columns) {
+ bridgeBuilder.addColumn(column);
+ }
+ return bridgeBuilder.with(new MonitorSelect(true, true, true, true)).build();
+ }
+
+
+
+ @Override
+ public void update(Object context, UpdateNotification upadateNotification) {
+
+ }
+
+ @Override
+ public void locked(Object context, List<String> ids) {
+
+ }
+
+ @Override
+ public void stolen(Object context, List<String> ids) {
+
+ }
+
+ private void updateTableCache(TableUpdates updates) {
+ for (String tableName : updates.getUpdates().keySet()) {
+ Map<UUID, Row> tUpdate = HardwareVtepSchemaSuiteIT.getTableCache().get(tableName);
+ TableUpdate update = updates.getUpdates().get(tableName);
+ for (UUID uuid : (Set<UUID>)update.getRows().keySet()) {
+ if (update.getNew(uuid) != null) {
+ if (tUpdate == null) {
+ tUpdate = new HashMap<>();
+ HardwareVtepSchemaSuiteIT.getTableCache().put(tableName, tUpdate);
+ }
+ tUpdate.put(uuid, update.getNew(uuid));
+ } else {
+ tUpdate.remove(uuid);
+ }
+ }
+ }
+ }
+
+ private class UpdateMonitor implements MonitorCallBack {
+ @Override
+ public void update(TableUpdates result, DatabaseSchema dbSchema) {
+ updateTableCache(result);
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ System.out.println("Exception t = " + t);
+ }
+ }
+}
+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Authors : Madhu Venugopal
- */
-package org.opendaylight.ovsdb.schema.hardwarevtep;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeoutException;
-
-import junit.framework.Assert;
-
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.ovsdb.lib.OvsdbClient;
-import org.opendaylight.ovsdb.lib.message.UpdateNotification;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.util.concurrent.ListenableFuture;
-
-public class TypedHardwareVTepSchemaIT extends OvsdbTestBase {
-
- Logger logger = LoggerFactory.getLogger(TypedHardwareVTepSchemaIT.class);
- OvsdbClient ovs;
- DatabaseSchema dbSchema = null;
-
- @Test
- public void testGetDBs() throws ExecutionException, InterruptedException {
- ListenableFuture<List<String>> databases = ovs.getDatabases();
- List<String> dbNames = databases.get();
- Assert.assertNotNull(dbNames);
- boolean hasHardwareVTepSchema = false;
- for(String dbName : dbNames) {
- if (dbName.equals(HARDWARE_VTEP_SCHEMA)) {
- hasHardwareVTepSchema = true;
- break;
- }
- }
- Assume.assumeTrue(hasHardwareVTepSchema);
- }
-
- @Before
- public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
- if (ovs != null) {
- return;
- }
- ovs = getTestConnection();
- testGetDBs();
- dbSchema = ovs.getSchema(HARDWARE_VTEP_SCHEMA).get();
- }
-
- @After
- public void tearDown() throws InterruptedException, ExecutionException {
- }
-
- @Override
- public void update(Object node, UpdateNotification upadateNotification) {
- // TODO Auto-generated method stub
-
- }
- @Override
- public void locked(Object node, List<String> ids) {
- // TODO Auto-generated method stub
-
- }
- @Override
- public void stolen(Object node, List<String> ids) {
- // TODO Auto-generated method stub
-
- }
-}