2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Sam Hague, Matt Oswalt
10 package org.opendaylight.ovsdb.integrationtest.schema.openvswitch;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertNotSame;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertSame;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20 import static org.junit.Assume.assumeTrue;
21 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
22 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
23 import static org.ops4j.pax.exam.CoreOptions.options;
24 import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;
25 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
27 import com.google.common.collect.ImmutableMap;
28 import com.google.common.collect.ImmutableSet;
29 import com.google.common.collect.Lists;
30 import com.google.common.collect.Maps;
31 import com.google.common.collect.Sets;
32 import com.google.common.util.concurrent.ListenableFuture;
33 import java.io.IOException;
34 import java.util.HashMap;
35 import java.util.List;
38 import java.util.concurrent.ExecutionException;
39 import javax.inject.Inject;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.junit.runner.RunWith;
43 import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
44 import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
45 import org.opendaylight.ovsdb.lib.MonitorCallBack;
46 import org.opendaylight.ovsdb.lib.OvsdbClient;
47 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
48 import org.opendaylight.ovsdb.lib.message.MonitorRequest;
49 import org.opendaylight.ovsdb.lib.message.MonitorRequestBuilder;
50 import org.opendaylight.ovsdb.lib.message.MonitorSelect;
51 import org.opendaylight.ovsdb.lib.message.TableUpdate;
52 import org.opendaylight.ovsdb.lib.message.TableUpdates;
53 import org.opendaylight.ovsdb.lib.notation.Mutator;
54 import org.opendaylight.ovsdb.lib.notation.Row;
55 import org.opendaylight.ovsdb.lib.notation.UUID;
56 import org.opendaylight.ovsdb.lib.notation.Version;
57 import org.opendaylight.ovsdb.lib.operations.OperationResult;
58 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
59 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
60 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
61 import org.opendaylight.ovsdb.lib.schema.TableSchema;
62 import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
63 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
64 import org.opendaylight.ovsdb.schema.openvswitch.Controller;
65 import org.opendaylight.ovsdb.schema.openvswitch.FlowSampleCollectorSet;
66 import org.opendaylight.ovsdb.schema.openvswitch.FlowTable;
67 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
68 import org.opendaylight.ovsdb.schema.openvswitch.IPFIX;
69 import org.opendaylight.ovsdb.schema.openvswitch.Manager;
70 import org.opendaylight.ovsdb.schema.openvswitch.Mirror;
71 import org.opendaylight.ovsdb.schema.openvswitch.NetFlow;
72 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
73 import org.opendaylight.ovsdb.schema.openvswitch.Port;
74 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
75 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
76 import org.opendaylight.ovsdb.schema.openvswitch.SFlow;
77 import org.opendaylight.ovsdb.schema.openvswitch.SSL;
78 import org.ops4j.pax.exam.Configuration;
79 import org.ops4j.pax.exam.Option;
80 import org.ops4j.pax.exam.junit.PaxExam;
81 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
82 import org.ops4j.pax.exam.spi.reactors.PerSuite;
83 import org.ops4j.pax.exam.util.PathUtils;
84 import org.osgi.framework.BundleContext;
85 import org.slf4j.Logger;
86 import org.slf4j.LoggerFactory;
88 @RunWith(PaxExam.class)
89 @ExamReactorStrategy(PerSuite.class)
90 public class OpenVSwitchIT extends OvsdbIntegrationTestBase {
91 private static final Logger LOG = LoggerFactory.getLogger(OpenVSwitchIT.class);
92 private static boolean monitorReady = false;
93 private static boolean schemaSupported = false;
94 private static final String TEST_BRIDGE_NAME = "br_test";
95 private static final String TEST_MANAGER_UUID_STR = "managerUuidName";
96 private static final String ASSERT_TRANS_ERROR = "Transaction should not have errors";
97 private static final String ASSERT_TRANS_RESULT_EMPTY = "Transaction should not be empty";
98 private static final String ASSERT_TRANS_OPERATION_COUNT = "Transaction should match number of operations";
99 private static final String ASSERT_TRANS_UUID = "Transaction UUID should not be null";
100 private Version schemaVersion;
101 private UUID testBridgeUuid = null;
102 private UUID testController1Uuid = null;
103 private UUID testController2Uuid = null;
104 private UUID testFlowSampleCollectorSetUuid = null;
105 private UUID testFlowTableUuid = null;
106 private UUID testInterfaceUuid = null;
107 private UUID testIpfixUuid = null;
108 private UUID testManagerUuid = null;
109 private UUID testMirrorUuid = null;
110 private UUID testNetFlowUuid = null;
111 private UUID testPortUuid = null;
112 private UUID testQosUuid = null;
113 private UUID testQueueUuid = null;
114 private UUID testSFlowUuid = null;
115 private UUID testSslUuid = null;
116 private Version flowSampleCollectorSetFromVersion = Version.fromString("7.1.0");
117 private Version flowTableFromVersion = Version.fromString("6.5.0");
118 private Version prefixesAddedVersion = Version.fromString("7.4.0");
119 private Version externalIdAddedVerson = Version.fromString("7.5.0");
120 private Version ipfixFromVersion = Version.fromString("7.1.0");
121 private Version ipfixCacheFromVersion = Version.fromString("7.3.0");
123 private static Map<String, Map<UUID, Row>> tableCache = new HashMap<>();
124 private static Map<String, Map<UUID, Row>> getTableCache () {
128 private static OvsdbClient ovsdbClient;
129 private OvsdbClient getClient () {
133 private static DatabaseSchema dbSchema;
134 private DatabaseSchema getDbSchema () {
139 private BundleContext bc;
142 public Option[] config() throws Exception {
144 systemProperty("logback.configurationFile").value(
145 "file:" + PathUtils.getBaseDir()
146 + "/src/test/resources/logback.xml"
148 // To start OSGi console for inspection remotely
149 systemProperty("osgi.console").value("2401"),
151 propagateSystemProperty("ovsdbserver.ipaddress"),
152 propagateSystemProperty("ovsdbserver.port"),
154 ConfigurationBundles.controllerBundles(),
155 ConfigurationBundles.ovsdbLibraryBundles(),
156 ConfigurationBundles.ovsdbDefaultSchemaBundles(),
162 public void setUp () throws ExecutionException, InterruptedException, IOException {
164 assertTrue(OPEN_VSWITCH_SCHEMA + " is required.", checkSchema(OPEN_VSWITCH_SCHEMA));
165 assertTrue("Failed to monitor tables", monitorTables());
166 schemaVersion = getClient().getDatabaseSchema(OPEN_VSWITCH_SCHEMA).getVersion();
167 LOG.info("{} schema version = {}", OPEN_VSWITCH_SCHEMA, schemaVersion);
170 public boolean checkSchema (String schema) {
171 if (schemaSupported) {
172 LOG.info("Schema ({}) is supported", schema);
176 ovsdbClient = getTestConnection();
177 assertNotNull("Invalid Client. Check connection params", ovsdbClient);
178 //Thread.sleep(3000); // Wait for a few seconds to get the Schema exchange done
179 if (isSchemaSupported(ovsdbClient, schema)) {
180 dbSchema = ovsdbClient.getSchema(schema).get();
181 assertNotNull(dbSchema);
182 LOG.info("{} schema in {} with tables: {}",
183 schema, ovsdbClient.getConnectionInfo(), dbSchema.getTables());
184 schemaSupported = true;
187 } catch (Exception e) {
188 fail("Exception : "+e.getMessage());
191 LOG.info("Schema ({}) is not supported", schema);
195 public UUID getOpenVSwitchTableUuid (OvsdbClient ovs, Map<String, Map<UUID, Row>> tableCache) {
196 OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
197 Map<UUID, Row> ovsTable = tableCache.get(openVSwitch.getSchema().getName());
198 if (ovsTable != null) {
199 if (ovsTable.keySet().size() >= 1) {
200 return (UUID)ovsTable.keySet().toArray()[0];
206 public boolean isSchemaSupported (OvsdbClient client, String schema) throws ExecutionException, InterruptedException {
207 ListenableFuture<List<String>> databases = client.getDatabases();
208 List<String> dbNames = databases.get();
209 assertNotNull(dbNames);
210 if (dbNames.contains(schema)) {
218 * As per RFC 7047, section 4.1.5, if a Monitor request is sent without any columns, the update response will not include
220 * ----------------------------------------------------------------------------------------------------------------------------------
221 * Each <monitor-request> specifies one or more columns and the manner in which the columns (or the entire table) are to be monitored.
222 * The "columns" member specifies the columns whose values are monitored. It MUST NOT contain duplicates.
223 * If "columns" is omitted, all columns in the table, except for "_uuid", are monitored.
224 * ----------------------------------------------------------------------------------------------------------------------------------
225 * In order to overcome this limitation, this method
227 * @return MonitorRequest that includes all the Bridge Columns including _uuid
229 public <T extends TypedBaseTable<GenericTableSchema>> MonitorRequest<GenericTableSchema> getAllColumnsMonitorRequest (Class <T> klazz) {
230 TypedBaseTable<GenericTableSchema> table = getClient().createTypedRowWrapper(klazz);
231 GenericTableSchema tableSchema = table.getSchema();
232 Set<String> columns = tableSchema.getColumns();
233 MonitorRequestBuilder<GenericTableSchema> bridgeBuilder = MonitorRequestBuilder.builder(table.getSchema());
234 for (String column : columns) {
235 bridgeBuilder.addColumn(column);
237 return bridgeBuilder.with(new MonitorSelect(true, true, true, true)).build();
240 public <T extends TableSchema<T>> MonitorRequest<T> getAllColumnsMonitorRequest (T tableSchema) {
241 Set<String> columns = tableSchema.getColumns();
242 MonitorRequestBuilder<T> monitorBuilder = MonitorRequestBuilder.builder(tableSchema);
243 for (String column : columns) {
244 monitorBuilder.addColumn(column);
246 return monitorBuilder.with(new MonitorSelect(true, true, true, true)).build();
249 public boolean monitorTables () throws ExecutionException, InterruptedException, IOException {
251 LOG.info("Monitoring is already initialized.");
255 assertNotNull(getDbSchema());
257 List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
258 Set<String> tables = getDbSchema().getTables();
259 assertNotNull("ovsdb tables should not be null", tables);
261 for (String tableName : tables) {
262 GenericTableSchema tableSchema = getDbSchema().table(tableName, GenericTableSchema.class);
263 monitorRequests.add(this.getAllColumnsMonitorRequest(tableSchema));
265 TableUpdates updates = getClient().monitor(getDbSchema(), monitorRequests, new UpdateMonitor());
266 assertNotNull(updates);
267 this.updateTableCache(updates);
270 LOG.info("Monitoring is initialized.");
274 private void updateTableCache (TableUpdates updates) {
275 for (String tableName : updates.getUpdates().keySet()) {
276 Map<UUID, Row> tUpdate = getTableCache().get(tableName);
277 TableUpdate update = updates.getUpdates().get(tableName);
278 for (UUID uuid : (Set<UUID>)update.getRows().keySet()) {
279 if (update.getNew(uuid) != null) {
280 if (tUpdate == null) {
281 tUpdate = new HashMap<>();
282 getTableCache().put(tableName, tUpdate);
284 tUpdate.put(uuid, update.getNew(uuid));
286 tUpdate.remove(uuid);
292 private class UpdateMonitor implements MonitorCallBack {
294 public void update(TableUpdates result, DatabaseSchema dbSchema) {
295 updateTableCache(result);
299 public void exception(Throwable t) {
300 LOG.error("Exception t = " + t);
304 public List<OperationResult> executeTransaction (TransactionBuilder transactionBuilder, String text)
305 throws ExecutionException, InterruptedException {
306 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
307 List<OperationResult> operationResults = results.get();
308 LOG.info("{}: {}", text, operationResults);
309 org.junit.Assert.assertFalse(ASSERT_TRANS_RESULT_EMPTY, operationResults.isEmpty());
310 assertEquals(ASSERT_TRANS_OPERATION_COUNT, transactionBuilder.getOperations().size(), operationResults.size());
311 for (OperationResult result : operationResults) {
312 assertNull(ASSERT_TRANS_ERROR, result.getError());
314 //Thread.sleep(500); // Wait for a few seconds to ensure the cache updates
315 return operationResults;
318 public UUID bridgeInsert () throws ExecutionException, InterruptedException {
319 Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
320 bridge.setName(TEST_BRIDGE_NAME);
321 bridge.setStatus(ImmutableMap.of("key", "value"));
322 bridge.setFloodVlans(Sets.newHashSet(34L));
324 OpenVSwitch openVSwitch = getClient().createTypedRowWrapper(OpenVSwitch.class);
325 openVSwitch.setBridges(Sets.newHashSet(new UUID(TEST_BRIDGE_NAME)));
327 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
328 .add(op.insert(bridge.getSchema())
329 .withId(TEST_BRIDGE_NAME)
330 .value(bridge.getNameColumn()))
331 .add(op.comment("Bridge: Inserting " + TEST_BRIDGE_NAME))
332 .add(op.update(bridge.getSchema())
333 .set(bridge.getStatusColumn())
334 .set(bridge.getFloodVlansColumn())
335 .where(bridge.getNameColumn().getSchema().opEqual(bridge.getName()))
336 .and(bridge.getNameColumn().getSchema().opEqual(bridge.getName()))
338 .add(op.comment("Bridge: Updating " + TEST_BRIDGE_NAME))
339 .add(op.mutate(openVSwitch.getSchema())
340 .addMutation(openVSwitch.getBridgesColumn().getSchema(), Mutator.INSERT,
341 openVSwitch.getBridgesColumn().getData()))
342 .add(op.comment("Open_vSwitch: Mutating " + TEST_BRIDGE_NAME));
344 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
345 "Bridge Insert, Update and Mutate operation results");
346 UUID bridgeUuid = operationResults.get(0).getUuid();
347 assertNotNull(ASSERT_TRANS_UUID, bridgeUuid);
351 public void bridgeDelete (UUID bridgeUuid) throws ExecutionException, InterruptedException {
352 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
353 OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
355 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
356 .add(op.delete(bridge.getSchema())
357 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
359 .add(op.comment("Bridge: Deleting " + TEST_BRIDGE_NAME))
360 .add(op.mutate(openVSwitch.getSchema())
361 .addMutation(openVSwitch.getBridgesColumn().getSchema(), Mutator.DELETE,
362 Sets.newHashSet(bridgeUuid)))
363 .add(op.comment("Open_vSwitch: Mutating " + TEST_BRIDGE_NAME + " " + bridgeUuid))
364 .add(op.commit(true));
366 executeTransaction(transactionBuilder, "Bridge delete operation results");
370 public void testBridge () throws ExecutionException, InterruptedException {
371 testBridgeUuid = bridgeInsert();
373 // Verify that the local cache was updated with the remote changes
374 Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
375 Row bridgeRow = getTableCache().get(bridge.getSchema().getName()).get(testBridgeUuid);
376 Bridge monitoredBridge = getClient().getTypedRowWrapper(Bridge.class, bridgeRow);
377 assertEquals(TEST_BRIDGE_NAME, monitoredBridge.getNameColumn().getData());
379 bridgeDelete(testBridgeUuid);
382 private void controllerInsert () throws ExecutionException, InterruptedException {
383 String controllerUuidStr = "controller";
384 Controller controller1 = getClient().createTypedRowWrapper(Controller.class);
385 controller1.setTarget("tcp:1.1.1.1:6640");
386 Controller controller2 = getClient().createTypedRowWrapper(Controller.class);
387 controller2.setTarget("tcp:2.2.2.2:6640");
388 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
390 // Insert row to Controller table with address in target column
391 // Update row in Bridge table with controller uuid in controller column
392 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
393 .add(op.insert(controller1.getSchema())
394 .withId(controllerUuidStr)
395 .value(controller1.getTargetColumn()))
396 .add(op.comment("Controller: Inserting controller1 " + controller1.getTargetColumn().getData()))
397 .add(op.mutate(bridge.getSchema())
398 .addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT,
399 Sets.newHashSet(new UUID(controllerUuidStr)))
400 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
402 .add(op.comment("Bridge: Mutating controller1 " + controller1.getTargetColumn().getData()));
404 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
405 "Controller: Insert & Mutate operation results for controller1");
406 testController1Uuid = operationResults.get(0).getUuid();
407 assertNotNull(ASSERT_TRANS_UUID, testController1Uuid);
409 // Verify that the local cache was updated with the remote changes
410 Row controllerRow = getTableCache().get(controller1.getSchema().getName()).get(testController1Uuid);
411 Controller monitoredController = getClient().getTypedRowWrapper(Controller.class, controllerRow);
412 assertEquals(controller1.getTargetColumn().getData(), monitoredController.getTargetColumn().getData());
414 Row bridgeRow = getTableCache().get(bridge.getSchema().getName()).get(testBridgeUuid);
415 Bridge monitoredBridge = getClient().getTypedRowWrapper(Bridge.class, bridgeRow);
416 assertEquals(1, monitoredBridge.getControllerColumn().getData().size());
418 transactionBuilder = getClient().transactBuilder(getDbSchema())
419 .add(op.insert(controller2.getSchema())
420 .withId(controllerUuidStr)
421 .value(controller2.getTargetColumn()))
422 .add(op.comment("Controller: Inserting controller2 " + controller2.getTargetColumn().getData()))
423 .add(op.mutate(bridge.getSchema())
424 .addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT,
425 Sets.newHashSet(new UUID(controllerUuidStr)))
426 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
428 .add(op.comment("Bridge: Mutating controller2 " + controller2.getTargetColumn().getData()));
430 operationResults = executeTransaction(transactionBuilder,
431 new String("Controller: Insert & Mutate operation results for controller2"));
432 testController2Uuid = operationResults.get(0).getUuid();
433 assertNotNull(ASSERT_TRANS_UUID, testController2Uuid);
435 // Verify that the local cache was updated with the remote changes
436 controllerRow = getTableCache().get(controller2.getSchema().getName()).get(testController2Uuid);
437 monitoredController = getClient().getTypedRowWrapper(Controller.class, controllerRow);
438 assertEquals(controller2.getTargetColumn().getData(), monitoredController.getTargetColumn().getData());
440 bridgeRow = getTableCache().get(bridge.getSchema().getName()).get(testBridgeUuid);
441 monitoredBridge = getClient().getTypedRowWrapper(Bridge.class, bridgeRow);
442 assertEquals(2, monitoredBridge.getControllerColumn().getData().size());
445 private void controllerDelete () throws ExecutionException, InterruptedException {
446 Controller controller = getClient().getTypedRowWrapper(Controller.class, null);
447 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
448 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
450 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
451 .add(op.delete(controller.getSchema())
452 .where(controller.getUuidColumn().getSchema().opEqual(testController1Uuid))
454 .add(op.comment("Controller: Deleting " + testController1Uuid))
455 .add(op.mutate(bridge.getSchema()) // Delete a controller column in the Bridge table
456 .addMutation(bridge.getControllerColumn().getSchema(), Mutator.DELETE,
457 Sets.newHashSet(testController1Uuid)))
458 .add(op.comment("Bridge: Mutating " + testController1Uuid))
459 .add(op.commit(true));
461 executeTransaction(transactionBuilder, "Controller: Delete operation results for controller1");
464 .add(op.delete(controller.getSchema())
465 .where(controller.getUuidColumn().getSchema().opEqual(testController2Uuid))
467 .add(op.comment("Controller: Deleting " + testController2Uuid))
468 .add(op.mutate(bridge.getSchema()) // Delete a controller column in the Bridge table
469 .addMutation(bridge.getControllerColumn().getSchema(), Mutator.DELETE,
470 Sets.newHashSet(testController2Uuid)))
471 .add(op.comment("Bridge: Mutating " + testController2Uuid))
472 .add(op.commit(true));
474 executeTransaction(transactionBuilder, "Controller: Delete operation results for controller2");
478 public void testController () throws ExecutionException, InterruptedException {
479 testBridgeUuid = bridgeInsert();
482 bridgeDelete(testBridgeUuid);
486 public void testFlowSampleCollectorSetTableNotSupported () {
487 // Don't run this test if the table is not supported
488 assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) < 0);
490 boolean isExceptionRaised = false;
492 FlowSampleCollectorSet flowSampleCollectorSet = getClient().createTypedRowWrapper(FlowSampleCollectorSet.class);
493 } catch (SchemaVersionMismatchException e) {
494 isExceptionRaised = true;
496 assertTrue(isExceptionRaised);
499 public void flowSampleCollectorSetInsert () throws ExecutionException, InterruptedException {
500 // Don't run this test if the table is not supported
501 assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) >= 0);
503 FlowSampleCollectorSet flowSampleCollectorSet =
504 getClient().createTypedRowWrapper(FlowSampleCollectorSet.class);
505 flowSampleCollectorSet.setId(Long.valueOf(1));
506 flowSampleCollectorSet.setExternalIds(ImmutableMap.of("I <3", "ovs"));
507 flowSampleCollectorSet.setBridge(testBridgeUuid);
509 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
510 .add(op.insert(flowSampleCollectorSet.getSchema())
511 .value(flowSampleCollectorSet.getIdColumn())
512 .value(flowSampleCollectorSet.getExternalIdsColumn())
513 .value(flowSampleCollectorSet.getBridgeColumn()))
514 .add(op.comment("FlowSampleCollectorSet: Inserting"));
516 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
517 "FlowSampleCollectorSet: Insert results");
518 testFlowSampleCollectorSetUuid = operationResults.get(0).getUuid();
519 assertNotNull(ASSERT_TRANS_UUID, testFlowSampleCollectorSetUuid);
521 // Verify that the local cache was updated with the remote changes
522 Row flowSampleCollectorSetRow = getTableCache().get(flowSampleCollectorSet.getSchema().getName())
523 .get(testFlowSampleCollectorSetUuid);
524 FlowSampleCollectorSet monitoredflowSampleCollectorSet =
525 getClient().getTypedRowWrapper(FlowSampleCollectorSet.class, flowSampleCollectorSetRow);
526 assertEquals(flowSampleCollectorSet.getIdColumn().getData(),
527 monitoredflowSampleCollectorSet.getIdColumn().getData());
530 public void flowSampleCollectorSetDelete () throws ExecutionException, InterruptedException {
531 assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) >= 0);
533 FlowSampleCollectorSet flowSampleCollectorSet = getClient().getTypedRowWrapper(FlowSampleCollectorSet.class, null);
534 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
535 .add(op.delete(flowSampleCollectorSet.getSchema())
536 .where(flowSampleCollectorSet.getUuidColumn().getSchema().opEqual(testFlowSampleCollectorSetUuid))
538 .add(op.comment("FlowSampleCollectorSet: Deleting " + testFlowSampleCollectorSetUuid))
539 .add(op.commit(true));
541 executeTransaction(transactionBuilder, "Bridge delete operation results");
545 public void testFlowSampleCollectorSet () throws ExecutionException, InterruptedException {
546 // Don't run this test if the table is not supported
547 assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) >= 0);
549 testBridgeUuid = bridgeInsert();
550 flowSampleCollectorSetInsert();
551 flowSampleCollectorSetDelete();
552 bridgeDelete(testBridgeUuid);
556 public void testFlowTableTableNotSupported () {
557 // Don't run this test if the table is not supported
558 assumeTrue(schemaVersion.compareTo(flowTableFromVersion) < 0);
560 boolean isExceptionRaised = false;
562 FlowTable flowTable = getClient().createTypedRowWrapper(FlowTable.class);
563 } catch (SchemaVersionMismatchException e) {
564 isExceptionRaised = true;
566 assertTrue(isExceptionRaised);
569 public void flowTableInsert () throws ExecutionException, InterruptedException {
570 // Don't run this test if the table is not supported
571 assumeTrue(schemaVersion.compareTo(flowTableFromVersion) >= 0);
573 String flowTableUuidStr = "testFlowTable";
574 String tableName = "flow_table_row_name";
575 String overflowPolicy = "evict";
576 String groups = "group name";
577 String prefixes = "wildcarding prefixes";
578 Long flowLimit = 50000L;
579 Map<Long, UUID> flowTableBrRef = new HashMap<>();
580 flowTableBrRef.put(1L, new UUID(flowTableUuidStr));
581 FlowTable flowTable = getClient().createTypedRowWrapper(FlowTable.class);
582 flowTable.setName(ImmutableSet.of(tableName));
583 flowTable.setOverflowPolicy(ImmutableSet.of(overflowPolicy));
584 flowTable.setGroups(ImmutableSet.of(groups));
585 if (schemaVersion.compareTo(prefixesAddedVersion) >= 0) {
586 flowTable.setPrefixes(ImmutableSet.of(prefixes));
588 if (schemaVersion.compareTo(externalIdAddedVerson) >= 0) {
589 flowTable.setExternalIds(ImmutableMap.of("I <3", "OVS"));
591 flowTable.setFlowLimit(ImmutableSet.of(flowLimit));
592 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
594 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
595 .add(op.insert(flowTable)
596 .withId(flowTableUuidStr))
597 .add(op.comment("Flowtable: Inserting " + flowTableUuidStr))
598 .add(op.mutate(bridge.getSchema())
599 .addMutation(bridge.getFlowTablesColumn().getSchema(), Mutator.INSERT, flowTableBrRef)
600 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
602 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
604 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
605 "FlowTable: Insert and Mutate results");
606 testFlowTableUuid = operationResults.get(0).getUuid();
607 assertNotNull(ASSERT_TRANS_UUID, testFlowTableUuid);
609 // Verify that the local cache was updated with the remote changes
610 Row flowTableRow = getTableCache().get(flowTable.getSchema().getName()).get(testFlowTableUuid);
611 FlowTable monitoredFlowTable = getClient().getTypedRowWrapper(FlowTable.class, flowTableRow);
612 assertEquals(flowTable.getNameColumn().getData(), monitoredFlowTable.getNameColumn().getData());
615 public void flowTableDelete () throws ExecutionException, InterruptedException {
616 // Don't run this test if the table is not supported
617 assumeTrue(schemaVersion.compareTo(flowTableFromVersion) >= 0);
619 FlowTable flowTable = getClient().getTypedRowWrapper(FlowTable.class, null);
620 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
622 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
623 .add(op.delete(flowTable.getSchema())
624 .where(flowTable.getUuidColumn().getSchema().opEqual(testFlowTableUuid))
626 .add(op.comment("FlowTable: Deleting " + testFlowTableUuid))
627 .add(op.mutate(bridge.getSchema())
628 .addMutation(bridge.getFlowTablesColumn().getSchema(), Mutator.DELETE,
629 Maps.newHashMap(ImmutableMap.of(1L, testFlowTableUuid))))
630 .add(op.comment("Bridge: Mutating " + testFlowTableUuid))
631 .add(op.commit(true));
633 executeTransaction(transactionBuilder, "FlowTable delete operation results");
637 public void setTestFlowTableSet () throws ExecutionException, InterruptedException {
638 // Don't run this test if the table is not supported
639 assumeTrue(schemaVersion.compareTo(flowTableFromVersion) >= 0);
641 UUID testBridgeUuid = bridgeInsert();
644 bridgeDelete(testBridgeUuid);
648 public void testIpfixTableNotSupported () {
649 // Don't run this test if the table is not supported
650 assumeTrue(schemaVersion.compareTo(ipfixFromVersion) < 0);
652 boolean isExceptionRaised = false;
654 IPFIX ipfix = getClient().createTypedRowWrapper(IPFIX.class);
655 } catch (SchemaVersionMismatchException e) {
656 isExceptionRaised = true;
658 assertTrue(isExceptionRaised);
661 public void ipfixInsert () throws ExecutionException, InterruptedException {
662 // Don't run this test if the table is not supported
663 assumeTrue(schemaVersion.compareTo(ipfixFromVersion) >= 0);
665 String ipfixUuidStr = "testIpfix";
666 String ipfixTarget = "172.16.20.1:4739";
667 Long obsDomainId = 112L;
668 Long obsPointId = 358L;
669 Long cacheMax = 132L;
670 Long cacheTimeout = 134L;
671 Long sampling = 558L;
673 IPFIX ipfix = getClient().createTypedRowWrapper(IPFIX.class);
674 ipfix.setTargets(ImmutableSet.of(ipfixTarget));
675 ipfix.setObsDomainId(ImmutableSet.of(obsDomainId));
676 ipfix.setObsPointId(ImmutableSet.of(obsPointId));
677 // Only set these rows if the schema version supports it
678 if (schemaVersion.compareTo(ipfixCacheFromVersion) >= 0) {
679 ipfix.setCacheMaxFlows(ImmutableSet.of(cacheMax));
680 ipfix.setCacheActiveTimeout(ImmutableSet.of(cacheTimeout));
682 ipfix.setSampling(ImmutableSet.of(sampling));
683 ipfix.setExternalIds(ImmutableMap.of("I <3", "ovs"));
684 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
686 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
687 .add(op.insert(ipfix)
688 .withId(ipfixUuidStr))
689 .add(op.comment("IPFIX: Inserting " + ipfixUuidStr))
690 .add(op.mutate(bridge.getSchema())
691 .addMutation(bridge.getIpfixColumn().getSchema(), Mutator.INSERT,
692 Sets.newHashSet(new UUID(ipfixUuidStr)))
693 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
695 .add(op.comment("Bridge: Mutating " + ipfixUuidStr));
697 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
698 "IPFIX: Insert and Mutate results");
699 testIpfixUuid = operationResults.get(0).getUuid();
700 assertNotNull(ASSERT_TRANS_UUID, testIpfixUuid);
702 // Verify that the local cache was updated with the remote changes
703 Row ipfixRow = getTableCache().get(ipfix.getSchema().getName()).get(testIpfixUuid);
704 IPFIX monitoredIPFIX = getClient().getTypedRowWrapper(IPFIX.class, ipfixRow);
705 assertEquals(testIpfixUuid, monitoredIPFIX.getUuidColumn().getData());
708 public void ipfixDelete () throws ExecutionException, InterruptedException {
709 // Don't run this test if the table is not supported
710 assumeTrue(schemaVersion.compareTo(ipfixFromVersion) >= 0);
712 FlowTable flowTable = getClient().getTypedRowWrapper(FlowTable.class, null);
713 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
715 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
716 .add(op.delete(flowTable.getSchema())
717 .where(flowTable.getUuidColumn().getSchema().opEqual(testIpfixUuid))
719 .add(op.comment("IPFIX: Deleting " + testIpfixUuid))
720 .add(op.mutate(bridge.getSchema()) // Delete a controller column in the Bridge table
721 .addMutation(bridge.getMirrorsColumn().getSchema(), Mutator.DELETE,
722 Sets.newHashSet(testIpfixUuid)))
723 .add(op.comment("Bridge: Mutating " + testIpfixUuid))
724 .add(op.commit(true));
726 executeTransaction(transactionBuilder, "IPFIX delete operation results");
730 public void testIpfix () throws ExecutionException, InterruptedException {
731 // Don't run this test if the table is not supported
732 assumeTrue(schemaVersion.compareTo(ipfixFromVersion) >= 0);
734 testBridgeUuid = bridgeInsert();
737 bridgeDelete(testBridgeUuid);
740 public void managerInsert() throws ExecutionException, InterruptedException {
741 ImmutableMap<String, String> externalIds = ImmutableMap.of("slaveof", "themaster");
742 UUID openVSwitchRowUuid = getOpenVSwitchTableUuid(getClient(), getTableCache());
743 OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
744 Manager manager = getClient().createTypedRowWrapper(Manager.class);
745 manager.setInactivityProbe(Sets.newHashSet(8192L));
746 manager.setMaxBackoff(Sets.newHashSet(4094L));
747 manager.setTarget(Sets.newHashSet("172.16.50.50:6640"));
748 manager.setExternalIds(externalIds);
750 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
751 .add(op.insert(manager.getSchema())
752 .withId(TEST_MANAGER_UUID_STR)
753 .value(manager.getTargetColumn())
754 .value(manager.getInactivityProbeColumn())
755 .value(manager.getMaxBackoffColumn())
756 .value(manager.getExternalIdsColumn()))
757 .add(op.comment("Manager: Inserting Slave Manager " + TEST_MANAGER_UUID_STR))
758 .add(op.mutate(openVSwitch.getSchema())
759 .addMutation(openVSwitch.getManagerOptionsColumn().getSchema(), Mutator.INSERT,
760 Sets.newHashSet(new UUID(TEST_MANAGER_UUID_STR)))
761 .where(openVSwitch.getUuidColumn().getSchema().opEqual(openVSwitchRowUuid))
763 .add(op.comment("Open_vSwitch: Mutating " + TEST_MANAGER_UUID_STR));
765 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
766 "Manager: Insert & Mutate operation results");
767 testManagerUuid = operationResults.get(0).getUuid();
768 assertNotNull(ASSERT_TRANS_UUID, testManagerUuid);
770 // Verify that the local cache was updated with the remote changes
771 Row managerRow = getTableCache().get(manager.getSchema().getName()).get(testManagerUuid);
772 Manager monitoredManager = getClient().getTypedRowWrapper(Manager.class, managerRow);
773 assertEquals(externalIds, monitoredManager.getExternalIdsColumn().getData());
776 public void managerDelete () throws ExecutionException, InterruptedException {
777 Manager manager = getClient().getTypedRowWrapper(Manager.class, null);
778 OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
780 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
781 .add(op.delete(manager.getSchema())
782 .where(manager.getUuidColumn().getSchema().opEqual(testManagerUuid))
784 .add(op.comment("Manager: Deleting " + TEST_MANAGER_UUID_STR))
785 .add(op.mutate(openVSwitch.getSchema())
786 .addMutation(openVSwitch.getManagerOptionsColumn().getSchema(), Mutator.DELETE,
787 Sets.newHashSet(testManagerUuid)))
788 .add(op.comment("Open_vSwitch: Mutating " + TEST_MANAGER_UUID_STR + " " + testManagerUuid))
789 .add(op.commit(true));
791 executeTransaction(transactionBuilder, "Manager: Delete operation results");
795 public void testManager () throws ExecutionException, InterruptedException {
800 public void mirrorInsert () throws ExecutionException, InterruptedException {
801 String mirrorUuidStr = "testMirror";
802 String mirrorName = "my_name_is_mirror";
803 Long outputVid = 1024L;
804 Long selectVid = Long.valueOf(2048);
806 Mirror mirror = getClient().createTypedRowWrapper(Mirror.class);
807 mirror.setName(ImmutableSet.of(mirrorName));
808 mirror.setExternalIds(ImmutableMap.of("overlays", "ftw"));
809 mirror.setOutputVlan(ImmutableSet.of(outputVid));
810 mirror.setSelectVlan(ImmutableSet.of(selectVid));
811 mirror.setExternalIds(ImmutableMap.of("reading", "urmail"));
812 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
814 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
815 .add(op.insert(mirror.getSchema())
816 .withId(mirrorUuidStr)
817 .value(mirror.getNameColumn())
818 .value(mirror.getExternalIdsColumn()))
819 .add(op.comment("Mirror: Inserting " + mirrorUuidStr))
820 .add(op.mutate(bridge.getSchema())
821 .addMutation(bridge.getMirrorsColumn().getSchema(), Mutator.INSERT,
822 Sets.newHashSet(new UUID(mirrorUuidStr)))
823 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
825 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
827 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
828 "Insert and Mutate operation results for Mirror");
829 testMirrorUuid = operationResults.get(0).getUuid();
830 assertNotNull(ASSERT_TRANS_UUID, testMirrorUuid);
832 // Verify that the local cache was updated with the remote changes
833 Row mirrorRow = getTableCache().get(mirror.getSchema().getName()).get(testMirrorUuid);
834 Mirror monitoredMirror = getClient().getTypedRowWrapper(Mirror.class, mirrorRow);
835 assertEquals(mirror.getExternalIdsColumn().getData(), monitoredMirror.getExternalIdsColumn().getData());
838 private void mirrorDelete () throws ExecutionException, InterruptedException {
839 Mirror mirror = getClient().getTypedRowWrapper(Mirror.class, null);
840 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
841 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
843 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
844 .add(op.delete(mirror.getSchema())
845 .where(mirror.getUuidColumn().getSchema().opEqual(testMirrorUuid))
847 .add(op.comment("Mirror: Deleting " + testMirrorUuid))
848 .add(op.mutate(bridge.getSchema()) // Delete a controller column in the Bridge table
849 .addMutation(bridge.getMirrorsColumn().getSchema(), Mutator.DELETE,
850 Sets.newHashSet(testMirrorUuid)))
851 .add(op.comment("Bridge: Mutating " + testMirrorUuid))
852 .add(op.commit(true));
854 executeTransaction(transactionBuilder, "Mirror: Delete operation results");
858 public void testMirror () throws ExecutionException, InterruptedException {
859 testBridgeUuid = bridgeInsert();
862 bridgeDelete(testBridgeUuid);
865 public void netFlowInsert () throws ExecutionException, InterruptedException {
866 String netFlowUuidStr = "testNetFlow";
867 String netFlowTargets = "172.16.20.200:6343";
868 Long engineType = 128L;
870 Long activityTimeout = 1L;
871 NetFlow netFlow = getClient().createTypedRowWrapper(NetFlow.class);
872 netFlow.setTargets(ImmutableSet.of(netFlowTargets));
873 netFlow.setEngineType(ImmutableSet.of(engineType));
874 netFlow.setEngineId(ImmutableSet.of(engineID));
875 netFlow.setActivityTimeout(ImmutableSet.of(activityTimeout));
876 netFlow.setExternalIds(ImmutableMap.of("big", "baby"));
877 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
878 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
879 .add(op.insert(netFlow.getSchema())
880 .withId(netFlowUuidStr)
881 .value(netFlow.getTargetsColumn())
882 .value(netFlow.getEngineTypeColumn())
883 .value(netFlow.getEngineIdColumn())
884 .value(netFlow.getActiveTimeoutColumn())
885 .value(netFlow.getExternalIdsColumn()))
886 .add(op.comment("Mirror: Inserting " + netFlowUuidStr))
887 .add(op.mutate(bridge.getSchema())
888 .addMutation(bridge.getNetflowColumn().getSchema(), Mutator.INSERT,
889 Sets.newHashSet(new UUID(netFlowUuidStr)))
890 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
892 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
894 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
895 "Insert and Mutate operation results for NetFlow");
896 testNetFlowUuid = operationResults.get(0).getUuid();
897 assertNotNull(ASSERT_TRANS_UUID, testNetFlowUuid);
899 // Verify that the local cache was updated with the remote changes
900 Row netFlowRow = getTableCache().get(netFlow.getSchema().getName()).get(testNetFlowUuid);
901 Mirror monitoredNetFlow = getClient().getTypedRowWrapper(Mirror.class, netFlowRow);
902 assertEquals(netFlow.getExternalIdsColumn().getData(), monitoredNetFlow.getExternalIdsColumn().getData());
905 private void netFlowDelete () throws ExecutionException, InterruptedException {
906 NetFlow netFlow = getClient().getTypedRowWrapper(NetFlow.class, null);
907 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
908 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
910 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
911 .add(op.delete(netFlow.getSchema())
912 .where(netFlow.getUuidColumn().getSchema().opEqual(testNetFlowUuid))
914 .add(op.comment("NetFlow: Deleting " + testNetFlowUuid))
915 .add(op.mutate(bridge.getSchema()) // Delete a controller column in the Bridge table
916 .addMutation(bridge.getNetflowColumn().getSchema(), Mutator.DELETE,
917 Sets.newHashSet(testNetFlowUuid)))
918 .add(op.comment("Bridge: Mutating " + testNetFlowUuid))
919 .add(op.commit(true));
921 executeTransaction(transactionBuilder, "NetFlow: Delete operation results");
925 public void testNetFlow () throws ExecutionException, InterruptedException {
926 testBridgeUuid = bridgeInsert();
929 bridgeDelete(testBridgeUuid);
932 public void portAndInterfaceInsert () throws ExecutionException, InterruptedException {
933 String portUuidStr = "testPort";
934 String intfUuidStr = "testIntf";
935 String tunnelEncap = "vxlan";
936 Port port = getClient().createTypedRowWrapper(Port.class);
937 port.setName("testPort");
938 port.setTag(ImmutableSet.of(1L));
939 port.setMac(ImmutableSet.of("00:00:00:00:00:01"));
940 port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
942 Interface intf = getClient().createTypedRowWrapper(Interface.class);
943 intf.setName(port.getNameColumn().getData());
944 intf.setType(tunnelEncap);
945 intf.setExternalIds(ImmutableMap.of("vm-id", "12345abcedf78910"));
946 // For per Flow TEPs use remote_ip=flow
947 // For per Port TEPs use remote_ip=x.x.x.x (ipv4)
948 intf.setOptions(ImmutableMap.of("local_ip", "172.16.24.145",
951 "dst_port", "8472"));
953 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
954 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
955 .add(op.insert(port.getSchema())
957 .value(port.getNameColumn())
958 .value(port.getMacColumn()))
959 .add(op.comment("Port: Inserting " + portUuidStr))
960 .add(op.insert(intf.getSchema())
962 .value(intf.getNameColumn()))
963 .add(op.comment("Interface: Inserting " + intfUuidStr))
964 .add(op.update(port.getSchema())
965 .set(port.getTagColumn())
966 .set(port.getMacColumn())
967 .set(port.getInterfacesColumn())
968 .where(port.getNameColumn().getSchema().opEqual(port.getName()))
970 .add(op.comment("Port: Updating " + portUuidStr))
971 .add(op.update(intf.getSchema())
972 .set(intf.getTypeColumn())
973 .set(intf.getExternalIdsColumn())
974 .set(intf.getOptionsColumn())
975 .where(intf.getNameColumn().getSchema().opEqual(intf.getName()))
977 .add(op.comment("Interface: Updating " + intfUuidStr))
978 .add(op.mutate(bridge.getSchema())
979 .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT, Sets.newHashSet(new UUID(portUuidStr)))
980 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
982 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
984 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
985 "Insert and Mutate operation results for Port and Interface");
986 testPortUuid = operationResults.get(0).getUuid();
987 assertNotNull(ASSERT_TRANS_UUID, testPortUuid);
988 testInterfaceUuid = operationResults.get(2).getUuid();
989 assertNotNull(ASSERT_TRANS_UUID, testInterfaceUuid);
991 // Verify that the local cache was updated with the remote changes
992 Row portRow = getTableCache().get(port.getSchema().getName()).get(testPortUuid);
993 Port monitoredPort = getClient().getTypedRowWrapper(Port.class, portRow);
994 assertEquals(port.getNameColumn().getData(), monitoredPort.getNameColumn().getData());
996 Row interfaceRow = getTableCache().get(intf.getSchema().getName()).get(testInterfaceUuid);
997 Interface monitoredInterface = getClient().getTypedRowWrapper(Interface.class, interfaceRow);
998 assertEquals(intf.getNameColumn().getData(), monitoredInterface.getNameColumn().getData());
1001 private void portAndInterfaceDelete () throws ExecutionException, InterruptedException {
1002 Port port = getClient().getTypedRowWrapper(Port.class, null);
1003 Interface intf = getClient().getTypedRowWrapper(Interface.class, null);
1004 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1005 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1007 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1008 .add(op.delete(port.getSchema())
1009 .where(port.getUuidColumn().getSchema().opEqual(testPortUuid))
1011 .add(op.comment("Port: Deleting " + testPortUuid))
1012 .add(op.delete(intf.getSchema())
1013 .where(intf.getUuidColumn().getSchema().opEqual(testInterfaceUuid))
1015 .add(op.comment("Interface: Deleting " + testInterfaceUuid))
1016 .add(op.mutate(bridge.getSchema()) // Delete a port column in the Bridge table
1017 .addMutation(bridge.getPortsColumn().getSchema(), Mutator.DELETE,
1018 Sets.newHashSet(testPortUuid)))
1019 .add(op.comment("Bridge: Mutating " + testPortUuid))
1020 .add(op.commit(true));
1022 executeTransaction(transactionBuilder, "Port and Interface: Delete operation results");
1026 public void testPortAndInterface () throws ExecutionException, InterruptedException {
1027 testBridgeUuid = bridgeInsert();
1028 portAndInterfaceInsert();
1029 portAndInterfaceDelete();
1030 bridgeDelete(testBridgeUuid);
1033 public void qosInsert() throws ExecutionException, InterruptedException {
1034 String portUuidStr = "testQosPortUuid";
1035 String intfUuidStr = "testQosIntfUuid";
1036 String qosUuidStr = "testQosUuid";
1037 String qosPort = "testQosPort";
1039 Port port = getClient().createTypedRowWrapper(Port.class);
1040 port.setName(qosPort);
1041 port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
1042 port.setQos(ImmutableSet.of(new UUID(qosUuidStr)));
1043 port.setOtherConfig(ImmutableMap.of("m0r3", "c0ff33"));
1045 Interface intf = getClient().createTypedRowWrapper(Interface.class);
1046 intf.setName(port.getNameColumn().getData());
1047 intf.setOtherConfig(ImmutableMap.of("proto", "duction"));
1048 intf.setExternalIds(ImmutableMap.of("stringly", "typed"));
1050 Qos qos = getClient().createTypedRowWrapper(Qos.class);
1051 qos.setOtherConfig(ImmutableMap.of("mmm", "kay"));
1052 qos.setType(ImmutableSet.of("404"));
1054 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1056 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1057 .add(op.insert(port.getSchema())
1058 .withId(portUuidStr)
1059 .value(port.getNameColumn()))
1060 .add(op.comment("Port: Inserting " + portUuidStr))
1061 .add(op.insert(intf.getSchema())
1062 .withId(intfUuidStr)
1063 .value(intf.getExternalIdsColumn())
1064 .value(intf.getNameColumn())
1065 .value(intf.getOtherConfigColumn()))
1066 .add(op.comment("Interface: Inserting " + intfUuidStr))
1067 .add(op.insert(qos.getSchema())
1069 .value(qos.getTypeColumn())
1070 .value(qos.getOtherConfigColumn()))
1071 .add(op.comment("QOS: Inserting " + qosUuidStr))
1072 .add(op.update(port.getSchema())
1073 .set(port.getOtherConfigColumn())
1074 .set(port.getInterfacesColumn())
1075 .set(port.getQosColumn())
1076 .where(port.getNameColumn().getSchema().opEqual(port.getName()))
1078 .add(op.comment("Interface: Updating " + intfUuidStr))
1079 .add(op.mutate(bridge.getSchema())
1080 .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT,
1081 Sets.newHashSet(new UUID(portUuidStr)))
1082 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
1084 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
1086 int insertPortOperationIndex = 0;
1087 int insertInterfaceOperationIndex = 2;
1088 int insertQosOperationIndex = 4;
1089 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1090 "Insert and Mutate operation results for Port and Interface");
1091 testPortUuid = operationResults.get(insertPortOperationIndex).getUuid();
1092 assertNotNull(ASSERT_TRANS_UUID, testPortUuid);
1093 testInterfaceUuid = operationResults.get(insertInterfaceOperationIndex).getUuid();
1094 assertNotNull(ASSERT_TRANS_UUID, testInterfaceUuid);
1095 testQosUuid = operationResults.get(insertQosOperationIndex).getUuid();
1096 assertNotNull(ASSERT_TRANS_UUID, testQosUuid);
1098 // Verify that the local cache was updated with the remote changes
1099 Row portRow = getTableCache().get(port.getSchema().getName()).get(testPortUuid);
1100 Port monitoredPort = getClient().getTypedRowWrapper(Port.class, portRow);
1101 assertEquals(port.getNameColumn().getData(), monitoredPort.getNameColumn().getData());
1103 Row interfaceRow = getTableCache().get(intf.getSchema().getName()).get(testInterfaceUuid);
1104 Interface monitoredInterface = getClient().getTypedRowWrapper(Interface.class, interfaceRow);
1105 assertEquals(intf.getNameColumn().getData(), monitoredInterface.getNameColumn().getData());
1107 Row qosRow = getTableCache().get(qos.getSchema().getName()).get(testQosUuid);
1108 Qos monitoredQos = getClient().getTypedRowWrapper(Qos.class, qosRow);
1109 assertEquals(qos.getTypeColumn().getData().toArray()[0], monitoredQos.getTypeColumn().getData());
1112 private void qosDelete () throws ExecutionException, InterruptedException {
1113 Port port = getClient().getTypedRowWrapper(Port.class, null);
1114 Interface intf = getClient().getTypedRowWrapper(Interface.class, null);
1115 Qos qos = getClient().getTypedRowWrapper(Qos.class, null);
1116 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1117 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1119 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1120 .add(op.delete(port.getSchema())
1121 .where(port.getUuidColumn().getSchema().opEqual(testPortUuid))
1123 .add(op.comment("Port: Deleting " + testPortUuid))
1124 .add(op.delete(intf.getSchema())
1125 .where(intf.getUuidColumn().getSchema().opEqual(testInterfaceUuid))
1127 .add(op.comment("Interface: Deleting " + testInterfaceUuid))
1128 .add(op.delete(qos.getSchema())
1129 .where(qos.getUuidColumn().getSchema().opEqual(testQosUuid))
1131 .add(op.comment("Qos: Deleting " + testQosUuid))
1132 .add(op.mutate(bridge.getSchema()) // Delete a port column in the Bridge table
1133 .addMutation(bridge.getPortsColumn().getSchema(), Mutator.DELETE,
1134 Sets.newHashSet(testPortUuid)))
1135 .add(op.comment("Bridge: Mutating " + testPortUuid))
1136 .add(op.mutate(port.getSchema()) // Delete a qos column in the Port table
1137 .addMutation(port.getQosColumn().getSchema(), Mutator.DELETE,
1138 Sets.newHashSet(testQosUuid)))
1139 .add(op.comment("Port: Mutating " + testPortUuid))
1140 .add(op.commit(true));
1142 executeTransaction(transactionBuilder, "Qos, Port and Interface: Delete operation results");
1146 public void testQos () throws ExecutionException, InterruptedException {
1147 testBridgeUuid = bridgeInsert();
1150 bridgeDelete(testBridgeUuid);
1153 public void queueInsert() throws InterruptedException, ExecutionException {
1155 * This is an arbitrary String that is a placeholder for
1156 * the future UUID generated by the OVSDB Server in the
1157 * future transaction. While it is possible to generate
1158 * ones own UUID for the transaction it is not recommended
1159 * since it wouldn't add any conceivable value.
1161 String queueUuidStr = "queueUuidStr";
1162 Long dscpVal = Long.valueOf(4);
1163 Queue queue = getClient().createTypedRowWrapper(Queue.class);
1164 // Example of explicit ImmutableSet/Map Attribute declaration
1165 ImmutableSet<Long> dscp = ImmutableSet.of(dscpVal);
1166 ImmutableMap<String, String> externalIds = ImmutableMap.of("little", "coat");
1167 // Example of condensing the attributes bindings in one line
1168 queue.setOtherConfig(ImmutableMap.of("war", "onfun"));
1169 // Bind the Attributes to the transaction. These values end up in columns.
1170 queue.setExternalIds(externalIds);
1171 queue.setDscp(dscp);
1172 // Get the parent Qos table row UUID to insert the queue.
1173 Qos qos = getClient().getTypedRowWrapper(Qos.class, null);
1174 // Queue key that is mapped to the queue record/value/ofp_action_enqueue
1176 // Reference the Port row to insert the Queue with UID or Port name
1177 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1178 .add(op.insert(queue.getSchema())
1179 .withId(queueUuidStr)
1180 .value(queue.getDscpColumn())
1181 .value(queue.getExternalIdsColumn())
1182 .value(queue.getOtherConfigColumn()))
1183 .add(op.comment("Queue: Inserting " + queueUuidStr))
1184 .add(op.mutate(qos.getSchema())
1185 .addMutation(qos.getQueuesColumn().getSchema(), Mutator.INSERT,
1186 ImmutableMap.of(queueKey, new UUID(queueUuidStr)))
1187 .where(qos.getUuidColumn().getSchema().opEqual(testQosUuid))
1189 .add(op.comment("Qos: Mutating " + testQosUuid));
1191 // The transaction index for the Queue insert is used to store the Queue UUID
1192 int insertQueueOperationIndex = 0;
1193 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1194 "Insert and Mutate operation results for Queue");
1195 testQueueUuid = operationResults.get(insertQueueOperationIndex).getUuid();
1196 assertNotNull(ASSERT_TRANS_UUID, testQueueUuid);
1198 // Verify that the local cache was updated with the remote changes
1199 Row queueRow = getTableCache().get(queue.getSchema().getName()).get(testQueueUuid);
1200 Queue monitoredQueue = getClient().getTypedRowWrapper(Queue.class, queueRow);
1201 assertEquals(queue.getExternalIdsColumn().getData(), monitoredQueue.getExternalIdsColumn().getData());
1204 private void queueDelete () throws ExecutionException, InterruptedException {
1205 Queue queue = getClient().getTypedRowWrapper(Queue.class, null);
1206 Qos qos = getClient().getTypedRowWrapper(Qos.class, null);
1207 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1209 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1210 .add(op.delete(queue.getSchema())
1211 .where(queue.getUuidColumn().getSchema().opEqual(testQueueUuid))
1213 .add(op.comment("Queue: Deleting " + testQueueUuid))
1214 .add(op.mutate(qos.getSchema()) // Delete a queue column in the Qos table
1215 .addMutation(qos.getQueuesColumn().getSchema(), Mutator.DELETE,
1216 Maps.newHashMap(ImmutableMap.of(0L,testQueueUuid))))
1217 .add(op.comment("Queue: Mutating " + testQueueUuid))
1218 .add(op.commit(true));
1220 executeTransaction(transactionBuilder, "Queue: Delete operation results");
1224 public void testQueue () throws ExecutionException, InterruptedException {
1225 testBridgeUuid = bridgeInsert();
1230 bridgeDelete(testBridgeUuid);
1233 public void sFlowInsert () throws ExecutionException, InterruptedException {
1234 String sFlowUuidStr = "testSFlow";
1235 String sFlowTarget = "172.16.20.200:6343";
1237 Long obsPointId = 358L;
1239 String agent = "172.16.20.210";
1240 Long sampling = 64L;
1241 SFlow sFlow = getClient().createTypedRowWrapper(SFlow.class);
1242 sFlow.setTargets(ImmutableSet.of(sFlowTarget));
1243 sFlow.setHeader(ImmutableSet.of(header));
1244 sFlow.setPolling(ImmutableSet.of(obsPointId));
1245 sFlow.setPolling(ImmutableSet.of(polling));
1246 sFlow.setAgent(ImmutableSet.of(agent));
1247 sFlow.setSampling(ImmutableSet.of(sampling));
1248 sFlow.setExternalIds(ImmutableMap.of("kit", "tah"));
1249 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1250 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1251 .add(op.insert(sFlow.getSchema())
1252 .withId(sFlowUuidStr)
1253 .value(sFlow.getTargetsColumn())
1254 .value(sFlow.getHeaderColumn())
1255 .value(sFlow.getPollingColumn())
1256 .value(sFlow.getAgentColumn())
1257 .value(sFlow.getSamplingColumn())
1258 .value(sFlow.getExternalIdsColumn()))
1259 .add(op.comment("sFlow: Inserting " + sFlowUuidStr))
1260 .add(op.mutate(bridge.getSchema())
1261 .addMutation(bridge.getSflowColumn().getSchema(), Mutator.INSERT,
1262 Sets.newHashSet(new UUID(sFlowUuidStr)))
1263 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
1265 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
1266 int insertSFlowOperationIndex = 0;
1267 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1268 "Insert and Mutate operation results for sFlow");
1269 testSFlowUuid = operationResults.get(insertSFlowOperationIndex).getUuid();
1270 assertNotNull(ASSERT_TRANS_UUID, testSFlowUuid);
1272 // Verify that the local cache was updated with the remote changes
1273 Row sFlowRow = getTableCache().get(sFlow.getSchema().getName()).get(testSFlowUuid);
1274 Queue monitoredSFlow = getClient().getTypedRowWrapper(Queue.class, sFlowRow);
1275 assertEquals(sFlow.getExternalIdsColumn().getData(), monitoredSFlow.getExternalIdsColumn().getData());
1278 private void sFlowDelete () throws ExecutionException, InterruptedException {
1279 SFlow sFlow = getClient().getTypedRowWrapper(SFlow.class, null);
1280 Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1281 DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1283 TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1284 .add(op.delete(sFlow.getSchema())
1285 .where(sFlow.getUuidColumn().getSchema().opEqual(testSFlowUuid))
1287 .add(op.comment("SFlow: Deleting " + testSFlowUuid))
1288 .add(op.mutate(bridge.getSchema()) // Delete an sflow column in the Bridge table
1289 .addMutation(bridge.getSflowColumn().getSchema(), Mutator.DELETE,
1290 Sets.newHashSet(testSFlowUuid)))
1291 .add(op.comment("Bridge: Mutating " + testSFlowUuid))
1292 .add(op.commit(true));
1294 executeTransaction(transactionBuilder, "Queue: Delete operation results");
1298 public void testSFlow () throws ExecutionException, InterruptedException {
1299 testBridgeUuid = bridgeInsert();
1302 bridgeDelete(testBridgeUuid);
1305 public void sslInsert () throws ExecutionException, InterruptedException {
1307 String sslUuidStr = "sslUuidName";
1308 String caCert = "PARC";
1309 String certificate = "01101110 01100101 01110010 01100100";
1310 String privateKey = "SSL_Table_Test_Secret";
1311 ImmutableMap<String, String> externalIds = ImmutableMap.of("roomba", "powered");
1313 SSL ssl = getClient().createTypedRowWrapper(SSL.class);
1314 ssl.setCaCert(caCert);
1315 ssl.setCertificate(certificate);
1316 ssl.setPrivateKey(privateKey);
1317 ssl.setExternalIds(externalIds);
1318 // Get the parent OVS table UUID in it's single row
1319 UUID openVSwitchRowUuid = getOpenVSwitchTableUuid(getClient(), getTableCache());
1320 OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
1321 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1322 .add(op.insert(ssl.getSchema())
1324 .value(ssl.getCertificateColumn())
1325 .value(ssl.getPrivateKeyColumn())
1326 .value(ssl.getCaCertColumn())
1327 .value(ssl.getExternalIdsColumn()))
1328 .add(op.comment("SSL: Inserting " + sslUuidStr))
1329 .add(op.mutate(openVSwitch.getSchema())
1330 .addMutation(openVSwitch.getSslColumn().getSchema(), Mutator.INSERT,
1331 Sets.newHashSet(new UUID(sslUuidStr)))
1332 .where(openVSwitch.getUuidColumn().getSchema().opEqual(openVSwitchRowUuid))
1334 .add(op.comment("Open_vSwitch: Mutating " + sslUuidStr));
1336 // The transaction index for the SSL insert is used to store the SSL UUID
1337 int insertSslOperationIndex = 0;
1338 List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1339 "Insert and Mutate operation results for SSL");
1340 testSslUuid = operationResults.get(insertSslOperationIndex).getUuid();
1341 assertNotNull(ASSERT_TRANS_UUID, testSslUuid);
1343 // Verify that the local cache was updated with the remote changes
1344 Row sslRow = getTableCache().get(ssl.getSchema().getName()).get(testSslUuid);
1345 SSL monitoredSsl = getClient().getTypedRowWrapper(SSL.class, sslRow);
1346 assertEquals(ssl.getExternalIdsColumn().getData(), monitoredSsl.getExternalIdsColumn().getData());
1349 public void sslDelete () throws ExecutionException, InterruptedException {
1350 SSL ssl = getClient().getTypedRowWrapper(SSL.class, null);
1351 OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
1353 TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1354 .add(op.delete(ssl.getSchema())
1355 .where(ssl.getUuidColumn().getSchema().opEqual(testSslUuid))
1357 .add(op.comment("SSL: Deleting " + testSslUuid))
1358 .add(op.mutate(openVSwitch.getSchema())
1359 .addMutation(openVSwitch.getSslColumn().getSchema(), Mutator.DELETE,
1360 Sets.newHashSet(testSslUuid)))
1361 .add(op.comment("Open_vSwitch: Mutating " + testSslUuid))
1362 .add(op.commit(true));
1364 executeTransaction(transactionBuilder, "SSL delete operation results");
1368 public void testSsl () throws ExecutionException, InterruptedException {
1374 public void testTyperUtilsSpecialMethodsToString () {
1375 Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1376 assertNotNull(bridge);
1377 bridge.setName(TEST_BRIDGE_NAME);
1378 bridge.setStatus(ImmutableMap.of("key", "value"));
1379 bridge.setFloodVlans(Sets.newHashSet(34L));
1380 assertNotNull(bridge.toString());
1382 Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1383 assertNotNull(nullRowBridge.toString());
1387 public void testTyperUtilsSpecialMethodsEquals () {
1388 Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1389 assertNotNull(bridge);
1390 bridge.setName(TEST_BRIDGE_NAME);
1391 bridge.setStatus(ImmutableMap.of("key", "value"));
1392 bridge.setFloodVlans(Sets.newHashSet(34L));
1394 assertTrue("Equals check on same Bridge object", bridge.equals(bridge));
1396 Bridge bridge2 = getClient().createTypedRowWrapper(Bridge.class);
1397 assertNotNull(bridge2);
1398 bridge2.setName(bridge.getName());
1399 bridge2.setStatus(bridge.getStatusColumn().getData());
1400 bridge2.setFloodVlans(bridge.getFloodVlansColumn().getData());
1402 assertTrue("Equals check for different Bridge objects with same content", bridge.equals(bridge2));
1404 bridge2.setStpEnable(true);
1405 assertFalse("Equals check for different Bridge objects with different content", bridge.equals(bridge2));
1407 Port port = getClient().createTypedRowWrapper(Port.class);
1408 port.setName(bridge.getName());
1409 assertFalse("Equals check for a Bridge object and Port Object", bridge.equals(port));
1410 assertFalse("Equals check for a Typed Proxy object and non-proxy object", port.equals("String"));
1412 Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1413 assertTrue("Equals check on Bridge object with null Row", nullRowBridge.equals(nullRowBridge));
1417 public void testTyperUtilsSpecialMethodsHashCode () {
1418 Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1420 assertNotNull(bridge);
1421 bridge.setName(TEST_BRIDGE_NAME);
1422 bridge.setStatus(ImmutableMap.of("key", "value"));
1423 bridge.setFloodVlans(Sets.newHashSet(34L));
1425 assertNotSame(bridge.hashCode(), 0);
1426 Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1427 assertSame(nullRowBridge.hashCode(), 0);