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.error.SchemaVersionMismatchException;
22 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
23 import org.opendaylight.ovsdb.lib.notation.Mutator;
24 import org.opendaylight.ovsdb.lib.notation.UUID;
25 import org.opendaylight.ovsdb.lib.notation.Version;
26 import org.opendaylight.ovsdb.lib.operations.OperationResult;
27 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import java.io.IOException;
32 import java.util.List;
33 import java.util.concurrent.ExecutionException;
34 import java.util.concurrent.TimeoutException;
36 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
38 public class IpfixTestCases extends OpenVswitchSchemaTestBase {
40 Logger logger = LoggerFactory.getLogger(IpfixTestCases.class);
41 Version schemaVersion;
42 Version ipfixFromVersion = Version.fromString("7.1.0");
43 Version ipfixCacheFromVersion = Version.fromString("7.3.0");
46 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
48 schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
52 public void testTableNotSupported() {
53 // Don't run this test if we can run the IPFIX test
54 Assume.assumeTrue(schemaVersion.compareTo(ipfixFromVersion) < 0);
55 boolean isExceptionRaised = false;
57 IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
58 } catch (SchemaVersionMismatchException e) {
59 isExceptionRaised = true;
61 Assert.assertTrue(isExceptionRaised);
65 public void testCreateTypedIpFix() throws InterruptedException, ExecutionException, IllegalArgumentException{
66 // Don't run this test if the table is not supported
67 Assume.assumeTrue(schemaVersion.compareTo(ipfixFromVersion) >= 0);
68 String ipfixUuidStr = "testIpfix";
69 String ipfixTarget = "172.16.20.1:4739";
70 Long obsDomainId = 112L;
71 Long obsPointId = 358L;
73 Long cacheTimeout = 134L;
76 IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
77 ipfix.setTargets(ImmutableSet.of(ipfixTarget));
78 ipfix.setObsDomainId(ImmutableSet.of(obsDomainId));
79 ipfix.setObsPointId(ImmutableSet.of(obsPointId));
80 // Only set these rows if the schema version supports it
81 if (schemaVersion.compareTo(ipfixCacheFromVersion) >= 0) {
82 ipfix.setCacheMaxFlows(ImmutableSet.of(cacheMax));
83 ipfix.setCacheActiveTimeout(ImmutableSet.of(cacheTimeout));
85 ipfix.setSampling(ImmutableSet.of(sampling));
86 ipfix.setExternalIds(ImmutableMap.of("<3", "ovs"));
87 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
88 TransactionBuilder transactionBuilder = ovs.transactBuilder()
90 .withId(ipfixUuidStr))
91 .add(op.mutate(bridge.getSchema())
92 .addMutation(bridge.getIpfixColumn().getSchema(), Mutator.INSERT,
93 Sets.newHashSet(new UUID(ipfixUuidStr)))
94 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
96 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
97 List<OperationResult> operationResults = results.get();
98 Assert.assertFalse(operationResults.isEmpty());
99 // Check if Results matches the number of operations in transaction
100 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
101 for (OperationResult result : operationResults) Assert.assertNull(result.getError());
102 logger.info("Insert & Mutate operation results for IPFIX = {} ", operationResults);
106 public void update(Object context, UpdateNotification upadateNotification) {
111 public void locked(Object context, List<String> ids) {
116 public void stolen(Object context, List<String> ids) {