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> |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 28 | #include <inttypes.h> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 29 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 30 | #include "device.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 31 | #include "core.h" |
| 32 | #include "indications.h" |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 33 | #include "stats_collection.h" |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 34 | #include "error_format.h" |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 35 | #include "state.h" |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 36 | #include "utils.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 37 | |
| 38 | extern "C" |
| 39 | { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 40 | #include <bcmolt_api.h> |
| 41 | #include <bcmolt_host_api.h> |
| 42 | #include <bcmolt_api_model_supporting_enums.h> |
| 43 | #include <bal_version.h> |
| 44 | #include <bcmolt_api_conn_mgr.h> |
| 45 | //CLI header files |
| 46 | #include <bcmcli_session.h> |
| 47 | #include <bcmcli.h> |
| 48 | #include <bcm_api_cli.h> |
| 49 | #include <bcmos_common.h> |
| 50 | #include <bcm_config.h> |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 51 | // FIXME : dependency problem |
| 52 | // #include <bcm_common_gpon.h> |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 53 | // #include <bcm_dev_log_task.h> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 54 | } |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 55 | dev_log_id openolt_log_id = bcm_dev_log_id_register("OPENOLT", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH); |
| 56 | dev_log_id omci_log_id = bcm_dev_log_id_register("OMCI", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH); |
| 57 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 58 | #define MAX_SUPPORTED_INTF 16 |
| 59 | #define BAL_RSC_MANAGER_BASE_TM_SCHED_ID 16384 |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 60 | #define MAX_TM_QUEUE_ID 8192 |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 61 | #define MAX_TM_SCHED_ID 1003 |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 62 | #define EAP_ETHER_TYPE 34958 |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 63 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 64 | static unsigned int num_of_nni_ports = 0; |
| 65 | static unsigned int num_of_pon_ports = 0; |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 66 | static std::string intf_technologies[MAX_SUPPORTED_INTF]; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 67 | static const std::string UNKNOWN_TECH("unknown"); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 68 | static const std::string MIXED_TECH("mixed"); |
| 69 | static std::string board_technology(UNKNOWN_TECH); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 70 | static std::string chip_family(UNKNOWN_TECH); |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 71 | static unsigned int OPENOLT_FIELD_LEN = 200; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 72 | static std::string firmware_version = "Openolt.2018.10.04"; |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 73 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 74 | const uint32_t tm_upstream_sched_id_start = 1020; |
| 75 | const uint32_t tm_downstream_sched_id_start = 1004; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 76 | //0 to 3 are default queues. Lets not use them. |
| 77 | const uint32_t tm_queue_id_start = 4; |
| 78 | // Upto 8 fixed Upstream. Queue id 0 to 3 are pre-created, lets not use them. |
| 79 | 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] | 80 | const std::string upstream = "upstream"; |
| 81 | const std::string downstream = "downstream"; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 82 | bcmolt_oltid dev_id = 0; |
| 83 | /* Current session */ |
| 84 | static bcmcli_session *current_session; |
| 85 | static bcmcli_entry *api_parent_dir; |
| 86 | bcmos_bool status_bcm_cli_quit = BCMOS_FALSE; |
| 87 | bcmos_task bal_cli_thread; |
| 88 | const char *bal_cli_thread_name = "bal_cli_thread"; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 89 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 90 | State state; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 91 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 92 | static std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports |
| 93 | static std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports |
| 94 | 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] | 95 | |
| 96 | // This represents the Key to 'queue_map' map. |
| 97 | // Represents (pon_intf_id, onu_id, uni_id, gemport_id, direction) |
| 98 | typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, std::string> queue_map_key_tuple; |
| 99 | // 'queue_map' maps queue_map_key_tuple to downstream queue id present |
| 100 | // on the Subscriber Scheduler |
| 101 | static std::map<queue_map_key_tuple, int> queue_map; |
| 102 | // This represents the Key to 'sched_map' map. |
| 103 | // Represents (pon_intf_id, onu_id, uni_id, direction) |
| 104 | |
| 105 | typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string> sched_map_key_tuple; |
| 106 | // 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or |
| 107 | // Subscriber (Downstream) Scheduler ID |
| 108 | static std::map<sched_map_key_tuple, int> sched_map; |
| 109 | |
| 110 | |
| 111 | std::bitset<MAX_TM_QUEUE_ID> tm_queue_bitset; |
| 112 | std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset; |
| 113 | |
| 114 | static bcmos_fastlock data_lock; |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 115 | |
| 116 | #define MIN_ALLOC_ID_GPON 256 |
| 117 | #define MIN_ALLOC_ID_XGSPON 1024 |
| 118 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 119 | static bcmos_errno CreateSched(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
| 120 | uint32_t port_no, uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, \ |
| 121 | uint32_t priority, tech_profile::SchedulingPolicy sched_policy, |
| 122 | tech_profile::TrafficShapingInfo traffic_shaping_info); |
| 123 | static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, std::string direction); |
| 124 | static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
| 125 | uint32_t priority, uint32_t gemport_id); |
| 126 | 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] | 127 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 128 | uint16_t get_dev_id(void) { |
| 129 | return dev_id; |
| 130 | } |
| 131 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 132 | /** |
| 133 | * Returns the default NNI (Upstream direction) or PON (Downstream direction) scheduler |
| 134 | * Every NNI port and PON port have default scheduler. |
| 135 | * The NNI0 default scheduler ID is 18432, and NNI1 is 18433 and so on. |
| 136 | * Similarly, PON0 default scheduler ID is 16384. PON1 is 16385 and so on. |
| 137 | * |
| 138 | * @param intf_id NNI or PON interface ID |
| 139 | * @param direction "upstream" or "downstream" |
| 140 | * |
| 141 | * @return default scheduler ID for the given interface. |
| 142 | */ |
| 143 | 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] | 144 | if (direction.compare(upstream) == 0) { |
| 145 | return tm_upstream_sched_id_start + intf_id; |
| 146 | } else if (direction.compare(downstream) == 0) { |
| 147 | return tm_downstream_sched_id_start + intf_id; |
| 148 | } |
| 149 | else { |
| 150 | BCM_LOG(ERROR, openolt_log_id, "invalid direction - %s\n", direction.c_str()); |
| 151 | return 0; |
| 152 | } |
| 153 | } |
| 154 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Gets a unique tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 157 | * The tm_queue_id is locally cached in a map, so that it can rendered when necessary. |
| 158 | * VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem |
| 159 | * |
| 160 | * @param intf_id NNI or PON intf ID |
| 161 | * @param onu_id ONU ID |
| 162 | * @param uni_id UNI ID |
| 163 | * @param gemport_id GEM Port ID |
| 164 | * @param direction Upstream or downstream |
| 165 | * |
| 166 | * @return tm_queue_id |
| 167 | */ |
| 168 | int get_tm_queue_id(int intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) { |
| 169 | queue_map_key_tuple key(intf_id, onu_id, uni_id, gemport_id, direction); |
| 170 | int queue_id = -1; |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 171 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 172 | std::map<queue_map_key_tuple, int>::const_iterator it = queue_map.find(key); |
| 173 | if (it != queue_map.end()) { |
| 174 | queue_id = it->second; |
| 175 | } |
| 176 | if (queue_id != -1) { |
| 177 | return queue_id; |
| 178 | } |
| 179 | |
| 180 | bcmos_fastlock_lock(&data_lock); |
| 181 | // Complexity of O(n). Is there better way that can avoid linear search? |
| 182 | for (queue_id = 0; queue_id < MAX_TM_QUEUE_ID; queue_id++) { |
| 183 | if (tm_queue_bitset[queue_id] == 0) { |
| 184 | tm_queue_bitset[queue_id] = 1; |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | bcmos_fastlock_unlock(&data_lock, 0); |
| 189 | |
| 190 | if (queue_id < MAX_TM_QUEUE_ID) { |
| 191 | bcmos_fastlock_lock(&data_lock); |
| 192 | queue_map[key] = queue_id; |
| 193 | bcmos_fastlock_unlock(&data_lock, 0); |
| 194 | return queue_id; |
| 195 | } else { |
| 196 | return -1; |
| 197 | } |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 200 | /** |
| 201 | * Update tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 202 | * |
| 203 | * @param intf_id NNI or PON intf ID |
| 204 | * @param onu_id ONU ID |
| 205 | * @param uni_id UNI ID |
| 206 | * @param gemport_id GEM Port ID |
| 207 | * @param direction Upstream or downstream |
| 208 | * @param tm_queue_id tm_queue_id |
| 209 | */ |
| 210 | void update_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction, |
| 211 | uint32_t queue_id) { |
| 212 | queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction); |
| 213 | bcmos_fastlock_lock(&data_lock); |
| 214 | queue_map[key] = queue_id; |
| 215 | bcmos_fastlock_unlock(&data_lock, 0); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Free tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 220 | * |
| 221 | * @param intf_id NNI or PON intf ID |
| 222 | * @param onu_id ONU ID |
| 223 | * @param uni_id UNI ID |
| 224 | * @param gemport_id GEM Port ID |
| 225 | * @param direction Upstream or downstream |
| 226 | */ |
| 227 | void free_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) { |
| 228 | queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction); |
| 229 | std::map<queue_map_key_tuple, int>::const_iterator it; |
| 230 | bcmos_fastlock_lock(&data_lock); |
| 231 | it = queue_map.find(key); |
| 232 | if (it != queue_map.end()) { |
| 233 | tm_queue_bitset[it->second] = 0; |
| 234 | queue_map.erase(it); |
| 235 | } |
| 236 | bcmos_fastlock_unlock(&data_lock, 0); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Gets a unique tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 241 | * The tm_sched_id is locally cached in a map, so that it can rendered when necessary. |
| 242 | * VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem |
| 243 | * |
| 244 | * @param intf_id NNI or PON intf ID |
| 245 | * @param onu_id ONU ID |
| 246 | * @param uni_id UNI ID |
| 247 | * @param gemport_id GEM Port ID |
| 248 | * @param direction Upstream or downstream |
| 249 | * |
| 250 | * @return tm_sched_id |
| 251 | */ |
| 252 | uint32_t get_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) { |
| 253 | sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction); |
| 254 | int sched_id = -1; |
| 255 | |
| 256 | std::map<sched_map_key_tuple, int>::const_iterator it = sched_map.find(key); |
| 257 | if (it != sched_map.end()) { |
| 258 | sched_id = it->second; |
| 259 | } |
| 260 | if (sched_id != -1) { |
| 261 | return sched_id; |
| 262 | } |
| 263 | |
| 264 | bcmos_fastlock_lock(&data_lock); |
| 265 | // Complexity of O(n). Is there better way that can avoid linear search? |
| 266 | for (sched_id = 0; sched_id < MAX_TM_SCHED_ID; sched_id++) { |
| 267 | if (tm_sched_bitset[sched_id] == 0) { |
| 268 | tm_sched_bitset[sched_id] = 1; |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | bcmos_fastlock_unlock(&data_lock, 0); |
| 273 | |
| 274 | if (sched_id < MAX_TM_SCHED_ID) { |
| 275 | bcmos_fastlock_lock(&data_lock); |
| 276 | sched_map[key] = sched_id; |
| 277 | bcmos_fastlock_unlock(&data_lock, 0); |
| 278 | return sched_id; |
| 279 | } else { |
| 280 | return -1; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Free tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction |
| 286 | * |
| 287 | * @param intf_id NNI or PON intf ID |
| 288 | * @param onu_id ONU ID |
| 289 | * @param uni_id UNI ID |
| 290 | * @param gemport_id GEM Port ID |
| 291 | * @param direction Upstream or downstream |
| 292 | */ |
| 293 | void free_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) { |
| 294 | sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction); |
| 295 | std::map<sched_map_key_tuple, int>::const_iterator it; |
| 296 | bcmos_fastlock_lock(&data_lock); |
| 297 | it = sched_map.find(key); |
| 298 | if (it != sched_map.end()) { |
| 299 | tm_sched_bitset[it->second] = 0; |
| 300 | sched_map.erase(it); |
| 301 | } |
| 302 | bcmos_fastlock_unlock(&data_lock, 0); |
| 303 | } |
| 304 | |
| 305 | bool is_tm_sched_id_present(int pon_intf_id, int onu_id, int uni_id, std::string direction) { |
| 306 | sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction); |
| 307 | return sched_map.count(key) > 0 ? true: false; |
| 308 | } |
| 309 | |
| 310 | bool is_tm_queue_id_present(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) { |
| 311 | queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction); |
| 312 | return queue_map.count(key) > 0 ? true: false; |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Jason Huang | 8879522 | 2019-06-13 19:28:44 +0800 | [diff] [blame] | 315 | char* openolt_read_sysinfo(const char* field_name, char* field_val) |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 316 | { |
| 317 | FILE *fp; |
| 318 | /* Prepare the command*/ |
| 319 | char command[150]; |
| 320 | |
| 321 | snprintf(command, sizeof command, "bash -l -c \"onlpdump -s\" | perl -ne 'print $1 if /%s: (\\S+)/'", field_name); |
| 322 | /* Open the command for reading. */ |
| 323 | fp = popen(command, "r"); |
| 324 | if (fp == NULL) { |
| 325 | /*The client has to check for a Null field value in this case*/ |
| 326 | BCM_LOG(INFO, openolt_log_id, "Failed to query the %s\n", field_name); |
| 327 | return field_val; |
| 328 | } |
| 329 | |
| 330 | /*Read the field value*/ |
| 331 | if (fp) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 332 | uint8_t ret; |
| 333 | ret = fread(field_val, OPENOLT_FIELD_LEN, 1, fp); |
| 334 | if (ret >= OPENOLT_FIELD_LEN) |
| 335 | BCM_LOG(INFO, openolt_log_id, "Read data length %u\n", ret); |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 336 | pclose(fp); |
| 337 | } |
| 338 | return field_val; |
| 339 | } |
| 340 | |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 341 | Status GetDeviceInfo_(openolt::DeviceInfo* device_info) { |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 342 | device_info->set_vendor(VENDOR_ID); |
| 343 | device_info->set_model(MODEL_ID); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 344 | device_info->set_hardware_version(""); |
| 345 | device_info->set_firmware_version(firmware_version); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 346 | device_info->set_technology(board_technology); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 347 | device_info->set_pon_ports(num_of_pon_ports); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 348 | |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 349 | char serial_number[OPENOLT_FIELD_LEN]; |
| 350 | memset(serial_number, '\0', OPENOLT_FIELD_LEN); |
| 351 | openolt_read_sysinfo("Serial Number", serial_number); |
| 352 | BCM_LOG(INFO, openolt_log_id, "Fetched device serial number %s\n", serial_number); |
| 353 | device_info->set_device_serial_number(serial_number); |
| 354 | |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 355 | // Legacy, device-wide ranges. To be deprecated when adapter |
| 356 | // is upgraded to support per-interface ranges |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 357 | if (board_technology == "XGS-PON") { |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 358 | device_info->set_onu_id_start(1); |
| 359 | device_info->set_onu_id_end(255); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 360 | device_info->set_alloc_id_start(MIN_ALLOC_ID_XGSPON); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 361 | device_info->set_alloc_id_end(16383); |
| 362 | device_info->set_gemport_id_start(1024); |
| 363 | device_info->set_gemport_id_end(65535); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 364 | device_info->set_flow_id_start(1); |
| 365 | device_info->set_flow_id_end(16383); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 366 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 367 | else if (board_technology == "GPON") { |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 368 | device_info->set_onu_id_start(1); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 369 | device_info->set_onu_id_end(127); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 370 | device_info->set_alloc_id_start(MIN_ALLOC_ID_GPON); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 371 | device_info->set_alloc_id_end(767); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 372 | device_info->set_gemport_id_start(256); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 373 | device_info->set_gemport_id_end(4095); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 374 | device_info->set_flow_id_start(1); |
| 375 | device_info->set_flow_id_end(16383); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 376 | } |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 377 | |
| 378 | std::map<std::string, openolt::DeviceInfo::DeviceResourceRanges*> ranges; |
| 379 | for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) { |
| 380 | std::string intf_technology = intf_technologies[intf_id]; |
| 381 | openolt::DeviceInfo::DeviceResourceRanges *range = ranges[intf_technology]; |
| 382 | if(range == nullptr) { |
| 383 | range = device_info->add_ranges(); |
| 384 | ranges[intf_technology] = range; |
| 385 | range->set_technology(intf_technology); |
| 386 | |
| 387 | if (intf_technology == "xgspon") { |
| 388 | openolt::DeviceInfo::DeviceResourceRanges::Pool* pool; |
| 389 | |
| 390 | pool = range->add_pools(); |
| 391 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID); |
| 392 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 393 | pool->set_start(1); |
| 394 | pool->set_end(255); |
| 395 | |
| 396 | pool = range->add_pools(); |
| 397 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID); |
| 398 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH); |
| 399 | pool->set_start(1024); |
| 400 | pool->set_end(16383); |
| 401 | |
| 402 | pool = range->add_pools(); |
| 403 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID); |
| 404 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 405 | pool->set_start(1024); |
| 406 | pool->set_end(65535); |
| 407 | |
| 408 | pool = range->add_pools(); |
| 409 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID); |
| 410 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 411 | pool->set_start(1); |
| 412 | pool->set_end(16383); |
| 413 | } |
| 414 | else if (intf_technology == "gpon") { |
| 415 | openolt::DeviceInfo::DeviceResourceRanges::Pool* pool; |
| 416 | |
| 417 | pool = range->add_pools(); |
| 418 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID); |
| 419 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 420 | pool->set_start(1); |
| 421 | pool->set_end(127); |
| 422 | |
| 423 | pool = range->add_pools(); |
| 424 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID); |
| 425 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH); |
| 426 | pool->set_start(256); |
| 427 | pool->set_end(757); |
| 428 | |
| 429 | pool = range->add_pools(); |
| 430 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID); |
| 431 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 432 | pool->set_start(256); |
| 433 | pool->set_end(4095); |
| 434 | |
| 435 | pool = range->add_pools(); |
| 436 | pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID); |
| 437 | pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 438 | pool->set_start(1); |
| 439 | pool->set_end(16383); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | range->add_intf_ids(intf_id); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 444 | } |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 445 | |
| 446 | // FIXME: Once dependency problem is fixed |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 447 | // device_info->set_pon_ports(num_of_pon_ports); |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 448 | // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1); |
| 449 | // device_info->set_alloc_id_start(1024); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 450 | // 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] | 451 | // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 452 | // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1); |
| 453 | // device_info->set_pon_ports(num_of_pon_ports); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 454 | |
| 455 | return Status::OK; |
| 456 | } |
| 457 | |
Jason Huang | 8879522 | 2019-06-13 19:28:44 +0800 | [diff] [blame] | 458 | Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state) |
| 459 | { |
| 460 | openolt::Indication ind; |
| 461 | openolt::IntfOperIndication* intf_oper_ind = new openolt::IntfOperIndication; |
| 462 | |
| 463 | intf_oper_ind->set_type(type); |
| 464 | intf_oper_ind->set_intf_id(intf_id); |
| 465 | intf_oper_ind->set_oper_state(state); |
| 466 | ind.set_allocated_intf_oper_ind(intf_oper_ind); |
| 467 | oltIndQ.push(ind); |
| 468 | return Status::OK; |
| 469 | } |
| 470 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 471 | #define CLI_HOST_PROMPT_FORMAT "BCM.%u> " |
| 472 | |
| 473 | /* Build CLI prompt */ |
| 474 | static void openolt_cli_get_prompt_cb(bcmcli_session *session, char *buf, uint32_t max_len) |
| 475 | { |
| 476 | snprintf(buf, max_len, CLI_HOST_PROMPT_FORMAT, dev_id); |
| 477 | } |
| 478 | |
| 479 | static int _bal_apiend_cli_thread_handler(long data) |
| 480 | { |
| 481 | char init_string[]="\n"; |
| 482 | bcmcli_session *sess = current_session; |
| 483 | bcmos_task_parm bal_cli_task_p_dummy; |
| 484 | |
| 485 | /* Switch to interactive mode if not stopped in the init script */ |
| 486 | if (!bcmcli_is_stopped(sess)) |
| 487 | { |
| 488 | /* Force a CLI command prompt |
| 489 | * The string passed into the parse function |
| 490 | * must be modifiable, so a string constant like |
| 491 | * bcmcli_parse(current_session, "\n") will not |
| 492 | * work. |
| 493 | */ |
| 494 | bcmcli_parse(sess, init_string); |
| 495 | |
| 496 | /* Process user input until EOF or quit command */ |
| 497 | bcmcli_driver(sess); |
| 498 | }; |
| 499 | BCM_LOG(INFO, openolt_log_id, "BAL API End CLI terminated\n"); |
| 500 | |
| 501 | /* Cleanup */ |
| 502 | bcmcli_session_close(current_session); |
| 503 | bcmcli_token_destroy(NULL); |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | /* Init API CLI commands for the current device */ |
| 508 | bcmos_errno bcm_openolt_api_cli_init(bcmcli_entry *parent_dir, bcmcli_session *session) |
| 509 | { |
| 510 | bcmos_errno rc; |
| 511 | |
| 512 | api_parent_dir = parent_dir; |
| 513 | |
| 514 | rc = bcm_api_cli_set_commands(session); |
| 515 | |
| 516 | #ifdef BCM_SUBSYSTEM_HOST |
| 517 | /* Subscribe for device change indication */ |
| 518 | rc = rc ? rc : bcmolt_olt_sel_ind_register(_api_cli_olt_change_ind); |
| 519 | #endif |
| 520 | |
| 521 | return rc; |
| 522 | } |
| 523 | |
| 524 | static bcmos_errno bcm_cli_quit(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 525 | { |
| 526 | bcmcli_stop(session); |
| 527 | bcmcli_session_print(session, "CLI terminated by 'Quit' command\n"); |
| 528 | status_bcm_cli_quit = BCMOS_TRUE; |
| 529 | |
| 530 | return BCM_ERR_OK; |
| 531 | } |
| 532 | |
| 533 | int get_status_bcm_cli_quit(void) { |
| 534 | return status_bcm_cli_quit; |
| 535 | } |
| 536 | |
| 537 | bcmos_errno bcmolt_apiend_cli_init() { |
| 538 | bcmos_errno ret; |
| 539 | bcmos_task_parm bal_cli_task_p = {}; |
| 540 | bcmos_task_parm bal_cli_task_p_dummy; |
| 541 | |
| 542 | /** before creating the task, check if it is already created by the other half of BAL i.e. Core side */ |
| 543 | if (BCM_ERR_OK != bcmos_task_query(&bal_cli_thread, &bal_cli_task_p_dummy)) |
| 544 | { |
| 545 | /* Create BAL CLI thread */ |
| 546 | bal_cli_task_p.name = bal_cli_thread_name; |
| 547 | bal_cli_task_p.handler = _bal_apiend_cli_thread_handler; |
| 548 | bal_cli_task_p.priority = TASK_PRIORITY_CLI; |
| 549 | |
| 550 | ret = bcmos_task_create(&bal_cli_thread, &bal_cli_task_p); |
| 551 | if (BCM_ERR_OK != ret) |
| 552 | { |
| 553 | bcmos_printf("Couldn't create BAL API end CLI thread\n"); |
| 554 | return ret; |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 559 | Status Enable_(int argc, char *argv[]) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 560 | bcmos_errno err; |
| 561 | bcmolt_host_init_parms init_parms = {}; |
| 562 | init_parms.transport.type = BCM_HOST_API_CONN_LOCAL; |
| 563 | bcmcli_session_parm mon_session_parm; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 564 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 565 | if (!state.is_activated()) { |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 566 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 567 | vendor_init(); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 568 | /* Initialize host subsystem */ |
| 569 | err = bcmolt_host_init(&init_parms); |
| 570 | if (BCM_ERR_OK != err) { |
| 571 | BCM_LOG(ERROR, openolt_log_id, "Failed to init OLT\n"); |
| 572 | return bcm_to_grpc_err(err, "Failed to init OLT"); |
| 573 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 574 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 575 | /* Create CLI session */ |
| 576 | memset(&mon_session_parm, 0, sizeof(mon_session_parm)); |
| 577 | mon_session_parm.get_prompt = openolt_cli_get_prompt_cb; |
| 578 | mon_session_parm.access_right = BCMCLI_ACCESS_ADMIN; |
| 579 | bcmos_errno rc = bcmcli_session_open(&mon_session_parm, ¤t_session); |
| 580 | BUG_ON(rc != BCM_ERR_OK); |
| 581 | |
| 582 | /* API CLI */ |
| 583 | bcm_openolt_api_cli_init(NULL, current_session); |
| 584 | |
| 585 | /* Add quit command */ |
| 586 | BCMCLI_MAKE_CMD_NOPARM(NULL, "quit", "Quit", bcm_cli_quit); |
| 587 | |
| 588 | err = bcmolt_apiend_cli_init(); |
| 589 | if (BCM_ERR_OK != err) { |
| 590 | BCM_LOG(ERROR, openolt_log_id, "Failed to add apiend init\n"); |
| 591 | return bcm_to_grpc_err(err, "Failed to add apiend init"); |
| 592 | } |
| 593 | |
| 594 | bcmos_fastlock_init(&data_lock, 0); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 595 | BCM_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID); |
| 596 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 597 | if (bcmolt_api_conn_mgr_is_connected(dev_id)) |
| 598 | { |
| 599 | Status status = SubscribeIndication(); |
| 600 | if (!status.ok()) { |
| 601 | BCM_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n", |
| 602 | grpc_status_code_to_string(status.error_code()).c_str(), |
| 603 | status.error_message().c_str()); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 604 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 605 | return status; |
| 606 | } |
| 607 | bcmos_errno err; |
| 608 | bcmolt_odid dev; |
| 609 | for (dev = 0; dev < BCM_MAX_DEVS_PER_LINE_CARD; dev++) { |
| 610 | bcmolt_device_cfg dev_cfg = { }; |
| 611 | bcmolt_device_key dev_key = { }; |
| 612 | dev_key.device_id = dev; |
| 613 | BCMOLT_CFG_INIT(&dev_cfg, device, dev_key); |
| 614 | BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode); |
| 615 | err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr); |
| 616 | if (err == BCM_ERR_NOT_CONNECTED) { |
| 617 | bcmolt_device_key key = {.device_id = dev}; |
| 618 | bcmolt_device_connect oper; |
| 619 | bcmolt_device_cfg cfg; |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 620 | BCM_LOG(INFO, openolt_log_id, "Enable Maple - %d/%d\n", dev + 1, BCM_MAX_DEVS_PER_LINE_CARD); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 621 | BCMOLT_OPER_INIT(&oper, device, connect, key); |
| 622 | BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI); |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 623 | BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_XGS__2_X); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 624 | err = bcmolt_oper_submit(dev_id, &oper.hdr); |
| 625 | if (err) |
| 626 | BCM_LOG(ERROR, openolt_log_id, "Enable Maple deivce %d failed\n", dev); |
| 627 | bcmos_usleep(200000); |
| 628 | } |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 629 | else { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 630 | BCM_LOG(ERROR, openolt_log_id, "Maple deivce %d already connected\n", dev); |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 631 | state.activate(); |
| 632 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 633 | } |
| 634 | init_stats(); |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 635 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 636 | } |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 637 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 638 | /* Start CLI */ |
| 639 | BCM_LOG(INFO, def_log_id, "Starting CLI\n"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 640 | //If already enabled, generate an extra indication ???? |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 641 | return Status::OK; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | Status Disable_() { |
| 645 | // bcmbal_access_terminal_cfg acc_term_obj; |
| 646 | // bcmbal_access_terminal_key key = { }; |
| 647 | // |
| 648 | // if (state::is_activated) { |
| 649 | // std::cout << "Disable OLT" << std::endl; |
| 650 | // key.access_term_id = DEFAULT_ATERM_ID; |
| 651 | // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 652 | // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN); |
| 653 | // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 654 | // if (err) { |
| 655 | // std::cout << "ERROR: Failed to disable OLT" << std::endl; |
| 656 | // return bcm_to_grpc_err(err, "Failed to disable OLT"); |
| 657 | // } |
| 658 | // } |
| 659 | // //If already disabled, generate an extra indication ???? |
| 660 | // return Status::OK; |
| 661 | //This fails with Operation Not Supported, bug ??? |
| 662 | |
| 663 | //TEMPORARY WORK AROUND |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 664 | Status status = DisableUplinkIf_(nni_intf_id); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 665 | if (status.ok()) { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 666 | state.deactivate(); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 667 | BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n"); |
Jason Huang | 8879522 | 2019-06-13 19:28:44 +0800 | [diff] [blame] | 668 | pushOltOperInd(nni_intf_id, "nni", "up"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 669 | } |
| 670 | return status; |
| 671 | |
| 672 | } |
| 673 | |
| 674 | Status Reenable_() { |
| 675 | Status status = EnableUplinkIf_(0); |
| 676 | if (status.ok()) { |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 677 | state.activate(); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 678 | BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n"); |
Jason Huang | 8879522 | 2019-06-13 19:28:44 +0800 | [diff] [blame] | 679 | pushOltOperInd(0, "nni", "up"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 680 | } |
| 681 | return status; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 684 | bcmos_errno get_pon_interface_status(bcmolt_interface pon_ni, bcmolt_interface_state *state) { |
| 685 | bcmos_errno err; |
| 686 | bcmolt_pon_interface_key pon_key; |
| 687 | bcmolt_pon_interface_cfg pon_cfg; |
| 688 | pon_key.pon_ni = pon_ni; |
| 689 | |
| 690 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 691 | BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, state); |
| 692 | BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, itu); |
| 693 | err = bcmolt_cfg_get(dev_id, &pon_cfg.hdr); |
| 694 | *state = pon_cfg.data.state; |
| 695 | return err; |
| 696 | } |
| 697 | |
Jason Huang | 439d24f | 2019-06-26 03:25:05 +0800 | [diff] [blame] | 698 | uint64_t get_flow_status(uint16_t flow_id, uint16_t data_id) { |
| 699 | bcmos_errno err; |
| 700 | bcmolt_flow_key flow_key; |
| 701 | bcmolt_flow_cfg flow_cfg; |
| 702 | |
| 703 | flow_key.flow_id = flow_id; |
| 704 | |
| 705 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 706 | |
| 707 | switch (data_id) { |
| 708 | case INTF_TYPE: //intf_type |
| 709 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf); |
| 710 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
| 711 | if (err) { |
| 712 | BCM_LOG(ERROR, openolt_log_id, "Failed to get intf_type\n"); |
| 713 | return err; |
| 714 | } |
| 715 | return flow_cfg.data.ingress_intf.intf_type; |
| 716 | case INTF_ID: //intf_id |
| 717 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf); |
| 718 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
| 719 | if (err) { |
| 720 | BCM_LOG(ERROR, openolt_log_id, "Failed to get intf_id\n"); |
| 721 | return err; |
| 722 | } |
| 723 | return flow_cfg.data.ingress_intf.intf_id; |
| 724 | |
| 725 | case SVC_PORT_ID: //svc_port_id |
| 726 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, svc_port_id); |
| 727 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
| 728 | if (err) { |
| 729 | BCM_LOG(ERROR, openolt_log_id, "Failed to get svc_port_id\n"); |
| 730 | return err; |
| 731 | } |
| 732 | return flow_cfg.data.svc_port_id; |
| 733 | case COOKIE: //cookie |
| 734 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, cookie); |
| 735 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
| 736 | if (err) { |
| 737 | BCM_LOG(ERROR, openolt_log_id, "Failed to get cookie\n"); |
| 738 | return err; |
| 739 | } |
| 740 | return flow_cfg.data.cookie; |
| 741 | default: |
| 742 | return BCM_ERR_INTERNAL; |
| 743 | } |
| 744 | |
| 745 | return err; |
| 746 | } |
| 747 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 748 | Status EnablePonIf_(uint32_t intf_id) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 749 | bcmos_errno err = BCM_ERR_OK; |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 750 | bcmolt_pon_interface_cfg interface_obj; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 751 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id}; |
| 752 | bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state; |
| 753 | bcmolt_interface_state state; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 754 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 755 | err = get_pon_interface_status((bcmolt_interface)intf_id, &state); |
| 756 | if (err == BCM_ERR_OK) { |
| 757 | if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) { |
| 758 | BCM_LOG(INFO, openolt_log_id, "PON interface: %d already enabled\n", intf_id); |
| 759 | return Status::OK; |
| 760 | } |
| 761 | } |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 762 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 763 | BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key); |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 764 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_ENABLE); |
| 765 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.interval, 5000); |
| 766 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.onu_post_discovery_mode, |
| 767 | BCMOLT_ONU_POST_DISCOVERY_MODE_ACTIVATE); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 768 | BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data, |
| 769 | operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING); |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 770 | |
| 771 | err = bcmolt_cfg_set(dev_id, &interface_obj.hdr); |
| 772 | if (err != BCM_ERR_OK) { |
| 773 | BCM_LOG(ERROR, openolt_log_id, "Failed to enable discovery onu: %d\n", intf_id); |
| 774 | return bcm_to_grpc_err(err, "Failed to enable discovery onu"); |
| 775 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 776 | err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr); |
| 777 | if (err != BCM_ERR_OK) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 778 | 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] | 779 | return bcm_to_grpc_err(err, "Failed to enable PON interface"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 780 | } |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 781 | else { |
| 782 | BCM_LOG(INFO, openolt_log_id, "Successfully enabled PON interface: %d\n", intf_id); |
| 783 | BCM_LOG(INFO, openolt_log_id, "Initializing tm sched creation for PON interface: %d\n", intf_id); |
| 784 | CreateDefaultSchedQueue_(intf_id, downstream); |
| 785 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 786 | |
| 787 | return Status::OK; |
| 788 | } |
| 789 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 790 | Status DisableUplinkIf_(uint32_t intf_id) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 791 | bcmolt_pon_interface_key intf_key = {.pon_ni = (uint8_t)intf_id}; |
| 792 | bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 793 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 794 | BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key); |
| 795 | BCMOLT_MSG_FIELD_SET(&pon_interface_set_state, operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING ); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 796 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 797 | bcmos_errno err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr); |
| 798 | if (err == BCM_ERR_OK) { |
| 799 | /* Wait for the interface activation to successfully complete */ |
| 800 | BCM_LOG(DEBUG, openolt_log_id, "PON interface: %d already enabled\n", intf_id); |
| 801 | return Status::OK; |
| 802 | } else { |
| 803 | BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", intf_id); |
| 804 | return bcm_to_grpc_err(err, "Failed to enable PON interface"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | return Status::OK; |
| 808 | } |
| 809 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 810 | Status ProbeDeviceCapabilities_() { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 811 | bcmos_errno err; |
| 812 | bcmolt_device_cfg dev_cfg = { }; |
| 813 | bcmolt_device_key dev_key = { }; |
| 814 | bcmolt_olt_cfg olt_cfg = { }; |
| 815 | bcmolt_olt_key olt_key = { }; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 816 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 817 | dev_key.device_id = dev_id; |
| 818 | BCMOLT_CFG_INIT(&dev_cfg, device, dev_key); |
| 819 | BCMOLT_MSG_FIELD_GET(&dev_cfg, firmware_sw_version); |
| 820 | BCMOLT_MSG_FIELD_GET(&dev_cfg, chip_family); |
| 821 | BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode); |
| 822 | err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr); |
| 823 | if (err) { |
| 824 | BCM_LOG(ERROR, openolt_log_id, "device: Failed to query OLT\n"); |
| 825 | return bcm_to_grpc_err(err, "device: Failed to query OLT"); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 826 | } |
| 827 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 828 | bcmolt_topology_map topo_map[BCM_MAX_PONS_PER_OLT] = { }; |
| 829 | bcmolt_topology topo = { }; |
| 830 | topo.topology_maps.len = BCM_MAX_PONS_PER_OLT; |
| 831 | topo.topology_maps.arr = &topo_map[0]; |
| 832 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 833 | BCMOLT_MSG_FIELD_GET(&olt_cfg, bal_state); |
| 834 | BCMOLT_FIELD_SET_PRESENT(&olt_cfg.data, olt_cfg_data, topology); |
| 835 | BCMOLT_CFG_LIST_BUF_SET(&olt_cfg, olt, topo.topology_maps.arr, |
| 836 | sizeof(bcmolt_topology_map) * topo.topology_maps.len); |
| 837 | err = bcmolt_cfg_get(dev_id, &olt_cfg.hdr); |
| 838 | if (err) { |
| 839 | BCM_LOG(ERROR, openolt_log_id, "cfg: Failed to query OLT\n"); |
| 840 | return bcm_to_grpc_err(err, "cfg: Failed to query OLT"); |
| 841 | } |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 842 | |
| 843 | std::string bal_version; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 844 | bal_version += std::to_string(dev_cfg.data.firmware_sw_version.major) |
| 845 | + "." + std::to_string(dev_cfg.data.firmware_sw_version.minor) |
| 846 | + "." + std::to_string(dev_cfg.data.firmware_sw_version.revision); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 847 | firmware_version = "BAL." + bal_version + "__" + firmware_version; |
| 848 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 849 | switch(dev_cfg.data.system_mode) { |
| 850 | case 9 ... 12: board_technology = "GPON"; break; |
| 851 | case 13 ... 16: board_technology = "XGPON"; break; |
| 852 | case 18 ... 20: board_technology = "XGS-PON"; break; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 853 | } |
| 854 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 855 | switch(dev_cfg.data.chip_family) { |
| 856 | case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6862_X_: chip_family = "Maple"; break; |
| 857 | case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6865_X_: chip_family = "Aspen"; break; |
| 858 | } |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 859 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 860 | num_of_nni_ports = olt_cfg.data.topology.num_switch_ports; |
| 861 | num_of_pon_ports = olt_cfg.data.topology.topology_maps.len; |
| 862 | |
| 863 | BCM_LOG(INFO, openolt_log_id, "OLT capabilitites, oper_state: %s\n", |
| 864 | olt_cfg.data.bal_state == BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY |
| 865 | ? "up" : "down"); |
| 866 | |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 867 | BCM_LOG(INFO, openolt_log_id, "version %s object model: %d\n", |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 868 | bal_version.c_str(), BAL_API_VERSION); |
| 869 | |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 870 | BCM_LOG(INFO, openolt_log_id, "topology nni:%d pon:%d dev:%d ppd:%d family: %s\n", |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 871 | num_of_nni_ports, |
| 872 | num_of_pon_ports, |
| 873 | BCM_MAX_DEVS_PER_LINE_CARD, |
| 874 | BCM_MAX_PONS_PER_DEV, |
| 875 | chip_family.c_str()); |
| 876 | |
| 877 | BCM_LOG(INFO, openolt_log_id, "PON num_intfs: %d global board_technology: %s\n", |
| 878 | num_of_pon_ports, board_technology.c_str()); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 879 | |
| 880 | return Status::OK; |
| 881 | } |
| 882 | |
| 883 | Status ProbePonIfTechnology_() { |
| 884 | // Probe maximum extent possible as configured into BAL driver to determine |
| 885 | // which are active in the current BAL topology. And for those |
| 886 | // that are active, determine each port's access technology, i.e. "gpon" or "xgspon". |
| 887 | for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 888 | bcmolt_pon_interface_cfg interface_obj; |
| 889 | bcmolt_pon_interface_key interface_key; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 890 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 891 | interface_key.pon_ni = intf_id; |
| 892 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key); |
| 893 | BCMOLT_MSG_FIELD_GET(&interface_obj, gpon_trx); |
| 894 | BCMOLT_MSG_FIELD_GET(&interface_obj, xgpon_trx); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 895 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 896 | bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 897 | if (err != BCM_ERR_OK) { |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 898 | intf_technologies[intf_id] = UNKNOWN_TECH; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 899 | if(err != BCM_ERR_RANGE) BCM_LOG(ERROR, openolt_log_id, "Failed to get PON config: %d\n", intf_id); |
| 900 | } |
| 901 | else { |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 902 | if (board_technology == "XGS-PON") { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 903 | switch(interface_obj.data.xgpon_trx.transceiver_type) { |
| 904 | case BCMOLT_XGPON_TRX_TYPE_LTH_7222_PC: |
| 905 | case BCMOLT_XGPON_TRX_TYPE_WTD_RTXM266_702: |
| 906 | case BCMOLT_XGPON_TRX_TYPE_LTH_7222_BC_PLUS: |
| 907 | case BCMOLT_XGPON_TRX_TYPE_LTH_7226_PC: |
| 908 | case BCMOLT_XGPON_TRX_TYPE_LTH_5302_PC: |
| 909 | case BCMOLT_XGPON_TRX_TYPE_LTH_7226_A_PC_PLUS: |
| 910 | case BCMOLT_XGPON_TRX_TYPE_D272RR_SSCB_DM: |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 911 | intf_technologies[intf_id] = "XGS-PON"; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 912 | break; |
| 913 | } |
| 914 | } else if (board_technology == "GPON") { |
| 915 | switch(interface_obj.data.gpon_trx.transceiver_type) { |
| 916 | case BCMOLT_TRX_TYPE_SPS_43_48_H_HP_CDE_SD_2013: |
| 917 | case BCMOLT_TRX_TYPE_LTE_3680_M: |
| 918 | case BCMOLT_TRX_TYPE_SOURCE_PHOTONICS: |
| 919 | case BCMOLT_TRX_TYPE_LTE_3680_P_TYPE_C_PLUS: |
| 920 | case BCMOLT_TRX_TYPE_LTE_3680_P_BC: |
| 921 | intf_technologies[intf_id] = "GPON"; |
| 922 | break; |
| 923 | } |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 924 | } |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 925 | |
| 926 | if (board_technology != UNKNOWN_TECH) { |
| 927 | board_technology = intf_technologies[intf_id]; |
| 928 | } else if (board_technology != MIXED_TECH && board_technology != intf_technologies[intf_id]) { |
| 929 | intf_technologies[intf_id] = MIXED_TECH; |
| 930 | } |
| 931 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
| 935 | return Status::OK; |
| 936 | } |
| 937 | |
| 938 | unsigned NumNniIf_() {return num_of_nni_ports;} |
| 939 | unsigned NumPonIf_() {return num_of_pon_ports;} |
| 940 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 941 | bcmos_errno get_nni_interface_status(bcmolt_interface id, bcmolt_interface_state *state) { |
| 942 | bcmos_errno err; |
| 943 | bcmolt_nni_interface_key nni_key; |
| 944 | bcmolt_nni_interface_cfg nni_cfg; |
| 945 | nni_key.id = id; |
| 946 | |
| 947 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 948 | BCMOLT_FIELD_SET_PRESENT(&nni_cfg.data, nni_interface_cfg_data, state); |
| 949 | err = bcmolt_cfg_get(dev_id, &nni_cfg.hdr); |
| 950 | *state = nni_cfg.data.state; |
| 951 | return err; |
| 952 | } |
| 953 | |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 954 | Status EnableUplinkIf_(uint32_t intf_id) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 955 | bcmos_errno err = BCM_ERR_OK; |
| 956 | bcmolt_nni_interface_key intf_key = {.id = (bcmolt_interface)intf_id}; |
| 957 | bcmolt_nni_interface_set_nni_state nni_interface_set_state; |
| 958 | bcmolt_interface_state state; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 959 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 960 | err = get_nni_interface_status((bcmolt_interface)intf_id, &state); |
| 961 | if (err == BCM_ERR_OK) { |
| 962 | if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) { |
| 963 | BCM_LOG(INFO, openolt_log_id, "NNI interface: %d already enabled\n", intf_id); |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 964 | BCM_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id); |
| 965 | CreateDefaultSchedQueue_(intf_id, upstream); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 966 | return Status::OK; |
| 967 | } |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 968 | } |
| 969 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 970 | BCMOLT_OPER_INIT(&nni_interface_set_state, nni_interface, set_nni_state, intf_key); |
| 971 | BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data, |
| 972 | nni_state, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING); |
| 973 | err = bcmolt_oper_submit(dev_id, &nni_interface_set_state.hdr); |
| 974 | if (err != BCM_ERR_OK) { |
| 975 | BCM_LOG(ERROR, openolt_log_id, "Failed to enable NNI interface: %d, err %d\n", intf_id, err); |
| 976 | return bcm_to_grpc_err(err, "Failed to enable NNI interface"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 977 | } |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 978 | else { |
| 979 | BCM_LOG(INFO, openolt_log_id, "Successfully enabled NNI interface: %d\n", intf_id); |
| 980 | BCM_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id); |
| 981 | CreateDefaultSchedQueue_(intf_id, upstream); |
| 982 | } |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 983 | |
| 984 | return Status::OK; |
| 985 | } |
| 986 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 987 | Status DisablePonIf_(uint32_t intf_id) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 988 | bcmolt_pon_interface_cfg interface_obj; |
| 989 | bcmolt_pon_interface_key interface_key; |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 990 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 991 | interface_key.pon_ni = intf_id; |
| 992 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key); |
| 993 | BCMOLT_MSG_FIELD_GET(&interface_obj, state); |
| 994 | bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 995 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 996 | 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] | 997 | return bcm_to_grpc_err(err, "Failed to disable PON interface"); |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | return Status::OK; |
| 1001 | } |
| 1002 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1003 | Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1004 | const char *vendor_id, const char *vendor_specific, uint32_t pir) { |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 1005 | bcmos_errno err = BCM_ERR_OK; |
| 1006 | bcmolt_onu_cfg onu_cfg; |
| 1007 | bcmolt_onu_key onu_key; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1008 | bcmolt_serial_number serial_number; /**< ONU serial number */ |
| 1009 | bcmolt_bin_str_36 registration_id; /**< ONU registration ID */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1010 | |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 1011 | onu_key.onu_id = onu_id; |
| 1012 | onu_key.pon_ni = intf_id; |
| 1013 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1014 | BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state); |
| 1015 | err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr); |
| 1016 | if (err == BCM_ERR_OK) { |
| 1017 | if ((onu_cfg.data.onu_state == BCMOLT_ONU_STATE_PROCESSING || |
| 1018 | onu_cfg.data.onu_state == BCMOLT_ONU_STATE_ACTIVE) || |
| 1019 | (onu_cfg.data.onu_state == BCMOLT_ONU_STATE_INACTIVE && |
| 1020 | onu_cfg.data.onu_old_state == BCMOLT_ONU_STATE_NOT_CONFIGURED)) |
| 1021 | return Status::OK; |
| 1022 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1023 | |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 1024 | BCM_LOG(INFO, openolt_log_id, "Enabling ONU %d on PON %d : vendor id %s, \ |
| 1025 | vendor specific %s, pir %d\n", onu_id, intf_id, vendor_id, |
| 1026 | vendor_specific_to_str(vendor_specific).c_str(), pir); |
| 1027 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1028 | memcpy(serial_number.vendor_id.arr, vendor_id, 4); |
| 1029 | memcpy(serial_number.vendor_specific.arr, vendor_specific, 4); |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 1030 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1031 | BCMOLT_MSG_FIELD_SET(&onu_cfg, onu_rate, BCMOLT_ONU_RATE_RATE_10G_DS_10G_US); |
| 1032 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.serial_number, serial_number); |
| 1033 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.auto_learning, BCMOS_TRUE); |
| 1034 | /*set burst and data profiles to fec disabled*/ |
| 1035 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.ranging_burst_profile, 0); |
| 1036 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.data_burst_profile, 1); |
| 1037 | err = bcmolt_cfg_set(dev_id, &onu_cfg.hdr); |
| 1038 | if (err != BCM_ERR_OK) { |
| 1039 | BCM_LOG(ERROR, openolt_log_id, "Failed to set activate ONU %d on PON %d, err %d\n", onu_id, intf_id, err); |
| 1040 | return bcm_to_grpc_err(err, "Failed to activate ONU"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1041 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1042 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1043 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1046 | Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id, |
| 1047 | const char *vendor_id, const char *vendor_specific) { |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 1048 | bcmos_errno err = BCM_ERR_OK; |
| 1049 | bcmolt_onu_set_onu_state onu_oper; /* declare main API struct */ |
| 1050 | bcmolt_onu_cfg onu_cfg; |
| 1051 | bcmolt_onu_key onu_key; /**< Object key. */ |
| 1052 | bcmolt_onu_state onu_state; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1053 | |
Jason Huang | b1fad57 | 2019-05-28 19:02:30 +0800 | [diff] [blame] | 1054 | onu_key.onu_id = onu_id; |
| 1055 | onu_key.pon_ni = intf_id; |
| 1056 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1057 | BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state); |
| 1058 | err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr); |
| 1059 | if (err == BCM_ERR_OK) { |
| 1060 | switch (onu_state) { |
| 1061 | case BCMOLT_ONU_OPERATION_ACTIVE: |
| 1062 | BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key); |
| 1063 | BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data, |
| 1064 | onu_state, BCMOLT_ONU_OPERATION_INACTIVE); |
| 1065 | err = bcmolt_oper_submit(dev_id, &onu_oper.hdr); |
| 1066 | if (err != BCM_ERR_OK) { |
| 1067 | BCM_LOG(ERROR, openolt_log_id, "Failed to \ |
| 1068 | deactivate ONU %d on PON %d, err %d\n", onu_id, intf_id, err); |
| 1069 | return bcm_to_grpc_err(err, "Failed to deactivate ONU"); |
| 1070 | } |
| 1071 | break; |
| 1072 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | return Status::OK; |
| 1076 | } |
| 1077 | |
| 1078 | Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1079 | const char *vendor_id, const char *vendor_specific) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1080 | |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 1081 | BCM_LOG(INFO, openolt_log_id, "DeleteOnu ONU %d on PON %d : vendor id %s, vendor specific %s\n", |
| 1082 | onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str()); |
| 1083 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1084 | // Need to deactivate before removing it (BAL rules) |
| 1085 | |
| 1086 | DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific); |
| 1087 | // Sleep to allow the state to propagate |
| 1088 | // We need the subscriber terminal object to be admin down before removal |
| 1089 | // Without sleep the race condition is lost by ~ 20 ms |
| 1090 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 1091 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1092 | // TODO: Delete the schedulers and queues. |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1093 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1094 | bcmolt_onu_cfg cfg_obj; |
| 1095 | bcmolt_onu_key key; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1096 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1097 | BCM_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n", |
| 1098 | onu_id, intf_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1099 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1100 | key.onu_id = onu_id; |
| 1101 | key.pon_ni = intf_id; |
| 1102 | BCMOLT_CFG_INIT(&cfg_obj, onu, key); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1103 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1104 | bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1105 | if (err != BCM_ERR_OK) |
| 1106 | { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1107 | BCM_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n", |
| 1108 | onu_id, intf_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1109 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 1110 | } |
| 1111 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1112 | return Status::OK; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1115 | #define MAX_CHAR_LENGTH 20 |
| 1116 | #define MAX_OMCI_MSG_LENGTH 44 |
| 1117 | Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1118 | bcmolt_bin_str buf = {}; |
| 1119 | bcmolt_onu_cpu_packets omci_cpu_packets; |
| 1120 | bcmolt_onu_key key; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1121 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1122 | key.pon_ni = intf_id; |
| 1123 | key.onu_id = onu_id; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1124 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1125 | BCMOLT_OPER_INIT(&omci_cpu_packets, onu, cpu_packets, key); |
| 1126 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_OMCI); |
| 1127 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, calc_crc, BCMOS_TRUE); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1128 | |
| 1129 | // ??? |
| 1130 | if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) { |
| 1131 | buf.len = MAX_OMCI_MSG_LENGTH; |
| 1132 | } else { |
| 1133 | buf.len = pkt.size()/2; |
| 1134 | } |
| 1135 | |
| 1136 | /* Send the OMCI packet using the BAL remote proxy API */ |
| 1137 | uint16_t idx1 = 0; |
| 1138 | uint16_t idx2 = 0; |
| 1139 | uint8_t arraySend[buf.len]; |
| 1140 | char str1[MAX_CHAR_LENGTH]; |
| 1141 | char str2[MAX_CHAR_LENGTH]; |
| 1142 | memset(&arraySend, 0, buf.len); |
| 1143 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1144 | for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) { |
| 1145 | sprintf(str1,"%c", pkt[idx1]); |
| 1146 | sprintf(str2,"%c", pkt[++idx1]); |
| 1147 | strcat(str1,str2); |
| 1148 | arraySend[idx2] = strtol(str1, NULL, 16); |
| 1149 | } |
| 1150 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1151 | buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 1152 | memcpy(buf.arr, (uint8_t *)arraySend, buf.len); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1153 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1154 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, number_of_packets, 1); |
| 1155 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_size, buf.len); |
| 1156 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, buffer, buf); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1157 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1158 | bcmos_errno err = bcmolt_oper_submit(dev_id, &omci_cpu_packets.hdr); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1159 | if (err) { |
| 1160 | BCM_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id); |
| 1161 | } else { |
| 1162 | 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] | 1163 | buf.len, onu_id, intf_id, pkt.c_str()); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1164 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1165 | free(buf.arr); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1166 | |
| 1167 | return Status::OK; |
| 1168 | } |
| 1169 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1170 | Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, uint32_t port_no, uint32_t gemport_id, const std::string pkt) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1171 | bcmolt_pon_interface_cpu_packets pon_interface_cpu_packets; /**< declare main API struct */ |
| 1172 | bcmolt_pon_interface_key key = {.pon_ni = (bcmolt_interface)intf_id}; /**< declare key */ |
| 1173 | bcmolt_bin_str buf = {}; |
| 1174 | bcmolt_gem_port_id gem_port_id_array[1]; |
| 1175 | bcmolt_gem_port_id_list_u8_max_16 gem_port_list = {}; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1176 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1177 | if (port_no > 0) { |
| 1178 | bool found = false; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1179 | if (gemport_id == 0) { |
| 1180 | bcmos_fastlock_lock(&data_lock); |
| 1181 | // Map the port_no to one of the flows that owns it to find a gemport_id for that flow. |
| 1182 | // Pick any flow that is mapped with the same port_no. |
| 1183 | std::map<uint32_t, std::set<uint32_t> >::const_iterator it = port_to_flows.find(port_no); |
| 1184 | if (it != port_to_flows.end() && !it->second.empty()) { |
| 1185 | uint32_t flow_id = *(it->second.begin()); // Pick any flow_id out of the bag set |
| 1186 | std::map<uint32_t, uint32_t>::const_iterator fit = flowid_to_gemport.find(flow_id); |
| 1187 | if (fit != flowid_to_gemport.end()) { |
| 1188 | found = true; |
| 1189 | gemport_id = fit->second; |
| 1190 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1191 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1192 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1193 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1194 | if (!found) { |
| 1195 | BCM_LOG(ERROR, openolt_log_id, "Packet out failed to find destination for ONU %d port_no %u on PON %d\n", |
| 1196 | onu_id, port_no, intf_id); |
| 1197 | return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow for port_no"); |
| 1198 | } |
| 1199 | BCM_LOG(INFO, openolt_log_id, "Gem port %u found for ONU %d port_no %u on PON %d\n", |
| 1200 | gemport_id, onu_id, port_no, intf_id); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1201 | } |
| 1202 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1203 | gem_port_id_array[0] = gemport_id; |
| 1204 | gem_port_list.len = 1; |
| 1205 | gem_port_list.arr = gem_port_id_array; |
| 1206 | buf.len = pkt.size(); |
| 1207 | buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 1208 | memcpy(buf.arr, (uint8_t *)pkt.data(), buf.len); |
| 1209 | |
| 1210 | /* init the API struct */ |
| 1211 | BCMOLT_OPER_INIT(&pon_interface_cpu_packets, pon_interface, cpu_packets, key); |
| 1212 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_ETH); |
| 1213 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, calc_crc, BCMOS_TRUE); |
| 1214 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, gem_port_list, gem_port_list); |
| 1215 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, buffer, buf); |
| 1216 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1217 | BCM_LOG(INFO, openolt_log_id, "Packet out of length %d sent to gemport %d on pon %d port_no %u\n", |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1218 | (uint8_t)pkt.size(), gemport_id, intf_id, port_no); |
| 1219 | |
| 1220 | /* call API */ |
| 1221 | bcmolt_oper_submit(0, &pon_interface_cpu_packets.hdr); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1222 | } |
| 1223 | else { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1224 | //TODO: Port No is 0, it is coming sender requirement. |
| 1225 | BCM_LOG(INFO, openolt_log_id, "port_no %d onu %d on pon %d\n", |
| 1226 | port_no, onu_id, intf_id); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1227 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1228 | free(buf.arr); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1229 | |
| 1230 | return Status::OK; |
| 1231 | } |
| 1232 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1233 | Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt, bcmolt_flow_id flow_id) { |
| 1234 | bcmolt_flow_cfg cfg; |
| 1235 | bcmolt_flow_key key = {}; /* declare key */ |
| 1236 | bcmolt_bin_str buffer = {}; |
| 1237 | bcmolt_flow_send_eth_packet oper; /* declare main API struct */ |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1238 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1239 | key.flow_id = flow_id; |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1240 | key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; /* send from uplink direction */ |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1241 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1242 | /* Initialize the API struct. */ |
| 1243 | BCMOLT_OPER_INIT(&oper, flow, send_eth_packet, key); |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1244 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1245 | buffer.len = pkt.size(); |
| 1246 | buffer.arr = (uint8_t *)malloc((buffer.len)*sizeof(uint8_t)); |
| 1247 | memcpy(buffer.arr, (uint8_t *)pkt.data(), buffer.len); |
| 1248 | if (buffer.arr == NULL) { |
| 1249 | BCM_LOG(ERROR, openolt_log_id, "allocate pakcet buffer failed\n"); |
| 1250 | return bcm_to_grpc_err(BCM_ERR_PARM, "allocate pakcet buffer failed"); |
| 1251 | } |
| 1252 | BCMOLT_FIELD_SET(&oper.data, flow_send_eth_packet_data, buffer, buffer); |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1253 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1254 | bcmos_errno err = bcmolt_oper_submit(dev_id, &oper.hdr); |
| 1255 | if (err) |
| 1256 | BCM_LOG(ERROR, omci_log_id, "Error sending packets to port %d\n", intf_id); |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1257 | |
| 1258 | return Status::OK; |
| 1259 | } |
| 1260 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1261 | uint32_t GetPortNum_(uint32_t flow_id) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1262 | bcmos_fastlock_lock(&data_lock); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1263 | uint32_t port_no = 0; |
| 1264 | std::map<uint32_t, uint32_t >::const_iterator it = flowid_to_port.find(flow_id); |
| 1265 | if (it != flowid_to_port.end()) { |
| 1266 | port_no = it->second; |
| 1267 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1268 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1269 | return port_no; |
| 1270 | } |
| 1271 | |
| 1272 | 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] | 1273 | uint32_t flow_id, const std::string flow_type, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1274 | int32_t alloc_id, int32_t network_intf_id, |
| 1275 | int32_t gemport_id, const ::openolt::Classifier& classifier, |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1276 | const ::openolt::Action& action, int32_t priority_value, uint64_t cookie) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1277 | bcmolt_flow_cfg cfg; |
| 1278 | bcmolt_flow_key key = { }; /**< Object key. */ |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1279 | int32_t o_vid = -1; |
| 1280 | bool single_tag = false; |
| 1281 | uint32_t ether_type = 0; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1282 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1283 | 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, \ |
Jason Huang | 439d24f | 2019-06-26 03:25:05 +0800 | [diff] [blame] | 1284 | gemport_id %d, network_intf_id %d, cookie %"PRIu64"\n", \ |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1285 | 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] | 1286 | |
| 1287 | key.flow_id = flow_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1288 | if (flow_type.compare(upstream) == 0 ) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1289 | key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1290 | } else if (flow_type.compare(downstream) == 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1291 | key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1292 | } else { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1293 | 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] | 1294 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1297 | BCMOLT_CFG_INIT(&cfg, flow, key); |
| 1298 | BCMOLT_MSG_FIELD_SET(&cfg, cookie, cookie); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1299 | |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1300 | if (access_intf_id >= 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1301 | if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) { |
| 1302 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON); |
| 1303 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, access_intf_id); |
| 1304 | } else if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
| 1305 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON); |
| 1306 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id); |
| 1307 | } |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1308 | } |
| 1309 | if (network_intf_id >= 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1310 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
| 1311 | //TODO: The ingress type is NNI condition |
| 1312 | //BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.access_int_id.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI); |
| 1313 | //BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.access_int_id.intf_id, network_intf_id); |
| 1314 | //The egress type is PON condition |
| 1315 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON); |
| 1316 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id); |
| 1317 | } |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1318 | } |
| 1319 | if (onu_id >= 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1320 | BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1321 | } |
| 1322 | if (gemport_id >= 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1323 | BCMOLT_MSG_FIELD_SET(&cfg, svc_port_id, gemport_id); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1324 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1325 | if (gemport_id >= 0 && port_no != 0) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1326 | bcmos_fastlock_lock(&data_lock); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1327 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1328 | port_to_flows[port_no].insert(key.flow_id); |
| 1329 | flowid_to_gemport[key.flow_id] = gemport_id; |
| 1330 | } |
| 1331 | else |
| 1332 | { |
| 1333 | flowid_to_port[key.flow_id] = port_no; |
| 1334 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1335 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1336 | } |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1337 | if (priority_value >= 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1338 | BCMOLT_MSG_FIELD_SET(&cfg, priority, priority_value); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1339 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1340 | |
| 1341 | { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1342 | bcmolt_classifier val = { }; |
| 1343 | /* removed by BAL v3.0 |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1344 | if (classifier.o_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1345 | 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] | 1346 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_tpid, classifier.o_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1347 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1348 | */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1349 | if (classifier.o_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1350 | BCM_LOG(DEBUG, openolt_log_id, "classify o_vid %d\n", classifier.o_vid()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1351 | BCMOLT_FIELD_SET(&val, classifier, o_vid, classifier.o_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1352 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1353 | /* removed by BAL v3.0 |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1354 | if (classifier.i_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1355 | 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] | 1356 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, i_tpid, classifier.i_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1357 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1358 | */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1359 | if (classifier.i_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1360 | BCM_LOG(DEBUG, openolt_log_id, "classify i_vid %d\n", classifier.i_vid()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1361 | BCMOLT_FIELD_SET(&val, classifier, i_vid, classifier.i_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1364 | if (classifier.eth_type()) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1365 | ether_type = classifier.eth_type(); |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1366 | BCM_LOG(DEBUG, openolt_log_id, "classify ether_type 0x%04x\n", classifier.eth_type()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1367 | BCMOLT_FIELD_SET(&val, classifier, ether_type, classifier.eth_type()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /* |
| 1371 | if (classifier.dst_mac()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1372 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_mac, classifier.dst_mac()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | if (classifier.src_mac()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1376 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_mac, classifier.src_mac()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1377 | } |
| 1378 | */ |
| 1379 | |
| 1380 | if (classifier.ip_proto()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1381 | BCM_LOG(DEBUG, openolt_log_id, "classify ip_proto %d\n", classifier.ip_proto()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1382 | BCMOLT_FIELD_SET(&val, classifier, ip_proto, classifier.ip_proto()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /* |
| 1386 | if (classifier.dst_ip()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1387 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_ip, classifier.dst_ip()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | if (classifier.src_ip()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1391 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_ip, classifier.src_ip()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1392 | } |
| 1393 | */ |
| 1394 | |
| 1395 | if (classifier.src_port()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1396 | BCM_LOG(DEBUG, openolt_log_id, "classify src_port %d\n", classifier.src_port()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1397 | BCMOLT_FIELD_SET(&val, classifier, src_port, classifier.src_port()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | if (classifier.dst_port()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1401 | BCM_LOG(DEBUG, openolt_log_id, "classify dst_port %d\n", classifier.dst_port()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1402 | BCMOLT_FIELD_SET(&val, classifier, dst_port, classifier.dst_port()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | if (!classifier.pkt_tag_type().empty()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1406 | 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] | 1407 | if (classifier.pkt_tag_type().compare("untagged") == 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1408 | BCMOLT_FIELD_SET(&val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_UNTAGGED); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1409 | } else if (classifier.pkt_tag_type().compare("single_tag") == 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1410 | BCMOLT_FIELD_SET(&val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_SINGLE_TAG); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1411 | single_tag = true; |
| 1412 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1413 | BCM_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits()); |
| 1414 | BCMOLT_FIELD_SET(&val, classifier, o_pbits, classifier.o_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1415 | } else if (classifier.pkt_tag_type().compare("double_tag") == 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1416 | BCMOLT_FIELD_SET(&val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1417 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1418 | BCM_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits()); |
| 1419 | BCMOLT_FIELD_SET(&val, classifier, o_pbits, classifier.o_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1420 | } |
| 1421 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1422 | BCMOLT_MSG_FIELD_SET(&cfg, classifier, val); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1426 | bcmolt_action val = { }; |
| 1427 | bcmolt_api_prop_path path; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1428 | |
| 1429 | const ::openolt::ActionCmd& cmd = action.cmd(); |
| 1430 | |
| 1431 | if (cmd.add_outer_tag()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1432 | BCM_LOG(INFO, openolt_log_id, "action add o_tag\n"); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1433 | BCMOLT_FIELD_SET(&val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | if (cmd.remove_outer_tag()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1437 | BCM_LOG(INFO, openolt_log_id, "action pop o_tag\n"); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1438 | BCMOLT_FIELD_SET(&val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1439 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1440 | /* removed by BAL v3.0 |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1441 | if (cmd.trap_to_host()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1442 | BCM_LOG(INFO, openolt_log_id, "action trap-to-host\n"); |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1443 | 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] | 1444 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1445 | */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1446 | if (action.o_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1447 | 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] | 1448 | o_vid = action.o_vid(); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1449 | BCMOLT_FIELD_SET(&val, action, o_vid, action.o_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | if (action.o_pbits()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1453 | BCM_LOG(INFO, openolt_log_id, "action o_pbits=0x%x\n", action.o_pbits()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1454 | BCMOLT_FIELD_SET(&val, action, o_pbits, action.o_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1455 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1456 | /* removed by BAL v3.0 |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1457 | if (action.o_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1458 | 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] | 1459 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, o_tpid, action.o_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1460 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1461 | */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1462 | if (action.i_vid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1463 | BCM_LOG(INFO, openolt_log_id, "action i_vid=%d\n", action.i_vid()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1464 | BCMOLT_FIELD_SET(&val, action, i_vid, action.i_vid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | if (action.i_pbits()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1468 | BCM_LOG(DEBUG, openolt_log_id, "action i_pbits=0x%x\n", action.i_pbits()); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1469 | BCMOLT_FIELD_SET(&val, action, i_pbits, action.i_pbits()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1470 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1471 | /* removed by BAL v3.0 |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1472 | if (action.i_tpid()) { |
Craig Lutgen | ecd353a | 2018-12-12 22:33:17 -0600 | [diff] [blame] | 1473 | 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] | 1474 | BCMBAL_ATTRIBUTE_PROP_SET(&val, action, i_tpid, action.i_tpid()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1475 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1476 | */ |
| 1477 | BCMOLT_MSG_FIELD_SET(&cfg, action, val); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1480 | if ((access_intf_id >= 0) && (onu_id >= 0)) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1481 | bcmolt_tm_queue_ref val = { }; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1482 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1483 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1484 | if (single_tag && ether_type == EAP_ETHER_TYPE) { |
| 1485 | val.sched_id = get_default_tm_sched_id(access_intf_id, downstream); |
| 1486 | val.queue_id = 0; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1487 | } else { |
| 1488 | val.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, downstream); // Subscriber Scheduler |
| 1489 | val.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, downstream); |
| 1490 | } |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1491 | BCM_LOG(INFO, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d\n", \ |
| 1492 | downstream.c_str(), val.queue_id, val.sched_id); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1493 | |
| 1494 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE); |
| 1495 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, val.sched_id); |
| 1496 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, val.queue_id); |
| 1497 | } else if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) { |
| 1498 | /* removed by BAL v3.0. N/A - Alloc ID is out of the scope of BAL. Used for OMCI only. |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1499 | bcmbal_tm_sched_id val1; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1500 | 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] | 1501 | BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val1); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1502 | */ |
| 1503 | val.sched_id = get_default_tm_sched_id(network_intf_id, upstream); // NNI Scheduler ID |
| 1504 | val.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] | 1505 | BCM_LOG(INFO, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d\n", \ |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1506 | upstream.c_str(), val.queue_id, val.sched_id); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1507 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1508 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE); |
| 1509 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, val.sched_id); |
| 1510 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, val.queue_id); |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1513 | BCMOLT_MSG_FIELD_SET(&cfg, state, BCMOLT_FLOW_STATE_ENABLE); |
| 1514 | bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg.hdr); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 1515 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1516 | BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n"); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 1517 | return bcm_to_grpc_err(err, "flow add failed"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | return Status::OK; |
| 1521 | } |
| 1522 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1523 | Status FlowRemove_(uint32_t flow_id, const std::string flow_type) { |
| 1524 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1525 | bcmolt_flow_cfg cfg; |
| 1526 | bcmolt_flow_key key = { }; |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1527 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1528 | key.flow_id = (bcmolt_flow_id) flow_id; |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1529 | key.flow_id = flow_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1530 | if (flow_type.compare(upstream) == 0 ) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1531 | key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1532 | } else if (flow_type.compare(downstream) == 0) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1533 | key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1534 | } else { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1535 | 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] | 1536 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
| 1537 | } |
| 1538 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1539 | bcmos_fastlock_lock(&data_lock); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1540 | uint32_t port_no = flowid_to_port[key.flow_id]; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1541 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1542 | flowid_to_gemport.erase(key.flow_id); |
| 1543 | port_to_flows[port_no].erase(key.flow_id); |
| 1544 | if (port_to_flows[port_no].empty()) port_to_flows.erase(port_no); |
| 1545 | } |
| 1546 | else |
| 1547 | { |
| 1548 | flowid_to_port.erase(key.flow_id); |
| 1549 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1550 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1551 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1552 | BCMOLT_CFG_INIT(&cfg, flow, key); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1553 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1554 | bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg.hdr); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1555 | if (err) { |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1556 | BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n", |
| 1557 | err, flow_id, flow_type.c_str()); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 1558 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow"); |
| 1559 | } |
| 1560 | |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1561 | 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] | 1562 | return Status::OK; |
| 1563 | } |
| 1564 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1565 | Status CreateDefaultSchedQueue_(uint32_t intf_id, const std::string direction) { |
| 1566 | bcmos_errno err; |
| 1567 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 1568 | bcmolt_tm_sched_key tm_sched_key = {.id = 1}; |
| 1569 | tm_sched_key.id = get_default_tm_sched_id(intf_id, direction); |
| 1570 | |
| 1571 | // bcmbal_tm_sched_owner |
| 1572 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 1573 | |
| 1574 | /**< The output of the tm_sched object instance */ |
| 1575 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_INTERFACE); |
| 1576 | |
| 1577 | if (direction.compare(upstream) == 0) { |
| 1578 | // In upstream it is NNI scheduler |
| 1579 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_NNI); |
| 1580 | } else if (direction.compare(downstream) == 0) { |
| 1581 | // In downstream it is PON scheduler |
| 1582 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_PON); |
| 1583 | } |
| 1584 | |
| 1585 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_id, intf_id); |
| 1586 | |
| 1587 | // bcmbal_tm_sched_type |
| 1588 | // set the deafult policy to strict priority |
| 1589 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP); |
| 1590 | |
| 1591 | // num_priorities: Max number of strict priority scheduling elements |
| 1592 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, 4); |
| 1593 | |
| 1594 | // bcmbal_tm_shaping |
| 1595 | uint32_t cir = 1000000; |
| 1596 | uint32_t pir = 1000000; |
| 1597 | uint32_t burst = 65536; |
| 1598 | BCM_LOG(INFO, openolt_log_id, "applying traffic shaping in %s pir=%u, burst=%u\n", |
| 1599 | direction.c_str(), pir, burst); |
| 1600 | BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, pir); |
| 1601 | BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, burst); |
| 1602 | // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet' |
| 1603 | // BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.cir, cir); |
| 1604 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.pir, pir); |
| 1605 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.burst, burst); |
| 1606 | |
| 1607 | err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr); |
| 1608 | if (err) { |
| 1609 | BCM_LOG(ERROR, openolt_log_id, "Failed to create %s scheduler, id %d, intf_id %d\n", direction.c_str(), tm_sched_key.id, intf_id); |
| 1610 | return Status(grpc::StatusCode::INTERNAL, "Failed to create %s scheduler", direction.c_str()); |
| 1611 | } |
| 1612 | BCM_LOG(INFO, openolt_log_id, "Create %s scheduler success, id %d, intf_id %d\n", direction.c_str(), tm_sched_key.id, intf_id); |
| 1613 | |
| 1614 | // Create 4 Queues for each default PON scheduler |
| 1615 | for (int queue_id = 0; queue_id < 4; queue_id++) { |
| 1616 | bcmolt_tm_queue_cfg tm_queue_cfg; |
| 1617 | bcmolt_tm_queue_key tm_queue_key = {}; |
| 1618 | tm_queue_key.sched_id = get_default_tm_sched_id(intf_id, direction); |
| 1619 | tm_queue_key.id = queue_id; |
| 1620 | |
| 1621 | BCMOLT_CFG_INIT(&tm_queue_cfg, tm_queue, tm_queue_key); |
| 1622 | BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.type, BCMOLT_TM_SCHED_PARAM_TYPE_PRIORITY); |
| 1623 | BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.u.priority.priority, queue_id); |
| 1624 | |
| 1625 | err = bcmolt_cfg_set(dev_id, &tm_queue_cfg.hdr); |
| 1626 | if (err) { |
| 1627 | BCM_LOG(ERROR, openolt_log_id, "Failed to create %s tm queue, id %d, sched_id %d\n", \ |
| 1628 | direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id); |
| 1629 | return Status(grpc::StatusCode::INTERNAL, "Failed to create %s tm queue", direction.c_str()); |
| 1630 | } |
| 1631 | |
| 1632 | BCM_LOG(INFO, openolt_log_id, "Create %s tm_queue success, id %d, sched_id %d\n", \ |
| 1633 | direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id); |
| 1634 | } |
| 1635 | return Status::OK; |
| 1636 | } |
| 1637 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1638 | bcmos_errno CreateSched(std::string direction, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t port_no, |
| 1639 | uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, uint32_t priority, |
| 1640 | tech_profile::SchedulingPolicy sched_policy, tech_profile::TrafficShapingInfo tf_sh_info) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1641 | |
| 1642 | bcmos_errno err; |
| 1643 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1644 | if (direction == downstream) { |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1645 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 1646 | bcmolt_tm_sched_key tm_sched_key = {.id = 1}; |
| 1647 | tm_sched_key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1648 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1649 | // bcmbal_tm_sched_owner |
| 1650 | // In downstream it is sub_term scheduler |
| 1651 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1652 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1653 | /**< The output of the tm_sched object instance */ |
| 1654 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_TM_SCHED); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1655 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1656 | // bcmbal_tm_sched_parent |
| 1657 | // The parent for the sub_term scheduler is the PON scheduler in the downstream |
| 1658 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_id, get_default_tm_sched_id(intf_id, direction)); |
| 1659 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_param.u.priority.priority, priority); |
| 1660 | /* removed by BAL v3.0, N/A - No direct attachment point of type ONU, same functionality may |
| 1661 | be achieved using the' virtual' type of attachment. |
| 1662 | tm_sched_owner.u.sub_term.intf_id = intf_id; |
| 1663 | tm_sched_owner.u.sub_term.sub_term_id = onu_id; |
| 1664 | */ |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1665 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1666 | // bcmbal_tm_sched_type |
| 1667 | // set the deafult policy to strict priority |
| 1668 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1669 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1670 | // num_priorities: Max number of strict priority scheduling elements |
| 1671 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, 8); |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1672 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1673 | // bcmbal_tm_shaping |
| 1674 | if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) { |
| 1675 | uint32_t cir = tf_sh_info.cir(); |
| 1676 | uint32_t pir = tf_sh_info.pir(); |
| 1677 | uint32_t burst = tf_sh_info.pbs(); |
| 1678 | BCM_LOG(INFO, openolt_log_id, "applying traffic shaping in DL cir=%u, pir=%u, burst=%u\n", |
| 1679 | cir, pir, burst); |
| 1680 | BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, pir); |
| 1681 | BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, burst); |
| 1682 | // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet' |
| 1683 | //BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.cir, cir); |
| 1684 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.pir, pir); |
| 1685 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.burst, burst); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1686 | } |
| 1687 | |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1688 | err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1689 | if (err) { |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1690 | BCM_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, \ |
| 1691 | intf_id %d, onu_id %d, uni_id %d, port_no %u\n", tm_sched_key.id, intf_id, onu_id, \ |
| 1692 | uni_id, port_no); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1693 | return err; |
| 1694 | } |
| 1695 | BCM_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \ |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1696 | uni_id %d, port_no %u\n", tm_sched_key.id, intf_id, onu_id, uni_id, port_no); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1697 | |
| 1698 | } else { //upstream |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1699 | bcmolt_itupon_alloc_cfg cfg; |
Thiyagarajan Subramani | 0695c98 | 2019-06-05 07:30:50 -0700 | [diff] [blame] | 1700 | bcmolt_itupon_alloc_key key = { }; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1701 | key.pon_ni = intf_id; |
| 1702 | key.alloc_id = alloc_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1703 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1704 | BCMOLT_CFG_INIT(&cfg, itupon_alloc, key); |
| 1705 | BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id); |
| 1706 | if (additional_bw == 2) //AdditionalBW_BestEffort |
| 1707 | BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, |
| 1708 | BCMOLT_ADDITIONAL_BW_ELIGIBILITY_BEST_EFFORT); |
| 1709 | else if (additional_bw == 3) //AdditionalBW_Auto |
| 1710 | BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, |
| 1711 | BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NON_ASSURED); |
| 1712 | /* CBR Real Time Bandwidth which require shaping of the bandwidth allocations |
| 1713 | in a fine granularity. */ |
| 1714 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_bw, 0); |
| 1715 | /* Fixed Bandwidth with no critical requirement of shaping */ |
| 1716 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_bw, 0); |
| 1717 | /* Dynamic bandwidth which the OLT is committed to allocate upon demand */ |
| 1718 | BCMOLT_MSG_FIELD_SET(&cfg, sla.guaranteed_bw, 0); |
| 1719 | /* Maximum allocated bandwidth allowed for this alloc ID */ |
| 1720 | BCMOLT_MSG_FIELD_SET(&cfg, sla.maximum_bw, tf_sh_info.pir()); |
| 1721 | BCMOLT_MSG_FIELD_SET(&cfg, sla.alloc_type, BCMOLT_ALLOC_TYPE_NSR); |
| 1722 | /* Set to True for AllocID with CBR RT Bandwidth that requires compensation |
| 1723 | for skipped allocations during quiet window */ |
| 1724 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_compensation, BCMOS_FALSE); |
| 1725 | /**< Allocation Profile index for CBR non-RT Bandwidth */ |
| 1726 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_ap_index, 0); |
| 1727 | /**< Allocation Profile index for CBR RT Bandwidth */ |
| 1728 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_ap_index, 0); |
| 1729 | /**< Alloc ID Weight used in case of Extended DBA mode */ |
| 1730 | BCMOLT_MSG_FIELD_SET(&cfg, sla.weight, 0); |
| 1731 | /**< Alloc ID Priority used in case of Extended DBA mode */ |
| 1732 | BCMOLT_MSG_FIELD_SET(&cfg, sla.priority, 0); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1733 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1734 | err = bcmolt_cfg_set(dev_id, &(cfg.hdr)); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1735 | if (err) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1736 | BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, intf_id %d, onu_id %d, uni_id %d,\ |
| 1737 | port_no %u, alloc_id %d\n", intf_id, onu_id,uni_id,port_no,alloc_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1738 | return err; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1739 | } |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1740 | BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, intf_id %d, onu_id %d, uni_id %d, port_no %u, \ |
| 1741 | alloc_id %d\n", intf_id,onu_id,uni_id,port_no,alloc_id); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1742 | } |
| 1743 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1744 | return BCM_ERR_OK; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1745 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1746 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1747 | Status CreateTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) { |
| 1748 | uint32_t intf_id = traffic_scheds->intf_id(); |
| 1749 | uint32_t onu_id = traffic_scheds->onu_id(); |
| 1750 | uint32_t uni_id = traffic_scheds->uni_id(); |
| 1751 | uint32_t port_no = traffic_scheds->port_no(); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1752 | std::string direction; |
| 1753 | unsigned int alloc_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1754 | tech_profile::SchedulerConfig sched_config; |
| 1755 | tech_profile::AdditionalBW additional_bw; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1756 | uint32_t priority; |
| 1757 | uint32_t weight; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1758 | tech_profile::SchedulingPolicy sched_policy; |
| 1759 | tech_profile::TrafficShapingInfo traffic_shaping_info; |
| 1760 | bcmos_errno err; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1761 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1762 | for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) { |
| 1763 | tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i); |
| 1764 | if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) { |
| 1765 | direction = upstream; |
| 1766 | } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1767 | direction = downstream; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1768 | } |
| 1769 | else { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1770 | 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] | 1771 | return Status::CANCELLED; |
| 1772 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1773 | alloc_id = traffic_sched.alloc_id(); |
| 1774 | sched_config = traffic_sched.scheduler(); |
| 1775 | additional_bw = sched_config.additional_bw(); |
| 1776 | priority = sched_config.priority(); |
| 1777 | weight = sched_config.weight(); |
| 1778 | sched_policy = sched_config.sched_policy(); |
| 1779 | traffic_shaping_info = traffic_sched.traffic_shaping_info(); |
| 1780 | err = CreateSched(direction, intf_id, onu_id, uni_id, port_no, alloc_id, additional_bw, weight, priority, |
| 1781 | sched_policy, traffic_shaping_info); |
| 1782 | if (err) { |
| 1783 | return bcm_to_grpc_err(err, "Failed to create scheduler"); |
| 1784 | } |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 1785 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1786 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1787 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1788 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1789 | 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] | 1790 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1791 | bcmos_errno err; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1792 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1793 | if (direction == upstream) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1794 | bcmolt_itupon_alloc_cfg cfg; |
| 1795 | bcmolt_itupon_alloc_key key = { }; |
| 1796 | key.pon_ni = intf_id; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1797 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1798 | BCMOLT_CFG_INIT(&cfg, itupon_alloc, key); |
| 1799 | BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id); |
| 1800 | BCMOLT_CFG_INIT(&cfg, itupon_alloc, key); |
| 1801 | err = bcmolt_cfg_clear(dev_id, &(cfg.hdr)); |
| 1802 | if (err) { |
| 1803 | BCM_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, intf_id %d, onu_id %d\n", \ |
| 1804 | direction.c_str(), intf_id, onu_id); |
| 1805 | return err; |
| 1806 | } |
| 1807 | BCM_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, intf_id %d, onu_id %d\n", \ |
| 1808 | direction.c_str(), intf_id, onu_id); |
| 1809 | } else if (direction == downstream) { |
| 1810 | bcmolt_tm_sched_cfg cfg; |
| 1811 | bcmolt_tm_sched_key key = { }; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1812 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1813 | if (is_tm_sched_id_present(intf_id, onu_id, uni_id, direction)) { |
| 1814 | key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction); |
| 1815 | } else { |
| 1816 | BCM_LOG(INFO, openolt_log_id, "schduler not present in %s\n", direction.c_str()); |
| 1817 | return BCM_ERR_OK; |
| 1818 | } |
| 1819 | BCMOLT_CFG_INIT(&cfg, tm_sched, key); |
| 1820 | err = bcmolt_cfg_clear(dev_id, &(cfg.hdr)); |
| 1821 | if (err) { |
| 1822 | BCM_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \ |
| 1823 | direction.c_str(), key.id, intf_id, onu_id); |
| 1824 | return err; |
| 1825 | } |
| 1826 | BCM_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \ |
| 1827 | direction.c_str(), key.id, intf_id, onu_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | free_tm_sched_id(intf_id, onu_id, uni_id, direction); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1831 | return BCM_ERR_OK; |
| 1832 | } |
| 1833 | |
| 1834 | Status RemoveTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) { |
| 1835 | uint32_t intf_id = traffic_scheds->intf_id(); |
| 1836 | uint32_t onu_id = traffic_scheds->onu_id(); |
| 1837 | uint32_t uni_id = traffic_scheds->uni_id(); |
| 1838 | std::string direction; |
| 1839 | bcmos_errno err; |
| 1840 | |
| 1841 | for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) { |
| 1842 | tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i); |
| 1843 | if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) { |
| 1844 | direction = upstream; |
| 1845 | } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1846 | direction = downstream; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1847 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1848 | else { |
| 1849 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_sched.direction()); |
| 1850 | return Status::CANCELLED; |
| 1851 | } |
| 1852 | err = RemoveSched(intf_id, onu_id, uni_id, direction); |
| 1853 | if (err) { |
| 1854 | return bcm_to_grpc_err(err, "error-removing-traffic-scheduler"); |
| 1855 | } |
| 1856 | } |
| 1857 | return Status::OK; |
| 1858 | } |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1859 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1860 | bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority, |
| 1861 | uint32_t gemport_id) { |
| 1862 | bcmos_errno err; |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1863 | bcmolt_tm_queue_cfg cfg; |
| 1864 | bcmolt_tm_queue_key key = { }; |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1865 | BCM_LOG(INFO, openolt_log_id, "creating queue. access_intf_id = %d, onu_id = %d, uni_id = %d \ |
| 1866 | 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] | 1867 | if (direction == downstream) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1868 | // There is one queue per gem port |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1869 | key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction); |
| 1870 | 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] | 1871 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1872 | } else { |
| 1873 | queue_map_key_tuple map_key(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1874 | if (queue_map.count(map_key) > 0) { |
| 1875 | BCM_LOG(INFO, openolt_log_id, "upstream queue exists for intf_id %d, onu_id %d, uni_id %d\n. Not re-creating", \ |
| 1876 | access_intf_id, onu_id, uni_id); |
| 1877 | return BCM_ERR_OK; |
| 1878 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1879 | key.sched_id = get_default_tm_sched_id(nni_intf_id, direction); |
| 1880 | if (priority > 7) { |
| 1881 | return BCM_ERR_RANGE; |
| 1882 | } |
| 1883 | // There are 8 queues (one per p-bit) |
| 1884 | key.id = us_fixed_queue_id_list[priority]; |
| 1885 | update_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction, key.id); |
| 1886 | // FIXME: The upstream queues have to be created once only. |
| 1887 | // The upstream queues on the NNI scheduler are shared by all subscribers. |
| 1888 | // When the first scheduler comes in, the queues get created, and are re-used by all others. |
| 1889 | // Also, these queues should be present until the last subscriber exits the system. |
| 1890 | // One solution is to have these queues always, i.e., create it as soon as OLT is enabled. |
| 1891 | } |
Girish Gowdru | 3650155 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 1892 | BCM_LOG(INFO, openolt_log_id, "queue assigned queue_id = %d\n", key.id); |
| 1893 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1894 | BCMOLT_CFG_INIT(&cfg, tm_queue, key); |
| 1895 | BCMOLT_MSG_FIELD_SET(&cfg, tm_sched_param.u.priority.priority, priority); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1896 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1897 | err = bcmolt_cfg_set(dev_id, &cfg.hdr); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1898 | if (err) { |
| 1899 | BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, id %d, sched_id %d, \ |
| 1900 | intf_id %d, onu_id %d, uni_id %d\n", \ |
| 1901 | direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id); |
| 1902 | return err; |
| 1903 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1904 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1905 | BCM_LOG(INFO, openolt_log_id, "Created tm_queue, direction %s, id %d, intf_id %d, onu_id %d, uni_id %d", \ |
| 1906 | direction.c_str(), key.id, access_intf_id, onu_id, uni_id); |
| 1907 | |
| 1908 | return BCM_ERR_OK; |
| 1909 | |
| 1910 | } |
| 1911 | |
| 1912 | Status CreateTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) { |
| 1913 | uint32_t intf_id = traffic_queues->intf_id(); |
| 1914 | uint32_t onu_id = traffic_queues->onu_id(); |
| 1915 | uint32_t uni_id = traffic_queues->uni_id(); |
| 1916 | std::string direction; |
| 1917 | unsigned int alloc_id; |
| 1918 | bcmos_errno err; |
| 1919 | |
| 1920 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
| 1921 | tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
| 1922 | if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) { |
| 1923 | direction = upstream; |
| 1924 | } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1925 | direction = downstream; |
| 1926 | } |
| 1927 | else { |
| 1928 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_queue.direction()); |
| 1929 | return Status::CANCELLED; |
| 1930 | } |
| 1931 | 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] | 1932 | // If the queue exists already, lets not return failure and break the loop. |
| 1933 | if (err && err != BCM_ERR_ALREADY) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1934 | return bcm_to_grpc_err(err, "Failed to create queue"); |
| 1935 | } |
| 1936 | } |
| 1937 | return Status::OK; |
| 1938 | } |
| 1939 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1940 | bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority, |
| 1941 | uint32_t gemport_id) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1942 | bcmolt_tm_queue_cfg cfg; |
| 1943 | bcmolt_tm_queue_key key = { }; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1944 | bcmos_errno err; |
| 1945 | |
| 1946 | if (direction == downstream) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1947 | if (is_tm_queue_id_present(access_intf_id, onu_id, uni_id, gemport_id, direction) && \ |
| 1948 | is_tm_sched_id_present(access_intf_id, onu_id, uni_id, direction)) { |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1949 | key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction); |
| 1950 | key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1951 | } else { |
| 1952 | BCM_LOG(INFO, openolt_log_id, "queue not present in DS. Not clearing"); |
| 1953 | return BCM_ERR_OK; |
| 1954 | } |
| 1955 | } else { |
| 1956 | free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1957 | // In the upstream we use pre-created queues on the NNI scheduler that are used by all subscribers. |
| 1958 | // They should not be removed. So, lets return OK. |
| 1959 | return BCM_ERR_OK; |
| 1960 | } |
| 1961 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1962 | BCMOLT_CFG_INIT(&cfg, tm_queue, key); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1963 | |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1964 | err = bcmolt_cfg_clear(dev_id, &(cfg.hdr)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1965 | |
| 1966 | if (err) { |
| 1967 | 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", |
Jason Huang | d33b4d8 | 2019-05-15 18:22:57 +0800 | [diff] [blame] | 1968 | direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1969 | return err; |
| 1970 | } |
| 1971 | |
| 1972 | free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction); |
| 1973 | |
| 1974 | return BCM_ERR_OK; |
| 1975 | } |
| 1976 | |
| 1977 | Status RemoveTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) { |
| 1978 | uint32_t intf_id = traffic_queues->intf_id(); |
| 1979 | uint32_t onu_id = traffic_queues->onu_id(); |
| 1980 | uint32_t uni_id = traffic_queues->uni_id(); |
| 1981 | uint32_t port_no = traffic_queues->port_no(); |
| 1982 | std::string direction; |
| 1983 | unsigned int alloc_id; |
| 1984 | bcmos_errno err; |
| 1985 | |
| 1986 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
| 1987 | tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
| 1988 | if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) { |
| 1989 | direction = upstream; |
| 1990 | } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) { |
| 1991 | direction = downstream; |
| 1992 | } else { |
| 1993 | BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_queue.direction()); |
| 1994 | return Status::CANCELLED; |
| 1995 | } |
| 1996 | err = RemoveQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id()); |
| 1997 | if (err) { |
| 1998 | return bcm_to_grpc_err(err, "Failed to remove queue"); |
| 1999 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2000 | } |
| 2001 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2002 | return Status::OK; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2003 | } |