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> |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 27 | #include <bitset> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 28 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 29 | #include "device.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 30 | #include "core.h" |
| 31 | #include "indications.h" |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 32 | #include "stats_collection.h" |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 33 | #include "error_format.h" |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 34 | #include "state.h" |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 35 | #include "utils.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 36 | |
| 37 | extern "C" |
| 38 | { |
| 39 | #include <bcmos_system.h> |
| 40 | #include <bal_api.h> |
| 41 | #include <bal_api_end.h> |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 42 | // FIXME : dependency problem |
| 43 | // #include <bcm_common_gpon.h> |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 44 | // #include <bcm_dev_log_task.h> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 45 | } |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 46 | // These need patched into bal_model_types.h directly. But, with above extern "C", it cannot be done |
| 47 | 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));} |
| 48 | 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));} |
| 49 | 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));} |
| 50 | 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));} |
| 51 | 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));} |
| 52 | 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] | 53 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 54 | dev_log_id openolt_log_id = bcm_dev_log_id_register("OPENOLT", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH); |
| 55 | dev_log_id omci_log_id = bcm_dev_log_id_register("OMCI", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH); |
| 56 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 57 | #define MAX_SUPPORTED_INTF 16 |
| 58 | #define BAL_RSC_MANAGER_BASE_TM_SCHED_ID 16384 |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 59 | #define MAX_TM_QUEUE_ID 8192 |
| 60 | #define MAX_TM_SCHED_ID 16384 |
| 61 | #define EAP_ETHER_TYPE 34958 |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 62 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 63 | static unsigned int num_of_nni_ports = 0; |
| 64 | static unsigned int num_of_pon_ports = 0; |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 65 | static std::string intf_technologies[MAX_SUPPORTED_INTF]; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 66 | static const std::string UNKNOWN_TECH("unknown"); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 67 | static const std::string MIXED_TECH("mixed"); |
| 68 | static std::string board_technology(UNKNOWN_TECH); |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 69 | static unsigned int OPENOLT_FIELD_LEN = 200; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 70 | static std::string firmware_version = "Openolt.2018.10.04"; |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 71 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 72 | const uint32_t tm_upstream_sched_id_start = 18432; |
| 73 | const uint32_t tm_downstream_sched_id_start = 16384; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 74 | //0 to 3 are default queues. Lets not use them. |
| 75 | const uint32_t tm_queue_id_start = 4; |
| 76 | // Upto 8 fixed Upstream. Queue id 0 to 3 are pre-created, lets not use them. |
| 77 | const uint32_t us_fixed_queue_id_list[8] = {4, 5, 6, 7, 8, 9, 10, 11}; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 78 | const std::string upstream = "upstream"; |
| 79 | const std::string downstream = "downstream"; |
| 80 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 81 | State state; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 82 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 83 | static std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports |
| 84 | static std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports |
| 85 | static std::map<uint32_t, std::set<uint32_t> > port_to_flows; // For mapping logical ports to downstream flows |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 86 | |
| 87 | // This represents the Key to 'queue_map' map. |
| 88 | // Represents (pon_intf_id, onu_id, uni_id, gemport_id, direction) |
| 89 | typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, std::string> queue_map_key_tuple; |
| 90 | // 'queue_map' maps queue_map_key_tuple to downstream queue id present |
| 91 | // on the Subscriber Scheduler |
| 92 | static std::map<queue_map_key_tuple, int> queue_map; |
| 93 | // This represents the Key to 'sched_map' map. |
| 94 | // Represents (pon_intf_id, onu_id, uni_id, direction) |
| 95 | |
| 96 | typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string> sched_map_key_tuple; |
| 97 | // 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or |
| 98 | // Subscriber (Downstream) Scheduler ID |
| 99 | static std::map<sched_map_key_tuple, int> sched_map; |
| 100 | |
| 101 | |
| 102 | std::bitset<MAX_TM_QUEUE_ID> tm_queue_bitset; |
| 103 | std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset; |
| 104 | |
| 105 | static bcmos_fastlock data_lock; |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 106 | |
| 107 | #define MIN_ALLOC_ID_GPON 256 |
| 108 | #define MIN_ALLOC_ID_XGSPON 1024 |
| 109 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 110 | static bcmos_errno CreateSched(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
| 111 | uint32_t port_no, uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, \ |
| 112 | uint32_t priority, tech_profile::SchedulingPolicy sched_policy, |
| 113 | tech_profile::TrafficShapingInfo traffic_shaping_info); |
| 114 | static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, std::string direction); |
| 115 | static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
| 116 | uint32_t priority, uint32_t gemport_id); |
| 117 | static bcmos_errno RemoveQueue(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] | 118 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 119 | /** |
| 120 | * Returns the default NNI (Upstream direction) or PON (Downstream direction) scheduler |
| 121 | * Every NNI port and PON port have default scheduler. |
| 122 | * The NNI0 default scheduler ID is 18432, and NNI1 is 18433 and so on. |
| 123 | * Similarly, PON0 default scheduler ID is 16384. PON1 is 16385 and so on. |
| 124 | * |
| 125 | * @param intf_id NNI or PON interface ID |
| 126 | * @param direction "upstream" or "downstream" |
| 127 | * |
| 128 | * @return default scheduler ID for the given interface. |
| 129 | */ |
| 130 | static inline int get_default_tm_sched_id(int intf_id, std::string direction) { |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 131 | if (direction.compare(upstream) == 0) { |
| 132 | return tm_upstream_sched_id_start + intf_id; |
| 133 | } else if (direction.compare(downstream) == 0) { |
| 134 | return tm_downstream_sched_id_start + intf_id; |
| 135 | } |
| 136 | else { |
| 137 | BCM_LOG(ERROR, openolt_log_id, "invalid direction - %s\n", direction.c_str()); |
| 138 | return 0; |
| 139 | } |
| 140 | } |
| 141 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 142 | /** |
| 143 | * Gets a unique tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 144 | * The tm_queue_id is locally cached in a map, so that it can rendered when necessary. |
| 145 | * VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem |
| 146 | * |
| 147 | * @param intf_id NNI or PON intf ID |
| 148 | * @param onu_id ONU ID |
| 149 | * @param uni_id UNI ID |
| 150 | * @param gemport_id GEM Port ID |
| 151 | * @param direction Upstream or downstream |
| 152 | * |
| 153 | * @return tm_queue_id |
| 154 | */ |
| 155 | int get_tm_queue_id(int intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) { |
| 156 | queue_map_key_tuple key(intf_id, onu_id, uni_id, gemport_id, direction); |
| 157 | int queue_id = -1; |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 158 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 159 | std::map<queue_map_key_tuple, int>::const_iterator it = queue_map.find(key); |
| 160 | if (it != queue_map.end()) { |
| 161 | queue_id = it->second; |
| 162 | } |
| 163 | if (queue_id != -1) { |
| 164 | return queue_id; |
| 165 | } |
| 166 | |
| 167 | bcmos_fastlock_lock(&data_lock); |
| 168 | // Complexity of O(n). Is there better way that can avoid linear search? |
| 169 | for (queue_id = 0; queue_id < MAX_TM_QUEUE_ID; queue_id++) { |
| 170 | if (tm_queue_bitset[queue_id] == 0) { |
| 171 | tm_queue_bitset[queue_id] = 1; |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | bcmos_fastlock_unlock(&data_lock, 0); |
| 176 | |
| 177 | if (queue_id < MAX_TM_QUEUE_ID) { |
| 178 | bcmos_fastlock_lock(&data_lock); |
| 179 | queue_map[key] = queue_id; |
| 180 | bcmos_fastlock_unlock(&data_lock, 0); |
| 181 | return queue_id; |
| 182 | } else { |
| 183 | return -1; |
| 184 | } |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 187 | /** |
| 188 | * Update tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 189 | * |
| 190 | * @param intf_id NNI or PON intf ID |
| 191 | * @param onu_id ONU ID |
| 192 | * @param uni_id UNI ID |
| 193 | * @param gemport_id GEM Port ID |
| 194 | * @param direction Upstream or downstream |
| 195 | * @param tm_queue_id tm_queue_id |
| 196 | */ |
| 197 | void update_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction, |
| 198 | uint32_t queue_id) { |
| 199 | queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction); |
| 200 | bcmos_fastlock_lock(&data_lock); |
| 201 | queue_map[key] = queue_id; |
| 202 | bcmos_fastlock_unlock(&data_lock, 0); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Free tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 207 | * |
| 208 | * @param intf_id NNI or PON intf ID |
| 209 | * @param onu_id ONU ID |
| 210 | * @param uni_id UNI ID |
| 211 | * @param gemport_id GEM Port ID |
| 212 | * @param direction Upstream or downstream |
| 213 | */ |
| 214 | void free_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) { |
| 215 | queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction); |
| 216 | std::map<queue_map_key_tuple, int>::const_iterator it; |
| 217 | bcmos_fastlock_lock(&data_lock); |
| 218 | it = queue_map.find(key); |
| 219 | if (it != queue_map.end()) { |
| 220 | tm_queue_bitset[it->second] = 0; |
| 221 | queue_map.erase(it); |
| 222 | } |
| 223 | bcmos_fastlock_unlock(&data_lock, 0); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Gets a unique tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 228 | * The tm_sched_id is locally cached in a map, so that it can rendered when necessary. |
| 229 | * VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem |
| 230 | * |
| 231 | * @param intf_id NNI or PON intf ID |
| 232 | * @param onu_id ONU ID |
| 233 | * @param uni_id UNI ID |
| 234 | * @param gemport_id GEM Port ID |
| 235 | * @param direction Upstream or downstream |
| 236 | * |
| 237 | * @return tm_sched_id |
| 238 | */ |
| 239 | uint32_t get_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) { |
| 240 | sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction); |
| 241 | int sched_id = -1; |
| 242 | |
| 243 | std::map<sched_map_key_tuple, int>::const_iterator it = sched_map.find(key); |
| 244 | if (it != sched_map.end()) { |
| 245 | sched_id = it->second; |
| 246 | } |
| 247 | if (sched_id != -1) { |
| 248 | return sched_id; |
| 249 | } |
| 250 | |
| 251 | bcmos_fastlock_lock(&data_lock); |
| 252 | // Complexity of O(n). Is there better way that can avoid linear search? |
| 253 | for (sched_id = 0; sched_id < MAX_TM_SCHED_ID; sched_id++) { |
| 254 | if (tm_sched_bitset[sched_id] == 0) { |
| 255 | tm_sched_bitset[sched_id] = 1; |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | bcmos_fastlock_unlock(&data_lock, 0); |
| 260 | |
| 261 | if (sched_id < MAX_TM_SCHED_ID) { |
| 262 | bcmos_fastlock_lock(&data_lock); |
| 263 | sched_map[key] = sched_id; |
| 264 | bcmos_fastlock_unlock(&data_lock, 0); |
| 265 | return sched_id; |
| 266 | } else { |
| 267 | return -1; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Free tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 273 | * |
| 274 | * @param intf_id NNI or PON intf ID |
| 275 | * @param onu_id ONU ID |
| 276 | * @param uni_id UNI ID |
| 277 | * @param gemport_id GEM Port ID |
| 278 | * @param direction Upstream or downstream |
| 279 | */ |
| 280 | void free_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) { |
| 281 | sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction); |
| 282 | std::map<sched_map_key_tuple, int>::const_iterator it; |
| 283 | bcmos_fastlock_lock(&data_lock); |
| 284 | it = sched_map.find(key); |
| 285 | if (it != sched_map.end()) { |
| 286 | tm_sched_bitset[it->second] = 0; |
| 287 | sched_map.erase(it); |
| 288 | } |
| 289 | bcmos_fastlock_unlock(&data_lock, 0); |
| 290 | } |
| 291 | |
| 292 | bool is_tm_sched_id_present(int pon_intf_id, int onu_id, int uni_id, std::string direction) { |
| 293 | sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction); |
| 294 | return sched_map.count(key) > 0 ? true: false; |
| 295 | } |
| 296 | |
| 297 | bool is_tm_queue_id_present(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) { |
| 298 | queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction); |
| 299 | return queue_map.count(key) > 0 ? true: false; |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 302 | char* openolt_read_sysinfo(char* field_name, char* field_val) |
| 303 | { |
| 304 | FILE *fp; |
| 305 | /* Prepare the command*/ |
| 306 | char command[150]; |
| 307 | |
| 308 | snprintf(command, sizeof command, "bash -l -c \"onlpdump -s\" | perl -ne 'print $1 if /%s: (\\S+)/'", field_name); |
| 309 | /* Open the command for reading. */ |
| 310 | fp = popen(command, "r"); |
| 311 | if (fp == NULL) { |
| 312 | /*The client has to check for a Null field value in this case*/ |
| 313 | BCM_LOG(INFO, openolt_log_id, "Failed to query the %s\n", field_name); |
| 314 | return field_val; |
| 315 | } |
| 316 | |
| 317 | /*Read the field value*/ |
| 318 | if (fp) { |
| 319 | fread(field_val, OPENOLT_FIELD_LEN, 1, fp); |
| 320 | pclose(fp); |
| 321 | } |
| 322 | return field_val; |
| 323 | } |
| 324 | |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 325 | Status GetDeviceInfo_(openolt::DeviceInfo* device_info) { |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 326 | device_info->set_vendor(VENDOR_ID); |
| 327 | device_info->set_model(MODEL_ID); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 328 | device_info->set_hardware_version(""); |
| 329 | device_info->set_firmware_version(firmware_version); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 330 | device_info->set_technology(board_technology); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 331 | device_info->set_pon_ports(num_of_pon_ports); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 332 | |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 333 | char serial_number[OPENOLT_FIELD_LEN]; |
| 334 | memset(serial_number, '\0', OPENOLT_FIELD_LEN); |
| 335 | openolt_read_sysinfo("Serial Number", serial_number); |
| 336 | BCM_LOG(INFO, openolt_log_id, "Fetched device serial number %s\n", serial_number); |
| 337 | device_info->set_device_serial_number(serial_number); |
| 338 | |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 339 | // Legacy, device-wide ranges. To be deprecated when adapter |
| 340 | // is upgraded to support per-interface ranges |
| 341 | if (board_technology == "xgspon") { |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 342 | device_info->set_onu_id_start(1); |
| 343 | device_info->set_onu_id_end(255); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 344 | device_info->set_alloc_id_start(MIN_ALLOC_ID_XGSPON); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 345 | device_info->set_alloc_id_end(16383); |
| 346 | device_info->set_gemport_id_start(1024); |
| 347 | device_info->set_gemport_id_end(65535); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 348 | device_info->set_flow_id_start(1); |
| 349 | device_info->set_flow_id_end(16383); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 350 | } |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 351 | else if (board_technology == "gpon") { |
| 352 | device_info->set_onu_id_start(1); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 353 | device_info->set_onu_id_end(127); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 354 | device_info->set_alloc_id_start(MIN_ALLOC_ID_GPON); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 355 | device_info->set_alloc_id_end(767); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 356 | device_info->set_gemport_id_start(256); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 357 | device_info->set_gemport_id_end(4095); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 358 | device_info->set_flow_id_start(1); |
| 359 | device_info->set_flow_id_end(16383); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 360 | } |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 361 | |
| 362 | std::map<std::string, openolt::DeviceInfo::DeviceResourceRanges*> ranges; |
| 363 | for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) { |
| 364 | std::string intf_technology = intf_technologies[intf_id]; |
| 365 | openolt::DeviceInfo::DeviceResourceRanges *range = ranges[intf_technology]; |
| 366 | if(range == nullptr) { |
| 367 | range = device_info->add_ranges(); |
| 368 | ranges[intf_technology] = range; |
| 369 | range->set_technology(intf_technology); |
| 370 | |
| 371 | if (intf_technology == "xgspon") { |
| 372 | openolt::DeviceInfo::DeviceResourceRanges::Pool* pool; |
| 373 | |
| 374 | pool = range->add_pools(); |
| 375 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID); |
| 376 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 377 | pool->set_start(1); |
| 378 | pool->set_end(255); |
| 379 | |
| 380 | pool = range->add_pools(); |
| 381 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID); |
| 382 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH); |
| 383 | pool->set_start(1024); |
| 384 | pool->set_end(16383); |
| 385 | |
| 386 | pool = range->add_pools(); |
| 387 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID); |
| 388 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 389 | pool->set_start(1024); |
| 390 | pool->set_end(65535); |
| 391 | |
| 392 | pool = range->add_pools(); |
| 393 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID); |
| 394 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 395 | pool->set_start(1); |
| 396 | pool->set_end(16383); |
| 397 | } |
| 398 | else if (intf_technology == "gpon") { |
| 399 | openolt::DeviceInfo::DeviceResourceRanges::Pool* pool; |
| 400 | |
| 401 | pool = range->add_pools(); |
| 402 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID); |
| 403 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 404 | pool->set_start(1); |
| 405 | pool->set_end(127); |
| 406 | |
| 407 | pool = range->add_pools(); |
| 408 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID); |
| 409 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH); |
| 410 | pool->set_start(256); |
| 411 | pool->set_end(757); |
| 412 | |
| 413 | pool = range->add_pools(); |
| 414 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID); |
| 415 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 416 | pool->set_start(256); |
| 417 | pool->set_end(4095); |
| 418 | |
| 419 | pool = range->add_pools(); |
| 420 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID); |
| 421 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 422 | pool->set_start(1); |
| 423 | pool->set_end(16383); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | range->add_intf_ids(intf_id); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 428 | } |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 429 | |
| 430 | // FIXME: Once dependency problem is fixed |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 431 | // device_info->set_pon_ports(num_of_pon_ports); |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 432 | // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1); |
| 433 | // device_info->set_alloc_id_start(1024); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 434 | // 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] | 435 | // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 436 | // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1); |
| 437 | // device_info->set_pon_ports(num_of_pon_ports); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 438 | |
| 439 | return Status::OK; |
| 440 | } |
| 441 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 442 | Status Enable_(int argc, char *argv[]) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 443 | bcmbal_access_terminal_cfg acc_term_obj; |
| 444 | bcmbal_access_terminal_key key = { }; |
| 445 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 446 | if (!state.is_activated()) { |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 447 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 448 | vendor_init(); |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 449 | bcmbal_init(argc, argv, NULL); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 450 | bcmos_fastlock_init(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 451 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 452 | BCM_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID); |
| 453 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 454 | Status status = SubscribeIndication(); |
| 455 | if (!status.ok()) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 456 | BCM_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n", |
| 457 | grpc_status_code_to_string(status.error_code()).c_str(), |
| 458 | status.error_message().c_str()); |
| 459 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 460 | return status; |
| 461 | } |
| 462 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 463 | key.access_term_id = DEFAULT_ATERM_ID; |
| 464 | BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 465 | 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] | 466 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 467 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 468 | BCM_LOG(ERROR, openolt_log_id, "Failed to enable OLT\n"); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 469 | return bcm_to_grpc_err(err, "Failed to enable OLT"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 470 | } |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 471 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 472 | init_stats(); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 473 | } |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 474 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 475 | //If already enabled, generate an extra indication ???? |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 476 | return Status::OK; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | Status Disable_() { |
| 480 | // bcmbal_access_terminal_cfg acc_term_obj; |
| 481 | // bcmbal_access_terminal_key key = { }; |
| 482 | // |
| 483 | // if (state::is_activated) { |
| 484 | // std::cout << "Disable OLT" << std::endl; |
| 485 | // key.access_term_id = DEFAULT_ATERM_ID; |
| 486 | // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 487 | // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN); |
| 488 | // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 489 | // if (err) { |
| 490 | // std::cout << "ERROR: Failed to disable OLT" << std::endl; |
| 491 | // return bcm_to_grpc_err(err, "Failed to disable OLT"); |
| 492 | // } |
| 493 | // } |
| 494 | // //If already disabled, generate an extra indication ???? |
| 495 | // return Status::OK; |
| 496 | //This fails with Operation Not Supported, bug ??? |
| 497 | |
| 498 | //TEMPORARY WORK AROUND |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 499 | Status status = DisableUplinkIf_(nni_intf_id); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 500 | if (status.ok()) { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 501 | state.deactivate(); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 502 | openolt::Indication ind; |
| 503 | openolt::OltIndication* olt_ind = new openolt::OltIndication; |
| 504 | olt_ind->set_oper_state("down"); |
| 505 | ind.set_allocated_olt_ind(olt_ind); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 506 | 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] | 507 | oltIndQ.push(ind); |
| 508 | } |
| 509 | return status; |
| 510 | |
| 511 | } |
| 512 | |
| 513 | Status Reenable_() { |
| 514 | Status status = EnableUplinkIf_(0); |
| 515 | if (status.ok()) { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 516 | state.activate(); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 517 | openolt::Indication ind; |
| 518 | openolt::OltIndication* olt_ind = new openolt::OltIndication; |
| 519 | olt_ind->set_oper_state("up"); |
| 520 | ind.set_allocated_olt_ind(olt_ind); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 521 | 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] | 522 | oltIndQ.push(ind); |
| 523 | } |
| 524 | return status; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | Status EnablePonIf_(uint32_t intf_id) { |
| 528 | bcmbal_interface_cfg interface_obj; |
| 529 | bcmbal_interface_key interface_key; |
| 530 | |
| 531 | interface_key.intf_id = intf_id; |
| 532 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 533 | |
| 534 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 535 | |
| 536 | BCMBAL_CFG_PROP_GET(&interface_obj, interface, admin_state); |
| 537 | bcmos_errno err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 538 | if (err == BCM_ERR_OK && interface_obj.data.admin_state == BCMBAL_STATE_UP) { |
| 539 | BCM_LOG(DEBUG, openolt_log_id, "PON interface: %d already enabled\n", intf_id); |
| 540 | return Status::OK; |
| 541 | } |
| 542 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 543 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP); |
| 544 | |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 545 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 546 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 547 | 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] | 548 | return bcm_to_grpc_err(err, "Failed to enable PON interface"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | return Status::OK; |
| 552 | } |
| 553 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 554 | Status DisableUplinkIf_(uint32_t intf_id) { |
| 555 | bcmbal_interface_cfg interface_obj; |
| 556 | bcmbal_interface_key interface_key; |
| 557 | |
| 558 | interface_key.intf_id = intf_id; |
| 559 | interface_key.intf_type = BCMBAL_INTF_TYPE_NNI; |
| 560 | |
| 561 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 562 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN); |
| 563 | |
| 564 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 565 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 566 | 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] | 567 | return bcm_to_grpc_err(err, "Failed to disable Uplink interface"); |
| 568 | } |
| 569 | |
| 570 | return Status::OK; |
| 571 | } |
| 572 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 573 | Status ProbeDeviceCapabilities_() { |
| 574 | bcmbal_access_terminal_cfg acc_term_obj; |
| 575 | bcmbal_access_terminal_key key = { }; |
| 576 | |
| 577 | key.access_term_id = DEFAULT_ATERM_ID; |
| 578 | BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 579 | BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, admin_state); |
| 580 | BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, oper_status); |
| 581 | BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, topology); |
| 582 | BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, sw_version); |
| 583 | BCMBAL_CFG_PROP_GET(&acc_term_obj, access_terminal, conn_id); |
| 584 | bcmos_errno err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 585 | if (err) { |
| 586 | BCM_LOG(ERROR, openolt_log_id, "Failed to query OLT\n"); |
| 587 | return bcm_to_grpc_err(err, "Failed to query OLT"); |
| 588 | } |
| 589 | |
| 590 | BCM_LOG(INFO, openolt_log_id, "OLT capabilitites, admin_state: %s oper_state: %s\n", |
| 591 | acc_term_obj.data.admin_state == BCMBAL_STATE_UP ? "up" : "down", |
| 592 | acc_term_obj.data.oper_status == BCMBAL_STATUS_UP ? "up" : "down"); |
| 593 | |
| 594 | std::string bal_version; |
| 595 | bal_version += std::to_string(acc_term_obj.data.sw_version.major_rev) |
| 596 | + "." + std::to_string(acc_term_obj.data.sw_version.minor_rev) |
| 597 | + "." + std::to_string(acc_term_obj.data.sw_version.release_rev); |
| 598 | firmware_version = "BAL." + bal_version + "__" + firmware_version; |
| 599 | |
| 600 | BCM_LOG(INFO, openolt_log_id, "--------------- version %s object model: %d\n", bal_version.c_str(), |
| 601 | acc_term_obj.data.sw_version.om_version); |
| 602 | |
| 603 | BCM_LOG(INFO, openolt_log_id, "--------------- topology nni:%d pon:%d dev:%d ppd:%d family: %d:%d\n", |
| 604 | acc_term_obj.data.topology.num_of_nni_ports, |
| 605 | acc_term_obj.data.topology.num_of_pon_ports, |
| 606 | acc_term_obj.data.topology.num_of_mac_devs, |
| 607 | acc_term_obj.data.topology.num_of_pons_per_mac_dev, |
| 608 | acc_term_obj.data.topology.pon_family, |
| 609 | acc_term_obj.data.topology.pon_sub_family |
| 610 | ); |
| 611 | |
| 612 | switch(acc_term_obj.data.topology.pon_sub_family) |
| 613 | { |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 614 | case BCMBAL_PON_SUB_FAMILY_GPON: board_technology = "gpon"; break; |
| 615 | case BCMBAL_PON_SUB_FAMILY_XGS: board_technology = "xgspon"; break; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | num_of_nni_ports = acc_term_obj.data.topology.num_of_nni_ports; |
| 619 | num_of_pon_ports = acc_term_obj.data.topology.num_of_pon_ports; |
| 620 | |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 621 | 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] | 622 | |
| 623 | return Status::OK; |
| 624 | } |
| 625 | |
| 626 | Status ProbePonIfTechnology_() { |
| 627 | // Probe maximum extent possible as configured into BAL driver to determine |
| 628 | // which are active in the current BAL topology. And for those |
| 629 | // that are active, determine each port's access technology, i.e. "gpon" or "xgspon". |
| 630 | for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) { |
| 631 | bcmbal_interface_cfg interface_obj; |
| 632 | bcmbal_interface_key interface_key; |
| 633 | |
| 634 | interface_key.intf_id = intf_id; |
| 635 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 636 | |
| 637 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 638 | BCMBAL_CFG_PROP_GET(&interface_obj, interface, admin_state); |
| 639 | BCMBAL_CFG_PROP_GET(&interface_obj, interface, transceiver_type); |
| 640 | |
| 641 | bcmos_errno err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 642 | if (err != BCM_ERR_OK) { |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 643 | intf_technologies[intf_id] = UNKNOWN_TECH; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 644 | if(err != BCM_ERR_RANGE) BCM_LOG(ERROR, openolt_log_id, "Failed to get PON config: %d\n", intf_id); |
| 645 | } |
| 646 | else { |
| 647 | switch(interface_obj.data.transceiver_type) { |
| 648 | case BCMBAL_TRX_TYPE_GPON_SPS_43_48: |
| 649 | case BCMBAL_TRX_TYPE_GPON_SPS_SOG_4321: |
| 650 | case BCMBAL_TRX_TYPE_GPON_LTE_3680_M: |
| 651 | case BCMBAL_TRX_TYPE_GPON_SOURCE_PHOTONICS: |
| 652 | case BCMBAL_TRX_TYPE_GPON_LTE_3680_P: |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 653 | intf_technologies[intf_id] = "gpon"; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 654 | break; |
| 655 | default: |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 656 | intf_technologies[intf_id] = "xgspon"; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 657 | break; |
| 658 | } |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 659 | BCM_LOG(INFO, openolt_log_id, "PON intf_id: %d intf_technologies: %d:%s\n", intf_id, |
| 660 | interface_obj.data.transceiver_type, intf_technologies[intf_id].c_str()); |
| 661 | |
| 662 | if (board_technology != UNKNOWN_TECH) { |
| 663 | board_technology = intf_technologies[intf_id]; |
| 664 | } else if (board_technology != MIXED_TECH && board_technology != intf_technologies[intf_id]) { |
| 665 | intf_technologies[intf_id] = MIXED_TECH; |
| 666 | } |
| 667 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
| 671 | return Status::OK; |
| 672 | } |
| 673 | |
| 674 | unsigned NumNniIf_() {return num_of_nni_ports;} |
| 675 | unsigned NumPonIf_() {return num_of_pon_ports;} |
| 676 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 677 | Status EnableUplinkIf_(uint32_t intf_id) { |
| 678 | bcmbal_interface_cfg interface_obj; |
| 679 | bcmbal_interface_key interface_key; |
| 680 | |
| 681 | interface_key.intf_id = intf_id; |
| 682 | interface_key.intf_type = BCMBAL_INTF_TYPE_NNI; |
| 683 | |
| 684 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 685 | |
| 686 | BCMBAL_CFG_PROP_GET(&interface_obj, interface, admin_state); |
| 687 | bcmos_errno err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 688 | if (err == BCM_ERR_OK && interface_obj.data.admin_state == BCMBAL_STATE_UP) { |
| 689 | BCM_LOG(DEBUG, openolt_log_id, "Uplink interface: %d already enabled\n", intf_id); |
| 690 | return Status::OK; |
| 691 | } |
| 692 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 693 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP); |
| 694 | |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 695 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 696 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 697 | 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] | 698 | return bcm_to_grpc_err(err, "Failed to enable Uplink interface"); |
| 699 | } |
| 700 | |
| 701 | return Status::OK; |
| 702 | } |
| 703 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 704 | Status DisablePonIf_(uint32_t intf_id) { |
| 705 | bcmbal_interface_cfg interface_obj; |
| 706 | bcmbal_interface_key interface_key; |
| 707 | |
| 708 | interface_key.intf_id = intf_id; |
| 709 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 710 | |
| 711 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 712 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN); |
| 713 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 714 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 715 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 716 | 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] | 717 | return bcm_to_grpc_err(err, "Failed to disable PON interface"); |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | return Status::OK; |
| 721 | } |
| 722 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 723 | Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 724 | const char *vendor_id, const char *vendor_specific, uint32_t pir) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 725 | |
| 726 | bcmbal_subscriber_terminal_cfg sub_term_obj = {}; |
| 727 | bcmbal_subscriber_terminal_key subs_terminal_key; |
| 728 | bcmbal_serial_number serial_num = {}; |
| 729 | bcmbal_registration_id registration_id = {}; |
| 730 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 731 | BCM_LOG(INFO, openolt_log_id, "Enabling ONU %d on PON %d : vendor id %s, vendor specific %s, pir %d\n", |
| 732 | 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] | 733 | |
| 734 | subs_terminal_key.sub_term_id = onu_id; |
| 735 | subs_terminal_key.intf_id = intf_id; |
| 736 | BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key); |
| 737 | |
| 738 | memcpy(serial_num.vendor_id, vendor_id, 4); |
| 739 | memcpy(serial_num.vendor_specific, vendor_specific, 4); |
| 740 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num); |
| 741 | |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 742 | #if 0 |
| 743 | // Commenting out as this is causing issues with onu activation |
| 744 | // with BAL 2.6 (Broadcom CS5248819). |
| 745 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 746 | // FIXME - Use a default (all zeros) registration id. |
| 747 | memset(registration_id.arr, 0, sizeof(registration_id.arr)); |
| 748 | 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] | 749 | #endif |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 750 | |
| 751 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP); |
| 752 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 753 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr)); |
| 754 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 755 | 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] | 756 | return bcm_to_grpc_err(err, "Failed to enable ONU"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 757 | } |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 758 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 761 | Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id, |
| 762 | const char *vendor_id, const char *vendor_specific) { |
| 763 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 764 | bcmbal_subscriber_terminal_cfg sub_term_obj = {}; |
| 765 | bcmbal_subscriber_terminal_key subs_terminal_key; |
| 766 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 767 | 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] | 768 | 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] | 769 | |
| 770 | subs_terminal_key.sub_term_id = onu_id; |
| 771 | subs_terminal_key.intf_id = intf_id; |
| 772 | BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key); |
| 773 | |
| 774 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN); |
| 775 | |
| 776 | if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 777 | 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] | 778 | return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU"); |
| 779 | } |
| 780 | |
| 781 | return Status::OK; |
| 782 | } |
| 783 | |
| 784 | Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 785 | const char *vendor_id, const char *vendor_specific) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 786 | |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 787 | BCM_LOG(INFO, openolt_log_id, "DeleteOnu ONU %d on PON %d : vendor id %s, vendor specific %s\n", |
| 788 | onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str()); |
| 789 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 790 | // Need to deactivate before removing it (BAL rules) |
| 791 | |
| 792 | DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific); |
| 793 | // Sleep to allow the state to propagate |
| 794 | // We need the subscriber terminal object to be admin down before removal |
| 795 | // Without sleep the race condition is lost by ~ 20 ms |
| 796 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 797 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 798 | // TODO: Delete the schedulers and queues. |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 799 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 800 | bcmos_errno err = BCM_ERR_OK; |
| 801 | bcmbal_subscriber_terminal_cfg cfg; |
| 802 | bcmbal_subscriber_terminal_key key = { }; |
| 803 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 804 | BCM_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n", |
| 805 | onu_id, intf_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 806 | |
| 807 | key.sub_term_id = onu_id ; |
| 808 | key.intf_id = intf_id ; |
| 809 | |
| 810 | if (0 == key.sub_term_id) |
| 811 | { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 812 | BCM_LOG(INFO, openolt_log_id,"Invalid Key to handle subscriber terminal clear subscriber_terminal_id %d, \ |
| 813 | Interface ID %d\n", onu_id, intf_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 814 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 815 | } |
| 816 | |
| 817 | BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key); |
| 818 | |
| 819 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr); |
| 820 | if (err != BCM_ERR_OK) |
| 821 | { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 822 | BCM_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n", |
| 823 | onu_id, intf_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 824 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 825 | } |
| 826 | |
| 827 | return Status::OK;; |
| 828 | } |
| 829 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 830 | #define MAX_CHAR_LENGTH 20 |
| 831 | #define MAX_OMCI_MSG_LENGTH 44 |
| 832 | Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
| 833 | bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */ |
| 834 | bcmos_errno err = BCM_ERR_OK; |
| 835 | |
| 836 | /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */ |
| 837 | bcmbal_dest proxy_pkt_dest; |
| 838 | |
| 839 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL; |
| 840 | proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id; |
| 841 | proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id; |
| 842 | |
| 843 | // ??? |
| 844 | if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) { |
| 845 | buf.len = MAX_OMCI_MSG_LENGTH; |
| 846 | } else { |
| 847 | buf.len = pkt.size()/2; |
| 848 | } |
| 849 | |
| 850 | /* Send the OMCI packet using the BAL remote proxy API */ |
| 851 | uint16_t idx1 = 0; |
| 852 | uint16_t idx2 = 0; |
| 853 | uint8_t arraySend[buf.len]; |
| 854 | char str1[MAX_CHAR_LENGTH]; |
| 855 | char str2[MAX_CHAR_LENGTH]; |
| 856 | memset(&arraySend, 0, buf.len); |
| 857 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 858 | for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) { |
| 859 | sprintf(str1,"%c", pkt[idx1]); |
| 860 | sprintf(str2,"%c", pkt[++idx1]); |
| 861 | strcat(str1,str2); |
| 862 | arraySend[idx2] = strtol(str1, NULL, 16); |
| 863 | } |
| 864 | |
| 865 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 866 | memcpy(buf.val, (uint8_t *)arraySend, buf.len); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 867 | |
| 868 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 869 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 870 | if (err) { |
| 871 | BCM_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id); |
| 872 | } else { |
| 873 | 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] | 874 | buf.len, onu_id, intf_id, pkt.c_str()); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 875 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 876 | |
| 877 | free(buf.val); |
| 878 | |
| 879 | return Status::OK; |
| 880 | } |
| 881 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 882 | Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, uint32_t port_no, uint32_t gemport_id, const std::string pkt) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 883 | bcmos_errno err = BCM_ERR_OK; |
| 884 | bcmbal_dest proxy_pkt_dest; |
| 885 | bcmbal_u8_list_u32_max_2048 buf; |
| 886 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 887 | if (port_no > 0) { |
| 888 | bool found = false; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 889 | if (gemport_id == 0) { |
| 890 | bcmos_fastlock_lock(&data_lock); |
| 891 | // Map the port_no to one of the flows that owns it to find a gemport_id for that flow. |
| 892 | // Pick any flow that is mapped with the same port_no. |
| 893 | std::map<uint32_t, std::set<uint32_t> >::const_iterator it = port_to_flows.find(port_no); |
| 894 | if (it != port_to_flows.end() && !it->second.empty()) { |
| 895 | uint32_t flow_id = *(it->second.begin()); // Pick any flow_id out of the bag set |
| 896 | std::map<uint32_t, uint32_t>::const_iterator fit = flowid_to_gemport.find(flow_id); |
| 897 | if (fit != flowid_to_gemport.end()) { |
| 898 | found = true; |
| 899 | gemport_id = fit->second; |
| 900 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 901 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 902 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 903 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 904 | if (!found) { |
| 905 | BCM_LOG(ERROR, openolt_log_id, "Packet out failed to find destination for ONU %d port_no %u on PON %d\n", |
| 906 | onu_id, port_no, intf_id); |
| 907 | return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow for port_no"); |
| 908 | } |
| 909 | BCM_LOG(INFO, openolt_log_id, "Gem port %u found for ONU %d port_no %u on PON %d\n", |
| 910 | gemport_id, onu_id, port_no, intf_id); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SVC_PORT; |
| 914 | proxy_pkt_dest.u.svc_port.svc_port_id = gemport_id; |
| 915 | proxy_pkt_dest.u.svc_port.intf_id = intf_id; |
| 916 | BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent to gemport %d on pon %d port_no %u\n", |
| 917 | pkt.size(), gemport_id, intf_id, port_no); |
| 918 | } |
| 919 | else { |
| 920 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM, |
| 921 | proxy_pkt_dest.u.sub_term.sub_term_id = onu_id; |
| 922 | proxy_pkt_dest.u.sub_term.intf_id = intf_id; |
| 923 | BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent to onu %d on pon %d\n", |
| 924 | pkt.size(), onu_id, intf_id); |
| 925 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 926 | |
| 927 | buf.len = pkt.size(); |
| 928 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 929 | memcpy(buf.val, (uint8_t *)pkt.data(), buf.len); |
| 930 | |
| 931 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 932 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 933 | free(buf.val); |
| 934 | |
| 935 | return Status::OK; |
| 936 | } |
| 937 | |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 938 | Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) { |
| 939 | bcmos_errno err = BCM_ERR_OK; |
| 940 | bcmbal_dest proxy_pkt_dest; |
| 941 | bcmbal_u8_list_u32_max_2048 buf; |
| 942 | |
| 943 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI, |
| 944 | proxy_pkt_dest.u.nni.intf_id = intf_id; |
| 945 | |
| 946 | buf.len = pkt.size(); |
| 947 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 948 | memcpy(buf.val, (uint8_t *)pkt.data(), buf.len); |
| 949 | |
| 950 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 951 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 952 | BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent through uplink port %d\n", |
| 953 | buf.len, intf_id); |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 954 | |
| 955 | free(buf.val); |
| 956 | |
| 957 | return Status::OK; |
| 958 | } |
| 959 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 960 | uint32_t GetPortNum_(uint32_t flow_id) |
| 961 | { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 962 | bcmos_fastlock_lock(&data_lock); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 963 | uint32_t port_no = 0; |
| 964 | std::map<uint32_t, uint32_t >::const_iterator it = flowid_to_port.find(flow_id); |
| 965 | if (it != flowid_to_port.end()) { |
| 966 | port_no = it->second; |
| 967 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 968 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 969 | return port_no; |
| 970 | } |
| 971 | |
| 972 | 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] | 973 | uint32_t flow_id, const std::string flow_type, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 974 | int32_t alloc_id, int32_t network_intf_id, |
| 975 | int32_t gemport_id, const ::openolt::Classifier& classifier, |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 976 | const ::openolt::Action& action, int32_t priority_value, uint64_t cookie) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 977 | bcmos_errno err; |
| 978 | bcmbal_flow_cfg cfg; |
| 979 | bcmbal_flow_key key = { }; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 980 | int32_t o_vid = -1; |
| 981 | bool single_tag = false; |
| 982 | uint32_t ether_type = 0; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 983 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 984 | 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, \ |
| 985 | gemport_id %d, network_intf_id %d, cookie %llu\n", \ |
| 986 | 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] | 987 | |
| 988 | key.flow_id = flow_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 989 | if (flow_type.compare(upstream) == 0 ) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 990 | key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 991 | } else if (flow_type.compare(downstream) == 0) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 992 | key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM; |
| 993 | } else { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 994 | 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] | 995 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | BCMBAL_CFG_INIT(&cfg, flow, key); |
| 999 | |
| 1000 | BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1001 | BCMBAL_CFG_PROP_SET(&cfg, flow, cookie, cookie); |
| 1002 | |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1003 | if (access_intf_id >= 0) { |
| 1004 | BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id); |
| 1005 | } |
| 1006 | if (network_intf_id >= 0) { |
| 1007 | BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id); |
| 1008 | } |
| 1009 | if (onu_id >= 0) { |
| 1010 | BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id); |
| 1011 | } |
| 1012 | if (gemport_id >= 0) { |
| 1013 | BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id); |
| 1014 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1015 | if (gemport_id >= 0 && port_no != 0) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1016 | bcmos_fastlock_lock(&data_lock); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1017 | if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) { |
| 1018 | port_to_flows[port_no].insert(key.flow_id); |
| 1019 | flowid_to_gemport[key.flow_id] = gemport_id; |
| 1020 | } |
| 1021 | else |
| 1022 | { |
| 1023 | flowid_to_port[key.flow_id] = port_no; |
| 1024 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1025 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1026 | } |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1027 | if (priority_value >= 0) { |
| 1028 | BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value); |
| 1029 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1030 | |
| 1031 | { |
| 1032 | bcmbal_classifier val = { }; |
| 1033 | |
| 1034 | if (classifier.o_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1035 | 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] | 1036 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_tpid, classifier.o_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | if (classifier.o_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1040 | 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] | 1041 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_vid, classifier.o_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | if (classifier.i_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1045 | 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] | 1046 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, i_tpid, classifier.i_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | if (classifier.i_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1050 | 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] | 1051 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, i_vid, classifier.i_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1054 | if (classifier.eth_type()) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1055 | ether_type = classifier.eth_type(); |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1056 | 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] | 1057 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, ether_type, classifier.eth_type()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /* |
| 1061 | if (classifier.dst_mac()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1062 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_mac, classifier.dst_mac()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | if (classifier.src_mac()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1066 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_mac, classifier.src_mac()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1067 | } |
| 1068 | */ |
| 1069 | |
| 1070 | if (classifier.ip_proto()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1071 | 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] | 1072 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, ip_proto, classifier.ip_proto()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | if (classifier.dst_ip()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1077 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_ip, classifier.dst_ip()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | if (classifier.src_ip()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1081 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_ip, classifier.src_ip()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1082 | } |
| 1083 | */ |
| 1084 | |
| 1085 | if (classifier.src_port()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1086 | 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] | 1087 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_port, classifier.src_port()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | if (classifier.dst_port()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1091 | 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] | 1092 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_port, classifier.dst_port()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | if (!classifier.pkt_tag_type().empty()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1096 | 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] | 1097 | if (classifier.pkt_tag_type().compare("untagged") == 0) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1098 | 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] | 1099 | } else if (classifier.pkt_tag_type().compare("single_tag") == 0) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1100 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, pkt_tag_type, BCMBAL_PKT_TAG_TYPE_SINGLE_TAG); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1101 | single_tag = true; |
| 1102 | |
| 1103 | BCM_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits()); |
| 1104 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_pbits, classifier.o_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1105 | } else if (classifier.pkt_tag_type().compare("double_tag") == 0) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1106 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, pkt_tag_type, BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1107 | |
| 1108 | BCM_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits()); |
| 1109 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_pbits, classifier.o_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val); |
| 1114 | } |
| 1115 | |
| 1116 | { |
| 1117 | bcmbal_action val = { }; |
| 1118 | |
| 1119 | const ::openolt::ActionCmd& cmd = action.cmd(); |
| 1120 | |
| 1121 | if (cmd.add_outer_tag()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1122 | BCM_LOG(INFO, openolt_log_id, "action add o_tag\n"); |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1123 | 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] | 1124 | } |
| 1125 | |
| 1126 | if (cmd.remove_outer_tag()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1127 | BCM_LOG(INFO, openolt_log_id, "action pop o_tag\n"); |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1128 | 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] | 1129 | } |
| 1130 | |
| 1131 | if (cmd.trap_to_host()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1132 | BCM_LOG(INFO, openolt_log_id, "action trap-to-host\n"); |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1133 | 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] | 1134 | } |
| 1135 | |
| 1136 | if (action.o_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1137 | BCM_LOG(INFO, openolt_log_id, "action o_vid=%d\n", action.o_vid()); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1138 | o_vid = action.o_vid(); |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1139 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, o_vid, action.o_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | if (action.o_pbits()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1143 | 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] | 1144 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, o_pbits, action.o_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | if (action.o_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1148 | 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] | 1149 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, o_tpid, action.o_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | if (action.i_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1153 | 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] | 1154 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, i_vid, action.i_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | if (action.i_pbits()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1158 | 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] | 1159 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, i_pbits, action.i_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | if (action.i_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1163 | 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] | 1164 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, i_tpid, action.i_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | BCMBAL_CFG_PROP_SET(&cfg, flow, action, val); |
| 1168 | } |
| 1169 | |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1170 | if ((access_intf_id >= 0) && (onu_id >= 0)) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1171 | |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1172 | if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) { |
| 1173 | bcmbal_tm_queue_ref val = { }; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1174 | if (single_tag && ether_type == EAP_ETHER_TYPE) { |
| 1175 | val.sched_id = get_default_tm_sched_id(access_intf_id, downstream); |
| 1176 | val.queue_id = 0; |
| 1177 | |
| 1178 | } else { |
| 1179 | val.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, downstream); // Subscriber Scheduler |
| 1180 | val.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, downstream); |
| 1181 | } |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1182 | BCM_LOG(INFO, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d\n", \ |
| 1183 | downstream.c_str(), val.queue_id, val.sched_id); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1184 | BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1185 | } else if (key.flow_type == BCMBAL_FLOW_TYPE_UPSTREAM) { |
| 1186 | bcmbal_tm_sched_id val1; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1187 | val1 = get_tm_sched_id(access_intf_id, onu_id, uni_id, upstream); // DBA Scheduler ID |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1188 | BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val1); |
| 1189 | |
| 1190 | bcmbal_tm_queue_ref val2 = { }; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1191 | val2.sched_id = get_default_tm_sched_id(network_intf_id, upstream); // NNI Scheduler ID |
Girish Gowdru | e1b5d56 | 2019-04-18 22:43:32 -0700 | [diff] [blame] | 1192 | val2.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, upstream); // Queue on NNI |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1193 | BCM_LOG(INFO, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d\n", \ |
| 1194 | upstream.c_str(), val2.queue_id, val2.sched_id); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1195 | BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val2); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1196 | } |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 1199 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
| 1200 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1201 | BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n"); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 1202 | return bcm_to_grpc_err(err, "flow add failed"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Nicolas Palpacuer | 6a63ea9 | 2018-09-05 17:21:37 -0400 | [diff] [blame] | 1205 | // register_new_flow(key); |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 1206 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1207 | return Status::OK; |
| 1208 | } |
| 1209 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1210 | Status FlowRemove_(uint32_t flow_id, const std::string flow_type) { |
| 1211 | |
| 1212 | bcmbal_flow_cfg cfg; |
| 1213 | bcmbal_flow_key key = { }; |
| 1214 | |
| 1215 | key.flow_id = (bcmbal_flow_id) flow_id; |
| 1216 | key.flow_id = flow_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1217 | if (flow_type.compare(upstream) == 0 ) { |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1218 | key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1219 | } else if (flow_type.compare(downstream) == 0) { |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1220 | key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM; |
| 1221 | } else { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1222 | 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] | 1223 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
| 1224 | } |
| 1225 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1226 | bcmos_fastlock_lock(&data_lock); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1227 | uint32_t port_no = flowid_to_port[key.flow_id]; |
| 1228 | if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) { |
| 1229 | flowid_to_gemport.erase(key.flow_id); |
| 1230 | port_to_flows[port_no].erase(key.flow_id); |
| 1231 | if (port_to_flows[port_no].empty()) port_to_flows.erase(port_no); |
| 1232 | } |
| 1233 | else |
| 1234 | { |
| 1235 | flowid_to_port.erase(key.flow_id); |
| 1236 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1237 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1238 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1239 | BCMBAL_CFG_INIT(&cfg, flow, key); |
| 1240 | |
| 1241 | |
| 1242 | bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr); |
| 1243 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1244 | BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n", |
| 1245 | err, flow_id, flow_type.c_str()); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1246 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow"); |
| 1247 | } |
| 1248 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1249 | 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] | 1250 | return Status::OK; |
| 1251 | } |
| 1252 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1253 | bcmos_errno CreateSched(std::string direction, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t port_no, |
| 1254 | uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, uint32_t priority, |
| 1255 | tech_profile::SchedulingPolicy sched_policy, tech_profile::TrafficShapingInfo tf_sh_info) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1256 | |
| 1257 | bcmos_errno err; |
| 1258 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1259 | if (direction == downstream) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1260 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1261 | bcmbal_tm_sched_cfg cfg; |
| 1262 | bcmbal_tm_sched_key key = { }; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1263 | key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction); |
| 1264 | key.dir = BCMBAL_TM_SCHED_DIR_DS; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1265 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1266 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 1267 | |
| 1268 | { |
| 1269 | // bcmbal_tm_sched_owner |
| 1270 | // In downstream it is sub_term scheduler |
| 1271 | bcmbal_tm_sched_owner tm_sched_owner = { }; |
| 1272 | tm_sched_owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM; |
| 1273 | tm_sched_owner.u.sub_term.intf_id = intf_id; |
| 1274 | tm_sched_owner.u.sub_term.sub_term_id = onu_id; |
| 1275 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, tm_sched_owner); |
| 1276 | |
| 1277 | // bcmbal_tm_sched_type |
| 1278 | // set the deafult policy to strict priority |
| 1279 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_SP); |
| 1280 | |
| 1281 | // bcmbal_tm_sched_parent |
| 1282 | // The parent for the sub_term scheduler is the PON scheduler in the downstream |
| 1283 | bcmbal_tm_sched_parent tm_sched_parent = { }; |
| 1284 | tm_sched_parent.presence_mask |= (BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID); |
| 1285 | tm_sched_parent.sched_id = get_default_tm_sched_id(intf_id, downstream); |
| 1286 | tm_sched_parent.presence_mask |= (BCMBAL_TM_SCHED_PARENT_ID_PRIORITY); |
| 1287 | tm_sched_parent.priority = 1; // TODO: Hardcoded priority as 1 |
| 1288 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, tm_sched_parent); |
| 1289 | |
| 1290 | // num_priorities: Max number of strict priority scheduling elements |
| 1291 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, num_priorities, 8); // TODO: hardcoded 8 priorities. |
| 1292 | |
| 1293 | // bcmbal_tm_shaping |
| 1294 | if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) { |
| 1295 | bcmbal_tm_shaping rate = {}; |
| 1296 | uint32_t cir = tf_sh_info.cir(); |
| 1297 | uint32_t pir = tf_sh_info.pir(); |
| 1298 | uint32_t burst = tf_sh_info.pbs(); |
| 1299 | BCM_LOG(INFO, openolt_log_id, "applying traffic shaping in DL cir=%u, pir=%u, burst=%u\n", |
| 1300 | cir, pir, burst); |
| 1301 | rate.presence_mask = BCMBAL_TM_SHAPING_ID_NONE; |
| 1302 | rate.presence_mask |= BCMBAL_TM_SHAPING_ID_PIR; |
| 1303 | rate.presence_mask |= BCMBAL_TM_SHAPING_ID_BURST; |
| 1304 | // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet' |
| 1305 | // rate.cir = cir; |
| 1306 | rate.pir = pir; |
| 1307 | rate.burst = burst; |
| 1308 | |
Girish Gowdru | e1b5d56 | 2019-04-18 22:43:32 -0700 | [diff] [blame] | 1309 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, rate); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | // creation_mode |
| 1313 | // BCMBAL_CFG_PROP_SET(&cfg, tm_sched, creation_mode, BCMBAL_TM_CREATION_MODE_MANUAL); |
| 1314 | } |
| 1315 | |
| 1316 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
| 1317 | if (err) { |
| 1318 | BCM_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, intf_id %d, \ |
| 1319 | onu_id %d, uni_id %d, port_no %u\n", key.id, intf_id, onu_id,uni_id,port_no); |
| 1320 | return err; |
| 1321 | } |
| 1322 | BCM_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \ |
| 1323 | uni_id %d, port_no %u\n", key.id,intf_id,onu_id,uni_id,port_no); |
| 1324 | |
| 1325 | } else { //upstream |
| 1326 | bcmbal_tm_sched_cfg cfg; |
| 1327 | bcmbal_tm_sched_key key = { }; |
| 1328 | |
| 1329 | key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1330 | key.dir = BCMBAL_TM_SCHED_DIR_US; |
| 1331 | |
| 1332 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 1333 | |
| 1334 | { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1335 | // bcmbal_tm_sched_owner: AGG PORT |
| 1336 | bcmbal_tm_sched_owner tm_sched_owner = { }; |
| 1337 | tm_sched_owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT; |
| 1338 | tm_sched_owner.u.agg_port.presence_mask |= bcmbal_tm_sched_owner_agg_port_id_all; |
| 1339 | tm_sched_owner.u.agg_port.intf_id = intf_id; |
| 1340 | tm_sched_owner.u.agg_port.sub_term_id = onu_id; |
| 1341 | tm_sched_owner.u.agg_port.agg_port_id = alloc_id; |
| 1342 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, tm_sched_owner); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1343 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1344 | // bcmbal_tm_shaping |
| 1345 | if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) { |
| 1346 | bcmbal_tm_shaping rate = {}; |
| 1347 | uint32_t cir = tf_sh_info.cir(); |
| 1348 | uint32_t pir = tf_sh_info.pir(); |
| 1349 | uint32_t burst = tf_sh_info.pbs(); |
| 1350 | BCM_LOG(INFO, openolt_log_id, "applying traffic shaping in UL cir=%u, pir=%u, burst=%u\n", |
| 1351 | cir, pir, burst); |
| 1352 | rate.presence_mask = BCMBAL_TM_SHAPING_ID_ALL; |
| 1353 | rate.cir = cir; |
| 1354 | rate.pir = pir; |
| 1355 | rate.burst = burst; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1356 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1357 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, rate); |
| 1358 | } |
Girish Gowdru | e075c64 | 2019-01-23 04:05:53 -0800 | [diff] [blame] | 1359 | } |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1360 | |
| 1361 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
| 1362 | if (err) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1363 | BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, id %d, intf_id %d, onu_id %d, uni_id %d,\ |
| 1364 | port_no %u, alloc_id %d\n", key.id, intf_id, onu_id,uni_id,port_no,alloc_id); |
| 1365 | return err; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1366 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1367 | BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, id %d, intf_id %d, onu_id %d, uni_id %d, port_no %u, \ |
| 1368 | alloc_id %d\n", key.id,intf_id,onu_id,uni_id,port_no,alloc_id); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1371 | return BCM_ERR_OK; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1372 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1373 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1374 | Status CreateTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) { |
| 1375 | uint32_t intf_id = traffic_scheds->intf_id(); |
| 1376 | uint32_t onu_id = traffic_scheds->onu_id(); |
| 1377 | uint32_t uni_id = traffic_scheds->uni_id(); |
| 1378 | uint32_t port_no = traffic_scheds->port_no(); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1379 | std::string direction; |
| 1380 | unsigned int alloc_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1381 | tech_profile::SchedulerConfig sched_config; |
| 1382 | tech_profile::AdditionalBW additional_bw; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1383 | uint32_t priority; |
| 1384 | uint32_t weight; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1385 | tech_profile::SchedulingPolicy sched_policy; |
| 1386 | tech_profile::TrafficShapingInfo traffic_shaping_info; |
| 1387 | bcmos_errno err; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1388 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1389 | for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) { |
| 1390 | tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i); |
| 1391 | if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) { |
| 1392 | direction = upstream; |
| 1393 | } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1394 | direction = downstream; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1395 | } |
| 1396 | else { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1397 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_sched.direction()); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1398 | return Status::CANCELLED; |
| 1399 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1400 | alloc_id = traffic_sched.alloc_id(); |
| 1401 | sched_config = traffic_sched.scheduler(); |
| 1402 | additional_bw = sched_config.additional_bw(); |
| 1403 | priority = sched_config.priority(); |
| 1404 | weight = sched_config.weight(); |
| 1405 | sched_policy = sched_config.sched_policy(); |
| 1406 | traffic_shaping_info = traffic_sched.traffic_shaping_info(); |
| 1407 | err = CreateSched(direction, intf_id, onu_id, uni_id, port_no, alloc_id, additional_bw, weight, priority, |
| 1408 | sched_policy, traffic_shaping_info); |
| 1409 | if (err) { |
| 1410 | return bcm_to_grpc_err(err, "Failed to create scheduler"); |
| 1411 | } |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 1412 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1413 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1414 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1415 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1416 | bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, std::string direction) { |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1417 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1418 | bcmos_errno err; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1419 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1420 | bcmbal_tm_sched_cfg tm_cfg_us; |
| 1421 | bcmbal_tm_sched_key tm_key_us = { }; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1422 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1423 | if (is_tm_sched_id_present(intf_id, onu_id, uni_id, direction)) { |
| 1424 | tm_key_us.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction); |
| 1425 | } else { |
| 1426 | BCM_LOG(INFO, openolt_log_id, "schduler not present in %s\n", direction.c_str()); |
| 1427 | return BCM_ERR_OK; |
| 1428 | } |
| 1429 | if (direction == upstream) { |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1430 | tm_key_us.dir = BCMBAL_TM_SCHED_DIR_US; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1431 | } else { |
| 1432 | tm_key_us.dir = BCMBAL_TM_SCHED_DIR_DS; |
| 1433 | } |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1434 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1435 | BCMBAL_CFG_INIT(&tm_cfg_us, tm_sched, tm_key_us); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1436 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1437 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_us.hdr)); |
| 1438 | if (err) { |
| 1439 | BCM_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \ |
| 1440 | direction.c_str(), tm_key_us.id, intf_id, onu_id); |
| 1441 | return err; |
| 1442 | } |
| 1443 | |
| 1444 | free_tm_sched_id(intf_id, onu_id, uni_id, direction); |
| 1445 | |
| 1446 | BCM_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \ |
| 1447 | direction.c_str(), tm_key_us.id, intf_id, onu_id); |
| 1448 | |
| 1449 | return BCM_ERR_OK; |
| 1450 | } |
| 1451 | |
| 1452 | Status RemoveTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) { |
| 1453 | uint32_t intf_id = traffic_scheds->intf_id(); |
| 1454 | uint32_t onu_id = traffic_scheds->onu_id(); |
| 1455 | uint32_t uni_id = traffic_scheds->uni_id(); |
| 1456 | std::string direction; |
| 1457 | bcmos_errno err; |
| 1458 | |
| 1459 | for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) { |
| 1460 | tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i); |
| 1461 | if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) { |
| 1462 | direction = upstream; |
| 1463 | } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1464 | direction = downstream; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1465 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1466 | else { |
| 1467 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_sched.direction()); |
| 1468 | return Status::CANCELLED; |
| 1469 | } |
| 1470 | err = RemoveSched(intf_id, onu_id, uni_id, direction); |
| 1471 | if (err) { |
| 1472 | return bcm_to_grpc_err(err, "error-removing-traffic-scheduler"); |
| 1473 | } |
| 1474 | } |
| 1475 | return Status::OK; |
| 1476 | } |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1477 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1478 | bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority, |
| 1479 | uint32_t gemport_id) { |
| 1480 | bcmos_errno err; |
| 1481 | bcmbal_tm_queue_cfg cfg; |
| 1482 | bcmbal_tm_queue_key key = { }; |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1483 | BCM_LOG(INFO, openolt_log_id, "creating queue. access_intf_id = %d, onu_id = %d, uni_id = %d \ |
| 1484 | gemport_id = %d, direction = %s\n", access_intf_id, onu_id, uni_id, gemport_id, direction.c_str()); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1485 | if (direction == downstream) { |
| 1486 | // In the downstream, the queues are on the 'sub term' scheduler |
| 1487 | // There is one queue per gem port |
| 1488 | key.sched_dir = BCMBAL_TM_SCHED_DIR_DS; |
| 1489 | key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction); |
| 1490 | key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1491 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1492 | } else { |
| 1493 | queue_map_key_tuple map_key(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1494 | if (queue_map.count(map_key) > 0) { |
| 1495 | BCM_LOG(INFO, openolt_log_id, "upstream queue exists for intf_id %d, onu_id %d, uni_id %d\n. Not re-creating", \ |
| 1496 | access_intf_id, onu_id, uni_id); |
| 1497 | return BCM_ERR_OK; |
| 1498 | } |
| 1499 | key.sched_dir = BCMBAL_TM_SCHED_DIR_US; |
| 1500 | key.sched_id = get_default_tm_sched_id(nni_intf_id, direction); |
| 1501 | if (priority > 7) { |
| 1502 | return BCM_ERR_RANGE; |
| 1503 | } |
| 1504 | // There are 8 queues (one per p-bit) |
| 1505 | key.id = us_fixed_queue_id_list[priority]; |
| 1506 | update_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction, key.id); |
| 1507 | // FIXME: The upstream queues have to be created once only. |
| 1508 | // The upstream queues on the NNI scheduler are shared by all subscribers. |
| 1509 | // When the first scheduler comes in, the queues get created, and are re-used by all others. |
| 1510 | // Also, these queues should be present until the last subscriber exits the system. |
| 1511 | // One solution is to have these queues always, i.e., create it as soon as OLT is enabled. |
| 1512 | } |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1513 | BCM_LOG(INFO, openolt_log_id, "queue assigned queue_id = %d\n", key.id); |
| 1514 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1515 | BCMBAL_CFG_INIT(&cfg, tm_queue, key); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1516 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1517 | BCMBAL_CFG_PROP_SET(&cfg, tm_queue, priority, priority); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1518 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1519 | // BCMBAL_CFG_PROP_SET(&cfg, tm_queue, creation_mode, BCMBAL_TM_CREATION_MODE_MANUAL); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1520 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1521 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1522 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr); |
| 1523 | if (err) { |
| 1524 | BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, id %d, sched_id %d, \ |
| 1525 | intf_id %d, onu_id %d, uni_id %d\n", \ |
| 1526 | direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id); |
| 1527 | return err; |
| 1528 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1529 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1530 | BCM_LOG(INFO, openolt_log_id, "Created tm_queue, direction %s, id %d, intf_id %d, onu_id %d, uni_id %d", \ |
| 1531 | direction.c_str(), key.id, access_intf_id, onu_id, uni_id); |
| 1532 | |
| 1533 | return BCM_ERR_OK; |
| 1534 | |
| 1535 | } |
| 1536 | |
| 1537 | Status CreateTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) { |
| 1538 | uint32_t intf_id = traffic_queues->intf_id(); |
| 1539 | uint32_t onu_id = traffic_queues->onu_id(); |
| 1540 | uint32_t uni_id = traffic_queues->uni_id(); |
| 1541 | std::string direction; |
| 1542 | unsigned int alloc_id; |
| 1543 | bcmos_errno err; |
| 1544 | |
| 1545 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
| 1546 | tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
| 1547 | if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) { |
| 1548 | direction = upstream; |
| 1549 | } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1550 | direction = downstream; |
| 1551 | } |
| 1552 | else { |
| 1553 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_queue.direction()); |
| 1554 | return Status::CANCELLED; |
| 1555 | } |
| 1556 | err = CreateQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id()); |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1557 | // If the queue exists already, lets not return failure and break the loop. |
| 1558 | if (err && err != BCM_ERR_ALREADY) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1559 | return bcm_to_grpc_err(err, "Failed to create queue"); |
| 1560 | } |
| 1561 | } |
| 1562 | return Status::OK; |
| 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority, |
| 1567 | uint32_t gemport_id) { |
| 1568 | bcmbal_tm_queue_cfg queue_cfg; |
| 1569 | bcmbal_tm_queue_key queue_key = { }; |
| 1570 | bcmos_errno err; |
| 1571 | |
| 1572 | if (direction == downstream) { |
| 1573 | queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS; |
| 1574 | if (is_tm_queue_id_present(access_intf_id, onu_id, uni_id, gemport_id, direction) && \ |
| 1575 | is_tm_sched_id_present(access_intf_id, onu_id, uni_id, direction)) { |
| 1576 | queue_key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction); |
| 1577 | queue_key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1578 | } else { |
| 1579 | BCM_LOG(INFO, openolt_log_id, "queue not present in DS. Not clearing"); |
| 1580 | return BCM_ERR_OK; |
| 1581 | } |
| 1582 | } else { |
| 1583 | free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1584 | // In the upstream we use pre-created queues on the NNI scheduler that are used by all subscribers. |
| 1585 | // They should not be removed. So, lets return OK. |
| 1586 | return BCM_ERR_OK; |
| 1587 | } |
| 1588 | |
| 1589 | BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key); |
| 1590 | |
| 1591 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr)); |
| 1592 | |
| 1593 | if (err) { |
| 1594 | BCM_LOG(ERROR, openolt_log_id, "Failed to remove queue, direction = %s, id %d, sched_id %d, intf_id %d, onu_id %d, uni_id %d\n", |
| 1595 | direction.c_str(), queue_key.id, queue_key.sched_id, access_intf_id, onu_id, uni_id); |
| 1596 | return err; |
| 1597 | } |
| 1598 | |
| 1599 | free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1600 | |
| 1601 | return BCM_ERR_OK; |
| 1602 | } |
| 1603 | |
| 1604 | Status RemoveTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) { |
| 1605 | uint32_t intf_id = traffic_queues->intf_id(); |
| 1606 | uint32_t onu_id = traffic_queues->onu_id(); |
| 1607 | uint32_t uni_id = traffic_queues->uni_id(); |
| 1608 | uint32_t port_no = traffic_queues->port_no(); |
| 1609 | std::string direction; |
| 1610 | unsigned int alloc_id; |
| 1611 | bcmos_errno err; |
| 1612 | |
| 1613 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
| 1614 | tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
| 1615 | if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) { |
| 1616 | direction = upstream; |
| 1617 | } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1618 | direction = downstream; |
| 1619 | } else { |
| 1620 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_queue.direction()); |
| 1621 | return Status::CANCELLED; |
| 1622 | } |
| 1623 | err = RemoveQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id()); |
| 1624 | if (err) { |
| 1625 | return bcm_to_grpc_err(err, "Failed to remove queue"); |
| 1626 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1629 | return Status::OK; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1630 | } |