blob: 99747f439ee0368b30a1ff937e617b77822c6a58 [file] [log] [blame]
Zack Williams477ba092018-10-17 10:50:06 -07001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Zack Williams477ba092018-10-17 10:50:06 -07003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Zack Williams477ba092018-10-17 10:50:06 -07007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Zack Williams477ba092018-10-17 10:50:06 -07009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Zack Williams477ba092018-10-17 10:50:06 -070016
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040017#include "stats_collection.h"
18
19#include <unistd.h>
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040020
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040021#include "indications.h"
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -040022#include "core.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053023#include "core_data.h"
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -040024#include "translation.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040025
26extern "C"
27{
28#include <bcmos_system.h>
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000029#include <bcmolt_api.h>
30#include <bcmolt_api_model_api_structs.h>
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040031}
32
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040033//FIXME
34#define FLOWS_COUNT 100
35
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000036bcmolt_flow_key* flows_keys = new bcmolt_flow_key[FLOWS_COUNT];
Jason Huang5d9ab1a2020-04-15 16:53:49 +080037bcmolt_odid device_id = 0;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040038
Shad Ansariedef2132018-08-10 22:14:50 +000039void init_stats() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000040 memset(flows_keys, 0, FLOWS_COUNT * sizeof(bcmolt_flow_key));
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040041}
42
43openolt::PortStatistics* get_default_port_statistics() {
44 openolt::PortStatistics* port_stats = new openolt::PortStatistics;
45 port_stats->set_intf_id(-1);
46 port_stats->set_rx_bytes(-1);
47 port_stats->set_rx_packets(-1);
48 port_stats->set_rx_ucast_packets(-1);
49 port_stats->set_rx_mcast_packets(-1);
50 port_stats->set_rx_bcast_packets(-1);
51 port_stats->set_rx_error_packets(-1);
Jason Huang2d9382f2020-10-21 17:52:05 +080052 port_stats->set_rx_crc_errors(-1);
53 port_stats->set_rx_frames(-1);
54 port_stats->set_rx_frames_64(-1);
55 port_stats->set_rx_frames_65_127(-1);
56 port_stats->set_rx_frames_128_255(-1);
57 port_stats->set_rx_frames_256_511(-1);
58 port_stats->set_rx_frames_512_1023(-1);
59 port_stats->set_rx_frames_1024_1518(-1);
60 port_stats->set_rx_frames_1519_2047(-1);
61 port_stats->set_rx_frames_2048_4095(-1);
62 port_stats->set_rx_frames_4096_9216(-1);
63 port_stats->set_rx_frames_9217_16383(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040064 port_stats->set_tx_bytes(-1);
65 port_stats->set_tx_packets(-1);
66 port_stats->set_tx_ucast_packets(-1);
67 port_stats->set_tx_mcast_packets(-1);
68 port_stats->set_tx_bcast_packets(-1);
69 port_stats->set_tx_error_packets(-1);
Jason Huang2d9382f2020-10-21 17:52:05 +080070 port_stats->set_tx_frames(-1);
71 port_stats->set_tx_frames_64(-1);
72 port_stats->set_tx_frames_65_127(-1);
73 port_stats->set_tx_frames_128_255(-1);
74 port_stats->set_tx_frames_256_511(-1);
75 port_stats->set_tx_frames_512_1023(-1);
76 port_stats->set_tx_frames_1024_1518(-1);
77 port_stats->set_tx_frames_1519_2047(-1);
78 port_stats->set_tx_frames_2048_4095(-1);
79 port_stats->set_tx_frames_4096_9216(-1);
80 port_stats->set_tx_frames_9217_16383(-1);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040081 port_stats->set_bip_errors(-1);
82
83 return port_stats;
84}
85
Shad Ansaricb004c52018-05-30 18:07:23 +000086#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040087openolt::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 Ansaricb004c52018-05-30 18:07:23 +000097#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040098
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000099openolt::PortStatistics* collectPortStatistics(bcmolt_intf_ref intf_ref) {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400100
101 openolt::PortStatistics* port_stats = get_default_port_statistics();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000102#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 Gowdrafc10f0d2020-11-30 13:06:35 -0800106 bcmolt_onu_itu_pon_stats pon_stats;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000107 bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
Jason Huang2d9382f2020-10-21 17:52:05 +0800108 bcmolt_internal_nni_enet_stats enet_stat;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400109
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000110 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 Huang2d9382f2020-10-21 17:52:05 +0800123 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 Subramani89fffc02019-05-13 21:33:20 +0000134 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 Huang2d9382f2020-10-21 17:52:05 +0800140 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 Palpacuer0f19b1a2018-06-07 17:29:31 -0400150
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000151 /* 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 Huang5d9ab1a2020-04-15 16:53:49 +0800157
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000158 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 Huang5d9ab1a2020-04-15 16:53:49 +0800170
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000171 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500172 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 Subramani89fffc02019-05-13 21:33:20 +0000174 }
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 Palpacuer0f19b1a2018-06-07 17:29:31 -0400185
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000186 /* 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 Subramani0890b1f2019-11-22 07:52:47 -0500193 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 Subramani89fffc02019-05-13 21:33:20 +0000195 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800196#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 Huang2d9382f2020-10-21 17:52:05 +0800217
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000218 {
Jason Huang2d9382f2020-10-21 17:52:05 +0800219 bcmolt_internal_nni_key key = {};
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000220 key.pon_ni = (bcmolt_interface)intf_ref.intf_id;
Jason Huang2d9382f2020-10-21 17:52:05 +0800221 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 Palpacuer0f19b1a2018-06-07 17:29:31 -0400246
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000247 /* call API */
Jason Huang2d9382f2020-10-21 17:52:05 +0800248 err = bcmolt_stat_get((bcmolt_oltid)device_id, &enet_stat.hdr, clear_on_read);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000249 if (err == BCM_ERR_OK) {
Jason Huang2d9382f2020-10-21 17:52:05 +0800250 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 Subramani89fffc02019-05-13 21:33:20 +0000275 } else {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500276 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 Subramani89fffc02019-05-13 21:33:20 +0000278 }
279 }
Girish Gowdrafc10f0d2020-11-30 13:06:35 -0800280#endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000281 break;
282 }
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800283 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000284
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 Palpacuer6a63ea92018-09-05 17:21:37 -0400286 time_t now;
287 time(&now);
288 port_stats->set_timestamp((int)now);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000289#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400290 return port_stats;
291
292}
293
Shad Ansaricb004c52018-05-30 18:07:23 +0000294#if 0
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400295openolt::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 Ansaricb004c52018-05-30 18:07:23 +0000332#endif
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400333
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400334void stats_collection() {
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400335
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400336 if (!state.is_connected()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000337 OPENOLT_LOG(INFO, openolt_log_id, "Voltha is not connected, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400338 return;
339 }
340 if (!state.is_activated()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000341 OPENOLT_LOG(INFO, openolt_log_id, "The OLT is not up, do not collect stats\n");
Nicolas Palpacuerc09fdb72018-08-22 10:23:22 -0400342 return;
343 }
344
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000345 OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n");
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400346
Shad Ansariedef2132018-08-10 22:14:50 +0000347 //Ports statistics
Nicolas Palpacuer3cad49d2018-07-02 14:03:24 -0400348
Shad Ansariedef2132018-08-10 22:14:50 +0000349 //Uplink ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500350 for (int i = 0; i < NumNniIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000351 bcmolt_intf_ref intf_ref;
352 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_NNI;
353 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400354
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000355 openolt::PortStatistics* port_stats =
356 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400357
Girish Gowdra252f4972020-09-07 21:24:01 -0700358 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000359 ind.set_allocated_port_stats(port_stats);
360 oltIndQ.push(ind);
361 }
362 //Pon ports
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500363 for (int i = 0; i < NumPonIf_(); i++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000364 bcmolt_intf_ref intf_ref;
365 intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON;
366 intf_ref.intf_id = i;
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400367
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800368 openolt::PortStatistics* port_stats =
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000369 collectPortStatistics(intf_ref);
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400370
Girish Gowdra252f4972020-09-07 21:24:01 -0700371 ::openolt::Indication ind;
Shad Ansariedef2132018-08-10 22:14:50 +0000372 ind.set_allocated_port_stats(port_stats);
373 oltIndQ.push(ind);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400374 }
375
Shad Ansariedef2132018-08-10 22:14:50 +0000376 //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 Palpacuer0f19b1a2018-06-07 17:29:31 -0400407
408}
409
410/* Storing flow keys, temporary */
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400411// 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// }