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.collect.Sets;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import junit.framework.Assert;
18 import org.junit.Assume;
19 import org.junit.Before;
20 import org.junit.Test;
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.List;
32 import java.util.concurrent.ExecutionException;
33 import java.util.concurrent.TimeoutException;
35 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
37 public class IpfixTestCases extends OpenVswitchSchemaTestBase {
39 Logger logger = LoggerFactory.getLogger(IpfixTestCases.class);
40 Version schemaVersion;
41 Version ipfixFromVersion = Version.fromString("7.3.0");
45 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
47 schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
50 @Test(expected=RuntimeException.class)
51 public void testUnsupportedTable() {
52 // Don't run this test if we can run the IPFIX test
53 Assume.assumeTrue(schemaVersion.compareTo(ipfixFromVersion) < 0);
54 IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
55 ipfix.setTargets(ImmutableSet.of("1.1.1.1:9988"));
59 public void testCreateTypedIpFix() throws InterruptedException, ExecutionException, IllegalArgumentException{
60 // Don't run this test if the table is not supported
61 Assume.assumeTrue(schemaVersion.compareTo(ipfixFromVersion) >= 0);
63 String ipfixUuidStr = "testIpfix";
64 String ipfixTarget = "172.16.20.1:4739";
65 Integer obsDomainId = 112;
66 Integer obsPointId = 358;
67 Integer cacheMax = 132;
68 Integer cacheTimeout = 134;
69 Integer sampling = 558;
71 IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
72 ipfix.setTargets(ImmutableSet.of(ipfixTarget));
73 ipfix.setObsDomainId(ImmutableSet.of(obsDomainId));
74 ipfix.setObsPointId(ImmutableSet.of(obsPointId));
75 ipfix.setCacheMaxFlows(ImmutableSet.of(cacheMax));
76 ipfix.setCacheActiveTimeout(ImmutableSet.of(cacheTimeout));
77 ipfix.setSampling(ImmutableSet.of(sampling));
78 ipfix.setExternalIds(ImmutableMap.of("<3", "ovs"));
79 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
80 TransactionBuilder transactionBuilder = ovs.transactBuilder()
81 .add(op.insert(ipfix.getSchema())
83 .value(ipfix.getTargetsColumn())
84 .value(ipfix.getObsDomainIdColumn())
85 .value(ipfix.getObsPointIdColumn())
86 .value(ipfix.getCacheMaxFlowsColumn())
87 .value(ipfix.getCacheActiveTimeoutColumn())
88 .value(ipfix.getSamplingColumn())
89 .value(ipfix.getExternalIdsColumn()))
90 .add(op.mutate(bridge.getSchema())
91 .addMutation(bridge.getIpfixColumn().getSchema(), Mutator.INSERT,
92 Sets.newHashSet(new UUID(ipfixUuidStr)))
93 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
95 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
96 List<OperationResult> operationResults = results.get();
97 Assert.assertFalse(operationResults.isEmpty());
98 // Check if Results matches the number of operations in transaction
99 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
100 for (OperationResult result : operationResults) Assert.assertNull(result.getError());
101 logger.info("Insert & Mutate operation results for IPFIX = {} ", operationResults);
105 public void update(Object context, UpdateNotification upadateNotification) {
110 public void locked(Object context, List<String> ids) {
115 public void stolen(Object context, List<String> ids) {