Merge "Added test for MouontPoints and URI"
[controller.git] / opendaylight / md-sal / statistics-manager / src / main / java / org / opendaylight / controller / md / statistics / manager / StatisticsUpdateCommiter.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.statistics.manager;
9
10 import java.util.List;
11 import java.util.concurrent.ConcurrentMap;
12
13 import org.opendaylight.controller.md.statistics.manager.NodeStatisticsAger.FlowEntry;
14 import org.opendaylight.controller.md.statistics.manager.NodeStatisticsAger.QueueEntry;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsData;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsDataBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.aggregate.flow.statistics.AggregateFlowStatisticsBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStats;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupDescStatsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeatures;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupFeaturesBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatisticsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.desc.GroupDescBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.features.GroupFeaturesBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStats;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterConfigStatsBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeatures;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterFeaturesBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatisticsBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.MeterFeaturesBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterConfigStatsBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsListener;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
104 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
105 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
106 import org.slf4j.Logger;
107 import org.slf4j.LoggerFactory;
108
109 /**
110  * Class implement statistics manager related listener interface and augment all the 
111  * received statistics data to data stores.
112  * TODO: Need to add error message listener and clean-up the associated tx id 
113  * if it exists in the tx-id cache.
114  * @author vishnoianil
115  *
116  */
117 public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
118         OpendaylightMeterStatisticsListener, 
119         OpendaylightFlowStatisticsListener,
120         OpendaylightPortStatisticsListener,
121         OpendaylightFlowTableStatisticsListener,
122         OpendaylightQueueStatisticsListener{
123     
124     public final static Logger sucLogger = LoggerFactory.getLogger(StatisticsUpdateCommiter.class);
125
126     private final StatisticsProvider statisticsManager;
127     
128     private int unaccountedFlowsCounter = 1;
129
130     public StatisticsUpdateCommiter(final StatisticsProvider manager){
131
132         this.statisticsManager = manager;
133     }
134     
135     public StatisticsProvider getStatisticsManager(){
136         return statisticsManager;
137     }
138    
139     @Override
140     public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
141         //Check if response is for the request statistics-manager sent.
142         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
143             return;
144         
145         NodeKey key = new NodeKey(notification.getId());
146
147         //Add statistics to local cache
148         ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
149         if(!cache.containsKey(notification.getId())){
150             cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
151         }
152         cache.get(notification.getId()).updateMeterConfigStats(notification.getMeterConfigStats());
153         
154         //Publish data to configuration data store
155         List<MeterConfigStats> meterConfigStatsList = notification.getMeterConfigStats();
156         
157         for(MeterConfigStats meterConfigStats : meterConfigStatsList){
158             DataModificationTransaction it = this.statisticsManager.startChange();
159             MeterBuilder meterBuilder = new MeterBuilder();
160             MeterKey meterKey = new MeterKey(meterConfigStats.getMeterId());
161             meterBuilder.setKey(meterKey);
162             
163             InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
164                                                                                         .augmentation(FlowCapableNode.class)
165                                                                                         .child(Meter.class,meterKey).toInstance();
166             
167             NodeMeterConfigStatsBuilder meterConfig= new NodeMeterConfigStatsBuilder();
168             MeterConfigStatsBuilder stats = new MeterConfigStatsBuilder();
169             stats.fieldsFrom(meterConfigStats);
170             meterConfig.setMeterConfigStats(stats.build());
171             
172             //Update augmented data
173             meterBuilder.addAugmentation(NodeMeterConfigStats.class, meterConfig.build());
174             it.putOperationalData(meterRef, meterBuilder.build());
175             it.commit();
176
177         }
178     }
179
180     @Override
181     public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
182         
183         //Check if response is for the request statistics-manager sent.
184         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
185             return;
186
187         NodeKey key = new NodeKey(notification.getId());
188         
189         List<MeterStats> meterStatsList = notification.getMeterStats();
190         
191         for(MeterStats meterStats : meterStatsList){
192
193             //Publish data to configuration data store
194             DataModificationTransaction it = this.statisticsManager.startChange();
195             MeterBuilder meterBuilder = new MeterBuilder();
196             MeterKey meterKey = new MeterKey(meterStats.getMeterId());
197             meterBuilder.setKey(meterKey);
198             
199             InstanceIdentifier<Meter> meterRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
200                                                                                         .augmentation(FlowCapableNode.class)
201                                                                                         .child(Meter.class,meterKey).toInstance();
202             
203             NodeMeterStatisticsBuilder meterStatsBuilder= new NodeMeterStatisticsBuilder();
204             MeterStatisticsBuilder stats = new MeterStatisticsBuilder();
205             stats.fieldsFrom(meterStats);
206             meterStatsBuilder.setMeterStatistics(stats.build());
207
208             //Update augmented data
209             meterBuilder.addAugmentation(NodeMeterStatistics.class, meterStatsBuilder.build());
210             it.putOperationalData(meterRef, meterBuilder.build());
211             it.commit();
212         }
213     }
214
215     @Override
216     public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
217         
218         //Check if response is for the request statistics-manager sent.
219         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
220             return;
221
222         NodeKey key = new NodeKey(notification.getId());
223
224         //Add statistics to local cache
225         ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
226         if(!cache.containsKey(notification.getId())){
227             cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
228         }
229         cache.get(notification.getId()).updateGroupDescStats(notification.getGroupDescStats());
230         
231         //Publish data to configuration data store
232         List<GroupDescStats> groupDescStatsList = notification.getGroupDescStats();
233
234         for(GroupDescStats groupDescStats : groupDescStatsList){
235             DataModificationTransaction it = this.statisticsManager.startChange();
236             
237             GroupBuilder groupBuilder = new GroupBuilder();
238             GroupKey groupKey = new GroupKey(groupDescStats.getGroupId());
239             groupBuilder.setKey(groupKey);
240             
241             InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
242                                                                                         .augmentation(FlowCapableNode.class)
243                                                                                         .child(Group.class,groupKey).toInstance();
244
245             NodeGroupDescStatsBuilder groupDesc= new NodeGroupDescStatsBuilder();
246             GroupDescBuilder stats = new GroupDescBuilder();
247             stats.fieldsFrom(groupDescStats);
248             groupDesc.setGroupDesc(stats.build());
249             
250             //Update augmented data
251             groupBuilder.addAugmentation(NodeGroupDescStats.class, groupDesc.build());
252
253             it.putOperationalData(groupRef, groupBuilder.build());
254             it.commit();
255         }
256     }
257
258     @Override
259     public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
260         
261         //Check if response is for the request statistics-manager sent.
262         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
263             return;
264
265         //Publish data to configuration data store
266         NodeKey key = new NodeKey(notification.getId());
267         List<GroupStats> groupStatsList = notification.getGroupStats();
268
269         for(GroupStats groupStats : groupStatsList){
270             DataModificationTransaction it = this.statisticsManager.startChange();
271             
272             GroupBuilder groupBuilder = new GroupBuilder();
273             GroupKey groupKey = new GroupKey(groupStats.getGroupId());
274             groupBuilder.setKey(groupKey);
275             
276             InstanceIdentifier<Group> groupRef = InstanceIdentifier.builder(Nodes.class).child(Node.class,key)
277                                                                                         .augmentation(FlowCapableNode.class)
278                                                                                         .child(Group.class,groupKey).toInstance();
279
280             NodeGroupStatisticsBuilder groupStatisticsBuilder= new NodeGroupStatisticsBuilder();
281             GroupStatisticsBuilder stats = new GroupStatisticsBuilder();
282             stats.fieldsFrom(groupStats);
283             groupStatisticsBuilder.setGroupStatistics(stats.build());
284             
285             //Update augmented data
286             groupBuilder.addAugmentation(NodeGroupStatistics.class, groupStatisticsBuilder.build());
287             it.putOperationalData(groupRef, groupBuilder.build());
288             it.commit();
289         }
290     }
291     
292     @Override
293     public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
294
295         MeterFeaturesBuilder meterFeature = new MeterFeaturesBuilder();
296         meterFeature.setMeterBandSupported(notification.getMeterBandSupported());
297         meterFeature.setMeterCapabilitiesSupported(notification.getMeterCapabilitiesSupported());
298         meterFeature.setMaxBands(notification.getMaxBands());
299         meterFeature.setMaxColor(notification.getMaxColor());
300         meterFeature.setMaxMeter(notification.getMaxMeter());
301         
302         //Publish data to configuration data store
303         DataModificationTransaction it = this.statisticsManager.startChange();
304         NodeKey key = new NodeKey(notification.getId());
305         NodeRef ref = getNodeRef(key);
306         
307         final NodeBuilder nodeData = new NodeBuilder(); 
308         nodeData.setKey(key);
309         
310         NodeMeterFeaturesBuilder nodeMeterFeatures= new NodeMeterFeaturesBuilder();
311         nodeMeterFeatures.setMeterFeatures(meterFeature.build());
312         
313         //Update augmented data
314         nodeData.addAugmentation(NodeMeterFeatures.class, nodeMeterFeatures.build());
315         
316         InstanceIdentifier<? extends Object> refValue = ref.getValue();
317         it.putOperationalData(refValue, nodeData.build());
318         it.commit();
319     }
320     
321     @Override
322     public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
323
324         GroupFeaturesBuilder groupFeatures = new GroupFeaturesBuilder();
325         groupFeatures.setActions(notification.getActions());
326         groupFeatures.setGroupCapabilitiesSupported(notification.getGroupCapabilitiesSupported());
327         groupFeatures.setGroupTypesSupported(notification.getGroupTypesSupported());
328         groupFeatures.setMaxGroups(notification.getMaxGroups());
329         
330         //Publish data to configuration data store
331         DataModificationTransaction it = this.statisticsManager.startChange();
332         NodeKey key = new NodeKey(notification.getId());
333         NodeRef ref = getNodeRef(key);
334         
335         final NodeBuilder nodeData = new NodeBuilder(); 
336         nodeData.setKey(key);
337         
338         NodeGroupFeaturesBuilder nodeGroupFeatures= new NodeGroupFeaturesBuilder();
339         nodeGroupFeatures.setGroupFeatures(groupFeatures.build());
340         
341         //Update augmented data
342         nodeData.addAugmentation(NodeGroupFeatures.class, nodeGroupFeatures.build());
343         
344         InstanceIdentifier<? extends Object> refValue = ref.getValue();
345         it.putOperationalData(refValue, nodeData.build());
346         it.commit();
347     }
348
349     @Override
350     public void onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
351         
352         //Check if response is for the request statistics-manager sent.
353         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
354             return;
355
356         NodeKey key = new NodeKey(notification.getId());
357         sucLogger.debug("Received flow stats update : {}",notification.toString());
358         
359         for(FlowAndStatisticsMapList map: notification.getFlowAndStatisticsMapList()){
360             short tableId = map.getTableId();
361             
362             DataModificationTransaction it = this.statisticsManager.startChange();
363
364             boolean foundOriginalFlow = false;
365
366             FlowBuilder flowBuilder = new FlowBuilder();
367
368             FlowStatisticsDataBuilder flowStatisticsData = new FlowStatisticsDataBuilder();
369
370             FlowBuilder flow = new FlowBuilder();
371             flow.setContainerName(map.getContainerName());
372             flow.setBufferId(map.getBufferId());
373             flow.setCookie(map.getCookie());
374             flow.setCookieMask(map.getCookieMask());
375             flow.setFlags(map.getFlags());
376             flow.setFlowName(map.getFlowName());
377             flow.setHardTimeout(map.getHardTimeout());
378             if(map.getFlowId() != null)
379                 flow.setId(new FlowId(map.getFlowId().getValue()));
380             flow.setIdleTimeout(map.getIdleTimeout());
381             flow.setInstallHw(map.isInstallHw());
382             flow.setInstructions(map.getInstructions());
383             if(map.getFlowId()!= null)
384                 flow.setKey(new FlowKey(new FlowId(map.getKey().getFlowId().getValue())));
385             flow.setMatch(map.getMatch());
386             flow.setOutGroup(map.getOutGroup());
387             flow.setOutPort(map.getOutPort());
388             flow.setPriority(map.getPriority());
389             flow.setStrict(map.isStrict());
390             flow.setTableId(tableId);
391                 
392             Flow flowRule = flow.build();
393                 
394             FlowAndStatisticsMapListBuilder stats = new FlowAndStatisticsMapListBuilder();
395             stats.setByteCount(map.getByteCount());
396             stats.setPacketCount(map.getPacketCount());
397             stats.setDuration(map.getDuration());
398                 
399             GenericStatistics flowStats = stats.build();
400                 
401             //Add statistics to local cache
402             ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
403             if(!cache.containsKey(notification.getId())){
404                 cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
405             }
406             NodeStatisticsAger nsa = cache.get(notification.getId());
407             FlowEntry flowStatsEntry = nsa.new FlowEntry(tableId,flowRule);
408             cache.get(notification.getId()).updateFlowStats(flowStatsEntry);
409                 
410             //Augment the data to the flow node
411
412             FlowStatisticsBuilder flowStatistics = new FlowStatisticsBuilder();
413             flowStatistics.setByteCount(flowStats.getByteCount());
414             flowStatistics.setPacketCount(flowStats.getPacketCount());
415             flowStatistics.setDuration(flowStats.getDuration());
416             flowStatistics.setContainerName(map.getContainerName());
417             flowStatistics.setBufferId(map.getBufferId());
418             flowStatistics.setCookie(map.getCookie());
419             flowStatistics.setCookieMask(map.getCookieMask());
420             flowStatistics.setFlags(map.getFlags());
421             flowStatistics.setFlowName(map.getFlowName());
422             flowStatistics.setHardTimeout(map.getHardTimeout());
423             flowStatistics.setIdleTimeout(map.getIdleTimeout());
424             flowStatistics.setInstallHw(map.isInstallHw());
425             flowStatistics.setInstructions(map.getInstructions());
426             flowStatistics.setMatch(map.getMatch());
427             flowStatistics.setOutGroup(map.getOutGroup());
428             flowStatistics.setOutPort(map.getOutPort());
429             flowStatistics.setPriority(map.getPriority());
430             flowStatistics.setStrict(map.isStrict());
431             flowStatistics.setTableId(tableId);
432
433             flowStatisticsData.setFlowStatistics(flowStatistics.build());
434                 
435             sucLogger.debug("Flow : {}",flowRule.toString());
436             sucLogger.debug("Statistics to augment : {}",flowStatistics.build().toString());
437
438             InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
439                     .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
440             
441             Table table= (Table)it.readConfigurationData(tableRef);
442
443             //TODO: Not a good way to do it, need to figure out better way.
444             //TODO: major issue in any alternate approach is that flow key is incrementally assigned 
445             //to the flows stored in data store.
446             if(table != null){
447
448                 for(Flow existingFlow : table.getFlow()){
449                     sucLogger.debug("Existing flow in data store : {}",existingFlow.toString());
450                     if(flowEquals(flowRule,existingFlow)){
451                         InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
452                                 .augmentation(FlowCapableNode.class)
453                                 .child(Table.class, new TableKey(tableId))
454                                 .child(Flow.class,existingFlow.getKey()).toInstance();
455                         flowBuilder.setKey(existingFlow.getKey());
456                         flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
457                         sucLogger.info("Found matching flow in the datastore, augmenting statistics");
458                         foundOriginalFlow = true;
459                         it.putOperationalData(flowRef, flowBuilder.build());
460                         it.commit();
461                         break;
462                     }
463                 }
464             }
465             
466             table= (Table)it.readOperationalData(tableRef);
467             if(!foundOriginalFlow && table != null){
468
469                 for(Flow existingFlow : table.getFlow()){
470                     FlowStatisticsData augmentedflowStatisticsData = existingFlow.getAugmentation(FlowStatisticsData.class);
471                     if(augmentedflowStatisticsData != null){
472                         FlowBuilder existingOperationalFlow = new FlowBuilder();
473                         existingOperationalFlow.fieldsFrom(augmentedflowStatisticsData.getFlowStatistics());
474                         sucLogger.debug("Existing unaccounted flow in operational data store : {}",existingFlow.toString());
475                         if(flowEquals(flowRule,existingOperationalFlow.build())){
476                             InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
477                                     .augmentation(FlowCapableNode.class)
478                                     .child(Table.class, new TableKey(tableId))
479                                     .child(Flow.class,existingFlow.getKey()).toInstance();
480                             flowBuilder.setKey(existingFlow.getKey());
481                             flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
482                             sucLogger.debug("Found matching flow in the operational datastore, augmenting statistics");
483                             foundOriginalFlow = true;
484                             it.putOperationalData(flowRef, flowBuilder.build());
485                             it.commit();
486                             break;
487                         }
488                     }
489                 }
490             }
491             if(!foundOriginalFlow){
492                 sucLogger.debug("Associated original flow is not found in data store. Augmenting flow in operational data store");
493                 long flowKey = Long.parseLong(new String("1"+Short.toString(tableId)+"0"+Integer.toString(this.unaccountedFlowsCounter)));
494                 this.unaccountedFlowsCounter++;
495                 FlowKey newFlowKey = new FlowKey(new FlowId(Long.toString(flowKey)));
496                 InstanceIdentifier<Flow> flowRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
497                         .augmentation(FlowCapableNode.class)
498                         .child(Table.class, new TableKey(tableId))
499                         .child(Flow.class,newFlowKey).toInstance();
500                 flowBuilder.setKey(newFlowKey);
501                 flowBuilder.addAugmentation(FlowStatisticsData.class, flowStatisticsData.build());
502                 sucLogger.info("Flow was no present in data store, augmenting statistics as an unaccounted flow");
503                 it.putOperationalData(flowRef, flowBuilder.build());
504                 it.commit();
505             }
506         }
507     }
508
509     @Override
510     public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
511         //Check if response is for the request statistics-manager sent.
512         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
513             return;
514
515         NodeKey key = new NodeKey(notification.getId());
516         sucLogger.debug("Received aggregate flow statistics update : {}",notification.toString());
517         
518         Short tableId = this.statisticsManager.getMultipartMessageManager().getTableIdForTxId(notification.getTransactionId());
519         if(tableId != null){
520             
521             DataModificationTransaction it = this.statisticsManager.startChange();
522
523             InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
524                     .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).toInstance();
525
526             AggregateFlowStatisticsDataBuilder aggregateFlowStatisticsDataBuilder = new AggregateFlowStatisticsDataBuilder();
527             AggregateFlowStatisticsBuilder aggregateFlowStatisticsBuilder = new AggregateFlowStatisticsBuilder();
528             aggregateFlowStatisticsBuilder.setByteCount(notification.getByteCount());
529             aggregateFlowStatisticsBuilder.setFlowCount(notification.getFlowCount());
530             aggregateFlowStatisticsBuilder.setPacketCount(notification.getPacketCount());
531             aggregateFlowStatisticsDataBuilder.setAggregateFlowStatistics(aggregateFlowStatisticsBuilder.build());
532             
533             sucLogger.debug("Augment aggregate statistics: {} for table {} on Node {}",aggregateFlowStatisticsBuilder.build().toString(),tableId,key);
534
535             TableBuilder tableBuilder = new TableBuilder();
536             tableBuilder.setKey(new TableKey(tableId));
537             tableBuilder.addAugmentation(AggregateFlowStatisticsData.class, aggregateFlowStatisticsDataBuilder.build());
538             it.putOperationalData(tableRef, tableBuilder.build());
539             it.commit();
540
541         }
542     }
543
544     @Override
545     public void onNodeConnectorStatisticsUpdate(NodeConnectorStatisticsUpdate notification) {
546         //Check if response is for the request statistics-manager sent.
547         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
548             return;
549
550         NodeKey key = new NodeKey(notification.getId());
551         sucLogger.debug("Received port stats update : {}",notification.toString());
552         
553         List<NodeConnectorStatisticsAndPortNumberMap> portsStats = notification.getNodeConnectorStatisticsAndPortNumberMap();
554         for(NodeConnectorStatisticsAndPortNumberMap portStats : portsStats){
555             
556             DataModificationTransaction it = this.statisticsManager.startChange();
557
558             FlowCapableNodeConnectorStatisticsBuilder statisticsBuilder 
559                                             = new FlowCapableNodeConnectorStatisticsBuilder();
560             statisticsBuilder.setBytes(portStats.getBytes());
561             statisticsBuilder.setCollisionCount(portStats.getCollisionCount());
562             statisticsBuilder.setDuration(portStats.getDuration());
563             statisticsBuilder.setPackets(portStats.getPackets());
564             statisticsBuilder.setReceiveCrcError(portStats.getReceiveCrcError());
565             statisticsBuilder.setReceiveDrops(portStats.getReceiveDrops());
566             statisticsBuilder.setReceiveErrors(portStats.getReceiveErrors());
567             statisticsBuilder.setReceiveFrameError(portStats.getReceiveFrameError());
568             statisticsBuilder.setReceiveOverRunError(portStats.getReceiveOverRunError());
569             statisticsBuilder.setTransmitDrops(portStats.getTransmitDrops());
570             statisticsBuilder.setTransmitErrors(portStats.getTransmitErrors());
571             
572             //Augment data to the node-connector
573             FlowCapableNodeConnectorStatisticsDataBuilder statisticsDataBuilder = 
574                     new FlowCapableNodeConnectorStatisticsDataBuilder();
575             
576             statisticsDataBuilder.setFlowCapableNodeConnectorStatistics(statisticsBuilder.build());
577             
578             InstanceIdentifier<NodeConnector> nodeConnectorRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).child(NodeConnector.class, new NodeConnectorKey(portStats.getNodeConnectorId())).toInstance();
579             
580             NodeConnector nodeConnector = (NodeConnector)it.readOperationalData(nodeConnectorRef);
581             
582             if(nodeConnector != null){
583                 sucLogger.debug("Augmenting port statistics {} to port {}",statisticsDataBuilder.build().toString(),nodeConnectorRef.toString());
584                 NodeConnectorBuilder nodeConnectorBuilder = new NodeConnectorBuilder();
585                 nodeConnectorBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class, statisticsDataBuilder.build());
586                 it.putOperationalData(nodeConnectorRef, nodeConnectorBuilder.build());
587                 it.commit();
588             }
589         }
590     }
591
592     @Override
593     public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
594         //Check if response is for the request statistics-manager sent.
595         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
596             return;
597
598         NodeKey key = new NodeKey(notification.getId());
599         sucLogger.debug("Received flow table statistics update : {}",notification.toString());
600         
601         List<FlowTableAndStatisticsMap> flowTablesStatsList = notification.getFlowTableAndStatisticsMap();
602         for (FlowTableAndStatisticsMap ftStats : flowTablesStatsList){
603             
604             DataModificationTransaction it = this.statisticsManager.startChange();
605
606             InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
607                     .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(ftStats.getTableId().getValue())).toInstance();
608             
609             FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
610             
611             FlowTableStatisticsBuilder statisticsBuilder = new FlowTableStatisticsBuilder();
612             statisticsBuilder.setActiveFlows(ftStats.getActiveFlows());
613             statisticsBuilder.setPacketsLookedUp(ftStats.getPacketsLookedUp());
614             statisticsBuilder.setPacketsMatched(ftStats.getPacketsMatched());
615             
616             statisticsDataBuilder.setFlowTableStatistics(statisticsBuilder.build());
617             
618             sucLogger.debug("Augment flow table statistics: {} for table {} on Node {}",statisticsBuilder.build().toString(),ftStats.getTableId(),key);
619             
620             TableBuilder tableBuilder = new TableBuilder();
621             tableBuilder.setKey(new TableKey(ftStats.getTableId().getValue()));
622             tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
623             it.putOperationalData(tableRef, tableBuilder.build());
624             it.commit();
625         }
626     }
627
628     @Override
629     public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
630         
631         //Check if response is for the request statistics-manager sent.
632         if(this.statisticsManager.getMultipartMessageManager().removeTxId(notification.getTransactionId()) == null)
633             return;
634
635         NodeKey key = new NodeKey(notification.getId());
636         sucLogger.debug("Received queue stats update : {}",notification.toString());
637         
638         //Add statistics to local cache
639         ConcurrentMap<NodeId, NodeStatisticsAger> cache = this.statisticsManager.getStatisticsCache();
640         if(!cache.containsKey(notification.getId())){
641             cache.put(notification.getId(), new NodeStatisticsAger(statisticsManager,key));
642         }
643         
644         NodeStatisticsAger nsa = cache.get(notification.getId());
645         
646         List<QueueIdAndStatisticsMap> queuesStats = notification.getQueueIdAndStatisticsMap();
647         for(QueueIdAndStatisticsMap swQueueStats : queuesStats){
648             
649             QueueEntry queueEntry = nsa.new QueueEntry(swQueueStats.getNodeConnectorId(),swQueueStats.getQueueId());
650             nsa.updateQueueStats(queueEntry);
651             
652             FlowCapableNodeConnectorQueueStatisticsDataBuilder queueStatisticsDataBuilder = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
653             
654             FlowCapableNodeConnectorQueueStatisticsBuilder queueStatisticsBuilder = new FlowCapableNodeConnectorQueueStatisticsBuilder();
655             
656             queueStatisticsBuilder.fieldsFrom(swQueueStats);
657             
658             queueStatisticsDataBuilder.setFlowCapableNodeConnectorQueueStatistics(queueStatisticsBuilder.build());
659             
660             DataModificationTransaction it = this.statisticsManager.startChange();
661
662             InstanceIdentifier<Queue> queueRef 
663                     = InstanceIdentifier.builder(Nodes.class)
664                                         .child(Node.class, key)
665                                         .child(NodeConnector.class, new NodeConnectorKey(swQueueStats.getNodeConnectorId()))
666                                         .augmentation(FlowCapableNodeConnector.class)
667                                         .child(Queue.class, new QueueKey(swQueueStats.getQueueId())).toInstance();
668             
669             QueueBuilder queueBuilder = new QueueBuilder();
670             queueBuilder.addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, queueStatisticsDataBuilder.build());
671             queueBuilder.setKey(new QueueKey(swQueueStats.getQueueId()));
672
673             sucLogger.info("Augmenting queue statistics {} of queue {} to port {}"
674                                         ,queueStatisticsDataBuilder.build().toString(),
675                                         swQueueStats.getQueueId(),
676                                         swQueueStats.getNodeConnectorId());
677             
678             it.putOperationalData(queueRef, queueBuilder.build());
679             it.commit();
680             
681         }
682         
683     }
684
685     private NodeRef getNodeRef(NodeKey nodeKey){
686         InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
687         return new NodeRef(builder.toInstance());
688     }
689     
690     public boolean flowEquals(Flow statsFlow, Flow storedFlow) {
691         if (statsFlow.getClass() != storedFlow.getClass()) {
692             return false;
693         }
694         if (statsFlow.getBufferId()== null) {
695             if (storedFlow.getBufferId() != null) {
696                 return false;
697             }
698         } else if(!statsFlow.getBufferId().equals(storedFlow.getBufferId())) {
699             return false;
700         }
701         if (statsFlow.getContainerName()== null) {
702             if (storedFlow.getContainerName()!= null) {
703                 return false;
704             }
705         } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
706             return false;
707         }
708         if (statsFlow.getCookie()== null) {
709             if (storedFlow.getCookie()!= null) {
710                 return false;
711             }
712         } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
713             return false;
714         }
715         if (statsFlow.getMatch()== null) {
716             if (storedFlow.getMatch() != null) {
717                 return false;
718             }
719         } //else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
720         else if(!matchEquals(statsFlow.getMatch(), storedFlow.getMatch())) {
721             return false;
722         }
723         if (statsFlow.getHardTimeout() == null) {
724             if (storedFlow.getHardTimeout() != null) {
725                 return false;
726             }
727         } else if(!statsFlow.getHardTimeout().equals(storedFlow.getHardTimeout() )) {
728             return false;
729         }
730         if (statsFlow.getIdleTimeout()== null) {
731             if (storedFlow.getIdleTimeout() != null) {
732                 return false;
733             }
734         } else if(!statsFlow.getIdleTimeout().equals(storedFlow.getIdleTimeout())) {
735             return false;
736         }
737         if (statsFlow.getPriority() == null) {
738             if (storedFlow.getPriority() != null) {
739                 return false;
740             }
741         } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
742             return false;
743         }
744         if (statsFlow.getTableId() == null) {
745             if (storedFlow.getTableId() != null) {
746                 return false;
747             }
748         } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {
749             return false;
750         }
751         return true;
752     }
753     
754     /**
755      * Explicit equals method to compare the 'match' for flows stored in the data-stores and flow fetched from the switch.
756      * Usecase: e.g If user don't set any ethernet source and destination address for match,data store will store null for 
757      * these address.
758      * e.g [_ethernetMatch=EthernetMatch [_ethernetDestination=null, _ethernetSource=null, _ethernetType=
759      * EthernetType [_type=EtherType [_value=2048], _mask=null, augmentation=[]]
760      * 
761      * But when you fetch the flows from switch, openflow driver library converts all zero bytes of mac address in the 
762      * message stream to 00:00:00:00:00:00. Following string shows how library interpret the zero mac address bytes and 
763      * eventually when translator convert it to MD-SAL match, this is how it looks 
764      * [_ethernetDestination=EthernetDestination [_address=MacAddress [_value=00:00:00:00:00:00], _mask=null, augmentation=[]], 
765      * _ethernetSource=EthernetSource [_address=MacAddress [_value=00:00:00:00:00:00], _mask=null, augmentation=[]], 
766      * _ethernetType=EthernetType [_type=EtherType [_value=2048], _mask=null, augmentation=[]]
767      * 
768      * Similarly for inPort, if user/application don't set any value for it, FRM will store null value for it in data store. 
769      * When we fetch the same flow (with its statistics) from switch, plugin converts its value to openflow:X:0.
770      *  e.g _inPort=Uri [_value=openflow:1:0]  
771      * 
772      * So this custom equals method add additional check to take care of these scenario, in case any match element is null in data-store-flow, but not
773      * in the flow fetched from switch.
774      * 
775      * @param statsFlow
776      * @param storedFlow
777      * @return
778      */
779     
780     public boolean matchEquals(Match statsFlow, Match storedFlow) {
781         if (statsFlow == storedFlow) {
782             return true;
783         }
784         if (storedFlow.getClass() != statsFlow.getClass()) {
785             return false;
786         }
787         if (storedFlow.getEthernetMatch() == null) {
788             if (statsFlow.getEthernetMatch() != null) {
789                 return false;
790             }
791         } else if(!storedFlow.getEthernetMatch().equals(statsFlow.getEthernetMatch())) {
792             return false;
793         }
794         if (storedFlow.getIcmpv4Match()== null) {
795             if (statsFlow.getIcmpv4Match() != null) {
796                 return false;
797             }
798         } else if(!storedFlow.getIcmpv4Match().equals(statsFlow.getIcmpv4Match())) {
799             return false;
800         }
801         if (storedFlow.getIcmpv6Match() == null) {
802             if (statsFlow.getIcmpv6Match() != null) {
803                 return false;
804             }
805         } else if(!storedFlow.getIcmpv6Match().equals(statsFlow.getIcmpv6Match())) {
806             return false;
807         }
808         if (storedFlow.getInPhyPort() == null) {
809             if (statsFlow.getInPhyPort() != null) {
810                 return false;
811             }
812         } else if(!storedFlow.getInPhyPort().equals(statsFlow.getInPhyPort())) {
813             return false;
814         }
815         if (storedFlow.getInPort()== null) {
816             if (statsFlow.getInPort() != null) {
817                 return false;
818             }
819         } else if(!storedFlow.getInPort().equals(statsFlow.getInPort())) {
820             return false;
821         }
822         if (storedFlow.getIpMatch()== null) {
823             if (statsFlow.getIpMatch() != null) {
824                 return false;
825             }
826         } else if(!storedFlow.getIpMatch().equals(statsFlow.getIpMatch())) {
827             return false;
828         }
829         if (storedFlow.getLayer3Match()== null) {
830             if (statsFlow.getLayer3Match() != null) {
831                     return false;
832             }
833         } else if(!storedFlow.getLayer3Match().equals(statsFlow.getLayer3Match())) {
834             return false;
835         }
836         if (storedFlow.getLayer4Match()== null) {
837             if (statsFlow.getLayer4Match() != null) {
838                 return false;
839             }
840         } else if(!storedFlow.getLayer4Match().equals(statsFlow.getLayer4Match())) {
841             return false;
842         }
843         if (storedFlow.getMetadata() == null) {
844             if (statsFlow.getMetadata() != null) {
845                 return false;
846             }
847         } else if(!storedFlow.getMetadata().equals(statsFlow.getMetadata())) {
848             return false;
849         }
850         if (storedFlow.getProtocolMatchFields() == null) {
851             if (statsFlow.getProtocolMatchFields() != null) {
852                 return false;
853             }
854         } else if(!storedFlow.getProtocolMatchFields().equals(statsFlow.getProtocolMatchFields())) {
855             return false;
856         }
857         if (storedFlow.getTunnel()== null) {
858             if (statsFlow.getTunnel() != null) {
859                 return false;
860             }
861         } else if(!storedFlow.getTunnel().equals(statsFlow.getTunnel())) {
862             return false;
863         }
864         if (storedFlow.getVlanMatch()== null) {
865             if (statsFlow.getVlanMatch() != null) {
866                 return false;
867             }
868         } else if(!storedFlow.getVlanMatch().equals(statsFlow.getVlanMatch())) {
869             return false;
870         }
871         return true;
872     }
873 }