Disable netvirt
[ovsdb.git] / utils / it-utils / src / main / java / org / opendaylight / ovsdb / utils / it / utils / NodeInfo.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others.  All rights reserved.
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
9 package org.opendaylight.ovsdb.utils.it.utils;
10
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.util.List;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
19 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Utility class for connections to an OVSDB node. Contains various info for the node
28  * as public data members.
29  */
30 public class NodeInfo {
31     private static final Logger LOG = LoggerFactory.getLogger(NodeInfo.class);
32     public static final String INTEGRATION_BRIDGE_NAME = "br-int";
33
34     private ConnectionInfo connectionInfo;
35     private InstanceIdentifier<Node> ovsdbIid;
36     InstanceIdentifier<Node> bridgeIid;
37     public long datapathId;
38     public Node ovsdbNode;
39     public Node bridgeNode;
40     NotifyingDataChangeListener ovsdbWaiter;
41     NotifyingDataChangeListener bridgeWaiter;
42     List<NotifyingDataChangeListener> waitList;
43     ItUtils itUtils;
44
45     /**
46      * Create a new NodeInfo object
47      * @param connectionInfo of the OVSDB node
48      * @param itUtils ItUtils instance
49      * @param waitList for tracking outstanding md-sal events
50      */
51     NodeInfo(ConnectionInfo connectionInfo, ItUtils itUtils, List<NotifyingDataChangeListener> waitList) {
52         this.connectionInfo = connectionInfo;
53         this.itUtils = itUtils;
54         this.waitList = waitList;
55         ovsdbIid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
56         bridgeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo, INTEGRATION_BRIDGE_NAME);
57     }
58
59     /**
60      * Connect to the OVSDB node, wait for the connection to be established and for the integration bridge
61      * to be successfully created. Contains assertions for unexpected states
62      * @throws InterruptedException
63      */
64     public void connect() throws InterruptedException {
65         ovsdbWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, ovsdbIid, waitList);
66         ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker);
67         bridgeWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, bridgeIid, waitList);
68         bridgeWaiter.registerDataChangeListener(itUtils.dataBroker);
69
70         assertNotNull("connection failed", itUtils.southboundUtils.addOvsdbNode(connectionInfo, 0));
71
72         ovsdbWaiter.waitForCreation();
73         ovsdbNode = itUtils.southboundUtils.getOvsdbNode(connectionInfo);
74         assertNotNull("node is not connected", ovsdbNode);
75
76         bridgeWaiter.waitForCreation();
77         assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
78                 + " is not connected", itUtils.isControllerConnected(connectionInfo));
79
80         bridgeNode = itUtils.southboundUtils.getBridgeNode(ovsdbNode, INTEGRATION_BRIDGE_NAME);
81         assertNotNull("bridge " + INTEGRATION_BRIDGE_NAME + " was not found", bridgeNode);
82         datapathId = itUtils.southboundUtils.getDataPathId(bridgeNode);
83         String datapathIdString = itUtils.southboundUtils.getDatapathId(bridgeNode);
84         LOG.info("testNetVirt: bridgeNode: {}, datapathId: {} - {}", bridgeNode, datapathIdString, datapathId);
85         assertNotEquals("datapathId was not found", datapathId, 0);
86     }
87
88     /**
89      * Remove integration bridge and teardown connection. Contains assertions for unexpected states.
90      * @throws InterruptedException
91      */
92     public void disconnect() throws InterruptedException {
93         assertTrue(itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0));
94         itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0);
95         bridgeWaiter.waitForDeletion();
96         Node bridgeNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
97         assertNull("Bridge should not be found", bridgeNode);
98         assertTrue(itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0));
99         itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0);
100         ovsdbWaiter.waitForDeletion();
101         Node ovsdbNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbIid);
102         assertNull("Ovsdb node should not be found", ovsdbNode);
103     }
104
105 }