Simplify StatisticsManagerActivator/StatisticsProvider contract
[controller.git] / opendaylight / md-sal / statistics-manager / src / main / java / org / opendaylight / controller / md / statistics / manager / StatisticsProvider.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.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.Future;
16
17 import org.eclipse.xtext.xbase.lib.Exceptions;
18 import org.opendaylight.controller.md.statistics.manager.MultipartMessageManager.StatsRequestType;
19 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
20 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
21 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
22 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
23 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInputBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInputBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInputBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
67 import org.opendaylight.yangtools.concepts.Registration;
68 import org.opendaylight.yangtools.yang.binding.DataObject;
69 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
70 import org.opendaylight.yangtools.yang.binding.NotificationListener;
71 import org.opendaylight.yangtools.yang.common.RpcResult;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74
75 import com.google.common.base.Preconditions;
76
77 /**
78  * Following are main responsibilities of the class:
79  * 1) Invoke statistics request thread to send periodic statistics request to all the
80  * flow capable switch connected to the controller. It sends statistics request for
81  * Group,Meter,Table,Flow,Queue,Aggregate stats.
82  *
83  * 2) Invoke statistics ager thread, to clean up all the stale statistics data from
84  * operational data store.
85  *
86  * @author avishnoi@in.ibm.com
87  *
88  */
89 public class StatisticsProvider implements AutoCloseable {
90     public static final int STATS_THREAD_EXECUTION_TIME= 15000;
91
92     private static final Logger spLogger = LoggerFactory.getLogger(StatisticsProvider.class);
93
94     private final MultipartMessageManager multipartMessageManager = new MultipartMessageManager();
95     private final InstanceIdentifier<Nodes> nodesIdentifier = InstanceIdentifier.builder(Nodes.class).toInstance();
96     private final DataProviderService dps;
97
98     //Local caching of stats
99     private final ConcurrentMap<NodeId,NodeStatisticsAger> statisticsCache = new ConcurrentHashMap<>();
100
101     private OpendaylightGroupStatisticsService groupStatsService;
102
103     private OpendaylightMeterStatisticsService meterStatsService;
104
105     private OpendaylightFlowStatisticsService flowStatsService;
106
107     private OpendaylightPortStatisticsService portStatsService;
108
109     private OpendaylightFlowTableStatisticsService flowTableStatsService;
110
111     private OpendaylightQueueStatisticsService queueStatsService;
112
113     private StatisticsUpdateHandler statsUpdateHandler;
114
115     private Thread statisticsRequesterThread;
116
117     private Thread statisticsAgerThread;
118
119
120     public StatisticsProvider(final DataProviderService dataService) {
121         this.dps = Preconditions.checkNotNull(dataService);
122     }
123
124     public MultipartMessageManager getMultipartMessageManager() {
125         return multipartMessageManager;
126     }
127
128     private final StatisticsUpdateCommiter updateCommiter = new StatisticsUpdateCommiter(StatisticsProvider.this);
129
130     private Registration<NotificationListener> listenerRegistration;
131
132     public void start(final DataBrokerService dbs, final NotificationProviderService nps, final RpcConsumerRegistry rpcRegistry) {
133
134         this.listenerRegistration = nps.registerNotificationListener(this.updateCommiter);
135
136         statsUpdateHandler = new StatisticsUpdateHandler(StatisticsProvider.this);
137         registerDataStoreUpdateListener(dbs);
138
139         // Get Group/Meter statistics service instance
140         groupStatsService = rpcRegistry.getRpcService(OpendaylightGroupStatisticsService.class);
141         meterStatsService = rpcRegistry.getRpcService(OpendaylightMeterStatisticsService.class);
142         flowStatsService = rpcRegistry.getRpcService(OpendaylightFlowStatisticsService.class);
143         portStatsService = rpcRegistry.getRpcService(OpendaylightPortStatisticsService.class);
144         flowTableStatsService = rpcRegistry.getRpcService(OpendaylightFlowTableStatisticsService.class);
145         queueStatsService = rpcRegistry.getRpcService(OpendaylightQueueStatisticsService.class);
146
147         statisticsRequesterThread = new Thread( new Runnable(){
148
149             @Override
150             public void run() {
151                 while(true){
152                     try {
153                         statsRequestSender();
154
155                         Thread.sleep(STATS_THREAD_EXECUTION_TIME);
156                     }catch (Exception e){
157                         spLogger.error("Exception occurred while sending stats request : {}",e);
158                     }
159                 }
160             }
161         });
162
163         spLogger.debug("Statistics requester thread started with timer interval : {}",STATS_THREAD_EXECUTION_TIME);
164
165         statisticsRequesterThread.start();
166
167         statisticsAgerThread = new Thread( new Runnable(){
168
169             @Override
170             public void run() {
171                 while(true){
172                     try {
173                         for(NodeStatisticsAger nodeStatisticsAger : statisticsCache.values()){
174                             nodeStatisticsAger.cleanStaleStatistics();
175                         }
176                         multipartMessageManager.cleanStaleTransactionIds();
177
178                         Thread.sleep(STATS_THREAD_EXECUTION_TIME);
179                     }catch (Exception e){
180                         spLogger.error("Exception occurred while sending stats request : {}",e);
181                     }
182                 }
183             }
184         });
185
186         spLogger.debug("Statistics ager thread started with timer interval : {}",STATS_THREAD_EXECUTION_TIME);
187
188         statisticsAgerThread.start();
189
190         spLogger.info("Statistics Provider started.");
191     }
192
193     private void registerDataStoreUpdateListener(DataBrokerService dbs) {
194         //Register for Node updates
195         InstanceIdentifier<? extends DataObject> pathNode = InstanceIdentifier.builder(Nodes.class)
196                                                                         .child(Node.class).toInstance();
197         dbs.registerDataChangeListener(pathNode, statsUpdateHandler);
198
199         //Register for flow updates
200         InstanceIdentifier<? extends DataObject> pathFlow = InstanceIdentifier.builder(Nodes.class).child(Node.class)
201                                                                     .augmentation(FlowCapableNode.class)
202                                                                     .child(Table.class)
203                                                                     .child(Flow.class).toInstance();
204         dbs.registerDataChangeListener(pathFlow, statsUpdateHandler);
205
206         //Register for meter updates
207         InstanceIdentifier<? extends DataObject> pathMeter = InstanceIdentifier.builder(Nodes.class).child(Node.class)
208                                                     .augmentation(FlowCapableNode.class)
209                                                     .child(Meter.class).toInstance();
210
211         dbs.registerDataChangeListener(pathMeter, statsUpdateHandler);
212
213         //Register for group updates
214         InstanceIdentifier<? extends DataObject> pathGroup = InstanceIdentifier.builder(Nodes.class).child(Node.class)
215                                                     .augmentation(FlowCapableNode.class)
216                                                     .child(Group.class).toInstance();
217         dbs.registerDataChangeListener(pathGroup, statsUpdateHandler);
218
219         //Register for queue updates
220         InstanceIdentifier<? extends DataObject> pathQueue = InstanceIdentifier.builder(Nodes.class).child(Node.class)
221                                                                     .child(NodeConnector.class)
222                                                                     .augmentation(FlowCapableNodeConnector.class)
223                                                                     .child(Queue.class).toInstance();
224         dbs.registerDataChangeListener(pathQueue, statsUpdateHandler);
225     }
226
227     protected DataModificationTransaction startChange() {
228         return dps.beginTransaction();
229     }
230
231     private void statsRequestSender(){
232
233         List<Node> targetNodes = getAllConnectedNodes();
234
235         if(targetNodes == null)
236             return;
237
238
239         for (Node targetNode : targetNodes){
240
241             if(targetNode.getAugmentation(FlowCapableNode.class) != null){
242                 sendStatisticsRequestsToNode(targetNode);
243             }
244         }
245     }
246
247     public void sendStatisticsRequestsToNode(Node targetNode){
248
249         spLogger.debug("Send requests for statistics collection to node : {})",targetNode.getId());
250
251         InstanceIdentifier<Node> targetInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class,targetNode.getKey()).toInstance();
252
253         NodeRef targetNodeRef = new NodeRef(targetInstanceId);
254
255         try{
256             if(flowStatsService != null){
257                 sendAggregateFlowsStatsFromAllTablesRequest(targetNode.getKey());
258                 sendAllFlowsStatsFromAllTablesRequest(targetNodeRef);
259             }
260             if(flowTableStatsService != null){
261                 sendAllFlowTablesStatisticsRequest(targetNodeRef);
262             }
263             if(portStatsService != null){
264                 sendAllNodeConnectorsStatisticsRequest(targetNodeRef);
265             }
266             if(groupStatsService != null){
267                 sendAllGroupStatisticsRequest(targetNodeRef);
268                 sendGroupDescriptionRequest(targetNodeRef);
269             }
270             if(meterStatsService != null){
271                 sendAllMeterStatisticsRequest(targetNodeRef);
272                 sendMeterConfigStatisticsRequest(targetNodeRef);
273             }
274             if(queueStatsService != null){
275                 sendAllQueueStatsFromAllNodeConnector (targetNodeRef);
276             }
277         }catch(Exception e){
278             spLogger.error("Exception occured while sending statistics requests : {}", e);
279         }
280     }
281
282
283     public void sendAllFlowTablesStatisticsRequest(NodeRef targetNodeRef) throws InterruptedException, ExecutionException {
284         final GetFlowTablesStatisticsInputBuilder input =
285                 new GetFlowTablesStatisticsInputBuilder();
286
287         input.setNode(targetNodeRef);
288
289         Future<RpcResult<GetFlowTablesStatisticsOutput>> response =
290                 flowTableStatsService.getFlowTablesStatistics(input.build());
291
292         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNodeRef),response.get().getResult().getTransactionId()
293                 , StatsRequestType.ALL_FLOW_TABLE);
294
295     }
296
297     public void sendAllFlowsStatsFromAllTablesRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
298         final GetAllFlowsStatisticsFromAllFlowTablesInputBuilder input =
299                 new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
300
301         input.setNode(targetNode);
302
303         Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> response =
304                 flowStatsService.getAllFlowsStatisticsFromAllFlowTables(input.build());
305
306         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
307                 , StatsRequestType.ALL_FLOW);
308
309     }
310
311     public void sendFlowStatsFromTableRequest(NodeRef targetNode,Flow flow) throws InterruptedException, ExecutionException{
312         final GetFlowStatisticsFromFlowTableInputBuilder input =
313                 new GetFlowStatisticsFromFlowTableInputBuilder();
314
315         input.setNode(targetNode);
316         input.fieldsFrom(flow);
317
318         Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> response =
319                 flowStatsService.getFlowStatisticsFromFlowTable(input.build());
320
321         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
322                 , StatsRequestType.ALL_FLOW);
323
324     }
325
326     public void sendAggregateFlowsStatsFromAllTablesRequest(NodeKey targetNodeKey) throws InterruptedException, ExecutionException{
327
328         List<Short> tablesId = getTablesFromNode(targetNodeKey);
329
330         if(tablesId.size() != 0){
331             for(Short id : tablesId){
332
333                 sendAggregateFlowsStatsFromTableRequest(targetNodeKey,id);
334             }
335         }else{
336             spLogger.debug("No details found in data store for flow tables associated with Node {}",targetNodeKey);
337         }
338     }
339
340     public void sendAggregateFlowsStatsFromTableRequest(NodeKey targetNodeKey,Short tableId) throws InterruptedException, ExecutionException{
341
342         spLogger.debug("Send aggregate stats request for flow table {} to node {}",tableId,targetNodeKey);
343         GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder input =
344                 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder();
345
346         input.setNode(new NodeRef(InstanceIdentifier.builder(Nodes.class).child(Node.class, targetNodeKey).toInstance()));
347         input.setTableId(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId(tableId));
348         Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> response =
349                 flowStatsService.getAggregateFlowStatisticsFromFlowTableForAllFlows(input.build());
350
351         multipartMessageManager.setTxIdAndTableIdMapEntry(targetNodeKey.getId(), response.get().getResult().getTransactionId(), tableId);
352         this.multipartMessageManager.addTxIdToRequestTypeEntry(targetNodeKey.getId(), response.get().getResult().getTransactionId()
353                 , StatsRequestType.AGGR_FLOW);
354     }
355
356     public void sendAllNodeConnectorsStatisticsRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
357
358         final GetAllNodeConnectorsStatisticsInputBuilder input = new GetAllNodeConnectorsStatisticsInputBuilder();
359
360         input.setNode(targetNode);
361
362         Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> response =
363                 portStatsService.getAllNodeConnectorsStatistics(input.build());
364         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
365                 , StatsRequestType.ALL_PORT);
366
367     }
368
369     public void sendAllGroupStatisticsRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
370
371         final GetAllGroupStatisticsInputBuilder input = new GetAllGroupStatisticsInputBuilder();
372
373         input.setNode(targetNode);
374
375         Future<RpcResult<GetAllGroupStatisticsOutput>> response =
376                 groupStatsService.getAllGroupStatistics(input.build());
377
378         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
379                 , StatsRequestType.ALL_GROUP);
380
381     }
382
383     public void sendGroupDescriptionRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
384         final GetGroupDescriptionInputBuilder input = new GetGroupDescriptionInputBuilder();
385
386         input.setNode(targetNode);
387
388         Future<RpcResult<GetGroupDescriptionOutput>> response =
389                 groupStatsService.getGroupDescription(input.build());
390
391         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
392                 , StatsRequestType.GROUP_DESC);
393
394     }
395
396     public void sendAllMeterStatisticsRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
397
398         GetAllMeterStatisticsInputBuilder input = new GetAllMeterStatisticsInputBuilder();
399
400         input.setNode(targetNode);
401
402         Future<RpcResult<GetAllMeterStatisticsOutput>> response =
403                 meterStatsService.getAllMeterStatistics(input.build());
404
405         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
406                 , StatsRequestType.ALL_METER);;
407
408     }
409
410     public void sendMeterConfigStatisticsRequest(NodeRef targetNode) throws InterruptedException, ExecutionException{
411
412         GetAllMeterConfigStatisticsInputBuilder input = new GetAllMeterConfigStatisticsInputBuilder();
413
414         input.setNode(targetNode);
415
416         Future<RpcResult<GetAllMeterConfigStatisticsOutput>> response =
417                 meterStatsService.getAllMeterConfigStatistics(input.build());
418
419         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
420                 , StatsRequestType.METER_CONFIG);;
421
422     }
423
424     public void sendAllQueueStatsFromAllNodeConnector(NodeRef targetNode) throws InterruptedException, ExecutionException {
425         GetAllQueuesStatisticsFromAllPortsInputBuilder input = new GetAllQueuesStatisticsFromAllPortsInputBuilder();
426
427         input.setNode(targetNode);
428
429         Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> response =
430                 queueStatsService.getAllQueuesStatisticsFromAllPorts(input.build());
431
432         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
433                 , StatsRequestType.ALL_QUEUE_STATS);;
434
435     }
436
437     public void sendQueueStatsFromGivenNodeConnector(NodeRef targetNode,NodeConnectorId nodeConnectorId, QueueId queueId) throws InterruptedException, ExecutionException {
438         GetQueueStatisticsFromGivenPortInputBuilder input = new GetQueueStatisticsFromGivenPortInputBuilder();
439
440         input.setNode(targetNode);
441         input.setNodeConnectorId(nodeConnectorId);
442         input.setQueueId(queueId);
443         Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> response =
444                 queueStatsService.getQueueStatisticsFromGivenPort(input.build());
445
446         this.multipartMessageManager.addTxIdToRequestTypeEntry(getNodeId(targetNode), response.get().getResult().getTransactionId()
447                 , StatsRequestType.ALL_QUEUE_STATS);;
448
449     }
450
451     public final NodeStatisticsAger getStatisticsAger(final NodeId nodeId) {
452         NodeStatisticsAger ager = statisticsCache.get(nodeId);
453         if (ager == null) {
454             ager = new NodeStatisticsAger(this, new NodeKey(nodeId));
455             statisticsCache.put(nodeId, ager);
456         }
457
458         return ager;
459     }
460
461     private List<Node> getAllConnectedNodes(){
462         Nodes nodes = (Nodes) dps.readOperationalData(nodesIdentifier);
463         if(nodes == null)
464             return null;
465
466         spLogger.debug("Number of connected nodes : {}",nodes.getNode().size());
467         return nodes.getNode();
468     }
469
470     private List<Short> getTablesFromNode(NodeKey nodeKey){
471         InstanceIdentifier<FlowCapableNode> nodesIdentifier = InstanceIdentifier.builder(Nodes.class).child(Node.class,nodeKey).augmentation(FlowCapableNode.class).toInstance();
472
473         FlowCapableNode node = (FlowCapableNode)dps.readOperationalData(nodesIdentifier);
474         List<Short> tablesId = new ArrayList<Short>();
475         if(node != null && node.getTable()!=null){
476             spLogger.debug("Number of tables {} supported by node {}",node.getTable().size(),nodeKey);
477             for(Table table: node.getTable()){
478                 tablesId.add(table.getId());
479             }
480         }
481         return tablesId;
482     }
483
484     @SuppressWarnings("unchecked")
485     private NodeId getNodeId(NodeRef nodeRef){
486         InstanceIdentifier<Node> nodeII = (InstanceIdentifier<Node>) nodeRef.getValue();
487         NodeKey nodeKey = InstanceIdentifier.keyOf(nodeII);
488         return nodeKey.getId();
489     }
490
491     @SuppressWarnings("deprecation")
492     @Override
493     public void close(){
494
495         try {
496             spLogger.info("Statistics Provider stopped.");
497             if (this.listenerRegistration != null) {
498
499                 this.listenerRegistration.close();
500
501                 this.statisticsRequesterThread.destroy();
502
503                 this.statisticsAgerThread.destroy();
504
505             }
506           } catch (Throwable e) {
507             throw Exceptions.sneakyThrow(e);
508           }
509     }
510
511 }