blob: 002783c4554ae0c0af3a46c59200b603a64be2bd [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
28#include "core.h"
29#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040030#include "stats_collection.h"
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040031#include "error_format.h"
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040032#include "state.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000033
34extern "C"
35{
36#include <bcmos_system.h>
37#include <bal_api.h>
38#include <bal_api_end.h>
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -040039// FIXME : dependency problem
40// #include <bcm_common_gpon.h>
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040041// #include <bcm_dev_log_task.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000042}
43
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040044dev_log_id openolt_log_id = bcm_dev_log_id_register("OPENOLT", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
45dev_log_id omci_log_id = bcm_dev_log_id_register("OMCI", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
46
47
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040048#define NUM_OF_PON_PORTS 16
49const std::string technology = "xgspon";
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040050const std::string firmware_version = "BAL.2.6.0.1__Openolt.2018.09.10";
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040051
Shad Ansariedef2132018-08-10 22:14:50 +000052State state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040053
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -070054static Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir);
55static Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id);
Shad Ansari627b5782018-08-13 22:49:32 +000056
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -040057static inline int mk_sched_id(int intf_id, int onu_id) {
58 return 1023 + intf_id * 112 + onu_id;
Shad Ansari627b5782018-08-13 22:49:32 +000059}
60
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -040061static inline int mk_agg_port_id(int intf_id, int onu_id) {
62 return 1023 + intf_id * 112 + onu_id;
Shad Ansari627b5782018-08-13 22:49:32 +000063}
64
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040065
66Status GetDeviceInfo_(openolt::DeviceInfo* device_info) {
67
68 device_info->set_vendor("EdgeCore");
69 device_info->set_model("asfvolt16");
70 device_info->set_hardware_version("");
71 device_info->set_firmware_version(firmware_version);
72 device_info->set_technology(technology);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040073 device_info->set_pon_ports(NUM_OF_PON_PORTS);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -040074 device_info->set_onu_id_start(1);
75 device_info->set_onu_id_end(257);
76 device_info->set_alloc_id_start(1024);
77 device_info->set_alloc_id_end(16383);
78 device_info->set_gemport_id_start(1024);
79 device_info->set_gemport_id_end(65535);
80
81 // FIXME: Once dependency problem is fixed
82 // device_info->set_pon_ports(NUM_OF_PON_PORTS);
83 // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1);
84 // device_info->set_alloc_id_start(1024);
85 // device_info->set_alloc_id_end(XGPON_NUM_OF_ALLOC_IDS * NUM_OF_PON_PORTS ? - 1);
86 // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID);
87 // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * NUM_OF_PON_PORTS ? - 1);
88 // device_info->set_pon_ports(NUM_OF_PON_PORTS);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040089
90 return Status::OK;
91}
92
Shad Ansari627b5782018-08-13 22:49:32 +000093Status Enable_(int argc, char *argv[]) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000094 bcmbal_access_terminal_cfg acc_term_obj;
95 bcmbal_access_terminal_key key = { };
96
Shad Ansariedef2132018-08-10 22:14:50 +000097 if (!state.is_activated()) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040098 BCM_LOG(INFO, openolt_log_id, "Enable OLT");
Shad Ansari627b5782018-08-13 22:49:32 +000099
100 bcmbal_init(argc, argv, NULL);
101
102 Status status = SubscribeIndication();
103 if (!status.ok()) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400104 BCM_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n",
105 grpc_status_code_to_string(status.error_code()).c_str(),
106 status.error_message().c_str());
107
Shad Ansari627b5782018-08-13 22:49:32 +0000108 return status;
109 }
110
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000111 key.access_term_id = DEFAULT_ATERM_ID;
112 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
113 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400114 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
115 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400116 BCM_LOG(ERROR, openolt_log_id, "Failed to enable OLT\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400117 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000118 }
Shad Ansariedef2132018-08-10 22:14:50 +0000119 init_stats();
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000120 }
Shad Ansariedef2132018-08-10 22:14:50 +0000121
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400122 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000123 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400124}
125
126Status Disable_() {
127 // bcmbal_access_terminal_cfg acc_term_obj;
128 // bcmbal_access_terminal_key key = { };
129 //
130 // if (state::is_activated) {
131 // std::cout << "Disable OLT" << std::endl;
132 // key.access_term_id = DEFAULT_ATERM_ID;
133 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
134 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
135 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
136 // if (err) {
137 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
138 // return bcm_to_grpc_err(err, "Failed to disable OLT");
139 // }
140 // }
141 // //If already disabled, generate an extra indication ????
142 // return Status::OK;
143 //This fails with Operation Not Supported, bug ???
144
145 //TEMPORARY WORK AROUND
146 Status status = DisableUplinkIf_(0);
147 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000148 state.deactivate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400149 openolt::Indication ind;
150 openolt::OltIndication* olt_ind = new openolt::OltIndication;
151 olt_ind->set_oper_state("down");
152 ind.set_allocated_olt_ind(olt_ind);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400153 BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400154 oltIndQ.push(ind);
155 }
156 return status;
157
158}
159
160Status Reenable_() {
161 Status status = EnableUplinkIf_(0);
162 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000163 state.activate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400164 openolt::Indication ind;
165 openolt::OltIndication* olt_ind = new openolt::OltIndication;
166 olt_ind->set_oper_state("up");
167 ind.set_allocated_olt_ind(olt_ind);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400168 BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400169 oltIndQ.push(ind);
170 }
171 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000172}
173
174Status EnablePonIf_(uint32_t intf_id) {
175 bcmbal_interface_cfg interface_obj;
176 bcmbal_interface_key interface_key;
177
178 interface_key.intf_id = intf_id;
179 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
180
181 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
182 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
183
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400184 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
185 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400186 BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400187 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000188 }
189
190 return Status::OK;
191}
192
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400193Status DisableUplinkIf_(uint32_t intf_id) {
194 bcmbal_interface_cfg interface_obj;
195 bcmbal_interface_key interface_key;
196
197 interface_key.intf_id = intf_id;
198 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
199
200 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
201 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
202
203 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
204 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400205 BCM_LOG(ERROR, openolt_log_id, "Failed to disable Uplink interface: %d\n", intf_id);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400206 return bcm_to_grpc_err(err, "Failed to disable Uplink interface");
207 }
208
209 return Status::OK;
210}
211
212Status EnableUplinkIf_(uint32_t intf_id) {
213 bcmbal_interface_cfg interface_obj;
214 bcmbal_interface_key interface_key;
215
216 interface_key.intf_id = intf_id;
217 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
218
219 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
220 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
221
222 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
223 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400224 BCM_LOG(ERROR, openolt_log_id, "Failed to enable Uplink interface: %d\n", intf_id);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400225 return bcm_to_grpc_err(err, "Failed to enable Uplink interface");
226 }
227
228 return Status::OK;
229}
230
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400231Status DisablePonIf_(uint32_t intf_id) {
232 bcmbal_interface_cfg interface_obj;
233 bcmbal_interface_key interface_key;
234
235 interface_key.intf_id = intf_id;
236 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
237
238 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
239 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
240
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400241 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
242 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400243 BCM_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400244 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400245 }
246
247 return Status::OK;
248}
249
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000250Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700251 const char *vendor_id, const char *vendor_specific, uint32_t pir,
252 uint32_t agg_port_id, uint32_t sched_id) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000253
254 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
255 bcmbal_subscriber_terminal_key subs_terminal_key;
256 bcmbal_serial_number serial_num = {};
257 bcmbal_registration_id registration_id = {};
258
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400259 BCM_LOG(INFO, openolt_log_id, "Enabling ONU %d on PON %d : vendor id %s, vendor specific %s, pir %d\n",
260 onu_id, intf_id, vendor_id, vendor_specific, pir);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000261
262 subs_terminal_key.sub_term_id = onu_id;
263 subs_terminal_key.intf_id = intf_id;
264 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
265
266 memcpy(serial_num.vendor_id, vendor_id, 4);
267 memcpy(serial_num.vendor_specific, vendor_specific, 4);
268 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
269
Shad Ansaricb004c52018-05-30 18:07:23 +0000270#if 0
271 // Commenting out as this is causing issues with onu activation
272 // with BAL 2.6 (Broadcom CS5248819).
273
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000274 // FIXME - Use a default (all zeros) registration id.
275 memset(registration_id.arr, 0, sizeof(registration_id.arr));
276 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000277#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000278
279 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
280
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400281 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
282 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400283 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 -0400284 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000285 }
286
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700287 if (agg_port_id != 0) {
288 return SchedAdd_(intf_id, onu_id, agg_port_id, sched_id, pir);
289 } else {
290 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), sched_id, pir);
291 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000292
293 //return Status::OK;
294}
295
Jonathan Davis70c21812018-07-19 15:32:10 -0400296Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
297 const char *vendor_id, const char *vendor_specific) {
298
Jonathan Davis70c21812018-07-19 15:32:10 -0400299 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
300 bcmbal_subscriber_terminal_key subs_terminal_key;
301
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400302 BCM_LOG(INFO, openolt_log_id, "Deactivating ONU %d on PON %d : vendor id %s, vendor specific %s\n",
303 onu_id, intf_id, vendor_id, vendor_specific);
Jonathan Davis70c21812018-07-19 15:32:10 -0400304
305 subs_terminal_key.sub_term_id = onu_id;
306 subs_terminal_key.intf_id = intf_id;
307 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
308
309 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
310
311 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400312 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 -0400313 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
314 }
315
316 return Status::OK;
317}
318
319Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700320 const char *vendor_id, const char *vendor_specific,
321 uint32_t agg_port_id, uint32_t sched_id) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400322
323 // Need to deactivate before removing it (BAL rules)
324
325 DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
326 // Sleep to allow the state to propagate
327 // We need the subscriber terminal object to be admin down before removal
328 // Without sleep the race condition is lost by ~ 20 ms
329 std::this_thread::sleep_for(std::chrono::milliseconds(100));
330
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700331 if (agg_port_id != 0) {
332 SchedRemove_(intf_id, onu_id, agg_port_id, sched_id);
333 } else {
334 SchedRemove_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), sched_id);
335 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400336
Jonathan Davis70c21812018-07-19 15:32:10 -0400337 bcmos_errno err = BCM_ERR_OK;
338 bcmbal_subscriber_terminal_cfg cfg;
339 bcmbal_subscriber_terminal_key key = { };
340
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400341 BCM_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
342 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400343
344 key.sub_term_id = onu_id ;
345 key.intf_id = intf_id ;
346
347 if (0 == key.sub_term_id)
348 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400349 BCM_LOG(INFO, openolt_log_id,"Invalid Key to handle subscriber terminal clear subscriber_terminal_id %d, Interface ID %d\n",
350 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400351 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
352 }
353
354 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
355
356 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
357 if (err != BCM_ERR_OK)
358 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400359 BCM_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n",
360 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400361 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
362 }
363
364 return Status::OK;;
365}
366
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000367#define MAX_CHAR_LENGTH 20
368#define MAX_OMCI_MSG_LENGTH 44
369Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
370 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
371 bcmos_errno err = BCM_ERR_OK;
372
373 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
374 bcmbal_dest proxy_pkt_dest;
375
376 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
377 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
378 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
379
380 // ???
381 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
382 buf.len = MAX_OMCI_MSG_LENGTH;
383 } else {
384 buf.len = pkt.size()/2;
385 }
386
387 /* Send the OMCI packet using the BAL remote proxy API */
388 uint16_t idx1 = 0;
389 uint16_t idx2 = 0;
390 uint8_t arraySend[buf.len];
391 char str1[MAX_CHAR_LENGTH];
392 char str2[MAX_CHAR_LENGTH];
393 memset(&arraySend, 0, buf.len);
394
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000395 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
396 sprintf(str1,"%c", pkt[idx1]);
397 sprintf(str2,"%c", pkt[++idx1]);
398 strcat(str1,str2);
399 arraySend[idx2] = strtol(str1, NULL, 16);
400 }
401
402 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
403 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000404
405 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
406
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400407 if (err) {
408 BCM_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id);
409 } else {
410 BCM_LOG(DEBUG, omci_log_id, "OMCI request msg of length %d sent to ONU %d on PON %d : %s\n",
411 buf.len, onu_id, intf_id, buf.val);
412 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000413
414 free(buf.val);
415
416 return Status::OK;
417}
418
419Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
420 bcmos_errno err = BCM_ERR_OK;
421 bcmbal_dest proxy_pkt_dest;
422 bcmbal_u8_list_u32_max_2048 buf;
423
424 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
425 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
426 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
427
428 buf.len = pkt.size();
429 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
430 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
431
432 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
433
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400434 BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent to ONU %d on PON %d\n",
435 buf.len, onu_id, intf_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000436
437 free(buf.val);
438
439 return Status::OK;
440}
441
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400442Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
443 bcmos_errno err = BCM_ERR_OK;
444 bcmbal_dest proxy_pkt_dest;
445 bcmbal_u8_list_u32_max_2048 buf;
446
447 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
448 proxy_pkt_dest.u.nni.intf_id = intf_id;
449
450 buf.len = pkt.size();
451 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
452 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
453
454 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
455
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400456 BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent through uplink port %d\n",
457 buf.len, intf_id);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400458
459 free(buf.val);
460
461 return Status::OK;
462}
463
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000464Status FlowAdd_(uint32_t onu_id,
465 uint32_t flow_id, const std::string flow_type,
466 uint32_t access_intf_id, uint32_t network_intf_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700467 uint32_t gemport_id, uint32_t sched_id,
468 uint32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000469 const ::openolt::Classifier& classifier,
470 const ::openolt::Action& action) {
471 bcmos_errno err;
472 bcmbal_flow_cfg cfg;
473 bcmbal_flow_key key = { };
474
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400475 BCM_LOG(INFO, openolt_log_id, "flow add - intf_id %d, onu_id %d, fow_id %d, `flow_type` %s, gemport_id %d, network_intf_id %d\n",
476 access_intf_id, onu_id, flow_id, flow_type.c_str(), gemport_id, network_intf_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000477
478 key.flow_id = flow_id;
479 if (flow_type.compare("upstream") == 0 ) {
480 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
481 } else if (flow_type.compare("downstream") == 0) {
482 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
483 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400484 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400485 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000486 }
487
488 BCMBAL_CFG_INIT(&cfg, flow, key);
489
490 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
491 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
492 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
493 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
494 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400495 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
496
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000497
498 {
499 bcmbal_classifier val = { };
500
501 if (classifier.o_tpid()) {
502 val.o_tpid = classifier.o_tpid();
503 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
504 }
505
506 if (classifier.o_vid()) {
507 val.o_vid = classifier.o_vid();
508 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
509 }
510
511 if (classifier.i_tpid()) {
512 val.i_tpid = classifier.i_tpid();
513 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
514 }
515
516 if (classifier.i_vid()) {
517 val.i_vid = classifier.i_vid();
518 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
519 }
520
521 if (classifier.o_pbits()) {
522 val.o_pbits = classifier.o_pbits();
523 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
524 }
525
526 if (classifier.i_pbits()) {
527 val.i_pbits = classifier.i_pbits();
528 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
529 }
530
531 if (classifier.eth_type()) {
532 val.ether_type = classifier.eth_type();
533 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
534 }
535
536 /*
537 if (classifier.dst_mac()) {
538 val.dst_mac = classifier.dst_mac();
539 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
540 }
541
542 if (classifier.src_mac()) {
543 val.src_mac = classifier.src_mac();
544 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
545 }
546 */
547
548 if (classifier.ip_proto()) {
549 val.ip_proto = classifier.ip_proto();
550 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
551 }
552
553 /*
554 if (classifier.dst_ip()) {
555 val.dst_ip = classifier.dst_ip();
556 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
557 }
558
559 if (classifier.src_ip()) {
560 val.src_ip = classifier.src_ip();
561 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
562 }
563 */
564
565 if (classifier.src_port()) {
566 val.src_port = classifier.src_port();
567 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
568 }
569
570 if (classifier.dst_port()) {
571 val.dst_port = classifier.dst_port();
572 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
573 }
574
575 if (!classifier.pkt_tag_type().empty()) {
576 if (classifier.pkt_tag_type().compare("untagged") == 0) {
577 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
578 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
579 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
580 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
581 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
582 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
583 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
584 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
585 }
586 }
587
588 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
589 }
590
591 {
592 bcmbal_action val = { };
593
594 const ::openolt::ActionCmd& cmd = action.cmd();
595
596 if (cmd.add_outer_tag()) {
597 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
598 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
599 }
600
601 if (cmd.remove_outer_tag()) {
602 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
603 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
604 }
605
606 if (cmd.trap_to_host()) {
607 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
608 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
609 }
610
611 if (action.o_vid()) {
612 val.o_vid = action.o_vid();
613 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
614 }
615
616 if (action.o_pbits()) {
617 val.o_pbits = action.o_pbits();
618 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
619 }
620
621 if (action.o_tpid()) {
622 val.o_tpid = action.o_tpid();
623 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
624 }
625
626 if (action.i_vid()) {
627 val.i_vid = action.i_vid();
628 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
629 }
630
631 if (action.i_pbits()) {
632 val.i_pbits = action.i_pbits();
633 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
634 }
635
636 if (action.i_tpid()) {
637 val.i_tpid = action.i_tpid();
638 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
639 }
640
641 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
642 }
643
644 {
645 bcmbal_tm_sched_id val;
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700646 if (sched_id != 0) {
647 val = sched_id;
648 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400649 val = (bcmbal_tm_sched_id) mk_sched_id(access_intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700650 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000651 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
652 }
653
Shad Ansari06101952018-07-25 00:22:09 +0000654 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
655 bcmbal_tm_queue_ref val = { };
656 val.sched_id = access_intf_id << 7 | onu_id;
657 val.queue_id = 0;
658 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
659 }
660
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400661 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
662 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400663 BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400664 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000665 }
666
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400667 // register_new_flow(key);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400668
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000669 return Status::OK;
670}
671
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400672Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
673
674 bcmbal_flow_cfg cfg;
675 bcmbal_flow_key key = { };
676
677 key.flow_id = (bcmbal_flow_id) flow_id;
678 key.flow_id = flow_id;
679 if (flow_type.compare("upstream") == 0 ) {
680 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
681 } else if (flow_type.compare("downstream") == 0) {
682 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
683 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400684 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400685 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
686 }
687
688 BCMBAL_CFG_INIT(&cfg, flow, key);
689
690
691 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
692 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400693 BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n",
694 err, flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400695 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
696 }
697
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400698 BCM_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400699 return Status::OK;
700}
701
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700702Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400703
704 bcmos_errno err;
705
706 /* Downstream */
707
708 /* Create subscriber's tm_sched */
709 {
710 bcmbal_tm_sched_cfg cfg;
711 bcmbal_tm_sched_key key = { };
712 key.dir = BCMBAL_TM_SCHED_DIR_DS;
713 key.id = intf_id << 7 | onu_id;
714 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
715
716 bcmbal_tm_sched_owner owner = { };
717 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
718 owner.u.sub_term.intf_id = intf_id;
719 owner.u.sub_term.sub_term_id = onu_id;
720 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
721
722 bcmbal_tm_sched_parent parent = { };
723 parent.sched_id = intf_id + 16384;
724 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
725 parent.weight = 1;
726 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
727 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
728
729 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
730
731 bcmbal_tm_shaping shaping = { };
732 shaping.pir = pir;
733 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
734 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
735
736 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
737 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400738 BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber downstream sched, id %d, intf_id %d, onu_id %d\n",
739 key.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400740 return bcm_to_grpc_err(err, "Failed to create subscriber downstream sched");
741 }
742 }
743
744 /* Create tm_queue */
745 {
746 bcmbal_tm_queue_cfg cfg;
747 bcmbal_tm_queue_key key = { };
748 key.sched_id = intf_id << 7 | onu_id;
749 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
750 key.id = 0;
751
752 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
753 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
754 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
755
756 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400757 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",
758 key.id, key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400759 return bcm_to_grpc_err(err, "Failed to create subscriber downstream tm queue");
760 }
761
762 }
763
764 /* Upstream */
765
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000766 bcmbal_tm_sched_cfg cfg;
767 bcmbal_tm_sched_key key = { };
768 bcmbal_tm_sched_type sched_type;
769
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700770 if (sched_id != 0) {
771 key.id = sched_id;
772 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400773 key.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700774 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000775 key.dir = BCMBAL_TM_SCHED_DIR_US;
776
777 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
778
779 {
780 bcmbal_tm_sched_owner val = { };
781
782 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
783 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400784 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 +0000785 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
786 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 -0400787 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
788 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 +0000789
790 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
791 }
792
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400793 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400794 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400795 BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
796 key.id, intf_id, onu_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400797 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000798 }
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400799 BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
800 key.id,intf_id,onu_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000801
802 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000803}
Jonathan Davis70c21812018-07-19 15:32:10 -0400804
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700805Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id) {
Jonathan Davis70c21812018-07-19 15:32:10 -0400806
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400807 bcmos_errno err;
Jonathan Davis70c21812018-07-19 15:32:10 -0400808
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400809 /* Upstream */
Jonathan Davis70c21812018-07-19 15:32:10 -0400810
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400811 bcmbal_tm_sched_cfg tm_cfg_us;
812 bcmbal_tm_sched_key tm_key_us = { };
813
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700814 if (sched_id != 0) {
815 tm_key_us.id = sched_id;
816 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400817 tm_key_us.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700818 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400819 tm_key_us.dir = BCMBAL_TM_SCHED_DIR_US;
820
821 BCMBAL_CFG_INIT(&tm_cfg_us, tm_sched, tm_key_us);
822
823 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_us.hdr));
824 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400825 BCM_LOG(ERROR, openolt_log_id, "Failed to remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
826 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400827 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
Jonathan Davis70c21812018-07-19 15:32:10 -0400828 }
829
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400830 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
831 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400832
833 /* Downstream */
834
835 // Queue
836
837 bcmbal_tm_queue_cfg queue_cfg;
838 bcmbal_tm_queue_key queue_key = { };
839 queue_key.sched_id = intf_id << 7 | onu_id;
840 queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
841 queue_key.id = 0;
842
843 BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key);
844
845 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr));
846 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400847 BCM_LOG(ERROR, openolt_log_id, "Failed to remove downstream tm queue, id %d, sched_id %d, intf_id %d, onu_id %d\n",
848 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400849 return Status(grpc::StatusCode::INTERNAL, "Failed to remove downstream tm queue");
850 }
851
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400852 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, sched_id %d, intf_id %d, onu_id %d\n",
853 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400854
855 // Sheduler
856
857 bcmbal_tm_sched_cfg tm_cfg_ds;
858 bcmbal_tm_sched_key tm_key_ds = { };
859 tm_key_ds.dir = BCMBAL_TM_SCHED_DIR_DS;
860 tm_key_ds.id = intf_id << 7 | onu_id;
861 BCMBAL_CFG_INIT(&tm_cfg_ds, tm_sched, tm_key_ds);
862
863 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_ds.hdr));
864 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400865 BCM_LOG(ERROR, openolt_log_id, "Failed to remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
866 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400867 return Status(grpc::StatusCode::INTERNAL, "Failed to remove sub downstream sched");
868 }
869
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400870 BCM_LOG(INFO, openolt_log_id, "Remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
871 tm_key_us.id, intf_id, onu_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400872
873 return Status::OK;
874 //return 0;
875}