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 |
| 35 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 36 | bcmolt_flow_key* flows_keys = new bcmolt_flow_key[FLOWS_COUNT]; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 37 | bcmolt_odid device_id = 0; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 38 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 39 | void init_stats() { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 40 | memset(flows_keys, 0, FLOWS_COUNT * sizeof(bcmolt_flow_key)); |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | openolt::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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 52 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 64 | 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 Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 70 | 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 Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 81 | port_stats->set_bip_errors(-1); |
| 82 | |
| 83 | return port_stats; |
| 84 | } |
| 85 | |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 86 | #if 0 |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 87 | openolt::FlowStatistics* get_default_flow_statistics() { |
| 88 | openolt::FlowStatistics* flow_stats = new openolt::FlowStatistics; |
| 89 | flow_stats->set_flow_id(-1); |
| 90 | flow_stats->set_rx_bytes(-1); |
| 91 | flow_stats->set_rx_packets(-1); |
| 92 | flow_stats->set_tx_bytes(-1); |
| 93 | flow_stats->set_tx_packets(-1); |
| 94 | |
| 95 | return flow_stats; |
| 96 | } |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 97 | #endif |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 98 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 99 | openolt::PortStatistics* collectPortStatistics(bcmolt_intf_ref intf_ref) { |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 100 | |
| 101 | openolt::PortStatistics* port_stats = get_default_port_statistics(); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 102 | #ifndef TEST_MODE |
| 103 | bcmos_errno err; |
| 104 | bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE; |
| 105 | bcmolt_nni_interface_stats nni_stats; |
Girish Gowdra | fc10f0d | 2020-11-30 13:06:35 -0800 | [diff] [blame] | 106 | bcmolt_onu_itu_pon_stats pon_stats; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 107 | bcmolt_pon_interface_itu_pon_stats itu_pon_stats; |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 108 | bcmolt_internal_nni_enet_stats enet_stat; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 109 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 110 | switch (intf_ref.intf_type) { |
| 111 | case BCMOLT_INTERFACE_TYPE_NNI: |
| 112 | { |
| 113 | bcmolt_nni_interface_key nni_intf_key; |
| 114 | nni_intf_key.id = intf_ref.intf_id; |
| 115 | /* init the API struct */ |
| 116 | BCMOLT_STAT_INIT(&nni_stats, nni_interface, stats, nni_intf_key); |
| 117 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bytes); |
| 118 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_packets); |
| 119 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_ucast_packets); |
| 120 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_mcast_packets); |
| 121 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_bcast_packets); |
| 122 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_error_packets); |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 123 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_64); |
| 124 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_65_127); |
| 125 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_128_255); |
| 126 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_256_511); |
| 127 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_512_1023); |
| 128 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1024_1518); |
| 129 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_1519_2047); |
| 130 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_2048_4095); |
| 131 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_4096_9216); |
| 132 | BCMOLT_MSG_FIELD_GET(&nni_stats, rx_frames_9217_16383); |
| 133 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 134 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bytes); |
| 135 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_packets); |
| 136 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_ucast_packets); |
| 137 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_mcast_packets); |
| 138 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_bcast_packets); |
| 139 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_error_packets); |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 140 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_64); |
| 141 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_65_127); |
| 142 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_128_255); |
| 143 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_256_511); |
| 144 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_512_1023); |
| 145 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1024_1518); |
| 146 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_1519_2047); |
| 147 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_2048_4095); |
| 148 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_4096_9216); |
| 149 | BCMOLT_MSG_FIELD_GET(&nni_stats, tx_frames_9217_16383); |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 150 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 151 | /* call API */ |
| 152 | err = bcmolt_stat_get((bcmolt_oltid)device_id, &nni_stats.hdr, clear_on_read); |
| 153 | if (err == BCM_ERR_OK) |
| 154 | { |
| 155 | //std::cout << "Interface statistics retrieved" |
| 156 | // << " intf_id:" << intf_id << std::endl; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 157 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 158 | port_stats->set_rx_bytes(nni_stats.data.rx_bytes); |
| 159 | port_stats->set_rx_packets(nni_stats.data.rx_packets); |
| 160 | port_stats->set_rx_ucast_packets(nni_stats.data.rx_ucast_packets); |
| 161 | port_stats->set_rx_mcast_packets(nni_stats.data.rx_mcast_packets); |
| 162 | port_stats->set_rx_bcast_packets(nni_stats.data.rx_bcast_packets); |
| 163 | port_stats->set_rx_error_packets(nni_stats.data.rx_error_packets); |
| 164 | port_stats->set_tx_bytes(nni_stats.data.tx_bytes); |
| 165 | port_stats->set_tx_packets(nni_stats.data.tx_packets); |
| 166 | port_stats->set_tx_ucast_packets(nni_stats.data.tx_ucast_packets); |
| 167 | port_stats->set_tx_mcast_packets(nni_stats.data.tx_mcast_packets); |
| 168 | port_stats->set_tx_bcast_packets(nni_stats.data.tx_bcast_packets); |
| 169 | port_stats->set_tx_error_packets(nni_stats.data.tx_error_packets); |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 170 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 171 | } else { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 172 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n", |
| 173 | (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] | 174 | } |
| 175 | break; |
| 176 | } |
| 177 | case BCMOLT_INTERFACE_TYPE_PON: |
| 178 | { |
| 179 | bcmolt_pon_interface_key key; |
| 180 | key.pon_ni = (bcmolt_interface)intf_ref.intf_id; |
| 181 | BCMOLT_STAT_INIT(&itu_pon_stats, pon_interface, itu_pon_stats, key); |
| 182 | BCMOLT_MSG_FIELD_GET(&itu_pon_stats, tx_packets); |
| 183 | BCMOLT_MSG_FIELD_GET(&itu_pon_stats, bip_errors); |
| 184 | BCMOLT_MSG_FIELD_GET(&itu_pon_stats, rx_crc_error); |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 185 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 186 | /* call API */ |
| 187 | err = bcmolt_stat_get((bcmolt_oltid)device_id, &itu_pon_stats.hdr, clear_on_read); |
| 188 | if (err == BCM_ERR_OK) { |
| 189 | port_stats->set_tx_packets(itu_pon_stats.data.tx_packets); |
| 190 | port_stats->set_bip_errors(itu_pon_stats.data.bip_errors); |
| 191 | port_stats->set_rx_crc_errors(itu_pon_stats.data.rx_crc_error); |
| 192 | } else { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 193 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n", |
| 194 | (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] | 195 | } |
Girish Gowdra | fc10f0d | 2020-11-30 13:06:35 -0800 | [diff] [blame] | 196 | #if 1 // Shall be fixed as part of VOL-3691. When fixed, the #else code block should be enabled. |
| 197 | { |
| 198 | bcmolt_onu_key key; |
| 199 | key.pon_ni = (bcmolt_interface)intf_ref.intf_id; |
| 200 | BCMOLT_STAT_INIT(&pon_stats, onu, itu_pon_stats, key); |
| 201 | BCMOLT_MSG_FIELD_GET(&pon_stats, rx_bytes); |
| 202 | BCMOLT_MSG_FIELD_GET(&pon_stats, rx_packets); |
| 203 | BCMOLT_MSG_FIELD_GET(&pon_stats, tx_bytes); |
| 204 | |
| 205 | /* call API */ |
| 206 | err = bcmolt_stat_get((bcmolt_oltid)device_id, &pon_stats.hdr, clear_on_read); |
| 207 | if (err == BCM_ERR_OK) { |
| 208 | port_stats->set_rx_bytes(pon_stats.data.rx_bytes); |
| 209 | port_stats->set_rx_packets(pon_stats.data.rx_packets); |
| 210 | port_stats->set_tx_bytes(pon_stats.data.tx_bytes); |
| 211 | } else { |
| 212 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n", |
| 213 | (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err)); |
| 214 | } |
| 215 | } |
| 216 | #else |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 217 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 218 | { |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 219 | bcmolt_internal_nni_key key = {}; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 220 | key.pon_ni = (bcmolt_interface)intf_ref.intf_id; |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 221 | BCMOLT_STAT_INIT(&enet_stat, internal_nni, enet_stats, key); |
| 222 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_bytes); |
| 223 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames); |
| 224 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_64); |
| 225 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_65_127); |
| 226 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_128_255); |
| 227 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_256_511); |
| 228 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_512_1023); |
| 229 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1024_1518); |
| 230 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_1519_2047); |
| 231 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_2048_4095); |
| 232 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_4096_9216); |
| 233 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, rx_frames_9217_16383); |
| 234 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_bytes); |
| 235 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames); |
| 236 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_64); |
| 237 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_65_127); |
| 238 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_128_255); |
| 239 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_256_511); |
| 240 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_512_1023); |
| 241 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1024_1518); |
| 242 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_1519_2047); |
| 243 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_2048_4095); |
| 244 | BCMOLT_FIELD_SET_PRESENT(&enet_stat.data, internal_nni_enet_stats_data, tx_frames_4096_9216); |
| 245 | 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] | 246 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 247 | /* call API */ |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 248 | 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] | 249 | if (err == BCM_ERR_OK) { |
Jason Huang | 2d9382f | 2020-10-21 17:52:05 +0800 | [diff] [blame] | 250 | port_stats->set_rx_bytes(enet_stat.data.rx_bytes); |
| 251 | port_stats->set_rx_packets(enet_stat.data.rx_frames); |
| 252 | port_stats->set_rx_packets(enet_stat.data.rx_frames_64); |
| 253 | port_stats->set_rx_packets(enet_stat.data.rx_frames_65_127); |
| 254 | port_stats->set_rx_packets(enet_stat.data.rx_frames_128_255); |
| 255 | port_stats->set_rx_packets(enet_stat.data.rx_frames_256_511); |
| 256 | port_stats->set_rx_packets(enet_stat.data.rx_frames_512_1023); |
| 257 | port_stats->set_rx_packets(enet_stat.data.rx_frames_1024_1518); |
| 258 | port_stats->set_rx_packets(enet_stat.data.rx_frames_1519_2047); |
| 259 | port_stats->set_rx_packets(enet_stat.data.rx_frames_2048_4095); |
| 260 | port_stats->set_rx_packets(enet_stat.data.rx_frames_4096_9216); |
| 261 | port_stats->set_rx_packets(enet_stat.data.rx_frames_9217_16383); |
| 262 | |
| 263 | port_stats->set_tx_bytes(enet_stat.data.tx_bytes); |
| 264 | port_stats->set_rx_packets(enet_stat.data.tx_frames); |
| 265 | port_stats->set_rx_packets(enet_stat.data.tx_frames_64); |
| 266 | port_stats->set_rx_packets(enet_stat.data.tx_frames_65_127); |
| 267 | port_stats->set_rx_packets(enet_stat.data.tx_frames_128_255); |
| 268 | port_stats->set_rx_packets(enet_stat.data.tx_frames_256_511); |
| 269 | port_stats->set_rx_packets(enet_stat.data.tx_frames_512_1023); |
| 270 | port_stats->set_rx_packets(enet_stat.data.tx_frames_1024_1518); |
| 271 | port_stats->set_rx_packets(enet_stat.data.tx_frames_1519_2047); |
| 272 | port_stats->set_rx_packets(enet_stat.data.tx_frames_2048_4095); |
| 273 | port_stats->set_rx_packets(enet_stat.data.tx_frames_4096_9216); |
| 274 | port_stats->set_rx_packets(enet_stat.data.tx_frames_9217_16383); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 275 | } else { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 276 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n", |
| 277 | (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] | 278 | } |
| 279 | } |
Girish Gowdra | fc10f0d | 2020-11-30 13:06:35 -0800 | [diff] [blame] | 280 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 281 | break; |
| 282 | } |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 283 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 284 | |
| 285 | 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] | 286 | time_t now; |
| 287 | time(&now); |
| 288 | port_stats->set_timestamp((int)now); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 289 | #endif |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 290 | return port_stats; |
| 291 | |
| 292 | } |
| 293 | |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 294 | #if 0 |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 295 | openolt::FlowStatistics* collectFlowStatistics(bcmbal_flow_id flow_id, bcmbal_flow_type flow_type) { |
| 296 | |
| 297 | bcmos_errno err; |
| 298 | bcmbal_flow_stat stat; /**< declare main API struct */ |
| 299 | bcmbal_flow_key key = { }; /**< declare key */ |
| 300 | bcmos_bool clear_on_read = false; |
| 301 | |
| 302 | openolt::FlowStatistics* flow_stats = get_default_flow_statistics(); |
| 303 | //Key |
| 304 | key.flow_id = flow_id; |
| 305 | key.flow_type = flow_type; |
| 306 | |
| 307 | /* init the API struct */ |
| 308 | BCMBAL_STAT_INIT(&stat, flow, key); |
| 309 | BCMBAL_STAT_PROP_GET(&stat, flow, all_properties); |
| 310 | |
| 311 | err = bcmbal_stat_get(DEFAULT_ATERM_ID, &stat.hdr, clear_on_read); |
| 312 | |
| 313 | if (err == BCM_ERR_OK) |
| 314 | { |
| 315 | std::cout << "Flow statistics retrieved" |
| 316 | << " flow_id:" << flow_id |
| 317 | << " flow_type:" << flow_type << std::endl; |
| 318 | |
| 319 | flow_stats->set_rx_bytes(stat.data.rx_bytes); |
| 320 | flow_stats->set_rx_packets(stat.data.rx_packets); |
| 321 | flow_stats->set_tx_bytes(stat.data.tx_bytes); |
| 322 | flow_stats->set_tx_packets(stat.data.tx_packets); |
| 323 | |
| 324 | } else { |
| 325 | std::cout << "ERROR: Failed to retrieve flow statistics" |
| 326 | << " flow_id:" << flow_id |
| 327 | << " flow_type:" << flow_type << std::endl; |
| 328 | } |
| 329 | |
| 330 | return flow_stats; |
| 331 | } |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 332 | #endif |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 333 | |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 334 | void stats_collection() { |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 335 | |
Nicolas Palpacuer | c09fdb7 | 2018-08-22 10:23:22 -0400 | [diff] [blame] | 336 | if (!state.is_connected()) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 337 | 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] | 338 | return; |
| 339 | } |
| 340 | if (!state.is_activated()) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 341 | 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] | 342 | return; |
| 343 | } |
| 344 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 345 | OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n"); |
Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 346 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 347 | //Ports statistics |
Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 348 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 349 | //Uplink ports |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 350 | for (int i = 0; i < NumNniIf_(); i++) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 351 | bcmolt_intf_ref intf_ref; |
| 352 | intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI; |
| 353 | intf_ref.intf_id = i; |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 354 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 355 | openolt::PortStatistics* port_stats = |
| 356 | collectPortStatistics(intf_ref); |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 357 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 358 | ::openolt::Indication ind; |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 359 | ind.set_allocated_port_stats(port_stats); |
| 360 | oltIndQ.push(ind); |
| 361 | } |
| 362 | //Pon ports |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 363 | for (int i = 0; i < NumPonIf_(); i++) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 364 | bcmolt_intf_ref intf_ref; |
| 365 | intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON; |
| 366 | intf_ref.intf_id = i; |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 367 | |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 368 | openolt::PortStatistics* port_stats = |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 369 | collectPortStatistics(intf_ref); |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 370 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 371 | ::openolt::Indication ind; |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 372 | ind.set_allocated_port_stats(port_stats); |
| 373 | oltIndQ.push(ind); |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 376 | //Flows statistics |
| 377 | // flow_inst *current_entry = NULL; |
| 378 | // |
| 379 | // TAILQ_FOREACH(current_entry, |
| 380 | // &FLOW_FSM_FLOW_LIST_CTX_PTR->active_flow_list, |
| 381 | // flow_inst_next) { |
| 382 | // int flows_measurements = 0; |
| 383 | // |
| 384 | // for (int i = 0; i < FLOWS_COUNT; i++) { |
| 385 | // |
| 386 | // // bcmbal_flow_id flow_id = current_entry->api_req_flow_info.key.flow_id; |
| 387 | // // bcmbal_flow_type flow_type = current_entry->api_req_flow_info.key.flow_type; |
| 388 | // |
| 389 | // if (flows_keys[i].flow_id != 0) { |
| 390 | // openolt::FlowStatistics* flow_stats = collectFlowStatistics(flows_keys[i].flow_id, flows_keys[i].flow_type); |
| 391 | // if (flow_stats->rx_packets() == -1) { |
| 392 | // //It Failed |
| 393 | // flows_keys[i].flow_id = 0; |
| 394 | // } else { |
| 395 | // flow_stats->set_flow_id(flows_keys[i].flow_id); |
| 396 | // time(&now); |
| 397 | // flow_stats->set_timestamp((int)now); |
| 398 | // openolt::Indication ind; |
| 399 | // ind.set_allocated_flow_stats(flow_stats); |
| 400 | // oltIndQ.push(ind); |
| 401 | // flows_measurements ++; |
| 402 | // } |
| 403 | // } |
| 404 | // |
| 405 | // } |
| 406 | // std::cout << "Stats of " << flows_measurements << " flows retrieved" << std::endl; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 407 | |
| 408 | } |
| 409 | |
| 410 | /* Storing flow keys, temporary */ |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 411 | // void register_new_flow(bcmbal_flow_key key) { |
| 412 | // for (int i = 0; i < FLOWS_COUNT; i++) { |
| 413 | // if (flows_keys[i].flow_id == 0) { |
| 414 | // flows_keys[i] = key; |
| 415 | // break; |
| 416 | // } |
| 417 | // } |
| 418 | // } |