| Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 1 | /* |
| Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
| Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 3 | |
| Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 4 | * 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 Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 7 | |
| Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Zack Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 9 | |
| Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 10 | * 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 Williams | 477ba09 | 2018-10-17 10:50:06 -0700 | [diff] [blame] | 16 | |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 17 | #include "stats_collection.h" |
| 18 | |
| 19 | #include <unistd.h> |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 20 | |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 21 | #include "indications.h" |
| Nicolas Palpacuer | c09fdb7 | 2018-08-22 10:23:22 -0400 | [diff] [blame] | 22 | #include "core.h" |
| Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 23 | #include "core_data.h" |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 24 | #include "translation.h" |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 25 | |
| 26 | extern "C" |
| 27 | { |
| 28 | #include <bcmos_system.h> |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 29 | #include <bcmolt_api.h> |
| 30 | #include <bcmolt_api_model_api_structs.h> |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 31 | } |
| 32 | |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 33 | //FIXME |
| 34 | #define FLOWS_COUNT 100 |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 35 | #define ALLOC_STATS_GET_INTERVAL 10 |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 36 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 37 | bcmolt_flow_key* flows_keys = new bcmolt_flow_key[FLOWS_COUNT]; |
| Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 38 | bcmolt_odid device_id = 0; |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 39 | |
| Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 40 | void init_stats() { |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 41 | memset(flows_keys, 0, FLOWS_COUNT * sizeof(bcmolt_flow_key)); |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 44 | common::PortStatistics* get_default_port_statistics() { |
| 45 | common::PortStatistics* port_stats = new common::PortStatistics; |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 46 | 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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 53 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 65 | 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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 71 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 82 | port_stats->set_bip_errors(-1); |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 83 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 107 | |
| 108 | return port_stats; |
| 109 | } |
| 110 | |
| Burak Gurdag | 74e3ab8 | 2020-12-17 13:35:06 +0000 | [diff] [blame] | 111 | openolt::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 | |
| 141 | openolt::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 Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 154 | openolt::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 Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 164 | #if 0 |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 165 | openolt::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 Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 175 | #endif |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 176 | |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 177 | common::PortStatistics* collectPortStatistics(bcmolt_intf_ref intf_ref) { |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 178 | |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 179 | common::PortStatistics* port_stats = get_default_port_statistics(); |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 180 | #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 Gowdra | fc10f0d | 2020-11-30 13:06:35 -0800 | [diff] [blame] | 184 | bcmolt_onu_itu_pon_stats pon_stats; |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 185 | bcmolt_pon_interface_itu_pon_stats itu_pon_stats; |
| Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 186 | bcmolt_internal_nni_enet_stats enet_stat; |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 187 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 188 | 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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 201 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 212 | 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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 218 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 228 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 229 | /* 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 235 | port_stats->set_rx_bytes(nni_stats.data.rx_bytes); |
| akashreddyk | 763899a | 2026-02-05 10:04:28 +0530 | [diff] [blame^] | 236 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 241 | port_stats->set_tx_bytes(nni_stats.data.tx_bytes); |
| akashreddyk | 763899a | 2026-02-05 10:04:28 +0530 | [diff] [blame^] | 242 | 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 Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 247 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 248 | } else { |
| Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 249 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 251 | } |
| 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 262 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 263 | /* 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 Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 270 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 272 | } |
| Girish Gowdra | fc10f0d | 2020-11-30 13:06:35 -0800 | [diff] [blame] | 273 | #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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 294 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 295 | { |
| Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 296 | bcmolt_internal_nni_key key = {}; |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 297 | key.pon_ni = (bcmolt_interface)intf_ref.intf_id; |
| Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 298 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 323 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 324 | /* call API */ |
| Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 325 | err = bcmolt_stat_get((bcmolt_oltid)device_id, &enet_stat.hdr, clear_on_read); |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 326 | if (err == BCM_ERR_OK) { |
| Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 327 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 352 | } else { |
| Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 353 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
| Girish Gowdra | fc10f0d | 2020-11-30 13:06:35 -0800 | [diff] [blame] | 357 | #endif |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 358 | break; |
| 359 | } |
| Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 360 | } |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 361 | |
| 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 Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 363 | time_t now; |
| 364 | time(&now); |
| 365 | port_stats->set_timestamp((int)now); |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 366 | #endif |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 367 | return port_stats; |
| 368 | |
| 369 | } |
| 370 | |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 371 | bcmos_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); |
| akashreddyk | bb9b4db | 2025-12-22 14:19:30 +0530 | [diff] [blame] | 433 | 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 Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 438 | 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); |
| akashreddyk | bb9b4db | 2025-12-22 14:19:30 +0530 | [diff] [blame] | 442 | 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 Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 447 | 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 Gurdag | 74e3ab8 | 2020-12-17 13:35:06 +0000 | [diff] [blame] | 529 | bcmos_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 | |
| 609 | bcmos_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 Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 652 | bcmos_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 | |
| 665 | bcmos_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 Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 720 | #if 0 |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 721 | openolt::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 Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 758 | #endif |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 759 | |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 760 | void stats_collection() { |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 761 | |
| Nicolas Palpacuer | c09fdb7 | 2018-08-22 10:23:22 -0400 | [diff] [blame] | 762 | if (!state.is_connected()) { |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 763 | OPENOLT_LOG(INFO, openolt_log_id, "Voltha is not connected, do not collect stats\n"); |
| Nicolas Palpacuer | c09fdb7 | 2018-08-22 10:23:22 -0400 | [diff] [blame] | 764 | return; |
| 765 | } |
| 766 | if (!state.is_activated()) { |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 767 | OPENOLT_LOG(INFO, openolt_log_id, "The OLT is not up, do not collect stats\n"); |
| Nicolas Palpacuer | c09fdb7 | 2018-08-22 10:23:22 -0400 | [diff] [blame] | 768 | return; |
| 769 | } |
| 770 | |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 771 | OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n"); |
| Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 772 | |
| Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 773 | //Ports statistics |
| Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 774 | |
| Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 775 | //Uplink ports |
| Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 776 | for (int i = 0; i < NumNniIf_(); i++) { |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 777 | bcmolt_intf_ref intf_ref; |
| 778 | intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI; |
| 779 | intf_ref.intf_id = i; |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 780 | |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 781 | common::PortStatistics* port_stats = |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 782 | collectPortStatistics(intf_ref); |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 783 | |
| Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 784 | ::openolt::Indication ind; |
| Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 785 | ind.set_allocated_port_stats(port_stats); |
| 786 | oltIndQ.push(ind); |
| 787 | } |
| 788 | //Pon ports |
| Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 789 | for (int i = 0; i < NumPonIf_(); i++) { |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 790 | bcmolt_intf_ref intf_ref; |
| 791 | intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON; |
| 792 | intf_ref.intf_id = i; |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 793 | |
| Akash Reddy Kankanala | dec6e7e | 2025-05-22 09:49:28 +0530 | [diff] [blame] | 794 | common::PortStatistics* port_stats = |
| Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 795 | collectPortStatistics(intf_ref); |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 796 | |
| Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 797 | ::openolt::Indication ind; |
| Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 798 | ind.set_allocated_port_stats(port_stats); |
| 799 | oltIndQ.push(ind); |
| Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 800 | } |
| 801 | |
| Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 802 | //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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 833 | |
| 834 | } |
| 835 | |
| 836 | /* Storing flow keys, temporary */ |
| Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 837 | // 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 | // } |