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 : Brent Salisbury, Dave Tucker
11 package org.opendaylight.ovsdb.schema.openvswitch;
13 import com.google.common.collect.ImmutableMap;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import junit.framework.Assert;
17 import org.junit.Assume;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
21 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
22 import org.opendaylight.ovsdb.lib.notation.Mutator;
23 import org.opendaylight.ovsdb.lib.notation.UUID;
24 import org.opendaylight.ovsdb.lib.notation.Version;
25 import org.opendaylight.ovsdb.lib.operations.OperationResult;
26 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import java.io.IOException;
31 import java.util.HashMap;
32 import java.util.List;
34 import java.util.concurrent.ExecutionException;
35 import java.util.concurrent.TimeoutException;
37 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
39 public class FlowTableTestCases extends OpenVswitchSchemaTestBase {
41 Logger logger = LoggerFactory.getLogger(IpfixTestCases.class);
42 Version schemaVersion;
43 Version flowTableFromVersion = Version.fromString("6.5.0");
44 Version prefixesAddedVersion = Version.fromString("7.4.0");
45 Version externalIdAddedVerson = Version.fromString("7.5.0");
48 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
50 schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
54 public void testTableNotSupported() {
55 // Don't run this test if the table is supported
56 Assume.assumeTrue(schemaVersion.compareTo(flowTableFromVersion) < 0);
57 boolean isExceptionRaised = false;
59 FlowTable flowTable = ovs.createTypedRowWrapper(FlowTable.class);
60 } catch (SchemaVersionMismatchException e) {
61 isExceptionRaised = true;
63 Assert.assertTrue(isExceptionRaised);
67 public void testCreateTypeFlowTable() throws InterruptedException, ExecutionException, IllegalArgumentException{
68 // Don't run this test if the table is not supported
69 Assume.assumeTrue(schemaVersion.compareTo(flowTableFromVersion) >= 0);
71 String flowTableUuidStr = "testFlowTable";
72 String tableName = "flow_table_row_name";
73 String overflowPolicy = "evict";
74 String groups = "group name";
75 String prefixes = "wildcarding prefixes";
76 Long flowLimit = 50000L;
77 Map<Long, UUID> flowTableBrRef = new HashMap<>();
78 flowTableBrRef.put(1L, new UUID(flowTableUuidStr));
79 FlowTable flowTable = ovs.createTypedRowWrapper(FlowTable.class);
80 flowTable.setName(ImmutableSet.of(tableName));
81 flowTable.setOverflowPolicy(ImmutableSet.of(overflowPolicy));
82 flowTable.setGroups(ImmutableSet.of(groups));
83 if (schemaVersion.compareTo(prefixesAddedVersion) >= 0) {
84 flowTable.setPrefixes(ImmutableSet.of(prefixes));
86 if (schemaVersion.compareTo(externalIdAddedVerson) >= 0) {
87 flowTable.setExternalIds(ImmutableMap.of("I <3", "OVS"));
89 flowTable.setFlowLimit(ImmutableSet.of(flowLimit));
90 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
91 TransactionBuilder transactionBuilder = ovs.transactBuilder(OpenVswitchSchemaSuiteIT.dbSchema)
92 .add(op.insert(flowTable)
93 .withId(flowTableUuidStr))
94 .add(op.mutate(bridge.getSchema())
95 .addMutation(bridge.getFlowTablesColumn().getSchema(), Mutator.INSERT,(flowTableBrRef))
96 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
98 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
99 List<OperationResult> operationResults = results.get();
100 for (OperationResult result : operationResults) Assert.assertNull(result.getError());
101 Assert.assertFalse(operationResults.isEmpty());
102 // Check if Results matches the number of operations in transaction
103 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
104 logger.info("Insert & Mutate operation results for Flow Table = {} ", operationResults);
108 public void update(Object context, UpdateNotification upadateNotification) {
113 public void locked(Object context, List<String> ids) {
118 public void stolen(Object context, List<String> ids) {