blob: 5065f6b6229e62cc393d949046d87bd23d9d9edf [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
Burak Gurdag74e3ab82020-12-17 13:35:06 +000086openolt::OnuStatistics get_default_onu_statistics() {
87 openolt::OnuStatistics onu_stats;
88
89 onu_stats.set_positive_drift(-1);
90 onu_stats.set_negative_drift(-1);
91 onu_stats.set_delimiter_miss_detection(-1);
92 onu_stats.set_bip_errors(-1);
93 onu_stats.set_bip_units(-1);
94 onu_stats.set_fec_corrected_symbols(-1);
95 onu_stats.set_fec_codewords_corrected(-1);
96 onu_stats.set_fec_codewords_uncorrectable(-1);
97 onu_stats.set_fec_codewords(-1);
98 onu_stats.set_fec_corrected_units(-1);
99 onu_stats.set_xgem_key_errors(-1);
100 onu_stats.set_xgem_loss(-1);
101 onu_stats.set_rx_ploams_error(-1);
102 onu_stats.set_rx_ploams_non_idle(-1);
103 onu_stats.set_rx_omci(-1);
104 onu_stats.set_rx_omci_packets_crc_error(-1);
105 onu_stats.set_rx_bytes(-1);
106 onu_stats.set_rx_packets(-1);
107 onu_stats.set_tx_bytes(-1);
108 onu_stats.set_tx_packets(-1);
109 onu_stats.set_ber_reported(-1);
110 onu_stats.set_lcdg_errors(-1);
111 onu_stats.set_rdi_errors(-1);
112
113 return onu_stats;
114}
115
116openolt::GemPortStatistics get_default_gemport_statistics() {
117 openolt::GemPortStatistics gemport_stats;
118
119 gemport_stats.set_intf_id(-1);
120 gemport_stats.set_gemport_id(-1);
121 gemport_stats.set_rx_packets(-1);
122 gemport_stats.set_rx_bytes(-1);
123 gemport_stats.set_tx_packets(-1);
124 gemport_stats.set_tx_bytes(-1);
125
126 return gemport_stats;
127}
128
Shad Ansaricb004c52018-05-30 18:07:23 +0000129#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400130openolt::FlowStatistics* get_default_flow_statistics() {
131 openolt::FlowStatistics* flow_stats = new openolt::FlowStatistics;
132 flow_stats->set_flow_id(-1);
133 flow_stats->set_rx_bytes(-1);
134 flow_stats->set_rx_packets(-1);
135 flow_stats->set_tx_bytes(-1);
136 flow_stats->set_tx_packets(-1);
137
138 return flow_stats;
139}
Shad Ansaricb004c52018-05-30 18:07:23 +0000140#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400141
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000142openolt::PortStatistics* collectPortStatistics(bcmolt_intf_ref intf_ref) {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400143
144 openolt::PortStatistics* port_stats = get_default_port_statistics();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000145#ifndef TEST_MODE
146 bcmos_errno err;
147 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
148 bcmolt_nni_interface_stats nni_stats;
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800149 bcmolt_onu_itu_pon_stats pon_stats;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000150 bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
Jason Huang2d9382f2020-10-21 17:52:05 +0800151 bcmolt_internal_nni_enet_stats enet_stat;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400152
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000153 switch (intf_ref.intf_type) {
154 case BCMOLT_INTERFACE_TYPE_NNI:
155 {
156 bcmolt_nni_interface_key nni_intf_key;
157 nni_intf_key.id = intf_ref.intf_id;
158 /* init the API struct */
159 BCMOLT_STAT_INIT(&nni_stats, nni_interface, stats, nni_intf_key);
160 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bytes);
161 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_packets);
162 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_ucast_packets);
163 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_mcast_packets);
164 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bcast_packets);
165 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_error_packets);
Jason Huang2d9382f2020-10-21 17:52:05 +0800166 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_64);
167 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_65_127);
168 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_128_255);
169 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_256_511);
170 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_512_1023);
171 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1024_1518);
172 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1519_2047);
173 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_2048_4095);
174 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_4096_9216);
175 BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_9217_16383);
176
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000177 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bytes);
178 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_packets);
179 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_ucast_packets);
180 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_mcast_packets);
181 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bcast_packets);
182 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_error_packets);
Jason Huang2d9382f2020-10-21 17:52:05 +0800183 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_64);
184 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_65_127);
185 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_128_255);
186 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_256_511);
187 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_512_1023);
188 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1024_1518);
189 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1519_2047);
190 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_2048_4095);
191 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_4096_9216);
192 BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400193
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000194 /* call API */
195 err = bcmolt_stat_get((bcmolt_oltid)device_id, &nni_stats.hdr, clear_on_read);
196 if (err == BCM_ERR_OK)
197 {
198 //std::cout << "Interface statistics retrieved"
199 // << " intf_id:" << intf_id << std::endl;
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800200
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000201 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
202 port_stats->set_rx_packets(nni_stats.data.rx_packets);
203 port_stats->set_rx_ucast_packets(nni_stats.data.rx_ucast_packets);
204 port_stats->set_rx_mcast_packets(nni_stats.data.rx_mcast_packets);
205 port_stats->set_rx_bcast_packets(nni_stats.data.rx_bcast_packets);
206 port_stats->set_rx_error_packets(nni_stats.data.rx_error_packets);
207 port_stats->set_tx_bytes(nni_stats.data.tx_bytes);
208 port_stats->set_tx_packets(nni_stats.data.tx_packets);
209 port_stats->set_tx_ucast_packets(nni_stats.data.tx_ucast_packets);
210 port_stats->set_tx_mcast_packets(nni_stats.data.tx_mcast_packets);
211 port_stats->set_tx_bcast_packets(nni_stats.data.tx_bcast_packets);
212 port_stats->set_tx_error_packets(nni_stats.data.tx_error_packets);
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800213
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000214 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500215 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
216 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000217 }
218 break;
219 }
220 case BCMOLT_INTERFACE_TYPE_PON:
221 {
222 bcmolt_pon_interface_key key;
223 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
224 BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key);
225 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets);
226 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors);
227 BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error);
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, &itu_pon_stats.hdr, clear_on_read);
231 if (err == BCM_ERR_OK) {
232 port_stats->set_tx_packets(itu_pon_stats.data.tx_packets);
233 port_stats->set_bip_errors(itu_pon_stats.data.bip_errors);
234 port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error);
235 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500236 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
237 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000238 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800239#if 1 // Shall be fixed as part of VOL-3691. When fixed, the #else code block should be enabled.
240 {
241 bcmolt_onu_key key;
242 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
243 BCMOLT_STAT_INIT(&pon_stats, onu, itu_pon_stats, key);
244 BCMOLT_MSG_FIELD_GET(&pon_stats, rx_bytes);
245 BCMOLT_MSG_FIELD_GET(&pon_stats, rx_packets);
246 BCMOLT_MSG_FIELD_GET(&pon_stats, tx_bytes);
247
248 /* call API */
249 err = bcmolt_stat_get((bcmolt_oltid)device_id, &pon_stats.hdr, clear_on_read);
250 if (err == BCM_ERR_OK) {
251 port_stats->set_rx_bytes(pon_stats.data.rx_bytes);
252 port_stats->set_rx_packets(pon_stats.data.rx_packets);
253 port_stats->set_tx_bytes(pon_stats.data.tx_bytes);
254 } else {
255 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
256 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
257 }
258 }
259#else
Jason Huang2d9382f2020-10-21 17:52:05 +0800260
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000261 {
Jason Huang2d9382f2020-10-21 17:52:05 +0800262 bcmolt_internal_nni_key key = {};
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000263 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
Jason Huang2d9382f2020-10-21 17:52:05 +0800264 BCMOLT_STAT_INIT(&enet_stat, internal_nni, enet_stats, key);
265 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_bytes);
266 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames);
267 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_64);
268 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_65_127);
269 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_128_255);
270 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_256_511);
271 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_512_1023);
272 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1024_1518);
273 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1519_2047);
274 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_2048_4095);
275 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_4096_9216);
276 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_9217_16383);
277 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_bytes);
278 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames);
279 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_64);
280 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_65_127);
281 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_128_255);
282 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_256_511);
283 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_512_1023);
284 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1024_1518);
285 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1519_2047);
286 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_2048_4095);
287 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_4096_9216);
288 BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_9217_16383);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400289
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000290 /* call API */
Jason Huang2d9382f2020-10-21 17:52:05 +0800291 err = bcmolt_stat_get((bcmolt_oltid)device_id, &enet_stat.hdr, clear_on_read);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000292 if (err == BCM_ERR_OK) {
Jason Huang2d9382f2020-10-21 17:52:05 +0800293 port_stats->set_rx_bytes(enet_stat.data.rx_bytes);
294 port_stats->set_rx_packets(enet_stat.data.rx_frames);
295 port_stats->set_rx_packets(enet_stat.data.rx_frames_64);
296 port_stats->set_rx_packets(enet_stat.data.rx_frames_65_127);
297 port_stats->set_rx_packets(enet_stat.data.rx_frames_128_255);
298 port_stats->set_rx_packets(enet_stat.data.rx_frames_256_511);
299 port_stats->set_rx_packets(enet_stat.data.rx_frames_512_1023);
300 port_stats->set_rx_packets(enet_stat.data.rx_frames_1024_1518);
301 port_stats->set_rx_packets(enet_stat.data.rx_frames_1519_2047);
302 port_stats->set_rx_packets(enet_stat.data.rx_frames_2048_4095);
303 port_stats->set_rx_packets(enet_stat.data.rx_frames_4096_9216);
304 port_stats->set_rx_packets(enet_stat.data.rx_frames_9217_16383);
305
306 port_stats->set_tx_bytes(enet_stat.data.tx_bytes);
307 port_stats->set_rx_packets(enet_stat.data.tx_frames);
308 port_stats->set_rx_packets(enet_stat.data.tx_frames_64);
309 port_stats->set_rx_packets(enet_stat.data.tx_frames_65_127);
310 port_stats->set_rx_packets(enet_stat.data.tx_frames_128_255);
311 port_stats->set_rx_packets(enet_stat.data.tx_frames_256_511);
312 port_stats->set_rx_packets(enet_stat.data.tx_frames_512_1023);
313 port_stats->set_rx_packets(enet_stat.data.tx_frames_1024_1518);
314 port_stats->set_rx_packets(enet_stat.data.tx_frames_1519_2047);
315 port_stats->set_rx_packets(enet_stat.data.tx_frames_2048_4095);
316 port_stats->set_rx_packets(enet_stat.data.tx_frames_4096_9216);
317 port_stats->set_rx_packets(enet_stat.data.tx_frames_9217_16383);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000318 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500319 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
320 (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000321 }
322 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800323#endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000324 break;
325 }
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800326 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000327
328 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 -0400329 time_t now;
330 time(&now);
331 port_stats->set_timestamp((int)now);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000332#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400333 return port_stats;
334
335}
336
Burak Gurdag74e3ab82020-12-17 13:35:06 +0000337bcmos_errno get_onu_statistics(bcmolt_interface_id intf_id, bcmolt_onu_id onu_id, openolt::OnuStatistics* onu_stats) {
338 bcmos_errno err = BCM_ERR_OK;
339
340#ifndef TEST_MODE
341 *onu_stats = get_default_onu_statistics();
342 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
343 bcmolt_onu_itu_pon_stats itu_onu_stats;
344
345 {
346 bcmolt_onu_key key;
347 key.pon_ni = intf_id;
348 key.onu_id = onu_id;
349 BCMOLT_STAT_INIT(&itu_onu_stats, onu, itu_pon_stats, key);
350 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, positive_drift);
351 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, negative_drift);
352 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, delimiter_miss_detection);
353 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, bip_errors);
354 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, bip_units);
355 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_corrected_symbols);
356 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords_corrected);
357 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords_uncorrectable);
358 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_codewords);
359 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, fec_corrected_units);
360 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, xgem_key_errors);
361 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, xgem_loss);
362 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_ploams_error);
363 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_ploams_non_idle);
364 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_omci);
365 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_omci_packets_crc_error);
366 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_bytes);
367 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rx_packets);
368 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, tx_bytes);
369 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, tx_packets);
370 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, ber_reported);
371 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, lcdg_errors);
372 BCMOLT_MSG_FIELD_GET(&itu_onu_stats, rdi_errors);
373
374 /* call API */
375 err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_onu_stats.hdr, clear_on_read);
376 if (err == BCM_ERR_OK) {
377 onu_stats->set_positive_drift(itu_onu_stats.data.positive_drift);
378 onu_stats->set_negative_drift(itu_onu_stats.data.negative_drift);
379 onu_stats->set_delimiter_miss_detection(itu_onu_stats.data.delimiter_miss_detection);
380 onu_stats->set_bip_errors(itu_onu_stats.data.bip_errors);
381 onu_stats->set_bip_units(itu_onu_stats.data.bip_units);
382 onu_stats->set_fec_corrected_symbols(itu_onu_stats.data.fec_corrected_symbols);
383 onu_stats->set_fec_codewords_corrected(itu_onu_stats.data.fec_codewords_corrected);
384 onu_stats->set_fec_codewords_uncorrectable(itu_onu_stats.data.fec_codewords_uncorrectable);
385 onu_stats->set_fec_codewords(itu_onu_stats.data.fec_codewords);
386 onu_stats->set_fec_corrected_units(itu_onu_stats.data.fec_corrected_units);
387 onu_stats->set_xgem_key_errors(itu_onu_stats.data.xgem_key_errors);
388 onu_stats->set_xgem_loss(itu_onu_stats.data.xgem_loss);
389 onu_stats->set_rx_ploams_error(itu_onu_stats.data.rx_ploams_error);
390 onu_stats->set_rx_ploams_non_idle(itu_onu_stats.data.rx_ploams_non_idle);
391 onu_stats->set_rx_omci(itu_onu_stats.data.rx_omci);
392 onu_stats->set_rx_omci_packets_crc_error(itu_onu_stats.data.rx_omci_packets_crc_error);
393 onu_stats->set_rx_bytes(itu_onu_stats.data.rx_bytes);
394 onu_stats->set_rx_packets(itu_onu_stats.data.rx_packets);
395 onu_stats->set_tx_bytes(itu_onu_stats.data.tx_bytes);
396 onu_stats->set_tx_packets(itu_onu_stats.data.tx_packets);
397 onu_stats->set_ber_reported(itu_onu_stats.data.ber_reported);
398 onu_stats->set_lcdg_errors(itu_onu_stats.data.lcdg_errors);
399 onu_stats->set_rdi_errors(itu_onu_stats.data.rdi_errors);
400 } else {
401 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ONU statistics, intf_id %d, onu_id %d, err no: %d - %s\n",
402 (int)intf_id, (int)onu_id, err, bcmos_strerror(err));
403 return err;
404 }
405 }
406
407 onu_stats->set_intf_id(intf_id);
408 onu_stats->set_onu_id(onu_id);
409 time_t now;
410 time(&now);
411 onu_stats->set_timestamp((int)now);
412#endif
413
414 return err;
415}
416
417bcmos_errno get_gemport_statistics(bcmolt_interface_id intf_id, bcmolt_gem_port_id gemport_id, openolt::GemPortStatistics* gemport_stats) {
418 bcmos_errno err = BCM_ERR_OK;
419
420#ifndef TEST_MODE
421 *gemport_stats = get_default_gemport_statistics();
422 bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE;
423 bcmolt_itupon_gem_stats gem_stats;
424
425 {
426 bcmolt_itupon_gem_key key;
427 key.pon_ni = intf_id;
428 key.gem_port_id = gemport_id;
429
430 BCMOLT_STAT_INIT(&gem_stats, itupon_gem, stats, key);
431 BCMOLT_MSG_FIELD_GET(&gem_stats, rx_packets);
432 BCMOLT_MSG_FIELD_GET(&gem_stats, rx_bytes);
433 BCMOLT_MSG_FIELD_GET(&gem_stats, tx_packets);
434 BCMOLT_MSG_FIELD_GET(&gem_stats, tx_bytes);
435
436 /* call API */
437 err = bcmolt_stat_get((bcmolt_oltid)device_id, &gem_stats.hdr, clear_on_read);
438 if (err == BCM_ERR_OK) {
439 gemport_stats->set_rx_packets(gem_stats.data.rx_packets);
440 gemport_stats->set_rx_bytes(gem_stats.data.rx_bytes);
441 gemport_stats->set_tx_packets(gem_stats.data.tx_packets);
442 gemport_stats->set_tx_bytes(gem_stats.data.tx_bytes);
443 } else {
444 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve GEMPORT statistics, intf_id %d, gemport_id %d, err no: %d - %s\n",
445 (int)intf_id, (int)gemport_id, err, bcmos_strerror(err));
446 return err;
447 }
448 }
449
450 gemport_stats->set_intf_id(intf_id);
451 gemport_stats->set_gemport_id(gemport_id);
452 time_t now;
453 time(&now);
454 gemport_stats->set_timestamp((int)now);
455#endif
456
457 return err;
458}
459
Shad Ansaricb004c52018-05-30 18:07:23 +0000460#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400461openolt::FlowStatistics* collectFlowStatistics(bcmbal_flow_id flow_id, bcmbal_flow_type flow_type) {
462
463 bcmos_errno err;
464 bcmbal_flow_stat stat; /**< declare main API struct */
465 bcmbal_flow_key key = { }; /**< declare key */
466 bcmos_bool clear_on_read = false;
467
468 openolt::FlowStatistics* flow_stats = get_default_flow_statistics();
469 //Key
470 key.flow_id = flow_id;
471 key.flow_type = flow_type;
472
473 /* init the API struct */
474 BCMBAL_STAT_INIT(&stat, flow, key);
475 BCMBAL_STAT_PROP_GET(&stat, flow, all_properties);
476
477 err = bcmbal_stat_get(DEFAULT_ATERM_ID, &stat.hdr, clear_on_read);
478
479 if (err == BCM_ERR_OK)
480 {
481 std::cout << "Flow statistics retrieved"
482 << " flow_id:" << flow_id
483 << " flow_type:" << flow_type << std::endl;
484
485 flow_stats->set_rx_bytes(stat.data.rx_bytes);
486 flow_stats->set_rx_packets(stat.data.rx_packets);
487 flow_stats->set_tx_bytes(stat.data.tx_bytes);
488 flow_stats->set_tx_packets(stat.data.tx_packets);
489
490 } else {
491 std::cout << "ERROR: Failed to retrieve flow statistics"
492 << " flow_id:" << flow_id
493 << " flow_type:" << flow_type << std::endl;
494 }
495
496 return flow_stats;
497}
Shad Ansaricb004c52018-05-30 18:07:23 +0000498#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400499
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400500void stats_collection() {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400501
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400502 if (!state.is_connected()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000503 OPENOLT_LOG(INFO, openolt_log_id, "Voltha is not connected, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400504 return;
505 }
506 if (!state.is_activated()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000507 OPENOLT_LOG(INFO, openolt_log_id, "The OLT is not up, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400508 return;
509 }
510
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000511 OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n");
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400512
Shad Ansariedef2132018-08-10 22:14:50 +0000513 //Ports statistics
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400514
Shad Ansariedef2132018-08-10 22:14:50 +0000515 //Uplink ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500516 for (int i = 0; i < NumNniIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000517 bcmolt_intf_ref intf_ref;
518 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI;
519 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400520
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000521 openolt::PortStatistics* port_stats =
522 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400523
Girish Gowdra252f4972020-09-07 21:24:01 -0700524 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000525 ind.set_allocated_port_stats(port_stats);
526 oltIndQ.push(ind);
527 }
528 //Pon ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500529 for (int i = 0; i < NumPonIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000530 bcmolt_intf_ref intf_ref;
531 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON;
532 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400533
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800534 openolt::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000535 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400536
Girish Gowdra252f4972020-09-07 21:24:01 -0700537 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000538 ind.set_allocated_port_stats(port_stats);
539 oltIndQ.push(ind);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400540 }
541
Shad Ansariedef2132018-08-10 22:14:50 +0000542 //Flows statistics
543 // flow_inst *current_entry = NULL;
544 //
545 // TAILQ_FOREACH(current_entry,
546 // &FLOW_FSM_FLOW_LIST_CTX_PTR->active_flow_list,
547 // flow_inst_next) {
548 // int flows_measurements = 0;
549 //
550 // for (int i = 0; i < FLOWS_COUNT; i++) {
551 //
552 // // bcmbal_flow_id flow_id = current_entry->api_req_flow_info.key.flow_id;
553 // // bcmbal_flow_type flow_type = current_entry->api_req_flow_info.key.flow_type;
554 //
555 // if (flows_keys[i].flow_id != 0) {
556 // openolt::FlowStatistics* flow_stats = collectFlowStatistics(flows_keys[i].flow_id, flows_keys[i].flow_type);
557 // if (flow_stats->rx_packets() == -1) {
558 // //It Failed
559 // flows_keys[i].flow_id = 0;
560 // } else {
561 // flow_stats->set_flow_id(flows_keys[i].flow_id);
562 // time(&now);
563 // flow_stats->set_timestamp((int)now);
564 // openolt::Indication ind;
565 // ind.set_allocated_flow_stats(flow_stats);
566 // oltIndQ.push(ind);
567 // flows_measurements ++;
568 // }
569 // }
570 //
571 // }
572 // std::cout << "Stats of " << flows_measurements << " flows retrieved" << std::endl;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400573
574}
575
576/* Storing flow keys, temporary */
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400577// void register_new_flow(bcmbal_flow_key key) {
578// for (int i = 0; i < FLOWS_COUNT; i++) {
579// if (flows_keys[i].flow_id == 0) {
580// flows_keys[i] = key;
581// break;
582// }
583// }
584// }