Switch node-id's for ovsdb-managed-nodes
[ovsdb.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.controllerBundles(),
155                 ConfigurationBundles.ovsdbLibraryBundles(),
156                 ConfigurationBundles.ovsdbDefaultSchemaBundles(),
157                 junitBundles()
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         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)));
941
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",
949                 "remote_ip", "flow",
950                 "key", "flow",
951                 "dst_port", "8472"));
952
953         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
954         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
955                 .add(op.insert(port.getSchema())
956                         .withId(portUuidStr)
957                         .value(port.getNameColumn())
958                         .value(port.getMacColumn()))
959                 .add(op.comment("Port: Inserting " + portUuidStr))
960                 .add(op.insert(intf.getSchema())
961                         .withId(intfUuidStr)
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()))
969                         .build())
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()))
976                         .build())
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))
981                         .build())
982                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
983
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);
990
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());
995
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());
999     }
1000
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();
1006
1007         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1008                 .add(op.delete(port.getSchema())
1009                         .where(port.getUuidColumn().getSchema().opEqual(testPortUuid))
1010                         .build())
1011                 .add(op.comment("Port: Deleting " + testPortUuid))
1012                 .add(op.delete(intf.getSchema())
1013                         .where(intf.getUuidColumn().getSchema().opEqual(testInterfaceUuid))
1014                         .build())
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));
1021
1022         executeTransaction(transactionBuilder, "Port and Interface: Delete operation results");
1023     }
1024
1025     @Test
1026     public void testPortAndInterface () throws ExecutionException, InterruptedException {
1027         testBridgeUuid = bridgeInsert();
1028         portAndInterfaceInsert();
1029         portAndInterfaceDelete();
1030         bridgeDelete(testBridgeUuid);
1031     }
1032
1033     public void qosInsert() throws ExecutionException, InterruptedException {
1034         String portUuidStr = "testQosPortUuid";
1035         String intfUuidStr = "testQosIntfUuid";
1036         String qosUuidStr = "testQosUuid";
1037         String qosPort = "testQosPort";
1038
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"));
1044
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"));
1049
1050         Qos qos = getClient().createTypedRowWrapper(Qos.class);
1051         qos.setOtherConfig(ImmutableMap.of("mmm", "kay"));
1052         qos.setType(ImmutableSet.of("404"));
1053
1054         Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
1055
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())
1068                         .withId(qosUuidStr)
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()))
1077                         .build())
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))
1083                         .build())
1084                 .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
1085
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);
1097
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());
1102
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());
1106
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());
1110     }
1111
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();
1118
1119         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1120                 .add(op.delete(port.getSchema())
1121                         .where(port.getUuidColumn().getSchema().opEqual(testPortUuid))
1122                         .build())
1123                 .add(op.comment("Port: Deleting " + testPortUuid))
1124                 .add(op.delete(intf.getSchema())
1125                         .where(intf.getUuidColumn().getSchema().opEqual(testInterfaceUuid))
1126                         .build())
1127                 .add(op.comment("Interface: Deleting " + testInterfaceUuid))
1128                 .add(op.delete(qos.getSchema())
1129                         .where(qos.getUuidColumn().getSchema().opEqual(testQosUuid))
1130                         .build())
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));
1141
1142         executeTransaction(transactionBuilder, "Qos, Port and Interface: Delete operation results");
1143     }
1144
1145     @Test
1146     public void testQos () throws ExecutionException, InterruptedException {
1147         testBridgeUuid = bridgeInsert();
1148         qosInsert();
1149         qosDelete();
1150         bridgeDelete(testBridgeUuid);
1151     }
1152
1153     public void queueInsert() throws InterruptedException, ExecutionException {
1154         /**
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.
1160          */
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
1175         Long queueKey = 0L;
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))
1188                         .build())
1189                 .add(op.comment("Qos: Mutating " + testQosUuid));
1190
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);
1197
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());
1202     }
1203
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();
1208
1209         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1210                 .add(op.delete(queue.getSchema())
1211                         .where(queue.getUuidColumn().getSchema().opEqual(testQueueUuid))
1212                         .build())
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));
1219
1220         executeTransaction(transactionBuilder, "Queue: Delete operation results");
1221     }
1222
1223     @Test
1224     public void testQueue () throws ExecutionException, InterruptedException {
1225         testBridgeUuid = bridgeInsert();
1226         qosInsert();
1227         queueInsert();
1228         queueDelete();
1229         qosDelete();
1230         bridgeDelete(testBridgeUuid);
1231     }
1232
1233     public void sFlowInsert () throws ExecutionException, InterruptedException {
1234         String sFlowUuidStr = "testSFlow";
1235         String sFlowTarget = "172.16.20.200:6343";
1236         Long header = 128L;
1237         Long obsPointId = 358L;
1238         Long polling =10L;
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))
1264                         .build())
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);
1271
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());
1276     }
1277
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();
1282
1283         TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
1284                 .add(op.delete(sFlow.getSchema())
1285                         .where(sFlow.getUuidColumn().getSchema().opEqual(testSFlowUuid))
1286                         .build())
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));
1293
1294         executeTransaction(transactionBuilder, "Queue: Delete operation results");
1295     }
1296
1297     @Test
1298     public void testSFlow () throws ExecutionException, InterruptedException {
1299         testBridgeUuid = bridgeInsert();
1300         sFlowInsert();
1301         sFlowDelete();
1302         bridgeDelete(testBridgeUuid);
1303     }
1304
1305     public void sslInsert () throws ExecutionException, InterruptedException {
1306
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");
1312
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())
1323                         .withId(sslUuidStr)
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))
1333                         .build())
1334                 .add(op.comment("Open_vSwitch: Mutating " + sslUuidStr));
1335
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);
1342
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());
1347     }
1348
1349     public void sslDelete () throws ExecutionException, InterruptedException {
1350         SSL ssl = getClient().getTypedRowWrapper(SSL.class, null);
1351         OpenVSwitch openVSwitch = getClient().getTypedRowWrapper(OpenVSwitch.class, null);
1352
1353         TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
1354                 .add(op.delete(ssl.getSchema())
1355                         .where(ssl.getUuidColumn().getSchema().opEqual(testSslUuid))
1356                         .build())
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));
1363
1364         executeTransaction(transactionBuilder, "SSL delete operation results");
1365     }
1366
1367     @Test
1368     public void testSsl () throws ExecutionException, InterruptedException {
1369         sslInsert();
1370         sslDelete();
1371     }
1372
1373     @Test
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());
1381
1382         Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1383         assertNotNull(nullRowBridge.toString());
1384     }
1385
1386     @Test
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));
1393
1394         assertTrue("Equals check on same Bridge object", bridge.equals(bridge));
1395
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());
1401
1402         assertTrue("Equals check for different Bridge objects with same content", bridge.equals(bridge2));
1403
1404         bridge2.setStpEnable(true);
1405         assertFalse("Equals check for different Bridge objects with different content", bridge.equals(bridge2));
1406
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"));
1411
1412         Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1413         assertTrue("Equals check on Bridge object with null Row", nullRowBridge.equals(nullRowBridge));
1414     }
1415
1416     @Test
1417     public void testTyperUtilsSpecialMethodsHashCode () {
1418         Bridge bridge = getClient().createTypedRowWrapper(Bridge.class);
1419
1420         assertNotNull(bridge);
1421         bridge.setName(TEST_BRIDGE_NAME);
1422         bridge.setStatus(ImmutableMap.of("key", "value"));
1423         bridge.setFloodVlans(Sets.newHashSet(34L));
1424
1425         assertNotSame(bridge.hashCode(), 0);
1426         Bridge nullRowBridge = getClient().getTypedRowWrapper(Bridge.class, null);
1427         assertSame(nullRowBridge.hashCode(), 0);
1428     }
1429 }