- deviceContext.getDeviceFlowRegistry().removeMarked();
- for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
- final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
- FlowId flowId = null;
- FlowHash flowHash = FlowHashFactory.create(flowBuilder.build());
- short tableId = flowStat.getTableId();
- try {
- FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowHash);
- flowId = flowDescriptor.getFlowId();
- } catch (FlowRegistryException e) {
- LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowHash.hashCode());
- flowId = FlowUtil.createAlienFlowId(tableId);
- FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(tableId, flowId);
- deviceContext.getDeviceFlowRegistry().store(flowHash, flowDescriptor);
+ }
+
+ /**
+ * Method extracts flow statistics out of flowAndStatistics model
+ *
+ * @param flowAndStats
+ */
+ private static FlowStatisticsDataBuilder refineFlowStatisticsAugmentation(final FlowAndStatisticsMapList flowAndStats) {
+ final FlowStatisticsBuilder flowStatisticsBuilder = new FlowStatisticsBuilder(flowAndStats);
+ final FlowStatisticsDataBuilder flowStatisticsDataBld = new FlowStatisticsDataBuilder();
+ flowStatisticsDataBld.setFlowStatistics(flowStatisticsBuilder.build());
+ return flowStatisticsDataBld;
+ }
+
+ public static ListenableFuture<Void> deleteAllKnownFlows(final DeviceState deviceState,
+ final DeviceFlowRegistry registry,
+ final TxFacade txFacade) {
+ /* DeviceState.deviceSynchronized is a marker for actual phase - false means initPhase, true means noInitPhase */
+ if (deviceState.deviceSynchronized()) {
+ final InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceState);
+ final ReadOnlyTransaction readTx = txFacade.getReadTransaction();
+ final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowCapableNodeFuture = readTx.read(
+ LogicalDatastoreType.OPERATIONAL, flowCapableNodePath);
+
+ /* we wish to close readTx for fallBack */
+ Futures.withFallback(flowCapableNodeFuture, new FutureFallback<Optional<FlowCapableNode>>() {
+
+ @Override
+ public ListenableFuture<Optional<FlowCapableNode>> create(final Throwable t) throws Exception {
+ readTx.close();
+ return Futures.immediateFailedFuture(t);
+ }
+ });
+ /*
+ * we have to read actual tables with all information before we set empty Flow list, merge is expensive and
+ * not applicable for lists
+ */
+ return Futures.transform(flowCapableNodeFuture, new AsyncFunction<Optional<FlowCapableNode>, Void>() {
+
+ @Override
+ public ListenableFuture<Void> apply(final Optional<FlowCapableNode> flowCapNodeOpt) throws Exception {
+ if (flowCapNodeOpt.isPresent()) {
+ for (final Table tableData : flowCapNodeOpt.get().getTable()) {
+ final Table table = new TableBuilder(tableData).setFlow(Collections.<Flow>emptyList()).build();
+ final InstanceIdentifier<Table> iiToTable = flowCapableNodePath.child(Table.class, tableData.getKey());
+ txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
+ }
+ }
+ registry.removeMarked();
+ readTx.close();
+ return Futures.immediateFuture(null);
+ }
+
+ });
+ }
+ return Futures.immediateFuture(null);
+ }
+
+ private static void processQueueStatistics(final Iterable<QueueStatisticsUpdate> data, final DeviceContext deviceContext) throws Exception {
+ // TODO: clean all queues of all node-connectors before writing up-to-date stats
+ final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier();
+ for (final QueueStatisticsUpdate queueStatisticsUpdate : data) {
+ for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) {
+ if (queueStat.getQueueId() != null) {
+ final FlowCapableNodeConnectorQueueStatistics statChild =
+ new FlowCapableNodeConnectorQueueStatisticsBuilder(queueStat).build();
+ final FlowCapableNodeConnectorQueueStatisticsDataBuilder statBuild =
+ new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
+ statBuild.setFlowCapableNodeConnectorQueueStatistics(statChild);
+ final QueueKey qKey = new QueueKey(queueStat.getQueueId());
+ final InstanceIdentifier<Queue> queueIdent = nodeIdent
+ .child(NodeConnector.class, new NodeConnectorKey(queueStat.getNodeConnectorId()))
+ .augmentation(FlowCapableNodeConnector.class)
+ .child(Queue.class, qKey);
+ final QueueBuilder queueBuilder = new QueueBuilder()
+ .setKey(qKey)
+ .setQueueId(queueStat.getQueueId())
+ // node-connector-id is already contained in parent node and the port-id here is of incompatible format
+ .addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, statBuild.build());
+ deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueIdent, queueBuilder.build());
+ }