blob: 10ba7832a736224eac353b26a33b02d18c5336d3 [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) {
Shad Ansari0c6fa3e2018-09-26 17:43:21 +000058 return 1023 + intf_id * 32 + 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) {
Shad Ansari0c6fa3e2018-09-26 17:43:21 +000062 return 1023 + intf_id * 32 + 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,
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700252 uint32_t alloc_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 Gowdru0ffa48b2018-09-26 01:55:29 -0700287 if (alloc_id != 0) {
288 // Use alloc_id as both agg_port_id and sched_id.
289 // Additional Notes:
290 // The agg_port_id is a BAL nomenclature for alloc_id (TCONT identifier).
291 // The TCONT is associated with its own DBA scheduler with a unique scheduler ID.
292 // Use the alloc_id itself as the DBA Scheduler identifier (sched_id).
293 return SchedAdd_(intf_id, onu_id, alloc_id, alloc_id, pir);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700294 } else {
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700295 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 -0700296 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000297
298 //return Status::OK;
299}
300
Jonathan Davis70c21812018-07-19 15:32:10 -0400301Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
302 const char *vendor_id, const char *vendor_specific) {
303
Jonathan Davis70c21812018-07-19 15:32:10 -0400304 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
305 bcmbal_subscriber_terminal_key subs_terminal_key;
306
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400307 BCM_LOG(INFO, openolt_log_id, "Deactivating ONU %d on PON %d : vendor id %s, vendor specific %s\n",
308 onu_id, intf_id, vendor_id, vendor_specific);
Jonathan Davis70c21812018-07-19 15:32:10 -0400309
310 subs_terminal_key.sub_term_id = onu_id;
311 subs_terminal_key.intf_id = intf_id;
312 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
313
314 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
315
316 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400317 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 -0400318 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
319 }
320
321 return Status::OK;
322}
323
324Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700325 const char *vendor_id, const char *vendor_specific,
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700326 uint32_t alloc_id) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400327
328 // Need to deactivate before removing it (BAL rules)
329
330 DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
331 // Sleep to allow the state to propagate
332 // We need the subscriber terminal object to be admin down before removal
333 // Without sleep the race condition is lost by ~ 20 ms
334 std::this_thread::sleep_for(std::chrono::milliseconds(100));
335
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700336 if (alloc_id != 0) {
337 // Use alloc_id as both agg_port_id and sched_id
338 // Additional Notes:
339 // The agg_port_id is a BAL nomenclature for alloc_id (TCONT identifier).
340 // The TCONT is associated with its own DBA scheduler with a unique scheduler ID.
341 // Use the alloc_id itself as the DBA Scheduler identifier (sched_id).
342 SchedRemove_(intf_id, onu_id, alloc_id, alloc_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700343 } else {
Girish Gowdru0ffa48b2018-09-26 01:55:29 -0700344 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 -0700345 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400346
Jonathan Davis70c21812018-07-19 15:32:10 -0400347 bcmos_errno err = BCM_ERR_OK;
348 bcmbal_subscriber_terminal_cfg cfg;
349 bcmbal_subscriber_terminal_key key = { };
350
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400351 BCM_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
352 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400353
354 key.sub_term_id = onu_id ;
355 key.intf_id = intf_id ;
356
357 if (0 == key.sub_term_id)
358 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400359 BCM_LOG(INFO, openolt_log_id,"Invalid Key to handle subscriber terminal clear 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 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
365
366 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
367 if (err != BCM_ERR_OK)
368 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400369 BCM_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n",
370 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400371 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
372 }
373
374 return Status::OK;;
375}
376
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000377#define MAX_CHAR_LENGTH 20
378#define MAX_OMCI_MSG_LENGTH 44
379Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
380 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
381 bcmos_errno err = BCM_ERR_OK;
382
383 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
384 bcmbal_dest proxy_pkt_dest;
385
386 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
387 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
388 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
389
390 // ???
391 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
392 buf.len = MAX_OMCI_MSG_LENGTH;
393 } else {
394 buf.len = pkt.size()/2;
395 }
396
397 /* Send the OMCI packet using the BAL remote proxy API */
398 uint16_t idx1 = 0;
399 uint16_t idx2 = 0;
400 uint8_t arraySend[buf.len];
401 char str1[MAX_CHAR_LENGTH];
402 char str2[MAX_CHAR_LENGTH];
403 memset(&arraySend, 0, buf.len);
404
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000405 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
406 sprintf(str1,"%c", pkt[idx1]);
407 sprintf(str2,"%c", pkt[++idx1]);
408 strcat(str1,str2);
409 arraySend[idx2] = strtol(str1, NULL, 16);
410 }
411
412 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
413 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000414
415 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
416
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400417 if (err) {
418 BCM_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id);
419 } else {
420 BCM_LOG(DEBUG, omci_log_id, "OMCI request msg of length %d sent to ONU %d on PON %d : %s\n",
421 buf.len, onu_id, intf_id, buf.val);
422 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000423
424 free(buf.val);
425
426 return Status::OK;
427}
428
429Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
430 bcmos_errno err = BCM_ERR_OK;
431 bcmbal_dest proxy_pkt_dest;
432 bcmbal_u8_list_u32_max_2048 buf;
433
434 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
435 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
436 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
437
438 buf.len = pkt.size();
439 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
440 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
441
442 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
443
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400444 BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent to ONU %d on PON %d\n",
445 buf.len, onu_id, intf_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000446
447 free(buf.val);
448
449 return Status::OK;
450}
451
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400452Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
453 bcmos_errno err = BCM_ERR_OK;
454 bcmbal_dest proxy_pkt_dest;
455 bcmbal_u8_list_u32_max_2048 buf;
456
457 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
458 proxy_pkt_dest.u.nni.intf_id = intf_id;
459
460 buf.len = pkt.size();
461 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
462 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
463
464 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
465
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400466 BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent through uplink port %d\n",
467 buf.len, intf_id);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400468
469 free(buf.val);
470
471 return Status::OK;
472}
473
Shad Ansari39739bc2018-09-13 21:38:37 +0000474Status FlowAdd_(int32_t onu_id,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000475 uint32_t flow_id, const std::string flow_type,
Shad Ansari39739bc2018-09-13 21:38:37 +0000476 int32_t access_intf_id, int32_t network_intf_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700477 uint32_t gemport_id, uint32_t sched_id,
Shad Ansari39739bc2018-09-13 21:38:37 +0000478 int32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000479 const ::openolt::Classifier& classifier,
480 const ::openolt::Action& action) {
481 bcmos_errno err;
482 bcmbal_flow_cfg cfg;
483 bcmbal_flow_key key = { };
484
Shad Ansari39739bc2018-09-13 21:38:37 +0000485 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 -0400486 access_intf_id, onu_id, flow_id, flow_type.c_str(), gemport_id, network_intf_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000487
488 key.flow_id = flow_id;
489 if (flow_type.compare("upstream") == 0 ) {
490 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
491 } else if (flow_type.compare("downstream") == 0) {
492 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
493 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400494 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400495 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000496 }
497
498 BCMBAL_CFG_INIT(&cfg, flow, key);
499
500 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
Shad Ansari39739bc2018-09-13 21:38:37 +0000501 if (access_intf_id >= 0) {
502 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
503 }
504 if (network_intf_id >= 0) {
505 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
506 }
507 if (onu_id >= 0) {
508 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
509 }
510 if (gemport_id >= 0) {
511 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
512 }
513 if (priority_value >= 0) {
514 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
515 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000516
517 {
518 bcmbal_classifier val = { };
519
520 if (classifier.o_tpid()) {
521 val.o_tpid = classifier.o_tpid();
522 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
523 }
524
525 if (classifier.o_vid()) {
526 val.o_vid = classifier.o_vid();
527 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
528 }
529
530 if (classifier.i_tpid()) {
531 val.i_tpid = classifier.i_tpid();
532 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
533 }
534
535 if (classifier.i_vid()) {
536 val.i_vid = classifier.i_vid();
537 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
538 }
539
540 if (classifier.o_pbits()) {
541 val.o_pbits = classifier.o_pbits();
542 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
543 }
544
545 if (classifier.i_pbits()) {
546 val.i_pbits = classifier.i_pbits();
547 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
548 }
549
550 if (classifier.eth_type()) {
551 val.ether_type = classifier.eth_type();
552 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
553 }
554
555 /*
556 if (classifier.dst_mac()) {
557 val.dst_mac = classifier.dst_mac();
558 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
559 }
560
561 if (classifier.src_mac()) {
562 val.src_mac = classifier.src_mac();
563 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
564 }
565 */
566
567 if (classifier.ip_proto()) {
568 val.ip_proto = classifier.ip_proto();
569 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
570 }
571
572 /*
573 if (classifier.dst_ip()) {
574 val.dst_ip = classifier.dst_ip();
575 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
576 }
577
578 if (classifier.src_ip()) {
579 val.src_ip = classifier.src_ip();
580 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
581 }
582 */
583
584 if (classifier.src_port()) {
585 val.src_port = classifier.src_port();
586 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
587 }
588
589 if (classifier.dst_port()) {
590 val.dst_port = classifier.dst_port();
591 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
592 }
593
594 if (!classifier.pkt_tag_type().empty()) {
595 if (classifier.pkt_tag_type().compare("untagged") == 0) {
596 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
597 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
598 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
599 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
600 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
601 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
602 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
603 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
604 }
605 }
606
607 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
608 }
609
610 {
611 bcmbal_action val = { };
612
613 const ::openolt::ActionCmd& cmd = action.cmd();
614
615 if (cmd.add_outer_tag()) {
616 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
617 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
618 }
619
620 if (cmd.remove_outer_tag()) {
621 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
622 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
623 }
624
625 if (cmd.trap_to_host()) {
626 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
627 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
628 }
629
630 if (action.o_vid()) {
631 val.o_vid = action.o_vid();
632 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
633 }
634
635 if (action.o_pbits()) {
636 val.o_pbits = action.o_pbits();
637 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
638 }
639
640 if (action.o_tpid()) {
641 val.o_tpid = action.o_tpid();
642 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
643 }
644
645 if (action.i_vid()) {
646 val.i_vid = action.i_vid();
647 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
648 }
649
650 if (action.i_pbits()) {
651 val.i_pbits = action.i_pbits();
652 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
653 }
654
655 if (action.i_tpid()) {
656 val.i_tpid = action.i_tpid();
657 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
658 }
659
660 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
661 }
662
Shad Ansari39739bc2018-09-13 21:38:37 +0000663 if ((access_intf_id >= 0) && (onu_id >= 0)) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000664 bcmbal_tm_sched_id val;
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700665 if (sched_id != 0) {
666 val = sched_id;
667 } else {
Shad Ansari39739bc2018-09-13 21:38:37 +0000668 val = (bcmbal_tm_sched_id) mk_sched_id(access_intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700669 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000670 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000671
Shad Ansari39739bc2018-09-13 21:38:37 +0000672 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
673 bcmbal_tm_queue_ref val = { };
674 val.sched_id = access_intf_id << 7 | onu_id;
675 val.queue_id = 0;
676 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
677 }
Shad Ansari06101952018-07-25 00:22:09 +0000678 }
679
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400680 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
681 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400682 BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400683 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000684 }
685
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400686 // register_new_flow(key);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400687
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000688 return Status::OK;
689}
690
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400691Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
692
693 bcmbal_flow_cfg cfg;
694 bcmbal_flow_key key = { };
695
696 key.flow_id = (bcmbal_flow_id) flow_id;
697 key.flow_id = flow_id;
698 if (flow_type.compare("upstream") == 0 ) {
699 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
700 } else if (flow_type.compare("downstream") == 0) {
701 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
702 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400703 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400704 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
705 }
706
707 BCMBAL_CFG_INIT(&cfg, flow, key);
708
709
710 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
711 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400712 BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n",
713 err, flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400714 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
715 }
716
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400717 BCM_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400718 return Status::OK;
719}
720
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700721Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400722
723 bcmos_errno err;
724
725 /* Downstream */
726
727 /* Create subscriber's tm_sched */
728 {
729 bcmbal_tm_sched_cfg cfg;
730 bcmbal_tm_sched_key key = { };
731 key.dir = BCMBAL_TM_SCHED_DIR_DS;
732 key.id = intf_id << 7 | onu_id;
733 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
734
735 bcmbal_tm_sched_owner owner = { };
736 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
737 owner.u.sub_term.intf_id = intf_id;
738 owner.u.sub_term.sub_term_id = onu_id;
739 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
740
741 bcmbal_tm_sched_parent parent = { };
742 parent.sched_id = intf_id + 16384;
743 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
744 parent.weight = 1;
745 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
746 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
747
748 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
749
750 bcmbal_tm_shaping shaping = { };
751 shaping.pir = pir;
752 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
753 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
754
755 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
756 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400757 BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber downstream sched, id %d, intf_id %d, onu_id %d\n",
758 key.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400759 return bcm_to_grpc_err(err, "Failed to create subscriber downstream sched");
760 }
761 }
762
763 /* Create tm_queue */
764 {
765 bcmbal_tm_queue_cfg cfg;
766 bcmbal_tm_queue_key key = { };
767 key.sched_id = intf_id << 7 | onu_id;
768 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
769 key.id = 0;
770
771 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
772 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
773 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
774
775 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400776 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",
777 key.id, key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400778 return bcm_to_grpc_err(err, "Failed to create subscriber downstream tm queue");
779 }
780
781 }
782
783 /* Upstream */
784
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000785 bcmbal_tm_sched_cfg cfg;
786 bcmbal_tm_sched_key key = { };
787 bcmbal_tm_sched_type sched_type;
788
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700789 if (sched_id != 0) {
790 key.id = sched_id;
791 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400792 key.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700793 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000794 key.dir = BCMBAL_TM_SCHED_DIR_US;
795
796 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
797
798 {
799 bcmbal_tm_sched_owner val = { };
800
801 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
802 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400803 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 +0000804 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
805 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 -0400806 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
807 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 +0000808
809 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
810 }
811
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400812 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400813 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400814 BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
815 key.id, intf_id, onu_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400816 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000817 }
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400818 BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
819 key.id,intf_id,onu_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000820
821 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000822}
Jonathan Davis70c21812018-07-19 15:32:10 -0400823
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700824Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id) {
Jonathan Davis70c21812018-07-19 15:32:10 -0400825
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400826 bcmos_errno err;
Jonathan Davis70c21812018-07-19 15:32:10 -0400827
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400828 /* Upstream */
Jonathan Davis70c21812018-07-19 15:32:10 -0400829
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400830 bcmbal_tm_sched_cfg tm_cfg_us;
831 bcmbal_tm_sched_key tm_key_us = { };
832
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700833 if (sched_id != 0) {
834 tm_key_us.id = sched_id;
835 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400836 tm_key_us.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700837 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400838 tm_key_us.dir = BCMBAL_TM_SCHED_DIR_US;
839
840 BCMBAL_CFG_INIT(&tm_cfg_us, tm_sched, tm_key_us);
841
842 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_us.hdr));
843 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400844 BCM_LOG(ERROR, openolt_log_id, "Failed to remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
845 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400846 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
Jonathan Davis70c21812018-07-19 15:32:10 -0400847 }
848
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400849 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, intf_id %d, onu_id %d\n",
850 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400851
852 /* Downstream */
853
854 // Queue
855
856 bcmbal_tm_queue_cfg queue_cfg;
857 bcmbal_tm_queue_key queue_key = { };
858 queue_key.sched_id = intf_id << 7 | onu_id;
859 queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
860 queue_key.id = 0;
861
862 BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key);
863
864 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr));
865 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400866 BCM_LOG(ERROR, openolt_log_id, "Failed to remove downstream tm queue, id %d, sched_id %d, intf_id %d, onu_id %d\n",
867 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400868 return Status(grpc::StatusCode::INTERNAL, "Failed to remove downstream tm queue");
869 }
870
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400871 BCM_LOG(INFO, openolt_log_id, "Remove upstream DBA sched, id %d, sched_id %d, intf_id %d, onu_id %d\n",
872 queue_key.id, queue_key.sched_id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400873
874 // Sheduler
875
876 bcmbal_tm_sched_cfg tm_cfg_ds;
877 bcmbal_tm_sched_key tm_key_ds = { };
878 tm_key_ds.dir = BCMBAL_TM_SCHED_DIR_DS;
879 tm_key_ds.id = intf_id << 7 | onu_id;
880 BCMBAL_CFG_INIT(&tm_cfg_ds, tm_sched, tm_key_ds);
881
882 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_ds.hdr));
883 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400884 BCM_LOG(ERROR, openolt_log_id, "Failed to remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
885 tm_key_us.id, intf_id, onu_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400886 return Status(grpc::StatusCode::INTERNAL, "Failed to remove sub downstream sched");
887 }
888
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400889 BCM_LOG(INFO, openolt_log_id, "Remove sub downstream sched, id %d, intf_id %d, onu_id %d\n",
890 tm_key_us.id, intf_id, onu_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400891
892 return Status::OK;
893 //return 0;
894}