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.Before;
19 import org.junit.Test;
20 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
21 import org.opendaylight.ovsdb.lib.notation.Mutator;
22 import org.opendaylight.ovsdb.lib.notation.UUID;
23 import org.opendaylight.ovsdb.lib.operations.OperationResult;
24 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import java.io.IOException;
29 import java.util.List;
30 import java.util.concurrent.ExecutionException;
31 import java.util.concurrent.TimeoutException;
33 import static org.junit.Assert.assertNull;
34 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
36 public class SflowTestCases extends OpenVswitchSchemaTestBase {
38 Logger logger = LoggerFactory.getLogger(SflowTestCases.class);
41 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
46 public void testCreateTypedSflow() throws InterruptedException, ExecutionException, IllegalArgumentException{
47 String sFlowUuidStr = "testSFlow";
48 String sFlowTarget = "172.16.20.200:6343";
50 Integer obsPointId = 358;
52 String agent = "172.16.20.210";
53 Integer sampling = 64;
54 SFlow sFlow = ovs.createTypedRowWrapper(SFlow.class);
55 sFlow.setTargets(ImmutableSet.of(sFlowTarget));
56 sFlow.setHeader(ImmutableSet.of(header));
57 sFlow.setPolling(ImmutableSet.of(obsPointId));
58 sFlow.setPolling(ImmutableSet.of(polling));
59 sFlow.setAgent(ImmutableSet.of(agent));
60 sFlow.setSampling(ImmutableSet.of(sampling));
61 sFlow.setExternalIds(ImmutableMap.of("kit", "tah"));
62 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
63 TransactionBuilder transactionBuilder = ovs.transactBuilder()
64 .add(op.insert(sFlow.getSchema())
66 .value(sFlow.getTargetsColumn())
67 .value(sFlow.getHeaderColumn())
68 .value(sFlow.getPollingColumn())
69 .value(sFlow.getAgentColumn())
70 .value(sFlow.getSamplingColumn())
71 .value(sFlow.getExternalIdsColumn()))
72 .add(op.mutate(bridge.getSchema())
73 .addMutation(bridge.getSflowColumn().getSchema(), Mutator.INSERT,
74 Sets.newHashSet(new UUID(sFlowUuidStr)))
75 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
77 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
78 List<OperationResult> operationResults = results.get();
79 for (OperationResult result : operationResults) {
80 assertNull(result.getError());
82 Assert.assertFalse(operationResults.isEmpty());
83 // Check if Results matches the number of operations in transaction
84 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
85 logger.info("Insert & Mutate operation results for SFlow = {} ", operationResults);
89 public void update(Object context, UpdateNotification upadateNotification) {
94 public void locked(Object context, List<String> ids) {
99 public void stolen(Object context, List<String> ids) {