Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1 | /* |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 2 | Copyright (C) 2018 Open Networking Foundation |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 3 | |
| 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 Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 25 | #include <chrono> |
| 26 | #include <thread> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 27 | |
| 28 | #include "core.h" |
| 29 | #include "indications.h" |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 30 | #include "stats_collection.h" |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 31 | #include "error_format.h" |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 32 | #include "state.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 33 | |
| 34 | extern "C" |
| 35 | { |
| 36 | #include <bcmos_system.h> |
| 37 | #include <bal_api.h> |
| 38 | #include <bal_api_end.h> |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame^] | 39 | // FIXME : dependency problem |
| 40 | // #include <bcm_common_gpon.h> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 43 | #define NUM_OF_PON_PORTS 16 |
| 44 | const std::string technology = "xgspon"; |
| 45 | const std::string firmware_version = "BAL.2.6.0.1__Openolt.2018.09.05"; |
| 46 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 47 | State state; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 48 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 49 | static Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir); |
| 50 | static Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id); |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 51 | |
Nicolas Palpacuer | 8ebaa26 | 2018-08-16 14:56:47 -0400 | [diff] [blame] | 52 | static inline int mk_sched_id(int intf_id, int onu_id) { |
| 53 | return 1023 + intf_id * 112 + onu_id; |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Nicolas Palpacuer | 8ebaa26 | 2018-08-16 14:56:47 -0400 | [diff] [blame] | 56 | static inline int mk_agg_port_id(int intf_id, int onu_id) { |
| 57 | return 1023 + intf_id * 112 + onu_id; |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 60 | |
| 61 | Status GetDeviceInfo_(openolt::DeviceInfo* device_info) { |
| 62 | |
| 63 | device_info->set_vendor("EdgeCore"); |
| 64 | device_info->set_model("asfvolt16"); |
| 65 | device_info->set_hardware_version(""); |
| 66 | device_info->set_firmware_version(firmware_version); |
| 67 | device_info->set_technology(technology); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 68 | device_info->set_pon_ports(NUM_OF_PON_PORTS); |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame^] | 69 | device_info->set_onu_id_start(1); |
| 70 | device_info->set_onu_id_end(257); |
| 71 | device_info->set_alloc_id_start(1024); |
| 72 | device_info->set_alloc_id_end(16383); |
| 73 | device_info->set_gemport_id_start(1024); |
| 74 | device_info->set_gemport_id_end(65535); |
| 75 | |
| 76 | // FIXME: Once dependency problem is fixed |
| 77 | // device_info->set_pon_ports(NUM_OF_PON_PORTS); |
| 78 | // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1); |
| 79 | // device_info->set_alloc_id_start(1024); |
| 80 | // device_info->set_alloc_id_end(XGPON_NUM_OF_ALLOC_IDS * NUM_OF_PON_PORTS ? - 1); |
| 81 | // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID); |
| 82 | // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * NUM_OF_PON_PORTS ? - 1); |
| 83 | // device_info->set_pon_ports(NUM_OF_PON_PORTS); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 84 | |
| 85 | return Status::OK; |
| 86 | } |
| 87 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 88 | Status Enable_(int argc, char *argv[]) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 89 | bcmbal_access_terminal_cfg acc_term_obj; |
| 90 | bcmbal_access_terminal_key key = { }; |
| 91 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 92 | if (!state.is_activated()) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 93 | std::cout << "Enable OLT" << std::endl; |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 94 | |
| 95 | bcmbal_init(argc, argv, NULL); |
| 96 | |
| 97 | Status status = SubscribeIndication(); |
| 98 | if (!status.ok()) { |
| 99 | std::cout << "ERROR: SubscribeIndication failed - " |
| 100 | << status.error_code() << ": " << status.error_message() |
| 101 | << std::endl; |
| 102 | return status; |
| 103 | } |
| 104 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 105 | key.access_term_id = DEFAULT_ATERM_ID; |
| 106 | BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 107 | BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 108 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 109 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 110 | std::cout << "ERROR: Failed to enable OLT" << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 111 | return bcm_to_grpc_err(err, "Failed to enable OLT"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 112 | } |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 113 | init_stats(); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 114 | } |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 115 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 116 | //If already enabled, generate an extra indication ???? |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 117 | return Status::OK; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | Status Disable_() { |
| 121 | // bcmbal_access_terminal_cfg acc_term_obj; |
| 122 | // bcmbal_access_terminal_key key = { }; |
| 123 | // |
| 124 | // if (state::is_activated) { |
| 125 | // std::cout << "Disable OLT" << std::endl; |
| 126 | // key.access_term_id = DEFAULT_ATERM_ID; |
| 127 | // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 128 | // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN); |
| 129 | // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 130 | // if (err) { |
| 131 | // std::cout << "ERROR: Failed to disable OLT" << std::endl; |
| 132 | // return bcm_to_grpc_err(err, "Failed to disable OLT"); |
| 133 | // } |
| 134 | // } |
| 135 | // //If already disabled, generate an extra indication ???? |
| 136 | // return Status::OK; |
| 137 | //This fails with Operation Not Supported, bug ??? |
| 138 | |
| 139 | //TEMPORARY WORK AROUND |
| 140 | Status status = DisableUplinkIf_(0); |
| 141 | if (status.ok()) { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 142 | state.deactivate(); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 143 | openolt::Indication ind; |
| 144 | openolt::OltIndication* olt_ind = new openolt::OltIndication; |
| 145 | olt_ind->set_oper_state("down"); |
| 146 | ind.set_allocated_olt_ind(olt_ind); |
| 147 | std::cout << "Disable OLT, add an extra indication" << std::endl; |
| 148 | oltIndQ.push(ind); |
| 149 | } |
| 150 | return status; |
| 151 | |
| 152 | } |
| 153 | |
| 154 | Status Reenable_() { |
| 155 | Status status = EnableUplinkIf_(0); |
| 156 | if (status.ok()) { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 157 | state.activate(); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 158 | openolt::Indication ind; |
| 159 | openolt::OltIndication* olt_ind = new openolt::OltIndication; |
| 160 | olt_ind->set_oper_state("up"); |
| 161 | ind.set_allocated_olt_ind(olt_ind); |
| 162 | std::cout << "Reenable OLT, add an extra indication" << std::endl; |
| 163 | oltIndQ.push(ind); |
| 164 | } |
| 165 | return status; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | Status EnablePonIf_(uint32_t intf_id) { |
| 169 | bcmbal_interface_cfg interface_obj; |
| 170 | bcmbal_interface_key interface_key; |
| 171 | |
| 172 | interface_key.intf_id = intf_id; |
| 173 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 174 | |
| 175 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 176 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP); |
| 177 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 178 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 179 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 180 | std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 181 | return bcm_to_grpc_err(err, "Failed to enable PON interface"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | return Status::OK; |
| 185 | } |
| 186 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 187 | Status DisableUplinkIf_(uint32_t intf_id) { |
| 188 | bcmbal_interface_cfg interface_obj; |
| 189 | bcmbal_interface_key interface_key; |
| 190 | |
| 191 | interface_key.intf_id = intf_id; |
| 192 | interface_key.intf_type = BCMBAL_INTF_TYPE_NNI; |
| 193 | |
| 194 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 195 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN); |
| 196 | |
| 197 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 198 | if (err) { |
| 199 | std::cout << "ERROR: Failed to disable Uplink interface: " << intf_id << std::endl; |
| 200 | return bcm_to_grpc_err(err, "Failed to disable Uplink interface"); |
| 201 | } |
| 202 | |
| 203 | return Status::OK; |
| 204 | } |
| 205 | |
| 206 | Status EnableUplinkIf_(uint32_t intf_id) { |
| 207 | bcmbal_interface_cfg interface_obj; |
| 208 | bcmbal_interface_key interface_key; |
| 209 | |
| 210 | interface_key.intf_id = intf_id; |
| 211 | interface_key.intf_type = BCMBAL_INTF_TYPE_NNI; |
| 212 | |
| 213 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 214 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP); |
| 215 | |
| 216 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 217 | if (err) { |
| 218 | std::cout << "ERROR: Failed to enable Uplink interface: " << intf_id << std::endl; |
| 219 | return bcm_to_grpc_err(err, "Failed to enable Uplink interface"); |
| 220 | } |
| 221 | |
| 222 | return Status::OK; |
| 223 | } |
| 224 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 225 | Status DisablePonIf_(uint32_t intf_id) { |
| 226 | bcmbal_interface_cfg interface_obj; |
| 227 | bcmbal_interface_key interface_key; |
| 228 | |
| 229 | interface_key.intf_id = intf_id; |
| 230 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 231 | |
| 232 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 233 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN); |
| 234 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 235 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 236 | if (err) { |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 237 | std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 238 | return bcm_to_grpc_err(err, "Failed to disable PON interface"); |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | return Status::OK; |
| 242 | } |
| 243 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 244 | Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 245 | const char *vendor_id, const char *vendor_specific, uint32_t pir, |
| 246 | uint32_t agg_port_id, uint32_t sched_id) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 247 | |
| 248 | bcmbal_subscriber_terminal_cfg sub_term_obj = {}; |
| 249 | bcmbal_subscriber_terminal_key subs_terminal_key; |
| 250 | bcmbal_serial_number serial_num = {}; |
| 251 | bcmbal_registration_id registration_id = {}; |
| 252 | |
| 253 | std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl; |
| 254 | std::cout << "Vendor Id " << vendor_id |
| 255 | << "Vendor Specific Id " << vendor_specific |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame] | 256 | << "pir " << pir |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 257 | << std::endl; |
| 258 | |
| 259 | subs_terminal_key.sub_term_id = onu_id; |
| 260 | subs_terminal_key.intf_id = intf_id; |
| 261 | BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key); |
| 262 | |
| 263 | memcpy(serial_num.vendor_id, vendor_id, 4); |
| 264 | memcpy(serial_num.vendor_specific, vendor_specific, 4); |
| 265 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num); |
| 266 | |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 267 | #if 0 |
| 268 | // Commenting out as this is causing issues with onu activation |
| 269 | // with BAL 2.6 (Broadcom CS5248819). |
| 270 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 271 | // FIXME - Use a default (all zeros) registration id. |
| 272 | memset(registration_id.arr, 0, sizeof(registration_id.arr)); |
| 273 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id); |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 274 | #endif |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 275 | |
| 276 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP); |
| 277 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 278 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr)); |
| 279 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 280 | std::cout << "ERROR: Failed to enable ONU: " << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 281 | return bcm_to_grpc_err(err, "Failed to enable ONU"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 284 | if (agg_port_id != 0) { |
| 285 | return SchedAdd_(intf_id, onu_id, agg_port_id, sched_id, pir); |
| 286 | } else { |
| 287 | return SchedAdd_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), sched_id, pir); |
| 288 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 289 | |
| 290 | //return Status::OK; |
| 291 | } |
| 292 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 293 | Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id, |
| 294 | const char *vendor_id, const char *vendor_specific) { |
| 295 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 296 | bcmbal_subscriber_terminal_cfg sub_term_obj = {}; |
| 297 | bcmbal_subscriber_terminal_key subs_terminal_key; |
| 298 | |
| 299 | std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl; |
| 300 | std::cout << "Vendor Id " << vendor_id |
| 301 | << "Vendor Specific Id " << vendor_specific |
| 302 | << std::endl; |
| 303 | |
| 304 | subs_terminal_key.sub_term_id = onu_id; |
| 305 | subs_terminal_key.intf_id = intf_id; |
| 306 | BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key); |
| 307 | |
| 308 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN); |
| 309 | |
| 310 | if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) { |
| 311 | std::cout << "ERROR: Failed to deactivate ONU: " << std::endl; |
| 312 | return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU"); |
| 313 | } |
| 314 | |
| 315 | return Status::OK; |
| 316 | } |
| 317 | |
| 318 | Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 319 | const char *vendor_id, const char *vendor_specific, |
| 320 | uint32_t agg_port_id, uint32_t sched_id) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 321 | |
| 322 | // Need to deactivate before removing it (BAL rules) |
| 323 | |
| 324 | DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific); |
| 325 | // Sleep to allow the state to propagate |
| 326 | // We need the subscriber terminal object to be admin down before removal |
| 327 | // Without sleep the race condition is lost by ~ 20 ms |
| 328 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 329 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 330 | if (agg_port_id != 0) { |
| 331 | SchedRemove_(intf_id, onu_id, agg_port_id, sched_id); |
| 332 | } else { |
| 333 | SchedRemove_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), sched_id); |
| 334 | } |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 335 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 336 | bcmos_errno err = BCM_ERR_OK; |
| 337 | bcmbal_subscriber_terminal_cfg cfg; |
| 338 | bcmbal_subscriber_terminal_key key = { }; |
| 339 | |
| 340 | std::cout << "Processing subscriber terminal cfg clear for sub_term_id = " |
| 341 | << onu_id << " and intf_id = " << intf_id << std::endl; |
| 342 | |
| 343 | key.sub_term_id = onu_id ; |
| 344 | key.intf_id = intf_id ; |
| 345 | |
| 346 | if (0 == key.sub_term_id) |
| 347 | { |
| 348 | std::cout << "Invalid Key to handle subscriber terminal clear subscriber_terminal_id = " |
| 349 | << onu_id << " Interface ID = " << intf_id << std::endl; |
| 350 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 351 | } |
| 352 | |
| 353 | BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key); |
| 354 | |
| 355 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr); |
| 356 | if (err != BCM_ERR_OK) |
| 357 | { |
| 358 | std::cout << "Failed to clear information for BAL subscriber_terminal_id = " |
| 359 | << onu_id << " Interface ID = " << intf_id << std::endl; |
| 360 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 361 | } |
| 362 | |
| 363 | return Status::OK;; |
| 364 | } |
| 365 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 366 | #define MAX_CHAR_LENGTH 20 |
| 367 | #define MAX_OMCI_MSG_LENGTH 44 |
| 368 | Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
| 369 | bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */ |
| 370 | bcmos_errno err = BCM_ERR_OK; |
| 371 | |
| 372 | /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */ |
| 373 | bcmbal_dest proxy_pkt_dest; |
| 374 | |
| 375 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL; |
| 376 | proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id; |
| 377 | proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id; |
| 378 | |
| 379 | // ??? |
| 380 | if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) { |
| 381 | buf.len = MAX_OMCI_MSG_LENGTH; |
| 382 | } else { |
| 383 | buf.len = pkt.size()/2; |
| 384 | } |
| 385 | |
| 386 | /* Send the OMCI packet using the BAL remote proxy API */ |
| 387 | uint16_t idx1 = 0; |
| 388 | uint16_t idx2 = 0; |
| 389 | uint8_t arraySend[buf.len]; |
| 390 | char str1[MAX_CHAR_LENGTH]; |
| 391 | char str2[MAX_CHAR_LENGTH]; |
| 392 | memset(&arraySend, 0, buf.len); |
| 393 | |
Nicolas Palpacuer | 135ce81 | 2018-08-30 09:04:34 -0400 | [diff] [blame] | 394 | // std::cout << "Sending omci msg to ONU of length is " |
| 395 | // << buf.len |
| 396 | // << std::endl; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 397 | |
| 398 | for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) { |
| 399 | sprintf(str1,"%c", pkt[idx1]); |
| 400 | sprintf(str2,"%c", pkt[++idx1]); |
| 401 | strcat(str1,str2); |
| 402 | arraySend[idx2] = strtol(str1, NULL, 16); |
| 403 | } |
| 404 | |
| 405 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 406 | memcpy(buf.val, (uint8_t *)arraySend, buf.len); |
Nicolas Palpacuer | 135ce81 | 2018-08-30 09:04:34 -0400 | [diff] [blame] | 407 | // |
| 408 | // std::cout << "After converting bytes to hex " |
| 409 | // << buf.val << buf.len << std::endl; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 410 | |
| 411 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 412 | |
Nicolas Palpacuer | 135ce81 | 2018-08-30 09:04:34 -0400 | [diff] [blame] | 413 | // std::cout << "OMCI request msg of length " << buf.len |
| 414 | // << " sent to ONU" << onu_id |
| 415 | // << " through PON " << intf_id << std::endl; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 416 | |
| 417 | free(buf.val); |
| 418 | |
| 419 | return Status::OK; |
| 420 | } |
| 421 | |
| 422 | Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
| 423 | bcmos_errno err = BCM_ERR_OK; |
| 424 | bcmbal_dest proxy_pkt_dest; |
| 425 | bcmbal_u8_list_u32_max_2048 buf; |
| 426 | |
| 427 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM, |
| 428 | proxy_pkt_dest.u.sub_term.sub_term_id = onu_id; |
| 429 | proxy_pkt_dest.u.sub_term.intf_id = intf_id; |
| 430 | |
| 431 | buf.len = pkt.size(); |
| 432 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 433 | memcpy(buf.val, (uint8_t *)pkt.data(), buf.len); |
| 434 | |
| 435 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 436 | |
| 437 | std::cout << "Packet out of length " << buf.len |
| 438 | << " sent to ONU" << onu_id |
| 439 | << " through PON " << intf_id << std::endl; |
| 440 | |
| 441 | free(buf.val); |
| 442 | |
| 443 | return Status::OK; |
| 444 | } |
| 445 | |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 446 | Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) { |
| 447 | bcmos_errno err = BCM_ERR_OK; |
| 448 | bcmbal_dest proxy_pkt_dest; |
| 449 | bcmbal_u8_list_u32_max_2048 buf; |
| 450 | |
| 451 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI, |
| 452 | proxy_pkt_dest.u.nni.intf_id = intf_id; |
| 453 | |
| 454 | buf.len = pkt.size(); |
| 455 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 456 | memcpy(buf.val, (uint8_t *)pkt.data(), buf.len); |
| 457 | |
| 458 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 459 | |
| 460 | std::cout << "Packet out of length " << buf.len |
| 461 | << " sent through uplink port " << intf_id << std::endl; |
| 462 | |
| 463 | free(buf.val); |
| 464 | |
| 465 | return Status::OK; |
| 466 | } |
| 467 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 468 | Status FlowAdd_(uint32_t onu_id, |
| 469 | uint32_t flow_id, const std::string flow_type, |
| 470 | uint32_t access_intf_id, uint32_t network_intf_id, |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 471 | uint32_t gemport_id, uint32_t sched_id, |
| 472 | uint32_t priority_value, |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 473 | const ::openolt::Classifier& classifier, |
| 474 | const ::openolt::Action& action) { |
| 475 | bcmos_errno err; |
| 476 | bcmbal_flow_cfg cfg; |
| 477 | bcmbal_flow_key key = { }; |
| 478 | |
| 479 | std::cout << "flow add -" |
| 480 | << " intf_id:" << access_intf_id |
| 481 | << " onu_id:" << onu_id |
| 482 | << " flow_id:" << flow_id |
| 483 | << " flow_type:" << flow_type |
| 484 | << " gemport_id:" << gemport_id |
| 485 | << " network_intf_id:" << network_intf_id |
| 486 | << std::endl; |
| 487 | |
| 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 { |
| 494 | std::cout << "Invalid flow type " << flow_type << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 495 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | BCMBAL_CFG_INIT(&cfg, flow, key); |
| 499 | |
| 500 | BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP); |
| 501 | BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id); |
| 502 | BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id); |
| 503 | BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id); |
| 504 | BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id); |
Nicolas Palpacuer | d6cf5aa | 2018-07-16 15:14:39 -0400 | [diff] [blame] | 505 | BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value); |
| 506 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 507 | |
| 508 | { |
| 509 | bcmbal_classifier val = { }; |
| 510 | |
| 511 | if (classifier.o_tpid()) { |
| 512 | val.o_tpid = classifier.o_tpid(); |
| 513 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID; |
| 514 | } |
| 515 | |
| 516 | if (classifier.o_vid()) { |
| 517 | val.o_vid = classifier.o_vid(); |
| 518 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID; |
| 519 | } |
| 520 | |
| 521 | if (classifier.i_tpid()) { |
| 522 | val.i_tpid = classifier.i_tpid(); |
| 523 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID; |
| 524 | } |
| 525 | |
| 526 | if (classifier.i_vid()) { |
| 527 | val.i_vid = classifier.i_vid(); |
| 528 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID; |
| 529 | } |
| 530 | |
| 531 | if (classifier.o_pbits()) { |
| 532 | val.o_pbits = classifier.o_pbits(); |
| 533 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS; |
| 534 | } |
| 535 | |
| 536 | if (classifier.i_pbits()) { |
| 537 | val.i_pbits = classifier.i_pbits(); |
| 538 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS; |
| 539 | } |
| 540 | |
| 541 | if (classifier.eth_type()) { |
| 542 | val.ether_type = classifier.eth_type(); |
| 543 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE; |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | if (classifier.dst_mac()) { |
| 548 | val.dst_mac = classifier.dst_mac(); |
| 549 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC; |
| 550 | } |
| 551 | |
| 552 | if (classifier.src_mac()) { |
| 553 | val.src_mac = classifier.src_mac(); |
| 554 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC; |
| 555 | } |
| 556 | */ |
| 557 | |
| 558 | if (classifier.ip_proto()) { |
| 559 | val.ip_proto = classifier.ip_proto(); |
| 560 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO; |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | if (classifier.dst_ip()) { |
| 565 | val.dst_ip = classifier.dst_ip(); |
| 566 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP; |
| 567 | } |
| 568 | |
| 569 | if (classifier.src_ip()) { |
| 570 | val.src_ip = classifier.src_ip(); |
| 571 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP; |
| 572 | } |
| 573 | */ |
| 574 | |
| 575 | if (classifier.src_port()) { |
| 576 | val.src_port = classifier.src_port(); |
| 577 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT; |
| 578 | } |
| 579 | |
| 580 | if (classifier.dst_port()) { |
| 581 | val.dst_port = classifier.dst_port(); |
| 582 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT; |
| 583 | } |
| 584 | |
| 585 | if (!classifier.pkt_tag_type().empty()) { |
| 586 | if (classifier.pkt_tag_type().compare("untagged") == 0) { |
| 587 | val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED; |
| 588 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE; |
| 589 | } else if (classifier.pkt_tag_type().compare("single_tag") == 0) { |
| 590 | val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG; |
| 591 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE; |
| 592 | } else if (classifier.pkt_tag_type().compare("double_tag") == 0) { |
| 593 | val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG; |
| 594 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val); |
| 599 | } |
| 600 | |
| 601 | { |
| 602 | bcmbal_action val = { }; |
| 603 | |
| 604 | const ::openolt::ActionCmd& cmd = action.cmd(); |
| 605 | |
| 606 | if (cmd.add_outer_tag()) { |
| 607 | val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 608 | val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK; |
| 609 | } |
| 610 | |
| 611 | if (cmd.remove_outer_tag()) { |
| 612 | val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG; |
| 613 | val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK; |
| 614 | } |
| 615 | |
| 616 | if (cmd.trap_to_host()) { |
| 617 | val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST; |
| 618 | val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK; |
| 619 | } |
| 620 | |
| 621 | if (action.o_vid()) { |
| 622 | val.o_vid = action.o_vid(); |
| 623 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID; |
| 624 | } |
| 625 | |
| 626 | if (action.o_pbits()) { |
| 627 | val.o_pbits = action.o_pbits(); |
| 628 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS; |
| 629 | } |
| 630 | |
| 631 | if (action.o_tpid()) { |
| 632 | val.o_tpid = action.o_tpid(); |
| 633 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID; |
| 634 | } |
| 635 | |
| 636 | if (action.i_vid()) { |
| 637 | val.i_vid = action.i_vid(); |
| 638 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID; |
| 639 | } |
| 640 | |
| 641 | if (action.i_pbits()) { |
| 642 | val.i_pbits = action.i_pbits(); |
| 643 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS; |
| 644 | } |
| 645 | |
| 646 | if (action.i_tpid()) { |
| 647 | val.i_tpid = action.i_tpid(); |
| 648 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID; |
| 649 | } |
| 650 | |
| 651 | BCMBAL_CFG_PROP_SET(&cfg, flow, action, val); |
| 652 | } |
| 653 | |
| 654 | { |
| 655 | bcmbal_tm_sched_id val; |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 656 | if (sched_id != 0) { |
| 657 | val = sched_id; |
| 658 | } else { |
Nicolas Palpacuer | 8ebaa26 | 2018-08-16 14:56:47 -0400 | [diff] [blame] | 659 | val = (bcmbal_tm_sched_id) mk_sched_id(access_intf_id, onu_id); |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 660 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 661 | BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val); |
| 662 | } |
| 663 | |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame] | 664 | if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) { |
| 665 | bcmbal_tm_queue_ref val = { }; |
| 666 | val.sched_id = access_intf_id << 7 | onu_id; |
| 667 | val.queue_id = 0; |
| 668 | BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val); |
| 669 | } |
| 670 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 671 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
| 672 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 673 | std::cout << "ERROR: flow add failed" << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 674 | return bcm_to_grpc_err(err, "flow add failed"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 677 | // register_new_flow(key); |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 678 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 679 | return Status::OK; |
| 680 | } |
| 681 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 682 | Status FlowRemove_(uint32_t flow_id, const std::string flow_type) { |
| 683 | |
| 684 | bcmbal_flow_cfg cfg; |
| 685 | bcmbal_flow_key key = { }; |
| 686 | |
| 687 | key.flow_id = (bcmbal_flow_id) flow_id; |
| 688 | key.flow_id = flow_id; |
| 689 | if (flow_type.compare("upstream") == 0 ) { |
| 690 | key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM; |
| 691 | } else if (flow_type.compare("downstream") == 0) { |
| 692 | key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM; |
| 693 | } else { |
| 694 | std::cout << "Invalid flow type " << flow_type << std::endl; |
| 695 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
| 696 | } |
| 697 | |
| 698 | BCMBAL_CFG_INIT(&cfg, flow, key); |
| 699 | |
| 700 | |
| 701 | bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr); |
| 702 | if (err) { |
| 703 | std::cout << "Error " << err << " while removing flow " |
| 704 | << flow_id << ", " << flow_type << std::endl; |
| 705 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow"); |
| 706 | } |
| 707 | |
| 708 | std::cout << "Flow " << flow_id << ", " << flow_type << " removed"; |
| 709 | return Status::OK; |
| 710 | } |
| 711 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 712 | Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 713 | |
| 714 | bcmos_errno err; |
| 715 | |
| 716 | /* Downstream */ |
| 717 | |
| 718 | /* Create subscriber's tm_sched */ |
| 719 | { |
| 720 | bcmbal_tm_sched_cfg cfg; |
| 721 | bcmbal_tm_sched_key key = { }; |
| 722 | key.dir = BCMBAL_TM_SCHED_DIR_DS; |
| 723 | key.id = intf_id << 7 | onu_id; |
| 724 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 725 | |
| 726 | bcmbal_tm_sched_owner owner = { }; |
| 727 | owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM; |
| 728 | owner.u.sub_term.intf_id = intf_id; |
| 729 | owner.u.sub_term.sub_term_id = onu_id; |
| 730 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner); |
| 731 | |
| 732 | bcmbal_tm_sched_parent parent = { }; |
| 733 | parent.sched_id = intf_id + 16384; |
| 734 | parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID; |
| 735 | parent.weight = 1; |
| 736 | parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT; |
| 737 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent); |
| 738 | |
| 739 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ); |
| 740 | |
| 741 | bcmbal_tm_shaping shaping = { }; |
| 742 | shaping.pir = pir; |
| 743 | shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR; |
| 744 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping); |
| 745 | |
| 746 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr); |
| 747 | if (err) { |
| 748 | std::cout << "ERROR: Failed to create subscriber downstream sched" |
| 749 | << " id:" << key.id |
| 750 | << " intf_id:" << intf_id |
| 751 | << " onu_id:" << onu_id << std::endl; |
| 752 | return bcm_to_grpc_err(err, "Failed to create subscriber downstream sched"); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | /* Create tm_queue */ |
| 757 | { |
| 758 | bcmbal_tm_queue_cfg cfg; |
| 759 | bcmbal_tm_queue_key key = { }; |
| 760 | key.sched_id = intf_id << 7 | onu_id; |
| 761 | key.sched_dir = BCMBAL_TM_SCHED_DIR_DS; |
| 762 | key.id = 0; |
| 763 | |
| 764 | BCMBAL_CFG_INIT(&cfg, tm_queue, key); |
| 765 | BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1); |
| 766 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr); |
| 767 | |
| 768 | if (err) { |
| 769 | std::cout << "ERROR: Failed to create subscriber downstream tm queue" |
| 770 | << " id: " << key.id |
| 771 | << " sched_id: " << key.sched_id |
| 772 | << " intf_id: " << intf_id |
| 773 | << " onu_id: " << onu_id << std::endl; |
| 774 | return bcm_to_grpc_err(err, "Failed to create subscriber downstream tm queue"); |
| 775 | } |
| 776 | |
| 777 | } |
| 778 | |
| 779 | /* Upstream */ |
| 780 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 781 | bcmbal_tm_sched_cfg cfg; |
| 782 | bcmbal_tm_sched_key key = { }; |
| 783 | bcmbal_tm_sched_type sched_type; |
| 784 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 785 | if (sched_id != 0) { |
| 786 | key.id = sched_id; |
| 787 | } else { |
Nicolas Palpacuer | 8ebaa26 | 2018-08-16 14:56:47 -0400 | [diff] [blame] | 788 | key.id = mk_sched_id(intf_id, onu_id); |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 789 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 790 | key.dir = BCMBAL_TM_SCHED_DIR_US; |
| 791 | |
| 792 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 793 | |
| 794 | { |
| 795 | bcmbal_tm_sched_owner val = { }; |
| 796 | |
| 797 | val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT; |
| 798 | val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 799 | val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_INTF_ID; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 800 | val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id; |
| 801 | val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_SUB_TERM_ID; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 802 | val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id; |
| 803 | val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_AGG_PORT_ID; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 804 | |
| 805 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val); |
| 806 | } |
| 807 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 808 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 809 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 810 | std::cout << "ERROR: Failed to create upstream DBA sched" |
| 811 | << " id:" << key.id |
| 812 | << " intf_id:" << intf_id |
| 813 | << " onu_id:" << onu_id << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 814 | return bcm_to_grpc_err(err, "Failed to create upstream DBA sched"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 815 | } |
| 816 | std::cout << "create upstream DBA sched" |
| 817 | << " id:" << key.id |
| 818 | << " intf_id:" << intf_id |
| 819 | << " onu_id:" << onu_id << std::endl; |
| 820 | |
| 821 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 822 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 823 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 824 | Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id) { |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 825 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 826 | bcmos_errno err; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 827 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 828 | /* Upstream */ |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 829 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 830 | bcmbal_tm_sched_cfg tm_cfg_us; |
| 831 | bcmbal_tm_sched_key tm_key_us = { }; |
| 832 | |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 833 | if (sched_id != 0) { |
| 834 | tm_key_us.id = sched_id; |
| 835 | } else { |
Nicolas Palpacuer | 8ebaa26 | 2018-08-16 14:56:47 -0400 | [diff] [blame] | 836 | tm_key_us.id = mk_sched_id(intf_id, onu_id); |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 837 | } |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 838 | 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) { |
| 844 | std::cout << "ERROR: Failed to remove upstream DBA sched" |
| 845 | << " id:" << tm_key_us.id |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 846 | << " intf_id:" << intf_id |
| 847 | << " onu_id:" << onu_id << std::endl; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 848 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched"); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | std::cout << "remove upstream DBA sched" |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 852 | << " id:" << tm_key_us.id |
| 853 | << " intf_id:" << intf_id |
| 854 | << " onu_id:" << onu_id << std::endl; |
| 855 | |
| 856 | /* Downstream */ |
| 857 | |
| 858 | // Queue |
| 859 | |
| 860 | bcmbal_tm_queue_cfg queue_cfg; |
| 861 | bcmbal_tm_queue_key queue_key = { }; |
| 862 | queue_key.sched_id = intf_id << 7 | onu_id; |
| 863 | queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS; |
| 864 | queue_key.id = 0; |
| 865 | |
| 866 | BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key); |
| 867 | |
| 868 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr)); |
| 869 | if (err) { |
| 870 | std::cout << "ERROR: Failed to remove downstream tm queue" |
| 871 | << " id:" << queue_key.id |
| 872 | << " sched_id:" << queue_key.sched_id |
| 873 | << " intf_id:" << intf_id |
| 874 | << " onu_id:" << onu_id << std::endl; |
| 875 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove downstream tm queue"); |
| 876 | } |
| 877 | |
| 878 | std::cout << "remove upstream DBA sched" |
| 879 | << " id:" << queue_key.id |
| 880 | << " sched_id:" << queue_key.sched_id |
| 881 | << " intf_id:" << intf_id |
| 882 | << " onu_id:" << onu_id << std::endl; |
| 883 | |
| 884 | // Sheduler |
| 885 | |
| 886 | bcmbal_tm_sched_cfg tm_cfg_ds; |
| 887 | bcmbal_tm_sched_key tm_key_ds = { }; |
| 888 | tm_key_ds.dir = BCMBAL_TM_SCHED_DIR_DS; |
| 889 | tm_key_ds.id = intf_id << 7 | onu_id; |
| 890 | BCMBAL_CFG_INIT(&tm_cfg_ds, tm_sched, tm_key_ds); |
| 891 | |
| 892 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_ds.hdr)); |
| 893 | if (err) { |
| 894 | std::cout << "ERROR: Failed to remove sub downstream sched" |
| 895 | << " id:" << tm_key_us.id |
| 896 | << " intf_id:" << intf_id |
| 897 | << " onu_id:" << onu_id << std::endl; |
| 898 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove sub downstream sched"); |
| 899 | } |
| 900 | |
| 901 | std::cout << "remove sub downstream sched" |
| 902 | << " id:" << tm_key_us.id |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 903 | << " intf_id:" << intf_id |
| 904 | << " onu_id:" << onu_id << std::endl; |
| 905 | |
| 906 | return Status::OK; |
| 907 | //return 0; |
| 908 | } |