2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.statistics;
11 import com.google.common.collect.Iterables;
13 import java.util.Collections;
14 import com.google.common.base.Function;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.JdkFutureAdapters;
17 import com.google.common.util.concurrent.ListenableFuture;
18 import java.util.List;
20 import javax.annotation.Nullable;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
23 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
24 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
25 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
26 import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
27 import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
28 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
29 import org.opendaylight.openflowplugin.impl.util.FlowUtil;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatistics;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatistics;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
90 import org.opendaylight.yangtools.yang.binding.DataObject;
91 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
92 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
93 import org.opendaylight.yangtools.yang.common.RpcResult;
94 import org.slf4j.Logger;
95 import org.slf4j.LoggerFactory;
98 * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015.
100 public final class StatisticsGatheringUtils {
102 private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringUtils.class);
103 private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
105 private StatisticsGatheringUtils() {
106 throw new IllegalStateException("This class should not be instantiated.");
109 private static KeyedInstanceIdentifier<Node, NodeKey> getInstanceIdentifier(final DeviceContext deviceContext) {
110 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
113 public static ListenableFuture<Boolean> gatherStatistics(final StatisticsGatheringService statisticsGatheringService,
114 final DeviceContext deviceContext,
115 final MultipartType type) {
116 //FIXME : anytype listener must not be send as parameter, it has to be extracted from device context inside service
117 final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
118 JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType(type));
119 return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
122 private static ListenableFuture<Boolean> transformAndStoreStatisticsData(final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture,
123 final DeviceContext deviceContext) {
124 return Futures.transform(statisticsDataInFuture, new Function<RpcResult<List<MultipartReply>>, Boolean>() {
127 public Boolean apply(final RpcResult<List<MultipartReply>> rpcResult) {
128 if (rpcResult.isSuccessful()) {
129 boolean isMultipartProcessed = Boolean.TRUE;
130 Iterable<? extends DataObject> allMultipartData = Collections.emptyList();
131 DataObject multipartData = null;
132 for (final MultipartReply singleReply : rpcResult.getResult()) {
133 final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply);
134 multipartData = multipartDataList.get(0);
135 allMultipartData = Iterables.concat(allMultipartData, multipartDataList);
138 if (deviceContext.getDeviceState().isValid()) {
139 deviceContext.startGatheringOperationsToOneTransaction();
142 if (multipartData instanceof GroupStatisticsUpdated) {
143 processGroupStatistics((Iterable<GroupStatisticsUpdated>)allMultipartData, deviceContext);
144 } else if (multipartData instanceof MeterStatisticsUpdated) {
145 processMetersStatistics((Iterable<MeterStatisticsUpdated>)allMultipartData, deviceContext);
146 } else if (multipartData instanceof NodeConnectorStatisticsUpdate) {
147 processNodeConnectorStatistics((Iterable<NodeConnectorStatisticsUpdate>) allMultipartData, deviceContext);
148 } else if (multipartData instanceof FlowTableStatisticsUpdate) {
149 processFlowTableStatistics((Iterable<FlowTableStatisticsUpdate>) allMultipartData, deviceContext);
150 } else if (multipartData instanceof QueueStatisticsUpdate) {
151 processQueueStatistics((Iterable<QueueStatisticsUpdate>) allMultipartData, deviceContext);
152 } else if (multipartData instanceof FlowsStatisticsUpdate) {
153 processFlowStatistics((Iterable<FlowsStatisticsUpdate>)allMultipartData, deviceContext);
154 } else if (multipartData instanceof GroupDescStatsUpdated) {
155 processGroupDescStats((Iterable<GroupDescStatsUpdated>) allMultipartData, deviceContext);
156 } else if (multipartData instanceof MeterConfigStatsUpdated) {
157 processMeterConfigStatsUpdated((Iterable<MeterConfigStatsUpdated>) allMultipartData, deviceContext);
159 isMultipartProcessed = Boolean.FALSE;
161 //TODO : implement experimenter
163 if (deviceContext.getDeviceState().isValid()) {
164 deviceContext.commitOperationsGatheredInOneTransaction();
166 return isMultipartProcessed;
168 return Boolean.FALSE;
173 private static void processMeterConfigStatsUpdated(final Iterable<MeterConfigStatsUpdated> data, final DeviceContext deviceContext) {
174 for (final MeterConfigStatsUpdated meterConfigStatsUpdated : data) {
175 NodeId nodeId = meterConfigStatsUpdated.getId();
176 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
177 for (MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) {
178 final MeterId meterId = meterConfigStats.getMeterId();
179 final InstanceIdentifier<Meter> meterInstanceIdentifier = fNodeIdent.child(Meter.class, new MeterKey(meterId));
181 final MeterBuilder meterBuilder = new MeterBuilder(meterConfigStats);
182 meterBuilder.setKey(new MeterKey(meterId));
183 meterBuilder.addAugmentation(NodeMeterStatistics.class, new NodeMeterStatisticsBuilder().build());
184 deviceContext.getDeviceMeterRegistry().store(meterId);
185 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, meterInstanceIdentifier, meterBuilder.build());
190 private static void processFlowStatistics(final Iterable<FlowsStatisticsUpdate> data, final DeviceContext deviceContext) {
191 final NodeId nodeId = deviceContext.getDeviceState().getNodeId();
192 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
193 .child(Node.class, new NodeKey(nodeId));
194 deleteAllKnownFlows(deviceContext, nodeIdent);
195 for (final FlowsStatisticsUpdate flowsStatistics : data) {
196 for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
197 final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
198 FlowId flowId = null;
199 FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
200 short tableId = flowStat.getTableId();
201 final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
202 FlowDescriptor flowDescriptor;
203 flowDescriptor = deviceFlowRegistry.retrieveIdForFlow(flowHash);
204 if (null != flowDescriptor) {
205 flowId = flowDescriptor.getFlowId();
207 LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowHash.hashCode());
208 flowId = FlowUtil.createAlienFlowId(tableId);
209 flowDescriptor = FlowDescriptorFactory.create(tableId, flowId);
210 deviceFlowRegistry.store(flowHash, flowDescriptor);
212 FlowKey flowKey = new FlowKey(flowId);
213 flowBuilder.setKey(flowKey);
214 final TableKey tableKey = new TableKey(tableId);
215 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowsStatistics.getId());
216 final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
217 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
222 private static void deleteAllKnownFlows(final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeIdent) {
223 if (deviceContext.getDeviceState().deviceSynchronized()) {
224 for (Map.Entry<FlowHash, FlowDescriptor> registryEntry : deviceContext.getDeviceFlowRegistry().getAllFlowDescriptors().entrySet()) {
225 FlowDescriptor flowDescriptor = registryEntry.getValue();
227 FlowId flowId = flowDescriptor.getFlowId();
228 FlowKey flowKey = new FlowKey(flowId);
229 final InstanceIdentifier<Flow> flowInstanceIdentifier = nodeIdent
230 .augmentation(FlowCapableNode.class)
231 .child(Table.class, flowDescriptor.getTableKey())
232 .child(Flow.class, flowKey);
234 LOG.trace("Deleting flow with id {}", flowInstanceIdentifier);
235 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, flowInstanceIdentifier);
238 deviceContext.getDeviceFlowRegistry().removeMarked();
241 private static void processQueueStatistics(final Iterable<QueueStatisticsUpdate> data, final DeviceContext deviceContext) {
242 for (final QueueStatisticsUpdate queueStatisticsUpdate : data) {
243 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
244 .child(Node.class, new NodeKey(queueStatisticsUpdate.getId()));
245 for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) {
246 if (queueStat.getQueueId() != null) {
247 final FlowCapableNodeConnectorQueueStatistics statChild =
248 new FlowCapableNodeConnectorQueueStatisticsBuilder(queueStat).build();
249 final FlowCapableNodeConnectorQueueStatisticsDataBuilder statBuild =
250 new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
251 statBuild.setFlowCapableNodeConnectorQueueStatistics(statChild);
252 final QueueKey qKey = new QueueKey(queueStat.getQueueId());
253 final InstanceIdentifier<Queue> queueIdent = nodeIdent
254 .child(NodeConnector.class, new NodeConnectorKey(queueStat.getNodeConnectorId()))
255 .augmentation(FlowCapableNodeConnector.class)
256 .child(Queue.class, qKey);
257 final InstanceIdentifier<FlowCapableNodeConnectorQueueStatisticsData> queueStatIdent = queueIdent.augmentation(FlowCapableNodeConnectorQueueStatisticsData.class);
258 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueStatIdent, statBuild.build());
264 private static void processFlowTableStatistics(final Iterable<FlowTableStatisticsUpdate> data, final DeviceContext deviceContext) {
265 for(final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) {
266 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowTableStatisticsUpdate.getId());
268 for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
269 final InstanceIdentifier<FlowTableStatistics> tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue()))
270 .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class);
271 final FlowTableStatistics stats = new FlowTableStatisticsBuilder(tableStat).build();
272 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tStatIdent, stats);
277 private static void processNodeConnectorStatistics(final Iterable<NodeConnectorStatisticsUpdate> data, final DeviceContext deviceContext) {
278 for (final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate : data) {
279 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
280 .child(Node.class, new NodeKey(nodeConnectorStatisticsUpdate.getId()));
281 for (final NodeConnectorStatisticsAndPortNumberMap nConnectPort : nodeConnectorStatisticsUpdate.getNodeConnectorStatisticsAndPortNumberMap()) {
282 final FlowCapableNodeConnectorStatistics stats = new FlowCapableNodeConnectorStatisticsBuilder(nConnectPort).build();
283 final NodeConnectorKey key = new NodeConnectorKey(nConnectPort.getNodeConnectorId());
284 final InstanceIdentifier<NodeConnector> nodeConnectorIdent = nodeIdent.child(NodeConnector.class, key);
285 final InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> nodeConnStatIdent = nodeConnectorIdent
286 .augmentation(FlowCapableNodeConnectorStatisticsData.class);
287 final InstanceIdentifier<FlowCapableNodeConnectorStatistics> flowCapNodeConnStatIdent =
288 nodeConnStatIdent.child(FlowCapableNodeConnectorStatistics.class);
289 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowCapNodeConnStatIdent, stats);
294 private static void processMetersStatistics(final Iterable<MeterStatisticsUpdated> data,
295 final DeviceContext deviceContext) {
296 NodeId nodeId = deviceContext.getDeviceState().getNodeId();
297 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
298 deleteAllKnownMeters(deviceContext, fNodeIdent);
299 for (MeterStatisticsUpdated meterStatisticsUpdated : data) {
300 for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
301 final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
302 final MeterId meterId = mStat.getMeterId();
303 final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
304 final InstanceIdentifier<NodeMeterStatistics> nodeMeterStatIdent = meterIdent
305 .augmentation(NodeMeterStatistics.class);
306 final InstanceIdentifier<MeterStatistics> msIdent = nodeMeterStatIdent.child(MeterStatistics.class);
307 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, msIdent, stats);
312 private static void deleteAllKnownMeters(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
313 for (MeterId meterId : deviceContext.getDeviceMeterRegistry().getAllMeterIds()) {
314 final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
315 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, meterIdent);
317 deviceContext.getDeviceMeterRegistry().removeMarked();
320 private static void processGroupDescStats(final Iterable<GroupDescStatsUpdated> data, final DeviceContext deviceContext) {
321 for ( GroupDescStatsUpdated groupDescStatsUpdated : data) {
322 NodeId nodeId = groupDescStatsUpdated.getId();
323 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
325 for (GroupDescStats groupDescStats : groupDescStatsUpdated.getGroupDescStats()) {
326 final GroupId groupId = groupDescStats.getGroupId();
328 final GroupBuilder groupBuilder = new GroupBuilder(groupDescStats);
329 groupBuilder.setKey(new GroupKey(groupId));
330 groupBuilder.addAugmentation(NodeGroupStatistics.class, new NodeGroupStatisticsBuilder().build());
332 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
334 deviceContext.getDeviceGroupRegistry().store(groupId);
335 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, groupIdent, groupBuilder.build());
340 private static void deleteAllKnownGroups(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
341 for (GroupId groupId : deviceContext.getDeviceGroupRegistry().getAllGroupIds()) {
342 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
343 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, groupIdent);
345 deviceContext.getDeviceGroupRegistry().removeMarked();
348 private static void processGroupStatistics(final Iterable<GroupStatisticsUpdated> data, final DeviceContext deviceContext) {
349 NodeId nodeId = deviceContext.getDeviceState().getNodeId();
350 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
351 deleteAllKnownGroups(deviceContext, fNodeIdent);
352 for (GroupStatisticsUpdated groupStatistics : data) {
353 for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
355 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupStats.getGroupId()));
356 final InstanceIdentifier<NodeGroupStatistics> nGroupStatIdent = groupIdent
357 .augmentation(NodeGroupStatistics.class);
359 final InstanceIdentifier<GroupStatistics> gsIdent = nGroupStatIdent.child(GroupStatistics.class);
360 final GroupStatistics stats = new GroupStatisticsBuilder(groupStats).build();
361 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gsIdent, stats);
366 private static InstanceIdentifier<FlowCapableNode> getFlowCapableNodeInstanceIdentifier(final NodeId nodeId) {
367 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier
368 .create(Nodes.class).child(Node.class, new NodeKey(nodeId));
369 return nodeIdent.augmentation(FlowCapableNode.class);