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