Added trunks code to go with the model.
[netvirt.git] / integrationtest / src / test / java / org / opendaylight / ovsdb / integrationtest / schema / openvswitch / OpenVSwitchIT.java
1 /*
2  *  Copyright (C) 2014 Red Hat, Inc.
3  *
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
7  *
8  *  Authors : Sam Hague, Matt Oswalt
9  */
10 package org.opendaylight.ovsdb.integrationtest.schema.openvswitch;
11
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;
26
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;
36 import java.util.Map;
37 import java.util.Set;
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;
87
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");
122
123     private static Map<String, Map<UUID, Row>> tableCache = new HashMap<>();
124     private static Map<String, Map<UUID, Row>> getTableCache () {
125         return tableCache;
126     }
127
128     private static OvsdbClient ovsdbClient;
129     private OvsdbClient getClient () {
130         return ovsdbClient;
131     }
132
133     private static DatabaseSchema dbSchema;
134     private DatabaseSchema getDbSchema () {
135         return dbSchema;
136     }
137
138     @Inject
139     private BundleContext bc;
140
141     @Configuration
142     public Option[] config() throws Exception {
143         return options(
144                 systemProperty("logback.configurationFile").value(
145                         "file:" + PathUtils.getBaseDir()
146                                 + "/src/test/resources/logback.xml"
147                 ),
148                 // To start OSGi console for inspection remotely
149                 systemProperty("osgi.console").value("2401"),
150
151                 propagateSystemProperty("ovsdbserver.ipaddress"),
152                 propagateSystemProperty("ovsdbserver.port"),
153
154                 ConfigurationBundles.mdsalBundles(),
155                 ConfigurationBundles.controllerBundles(),
156                 ConfigurationBundles.ovsdbLibraryBundles(),
157                 ConfigurationBundles.ovsdbDefaultSchemaBundles()
158         );
159     }
160
161     @Before
162     public void setUp () throws ExecutionException, InterruptedException, IOException {
163         areWeReady(bc);
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);
168     }
169
170     public boolean checkSchema (String schema) {
171         if (schemaSupported) {
172             LOG.info("Schema ({}) is supported", schema);
173             return true;
174         }
175         try {
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;
185                 return true;
186             }
187         } catch (Exception e) {
188             fail("Exception : "+e.getMessage());
189         }
190
191         LOG.info("Schema ({}) is not supported", schema);
192         return false;
193     }
194
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];
201             }
202         }
203         return null;
204     }
205
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)) {
211             return true;
212         } else {
213             return false;
214         }
215     }
216
217     /**
218      * As per RFC 7047, section 4.1.5, if a Monitor request is sent without any columns, the update response will not include
219      * the _uuid column.
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
226      *
227      * @return MonitorRequest that includes all the Bridge Columns including _uuid
228      */
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);
236         }
237         return bridgeBuilder.with(new MonitorSelect(true, true, true, true)).build();
238     }
239
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);
245         }
246         return monitorBuilder.with(new MonitorSelect(true, true, true, true)).build();
247     }
248
249     public boolean monitorTables () throws ExecutionException, InterruptedException, IOException {
250         if (monitorReady) {
251             LOG.info("Monitoring is already initialized.");
252             return monitorReady;
253         }
254
255         assertNotNull(getDbSchema());
256
257         List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
258         Set<String> tables = getDbSchema().getTables();
259         assertNotNull("ovsdb tables should not be null", tables);
260
261         for (String tableName : tables) {
262             GenericTableSchema tableSchema = getDbSchema().table(tableName, GenericTableSchema.class);
263             monitorRequests.add(this.getAllColumnsMonitorRequest(tableSchema));
264         }
265         TableUpdates updates = getClient().monitor(getDbSchema(), monitorRequests, new UpdateMonitor());
266         assertNotNull(updates);
267         this.updateTableCache(updates);
268
269         monitorReady = true;
270         LOG.info("Monitoring is initialized.");
271         return monitorReady;
272     }
273
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);
283                     }
284                     tUpdate.put(uuid, update.getNew(uuid));
285                 } else {
286                     tUpdate.remove(uuid);
287                 }
288             }
289         }
290     }
291
292     private class UpdateMonitor implements MonitorCallBack {
293         @Override
294         public void update(TableUpdates result, DatabaseSchema dbSchema) {
295             updateTableCache(result);
296         }
297
298         @Override
299         public void exception(Throwable t) {
300             LOG.error("Exception t = " + t);
301         }
302     }
303
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());
313         }
314         //Thread.sleep(500); // Wait for a few seconds to ensure the cache updates
315         return operationResults;
316     }
317
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));
323
324         OpenVSwitch openVSwitch = getClient().createTypedRowWrapper(OpenVSwitch.class);
325         openVSwitch.setBridges(Sets.newHashSet(new UUID(TEST_BRIDGE_NAME)));
326
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()))
337                         .build())
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));
343
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);
348         return bridgeUuid;
349     }
350
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);
354
355         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
356                 .add(op.delete(bridge.getSchema())
357                         .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
358                         .build())
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));
365
366         executeTransaction(transactionBuilder, "Bridge delete operation results");
367     }
368
369     @Test
370     public void testBridge () throws ExecutionException, InterruptedException {
371         testBridgeUuid = bridgeInsert();
372
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());
378
379         bridgeDelete(testBridgeUuid);
380     }
381
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);
389
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))
401                         .build())
402                 .add(op.comment("Bridge: Mutating controller1 " + controller1.getTargetColumn().getData()));
403
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);
408
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());
413
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());
417
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))
427                         .build())
428                 .add(op.comment("Bridge: Mutating controller2 " + controller2.getTargetColumn().getData()));
429
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);
434
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());
439
440         bridgeRow = getTableCache().get(bridge.getSchema().getName()).get(testBridgeUuid);
441         monitoredBridge = getClient().getTypedRowWrapper(Bridge.class, bridgeRow);
442         assertEquals(2, monitoredBridge.getControllerColumn().getData().size());
443     }
444
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();
449
450         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
451                 .add(op.delete(controller.getSchema())
452                         .where(controller.getUuidColumn().getSchema().opEqual(testController1Uuid))
453                         .build())
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));
460
461         executeTransaction(transactionBuilder, "Controller: Delete operation results for controller1");
462
463         transactionBuilder
464                 .add(op.delete(controller.getSchema())
465                         .where(controller.getUuidColumn().getSchema().opEqual(testController2Uuid))
466                         .build())
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));
473
474         executeTransaction(transactionBuilder, "Controller: Delete operation results for controller2");
475     }
476
477     @Test
478     public void testController () throws ExecutionException, InterruptedException {
479         testBridgeUuid = bridgeInsert();
480         controllerInsert();
481         controllerDelete();
482         bridgeDelete(testBridgeUuid);
483     }
484
485     @Test
486     public void testFlowSampleCollectorSetTableNotSupported () {
487         // Don't run this test if the table is not supported
488         assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) < 0);
489
490         boolean isExceptionRaised = false;
491         try {
492             FlowSampleCollectorSet flowSampleCollectorSet = getClient().createTypedRowWrapper(FlowSampleCollectorSet.class);
493         } catch (SchemaVersionMismatchException e) {
494             isExceptionRaised = true;
495         }
496         assertTrue(isExceptionRaised);
497     }
498
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);
502
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);
508
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"));
515
516         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
517                 "FlowSampleCollectorSet: Insert results");
518         testFlowSampleCollectorSetUuid = operationResults.get(0).getUuid();
519         assertNotNull(ASSERT_TRANS_UUID, testFlowSampleCollectorSetUuid);
520
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());
528     }
529
530     public void flowSampleCollectorSetDelete () throws ExecutionException, InterruptedException {
531         assumeTrue(schemaVersion.compareTo(flowSampleCollectorSetFromVersion) >= 0);
532
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))
537                         .build())
538                 .add(op.comment("FlowSampleCollectorSet: Deleting " + testFlowSampleCollectorSetUuid))
539                 .add(op.commit(true));
540
541         executeTransaction(transactionBuilder, "Bridge delete operation results");
542     }
543
544     @Test
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);
548
549         testBridgeUuid = bridgeInsert();
550         flowSampleCollectorSetInsert();
551         flowSampleCollectorSetDelete();
552         bridgeDelete(testBridgeUuid);
553     }
554
555     @Test
556     public void testFlowTableTableNotSupported () {
557         // Don't run this test if the table is not supported
558         assumeTrue(schemaVersion.compareTo(flowTableFromVersion) < 0);
559
560         boolean isExceptionRaised = false;
561         try {
562             FlowTable flowTable = getClient().createTypedRowWrapper(FlowTable.class);
563         } catch (SchemaVersionMismatchException e) {
564             isExceptionRaised = true;
565         }
566         assertTrue(isExceptionRaised);
567     }
568
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);
572
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));
587         }
588         if (schemaVersion.compareTo(externalIdAddedVerson) >= 0) {
589             flowTable.setExternalIds(ImmutableMap.of("I <3", "OVS"));
590         }
591         flowTable.setFlowLimit(ImmutableSet.of(flowLimit));
592         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
593
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))
601                         .build())
602                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
603
604         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
605                 "FlowTable: Insert and Mutate results");
606         testFlowTableUuid = operationResults.get(0).getUuid();
607         assertNotNull(ASSERT_TRANS_UUID, testFlowTableUuid);
608
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());
613     }
614
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);
618
619         FlowTable flowTable = getClient().getTypedRowWrapper(FlowTable.class, null);
620         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
621
622         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
623                 .add(op.delete(flowTable.getSchema())
624                         .where(flowTable.getUuidColumn().getSchema().opEqual(testFlowTableUuid))
625                         .build())
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));
632
633         executeTransaction(transactionBuilder, "FlowTable delete operation results");
634     }
635
636     @Test
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);
640
641         UUID testBridgeUuid = bridgeInsert();
642         flowTableInsert();
643         flowTableDelete();
644         bridgeDelete(testBridgeUuid);
645     }
646
647     @Test
648     public void testIpfixTableNotSupported () {
649         // Don't run this test if the table is not supported
650         assumeTrue(schemaVersion.compareTo(ipfixFromVersion) < 0);
651
652         boolean isExceptionRaised = false;
653         try {
654             IPFIX ipfix = getClient().createTypedRowWrapper(IPFIX.class);
655         } catch (SchemaVersionMismatchException e) {
656             isExceptionRaised = true;
657         }
658         assertTrue(isExceptionRaised);
659     }
660
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);
664
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;
672
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));
681         }
682         ipfix.setSampling(ImmutableSet.of(sampling));
683         ipfix.setExternalIds(ImmutableMap.of("I <3", "ovs"));
684         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
685
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))
694                         .build())
695                 .add(op.comment("Bridge: Mutating " + ipfixUuidStr));
696
697         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
698                 "IPFIX: Insert and Mutate results");
699         testIpfixUuid = operationResults.get(0).getUuid();
700         assertNotNull(ASSERT_TRANS_UUID, testIpfixUuid);
701
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());
706     }
707
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);
711
712         FlowTable flowTable = getClient().getTypedRowWrapper(FlowTable.class, null);
713         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
714
715         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
716                 .add(op.delete(flowTable.getSchema())
717                         .where(flowTable.getUuidColumn().getSchema().opEqual(testIpfixUuid))
718                         .build())
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));
725
726         executeTransaction(transactionBuilder, "IPFIX delete operation results");
727     }
728
729     @Test
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);
733
734         testBridgeUuid = bridgeInsert();
735         ipfixInsert();
736         ipfixDelete();
737         bridgeDelete(testBridgeUuid);
738     }
739
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);
749
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))
762                         .build())
763                 .add(op.comment("Open_vSwitch: Mutating " + TEST_MANAGER_UUID_STR));
764
765         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
766                 "Manager: Insert & Mutate operation results");
767         testManagerUuid = operationResults.get(0).getUuid();
768         assertNotNull(ASSERT_TRANS_UUID, testManagerUuid);
769
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());
774     }
775
776     public void managerDelete () throws ExecutionException, InterruptedException {
777         Manager manager = getClient().getTypedRowWrapper(Manager.class, null);
778         OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
779
780         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
781                 .add(op.delete(manager.getSchema())
782                         .where(manager.getUuidColumn().getSchema().opEqual(testManagerUuid))
783                         .build())
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));
790
791         executeTransaction(transactionBuilder, "Manager: Delete operation results");
792     }
793
794     @Test
795     public void testManager () throws ExecutionException, InterruptedException {
796         managerInsert();
797         managerDelete();
798     }
799
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);
805
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);
813
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))
824                         .build())
825                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
826
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);
831
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());
836     }
837
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();
842
843         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
844                 .add(op.delete(mirror.getSchema())
845                         .where(mirror.getUuidColumn().getSchema().opEqual(testMirrorUuid))
846                         .build())
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));
853
854         executeTransaction(transactionBuilder, "Mirror: Delete operation results");
855     }
856
857     @Test
858     public void testMirror () throws ExecutionException, InterruptedException {
859         testBridgeUuid = bridgeInsert();
860         mirrorInsert();
861         mirrorDelete();
862         bridgeDelete(testBridgeUuid);
863     }
864
865     public void netFlowInsert () throws ExecutionException, InterruptedException {
866         String netFlowUuidStr = "testNetFlow";
867         String netFlowTargets = "172.16.20.200:6343";
868         Long engineType = 128L;
869         Long engineID = 32L;
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))
891                         .build())
892                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
893
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);
898
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());
903     }
904
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();
909
910         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
911                 .add(op.delete(netFlow.getSchema())
912                         .where(netFlow.getUuidColumn().getSchema().opEqual(testNetFlowUuid))
913                         .build())
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));
920
921         executeTransaction(transactionBuilder, "NetFlow: Delete operation results");
922     }
923
924     @Test
925     public void testNetFlow () throws ExecutionException, InterruptedException {
926         testBridgeUuid = bridgeInsert();
927         netFlowInsert();
928         netFlowDelete();
929         bridgeDelete(testBridgeUuid);
930     }
931
932     public void portAndInterfaceInsert () throws ExecutionException, InterruptedException {
933         String portUuidStr = "testPort";
934         String intfUuidStr = "testIntf";
935         String tunnelEncap = "vxlan";
936         int tag = 10;
937         Port port = getClient().createTypedRowWrapper(Port.class);
938         port.setName("testPort");
939         port.setTag(tag);
940         port.setMac(ImmutableSet.of("00:00:00:00:00:01"));
941         port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
942
943         Interface intf = getClient().createTypedRowWrapper(Interface.class);
944         intf.setName(port.getNameColumn().getData());
945         intf.setType(tunnelEncap);
946         intf.setExternalIds(ImmutableMap.of("vm-id", "12345abcedf78910"));
947         // For per Flow TEPs use remote_ip=flow
948         // For per Port TEPs use remote_ip=x.x.x.x (ipv4)
949         intf.setOptions(ImmutableMap.of("local_ip", "172.16.24.145",
950                 "remote_ip", "flow",
951                 "key", "flow",
952                 "dst_port", "8472"));
953
954         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
955         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
956                 .add(op.insert(port.getSchema())
957                         .withId(portUuidStr)
958                         .value(port.getNameColumn())
959                         .value(port.getMacColumn()))
960                 .add(op.comment("Port: Inserting " + portUuidStr))
961                 .add(op.insert(intf.getSchema())
962                         .withId(intfUuidStr)
963                         .value(intf.getNameColumn()))
964                 .add(op.comment("Interface: Inserting " + intfUuidStr))
965                 .add(op.update(port.getSchema())
966                         .set(port.getTagColumn())
967                         .set(port.getMacColumn())
968                         .set(port.getInterfacesColumn())
969                         .where(port.getNameColumn().getSchema().opEqual(port.getName()))
970                         .build())
971                 .add(op.comment("Port: Updating " + portUuidStr))
972                 .add(op.update(intf.getSchema())
973                         .set(intf.getTypeColumn())
974                         .set(intf.getExternalIdsColumn())
975                         .set(intf.getOptionsColumn())
976                         .where(intf.getNameColumn().getSchema().opEqual(intf.getName()))
977                         .build())
978                 .add(op.comment("Interface: Updating " + intfUuidStr))
979                 .add(op.mutate(bridge.getSchema())
980                         .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT, Sets.newHashSet(new UUID(portUuidStr)))
981                         .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
982                         .build())
983                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
984
985         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
986                 "Insert and Mutate operation results for Port and Interface");
987         testPortUuid = operationResults.get(0).getUuid();
988         assertNotNull(ASSERT_TRANS_UUID, testPortUuid);
989         testInterfaceUuid = operationResults.get(2).getUuid();
990         assertNotNull(ASSERT_TRANS_UUID, testInterfaceUuid);
991
992         // Verify that the local cache was updated with the remote changes
993         Row portRow = getTableCache().get(port.getSchema().getName()).get(testPortUuid);
994         Port monitoredPort = getClient().getTypedRowWrapper(Port.class, portRow);
995         assertEquals(port.getNameColumn().getData(), monitoredPort.getNameColumn().getData());
996
997         Row interfaceRow = getTableCache().get(intf.getSchema().getName()).get(testInterfaceUuid);
998         Interface monitoredInterface = getClient().getTypedRowWrapper(Interface.class, interfaceRow);
999         assertEquals(intf.getNameColumn().getData(), monitoredInterface.getNameColumn().getData());
1000     }
1001
1002     private void portAndInterfaceDelete () throws ExecutionException, InterruptedException {
1003         Port port = getClient().getTypedRowWrapper(Port.class, null);
1004         Interface intf = getClient().getTypedRowWrapper(Interface.class, null);
1005         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1006         DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1007
1008         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1009                 .add(op.delete(port.getSchema())
1010                         .where(port.getUuidColumn().getSchema().opEqual(testPortUuid))
1011                         .build())
1012                 .add(op.comment("Port: Deleting " + testPortUuid))
1013                 .add(op.delete(intf.getSchema())
1014                         .where(intf.getUuidColumn().getSchema().opEqual(testInterfaceUuid))
1015                         .build())
1016                 .add(op.comment("Interface: Deleting " + testInterfaceUuid))
1017                 .add(op.mutate(bridge.getSchema()) // Delete a port column in the Bridge table
1018                         .addMutation(bridge.getPortsColumn().getSchema(), Mutator.DELETE,
1019                                 Sets.newHashSet(testPortUuid)))
1020                 .add(op.comment("Bridge: Mutating " + testPortUuid))
1021                 .add(op.commit(true));
1022
1023         executeTransaction(transactionBuilder, "Port and Interface: Delete operation results");
1024     }
1025
1026     @Test
1027     public void testPortAndInterface () throws ExecutionException, InterruptedException {
1028         testBridgeUuid = bridgeInsert();
1029         portAndInterfaceInsert();
1030         portAndInterfaceDelete();
1031         bridgeDelete(testBridgeUuid);
1032     }
1033
1034     public void qosInsert() throws ExecutionException, InterruptedException {
1035         String portUuidStr = "testQosPortUuid";
1036         String intfUuidStr = "testQosIntfUuid";
1037         String qosUuidStr = "testQosUuid";
1038         String qosPort = "testQosPort";
1039
1040         Port port = getClient().createTypedRowWrapper(Port.class);
1041         port.setName(qosPort);
1042         port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
1043         port.setQos(ImmutableSet.of(new UUID(qosUuidStr)));
1044         port.setOtherConfig(ImmutableMap.of("m0r3", "c0ff33"));
1045
1046         Interface intf = getClient().createTypedRowWrapper(Interface.class);
1047         intf.setName(port.getNameColumn().getData());
1048         intf.setOtherConfig(ImmutableMap.of("proto", "duction"));
1049         intf.setExternalIds(ImmutableMap.of("stringly", "typed"));
1050
1051         Qos qos = getClient().createTypedRowWrapper(Qos.class);
1052         qos.setOtherConfig(ImmutableMap.of("mmm", "kay"));
1053         qos.setType(ImmutableSet.of("404"));
1054
1055         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1056
1057         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1058                 .add(op.insert(port.getSchema())
1059                         .withId(portUuidStr)
1060                         .value(port.getNameColumn()))
1061                 .add(op.comment("Port: Inserting " + portUuidStr))
1062                 .add(op.insert(intf.getSchema())
1063                         .withId(intfUuidStr)
1064                         .value(intf.getExternalIdsColumn())
1065                         .value(intf.getNameColumn())
1066                         .value(intf.getOtherConfigColumn()))
1067                 .add(op.comment("Interface: Inserting " + intfUuidStr))
1068                 .add(op.insert(qos.getSchema())
1069                         .withId(qosUuidStr)
1070                         .value(qos.getTypeColumn())
1071                         .value(qos.getOtherConfigColumn()))
1072                 .add(op.comment("QOS: Inserting " + qosUuidStr))
1073                 .add(op.update(port.getSchema())
1074                         .set(port.getOtherConfigColumn())
1075                         .set(port.getInterfacesColumn())
1076                         .set(port.getQosColumn())
1077                         .where(port.getNameColumn().getSchema().opEqual(port.getName()))
1078                         .build())
1079                 .add(op.comment("Interface: Updating " + intfUuidStr))
1080                 .add(op.mutate(bridge.getSchema())
1081                         .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT,
1082                                 Sets.newHashSet(new UUID(portUuidStr)))
1083                         .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
1084                         .build())
1085                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
1086
1087         int insertPortOperationIndex = 0;
1088         int insertInterfaceOperationIndex = 2;
1089         int insertQosOperationIndex = 4;
1090         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1091                 "Insert and Mutate operation results for Port and Interface");
1092         testPortUuid = operationResults.get(insertPortOperationIndex).getUuid();
1093         assertNotNull(ASSERT_TRANS_UUID, testPortUuid);
1094         testInterfaceUuid = operationResults.get(insertInterfaceOperationIndex).getUuid();
1095         assertNotNull(ASSERT_TRANS_UUID, testInterfaceUuid);
1096         testQosUuid = operationResults.get(insertQosOperationIndex).getUuid();
1097         assertNotNull(ASSERT_TRANS_UUID, testQosUuid);
1098
1099         // Verify that the local cache was updated with the remote changes
1100         Row portRow = getTableCache().get(port.getSchema().getName()).get(testPortUuid);
1101         Port monitoredPort = getClient().getTypedRowWrapper(Port.class, portRow);
1102         assertEquals(port.getNameColumn().getData(), monitoredPort.getNameColumn().getData());
1103
1104         Row interfaceRow = getTableCache().get(intf.getSchema().getName()).get(testInterfaceUuid);
1105         Interface monitoredInterface = getClient().getTypedRowWrapper(Interface.class, interfaceRow);
1106         assertEquals(intf.getNameColumn().getData(), monitoredInterface.getNameColumn().getData());
1107
1108         Row qosRow = getTableCache().get(qos.getSchema().getName()).get(testQosUuid);
1109         Qos monitoredQos = getClient().getTypedRowWrapper(Qos.class, qosRow);
1110         assertEquals(qos.getTypeColumn().getData().toArray()[0], monitoredQos.getTypeColumn().getData());
1111     }
1112
1113     private void qosDelete () throws ExecutionException, InterruptedException {
1114         Port port = getClient().getTypedRowWrapper(Port.class, null);
1115         Interface intf = getClient().getTypedRowWrapper(Interface.class, null);
1116         Qos qos = getClient().getTypedRowWrapper(Qos.class, null);
1117         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1118         DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1119
1120         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1121                 .add(op.delete(port.getSchema())
1122                         .where(port.getUuidColumn().getSchema().opEqual(testPortUuid))
1123                         .build())
1124                 .add(op.comment("Port: Deleting " + testPortUuid))
1125                 .add(op.delete(intf.getSchema())
1126                         .where(intf.getUuidColumn().getSchema().opEqual(testInterfaceUuid))
1127                         .build())
1128                 .add(op.comment("Interface: Deleting " + testInterfaceUuid))
1129                 .add(op.delete(qos.getSchema())
1130                         .where(qos.getUuidColumn().getSchema().opEqual(testQosUuid))
1131                         .build())
1132                 .add(op.comment("Qos: Deleting " + testQosUuid))
1133                 .add(op.mutate(bridge.getSchema()) // Delete a port column in the Bridge table
1134                         .addMutation(bridge.getPortsColumn().getSchema(), Mutator.DELETE,
1135                                 Sets.newHashSet(testPortUuid)))
1136                 .add(op.comment("Bridge: Mutating " + testPortUuid))
1137                 .add(op.mutate(port.getSchema()) // Delete a qos column in the Port table
1138                         .addMutation(port.getQosColumn().getSchema(), Mutator.DELETE,
1139                                 Sets.newHashSet(testQosUuid)))
1140                 .add(op.comment("Port: Mutating " + testPortUuid))
1141                 .add(op.commit(true));
1142
1143         executeTransaction(transactionBuilder, "Qos, Port and Interface: Delete operation results");
1144     }
1145
1146     @Test
1147     public void testQos () throws ExecutionException, InterruptedException {
1148         testBridgeUuid = bridgeInsert();
1149         qosInsert();
1150         qosDelete();
1151         bridgeDelete(testBridgeUuid);
1152     }
1153
1154     public void queueInsert() throws InterruptedException, ExecutionException {
1155         /**
1156          * This is an arbitrary String that is a placeholder for
1157          * the future UUID generated by the OVSDB Server in the
1158          * future transaction. While it is possible to generate
1159          * ones own UUID for the transaction it is not recommended
1160          * since it wouldn't add any conceivable value.
1161          */
1162         String queueUuidStr = "queueUuidStr";
1163         Long dscpVal = Long.valueOf(4);
1164         Queue queue = getClient().createTypedRowWrapper(Queue.class);
1165         // Example of explicit ImmutableSet/Map Attribute declaration
1166         ImmutableSet<Long> dscp = ImmutableSet.of(dscpVal);
1167         ImmutableMap<String, String> externalIds = ImmutableMap.of("little", "coat");
1168         // Example of condensing the attributes bindings in one line
1169         queue.setOtherConfig(ImmutableMap.of("war", "onfun"));
1170         // Bind the Attributes to the transaction. These values end up in columns.
1171         queue.setExternalIds(externalIds);
1172         queue.setDscp(dscp);
1173         // Get the parent Qos table row UUID to insert the queue.
1174         Qos qos = getClient().getTypedRowWrapper(Qos.class, null);
1175         // Queue key that is mapped to the queue record/value/ofp_action_enqueue
1176         Long queueKey = 0L;
1177         // Reference the Port row to insert the Queue with UID or Port name
1178         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1179                 .add(op.insert(queue.getSchema())
1180                         .withId(queueUuidStr)
1181                         .value(queue.getDscpColumn())
1182                         .value(queue.getExternalIdsColumn())
1183                         .value(queue.getOtherConfigColumn()))
1184                 .add(op.comment("Queue: Inserting " + queueUuidStr))
1185                 .add(op.mutate(qos.getSchema())
1186                         .addMutation(qos.getQueuesColumn().getSchema(), Mutator.INSERT,
1187                                 ImmutableMap.of(queueKey, new UUID(queueUuidStr)))
1188                         .where(qos.getUuidColumn().getSchema().opEqual(testQosUuid))
1189                         .build())
1190                 .add(op.comment("Qos: Mutating " + testQosUuid));
1191
1192         // The transaction index for the Queue insert is used to store the Queue UUID
1193         int insertQueueOperationIndex = 0;
1194         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1195                 "Insert and Mutate operation results for Queue");
1196         testQueueUuid = operationResults.get(insertQueueOperationIndex).getUuid();
1197         assertNotNull(ASSERT_TRANS_UUID, testQueueUuid);
1198
1199         // Verify that the local cache was updated with the remote changes
1200         Row queueRow = getTableCache().get(queue.getSchema().getName()).get(testQueueUuid);
1201         Queue monitoredQueue = getClient().getTypedRowWrapper(Queue.class, queueRow);
1202         assertEquals(queue.getExternalIdsColumn().getData(), monitoredQueue.getExternalIdsColumn().getData());
1203     }
1204
1205     private void queueDelete () throws ExecutionException, InterruptedException {
1206         Queue queue = getClient().getTypedRowWrapper(Queue.class, null);
1207         Qos qos = getClient().getTypedRowWrapper(Qos.class, null);
1208         DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1209
1210         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1211                 .add(op.delete(queue.getSchema())
1212                         .where(queue.getUuidColumn().getSchema().opEqual(testQueueUuid))
1213                         .build())
1214                 .add(op.comment("Queue: Deleting " + testQueueUuid))
1215                 .add(op.mutate(qos.getSchema()) // Delete a queue column in the Qos table
1216                         .addMutation(qos.getQueuesColumn().getSchema(), Mutator.DELETE,
1217                                 Maps.newHashMap(ImmutableMap.of(0L,testQueueUuid))))
1218                 .add(op.comment("Queue: Mutating " + testQueueUuid))
1219                 .add(op.commit(true));
1220
1221         executeTransaction(transactionBuilder, "Queue: Delete operation results");
1222     }
1223
1224     @Test
1225     public void testQueue () throws ExecutionException, InterruptedException {
1226         testBridgeUuid = bridgeInsert();
1227         qosInsert();
1228         queueInsert();
1229         queueDelete();
1230         qosDelete();
1231         bridgeDelete(testBridgeUuid);
1232     }
1233
1234     public void sFlowInsert () throws ExecutionException, InterruptedException {
1235         String sFlowUuidStr = "testSFlow";
1236         String sFlowTarget = "172.16.20.200:6343";
1237         Long header = 128L;
1238         Long obsPointId = 358L;
1239         Long polling =10L;
1240         String agent = "172.16.20.210";
1241         Long sampling = 64L;
1242         SFlow sFlow = getClient().createTypedRowWrapper(SFlow.class);
1243         sFlow.setTargets(ImmutableSet.of(sFlowTarget));
1244         sFlow.setHeader(ImmutableSet.of(header));
1245         sFlow.setPolling(ImmutableSet.of(obsPointId));
1246         sFlow.setPolling(ImmutableSet.of(polling));
1247         sFlow.setAgent(ImmutableSet.of(agent));
1248         sFlow.setSampling(ImmutableSet.of(sampling));
1249         sFlow.setExternalIds(ImmutableMap.of("kit", "tah"));
1250         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1251         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1252                 .add(op.insert(sFlow.getSchema())
1253                         .withId(sFlowUuidStr)
1254                         .value(sFlow.getTargetsColumn())
1255                         .value(sFlow.getHeaderColumn())
1256                         .value(sFlow.getPollingColumn())
1257                         .value(sFlow.getAgentColumn())
1258                         .value(sFlow.getSamplingColumn())
1259                         .value(sFlow.getExternalIdsColumn()))
1260                 .add(op.comment("sFlow: Inserting " + sFlowUuidStr))
1261                 .add(op.mutate(bridge.getSchema())
1262                         .addMutation(bridge.getSflowColumn().getSchema(), Mutator.INSERT,
1263                                 Sets.newHashSet(new UUID(sFlowUuidStr)))
1264                         .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
1265                         .build())
1266                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
1267         int insertSFlowOperationIndex = 0;
1268         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1269                 "Insert and Mutate operation results for sFlow");
1270         testSFlowUuid = operationResults.get(insertSFlowOperationIndex).getUuid();
1271         assertNotNull(ASSERT_TRANS_UUID, testSFlowUuid);
1272
1273         // Verify that the local cache was updated with the remote changes
1274         Row sFlowRow = getTableCache().get(sFlow.getSchema().getName()).get(testSFlowUuid);
1275         Queue monitoredSFlow = getClient().getTypedRowWrapper(Queue.class, sFlowRow);
1276         assertEquals(sFlow.getExternalIdsColumn().getData(), monitoredSFlow.getExternalIdsColumn().getData());
1277     }
1278
1279     private void sFlowDelete () throws ExecutionException, InterruptedException {
1280         SFlow sFlow = getClient().getTypedRowWrapper(SFlow.class, null);
1281         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1282         DatabaseSchema dbSchema = getClient().getSchema(OPEN_VSWITCH_SCHEMA).get();
1283
1284         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1285                 .add(op.delete(sFlow.getSchema())
1286                         .where(sFlow.getUuidColumn().getSchema().opEqual(testSFlowUuid))
1287                         .build())
1288                 .add(op.comment("SFlow: Deleting " + testSFlowUuid))
1289                 .add(op.mutate(bridge.getSchema()) // Delete an sflow column in the Bridge table
1290                         .addMutation(bridge.getSflowColumn().getSchema(), Mutator.DELETE,
1291                                 Sets.newHashSet(testSFlowUuid)))
1292                 .add(op.comment("Bridge: Mutating " + testSFlowUuid))
1293                 .add(op.commit(true));
1294
1295         executeTransaction(transactionBuilder, "Queue: Delete operation results");
1296     }
1297
1298     @Test
1299     public void testSFlow () throws ExecutionException, InterruptedException {
1300         testBridgeUuid = bridgeInsert();
1301         sFlowInsert();
1302         sFlowDelete();
1303         bridgeDelete(testBridgeUuid);
1304     }
1305
1306     public void sslInsert () throws ExecutionException, InterruptedException {
1307
1308         String sslUuidStr = "sslUuidName";
1309         String caCert = "PARC";
1310         String certificate = "01101110 01100101 01110010 01100100";
1311         String privateKey = "SSL_Table_Test_Secret";
1312         ImmutableMap<String, String> externalIds = ImmutableMap.of("roomba", "powered");
1313
1314         SSL ssl = getClient().createTypedRowWrapper(SSL.class);
1315         ssl.setCaCert(caCert);
1316         ssl.setCertificate(certificate);
1317         ssl.setPrivateKey(privateKey);
1318         ssl.setExternalIds(externalIds);
1319         // Get the parent OVS table UUID in it's single row
1320         UUID openVSwitchRowUuid = getOpenVSwitchTableUuid(getClient(), getTableCache());
1321         OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
1322         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1323                 .add(op.insert(ssl.getSchema())
1324                         .withId(sslUuidStr)
1325                         .value(ssl.getCertificateColumn())
1326                         .value(ssl.getPrivateKeyColumn())
1327                         .value(ssl.getCaCertColumn())
1328                         .value(ssl.getExternalIdsColumn()))
1329                 .add(op.comment("SSL: Inserting " + sslUuidStr))
1330                 .add(op.mutate(openVSwitch.getSchema())
1331                         .addMutation(openVSwitch.getSslColumn().getSchema(), Mutator.INSERT,
1332                                 Sets.newHashSet(new UUID(sslUuidStr)))
1333                         .where(openVSwitch.getUuidColumn().getSchema().opEqual(openVSwitchRowUuid))
1334                         .build())
1335                 .add(op.comment("Open_vSwitch: Mutating " + sslUuidStr));
1336
1337         // The transaction index for the SSL insert is used to store the SSL UUID
1338         int insertSslOperationIndex = 0;
1339         List<OperationResult> operationResults = executeTransaction(transactionBuilder,
1340                 "Insert and Mutate operation results for SSL");
1341         testSslUuid = operationResults.get(insertSslOperationIndex).getUuid();
1342         assertNotNull(ASSERT_TRANS_UUID, testSslUuid);
1343
1344         // Verify that the local cache was updated with the remote changes
1345         Row sslRow = getTableCache().get(ssl.getSchema().getName()).get(testSslUuid);
1346         SSL monitoredSsl = getClient().getTypedRowWrapper(SSL.class, sslRow);
1347         assertEquals(ssl.getExternalIdsColumn().getData(), monitoredSsl.getExternalIdsColumn().getData());
1348     }
1349
1350     public void sslDelete () throws ExecutionException, InterruptedException {
1351         SSL ssl = getClient().getTypedRowWrapper(SSL.class, null);
1352         OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
1353
1354         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1355                 .add(op.delete(ssl.getSchema())
1356                         .where(ssl.getUuidColumn().getSchema().opEqual(testSslUuid))
1357                         .build())
1358                 .add(op.comment("SSL: Deleting " + testSslUuid))
1359                 .add(op.mutate(openVSwitch.getSchema())
1360                         .addMutation(openVSwitch.getSslColumn().getSchema(), Mutator.DELETE,
1361                                 Sets.newHashSet(testSslUuid)))
1362                 .add(op.comment("Open_vSwitch: Mutating " + testSslUuid))
1363                 .add(op.commit(true));
1364
1365         executeTransaction(transactionBuilder, "SSL delete operation results");
1366     }
1367
1368     @Test
1369     public void testSsl () throws ExecutionException, InterruptedException {
1370         sslInsert();
1371         sslDelete();
1372     }
1373
1374     @Test
1375     public void testTyperUtilsSpecialMethodsToString () {
1376         Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1377         assertNotNull(bridge);
1378         bridge.setName(TEST_BRIDGE_NAME);
1379         bridge.setStatus(ImmutableMap.of("key", "value"));
1380         bridge.setFloodVlans(Sets.newHashSet(34L));
1381         assertNotNull(bridge.toString());
1382
1383         Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1384         assertNotNull(nullRowBridge.toString());
1385     }
1386
1387     @Test
1388     public void testTyperUtilsSpecialMethodsEquals () {
1389         Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1390         assertNotNull(bridge);
1391         bridge.setName(TEST_BRIDGE_NAME);
1392         bridge.setStatus(ImmutableMap.of("key", "value"));
1393         bridge.setFloodVlans(Sets.newHashSet(34L));
1394
1395         assertTrue("Equals check on same Bridge object", bridge.equals(bridge));
1396
1397         Bridge bridge2 = getClient().createTypedRowWrapper(Bridge.class);
1398         assertNotNull(bridge2);
1399         bridge2.setName(bridge.getName());
1400         bridge2.setStatus(bridge.getStatusColumn().getData());
1401         bridge2.setFloodVlans(bridge.getFloodVlansColumn().getData());
1402
1403         assertTrue("Equals check for different Bridge objects with same content", bridge.equals(bridge2));
1404
1405         bridge2.setStpEnable(true);
1406         assertFalse("Equals check for different Bridge objects with different content", bridge.equals(bridge2));
1407
1408         Port port = getClient().createTypedRowWrapper(Port.class);
1409         port.setName(bridge.getName());
1410         assertFalse("Equals check for a Bridge object and Port Object", bridge.equals(port));
1411         assertFalse("Equals check for a Typed Proxy object and non-proxy object", port.equals("String"));
1412
1413         Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1414         assertTrue("Equals check on Bridge object with null Row", nullRowBridge.equals(nullRowBridge));
1415     }
1416
1417     @Test
1418     public void testTyperUtilsSpecialMethodsHashCode () {
1419         Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1420
1421         assertNotNull(bridge);
1422         bridge.setName(TEST_BRIDGE_NAME);
1423         bridge.setStatus(ImmutableMap.of("key", "value"));
1424         bridge.setFloodVlans(Sets.newHashSet(34L));
1425
1426         assertNotSame(bridge.hashCode(), 0);
1427         Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1428         assertSame(nullRowBridge.hashCode(), 0);
1429     }
1430 }