+ private static void processFlowStatistics(final Iterable<FlowsStatisticsUpdate> data, final DeviceContext deviceContext) {
+ boolean isFirstLoop = true;
+ for (final FlowsStatisticsUpdate flowsStatistics : data) {
+ if (isFirstLoop) {
+ final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
+ .child(Node.class, new NodeKey(flowsStatistics.getId()));
+ deleteAllKnownFlows(deviceContext, nodeIdent);
+ isFirstLoop = false;
+ }
+ for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
+ final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
+ FlowId flowId = null;
+ FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+ short tableId = flowStat.getTableId();
+ final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
+ FlowDescriptor flowDescriptor;
+ flowDescriptor = deviceFlowRegistry.retrieveIdForFlow(flowHash);
+ if (null != flowDescriptor) {
+ flowId = flowDescriptor.getFlowId();
+ } else {
+ LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowHash.hashCode());
+ flowId = FlowUtil.createAlienFlowId(tableId);
+ flowDescriptor = FlowDescriptorFactory.create(tableId, flowId);
+ deviceFlowRegistry.store(flowHash, flowDescriptor);
+ }
+ FlowKey flowKey = new FlowKey(flowId);
+ flowBuilder.setKey(flowKey);
+ final TableKey tableKey = new TableKey(tableId);
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowsStatistics.getId());
+ final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
+ deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
+ }
+ }
+ }
+
+ private static void deleteAllKnownFlows(final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeIdent) {