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