blob: 20e512ab11d50b233d91a2cf77e7c94596c535d7 [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;
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800235
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000236 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
237 port_stats->set_rx_packets(nni_stats.data.rx_packets);
238 port_stats->set_rx_ucast_packets(nni_stats.data.rx_ucast_packets);
239 port_stats->set_rx_mcast_packets(nni_stats.data.rx_mcast_packets);
240 port_stats->set_rx_bcast_packets(nni_stats.data.rx_bcast_packets);
241 port_stats->set_rx_error_packets(nni_stats.data.rx_error_packets);
242 port_stats->set_tx_bytes(nni_stats.data.tx_bytes);
243 port_stats->set_tx_packets(nni_stats.data.tx_packets);
244 port_stats->set_tx_ucast_packets(nni_stats.data.tx_ucast_packets);
245 port_stats->set_tx_mcast_packets(nni_stats.data.tx_mcast_packets);
246 port_stats->set_tx_bcast_packets(nni_stats.data.tx_bcast_packets);
247 port_stats->set_tx_error_packets(nni_stats.data.tx_error_packets);
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800248
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000249 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500250 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
251 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000252 }
253 break;
254 }
255 case BCMOLT_INTERFACE_TYPE_PON:
256 {
257 bcmolt_pon_interface_key key;
258 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
259 BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key);
260 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets);
261 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors);
262 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400263
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000264 /* call API */
265 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_pon_stats.hdr, clear_on_read);
266 if (err == BCM_ERR_OK) {
267 port_stats->set_tx_packets(itu_pon_stats.data.tx_packets);
268 port_stats->set_bip_errors(itu_pon_stats.data.bip_errors);
269 port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error);
270 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500271 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
272 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000273 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800274#if 1 // Shall be fixed as part of VOL-3691. When fixed, the #else code block should be enabled.
275 {
276 bcmolt_onu_key key;
277 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
278 BCMOLT_STAT_INIT(&pon_stats, onu, itu_pon_stats, key);
279 BCMOLT_MSG_FIELD_GET(&pon_stats, rx_bytes);
280 BCMOLT_MSG_FIELD_GET(&pon_stats, rx_packets);
281 BCMOLT_MSG_FIELD_GET(&pon_stats, tx_bytes);
282
283 /* call API */
284 err = bcmolt_stat_get((bcmolt_oltid)device_id, &pon_stats.hdr, clear_on_read);
285 if (err == BCM_ERR_OK) {
286 port_stats->set_rx_bytes(pon_stats.data.rx_bytes);
287 port_stats->set_rx_packets(pon_stats.data.rx_packets);
288 port_stats->set_tx_bytes(pon_stats.data.tx_bytes);
289 } else {
290 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
291 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
292 }
293 }
294#else
Jason Huang2d9382f2020-10-21 17:52:05 +0800295
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000296 {
Jason Huang2d9382f2020-10-21 17:52:05 +0800297 bcmolt_internal_nni_key key = {};
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000298 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
Jason Huang2d9382f2020-10-21 17:52:05 +0800299 BCMOLT_STAT_INIT(&enet_stat, internal_nni, enet_stats, key);
300 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_bytes);
301 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames);
302 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_64);
303 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_65_127);
304 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_128_255);
305 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_256_511);
306 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_512_1023);
307 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1024_1518);
308 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1519_2047);
309 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_2048_4095);
310 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_4096_9216);
311 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_9217_16383);
312 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_bytes);
313 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames);
314 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_64);
315 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_65_127);
316 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_128_255);
317 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_256_511);
318 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_512_1023);
319 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1024_1518);
320 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1519_2047);
321 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_2048_4095);
322 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_4096_9216);
323 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400324
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000325 /* call API */
Jason Huang2d9382f2020-10-21 17:52:05 +0800326 err = bcmolt_stat_get((bcmolt_oltid)device_id, &enet_stat.hdr, clear_on_read);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000327 if (err == BCM_ERR_OK) {
Jason Huang2d9382f2020-10-21 17:52:05 +0800328 port_stats->set_rx_bytes(enet_stat.data.rx_bytes);
329 port_stats->set_rx_packets(enet_stat.data.rx_frames);
330 port_stats->set_rx_packets(enet_stat.data.rx_frames_64);
331 port_stats->set_rx_packets(enet_stat.data.rx_frames_65_127);
332 port_stats->set_rx_packets(enet_stat.data.rx_frames_128_255);
333 port_stats->set_rx_packets(enet_stat.data.rx_frames_256_511);
334 port_stats->set_rx_packets(enet_stat.data.rx_frames_512_1023);
335 port_stats->set_rx_packets(enet_stat.data.rx_frames_1024_1518);
336 port_stats->set_rx_packets(enet_stat.data.rx_frames_1519_2047);
337 port_stats->set_rx_packets(enet_stat.data.rx_frames_2048_4095);
338 port_stats->set_rx_packets(enet_stat.data.rx_frames_4096_9216);
339 port_stats->set_rx_packets(enet_stat.data.rx_frames_9217_16383);
340
341 port_stats->set_tx_bytes(enet_stat.data.tx_bytes);
342 port_stats->set_rx_packets(enet_stat.data.tx_frames);
343 port_stats->set_rx_packets(enet_stat.data.tx_frames_64);
344 port_stats->set_rx_packets(enet_stat.data.tx_frames_65_127);
345 port_stats->set_rx_packets(enet_stat.data.tx_frames_128_255);
346 port_stats->set_rx_packets(enet_stat.data.tx_frames_256_511);
347 port_stats->set_rx_packets(enet_stat.data.tx_frames_512_1023);
348 port_stats->set_rx_packets(enet_stat.data.tx_frames_1024_1518);
349 port_stats->set_rx_packets(enet_stat.data.tx_frames_1519_2047);
350 port_stats->set_rx_packets(enet_stat.data.tx_frames_2048_4095);
351 port_stats->set_rx_packets(enet_stat.data.tx_frames_4096_9216);
352 port_stats->set_rx_packets(enet_stat.data.tx_frames_9217_16383);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000353 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500354 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
355 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000356 }
357 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800358#endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000359 break;
360 }
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800361 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000362
363 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 -0400364 time_t now;
365 time(&now);
366 port_stats->set_timestamp((int)now);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000367#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400368 return port_stats;
369
370}
371
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530372bcmos_errno get_port_statistics(bcmolt_intf_ref intf_ref, common::PortStatistics* port_stats) {
373 bcmos_errno err = BCM_ERR_OK;
374 common::PortStatistics* port_stats_temp = get_default_port_statistics();
375 memcpy(port_stats, port_stats_temp, sizeof(common::PortStatistics));
376 delete port_stats_temp;
377
378#ifndef TEST_MODE
379 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
380 bcmolt_nni_interface_stats nni_stats;
381 bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
382
383 switch (intf_ref.intf_type) {
384 case BCMOLT_INTERFACE_TYPE_NNI:
385 {
386 bcmolt_nni_interface_key nni_intf_key;
387 nni_intf_key.id = intf_ref.intf_id;
388 /* init the API struct */
389 BCMOLT_STAT_INIT(&nni_stats, nni_interface, stats, nni_intf_key);
390 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bytes);
391 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_packets);
392 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_ucast_packets);
393 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_mcast_packets);
394 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bcast_packets);
395 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_error_packets);
396 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_fcs_error_packets);
397 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_undersize_packets);
398 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_oversize_packets);
399 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_64);
400 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_65_127);
401 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_128_255);
402 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_256_511);
403 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_512_1023);
404 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1024_1518);
405 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1519_2047);
406 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_2048_4095);
407 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_4096_9216);
408 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_9217_16383);
409
410 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bytes);
411 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_packets);
412 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_ucast_packets);
413 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_mcast_packets);
414 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bcast_packets);
415 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_error_packets);
416 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_undersize_packets);
417 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_oversize_packets);
418 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_64);
419 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_65_127);
420 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_128_255);
421 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_256_511);
422 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_512_1023);
423 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1024_1518);
424 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1519_2047);
425 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_2048_4095);
426 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_4096_9216);
427 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_9217_16383);
428
429 /* call API */
430 err = bcmolt_stat_get((bcmolt_oltid)device_id, &nni_stats.hdr, clear_on_read);
431 if (err == BCM_ERR_OK)
432 {
433 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
434 port_stats->set_rx_packets(nni_stats.data.rx_packets);
435 port_stats->set_rx_ucast_packets(nni_stats.data.rx_ucast_packets);
436 port_stats->set_rx_mcast_packets(nni_stats.data.rx_mcast_packets);
437 port_stats->set_rx_bcast_packets(nni_stats.data.rx_bcast_packets);
438 port_stats->set_rx_error_packets(nni_stats.data.rx_error_packets);
439 port_stats->set_rxfcserrorpackets(nni_stats.data.rx_fcs_error_packets);
440 port_stats->set_rxundersizepackets(nni_stats.data.rx_undersize_packets);
441 port_stats->set_rxoversizepackets(nni_stats.data.rx_oversize_packets);
442 port_stats->set_tx_bytes(nni_stats.data.tx_bytes);
443 port_stats->set_tx_packets(nni_stats.data.tx_packets);
444 port_stats->set_tx_ucast_packets(nni_stats.data.tx_ucast_packets);
445 port_stats->set_tx_mcast_packets(nni_stats.data.tx_mcast_packets);
446 port_stats->set_tx_bcast_packets(nni_stats.data.tx_bcast_packets);
447 port_stats->set_tx_error_packets(nni_stats.data.tx_error_packets);
448 port_stats->set_txundersizepackets(nni_stats.data.tx_undersize_packets);
449 port_stats->set_txoversizepackets(nni_stats.data.tx_oversize_packets);
450
451 } else {
452 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
453 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
454 return err;
455 }
456 break;
457 }
458 case BCMOLT_INTERFACE_TYPE_PON:
459 {
460 bcmolt_pon_interface_key key;
461 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
462 BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key);
463 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_units);
464 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors);
465 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_packets);
466 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem);
467 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_dropped);
468 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_idle);
469 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_corrected);
470 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error);
471 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_fragment_error);
472 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_packets_dropped);
473 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_cpu_omci_packets_dropped);
474 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_cpu);
475 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_omci);
476 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_omci_packets_crc_error);
477 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_gem_illegal);
478 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets);
479 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_gem);
480 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_cpu);
481 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_omci);
482 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_illegal_length);
483 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_tpid_miss);
484 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_vid_miss);
485 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_dropped_total);
486
487 /* call API */
488 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_pon_stats.hdr, clear_on_read);
489 if (err == BCM_ERR_OK) {
490 port_stats->set_bip_units(itu_pon_stats.data.bip_units);
491 port_stats->set_bip_errors(itu_pon_stats.data.bip_errors);
492 port_stats->set_rx_packets(itu_pon_stats.data.rx_packets);
493 port_stats->set_rxgem(itu_pon_stats.data.rx_gem);
494 port_stats->set_rxgemdropped(itu_pon_stats.data.rx_gem_dropped);
495 port_stats->set_rxgemidle(itu_pon_stats.data.rx_gem_idle);
496 port_stats->set_rxgemcorrected(itu_pon_stats.data.rx_gem_corrected);
497 port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error);
498 port_stats->set_rxfragmenterror(itu_pon_stats.data.rx_fragment_error);
499 port_stats->set_rxpacketsdropped(itu_pon_stats.data.rx_packets_dropped);
500 port_stats->set_rxcpuomcipacketsdropped(itu_pon_stats.data.rx_cpu_omci_packets_dropped);
501 port_stats->set_rxcpu(itu_pon_stats.data.rx_cpu);
502 port_stats->set_rxomci(itu_pon_stats.data.rx_omci);
503 port_stats->set_rxomcipacketscrcerror(itu_pon_stats.data.rx_omci_packets_crc_error);
504 port_stats->set_rxgemillegal(itu_pon_stats.data.rx_gem_illegal);
505 port_stats->set_tx_packets(itu_pon_stats.data.tx_packets);
506 port_stats->set_txgem(itu_pon_stats.data.tx_gem);
507 port_stats->set_txcpu(itu_pon_stats.data.tx_cpu);
508 port_stats->set_txomci(itu_pon_stats.data.tx_omci);
509 port_stats->set_txdroppedillegallength(itu_pon_stats.data.tx_dropped_illegal_length);
510 port_stats->set_txdroppedtpidmiss(itu_pon_stats.data.tx_dropped_tpid_miss);
511 port_stats->set_txdroppedvidmiss(itu_pon_stats.data.tx_dropped_vid_miss);
512 port_stats->set_txdroppedtotal(itu_pon_stats.data.tx_dropped_total);
513 } else {
514 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
515 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
516 return err;
517 }
518 break;
519 }
520 }
521
522 port_stats->set_intf_id(interface_key_to_port_no((bcmolt_interface_id)intf_ref.intf_id, (bcmolt_interface_type)intf_ref.intf_type));
523 time_t now;
524 time(&now);
525 port_stats->set_timestamp((int)now);
526#endif
527 return err;
528}
529
Burak Gurdag74e3ab82020-12-17 13:35:06 +0000530bcmos_errno get_onu_statistics(bcmolt_interface_id intf_id, bcmolt_onu_id onu_id, openolt::OnuStatistics* onu_stats) {
531 bcmos_errno err = BCM_ERR_OK;
532
533#ifndef TEST_MODE
534 *onu_stats = get_default_onu_statistics();
535 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
536 bcmolt_onu_itu_pon_stats itu_onu_stats;
537
538 {
539 bcmolt_onu_key key;
540 key.pon_ni = intf_id;
541 key.onu_id = onu_id;
542 BCMOLT_STAT_INIT(&itu_onu_stats, onu, itu_pon_stats, key);
543 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, positive_drift);
544 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, negative_drift);
545 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, delimiter_miss_detection);
546 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, bip_errors);
547 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, bip_units);
548 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_corrected_symbols);
549 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords_corrected);
550 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords_uncorrectable);
551 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords);
552 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_corrected_units);
553 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, xgem_key_errors);
554 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, xgem_loss);
555 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_ploams_error);
556 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_ploams_non_idle);
557 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_omci);
558 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_omci_packets_crc_error);
559 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_bytes);
560 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_packets);
561 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, tx_bytes);
562 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, tx_packets);
563 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, ber_reported);
564 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, lcdg_errors);
565 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rdi_errors);
566
567 /* call API */
568 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_onu_stats.hdr, clear_on_read);
569 if (err == BCM_ERR_OK) {
570 onu_stats->set_positive_drift(itu_onu_stats.data.positive_drift);
571 onu_stats->set_negative_drift(itu_onu_stats.data.negative_drift);
572 onu_stats->set_delimiter_miss_detection(itu_onu_stats.data.delimiter_miss_detection);
573 onu_stats->set_bip_errors(itu_onu_stats.data.bip_errors);
574 onu_stats->set_bip_units(itu_onu_stats.data.bip_units);
575 onu_stats->set_fec_corrected_symbols(itu_onu_stats.data.fec_corrected_symbols);
576 onu_stats->set_fec_codewords_corrected(itu_onu_stats.data.fec_codewords_corrected);
577 onu_stats->set_fec_codewords_uncorrectable(itu_onu_stats.data.fec_codewords_uncorrectable);
578 onu_stats->set_fec_codewords(itu_onu_stats.data.fec_codewords);
579 onu_stats->set_fec_corrected_units(itu_onu_stats.data.fec_corrected_units);
580 onu_stats->set_xgem_key_errors(itu_onu_stats.data.xgem_key_errors);
581 onu_stats->set_xgem_loss(itu_onu_stats.data.xgem_loss);
582 onu_stats->set_rx_ploams_error(itu_onu_stats.data.rx_ploams_error);
583 onu_stats->set_rx_ploams_non_idle(itu_onu_stats.data.rx_ploams_non_idle);
584 onu_stats->set_rx_omci(itu_onu_stats.data.rx_omci);
585 onu_stats->set_rx_omci_packets_crc_error(itu_onu_stats.data.rx_omci_packets_crc_error);
586 onu_stats->set_rx_bytes(itu_onu_stats.data.rx_bytes);
587 onu_stats->set_rx_packets(itu_onu_stats.data.rx_packets);
588 onu_stats->set_tx_bytes(itu_onu_stats.data.tx_bytes);
589 onu_stats->set_tx_packets(itu_onu_stats.data.tx_packets);
590 onu_stats->set_ber_reported(itu_onu_stats.data.ber_reported);
591 onu_stats->set_lcdg_errors(itu_onu_stats.data.lcdg_errors);
592 onu_stats->set_rdi_errors(itu_onu_stats.data.rdi_errors);
593 } else {
594 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ONU statistics, intf_id %d, onu_id %d, err no: %d - %s\n",
595 (int)intf_id, (int)onu_id, err, bcmos_strerror(err));
596 return err;
597 }
598 }
599
600 onu_stats->set_intf_id(intf_id);
601 onu_stats->set_onu_id(onu_id);
602 time_t now;
603 time(&now);
604 onu_stats->set_timestamp((int)now);
605#endif
606
607 return err;
608}
609
610bcmos_errno get_gemport_statistics(bcmolt_interface_id intf_id, bcmolt_gem_port_id gemport_id, openolt::GemPortStatistics* gemport_stats) {
611 bcmos_errno err = BCM_ERR_OK;
612
613#ifndef TEST_MODE
614 *gemport_stats = get_default_gemport_statistics();
615 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
616 bcmolt_itupon_gem_stats gem_stats;
617
618 {
619 bcmolt_itupon_gem_key key;
620 key.pon_ni = intf_id;
621 key.gem_port_id = gemport_id;
622
623 BCMOLT_STAT_INIT(&gem_stats, itupon_gem, stats, key);
624 BCMOLT_MSG_FIELD_GET(&gem_stats, rx_packets);
625 BCMOLT_MSG_FIELD_GET(&gem_stats, rx_bytes);
626 BCMOLT_MSG_FIELD_GET(&gem_stats, tx_packets);
627 BCMOLT_MSG_FIELD_GET(&gem_stats, tx_bytes);
628
629 /* call API */
630 err = bcmolt_stat_get((bcmolt_oltid)device_id, &gem_stats.hdr, clear_on_read);
631 if (err == BCM_ERR_OK) {
632 gemport_stats->set_rx_packets(gem_stats.data.rx_packets);
633 gemport_stats->set_rx_bytes(gem_stats.data.rx_bytes);
634 gemport_stats->set_tx_packets(gem_stats.data.tx_packets);
635 gemport_stats->set_tx_bytes(gem_stats.data.tx_bytes);
636 } else {
637 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve GEMPORT statistics, intf_id %d, gemport_id %d, err no: %d - %s\n",
638 (int)intf_id, (int)gemport_id, err, bcmos_strerror(err));
639 return err;
640 }
641 }
642
643 gemport_stats->set_intf_id(intf_id);
644 gemport_stats->set_gemport_id(gemport_id);
645 time_t now;
646 time(&now);
647 gemport_stats->set_timestamp((int)now);
648#endif
649
650 return err;
651}
652
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530653bcmos_errno set_collect_alloc_stats(bcmolt_interface_id intf_id, bcmolt_alloc_id alloc_id, bcmos_bool collect_stats) {
654 bcmos_errno err = BCM_ERR_OK;
655 bcmolt_itupon_alloc_cfg cfg;
656 bcmolt_itupon_alloc_key key;
657 key.pon_ni = intf_id;
658 key.alloc_id = alloc_id;
659
660 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
661 BCMOLT_FIELD_SET(&cfg.data, itupon_alloc_cfg_data, collect_stats, collect_stats);
662 err = bcmolt_cfg_set((bcmolt_oltid)device_id, &cfg.hdr);
663 return err;
664}
665
666bcmos_errno get_alloc_statistics(bcmolt_interface_id intf_id, bcmolt_alloc_id alloc_id, openolt::OnuAllocIdStatistics* allocid_stats) {
667 bcmos_errno err = BCM_ERR_OK;
668
669#ifndef TEST_MODE
670
671 bcmos_errno err1 = BCM_ERR_OK;
672 err1 = set_collect_alloc_stats(intf_id, alloc_id, BCMOS_TRUE);
673 if (err1 == BCM_ERR_OK) {
674 *allocid_stats = get_default_alloc_statistics();
675 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
676 bcmolt_itupon_alloc_stats alloc_stats;
677 bcmolt_itupon_alloc_key key;
678 key.pon_ni = intf_id;
679 key.alloc_id = alloc_id;
680
681 // Wait to collect alloc stats after enabling it
682 sleep(ALLOC_STATS_GET_INTERVAL);
683
684 BCMOLT_STAT_INIT(&alloc_stats, itupon_alloc, stats, key);
685 BCMOLT_MSG_FIELD_GET(&alloc_stats, rx_bytes);
686
687 /* call API */
688 err = bcmolt_stat_get((bcmolt_oltid)device_id, &alloc_stats.hdr, clear_on_read);
689 if (err == BCM_ERR_OK) {
690 allocid_stats->set_rxbytes(alloc_stats.data.rx_bytes);
691 allocid_stats->set_intfid(intf_id);
692 allocid_stats->set_allocid(alloc_id);
693 } else {
694 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ALLOC_ID statistics, intf_id %d, alloc_id %d, err no: %d - %s\n",
695 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
696 err1 = set_collect_alloc_stats(intf_id, alloc_id, BCMOS_FALSE);
697 if (err1 != BCM_ERR_OK) {
698 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",
699 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
700 }
701 return err;
702 }
703 } else {
704 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",
705 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
706 return err1;
707 }
708
709 err1 = set_collect_alloc_stats(intf_id, alloc_id, BCMOS_FALSE);
710 if (err1 != BCM_ERR_OK) {
711 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",
712 (int)intf_id, (int)alloc_id, err, bcmos_strerror(err));
713 return err1;
714 }
715
716#endif
717
718 return err;
719}
720
Shad Ansaricb004c52018-05-30 18:07:23 +0000721#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400722openolt::FlowStatistics* collectFlowStatistics(bcmbal_flow_id flow_id, bcmbal_flow_type flow_type) {
723
724 bcmos_errno err;
725 bcmbal_flow_stat stat; /**< declare main API struct */
726 bcmbal_flow_key key = { }; /**< declare key */
727 bcmos_bool clear_on_read = false;
728
729 openolt::FlowStatistics* flow_stats = get_default_flow_statistics();
730 //Key
731 key.flow_id = flow_id;
732 key.flow_type = flow_type;
733
734 /* init the API struct */
735 BCMBAL_STAT_INIT(&stat, flow, key);
736 BCMBAL_STAT_PROP_GET(&stat, flow, all_properties);
737
738 err = bcmbal_stat_get(DEFAULT_ATERM_ID, &stat.hdr, clear_on_read);
739
740 if (err == BCM_ERR_OK)
741 {
742 std::cout << "Flow statistics retrieved"
743 << " flow_id:" << flow_id
744 << " flow_type:" << flow_type << std::endl;
745
746 flow_stats->set_rx_bytes(stat.data.rx_bytes);
747 flow_stats->set_rx_packets(stat.data.rx_packets);
748 flow_stats->set_tx_bytes(stat.data.tx_bytes);
749 flow_stats->set_tx_packets(stat.data.tx_packets);
750
751 } else {
752 std::cout << "ERROR: Failed to retrieve flow statistics"
753 << " flow_id:" << flow_id
754 << " flow_type:" << flow_type << std::endl;
755 }
756
757 return flow_stats;
758}
Shad Ansaricb004c52018-05-30 18:07:23 +0000759#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400760
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400761void stats_collection() {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400762
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400763 if (!state.is_connected()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000764 OPENOLT_LOG(INFO, openolt_log_id, "Voltha is not connected, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400765 return;
766 }
767 if (!state.is_activated()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000768 OPENOLT_LOG(INFO, openolt_log_id, "The OLT is not up, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400769 return;
770 }
771
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000772 OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n");
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400773
Shad Ansariedef2132018-08-10 22:14:50 +0000774 //Ports statistics
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400775
Shad Ansariedef2132018-08-10 22:14:50 +0000776 //Uplink ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500777 for (int i = 0; i < NumNniIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000778 bcmolt_intf_ref intf_ref;
779 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI;
780 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400781
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530782 common::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000783 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400784
Girish Gowdra252f4972020-09-07 21:24:01 -0700785 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000786 ind.set_allocated_port_stats(port_stats);
787 oltIndQ.push(ind);
788 }
789 //Pon ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500790 for (int i = 0; i < NumPonIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000791 bcmolt_intf_ref intf_ref;
792 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON;
793 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400794
Akash Reddy Kankanaladec6e7e2025-05-22 09:49:28 +0530795 common::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000796 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400797
Girish Gowdra252f4972020-09-07 21:24:01 -0700798 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000799 ind.set_allocated_port_stats(port_stats);
800 oltIndQ.push(ind);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400801 }
802
Shad Ansariedef2132018-08-10 22:14:50 +0000803 //Flows statistics
804 // flow_inst *current_entry = NULL;
805 //
806 // TAILQ_FOREACH(current_entry,
807 // &FLOW_FSM_FLOW_LIST_CTX_PTR->active_flow_list,
808 // flow_inst_next) {
809 // int flows_measurements = 0;
810 //
811 // for (int i = 0; i < FLOWS_COUNT; i++) {
812 //
813 // // bcmbal_flow_id flow_id = current_entry->api_req_flow_info.key.flow_id;
814 // // bcmbal_flow_type flow_type = current_entry->api_req_flow_info.key.flow_type;
815 //
816 // if (flows_keys[i].flow_id != 0) {
817 // openolt::FlowStatistics* flow_stats = collectFlowStatistics(flows_keys[i].flow_id, flows_keys[i].flow_type);
818 // if (flow_stats->rx_packets() == -1) {
819 // //It Failed
820 // flows_keys[i].flow_id = 0;
821 // } else {
822 // flow_stats->set_flow_id(flows_keys[i].flow_id);
823 // time(&now);
824 // flow_stats->set_timestamp((int)now);
825 // openolt::Indication ind;
826 // ind.set_allocated_flow_stats(flow_stats);
827 // oltIndQ.push(ind);
828 // flows_measurements ++;
829 // }
830 // }
831 //
832 // }
833 // std::cout << "Stats of " << flows_measurements << " flows retrieved" << std::endl;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400834
835}
836
837/* Storing flow keys, temporary */
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400838// void register_new_flow(bcmbal_flow_key key) {
839// for (int i = 0; i < FLOWS_COUNT; i++) {
840// if (flows_keys[i].flow_id == 0) {
841// flows_keys[i] = key;
842// break;
843// }
844// }
845// }