Normalize Bundle Naming
[ovsdb.git] / schemas / openvswitch / src / test / java / org / opendaylight / ovsdb / schema / openvswitch / FlowTableTestCases.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 : Brent Salisbury, Dave Tucker
9  */
10
11 package org.opendaylight.ovsdb.schema.openvswitch;
12
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;
29
30 import java.io.IOException;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.concurrent.ExecutionException;
35 import java.util.concurrent.TimeoutException;
36
37 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
38
39 public class FlowTableTestCases extends OpenVswitchSchemaTestBase {
40
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");
46
47     @Before
48     public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
49         super.setUp();
50         schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
51     }
52
53     @Test
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;
58         try {
59             FlowTable flowTable = ovs.createTypedRowWrapper(FlowTable.class);
60         } catch (SchemaVersionMismatchException e) {
61             isExceptionRaised = true;
62         }
63         Assert.assertTrue(isExceptionRaised);
64     }
65
66     @Test
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);
70
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));
85         }
86         if (schemaVersion.compareTo(externalIdAddedVerson) >= 0) {
87             flowTable.setExternalIds(ImmutableMap.of("I <3", "OVS"));
88         }
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))
97                         .build());
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);
105     }
106
107     @Override
108     public void update(Object context, UpdateNotification upadateNotification) {
109
110     }
111
112     @Override
113     public void locked(Object context, List<String> ids) {
114
115     }
116
117     @Override
118     public void stolen(Object context, List<String> ids) {
119
120     }
121 }