Search in sources :

Example 31 with Node

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;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(java.util.Optional) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)

Example 32 with Node

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);
    }
}
Also used : FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) SyncupEntry(org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 33 with Node

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;
}
Also used : FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 34 with Node

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;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) HashSet(java.util.HashSet)

Example 35 with Node

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);
}
Also used : Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ArrayList(java.util.ArrayList) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) NodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Before(org.junit.Before)

Aggregations

Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)112 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)58 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)56 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)54 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)43 Test (org.junit.Test)21 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)20 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)19 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)19 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)19 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)17 BigInteger (java.math.BigInteger)16 ArrayList (java.util.ArrayList)16 NodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder)16 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)15 Before (org.junit.Before)11 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)7 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)7 Optional (com.google.common.base.Optional)6