2 * Copyright IBM Corporation, 2013. 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
8 package org.opendaylight.controller.md.statistics.manager;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.concurrent.ConcurrentMap;
14 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsDataBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsUpdated;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowTableStatisticsUpdated;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.NodeConnectorStatisticsUpdated;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.aggregate.flow.statistics.AggregateFlowStatisticsBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
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.FlowTableStatisticsBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStatsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.desc.GroupDescBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStatsBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterFeaturesBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterConfigStatsBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericQueueStatistics;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.PortStatisticsUpdate;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsListener;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
107 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
108 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
109 import org.slf4j.Logger;
110 import org.slf4j.LoggerFactory;
113 * Class implement statistics manager related listener interface and augment all the
114 * received statistics data to data stores.
115 * TODO: Need to add error message listener and clean-up the associated tx id
116 * if it exists in the tx-id cache.
117 * @author vishnoianil
120 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
121 OpendaylightMeterStatisticsListener,
122 OpendaylightFlowStatisticsListener,
123 OpendaylightPortStatisticsListener,
124 OpendaylightFlowTableStatisticsListener,
125 OpendaylightQueueStatisticsListener{
127 public final static Logger sucLogger = LoggerFactory.getLogger(StatisticsUpdateCommiter.class);
129 private final StatisticsProvider statisticsManager;
131 private final int unaccountedFlowsCounter = 1;
133 public StatisticsUpdateCommiter(final StatisticsProvider manager){
135 this.statisticsManager = manager;
138 public StatisticsProvider getStatisticsManager(){
139 return statisticsManager;
143 public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
144 //Check if response is for the request statistics-manager sent.
145 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
148 //Add statistics to local cache
149 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
150 if(!cache.containsKey(notification.getId())){
151 cache.put(notification.getId(), new NodeStatistics());
153 cache.get(notification.getId()).setMeterConfigStats(notification.getMeterConfigStats());
155 //Publish data to configuration data store
156 NodeKey key = new NodeKey(notification.getId());
158 List<MeterConfigStats> eterConfigStatsList = notification.getMeterConfigStats();
160 for(MeterConfigStats meterConfigStats : eterConfigStatsList){
161 DataModificationTransaction it = this.statisticsManager.startChange();
162 MeterBuilder meterBuilder = new MeterBuilder();
163 MeterKey meterKey = new MeterKey(meterConfigStats.getMeterId());
164 meterBuilder.setKey(meterKey);
166 InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
167 .augmentation(FlowCapableNode.class)
168 .child(Meter.class,meterKey).toInstance();
170 NodeMeterConfigStatsBuilder meterConfig= new NodeMeterConfigStatsBuilder();
171 MeterConfigStatsBuilder stats = new MeterConfigStatsBuilder();
172 stats.fieldsFrom(meterConfigStats);
173 meterConfig.setMeterConfigStats(stats.build());
175 //Update augmented data
176 meterBuilder.addAugmentation(NodeMeterConfigStats.class, meterConfig.build());
177 it.putOperationalData(meterRef, meterBuilder.build());
184 public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
186 //Check if response is for the request statistics-manager sent.
187 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
190 //Add statistics to local cache
191 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
192 if(!cache.containsKey(notification.getId())){
193 cache.put(notification.getId(), new NodeStatistics());
195 cache.get(notification.getId()).setMeterStatistics(notification.getMeterStats());
197 NodeKey key = new NodeKey(notification.getId());
199 List<MeterStats> meterStatsList = notification.getMeterStats();
201 for(MeterStats meterStats : meterStatsList){
203 //Publish data to configuration data store
204 DataModificationTransaction it = this.statisticsManager.startChange();
205 MeterBuilder meterBuilder = new MeterBuilder();
206 MeterKey meterKey = new MeterKey(meterStats.getMeterId());
207 meterBuilder.setKey(meterKey);
209 InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
210 .augmentation(FlowCapableNode.class)
211 .child(Meter.class,meterKey).toInstance();
213 NodeMeterStatisticsBuilder meterStatsBuilder= new NodeMeterStatisticsBuilder();
214 MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
215 stats.fieldsFrom(meterStats);
216 meterStatsBuilder.setMeterStatistics(stats.build());
218 //Update augmented data
219 meterBuilder.addAugmentation(NodeMeterStatistics.class, meterStatsBuilder.build());
220 it.putOperationalData(meterRef, meterBuilder.build());
226 public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
228 //Check if response is for the request statistics-manager sent.
229 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
232 //Add statistics to local cache
233 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
234 if(!cache.containsKey(notification.getId())){
235 cache.put(notification.getId(), new NodeStatistics());
237 cache.get(notification.getId()).setGroupDescStats(notification.getGroupDescStats());
239 //Publish data to configuration data store
240 NodeKey key = new NodeKey(notification.getId());
241 List<GroupDescStats> groupDescStatsList = notification.getGroupDescStats();
243 for(GroupDescStats groupDescStats : groupDescStatsList){
244 DataModificationTransaction it = this.statisticsManager.startChange();
246 GroupBuilder groupBuilder = new GroupBuilder();
247 GroupKey groupKey = new GroupKey(groupDescStats.getGroupId());
248 groupBuilder.setKey(groupKey);
250 InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
251 .augmentation(FlowCapableNode.class)
252 .child(Group.class,groupKey).toInstance();
254 NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
255 GroupDescBuilder stats = new GroupDescBuilder();
256 stats.fieldsFrom(groupDescStats);
257 groupDesc.setGroupDesc(stats.build());
259 //Update augmented data
260 groupBuilder.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
262 it.putOperationalData(groupRef, groupBuilder.build());
268 public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
270 //Check if response is for the request statistics-manager sent.
271 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
274 //Add statistics to local cache
275 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
276 if(!cache.containsKey(notification.getId())){
277 cache.put(notification.getId(), new NodeStatistics());
279 cache.get(notification.getId()).setGroupStatistics(notification.getGroupStats());
281 //Publish data to configuration data store
282 NodeKey key = new NodeKey(notification.getId());
283 List<GroupStats> groupStatsList = notification.getGroupStats();
285 for(GroupStats groupStats : groupStatsList){
286 DataModificationTransaction it = this.statisticsManager.startChange();
288 GroupBuilder groupBuilder = new GroupBuilder();
289 GroupKey groupKey = new GroupKey(groupStats.getGroupId());
290 groupBuilder.setKey(groupKey);
292 InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
293 .augmentation(FlowCapableNode.class)
294 .child(Group.class,groupKey).toInstance();
296 NodeGroupStatisticsBuilder groupStatisticsBuilder= new NodeGroupStatisticsBuilder();
297 GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
298 stats.fieldsFrom(groupStats);
299 groupStatisticsBuilder.setGroupStatistics(stats.build());
301 //Update augmented data
302 groupBuilder.addAugmentation(NodeGroupStatistics.class, groupStatisticsBuilder.build());
303 it.putOperationalData(groupRef, groupBuilder.build());
309 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
311 //Add statistics to local cache
312 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
313 if(!cache.containsKey(notification.getId())){
314 cache.put(notification.getId(), new NodeStatistics());
316 MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
317 meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
318 meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
319 meterFeature.setMaxBands(notification.getMaxBands());
320 meterFeature.setMaxColor(notification.getMaxColor());
321 meterFeature.setMaxMeter(notification.getMaxMeter());
323 cache.get(notification.getId()).setMeterFeatures(meterFeature.build());
325 //Publish data to configuration data store
326 DataModificationTransaction it = this.statisticsManager.startChange();
327 NodeKey key = new NodeKey(notification.getId());
328 NodeRef ref = getNodeRef(key);
330 final NodeBuilder nodeData = new NodeBuilder();
331 nodeData.setKey(key);
333 NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
334 nodeMeterFeatures.setMeterFeatures(meterFeature.build());
336 //Update augmented data
337 nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
339 InstanceIdentifier<? extends Object> refValue = ref.getValue();
340 it.putOperationalData(refValue, nodeData.build());
345 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
347 //Add statistics to local cache
348 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
349 if(!cache.containsKey(notification.getId())){
350 cache.put(notification.getId(), new NodeStatistics());
353 GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
354 groupFeatures.setActions(notification.getActions());
355 groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
356 groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
357 groupFeatures.setMaxGroups(notification.getMaxGroups());
358 cache.get(notification.getId()).setGroupFeatures(groupFeatures.build());
360 //Publish data to configuration data store
361 DataModificationTransaction it = this.statisticsManager.startChange();
362 NodeKey key = new NodeKey(notification.getId());
363 NodeRef ref = getNodeRef(key);
365 final NodeBuilder nodeData = new NodeBuilder();
366 nodeData.setKey(key);
368 NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
369 nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
371 //Update augmented data
372 nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
374 InstanceIdentifier<? extends Object> refValue = ref.getValue();
375 it.putOperationalData(refValue, nodeData.build());
380 public void onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
382 //Check if response is for the request statistics-manager sent.
383 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
386 NodeKey key = new NodeKey(notification.getId());
387 sucLogger.debug("Received flow stats update : {}",notification.toString());
389 for(FlowAndStatisticsMapList map: notification.getFlowAndStatisticsMapList()){
390 short tableId = map.getTableId();
392 DataModificationTransaction it = this.statisticsManager.startChange();
394 boolean foundOriginalFlow = false;
396 FlowBuilder flowBuilder = new FlowBuilder();
398 FlowStatisticsDataBuilder flowStatisticsData = new FlowStatisticsDataBuilder();
400 FlowBuilder flow = new FlowBuilder();
401 flow.setContainerName(map.getContainerName());
402 flow.setBufferId(map.getBufferId());
403 flow.setCookie(map.getCookie());
404 flow.setCookieMask(map.getCookieMask());
405 flow.setFlags(map.getFlags());
406 flow.setFlowName(map.getFlowName());
407 flow.setHardTimeout(map.getHardTimeout());
408 if(map.getFlowId() != null)
409 flow.setId(new FlowId(map.getFlowId().getValue()));
410 flow.setIdleTimeout(map.getIdleTimeout());
411 flow.setInstallHw(map.isInstallHw());
412 flow.setInstructions(map.getInstructions());
413 if(map.getFlowId()!= null)
414 flow.setKey(new FlowKey(new FlowId(map.getKey().getFlowId().getValue())));
415 flow.setMatch(map.getMatch());
416 flow.setOutGroup(map.getOutGroup());
417 flow.setOutPort(map.getOutPort());
418 flow.setPriority(map.getPriority());
419 flow.setStrict(map.isStrict());
420 flow.setTableId(tableId);
422 Flow flowRule = flow.build();
424 FlowAndStatisticsMapListBuilder stats = new FlowAndStatisticsMapListBuilder();
425 stats.setByteCount(map.getByteCount());
426 stats.setPacketCount(map.getPacketCount());
427 stats.setDuration(map.getDuration());
429 GenericStatistics flowStats = stats.build();
431 //Add statistics to local cache
432 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
433 if(!cache.containsKey(notification.getId())){
434 cache.put(notification.getId(), new NodeStatistics());
436 if(!cache.get(notification.getId()).getFlowAndStatsMap().containsKey(tableId)){
437 cache.get(notification.getId()).getFlowAndStatsMap().put(tableId, new HashMap<Flow,GenericStatistics>());
439 cache.get(notification.getId()).getFlowAndStatsMap().get(tableId).put(flowRule,flowStats);
441 //Augment the data to the flow node
443 FlowStatisticsBuilder flowStatistics = new FlowStatisticsBuilder();
444 flowStatistics.setByteCount(flowStats.getByteCount());
445 flowStatistics.setPacketCount(flowStats.getPacketCount());
446 flowStatistics.setDuration(flowStats.getDuration());
447 flowStatistics.setContainerName(map.getContainerName());
448 flowStatistics.setBufferId(map.getBufferId());
449 flowStatistics.setCookie(map.getCookie());
450 flowStatistics.setCookieMask(map.getCookieMask());
451 flowStatistics.setFlags(map.getFlags());
452 flowStatistics.setFlowName(map.getFlowName());
453 flowStatistics.setHardTimeout(map.getHardTimeout());
454 flowStatistics.setIdleTimeout(map.getIdleTimeout());
455 flowStatistics.setInstallHw(map.isInstallHw());
456 flowStatistics.setInstructions(map.getInstructions());
457 flowStatistics.setMatch(map.getMatch());
458 flowStatistics.setOutGroup(map.getOutGroup());
459 flowStatistics.setOutPort(map.getOutPort());
460 flowStatistics.setPriority(map.getPriority());
461 flowStatistics.setStrict(map.isStrict());
462 flowStatistics.setTableId(tableId);
464 flowStatisticsData.setFlowStatistics(flowStatistics.build());
466 sucLogger.debug("Flow : {}",flowRule.toString());
467 sucLogger.debug("Statistics to augment : {}",flowStatistics.build().toString());
469 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
470 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
472 Table table= (Table)it.readConfigurationData(tableRef);
474 //TODO: Not a good way to do it, need to figure out better way.
475 //TODO: major issue in any alternate approach is that flow key is incrementally assigned
476 //to the flows stored in data store.
479 for(Flow existingFlow : table.getFlow()){
480 sucLogger.debug("Existing flow in data store : {}",existingFlow.toString());
481 if(flowEquals(flowRule,existingFlow)){
482 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
483 .augmentation(FlowCapableNode.class)
484 .child(Table.class, new TableKey(tableId))
485 .child(Flow.class,existingFlow.getKey()).toInstance();
486 flowBuilder.setKey(existingFlow.getKey());
487 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
488 sucLogger.debug("Found matching flow in the datastore, augmenting statistics");
489 foundOriginalFlow = true;
490 it.putOperationalData(flowRef, flowBuilder.build());
497 if(!foundOriginalFlow){
498 sucLogger.info("Associated original flow is not found in data store. Augmenting flow in operational data st");
499 //TODO: Temporary fix: format [ 0+tableid+0+unaccounted flow counter]
500 long flowKey = Long.getLong(new String("0"+Short.toString(tableId)+"0"+Integer.toString(this.unaccountedFlowsCounter)));
501 FlowKey newFlowKey = new FlowKey(new FlowId(flowKey));
502 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
503 .augmentation(FlowCapableNode.class)
504 .child(Table.class, new TableKey(tableId))
505 .child(Flow.class,newFlowKey).toInstance();
506 flowBuilder.setKey(newFlowKey);
507 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
508 sucLogger.info("Flow was no present in data store, augmenting statistics as an unaccounted flow");
509 it.putOperationalData(flowRef, flowBuilder.build());
516 public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
517 //Check if response is for the request statistics-manager sent.
518 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
521 NodeKey key = new NodeKey(notification.getId());
522 sucLogger.debug("Received aggregate flow statistics update : {}",notification.toString());
524 Short tableId = this.statisticsManager.getMultipartMessageManager().getTableIdForTxId(notification.getTransactionId());
527 DataModificationTransaction it = this.statisticsManager.startChange();
529 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
530 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
532 AggregateFlowStatisticsDataBuilder aggregateFlowStatisticsDataBuilder = new AggregateFlowStatisticsDataBuilder();
533 AggregateFlowStatisticsBuilder aggregateFlowStatisticsBuilder = new AggregateFlowStatisticsBuilder();
534 aggregateFlowStatisticsBuilder.setByteCount(notification.getByteCount());
535 aggregateFlowStatisticsBuilder.setFlowCount(notification.getFlowCount());
536 aggregateFlowStatisticsBuilder.setPacketCount(notification.getPacketCount());
537 aggregateFlowStatisticsDataBuilder.setAggregateFlowStatistics(aggregateFlowStatisticsBuilder.build());
539 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
540 if(!cache.containsKey(notification.getId())){
541 cache.put(notification.getId(), new NodeStatistics());
543 cache.get(notification.getId()).getTableAndAggregateFlowStatsMap().put(tableId,aggregateFlowStatisticsBuilder.build());
545 sucLogger.debug("Augment aggregate statistics: {} for table {} on Node {}",aggregateFlowStatisticsBuilder.build().toString(),tableId,key);
547 TableBuilder tableBuilder = new TableBuilder();
548 tableBuilder.setKey(new TableKey(tableId));
549 tableBuilder.addAugmentation(AggregateFlowStatisticsData.class, aggregateFlowStatisticsDataBuilder.build());
550 it.putOperationalData(tableRef, tableBuilder.build());
557 public void onPortStatisticsUpdate(PortStatisticsUpdate notification) {
558 //Check if response is for the request statistics-manager sent.
559 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
562 NodeKey key = new NodeKey(notification.getId());
563 sucLogger.debug("Received port stats update : {}",notification.toString());
565 //Add statistics to local cache
566 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
567 if(!cache.containsKey(notification.getId())){
568 cache.put(notification.getId(), new NodeStatistics());
572 List<NodeConnectorStatisticsAndPortNumberMap> portsStats = notification.getNodeConnectorStatisticsAndPortNumberMap();
573 for(NodeConnectorStatisticsAndPortNumberMap portStats : portsStats){
575 DataModificationTransaction it = this.statisticsManager.startChange();
577 FlowCapableNodeConnectorStatisticsBuilder statisticsBuilder
578 = new FlowCapableNodeConnectorStatisticsBuilder();
579 statisticsBuilder.setBytes(portStats.getBytes());
580 statisticsBuilder.setCollisionCount(portStats.getCollisionCount());
581 statisticsBuilder.setDuration(portStats.getDuration());
582 statisticsBuilder.setPackets(portStats.getPackets());
583 statisticsBuilder.setReceiveCrcError(portStats.getReceiveCrcError());
584 statisticsBuilder.setReceiveDrops(portStats.getReceiveDrops());
585 statisticsBuilder.setReceiveErrors(portStats.getReceiveErrors());
586 statisticsBuilder.setReceiveFrameError(portStats.getReceiveFrameError());
587 statisticsBuilder.setReceiveOverRunError(portStats.getReceiveOverRunError());
588 statisticsBuilder.setTransmitDrops(portStats.getTransmitDrops());
589 statisticsBuilder.setTransmitErrors(portStats.getTransmitErrors());
591 //Update data in the cache
592 cache.get(notification.getId()).getNodeConnectorStats().put(portStats.getNodeConnectorId(), statisticsBuilder.build());
594 //Augment data to the node-connector
595 FlowCapableNodeConnectorStatisticsDataBuilder statisticsDataBuilder =
596 new FlowCapableNodeConnectorStatisticsDataBuilder();
598 statisticsDataBuilder.setFlowCapableNodeConnectorStatistics(statisticsBuilder.build());
600 InstanceIdentifier<NodeConnector> nodeConnectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).child(NodeConnector.class, new NodeConnectorKey(portStats.getNodeConnectorId())).toInstance();
602 NodeConnector nodeConnector = (NodeConnector)it.readOperationalData(nodeConnectorRef);
604 if(nodeConnector != null){
605 sucLogger.debug("Augmenting port statistics {} to port {}",statisticsDataBuilder.build().toString(),nodeConnectorRef.toString());
606 NodeConnectorBuilder nodeConnectorBuilder = new NodeConnectorBuilder();
607 nodeConnectorBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, statisticsDataBuilder.build());
608 it.putOperationalData(nodeConnectorRef, nodeConnectorBuilder.build());
615 public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
616 //Check if response is for the request statistics-manager sent.
617 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
620 NodeKey key = new NodeKey(notification.getId());
621 sucLogger.debug("Received flow table statistics update : {}",notification.toString());
623 List<FlowTableAndStatisticsMap> flowTablesStatsList = notification.getFlowTableAndStatisticsMap();
624 for (FlowTableAndStatisticsMap ftStats : flowTablesStatsList){
626 DataModificationTransaction it = this.statisticsManager.startChange();
628 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
629 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
631 FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
633 FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
634 statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
635 statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
636 statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
638 statisticsDataBuilder.setFlowTableStatistics(statisticsBuilder.build());
640 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
641 if(!cache.containsKey(notification.getId())){
642 cache.put(notification.getId(), new NodeStatistics());
644 cache.get(notification.getId()).getFlowTableAndStatisticsMap().put(ftStats.getTableId().getValue(),statisticsBuilder.build());
646 sucLogger.debug("Augment flow table statistics: {} for table {} on Node {}",statisticsBuilder.build().toString(),ftStats.getTableId(),key);
648 TableBuilder tableBuilder = new TableBuilder();
649 tableBuilder.setKey(new TableKey(ftStats.getTableId().getValue()));
650 tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
651 it.putOperationalData(tableRef, tableBuilder.build());
657 public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
659 //Check if response is for the request statistics-manager sent.
660 if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
663 NodeKey key = new NodeKey(notification.getId());
664 sucLogger.debug("Received queue stats update : {}",notification.toString());
666 //Add statistics to local cache
667 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
668 if(!cache.containsKey(notification.getId())){
669 cache.put(notification.getId(), new NodeStatistics());
672 List<QueueIdAndStatisticsMap> queuesStats = notification.getQueueIdAndStatisticsMap();
673 for(QueueIdAndStatisticsMap swQueueStats : queuesStats){
675 if(!cache.get(notification.getId()).getNodeConnectorAndQueuesStatsMap().containsKey(swQueueStats.getNodeConnectorId())){
676 cache.get(notification.getId()).getNodeConnectorAndQueuesStatsMap().put(swQueueStats.getNodeConnectorId(), new HashMap<QueueId,GenericQueueStatistics>());
679 FlowCapableNodeConnectorQueueStatisticsDataBuilder queueStatisticsDataBuilder = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
681 FlowCapableNodeConnectorQueueStatisticsBuilder queueStatisticsBuilder = new FlowCapableNodeConnectorQueueStatisticsBuilder();
683 queueStatisticsBuilder.fieldsFrom(swQueueStats);
685 queueStatisticsDataBuilder.setFlowCapableNodeConnectorQueueStatistics(queueStatisticsBuilder.build());
687 cache.get(notification.getId()).getNodeConnectorAndQueuesStatsMap()
688 .get(swQueueStats.getNodeConnectorId())
689 .put(swQueueStats.getQueueId(), queueStatisticsBuilder.build());
692 DataModificationTransaction it = this.statisticsManager.startChange();
694 InstanceIdentifier<Queue> queueRef
695 = InstanceIdentifier.builder(Nodes.class)
696 .child(Node.class, key)
697 .child(NodeConnector.class, new NodeConnectorKey(swQueueStats.getNodeConnectorId()))
698 .augmentation(FlowCapableNodeConnector.class)
699 .child(Queue.class, new QueueKey(swQueueStats.getQueueId())).toInstance();
701 QueueBuilder queueBuilder = new QueueBuilder();
702 queueBuilder.addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, queueStatisticsDataBuilder.build());
703 queueBuilder.setKey(new QueueKey(swQueueStats.getQueueId()));
705 sucLogger.info("Augmenting queue statistics {} of queue {} to port {}"
706 ,queueStatisticsDataBuilder.build().toString(),
707 swQueueStats.getQueueId(),
708 swQueueStats.getNodeConnectorId());
710 it.putOperationalData(queueRef, queueBuilder.build());
718 public void onFlowStatisticsUpdated(FlowStatisticsUpdated notification) {
719 // TODO Auto-generated method stub
720 //TODO: Depricated, will clean it up once sal-compatibility is fixed.
721 //Sal-Compatibility code usage this notification event.
726 public void onFlowTableStatisticsUpdated(FlowTableStatisticsUpdated notification) {
727 // TODO Auto-generated method stub
728 //TODO: Need to implement it yet
733 public void onNodeConnectorStatisticsUpdated(NodeConnectorStatisticsUpdated notification) {
734 // TODO Auto-generated method stub
735 //TODO: Need to implement it yet
739 private NodeRef getNodeRef(NodeKey nodeKey){
740 InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
741 return new NodeRef(builder.toInstance());
744 public boolean flowEquals(Flow statsFlow, Flow storedFlow) {
745 if (statsFlow.getClass() != storedFlow.getClass()) {
748 if (statsFlow.getBufferId()== null) {
749 if (storedFlow.getBufferId() != null) {
752 } else if(!statsFlow.getBufferId().equals(storedFlow.getBufferId())) {
755 if (statsFlow.getContainerName()== null) {
756 if (storedFlow.getContainerName()!= null) {
759 } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
762 if (statsFlow.getCookie()== null) {
763 if (storedFlow.getCookie()!= null) {
766 } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
769 if (statsFlow.getMatch()== null) {
770 if (storedFlow.getMatch() != null) {
773 } else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
776 if (statsFlow.getCookie()== null) {
777 if (storedFlow.getCookie()!= null) {
780 } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
783 if (statsFlow.getHardTimeout() == null) {
784 if (storedFlow.getHardTimeout() != null) {
787 } else if(!statsFlow.getHardTimeout().equals(storedFlow.getHardTimeout() )) {
790 if (statsFlow.getIdleTimeout()== null) {
791 if (storedFlow.getIdleTimeout() != null) {
794 } else if(!statsFlow.getIdleTimeout().equals(storedFlow.getIdleTimeout())) {
797 if (statsFlow.getPriority() == null) {
798 if (storedFlow.getPriority() != null) {
801 } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
804 if (statsFlow.getTableId() == null) {
805 if (storedFlow.getTableId() != null) {
808 } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {