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