blob: e1a6e3f1d9af4222bf430d128014cb2a4af499ba [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);
Nicolas Palpacuer8779a172018-09-12 13:45:42 -040075 device_info->set_onu_id_end(255);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -040076 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 Ansari39739bc2018-09-13 21:38:37 +0000464Status FlowAdd_(int32_t onu_id,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000465 uint32_t flow_id, const std::string flow_type,
Shad Ansari39739bc2018-09-13 21:38:37 +0000466 int32_t access_intf_id, int32_t network_intf_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700467 uint32_t gemport_id, uint32_t sched_id,
Shad Ansari39739bc2018-09-13 21:38:37 +0000468 int32_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
Shad Ansari39739bc2018-09-13 21:38:37 +0000475 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 -0400476 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);
Shad Ansari39739bc2018-09-13 21:38:37 +0000491 if (access_intf_id >= 0) {
492 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
493 }
494 if (network_intf_id >= 0) {
495 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
496 }
497 if (onu_id >= 0) {
498 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
499 }
500 if (gemport_id >= 0) {
501 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
502 }
503 if (priority_value >= 0) {
504 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
505 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000506
507 {
508 bcmbal_classifier val = { };
509
510 if (classifier.o_tpid()) {
511 val.o_tpid = classifier.o_tpid();
512 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
513 }
514
515 if (classifier.o_vid()) {
516 val.o_vid = classifier.o_vid();
517 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
518 }
519
520 if (classifier.i_tpid()) {
521 val.i_tpid = classifier.i_tpid();
522 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
523 }
524
525 if (classifier.i_vid()) {
526 val.i_vid = classifier.i_vid();
527 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
528 }
529
530 if (classifier.o_pbits()) {
531 val.o_pbits = classifier.o_pbits();
532 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
533 }
534
535 if (classifier.i_pbits()) {
536 val.i_pbits = classifier.i_pbits();
537 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
538 }
539
540 if (classifier.eth_type()) {
541 val.ether_type = classifier.eth_type();
542 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
543 }
544
545 /*
546 if (classifier.dst_mac()) {
547 val.dst_mac = classifier.dst_mac();
548 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
549 }
550
551 if (classifier.src_mac()) {
552 val.src_mac = classifier.src_mac();
553 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
554 }
555 */
556
557 if (classifier.ip_proto()) {
558 val.ip_proto = classifier.ip_proto();
559 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
560 }
561
562 /*
563 if (classifier.dst_ip()) {
564 val.dst_ip = classifier.dst_ip();
565 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
566 }
567
568 if (classifier.src_ip()) {
569 val.src_ip = classifier.src_ip();
570 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
571 }
572 */
573
574 if (classifier.src_port()) {
575 val.src_port = classifier.src_port();
576 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
577 }
578
579 if (classifier.dst_port()) {
580 val.dst_port = classifier.dst_port();
581 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
582 }
583
584 if (!classifier.pkt_tag_type().empty()) {
585 if (classifier.pkt_tag_type().compare("untagged") == 0) {
586 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
587 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
588 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
589 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
590 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
591 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
592 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
593 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
594 }
595 }
596
597 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
598 }
599
600 {
601 bcmbal_action val = { };
602
603 const ::openolt::ActionCmd& cmd = action.cmd();
604
605 if (cmd.add_outer_tag()) {
606 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
607 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
608 }
609
610 if (cmd.remove_outer_tag()) {
611 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
612 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
613 }
614
615 if (cmd.trap_to_host()) {
616 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
617 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
618 }
619
620 if (action.o_vid()) {
621 val.o_vid = action.o_vid();
622 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
623 }
624
625 if (action.o_pbits()) {
626 val.o_pbits = action.o_pbits();
627 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
628 }
629
630 if (action.o_tpid()) {
631 val.o_tpid = action.o_tpid();
632 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
633 }
634
635 if (action.i_vid()) {
636 val.i_vid = action.i_vid();
637 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
638 }
639
640 if (action.i_pbits()) {
641 val.i_pbits = action.i_pbits();
642 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
643 }
644
645 if (action.i_tpid()) {
646 val.i_tpid = action.i_tpid();
647 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
648 }
649
650 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
651 }
652
Shad Ansari39739bc2018-09-13 21:38:37 +0000653 if ((access_intf_id >= 0) && (onu_id >= 0)) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000654 bcmbal_tm_sched_id val;
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700655 if (sched_id != 0) {
656 val = sched_id;
657 } else {
Shad Ansari39739bc2018-09-13 21:38:37 +0000658 val = (bcmbal_tm_sched_id) mk_sched_id(access_intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700659 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000660 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000661
Shad Ansari39739bc2018-09-13 21:38:37 +0000662 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
663 bcmbal_tm_queue_ref val = { };
664 val.sched_id = access_intf_id << 7 | onu_id;
665 val.queue_id = 0;
666 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
667 }
Shad Ansari06101952018-07-25 00:22:09 +0000668 }
669
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400670 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
671 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400672 BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400673 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000674 }
675
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400676 // register_new_flow(key);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400677
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000678 return Status::OK;
679}
680
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400681Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
682
683 bcmbal_flow_cfg cfg;
684 bcmbal_flow_key key = { };
685
686 key.flow_id = (bcmbal_flow_id) flow_id;
687 key.flow_id = flow_id;
688 if (flow_type.compare("upstream") == 0 ) {
689 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
690 } else if (flow_type.compare("downstream") == 0) {
691 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
692 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400693 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400694 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
695 }
696
697 BCMBAL_CFG_INIT(&cfg, flow, key);
698
699
700 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
701 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400702 BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n",
703 err, flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400704 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
705 }
706
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400707 BCM_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400708 return Status::OK;
709}
710
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700711Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400712
713 bcmos_errno err;
714
715 /* Downstream */
716
717 /* Create subscriber's tm_sched */
718 {
719 bcmbal_tm_sched_cfg cfg;
720 bcmbal_tm_sched_key key = { };
721 key.dir = BCMBAL_TM_SCHED_DIR_DS;
722 key.id = intf_id << 7 | onu_id;
723 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
724
725 bcmbal_tm_sched_owner owner = { };
726 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
727 owner.u.sub_term.intf_id = intf_id;
728 owner.u.sub_term.sub_term_id = onu_id;
729 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
730
731 bcmbal_tm_sched_parent parent = { };
732 parent.sched_id = intf_id + 16384;
733 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
734 parent.weight = 1;
735 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
736 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
737
738 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
739
740 bcmbal_tm_shaping shaping = { };
741 shaping.pir = pir;
742 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
743 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
744
745 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
746 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400747 BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber downstream sched, id %d, intf_id %d, onu_id %d\n",
748 key.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400749 return bcm_to_grpc_err(err, "Failed to create subscriber downstream sched");
750 }
751 }
752
753 /* Create tm_queue */
754 {
755 bcmbal_tm_queue_cfg cfg;
756 bcmbal_tm_queue_key key = { };
757 key.sched_id = intf_id << 7 | onu_id;
758 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
759 key.id = 0;
760
761 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
762 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
763 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
764
765 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400766 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",
767 key.id, key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400768 return bcm_to_grpc_err(err, "Failed to create subscriber downstream tm queue");
769 }
770
771 }
772
773 /* Upstream */
774
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000775 bcmbal_tm_sched_cfg cfg;
776 bcmbal_tm_sched_key key = { };
777 bcmbal_tm_sched_type sched_type;
778
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700779 if (sched_id != 0) {
780 key.id = sched_id;
781 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400782 key.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700783 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000784 key.dir = BCMBAL_TM_SCHED_DIR_US;
785
786 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
787
788 {
789 bcmbal_tm_sched_owner val = { };
790
791 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
792 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400793 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 +0000794 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
795 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 -0400796 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
797 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 +0000798
799 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
800 }
801
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400802 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400803 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400804 BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
805 key.id, intf_id, onu_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400806 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000807 }
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400808 BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
809 key.id,intf_id,onu_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000810
811 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000812}
Jonathan Davis70c21812018-07-19 15:32:10 -0400813
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700814Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id) {
Jonathan Davis70c21812018-07-19 15:32:10 -0400815
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400816 bcmos_errno err;
Jonathan Davis70c21812018-07-19 15:32:10 -0400817
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400818 /* Upstream */
Jonathan Davis70c21812018-07-19 15:32:10 -0400819
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400820 bcmbal_tm_sched_cfg tm_cfg_us;
821 bcmbal_tm_sched_key tm_key_us = { };
822
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700823 if (sched_id != 0) {
824 tm_key_us.id = sched_id;
825 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400826 tm_key_us.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700827 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400828 tm_key_us.dir = BCMBAL_TM_SCHED_DIR_US;
829
830 BCMBAL_CFG_INIT(&tm_cfg_us, tm_sched, tm_key_us);
831
832 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_us.hdr));
833 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400834 BCM_LOG(ERROR, openolt_log_id, "Failed to remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
835 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400836 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
Jonathan Davis70c21812018-07-19 15:32:10 -0400837 }
838
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400839 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
840 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400841
842 /* Downstream */
843
844 // Queue
845
846 bcmbal_tm_queue_cfg queue_cfg;
847 bcmbal_tm_queue_key queue_key = { };
848 queue_key.sched_id = intf_id << 7 | onu_id;
849 queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
850 queue_key.id = 0;
851
852 BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key);
853
854 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr));
855 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400856 BCM_LOG(ERROR, openolt_log_id, "Failed to remove downstream tm queue, id %d, sched_id %d, intf_id %d, onu_id %d\n",
857 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400858 return Status(grpc::StatusCode::INTERNAL, "Failed to remove downstream tm queue");
859 }
860
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400861 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, sched_id %d, intf_id %d, onu_id %d\n",
862 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400863
864 // Sheduler
865
866 bcmbal_tm_sched_cfg tm_cfg_ds;
867 bcmbal_tm_sched_key tm_key_ds = { };
868 tm_key_ds.dir = BCMBAL_TM_SCHED_DIR_DS;
869 tm_key_ds.id = intf_id << 7 | onu_id;
870 BCMBAL_CFG_INIT(&tm_cfg_ds, tm_sched, tm_key_ds);
871
872 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_ds.hdr));
873 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400874 BCM_LOG(ERROR, openolt_log_id, "Failed to remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
875 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400876 return Status(grpc::StatusCode::INTERNAL, "Failed to remove sub downstream sched");
877 }
878
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400879 BCM_LOG(INFO, openolt_log_id, "Remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
880 tm_key_us.id, intf_id, onu_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400881
882 return Status::OK;
883 //return 0;
884}