blob: 5524daf0a3256586f6c945cea7eedac45d22b9f3 [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
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +053035#define ALLOC_STATS_GET_INTERVAL 10
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040036
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000037bcmolt_flow_key* flows_keys = new bcmolt_flow_key[FLOWS_COUNT];
Jason Huang5d9ab1a2020-04-15 16:53:49 +080038bcmolt_odid device_id = 0;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040039
Shad Ansariedef2132018-08-10 22:14:50 +000040void init_stats() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000041 memset(flows_keys, 0, FLOWS_COUNT * sizeof(bcmolt_flow_key));
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040042}
43
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +053044common::PortStatistics* get_default_port_statistics() {
45 common::PortStatistics* port_stats = new common::PortStatistics;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040046 port_stats->set_intf_id(-1);
47 port_stats->set_rx_bytes(-1);
48 port_stats->set_rx_packets(-1);
49 port_stats->set_rx_ucast_packets(-1);
50 port_stats->set_rx_mcast_packets(-1);
51 port_stats->set_rx_bcast_packets(-1);
52 port_stats->set_rx_error_packets(-1);
Jason Huang2d9382f2020-10-21 17:52:05 +080053 port_stats->set_rx_crc_errors(-1);
54 port_stats->set_rx_frames(-1);
55 port_stats->set_rx_frames_64(-1);
56 port_stats->set_rx_frames_65_127(-1);
57 port_stats->set_rx_frames_128_255(-1);
58 port_stats->set_rx_frames_256_511(-1);
59 port_stats->set_rx_frames_512_1023(-1);
60 port_stats->set_rx_frames_1024_1518(-1);
61 port_stats->set_rx_frames_1519_2047(-1);
62 port_stats->set_rx_frames_2048_4095(-1);
63 port_stats->set_rx_frames_4096_9216(-1);
64 port_stats->set_rx_frames_9217_16383(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040065 port_stats->set_tx_bytes(-1);
66 port_stats->set_tx_packets(-1);
67 port_stats->set_tx_ucast_packets(-1);
68 port_stats->set_tx_mcast_packets(-1);
69 port_stats->set_tx_bcast_packets(-1);
70 port_stats->set_tx_error_packets(-1);
Jason Huang2d9382f2020-10-21 17:52:05 +080071 port_stats->set_tx_frames(-1);
72 port_stats->set_tx_frames_64(-1);
73 port_stats->set_tx_frames_65_127(-1);
74 port_stats->set_tx_frames_128_255(-1);
75 port_stats->set_tx_frames_256_511(-1);
76 port_stats->set_tx_frames_512_1023(-1);
77 port_stats->set_tx_frames_1024_1518(-1);
78 port_stats->set_tx_frames_1519_2047(-1);
79 port_stats->set_tx_frames_2048_4095(-1);
80 port_stats->set_tx_frames_4096_9216(-1);
81 port_stats->set_tx_frames_9217_16383(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040082 port_stats->set_bip_errors(-1);
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +053083 port_stats->set_bip_units(-1);
84 port_stats->set_rxgem(-1);
85 port_stats->set_rxgemdropped(-1);
86 port_stats->set_rxgemidle(-1);
87 port_stats->set_rxgemcorrected(-1);
88 port_stats->set_rxfragmenterror(-1);
89 port_stats->set_rxpacketsdropped(-1);
90 port_stats->set_rxcpuomcipacketsdropped(-1);
91 port_stats->set_rxcpu(-1);
92 port_stats->set_rxomci(-1);
93 port_stats->set_rxomcipacketscrcerror(-1);
94 port_stats->set_rxgemillegal(-1);
95 port_stats->set_txgem(-1);
96 port_stats->set_txcpu(-1);
97 port_stats->set_txomci(-1);
98 port_stats->set_txdroppedillegallength(-1);
99 port_stats->set_txdroppedtpidmiss(-1);
100 port_stats->set_txdroppedvidmiss(-1);
101 port_stats->set_txdroppedtotal(-1);
102 port_stats->set_rxfcserrorpackets(-1);
103 port_stats->set_rxundersizepackets(-1);
104 port_stats->set_rxoversizepackets(-1);
105 port_stats->set_txundersizepackets(-1);
106 port_stats->set_txoversizepackets(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400107
108 return port_stats;
109}
110
Burak Gurdag74e3ab82020-12-17 13:35:06 +0000111openolt::OnuStatistics get_default_onu_statistics() {
112 openolt::OnuStatistics onu_stats;
113
114 onu_stats.set_positive_drift(-1);
115 onu_stats.set_negative_drift(-1);
116 onu_stats.set_delimiter_miss_detection(-1);
117 onu_stats.set_bip_errors(-1);
118 onu_stats.set_bip_units(-1);
119 onu_stats.set_fec_corrected_symbols(-1);
120 onu_stats.set_fec_codewords_corrected(-1);
121 onu_stats.set_fec_codewords_uncorrectable(-1);
122 onu_stats.set_fec_codewords(-1);
123 onu_stats.set_fec_corrected_units(-1);
124 onu_stats.set_xgem_key_errors(-1);
125 onu_stats.set_xgem_loss(-1);
126 onu_stats.set_rx_ploams_error(-1);
127 onu_stats.set_rx_ploams_non_idle(-1);
128 onu_stats.set_rx_omci(-1);
129 onu_stats.set_rx_omci_packets_crc_error(-1);
130 onu_stats.set_rx_bytes(-1);
131 onu_stats.set_rx_packets(-1);
132 onu_stats.set_tx_bytes(-1);
133 onu_stats.set_tx_packets(-1);
134 onu_stats.set_ber_reported(-1);
135 onu_stats.set_lcdg_errors(-1);
136 onu_stats.set_rdi_errors(-1);
137
138 return onu_stats;
139}
140
141openolt::GemPortStatistics get_default_gemport_statistics() {
142 openolt::GemPortStatistics gemport_stats;
143
144 gemport_stats.set_intf_id(-1);
145 gemport_stats.set_gemport_id(-1);
146 gemport_stats.set_rx_packets(-1);
147 gemport_stats.set_rx_bytes(-1);
148 gemport_stats.set_tx_packets(-1);
149 gemport_stats.set_tx_bytes(-1);
150
151 return gemport_stats;
152}
153
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530154openolt::OnuAllocIdStatistics get_default_alloc_statistics() {
155 openolt::OnuAllocIdStatistics alloc_stats;
156
157 alloc_stats.set_intfid(-1);
158 alloc_stats.set_allocid(-1);
159 alloc_stats.set_rxbytes(-1);
160
161 return alloc_stats;
162}
163
Shad Ansaricb004c52018-05-30 18:07:23 +0000164#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400165openolt::FlowStatistics* get_default_flow_statistics() {
166 openolt::FlowStatistics* flow_stats = new openolt::FlowStatistics;
167 flow_stats->set_flow_id(-1);
168 flow_stats->set_rx_bytes(-1);
169 flow_stats->set_rx_packets(-1);
170 flow_stats->set_tx_bytes(-1);
171 flow_stats->set_tx_packets(-1);
172
173 return flow_stats;
174}
Shad Ansaricb004c52018-05-30 18:07:23 +0000175#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400176
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530177common::PortStatistics* collectPortStatistics(bcmolt_intf_ref intf_ref) {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400178
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530179 common::PortStatistics* port_stats = get_default_port_statistics();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000180#ifndef TEST_MODE
181 bcmos_errno err;
182 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
183 bcmolt_nni_interface_stats nni_stats;
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800184 bcmolt_onu_itu_pon_stats pon_stats;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000185 bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
Jason Huang2d9382f2020-10-21 17:52:05 +0800186 bcmolt_internal_nni_enet_stats enet_stat;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400187
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000188 switch (intf_ref.intf_type) {
189 case BCMOLT_INTERFACE_TYPE_NNI:
190 {
191 bcmolt_nni_interface_key nni_intf_key;
192 nni_intf_key.id = intf_ref.intf_id;
193 /* init the API struct */
194 BCMOLT_STAT_INIT(&nni_stats, nni_interface, stats, nni_intf_key);
195 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bytes);
196 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_packets);
197 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_ucast_packets);
198 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_mcast_packets);
199 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bcast_packets);
200 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_error_packets);
Jason Huang2d9382f2020-10-21 17:52:05 +0800201 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_64);
202 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_65_127);
203 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_128_255);
204 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_256_511);
205 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_512_1023);
206 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1024_1518);
207 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1519_2047);
208 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_2048_4095);
209 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_4096_9216);
210 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_9217_16383);
211
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000212 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bytes);
213 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_packets);
214 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_ucast_packets);
215 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_mcast_packets);
216 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bcast_packets);
217 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_error_packets);
Jason Huang2d9382f2020-10-21 17:52:05 +0800218 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_64);
219 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_65_127);
220 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_128_255);
221 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_256_511);
222 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_512_1023);
223 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1024_1518);
224 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1519_2047);
225 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_2048_4095);
226 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_4096_9216);
227 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400228
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000229 /* call API */
230 err = bcmolt_stat_get((bcmolt_oltid)device_id, &nni_stats.hdr, clear_on_read);
231 if (err == BCM_ERR_OK)
232 {
233 //std::cout << "Interface statistics retrieved"
234 // << " intf_id:" << intf_id << std::endl;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000235 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
akashreddyk763899a2026-02-05 10:04:28 +0530236 port_stats->set_rx_frames(nni_stats.data.rx_packets);
237 port_stats->set_rx_ucast_frames(nni_stats.data.rx_ucast_packets);
238 port_stats->set_rx_mcast_frames(nni_stats.data.rx_mcast_packets);
239 port_stats->set_rx_bcast_frames(nni_stats.data.rx_bcast_packets);
240 port_stats->set_rx_error_frames(nni_stats.data.rx_error_packets);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000241 port_stats->set_tx_bytes(nni_stats.data.tx_bytes);
akashreddyk763899a2026-02-05 10:04:28 +0530242 port_stats->set_tx_frames(nni_stats.data.tx_packets);
243 port_stats->set_tx_ucast_frames(nni_stats.data.tx_ucast_packets);
244 port_stats->set_tx_mcast_frames(nni_stats.data.tx_mcast_packets);
245 port_stats->set_tx_bcast_frames(nni_stats.data.tx_bcast_packets);
246 port_stats->set_tx_error_frames(nni_stats.data.tx_error_packets);
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800247
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000248 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500249 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
250 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000251 }
252 break;
253 }
254 case BCMOLT_INTERFACE_TYPE_PON:
255 {
256 bcmolt_pon_interface_key key;
257 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
258 BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key);
259 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets);
260 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors);
261 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400262
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000263 /* call API */
264 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_pon_stats.hdr, clear_on_read);
265 if (err == BCM_ERR_OK) {
266 port_stats->set_tx_packets(itu_pon_stats.data.tx_packets);
267 port_stats->set_bip_errors(itu_pon_stats.data.bip_errors);
268 port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error);
269 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500270 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
271 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000272 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800273#if 1 // Shall be fixed as part of VOL-3691. When fixed, the #else code block should be enabled.
274 {
275 bcmolt_onu_key key;
276 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
277 BCMOLT_STAT_INIT(&pon_stats, onu, itu_pon_stats, key);
278 BCMOLT_MSG_FIELD_GET(&pon_stats, rx_bytes);
279 BCMOLT_MSG_FIELD_GET(&pon_stats, rx_packets);
280 BCMOLT_MSG_FIELD_GET(&pon_stats, tx_bytes);
281
282 /* call API */
283 err = bcmolt_stat_get((bcmolt_oltid)device_id, &pon_stats.hdr, clear_on_read);
284 if (err == BCM_ERR_OK) {
285 port_stats->set_rx_bytes(pon_stats.data.rx_bytes);
286 port_stats->set_rx_packets(pon_stats.data.rx_packets);
287 port_stats->set_tx_bytes(pon_stats.data.tx_bytes);
288 } else {
289 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
290 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
291 }
292 }
293#else
Jason Huang2d9382f2020-10-21 17:52:05 +0800294
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000295 {
Jason Huang2d9382f2020-10-21 17:52:05 +0800296 bcmolt_internal_nni_key key = {};
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000297 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
Jason Huang2d9382f2020-10-21 17:52:05 +0800298 BCMOLT_STAT_INIT(&enet_stat, internal_nni, enet_stats, key);
299 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_bytes);
300 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames);
301 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_64);
302 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_65_127);
303 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_128_255);
304 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_256_511);
305 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_512_1023);
306 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1024_1518);
307 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1519_2047);
308 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_2048_4095);
309 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_4096_9216);
310 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_9217_16383);
311 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_bytes);
312 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames);
313 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_64);
314 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_65_127);
315 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_128_255);
316 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_256_511);
317 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_512_1023);
318 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1024_1518);
319 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1519_2047);
320 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_2048_4095);
321 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_4096_9216);
322 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400323
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000324 /* call API */
Jason Huang2d9382f2020-10-21 17:52:05 +0800325 err = bcmolt_stat_get((bcmolt_oltid)device_id, &enet_stat.hdr, clear_on_read);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000326 if (err == BCM_ERR_OK) {
Jason Huang2d9382f2020-10-21 17:52:05 +0800327 port_stats->set_rx_bytes(enet_stat.data.rx_bytes);
328 port_stats->set_rx_packets(enet_stat.data.rx_frames);
329 port_stats->set_rx_packets(enet_stat.data.rx_frames_64);
330 port_stats->set_rx_packets(enet_stat.data.rx_frames_65_127);
331 port_stats->set_rx_packets(enet_stat.data.rx_frames_128_255);
332 port_stats->set_rx_packets(enet_stat.data.rx_frames_256_511);
333 port_stats->set_rx_packets(enet_stat.data.rx_frames_512_1023);
334 port_stats->set_rx_packets(enet_stat.data.rx_frames_1024_1518);
335 port_stats->set_rx_packets(enet_stat.data.rx_frames_1519_2047);
336 port_stats->set_rx_packets(enet_stat.data.rx_frames_2048_4095);
337 port_stats->set_rx_packets(enet_stat.data.rx_frames_4096_9216);
338 port_stats->set_rx_packets(enet_stat.data.rx_frames_9217_16383);
339
340 port_stats->set_tx_bytes(enet_stat.data.tx_bytes);
341 port_stats->set_rx_packets(enet_stat.data.tx_frames);
342 port_stats->set_rx_packets(enet_stat.data.tx_frames_64);
343 port_stats->set_rx_packets(enet_stat.data.tx_frames_65_127);
344 port_stats->set_rx_packets(enet_stat.data.tx_frames_128_255);
345 port_stats->set_rx_packets(enet_stat.data.tx_frames_256_511);
346 port_stats->set_rx_packets(enet_stat.data.tx_frames_512_1023);
347 port_stats->set_rx_packets(enet_stat.data.tx_frames_1024_1518);
348 port_stats->set_rx_packets(enet_stat.data.tx_frames_1519_2047);
349 port_stats->set_rx_packets(enet_stat.data.tx_frames_2048_4095);
350 port_stats->set_rx_packets(enet_stat.data.tx_frames_4096_9216);
351 port_stats->set_rx_packets(enet_stat.data.tx_frames_9217_16383);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000352 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500353 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
354 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000355 }
356 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800357#endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000358 break;
359 }
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800360 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000361
362 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 -0400363 time_t now;
364 time(&now);
365 port_stats->set_timestamp((int)now);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000366#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400367 return port_stats;
368
369}
370
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530371bcmos_errno get_port_statistics(bcmolt_intf_ref intf_ref, common::PortStatistics* port_stats) {
372 bcmos_errno err = BCM_ERR_OK;
373 common::PortStatistics* port_stats_temp = get_default_port_statistics();
374 memcpy(port_stats, port_stats_temp, sizeof(common::PortStatistics));
375 delete port_stats_temp;
376
377#ifndef TEST_MODE
378 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
379 bcmolt_nni_interface_stats nni_stats;
380 bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
381
382 switch (intf_ref.intf_type) {
383 case BCMOLT_INTERFACE_TYPE_NNI:
384 {
385 bcmolt_nni_interface_key nni_intf_key;
386 nni_intf_key.id = intf_ref.intf_id;
387 /* init the API struct */
388 BCMOLT_STAT_INIT(&nni_stats, nni_interface, stats, nni_intf_key);
389 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bytes);
390 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_packets);
391 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_ucast_packets);
392 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_mcast_packets);
393 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bcast_packets);
394 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_error_packets);
395 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_fcs_error_packets);
396 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_undersize_packets);
397 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_oversize_packets);
398 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_64);
399 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_65_127);
400 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_128_255);
401 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_256_511);
402 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_512_1023);
403 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1024_1518);
404 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1519_2047);
405 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_2048_4095);
406 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_4096_9216);
407 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_9217_16383);
408
409 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bytes);
410 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_packets);
411 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_ucast_packets);
412 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_mcast_packets);
413 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bcast_packets);
414 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_error_packets);
415 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_undersize_packets);
416 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_oversize_packets);
417 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_64);
418 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_65_127);
419 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_128_255);
420 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_256_511);
421 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_512_1023);
422 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1024_1518);
423 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1519_2047);
424 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_2048_4095);
425 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_4096_9216);
426 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_9217_16383);
427
428 /* call API */
429 err = bcmolt_stat_get((bcmolt_oltid)device_id, &nni_stats.hdr, clear_on_read);
430 if (err == BCM_ERR_OK)
431 {
432 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
akashreddykbb9b4db2025-12-22 14:19:30 +0530433 port_stats->set_rx_frames(nni_stats.data.rx_packets);
434 port_stats->set_rx_ucast_frames(nni_stats.data.rx_ucast_packets);
435 port_stats->set_rx_mcast_frames(nni_stats.data.rx_mcast_packets);
436 port_stats->set_rx_bcast_frames(nni_stats.data.rx_bcast_packets);
437 port_stats->set_rx_error_frames(nni_stats.data.rx_error_packets);
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530438 port_stats->set_rxfcserrorpackets(nni_stats.data.rx_fcs_error_packets);
439 port_stats->set_rxundersizepackets(nni_stats.data.rx_undersize_packets);
440 port_stats->set_rxoversizepackets(nni_stats.data.rx_oversize_packets);
441 port_stats->set_tx_bytes(nni_stats.data.tx_bytes);
akashreddykbb9b4db2025-12-22 14:19:30 +0530442 port_stats->set_tx_frames(nni_stats.data.tx_packets);
443 port_stats->set_tx_ucast_frames(nni_stats.data.tx_ucast_packets);
444 port_stats->set_tx_mcast_frames(nni_stats.data.tx_mcast_packets);
445 port_stats->set_tx_bcast_frames(nni_stats.data.tx_bcast_packets);
446 port_stats->set_tx_error_frames(nni_stats.data.tx_error_packets);
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530447 port_stats->set_txundersizepackets(nni_stats.data.tx_undersize_packets);
448 port_stats->set_txoversizepackets(nni_stats.data.tx_oversize_packets);
449
450 } else {
451 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
452 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
453 return err;
454 }
455 break;
456 }
457 case BCMOLT_INTERFACE_TYPE_PON:
458 {
459 bcmolt_pon_interface_key key;
460 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
461 BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key);
462 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_units);
463 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors);
464 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_packets);
465 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem);
466 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_dropped);
467 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_idle);
468 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_corrected);
469 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error);
470 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_fragment_error);
471 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_packets_dropped);
472 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_cpu_omci_packets_dropped);
473 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_cpu);
474 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_omci);
475 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_omci_packets_crc_error);
476 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_illegal);
477 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets);
478 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_gem);
479 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_cpu);
480 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_omci);
481 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_illegal_length);
482 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_tpid_miss);
483 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_vid_miss);
484 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_total);
485
486 /* call API */
487 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_pon_stats.hdr, clear_on_read);
488 if (err == BCM_ERR_OK) {
489 port_stats->set_bip_units(itu_pon_stats.data.bip_units);
490 port_stats->set_bip_errors(itu_pon_stats.data.bip_errors);
491 port_stats->set_rx_packets(itu_pon_stats.data.rx_packets);
492 port_stats->set_rxgem(itu_pon_stats.data.rx_gem);
493 port_stats->set_rxgemdropped(itu_pon_stats.data.rx_gem_dropped);
494 port_stats->set_rxgemidle(itu_pon_stats.data.rx_gem_idle);
495 port_stats->set_rxgemcorrected(itu_pon_stats.data.rx_gem_corrected);
496 port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error);
497 port_stats->set_rxfragmenterror(itu_pon_stats.data.rx_fragment_error);
498 port_stats->set_rxpacketsdropped(itu_pon_stats.data.rx_packets_dropped);
499 port_stats->set_rxcpuomcipacketsdropped(itu_pon_stats.data.rx_cpu_omci_packets_dropped);
500 port_stats->set_rxcpu(itu_pon_stats.data.rx_cpu);
501 port_stats->set_rxomci(itu_pon_stats.data.rx_omci);
502 port_stats->set_rxomcipacketscrcerror(itu_pon_stats.data.rx_omci_packets_crc_error);
503 port_stats->set_rxgemillegal(itu_pon_stats.data.rx_gem_illegal);
504 port_stats->set_tx_packets(itu_pon_stats.data.tx_packets);
505 port_stats->set_txgem(itu_pon_stats.data.tx_gem);
506 port_stats->set_txcpu(itu_pon_stats.data.tx_cpu);
507 port_stats->set_txomci(itu_pon_stats.data.tx_omci);
508 port_stats->set_txdroppedillegallength(itu_pon_stats.data.tx_dropped_illegal_length);
509 port_stats->set_txdroppedtpidmiss(itu_pon_stats.data.tx_dropped_tpid_miss);
510 port_stats->set_txdroppedvidmiss(itu_pon_stats.data.tx_dropped_vid_miss);
511 port_stats->set_txdroppedtotal(itu_pon_stats.data.tx_dropped_total);
512 } else {
513 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
514 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
515 return err;
516 }
517 break;
518 }
519 }
520
521 port_stats->set_intf_id(interface_key_to_port_no((bcmolt_interface_id)intf_ref.intf_id, (bcmolt_interface_type)intf_ref.intf_type));
522 time_t now;
523 time(&now);
524 port_stats->set_timestamp((int)now);
525#endif
526 return err;
527}
528
Burak Gurdag74e3ab82020-12-17 13:35:06 +0000529bcmos_errno get_onu_statistics(bcmolt_interface_id intf_id, bcmolt_onu_id onu_id, openolt::OnuStatistics* onu_stats) {
530 bcmos_errno err = BCM_ERR_OK;
531
532#ifndef TEST_MODE
533 *onu_stats = get_default_onu_statistics();
534 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
535 bcmolt_onu_itu_pon_stats itu_onu_stats;
536
537 {
538 bcmolt_onu_key key;
539 key.pon_ni = intf_id;
540 key.onu_id = onu_id;
541 BCMOLT_STAT_INIT(&itu_onu_stats, onu, itu_pon_stats, key);
542 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, positive_drift);
543 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, negative_drift);
544 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, delimiter_miss_detection);
545 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, bip_errors);
546 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, bip_units);
547 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_corrected_symbols);
548 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords_corrected);
549 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords_uncorrectable);
550 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords);
551 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_corrected_units);
552 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, xgem_key_errors);
553 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, xgem_loss);
554 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_ploams_error);
555 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_ploams_non_idle);
556 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_omci);
557 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_omci_packets_crc_error);
558 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_bytes);
559 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_packets);
560 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, tx_bytes);
561 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, tx_packets);
562 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, ber_reported);
563 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, lcdg_errors);
564 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rdi_errors);
565
566 /* call API */
567 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_onu_stats.hdr, clear_on_read);
568 if (err == BCM_ERR_OK) {
569 onu_stats->set_positive_drift(itu_onu_stats.data.positive_drift);
570 onu_stats->set_negative_drift(itu_onu_stats.data.negative_drift);
571 onu_stats->set_delimiter_miss_detection(itu_onu_stats.data.delimiter_miss_detection);
572 onu_stats->set_bip_errors(itu_onu_stats.data.bip_errors);
573 onu_stats->set_bip_units(itu_onu_stats.data.bip_units);
574 onu_stats->set_fec_corrected_symbols(itu_onu_stats.data.fec_corrected_symbols);
575 onu_stats->set_fec_codewords_corrected(itu_onu_stats.data.fec_codewords_corrected);
576 onu_stats->set_fec_codewords_uncorrectable(itu_onu_stats.data.fec_codewords_uncorrectable);
577 onu_stats->set_fec_codewords(itu_onu_stats.data.fec_codewords);
578 onu_stats->set_fec_corrected_units(itu_onu_stats.data.fec_corrected_units);
579 onu_stats->set_xgem_key_errors(itu_onu_stats.data.xgem_key_errors);
580 onu_stats->set_xgem_loss(itu_onu_stats.data.xgem_loss);
581 onu_stats->set_rx_ploams_error(itu_onu_stats.data.rx_ploams_error);
582 onu_stats->set_rx_ploams_non_idle(itu_onu_stats.data.rx_ploams_non_idle);
583 onu_stats->set_rx_omci(itu_onu_stats.data.rx_omci);
584 onu_stats->set_rx_omci_packets_crc_error(itu_onu_stats.data.rx_omci_packets_crc_error);
585 onu_stats->set_rx_bytes(itu_onu_stats.data.rx_bytes);
586 onu_stats->set_rx_packets(itu_onu_stats.data.rx_packets);
587 onu_stats->set_tx_bytes(itu_onu_stats.data.tx_bytes);
588 onu_stats->set_tx_packets(itu_onu_stats.data.tx_packets);
589 onu_stats->set_ber_reported(itu_onu_stats.data.ber_reported);
590 onu_stats->set_lcdg_errors(itu_onu_stats.data.lcdg_errors);
591 onu_stats->set_rdi_errors(itu_onu_stats.data.rdi_errors);
592 } else {
593 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ONU statistics, intf_id %d, onu_id %d, err no: %d - %s\n",
594 (int)intf_id, (int)onu_id, err, bcmos_strerror(err));
595 return err;
596 }
597 }
598
599 onu_stats->set_intf_id(intf_id);
600 onu_stats->set_onu_id(onu_id);
601 time_t now;
602 time(&now);
603 onu_stats->set_timestamp((int)now);
604#endif
605
606 return err;
607}
608
609bcmos_errno get_gemport_statistics(bcmolt_interface_id intf_id, bcmolt_gem_port_id gemport_id, openolt::GemPortStatistics* gemport_stats) {
610 bcmos_errno err = BCM_ERR_OK;
611
612#ifndef TEST_MODE
613 *gemport_stats = get_default_gemport_statistics();
614 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
615 bcmolt_itupon_gem_stats gem_stats;
616
617 {
618 bcmolt_itupon_gem_key key;
619 key.pon_ni = intf_id;
620 key.gem_port_id = gemport_id;
621
622 BCMOLT_STAT_INIT(&gem_stats, itupon_gem, stats, key);
623 BCMOLT_MSG_FIELD_GET(&gem_stats, rx_packets);
624 BCMOLT_MSG_FIELD_GET(&gem_stats, rx_bytes);
625 BCMOLT_MSG_FIELD_GET(&gem_stats, tx_packets);
626 BCMOLT_MSG_FIELD_GET(&gem_stats, tx_bytes);
627
628 /* call API */
629 err = bcmolt_stat_get((bcmolt_oltid)device_id, &gem_stats.hdr, clear_on_read);
630 if (err == BCM_ERR_OK) {
631 gemport_stats->set_rx_packets(gem_stats.data.rx_packets);
632 gemport_stats->set_rx_bytes(gem_stats.data.rx_bytes);
633 gemport_stats->set_tx_packets(gem_stats.data.tx_packets);
634 gemport_stats->set_tx_bytes(gem_stats.data.tx_bytes);
635 } else {
636 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve GEMPORT statistics, intf_id %d, gemport_id %d, err no: %d - %s\n",
637 (int)intf_id, (int)gemport_id, err, bcmos_strerror(err));
638 return err;
639 }
640 }
641
642 gemport_stats->set_intf_id(intf_id);
643 gemport_stats->set_gemport_id(gemport_id);
644 time_t now;
645 time(&now);
646 gemport_stats->set_timestamp((int)now);
647#endif
648
649 return err;
650}
651
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530652bcmos_errno set_collect_alloc_stats(bcmolt_interface_id intf_id, bcmolt_alloc_id alloc_id, bcmos_bool collect_stats) {
653 bcmos_errno err = BCM_ERR_OK;
654 bcmolt_itupon_alloc_cfg cfg;
655 bcmolt_itupon_alloc_key key;
656 key.pon_ni = intf_id;
657 key.alloc_id = alloc_id;
658
659 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
660 BCMOLT_FIELD_SET(&cfg.data, itupon_alloc_cfg_data, collect_stats, collect_stats);
661 err = bcmolt_cfg_set((bcmolt_oltid)device_id, &cfg.hdr);
662 return err;
663}
664
665bcmos_errno get_alloc_statistics(bcmolt_interface_id intf_id, bcmolt_alloc_id alloc_id, openolt::OnuAllocIdStatistics* allocid_stats) {
666 bcmos_errno err = BCM_ERR_OK;
667
668#ifndef TEST_MODE
669
670 bcmos_errno err1 = BCM_ERR_OK;
671 err1 = set_collect_alloc_stats(intf_id, alloc_id, BCMOS_TRUE);
672 if (err1 == BCM_ERR_OK) {
673 *allocid_stats = get_default_alloc_statistics();
674 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
675 bcmolt_itupon_alloc_stats alloc_stats;
676 bcmolt_itupon_alloc_key key;
677 key.pon_ni = intf_id;
678 key.alloc_id = alloc_id;
679
680 // Wait to collect alloc stats after enabling it
681 sleep(ALLOC_STATS_GET_INTERVAL);
682
683 BCMOLT_STAT_INIT(&alloc_stats, itupon_alloc, stats, key);
684 BCMOLT_MSG_FIELD_GET(&alloc_stats, rx_bytes);
685
686 /* call API */
687 err = bcmolt_stat_get((bcmolt_oltid)device_id, &alloc_stats.hdr, clear_on_read);
688 if (err == BCM_ERR_OK) {
689 allocid_stats->set_rxbytes(alloc_stats.data.rx_bytes);
690 allocid_stats->set_intfid(intf_id);
691 allocid_stats->set_allocid(alloc_id);
692 } else {
693 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ALLOC_ID statistics, intf_id %d, alloc_id %d, err no: %d - %s\n",
694 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
695 err1 = set_collect_alloc_stats(intf_id, alloc_id, BCMOS_FALSE);
696 if (err1 != BCM_ERR_OK) {
697 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable collect_stats for ALLOC_ID, intf_id %d, alloc_id %d, err no: %d - %s\n",
698 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
699 }
700 return err;
701 }
702 } else {
703 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable collect_stats for ALLOC_ID, intf_id %d, alloc_id %d, err no: %d - %s\n",
704 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
705 return err1;
706 }
707
708 err1 = set_collect_alloc_stats(intf_id, alloc_id, BCMOS_FALSE);
709 if (err1 != BCM_ERR_OK) {
710 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable collect_stats for ALLOC_ID, intf_id %d, alloc_id %d, err no: %d - %s\n",
711 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
712 return err1;
713 }
714
715#endif
716
717 return err;
718}
719
Shad Ansaricb004c52018-05-30 18:07:23 +0000720#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400721openolt::FlowStatistics* collectFlowStatistics(bcmbal_flow_id flow_id, bcmbal_flow_type flow_type) {
722
723 bcmos_errno err;
724 bcmbal_flow_stat stat; /**< declare main API struct */
725 bcmbal_flow_key key = { }; /**< declare key */
726 bcmos_bool clear_on_read = false;
727
728 openolt::FlowStatistics* flow_stats = get_default_flow_statistics();
729 //Key
730 key.flow_id = flow_id;
731 key.flow_type = flow_type;
732
733 /* init the API struct */
734 BCMBAL_STAT_INIT(&stat, flow, key);
735 BCMBAL_STAT_PROP_GET(&stat, flow, all_properties);
736
737 err = bcmbal_stat_get(DEFAULT_ATERM_ID, &stat.hdr, clear_on_read);
738
739 if (err == BCM_ERR_OK)
740 {
741 std::cout << "Flow statistics retrieved"
742 << " flow_id:" << flow_id
743 << " flow_type:" << flow_type << std::endl;
744
745 flow_stats->set_rx_bytes(stat.data.rx_bytes);
746 flow_stats->set_rx_packets(stat.data.rx_packets);
747 flow_stats->set_tx_bytes(stat.data.tx_bytes);
748 flow_stats->set_tx_packets(stat.data.tx_packets);
749
750 } else {
751 std::cout << "ERROR: Failed to retrieve flow statistics"
752 << " flow_id:" << flow_id
753 << " flow_type:" << flow_type << std::endl;
754 }
755
756 return flow_stats;
757}
Shad Ansaricb004c52018-05-30 18:07:23 +0000758#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400759
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400760void stats_collection() {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400761
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400762 if (!state.is_connected()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000763 OPENOLT_LOG(INFO, openolt_log_id, "Voltha is not connected, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400764 return;
765 }
766 if (!state.is_activated()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000767 OPENOLT_LOG(INFO, openolt_log_id, "The OLT is not up, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400768 return;
769 }
770
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000771 OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n");
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400772
Shad Ansariedef2132018-08-10 22:14:50 +0000773 //Ports statistics
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400774
Shad Ansariedef2132018-08-10 22:14:50 +0000775 //Uplink ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500776 for (int i = 0; i < NumNniIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000777 bcmolt_intf_ref intf_ref;
778 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI;
779 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400780
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530781 common::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000782 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400783
Girish Gowdra252f4972020-09-07 21:24:01 -0700784 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000785 ind.set_allocated_port_stats(port_stats);
786 oltIndQ.push(ind);
787 }
788 //Pon ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500789 for (int i = 0; i < NumPonIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000790 bcmolt_intf_ref intf_ref;
791 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON;
792 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400793
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530794 common::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000795 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400796
Girish Gowdra252f4972020-09-07 21:24:01 -0700797 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000798 ind.set_allocated_port_stats(port_stats);
799 oltIndQ.push(ind);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400800 }
801
Shad Ansariedef2132018-08-10 22:14:50 +0000802 //Flows statistics
803 // flow_inst *current_entry = NULL;
804 //
805 // TAILQ_FOREACH(current_entry,
806 // &FLOW_FSM_FLOW_LIST_CTX_PTR->active_flow_list,
807 // flow_inst_next) {
808 // int flows_measurements = 0;
809 //
810 // for (int i = 0; i < FLOWS_COUNT; i++) {
811 //
812 // // bcmbal_flow_id flow_id = current_entry->api_req_flow_info.key.flow_id;
813 // // bcmbal_flow_type flow_type = current_entry->api_req_flow_info.key.flow_type;
814 //
815 // if (flows_keys[i].flow_id != 0) {
816 // openolt::FlowStatistics* flow_stats = collectFlowStatistics(flows_keys[i].flow_id, flows_keys[i].flow_type);
817 // if (flow_stats->rx_packets() == -1) {
818 // //It Failed
819 // flows_keys[i].flow_id = 0;
820 // } else {
821 // flow_stats->set_flow_id(flows_keys[i].flow_id);
822 // time(&now);
823 // flow_stats->set_timestamp((int)now);
824 // openolt::Indication ind;
825 // ind.set_allocated_flow_stats(flow_stats);
826 // oltIndQ.push(ind);
827 // flows_measurements ++;
828 // }
829 // }
830 //
831 // }
832 // std::cout << "Stats of " << flows_measurements << " flows retrieved" << std::endl;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400833
834}
835
836/* Storing flow keys, temporary */
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400837// void register_new_flow(bcmbal_flow_key key) {
838// for (int i = 0; i < FLOWS_COUNT; i++) {
839// if (flows_keys[i].flow_id == 0) {
840// flows_keys[i] = key;
841// break;
842// }
843// }
844// }