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 : 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.opendaylight.ovsdb.lib.operations.Operations.op;
35 public class PortAndInterfaceTestCases extends OpenVswitchSchemaTestBase {
37 Logger logger = LoggerFactory.getLogger(PortAndInterfaceTestCases.class);
40 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
46 public void testCreateTypedPortandInterface() throws InterruptedException, ExecutionException {
47 String portUuidStr = "testPort";
48 String intfUuidStr = "testIntf";
49 Port port = ovs.createTypedRowWrapper(Port.class);
50 port.setName("testPort");
51 port.setTag(ImmutableSet.of(1L));
52 port.setMac(ImmutableSet.of("00:00:00:00:00:01"));
53 port.setInterfaces(ImmutableSet.of(new UUID(intfUuidStr)));
55 Interface intf = ovs.createTypedRowWrapper(Interface.class);
56 intf.setName(port.getNameColumn().getData());
57 intf.setExternalIds(ImmutableMap.of("vm-id", "12345abcedf78910"));
59 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
60 TransactionBuilder transactionBuilder = ovs.transactBuilder(OpenVswitchSchemaSuiteIT.dbSchema)
61 .add(op.insert(port.getSchema())
63 .value(port.getNameColumn())
64 .value(port.getMacColumn()))
65 .add(op.insert(intf.getSchema())
67 .value(intf.getNameColumn()))
68 .add(op.update(port.getSchema())
69 .set(port.getTagColumn())
70 .set(port.getMacColumn())
71 .set(port.getInterfacesColumn())
72 .where(port.getNameColumn().getSchema().opEqual(port.getName()))
74 .add(op.update(intf.getSchema())
75 .set(intf.getExternalIdsColumn())
76 .where(intf.getNameColumn().getSchema().opEqual(intf.getName()))
78 .add(op.mutate(bridge.getSchema())
79 .addMutation(bridge.getPortsColumn().getSchema(), Mutator.INSERT, Sets.newHashSet(new UUID(portUuidStr)))
80 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
82 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
83 List<OperationResult> operationResults = results.get();
84 Assert.assertFalse(operationResults.isEmpty());
85 // Check if Results matches the number of operations in transaction
86 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
87 logger.info("Insert & Mutate operation results for Port and Interface = " + operationResults);
91 public void update(Object context, UpdateNotification upadateNotification) {
96 public void locked(Object context, List<String> ids) {
101 public void stolen(Object context, List<String> ids) {