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;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 import com.google.common.collect.ImmutableMap;
42 import com.google.common.collect.Sets;
43 import com.google.common.util.concurrent.ListenableFuture;
45 public class OvsdbClientTestITTyped extends OvsdbTestBase {
47 Logger logger = LoggerFactory.getLogger(OvsdbClientTestITTyped.class);
49 DatabaseSchema dbSchema = null;
50 static String testBridgeName = "br_test";
51 static UUID testBridgeUuid = null;
54 * Test creation of statically typed bridge table as defined in
55 * ovs-vswitchd.conf.db with get/set for all relevant columns. The
56 * SETDATA methods for "name", "status" and "flood_vlans" columns
60 public void testTypedBridgeCreate() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
61 TestBridge rBridge = ovs.createTypedRowWrapper(TestBridge.class);
62 rBridge.setName(testBridgeName);
63 rBridge.setStatus(ImmutableMap.of("key","value"));
64 rBridge.setFloodVlans(Sets.newHashSet(34));
66 GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class);
67 ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn("bridges", UUID.class);
69 String namedUuid = "br_test";
70 int insertOperationIndex = 0;
72 TransactionBuilder transactionBuilder = ovs.transactBuilder(dbSchema)
73 .add(op.insert(rBridge)
75 .add(op.mutate(ovsTable)
76 .addMutation(bridges, Mutator.INSERT, Sets.newHashSet(new UUID(namedUuid))));
78 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
79 List<OperationResult> operationResults = results.get();
80 Assert.assertFalse(operationResults.isEmpty());
81 // Check if Results matches the number of operations in transaction
82 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
83 System.out.println("Insert & Update operation results = " + operationResults);
84 testBridgeUuid = operationResults.get(insertOperationIndex).getUuid();
87 public void testGetDBs() throws ExecutionException, InterruptedException {
88 ListenableFuture<List<String>> databases = ovs.getDatabases();
89 List<String> dbNames = databases.get();
90 Assert.assertNotNull(dbNames);
91 boolean hasOpenVswitchSchema = false;
92 for(String dbName : dbNames) {
93 if (dbName.equals(OPEN_VSWITCH_SCHEMA)) {
94 hasOpenVswitchSchema = true;
98 Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema);
102 public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
106 ovs = this.getTestConnection();
108 dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA).get();
112 public void tearDown() throws InterruptedException, ExecutionException {
113 TableSchema<GenericTableSchema> bridge = dbSchema.table("Bridge", GenericTableSchema.class);
114 ColumnSchema<GenericTableSchema, String> name = bridge.column("name", String.class);
115 GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class);
116 ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn("bridges", UUID.class);
118 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder(dbSchema)
119 .add(op.delete(bridge)
120 .where(name.opEqual(testBridgeName))
122 .add(op.mutate(ovsTable)
123 .addMutation(bridges, Mutator.DELETE, Sets.newHashSet(testBridgeUuid)))
124 .add(op.commit(true))
127 List<OperationResult> operationResults = results.get();
128 System.out.println("Delete operation results = " + operationResults);
129 OvsdbConnectionService.getService().disconnect(ovs);
133 public void update(Object node, UpdateNotification upadateNotification) {
134 // TODO Auto-generated method stub
138 public void locked(Object node, List<String> ids) {
139 // TODO Auto-generated method stub
143 public void stolen(Object node, List<String> ids) {
144 // TODO Auto-generated method stub