blob: 11766c7dc62f513169a4d3730074b74f7858595e [file] [log] [blame]
Zack Williams477ba092018-10-17 10:50:06 -07001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Zack Williams477ba092018-10-17 10:50:06 -07003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Zack Williams477ba092018-10-17 10:50:06 -07007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Zack Williams477ba092018-10-17 10:50:06 -07009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Zack Williams477ba092018-10-17 10:50:06 -070016
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040017#include "stats_collection.h"
18
19#include <unistd.h>
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040020
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040021#include "indications.h"
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -040022#include "core.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053023#include "core_data.h"
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -040024#include "translation.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040025
26extern "C"
27{
28#include <bcmos_system.h>
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000029#include <bcmolt_api.h>
30#include <bcmolt_api_model_api_structs.h>
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040031}
32
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040033//FIXME
34#define FLOWS_COUNT 100
35
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000036bcmolt_flow_key* flows_keys = new bcmolt_flow_key[FLOWS_COUNT];
Jason Huang5d9ab1a2020-04-15 16:53:49 +080037bcmolt_odid device_id = 0;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040038
Shad Ansariedef2132018-08-10 22:14:50 +000039void init_stats() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000040 memset(flows_keys, 0, FLOWS_COUNT * sizeof(bcmolt_flow_key));
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040041}
42
43openolt::PortStatistics* get_default_port_statistics() {
44 openolt::PortStatistics* port_stats = new openolt::PortStatistics;
45 port_stats->set_intf_id(-1);
46 port_stats->set_rx_bytes(-1);
47 port_stats->set_rx_packets(-1);
48 port_stats->set_rx_ucast_packets(-1);
49 port_stats->set_rx_mcast_packets(-1);
50 port_stats->set_rx_bcast_packets(-1);
51 port_stats->set_rx_error_packets(-1);
Jason Huang2d9382f2020-10-21 17:52:05 +080052 port_stats->set_rx_crc_errors(-1);
53 port_stats->set_rx_frames(-1);
54 port_stats->set_rx_frames_64(-1);
55 port_stats->set_rx_frames_65_127(-1);
56 port_stats->set_rx_frames_128_255(-1);
57 port_stats->set_rx_frames_256_511(-1);
58 port_stats->set_rx_frames_512_1023(-1);
59 port_stats->set_rx_frames_1024_1518(-1);
60 port_stats->set_rx_frames_1519_2047(-1);
61 port_stats->set_rx_frames_2048_4095(-1);
62 port_stats->set_rx_frames_4096_9216(-1);
63 port_stats->set_rx_frames_9217_16383(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040064 port_stats->set_tx_bytes(-1);
65 port_stats->set_tx_packets(-1);
66 port_stats->set_tx_ucast_packets(-1);
67 port_stats->set_tx_mcast_packets(-1);
68 port_stats->set_tx_bcast_packets(-1);
69 port_stats->set_tx_error_packets(-1);
Jason Huang2d9382f2020-10-21 17:52:05 +080070 port_stats->set_tx_frames(-1);
71 port_stats->set_tx_frames_64(-1);
72 port_stats->set_tx_frames_65_127(-1);
73 port_stats->set_tx_frames_128_255(-1);
74 port_stats->set_tx_frames_256_511(-1);
75 port_stats->set_tx_frames_512_1023(-1);
76 port_stats->set_tx_frames_1024_1518(-1);
77 port_stats->set_tx_frames_1519_2047(-1);
78 port_stats->set_tx_frames_2048_4095(-1);
79 port_stats->set_tx_frames_4096_9216(-1);
80 port_stats->set_tx_frames_9217_16383(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040081 port_stats->set_bip_errors(-1);
82
83 return port_stats;
84}
85
Shad Ansaricb004c52018-05-30 18:07:23 +000086#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040087openolt::FlowStatistics* get_default_flow_statistics() {
88 openolt::FlowStatistics* flow_stats = new openolt::FlowStatistics;
89 flow_stats->set_flow_id(-1);
90 flow_stats->set_rx_bytes(-1);
91 flow_stats->set_rx_packets(-1);
92 flow_stats->set_tx_bytes(-1);
93 flow_stats->set_tx_packets(-1);
94
95 return flow_stats;
96}
Shad Ansaricb004c52018-05-30 18:07:23 +000097#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040098
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000099openolt::PortStatistics* collectPortStatistics(bcmolt_intf_ref intf_ref) {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400100
101 openolt::PortStatistics* port_stats = get_default_port_statistics();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000102#ifndef TEST_MODE
103 bcmos_errno err;
104 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
105 bcmolt_nni_interface_stats nni_stats;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000106 bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
Jason Huang2d9382f2020-10-21 17:52:05 +0800107 bcmolt_internal_nni_enet_stats enet_stat;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400108
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000109 switch (intf_ref.intf_type) {
110 case BCMOLT_INTERFACE_TYPE_NNI:
111 {
112 bcmolt_nni_interface_key nni_intf_key;
113 nni_intf_key.id = intf_ref.intf_id;
114 /* init the API struct */
115 BCMOLT_STAT_INIT(&nni_stats, nni_interface, stats, nni_intf_key);
116 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bytes);
117 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_packets);
118 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_ucast_packets);
119 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_mcast_packets);
120 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bcast_packets);
121 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_error_packets);
Jason Huang2d9382f2020-10-21 17:52:05 +0800122 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_64);
123 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_65_127);
124 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_128_255);
125 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_256_511);
126 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_512_1023);
127 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1024_1518);
128 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1519_2047);
129 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_2048_4095);
130 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_4096_9216);
131 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_9217_16383);
132
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000133 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bytes);
134 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_packets);
135 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_ucast_packets);
136 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_mcast_packets);
137 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bcast_packets);
138 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_error_packets);
Jason Huang2d9382f2020-10-21 17:52:05 +0800139 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_64);
140 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_65_127);
141 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_128_255);
142 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_256_511);
143 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_512_1023);
144 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1024_1518);
145 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1519_2047);
146 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_2048_4095);
147 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_4096_9216);
148 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400149
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000150 /* call API */
151 err = bcmolt_stat_get((bcmolt_oltid)device_id, &nni_stats.hdr, clear_on_read);
152 if (err == BCM_ERR_OK)
153 {
154 //std::cout << "Interface statistics retrieved"
155 // << " intf_id:" << intf_id << std::endl;
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800156
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000157 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
158 port_stats->set_rx_packets(nni_stats.data.rx_packets);
159 port_stats->set_rx_ucast_packets(nni_stats.data.rx_ucast_packets);
160 port_stats->set_rx_mcast_packets(nni_stats.data.rx_mcast_packets);
161 port_stats->set_rx_bcast_packets(nni_stats.data.rx_bcast_packets);
162 port_stats->set_rx_error_packets(nni_stats.data.rx_error_packets);
163 port_stats->set_tx_bytes(nni_stats.data.tx_bytes);
164 port_stats->set_tx_packets(nni_stats.data.tx_packets);
165 port_stats->set_tx_ucast_packets(nni_stats.data.tx_ucast_packets);
166 port_stats->set_tx_mcast_packets(nni_stats.data.tx_mcast_packets);
167 port_stats->set_tx_bcast_packets(nni_stats.data.tx_bcast_packets);
168 port_stats->set_tx_error_packets(nni_stats.data.tx_error_packets);
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800169
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000170 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500171 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
172 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000173 }
174 break;
175 }
176 case BCMOLT_INTERFACE_TYPE_PON:
177 {
178 bcmolt_pon_interface_key key;
179 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
180 BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key);
181 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets);
182 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors);
183 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400184
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000185 /* call API */
186 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_pon_stats.hdr, clear_on_read);
187 if (err == BCM_ERR_OK) {
188 port_stats->set_tx_packets(itu_pon_stats.data.tx_packets);
189 port_stats->set_bip_errors(itu_pon_stats.data.bip_errors);
190 port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error);
191 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500192 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
193 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000194 }
Jason Huang2d9382f2020-10-21 17:52:05 +0800195
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000196 {
Jason Huang2d9382f2020-10-21 17:52:05 +0800197 bcmolt_internal_nni_key key = {};
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000198 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
Jason Huang2d9382f2020-10-21 17:52:05 +0800199 BCMOLT_STAT_INIT(&enet_stat, internal_nni, enet_stats, key);
200 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_bytes);
201 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames);
202 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_64);
203 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_65_127);
204 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_128_255);
205 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_256_511);
206 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_512_1023);
207 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1024_1518);
208 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1519_2047);
209 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_2048_4095);
210 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_4096_9216);
211 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_9217_16383);
212 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_bytes);
213 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames);
214 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_64);
215 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_65_127);
216 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_128_255);
217 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_256_511);
218 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_512_1023);
219 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1024_1518);
220 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1519_2047);
221 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_2048_4095);
222 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_4096_9216);
223 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400224
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000225 /* call API */
Jason Huang2d9382f2020-10-21 17:52:05 +0800226 err = bcmolt_stat_get((bcmolt_oltid)device_id, &enet_stat.hdr, clear_on_read);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000227 if (err == BCM_ERR_OK) {
Jason Huang2d9382f2020-10-21 17:52:05 +0800228 port_stats->set_rx_bytes(enet_stat.data.rx_bytes);
229 port_stats->set_rx_packets(enet_stat.data.rx_frames);
230 port_stats->set_rx_packets(enet_stat.data.rx_frames_64);
231 port_stats->set_rx_packets(enet_stat.data.rx_frames_65_127);
232 port_stats->set_rx_packets(enet_stat.data.rx_frames_128_255);
233 port_stats->set_rx_packets(enet_stat.data.rx_frames_256_511);
234 port_stats->set_rx_packets(enet_stat.data.rx_frames_512_1023);
235 port_stats->set_rx_packets(enet_stat.data.rx_frames_1024_1518);
236 port_stats->set_rx_packets(enet_stat.data.rx_frames_1519_2047);
237 port_stats->set_rx_packets(enet_stat.data.rx_frames_2048_4095);
238 port_stats->set_rx_packets(enet_stat.data.rx_frames_4096_9216);
239 port_stats->set_rx_packets(enet_stat.data.rx_frames_9217_16383);
240
241 port_stats->set_tx_bytes(enet_stat.data.tx_bytes);
242 port_stats->set_rx_packets(enet_stat.data.tx_frames);
243 port_stats->set_rx_packets(enet_stat.data.tx_frames_64);
244 port_stats->set_rx_packets(enet_stat.data.tx_frames_65_127);
245 port_stats->set_rx_packets(enet_stat.data.tx_frames_128_255);
246 port_stats->set_rx_packets(enet_stat.data.tx_frames_256_511);
247 port_stats->set_rx_packets(enet_stat.data.tx_frames_512_1023);
248 port_stats->set_rx_packets(enet_stat.data.tx_frames_1024_1518);
249 port_stats->set_rx_packets(enet_stat.data.tx_frames_1519_2047);
250 port_stats->set_rx_packets(enet_stat.data.tx_frames_2048_4095);
251 port_stats->set_rx_packets(enet_stat.data.tx_frames_4096_9216);
252 port_stats->set_rx_packets(enet_stat.data.tx_frames_9217_16383);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000253 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500254 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
255 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000256 }
257 }
258 break;
259 }
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800260 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000261
262 port_stats->set_intf_id(interface_key_to_port_no((bcmolt_interface_id)intf_ref.intf_id, (bcmolt_interface_type)intf_ref.intf_type));
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400263 time_t now;
264 time(&now);
265 port_stats->set_timestamp((int)now);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000266#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400267 return port_stats;
268
269}
270
Shad Ansaricb004c52018-05-30 18:07:23 +0000271#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400272openolt::FlowStatistics* collectFlowStatistics(bcmbal_flow_id flow_id, bcmbal_flow_type flow_type) {
273
274 bcmos_errno err;
275 bcmbal_flow_stat stat; /**< declare main API struct */
276 bcmbal_flow_key key = { }; /**< declare key */
277 bcmos_bool clear_on_read = false;
278
279 openolt::FlowStatistics* flow_stats = get_default_flow_statistics();
280 //Key
281 key.flow_id = flow_id;
282 key.flow_type = flow_type;
283
284 /* init the API struct */
285 BCMBAL_STAT_INIT(&stat, flow, key);
286 BCMBAL_STAT_PROP_GET(&stat, flow, all_properties);
287
288 err = bcmbal_stat_get(DEFAULT_ATERM_ID, &stat.hdr, clear_on_read);
289
290 if (err == BCM_ERR_OK)
291 {
292 std::cout << "Flow statistics retrieved"
293 << " flow_id:" << flow_id
294 << " flow_type:" << flow_type << std::endl;
295
296 flow_stats->set_rx_bytes(stat.data.rx_bytes);
297 flow_stats->set_rx_packets(stat.data.rx_packets);
298 flow_stats->set_tx_bytes(stat.data.tx_bytes);
299 flow_stats->set_tx_packets(stat.data.tx_packets);
300
301 } else {
302 std::cout << "ERROR: Failed to retrieve flow statistics"
303 << " flow_id:" << flow_id
304 << " flow_type:" << flow_type << std::endl;
305 }
306
307 return flow_stats;
308}
Shad Ansaricb004c52018-05-30 18:07:23 +0000309#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400310
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400311void stats_collection() {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400312
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400313 if (!state.is_connected()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000314 OPENOLT_LOG(INFO, openolt_log_id, "Voltha is not connected, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400315 return;
316 }
317 if (!state.is_activated()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000318 OPENOLT_LOG(INFO, openolt_log_id, "The OLT is not up, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400319 return;
320 }
321
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000322 OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n");
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400323
Shad Ansariedef2132018-08-10 22:14:50 +0000324 //Ports statistics
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400325
Shad Ansariedef2132018-08-10 22:14:50 +0000326 //Uplink ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500327 for (int i = 0; i < NumNniIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000328 bcmolt_intf_ref intf_ref;
329 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI;
330 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400331
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000332 openolt::PortStatistics* port_stats =
333 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400334
Girish Gowdra252f4972020-09-07 21:24:01 -0700335 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000336 ind.set_allocated_port_stats(port_stats);
337 oltIndQ.push(ind);
338 }
339 //Pon ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500340 for (int i = 0; i < NumPonIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000341 bcmolt_intf_ref intf_ref;
342 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON;
343 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400344
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800345 openolt::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000346 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400347
Girish Gowdra252f4972020-09-07 21:24:01 -0700348 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000349 ind.set_allocated_port_stats(port_stats);
350 oltIndQ.push(ind);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400351 }
352
Shad Ansariedef2132018-08-10 22:14:50 +0000353 //Flows statistics
354 // flow_inst *current_entry = NULL;
355 //
356 // TAILQ_FOREACH(current_entry,
357 // &FLOW_FSM_FLOW_LIST_CTX_PTR->active_flow_list,
358 // flow_inst_next) {
359 // int flows_measurements = 0;
360 //
361 // for (int i = 0; i < FLOWS_COUNT; i++) {
362 //
363 // // bcmbal_flow_id flow_id = current_entry->api_req_flow_info.key.flow_id;
364 // // bcmbal_flow_type flow_type = current_entry->api_req_flow_info.key.flow_type;
365 //
366 // if (flows_keys[i].flow_id != 0) {
367 // openolt::FlowStatistics* flow_stats = collectFlowStatistics(flows_keys[i].flow_id, flows_keys[i].flow_type);
368 // if (flow_stats->rx_packets() == -1) {
369 // //It Failed
370 // flows_keys[i].flow_id = 0;
371 // } else {
372 // flow_stats->set_flow_id(flows_keys[i].flow_id);
373 // time(&now);
374 // flow_stats->set_timestamp((int)now);
375 // openolt::Indication ind;
376 // ind.set_allocated_flow_stats(flow_stats);
377 // oltIndQ.push(ind);
378 // flows_measurements ++;
379 // }
380 // }
381 //
382 // }
383 // std::cout << "Stats of " << flows_measurements << " flows retrieved" << std::endl;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400384
385}
386
387/* Storing flow keys, temporary */
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400388// void register_new_flow(bcmbal_flow_key key) {
389// for (int i = 0; i < FLOWS_COUNT; i++) {
390// if (flows_keys[i].flow_id == 0) {
391// flows_keys[i] = key;
392// break;
393// }
394// }
395// }