Search in sources :

Example 51 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project openflowplugin by opendaylight.

the class ShellUtil method getAllNodes.

@Nonnull
public static List<OFNode> getAllNodes(final DataBroker broker) {
    List<Node> nodes = null;
    ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
    InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).build();
    try {
        CheckedFuture<Optional<Nodes>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
        Optional<Nodes> result = checkedFuture.get();
        if (result.isPresent()) {
            nodes = result.get().getNode();
        }
    } catch (ExecutionException | InterruptedException | NullPointerException e) {
        LOG.error("Error reading nodes from Inventory DS", e);
    }
    if (nodes != null) {
        List<OFNode> nodeList = new ArrayList<>();
        for (Node node : nodes) {
            String[] nodeId = node.getId().getValue().split(":");
            String name = null;
            FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
            if (flowCapableNode != null) {
                name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
            } else {
                LOG.error("Error while converting OFNode: {} to FlowCapableNode", node.getId());
                return Collections.emptyList();
            }
            OFNode ofNode = new OFNode(Long.parseLong(nodeId[1]), name);
            LOG.trace("Added OFNode: {} to the list", ofNode.getNodeId());
            nodeList.add(ofNode);
        }
        Collections.sort(nodeList);
        return nodeList;
    }
    return Collections.emptyList();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.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) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ArrayList(java.util.ArrayList) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExecutionException(java.util.concurrent.ExecutionException) Nonnull(javax.annotation.Nonnull)

Example 52 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project openflowplugin by opendaylight.

the class FlowReader method readFlowsX.

private void readFlowsX() {
    readOpStatus.set(FlowCounter.OperationStatus.IN_PROGRESS.status());
    for (int i = 1; i <= dpnCount; i++) {
        String dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + i;
        for (int j = 0; j < flowsPerDpn; j++) {
            short tableRollover = (short) (endTableId - startTableId + 1);
            short tableId = (short) (j % tableRollover + startTableId);
            Integer sourceIp = j + 1;
            String flowId = "Flow-" + dpId + "." + tableId + "." + sourceIp;
            InstanceIdentifier<Flow> flowIid = getFlowInstanceIdentifier(dpId, tableId, flowId);
            ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
            try {
                Optional<Flow> flowOptional;
                if (isConfigDs) {
                    flowOptional = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, flowIid).checkedGet();
                } else {
                    flowOptional = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, flowIid).checkedGet();
                }
                if (flowOptional.isPresent()) {
                    flowCount.incrementAndGet();
                    if (verbose) {
                        LOG.info("Flow found: {}", flowOptional.get());
                    }
                } else {
                    if (verbose) {
                        LOG.info("Flow: {} not found", flowIid);
                    }
                }
            } catch (ReadFailedException e) {
                readOpStatus.set(FlowCounter.OperationStatus.FAILURE.status());
                LOG.error(e.getMessage(), e);
            }
        }
    }
    if (readOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
        readOpStatus.set(FlowCounter.OperationStatus.SUCCESS.status());
    }
    LOG.info("Total Flows read: {}", flowCount);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 53 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project openflowplugin by opendaylight.

the class OpenflowpluginStatsTestCommandProvider method _tableStats.

public void _tableStats(CommandInterpreter ci) {
    int tableCount = 0;
    int tableStatsCount = 0;
    List<Node> nodes = getNodes();
    for (Node node2 : nodes) {
        NodeKey nodeKey = node2.getKey();
        InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
        FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
        if (node != null) {
            List<Table> tables = node.getTable();
            for (Table table2 : tables) {
                tableCount++;
                TableKey tableKey = table2.getKey();
                InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
                Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                if (table != null) {
                    FlowTableStatisticsData data = table.getAugmentation(FlowTableStatisticsData.class);
                    if (null != data) {
                        tableStatsCount++;
                    }
                }
            }
        }
    }
    if (tableCount == tableStatsCount) {
        LOG.debug("tableStats - Success");
    } else {
        LOG.debug("tableStats - Failed");
        LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
    }
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowTableStatisticsData(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 54 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project openflowplugin by opendaylight.

the class OpenflowpluginStatsTestCommandProvider method _aggregateStats.

public void _aggregateStats(CommandInterpreter ci) {
    int aggregateFlowCount = 0;
    int aggerateFlowStatsCount = 0;
    List<Node> nodes = getNodes();
    for (Node node2 : nodes) {
        NodeKey nodeKey = node2.getKey();
        InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
        FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
        if (node != null) {
            List<Table> tables = node.getTable();
            for (Table table2 : tables) {
                aggregateFlowCount++;
                TableKey tableKey = table2.getKey();
                InstanceIdentifier<Table> tableRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
                Table table = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, tableRef);
                if (table != null) {
                    AggregateFlowStatisticsData data = table.getAugmentation(AggregateFlowStatisticsData.class);
                    if (null != data) {
                        aggerateFlowStatsCount++;
                    }
                }
            }
        }
    }
    if (aggregateFlowCount == aggerateFlowStatsCount) {
        LOG.debug("aggregateStats - Success");
    } else {
        LOG.debug("aggregateStats - Failed");
        LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
    }
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) AggregateFlowStatisticsData(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData)

Example 55 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project openflowplugin by opendaylight.

the class OpenflowpluginStatsTestCommandProvider method _descStats.

public void _descStats(CommandInterpreter ci) {
    int descCount = 0;
    int descStatsCount = 0;
    List<Node> nodes = getNodes();
    for (Node node2 : nodes) {
        descCount++;
        NodeKey nodeKey = node2.getKey();
        InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
        FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
        if (node != null) {
            if (null != node.getHardware() && null != node.getManufacturer() && null != node.getSoftware()) {
                descStatsCount++;
            }
        }
    }
    if (descCount == descStatsCount) {
        LOG.debug("descStats - Success");
    } else {
        LOG.debug("descStats - Failed");
        LOG.debug("System fetches stats data in 50 seconds interval, so please wait and try again.");
    }
}
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) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Aggregations

ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)65 Optional (com.google.common.base.Optional)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 ExecutionException (java.util.concurrent.ExecutionException)17 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)16 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)16 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)13 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)12 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)8 ArrayList (java.util.ArrayList)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)7 List (java.util.List)6 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)6 Test (org.junit.Test)5 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)5 Nonnull (javax.annotation.Nonnull)4 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)4 CacheBuilder (com.google.common.cache.CacheBuilder)3