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