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();
}
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);
}
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.");
}
}
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.");
}
}
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.");
}
}
Aggregations