blob: 10be676534fcc85b03eaf0eea206a57fd779d4f9 [file] [log] [blame]
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001/*
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04002 Copyright (C) 2018 Open Networking Foundation
Shad Ansarib7b0ced2018-05-11 21:53:32 +00003
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <iostream>
19#include <memory>
20#include <string>
21
22#include "Queue.h"
23#include <iostream>
24#include <sstream>
Nicolas Palpacuer9c352082018-08-14 16:37:14 -040025#include <chrono>
26#include <thread>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000027
Craig Lutgen88a22ad2018-10-04 12:30:46 -050028#include "device.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000029#include "core.h"
30#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040031#include "stats_collection.h"
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040032#include "error_format.h"
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040033#include "state.h"
Craig Lutgen88a22ad2018-10-04 12:30:46 -050034#include "utils.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000035
36extern "C"
37{
38#include <bcmos_system.h>
39#include <bal_api.h>
40#include <bal_api_end.h>
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -040041// FIXME : dependency problem
42// #include <bcm_common_gpon.h>
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040043// #include <bcm_dev_log_task.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000044}
45
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040046dev_log_id openolt_log_id = bcm_dev_log_id_register("OPENOLT", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
47dev_log_id omci_log_id = bcm_dev_log_id_register("OMCI", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
48
Craig Lutgen88a22ad2018-10-04 12:30:46 -050049#define MAX_SUPPORTED_INTF 16
50#define BAL_RSC_MANAGER_BASE_TM_SCHED_ID 16384
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040051
Craig Lutgen88a22ad2018-10-04 12:30:46 -050052static unsigned int num_of_nni_ports = 0;
53static unsigned int num_of_pon_ports = 0;
54static std::string intf_technology[MAX_SUPPORTED_INTF];
55static const std::string UNKNOWN_TECH("unknown");
56static std::string technology(UNKNOWN_TECH);
57
58static std::string firmware_version = "Openolt.2018.10.04";
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040059
Shad Ansariedef2132018-08-10 22:14:50 +000060State state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040061
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -070062static Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir);
63static Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id);
Shad Ansari627b5782018-08-13 22:49:32 +000064
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -040065static inline int mk_sched_id(int intf_id, int onu_id) {
Shad Ansari0c6fa3e2018-09-26 17:43:21 +000066 return 1023 + intf_id * 32 + onu_id;
Shad Ansari627b5782018-08-13 22:49:32 +000067}
68
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -040069static inline int mk_agg_port_id(int intf_id, int onu_id) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -050070 if (technology == "gpon") return 511 + intf_id * 32 + onu_id;
Shad Ansari0c6fa3e2018-09-26 17:43:21 +000071 return 1023 + intf_id * 32 + onu_id;
Shad Ansari627b5782018-08-13 22:49:32 +000072}
73
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040074Status GetDeviceInfo_(openolt::DeviceInfo* device_info) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -050075 device_info->set_vendor(VENDOR_ID);
76 device_info->set_model(MODEL_ID);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040077 device_info->set_hardware_version("");
78 device_info->set_firmware_version(firmware_version);
79 device_info->set_technology(technology);
Craig Lutgen88a22ad2018-10-04 12:30:46 -050080 device_info->set_pon_ports(num_of_pon_ports);
81 if (technology == "xgspon") {
82 device_info->set_onu_id_start(1);
83 device_info->set_onu_id_end(255);
84 device_info->set_alloc_id_start(1024);
85 device_info->set_alloc_id_end(16383);
86 device_info->set_gemport_id_start(1024);
87 device_info->set_gemport_id_end(65535);
88 }
89 else if (technology == "gpon") {
90 device_info->set_onu_id_start(0);
91 device_info->set_onu_id_end(127);
92 device_info->set_alloc_id_start(256);
93 device_info->set_alloc_id_end(767);
94 device_info->set_gemport_id_start(0);
95 device_info->set_gemport_id_end(4095);
96 }
97 else {
98 device_info->set_onu_id_start(0);
99 device_info->set_onu_id_end(0);
100 device_info->set_alloc_id_start(0);
101 device_info->set_alloc_id_end(0);
102 device_info->set_gemport_id_start(0);
103 device_info->set_gemport_id_end(0);
104 }
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400105
106 // FIXME: Once dependency problem is fixed
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500107 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400108 // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1);
109 // device_info->set_alloc_id_start(1024);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500110 // device_info->set_alloc_id_end(XGPON_NUM_OF_ALLOC_IDS * num_of_pon_ports ? - 1);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400111 // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500112 // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1);
113 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400114
115 return Status::OK;
116}
117
Shad Ansari627b5782018-08-13 22:49:32 +0000118Status Enable_(int argc, char *argv[]) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000119 bcmbal_access_terminal_cfg acc_term_obj;
120 bcmbal_access_terminal_key key = { };
121
Shad Ansariedef2132018-08-10 22:14:50 +0000122 if (!state.is_activated()) {
Shad Ansari627b5782018-08-13 22:49:32 +0000123
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500124 vendor_init();
Shad Ansari627b5782018-08-13 22:49:32 +0000125 bcmbal_init(argc, argv, NULL);
126
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500127 BCM_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID);
128
Shad Ansari627b5782018-08-13 22:49:32 +0000129 Status status = SubscribeIndication();
130 if (!status.ok()) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400131 BCM_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n",
132 grpc_status_code_to_string(status.error_code()).c_str(),
133 status.error_message().c_str());
134
Shad Ansari627b5782018-08-13 22:49:32 +0000135 return status;
136 }
137
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000138 key.access_term_id = DEFAULT_ATERM_ID;
139 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
140 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400141 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
142 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400143 BCM_LOG(ERROR, openolt_log_id, "Failed to enable OLT\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400144 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000145 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500146
Shad Ansariedef2132018-08-10 22:14:50 +0000147 init_stats();
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000148 }
Shad Ansariedef2132018-08-10 22:14:50 +0000149
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400150 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000151 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400152}
153
154Status Disable_() {
155 // bcmbal_access_terminal_cfg acc_term_obj;
156 // bcmbal_access_terminal_key key = { };
157 //
158 // if (state::is_activated) {
159 // std::cout << "Disable OLT" << std::endl;
160 // key.access_term_id = DEFAULT_ATERM_ID;
161 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
162 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
163 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
164 // if (err) {
165 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
166 // return bcm_to_grpc_err(err, "Failed to disable OLT");
167 // }
168 // }
169 // //If already disabled, generate an extra indication ????
170 // return Status::OK;
171 //This fails with Operation Not Supported, bug ???
172
173 //TEMPORARY WORK AROUND
174 Status status = DisableUplinkIf_(0);
175 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000176 state.deactivate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400177 openolt::Indication ind;
178 openolt::OltIndication* olt_ind = new openolt::OltIndication;
179 olt_ind->set_oper_state("down");
180 ind.set_allocated_olt_ind(olt_ind);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400181 BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400182 oltIndQ.push(ind);
183 }
184 return status;
185
186}
187
188Status Reenable_() {
189 Status status = EnableUplinkIf_(0);
190 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000191 state.activate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400192 openolt::Indication ind;
193 openolt::OltIndication* olt_ind = new openolt::OltIndication;
194 olt_ind->set_oper_state("up");
195 ind.set_allocated_olt_ind(olt_ind);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400196 BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400197 oltIndQ.push(ind);
198 }
199 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000200}
201
202Status EnablePonIf_(uint32_t intf_id) {
203 bcmbal_interface_cfg interface_obj;
204 bcmbal_interface_key interface_key;
205
206 interface_key.intf_id = intf_id;
207 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
208
209 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
210 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
211
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400212 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
213 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400214 BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400215 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000216 }
217
218 return Status::OK;
219}
220
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400221Status DisableUplinkIf_(uint32_t intf_id) {
222 bcmbal_interface_cfg interface_obj;
223 bcmbal_interface_key interface_key;
224
225 interface_key.intf_id = intf_id;
226 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
227
228 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
229 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
230
231 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
232 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400233 BCM_LOG(ERROR, openolt_log_id, "Failed to disable Uplink interface: %d\n", intf_id);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400234 return bcm_to_grpc_err(err, "Failed to disable Uplink interface");
235 }
236
237 return Status::OK;
238}
239
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500240Status ProbeDeviceCapabilities_() {
241 bcmbal_access_terminal_cfg acc_term_obj;
242 bcmbal_access_terminal_key key = { };
243
244 key.access_term_id = DEFAULT_ATERM_ID;
245 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
246 BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, admin_state);
247 BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, oper_status);
248 BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, topology);
249 BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, sw_version);
250 BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, conn_id);
251 bcmos_errno err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
252 if (err) {
253 BCM_LOG(ERROR, openolt_log_id, "Failed to query OLT\n");
254 return bcm_to_grpc_err(err, "Failed to query OLT");
255 }
256
257 BCM_LOG(INFO, openolt_log_id, "OLT capabilitites, admin_state: %s oper_state: %s\n",
258 acc_term_obj.data.admin_state == BCMBAL_STATE_UP ? "up" : "down",
259 acc_term_obj.data.oper_status == BCMBAL_STATUS_UP ? "up" : "down");
260
261 std::string bal_version;
262 bal_version += std::to_string(acc_term_obj.data.sw_version.major_rev)
263 + "." + std::to_string(acc_term_obj.data.sw_version.minor_rev)
264 + "." + std::to_string(acc_term_obj.data.sw_version.release_rev);
265 firmware_version = "BAL." + bal_version + "__" + firmware_version;
266
267 BCM_LOG(INFO, openolt_log_id, "--------------- version %s object model: %d\n", bal_version.c_str(),
268 acc_term_obj.data.sw_version.om_version);
269
270 BCM_LOG(INFO, openolt_log_id, "--------------- topology nni:%d pon:%d dev:%d ppd:%d family: %d:%d\n",
271 acc_term_obj.data.topology.num_of_nni_ports,
272 acc_term_obj.data.topology.num_of_pon_ports,
273 acc_term_obj.data.topology.num_of_mac_devs,
274 acc_term_obj.data.topology.num_of_pons_per_mac_dev,
275 acc_term_obj.data.topology.pon_family,
276 acc_term_obj.data.topology.pon_sub_family
277 );
278
279 switch(acc_term_obj.data.topology.pon_sub_family)
280 {
281 case BCMBAL_PON_SUB_FAMILY_GPON: technology = "gpon"; break;
282 case BCMBAL_PON_SUB_FAMILY_XGS: technology = "xgspon"; break;
283 }
284
285 num_of_nni_ports = acc_term_obj.data.topology.num_of_nni_ports;
286 num_of_pon_ports = acc_term_obj.data.topology.num_of_pon_ports;
287
288 BCM_LOG(INFO, openolt_log_id, "PON num_intfs: %d global technology: %s\n", num_of_pon_ports, technology.c_str());
289
290 return Status::OK;
291}
292
293Status ProbePonIfTechnology_() {
294 // Probe maximum extent possible as configured into BAL driver to determine
295 // which are active in the current BAL topology. And for those
296 // that are active, determine each port's access technology, i.e. "gpon" or "xgspon".
297 for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) {
298 bcmbal_interface_cfg interface_obj;
299 bcmbal_interface_key interface_key;
300
301 interface_key.intf_id = intf_id;
302 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
303
304 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
305 BCMBAL_CFG_PROP_GET(&interface_obj, interface, admin_state);
306 BCMBAL_CFG_PROP_GET(&interface_obj, interface, transceiver_type);
307
308 bcmos_errno err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &(interface_obj.hdr));
309 if (err != BCM_ERR_OK) {
310 intf_technology[intf_id] = UNKNOWN_TECH;
311 if(err != BCM_ERR_RANGE) BCM_LOG(ERROR, openolt_log_id, "Failed to get PON config: %d\n", intf_id);
312 }
313 else {
314 switch(interface_obj.data.transceiver_type) {
315 case BCMBAL_TRX_TYPE_GPON_SPS_43_48:
316 case BCMBAL_TRX_TYPE_GPON_SPS_SOG_4321:
317 case BCMBAL_TRX_TYPE_GPON_LTE_3680_M:
318 case BCMBAL_TRX_TYPE_GPON_SOURCE_PHOTONICS:
319 case BCMBAL_TRX_TYPE_GPON_LTE_3680_P:
320 intf_technology[intf_id] = "gpon";
321 break;
322 default:
323 intf_technology[intf_id] = "xgspon";
324 break;
325 }
326 BCM_LOG(INFO, openolt_log_id, "PON intf_id: %d technology: %d:%s\n", intf_id,
327 interface_obj.data.transceiver_type, intf_technology[intf_id].c_str());
328 }
329 }
330
331 return Status::OK;
332}
333
334unsigned NumNniIf_() {return num_of_nni_ports;}
335unsigned NumPonIf_() {return num_of_pon_ports;}
336
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400337Status EnableUplinkIf_(uint32_t intf_id) {
338 bcmbal_interface_cfg interface_obj;
339 bcmbal_interface_key interface_key;
340
341 interface_key.intf_id = intf_id;
342 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
343
344 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
345 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
346
347 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
348 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400349 BCM_LOG(ERROR, openolt_log_id, "Failed to enable Uplink interface: %d\n", intf_id);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400350 return bcm_to_grpc_err(err, "Failed to enable Uplink interface");
351 }
352
353 return Status::OK;
354}
355
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400356Status DisablePonIf_(uint32_t intf_id) {
357 bcmbal_interface_cfg interface_obj;
358 bcmbal_interface_key interface_key;
359
360 interface_key.intf_id = intf_id;
361 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
362
363 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
364 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
365
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400366 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
367 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400368 BCM_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400369 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400370 }
371
372 return Status::OK;
373}
374
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000375Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700376 const char *vendor_id, const char *vendor_specific, uint32_t pir,
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700377 uint32_t alloc_id) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000378
379 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
380 bcmbal_subscriber_terminal_key subs_terminal_key;
381 bcmbal_serial_number serial_num = {};
382 bcmbal_registration_id registration_id = {};
383
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500384 BCM_LOG(INFO, openolt_log_id, "Enabling ONU %d on PON %d : vendor id %s, vendor specific %s, pir %d, alloc_id %d\n",
385 onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str(), pir, alloc_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000386
387 subs_terminal_key.sub_term_id = onu_id;
388 subs_terminal_key.intf_id = intf_id;
389 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
390
391 memcpy(serial_num.vendor_id, vendor_id, 4);
392 memcpy(serial_num.vendor_specific, vendor_specific, 4);
393 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
394
Shad Ansaricb004c52018-05-30 18:07:23 +0000395#if 0
396 // Commenting out as this is causing issues with onu activation
397 // with BAL 2.6 (Broadcom CS5248819).
398
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000399 // FIXME - Use a default (all zeros) registration id.
400 memset(registration_id.arr, 0, sizeof(registration_id.arr));
401 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000402#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000403
404 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
405
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400406 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
407 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400408 BCM_LOG(ERROR, openolt_log_id, "Failed to enable ONU %d on PON %d\n", onu_id, intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400409 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000410 }
411
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700412 if (alloc_id != 0) {
413 // Use alloc_id as both agg_port_id and sched_id.
414 // Additional Notes:
415 // The agg_port_id is a BAL nomenclature for alloc_id (TCONT identifier).
416 // The TCONT is associated with its own DBA scheduler with a unique scheduler ID.
417 // Use the alloc_id itself as the DBA Scheduler identifier (sched_id).
418 return SchedAdd_(intf_id, onu_id, alloc_id, alloc_id, pir);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700419 } else {
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700420 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), mk_sched_id(intf_id, onu_id), pir);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700421 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000422
423 //return Status::OK;
424}
425
Jonathan Davis70c21812018-07-19 15:32:10 -0400426Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
427 const char *vendor_id, const char *vendor_specific) {
428
Jonathan Davis70c21812018-07-19 15:32:10 -0400429 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
430 bcmbal_subscriber_terminal_key subs_terminal_key;
431
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400432 BCM_LOG(INFO, openolt_log_id, "Deactivating ONU %d on PON %d : vendor id %s, vendor specific %s\n",
433 onu_id, intf_id, vendor_id, vendor_specific);
Jonathan Davis70c21812018-07-19 15:32:10 -0400434
435 subs_terminal_key.sub_term_id = onu_id;
436 subs_terminal_key.intf_id = intf_id;
437 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
438
439 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
440
441 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400442 BCM_LOG(ERROR, openolt_log_id, "Failed to deactivate ONU %d on PON %d\n", onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400443 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
444 }
445
446 return Status::OK;
447}
448
449Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700450 const char *vendor_id, const char *vendor_specific,
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700451 uint32_t alloc_id) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400452
453 // Need to deactivate before removing it (BAL rules)
454
455 DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
456 // Sleep to allow the state to propagate
457 // We need the subscriber terminal object to be admin down before removal
458 // Without sleep the race condition is lost by ~ 20 ms
459 std::this_thread::sleep_for(std::chrono::milliseconds(100));
460
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700461 if (alloc_id != 0) {
462 // Use alloc_id as both agg_port_id and sched_id
463 // Additional Notes:
464 // The agg_port_id is a BAL nomenclature for alloc_id (TCONT identifier).
465 // The TCONT is associated with its own DBA scheduler with a unique scheduler ID.
466 // Use the alloc_id itself as the DBA Scheduler identifier (sched_id).
467 SchedRemove_(intf_id, onu_id, alloc_id, alloc_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700468 } else {
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700469 SchedRemove_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), mk_sched_id(intf_id, onu_id));
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700470 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400471
Jonathan Davis70c21812018-07-19 15:32:10 -0400472 bcmos_errno err = BCM_ERR_OK;
473 bcmbal_subscriber_terminal_cfg cfg;
474 bcmbal_subscriber_terminal_key key = { };
475
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400476 BCM_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
477 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400478
479 key.sub_term_id = onu_id ;
480 key.intf_id = intf_id ;
481
482 if (0 == key.sub_term_id)
483 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400484 BCM_LOG(INFO, openolt_log_id,"Invalid Key to handle subscriber terminal clear subscriber_terminal_id %d, Interface ID %d\n",
485 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400486 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
487 }
488
489 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
490
491 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
492 if (err != BCM_ERR_OK)
493 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400494 BCM_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n",
495 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400496 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
497 }
498
499 return Status::OK;;
500}
501
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000502#define MAX_CHAR_LENGTH 20
503#define MAX_OMCI_MSG_LENGTH 44
504Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
505 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
506 bcmos_errno err = BCM_ERR_OK;
507
508 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
509 bcmbal_dest proxy_pkt_dest;
510
511 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
512 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
513 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
514
515 // ???
516 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
517 buf.len = MAX_OMCI_MSG_LENGTH;
518 } else {
519 buf.len = pkt.size()/2;
520 }
521
522 /* Send the OMCI packet using the BAL remote proxy API */
523 uint16_t idx1 = 0;
524 uint16_t idx2 = 0;
525 uint8_t arraySend[buf.len];
526 char str1[MAX_CHAR_LENGTH];
527 char str2[MAX_CHAR_LENGTH];
528 memset(&arraySend, 0, buf.len);
529
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000530 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
531 sprintf(str1,"%c", pkt[idx1]);
532 sprintf(str2,"%c", pkt[++idx1]);
533 strcat(str1,str2);
534 arraySend[idx2] = strtol(str1, NULL, 16);
535 }
536
537 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
538 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000539
540 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
541
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400542 if (err) {
543 BCM_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id);
544 } else {
545 BCM_LOG(DEBUG, omci_log_id, "OMCI request msg of length %d sent to ONU %d on PON %d : %s\n",
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500546 buf.len, onu_id, intf_id, pkt.c_str());
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400547 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000548
549 free(buf.val);
550
551 return Status::OK;
552}
553
554Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
555 bcmos_errno err = BCM_ERR_OK;
556 bcmbal_dest proxy_pkt_dest;
557 bcmbal_u8_list_u32_max_2048 buf;
558
559 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
560 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
561 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
562
563 buf.len = pkt.size();
564 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
565 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
566
567 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
568
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400569 BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent to ONU %d on PON %d\n",
570 buf.len, onu_id, intf_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000571
572 free(buf.val);
573
574 return Status::OK;
575}
576
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400577Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
578 bcmos_errno err = BCM_ERR_OK;
579 bcmbal_dest proxy_pkt_dest;
580 bcmbal_u8_list_u32_max_2048 buf;
581
582 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
583 proxy_pkt_dest.u.nni.intf_id = intf_id;
584
585 buf.len = pkt.size();
586 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
587 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
588
589 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
590
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400591 BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent through uplink port %d\n",
592 buf.len, intf_id);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400593
594 free(buf.val);
595
596 return Status::OK;
597}
598
Shad Ansari39739bc2018-09-13 21:38:37 +0000599Status FlowAdd_(int32_t onu_id,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000600 uint32_t flow_id, const std::string flow_type,
Shad Ansari39739bc2018-09-13 21:38:37 +0000601 int32_t access_intf_id, int32_t network_intf_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700602 uint32_t gemport_id, uint32_t sched_id,
Shad Ansari39739bc2018-09-13 21:38:37 +0000603 int32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000604 const ::openolt::Classifier& classifier,
605 const ::openolt::Action& action) {
606 bcmos_errno err;
607 bcmbal_flow_cfg cfg;
608 bcmbal_flow_key key = { };
609
Shad Ansari39739bc2018-09-13 21:38:37 +0000610 BCM_LOG(INFO, openolt_log_id, "flow add - intf_id %d, onu_id %d, flow_id %d, `flow_type` %s, gemport_id %d, network_intf_id %d\n",
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400611 access_intf_id, onu_id, flow_id, flow_type.c_str(), gemport_id, network_intf_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000612
613 key.flow_id = flow_id;
614 if (flow_type.compare("upstream") == 0 ) {
615 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
616 } else if (flow_type.compare("downstream") == 0) {
617 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
618 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400619 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400620 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000621 }
622
623 BCMBAL_CFG_INIT(&cfg, flow, key);
624
625 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
Shad Ansari39739bc2018-09-13 21:38:37 +0000626 if (access_intf_id >= 0) {
627 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
628 }
629 if (network_intf_id >= 0) {
630 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
631 }
632 if (onu_id >= 0) {
633 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
634 }
635 if (gemport_id >= 0) {
636 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
637 }
638 if (priority_value >= 0) {
639 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
640 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000641
642 {
643 bcmbal_classifier val = { };
644
645 if (classifier.o_tpid()) {
646 val.o_tpid = classifier.o_tpid();
647 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
648 }
649
650 if (classifier.o_vid()) {
651 val.o_vid = classifier.o_vid();
652 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
653 }
654
655 if (classifier.i_tpid()) {
656 val.i_tpid = classifier.i_tpid();
657 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
658 }
659
660 if (classifier.i_vid()) {
661 val.i_vid = classifier.i_vid();
662 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
663 }
664
665 if (classifier.o_pbits()) {
666 val.o_pbits = classifier.o_pbits();
667 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
668 }
669
670 if (classifier.i_pbits()) {
671 val.i_pbits = classifier.i_pbits();
672 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
673 }
674
675 if (classifier.eth_type()) {
676 val.ether_type = classifier.eth_type();
677 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
678 }
679
680 /*
681 if (classifier.dst_mac()) {
682 val.dst_mac = classifier.dst_mac();
683 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
684 }
685
686 if (classifier.src_mac()) {
687 val.src_mac = classifier.src_mac();
688 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
689 }
690 */
691
692 if (classifier.ip_proto()) {
693 val.ip_proto = classifier.ip_proto();
694 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
695 }
696
697 /*
698 if (classifier.dst_ip()) {
699 val.dst_ip = classifier.dst_ip();
700 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
701 }
702
703 if (classifier.src_ip()) {
704 val.src_ip = classifier.src_ip();
705 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
706 }
707 */
708
709 if (classifier.src_port()) {
710 val.src_port = classifier.src_port();
711 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
712 }
713
714 if (classifier.dst_port()) {
715 val.dst_port = classifier.dst_port();
716 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
717 }
718
719 if (!classifier.pkt_tag_type().empty()) {
720 if (classifier.pkt_tag_type().compare("untagged") == 0) {
721 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
722 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
723 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
724 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
725 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
726 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
727 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
728 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
729 }
730 }
731
732 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
733 }
734
735 {
736 bcmbal_action val = { };
737
738 const ::openolt::ActionCmd& cmd = action.cmd();
739
740 if (cmd.add_outer_tag()) {
741 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
742 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
743 }
744
745 if (cmd.remove_outer_tag()) {
746 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
747 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
748 }
749
750 if (cmd.trap_to_host()) {
751 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
752 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
753 }
754
755 if (action.o_vid()) {
756 val.o_vid = action.o_vid();
757 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
758 }
759
760 if (action.o_pbits()) {
761 val.o_pbits = action.o_pbits();
762 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
763 }
764
765 if (action.o_tpid()) {
766 val.o_tpid = action.o_tpid();
767 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
768 }
769
770 if (action.i_vid()) {
771 val.i_vid = action.i_vid();
772 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
773 }
774
775 if (action.i_pbits()) {
776 val.i_pbits = action.i_pbits();
777 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
778 }
779
780 if (action.i_tpid()) {
781 val.i_tpid = action.i_tpid();
782 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
783 }
784
785 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
786 }
787
Shad Ansari39739bc2018-09-13 21:38:37 +0000788 if ((access_intf_id >= 0) && (onu_id >= 0)) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000789 bcmbal_tm_sched_id val;
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700790 if (sched_id != 0) {
791 val = sched_id;
792 } else {
Shad Ansari39739bc2018-09-13 21:38:37 +0000793 val = (bcmbal_tm_sched_id) mk_sched_id(access_intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700794 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000795 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000796
Shad Ansari39739bc2018-09-13 21:38:37 +0000797 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
798 bcmbal_tm_queue_ref val = { };
799 val.sched_id = access_intf_id << 7 | onu_id;
800 val.queue_id = 0;
801 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
802 }
Shad Ansari06101952018-07-25 00:22:09 +0000803 }
804
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400805 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
806 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400807 BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400808 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000809 }
810
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400811 // register_new_flow(key);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400812
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000813 return Status::OK;
814}
815
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400816Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
817
818 bcmbal_flow_cfg cfg;
819 bcmbal_flow_key key = { };
820
821 key.flow_id = (bcmbal_flow_id) flow_id;
822 key.flow_id = flow_id;
823 if (flow_type.compare("upstream") == 0 ) {
824 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
825 } else if (flow_type.compare("downstream") == 0) {
826 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
827 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400828 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400829 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
830 }
831
832 BCMBAL_CFG_INIT(&cfg, flow, key);
833
834
835 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
836 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400837 BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n",
838 err, flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400839 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
840 }
841
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400842 BCM_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400843 return Status::OK;
844}
845
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700846Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400847
848 bcmos_errno err;
849
850 /* Downstream */
851
852 /* Create subscriber's tm_sched */
853 {
854 bcmbal_tm_sched_cfg cfg;
855 bcmbal_tm_sched_key key = { };
856 key.dir = BCMBAL_TM_SCHED_DIR_DS;
857 key.id = intf_id << 7 | onu_id;
858 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
859
860 bcmbal_tm_sched_owner owner = { };
861 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
862 owner.u.sub_term.intf_id = intf_id;
863 owner.u.sub_term.sub_term_id = onu_id;
864 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
865
866 bcmbal_tm_sched_parent parent = { };
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500867 parent.sched_id = intf_id + BAL_RSC_MANAGER_BASE_TM_SCHED_ID;
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400868 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
869 parent.weight = 1;
870 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
871 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
872
873 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
874
875 bcmbal_tm_shaping shaping = { };
876 shaping.pir = pir;
877 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
878 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
879
880 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
881 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400882 BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber downstream sched, id %d, intf_id %d, onu_id %d\n",
883 key.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400884 return bcm_to_grpc_err(err, "Failed to create subscriber downstream sched");
885 }
886 }
887
888 /* Create tm_queue */
889 {
890 bcmbal_tm_queue_cfg cfg;
891 bcmbal_tm_queue_key key = { };
892 key.sched_id = intf_id << 7 | onu_id;
893 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
894 key.id = 0;
895
896 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
897 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
898 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
899
900 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400901 BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber downstream tm queue, id %d, sched_id %d, intf_id %d, onu_id %d\n",
902 key.id, key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400903 return bcm_to_grpc_err(err, "Failed to create subscriber downstream tm queue");
904 }
905
906 }
907
908 /* Upstream */
909
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000910 bcmbal_tm_sched_cfg cfg;
911 bcmbal_tm_sched_key key = { };
912 bcmbal_tm_sched_type sched_type;
913
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700914 if (sched_id != 0) {
915 key.id = sched_id;
916 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400917 key.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700918 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000919 key.dir = BCMBAL_TM_SCHED_DIR_US;
920
921 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
922
923 {
924 bcmbal_tm_sched_owner val = { };
925
926 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
927 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400928 val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_INTF_ID;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000929 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
930 val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_SUB_TERM_ID;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400931 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
932 val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_AGG_PORT_ID;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000933
934 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
935 }
936
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400937 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400938 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400939 BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
940 key.id, intf_id, onu_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400941 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000942 }
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400943 BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
944 key.id,intf_id,onu_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000945
946 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000947}
Jonathan Davis70c21812018-07-19 15:32:10 -0400948
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700949Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id) {
Jonathan Davis70c21812018-07-19 15:32:10 -0400950
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400951 bcmos_errno err;
Jonathan Davis70c21812018-07-19 15:32:10 -0400952
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400953 /* Upstream */
Jonathan Davis70c21812018-07-19 15:32:10 -0400954
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400955 bcmbal_tm_sched_cfg tm_cfg_us;
956 bcmbal_tm_sched_key tm_key_us = { };
957
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700958 if (sched_id != 0) {
959 tm_key_us.id = sched_id;
960 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400961 tm_key_us.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700962 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400963 tm_key_us.dir = BCMBAL_TM_SCHED_DIR_US;
964
965 BCMBAL_CFG_INIT(&tm_cfg_us, tm_sched, tm_key_us);
966
967 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_us.hdr));
968 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400969 BCM_LOG(ERROR, openolt_log_id, "Failed to remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
970 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400971 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
Jonathan Davis70c21812018-07-19 15:32:10 -0400972 }
973
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400974 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
975 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400976
977 /* Downstream */
978
979 // Queue
980
981 bcmbal_tm_queue_cfg queue_cfg;
982 bcmbal_tm_queue_key queue_key = { };
983 queue_key.sched_id = intf_id << 7 | onu_id;
984 queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
985 queue_key.id = 0;
986
987 BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key);
988
989 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr));
990 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400991 BCM_LOG(ERROR, openolt_log_id, "Failed to remove downstream tm queue, id %d, sched_id %d, intf_id %d, onu_id %d\n",
992 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400993 return Status(grpc::StatusCode::INTERNAL, "Failed to remove downstream tm queue");
994 }
995
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400996 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, sched_id %d, intf_id %d, onu_id %d\n",
997 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400998
999 // Sheduler
1000
1001 bcmbal_tm_sched_cfg tm_cfg_ds;
1002 bcmbal_tm_sched_key tm_key_ds = { };
1003 tm_key_ds.dir = BCMBAL_TM_SCHED_DIR_DS;
1004 tm_key_ds.id = intf_id << 7 | onu_id;
1005 BCMBAL_CFG_INIT(&tm_cfg_ds, tm_sched, tm_key_ds);
1006
1007 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_ds.hdr));
1008 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001009 BCM_LOG(ERROR, openolt_log_id, "Failed to remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
1010 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001011 return Status(grpc::StatusCode::INTERNAL, "Failed to remove sub downstream sched");
1012 }
1013
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001014 BCM_LOG(INFO, openolt_log_id, "Remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
1015 tm_key_us.id, intf_id, onu_id);
Jonathan Davis70c21812018-07-19 15:32:10 -04001016
1017 return Status::OK;
1018 //return 0;
1019}