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.FlowId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsDataBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsUpdated;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowTableStatisticsUpdated;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.NodeConnectorStatisticsUpdated;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.aggregate.flow.statistics.AggregateFlowStatisticsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStatsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.desc.GroupDescBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
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.MeterFeaturesUpdated;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStatsBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterConfigStatsBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterFeaturesBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterStatisticsBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
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.FlowCapableNodeConnectorStatisticsDataBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.PortStatisticsUpdate;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
85 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
86 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
87 import org.slf4j.Logger;
88 import org.slf4j.LoggerFactory;
90 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
91 OpendaylightMeterStatisticsListener,
92 OpendaylightFlowStatisticsListener,
93 OpendaylightPortStatisticsListener,
94 OpendaylightFlowTableStatisticsListener{
96 public final static Logger sucLogger = LoggerFactory.getLogger(StatisticsUpdateCommiter.class);
98 private final StatisticsProvider statisticsManager;
100 private final int unaccountedFlowsCounter = 1;
102 public StatisticsUpdateCommiter(final StatisticsProvider manager){
104 this.statisticsManager = manager;
107 public StatisticsProvider getStatisticsManager(){
108 return statisticsManager;
112 public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
114 //Add statistics to local cache
115 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
116 if(!cache.containsKey(notification.getId())){
117 cache.put(notification.getId(), new NodeStatistics());
119 cache.get(notification.getId()).setMeterConfigStats(notification.getMeterConfigStats());
121 //Publish data to configuration data store
122 DataModificationTransaction it = this.statisticsManager.startChange();
123 NodeKey key = new NodeKey(notification.getId());
124 NodeRef ref = getNodeRef(key);
126 final NodeBuilder nodeData = new NodeBuilder();
127 nodeData.setKey(key);
129 NodeMeterConfigStatsBuilder meterConfig= new NodeMeterConfigStatsBuilder();
130 MeterConfigStatsBuilder stats = new MeterConfigStatsBuilder();
131 stats.setMeterConfigStats(notification.getMeterConfigStats());
132 meterConfig.setMeterConfigStats(stats.build());
134 //Update augmented data
135 nodeData.addAugmentation(NodeMeterConfigStats.class, meterConfig.build());
137 InstanceIdentifier<? extends Object> refValue = ref.getValue();
138 it.putOperationalData(refValue, nodeData.build());
144 public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
145 //Add statistics to local cache
146 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
147 if(!cache.containsKey(notification.getId())){
148 cache.put(notification.getId(), new NodeStatistics());
150 cache.get(notification.getId()).setMeterStatistics(notification.getMeterStats());
152 //Publish data to configuration data store
153 DataModificationTransaction it = this.statisticsManager.startChange();
154 NodeKey key = new NodeKey(notification.getId());
155 NodeRef ref = getNodeRef(key);
157 final NodeBuilder nodeData = new NodeBuilder();
158 nodeData.setKey(key);
160 NodeMeterStatisticsBuilder meterStats= new NodeMeterStatisticsBuilder();
161 MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
162 stats.setMeterStats(notification.getMeterStats());
163 meterStats.setMeterStatistics(stats.build());
165 //Update augmented data
166 nodeData.addAugmentation(NodeMeterStatistics.class, meterStats.build());
168 InstanceIdentifier<? extends Object> refValue = ref.getValue();
169 it.putOperationalData(refValue, nodeData.build());
175 public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
176 //Add statistics to local cache
177 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
178 if(!cache.containsKey(notification.getId())){
179 cache.put(notification.getId(), new NodeStatistics());
181 cache.get(notification.getId()).setGroupDescStats(notification.getGroupDescStats());
183 //Publish data to configuration data store
184 DataModificationTransaction it = this.statisticsManager.startChange();
185 NodeKey key = new NodeKey(notification.getId());
186 NodeRef ref = getNodeRef(key);
188 final NodeBuilder nodeData = new NodeBuilder();
189 nodeData.setKey(key);
191 NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
192 GroupDescBuilder stats = new GroupDescBuilder();
193 stats.setGroupDescStats(notification.getGroupDescStats());
194 groupDesc.setGroupDesc(stats.build());
196 //Update augmented data
197 nodeData.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
199 InstanceIdentifier<? extends Object> refValue = ref.getValue();
200 it.putOperationalData(refValue, nodeData.build());
206 public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
208 //Add statistics to local cache
209 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
210 if(!cache.containsKey(notification.getId())){
211 cache.put(notification.getId(), new NodeStatistics());
213 cache.get(notification.getId()).setGroupStatistics(notification.getGroupStats());
215 //Publish data to configuration data store
217 DataModificationTransaction it = this.statisticsManager.startChange();
218 NodeKey key = new NodeKey(notification.getId());
219 NodeRef ref = getNodeRef(key);
221 final NodeBuilder nodeData = new NodeBuilder();
222 nodeData.setKey(key);
224 NodeGroupStatisticsBuilder groupStats = new NodeGroupStatisticsBuilder();
225 GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
226 stats.setGroupStats(notification.getGroupStats());
227 groupStats.setGroupStatistics(stats.build());
229 //Update augmented data
230 nodeData.addAugmentation(NodeGroupStatistics.class, groupStats.build());
232 InstanceIdentifier<? extends Object> refValue = ref.getValue();
233 it.putOperationalData(refValue, nodeData.build());
236 // for (GroupStats groupstat : notification.getGroupStats()) {
238 // GroupStatsKey groupKey = groupstat.getKey();
239 // InstanceIdentifier<? extends Object> id = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).augmentation(NodeGroupStatistics.class).child(GroupStatistics.class).child(GroupStats.class,groupKey).toInstance();
240 // it.putOperationalData(id, groupstat);
246 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
248 //Add statistics to local cache
249 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
250 if(!cache.containsKey(notification.getId())){
251 cache.put(notification.getId(), new NodeStatistics());
253 MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
254 meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
255 meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
256 meterFeature.setMaxBands(notification.getMaxBands());
257 meterFeature.setMaxColor(notification.getMaxColor());
258 meterFeature.setMaxMeter(notification.getMaxMeter());
260 cache.get(notification.getId()).setMeterFeatures(meterFeature.build());
262 //Publish data to configuration data store
263 DataModificationTransaction it = this.statisticsManager.startChange();
264 NodeKey key = new NodeKey(notification.getId());
265 NodeRef ref = getNodeRef(key);
267 final NodeBuilder nodeData = new NodeBuilder();
268 nodeData.setKey(key);
270 NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
271 nodeMeterFeatures.setMeterFeatures(meterFeature.build());
273 //Update augmented data
274 nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
276 InstanceIdentifier<? extends Object> refValue = ref.getValue();
277 it.putOperationalData(refValue, nodeData.build());
282 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
284 //Add statistics to local cache
285 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
286 if(!cache.containsKey(notification.getId())){
287 cache.put(notification.getId(), new NodeStatistics());
290 GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
291 groupFeatures.setActions(notification.getActions());
292 groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
293 groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
294 groupFeatures.setMaxGroups(notification.getMaxGroups());
295 cache.get(notification.getId()).setGroupFeatures(groupFeatures.build());
297 //Publish data to configuration data store
298 DataModificationTransaction it = this.statisticsManager.startChange();
299 NodeKey key = new NodeKey(notification.getId());
300 NodeRef ref = getNodeRef(key);
302 final NodeBuilder nodeData = new NodeBuilder();
303 nodeData.setKey(key);
305 NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
306 nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
308 //Update augmented data
309 nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
311 InstanceIdentifier<? extends Object> refValue = ref.getValue();
312 it.putOperationalData(refValue, nodeData.build());
317 public void onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
318 NodeKey key = new NodeKey(notification.getId());
319 sucLogger.info("Received flow stats update : {}",notification.toString());
321 for(FlowAndStatisticsMapList map: notification.getFlowAndStatisticsMapList()){
322 short tableId = map.getTableId();
324 DataModificationTransaction it = this.statisticsManager.startChange();
326 boolean foundOriginalFlow = false;
328 FlowBuilder flowBuilder = new FlowBuilder();
330 FlowStatisticsDataBuilder flowStatisticsData = new FlowStatisticsDataBuilder();
332 FlowBuilder flow = new FlowBuilder();
333 flow.setContainerName(map.getContainerName());
334 flow.setBufferId(map.getBufferId());
335 flow.setCookie(map.getCookie());
336 flow.setCookieMask(map.getCookieMask());
337 flow.setFlags(map.getFlags());
338 flow.setFlowName(map.getFlowName());
339 flow.setHardTimeout(map.getHardTimeout());
340 if(map.getFlowId() != null)
341 flow.setId(new FlowId(map.getFlowId().getValue()));
342 flow.setIdleTimeout(map.getIdleTimeout());
343 flow.setInstallHw(map.isInstallHw());
344 flow.setInstructions(map.getInstructions());
345 if(map.getFlowId()!= null)
346 flow.setKey(new FlowKey(new FlowId(map.getKey().getFlowId().getValue())));
347 flow.setMatch(map.getMatch());
348 flow.setOutGroup(map.getOutGroup());
349 flow.setOutPort(map.getOutPort());
350 flow.setPriority(map.getPriority());
351 flow.setStrict(map.isStrict());
352 flow.setTableId(tableId);
354 Flow flowRule = flow.build();
356 FlowAndStatisticsMapListBuilder stats = new FlowAndStatisticsMapListBuilder();
357 stats.setByteCount(map.getByteCount());
358 stats.setPacketCount(map.getPacketCount());
359 stats.setDuration(map.getDuration());
361 GenericStatistics flowStats = stats.build();
363 //Add statistics to local cache
364 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
365 if(!cache.containsKey(notification.getId())){
366 cache.put(notification.getId(), new NodeStatistics());
368 if(!cache.get(notification.getId()).getFlowAndStatsMap().containsKey(tableId)){
369 cache.get(notification.getId()).getFlowAndStatsMap().put(tableId, new HashMap<Flow,GenericStatistics>());
371 cache.get(notification.getId()).getFlowAndStatsMap().get(tableId).put(flowRule,flowStats);
373 //Augment the data to the flow node
375 FlowStatisticsBuilder flowStatistics = new FlowStatisticsBuilder();
376 flowStatistics.setByteCount(flowStats.getByteCount());
377 flowStatistics.setPacketCount(flowStats.getPacketCount());
378 flowStatistics.setDuration(flowStats.getDuration());
379 flowStatistics.setContainerName(map.getContainerName());
380 flowStatistics.setBufferId(map.getBufferId());
381 flowStatistics.setCookie(map.getCookie());
382 flowStatistics.setCookieMask(map.getCookieMask());
383 flowStatistics.setFlags(map.getFlags());
384 flowStatistics.setFlowName(map.getFlowName());
385 flowStatistics.setHardTimeout(map.getHardTimeout());
386 flowStatistics.setIdleTimeout(map.getIdleTimeout());
387 flowStatistics.setInstallHw(map.isInstallHw());
388 flowStatistics.setInstructions(map.getInstructions());
389 flowStatistics.setMatch(map.getMatch());
390 flowStatistics.setOutGroup(map.getOutGroup());
391 flowStatistics.setOutPort(map.getOutPort());
392 flowStatistics.setPriority(map.getPriority());
393 flowStatistics.setStrict(map.isStrict());
394 flowStatistics.setTableId(tableId);
396 flowStatisticsData.setFlowStatistics(flowStatistics.build());
398 sucLogger.info("Flow : {}",flowRule.toString());
399 sucLogger.info("Statistics to augment : {}",flowStatistics.build().toString());
401 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
402 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
404 Table table= (Table)it.readConfigurationData(tableRef);
406 //TODO: Not a good way to do it, need to figure out better way.
407 //TODO: major issue in any alternate approach is that flow key is incrementally assigned
408 //to the flows stored in data store.
411 for(Flow existingFlow : table.getFlow()){
412 sucLogger.debug("Existing flow in data store : {}",existingFlow.toString());
413 if(flowEquals(flowRule,existingFlow)){
414 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
415 .augmentation(FlowCapableNode.class)
416 .child(Table.class, new TableKey(tableId))
417 .child(Flow.class,existingFlow.getKey()).toInstance();
418 flowBuilder.setKey(existingFlow.getKey());
419 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
420 sucLogger.debug("Found matching flow in the datastore, augmenting statistics");
421 foundOriginalFlow = true;
422 it.putOperationalData(flowRef, flowBuilder.build());
429 if(!foundOriginalFlow){
430 sucLogger.info("Associated original flow is not found in data store. Augmenting flow in operational data st");
431 //TODO: Temporary fix: format [ 0+tableid+0+unaccounted flow counter]
432 long flowKey = Long.getLong(new String("0"+Short.toString(tableId)+"0"+Integer.toString(this.unaccountedFlowsCounter)));
433 FlowKey newFlowKey = new FlowKey(new FlowId(flowKey));
434 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
435 .augmentation(FlowCapableNode.class)
436 .child(Table.class, new TableKey(tableId))
437 .child(Flow.class,newFlowKey).toInstance();
438 flowBuilder.setKey(newFlowKey);
439 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
440 sucLogger.debug("Flow was no present in data store, augmenting statistics as an unaccounted flow");
441 it.putOperationalData(flowRef, flowBuilder.build());
448 public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
449 NodeKey key = new NodeKey(notification.getId());
450 sucLogger.debug("Received aggregate flow statistics update : {}",notification.toString());
452 Short tableId = this.statisticsManager.getMultipartMessageManager().getTableIdForTxId(notification.getTransactionId());
455 DataModificationTransaction it = this.statisticsManager.startChange();
457 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
458 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
460 AggregateFlowStatisticsDataBuilder aggregateFlowStatisticsDataBuilder = new AggregateFlowStatisticsDataBuilder();
461 AggregateFlowStatisticsBuilder aggregateFlowStatisticsBuilder = new AggregateFlowStatisticsBuilder();
462 aggregateFlowStatisticsBuilder.setByteCount(notification.getByteCount());
463 aggregateFlowStatisticsBuilder.setFlowCount(notification.getFlowCount());
464 aggregateFlowStatisticsBuilder.setPacketCount(notification.getPacketCount());
465 aggregateFlowStatisticsDataBuilder.setAggregateFlowStatistics(aggregateFlowStatisticsBuilder.build());
467 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
468 if(!cache.containsKey(notification.getId())){
469 cache.put(notification.getId(), new NodeStatistics());
471 cache.get(notification.getId()).getTableAndAggregateFlowStatsMap().put(tableId,aggregateFlowStatisticsBuilder.build());
473 sucLogger.debug("Augment aggregate statistics: {} for table {} on Node {}",aggregateFlowStatisticsBuilder.build().toString(),tableId,key);
475 TableBuilder tableBuilder = new TableBuilder();
476 tableBuilder.setKey(new TableKey(tableId));
477 tableBuilder.addAugmentation(AggregateFlowStatisticsData.class, aggregateFlowStatisticsDataBuilder.build());
478 it.putOperationalData(tableRef, tableBuilder.build());
485 public void onPortStatisticsUpdate(PortStatisticsUpdate notification) {
486 NodeKey key = new NodeKey(notification.getId());
487 sucLogger.info("Received port stats update : {}",notification.toString());
489 //Add statistics to local cache
490 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
491 if(!cache.containsKey(notification.getId())){
492 cache.put(notification.getId(), new NodeStatistics());
496 List<NodeConnectorStatisticsAndPortNumberMap> portsStats = notification.getNodeConnectorStatisticsAndPortNumberMap();
497 for(NodeConnectorStatisticsAndPortNumberMap portStats : portsStats){
499 DataModificationTransaction it = this.statisticsManager.startChange();
501 FlowCapableNodeConnectorStatisticsBuilder statisticsBuilder
502 = new FlowCapableNodeConnectorStatisticsBuilder();
503 statisticsBuilder.setBytes(portStats.getBytes());
504 statisticsBuilder.setCollisionCount(portStats.getCollisionCount());
505 statisticsBuilder.setDuration(portStats.getDuration());
506 statisticsBuilder.setPackets(portStats.getPackets());
507 statisticsBuilder.setReceiveCrcError(portStats.getReceiveCrcError());
508 statisticsBuilder.setReceiveDrops(portStats.getReceiveDrops());
509 statisticsBuilder.setReceiveErrors(portStats.getReceiveErrors());
510 statisticsBuilder.setReceiveFrameError(portStats.getReceiveFrameError());
511 statisticsBuilder.setReceiveOverRunError(portStats.getReceiveOverRunError());
512 statisticsBuilder.setTransmitDrops(portStats.getTransmitDrops());
513 statisticsBuilder.setTransmitErrors(portStats.getTransmitErrors());
515 //Update data in the cache
516 cache.get(notification.getId()).getNodeConnectorStats().put(portStats.getNodeConnectorId(), statisticsBuilder.build());
518 //Augment data to the node-connector
519 FlowCapableNodeConnectorStatisticsDataBuilder statisticsDataBuilder =
520 new FlowCapableNodeConnectorStatisticsDataBuilder();
522 statisticsDataBuilder.setFlowCapableNodeConnectorStatistics(statisticsBuilder.build());
524 InstanceIdentifier<NodeConnector> nodeConnectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).child(NodeConnector.class, new NodeConnectorKey(portStats.getNodeConnectorId())).toInstance();
526 NodeConnector nodeConnector = (NodeConnector)it.readOperationalData(nodeConnectorRef);
528 if(nodeConnector != null){
529 sucLogger.debug("Augmenting port statistics {} to port {}",statisticsDataBuilder.build().toString(),nodeConnectorRef.toString());
530 NodeConnectorBuilder nodeConnectorBuilder = new NodeConnectorBuilder();
531 nodeConnectorBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, statisticsDataBuilder.build());
532 it.putOperationalData(nodeConnectorRef, nodeConnectorBuilder.build());
539 public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
540 NodeKey key = new NodeKey(notification.getId());
541 sucLogger.debug("Received flow table statistics update : {}",notification.toString());
543 List<FlowTableAndStatisticsMap> flowTablesStatsList = notification.getFlowTableAndStatisticsMap();
544 for (FlowTableAndStatisticsMap ftStats : flowTablesStatsList){
546 DataModificationTransaction it = this.statisticsManager.startChange();
548 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
549 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
551 FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
553 FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
554 statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
555 statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
556 statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
558 statisticsDataBuilder.setFlowTableStatistics(statisticsBuilder.build());
560 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
561 if(!cache.containsKey(notification.getId())){
562 cache.put(notification.getId(), new NodeStatistics());
564 cache.get(notification.getId()).getFlowTableAndStatisticsMap().put(ftStats.getTableId().getValue(),statisticsBuilder.build());
566 sucLogger.debug("Augment flow table statistics: {} for table {} on Node {}",statisticsBuilder.build().toString(),ftStats.getTableId(),key);
568 TableBuilder tableBuilder = new TableBuilder();
569 tableBuilder.setKey(new TableKey(ftStats.getTableId().getValue()));
570 tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
571 it.putOperationalData(tableRef, tableBuilder.build());
577 public void onFlowStatisticsUpdated(FlowStatisticsUpdated notification) {
578 // TODO Auto-generated method stub
579 //TODO: Depricated, will clean it up once sal-compatibility is fixed.
580 //Sal-Compatibility code usage this notification event.
585 public void onFlowTableStatisticsUpdated(FlowTableStatisticsUpdated notification) {
586 // TODO Auto-generated method stub
587 //TODO: Need to implement it yet
592 public void onNodeConnectorStatisticsUpdated(NodeConnectorStatisticsUpdated notification) {
593 // TODO Auto-generated method stub
594 //TODO: Need to implement it yet
598 private NodeRef getNodeRef(NodeKey nodeKey){
599 InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
600 return new NodeRef(builder.toInstance());
603 public boolean flowEquals(Flow statsFlow, Flow storedFlow) {
604 if (statsFlow.getClass() != storedFlow.getClass()) {
607 if (statsFlow.getBufferId()== null) {
608 if (storedFlow.getBufferId() != null) {
611 } else if(!statsFlow.getBufferId().equals(storedFlow.getBufferId())) {
614 if (statsFlow.getContainerName()== null) {
615 if (storedFlow.getContainerName()!= null) {
618 } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
621 if (statsFlow.getCookie()== null) {
622 if (storedFlow.getCookie()!= null) {
625 } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
628 if (statsFlow.getMatch()== null) {
629 if (storedFlow.getMatch() != null) {
632 } else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
635 if (statsFlow.getCookie()== null) {
636 if (storedFlow.getCookie()!= null) {
639 } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
642 if (statsFlow.getHardTimeout() == null) {
643 if (storedFlow.getHardTimeout() != null) {
646 } else if(!statsFlow.getHardTimeout().equals(storedFlow.getHardTimeout() )) {
649 if (statsFlow.getIdleTimeout()== null) {
650 if (storedFlow.getIdleTimeout() != null) {
653 } else if(!statsFlow.getIdleTimeout().equals(storedFlow.getIdleTimeout())) {
656 if (statsFlow.getPriority() == null) {
657 if (storedFlow.getPriority() != null) {
660 } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
663 if (statsFlow.getTableId() == null) {
664 if (storedFlow.getTableId() != null) {
667 } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {