Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1 | /* |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 3 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 7 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 9 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 16 | |
| 17 | #include <iostream> |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 | |
| 21 | #include "Queue.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 22 | #include <sstream> |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 23 | #include <chrono> |
| 24 | #include <thread> |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 25 | #include <bitset> |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 26 | #include <inttypes.h> |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 27 | #include <unistd.h> |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 28 | #include <sys/socket.h> |
| 29 | #include <netinet/in.h> |
| 30 | #include <arpa/inet.h> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 31 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 32 | #include "device.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 33 | #include "core.h" |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 34 | #include "core_data.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 35 | #include "indications.h" |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 36 | #include "stats_collection.h" |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 37 | #include "error_format.h" |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 38 | #include "state.h" |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 39 | #include "core_utils.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 40 | |
| 41 | extern "C" |
| 42 | { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 43 | #include <bcmolt_api.h> |
| 44 | #include <bcmolt_host_api.h> |
| 45 | #include <bcmolt_api_model_supporting_enums.h> |
| 46 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 47 | #include <bcmolt_api_conn_mgr.h> |
| 48 | //CLI header files |
| 49 | #include <bcmcli_session.h> |
| 50 | #include <bcmcli.h> |
| 51 | #include <bcm_api_cli.h> |
| 52 | |
| 53 | #include <bcmos_common.h> |
| 54 | #include <bcm_config.h> |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 55 | // FIXME : dependency problem |
| 56 | // #include <bcm_common_gpon.h> |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 57 | // #include <bcm_dev_log_task.h> |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 58 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 59 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 60 | static std::string intf_technologies[MAX_SUPPORTED_PON]; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 61 | static const std::string UNKNOWN_TECH("unknown"); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 62 | static const std::string MIXED_TECH("mixed"); |
| 63 | static std::string board_technology(UNKNOWN_TECH); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 64 | static std::string chip_family(UNKNOWN_TECH); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 65 | static std::string firmware_version = "Openolt.2019.07.01"; |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 66 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 67 | static bcmos_errno CreateSched(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 68 | uint32_t port_no, uint32_t alloc_id, ::tech_profile::AdditionalBW additional_bw, uint32_t weight, \ |
| 69 | uint32_t priority, ::tech_profile::SchedulingPolicy sched_policy, |
| 70 | ::tech_profile::TrafficShapingInfo traffic_shaping_info, uint32_t tech_profile_id); |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 71 | static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction, int tech_profile_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 72 | static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 73 | bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id); |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 74 | static bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 75 | bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 76 | static bcmos_errno CreateDefaultSched(uint32_t intf_id, const std::string direction); |
| 77 | static bcmos_errno CreateDefaultQueue(uint32_t intf_id, const std::string direction); |
| 78 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 79 | inline const char *get_flow_acton_command(uint32_t command) { |
| 80 | char actions[200] = { }; |
| 81 | char *s_actions_ptr = actions; |
| 82 | if (command & BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG) strcat(s_actions_ptr, "ADD_OUTER_TAG|"); |
| 83 | if (command & BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG) strcat(s_actions_ptr, "REMOVE_OUTER_TAG|"); |
| 84 | if (command & BCMOLT_ACTION_CMD_ID_XLATE_OUTER_TAG) strcat(s_actions_ptr, "TRANSLATE_OUTER_TAG|"); |
| 85 | if (command & BCMOLT_ACTION_CMD_ID_ADD_INNER_TAG) strcat(s_actions_ptr, "ADD_INNTER_TAG|"); |
| 86 | if (command & BCMOLT_ACTION_CMD_ID_REMOVE_INNER_TAG) strcat(s_actions_ptr, "REMOVE_INNER_TAG|"); |
| 87 | if (command & BCMOLT_ACTION_CMD_ID_XLATE_INNER_TAG) strcat(s_actions_ptr, "TRANSLATE_INNER_TAG|"); |
| 88 | if (command & BCMOLT_ACTION_CMD_ID_REMARK_OUTER_PBITS) strcat(s_actions_ptr, "REMOVE_OUTER_PBITS|"); |
| 89 | if (command & BCMOLT_ACTION_CMD_ID_REMARK_INNER_PBITS) strcat(s_actions_ptr, "REMAKE_INNER_PBITS|"); |
| 90 | return s_actions_ptr; |
| 91 | } |
| 92 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 93 | bcmolt_stat_alarm_config set_stat_alarm_config(const config::OnuItuPonAlarm* request) { |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 94 | bcmolt_stat_alarm_config alarm_cfg = {}; |
| 95 | bcmolt_stat_alarm_trigger_config trigger_obj = {}; |
| 96 | bcmolt_stat_alarm_soak_config soak_obj = {}; |
| 97 | |
| 98 | switch (request->alarm_reporting_condition()) { |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 99 | case config::OnuItuPonAlarm::RATE_THRESHOLD: |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 100 | trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 101 | BCMOLT_FIELD_SET(&trigger_obj.u.rate_threshold, stat_alarm_trigger_config_rate_threshold, |
| 102 | rising, request->rate_threshold_config().rate_threshold_rising()); |
| 103 | BCMOLT_FIELD_SET(&trigger_obj.u.rate_threshold, stat_alarm_trigger_config_rate_threshold, |
| 104 | falling, request->rate_threshold_config().rate_threshold_falling()); |
| 105 | BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time, |
| 106 | request->rate_threshold_config().soak_time().active_soak_time()); |
| 107 | BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time, |
| 108 | request->rate_threshold_config().soak_time().clear_soak_time()); |
| 109 | break; |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 110 | case config::OnuItuPonAlarm::RATE_RANGE: |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 111 | trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 112 | BCMOLT_FIELD_SET(&trigger_obj.u.rate_range, stat_alarm_trigger_config_rate_range, upper, |
| 113 | request->rate_range_config().rate_range_upper()); |
| 114 | BCMOLT_FIELD_SET(&trigger_obj.u.rate_range, stat_alarm_trigger_config_rate_range, lower, |
| 115 | request->rate_range_config().rate_range_lower()); |
| 116 | BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time, |
| 117 | request->rate_range_config().soak_time().active_soak_time()); |
| 118 | BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time, |
| 119 | request->rate_range_config().soak_time().clear_soak_time()); |
| 120 | break; |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 121 | case config::OnuItuPonAlarm::VALUE_THRESHOLD: |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 122 | trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 123 | BCMOLT_FIELD_SET(&trigger_obj.u.value_threshold, stat_alarm_trigger_config_value_threshold, |
| 124 | limit, request->value_threshold_config().threshold_limit()); |
| 125 | BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time, |
| 126 | request->value_threshold_config().soak_time().active_soak_time()); |
| 127 | BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time, |
| 128 | request->value_threshold_config().soak_time().clear_soak_time()); |
| 129 | break; |
| 130 | default: |
| 131 | OPENOLT_LOG(ERROR, openolt_log_id, "unsupported alarm reporting condition = %u\n", request->alarm_reporting_condition()); |
| 132 | // For now just log the error and not return error. We can handle this scenario in the future. |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | BCMOLT_FIELD_SET(&alarm_cfg, stat_alarm_config, trigger, trigger_obj); |
| 137 | BCMOLT_FIELD_SET(&alarm_cfg, stat_alarm_config, soak, soak_obj); |
| 138 | |
| 139 | return alarm_cfg; |
| 140 | } |
| 141 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 142 | Status OnuItuPonAlarmSet_(const config::OnuItuPonAlarm* request) { |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 143 | bcmos_errno err; |
| 144 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; /* declare main API struct */ |
| 145 | bcmolt_onu_key key = {}; /* declare key */ |
| 146 | bcmolt_stat_alarm_config errors_cfg = {}; |
| 147 | |
| 148 | key.pon_ni = request->pon_ni(); |
| 149 | key.onu_id = request->onu_id(); |
| 150 | |
| 151 | /* Initialize the API struct. */ |
| 152 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 153 | |
| 154 | /* |
| 155 | 1. BCMOLT_STAT_CONDITION_TYPE_NONE = 0, The alarm is disabled. |
| 156 | 2. BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD = 1, The alarm is triggered if the stats delta value between samples |
| 157 | crosses the configured threshold boundary. |
| 158 | rising: The alarm is raised if the stats delta value per second becomes greater than this threshold level. |
| 159 | falling: The alarm is cleared if the stats delta value per second becomes less than this threshold level. |
| 160 | 3. BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE = 2, The alarm is triggered if the stats delta value between samples |
| 161 | deviates from the configured range. |
| 162 | upper: The alarm is raised if the stats delta value per second becomes greater than this upper level. |
| 163 | lower: The alarm is raised if the stats delta value per second becomes less than this lower level. |
| 164 | 4. BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD = 3, The alarm is raised if the stats sample value becomes greater |
| 165 | than this level. The alarm is cleared when the host read the stats. |
| 166 | limit: The alarm is raised if the stats sample value becomes greater than this level. |
| 167 | The alarm is cleared when the host clears the stats. |
| 168 | |
| 169 | active_soak_time: If the alarm condition is raised and stays in the raised state for at least this amount |
| 170 | of time (unit=seconds), the alarm indication is sent to the host. |
| 171 | The OLT delays the alarm indication no less than this delay period. |
| 172 | It can be delayed more than this period because of the statistics sampling interval. |
| 173 | clear_soak_time: After the alarm is raised, if it is cleared and stays in the cleared state for at least |
| 174 | this amount of time (unit=seconds), the alarm indication is sent to the host. |
| 175 | The OLT delays the alarm indication no less than this delay period. It can be delayed more |
| 176 | than this period because of the statistics sampling interval. |
| 177 | */ |
| 178 | |
| 179 | errors_cfg = set_stat_alarm_config(request); |
| 180 | |
| 181 | switch (request->alarm_id()) { |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 182 | case config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS: |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 183 | //set the rdi_errors alarm |
| 184 | BCMOLT_FIELD_SET(&stat_cfg.data, onu_itu_pon_stats_cfg_data, rdi_errors, errors_cfg); |
| 185 | break; |
| 186 | default: |
| 187 | OPENOLT_LOG(ERROR, openolt_log_id, "could not find the alarm id %d\n", request->alarm_id()); |
| 188 | return bcm_to_grpc_err(BCM_ERR_PARM, "the alarm id is wrong"); |
| 189 | } |
| 190 | |
| 191 | err = bcmolt_stat_cfg_set(dev_id, &stat_cfg.hdr); |
| 192 | if (err != BCM_ERR_OK) { |
| 193 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to set onu itu pon stats, alarm id %d, pon_ni %d, onu_id %d, err = %s\n", |
| 194 | request->alarm_id(), key.pon_ni, key.onu_id, bcmos_strerror(err)); |
| 195 | return bcm_to_grpc_err(err, "set Onu ITU PON stats alarm faild"); |
| 196 | } else { |
| 197 | OPENOLT_LOG(INFO, openolt_log_id, "set onu itu pon stats alarm %d successfully, pon_ni %d, onu_id %d\n", |
| 198 | request->alarm_id(), key.pon_ni, key.onu_id); |
| 199 | } |
| 200 | |
| 201 | return Status::OK; |
| 202 | } |
| 203 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 204 | Status GetDeviceInfo_(::openolt::DeviceInfo* device_info) { |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 205 | device_info->set_vendor(VENDOR_ID); |
| 206 | device_info->set_model(MODEL_ID); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 207 | device_info->set_hardware_version(""); |
| 208 | device_info->set_firmware_version(firmware_version); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 209 | device_info->set_technology(board_technology); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 210 | device_info->set_pon_ports(num_of_pon_ports); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 211 | |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 212 | char serial_number[OPENOLT_FIELD_LEN]; |
| 213 | memset(serial_number, '\0', OPENOLT_FIELD_LEN); |
| 214 | openolt_read_sysinfo("Serial Number", serial_number); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 215 | OPENOLT_LOG(INFO, openolt_log_id, "Fetched device serial number %s\n", serial_number); |
Thiyagarajan Subramani | 5e97353 | 2019-02-02 03:21:43 -0800 | [diff] [blame] | 216 | device_info->set_device_serial_number(serial_number); |
| 217 | |
Girish Gowdru | 771f9ff | 2019-07-24 12:02:10 -0700 | [diff] [blame] | 218 | char device_id[OPENOLT_FIELD_LEN]; |
| 219 | memset(device_id, '\0', OPENOLT_FIELD_LEN); |
Humera Kouser | 6143c9e | 2020-06-17 22:37:31 +0530 | [diff] [blame] | 220 | |
| 221 | if (grpc_server_interface_name != NULL) { |
| 222 | if (get_intf_mac(grpc_server_interface_name, device_id, sizeof(device_id)) != NULL) |
| 223 | { |
| 224 | OPENOLT_LOG(INFO, openolt_log_id, "Fetched mac address %s of an interface %s\n", device_id, grpc_server_interface_name); |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | OPENOLT_LOG(ERROR, openolt_log_id, "Mac address of an interface %s is NULL\n", grpc_server_interface_name); |
| 229 | } |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | openolt_read_sysinfo("MAC", device_id); |
| 234 | OPENOLT_LOG(INFO, openolt_log_id, "Fetched device mac address %s\n", device_id); |
| 235 | } |
| 236 | |
Girish Gowdru | 771f9ff | 2019-07-24 12:02:10 -0700 | [diff] [blame] | 237 | device_info->set_device_id(device_id); |
| 238 | |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 239 | // Legacy, device-wide ranges. To be deprecated when adapter |
| 240 | // is upgraded to support per-interface ranges |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 241 | device_info->set_onu_id_start(ONU_ID_START); |
| 242 | device_info->set_onu_id_end(ONU_ID_END); |
| 243 | device_info->set_alloc_id_start(ALLOC_ID_START); |
| 244 | device_info->set_alloc_id_end(ALLOC_ID_END); |
| 245 | device_info->set_gemport_id_start(GEM_PORT_ID_START); |
| 246 | device_info->set_gemport_id_end(GEM_PORT_ID_END); |
| 247 | device_info->set_flow_id_start(FLOW_ID_START); |
| 248 | device_info->set_flow_id_end(FLOW_ID_END); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 249 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 250 | std::map<std::string, ::openolt::DeviceInfo::DeviceResourceRanges*> ranges; |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 251 | for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) { |
| 252 | std::string intf_technology = intf_technologies[intf_id]; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 253 | ::openolt::DeviceInfo::DeviceResourceRanges *range = ranges[intf_technology]; |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 254 | if(range == nullptr) { |
| 255 | range = device_info->add_ranges(); |
| 256 | ranges[intf_technology] = range; |
| 257 | range->set_technology(intf_technology); |
| 258 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 259 | ::openolt::DeviceInfo::DeviceResourceRanges::Pool* pool; |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 260 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 261 | pool = range->add_pools(); |
| 262 | pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID); |
| 263 | pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 264 | pool->set_start(ONU_ID_START); |
| 265 | pool->set_end(ONU_ID_END); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 266 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 267 | pool = range->add_pools(); |
| 268 | pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID); |
| 269 | pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 270 | pool->set_start(ALLOC_ID_START); |
| 271 | pool->set_end(ALLOC_ID_START); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 272 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 273 | pool = range->add_pools(); |
| 274 | pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID); |
| 275 | pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF); |
| 276 | pool->set_start(GEM_PORT_ID_START); |
| 277 | pool->set_end(GEM_PORT_ID_END); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 278 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 279 | pool = range->add_pools(); |
| 280 | pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID); |
| 281 | pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH); |
| 282 | pool->set_start(FLOW_ID_START); |
| 283 | pool->set_end(FLOW_ID_END); |
Craig Lutgen | b2601f0 | 2018-10-23 13:04:31 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | range->add_intf_ids(intf_id); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 287 | } |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 288 | |
| 289 | // FIXME: Once dependency problem is fixed |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 290 | // device_info->set_pon_ports(num_of_pon_ports); |
Nicolas Palpacuer | f0b0249 | 2018-09-10 10:21:29 -0400 | [diff] [blame] | 291 | // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1); |
| 292 | // device_info->set_alloc_id_start(1024); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 293 | // 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] | 294 | // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 295 | // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1); |
| 296 | // device_info->set_pon_ports(num_of_pon_ports); |
Nicolas Palpacuer | dff9679 | 2018-09-06 14:59:32 -0400 | [diff] [blame] | 297 | |
| 298 | return Status::OK; |
| 299 | } |
| 300 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 301 | Status Enable_(int argc, char *argv[]) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 302 | bcmos_errno err; |
| 303 | bcmolt_host_init_parms init_parms = {}; |
| 304 | init_parms.transport.type = BCM_HOST_API_CONN_LOCAL; |
| 305 | unsigned int failed_enable_device_cnt = 0; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 306 | |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 307 | if (!state.is_activated()) { |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 308 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 309 | vendor_init(); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 310 | /* Initialize host subsystem */ |
| 311 | err = bcmolt_host_init(&init_parms); |
| 312 | if (BCM_ERR_OK != err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 313 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to init OLT, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 314 | return bcm_to_grpc_err(err, "Failed to init OLT"); |
| 315 | } |
| 316 | |
| 317 | bcmcli_session_parm mon_session_parm; |
| 318 | /* Create CLI session */ |
| 319 | memset(&mon_session_parm, 0, sizeof(mon_session_parm)); |
| 320 | mon_session_parm.get_prompt = openolt_cli_get_prompt_cb; |
| 321 | mon_session_parm.access_right = BCMCLI_ACCESS_ADMIN; |
| 322 | bcmos_errno rc = bcmcli_session_open(&mon_session_parm, ¤t_session); |
| 323 | BUG_ON(rc != BCM_ERR_OK); |
| 324 | |
| 325 | /* API CLI */ |
| 326 | bcm_openolt_api_cli_init(NULL, current_session); |
| 327 | |
| 328 | /* Add quit command */ |
| 329 | BCMCLI_MAKE_CMD_NOPARM(NULL, "quit", "Quit", bcm_cli_quit); |
| 330 | |
| 331 | err = bcmolt_apiend_cli_init(); |
| 332 | if (BCM_ERR_OK != err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 333 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to add apiend init, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 334 | return bcm_to_grpc_err(err, "Failed to add apiend init"); |
| 335 | } |
| 336 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 337 | bcmos_fastlock_init(&data_lock, 0); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 338 | bcmos_fastlock_init(&acl_id_bitset_lock, 0); |
| 339 | bcmos_fastlock_init(&tm_sched_bitset_lock, 0); |
| 340 | bcmos_fastlock_init(&tm_qmp_bitset_lock, 0); |
| 341 | bcmos_fastlock_init(&flow_id_bitset_lock, 0); |
| 342 | bcmos_fastlock_init(&voltha_flow_to_device_flow_lock, 0); |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 343 | bcmos_fastlock_init(&alloc_cfg_wait_lock, 0); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 344 | bcmos_fastlock_init(&onu_deactivate_wait_lock, 0); |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 345 | bcmos_fastlock_init(&acl_packet_trap_handler_lock, 0); |
| 346 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 347 | OPENOLT_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 348 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 349 | //check BCM daemon is connected or not |
| 350 | Status status = check_connection(); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 351 | if (!status.ok()) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 352 | return status; |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 353 | } |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 354 | else { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 355 | Status status = SubscribeIndication(); |
| 356 | if (!status.ok()) { |
| 357 | OPENOLT_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n", |
| 358 | grpc_status_code_to_string(status.error_code()).c_str(), |
| 359 | status.error_message().c_str()); |
| 360 | return status; |
| 361 | } |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 362 | |
| 363 | //check BAL state in initial stage |
| 364 | status = check_bal_ready(); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 365 | if (!status.ok()) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 366 | return status; |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 367 | } |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 371 | bcmos_errno err; |
| 372 | bcmolt_odid dev; |
| 373 | OPENOLT_LOG(INFO, openolt_log_id, "Enabling PON %d Devices ... \n", BCM_MAX_DEVS_PER_LINE_CARD); |
| 374 | for (dev = 0; dev < BCM_MAX_DEVS_PER_LINE_CARD; dev++) { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 375 | bcmolt_device_cfg dev_cfg = { }; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 376 | bcmolt_device_key dev_key = { }; |
| 377 | dev_key.device_id = dev; |
| 378 | BCMOLT_CFG_INIT(&dev_cfg, device, dev_key); |
| 379 | BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode); |
| 380 | err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr); |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 381 | if (err == BCM_ERR_NOT_CONNECTED) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 382 | bcmolt_device_key key = {.device_id = dev}; |
| 383 | bcmolt_device_connect oper; |
| 384 | BCMOLT_OPER_INIT(&oper, device, connect, key); |
| 385 | if (MODEL_ID == "asfvolt16") { |
| 386 | BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI); |
| 387 | BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_XGS__2_X); |
| 388 | } else if (MODEL_ID == "asgvolt64") { |
| 389 | BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI); |
| 390 | BCMOLT_MSG_FIELD_SET(&oper, inni_config.mux, BCMOLT_INNI_MUX_FOUR_TO_ONE); |
| 391 | BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_GPON__16_X); |
| 392 | } |
| 393 | err = bcmolt_oper_submit(dev_id, &oper.hdr); |
| 394 | if (err) { |
| 395 | failed_enable_device_cnt ++; |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 396 | OPENOLT_LOG(ERROR, openolt_log_id, "Enable PON device %d failed, err = %s\n", dev, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 397 | if (failed_enable_device_cnt == BCM_MAX_DEVS_PER_LINE_CARD) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 398 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable all the pon ports, err = %s\n", bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 399 | return Status(grpc::StatusCode::INTERNAL, "Failed to activate all PON ports"); |
| 400 | } |
| 401 | } |
| 402 | bcmos_usleep(200000); |
| 403 | } |
| 404 | else { |
| 405 | OPENOLT_LOG(WARNING, openolt_log_id, "PON deivce %d already connected\n", dev); |
| 406 | state.activate(); |
| 407 | } |
| 408 | } |
| 409 | init_stats(); |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 410 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 411 | } |
Shad Ansari | edef213 | 2018-08-10 22:14:50 +0000 | [diff] [blame] | 412 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 413 | /* Start CLI */ |
| 414 | OPENOLT_LOG(INFO, def_log_id, "Starting CLI\n"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 415 | //If already enabled, generate an extra indication ???? |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 416 | return Status::OK; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | Status Disable_() { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 420 | //In the earlier implementation Disabling olt is done by disabling the NNI port associated with that. |
| 421 | //In inband scenario instead of using management interface to establish connection with adapter ,NNI interface will be used. |
| 422 | //Disabling NNI port on olt disable causes connection loss between adapter and agent. |
| 423 | //To overcome this disable is implemented by disabling all the PON ports |
| 424 | //associated with the device so as to support both in-band |
| 425 | //and out of band scenarios. |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 426 | |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 427 | Status status; |
| 428 | int failedCount = 0; |
| 429 | for (int i = 0; i < NumPonIf_(); i++) { |
| 430 | status = DisablePonIf_(i); |
| 431 | if (!status.ok()) { |
| 432 | failedCount+=1; |
| 433 | BCM_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n", i); |
| 434 | } |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 435 | } |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 436 | if (failedCount == 0) { |
| 437 | state.deactivate(); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 438 | ::openolt::Indication ind; |
| 439 | ::openolt::OltIndication* olt_ind = new ::openolt::OltIndication; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 440 | olt_ind->set_oper_state("down"); |
| 441 | ind.set_allocated_olt_ind(olt_ind); |
| 442 | BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n"); |
| 443 | oltIndQ.push(ind); |
| 444 | return Status::OK; |
| 445 | } |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 446 | if (failedCount ==NumPonIf_()) { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 447 | return grpc::Status(grpc::StatusCode::INTERNAL, "failed to disable olt ,all the PON ports are still in enabled state"); |
| 448 | } |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 449 | |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 450 | return grpc::Status(grpc::StatusCode::UNKNOWN, "failed to disable olt ,few PON ports are still in enabled state"); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | Status Reenable_() { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 454 | Status status; |
| 455 | int failedCount = 0; |
| 456 | for (int i = 0; i < NumPonIf_(); i++) { |
| 457 | status = EnablePonIf_(i); |
| 458 | if (!status.ok()) { |
| 459 | failedCount+=1; |
| 460 | BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", i); |
| 461 | } |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 462 | } |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 463 | if (failedCount == 0) { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 464 | state.activate(); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 465 | ::openolt::Indication ind; |
| 466 | ::openolt::OltIndication* olt_ind = new ::openolt::OltIndication; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 467 | olt_ind->set_oper_state("up"); |
| 468 | ind.set_allocated_olt_ind(olt_ind); |
| 469 | BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n"); |
| 470 | oltIndQ.push(ind); |
| 471 | return Status::OK; |
| 472 | } |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 473 | if (failedCount ==NumPonIf_()) { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 474 | return grpc::Status(grpc::StatusCode::INTERNAL, "failed to re-enable olt ,all the PON ports are still in disabled state"); |
| 475 | } |
| 476 | return grpc::Status(grpc::StatusCode::UNKNOWN, "failed to re-enable olt ,few PON ports are still in disabled state"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 479 | inline uint64_t get_flow_status(uint16_t flow_id, uint16_t flow_type, uint16_t data_id) { |
| 480 | bcmos_errno err; |
| 481 | bcmolt_flow_key flow_key; |
| 482 | bcmolt_flow_cfg flow_cfg; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 483 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 484 | flow_key.flow_id = flow_id; |
| 485 | flow_key.flow_type = (bcmolt_flow_type)flow_type; |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 486 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 487 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 488 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 489 | switch (data_id) { |
| 490 | case ONU_ID: //onu_id |
| 491 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, onu_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 492 | #ifdef TEST_MODE |
| 493 | // It is impossible to mock the setting of flow_cfg.data.state because |
| 494 | // the actual bcmolt_cfg_get passes the address of flow_cfg.hdr and we cannot |
| 495 | // set the flow_cfg.data. So a new stub function is created and address |
| 496 | // of flow_cfg is passed. This is one-of case where we need to add test specific |
| 497 | // code in production code. |
| 498 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 499 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 500 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 501 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 502 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 503 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get onu_id, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 504 | return err; |
| 505 | } |
| 506 | return flow_cfg.data.onu_id; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 507 | case FLOW_TYPE: |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 508 | #ifdef TEST_MODE |
| 509 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 510 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 511 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 512 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 513 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 514 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get flow_type, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 515 | return err; |
| 516 | } |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 517 | return flow_cfg.key.flow_type; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 518 | case SVC_PORT_ID: //svc_port_id |
| 519 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, svc_port_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 520 | #ifdef TEST_MODE |
| 521 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 522 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 523 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 524 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 525 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 526 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get svc_port_id, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 527 | return err; |
| 528 | } |
| 529 | return flow_cfg.data.svc_port_id; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 530 | case PRIORITY: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 531 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, priority); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 532 | #ifdef TEST_MODE |
| 533 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 534 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 535 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 536 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 537 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 538 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get priority, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 539 | return err; |
| 540 | } |
| 541 | return flow_cfg.data.priority; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 542 | case COOKIE: //cookie |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 543 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, cookie); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 544 | #ifdef TEST_MODE |
| 545 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 546 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 547 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 548 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 549 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 550 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get cookie, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 551 | return err; |
| 552 | } |
| 553 | return flow_cfg.data.cookie; |
| 554 | case INGRESS_INTF_TYPE: //ingress intf_type |
| 555 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 556 | #ifdef TEST_MODE |
| 557 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 558 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 559 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 560 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 561 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 562 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_type, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 563 | return err; |
| 564 | } |
| 565 | return flow_cfg.data.ingress_intf.intf_type; |
| 566 | case EGRESS_INTF_TYPE: //egress intf_type |
| 567 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_intf); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 568 | #ifdef TEST_MODE |
| 569 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 570 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 571 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 572 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 573 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 574 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_type, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 575 | return err; |
| 576 | } |
| 577 | return flow_cfg.data.egress_intf.intf_type; |
| 578 | case INGRESS_INTF_ID: //ingress intf_id |
| 579 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 580 | #ifdef TEST_MODE |
| 581 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 582 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 583 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 584 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 585 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 586 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_id, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 587 | return err; |
| 588 | } |
| 589 | return flow_cfg.data.ingress_intf.intf_id; |
| 590 | case EGRESS_INTF_ID: //egress intf_id |
| 591 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_intf); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 592 | #ifdef TEST_MODE |
| 593 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 594 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 595 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 596 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 597 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 598 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_id, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 599 | return err; |
| 600 | } |
| 601 | return flow_cfg.data.egress_intf.intf_id; |
| 602 | case CLASSIFIER_O_VID: |
| 603 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 604 | #ifdef TEST_MODE |
| 605 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 606 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 607 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 608 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 609 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 610 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_vid, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 611 | return err; |
| 612 | } |
| 613 | return flow_cfg.data.classifier.o_vid; |
| 614 | case CLASSIFIER_O_PBITS: |
| 615 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 616 | #ifdef TEST_MODE |
| 617 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 618 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 619 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 620 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 621 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 622 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_pbits, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 623 | return err; |
| 624 | } |
| 625 | return flow_cfg.data.classifier.o_pbits; |
| 626 | case CLASSIFIER_I_VID: |
| 627 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 628 | #ifdef TEST_MODE |
| 629 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 630 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 631 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 632 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 633 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 634 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_vid, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 635 | return err; |
| 636 | } |
| 637 | return flow_cfg.data.classifier.i_vid; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 638 | case CLASSIFIER_I_PBITS: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 639 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 640 | #ifdef TEST_MODE |
| 641 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 642 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 643 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 644 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 645 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 646 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_pbits, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 647 | return err; |
| 648 | } |
| 649 | return flow_cfg.data.classifier.i_pbits; |
| 650 | case CLASSIFIER_ETHER_TYPE: |
| 651 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 652 | #ifdef TEST_MODE |
| 653 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 654 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 655 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 656 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 657 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 658 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ether_type, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 659 | return err; |
| 660 | } |
| 661 | return flow_cfg.data.classifier.ether_type; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 662 | case CLASSIFIER_IP_PROTO: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 663 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 664 | #ifdef TEST_MODE |
| 665 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 666 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 667 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 668 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 669 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 670 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ip_proto, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 671 | return err; |
| 672 | } |
| 673 | return flow_cfg.data.classifier.ip_proto; |
| 674 | case CLASSIFIER_SRC_PORT: |
| 675 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 676 | #ifdef TEST_MODE |
| 677 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 678 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 679 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 680 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 681 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 682 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier src_port, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 683 | return err; |
| 684 | } |
| 685 | return flow_cfg.data.classifier.src_port; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 686 | case CLASSIFIER_DST_PORT: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 687 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 688 | #ifdef TEST_MODE |
| 689 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 690 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 691 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 692 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 693 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 694 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier dst_port, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 695 | return err; |
| 696 | } |
| 697 | return flow_cfg.data.classifier.dst_port; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 698 | case CLASSIFIER_PKT_TAG_TYPE: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 699 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 700 | #ifdef TEST_MODE |
| 701 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 702 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 703 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 704 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 705 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 706 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier pkt_tag_type, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 707 | return err; |
| 708 | } |
| 709 | return flow_cfg.data.classifier.pkt_tag_type; |
| 710 | case EGRESS_QOS_TYPE: |
| 711 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 712 | #ifdef TEST_MODE |
| 713 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 714 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 715 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 716 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 717 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 718 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos type, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 719 | return err; |
| 720 | } |
| 721 | return flow_cfg.data.egress_qos.type; |
| 722 | case EGRESS_QOS_QUEUE_ID: |
| 723 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 724 | #ifdef TEST_MODE |
| 725 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 726 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 727 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 728 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 729 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 730 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos queue_id, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 731 | return err; |
| 732 | } |
| 733 | switch (flow_cfg.data.egress_qos.type) { |
| 734 | case BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE: |
| 735 | return flow_cfg.data.egress_qos.u.fixed_queue.queue_id; |
| 736 | case BCMOLT_EGRESS_QOS_TYPE_TC_TO_QUEUE: |
| 737 | return flow_cfg.data.egress_qos.u.tc_to_queue.tc_to_queue_id; |
| 738 | case BCMOLT_EGRESS_QOS_TYPE_PBIT_TO_TC: |
| 739 | return flow_cfg.data.egress_qos.u.pbit_to_tc.tc_to_queue_id; |
| 740 | case BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE: |
| 741 | return flow_cfg.data.egress_qos.u.priority_to_queue.tm_q_set_id; |
| 742 | case BCMOLT_EGRESS_QOS_TYPE_NONE: |
| 743 | default: |
| 744 | return -1; |
| 745 | } |
| 746 | case EGRESS_QOS_TM_SCHED_ID: |
| 747 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 748 | #ifdef TEST_MODE |
| 749 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 750 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 751 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 752 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 753 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 754 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos tm_sched_id, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 755 | return err; |
| 756 | } |
| 757 | return flow_cfg.data.egress_qos.tm_sched.id; |
| 758 | case ACTION_CMDS_BITMASK: |
| 759 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 760 | #ifdef TEST_MODE |
| 761 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 762 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 763 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 764 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 765 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 766 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action cmds_bitmask, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 767 | return err; |
| 768 | } |
| 769 | return flow_cfg.data.action.cmds_bitmask; |
| 770 | case ACTION_O_VID: |
| 771 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 772 | #ifdef TEST_MODE |
| 773 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 774 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 775 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 776 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 777 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 778 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_vid, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 779 | return err; |
| 780 | } |
| 781 | return flow_cfg.data.action.o_vid; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 782 | case ACTION_O_PBITS: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 783 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 784 | #ifdef TEST_MODE |
| 785 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 786 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 787 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 788 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 789 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 790 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_pbits, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 791 | return err; |
| 792 | } |
| 793 | return flow_cfg.data.action.o_pbits; |
| 794 | case ACTION_I_VID: |
| 795 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 796 | #ifdef TEST_MODE |
| 797 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 798 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 799 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 800 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 801 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 802 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_vid, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 803 | return err; |
| 804 | } |
| 805 | return flow_cfg.data.action.i_vid; |
| 806 | case ACTION_I_PBITS: |
| 807 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 808 | #ifdef TEST_MODE |
| 809 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 810 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 811 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 812 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 813 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 814 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_pbits, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 815 | return err; |
| 816 | } |
| 817 | return flow_cfg.data.action.i_pbits; |
| 818 | case STATE: |
| 819 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, state); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 820 | #ifdef TEST_MODE |
| 821 | err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg); |
| 822 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 823 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 824 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 825 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 826 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get state, err = %s\n",bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 827 | return err; |
| 828 | } |
| 829 | return flow_cfg.data.state; |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 830 | case GROUP_ID: |
| 831 | BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, group_id); |
| 832 | err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr); |
| 833 | if (err) { |
| 834 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get group_id, err = %s\n",bcmos_strerror(err)); |
| 835 | return err; |
| 836 | } |
| 837 | return flow_cfg.data.group_id; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 838 | default: |
| 839 | return BCM_ERR_INTERNAL; |
| 840 | } |
| 841 | |
| 842 | return err; |
| 843 | } |
| 844 | |
| 845 | Status EnablePonIf_(uint32_t intf_id) { |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 846 | bcmos_errno err = BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 847 | bcmolt_pon_interface_cfg interface_obj; |
| 848 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id}; |
| 849 | bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state; |
| 850 | bcmolt_interface_state state; |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 851 | bcmolt_status los_status; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 852 | |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 853 | err = get_pon_interface_status((bcmolt_interface)intf_id, &state, &los_status); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 854 | if (err == BCM_ERR_OK) { |
| 855 | if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 856 | OPENOLT_LOG(WARNING, openolt_log_id, "PON interface: %d already enabled\n", intf_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 857 | return Status::OK; |
| 858 | } |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 859 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 860 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
| 861 | BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key); |
| 862 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_ENABLE); |
| 863 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.interval, 5000); |
| 864 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.onu_post_discovery_mode, |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 865 | BCMOLT_ONU_POST_DISCOVERY_MODE_NONE); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 866 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.los, true); |
| 867 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.onu_alarms, true); |
| 868 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.tiwi, true); |
| 869 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.ack_timeout, true); |
| 870 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.sfi, true); |
| 871 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.loki, true); |
Burak Gurdag | 5e58779 | 2020-05-06 14:58:02 +0000 | [diff] [blame] | 872 | |
| 873 | // On GPON, power level mode is not set to its default value (i.e. 0) as documented in Broadcom documentation. |
| 874 | // Instead, it is set to 2 which means -6 dbM attenuation. Therefore, we explicitly set it to the default value below. |
| 875 | if (board_technology == "GPON") { |
| 876 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.gpon.power_level.pls_maximum_allocation_size, BCMOLT_PON_POWER_LEVEL_PLS_MAXIMUM_ALLOCATION_SIZE_DEFAULT); |
| 877 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.gpon.power_level.mode, BCMOLT_PON_POWER_LEVEL_MODE_DEFAULT); |
| 878 | } |
| 879 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 880 | //Enable AES Encryption |
| 881 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.onu_activation.key_exchange, BCMOLT_CONTROL_STATE_ENABLE); |
| 882 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.onu_activation.authentication, BCMOLT_CONTROL_STATE_ENABLE); |
| 883 | BCMOLT_MSG_FIELD_SET(&interface_obj, itu.onu_activation.fail_due_to_authentication_failure, BCMOLT_CONTROL_STATE_ENABLE); |
| 884 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 885 | BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data, |
| 886 | operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING); |
| 887 | |
| 888 | err = bcmolt_cfg_set(dev_id, &interface_obj.hdr); |
| 889 | if (err != BCM_ERR_OK) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 890 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable discovery onu, PON interface %d, err = %s\n", intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 891 | return bcm_to_grpc_err(err, "Failed to enable discovery onu"); |
| 892 | } |
| 893 | err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr); |
| 894 | if (err != BCM_ERR_OK) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 895 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d, err = %s\n", intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 896 | return bcm_to_grpc_err(err, "Failed to enable PON interface"); |
| 897 | } |
| 898 | else { |
| 899 | OPENOLT_LOG(INFO, openolt_log_id, "Successfully enabled PON interface: %d\n", intf_id); |
| 900 | OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for PON interface: %d\n", intf_id); |
| 901 | CreateDefaultSched(intf_id, downstream); |
| 902 | CreateDefaultQueue(intf_id, downstream); |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | return Status::OK; |
| 906 | } |
| 907 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 908 | Status ProbeDeviceCapabilities_() { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 909 | bcmos_errno err; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 910 | bcmolt_device_cfg dev_cfg = { }; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 911 | bcmolt_device_key dev_key = { }; |
| 912 | bcmolt_olt_cfg olt_cfg = { }; |
| 913 | bcmolt_olt_key olt_key = { }; |
| 914 | bcmolt_topology_map topo_map[BCM_MAX_PONS_PER_OLT] = { }; |
| 915 | bcmolt_topology topo = { }; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 916 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 917 | topo.topology_maps.len = BCM_MAX_PONS_PER_OLT; |
| 918 | topo.topology_maps.arr = &topo_map[0]; |
| 919 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 920 | BCMOLT_MSG_FIELD_GET(&olt_cfg, bal_state); |
| 921 | BCMOLT_FIELD_SET_PRESENT(&olt_cfg.data, olt_cfg_data, topology); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 922 | BCMOLT_CFG_LIST_BUF_SET(&olt_cfg, olt, topo.topology_maps.arr, |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 923 | sizeof(bcmolt_topology_map) * topo.topology_maps.len); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 924 | #ifdef TEST_MODE |
| 925 | // It is impossible to mock the setting of olt_cfg.data.bal_state because |
| 926 | // the actual bcmolt_cfg_get passes the address of olt_cfg.hdr and we cannot |
| 927 | // set the olt_cfg.data.topology. So a new stub function is created and address |
| 928 | // of olt_cfg is passed. This is one-of case where we need to test add specific |
| 929 | // code in production code. |
| 930 | err = bcmolt_cfg_get__olt_topology_stub(dev_id, &olt_cfg); |
| 931 | #else |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 932 | err = bcmolt_cfg_get_mult_retry(dev_id, &olt_cfg.hdr); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 933 | #endif |
| 934 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 935 | OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query OLT topology, err = %s\n", bcmos_strerror(err)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 936 | return bcm_to_grpc_err(err, "cfg: Failed to query OLT topology"); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 937 | } |
| 938 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 939 | num_of_nni_ports = olt_cfg.data.topology.num_switch_ports; |
| 940 | num_of_pon_ports = olt_cfg.data.topology.topology_maps.len; |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 941 | |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 942 | OPENOLT_LOG(INFO, openolt_log_id, "OLT capabilitites, oper_state: %s\n", |
| 943 | olt_cfg.data.bal_state == BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 944 | ? "up" : "down"); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 945 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 946 | OPENOLT_LOG(INFO, openolt_log_id, "topology nni: %d pon: %d dev: %d\n", |
| 947 | num_of_nni_ports, |
| 948 | num_of_pon_ports, |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 949 | BCM_MAX_DEVS_PER_LINE_CARD); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 950 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 951 | uint32_t num_failed_cfg_gets = 0; |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 952 | static std::string openolt_version = firmware_version; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 953 | for (int devid = 0; devid < BCM_MAX_DEVS_PER_LINE_CARD; devid++) { |
| 954 | dev_key.device_id = devid; |
| 955 | BCMOLT_CFG_INIT(&dev_cfg, device, dev_key); |
| 956 | BCMOLT_MSG_FIELD_GET(&dev_cfg, firmware_sw_version); |
| 957 | BCMOLT_MSG_FIELD_GET(&dev_cfg, chip_family); |
| 958 | BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 959 | err = bcmolt_cfg_get_mult_retry(dev_id, &dev_cfg.hdr); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 960 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 961 | OPENOLT_LOG(WARNING, openolt_log_id,"Failed to query PON MAC Device %d (errno = %s). Skipping the device.\n", devid, bcmos_strerror(err)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 962 | num_failed_cfg_gets++; |
| 963 | continue; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 964 | } |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 965 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 966 | std::string bal_version; |
| 967 | bal_version += std::to_string(dev_cfg.data.firmware_sw_version.major) |
| 968 | + "." + std::to_string(dev_cfg.data.firmware_sw_version.minor) |
| 969 | + "." + std::to_string(dev_cfg.data.firmware_sw_version.revision); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 970 | firmware_version = "BAL." + bal_version + "__" + openolt_version; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 971 | |
| 972 | switch(dev_cfg.data.system_mode) { |
| 973 | case 10: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*4,(devid+1)*4,"GPON"); break; |
| 974 | case 11: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*8,(devid+1)*8,"GPON"); break; |
| 975 | case 12: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"GPON"); break; |
| 976 | case 13: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,"XGPON"); break; |
| 977 | case 14: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*4,(devid+1)*4,"XGPON"); break; |
| 978 | case 15: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*8,(devid+1)*8,"XGPON"); break; |
| 979 | case 16: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"XGPON"); break; |
| 980 | case 18: board_technology = "XGS-PON"; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,"XGS-PON"); break; |
| 981 | case 19: board_technology = "XGS-PON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"XGS-PON"); break; |
| 982 | case 20: board_technology = MIXED_TECH; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,MIXED_TECH); break; |
| 983 | } |
| 984 | |
| 985 | switch(dev_cfg.data.chip_family) { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 986 | case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6862_X: chip_family = "Maple"; break; |
| 987 | case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6865_X: chip_family = "Aspen"; break; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 990 | OPENOLT_LOG(INFO, openolt_log_id, "device %d, pon: %d, version %s, family: %s, board_technology: %s\n", |
| 991 | devid, BCM_MAX_PONS_PER_DEV, bal_version.c_str(), chip_family.c_str(), board_technology.c_str()); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 992 | |
| 993 | bcmos_usleep(500000); |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 994 | } |
| 995 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 996 | /* If all the devices returned errors then we tell the caller that this is an error else we work with |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 997 | only the devices that retured success*/ |
| 998 | if (num_failed_cfg_gets == BCM_MAX_DEVS_PER_LINE_CARD) { |
| 999 | OPENOLT_LOG(ERROR, openolt_log_id, "device: Query of all the devices failed\n"); |
| 1000 | return bcm_to_grpc_err(err, "device: All devices failed query"); |
| 1001 | } |
| 1002 | |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 1003 | return Status::OK; |
| 1004 | } |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 1005 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1006 | Status SetStateUplinkIf_(uint32_t intf_id, bool set_state) { |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1007 | bcmos_errno err = BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1008 | bcmolt_nni_interface_key intf_key = {.id = (bcmolt_interface)intf_id}; |
| 1009 | bcmolt_nni_interface_set_nni_state nni_interface_set_state; |
| 1010 | bcmolt_interface_state state; |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 1011 | |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 1012 | err = get_nni_interface_status((bcmolt_interface)intf_id, &state); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1013 | if (err == BCM_ERR_OK) { |
| 1014 | if (set_state && state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) { |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 1015 | OPENOLT_LOG(WARNING, openolt_log_id, "NNI interface: %d already enabled\n", intf_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1016 | OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id); |
| 1017 | CreateDefaultSched(intf_id, upstream); |
| 1018 | CreateDefaultQueue(intf_id, upstream); |
| 1019 | return Status::OK; |
| 1020 | } else if (!set_state && state == BCMOLT_INTERFACE_STATE_INACTIVE) { |
| 1021 | OPENOLT_LOG(INFO, openolt_log_id, "NNI interface: %d already disabled\n", intf_id); |
| 1022 | return Status::OK; |
| 1023 | } |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 1024 | } |
| 1025 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1026 | BCMOLT_OPER_INIT(&nni_interface_set_state, nni_interface, set_nni_state, intf_key); |
| 1027 | if (set_state) { |
| 1028 | BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data, |
| 1029 | nni_state, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING); |
| 1030 | } else { |
| 1031 | BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data, |
| 1032 | nni_state, BCMOLT_INTERFACE_OPERATION_INACTIVE); |
| 1033 | } |
| 1034 | err = bcmolt_oper_submit(dev_id, &nni_interface_set_state.hdr); |
| 1035 | if (err != BCM_ERR_OK) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 1036 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to %s NNI interface: %d, err = %s\n", |
| 1037 | (set_state)?"enable":"disable", intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1038 | return bcm_to_grpc_err(err, "Failed to enable NNI interface"); |
| 1039 | } |
| 1040 | else { |
| 1041 | OPENOLT_LOG(INFO, openolt_log_id, "Successfully %s NNI interface: %d\n", (set_state)?"enable":"disable", intf_id); |
| 1042 | if (set_state) { |
| 1043 | OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id); |
| 1044 | CreateDefaultSched(intf_id, upstream); |
| 1045 | CreateDefaultQueue(intf_id, upstream); |
| 1046 | } |
Nicolas Palpacuer | e3fc0d2 | 2018-08-02 16:51:05 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | return Status::OK; |
| 1050 | } |
| 1051 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 1052 | Status DisablePonIf_(uint32_t intf_id) { |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 1053 | bcmos_errno err; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1054 | bcmolt_pon_interface_cfg interface_obj; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 1055 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id}; |
| 1056 | bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state; |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 1057 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 1058 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
| 1059 | BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key); |
| 1060 | BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_DISABLE); |
| 1061 | |
| 1062 | err = bcmolt_cfg_set(dev_id, &interface_obj.hdr); |
| 1063 | if (err != BCM_ERR_OK) { |
| 1064 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable discovery of onu, PON interface %d, err %d\n", intf_id, err); |
| 1065 | return bcm_to_grpc_err(err, "Failed to disable discovery of onu"); |
| 1066 | } |
| 1067 | |
| 1068 | BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data, |
| 1069 | operation, BCMOLT_INTERFACE_OPERATION_INACTIVE); |
| 1070 | |
| 1071 | err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr); |
| 1072 | if (err != BCM_ERR_OK) { |
| 1073 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n , err %d\n", intf_id, err); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 1074 | return bcm_to_grpc_err(err, "Failed to disable PON interface"); |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 1075 | } |
| 1076 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 1077 | OPENOLT_LOG(INFO, openolt_log_id, "Successfully disabled PON interface: %d\n", intf_id); |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 1078 | return Status::OK; |
| 1079 | } |
| 1080 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1081 | Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id, |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 1082 | const char *vendor_id, const char *vendor_specific, uint32_t pir, bool omcc_encryption_mode) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1083 | bcmos_errno err = BCM_ERR_OK; |
| 1084 | bcmolt_onu_cfg onu_cfg; |
| 1085 | bcmolt_onu_key onu_key; |
| 1086 | bcmolt_serial_number serial_number; /**< ONU serial number */ |
| 1087 | bcmolt_bin_str_36 registration_id; /**< ONU registration ID */ |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1088 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1089 | bcmolt_onu_set_onu_state onu_oper; /* declare main API struct */ |
| 1090 | bcmolt_onu_state onu_state; |
| 1091 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1092 | onu_key.onu_id = onu_id; |
| 1093 | onu_key.pon_ni = intf_id; |
| 1094 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1095 | BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1096 | #ifdef TEST_MODE |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1097 | // It is impossible to mock the setting of onu_cfg.data.onu_state because |
| 1098 | // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot |
| 1099 | // set the onu_cfg.data.onu_state. So a new stub function is created and address |
| 1100 | // of onu_cfg is passed. This is one-of case where we need to add test specific |
| 1101 | // code in production code. |
| 1102 | err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1103 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1104 | err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1105 | #endif |
| 1106 | OPENOLT_LOG(INFO, openolt_log_id, "Activate ONU : old state = %d, current state = %d\n", |
| 1107 | onu_cfg.data.onu_old_state, onu_cfg.data.onu_state); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 1108 | if (err == BCM_ERR_OK) { |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1109 | if (onu_cfg.data.onu_state == BCMOLT_ONU_STATE_ACTIVE) { |
| 1110 | OPENOLT_LOG(INFO, openolt_log_id, "ONU is already in ACTIVE state, \ |
| 1111 | not processing this request for pon_intf=%d onu_id=%d\n", intf_id, onu_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1112 | return Status::OK; |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1113 | } else if (onu_cfg.data.onu_state != BCMOLT_ONU_STATE_NOT_CONFIGURED && |
| 1114 | onu_cfg.data.onu_state != BCMOLT_ONU_STATE_INACTIVE) { |
| 1115 | // We need the ONU to be in NOT_CONFIGURED or INACTIVE state to further process the request |
| 1116 | OPENOLT_LOG(ERROR, openolt_log_id, "ONU in an invalid state to process the request, \ |
| 1117 | state=%d pon_intf=%d onu_id=%d\n", onu_cfg.data.onu_state, intf_id, onu_id); |
| 1118 | return bcm_to_grpc_err(err, "Failed to activate ONU, invalid ONU state"); |
| 1119 | } |
| 1120 | } else { |
| 1121 | // This should never happen. BAL GET should succeed for non-existant ONUs too. The state of such ONUs will be NOT_CONFIGURED |
| 1122 | OPENOLT_LOG(ERROR, openolt_log_id, "ONU state query failed pon_intf=%d onu_id=%d\n", intf_id, onu_id); |
| 1123 | return bcm_to_grpc_err(err, "onu get failed"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1124 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1125 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1126 | // If the ONU is not configured at all we need to first configure it |
| 1127 | if (onu_cfg.data.onu_state == BCMOLT_ONU_STATE_NOT_CONFIGURED) { |
| 1128 | OPENOLT_LOG(INFO, openolt_log_id, "Configuring ONU %d on PON %d : vendor id %s, \ |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 1129 | vendor specific %s, pir %d\n", onu_id, intf_id, vendor_id, |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1130 | vendor_specific_to_str(vendor_specific).c_str(), pir); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1131 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1132 | memcpy(serial_number.vendor_id.arr, vendor_id, 4); |
| 1133 | memcpy(serial_number.vendor_specific.arr, vendor_specific, 4); |
| 1134 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1135 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.serial_number, serial_number); |
| 1136 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.auto_learning, BCMOS_TRUE); |
| 1137 | /*set burst and data profiles to fec disabled*/ |
| 1138 | if (board_technology == "XGS-PON") { |
| 1139 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.ranging_burst_profile, 2); |
| 1140 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.data_burst_profile, 1); |
| 1141 | } else if (board_technology == "GPON") { |
| 1142 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.gpon.ds_ber_reporting_interval, 1000000); |
| 1143 | BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.gpon.omci_port_id, onu_id); |
| 1144 | } |
| 1145 | err = bcmolt_cfg_set(dev_id, &onu_cfg.hdr); |
| 1146 | if (err != BCM_ERR_OK) { |
| 1147 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to configure ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err)); |
| 1148 | return bcm_to_grpc_err(err, "Failed to configure ONU"); |
| 1149 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1150 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1151 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1152 | // TODO: MOVE THIS TO A NEW METHOD |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 1153 | if (omcc_encryption_mode == true) { |
| 1154 | // set the encryption mode for omci port id |
| 1155 | bcmolt_itupon_gem_cfg gem_cfg; |
| 1156 | bcmolt_itupon_gem_key key = {}; |
| 1157 | bcmolt_gem_port_configuration configuration = {}; |
| 1158 | key.pon_ni = intf_id; |
| 1159 | key.gem_port_id = onu_id; |
| 1160 | bcmolt_control_state encryption_mode; |
| 1161 | encryption_mode = BCMOLT_CONTROL_STATE_ENABLE; |
| 1162 | BCMOLT_CFG_INIT(&gem_cfg, itupon_gem, key); |
| 1163 | BCMOLT_FIELD_SET(&gem_cfg.data, itupon_gem_cfg_data, encryption_mode, encryption_mode); |
| 1164 | err = bcmolt_cfg_set(dev_id, &gem_cfg.hdr); |
| 1165 | if(err != BCM_ERR_OK) { |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1166 | OPENOLT_LOG(ERROR, openolt_log_id, "failed to configure omci gem_port encryption mode = %d\n", onu_id); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 1167 | return bcm_to_grpc_err(err, "Access_Control set ITU PON OMCI Gem port failed"); |
| 1168 | } |
| 1169 | } |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1170 | // Now that the ONU is configured, move the ONU to ACTIVE state |
| 1171 | memset(&onu_cfg, 0, sizeof(bcmolt_onu_cfg)); |
| 1172 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1173 | BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state); |
| 1174 | BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key); |
| 1175 | BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data, |
| 1176 | onu_state, BCMOLT_ONU_OPERATION_ACTIVE); |
| 1177 | err = bcmolt_oper_submit(dev_id, &onu_oper.hdr); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1178 | if (err != BCM_ERR_OK) { |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1179 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to activate ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1180 | return bcm_to_grpc_err(err, "Failed to activate ONU"); |
| 1181 | } |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1182 | // ONU will eventually get activated after we have submitted the operation request. The adapter will receive an asynchronous |
| 1183 | // ONU_ACTIVATION_COMPLETED_INDICATION |
| 1184 | |
| 1185 | OPENOLT_LOG(INFO, openolt_log_id, "Activated ONU, onu_id %d on PON %d\n", onu_id, intf_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1186 | |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1187 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1190 | Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id, |
| 1191 | const char *vendor_id, const char *vendor_specific) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1192 | bcmos_errno err = BCM_ERR_OK; |
| 1193 | bcmolt_onu_set_onu_state onu_oper; /* declare main API struct */ |
| 1194 | bcmolt_onu_cfg onu_cfg; |
| 1195 | bcmolt_onu_key onu_key; /**< Object key. */ |
| 1196 | bcmolt_onu_state onu_state; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1197 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1198 | onu_key.onu_id = onu_id; |
| 1199 | onu_key.pon_ni = intf_id; |
| 1200 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1201 | BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1202 | #ifdef TEST_MODE |
| 1203 | // It is impossible to mock the setting of onu_cfg.data.onu_state because |
| 1204 | // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot |
| 1205 | // set the onu_cfg.data.onu_state. So a new stub function is created and address |
| 1206 | // of onu_cfg is passed. This is one-of case where we need to add test specific |
| 1207 | // code in production code. |
| 1208 | err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1209 | #else |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1210 | err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1211 | #endif |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1212 | onu_state = onu_cfg.data.onu_state; |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 1213 | if (err == BCM_ERR_OK) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1214 | switch (onu_state) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1215 | case BCMOLT_ONU_STATE_ACTIVE: |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1216 | BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key); |
Chaitrashree G S | fd15c8c | 2019-09-09 18:46:15 -0400 | [diff] [blame] | 1217 | BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data, |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1218 | onu_state, BCMOLT_ONU_OPERATION_INACTIVE); |
| 1219 | err = bcmolt_oper_submit(dev_id, &onu_oper.hdr); |
| 1220 | if (err != BCM_ERR_OK) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 1221 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to deactivate ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1222 | return bcm_to_grpc_err(err, "Failed to deactivate ONU"); |
| 1223 | } |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1224 | OPENOLT_LOG(INFO, openolt_log_id, "Deactivated ONU, onu_id %d on PON %d\n", onu_id, intf_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1225 | break; |
| 1226 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | return Status::OK; |
| 1230 | } |
| 1231 | |
| 1232 | Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1233 | const char *vendor_id, const char *vendor_specific) { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1234 | bcmos_errno err = BCM_ERR_OK; |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1235 | bcmolt_onu_state onu_state; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1236 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1237 | OPENOLT_LOG(INFO, openolt_log_id, "DeleteOnu ONU %d on PON %d : vendor id %s, vendor specific %s\n", |
Craig Lutgen | d0bae9b | 2018-10-18 18:02:07 -0500 | [diff] [blame] | 1238 | onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str()); |
| 1239 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1240 | // Need to deactivate before removing it (BAL rules) |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1241 | DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific); |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1242 | |
| 1243 | err = get_onu_status((bcmolt_interface)intf_id, onu_id, &onu_state); |
| 1244 | if (err == BCM_ERR_OK) { |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1245 | if (onu_state != BCMOLT_ONU_STATE_INACTIVE) { |
| 1246 | OPENOLT_LOG(INFO, openolt_log_id, "waiting for onu deactivate complete response: intf_id=%d, onu_id=%d\n", |
| 1247 | intf_id, onu_id); |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1248 | err = wait_for_onu_deactivate_complete(intf_id, onu_id); |
| 1249 | if (err) { |
| 1250 | OPENOLT_LOG(ERROR, openolt_log_id, "failed to delete onu intf_id %d, onu_id %d\n", |
| 1251 | intf_id, onu_id); |
| 1252 | return bcm_to_grpc_err(err, "Failed to delete ONU"); |
| 1253 | } |
| 1254 | } |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1255 | else { |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1256 | OPENOLT_LOG(INFO, openolt_log_id, "Onu is Inactive, onu_id: %d, not waiting for onu deactivate complete response\n", |
| 1257 | intf_id); |
| 1258 | } |
| 1259 | } |
| 1260 | else { |
| 1261 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch Onu status, onu_id = %d, intf_id = %d, err = %s\n", |
| 1262 | onu_id, intf_id, bcmos_strerror(err)); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1263 | return bcm_to_grpc_err(err, "Failed to delete ONU"); |
| 1264 | } |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 1265 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1266 | bcmolt_onu_cfg cfg_obj; |
| 1267 | bcmolt_onu_key key; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1268 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1269 | OPENOLT_LOG(INFO, openolt_log_id, "Processing onu cfg clear for onu_id %d and intf_id %d\n", |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1270 | onu_id, intf_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1271 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1272 | key.onu_id = onu_id; |
| 1273 | key.pon_ni = intf_id; |
| 1274 | BCMOLT_CFG_INIT(&cfg_obj, onu, key); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1275 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1276 | err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1277 | if (err != BCM_ERR_OK) |
| 1278 | { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1279 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL onu_id %d, Interface ID %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err)); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1280 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 1281 | } |
| 1282 | |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1283 | OPENOLT_LOG(INFO, openolt_log_id, "Deleted ONU, onu_id %d on PON %d\n", onu_id, intf_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1284 | return Status::OK; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1287 | #define MAX_CHAR_LENGTH 20 |
| 1288 | #define MAX_OMCI_MSG_LENGTH 44 |
| 1289 | Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1290 | bcmolt_bin_str buf = {}; |
| 1291 | bcmolt_onu_cpu_packets omci_cpu_packets; |
| 1292 | bcmolt_onu_key key; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1293 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1294 | key.pon_ni = intf_id; |
| 1295 | key.onu_id = onu_id; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1296 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1297 | BCMOLT_OPER_INIT(&omci_cpu_packets, onu, cpu_packets, key); |
| 1298 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_OMCI); |
| 1299 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, calc_crc, BCMOS_TRUE); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1300 | |
| 1301 | // ??? |
| 1302 | if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) { |
| 1303 | buf.len = MAX_OMCI_MSG_LENGTH; |
| 1304 | } else { |
| 1305 | buf.len = pkt.size()/2; |
| 1306 | } |
| 1307 | |
| 1308 | /* Send the OMCI packet using the BAL remote proxy API */ |
| 1309 | uint16_t idx1 = 0; |
| 1310 | uint16_t idx2 = 0; |
| 1311 | uint8_t arraySend[buf.len]; |
| 1312 | char str1[MAX_CHAR_LENGTH]; |
| 1313 | char str2[MAX_CHAR_LENGTH]; |
| 1314 | memset(&arraySend, 0, buf.len); |
| 1315 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1316 | for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) { |
| 1317 | sprintf(str1,"%c", pkt[idx1]); |
| 1318 | sprintf(str2,"%c", pkt[++idx1]); |
| 1319 | strcat(str1,str2); |
| 1320 | arraySend[idx2] = strtol(str1, NULL, 16); |
| 1321 | } |
| 1322 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1323 | buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 1324 | memcpy(buf.arr, (uint8_t *)arraySend, buf.len); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1325 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1326 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, number_of_packets, 1); |
| 1327 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_size, buf.len); |
| 1328 | BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, buffer, buf); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1329 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1330 | bcmos_errno err = bcmolt_oper_submit(dev_id, &omci_cpu_packets.hdr); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1331 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 1332 | OPENOLT_LOG(ERROR, openolt_log_id, "Error sending OMCI message to ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1333 | return bcm_to_grpc_err(err, "send OMCI failed"); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1334 | } else { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1335 | OPENOLT_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] | 1336 | buf.len, onu_id, intf_id, pkt.c_str()); |
Nicolas Palpacuer | 967438f | 2018-09-07 14:41:54 -0400 | [diff] [blame] | 1337 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1338 | free(buf.arr); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1339 | |
| 1340 | return Status::OK; |
| 1341 | } |
| 1342 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1343 | Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, uint32_t port_no, uint32_t gemport_id, const std::string pkt) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1344 | bcmolt_pon_interface_cpu_packets pon_interface_cpu_packets; /**< declare main API struct */ |
| 1345 | bcmolt_pon_interface_key key = {.pon_ni = (bcmolt_interface)intf_id}; /**< declare key */ |
| 1346 | bcmolt_bin_str buf = {}; |
| 1347 | bcmolt_gem_port_id gem_port_id_array[1]; |
| 1348 | bcmolt_gem_port_id_list_u8_max_16 gem_port_list = {}; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1349 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1350 | if (port_no > 0) { |
| 1351 | bool found = false; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1352 | if (gemport_id == 0) { |
| 1353 | bcmos_fastlock_lock(&data_lock); |
| 1354 | // Map the port_no to one of the flows that owns it to find a gemport_id for that flow. |
| 1355 | // Pick any flow that is mapped with the same port_no. |
| 1356 | std::map<uint32_t, std::set<uint32_t> >::const_iterator it = port_to_flows.find(port_no); |
| 1357 | if (it != port_to_flows.end() && !it->second.empty()) { |
| 1358 | uint32_t flow_id = *(it->second.begin()); // Pick any flow_id out of the bag set |
| 1359 | std::map<uint32_t, uint32_t>::const_iterator fit = flowid_to_gemport.find(flow_id); |
| 1360 | if (fit != flowid_to_gemport.end()) { |
| 1361 | found = true; |
| 1362 | gemport_id = fit->second; |
| 1363 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1364 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1365 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1366 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1367 | if (!found) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1368 | OPENOLT_LOG(ERROR, openolt_log_id, "Packet out failed to find destination for ONU %d port_no %u on PON %d\n", |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1369 | onu_id, port_no, intf_id); |
| 1370 | return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow for port_no"); |
| 1371 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1372 | OPENOLT_LOG(INFO, openolt_log_id, "Gem port %u found for ONU %d port_no %u on PON %d\n", |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1373 | gemport_id, onu_id, port_no, intf_id); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1374 | } |
| 1375 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1376 | gem_port_id_array[0] = gemport_id; |
| 1377 | gem_port_list.len = 1; |
| 1378 | gem_port_list.arr = gem_port_id_array; |
| 1379 | buf.len = pkt.size(); |
| 1380 | buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 1381 | memcpy(buf.arr, (uint8_t *)pkt.data(), buf.len); |
| 1382 | |
| 1383 | /* init the API struct */ |
| 1384 | BCMOLT_OPER_INIT(&pon_interface_cpu_packets, pon_interface, cpu_packets, key); |
| 1385 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_ETH); |
| 1386 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, calc_crc, BCMOS_TRUE); |
| 1387 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, gem_port_list, gem_port_list); |
| 1388 | BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, buffer, buf); |
| 1389 | |
| 1390 | OPENOLT_LOG(INFO, openolt_log_id, "Packet out of length %d sent to gemport %d on pon %d port_no %u\n", |
| 1391 | (uint8_t)pkt.size(), gemport_id, intf_id, port_no); |
| 1392 | |
| 1393 | /* call API */ |
| 1394 | bcmolt_oper_submit(dev_id, &pon_interface_cpu_packets.hdr); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1395 | } |
| 1396 | else { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1397 | //TODO: Port No is 0, it is coming sender requirement. |
| 1398 | OPENOLT_LOG(INFO, openolt_log_id, "port_no %d onu %d on pon %d\n", |
| 1399 | port_no, onu_id, intf_id); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1400 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1401 | free(buf.arr); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1402 | |
| 1403 | return Status::OK; |
| 1404 | } |
| 1405 | |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1406 | Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1407 | bcmolt_flow_key key = {}; /* declare key */ |
| 1408 | bcmolt_bin_str buffer = {}; |
| 1409 | bcmolt_flow_send_eth_packet oper; /* declare main API struct */ |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1410 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1411 | // TODO: flow_id is currently not passed in UplinkPacket message from voltha. |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1412 | bcmolt_flow_id flow_id = INVALID_FLOW_ID; |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1413 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1414 | //validate flow_id and find flow_id/flow type: upstream/ingress type: PON/egress type: NNI |
| 1415 | if (get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, FLOW_TYPE) == BCMOLT_FLOW_TYPE_UPSTREAM && \ |
| 1416 | get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, INGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_PON && \ |
| 1417 | get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, EGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_NNI) |
| 1418 | key.flow_id = flow_id; |
| 1419 | else { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1420 | if (flow_id_counters) { |
| 1421 | std::map<flow_pair, int>::iterator it; |
| 1422 | for(it = flow_map.begin(); it != flow_map.end(); it++) { |
| 1423 | int flow_index = it->first.first; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1424 | if (get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, FLOW_TYPE) == BCMOLT_FLOW_TYPE_UPSTREAM && \ |
| 1425 | get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, INGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_PON && \ |
| 1426 | get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, EGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_NNI) { |
| 1427 | key.flow_id = flow_index; |
| 1428 | break; |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | else { |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1433 | OPENOLT_LOG(ERROR, openolt_log_id, "no flow id found for uplink packetout\n"); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1434 | return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow id found"); |
| 1435 | } |
| 1436 | } |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1437 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1438 | key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; /* send from uplink direction */ |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1439 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1440 | /* Initialize the API struct. */ |
| 1441 | BCMOLT_OPER_INIT(&oper, flow, send_eth_packet, key); |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1442 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1443 | buffer.len = pkt.size(); |
| 1444 | buffer.arr = (uint8_t *)malloc((buffer.len)*sizeof(uint8_t)); |
| 1445 | memcpy(buffer.arr, (uint8_t *)pkt.data(), buffer.len); |
| 1446 | if (buffer.arr == NULL) { |
| 1447 | OPENOLT_LOG(ERROR, openolt_log_id, "allocate packet buffer failed\n"); |
| 1448 | return bcm_to_grpc_err(BCM_ERR_PARM, "allocate packet buffer failed"); |
| 1449 | } |
| 1450 | BCMOLT_FIELD_SET(&oper.data, flow_send_eth_packet_data, buffer, buffer); |
| 1451 | |
| 1452 | bcmos_errno err = bcmolt_oper_submit(dev_id, &oper.hdr); |
| 1453 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 1454 | OPENOLT_LOG(ERROR, openolt_log_id, "Error sending packets via nni port %d, flow_id %d, err = %s\n", intf_id, key.flow_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1455 | return bcm_to_grpc_err(BCM_ERR_SYSCALL_ERR, "Error sending packets via nni port"); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1456 | } else { |
| 1457 | OPENOLT_LOG(INFO, openolt_log_id, "sent packets to port %d in upstream direction, flow_id %d \n", intf_id, key.flow_id); |
| 1458 | } |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 1459 | |
| 1460 | return Status::OK; |
| 1461 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1462 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1463 | bool get_aes_flag_for_gem_port(const google::protobuf::Map<unsigned int, bool> &gemport_to_aes, uint32_t gemport_id) { |
| 1464 | bool aes_flag = false; |
| 1465 | for (google::protobuf::Map<unsigned int, bool>::const_iterator it=gemport_to_aes.begin(); it!=gemport_to_aes.end(); it++) { |
| 1466 | if (it->first == gemport_id) { |
| 1467 | aes_flag = it->second; |
| 1468 | break; |
| 1469 | } |
| 1470 | } |
| 1471 | return aes_flag; |
| 1472 | } |
| 1473 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1474 | Status FlowAddWrapper_(const ::openolt::Flow* request) { |
| 1475 | |
| 1476 | int32_t access_intf_id = request->access_intf_id(); |
| 1477 | int32_t onu_id = request->onu_id(); |
| 1478 | int32_t uni_id = request->uni_id(); |
| 1479 | uint32_t port_no = request->port_no(); |
| 1480 | uint64_t voltha_flow_id = request->flow_id(); |
| 1481 | uint64_t symmetric_voltha_flow_id = request->symmetric_flow_id(); |
| 1482 | const std::string flow_type = request->flow_type(); |
| 1483 | int32_t alloc_id = request->alloc_id(); |
| 1484 | int32_t network_intf_id = request->network_intf_id(); |
| 1485 | int32_t gemport_id = request->gemport_id(); |
| 1486 | const ::openolt::Classifier& classifier = request->classifier(); |
| 1487 | const ::openolt::Action& action = request->action(); |
| 1488 | int32_t priority = request->priority(); |
| 1489 | uint64_t cookie = request->cookie(); |
| 1490 | int32_t group_id = request->group_id(); |
| 1491 | uint32_t tech_profile_id = request->tech_profile_id(); |
| 1492 | bool replicate_flow = request->replicate_flow(); |
| 1493 | const google::protobuf::Map<unsigned int, unsigned int> &pbit_to_gemport = request->pbit_to_gemport(); |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1494 | const google::protobuf::Map<unsigned int, bool> &gemport_to_aes = request->gemport_to_aes(); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1495 | uint16_t flow_id; |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1496 | bool enable_encryption; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1497 | |
| 1498 | // The intf_id variable defaults to access(PON) interface ID. |
| 1499 | // For trap-from-nni flow where access interface ID is not valid , change it to NNI interface ID |
| 1500 | // This intf_id identifies the pool from which we get the flow_id |
| 1501 | uint32_t intf_id = access_intf_id; |
| 1502 | if (onu_id < 1) { |
| 1503 | onu_id = 1; |
| 1504 | } |
| 1505 | if (access_intf_id < 0) { |
| 1506 | intf_id = network_intf_id; |
| 1507 | } |
| 1508 | |
| 1509 | OPENOLT_LOG(INFO, openolt_log_id, "received flow add. voltha_flow_id=%lu, symmetric_voltha_flow_id=%lu, replication=%d\n", voltha_flow_id, symmetric_voltha_flow_id, replicate_flow) |
| 1510 | // This is the case of voltha_flow_id (not symmetric_voltha_flow_id) |
| 1511 | if (is_voltha_flow_installed(voltha_flow_id)) { |
| 1512 | OPENOLT_LOG(INFO, openolt_log_id, "voltha_flow_id=%lu, already installed\n", voltha_flow_id); |
| 1513 | return ::Status(grpc::StatusCode::ALREADY_EXISTS, "voltha-flow-already-installed"); |
| 1514 | } |
| 1515 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1516 | // This is the case of symmetric_voltha_flow_id |
| 1517 | // If symmetric_voltha_flow_id is available and valid in the Flow message, |
| 1518 | // check if it is installed, and use the corresponding device_flow_id |
| 1519 | if (symmetric_voltha_flow_id > 0 && is_voltha_flow_installed(symmetric_voltha_flow_id)) { // symmetric flow found |
| 1520 | OPENOLT_LOG(INFO, openolt_log_id, "symmetric flow and the symmetric flow is installed\n"); |
| 1521 | const device_flow_params *dev_fl_symm_params; |
| 1522 | dev_fl_symm_params = get_device_flow_params(symmetric_voltha_flow_id); |
| 1523 | if (dev_fl_symm_params == NULL) { |
| 1524 | OPENOLT_LOG(ERROR, openolt_log_id, "symmetric flow device params not found symm-voltha-flow=%lu voltha-flow=%lu\n", symmetric_voltha_flow_id, voltha_flow_id) |
| 1525 | return ::Status(grpc::StatusCode::INTERNAL, "symmetric-flow-details-not-found"); |
| 1526 | } |
| 1527 | |
| 1528 | if (!replicate_flow) { // No flow replication |
| 1529 | flow_id = dev_fl_symm_params[0].flow_id; |
| 1530 | gemport_id = dev_fl_symm_params[0].gemport_id; // overwrite the gemport with symmetric flow gemport |
| 1531 | // Should be same as what is coming in this request. |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1532 | enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1533 | ::openolt::Classifier cl = ::openolt::Classifier(classifier); |
| 1534 | cl.set_o_pbits(dev_fl_symm_params[0].pbit); |
| 1535 | Status st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, |
| 1536 | flow_type, alloc_id, network_intf_id, gemport_id, cl, |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1537 | action, priority, cookie, group_id, tech_profile_id, enable_encryption); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1538 | if (st.error_code() == grpc::StatusCode::OK) { |
| 1539 | device_flow dev_fl; |
| 1540 | dev_fl.is_flow_replicated = false; |
| 1541 | dev_fl.symmetric_voltha_flow_id = symmetric_voltha_flow_id; |
| 1542 | dev_fl.voltha_flow_id = voltha_flow_id; |
| 1543 | memcpy(dev_fl.params, dev_fl_symm_params, sizeof(device_flow_params)); |
| 1544 | // update voltha flow to cache |
| 1545 | update_voltha_flow_to_cache(voltha_flow_id, dev_fl); |
| 1546 | } |
| 1547 | return st; |
| 1548 | } else { // Flow to be replicated |
| 1549 | OPENOLT_LOG(INFO, openolt_log_id,"symmetric flow and replication is needed\n"); |
| 1550 | for (uint8_t i=0; i<NUMBER_OF_REPLICATED_FLOWS; i++) { |
| 1551 | ::openolt::Classifier cl = ::openolt::Classifier(classifier); |
| 1552 | flow_id = dev_fl_symm_params[i].flow_id; |
| 1553 | gemport_id = dev_fl_symm_params[i].gemport_id; |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1554 | enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1555 | cl.set_o_pbits(dev_fl_symm_params[i].pbit); |
| 1556 | Status st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, |
Girish Gowdra | de65ab4 | 2020-12-17 23:08:43 -0800 | [diff] [blame] | 1557 | flow_type, alloc_id, network_intf_id, gemport_id, cl, |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1558 | action, priority, cookie, group_id, tech_profile_id, enable_encryption); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1559 | if (st.error_code() != grpc::StatusCode::OK && st.error_code() != grpc::StatusCode::ALREADY_EXISTS) { |
| 1560 | OPENOLT_LOG(ERROR, openolt_log_id, "failed to install device flow=%u for voltha flow=%lu. Undoing any device flows installed.", flow_id, voltha_flow_id); |
| 1561 | // On failure remove any successfully replicated flows installed so far for the voltha_flow_id |
| 1562 | if (i > 0) { |
| 1563 | for (int8_t j = i-1; j >= 0; j--) { |
| 1564 | flow_id = dev_fl_symm_params[j].flow_id; |
| 1565 | FlowRemove_(flow_id, flow_type); |
| 1566 | } |
| 1567 | } |
| 1568 | return st; |
| 1569 | } |
| 1570 | } |
| 1571 | device_flow dev_fl; |
| 1572 | dev_fl.is_flow_replicated = true; |
| 1573 | dev_fl.symmetric_voltha_flow_id = symmetric_voltha_flow_id; |
| 1574 | dev_fl.voltha_flow_id = voltha_flow_id; |
| 1575 | memcpy(dev_fl.params, dev_fl_symm_params, sizeof(device_flow_params)*NUMBER_OF_REPLICATED_FLOWS); |
| 1576 | // update voltha flow to cache |
| 1577 | update_voltha_flow_to_cache(voltha_flow_id, dev_fl); |
| 1578 | } |
| 1579 | } else { // No symmetric flow found |
| 1580 | if (!replicate_flow) { // No flow replication |
| 1581 | OPENOLT_LOG(INFO, openolt_log_id, "not a symmetric flow and replication is not needed\n"); |
| 1582 | flow_id = get_flow_id(); |
| 1583 | if (flow_id == INVALID_FLOW_ID) { |
| 1584 | OPENOLT_LOG(ERROR, openolt_log_id, "could not allocated flow id for voltha-flow-id=%lu\n", voltha_flow_id); |
| 1585 | return ::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "flow-ids-exhausted"); |
| 1586 | } |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1587 | enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1588 | Status st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, |
| 1589 | flow_type, alloc_id, network_intf_id, gemport_id, classifier, |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1590 | action, priority, cookie, group_id, tech_profile_id, enable_encryption); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1591 | if (st.error_code() == grpc::StatusCode::OK) { |
| 1592 | device_flow dev_fl; |
| 1593 | dev_fl.is_flow_replicated = false; |
| 1594 | dev_fl.symmetric_voltha_flow_id = INVALID_FLOW_ID; // Invalid |
| 1595 | dev_fl.voltha_flow_id = voltha_flow_id; |
| 1596 | dev_fl.params[0].flow_id = flow_id; |
| 1597 | dev_fl.params[0].gemport_id = gemport_id; |
| 1598 | dev_fl.params[0].pbit = classifier.o_pbits(); |
| 1599 | // update voltha flow to cache |
| 1600 | update_voltha_flow_to_cache(voltha_flow_id, dev_fl); |
| 1601 | } else { |
| 1602 | // Free the flow id on failure |
| 1603 | free_flow_id(flow_id); |
| 1604 | } |
| 1605 | return st; |
| 1606 | } else { // Flow to be replicated |
| 1607 | OPENOLT_LOG(INFO, openolt_log_id,"not a symmetric flow and replication is needed\n"); |
| 1608 | if (pbit_to_gemport.size() != NUMBER_OF_PBITS) { |
| 1609 | OPENOLT_LOG(ERROR, openolt_log_id, "invalid pbit-to-gemport map size=%lu", pbit_to_gemport.size()) |
| 1610 | return ::Status(grpc::StatusCode::OUT_OF_RANGE, "pbit-to-gemport-map-len-invalid-for-flow-replication"); |
| 1611 | } |
| 1612 | uint16_t flow_ids[NUMBER_OF_REPLICATED_FLOWS]; |
| 1613 | device_flow dev_fl; |
| 1614 | if (get_flow_ids(NUMBER_OF_REPLICATED_FLOWS, flow_ids)) { |
| 1615 | uint8_t cnt = 0; |
| 1616 | dev_fl.is_flow_replicated = true; |
| 1617 | dev_fl.voltha_flow_id = voltha_flow_id; |
| 1618 | dev_fl.symmetric_voltha_flow_id = INVALID_FLOW_ID; // invalid |
| 1619 | for (google::protobuf::Map<unsigned int, unsigned int>::const_iterator it=pbit_to_gemport.begin(); it!=pbit_to_gemport.end(); it++) { |
| 1620 | dev_fl.params[cnt].flow_id = flow_ids[cnt]; |
| 1621 | dev_fl.params[cnt].pbit = it->first; |
| 1622 | dev_fl.params[cnt].gemport_id = it->second; |
| 1623 | |
| 1624 | ::openolt::Classifier cl = ::openolt::Classifier(classifier); |
| 1625 | flow_id = dev_fl.params[cnt].flow_id; |
| 1626 | gemport_id = dev_fl.params[cnt].gemport_id; |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1627 | enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1628 | cl.set_o_pbits(dev_fl.params[cnt].pbit); |
| 1629 | Status st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, |
| 1630 | flow_type, alloc_id, network_intf_id, gemport_id, cl, |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1631 | action, priority, cookie, group_id, tech_profile_id, enable_encryption); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1632 | if (st.error_code() != grpc::StatusCode::OK) { |
| 1633 | OPENOLT_LOG(ERROR, openolt_log_id, "failed to install device flow=%u for voltha flow=%lu. Undoing any device flows installed.", flow_id, voltha_flow_id); |
| 1634 | // Remove any successfully replicated flows installed so far for the voltha_flow_id |
| 1635 | if (cnt > 0) { |
| 1636 | for (int8_t j = cnt-1; j >= 0; j--) { |
| 1637 | flow_id = dev_fl.params[j].flow_id; |
| 1638 | FlowRemove_(flow_id, flow_type); |
| 1639 | } |
| 1640 | } |
| 1641 | // Free up all the flow IDs on failure |
| 1642 | free_flow_ids(NUMBER_OF_REPLICATED_FLOWS, flow_ids); |
| 1643 | return st; |
| 1644 | } |
| 1645 | cnt++; |
| 1646 | } |
| 1647 | // On successful flow replication update voltha-flow-id to device-flow map to cache |
| 1648 | update_voltha_flow_to_cache(voltha_flow_id, dev_fl); |
| 1649 | } else { |
| 1650 | OPENOLT_LOG(ERROR, openolt_log_id, "could not allocate flow ids for replication voltha-flow-id=%lu\n", voltha_flow_id); |
| 1651 | return ::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "flow-ids-exhausted"); |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | return Status::OK; |
| 1657 | } |
| 1658 | |
| 1659 | |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1660 | 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] | 1661 | uint32_t flow_id, const std::string flow_type, |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 1662 | int32_t alloc_id, int32_t network_intf_id, |
| 1663 | int32_t gemport_id, const ::openolt::Classifier& classifier, |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1664 | const ::openolt::Action& action, int32_t priority_value, uint64_t cookie, |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1665 | int32_t group_id, uint32_t tech_profile_id, bool aes_enabled) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1666 | bcmolt_flow_cfg cfg; |
| 1667 | bcmolt_flow_key key = { }; /**< Object key. */ |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1668 | int32_t o_vid = -1; |
| 1669 | bool single_tag = false; |
| 1670 | uint32_t ether_type = 0; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1671 | bcmolt_classifier c_val = { }; |
| 1672 | bcmolt_action a_val = { }; |
| 1673 | bcmolt_tm_queue_ref tm_val = { }; |
| 1674 | int tm_qmp_id, tm_q_set_id; |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 1675 | bcmolt_egress_qos_type qos_type; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1676 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1677 | OPENOLT_LOG(INFO, openolt_log_id, "flow add received for flow_id=%u, flow_type=%s\n", flow_id, flow_type.c_str()); |
| 1678 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1679 | key.flow_id = flow_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1680 | if (flow_type.compare(upstream) == 0 ) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1681 | key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1682 | } else if (flow_type.compare(downstream) == 0) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1683 | key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1684 | } else if (flow_type.compare(multicast) == 0) { |
| 1685 | key.flow_type = BCMOLT_FLOW_TYPE_MULTICAST; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1686 | } else { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1687 | OPENOLT_LOG(ERROR, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str()); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 1688 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1691 | BCMOLT_CFG_INIT(&cfg, flow, key); |
| 1692 | BCMOLT_MSG_FIELD_SET(&cfg, cookie, cookie); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1693 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1694 | if (action.cmd().trap_to_host()) { |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 1695 | Status resp = handle_acl_rule_install(onu_id, flow_id, gemport_id, flow_type, access_intf_id, |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1696 | network_intf_id, classifier); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1697 | return resp; |
| 1698 | } |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1699 | |
| 1700 | if (key.flow_type != BCMOLT_FLOW_TYPE_MULTICAST) { |
| 1701 | |
| 1702 | if (access_intf_id >= 0 && network_intf_id >= 0) { |
| 1703 | if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) { //upstream |
| 1704 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON); |
| 1705 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, access_intf_id); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1706 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI); |
| 1707 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, network_intf_id); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1708 | } else if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { //downstream |
| 1709 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI); |
| 1710 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, network_intf_id); |
| 1711 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON); |
| 1712 | BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1713 | } |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1714 | } else { |
| 1715 | OPENOLT_LOG(ERROR, openolt_log_id, "flow network setting invalid\n"); |
| 1716 | return bcm_to_grpc_err(BCM_ERR_PARM, "flow network setting invalid"); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1717 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1718 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1719 | if (onu_id >= ONU_ID_START) { |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1720 | BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id); |
| 1721 | } |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1722 | if (gemport_id >= GEM_PORT_ID_START) { |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1723 | BCMOLT_MSG_FIELD_SET(&cfg, svc_port_id, gemport_id); |
| 1724 | } |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1725 | if (gemport_id >= GEM_PORT_ID_START && port_no != 0) { |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1726 | bcmos_fastlock_lock(&data_lock); |
| 1727 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
| 1728 | port_to_flows[port_no].insert(key.flow_id); |
| 1729 | flowid_to_gemport[key.flow_id] = gemport_id; |
| 1730 | } |
| 1731 | else |
| 1732 | { |
| 1733 | flowid_to_port[key.flow_id] = port_no; |
| 1734 | } |
| 1735 | bcmos_fastlock_unlock(&data_lock, 0); |
| 1736 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1737 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1738 | if (priority_value >= 0) { |
| 1739 | BCMOLT_MSG_FIELD_SET(&cfg, priority, priority_value); |
| 1740 | } |
Girish Gowdra | 80b0fb9 | 2019-11-15 11:40:39 +0530 | [diff] [blame] | 1741 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1742 | } else { // MULTICAST FLOW |
| 1743 | if (group_id >= 0) { |
| 1744 | BCMOLT_MSG_FIELD_SET(&cfg, group_id, group_id); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 1745 | } |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1746 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI); |
| 1747 | BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, network_intf_id); |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1748 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1749 | |
| 1750 | { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1751 | if (classifier.eth_type()) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1752 | ether_type = classifier.eth_type(); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1753 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify ether_type 0x%04x\n", classifier.eth_type()); |
| 1754 | BCMOLT_FIELD_SET(&c_val, classifier, ether_type, classifier.eth_type()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1757 | if (classifier.dst_mac().size() > 0) { |
| 1758 | bcmos_mac_address d_mac = {}; |
| 1759 | bcmos_mac_address_init(&d_mac); |
| 1760 | memcpy(d_mac.u8, classifier.dst_mac().data(), sizeof(d_mac.u8)); |
| 1761 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_mac %02x:%02x:%02x:%02x:%02x:%02x\n", d_mac.u8[0], |
| 1762 | d_mac.u8[1], d_mac.u8[2], d_mac.u8[3], d_mac.u8[4], d_mac.u8[5]); |
| 1763 | BCMOLT_FIELD_SET(&c_val, classifier, dst_mac, d_mac); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1766 | /* |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1767 | if (classifier.src_mac()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1768 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_mac, classifier.src_mac()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1769 | } |
| 1770 | */ |
| 1771 | |
| 1772 | if (classifier.ip_proto()) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1773 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify ip_proto %d\n", classifier.ip_proto()); |
| 1774 | BCMOLT_FIELD_SET(&c_val, classifier, ip_proto, classifier.ip_proto()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1777 | if (classifier.dst_ip()) { |
Girish Gowdra | f7feb4b | 2021-01-08 16:08:52 -0800 | [diff] [blame] | 1778 | bcmos_ipv4_address d_ip = {}; |
| 1779 | bcmos_ipv4_address_init(&d_ip); |
| 1780 | d_ip.u32 = classifier.dst_ip(); |
| 1781 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_ip %04x\n", d_ip.u32); |
| 1782 | BCMOLT_FIELD_SET(&c_val, classifier, dst_ip, d_ip); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Girish Gowdra | f7feb4b | 2021-01-08 16:08:52 -0800 | [diff] [blame] | 1785 | /* |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1786 | if (classifier.src_ip()) { |
Craig Lutgen | 1951231 | 2018-11-02 10:14:46 -0500 | [diff] [blame] | 1787 | BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_ip, classifier.src_ip()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1788 | } |
| 1789 | */ |
| 1790 | |
| 1791 | if (classifier.src_port()) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1792 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify src_port %d\n", classifier.src_port()); |
| 1793 | BCMOLT_FIELD_SET(&c_val, classifier, src_port, classifier.src_port()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | if (classifier.dst_port()) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1797 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_port %d\n", classifier.dst_port()); |
| 1798 | BCMOLT_FIELD_SET(&c_val, classifier, dst_port, classifier.dst_port()); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | if (!classifier.pkt_tag_type().empty()) { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1802 | if (classifier.o_vid()) { |
| 1803 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_vid %d\n", classifier.o_vid()); |
| 1804 | BCMOLT_FIELD_SET(&c_val, classifier, o_vid, classifier.o_vid()); |
| 1805 | } |
| 1806 | |
| 1807 | if (classifier.i_vid()) { |
| 1808 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify i_vid %d\n", classifier.i_vid()); |
| 1809 | BCMOLT_FIELD_SET(&c_val, classifier, i_vid, classifier.i_vid()); |
| 1810 | } |
| 1811 | |
| 1812 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify tag_type %s\n", classifier.pkt_tag_type().c_str()); |
| 1813 | if (classifier.pkt_tag_type().compare("untagged") == 0) { |
| 1814 | BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_UNTAGGED); |
| 1815 | } else if (classifier.pkt_tag_type().compare("single_tag") == 0) { |
| 1816 | BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_SINGLE_TAG); |
| 1817 | single_tag = true; |
| 1818 | |
| 1819 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits()); |
Girish Gowdra | 7bcfaf6 | 2020-02-17 19:17:20 +0530 | [diff] [blame] | 1820 | // OpenOlt adapter will send 0xFF in case of no pbit classification |
| 1821 | // If it is any other value (0 to 7), it is for outer pbit classification. |
| 1822 | // OpenFlow protocol does not provide inner pbit classification (in case of double tagged packets), |
| 1823 | // and VOLTHA has not used any workaround to solve this problem (for ex: use metadata field). |
| 1824 | // Also there exists no use case for i-pbit classification, so we can safely ignore this for now. |
| 1825 | if(0xFF != classifier.o_pbits()){ |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1826 | BCMOLT_FIELD_SET(&c_val, classifier, o_pbits, classifier.o_pbits()); |
Girish Gowdra | 80b0fb9 | 2019-11-15 11:40:39 +0530 | [diff] [blame] | 1827 | } |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1828 | } else if (classifier.pkt_tag_type().compare("double_tag") == 0) { |
| 1829 | BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1830 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1831 | OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits()); |
Girish Gowdra | 7bcfaf6 | 2020-02-17 19:17:20 +0530 | [diff] [blame] | 1832 | // Same comments as in case of "single_tag" packets. |
| 1833 | // 0xFF means no pbit classification, otherwise a valid PCP (0 to 7). |
| 1834 | if(0xFF != classifier.o_pbits()){ |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1835 | BCMOLT_FIELD_SET(&c_val, classifier, o_pbits, classifier.o_pbits()); |
Girish Gowdra | 80b0fb9 | 2019-11-15 11:40:39 +0530 | [diff] [blame] | 1836 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1837 | } |
| 1838 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1839 | BCMOLT_MSG_FIELD_SET(&cfg, classifier, c_val); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1842 | const ::openolt::ActionCmd& cmd = action.cmd(); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1843 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1844 | if (cmd.add_outer_tag()) { |
| 1845 | OPENOLT_LOG(DEBUG, openolt_log_id, "action add o_tag\n"); |
| 1846 | BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1849 | if (cmd.remove_outer_tag()) { |
| 1850 | OPENOLT_LOG(DEBUG, openolt_log_id, "action pop o_tag\n"); |
| 1851 | BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG); |
| 1852 | } |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 1853 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1854 | if (action.o_vid()) { |
| 1855 | OPENOLT_LOG(DEBUG, openolt_log_id, "action o_vid=%d\n", action.o_vid()); |
| 1856 | o_vid = action.o_vid(); |
| 1857 | BCMOLT_FIELD_SET(&a_val, action, o_vid, action.o_vid()); |
| 1858 | } |
| 1859 | |
| 1860 | if (action.o_pbits()) { |
| 1861 | OPENOLT_LOG(DEBUG, openolt_log_id, "action o_pbits=0x%x\n", action.o_pbits()); |
| 1862 | BCMOLT_FIELD_SET(&a_val, action, o_pbits, action.o_pbits()); |
| 1863 | } |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 1864 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1865 | if (action.i_vid()) { |
| 1866 | OPENOLT_LOG(DEBUG, openolt_log_id, "action i_vid=%d\n", action.i_vid()); |
| 1867 | BCMOLT_FIELD_SET(&a_val, action, i_vid, action.i_vid()); |
| 1868 | } |
| 1869 | |
| 1870 | if (action.i_pbits()) { |
| 1871 | OPENOLT_LOG(DEBUG, openolt_log_id, "action i_pbits=0x%x\n", action.i_pbits()); |
| 1872 | BCMOLT_FIELD_SET(&a_val, action, i_pbits, action.i_pbits()); |
| 1873 | } |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 1874 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1875 | BCMOLT_MSG_FIELD_SET(&cfg, action, a_val); |
| 1876 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 1877 | if ((access_intf_id >= 0) && (onu_id >= ONU_ID_START)) { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1878 | qos_type = get_qos_type(access_intf_id, onu_id, uni_id); |
| 1879 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1880 | tm_val.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, downstream, tech_profile_id); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1881 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1882 | if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) { |
| 1883 | // Queue 0 on DS subscriber scheduler |
| 1884 | tm_val.queue_id = 0; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1885 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1886 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type); |
| 1887 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id); |
| 1888 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1889 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1890 | OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \ |
| 1891 | downstream.c_str(), tm_val.queue_id, tm_val.sched_id, \ |
| 1892 | GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1893 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1894 | } else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) { |
| 1895 | /* Fetch TM QMP ID mapped to DS subscriber scheduler */ |
| 1896 | tm_qmp_id = tm_q_set_id = get_tm_qmp_id(tm_val.sched_id, access_intf_id, onu_id, uni_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1897 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1898 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type); |
| 1899 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id); |
| 1900 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_qmp_id, tm_qmp_id); |
| 1901 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_q_set_id, tm_q_set_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1902 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1903 | OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, q_set_id = %d, sched_id = %d, intf_type %s\n", \ |
| 1904 | downstream.c_str(), tm_q_set_id, tm_val.sched_id, \ |
| 1905 | GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type)); |
| 1906 | } |
| 1907 | } else if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) { |
| 1908 | // NNI Scheduler ID |
| 1909 | tm_val.sched_id = get_default_tm_sched_id(network_intf_id, upstream); |
| 1910 | if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) { |
| 1911 | // Queue 0 on NNI scheduler |
| 1912 | tm_val.queue_id = 0; |
| 1913 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type); |
| 1914 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id); |
| 1915 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1916 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1917 | OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1918 | upstream.c_str(), tm_val.queue_id, tm_val.sched_id, \ |
| 1919 | GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type)); |
| 1920 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1921 | } else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) { |
| 1922 | /* Fetch TM QMP ID mapped to US NNI scheduler */ |
| 1923 | tm_qmp_id = tm_q_set_id = get_tm_qmp_id(tm_val.sched_id, access_intf_id, onu_id, uni_id); |
| 1924 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type); |
| 1925 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id); |
| 1926 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_qmp_id, tm_qmp_id); |
| 1927 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_q_set_id, tm_q_set_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1928 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1929 | OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, q_set_id = %d, sched_id = %d, intf_type %s\n", \ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1930 | upstream.c_str(), tm_q_set_id, tm_val.sched_id, \ |
| 1931 | GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 1932 | } |
Shad Ansari | 39739bc | 2018-09-13 21:38:37 +0000 | [diff] [blame] | 1933 | } |
Girish Gowdra | 80b0fb9 | 2019-11-15 11:40:39 +0530 | [diff] [blame] | 1934 | } else { |
| 1935 | tm_val.sched_id = get_default_tm_sched_id(network_intf_id, upstream); |
| 1936 | tm_val.queue_id = 0; |
| 1937 | |
| 1938 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE); |
| 1939 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id); |
| 1940 | BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id); |
| 1941 | |
| 1942 | OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \ |
| 1943 | flow_type.c_str(), tm_val.queue_id, tm_val.sched_id, \ |
| 1944 | GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type)); |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1947 | BCMOLT_MSG_FIELD_SET(&cfg, state, BCMOLT_FLOW_STATE_ENABLE); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1948 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1949 | #ifndef SCALE_AND_PERF |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1950 | // BAL 3.1 supports statistics only for unicast flows. |
| 1951 | if (key.flow_type != BCMOLT_FLOW_TYPE_MULTICAST) { |
| 1952 | BCMOLT_MSG_FIELD_SET(&cfg, statistics, BCMOLT_CONTROL_STATE_ENABLE); |
| 1953 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1954 | #endif // SCALE_AND_PERF |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1955 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 1956 | #ifndef SCALE_AND_PERF |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1957 | #ifdef FLOW_CHECKER |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 1958 | //Flow Checker, To avoid duplicate flow. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1959 | if (flow_id_counters != 0) { |
| 1960 | bool b_duplicate_flow = false; |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 1961 | std::map<flow_pair, int>::iterator it; |
| 1962 | |
| 1963 | for(it = flow_map.begin(); it != flow_map.end(); it++) { |
| 1964 | b_duplicate_flow = (cfg.data.onu_id == get_flow_status(it->first.first, it->first.second, ONU_ID)) && \ |
| 1965 | (key.flow_type == it->first.second) && \ |
| 1966 | (cfg.data.svc_port_id == get_flow_status(it->first.first, it->first.second, SVC_PORT_ID)) && \ |
| 1967 | (cfg.data.priority == get_flow_status(it->first.first, it->first.second, PRIORITY)) && \ |
| 1968 | (cfg.data.cookie == get_flow_status(it->first.first, it->first.second, COOKIE)) && \ |
| 1969 | (cfg.data.ingress_intf.intf_type == get_flow_status(it->first.first, it->first.second, INGRESS_INTF_TYPE)) && \ |
| 1970 | (cfg.data.ingress_intf.intf_id == get_flow_status(it->first.first, it->first.second, INGRESS_INTF_ID)) && \ |
| 1971 | (cfg.data.egress_intf.intf_type == get_flow_status(it->first.first, it->first.second, EGRESS_INTF_TYPE)) && \ |
| 1972 | (cfg.data.egress_intf.intf_id == get_flow_status(it->first.first, it->first.second, EGRESS_INTF_ID)) && \ |
| 1973 | (c_val.o_vid == get_flow_status(it->first.first, it->first.second, CLASSIFIER_O_VID)) && \ |
| 1974 | (c_val.o_pbits == get_flow_status(it->first.first, it->first.second, CLASSIFIER_O_PBITS)) && \ |
| 1975 | (c_val.i_vid == get_flow_status(it->first.first, it->first.second, CLASSIFIER_I_VID)) && \ |
| 1976 | (c_val.i_pbits == get_flow_status(it->first.first, it->first.second, CLASSIFIER_I_PBITS)) && \ |
| 1977 | (c_val.ether_type == get_flow_status(it->first.first, it->first.second, CLASSIFIER_ETHER_TYPE)) && \ |
| 1978 | (c_val.ip_proto == get_flow_status(it->first.first, it->first.second, CLASSIFIER_IP_PROTO)) && \ |
| 1979 | (c_val.src_port == get_flow_status(it->first.first, it->first.second, CLASSIFIER_SRC_PORT)) && \ |
| 1980 | (c_val.dst_port == get_flow_status(it->first.first, it->first.second, CLASSIFIER_DST_PORT)) && \ |
| 1981 | (c_val.pkt_tag_type == get_flow_status(it->first.first, it->first.second, CLASSIFIER_PKT_TAG_TYPE)) && \ |
| 1982 | (cfg.data.egress_qos.type == get_flow_status(it->first.first, it->first.second, EGRESS_QOS_TYPE)) && \ |
| 1983 | (cfg.data.egress_qos.u.fixed_queue.queue_id == get_flow_status(it->first.first, it->first.second, EGRESS_QOS_QUEUE_ID)) && \ |
| 1984 | (cfg.data.egress_qos.tm_sched.id == get_flow_status(it->first.first, it->first.second, EGRESS_QOS_TM_SCHED_ID)) && \ |
| 1985 | (a_val.cmds_bitmask == get_flow_status(it->first.first, it->first.second, ACTION_CMDS_BITMASK)) && \ |
| 1986 | (a_val.o_vid == get_flow_status(it->first.first, it->first.second, ACTION_O_VID)) && \ |
| 1987 | (a_val.i_vid == get_flow_status(it->first.first, it->first.second, ACTION_I_VID)) && \ |
| 1988 | (a_val.o_pbits == get_flow_status(it->first.first, it->first.second, ACTION_O_PBITS)) && \ |
| 1989 | (a_val.i_pbits == get_flow_status(it->first.first, it->first.second, ACTION_I_PBITS)) && \ |
| 1990 | (cfg.data.state == get_flow_status(it->first.first, it->first.second, STATE)) && \ |
| 1991 | (cfg.data.group_id == get_flow_status(it->first.first, it->first.second, GROUP_ID)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1992 | #ifdef SHOW_FLOW_PARAM |
| 1993 | // Flow Parameter |
| 1994 | FLOW_PARAM_LOG(); |
| 1995 | #endif |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 1996 | if (b_duplicate_flow) { |
| 1997 | FLOW_LOG(WARNING, "Flow duplicate", 0); |
| 1998 | return bcm_to_grpc_err(BCM_ERR_ALREADY, "flow exists"); |
| 1999 | } |
| 2000 | } |
| 2001 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2002 | #endif // FLOW_CHECKER |
| 2003 | #endif // SCALE_AND_PERF |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2004 | |
| 2005 | bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg.hdr); |
| 2006 | if (err) { |
| 2007 | FLOW_LOG(ERROR, "Flow add failed", err); |
| 2008 | return bcm_to_grpc_err(err, "flow add failed"); |
| 2009 | } else { |
| 2010 | FLOW_LOG(INFO, "Flow add ok", err); |
| 2011 | bcmos_fastlock_lock(&data_lock); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2012 | flow_map[std::pair<int, int>(key.flow_id,key.flow_type)] = flow_map.size(); |
| 2013 | flow_id_counters = flow_map.size(); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2014 | bcmos_fastlock_unlock(&data_lock, 0); |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2015 | |
| 2016 | } |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame^] | 2017 | |
| 2018 | /* |
| 2019 | Enable AES encryption on GEM ports if they are used in downstream unicast flows. |
| 2020 | Rationale: We can't do upstream encryption in GPON. This change addresses the common denominator (and also minimum viable) |
| 2021 | use case for both technologies which is downstream unicast GEM port encryption. Since the downstream traffic is inherently |
| 2022 | broadcast to all the ONUs behind a PON port, encrypting the individual subscriber traffic in this direction is important |
| 2023 | and considered good enough in terms of security (See Section 12.1 of G.984.3). For upstream unicast and downstream multicast |
| 2024 | GEM encryption, we need to make additional changes specific to XGSPON. This will be done as a future work. |
| 2025 | */ |
| 2026 | if (aes_enabled && (access_intf_id >= 0) && (gemport_id >= GEM_PORT_ID_START) && (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM)) { |
| 2027 | OPENOLT_LOG(INFO, openolt_log_id, "Setting encryption on pon = %d gem_port = %d through flow_id = %d\n", access_intf_id, gemport_id, flow_id); |
| 2028 | enable_encryption_for_gem_port(access_intf_id, gemport_id); |
| 2029 | } else { |
| 2030 | OPENOLT_LOG(WARNING, openolt_log_id, "Flow config for flow_id = %d is not suitable for setting downstream encryption on pon = %d gem_port = %d. No action taken.\n", flow_id, access_intf_id, gemport_id); |
| 2031 | } |
| 2032 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2033 | return Status::OK; |
| 2034 | } |
| 2035 | |
| 2036 | Status FlowRemoveWrapper_(const ::openolt::Flow* request) { |
| 2037 | const std::string flow_type = request->flow_type(); |
| 2038 | uint64_t voltha_flow_id = request->flow_id(); |
| 2039 | Status st; |
| 2040 | |
| 2041 | // If Voltha flow is not installed, return fail |
| 2042 | if (! is_voltha_flow_installed(voltha_flow_id)) { |
| 2043 | OPENOLT_LOG(ERROR, openolt_log_id, "voltha_flow_id=%lu not found\n", voltha_flow_id); |
| 2044 | return ::Status(grpc::StatusCode::NOT_FOUND, "voltha-flow-not-found"); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2045 | } |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 2046 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2047 | const device_flow *dev_fl = get_device_flow(voltha_flow_id); |
| 2048 | if (dev_fl == NULL) { |
| 2049 | OPENOLT_LOG(ERROR, openolt_log_id, "device flow for voltha_flow_id=%lu in the cache is NULL\n", voltha_flow_id); |
| 2050 | return ::Status(grpc::StatusCode::INTERNAL, "device-flow-null-in-cache"); |
| 2051 | } |
| 2052 | if (dev_fl->is_flow_replicated) { |
| 2053 | // Note: Here we are ignoring FlowRemove failures |
| 2054 | for (int i=0; i<NUMBER_OF_REPLICATED_FLOWS; i++) { |
| 2055 | st = FlowRemove_(dev_fl->params[i].flow_id, flow_type); |
| 2056 | if (st.error_code() == grpc::StatusCode::OK) { |
| 2057 | free_flow_id(dev_fl->params[i].flow_id); |
| 2058 | } |
| 2059 | } |
| 2060 | } else { |
| 2061 | // Note: Here we are ignoring FlowRemove failures |
| 2062 | st = FlowRemove_(dev_fl->params[0].flow_id, flow_type); |
| 2063 | if (st.error_code() == grpc::StatusCode::OK) { |
| 2064 | free_flow_id(dev_fl->params[0].flow_id); |
| 2065 | } |
| 2066 | } |
| 2067 | // remove the flow from cache on voltha flow removal |
| 2068 | remove_voltha_flow_from_cache(voltha_flow_id); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 2069 | return Status::OK; |
| 2070 | } |
| 2071 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2072 | Status FlowRemove_(uint32_t flow_id, const std::string flow_type) { |
| 2073 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2074 | bcmolt_flow_cfg cfg; |
| 2075 | bcmolt_flow_key key = { }; |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2076 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2077 | key.flow_id = (bcmolt_flow_id) flow_id; |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2078 | key.flow_id = flow_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2079 | if (flow_type.compare(upstream) == 0 ) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2080 | key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2081 | } else if (flow_type.compare(downstream) == 0) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2082 | key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2083 | } else if(flow_type.compare(multicast) == 0) { |
| 2084 | key.flow_type = BCMOLT_FLOW_TYPE_MULTICAST; |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2085 | } else { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2086 | OPENOLT_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] | 2087 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
| 2088 | } |
| 2089 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2090 | OPENOLT_LOG(INFO, openolt_log_id, "flow remove received for flow_id=%u, flow_type=%s\n", |
| 2091 | flow_id, flow_type.c_str()); |
| 2092 | |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 2093 | bcmos_fastlock_lock(&acl_packet_trap_handler_lock); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2094 | flow_id_flow_direction fl_id_fl_dir(flow_id, flow_type); |
| 2095 | int32_t gemport_id = -1; |
| 2096 | int32_t intf_id = -1; |
| 2097 | int16_t acl_id = -1; |
| 2098 | if (flow_to_acl_map.count(fl_id_fl_dir) > 0) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2099 | |
| 2100 | acl_id_intf_id ac_id_if_id = flow_to_acl_map[fl_id_fl_dir]; |
| 2101 | acl_id = std::get<0>(ac_id_if_id); |
| 2102 | intf_id = std::get<1>(ac_id_if_id); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2103 | // cleanup acl only if it is a valid acl. If not valid acl, it may be datapath flow. |
| 2104 | if (acl_id >= 0) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2105 | Status resp = handle_acl_rule_cleanup(acl_id, intf_id, flow_type); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2106 | if (resp.ok()) { |
| 2107 | OPENOLT_LOG(INFO, openolt_log_id, "acl removed ok for flow_id = %u with acl_id = %d\n", flow_id, acl_id); |
| 2108 | flow_to_acl_map.erase(fl_id_fl_dir); |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 2109 | |
| 2110 | // When flow is being removed, extract the value corresponding to flow_id from trap_to_host_pkt_info_with_vlan_for_flow_id if it exists |
| 2111 | if (trap_to_host_pkt_info_with_vlan_for_flow_id.count(flow_id) > 0) { |
| 2112 | trap_to_host_pkt_info_with_vlan pkt_info_with_vlan = trap_to_host_pkt_info_with_vlan_for_flow_id[flow_id]; |
| 2113 | // Formulate the trap_to_host_pkt_info tuple key |
| 2114 | trap_to_host_pkt_info pkt_info(std::get<0>(pkt_info_with_vlan), |
| 2115 | std::get<1>(pkt_info_with_vlan), |
| 2116 | std::get<2>(pkt_info_with_vlan), |
| 2117 | std::get<3>(pkt_info_with_vlan)); |
| 2118 | // Extract the value corresponding to trap_to_host_pkt_info key from trap_to_host_vlan_ids_for_trap_to_host_pkt_info |
| 2119 | // The value is a list of vlan_ids for the given trap_to_host_pkt_info key |
| 2120 | // Remove the vlan_id from the list that corresponded to the flow being removed. |
| 2121 | if (trap_to_host_vlan_ids_for_trap_to_host_pkt_info.count(pkt_info) > 0) { |
| 2122 | trap_to_host_vlan_ids_for_trap_to_host_pkt_info[pkt_info].remove(std::get<4>(pkt_info_with_vlan)); |
| 2123 | } else { |
| 2124 | OPENOLT_LOG(ERROR, openolt_log_id, "trap-to-host with intf_type = %d, intf_id = %d, pkt_type = %d gemport_id = %d not found in trap_to_host_vlan_ids_for_trap_to_host_pkt_info map", |
| 2125 | std::get<0>(pkt_info_with_vlan), std::get<1>(pkt_info_with_vlan), std::get<2>(pkt_info_with_vlan), std::get<3>(pkt_info_with_vlan)); |
| 2126 | } |
| 2127 | |
| 2128 | } else { |
| 2129 | OPENOLT_LOG(ERROR, openolt_log_id, "flow id = %u not found in trap_to_host_pkt_info_with_vlan_for_flow_id map", flow_id); |
| 2130 | } |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2131 | } else { |
| 2132 | OPENOLT_LOG(ERROR, openolt_log_id, "acl remove error for flow_id = %u with acl_id = %d\n", flow_id, acl_id); |
| 2133 | } |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 2134 | bcmos_fastlock_unlock(&acl_packet_trap_handler_lock, 0); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2135 | return resp; |
| 2136 | } |
| 2137 | } |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 2138 | bcmos_fastlock_unlock(&acl_packet_trap_handler_lock, 0); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2139 | |
Girish Gowdra | 1935e6a | 2020-10-31 21:48:22 -0700 | [diff] [blame] | 2140 | bcmos_fastlock_lock(&data_lock); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 2141 | uint32_t port_no = flowid_to_port[key.flow_id]; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2142 | if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 2143 | flowid_to_gemport.erase(key.flow_id); |
| 2144 | port_to_flows[port_no].erase(key.flow_id); |
| 2145 | if (port_to_flows[port_no].empty()) port_to_flows.erase(port_no); |
| 2146 | } |
| 2147 | else |
| 2148 | { |
| 2149 | flowid_to_port.erase(key.flow_id); |
| 2150 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2151 | bcmos_fastlock_unlock(&data_lock, 0); |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 2152 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2153 | BCMOLT_CFG_INIT(&cfg, flow, key); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2154 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2155 | bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg.hdr); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2156 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2157 | OPENOLT_LOG(ERROR, openolt_log_id, "Error while removing %s flow, flow_id=%d, err = %s\n", flow_type.c_str(), flow_id, bcmos_strerror(err)); |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2158 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow"); |
| 2159 | } |
| 2160 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2161 | bcmos_fastlock_lock(&data_lock); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2162 | if (flow_id_counters != 0) { |
| 2163 | std::map<flow_pair, int>::iterator it; |
| 2164 | for(it = flow_map.begin(); it != flow_map.end(); it++) { |
| 2165 | if (it->first.first == flow_id && it->first.second == key.flow_type) { |
| 2166 | flow_id_counters -= 1; |
| 2167 | flow_map.erase(it); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2168 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2169 | } |
| 2170 | } |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2171 | OPENOLT_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str()); |
| 2172 | |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2173 | flow_to_acl_map.erase(fl_id_fl_dir); |
| 2174 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2175 | bcmos_fastlock_unlock(&data_lock, 0); |
| 2176 | |
Nicolas Palpacuer | edfaa0c | 2018-07-05 15:05:27 -0400 | [diff] [blame] | 2177 | return Status::OK; |
| 2178 | } |
| 2179 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2180 | bcmos_errno CreateDefaultSched(uint32_t intf_id, const std::string direction) { |
| 2181 | bcmos_errno err; |
| 2182 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 2183 | bcmolt_tm_sched_key tm_sched_key = {.id = 1}; |
| 2184 | tm_sched_key.id = get_default_tm_sched_id(intf_id, direction); |
| 2185 | |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 2186 | //check TM scheduler has configured or not |
| 2187 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 2188 | BCMOLT_MSG_FIELD_GET(&tm_sched_cfg, state); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2189 | #ifdef TEST_MODE |
| 2190 | // It is impossible to mock the setting of tm_sched_cfg.data.state because |
| 2191 | // the actual bcmolt_cfg_get passes the address of tm_sched_cfg.hdr and we cannot |
| 2192 | // set the tm_sched_cfg.data.state. So a new stub function is created and address |
| 2193 | // of tm_sched_cfg is passed. This is one-of case where we need to add test specific |
| 2194 | // code in production code. |
| 2195 | err = bcmolt_cfg_get__tm_sched_stub(dev_id, &tm_sched_cfg); |
| 2196 | #else |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 2197 | err = bcmolt_cfg_get(dev_id, &tm_sched_cfg.hdr); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2198 | #endif |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 2199 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2200 | OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query TM scheduler, err = %s\n",bcmos_strerror(err)); |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 2201 | return err; |
| 2202 | } |
| 2203 | else if (tm_sched_cfg.data.state == BCMOLT_CONFIG_STATE_CONFIGURED) { |
| 2204 | OPENOLT_LOG(WARNING, openolt_log_id, "tm scheduler default config has already with id %d\n", tm_sched_key.id); |
| 2205 | return BCM_ERR_OK; |
| 2206 | } |
| 2207 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2208 | // bcmbal_tm_sched_owner |
| 2209 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 2210 | |
| 2211 | /**< The output of the tm_sched object instance */ |
| 2212 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_INTERFACE); |
| 2213 | |
| 2214 | if (direction.compare(upstream) == 0) { |
| 2215 | // In upstream it is NNI scheduler |
| 2216 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_NNI); |
| 2217 | } else if (direction.compare(downstream) == 0) { |
| 2218 | // In downstream it is PON scheduler |
| 2219 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_PON); |
| 2220 | } |
| 2221 | |
| 2222 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_id, intf_id); |
| 2223 | |
| 2224 | // bcmbal_tm_sched_type |
| 2225 | // set the deafult policy to strict priority |
| 2226 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP); |
| 2227 | |
| 2228 | // num_priorities: Max number of strict priority scheduling elements |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2229 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, NUM_OF_PRIORITIES); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2230 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2231 | err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr); |
| 2232 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2233 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create %s scheduler, id %d, intf_id %d, err = %s\n", |
| 2234 | direction.c_str(), tm_sched_key.id, intf_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2235 | return err; |
| 2236 | } |
| 2237 | |
| 2238 | OPENOLT_LOG(INFO, openolt_log_id, "Create %s scheduler success, id %d, intf_id %d\n", \ |
| 2239 | direction.c_str(), tm_sched_key.id, intf_id); |
| 2240 | return BCM_ERR_OK; |
| 2241 | } |
| 2242 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2243 | bcmos_errno CreateSched(std::string direction, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t port_no, |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2244 | uint32_t alloc_id, ::tech_profile::AdditionalBW additional_bw, uint32_t weight, uint32_t priority, |
| 2245 | ::tech_profile::SchedulingPolicy sched_policy, ::tech_profile::TrafficShapingInfo tf_sh_info, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2246 | uint32_t tech_profile_id) { |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2247 | |
| 2248 | bcmos_errno err; |
| 2249 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2250 | if (direction == downstream) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2251 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 2252 | bcmolt_tm_sched_key tm_sched_key = {.id = 1}; |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2253 | tm_sched_key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2254 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2255 | // bcmbal_tm_sched_owner |
| 2256 | // In downstream it is sub_term scheduler |
| 2257 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2258 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2259 | /**< The output of the tm_sched object instance */ |
| 2260 | 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] | 2261 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2262 | // bcmbal_tm_sched_parent |
| 2263 | // The parent for the sub_term scheduler is the PON scheduler in the downstream |
| 2264 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_id, get_default_tm_sched_id(intf_id, direction)); |
| 2265 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_param.u.priority.priority, priority); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2266 | /* removed by BAL v3.0, N/A - No direct attachment point of type ONU, same functionality may |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2267 | be achieved using the' virtual' type of attachment. |
| 2268 | tm_sched_owner.u.sub_term.intf_id = intf_id; |
| 2269 | tm_sched_owner.u.sub_term.sub_term_id = onu_id; |
| 2270 | */ |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2271 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2272 | // bcmbal_tm_sched_type |
| 2273 | // set the deafult policy to strict priority |
| 2274 | 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] | 2275 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2276 | // num_priorities: Max number of strict priority scheduling elements |
| 2277 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, 8); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2278 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2279 | // bcmbal_tm_shaping |
| 2280 | if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) { |
| 2281 | uint32_t cir = tf_sh_info.cir(); |
| 2282 | uint32_t pir = tf_sh_info.pir(); |
| 2283 | uint32_t burst = tf_sh_info.pbs(); |
| 2284 | OPENOLT_LOG(INFO, openolt_log_id, "applying traffic shaping in DL cir=%u, pir=%u, burst=%u\n", |
| 2285 | cir, pir, burst); |
| 2286 | BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, pir); |
| 2287 | BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, burst); |
| 2288 | // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet' |
| 2289 | //BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.cir, cir); |
| 2290 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.pir, pir); |
| 2291 | BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.burst, burst); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2292 | } |
| 2293 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2294 | err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2295 | if (err) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2296 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, \ |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2297 | intf_id %d, onu_id %d, uni_id %d, port_no %u, err = %s\n", tm_sched_key.id, intf_id, onu_id, uni_id, \ |
| 2298 | port_no, bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2299 | return err; |
| 2300 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2301 | OPENOLT_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \ |
| 2302 | 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] | 2303 | |
| 2304 | } else { //upstream |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2305 | bcmolt_itupon_alloc_cfg cfg; |
| 2306 | bcmolt_itupon_alloc_key key = { }; |
| 2307 | key.pon_ni = intf_id; |
| 2308 | key.alloc_id = alloc_id; |
| 2309 | int bw_granularity = (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY; |
Burak Gurdag | 03919c7 | 2020-02-04 22:46:57 +0000 | [diff] [blame] | 2310 | int pir_bw = tf_sh_info.pir()*125; // conversion from kbps to bytes/sec |
| 2311 | int cir_bw = tf_sh_info.cir()*125; // conversion from kbps to bytes/sec |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2312 | //offset to match bandwidth granularity |
| 2313 | int offset_pir_bw = pir_bw%bw_granularity; |
| 2314 | int offset_cir_bw = cir_bw%bw_granularity; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2315 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2316 | pir_bw = pir_bw - offset_pir_bw; |
| 2317 | cir_bw = cir_bw - offset_cir_bw; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2318 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2319 | BCMOLT_CFG_INIT(&cfg, itupon_alloc, key); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2320 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2321 | switch (additional_bw) { |
| 2322 | case 2: //AdditionalBW_BestEffort |
| 2323 | if (pir_bw == 0) { |
| 2324 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \ |
| 2325 | %d bytes/sec\n", (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2326 | return BCM_ERR_PARM; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2327 | } else if (pir_bw < cir_bw) { |
| 2328 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \ |
| 2329 | bandwidth (%d)\n", pir_bw, cir_bw); |
| 2330 | return BCM_ERR_PARM; |
| 2331 | } else if (pir_bw == cir_bw) { |
| 2332 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be greater than Guaranteed \ |
| 2333 | bandwidth for additional bandwidth eligibility of type best_effort\n"); |
| 2334 | return BCM_ERR_PARM; |
| 2335 | } |
| 2336 | BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_BEST_EFFORT); |
| 2337 | break; |
| 2338 | case 1: //AdditionalBW_NA |
| 2339 | if (pir_bw == 0) { |
| 2340 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \ |
| 2341 | %d bytes/sec\n", (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY); |
| 2342 | return BCM_ERR_PARM; |
| 2343 | } else if (cir_bw == 0) { |
| 2344 | OPENOLT_LOG(ERROR, openolt_log_id, "Guaranteed bandwidth must be greater than zero for \ |
| 2345 | additional bandwidth eligibility of type Non-Assured (NA)\n"); |
| 2346 | return BCM_ERR_PARM; |
| 2347 | } else if (pir_bw < cir_bw) { |
| 2348 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \ |
| 2349 | bandwidth (%d)\n", pir_bw, cir_bw); |
| 2350 | return BCM_ERR_PARM; |
| 2351 | } else if (pir_bw == cir_bw) { |
| 2352 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be greater than Guaranteed \ |
| 2353 | bandwidth for additional bandwidth eligibility of type non_assured\n"); |
| 2354 | return BCM_ERR_PARM; |
| 2355 | } |
| 2356 | BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NON_ASSURED); |
| 2357 | break; |
| 2358 | case 0: //AdditionalBW_None |
| 2359 | if (pir_bw == 0) { |
| 2360 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \ |
| 2361 | 16000 bytes/sec\n"); |
| 2362 | return BCM_ERR_PARM; |
| 2363 | } else if (cir_bw == 0) { |
| 2364 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be equal to Guaranteed bandwidth \ |
| 2365 | for additional bandwidth eligibility of type None\n"); |
| 2366 | return BCM_ERR_PARM; |
| 2367 | } else if (pir_bw > cir_bw) { |
| 2368 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be equal to Guaranteed bandwidth \ |
| 2369 | for additional bandwidth eligibility of type None\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2370 | OPENOLT_LOG(ERROR, openolt_log_id, "Setting Maximum bandwidth (%d) to Guaranteed \ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2371 | bandwidth in None eligibility\n", pir_bw); |
| 2372 | cir_bw = pir_bw; |
| 2373 | } else if (pir_bw < cir_bw) { |
| 2374 | OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \ |
| 2375 | bandwidth (%d)\n", pir_bw, cir_bw); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2376 | OPENOLT_LOG(ERROR, openolt_log_id, "Setting Maximum bandwidth (%d) to Guaranteed \ |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2377 | bandwidth in None eligibility\n", pir_bw); |
| 2378 | cir_bw = pir_bw; |
| 2379 | } |
| 2380 | BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NONE); |
| 2381 | break; |
| 2382 | default: |
| 2383 | return BCM_ERR_PARM; |
Girish Gowdru | e075c64 | 2019-01-23 04:05:53 -0800 | [diff] [blame] | 2384 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2385 | /* CBR Real Time Bandwidth which require shaping of the bandwidth allocations |
| 2386 | in a fine granularity. */ |
| 2387 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_bw, 0); |
| 2388 | /* Fixed Bandwidth with no critical requirement of shaping */ |
| 2389 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_bw, 0); |
| 2390 | /* Dynamic bandwidth which the OLT is committed to allocate upon demand */ |
| 2391 | BCMOLT_MSG_FIELD_SET(&cfg, sla.guaranteed_bw, cir_bw); |
| 2392 | /* Maximum allocated bandwidth allowed for this alloc ID */ |
| 2393 | BCMOLT_MSG_FIELD_SET(&cfg, sla.maximum_bw, pir_bw); |
| 2394 | BCMOLT_MSG_FIELD_SET(&cfg, sla.alloc_type, BCMOLT_ALLOC_TYPE_NSR); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2395 | /* Set to True for AllocID with CBR RT Bandwidth that requires compensation |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2396 | for skipped allocations during quiet window */ |
| 2397 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_compensation, BCMOS_FALSE); |
| 2398 | /**< Allocation Profile index for CBR non-RT Bandwidth */ |
| 2399 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_ap_index, 0); |
| 2400 | /**< Allocation Profile index for CBR RT Bandwidth */ |
| 2401 | BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_ap_index, 0); |
| 2402 | /**< Alloc ID Weight used in case of Extended DBA mode */ |
| 2403 | BCMOLT_MSG_FIELD_SET(&cfg, sla.weight, 0); |
| 2404 | /**< Alloc ID Priority used in case of Extended DBA mode */ |
| 2405 | BCMOLT_MSG_FIELD_SET(&cfg, sla.priority, 0); |
| 2406 | BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2407 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2408 | err = bcmolt_cfg_set(dev_id, &cfg.hdr); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2409 | if (err) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2410 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\ |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2411 | port_no %u, alloc_id %d, err = %s\n", intf_id, onu_id,uni_id,port_no,alloc_id, bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2412 | return err; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2413 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2414 | #ifndef SCALE_AND_PERF |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2415 | err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_CREATE); |
| 2416 | if (err) { |
| 2417 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\ |
| 2418 | port_no %u, alloc_id %d, err = %s\n", intf_id, onu_id,uni_id,port_no,alloc_id, bcmos_strerror(err)); |
| 2419 | return err; |
| 2420 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2421 | #endif |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2422 | |
| 2423 | OPENOLT_LOG(INFO, openolt_log_id, "create upstream bandwidth allocation success, intf_id %d, onu_id %d, uni_id %d,\ |
| 2424 | port_no %u, alloc_id %d\n", intf_id, onu_id,uni_id,port_no,alloc_id); |
| 2425 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2426 | } |
| 2427 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2428 | return BCM_ERR_OK; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2429 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 2430 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2431 | Status CreateTrafficSchedulers_(const ::tech_profile::TrafficSchedulers *traffic_scheds) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2432 | uint32_t intf_id = traffic_scheds->intf_id(); |
| 2433 | uint32_t onu_id = traffic_scheds->onu_id(); |
| 2434 | uint32_t uni_id = traffic_scheds->uni_id(); |
| 2435 | uint32_t port_no = traffic_scheds->port_no(); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2436 | std::string direction; |
| 2437 | unsigned int alloc_id; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2438 | ::tech_profile::SchedulerConfig sched_config; |
| 2439 | ::tech_profile::AdditionalBW additional_bw; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2440 | uint32_t priority; |
| 2441 | uint32_t weight; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2442 | ::tech_profile::SchedulingPolicy sched_policy; |
| 2443 | ::tech_profile::TrafficShapingInfo traffic_shaping_info; |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2444 | uint32_t tech_profile_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2445 | bcmos_errno err; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2446 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2447 | for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2448 | ::tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2449 | |
| 2450 | direction = GetDirection(traffic_sched.direction()); |
| 2451 | if (direction.compare("direction-not-supported") == 0) |
| 2452 | return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported"); |
| 2453 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2454 | alloc_id = traffic_sched.alloc_id(); |
| 2455 | sched_config = traffic_sched.scheduler(); |
| 2456 | additional_bw = sched_config.additional_bw(); |
| 2457 | priority = sched_config.priority(); |
| 2458 | weight = sched_config.weight(); |
| 2459 | sched_policy = sched_config.sched_policy(); |
| 2460 | traffic_shaping_info = traffic_sched.traffic_shaping_info(); |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2461 | tech_profile_id = traffic_sched.tech_profile_id(); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2462 | err = CreateSched(direction, intf_id, onu_id, uni_id, port_no, alloc_id, additional_bw, weight, priority, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2463 | sched_policy, traffic_shaping_info, tech_profile_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2464 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2465 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create scheduler, err = %s\n", bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2466 | return bcm_to_grpc_err(err, "Failed to create scheduler"); |
| 2467 | } |
Girish Gowdru | 1cdf6ce | 2018-08-27 02:43:02 -0700 | [diff] [blame] | 2468 | } |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 2469 | return Status::OK; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 2470 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2471 | |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2472 | bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction, int tech_profile_id) { |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2473 | |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2474 | bcmos_errno err; |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2475 | bcmolt_interface_state state; |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 2476 | bcmolt_status los_status; |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2477 | uint16_t sched_id; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2478 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2479 | if (direction == upstream) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2480 | bcmolt_itupon_alloc_cfg cfg; |
| 2481 | bcmolt_itupon_alloc_key key = { }; |
| 2482 | key.pon_ni = intf_id; |
| 2483 | key.alloc_id = alloc_id; |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2484 | sched_id = alloc_id; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2485 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2486 | BCMOLT_CFG_INIT(&cfg, itupon_alloc, key); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2487 | err = bcmolt_cfg_clear(dev_id, &cfg.hdr); |
| 2488 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2489 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, intf_id %d, alloc_id %d, err = %s\n", |
| 2490 | direction.c_str(), intf_id, alloc_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2491 | return err; |
| 2492 | } |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2493 | |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 2494 | err = get_pon_interface_status((bcmolt_interface)intf_id, &state, &los_status); |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2495 | if (err == BCM_ERR_OK) { |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 2496 | if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING && los_status == BCMOLT_STATUS_OFF) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2497 | #ifndef SCALE_AND_PERF |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 2498 | OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is enabled and LoS status is OFF, waiting for alloc cfg clear response\n", |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2499 | intf_id); |
| 2500 | err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_DELETE); |
| 2501 | if (err) { |
| 2502 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, intf_id %d, alloc_id %d, err = %s\n", |
| 2503 | direction.c_str(), intf_id, alloc_id, bcmos_strerror(err)); |
| 2504 | return err; |
| 2505 | } |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2506 | #endif |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2507 | } |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 2508 | else if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING && los_status == BCMOLT_STATUS_ON) { |
| 2509 | OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is enabled but LoS status is ON, not waiting for alloc cfg clear response\n", |
| 2510 | intf_id); |
| 2511 | } |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2512 | else if (state == BCMOLT_INTERFACE_STATE_INACTIVE) { |
| 2513 | OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d is disabled, not waiting for alloc cfg clear response\n", |
| 2514 | intf_id); |
| 2515 | } |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 2516 | } else { |
| 2517 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch PON interface status, intf_id = %d, err = %s\n", |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2518 | intf_id, bcmos_strerror(err)); |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2519 | return err; |
| 2520 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2521 | } else if (direction == downstream) { |
| 2522 | bcmolt_tm_sched_cfg cfg; |
| 2523 | bcmolt_tm_sched_key key = { }; |
Nicolas Palpacuer | 9c35208 | 2018-08-14 16:37:14 -0400 | [diff] [blame] | 2524 | |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2525 | if (is_tm_sched_id_present(intf_id, onu_id, uni_id, direction, tech_profile_id)) { |
| 2526 | key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id); |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2527 | sched_id = key.id; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2528 | } else { |
| 2529 | OPENOLT_LOG(INFO, openolt_log_id, "schduler not present in %s, err %d\n", direction.c_str(), err); |
| 2530 | return BCM_ERR_OK; |
| 2531 | } |
Girish Gowdra | 9646105 | 2019-11-22 20:13:59 +0530 | [diff] [blame] | 2532 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2533 | BCMOLT_CFG_INIT(&cfg, tm_sched, key); |
| 2534 | err = bcmolt_cfg_clear(dev_id, &(cfg.hdr)); |
| 2535 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2536 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, sched_id %d, \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2537 | intf_id %d, onu_id %d, tech_profile_id %d, err = %s\n", direction.c_str(), key.id, intf_id, onu_id, tech_profile_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2538 | return err; |
| 2539 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2540 | } |
| 2541 | |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2542 | OPENOLT_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, id %d, intf_id %d, onu_id %d, tech_profile_id %d\n", |
| 2543 | direction.c_str(), sched_id, intf_id, onu_id, tech_profile_id); |
| 2544 | free_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2545 | return BCM_ERR_OK; |
| 2546 | } |
| 2547 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2548 | Status RemoveTrafficSchedulers_(const ::tech_profile::TrafficSchedulers *traffic_scheds) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2549 | uint32_t intf_id = traffic_scheds->intf_id(); |
| 2550 | uint32_t onu_id = traffic_scheds->onu_id(); |
| 2551 | uint32_t uni_id = traffic_scheds->uni_id(); |
| 2552 | std::string direction; |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2553 | uint32_t tech_profile_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2554 | bcmos_errno err; |
| 2555 | |
| 2556 | for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2557 | ::tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2558 | |
| 2559 | direction = GetDirection(traffic_sched.direction()); |
| 2560 | if (direction.compare("direction-not-supported") == 0) |
| 2561 | return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported"); |
| 2562 | |
| 2563 | int alloc_id = traffic_sched.alloc_id(); |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2564 | int tech_profile_id = traffic_sched.tech_profile_id(); |
| 2565 | err = RemoveSched(intf_id, onu_id, uni_id, alloc_id, direction, tech_profile_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2566 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2567 | OPENOLT_LOG(ERROR, openolt_log_id, "Error-removing-traffic-scheduler, err = %s\n",bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2568 | return bcm_to_grpc_err(err, "error-removing-traffic-scheduler"); |
| 2569 | } |
| 2570 | } |
| 2571 | return Status::OK; |
| 2572 | } |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2573 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2574 | bcmos_errno CreateTrafficQueueMappingProfile(uint32_t sched_id, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, \ |
| 2575 | std::string direction, std::vector<uint32_t> tmq_map_profile) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2576 | bcmos_errno err; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2577 | bcmolt_tm_qmp_cfg tm_qmp_cfg; |
| 2578 | bcmolt_tm_qmp_key tm_qmp_key; |
| 2579 | bcmolt_arr_u8_8 pbits_to_tmq_id = {0}; |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2580 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2581 | int tm_qmp_id = get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id, tmq_map_profile); |
| 2582 | if (tm_qmp_id == -1) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2583 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile. Max allowed tm queue mapping profile count is 16.\n"); |
| 2584 | return BCM_ERR_RANGE; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2585 | } |
Girish Gowdru | f26cf88 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 2586 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2587 | tm_qmp_key.id = tm_qmp_id; |
| 2588 | for (uint32_t priority=0; priority<tmq_map_profile.size(); priority++) { |
| 2589 | pbits_to_tmq_id.arr[priority] = tmq_map_profile[priority]; |
| 2590 | } |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2591 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2592 | BCMOLT_CFG_INIT(&tm_qmp_cfg, tm_qmp, tm_qmp_key); |
| 2593 | BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, type, BCMOLT_TM_QMP_TYPE_PBITS); |
| 2594 | BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, pbits_to_tmq_id, pbits_to_tmq_id); |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 2595 | //BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, ref_count, 0); |
| 2596 | //BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, state, BCMOLT_CONFIG_STATE_CONFIGURED); |
Girish Gowdru | 7c4ec2d | 2018-10-25 00:29:54 -0700 | [diff] [blame] | 2597 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2598 | err = bcmolt_cfg_set(dev_id, &tm_qmp_cfg.hdr); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2599 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2600 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile, tm_qmp_id %d, err = %s\n", |
| 2601 | tm_qmp_key.id, bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2602 | return err; |
| 2603 | } |
Craig Lutgen | 967a1d0 | 2018-11-27 10:41:51 -0600 | [diff] [blame] | 2604 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2605 | OPENOLT_LOG(INFO, openolt_log_id, "Create tm queue mapping profile success, id %d\n", \ |
| 2606 | tm_qmp_key.id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2607 | return BCM_ERR_OK; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2608 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2609 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2610 | bcmos_errno RemoveTrafficQueueMappingProfile(uint32_t tm_qmp_id) { |
| 2611 | bcmos_errno err; |
| 2612 | bcmolt_tm_qmp_cfg tm_qmp_cfg; |
| 2613 | bcmolt_tm_qmp_key tm_qmp_key; |
| 2614 | tm_qmp_key.id = tm_qmp_id; |
| 2615 | |
| 2616 | BCMOLT_CFG_INIT(&tm_qmp_cfg, tm_qmp, tm_qmp_key); |
| 2617 | err = bcmolt_cfg_clear(dev_id, &tm_qmp_cfg.hdr); |
| 2618 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2619 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove tm queue mapping profile, tm_qmp_id %d, err = %s\n", |
| 2620 | tm_qmp_key.id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2621 | return err; |
| 2622 | } |
| 2623 | |
| 2624 | OPENOLT_LOG(INFO, openolt_log_id, "Remove tm queue mapping profile success, id %d\n", \ |
| 2625 | tm_qmp_key.id); |
| 2626 | return BCM_ERR_OK; |
| 2627 | } |
| 2628 | |
| 2629 | bcmos_errno CreateDefaultQueue(uint32_t intf_id, const std::string direction) { |
| 2630 | bcmos_errno err; |
| 2631 | |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2632 | /* Create default queues on the given PON/NNI scheduler */ |
| 2633 | for (int queue_id = 0; queue_id < NUMBER_OF_DEFAULT_INTERFACE_QUEUES; queue_id++) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2634 | bcmolt_tm_queue_cfg tm_queue_cfg; |
| 2635 | bcmolt_tm_queue_key tm_queue_key = {}; |
| 2636 | tm_queue_key.sched_id = get_default_tm_sched_id(intf_id, direction); |
| 2637 | tm_queue_key.id = queue_id; |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 2638 | /* DefaultQueues on PON/NNI schedulers are created with egress_qos_type as |
| 2639 | BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE - with tm_q_set_id 32768 */ |
| 2640 | tm_queue_key.tm_q_set_id = BCMOLT_TM_QUEUE_SET_ID_QSET_NOT_USE; |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2641 | |
| 2642 | BCMOLT_CFG_INIT(&tm_queue_cfg, tm_queue, tm_queue_key); |
| 2643 | BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.type, BCMOLT_TM_SCHED_PARAM_TYPE_PRIORITY); |
| 2644 | BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.u.priority.priority, queue_id); |
| 2645 | |
| 2646 | err = bcmolt_cfg_set(dev_id, &tm_queue_cfg.hdr); |
| 2647 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2648 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create %s tm queue, id %d, sched_id %d, tm_q_set_id %d, err = %s\n", \ |
| 2649 | direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id, tm_queue_key.tm_q_set_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2650 | return err; |
| 2651 | } |
| 2652 | |
| 2653 | OPENOLT_LOG(INFO, openolt_log_id, "Create %s tm_queue success, id %d, sched_id %d, tm_q_set_id %d\n", \ |
| 2654 | direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id, tm_queue_key.tm_q_set_id); |
| 2655 | } |
| 2656 | return BCM_ERR_OK; |
| 2657 | } |
| 2658 | |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 2659 | bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2660 | bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2661 | bcmos_errno err; |
| 2662 | bcmolt_tm_queue_cfg cfg; |
| 2663 | bcmolt_tm_queue_key key = { }; |
| 2664 | OPENOLT_LOG(INFO, openolt_log_id, "creating %s queue. access_intf_id = %d, onu_id = %d, uni_id = %d \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2665 | gemport_id = %d, tech_profile_id = %d\n", direction.c_str(), access_intf_id, onu_id, uni_id, gemport_id, tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2666 | |
| 2667 | key.sched_id = (direction.compare(upstream) == 0) ? get_default_tm_sched_id(nni_intf_id, direction) : \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2668 | get_tm_sched_id(access_intf_id, onu_id, uni_id, direction, tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2669 | |
| 2670 | if (priority > 7) { |
| 2671 | return BCM_ERR_RANGE; |
| 2672 | } |
| 2673 | |
| 2674 | /* FIXME: The upstream queues have to be created once only. |
| 2675 | The upstream queues on the NNI scheduler are shared by all subscribers. |
| 2676 | When the first scheduler comes in, the queues get created, and are re-used by all others. |
| 2677 | Also, these queues should be present until the last subscriber exits the system. |
| 2678 | One solution is to have these queues always, i.e., create it as soon as OLT is enabled. |
| 2679 | |
| 2680 | There is one queue per gem port and Queue ID is fetched based on priority_q configuration |
| 2681 | for each GEM in TECH PROFILE */ |
| 2682 | key.id = queue_id_list[priority]; |
| 2683 | |
| 2684 | if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) { |
| 2685 | // Reset the Queue ID to 0, if it is fixed queue, i.e., there is only one queue for subscriber. |
| 2686 | key.id = 0; |
| 2687 | key.tm_q_set_id = BCMOLT_TM_QUEUE_SET_ID_QSET_NOT_USE; |
| 2688 | } |
| 2689 | else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) { |
| 2690 | key.tm_q_set_id = get_tm_qmp_id(key.sched_id, access_intf_id, onu_id, uni_id); |
| 2691 | } |
| 2692 | else { |
| 2693 | key.tm_q_set_id = BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT; |
| 2694 | } |
| 2695 | |
| 2696 | OPENOLT_LOG(INFO, openolt_log_id, "queue assigned queue_id = %d\n", key.id); |
| 2697 | |
| 2698 | BCMOLT_CFG_INIT(&cfg, tm_queue, key); |
| 2699 | BCMOLT_MSG_FIELD_SET(&cfg, tm_sched_param.u.priority.priority, priority); |
| 2700 | |
| 2701 | err = bcmolt_cfg_set(dev_id, &cfg.hdr); |
| 2702 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2703 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, queue_id %d, \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2704 | sched_id %d, tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, tech_profile_id %d, err = %s\n", \ |
| 2705 | direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, tech_profile_id, bcmos_strerror(err)); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2706 | return err; |
| 2707 | } |
| 2708 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2709 | if (direction.compare(upstream) == 0) { |
| 2710 | Status st = install_gem_port(access_intf_id, onu_id, gemport_id); |
| 2711 | if (st.error_code() != grpc::StatusCode::ALREADY_EXISTS && st.error_code() != grpc::StatusCode::OK) { |
| 2712 | OPENOLT_LOG(ERROR, openolt_log_id, "failed to created gemport=%d, access_intf=%d, onu_id=%d\n", gemport_id, access_intf_id, onu_id); |
| 2713 | return BCM_ERR_INTERNAL; |
| 2714 | } |
| 2715 | } |
| 2716 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2717 | OPENOLT_LOG(INFO, openolt_log_id, "Created tm_queue, direction %s, id %d, sched_id %d, tm_q_set_id %d, \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2718 | intf_id %d, onu_id %d, uni_id %d, tech_profiled_id %d\n", direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2719 | return BCM_ERR_OK; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2720 | } |
| 2721 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2722 | Status CreateTrafficQueues_(const ::tech_profile::TrafficQueues *traffic_queues) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2723 | uint32_t intf_id = traffic_queues->intf_id(); |
| 2724 | uint32_t onu_id = traffic_queues->onu_id(); |
| 2725 | uint32_t uni_id = traffic_queues->uni_id(); |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2726 | uint32_t tech_profile_id = traffic_queues->tech_profile_id(); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2727 | uint32_t sched_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2728 | std::string direction; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2729 | bcmos_errno err; |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 2730 | bcmolt_egress_qos_type qos_type = get_qos_type(intf_id, onu_id, uni_id, traffic_queues->traffic_queues_size()); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2731 | |
| 2732 | if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) { |
| 2733 | uint32_t queues_priority_q[traffic_queues->traffic_queues_size()] = {0}; |
| 2734 | std::string queues_pbit_map[traffic_queues->traffic_queues_size()]; |
| 2735 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2736 | ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2737 | |
| 2738 | direction = GetDirection(traffic_queue.direction()); |
| 2739 | if (direction.compare("direction-not-supported") == 0) |
| 2740 | return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported"); |
| 2741 | |
| 2742 | queues_priority_q[i] = traffic_queue.priority(); |
| 2743 | queues_pbit_map[i] = traffic_queue.pbit_map(); |
| 2744 | } |
| 2745 | |
| 2746 | std::vector<uint32_t> tmq_map_profile(8, 0); |
| 2747 | tmq_map_profile = get_tmq_map_profile(get_valid_queues_pbit_map(queues_pbit_map, COUNT_OF(queues_pbit_map)), \ |
| 2748 | queues_priority_q, COUNT_OF(queues_priority_q)); |
| 2749 | sched_id = (direction.compare(upstream) == 0) ? get_default_tm_sched_id(nni_intf_id, direction) : \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2750 | get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2751 | |
| 2752 | int tm_qmp_id = get_tm_qmp_id(tmq_map_profile); |
| 2753 | if (tm_qmp_id == -1) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2754 | err = CreateTrafficQueueMappingProfile(sched_id, intf_id, onu_id, uni_id, direction, tmq_map_profile); |
| 2755 | if (err != BCM_ERR_OK) { |
| 2756 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile, err = %s\n", bcmos_strerror(err)); |
| 2757 | return bcm_to_grpc_err(err, "Failed to create tm queue mapping profile"); |
| 2758 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2759 | } else if (tm_qmp_id != -1 && get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id) == -1) { |
| 2760 | OPENOLT_LOG(INFO, openolt_log_id, "tm queue mapping profile present already with id %d\n", tm_qmp_id); |
| 2761 | update_sched_qmp_id_map(sched_id, intf_id, onu_id, uni_id, tm_qmp_id); |
| 2762 | } |
| 2763 | } |
| 2764 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2765 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2766 | ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2767 | |
| 2768 | direction = GetDirection(traffic_queue.direction()); |
| 2769 | if (direction.compare("direction-not-supported") == 0) |
| 2770 | return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported"); |
| 2771 | |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2772 | err = CreateQueue(direction, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2773 | |
Girish Gowdru | f26cf88 | 2019-05-01 23:47:58 -0700 | [diff] [blame] | 2774 | // If the queue exists already, lets not return failure and break the loop. |
| 2775 | if (err && err != BCM_ERR_ALREADY) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2776 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create queue, err = %s\n",bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2777 | return bcm_to_grpc_err(err, "Failed to create queue"); |
| 2778 | } |
| 2779 | } |
| 2780 | return Status::OK; |
| 2781 | } |
| 2782 | |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 2783 | bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2784 | bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2785 | bcmolt_tm_queue_cfg cfg; |
| 2786 | bcmolt_tm_queue_key key = { }; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2787 | bcmos_errno err; |
| 2788 | |
| 2789 | if (direction == downstream) { |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2790 | if (is_tm_sched_id_present(access_intf_id, onu_id, uni_id, direction, tech_profile_id)) { |
| 2791 | key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction, tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2792 | key.id = queue_id_list[priority]; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2793 | } else { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2794 | OPENOLT_LOG(INFO, openolt_log_id, "queue not present in DS. Not clearing, access_intf_id %d, onu_id %d, uni_id %d, 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] | 2795 | return BCM_ERR_OK; |
| 2796 | } |
| 2797 | } else { |
Girish Gowdra | 4fd3067 | 2020-11-09 17:23:06 -0800 | [diff] [blame] | 2798 | // Gemports are bi-directional (except in multicast case). We create the gem port when we create the |
| 2799 | // upstream queue (see CreateQueue function) and it makes sense to delete them when remove the upstream queues. |
| 2800 | // For multicast case we do not manage the install/remove of gem port in agent application. It is managed by BAL. |
| 2801 | // Moreover it also makes sense to remove when upstream queue is getting removed because the upstream queue MUST exist always. |
| 2802 | // It is possible that the downstream queues are not created for a subscriber (for ex: upstream EAPoL trap flow only exists |
| 2803 | // but no other flow, and in this case only upstream scheduler and queues exist. We do not have a scenario where only downstream |
| 2804 | // subscriber flows exist but no upstream ) |
| 2805 | remove_gem_port(access_intf_id, gemport_id); |
| 2806 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2807 | /* In the upstream we use pre-created queues on the NNI scheduler that are used by all subscribers. |
| 2808 | They should not be removed. So, lets return OK. */ |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2809 | return BCM_ERR_OK; |
| 2810 | } |
| 2811 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2812 | if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) { |
| 2813 | key.tm_q_set_id = BCMOLT_TM_QUEUE_SET_ID_QSET_NOT_USE; |
| 2814 | // Reset the queue id to 0 when using fixed queue. |
| 2815 | key.id = 0; |
| 2816 | } |
| 2817 | else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) { |
| 2818 | key.tm_q_set_id = get_tm_qmp_id(key.sched_id, access_intf_id, onu_id, uni_id); |
| 2819 | } |
| 2820 | else { |
| 2821 | key.tm_q_set_id = BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT; |
| 2822 | } |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2823 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2824 | BCMOLT_CFG_INIT(&cfg, tm_queue, key); |
| 2825 | err = bcmolt_cfg_clear(dev_id, &(cfg.hdr)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2826 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2827 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, direction = %s, queue_id %d, sched_id %d, \ |
| 2828 | tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, err = %s\n", |
| 2829 | direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2830 | return err; |
| 2831 | } |
| 2832 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2833 | OPENOLT_LOG(INFO, openolt_log_id, "Removed tm_queue, direction %s, id %d, sched_id %d, tm_q_set_id %d, \ |
| 2834 | intf_id %d, onu_id %d, uni_id %d\n", direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2835 | |
| 2836 | return BCM_ERR_OK; |
| 2837 | } |
| 2838 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2839 | Status RemoveTrafficQueues_(const ::tech_profile::TrafficQueues *traffic_queues) { |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2840 | uint32_t intf_id = traffic_queues->intf_id(); |
| 2841 | uint32_t onu_id = traffic_queues->onu_id(); |
| 2842 | uint32_t uni_id = traffic_queues->uni_id(); |
| 2843 | uint32_t port_no = traffic_queues->port_no(); |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2844 | uint32_t tech_profile_id = traffic_queues->tech_profile_id(); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2845 | uint32_t sched_id; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2846 | std::string direction; |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2847 | bcmos_errno err; |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 2848 | bcmolt_egress_qos_type qos_type = get_qos_type(intf_id, onu_id, uni_id, traffic_queues->traffic_queues_size()); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2849 | |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2850 | for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2851 | ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2852 | |
| 2853 | direction = GetDirection(traffic_queue.direction()); |
| 2854 | if (direction.compare("direction-not-supported") == 0) |
| 2855 | return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported"); |
| 2856 | |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2857 | err = RemoveQueue(direction, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2858 | if (err) { |
Thiyagarajan Subramani | 0890b1f | 2019-11-22 07:52:47 -0500 | [diff] [blame] | 2859 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, err = %s\n",bcmos_strerror(err)); |
Girish Gowdru | c8ed2ef | 2019-02-13 08:18:44 -0800 | [diff] [blame] | 2860 | return bcm_to_grpc_err(err, "Failed to remove queue"); |
| 2861 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2862 | } |
| 2863 | |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2864 | if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE && (direction.compare(upstream) == 0 || direction.compare(downstream) == 0 && is_tm_sched_id_present(intf_id, onu_id, uni_id, direction, tech_profile_id))) { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2865 | sched_id = (direction.compare(upstream) == 0) ? get_default_tm_sched_id(nni_intf_id, direction) : \ |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 2866 | get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2867 | |
| 2868 | int tm_qmp_id = get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id); |
| 2869 | if (free_tm_qmp_id(sched_id, intf_id, onu_id, uni_id, tm_qmp_id)) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2870 | err = RemoveTrafficQueueMappingProfile(tm_qmp_id); |
| 2871 | if (err != BCM_ERR_OK) { |
| 2872 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove tm queue mapping profile, err = %s\n", bcmos_strerror(err)); |
| 2873 | return bcm_to_grpc_err(err, "Failed to remove tm queue mapping profile"); |
| 2874 | } |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 2875 | } |
| 2876 | } |
Thiyagarajan Subramani | 8154d93 | 2019-11-13 05:29:06 -0500 | [diff] [blame] | 2877 | clear_qos_type(intf_id, onu_id, uni_id); |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2878 | return Status::OK; |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 2879 | } |
Jason Huang | bf45ffb | 2019-10-30 17:29:02 +0800 | [diff] [blame] | 2880 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2881 | Status PerformGroupOperation_(const ::openolt::Group *group_cfg) { |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2882 | |
| 2883 | bcmos_errno err; |
| 2884 | bcmolt_group_key key = {}; |
| 2885 | bcmolt_group_cfg grp_cfg_obj; |
| 2886 | bcmolt_group_members_update grp_mem_upd; |
| 2887 | bcmolt_members_update_command grp_mem_upd_cmd; |
| 2888 | bcmolt_group_member_info member_info = {}; |
| 2889 | bcmolt_group_member_info_list_u8 members = {}; |
| 2890 | bcmolt_intf_ref interface_ref = {}; |
| 2891 | bcmolt_egress_qos egress_qos = {}; |
| 2892 | bcmolt_tm_sched_ref tm_sched_ref = {}; |
| 2893 | bcmolt_action a_val = {}; |
| 2894 | |
| 2895 | uint32_t group_id = group_cfg->group_id(); |
| 2896 | |
| 2897 | OPENOLT_LOG(INFO, openolt_log_id, "PerformGroupOperation request received for Group %d\n", group_id); |
| 2898 | |
| 2899 | if (group_id >= 0) { |
| 2900 | key.id = group_id; |
| 2901 | } |
| 2902 | else { |
| 2903 | OPENOLT_LOG(ERROR, openolt_log_id, "Invalid group id %d.\n", group_id); |
| 2904 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid group id"); |
| 2905 | } |
| 2906 | |
| 2907 | BCMOLT_CFG_INIT(&grp_cfg_obj, group, key); |
| 2908 | BCMOLT_FIELD_SET_PRESENT(&grp_cfg_obj.data, group_cfg_data, state); |
| 2909 | |
| 2910 | OPENOLT_LOG(INFO, openolt_log_id, "Checking if Group %d exists...\n",group_id); |
| 2911 | |
| 2912 | err = bcmolt_cfg_get(dev_id, &(grp_cfg_obj.hdr)); |
| 2913 | if (err != BCM_ERR_OK) { |
| 2914 | OPENOLT_LOG(ERROR, openolt_log_id, "Error in querying Group %d, err = %s\n", group_id, bcmos_strerror(err)); |
| 2915 | return bcm_to_grpc_err(err, "Error in querying group"); |
| 2916 | } |
| 2917 | |
| 2918 | members.len = group_cfg->members_size(); |
| 2919 | |
| 2920 | // IMPORTANT: A member cannot be added to a group if the group type is not determined. |
| 2921 | // Group type is determined after a flow is assigned to it. |
| 2922 | // Therefore, a group must be created first, then a flow (with multicast type) must be assigned to it. |
| 2923 | // Only then we can add members to the group. |
| 2924 | |
| 2925 | // if group does not exist, create it and return. |
| 2926 | if (grp_cfg_obj.data.state == BCMOLT_GROUP_STATE_NOT_CONFIGURED) { |
| 2927 | |
| 2928 | if (members.len != 0) { |
| 2929 | OPENOLT_LOG(ERROR, openolt_log_id, "Member list is not empty for non-existent Group %d. Members can be added only after a flow is assigned to this newly-created group.\n", group_id); |
| 2930 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Non-empty member list given for non-existent group"); |
| 2931 | } else { |
| 2932 | |
| 2933 | BCMOLT_CFG_INIT(&grp_cfg_obj, group, key); |
| 2934 | BCMOLT_MSG_FIELD_SET(&grp_cfg_obj, cookie, key.id); |
| 2935 | |
| 2936 | /* Setting group actions and action parameters, if any. |
| 2937 | Only remove_outer_tag and translate_inner_tag actions and i_vid action parameter |
| 2938 | are supported for multicast groups in BAL 3.1. |
| 2939 | */ |
| 2940 | const ::openolt::Action& action = group_cfg->action(); |
| 2941 | const ::openolt::ActionCmd &cmd = action.cmd(); |
| 2942 | |
| 2943 | bcmolt_action_cmd_id cmd_bmask = BCMOLT_ACTION_CMD_ID_NONE; |
| 2944 | if (cmd.remove_outer_tag()) { |
| 2945 | OPENOLT_LOG(INFO, openolt_log_id, "Action remove_outer_tag applied to Group %d.\n", group_id); |
| 2946 | cmd_bmask = (bcmolt_action_cmd_id) (cmd_bmask | BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG); |
| 2947 | } |
| 2948 | |
| 2949 | if (cmd.translate_inner_tag()) { |
| 2950 | OPENOLT_LOG(INFO, openolt_log_id, "Action translate_inner_tag applied to Group %d.\n", group_id); |
| 2951 | cmd_bmask = (bcmolt_action_cmd_id) (cmd_bmask | BCMOLT_ACTION_CMD_ID_XLATE_INNER_TAG); |
| 2952 | } |
| 2953 | |
| 2954 | BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, cmd_bmask); |
| 2955 | |
| 2956 | if (action.i_vid()) { |
| 2957 | OPENOLT_LOG(INFO, openolt_log_id, "Setting action parameter i_vid=%d for Group %d.\n", action.i_vid(), group_id); |
| 2958 | BCMOLT_FIELD_SET(&a_val, action, i_vid, action.i_vid()); |
| 2959 | } |
| 2960 | |
| 2961 | BCMOLT_MSG_FIELD_SET(&grp_cfg_obj, action, a_val); |
| 2962 | |
| 2963 | // Create group |
| 2964 | err = bcmolt_cfg_set(dev_id, &(grp_cfg_obj.hdr)); |
| 2965 | |
| 2966 | if (BCM_ERR_OK != err) { |
| 2967 | BCM_LOG(ERROR, openolt_log_id, "Failed to create Group %d, err = %s (%d)\n", key.id, bcmos_strerror(err), err); |
| 2968 | return bcm_to_grpc_err(err, "Error in creating group"); |
| 2969 | } |
| 2970 | |
| 2971 | BCM_LOG(INFO, openolt_log_id, "Group %d has been created and configured with empty member list.\n", key.id); |
| 2972 | return Status::OK; |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | // The group already exists. Continue configuring it according to the update member command. |
| 2977 | |
| 2978 | OPENOLT_LOG(INFO, openolt_log_id, "Configuring existing Group %d.\n",group_id); |
| 2979 | |
| 2980 | // MEMBER LIST CONSTRUCTION |
| 2981 | // Note that members.len can be 0 here. if the group already exists and the command is SET then sending |
| 2982 | // empty list to the group is a legit operation and this actually empties the member list. |
| 2983 | members.arr = (bcmolt_group_member_info*)bcmos_calloc((members.len)*sizeof(bcmolt_group_member_info)); |
| 2984 | |
| 2985 | if (!members.arr) { |
| 2986 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to allocate memory for group member list.\n"); |
| 2987 | return grpc::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "Memory exhausted during member list creation"); |
| 2988 | } |
| 2989 | |
| 2990 | /* SET GROUP MEMBERS UPDATE COMMAND */ |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2991 | ::openolt::Group::GroupMembersCommand command = group_cfg->command(); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2992 | switch(command) { |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2993 | case ::openolt::Group::SET_MEMBERS : |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2994 | grp_mem_upd_cmd = BCMOLT_MEMBERS_UPDATE_COMMAND_SET; |
| 2995 | OPENOLT_LOG(INFO, openolt_log_id, "Setting %d members for Group %d.\n", members.len, group_id); |
| 2996 | break; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 2997 | case ::openolt::Group::ADD_MEMBERS : |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 2998 | grp_mem_upd_cmd = BCMOLT_MEMBERS_UPDATE_COMMAND_ADD; |
| 2999 | OPENOLT_LOG(INFO, openolt_log_id, "Adding %d members to Group %d.\n", members.len, group_id); |
| 3000 | break; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3001 | case ::openolt::Group::REMOVE_MEMBERS : |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3002 | grp_mem_upd_cmd = BCMOLT_MEMBERS_UPDATE_COMMAND_REMOVE; |
| 3003 | OPENOLT_LOG(INFO, openolt_log_id, "Removing %d members from Group %d.\n", members.len, group_id); |
| 3004 | break; |
| 3005 | default : |
| 3006 | OPENOLT_LOG(ERROR, openolt_log_id, "Invalid value %d for group member command.\n", command); |
| 3007 | bcmos_free(members.arr); |
| 3008 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid group member command"); |
| 3009 | } |
| 3010 | |
| 3011 | // SET MEMBERS LIST |
| 3012 | for (int i = 0; i < members.len; i++) { |
| 3013 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3014 | if (command == ::openolt::Group::REMOVE_MEMBERS) { |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3015 | OPENOLT_LOG(INFO, openolt_log_id, "Removing group member %d from group %d\n",i,key.id); |
| 3016 | } else { |
| 3017 | OPENOLT_LOG(INFO, openolt_log_id, "Adding group member %d to group %d\n",i,key.id); |
| 3018 | } |
| 3019 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3020 | ::openolt::GroupMember *member = (::openolt::GroupMember *) &group_cfg->members()[i]; |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3021 | |
| 3022 | // Set member interface type |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3023 | ::openolt::GroupMember::InterfaceType if_type = member->interface_type(); |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3024 | switch(if_type){ |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3025 | case ::openolt::GroupMember::PON : |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3026 | BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_type, BCMOLT_INTERFACE_TYPE_PON); |
| 3027 | OPENOLT_LOG(INFO, openolt_log_id, "Interface type PON is assigned to GroupMember %d\n",i); |
| 3028 | break; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3029 | case ::openolt::GroupMember::EPON_1G_PATH : |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3030 | BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_type, BCMOLT_INTERFACE_TYPE_EPON_1_G); |
| 3031 | OPENOLT_LOG(INFO, openolt_log_id, "Interface type EPON_1G is assigned to GroupMember %d\n",i); |
| 3032 | break; |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3033 | case ::openolt::GroupMember::EPON_10G_PATH : |
Burak Gurdag | c78b9e1 | 2019-11-29 11:14:51 +0000 | [diff] [blame] | 3034 | BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_type, BCMOLT_INTERFACE_TYPE_EPON_10_G); |
| 3035 | OPENOLT_LOG(INFO, openolt_log_id, "Interface type EPON_10G is assigned to GroupMember %d\n",i); |
| 3036 | break; |
| 3037 | default : |
| 3038 | OPENOLT_LOG(ERROR, openolt_log_id, "Invalid interface type value %d for GroupMember %d.\n",if_type,i); |
| 3039 | bcmos_free(members.arr); |
| 3040 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid interface type for a group member"); |
| 3041 | } |
| 3042 | |
| 3043 | // Set member interface id |
| 3044 | if (member->interface_id() >= 0) { |
| 3045 | BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_id, member->interface_id()); |
| 3046 | OPENOLT_LOG(INFO, openolt_log_id, "Interface %d is assigned to GroupMember %d\n", member->interface_id(), i); |
| 3047 | } else { |
| 3048 | bcmos_free(members.arr); |
| 3049 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid interface id for a group member"); |
| 3050 | } |
| 3051 | |
| 3052 | // Set member interface_ref |
| 3053 | BCMOLT_FIELD_SET(&member_info, group_member_info, intf, interface_ref); |
| 3054 | |
| 3055 | // Set member gem_port_id. This must be a multicast gemport. |
| 3056 | if (member->gem_port_id() >= 0) { |
| 3057 | BCMOLT_FIELD_SET(&member_info, group_member_info, svc_port_id, member->gem_port_id()); |
| 3058 | OPENOLT_LOG(INFO, openolt_log_id, "GEM Port %d is assigned to GroupMember %d\n", member->gem_port_id(), i); |
| 3059 | } else { |
| 3060 | bcmos_free(members.arr); |
| 3061 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid gem port id for a group member"); |
| 3062 | } |
| 3063 | |
| 3064 | // Set member scheduler id and queue_id |
| 3065 | uint32_t tm_sched_id = get_default_tm_sched_id(member->interface_id(), downstream); |
| 3066 | OPENOLT_LOG(INFO, openolt_log_id, "Scheduler %d is assigned to GroupMember %d\n", tm_sched_id, i); |
| 3067 | BCMOLT_FIELD_SET(&tm_sched_ref, tm_sched_ref, id, tm_sched_id); |
| 3068 | BCMOLT_FIELD_SET(&egress_qos, egress_qos, tm_sched, tm_sched_ref); |
| 3069 | |
| 3070 | // We assume that all multicast traffic destined to a PON port is using the same fixed queue. |
| 3071 | uint32_t tm_queue_id; |
| 3072 | if (member->priority() >= 0 && member->priority() < NUMBER_OF_DEFAULT_INTERFACE_QUEUES) { |
| 3073 | tm_queue_id = queue_id_list[member->priority()]; |
| 3074 | OPENOLT_LOG(INFO, openolt_log_id, "Queue %d is assigned to GroupMember %d\n", tm_queue_id, i); |
| 3075 | BCMOLT_FIELD_SET(&egress_qos, egress_qos, type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE); |
| 3076 | BCMOLT_FIELD_SET(&egress_qos.u.fixed_queue, egress_qos_fixed_queue, queue_id, tm_queue_id); |
| 3077 | } else { |
| 3078 | OPENOLT_LOG(ERROR, openolt_log_id, "Invalid fixed queue priority/ID %d for GroupMember %d\n", member->priority(), i); |
| 3079 | bcmos_free(members.arr); |
| 3080 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid queue priority for a group member"); |
| 3081 | } |
| 3082 | |
| 3083 | BCMOLT_FIELD_SET(&member_info, group_member_info, egress_qos, egress_qos); |
| 3084 | BCMOLT_ARRAY_ELEM_SET(&(members), i, member_info); |
| 3085 | } |
| 3086 | |
| 3087 | BCMOLT_OPER_INIT(&grp_mem_upd, group, members_update, key); |
| 3088 | BCMOLT_MSG_FIELD_SET(&grp_mem_upd, members_cmd.members, members); |
| 3089 | BCMOLT_MSG_FIELD_SET(&grp_mem_upd, members_cmd.command, grp_mem_upd_cmd); |
| 3090 | |
| 3091 | err = bcmolt_oper_submit(dev_id, &(grp_mem_upd.hdr)); |
| 3092 | bcmos_free(members.arr); |
| 3093 | |
| 3094 | if (BCM_ERR_OK != err) { |
| 3095 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to submit members update operation for Group %d err = %s (%d)\n", key.id, bcmos_strerror(err), err); |
| 3096 | return bcm_to_grpc_err(err, "Failed to submit members update operation for the group"); |
| 3097 | } |
| 3098 | |
| 3099 | OPENOLT_LOG(INFO, openolt_log_id, "Successfully submitted members update operation for Group %d\n", key.id); |
| 3100 | |
| 3101 | return Status::OK; |
| 3102 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 3103 | |
| 3104 | Status DeleteGroup_(uint32_t group_id) { |
| 3105 | |
| 3106 | bcmos_errno err = BCM_ERR_OK; |
| 3107 | bcmolt_group_cfg grp_cfg_obj; |
| 3108 | bcmolt_group_key key = {}; |
| 3109 | |
| 3110 | |
| 3111 | OPENOLT_LOG(INFO, openolt_log_id, "Delete request received for group %d\n", group_id); |
| 3112 | |
| 3113 | if (group_id >= 0) { |
| 3114 | key.id = group_id; |
| 3115 | } else { |
| 3116 | OPENOLT_LOG(ERROR, openolt_log_id, "Invalid group id %d.\n", group_id); |
| 3117 | return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid group id"); |
| 3118 | } |
| 3119 | |
| 3120 | /* init the BAL INIT API */ |
| 3121 | BCMOLT_CFG_INIT(&grp_cfg_obj, group, key); |
| 3122 | |
| 3123 | OPENOLT_LOG(DEBUG, openolt_log_id, "Checking if group %d exists...\n",group_id); |
| 3124 | |
| 3125 | // CONFIGURE GROUP MEMBERS |
| 3126 | BCMOLT_FIELD_SET_PRESENT(&grp_cfg_obj.data, group_cfg_data, state); |
| 3127 | err = bcmolt_cfg_get(dev_id, &(grp_cfg_obj.hdr)); |
| 3128 | |
| 3129 | if (err != BCM_ERR_OK) { |
| 3130 | OPENOLT_LOG(ERROR, openolt_log_id, "Error in querying Group %d, err = %s\n", group_id, bcmos_strerror(err)); |
| 3131 | return bcm_to_grpc_err(err, "Error in querying group"); |
| 3132 | } |
| 3133 | |
| 3134 | if (grp_cfg_obj.data.state != BCMOLT_GROUP_STATE_NOT_CONFIGURED) { |
| 3135 | OPENOLT_LOG(DEBUG, openolt_log_id, "Group %d exists. Will be deleted.\n",group_id); |
| 3136 | err = bcmolt_cfg_clear(dev_id, &(grp_cfg_obj.hdr)); |
| 3137 | if (err != BCM_ERR_OK) { |
| 3138 | OPENOLT_LOG(ERROR, openolt_log_id, "Group %d cannot be deleted err = %s (%d).\n", group_id, bcmos_strerror(err), err); |
| 3139 | return bcm_to_grpc_err(err, "Failed to delete group");; |
| 3140 | } |
| 3141 | } else { |
| 3142 | OPENOLT_LOG(ERROR, openolt_log_id, "Group %d does not exist.\n", group_id); |
| 3143 | return Status(grpc::StatusCode::NOT_FOUND, "Group not found"); |
| 3144 | } |
| 3145 | |
| 3146 | OPENOLT_LOG(INFO, openolt_log_id, "Group %d has been deleted successfully.\n", group_id); |
| 3147 | return Status::OK; |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 3148 | } |
| 3149 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3150 | Status GetLogicalOnuDistanceZero_(uint32_t intf_id, ::openolt::OnuLogicalDistance* response) { |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 3151 | bcmos_errno err = BCM_ERR_OK; |
| 3152 | uint32_t mld = 0; |
| 3153 | double LD0; |
| 3154 | |
| 3155 | err = getOnuMaxLogicalDistance(intf_id, &mld); |
| 3156 | if (err != BCM_ERR_OK) { |
| 3157 | return bcm_to_grpc_err(err, "Failed to retrieve ONU maximum logical distance"); |
| 3158 | } |
| 3159 | |
| 3160 | LD0 = LOGICAL_DISTANCE(mld*1000, MINIMUM_ONU_RESPONSE_RANGING_TIME, ONU_BIT_TRANSMISSION_DELAY); |
| 3161 | OPENOLT_LOG(INFO, openolt_log_id, "The ONU logical distance zero is %f, (PON %d)\n", LD0, intf_id); |
| 3162 | response->set_intf_id(intf_id); |
| 3163 | response->set_logical_onu_distance_zero(LD0); |
| 3164 | |
| 3165 | return Status::OK; |
| 3166 | } |
| 3167 | |
Girish Gowdra | 252f497 | 2020-09-07 21:24:01 -0700 | [diff] [blame] | 3168 | Status GetLogicalOnuDistance_(uint32_t intf_id, uint32_t onu_id, ::openolt::OnuLogicalDistance* response) { |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 3169 | bcmos_errno err = BCM_ERR_OK; |
| 3170 | bcmolt_itu_onu_params itu = {}; |
| 3171 | bcmolt_onu_cfg onu_cfg; |
| 3172 | bcmolt_onu_key onu_key = {}; |
| 3173 | uint32_t mld = 0; |
| 3174 | double LDi; |
| 3175 | |
| 3176 | onu_key.pon_ni = intf_id; |
| 3177 | onu_key.onu_id = onu_id; |
| 3178 | |
| 3179 | err = getOnuMaxLogicalDistance(intf_id, &mld); |
| 3180 | if (err != BCM_ERR_OK) { |
| 3181 | return bcm_to_grpc_err(err, "Failed to retrieve ONU maximum logical distance"); |
| 3182 | } |
| 3183 | |
| 3184 | /* Initialize the API struct. */ |
| 3185 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3186 | BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state); |
| 3187 | BCMOLT_FIELD_SET_PRESENT(&itu, itu_onu_params, ranging_time); |
| 3188 | BCMOLT_FIELD_SET(&onu_cfg.data, onu_cfg_data, itu, itu); |
| 3189 | #ifdef TEST_MODE |
| 3190 | // It is impossible to mock the setting of onu_cfg.data.onu_state because |
| 3191 | // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot |
| 3192 | // set the onu_cfg.data.onu_state. So a new stub function is created and address |
| 3193 | // of onu_cfg is passed. This is one-of case where we need to add test specific |
| 3194 | // code in production code. |
| 3195 | err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg); |
| 3196 | #else |
| 3197 | /* Call API function. */ |
| 3198 | err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr); |
| 3199 | #endif |
| 3200 | if (err != BCM_ERR_OK) { |
| 3201 | OPENOLT_LOG(ERROR, openolt_log_id, "Failed to retrieve ONU ranging time for PON %d/ONU id %d, err = %s (%d)\n", intf_id, onu_id, bcmos_strerror(err), err); |
| 3202 | return bcm_to_grpc_err(err, "Failed to retrieve ONU ranging time"); |
| 3203 | } |
| 3204 | |
| 3205 | if (onu_cfg.data.onu_state != BCMOLT_ONU_STATE_ACTIVE) { |
| 3206 | OPENOLT_LOG(ERROR, openolt_log_id, "ONU is not yet activated (PON %d, ONU id %d)\n", intf_id, onu_id); |
| 3207 | return bcm_to_grpc_err(BCM_ERR_PARM, "ONU is not yet activated\n"); |
| 3208 | } |
| 3209 | |
| 3210 | LDi = LOGICAL_DISTANCE(mld*1000, onu_cfg.data.itu.ranging_time, ONU_BIT_TRANSMISSION_DELAY); |
| 3211 | OPENOLT_LOG(INFO, openolt_log_id, "The ONU logical distance is %f, (PON %d, ONU id %d)\n", LDi, intf_id, onu_id); |
| 3212 | response->set_intf_id(intf_id); |
| 3213 | response->set_onu_id(onu_id); |
| 3214 | response->set_logical_onu_distance(LDi); |
| 3215 | |
| 3216 | return Status::OK; |
| 3217 | } |
Burak Gurdag | 74e3ab8 | 2020-12-17 13:35:06 +0000 | [diff] [blame] | 3218 | |
| 3219 | Status GetOnuStatistics_(uint32_t intf_id, uint32_t onu_id, openolt::OnuStatistics* onu_stats) { |
| 3220 | bcmos_errno err; |
| 3221 | |
| 3222 | err = get_onu_statistics((bcmolt_interface_id)intf_id, (bcmolt_onu_id)onu_id, onu_stats); |
| 3223 | |
| 3224 | if (err != BCM_ERR_OK) { |
| 3225 | OPENOLT_LOG(ERROR, openolt_log_id, "retrieval of ONU statistics failed - PON ID = %u, ONU ID = %u, err = %d - %s", intf_id, onu_id, err, bcmos_strerror(err)); |
| 3226 | return grpc::Status(grpc::StatusCode::INTERNAL, "retrieval of ONU statistics failed"); |
| 3227 | } |
| 3228 | |
| 3229 | OPENOLT_LOG(INFO, openolt_log_id, "retrieved ONU statistics for PON ID = %d, ONU ID = %d\n", (int)intf_id, (int)onu_id); |
| 3230 | return Status::OK; |
| 3231 | } |
| 3232 | |
| 3233 | Status GetGemPortStatistics_(uint32_t intf_id, uint32_t gemport_id, openolt::GemPortStatistics* gemport_stats) { |
| 3234 | bcmos_errno err; |
| 3235 | |
| 3236 | err = get_gemport_statistics((bcmolt_interface_id)intf_id, (bcmolt_gem_port_id)gemport_id, gemport_stats); |
| 3237 | |
| 3238 | if (err != BCM_ERR_OK) { |
| 3239 | OPENOLT_LOG(ERROR, openolt_log_id, "retrieval of GEMPORT statistics failed - PON ID = %u, ONU ID = %u, err = %d - %s", intf_id, gemport_id, err, bcmos_strerror(err)); |
| 3240 | return grpc::Status(grpc::StatusCode::INTERNAL, "retrieval of GEMPORT statistics failed"); |
| 3241 | } |
| 3242 | |
| 3243 | OPENOLT_LOG(INFO, openolt_log_id, "retrieved GEMPORT statistics for PON ID = %d, GEMPORT ID = %d\n", (int)intf_id, (int)gemport_id); |
| 3244 | return Status::OK; |
| 3245 | } |