2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal
10 package org.opendaylight.ovsdb.schema.openvswitch;
12 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
14 import java.io.IOException;
15 import java.lang.reflect.InvocationTargetException;
16 import java.util.List;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
21 import junit.framework.Assert;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.ovsdb.lib.OvsDBClientImpl;
27 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
28 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
29 import org.opendaylight.ovsdb.lib.notation.Mutator;
30 import org.opendaylight.ovsdb.lib.notation.UUID;
31 import org.opendaylight.ovsdb.lib.operations.OperationResult;
32 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
33 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import com.google.common.collect.ImmutableMap;
38 import com.google.common.collect.Sets;
39 import com.google.common.util.concurrent.ListenableFuture;
41 public class TypedVSwitchdSchemaIT extends OvsdbTestBase {
43 Logger logger = LoggerFactory.getLogger(TypedVSwitchdSchemaIT.class);
45 DatabaseSchema dbSchema = null;
46 static String testBridgeName = "br_test";
47 static UUID testBridgeUuid = null;
50 public void testTypedBridgeOperations() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
51 this.createTypedBridge();
54 private void createTypedBridge() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
55 Bridge bridge = ovs.createTypedRowWrapper(Bridge.class);
56 bridge.setName(testBridgeName);
57 bridge.setStatus(ImmutableMap.of("key","value"));
58 bridge.setFloodVlans(Sets.newHashSet(34));
60 OpenVSwitch openVSwitch = ovs.createTypedRowWrapper(OpenVSwitch.class);
61 openVSwitch.setBridges(Sets.newHashSet(new UUID(testBridgeName)));
63 int insertOperationIndex = 0;
65 TransactionBuilder transactionBuilder = ovs.transactBuilder()
66 .add(op.insert(bridge.getSchema())
67 .withId(testBridgeName)
68 .value(bridge.getNameColumn()))
69 .add(op.update(bridge.getSchema())
70 .set(bridge.getStatusColumn())
71 .set(bridge.getFloodVlansColumn())
72 .where(bridge.getNameColumn().getSchema().opEqual(bridge.getName()))
73 .and(bridge.getNameColumn().getSchema().opEqual(bridge.getName())).build())
74 .add(op.mutate(openVSwitch.getSchema())
75 .addMutation(openVSwitch.getBridgesColumn().getSchema(), Mutator.INSERT,
76 openVSwitch.getBridgesColumn().getData()));
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();
86 public void testGetDBs() throws ExecutionException, InterruptedException {
87 ListenableFuture<List<String>> databases = ovs.getDatabases();
88 List<String> dbNames = databases.get();
89 Assert.assertNotNull(dbNames);
90 boolean hasOpenVswitchSchema = false;
91 for(String dbName : dbNames) {
92 if (dbName.equals(OPEN_VSWITCH_SCHEMA)) {
93 hasOpenVswitchSchema = true;
97 Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema);
101 public void setUp() throws IOException, ExecutionException, InterruptedException {
105 OvsdbRPC rpc = getTestConnection();
107 System.out.println("Unable to Establish Test Connection");
109 ExecutorService executorService = Executors.newFixedThreadPool(3);
110 ovs = new OvsDBClientImpl(rpc, executorService);
112 dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get();
116 public void tearDown() throws InterruptedException, ExecutionException {
117 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
118 OpenVSwitch openVSwitch = ovs.getTypedRowWrapper(OpenVSwitch.class, null);
120 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
121 .add(op.delete(bridge.getSchema())
122 .where(bridge.getNameColumn().getSchema().opEqual(testBridgeName))
124 .add(op.mutate(openVSwitch.getSchema())
125 .addMutation(openVSwitch.getBridgesColumn().getSchema(), Mutator.DELETE, Sets.newHashSet(testBridgeUuid)))
126 .add(op.commit(true))
129 List<OperationResult> operationResults = results.get();
130 System.out.println("Delete operation results = " + operationResults);
134 public void update(Object node, UpdateNotification upadateNotification) {
135 // TODO Auto-generated method stub
139 public void locked(Object node, List<String> ids) {
140 // TODO Auto-generated method stub
144 public void stolen(Object node, List<String> ids) {
145 // TODO Auto-generated method stub