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