2 * Copyright IBM Corporation, 2013. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.statistics.manager;
10 import 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;
31 * This class is responsible for listening for statistics update notifications and
32 * routing them to the appropriate NodeStatisticsHandler.
34 * TODO: Need to add error message listener and clean-up the associated tx id
35 * if it exists in the tx-id cache.
38 public class StatisticsListener implements OpendaylightGroupStatisticsListener,
39 OpendaylightMeterStatisticsListener,
40 OpendaylightFlowStatisticsListener,
41 OpendaylightPortStatisticsListener,
42 OpendaylightFlowTableStatisticsListener,
43 OpendaylightQueueStatisticsListener{
45 private final static Logger sucLogger = LoggerFactory.getLogger(StatisticsListener.class);
46 private final StatisticsProvider statisticsManager;
47 private final MultipartMessageManager messageManager;
53 public StatisticsListener(final StatisticsProvider manager){
54 this.statisticsManager = manager;
55 this.messageManager = this.statisticsManager.getMultipartMessageManager();
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()))
64 //Add statistics to local cache
65 final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
66 if (handler != null) {
67 handler.updateMeterConfigStats(notification.getMeterConfigStats());
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()))
77 //Add statistics to local cache
78 final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
79 if (handler != null) {
80 handler.updateMeterStats(notification.getMeterStats());
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()))
90 final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
91 if (handler != null) {
92 handler.updateGroupDescStats(notification.getGroupDescStats());
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()))
102 final NodeStatisticsHandler handler = statisticsManager.getStatisticsHandler(notification.getId());
103 if (handler != null) {
104 handler.updateGroupStats(notification.getGroupStats());
109 public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
110 final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
112 sna.updateMeterFeatures(notification);
117 public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
118 final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
120 sna.updateGroupFeatures(notification);
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()))
130 sucLogger.debug("Received flow stats update : {}",notification.toString());
131 final NodeStatisticsHandler sna = this.statisticsManager.getStatisticsHandler(notification.getId());
133 sna.updateFlowStats(notification.getFlowAndStatisticsMapList());
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()))
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);
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()))
156 final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
157 if (handler != null) {
158 handler.updateNodeConnectorStats(notification.getNodeConnectorStatisticsAndPortNumberMap());
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()))
168 final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
169 if (handler != null) {
170 handler.updateFlowTableStats(notification.getFlowTableAndStatisticsMap());
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()))
180 //Add statistics to local cache
181 final NodeStatisticsHandler handler = this.statisticsManager.getStatisticsHandler(notification.getId());
182 if (handler != null) {
183 handler.updateQueueStats(notification.getQueueIdAndStatisticsMap());