use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method _removeMDFlow.
public void _removeMDFlow(final CommandInterpreter ci) {
final ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
final NodeBuilder tn = createTestNode(ci.nextArgument());
final String flowtype = ci.nextArgument();
FlowBuilder tf;
if (flowtype.equals("fTM")) {
tf = createtablemiss();
} else {
tf = createTestFlow(tn, flowtype, ci.nextArgument());
}
final InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId())).child(Flow.class, tf.getKey());
modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
final CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(final Void notUsed) {
ci.println("Status of Group Data Loaded Transaction: success.");
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error(throwable.getMessage(), throwable);
ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.
the class NodeChangeListenerImplTest method testOnNodeAdded.
@Test
public void testOnNodeAdded() {
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey("node1");
InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nodeKey);
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, invNodeID);
nodeChangeListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch);
ArgumentCaptor<Node> mergedNode = ArgumentCaptor.forClass(Node.class);
NodeId expNodeId = new NodeId("node1");
verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(topologyIID.child(Node.class, new NodeKey(expNodeId))), mergedNode.capture(), eq(true));
assertEquals("getNodeId", expNodeId, mergedNode.getValue().getNodeId());
InventoryNode augmentation = mergedNode.getValue().getAugmentation(InventoryNode.class);
assertNotNull("Missing augmentation", augmentation);
assertEquals("getInventoryNodeRef", new NodeRef(invNodeID), augmentation.getInventoryNodeRef());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.
the class NodeChangeListenerImplTest method testOnNodeRemoved.
@SuppressWarnings({ "rawtypes" })
@Test
public void testOnNodeRemoved() {
NodeKey topoNodeKey = new NodeKey(new NodeId("node1"));
final InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
Node topoNode = new NodeBuilder().setKey(topoNodeKey).build();
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
final InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nodeKey);
List<Link> linkList = Arrays.asList(newLink("link1", newSourceNode("node1"), newDestNode("dest")), newLink("link2", newSourceNode("source"), newDestNode("node1")), newLink("link2", newSourceNode("source2"), newDestNode("dest2")));
final Topology topology = new TopologyBuilder().setLink(linkList).build();
final InstanceIdentifier[] expDeletedIIDs = { topologyIID.child(Link.class, linkList.get(0).getKey()), topologyIID.child(Link.class, linkList.get(1).getKey()), topologyIID.child(Node.class, new NodeKey(new NodeId("node1"))) };
SettableFuture<Optional<Topology>> readFuture = SettableFuture.create();
readFuture.set(Optional.of(topology));
ReadWriteTransaction mockTx1 = mock(ReadWriteTransaction.class);
doReturn(Futures.makeChecked(readFuture, ReadFailedException.MAPPER)).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
SettableFuture<Optional<Node>> readFutureNode = SettableFuture.create();
readFutureNode.set(Optional.of(topoNode));
doReturn(Futures.makeChecked(readFutureNode, ReadFailedException.MAPPER)).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
final CountDownLatch submitLatch1 = setupStubbedSubmit(mockTx1);
int expDeleteCalls = expDeletedIIDs.length;
CountDownLatch deleteLatch = new CountDownLatch(expDeleteCalls);
ArgumentCaptor<InstanceIdentifier> deletedLinkIDs = ArgumentCaptor.forClass(InstanceIdentifier.class);
setupStubbedDeletes(mockTx1, deletedLinkIDs, deleteLatch);
doReturn(mockTx1).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(DELETE, invNodeID);
nodeChangeListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch1);
setReadFutureAsync(topology, readFuture);
waitForDeletes(expDeleteCalls, deleteLatch);
assertDeletedIDs(expDeletedIIDs, deletedLinkIDs);
verifyMockTx(mockTx1);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.
the class NodeChangeListenerImplTest method testOnNodeRemovedWithNoTopology.
@SuppressWarnings({ "rawtypes" })
@Test
public void testOnNodeRemovedWithNoTopology() {
NodeKey topoNodeKey = new NodeKey(new NodeId("node1"));
InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
Node topoNode = new NodeBuilder().setKey(topoNodeKey).build();
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
final InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nodeKey);
final InstanceIdentifier[] expDeletedIIDs = { topologyIID.child(Node.class, new NodeKey(new NodeId("node1"))) };
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(mockTx).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
final CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
SettableFuture<Optional<Node>> readFutureNode = SettableFuture.create();
readFutureNode.set(Optional.of(topoNode));
doReturn(Futures.makeChecked(readFutureNode, ReadFailedException.MAPPER)).when(mockTx).read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
CountDownLatch deleteLatch = new CountDownLatch(1);
ArgumentCaptor<InstanceIdentifier> deletedLinkIDs = ArgumentCaptor.forClass(InstanceIdentifier.class);
setupStubbedDeletes(mockTx, deletedLinkIDs, deleteLatch);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(DELETE, invNodeID);
nodeChangeListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch);
waitForDeletes(1, deleteLatch);
assertDeletedIDs(expDeletedIIDs, deletedLinkIDs);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.
the class FlowCapableTopologyExporterTest method testOnLinkDiscovered.
@Test
public void testOnLinkDiscovered() {
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey sourceNodeKey = newInvNodeKey("sourceNode");
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey sourceNodeConnKey = newInvNodeConnKey("sourceTP");
InstanceIdentifier<?> sourceConnID = newNodeConnID(sourceNodeKey, sourceNodeConnKey);
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey destNodeKey = newInvNodeKey("destNode");
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey destNodeConnKey = newInvNodeConnKey("destTP");
InstanceIdentifier<?> destConnID = newNodeConnID(destNodeKey, destNodeConnKey);
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
exporter.onLinkDiscovered(new LinkDiscoveredBuilder().setSource(new NodeConnectorRef(sourceConnID)).setDestination(new NodeConnectorRef(destConnID)).build());
waitForSubmit(submitLatch);
ArgumentCaptor<Link> mergedNode = ArgumentCaptor.forClass(Link.class);
verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(topologyIID.child(Link.class, new LinkKey(new LinkId(sourceNodeConnKey.getId())))), mergedNode.capture(), eq(true));
assertEquals("Source node ID", "sourceNode", mergedNode.getValue().getSource().getSourceNode().getValue());
assertEquals("Dest TP ID", "sourceTP", mergedNode.getValue().getSource().getSourceTp().getValue());
assertEquals("Dest node ID", "destNode", mergedNode.getValue().getDestination().getDestNode().getValue());
assertEquals("Dest TP ID", "destTP", mergedNode.getValue().getDestination().getDestTp().getValue());
}
Aggregations