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