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.tables.Table;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsDataBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsUpdated;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowTableStatisticsUpdated;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.NodeConnectorStatisticsUpdated;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.aggregate.flow.statistics.AggregateFlowStatisticsBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStatsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.desc.GroupDescBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
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.NodeConnectorBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStatsBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterConfigStatsBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterFeaturesBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterStatisticsBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericQueueStatistics;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.PortStatisticsUpdate;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsListener;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
97 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
98 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
99 import org.slf4j.Logger;
100 import org.slf4j.LoggerFactory;
102 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
103 OpendaylightMeterStatisticsListener,
104 OpendaylightFlowStatisticsListener,
105 OpendaylightPortStatisticsListener,
106 OpendaylightFlowTableStatisticsListener,
107 OpendaylightQueueStatisticsListener{
109 public final static Logger sucLogger = LoggerFactory.getLogger(StatisticsUpdateCommiter.class);
111 private final StatisticsProvider statisticsManager;
113 private final int unaccountedFlowsCounter = 1;
115 public StatisticsUpdateCommiter(final StatisticsProvider manager){
117 this.statisticsManager = manager;
120 public StatisticsProvider getStatisticsManager(){
121 return statisticsManager;
125 public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
127 //Add statistics to local cache
128 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
129 if(!cache.containsKey(notification.getId())){
130 cache.put(notification.getId(), new NodeStatistics());
132 cache.get(notification.getId()).setMeterConfigStats(notification.getMeterConfigStats());
134 //Publish data to configuration data store
135 DataModificationTransaction it = this.statisticsManager.startChange();
136 NodeKey key = new NodeKey(notification.getId());
137 NodeRef ref = getNodeRef(key);
139 final NodeBuilder nodeData = new NodeBuilder();
140 nodeData.setKey(key);
142 NodeMeterConfigStatsBuilder meterConfig= new NodeMeterConfigStatsBuilder();
143 MeterConfigStatsBuilder stats = new MeterConfigStatsBuilder();
144 stats.setMeterConfigStats(notification.getMeterConfigStats());
145 meterConfig.setMeterConfigStats(stats.build());
147 //Update augmented data
148 nodeData.addAugmentation(NodeMeterConfigStats.class, meterConfig.build());
150 InstanceIdentifier<? extends Object> refValue = ref.getValue();
151 it.putOperationalData(refValue, nodeData.build());
157 public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
158 //Add statistics to local cache
159 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
160 if(!cache.containsKey(notification.getId())){
161 cache.put(notification.getId(), new NodeStatistics());
163 cache.get(notification.getId()).setMeterStatistics(notification.getMeterStats());
165 //Publish data to configuration data store
166 DataModificationTransaction it = this.statisticsManager.startChange();
167 NodeKey key = new NodeKey(notification.getId());
168 NodeRef ref = getNodeRef(key);
170 final NodeBuilder nodeData = new NodeBuilder();
171 nodeData.setKey(key);
173 NodeMeterStatisticsBuilder meterStats= new NodeMeterStatisticsBuilder();
174 MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
175 stats.setMeterStats(notification.getMeterStats());
176 meterStats.setMeterStatistics(stats.build());
178 //Update augmented data
179 nodeData.addAugmentation(NodeMeterStatistics.class, meterStats.build());
181 InstanceIdentifier<? extends Object> refValue = ref.getValue();
182 it.putOperationalData(refValue, nodeData.build());
188 public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
189 //Add statistics to local cache
190 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
191 if(!cache.containsKey(notification.getId())){
192 cache.put(notification.getId(), new NodeStatistics());
194 cache.get(notification.getId()).setGroupDescStats(notification.getGroupDescStats());
196 //Publish data to configuration data store
197 DataModificationTransaction it = this.statisticsManager.startChange();
198 NodeKey key = new NodeKey(notification.getId());
199 NodeRef ref = getNodeRef(key);
201 final NodeBuilder nodeData = new NodeBuilder();
202 nodeData.setKey(key);
204 NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
205 GroupDescBuilder stats = new GroupDescBuilder();
206 stats.setGroupDescStats(notification.getGroupDescStats());
207 groupDesc.setGroupDesc(stats.build());
209 //Update augmented data
210 nodeData.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
212 InstanceIdentifier<? extends Object> refValue = ref.getValue();
213 it.putOperationalData(refValue, nodeData.build());
219 public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
221 //Add statistics to local cache
222 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
223 if(!cache.containsKey(notification.getId())){
224 cache.put(notification.getId(), new NodeStatistics());
226 cache.get(notification.getId()).setGroupStatistics(notification.getGroupStats());
228 //Publish data to configuration data store
230 DataModificationTransaction it = this.statisticsManager.startChange();
231 NodeKey key = new NodeKey(notification.getId());
232 NodeRef ref = getNodeRef(key);
234 final NodeBuilder nodeData = new NodeBuilder();
235 nodeData.setKey(key);
237 NodeGroupStatisticsBuilder groupStats = new NodeGroupStatisticsBuilder();
238 GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
239 stats.setGroupStats(notification.getGroupStats());
240 groupStats.setGroupStatistics(stats.build());
242 //Update augmented data
243 nodeData.addAugmentation(NodeGroupStatistics.class, groupStats.build());
245 InstanceIdentifier<? extends Object> refValue = ref.getValue();
246 it.putOperationalData(refValue, nodeData.build());
249 // for (GroupStats groupstat : notification.getGroupStats()) {
251 // GroupStatsKey groupKey = groupstat.getKey();
252 // InstanceIdentifier<? extends Object> id = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).augmentation(NodeGroupStatistics.class).child(GroupStatistics.class).child(GroupStats.class,groupKey).toInstance();
253 // it.putOperationalData(id, groupstat);
259 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
261 //Add statistics to local cache
262 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
263 if(!cache.containsKey(notification.getId())){
264 cache.put(notification.getId(), new NodeStatistics());
266 MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
267 meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
268 meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
269 meterFeature.setMaxBands(notification.getMaxBands());
270 meterFeature.setMaxColor(notification.getMaxColor());
271 meterFeature.setMaxMeter(notification.getMaxMeter());
273 cache.get(notification.getId()).setMeterFeatures(meterFeature.build());
275 //Publish data to configuration data store
276 DataModificationTransaction it = this.statisticsManager.startChange();
277 NodeKey key = new NodeKey(notification.getId());
278 NodeRef ref = getNodeRef(key);
280 final NodeBuilder nodeData = new NodeBuilder();
281 nodeData.setKey(key);
283 NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
284 nodeMeterFeatures.setMeterFeatures(meterFeature.build());
286 //Update augmented data
287 nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
289 InstanceIdentifier<? extends Object> refValue = ref.getValue();
290 it.putOperationalData(refValue, nodeData.build());
295 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
297 //Add statistics to local cache
298 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
299 if(!cache.containsKey(notification.getId())){
300 cache.put(notification.getId(), new NodeStatistics());
303 GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
304 groupFeatures.setActions(notification.getActions());
305 groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
306 groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
307 groupFeatures.setMaxGroups(notification.getMaxGroups());
308 cache.get(notification.getId()).setGroupFeatures(groupFeatures.build());
310 //Publish data to configuration data store
311 DataModificationTransaction it = this.statisticsManager.startChange();
312 NodeKey key = new NodeKey(notification.getId());
313 NodeRef ref = getNodeRef(key);
315 final NodeBuilder nodeData = new NodeBuilder();
316 nodeData.setKey(key);
318 NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
319 nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
321 //Update augmented data
322 nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
324 InstanceIdentifier<? extends Object> refValue = ref.getValue();
325 it.putOperationalData(refValue, nodeData.build());
330 public void onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
331 NodeKey key = new NodeKey(notification.getId());
332 sucLogger.info("Received flow stats update : {}",notification.toString());
334 for(FlowAndStatisticsMapList map: notification.getFlowAndStatisticsMapList()){
335 short tableId = map.getTableId();
337 DataModificationTransaction it = this.statisticsManager.startChange();
339 boolean foundOriginalFlow = false;
341 FlowBuilder flowBuilder = new FlowBuilder();
343 FlowStatisticsDataBuilder flowStatisticsData = new FlowStatisticsDataBuilder();
345 FlowBuilder flow = new FlowBuilder();
346 flow.setContainerName(map.getContainerName());
347 flow.setBufferId(map.getBufferId());
348 flow.setCookie(map.getCookie());
349 flow.setCookieMask(map.getCookieMask());
350 flow.setFlags(map.getFlags());
351 flow.setFlowName(map.getFlowName());
352 flow.setHardTimeout(map.getHardTimeout());
353 if(map.getFlowId() != null)
354 flow.setId(new FlowId(map.getFlowId().getValue()));
355 flow.setIdleTimeout(map.getIdleTimeout());
356 flow.setInstallHw(map.isInstallHw());
357 flow.setInstructions(map.getInstructions());
358 if(map.getFlowId()!= null)
359 flow.setKey(new FlowKey(new FlowId(map.getKey().getFlowId().getValue())));
360 flow.setMatch(map.getMatch());
361 flow.setOutGroup(map.getOutGroup());
362 flow.setOutPort(map.getOutPort());
363 flow.setPriority(map.getPriority());
364 flow.setStrict(map.isStrict());
365 flow.setTableId(tableId);
367 Flow flowRule = flow.build();
369 FlowAndStatisticsMapListBuilder stats = new FlowAndStatisticsMapListBuilder();
370 stats.setByteCount(map.getByteCount());
371 stats.setPacketCount(map.getPacketCount());
372 stats.setDuration(map.getDuration());
374 GenericStatistics flowStats = stats.build();
376 //Add statistics to local cache
377 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
378 if(!cache.containsKey(notification.getId())){
379 cache.put(notification.getId(), new NodeStatistics());
381 if(!cache.get(notification.getId()).getFlowAndStatsMap().containsKey(tableId)){
382 cache.get(notification.getId()).getFlowAndStatsMap().put(tableId, new HashMap<Flow,GenericStatistics>());
384 cache.get(notification.getId()).getFlowAndStatsMap().get(tableId).put(flowRule,flowStats);
386 //Augment the data to the flow node
388 FlowStatisticsBuilder flowStatistics = new FlowStatisticsBuilder();
389 flowStatistics.setByteCount(flowStats.getByteCount());
390 flowStatistics.setPacketCount(flowStats.getPacketCount());
391 flowStatistics.setDuration(flowStats.getDuration());
392 flowStatistics.setContainerName(map.getContainerName());
393 flowStatistics.setBufferId(map.getBufferId());
394 flowStatistics.setCookie(map.getCookie());
395 flowStatistics.setCookieMask(map.getCookieMask());
396 flowStatistics.setFlags(map.getFlags());
397 flowStatistics.setFlowName(map.getFlowName());
398 flowStatistics.setHardTimeout(map.getHardTimeout());
399 flowStatistics.setIdleTimeout(map.getIdleTimeout());
400 flowStatistics.setInstallHw(map.isInstallHw());
401 flowStatistics.setInstructions(map.getInstructions());
402 flowStatistics.setMatch(map.getMatch());
403 flowStatistics.setOutGroup(map.getOutGroup());
404 flowStatistics.setOutPort(map.getOutPort());
405 flowStatistics.setPriority(map.getPriority());
406 flowStatistics.setStrict(map.isStrict());
407 flowStatistics.setTableId(tableId);
409 flowStatisticsData.setFlowStatistics(flowStatistics.build());
411 sucLogger.debug("Flow : {}",flowRule.toString());
412 sucLogger.debug("Statistics to augment : {}",flowStatistics.build().toString());
414 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
415 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
417 Table table= (Table)it.readConfigurationData(tableRef);
419 //TODO: Not a good way to do it, need to figure out better way.
420 //TODO: major issue in any alternate approach is that flow key is incrementally assigned
421 //to the flows stored in data store.
424 for(Flow existingFlow : table.getFlow()){
425 sucLogger.debug("Existing flow in data store : {}",existingFlow.toString());
426 if(flowEquals(flowRule,existingFlow)){
427 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
428 .augmentation(FlowCapableNode.class)
429 .child(Table.class, new TableKey(tableId))
430 .child(Flow.class,existingFlow.getKey()).toInstance();
431 flowBuilder.setKey(existingFlow.getKey());
432 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
433 sucLogger.debug("Found matching flow in the datastore, augmenting statistics");
434 foundOriginalFlow = true;
435 it.putOperationalData(flowRef, flowBuilder.build());
442 if(!foundOriginalFlow){
443 sucLogger.info("Associated original flow is not found in data store. Augmenting flow in operational data st");
444 //TODO: Temporary fix: format [ 0+tableid+0+unaccounted flow counter]
445 long flowKey = Long.getLong(new String("0"+Short.toString(tableId)+"0"+Integer.toString(this.unaccountedFlowsCounter)));
446 FlowKey newFlowKey = new FlowKey(new FlowId(flowKey));
447 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
448 .augmentation(FlowCapableNode.class)
449 .child(Table.class, new TableKey(tableId))
450 .child(Flow.class,newFlowKey).toInstance();
451 flowBuilder.setKey(newFlowKey);
452 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
453 sucLogger.debug("Flow was no present in data store, augmenting statistics as an unaccounted flow");
454 it.putOperationalData(flowRef, flowBuilder.build());
461 public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
462 NodeKey key = new NodeKey(notification.getId());
463 sucLogger.debug("Received aggregate flow statistics update : {}",notification.toString());
465 Short tableId = this.statisticsManager.getMultipartMessageManager().getTableIdForTxId(notification.getTransactionId());
468 DataModificationTransaction it = this.statisticsManager.startChange();
470 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
471 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
473 AggregateFlowStatisticsDataBuilder aggregateFlowStatisticsDataBuilder = new AggregateFlowStatisticsDataBuilder();
474 AggregateFlowStatisticsBuilder aggregateFlowStatisticsBuilder = new AggregateFlowStatisticsBuilder();
475 aggregateFlowStatisticsBuilder.setByteCount(notification.getByteCount());
476 aggregateFlowStatisticsBuilder.setFlowCount(notification.getFlowCount());
477 aggregateFlowStatisticsBuilder.setPacketCount(notification.getPacketCount());
478 aggregateFlowStatisticsDataBuilder.setAggregateFlowStatistics(aggregateFlowStatisticsBuilder.build());
480 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
481 if(!cache.containsKey(notification.getId())){
482 cache.put(notification.getId(), new NodeStatistics());
484 cache.get(notification.getId()).getTableAndAggregateFlowStatsMap().put(tableId,aggregateFlowStatisticsBuilder.build());
486 sucLogger.debug("Augment aggregate statistics: {} for table {} on Node {}",aggregateFlowStatisticsBuilder.build().toString(),tableId,key);
488 TableBuilder tableBuilder = new TableBuilder();
489 tableBuilder.setKey(new TableKey(tableId));
490 tableBuilder.addAugmentation(AggregateFlowStatisticsData.class, aggregateFlowStatisticsDataBuilder.build());
491 it.putOperationalData(tableRef, tableBuilder.build());
498 public void onPortStatisticsUpdate(PortStatisticsUpdate notification) {
499 NodeKey key = new NodeKey(notification.getId());
500 sucLogger.info("Received port stats update : {}",notification.toString());
502 //Add statistics to local cache
503 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
504 if(!cache.containsKey(notification.getId())){
505 cache.put(notification.getId(), new NodeStatistics());
509 List<NodeConnectorStatisticsAndPortNumberMap> portsStats = notification.getNodeConnectorStatisticsAndPortNumberMap();
510 for(NodeConnectorStatisticsAndPortNumberMap portStats : portsStats){
512 DataModificationTransaction it = this.statisticsManager.startChange();
514 FlowCapableNodeConnectorStatisticsBuilder statisticsBuilder
515 = new FlowCapableNodeConnectorStatisticsBuilder();
516 statisticsBuilder.setBytes(portStats.getBytes());
517 statisticsBuilder.setCollisionCount(portStats.getCollisionCount());
518 statisticsBuilder.setDuration(portStats.getDuration());
519 statisticsBuilder.setPackets(portStats.getPackets());
520 statisticsBuilder.setReceiveCrcError(portStats.getReceiveCrcError());
521 statisticsBuilder.setReceiveDrops(portStats.getReceiveDrops());
522 statisticsBuilder.setReceiveErrors(portStats.getReceiveErrors());
523 statisticsBuilder.setReceiveFrameError(portStats.getReceiveFrameError());
524 statisticsBuilder.setReceiveOverRunError(portStats.getReceiveOverRunError());
525 statisticsBuilder.setTransmitDrops(portStats.getTransmitDrops());
526 statisticsBuilder.setTransmitErrors(portStats.getTransmitErrors());
528 //Update data in the cache
529 cache.get(notification.getId()).getNodeConnectorStats().put(portStats.getNodeConnectorId(), statisticsBuilder.build());
531 //Augment data to the node-connector
532 FlowCapableNodeConnectorStatisticsDataBuilder statisticsDataBuilder =
533 new FlowCapableNodeConnectorStatisticsDataBuilder();
535 statisticsDataBuilder.setFlowCapableNodeConnectorStatistics(statisticsBuilder.build());
537 InstanceIdentifier<NodeConnector> nodeConnectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).child(NodeConnector.class, new NodeConnectorKey(portStats.getNodeConnectorId())).toInstance();
539 NodeConnector nodeConnector = (NodeConnector)it.readOperationalData(nodeConnectorRef);
541 if(nodeConnector != null){
542 sucLogger.debug("Augmenting port statistics {} to port {}",statisticsDataBuilder.build().toString(),nodeConnectorRef.toString());
543 NodeConnectorBuilder nodeConnectorBuilder = new NodeConnectorBuilder();
544 nodeConnectorBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, statisticsDataBuilder.build());
545 it.putOperationalData(nodeConnectorRef, nodeConnectorBuilder.build());
552 public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
553 NodeKey key = new NodeKey(notification.getId());
554 sucLogger.debug("Received flow table statistics update : {}",notification.toString());
556 List<FlowTableAndStatisticsMap> flowTablesStatsList = notification.getFlowTableAndStatisticsMap();
557 for (FlowTableAndStatisticsMap ftStats : flowTablesStatsList){
559 DataModificationTransaction it = this.statisticsManager.startChange();
561 InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
562 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
564 FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
566 FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
567 statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
568 statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
569 statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
571 statisticsDataBuilder.setFlowTableStatistics(statisticsBuilder.build());
573 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
574 if(!cache.containsKey(notification.getId())){
575 cache.put(notification.getId(), new NodeStatistics());
577 cache.get(notification.getId()).getFlowTableAndStatisticsMap().put(ftStats.getTableId().getValue(),statisticsBuilder.build());
579 sucLogger.debug("Augment flow table statistics: {} for table {} on Node {}",statisticsBuilder.build().toString(),ftStats.getTableId(),key);
581 TableBuilder tableBuilder = new TableBuilder();
582 tableBuilder.setKey(new TableKey(ftStats.getTableId().getValue()));
583 tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
584 it.putOperationalData(tableRef, tableBuilder.build());
590 public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
591 NodeKey key = new NodeKey(notification.getId());
592 sucLogger.info("Received queue stats update : {}",notification.toString());
594 //Add statistics to local cache
595 ConcurrentMap<NodeId, NodeStatistics> cache = this.statisticsManager.getStatisticsCache();
596 if(!cache.containsKey(notification.getId())){
597 cache.put(notification.getId(), new NodeStatistics());
600 List<QueueIdAndStatisticsMap> queuesStats = notification.getQueueIdAndStatisticsMap();
601 for(QueueIdAndStatisticsMap swQueueStats : queuesStats){
603 if(!cache.get(notification.getId()).getNodeConnectorAndQueuesStatsMap().containsKey(swQueueStats.getNodeConnectorId())){
604 cache.get(notification.getId()).getNodeConnectorAndQueuesStatsMap().put(swQueueStats.getNodeConnectorId(), new HashMap<QueueId,GenericQueueStatistics>());
607 FlowCapableNodeConnectorQueueStatisticsDataBuilder queueStatisticsDataBuilder = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
609 FlowCapableNodeConnectorQueueStatisticsBuilder queueStatisticsBuilder = new FlowCapableNodeConnectorQueueStatisticsBuilder();
611 queueStatisticsBuilder.fieldsFrom(swQueueStats);
613 queueStatisticsDataBuilder.setFlowCapableNodeConnectorQueueStatistics(queueStatisticsBuilder.build());
615 cache.get(notification.getId()).getNodeConnectorAndQueuesStatsMap()
616 .get(swQueueStats.getNodeConnectorId())
617 .put(swQueueStats.getQueueId(), queueStatisticsBuilder.build());
620 DataModificationTransaction it = this.statisticsManager.startChange();
622 InstanceIdentifier<Queue> queueRef
623 = InstanceIdentifier.builder(Nodes.class)
624 .child(Node.class, key)
625 .child(NodeConnector.class, new NodeConnectorKey(swQueueStats.getNodeConnectorId()))
626 .augmentation(FlowCapableNodeConnector.class)
627 .child(Queue.class, new QueueKey(swQueueStats.getQueueId())).toInstance();
629 QueueBuilder queueBuilder = new QueueBuilder();
630 queueBuilder.addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, queueStatisticsDataBuilder.build());
631 queueBuilder.setKey(new QueueKey(swQueueStats.getQueueId()));
633 sucLogger.info("Augmenting queue statistics {} of queue {} to port {}"
634 ,queueStatisticsDataBuilder.build().toString(),
635 swQueueStats.getQueueId(),
636 swQueueStats.getNodeConnectorId());
638 it.putOperationalData(queueRef, queueBuilder.build());
646 public void onFlowStatisticsUpdated(FlowStatisticsUpdated notification) {
647 // TODO Auto-generated method stub
648 //TODO: Depricated, will clean it up once sal-compatibility is fixed.
649 //Sal-Compatibility code usage this notification event.
654 public void onFlowTableStatisticsUpdated(FlowTableStatisticsUpdated notification) {
655 // TODO Auto-generated method stub
656 //TODO: Need to implement it yet
661 public void onNodeConnectorStatisticsUpdated(NodeConnectorStatisticsUpdated notification) {
662 // TODO Auto-generated method stub
663 //TODO: Need to implement it yet
667 private NodeRef getNodeRef(NodeKey nodeKey){
668 InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
669 return new NodeRef(builder.toInstance());
672 public boolean flowEquals(Flow statsFlow, Flow storedFlow) {
673 if (statsFlow.getClass() != storedFlow.getClass()) {
676 if (statsFlow.getBufferId()== null) {
677 if (storedFlow.getBufferId() != null) {
680 } else if(!statsFlow.getBufferId().equals(storedFlow.getBufferId())) {
683 if (statsFlow.getContainerName()== null) {
684 if (storedFlow.getContainerName()!= null) {
687 } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
690 if (statsFlow.getCookie()== null) {
691 if (storedFlow.getCookie()!= null) {
694 } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
697 if (statsFlow.getMatch()== null) {
698 if (storedFlow.getMatch() != null) {
701 } else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
704 if (statsFlow.getCookie()== null) {
705 if (storedFlow.getCookie()!= null) {
708 } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
711 if (statsFlow.getHardTimeout() == null) {
712 if (storedFlow.getHardTimeout() != null) {
715 } else if(!statsFlow.getHardTimeout().equals(storedFlow.getHardTimeout() )) {
718 if (statsFlow.getIdleTimeout()== null) {
719 if (storedFlow.getIdleTimeout() != null) {
722 } else if(!statsFlow.getIdleTimeout().equals(storedFlow.getIdleTimeout())) {
725 if (statsFlow.getPriority() == null) {
726 if (storedFlow.getPriority() != null) {
729 } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
732 if (statsFlow.getTableId() == null) {
733 if (storedFlow.getTableId() != null) {
736 } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {