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.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;
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.DeviceFlowRegistry;
21 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
22 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
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;
95 * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015.
97 public final class StatisticsGatheringUtils {
99 private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringUtils.class);
100 private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
102 private StatisticsGatheringUtils() {
103 throw new IllegalStateException("This class should not be instantiated.");
106 private static KeyedInstanceIdentifier<Node, NodeKey> getInstanceIdentifier(final DeviceContext deviceContext) {
107 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(deviceContext.getPrimaryConnectionContext().getNodeId()));
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);
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>() {
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);
133 if (singleMultipartData instanceof MeterStatisticsUpdated) {
134 processMetersStatistics((MeterStatisticsUpdated) singleMultipartData, deviceContext);
136 if (singleMultipartData instanceof NodeConnectorStatisticsUpdate) {
137 processNodeConnectorStatistics((NodeConnectorStatisticsUpdate) singleMultipartData, deviceContext);
139 if (singleMultipartData instanceof FlowTableStatisticsUpdate) {
140 processFlowTableStatistics((FlowTableStatisticsUpdate) singleMultipartData, deviceContext);
142 if (singleMultipartData instanceof QueueStatisticsUpdate) {
143 processQueueStatistics((QueueStatisticsUpdate) singleMultipartData, deviceContext);
145 if (singleMultipartData instanceof FlowsStatisticsUpdate) {
146 processFlowStatistics((FlowsStatisticsUpdate) singleMultipartData, deviceContext);
148 if (singleMultipartData instanceof GroupDescStatsUpdated) {
149 processGroupDescStats((GroupDescStatsUpdated) singleMultipartData, deviceContext);
151 if (singleMultipartData instanceof MeterConfigStatsUpdated) {
152 processMeterConfigStatsUpdated((MeterConfigStatsUpdated) singleMultipartData, deviceContext);
155 //TODO : implement experimenter
160 return Boolean.FALSE;
165 private static void processMeterConfigStatsUpdated(final MeterConfigStatsUpdated meterConfigStatsUpdated, final DeviceContext deviceContext) {
166 NodeId nodeId = meterConfigStatsUpdated.getId();
167 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
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));
175 final MeterBuilder meterBuilder = new MeterBuilder(meterConfigStats);
176 meterBuilder.setKey(new MeterKey(meterId));
177 meterBuilder.addAugmentation(NodeMeterStatistics.class, new NodeMeterStatisticsBuilder().build());
178 deviceContext.getDeviceMeterRegistry().store(meterId);
179 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, meterInstanceIdentifier, meterBuilder.build());
183 private static void processFlowStatistics(final FlowsStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
184 final FlowsStatisticsUpdate flowsStatistics = singleMultipartData;
185 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
186 .child(Node.class, new NodeKey(flowsStatistics.getId()));
188 if (deviceContext.getDeviceState().isValid()) {
189 deviceContext.startGatheringOperationsToOneTransaction();
192 deleteAllKnownFlows(deviceContext, nodeIdent);
194 for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
195 final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
196 FlowId flowId = null;
197 FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
198 short tableId = flowStat.getTableId();
199 final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
200 FlowDescriptor flowDescriptor;
201 flowDescriptor = deviceFlowRegistry.retrieveIdForFlow(flowHash);
202 if (null != flowDescriptor) {
203 flowId = flowDescriptor.getFlowId();
205 LOG.trace("Flow descriptor for flow hash {} wasn't found.", flowHash.hashCode());
206 flowId = FlowUtil.createAlienFlowId(tableId);
207 flowDescriptor = FlowDescriptorFactory.create(tableId, flowId);
209 deviceFlowRegistry.store(flowHash, flowDescriptor);
210 FlowKey flowKey = new FlowKey(flowId);
211 flowBuilder.setKey(flowKey);
212 final TableKey tableKey = new TableKey(tableId);
213 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(singleMultipartData.getId());
214 final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
215 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
218 if (deviceContext.getDeviceState().isValid()) {
219 deviceContext.commitOperationsGatheredInOneTransaction();
224 private static void deleteAllKnownFlows(final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeIdent) {
225 if (deviceContext.getDeviceState().deviceSynchronized()) {
226 for (Map.Entry<FlowHash, FlowDescriptor> registryEntry : deviceContext.getDeviceFlowRegistry().getAllFlowDescriptors().entrySet()) {
227 FlowDescriptor flowDescriptor = registryEntry.getValue();
229 FlowId flowId = flowDescriptor.getFlowId();
230 FlowKey flowKey = new FlowKey(flowId);
231 final InstanceIdentifier<Flow> flowInstanceIdentifier = nodeIdent
232 .augmentation(FlowCapableNode.class)
233 .child(Table.class, flowDescriptor.getTableKey())
234 .child(Flow.class, flowKey);
236 LOG.trace("Deleting flow with id {}", flowInstanceIdentifier);
237 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, flowInstanceIdentifier);
240 deviceContext.getDeviceFlowRegistry().removeMarked();
243 private static void processQueueStatistics(final QueueStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
244 final QueueStatisticsUpdate queueStatisticsUpdate = singleMultipartData;
245 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
246 .child(Node.class, new NodeKey(queueStatisticsUpdate.getId()));
247 for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) {
248 if (queueStat.getQueueId() != null) {
249 final FlowCapableNodeConnectorQueueStatistics statChild =
250 new FlowCapableNodeConnectorQueueStatisticsBuilder(queueStat).build();
251 final FlowCapableNodeConnectorQueueStatisticsDataBuilder statBuild =
252 new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
253 statBuild.setFlowCapableNodeConnectorQueueStatistics(statChild);
254 final QueueKey qKey = new QueueKey(queueStat.getQueueId());
255 final InstanceIdentifier<Queue> queueIdent = nodeIdent
256 .child(NodeConnector.class, new NodeConnectorKey(queueStat.getNodeConnectorId()))
257 .augmentation(FlowCapableNodeConnector.class)
258 .child(Queue.class, qKey);
259 final InstanceIdentifier<FlowCapableNodeConnectorQueueStatisticsData> queueStatIdent = queueIdent.augmentation(FlowCapableNodeConnectorQueueStatisticsData.class);
260 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueStatIdent, statBuild.build());
265 private static void processFlowTableStatistics(final FlowTableStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
266 final FlowTableStatisticsUpdate flowTableStatisticsUpdate = singleMultipartData;
267 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowTableStatisticsUpdate.getId());
269 for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
270 final InstanceIdentifier<FlowTableStatistics> tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue()))
271 .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class);
272 final FlowTableStatistics stats = new FlowTableStatisticsBuilder(tableStat).build();
273 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tStatIdent, stats);
277 private static void processNodeConnectorStatistics(final NodeConnectorStatisticsUpdate singleMultipartData, final DeviceContext deviceContext) {
278 final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate = singleMultipartData;
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);
293 private static void processMetersStatistics(final MeterStatisticsUpdated singleMultipartData, final DeviceContext deviceContext) {
294 final MeterStatisticsUpdated meterStatisticsUpdated = singleMultipartData;
295 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(meterStatisticsUpdated.getId());
298 for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
299 final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
300 final MeterId meterId = mStat.getMeterId();
301 final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
302 final InstanceIdentifier<NodeMeterStatistics> nodeMeterStatIdent = meterIdent
303 .augmentation(NodeMeterStatistics.class);
304 final InstanceIdentifier<MeterStatistics> msIdent = nodeMeterStatIdent.child(MeterStatistics.class);
305 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, msIdent, stats);
309 private static void deleteAllKnownMeters(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
310 for (MeterId meterId : deviceContext.getDeviceMeterRegistry().getAllMeterIds()) {
311 final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
312 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, meterIdent);
314 deviceContext.getDeviceMeterRegistry().removeMarked();
317 private static void processGroupDescStats(GroupDescStatsUpdated groupDescStatsUpdated, final DeviceContext deviceContext) {
318 NodeId nodeId = groupDescStatsUpdated.getId();
319 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
321 deleteAllKnownGroups(deviceContext, fNodeIdent);
322 for (GroupDescStats groupDescStats : groupDescStatsUpdated.getGroupDescStats()) {
323 final GroupId groupId = groupDescStats.getGroupId();
325 final GroupBuilder groupBuilder = new GroupBuilder(groupDescStats);
326 groupBuilder.setKey(new GroupKey(groupId));
327 groupBuilder.addAugmentation(NodeGroupStatistics.class, new NodeGroupStatisticsBuilder().build());
329 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
331 deviceContext.getDeviceGroupRegistry().store(groupId);
332 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, groupIdent, groupBuilder.build());
336 private static void deleteAllKnownGroups(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
337 for (GroupId groupId : deviceContext.getDeviceGroupRegistry().getAllGroupIds()) {
338 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
339 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, groupIdent);
341 deviceContext.getDeviceGroupRegistry().removeMarked();
344 private static void processGroupStatistics(final GroupStatisticsUpdated singleMultipartData, final DeviceContext deviceContext) {
345 final GroupStatisticsUpdated groupStatistics = singleMultipartData;
346 NodeId nodeId = groupStatistics.getId();
347 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
349 for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
351 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupStats.getGroupId()));
352 final InstanceIdentifier<NodeGroupStatistics> nGroupStatIdent = groupIdent
353 .augmentation(NodeGroupStatistics.class);
355 final InstanceIdentifier<GroupStatistics> gsIdent = nGroupStatIdent.child(GroupStatistics.class);
356 final GroupStatistics stats = new GroupStatisticsBuilder(groupStats).build();
357 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gsIdent, stats);
361 private static InstanceIdentifier<FlowCapableNode> getFlowCapableNodeInstanceIdentifier(final NodeId nodeId) {
362 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier
363 .create(Nodes.class).child(Node.class, new NodeKey(nodeId));
364 return nodeIdent.augmentation(FlowCapableNode.class);