use of Nodes.Node in project openflowplugin by opendaylight.
the class ForwardingRulesManagerImpl method checkNodeInOperationalDataStore.
@Override
public boolean checkNodeInOperationalDataStore(InstanceIdentifier<FlowCapableNode> ident) {
boolean result = false;
InstanceIdentifier<Node> nodeIid = ident.firstIdentifierOf(Node.class);
final ReadOnlyTransaction transaction = dataService.newReadOnlyTransaction();
CheckedFuture<com.google.common.base.Optional<Node>, ReadFailedException> future = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeIid);
try {
com.google.common.base.Optional<Node> optionalDataObject = future.checkedGet();
if (optionalDataObject.isPresent()) {
result = true;
} else {
LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], nodeIid);
}
} catch (ReadFailedException e) {
LOG.warn("Failed to read {} ", nodeIid, e);
}
transaction.close();
return result;
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class SimplifiedOperationalListener method reconciliation.
/**
* If node is present in config DS diff between wanted configuration (in config DS) and actual device
* configuration (coming from operational) should be calculated and sent to device.
* @param modification from DS
* @return optional syncup future
*/
private Optional<ListenableFuture<Boolean>> reconciliation(final DataTreeModification<Node> modification) {
final NodeId nodeId = ModificationUtil.nodeId(modification);
final Optional<FlowCapableNode> nodeConfiguration = configDao.loadByNodeId(nodeId);
if (nodeConfiguration.isPresent()) {
LOG.debug("Reconciliation {}: {}", dsType(), nodeId.getValue());
final InstanceIdentifier<FlowCapableNode> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(ModificationUtil.nodeId(modification))).augmentation(FlowCapableNode.class);
final FlowCapableNode fcOperationalNode = ModificationUtil.flowCapableNodeAfter(modification);
final SyncupEntry syncupEntry = new SyncupEntry(nodeConfiguration.get(), LogicalDatastoreType.CONFIGURATION, fcOperationalNode, dsType());
return Optional.of(reactor.syncup(nodePath, syncupEntry));
} else {
LOG.debug("Config not present for reconciliation: {}", nodeId.getValue());
reconciliationRegistry.unregisterIfRegistered(nodeId);
return skipModification(modification);
}
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class SimplifiedOperationalListener method processNodeModification.
/**
* Update cache, register for device mastership when device connected and start reconciliation if device
* is registered and actual modification is consistent.Skip the event otherwise.
*/
@Override
protected Optional<ListenableFuture<Boolean>> processNodeModification(final DataTreeModification<Node> modification) {
Optional<ListenableFuture<Boolean>> result;
final NodeId nodeId = ModificationUtil.nodeId(modification);
final DataObjectModification<Node> nodeModification = modification.getRootNode();
if (isDelete(nodeModification) || isDeleteLogical(nodeModification)) {
operationalSnapshot.updateCache(nodeId, Optional.absent());
deviceMastershipManager.onDeviceDisconnected(nodeId);
result = skipModification(modification);
} else {
operationalSnapshot.updateCache(nodeId, Optional.fromNullable(ModificationUtil.flowCapableNodeAfter(modification)));
final boolean isAdd = isAdd(nodeModification) || isAddLogical(nodeModification);
if (isAdd) {
deviceMastershipManager.onDeviceConnected(nodeId);
}
// one step on startup
if (reconciliationRegistry.isRegistered(nodeId) && (isAdd || isConsistentForReconcile(modification))) {
result = reconciliation(modification);
} else {
result = skipModification(modification);
}
}
return result;
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class FlowWriterDirectOFRpc method getAllNodes.
private Set<String> getAllNodes() {
Set<String> nodeIds = new HashSet<>();
InstanceIdentifier<Nodes> nodes = InstanceIdentifier.create(Nodes.class);
ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
try {
Optional<Nodes> nodesDataNode = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodes).checkedGet();
if (nodesDataNode.isPresent()) {
List<Node> nodesCollection = nodesDataNode.get().getNode();
if (nodesCollection != null && !nodesCollection.isEmpty()) {
for (Node node : nodesCollection) {
LOG.info("Switch with ID {} discovered !!", node.getId().getValue());
nodeIds.add(node.getId().getValue());
}
} else {
return Collections.emptySet();
}
} else {
return Collections.emptySet();
}
} catch (ReadFailedException rdFailedException) {
LOG.error("Failed to read connected nodes {}", rdFailedException);
}
return nodeIds;
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class FlowWriterDirectOFRpcTest method setUp.
@Before
public void setUp() throws Exception {
doReturn(RpcResultBuilder.success().buildFuture()).when(mockSalFlowService).addFlow(any());
when(mockDataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
NodeBuilder nodeBuilder = new NodeBuilder().setId(new NodeId("1"));
final List<Node> nodes = new ArrayList<>();
final Node node = nodeBuilder.build();
nodes.add(node);
when(mockNodes.getNode()).thenReturn(nodes);
when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Nodes>>any())).thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
Mockito.doAnswer(invocation -> {
((Runnable) invocation.getArguments()[0]).run();
return null;
}).when(mockFlowPusher).execute(Matchers.<Runnable>any());
flowWriterDirectOFRpc = new FlowWriterDirectOFRpc(mockDataBroker, mockSalFlowService, mockFlowPusher);
}
Aggregations