Merge "CHange log level from warn to debug in ProtocolSessionPromise when connection...
[controller.git] / opendaylight / md-sal / statistics-manager / src / main / java / org / opendaylight / controller / md / statistics / manager / StatisticsListener.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 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsListener;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * This class is responsible for listening for statistics update notifications and
32  * routing them to the appropriate NodeStatisticsHandler.
33
34  * TODO: Need to add error message listener and clean-up the associated tx id
35  * if it exists in the tx-id cache.
36  * @author vishnoianil
37  */
38 public class StatisticsListener implements OpendaylightGroupStatisticsListener,
39         OpendaylightMeterStatisticsListener,
40         OpendaylightFlowStatisticsListener,
41         OpendaylightPortStatisticsListener,
42         OpendaylightFlowTableStatisticsListener,
43         OpendaylightQueueStatisticsListener{
44
45     private final static Logger sucLogger = LoggerFactory.getLogger(StatisticsListener.class);
46     private final StatisticsProvider statisticsManager;
47
48     /**
49      * default ctor
50      * @param manager
51      */
52     public StatisticsListener(final StatisticsProvider manager){
53         this.statisticsManager = manager;
54     }
55
56     @Override
57     public void onMeterConfigStatsUpdated(final MeterConfigStatsUpdated notification) {
58         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
59         if (handler != null) {
60             handler.updateMeterConfigStats(notification, notification.isMoreReplies(), notification.getMeterConfigStats());
61         }
62     }
63
64     @Override
65     public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
66         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
67         if (handler != null) {
68             handler.updateMeterStats(notification, notification.isMoreReplies(), notification.getMeterStats());
69         }
70     }
71
72     @Override
73     public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
74         final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
75         if (handler != null) {
76             handler.updateGroupDescStats(notification, notification.isMoreReplies(), notification.getGroupDescStats());
77         }
78     }
79
80     @Override
81     public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
82         final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
83         if (handler != null) {
84             handler.updateGroupStats(notification, notification.isMoreReplies(), notification.getGroupStats());
85         }
86     }
87
88     @Override
89     public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
90         final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
91         if (sna != null) {
92             sna.updateMeterFeatures(notification);
93         }
94     }
95
96     @Override
97     public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
98         final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
99         if (sna != null) {
100             sna.updateGroupFeatures(notification);
101         }
102     }
103
104     @Override
105     public void onFlowsStatisticsUpdate(final FlowsStatisticsUpdate notification) {
106         sucLogger.debug("Received flow stats update : {}",notification.toString());
107         final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
108         if (sna != null) {
109             sna.updateFlowStats(notification, notification.isMoreReplies(), notification.getFlowAndStatisticsMapList());
110         }
111     }
112
113     @Override
114     public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
115         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
116         if (handler != null) {
117             handler.updateAggregateFlowStats(notification, notification.isMoreReplies(), notification);
118         }
119     }
120
121     @Override
122     public void onNodeConnectorStatisticsUpdate(NodeConnectorStatisticsUpdate notification) {
123         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
124         if (handler != null) {
125             handler.updateNodeConnectorStats(notification, notification.isMoreReplies(), notification.getNodeConnectorStatisticsAndPortNumberMap());
126         }
127     }
128
129     @Override
130     public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
131         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
132         if (handler != null) {
133             handler.updateFlowTableStats(notification, notification.isMoreReplies(), notification.getFlowTableAndStatisticsMap());
134         }
135     }
136
137     @Override
138     public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
139         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
140         if (handler != null) {
141             handler.updateQueueStats(notification, notification.isMoreReplies(), notification.getQueueIdAndStatisticsMap());
142         }
143     }
144 }