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