155815dc8802e70b09015d6590f7957e85a44492
[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     private final MultipartMessageManager messageManager;
48
49     /**
50      * default ctor
51      * @param manager
52      */
53     public StatisticsListener(final StatisticsProvider manager){
54         this.statisticsManager = manager;
55         this.messageManager = this.statisticsManager.getMultipartMessageManager();
56     }
57
58     @Override
59     public void onMeterConfigStatsUpdated(final MeterConfigStatsUpdated notification) {
60         //Check if response is for the request statistics-manager sent.
61         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
62             return;
63
64         //Add statistics to local cache
65         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
66         if (handler != null) {
67             handler.updateMeterConfigStats(notification.getMeterConfigStats());
68         }
69     }
70
71     @Override
72     public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
73         //Check if response is for the request statistics-manager sent.
74         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
75             return;
76
77         //Add statistics to local cache
78         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
79         if (handler != null) {
80             handler.updateMeterStats(notification.getMeterStats());
81         }
82     }
83
84     @Override
85     public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
86         //Check if response is for the request statistics-manager sent.
87         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
88             return;
89
90         final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
91         if (handler != null) {
92             handler.updateGroupDescStats(notification.getGroupDescStats());
93         }
94     }
95
96     @Override
97     public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
98         //Check if response is for the request statistics-manager sent.
99         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
100             return;
101
102         final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
103         if (handler != null) {
104             handler.updateGroupStats(notification.getGroupStats());
105         }
106     }
107
108     @Override
109     public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
110         final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
111         if (sna != null) {
112             sna.updateMeterFeatures(notification);
113         }
114     }
115
116     @Override
117     public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
118         final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
119         if (sna != null) {
120             sna.updateGroupFeatures(notification);
121         }
122     }
123
124     @Override
125     public void onFlowsStatisticsUpdate(final FlowsStatisticsUpdate notification) {
126         //Check if response is for the request statistics-manager sent.
127         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
128             return;
129
130         sucLogger.debug("Received flow stats update : {}",notification.toString());
131         final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
132         if (sna != null) {
133             sna.updateFlowStats(notification.getFlowAndStatisticsMapList());
134         }
135     }
136
137     @Override
138     public void onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
139         //Check if response is for the request statistics-manager sent.
140         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
141             return;
142
143         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
144         if (handler != null) {
145             final Short tableId = messageManager.getTableIdForTxId(notification.getId(),notification.getTransactionId());
146             handler.updateAggregateFlowStats(tableId, notification);
147         }
148     }
149
150     @Override
151     public void onNodeConnectorStatisticsUpdate(NodeConnectorStatisticsUpdate notification) {
152         //Check if response is for the request statistics-manager sent.
153         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
154             return;
155
156         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
157         if (handler != null) {
158             handler.updateNodeConnectorStats(notification.getNodeConnectorStatisticsAndPortNumberMap());
159         }
160     }
161
162     @Override
163     public void onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
164         //Check if response is for the request statistics-manager sent.
165         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
166             return;
167
168         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
169         if (handler != null) {
170             handler.updateFlowTableStats(notification.getFlowTableAndStatisticsMap());
171         }
172     }
173
174     @Override
175     public void onQueueStatisticsUpdate(QueueStatisticsUpdate notification) {
176         //Check if response is for the request statistics-manager sent.
177         if(!messageManager.isRequestTxIdExist(notification.getId(),notification.getTransactionId(),notification.isMoreReplies()))
178             return;
179
180         //Add statistics to local cache
181         final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
182         if (handler != null) {
183             handler.updateQueueStats(notification.getQueueIdAndStatisticsMap());
184         }
185     }
186 }
187