deviceCtx should not be used where is not needed
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsGatheringUtils.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.statistics;
10
11 import com.google.common.base.Function;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.JdkFutureAdapters;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.List;
16 import java.util.Map;
17 import javax.annotation.Nullable;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
20 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
21 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
22 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryException;
23 import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
24 import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
25 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
26 import org.opendaylight.openflowplugin.impl.util.FlowUtil;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatistics;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatistics;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
87 import org.opendaylight.yangtools.yang.binding.DataObject;
88 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
89 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
90 import org.opendaylight.yangtools.yang.common.RpcResult;
91 import org.slf4j.Logger;
92 import org.slf4j.LoggerFactory;
93
94 /**
95  * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015.
96  */
97 public final class StatisticsGatheringUtils {
98
99     private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringUtils.class);
100     private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
101
102     private StatisticsGatheringUtils() {
103         throw new IllegalStateException("This class should not be instantiated.");
104     }
105
106     private static KeyedInstanceIdentifier<Node, NodeKey> getInstanceIdentifier(final DeviceContext deviceContext) {
107         return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
108     }
109
110     public static ListenableFuture<Boolean> gatherStatistics(final StatisticsGatheringService statisticsGatheringService,
111                                                              final DeviceContext deviceContext,
112                                                              final MultipartType type) {
113         //FIXME : anytype listener must not be send as parameter, it has to be extracted from device context inside service
114         final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
115                 JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType(type));
116         return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
117     }
118
119     private static ListenableFuture<Boolean> transformAndStoreStatisticsData(final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture,
120                                                                              final DeviceContext deviceContext) {
121         return Futures.transform(statisticsDataInFuture, new Function<RpcResult<List<MultipartReply>>, Boolean>() {
122             @Nullable
123             @Override
124             public Boolean apply(final RpcResult<List<MultipartReply>> rpcResult) {
125                 if (rpcResult.isSuccessful()) {
126                     for (final MultipartReply singleReply : rpcResult.getResult()) {
127                         final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply);
128                         for (final DataObject singleMultipartData : multipartDataList) {
129                             if (singleMultipartData instanceof GroupStatisticsUpdated) {
130                                 processGroupStatistics((GroupStatisticsUpdated) singleMultipartData, deviceContext);
131                             }
132
133                             if (singleMultipartData instanceof MeterStatisticsUpdated) {
134                                 processMetersStatistics((MeterStatisticsUpdated) singleMultipartData, deviceContext);
135                             }
136                             if (singleMultipartData instanceof NodeConnectorStatisticsUpdate) {
137                                 processNodeConnectorStatistics((NodeConnectorStatisticsUpdate) singleMultipartData, deviceContext);
138                             }
139                             if (singleMultipartData instanceof FlowTableStatisticsUpdate) {
140                                 processFlowTableStatistics((FlowTableStatisticsUpdate) singleMultipartData, deviceContext);
141                             }
142                             if (singleMultipartData instanceof QueueStatisticsUpdate) {
143                                 processQueueStatistics((QueueStatisticsUpdate) singleMultipartData, deviceContext);
144                             }
145                             if (singleMultipartData instanceof FlowsStatisticsUpdate) {
146                                 processFlowStatistics((FlowsStatisticsUpdate) singleMultipartData, deviceContext);
147                             }
148                             if (singleMultipartData instanceof GroupDescStatsUpdated) {
149                                 processGroupDescStats((GroupDescStatsUpdated) singleMultipartData, deviceContext);
150                             }
151                             if (singleMultipartData instanceof MeterConfigStatsUpdated) {
152                                 processMeterConfigStatsUpdated((MeterConfigStatsUpdated) singleMultipartData, deviceContext);
153                             }
154
155                             //TODO : implement experimenter
156                         }
157                     }
158                     return Boolean.TRUE;
159                 }
160                 return Boolean.FALSE;
161             }
162         });
163     }
164
165     private static void processMeterConfigStatsUpdated(final MeterConfigStatsUpdated meterConfigStatsUpdated, final DeviceContext deviceContext) {
166         NodeId nodeId = meterConfigStatsUpdated.getId();
167         final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
168
169
170         deleteAllKnownMeters(deviceContext, fNodeIdent);
171         for (MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) {
172             final MeterId meterId = meterConfigStats.getMeterId();
173             final InstanceIdentifier<Meter> meterInstanceIdentifier = fNodeIdent.child(Meter.class, new MeterKey(meterId));
174
175             final MeterBuilder meterBuilder = new MeterBuilder(meterConfigStats);
176             meterBuilder.setKey(new MeterKey(meterId));
177             meterBuilder.addAugmentation(NodeMeterStatistics.class, new NodeMeterStatisticsBuilder().build());
178
179             deviceContext.getDeviceMeterRegistry().store(meterId);
180             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, meterInstanceIdentifier, meterBuilder.build());
181         }
182     }
183
184     private static void processFlowStatistics(final FlowsStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
185         final FlowsStatisticsUpdate flowsStatistics = singleMultipartData;
186         final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
187                 .child(Node.class, new NodeKey(flowsStatistics.getId()));
188
189         if (deviceContext.getDeviceState().isValid()) {
190             deviceContext.startGatheringOperationsToOneTransaction();
191         }
192
193         deleteAllKnownFlows(deviceContext, nodeIdent);
194
195         for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
196             final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
197             FlowId flowId = null;
198             FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
199             short tableId = flowStat.getTableId();
200             try {
201                 FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowHash);
202                 flowId = flowDescriptor.getFlowId();
203             } catch (FlowRegistryException e) {
204                 LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowHash.hashCode());
205                 flowId = FlowUtil.createAlienFlowId(tableId);
206                 FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(tableId, flowId);
207                 deviceContext.getDeviceFlowRegistry().store(flowHash, flowDescriptor);
208             }
209             FlowKey flowKey = new FlowKey(flowId);
210             flowBuilder.setKey(flowKey);
211             final TableKey tableKey = new TableKey(tableId);
212             final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(singleMultipartData.getId());
213             final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
214             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
215         }
216
217         if (deviceContext.getDeviceState().isValid()) {
218             deviceContext.commitOperationsGatheredInOneTransaction();
219         }
220     }
221
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();
226
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);
233
234                 LOG.trace("Deleting flow with id {}", flowInstanceIdentifier);
235                 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, flowInstanceIdentifier);
236             }
237         }
238         deviceContext.getDeviceFlowRegistry().removeMarked();
239     }
240
241     private static void processQueueStatistics(final QueueStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
242         final QueueStatisticsUpdate queueStatisticsUpdate = singleMultipartData;
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());
259             }
260         }
261     }
262
263     private static void processFlowTableStatistics(final FlowTableStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
264         final FlowTableStatisticsUpdate flowTableStatisticsUpdate = singleMultipartData;
265         final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowTableStatisticsUpdate.getId());
266
267         for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
268             final InstanceIdentifier<FlowTableStatistics> tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue()))
269                     .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class);
270             final FlowTableStatistics stats = new FlowTableStatisticsBuilder(tableStat).build();
271             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tStatIdent, stats);
272         }
273     }
274
275     private static void processNodeConnectorStatistics(final NodeConnectorStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
276         final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate = singleMultipartData;
277         final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
278                 .child(Node.class, new NodeKey(nodeConnectorStatisticsUpdate.getId()));
279         for (final NodeConnectorStatisticsAndPortNumberMap nConnectPort : nodeConnectorStatisticsUpdate.getNodeConnectorStatisticsAndPortNumberMap()) {
280             final FlowCapableNodeConnectorStatistics stats = new FlowCapableNodeConnectorStatisticsBuilder(nConnectPort).build();
281             final NodeConnectorKey key = new NodeConnectorKey(nConnectPort.getNodeConnectorId());
282             final InstanceIdentifier<NodeConnector> nodeConnectorIdent = nodeIdent.child(NodeConnector.class, key);
283             final InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> nodeConnStatIdent = nodeConnectorIdent
284                     .augmentation(FlowCapableNodeConnectorStatisticsData.class);
285             final InstanceIdentifier<FlowCapableNodeConnectorStatistics> flowCapNodeConnStatIdent =
286                     nodeConnStatIdent.child(FlowCapableNodeConnectorStatistics.class);
287             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowCapNodeConnStatIdent, stats);
288         }
289     }
290
291     private static void processMetersStatistics(final MeterStatisticsUpdated singleMultipartData, final DeviceContext deviceContext) {
292         final MeterStatisticsUpdated meterStatisticsUpdated = singleMultipartData;
293         final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(meterStatisticsUpdated.getId());
294
295
296         for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
297             final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
298             final MeterId meterId = mStat.getMeterId();
299             final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
300             final InstanceIdentifier<NodeMeterStatistics> nodeMeterStatIdent = meterIdent
301                     .augmentation(NodeMeterStatistics.class);
302             final InstanceIdentifier<MeterStatistics> msIdent = nodeMeterStatIdent.child(MeterStatistics.class);
303             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, msIdent, stats);
304         }
305     }
306
307     private static void deleteAllKnownMeters(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
308         for (MeterId meterId : deviceContext.getDeviceMeterRegistry().getAllMeterIds()) {
309             final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
310             deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, meterIdent);
311         }
312         deviceContext.getDeviceMeterRegistry().removeMarked();
313     }
314
315     private static void processGroupDescStats(GroupDescStatsUpdated groupDescStatsUpdated, final DeviceContext deviceContext) {
316         NodeId nodeId = groupDescStatsUpdated.getId();
317         final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
318
319         deleteAllKnownGroups(deviceContext, fNodeIdent);
320         for (GroupDescStats groupDescStats : groupDescStatsUpdated.getGroupDescStats()) {
321             final GroupId groupId = groupDescStats.getGroupId();
322
323             final GroupBuilder groupBuilder = new GroupBuilder(groupDescStats);
324             groupBuilder.setKey(new GroupKey(groupId));
325             groupBuilder.addAugmentation(NodeGroupStatistics.class, new NodeGroupStatisticsBuilder().build());
326
327             final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
328             deviceContext.getDeviceGroupRegistry().store(groupId);
329             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, groupIdent, groupBuilder.build());
330         }
331     }
332
333     private static void deleteAllKnownGroups(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
334         for (GroupId groupId : deviceContext.getDeviceGroupRegistry().getAllGroupIds()) {
335             final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
336             deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, groupIdent);
337         }
338         deviceContext.getDeviceGroupRegistry().removeMarked();
339     }
340
341     private static void processGroupStatistics(final GroupStatisticsUpdated singleMultipartData, final DeviceContext deviceContext) {
342         final GroupStatisticsUpdated groupStatistics = singleMultipartData;
343         NodeId nodeId = groupStatistics.getId();
344         final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
345
346         for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
347
348             final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupStats.getGroupId()));
349             final InstanceIdentifier<NodeGroupStatistics> nGroupStatIdent = groupIdent
350                     .augmentation(NodeGroupStatistics.class);
351
352             final InstanceIdentifier<GroupStatistics> gsIdent = nGroupStatIdent.child(GroupStatistics.class);
353             final GroupStatistics stats = new GroupStatisticsBuilder(groupStats).build();
354             deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gsIdent, stats);
355         }
356     }
357
358     private static InstanceIdentifier<FlowCapableNode> getFlowCapableNodeInstanceIdentifier(final NodeId nodeId) {
359         final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier
360                 .create(Nodes.class).child(Node.class, new NodeKey(nodeId));
361         return nodeIdent.augmentation(FlowCapableNode.class);
362     }
363 }