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