import static org.junit.Assert.assertTrue;
import java.util.List;
-
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerNotifyingDataChangeListener;
import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
private static final Logger LOG = LoggerFactory.getLogger(NodeInfo.class);
public static final String INTEGRATION_BRIDGE_NAME = "br-int";
- private ConnectionInfo connectionInfo;
- private InstanceIdentifier<Node> ovsdbIid;
- InstanceIdentifier<Node> bridgeIid;
+ private final ConnectionInfo connectionInfo;
+ private final InstanceIdentifier<Node> ovsdbIid;
+ private final InstanceIdentifier<Node> bridgeIid;
public long datapathId;
public Node ovsdbNode;
public Node bridgeNode;
- NotifyingDataChangeListener ovsdbWaiter;
- NotifyingDataChangeListener bridgeWaiter;
- List<NotifyingDataChangeListener> waitList;
- OvsdbItUtils itUtils;
+ private ControllerNotifyingDataChangeListener ovsdbWaiter;
+ private ControllerNotifyingDataChangeListener bridgeWaiter;
+ private final List<ControllerNotifyingDataChangeListener> waitList;
+ private final OvsdbItUtils itUtils;
/**
* Create a new NodeInfo object.
* @param itUtils OvsdbItUtils instance
* @param waitList for tracking outstanding md-sal events
*/
- NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils, List<NotifyingDataChangeListener> waitList) {
+ NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils,
+ List<ControllerNotifyingDataChangeListener> waitList) {
this.connectionInfo = connectionInfo;
this.itUtils = itUtils;
this.waitList = waitList;
bridgeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo, INTEGRATION_BRIDGE_NAME);
}
+ private void addWaiters() {
+ ovsdbWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ ControllerNotifyingDataChangeListener.BIT_CREATE, ovsdbIid, waitList);
+ ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker);
+ bridgeWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ ControllerNotifyingDataChangeListener.BIT_CREATE, bridgeIid, waitList);
+ bridgeWaiter.registerDataChangeListener(itUtils.dataBroker);
+ }
+
+ private void closeWaiters() throws Exception {
+ ovsdbWaiter.close();
+ bridgeWaiter.close();
+ }
+
/**
* Connect to the OVSDB node, wait for the connection to be established and for the integration bridge
* to be successfully created. Contains assertions for unexpected states
* @throws InterruptedException if interrupted while waiting for connection
*/
- public void connect() throws InterruptedException {
- ovsdbWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, ovsdbIid, waitList);
- ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker);
- bridgeWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, bridgeIid, waitList);
- bridgeWaiter.registerDataChangeListener(itUtils.dataBroker);
+ public void connect() throws Exception {
+ addWaiters();
assertNotNull("connection failed", itUtils.southboundUtils.addOvsdbNode(connectionInfo, 0));
* Remove integration bridge and teardown connection. Contains assertions for unexpected states.
* @throws InterruptedException if interrupted while waiting for disconnect to complete
*/
- public void disconnect() throws InterruptedException {
+ public void disconnect() throws Exception {
+ ovsdbWaiter.setMask(NotifyingDataChangeListener.BIT_DELETE);
+ bridgeWaiter.setMask(NotifyingDataChangeListener.BIT_DELETE);
assertTrue(itUtils.southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME, 0));
bridgeWaiter.waitForDeletion();
- Node bridgeNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
- assertNull("Bridge should not be found", bridgeNode);
+ assertNull("Bridge should not be found", itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid));
assertTrue(itUtils.southboundUtils.disconnectOvsdbNode(connectionInfo, 0));
ovsdbWaiter.waitForDeletion();
- Node ovsdbNode = itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbIid);
- assertNull("Ovsdb node should not be found", ovsdbNode);
+ assertNull("Ovsdb node should not be found",
+ itUtils.mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbIid));
+ closeWaiters();
}
-
}