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