2 * Copyright (C) 2014 EBay Software Foundation
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Ashwin Raveendran, Madhu Venugopal
11 package org.opendaylight.ovsdb.integrationtest.ovsdbclient;
13 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
15 import java.io.IOException;
16 import java.lang.reflect.InvocationTargetException;
17 import java.util.List;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.TimeoutException;
22 import junit.framework.Assert;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.opendaylight.ovsdb.lib.OvsdbClient;
28 import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
29 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
30 import org.opendaylight.ovsdb.lib.notation.Mutator;
31 import org.opendaylight.ovsdb.lib.notation.UUID;
32 import org.opendaylight.ovsdb.lib.operations.OperationResult;
33 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
34 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
35 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
36 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
37 import org.opendaylight.ovsdb.lib.schema.TableSchema;
39 import com.google.common.collect.ImmutableMap;
40 import com.google.common.collect.Sets;
41 import com.google.common.util.concurrent.ListenableFuture;
43 public class OvsdbClientTestITTyped extends OvsdbTestBase {
46 DatabaseSchema dbSchema = null;
47 static String testBridgeName = "br_test";
48 static UUID testBridgeUuid = null;
51 * Test creation of statically typed bridge table as defined in
52 * ovs-vswitchd.conf.db with get/set for all relevant columns. The
53 * SETDATA methods for "name", "status" and "flood_vlans" columns
57 public void testTypedBridgeCreate() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
58 TestBridge rBridge = ovs.createTypedRowWrapper(TestBridge.class);
59 rBridge.setName(testBridgeName);
60 rBridge.setStatus(ImmutableMap.of("key","value"));
61 rBridge.setFloodVlans(Sets.newHashSet(34));
63 GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class);
64 ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn("bridges", UUID.class);
66 String namedUuid = "br_test";
67 int insertOperationIndex = 0;
69 TransactionBuilder transactionBuilder = ovs.transactBuilder(dbSchema)
70 .add(op.insert(rBridge)
72 .add(op.mutate(ovsTable)
73 .addMutation(bridges, Mutator.INSERT, Sets.newHashSet(new UUID(namedUuid))));
75 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
76 List<OperationResult> operationResults = results.get();
77 Assert.assertFalse(operationResults.isEmpty());
78 // Check if Results matches the number of operations in transaction
79 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
80 System.out.println("Insert & Update operation results = " + operationResults);
81 testBridgeUuid = operationResults.get(insertOperationIndex).getUuid();
84 public void testGetDBs() throws ExecutionException, InterruptedException {
85 ListenableFuture<List<String>> databases = ovs.getDatabases();
86 List<String> dbNames = databases.get();
87 Assert.assertNotNull(dbNames);
88 boolean hasOpenVswitchSchema = false;
89 for(String dbName : dbNames) {
90 if (dbName.equals(OPEN_VSWITCH_SCHEMA)) {
91 hasOpenVswitchSchema = true;
95 Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema);
99 public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
103 ovs = this.getTestConnection();
105 dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA).get();
109 public void tearDown() throws InterruptedException, ExecutionException {
110 TableSchema<GenericTableSchema> bridge = dbSchema.table("Bridge", GenericTableSchema.class);
111 ColumnSchema<GenericTableSchema, String> name = bridge.column("name", String.class);
112 GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class);
113 ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn("bridges", UUID.class);
115 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder(dbSchema)
116 .add(op.delete(bridge)
117 .where(name.opEqual(testBridgeName))
119 .add(op.mutate(ovsTable)
120 .addMutation(bridges, Mutator.DELETE, Sets.newHashSet(testBridgeUuid)))
121 .add(op.commit(true))
124 List<OperationResult> operationResults = results.get();
125 System.out.println("Delete operation results = " + operationResults);
126 OvsdbConnectionService.getService().disconnect(ovs);
130 public void update(Object node, UpdateNotification upadateNotification) {
131 // TODO Auto-generated method stub
135 public void locked(Object node, List<String> ids) {
136 // TODO Auto-generated method stub
140 public void stolen(Object node, List<String> ids) {
141 // TODO Auto-generated method stub