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.base.Optional;
13 import com.google.common.collect.Iterables;
14 import com.google.common.util.concurrent.CheckedFuture;
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.Collections;
19 import java.util.List;
20 import java.util.concurrent.ExecutionException;
21 import javax.annotation.Nullable;
22 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
26 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
27 import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
28 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
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 short tableId = flowStat.getTableId();
199 final Short version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
201 final FlowHash flowHash = FlowHashFactory.create(flowBuilder.build(), version);
202 final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowHash, tableId);
204 final FlowKey flowKey = new FlowKey(flowId);
205 flowBuilder.setKey(flowKey);
206 final TableKey tableKey = new TableKey(tableId);
207 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowsStatistics.getId());
208 final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
209 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
214 private static void deleteAllKnownFlows(final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeIdent) {
215 if (deviceContext.getDeviceState().deviceSynchronized()) {
216 final Short numOfTablesOnDevice = deviceContext.getDeviceState().getFeatures().getTables();
217 for (short i=0; i<numOfTablesOnDevice; i++) {
218 KeyedInstanceIdentifier<Table, TableKey> iiToTable
219 = nodeIdent.augmentation(FlowCapableNode.class).child( Table.class, new TableKey(i) );
220 final ReadTransaction readTx = deviceContext.getReadTransaction();
221 CheckedFuture<Optional<Table>, ReadFailedException> tableDataFuture = readTx.read(LogicalDatastoreType.OPERATIONAL, iiToTable);
223 Optional<Table> tableDataOpt = tableDataFuture.get();
224 if (tableDataOpt.isPresent()) {
225 final Table tableData = tableDataOpt.get();
226 final Table table = new TableBuilder(tableData).setFlow(Collections.<Flow>emptyList()).build();
227 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
229 } catch (InterruptedException e) {
230 LOG.trace("Reading of table features for table wit ID {} was interrputed.",i);
231 } catch (ExecutionException e) {
232 LOG.trace("Reading of table features for table wit ID {} encountered execution exception {}.",i,e);
238 private static void processQueueStatistics(final Iterable<QueueStatisticsUpdate> data, final DeviceContext deviceContext) {
239 for (final QueueStatisticsUpdate queueStatisticsUpdate : data) {
240 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
241 .child(Node.class, new NodeKey(queueStatisticsUpdate.getId()));
242 for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) {
243 if (queueStat.getQueueId() != null) {
244 final FlowCapableNodeConnectorQueueStatistics statChild =
245 new FlowCapableNodeConnectorQueueStatisticsBuilder(queueStat).build();
246 final FlowCapableNodeConnectorQueueStatisticsDataBuilder statBuild =
247 new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
248 statBuild.setFlowCapableNodeConnectorQueueStatistics(statChild);
249 final QueueKey qKey = new QueueKey(queueStat.getQueueId());
250 final InstanceIdentifier<Queue> queueIdent = nodeIdent
251 .child(NodeConnector.class, new NodeConnectorKey(queueStat.getNodeConnectorId()))
252 .augmentation(FlowCapableNodeConnector.class)
253 .child(Queue.class, qKey);
254 final InstanceIdentifier<FlowCapableNodeConnectorQueueStatisticsData> queueStatIdent = queueIdent.augmentation(FlowCapableNodeConnectorQueueStatisticsData.class);
255 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueStatIdent, statBuild.build());
261 private static void processFlowTableStatistics(final Iterable<FlowTableStatisticsUpdate> data, final DeviceContext deviceContext) {
262 for(final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) {
263 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowTableStatisticsUpdate.getId());
265 for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
266 final InstanceIdentifier<FlowTableStatistics> tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue()))
267 .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class);
268 final FlowTableStatistics stats = new FlowTableStatisticsBuilder(tableStat).build();
269 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tStatIdent, stats);
274 private static void processNodeConnectorStatistics(final Iterable<NodeConnectorStatisticsUpdate> data, final DeviceContext deviceContext) {
275 for (final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate : data) {
276 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
277 .child(Node.class, new NodeKey(nodeConnectorStatisticsUpdate.getId()));
278 for (final NodeConnectorStatisticsAndPortNumberMap nConnectPort : nodeConnectorStatisticsUpdate.getNodeConnectorStatisticsAndPortNumberMap()) {
279 final FlowCapableNodeConnectorStatistics stats = new FlowCapableNodeConnectorStatisticsBuilder(nConnectPort).build();
280 final NodeConnectorKey key = new NodeConnectorKey(nConnectPort.getNodeConnectorId());
281 final InstanceIdentifier<NodeConnector> nodeConnectorIdent = nodeIdent.child(NodeConnector.class, key);
282 final InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> nodeConnStatIdent = nodeConnectorIdent
283 .augmentation(FlowCapableNodeConnectorStatisticsData.class);
284 final InstanceIdentifier<FlowCapableNodeConnectorStatistics> flowCapNodeConnStatIdent =
285 nodeConnStatIdent.child(FlowCapableNodeConnectorStatistics.class);
286 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowCapNodeConnStatIdent, stats);
291 private static void processMetersStatistics(final Iterable<MeterStatisticsUpdated> data,
292 final DeviceContext deviceContext) {
293 NodeId nodeId = deviceContext.getDeviceState().getNodeId();
294 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
295 deleteAllKnownMeters(deviceContext, fNodeIdent);
296 for (MeterStatisticsUpdated meterStatisticsUpdated : data) {
297 for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
298 final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
299 final MeterId meterId = mStat.getMeterId();
300 final InstanceIdentifier<Meter> meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId));
301 final InstanceIdentifier<NodeMeterStatistics> nodeMeterStatIdent = meterIdent
302 .augmentation(NodeMeterStatistics.class);
303 final InstanceIdentifier<MeterStatistics> msIdent = nodeMeterStatIdent.child(MeterStatistics.class);
304 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(final Iterable<GroupDescStatsUpdated> data, final DeviceContext deviceContext) {
318 for ( GroupDescStatsUpdated groupDescStatsUpdated : data) {
319 NodeId nodeId = groupDescStatsUpdated.getId();
320 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
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());
337 private static void deleteAllKnownGroups(final DeviceContext deviceContext, final InstanceIdentifier<FlowCapableNode> fNodeIdent) {
338 for (GroupId groupId : deviceContext.getDeviceGroupRegistry().getAllGroupIds()) {
339 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId));
340 deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, groupIdent);
342 deviceContext.getDeviceGroupRegistry().removeMarked();
345 private static void processGroupStatistics(final Iterable<GroupStatisticsUpdated> data, final DeviceContext deviceContext) {
346 NodeId nodeId = deviceContext.getDeviceState().getNodeId();
347 final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
348 deleteAllKnownGroups(deviceContext, fNodeIdent);
349 for (GroupStatisticsUpdated groupStatistics : data) {
350 for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
352 final InstanceIdentifier<Group> groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupStats.getGroupId()));
353 final InstanceIdentifier<NodeGroupStatistics> nGroupStatIdent = groupIdent
354 .augmentation(NodeGroupStatistics.class);
356 final InstanceIdentifier<GroupStatistics> gsIdent = nGroupStatIdent.child(GroupStatistics.class);
357 final GroupStatistics stats = new GroupStatisticsBuilder(groupStats).build();
358 deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gsIdent, stats);
363 private static InstanceIdentifier<FlowCapableNode> getFlowCapableNodeInstanceIdentifier(final NodeId nodeId) {
364 final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier
365 .create(Nodes.class).child(Node.class, new NodeKey(nodeId));
366 return nodeIdent.augmentation(FlowCapableNode.class);