blob: 7bd990832e1a458b647a3e4e31520dc5e82d3fa9 [file] [log] [blame]
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Shad Ansarib7b0ced2018-05-11 21:53:32 +00003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * 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 Ansarib7b0ced2018-05-11 21:53:32 +00007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * 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 Ansarib7b0ced2018-05-11 21:53:32 +000016
17#include <iostream>
18#include <memory>
19#include <string>
20
21#include "Queue.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000022#include <sstream>
Nicolas Palpacuer9c352082018-08-14 16:37:14 -040023#include <chrono>
24#include <thread>
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080025#include <bitset>
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000026#include <inttypes.h>
Jason Huangbf45ffb2019-10-30 17:29:02 +080027#include <unistd.h>
Jason Huang09b73ea2020-01-08 17:52:05 +080028#include <sys/socket.h>
29#include <netinet/in.h>
30#include <arpa/inet.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000031
Craig Lutgen88a22ad2018-10-04 12:30:46 -050032#include "device.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000033#include "core.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053034#include "core_data.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000035#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040036#include "stats_collection.h"
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040037#include "error_format.h"
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040038#include "state.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053039#include "core_utils.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000040
41extern "C"
42{
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000043#include <bcmolt_api.h>
44#include <bcmolt_host_api.h>
45#include <bcmolt_api_model_supporting_enums.h>
46
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000047#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 Palpacuerf0b02492018-09-10 10:21:29 -040055// FIXME : dependency problem
56// #include <bcm_common_gpon.h>
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040057// #include <bcm_dev_log_task.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000058}
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000059
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000060static std::string intf_technologies[MAX_SUPPORTED_PON];
Craig Lutgen88a22ad2018-10-04 12:30:46 -050061static const std::string UNKNOWN_TECH("unknown");
Craig Lutgenb2601f02018-10-23 13:04:31 -050062static const std::string MIXED_TECH("mixed");
63static std::string board_technology(UNKNOWN_TECH);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000064static std::string chip_family(UNKNOWN_TECH);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000065static std::string firmware_version = "Openolt.2019.07.01";
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040066
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080067static bcmos_errno CreateSched(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
Girish Gowdra252f4972020-09-07 21:24:01 -070068 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 Gurdag2f2618c2020-04-23 13:20:30 +000071static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction, int tech_profile_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080072static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
Burak Gurdag2f2618c2020-04-23 13:20:30 +000073 bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id);
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -050074static bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
Burak Gurdag2f2618c2020-04-23 13:20:30 +000075 bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000076static bcmos_errno CreateDefaultSched(uint32_t intf_id, const std::string direction);
77static bcmos_errno CreateDefaultQueue(uint32_t intf_id, const std::string direction);
Orhan Kupusogluec57af02021-05-12 12:38:17 +000078static const std::chrono::milliseconds ONU_RSSI_COMPLETE_WAIT_TIMEOUT = std::chrono::seconds(10);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000079
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000080inline const char *get_flow_acton_command(uint32_t command) {
81 char actions[200] = { };
82 char *s_actions_ptr = actions;
83 if (command & BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG) strcat(s_actions_ptr, "ADD_OUTER_TAG|");
84 if (command & BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG) strcat(s_actions_ptr, "REMOVE_OUTER_TAG|");
85 if (command & BCMOLT_ACTION_CMD_ID_XLATE_OUTER_TAG) strcat(s_actions_ptr, "TRANSLATE_OUTER_TAG|");
86 if (command & BCMOLT_ACTION_CMD_ID_ADD_INNER_TAG) strcat(s_actions_ptr, "ADD_INNTER_TAG|");
87 if (command & BCMOLT_ACTION_CMD_ID_REMOVE_INNER_TAG) strcat(s_actions_ptr, "REMOVE_INNER_TAG|");
88 if (command & BCMOLT_ACTION_CMD_ID_XLATE_INNER_TAG) strcat(s_actions_ptr, "TRANSLATE_INNER_TAG|");
89 if (command & BCMOLT_ACTION_CMD_ID_REMARK_OUTER_PBITS) strcat(s_actions_ptr, "REMOVE_OUTER_PBITS|");
90 if (command & BCMOLT_ACTION_CMD_ID_REMARK_INNER_PBITS) strcat(s_actions_ptr, "REMAKE_INNER_PBITS|");
91 return s_actions_ptr;
92}
93
kesavandc1f2db92020-08-31 15:32:06 +053094bcmolt_stat_alarm_config set_stat_alarm_config(const config::OnuItuPonAlarm* request) {
Jason Huang5d9ab1a2020-04-15 16:53:49 +080095 bcmolt_stat_alarm_config alarm_cfg = {};
96 bcmolt_stat_alarm_trigger_config trigger_obj = {};
97 bcmolt_stat_alarm_soak_config soak_obj = {};
98
99 switch (request->alarm_reporting_condition()) {
kesavandc1f2db92020-08-31 15:32:06 +0530100 case config::OnuItuPonAlarm::RATE_THRESHOLD:
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800101 trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
102 BCMOLT_FIELD_SET(&trigger_obj.u.rate_threshold, stat_alarm_trigger_config_rate_threshold,
103 rising, request->rate_threshold_config().rate_threshold_rising());
104 BCMOLT_FIELD_SET(&trigger_obj.u.rate_threshold, stat_alarm_trigger_config_rate_threshold,
105 falling, request->rate_threshold_config().rate_threshold_falling());
106 BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time,
107 request->rate_threshold_config().soak_time().active_soak_time());
108 BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time,
109 request->rate_threshold_config().soak_time().clear_soak_time());
110 break;
kesavandc1f2db92020-08-31 15:32:06 +0530111 case config::OnuItuPonAlarm::RATE_RANGE:
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800112 trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
113 BCMOLT_FIELD_SET(&trigger_obj.u.rate_range, stat_alarm_trigger_config_rate_range, upper,
114 request->rate_range_config().rate_range_upper());
115 BCMOLT_FIELD_SET(&trigger_obj.u.rate_range, stat_alarm_trigger_config_rate_range, lower,
116 request->rate_range_config().rate_range_lower());
117 BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time,
118 request->rate_range_config().soak_time().active_soak_time());
119 BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time,
120 request->rate_range_config().soak_time().clear_soak_time());
121 break;
kesavandc1f2db92020-08-31 15:32:06 +0530122 case config::OnuItuPonAlarm::VALUE_THRESHOLD:
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800123 trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
124 BCMOLT_FIELD_SET(&trigger_obj.u.value_threshold, stat_alarm_trigger_config_value_threshold,
125 limit, request->value_threshold_config().threshold_limit());
126 BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time,
127 request->value_threshold_config().soak_time().active_soak_time());
128 BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time,
129 request->value_threshold_config().soak_time().clear_soak_time());
130 break;
131 default:
132 OPENOLT_LOG(ERROR, openolt_log_id, "unsupported alarm reporting condition = %u\n", request->alarm_reporting_condition());
133 // For now just log the error and not return error. We can handle this scenario in the future.
134 break;
135 }
136
137 BCMOLT_FIELD_SET(&alarm_cfg, stat_alarm_config, trigger, trigger_obj);
138 BCMOLT_FIELD_SET(&alarm_cfg, stat_alarm_config, soak, soak_obj);
139
140 return alarm_cfg;
141}
142
kesavandc1f2db92020-08-31 15:32:06 +0530143Status OnuItuPonAlarmSet_(const config::OnuItuPonAlarm* request) {
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800144 bcmos_errno err;
145 bcmolt_onu_itu_pon_stats_cfg stat_cfg; /* declare main API struct */
146 bcmolt_onu_key key = {}; /* declare key */
147 bcmolt_stat_alarm_config errors_cfg = {};
148
149 key.pon_ni = request->pon_ni();
150 key.onu_id = request->onu_id();
151
152 /* Initialize the API struct. */
153 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
154
155 /*
156 1. BCMOLT_STAT_CONDITION_TYPE_NONE = 0, The alarm is disabled.
157 2. BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD = 1, The alarm is triggered if the stats delta value between samples
158 crosses the configured threshold boundary.
159 rising: The alarm is raised if the stats delta value per second becomes greater than this threshold level.
160 falling: The alarm is cleared if the stats delta value per second becomes less than this threshold level.
161 3. BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE = 2, The alarm is triggered if the stats delta value between samples
162 deviates from the configured range.
163 upper: The alarm is raised if the stats delta value per second becomes greater than this upper level.
164 lower: The alarm is raised if the stats delta value per second becomes less than this lower level.
165 4. BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD = 3, The alarm is raised if the stats sample value becomes greater
166 than this level. The alarm is cleared when the host read the stats.
167 limit: The alarm is raised if the stats sample value becomes greater than this level.
168 The alarm is cleared when the host clears the stats.
169
170 active_soak_time: If the alarm condition is raised and stays in the raised state for at least this amount
171 of time (unit=seconds), the alarm indication is sent to the host.
172 The OLT delays the alarm indication no less than this delay period.
173 It can be delayed more than this period because of the statistics sampling interval.
174 clear_soak_time: After the alarm is raised, if it is cleared and stays in the cleared state for at least
175 this amount of time (unit=seconds), the alarm indication is sent to the host.
176 The OLT delays the alarm indication no less than this delay period. It can be delayed more
177 than this period because of the statistics sampling interval.
178 */
179
180 errors_cfg = set_stat_alarm_config(request);
181
182 switch (request->alarm_id()) {
kesavandc1f2db92020-08-31 15:32:06 +0530183 case config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS:
Jason Huang5d9ab1a2020-04-15 16:53:49 +0800184 //set the rdi_errors alarm
185 BCMOLT_FIELD_SET(&stat_cfg.data, onu_itu_pon_stats_cfg_data, rdi_errors, errors_cfg);
186 break;
187 default:
188 OPENOLT_LOG(ERROR, openolt_log_id, "could not find the alarm id %d\n", request->alarm_id());
189 return bcm_to_grpc_err(BCM_ERR_PARM, "the alarm id is wrong");
190 }
191
192 err = bcmolt_stat_cfg_set(dev_id, &stat_cfg.hdr);
193 if (err != BCM_ERR_OK) {
194 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",
195 request->alarm_id(), key.pon_ni, key.onu_id, bcmos_strerror(err));
196 return bcm_to_grpc_err(err, "set Onu ITU PON stats alarm faild");
197 } else {
198 OPENOLT_LOG(INFO, openolt_log_id, "set onu itu pon stats alarm %d successfully, pon_ni %d, onu_id %d\n",
199 request->alarm_id(), key.pon_ni, key.onu_id);
200 }
201
202 return Status::OK;
203}
204
Girish Gowdra252f4972020-09-07 21:24:01 -0700205Status GetDeviceInfo_(::openolt::DeviceInfo* device_info) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500206 device_info->set_vendor(VENDOR_ID);
207 device_info->set_model(MODEL_ID);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400208 device_info->set_hardware_version("");
209 device_info->set_firmware_version(firmware_version);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500210 device_info->set_technology(board_technology);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500211 device_info->set_pon_ports(num_of_pon_ports);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500212
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800213 char serial_number[OPENOLT_FIELD_LEN];
214 memset(serial_number, '\0', OPENOLT_FIELD_LEN);
215 openolt_read_sysinfo("Serial Number", serial_number);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000216 OPENOLT_LOG(INFO, openolt_log_id, "Fetched device serial number %s\n", serial_number);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800217 device_info->set_device_serial_number(serial_number);
Burak Gurdag30db4822021-03-10 21:30:01 +0000218 device_info->set_previously_connected(state.previously_connected());
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800219
Girish Gowdru771f9ff2019-07-24 12:02:10 -0700220 char device_id[OPENOLT_FIELD_LEN];
221 memset(device_id, '\0', OPENOLT_FIELD_LEN);
Humera Kouser6143c9e2020-06-17 22:37:31 +0530222
223 if (grpc_server_interface_name != NULL) {
224 if (get_intf_mac(grpc_server_interface_name, device_id, sizeof(device_id)) != NULL)
225 {
226 OPENOLT_LOG(INFO, openolt_log_id, "Fetched mac address %s of an interface %s\n", device_id, grpc_server_interface_name);
227 }
228 else
229 {
230 OPENOLT_LOG(ERROR, openolt_log_id, "Mac address of an interface %s is NULL\n", grpc_server_interface_name);
231 }
232 }
233 else
234 {
235 openolt_read_sysinfo("MAC", device_id);
236 OPENOLT_LOG(INFO, openolt_log_id, "Fetched device mac address %s\n", device_id);
237 }
238
Girish Gowdru771f9ff2019-07-24 12:02:10 -0700239 device_info->set_device_id(device_id);
240
Craig Lutgenb2601f02018-10-23 13:04:31 -0500241 // Legacy, device-wide ranges. To be deprecated when adapter
242 // is upgraded to support per-interface ranges
Girish Gowdra252f4972020-09-07 21:24:01 -0700243 device_info->set_onu_id_start(ONU_ID_START);
244 device_info->set_onu_id_end(ONU_ID_END);
245 device_info->set_alloc_id_start(ALLOC_ID_START);
246 device_info->set_alloc_id_end(ALLOC_ID_END);
247 device_info->set_gemport_id_start(GEM_PORT_ID_START);
248 device_info->set_gemport_id_end(GEM_PORT_ID_END);
249 device_info->set_flow_id_start(FLOW_ID_START);
250 device_info->set_flow_id_end(FLOW_ID_END);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500251
Girish Gowdra252f4972020-09-07 21:24:01 -0700252 std::map<std::string, ::openolt::DeviceInfo::DeviceResourceRanges*> ranges;
Craig Lutgenb2601f02018-10-23 13:04:31 -0500253 for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) {
254 std::string intf_technology = intf_technologies[intf_id];
Girish Gowdra252f4972020-09-07 21:24:01 -0700255 ::openolt::DeviceInfo::DeviceResourceRanges *range = ranges[intf_technology];
Craig Lutgenb2601f02018-10-23 13:04:31 -0500256 if(range == nullptr) {
257 range = device_info->add_ranges();
258 ranges[intf_technology] = range;
259 range->set_technology(intf_technology);
260
Girish Gowdra252f4972020-09-07 21:24:01 -0700261 ::openolt::DeviceInfo::DeviceResourceRanges::Pool* pool;
Craig Lutgenb2601f02018-10-23 13:04:31 -0500262
Girish Gowdra252f4972020-09-07 21:24:01 -0700263 pool = range->add_pools();
264 pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID);
265 pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
266 pool->set_start(ONU_ID_START);
267 pool->set_end(ONU_ID_END);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500268
Girish Gowdra252f4972020-09-07 21:24:01 -0700269 pool = range->add_pools();
270 pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID);
271 pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
272 pool->set_start(ALLOC_ID_START);
Girish Gowdraeec0fc92021-05-12 15:37:55 -0700273 pool->set_end(ALLOC_ID_END);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500274
Girish Gowdra252f4972020-09-07 21:24:01 -0700275 pool = range->add_pools();
276 pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID);
277 pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
278 pool->set_start(GEM_PORT_ID_START);
279 pool->set_end(GEM_PORT_ID_END);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500280
Girish Gowdra252f4972020-09-07 21:24:01 -0700281 pool = range->add_pools();
282 pool->set_type(::openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID);
283 pool->set_sharing(::openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
284 pool->set_start(FLOW_ID_START);
285 pool->set_end(FLOW_ID_END);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500286 }
287
288 range->add_intf_ids(intf_id);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500289 }
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400290
291 // FIXME: Once dependency problem is fixed
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500292 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400293 // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1);
294 // device_info->set_alloc_id_start(1024);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500295 // device_info->set_alloc_id_end(XGPON_NUM_OF_ALLOC_IDS * num_of_pon_ports ? - 1);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400296 // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500297 // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1);
298 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400299
300 return Status::OK;
301}
302
Thiyagarajan Subramani3e8bfd92021-04-26 15:07:14 +0530303void reset_pon_device(bcmolt_odid dev)
304{
305 bcmos_errno err;
306 bcmolt_device_reset oper;
307 bcmolt_device_key key = {.device_id = dev};
308
309 OPENOLT_LOG(INFO, openolt_log_id, "Reset PON device: %d\n", dev);
310
311 BCMOLT_OPER_INIT(&oper, device, reset, key);
312 err = bcmolt_oper_submit(dev_id, &oper.hdr);
313 if (err)
314 {
315 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to reset PON device(%d) failed, err = %s\n", dev, bcmos_strerror(err));
316 }else
317 {
318 OPENOLT_LOG(INFO, openolt_log_id, "Reset PON device(%d) success\n", dev);
319 }
320}
321
Shad Ansari627b5782018-08-13 22:49:32 +0000322Status Enable_(int argc, char *argv[]) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000323 bcmos_errno err;
324 bcmolt_host_init_parms init_parms = {};
325 init_parms.transport.type = BCM_HOST_API_CONN_LOCAL;
326 unsigned int failed_enable_device_cnt = 0;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000327
Shad Ansariedef2132018-08-10 22:14:50 +0000328 if (!state.is_activated()) {
Shad Ansari627b5782018-08-13 22:49:32 +0000329
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500330 vendor_init();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000331 /* Initialize host subsystem */
332 err = bcmolt_host_init(&init_parms);
333 if (BCM_ERR_OK != err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500334 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to init OLT, err = %s\n",bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000335 return bcm_to_grpc_err(err, "Failed to init OLT");
336 }
337
338 bcmcli_session_parm mon_session_parm;
339 /* Create CLI session */
340 memset(&mon_session_parm, 0, sizeof(mon_session_parm));
341 mon_session_parm.get_prompt = openolt_cli_get_prompt_cb;
342 mon_session_parm.access_right = BCMCLI_ACCESS_ADMIN;
343 bcmos_errno rc = bcmcli_session_open(&mon_session_parm, &current_session);
344 BUG_ON(rc != BCM_ERR_OK);
345
346 /* API CLI */
347 bcm_openolt_api_cli_init(NULL, current_session);
348
349 /* Add quit command */
350 BCMCLI_MAKE_CMD_NOPARM(NULL, "quit", "Quit", bcm_cli_quit);
351
352 err = bcmolt_apiend_cli_init();
353 if (BCM_ERR_OK != err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500354 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to add apiend init, err = %s\n",bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000355 return bcm_to_grpc_err(err, "Failed to add apiend init");
356 }
357
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800358 bcmos_fastlock_init(&data_lock, 0);
Girish Gowdra252f4972020-09-07 21:24:01 -0700359 bcmos_fastlock_init(&acl_id_bitset_lock, 0);
360 bcmos_fastlock_init(&tm_sched_bitset_lock, 0);
361 bcmos_fastlock_init(&tm_qmp_bitset_lock, 0);
362 bcmos_fastlock_init(&flow_id_bitset_lock, 0);
363 bcmos_fastlock_init(&voltha_flow_to_device_flow_lock, 0);
Girish Gowdra96461052019-11-22 20:13:59 +0530364 bcmos_fastlock_init(&alloc_cfg_wait_lock, 0);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +0530365 bcmos_fastlock_init(&gem_cfg_wait_lock, 0);
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530366 bcmos_fastlock_init(&onu_deactivate_wait_lock, 0);
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700367 bcmos_fastlock_init(&acl_packet_trap_handler_lock, 0);
Girish Gowdraeec0fc92021-05-12 15:37:55 -0700368 bcmos_fastlock_init(&symmetric_datapath_flow_id_lock, 0);
369 bcmos_fastlock_init(&pon_gem_to_onu_uni_map_lock, 0);
370
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700371
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000372 OPENOLT_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600373
Jason Huangbf45ffb2019-10-30 17:29:02 +0800374 //check BCM daemon is connected or not
375 Status status = check_connection();
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000376 if (!status.ok()) {
Jason Huangbf45ffb2019-10-30 17:29:02 +0800377 return status;
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000378 }
Jason Huangbf45ffb2019-10-30 17:29:02 +0800379 else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000380 Status status = SubscribeIndication();
381 if (!status.ok()) {
382 OPENOLT_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n",
383 grpc_status_code_to_string(status.error_code()).c_str(),
384 status.error_message().c_str());
385 return status;
386 }
Jason Huangbf45ffb2019-10-30 17:29:02 +0800387
388 //check BAL state in initial stage
389 status = check_bal_ready();
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000390 if (!status.ok()) {
Jason Huangbf45ffb2019-10-30 17:29:02 +0800391 return status;
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000392 }
Jason Huangbf45ffb2019-10-30 17:29:02 +0800393 }
394
395 {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000396 bcmos_errno err;
397 bcmolt_odid dev;
398 OPENOLT_LOG(INFO, openolt_log_id, "Enabling PON %d Devices ... \n", BCM_MAX_DEVS_PER_LINE_CARD);
399 for (dev = 0; dev < BCM_MAX_DEVS_PER_LINE_CARD; dev++) {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400400 bcmolt_device_cfg dev_cfg = { };
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000401 bcmolt_device_key dev_key = { };
402 dev_key.device_id = dev;
403 BCMOLT_CFG_INIT(&dev_cfg, device, dev_key);
404 BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode);
Thiyagarajan Subramani4e62e172021-06-25 17:31:30 +0530405
406 /* FIXME: Single Phoenix BAL patch is prepared for all three variants of Radisys OLT
407 * in which BCM_MAX_DEVS_PER_LINE_CARD macro need to be redefined as 1 incase of
408 * "rlt-1600g-w" and "rlt-1600x-w", till then this workaround is required.*/
409 if (dev == 1 && (MODEL_ID == "rlt-1600g-w" || MODEL_ID == "rlt-1600x-w")) {
410 continue;
411 }
412
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000413 err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr);
Jason Huangbf45ffb2019-10-30 17:29:02 +0800414 if (err == BCM_ERR_NOT_CONNECTED) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000415 bcmolt_device_key key = {.device_id = dev};
416 bcmolt_device_connect oper;
417 BCMOLT_OPER_INIT(&oper, device, connect, key);
Thiyagarajan Subramani3e8bfd92021-04-26 15:07:14 +0530418
419 /* BAL saves current state into dram_tune soc file and when dev_mgmt_daemon restarts
420 * it retains config from soc file. If openolt agent try to connect device without
421 * device reset device initialization fails hence doing device reset here. */
422 reset_pon_device(dev);
423
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000424 if (MODEL_ID == "asfvolt16") {
425 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI);
426 BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_XGS__2_X);
427 } else if (MODEL_ID == "asgvolt64") {
428 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI);
429 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mux, BCMOLT_INNI_MUX_FOUR_TO_ONE);
430 BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_GPON__16_X);
Thiyagarajan Subramani4e62e172021-06-25 17:31:30 +0530431 } else if (MODEL_ID == "rlt-3200g-w" || MODEL_ID == "rlt-1600g-w") {
Thiyagarajan Subramani3e8bfd92021-04-26 15:07:14 +0530432 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mux, BCMOLT_INNI_MUX_NONE);
433 if(dev == 1) {
434 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mux, BCMOLT_INNI_MUX_FOUR_TO_ONE);
435 }
436 BCMOLT_MSG_FIELD_SET (&oper, ras_ddr_mode, BCMOLT_RAS_DDR_USAGE_MODE_TWO_DDRS);
437 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI);
438 BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_GPON__16_X);
Thiyagarajan Subramani4e62e172021-06-25 17:31:30 +0530439 } else if (MODEL_ID == "rlt-1600x-w") {
440 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mux, BCMOLT_INNI_MUX_NONE);
441 BCMOLT_MSG_FIELD_SET (&oper, ras_ddr_mode, BCMOLT_RAS_DDR_USAGE_MODE_TWO_DDRS);
442 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI);
443 /* By default setting device mode to GPON for rlt 1600x.
444 In future device mode can be configured to XGSPON || GPON by reading
445 device mode configuration from a static configuration file*/
446 BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_GPON__16_X);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000447 }
448 err = bcmolt_oper_submit(dev_id, &oper.hdr);
449 if (err) {
450 failed_enable_device_cnt ++;
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500451 OPENOLT_LOG(ERROR, openolt_log_id, "Enable PON device %d failed, err = %s\n", dev, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000452 if (failed_enable_device_cnt == BCM_MAX_DEVS_PER_LINE_CARD) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500453 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable all the pon ports, err = %s\n", bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000454 return Status(grpc::StatusCode::INTERNAL, "Failed to activate all PON ports");
455 }
456 }
Girish Gowdra72bb4652022-01-18 17:04:30 -0800457 bcmos_usleep(MAC_DEVICE_ACTIVATION_DELAY);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000458 }
459 else {
Thiyagarajan Subramani4e62e172021-06-25 17:31:30 +0530460 OPENOLT_LOG(WARNING, openolt_log_id, "PON device %d already connected\n", dev);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000461 state.activate();
462 }
463 }
464 init_stats();
Shad Ansari627b5782018-08-13 22:49:32 +0000465 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000466 }
Shad Ansariedef2132018-08-10 22:14:50 +0000467
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000468 /* Start CLI */
469 OPENOLT_LOG(INFO, def_log_id, "Starting CLI\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400470 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000471 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400472}
473
474Status Disable_() {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400475 //In the earlier implementation Disabling olt is done by disabling the NNI port associated with that.
476 //In inband scenario instead of using management interface to establish connection with adapter ,NNI interface will be used.
477 //Disabling NNI port on olt disable causes connection loss between adapter and agent.
478 //To overcome this disable is implemented by disabling all the PON ports
479 //associated with the device so as to support both in-band
480 //and out of band scenarios.
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400481
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400482 Status status;
483 int failedCount = 0;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700484 OPENOLT_LOG(INFO, openolt_log_id, "Received disable OLT\n");
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400485 for (int i = 0; i < NumPonIf_(); i++) {
486 status = DisablePonIf_(i);
487 if (!status.ok()) {
488 failedCount+=1;
489 BCM_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n", i);
490 }
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400491 }
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400492 if (failedCount == 0) {
493 state.deactivate();
Girish Gowdra252f4972020-09-07 21:24:01 -0700494 ::openolt::Indication ind;
495 ::openolt::OltIndication* olt_ind = new ::openolt::OltIndication;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400496 olt_ind->set_oper_state("down");
497 ind.set_allocated_olt_ind(olt_ind);
498 BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n");
499 oltIndQ.push(ind);
500 return Status::OK;
501 }
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000502 if (failedCount ==NumPonIf_()) {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400503 return grpc::Status(grpc::StatusCode::INTERNAL, "failed to disable olt ,all the PON ports are still in enabled state");
504 }
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400505
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400506 return grpc::Status(grpc::StatusCode::UNKNOWN, "failed to disable olt ,few PON ports are still in enabled state");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400507}
508
509Status Reenable_() {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400510 Status status;
511 int failedCount = 0;
512 for (int i = 0; i < NumPonIf_(); i++) {
513 status = EnablePonIf_(i);
514 if (!status.ok()) {
515 failedCount+=1;
516 BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", i);
517 }
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400518 }
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000519 if (failedCount == 0) {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400520 state.activate();
Girish Gowdra252f4972020-09-07 21:24:01 -0700521 ::openolt::Indication ind;
522 ::openolt::OltIndication* olt_ind = new ::openolt::OltIndication;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400523 olt_ind->set_oper_state("up");
524 ind.set_allocated_olt_ind(olt_ind);
525 BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n");
526 oltIndQ.push(ind);
527 return Status::OK;
528 }
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000529 if (failedCount ==NumPonIf_()) {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400530 return grpc::Status(grpc::StatusCode::INTERNAL, "failed to re-enable olt ,all the PON ports are still in disabled state");
531 }
532 return grpc::Status(grpc::StatusCode::UNKNOWN, "failed to re-enable olt ,few PON ports are still in disabled state");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000533}
534
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000535inline uint64_t get_flow_status(uint16_t flow_id, uint16_t flow_type, uint16_t data_id) {
536 bcmos_errno err;
537 bcmolt_flow_key flow_key;
538 bcmolt_flow_cfg flow_cfg;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400539
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000540 flow_key.flow_id = flow_id;
541 flow_key.flow_type = (bcmolt_flow_type)flow_type;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400542
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000543 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400544
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000545 switch (data_id) {
546 case ONU_ID: //onu_id
547 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, onu_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500548 #ifdef TEST_MODE
549 // It is impossible to mock the setting of flow_cfg.data.state because
550 // the actual bcmolt_cfg_get passes the address of flow_cfg.hdr and we cannot
551 // set the flow_cfg.data. So a new stub function is created and address
552 // of flow_cfg is passed. This is one-of case where we need to add test specific
553 // code in production code.
554 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
555 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000556 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500557 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000558 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700559 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get onu_id, err = %s (%d)\n", flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000560 return err;
561 }
562 return flow_cfg.data.onu_id;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400563 case FLOW_TYPE:
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500564 #ifdef TEST_MODE
565 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
566 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000567 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500568 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000569 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700570 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get flow_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000571 return err;
572 }
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400573 return flow_cfg.key.flow_type;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000574 case SVC_PORT_ID: //svc_port_id
575 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, svc_port_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500576 #ifdef TEST_MODE
577 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
578 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000579 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500580 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000581 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700582 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get svc_port_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000583 return err;
584 }
585 return flow_cfg.data.svc_port_id;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400586 case PRIORITY:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000587 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, priority);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500588 #ifdef TEST_MODE
589 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
590 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000591 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500592 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000593 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700594 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get priority, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000595 return err;
596 }
597 return flow_cfg.data.priority;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400598 case COOKIE: //cookie
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000599 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, cookie);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500600 #ifdef TEST_MODE
601 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
602 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000603 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500604 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000605 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700606 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get cookie, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000607 return err;
608 }
609 return flow_cfg.data.cookie;
610 case INGRESS_INTF_TYPE: //ingress intf_type
611 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500612 #ifdef TEST_MODE
613 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
614 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000615 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500616 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000617 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700618 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000619 return err;
620 }
621 return flow_cfg.data.ingress_intf.intf_type;
622 case EGRESS_INTF_TYPE: //egress intf_type
623 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_intf);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500624 #ifdef TEST_MODE
625 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
626 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000627 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500628 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000629 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700630 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000631 return err;
632 }
633 return flow_cfg.data.egress_intf.intf_type;
634 case INGRESS_INTF_ID: //ingress intf_id
635 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500636 #ifdef TEST_MODE
637 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
638 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000639 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500640 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000641 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700642 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000643 return err;
644 }
645 return flow_cfg.data.ingress_intf.intf_id;
646 case EGRESS_INTF_ID: //egress intf_id
647 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_intf);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500648 #ifdef TEST_MODE
649 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
650 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000651 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500652 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000653 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700654 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000655 return err;
656 }
657 return flow_cfg.data.egress_intf.intf_id;
658 case CLASSIFIER_O_VID:
659 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500660 #ifdef TEST_MODE
661 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
662 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000663 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500664 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000665 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700666 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000667 return err;
668 }
669 return flow_cfg.data.classifier.o_vid;
670 case CLASSIFIER_O_PBITS:
671 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500672 #ifdef TEST_MODE
673 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
674 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000675 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500676 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000677 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700678 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000679 return err;
680 }
681 return flow_cfg.data.classifier.o_pbits;
682 case CLASSIFIER_I_VID:
683 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500684 #ifdef TEST_MODE
685 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
686 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000687 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500688 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000689 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700690 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000691 return err;
692 }
693 return flow_cfg.data.classifier.i_vid;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400694 case CLASSIFIER_I_PBITS:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000695 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500696 #ifdef TEST_MODE
697 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
698 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000699 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500700 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000701 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700702 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000703 return err;
704 }
705 return flow_cfg.data.classifier.i_pbits;
706 case CLASSIFIER_ETHER_TYPE:
707 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500708 #ifdef TEST_MODE
709 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
710 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000711 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500712 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000713 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700714 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ether_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000715 return err;
716 }
717 return flow_cfg.data.classifier.ether_type;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400718 case CLASSIFIER_IP_PROTO:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000719 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500720 #ifdef TEST_MODE
721 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
722 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000723 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500724 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000725 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700726 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ip_proto, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000727 return err;
728 }
729 return flow_cfg.data.classifier.ip_proto;
730 case CLASSIFIER_SRC_PORT:
731 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500732 #ifdef TEST_MODE
733 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
734 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000735 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500736 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000737 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700738 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier src_port, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000739 return err;
740 }
741 return flow_cfg.data.classifier.src_port;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400742 case CLASSIFIER_DST_PORT:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000743 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500744 #ifdef TEST_MODE
745 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
746 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000747 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500748 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000749 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700750 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier dst_port, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000751 return err;
752 }
753 return flow_cfg.data.classifier.dst_port;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400754 case CLASSIFIER_PKT_TAG_TYPE:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000755 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500756 #ifdef TEST_MODE
757 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
758 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000759 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500760 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000761 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700762 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier pkt_tag_type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000763 return err;
764 }
765 return flow_cfg.data.classifier.pkt_tag_type;
766 case EGRESS_QOS_TYPE:
767 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500768 #ifdef TEST_MODE
769 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
770 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000771 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500772 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000773 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700774 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos type, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000775 return err;
776 }
777 return flow_cfg.data.egress_qos.type;
778 case EGRESS_QOS_QUEUE_ID:
779 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500780 #ifdef TEST_MODE
781 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
782 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000783 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500784 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000785 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700786 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos queue_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000787 return err;
788 }
789 switch (flow_cfg.data.egress_qos.type) {
790 case BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE:
791 return flow_cfg.data.egress_qos.u.fixed_queue.queue_id;
792 case BCMOLT_EGRESS_QOS_TYPE_TC_TO_QUEUE:
793 return flow_cfg.data.egress_qos.u.tc_to_queue.tc_to_queue_id;
794 case BCMOLT_EGRESS_QOS_TYPE_PBIT_TO_TC:
795 return flow_cfg.data.egress_qos.u.pbit_to_tc.tc_to_queue_id;
796 case BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE:
797 return flow_cfg.data.egress_qos.u.priority_to_queue.tm_q_set_id;
798 case BCMOLT_EGRESS_QOS_TYPE_NONE:
799 default:
800 return -1;
801 }
802 case EGRESS_QOS_TM_SCHED_ID:
803 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500804 #ifdef TEST_MODE
805 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
806 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000807 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500808 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000809 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700810 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos tm_sched_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000811 return err;
812 }
813 return flow_cfg.data.egress_qos.tm_sched.id;
814 case ACTION_CMDS_BITMASK:
815 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500816 #ifdef TEST_MODE
817 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
818 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000819 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500820 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000821 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700822 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action cmds_bitmask, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000823 return err;
824 }
825 return flow_cfg.data.action.cmds_bitmask;
826 case ACTION_O_VID:
827 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500828 #ifdef TEST_MODE
829 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
830 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000831 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500832 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000833 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700834 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000835 return err;
836 }
837 return flow_cfg.data.action.o_vid;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400838 case ACTION_O_PBITS:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000839 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500840 #ifdef TEST_MODE
841 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
842 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000843 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500844 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000845 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700846 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000847 return err;
848 }
849 return flow_cfg.data.action.o_pbits;
850 case ACTION_I_VID:
851 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500852 #ifdef TEST_MODE
853 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
854 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000855 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500856 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000857 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700858 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_vid, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000859 return err;
860 }
861 return flow_cfg.data.action.i_vid;
862 case ACTION_I_PBITS:
863 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500864 #ifdef TEST_MODE
865 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
866 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000867 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500868 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000869 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700870 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_pbits, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000871 return err;
872 }
873 return flow_cfg.data.action.i_pbits;
874 case STATE:
875 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, state);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500876 #ifdef TEST_MODE
877 err = bcmolt_cfg_get__flow_stub(dev_id, &flow_cfg);
878 #else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000879 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -0500880 #endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000881 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700882 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get state, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000883 return err;
884 }
885 return flow_cfg.data.state;
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000886 case GROUP_ID:
887 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, group_id);
888 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
889 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -0700890 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get group_id, err = %s (%d)\n",flow_cfg.hdr.hdr.err_text, err);
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000891 return err;
892 }
893 return flow_cfg.data.group_id;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000894 default:
895 return BCM_ERR_INTERNAL;
896 }
897
898 return err;
899}
900
901Status EnablePonIf_(uint32_t intf_id) {
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400902 bcmos_errno err = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000903 bcmolt_pon_interface_cfg interface_obj;
904 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id};
905 bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state;
906 bcmolt_interface_state state;
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +0530907 bcmolt_status los_status;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000908
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +0530909 err = get_pon_interface_status((bcmolt_interface)intf_id, &state, &los_status);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000910 if (err == BCM_ERR_OK) {
911 if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) {
Jason Huangbf45ffb2019-10-30 17:29:02 +0800912 OPENOLT_LOG(WARNING, openolt_log_id, "PON interface: %d already enabled\n", intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000913 return Status::OK;
914 }
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400915 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000916 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
917 BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key);
918 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_ENABLE);
919 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.interval, 5000);
920 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.onu_post_discovery_mode,
Girish Gowdra24297032020-03-23 12:32:37 -0700921 BCMOLT_ONU_POST_DISCOVERY_MODE_NONE);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000922 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.los, true);
923 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.onu_alarms, true);
924 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.tiwi, true);
925 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.ack_timeout, true);
926 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.sfi, true);
927 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.loki, true);
Burak Gurdag5e587792020-05-06 14:58:02 +0000928
929 // On GPON, power level mode is not set to its default value (i.e. 0) as documented in Broadcom documentation.
930 // Instead, it is set to 2 which means -6 dbM attenuation. Therefore, we explicitly set it to the default value below.
931 if (board_technology == "GPON") {
932 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.gpon.power_level.pls_maximum_allocation_size, BCMOLT_PON_POWER_LEVEL_PLS_MAXIMUM_ALLOCATION_SIZE_DEFAULT);
933 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.gpon.power_level.mode, BCMOLT_PON_POWER_LEVEL_MODE_DEFAULT);
934 }
935
kesavandc1f2db92020-08-31 15:32:06 +0530936 //Enable AES Encryption
937 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.onu_activation.key_exchange, BCMOLT_CONTROL_STATE_ENABLE);
938 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.onu_activation.authentication, BCMOLT_CONTROL_STATE_ENABLE);
939 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.onu_activation.fail_due_to_authentication_failure, BCMOLT_CONTROL_STATE_ENABLE);
940
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000941 BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data,
942 operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING);
943
944 err = bcmolt_cfg_set(dev_id, &interface_obj.hdr);
945 if (err != BCM_ERR_OK) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500946 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable discovery onu, PON interface %d, err = %s\n", intf_id, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000947 return bcm_to_grpc_err(err, "Failed to enable discovery onu");
948 }
949 err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr);
950 if (err != BCM_ERR_OK) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500951 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d, err = %s\n", intf_id, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000952 return bcm_to_grpc_err(err, "Failed to enable PON interface");
953 }
954 else {
955 OPENOLT_LOG(INFO, openolt_log_id, "Successfully enabled PON interface: %d\n", intf_id);
956 OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for PON interface: %d\n", intf_id);
957 CreateDefaultSched(intf_id, downstream);
958 CreateDefaultQueue(intf_id, downstream);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400959 }
960
961 return Status::OK;
962}
963
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500964Status ProbeDeviceCapabilities_() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000965 bcmos_errno err;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400966 bcmolt_device_cfg dev_cfg = { };
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000967 bcmolt_device_key dev_key = { };
968 bcmolt_olt_cfg olt_cfg = { };
969 bcmolt_olt_key olt_key = { };
970 bcmolt_topology_map topo_map[BCM_MAX_PONS_PER_OLT] = { };
971 bcmolt_topology topo = { };
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500972
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000973 topo.topology_maps.len = BCM_MAX_PONS_PER_OLT;
974 topo.topology_maps.arr = &topo_map[0];
975 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
976 BCMOLT_MSG_FIELD_GET(&olt_cfg, bal_state);
977 BCMOLT_FIELD_SET_PRESENT(&olt_cfg.data, olt_cfg_data, topology);
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400978 BCMOLT_CFG_LIST_BUF_SET(&olt_cfg, olt, topo.topology_maps.arr,
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000979 sizeof(bcmolt_topology_map) * topo.topology_maps.len);
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400980 #ifdef TEST_MODE
981 // It is impossible to mock the setting of olt_cfg.data.bal_state because
982 // the actual bcmolt_cfg_get passes the address of olt_cfg.hdr and we cannot
983 // set the olt_cfg.data.topology. So a new stub function is created and address
984 // of olt_cfg is passed. This is one-of case where we need to test add specific
985 // code in production code.
986 err = bcmolt_cfg_get__olt_topology_stub(dev_id, &olt_cfg);
987 #else
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000988 err = bcmolt_cfg_get_mult_retry(dev_id, &olt_cfg.hdr);
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400989 #endif
990 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -0500991 OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query OLT topology, err = %s\n", bcmos_strerror(err));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000992 return bcm_to_grpc_err(err, "cfg: Failed to query OLT topology");
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500993 }
994
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000995 num_of_nni_ports = olt_cfg.data.topology.num_switch_ports;
996 num_of_pon_ports = olt_cfg.data.topology.topology_maps.len;
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500997
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -0400998 OPENOLT_LOG(INFO, openolt_log_id, "OLT capabilitites, oper_state: %s\n",
999 olt_cfg.data.bal_state == BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001000 ? "up" : "down");
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001001
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001002 OPENOLT_LOG(INFO, openolt_log_id, "topology nni: %d pon: %d dev: %d\n",
1003 num_of_nni_ports,
1004 num_of_pon_ports,
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001005 BCM_MAX_DEVS_PER_LINE_CARD);
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001006
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001007 uint32_t num_failed_cfg_gets = 0;
Jason Huang09b73ea2020-01-08 17:52:05 +08001008 static std::string openolt_version = firmware_version;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001009 for (int devid = 0; devid < BCM_MAX_DEVS_PER_LINE_CARD; devid++) {
1010 dev_key.device_id = devid;
1011 BCMOLT_CFG_INIT(&dev_cfg, device, dev_key);
1012 BCMOLT_MSG_FIELD_GET(&dev_cfg, firmware_sw_version);
1013 BCMOLT_MSG_FIELD_GET(&dev_cfg, chip_family);
1014 BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode);
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001015 err = bcmolt_cfg_get_mult_retry(dev_id, &dev_cfg.hdr);
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001016 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05001017 OPENOLT_LOG(WARNING, openolt_log_id,"Failed to query PON MAC Device %d (errno = %s). Skipping the device.\n", devid, bcmos_strerror(err));
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001018 num_failed_cfg_gets++;
1019 continue;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001020 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001021
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001022 std::string bal_version;
1023 bal_version += std::to_string(dev_cfg.data.firmware_sw_version.major)
1024 + "." + std::to_string(dev_cfg.data.firmware_sw_version.minor)
1025 + "." + std::to_string(dev_cfg.data.firmware_sw_version.revision);
Jason Huang09b73ea2020-01-08 17:52:05 +08001026 firmware_version = "BAL." + bal_version + "__" + openolt_version;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001027
1028 switch(dev_cfg.data.system_mode) {
1029 case 10: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*4,(devid+1)*4,"GPON"); break;
1030 case 11: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*8,(devid+1)*8,"GPON"); break;
1031 case 12: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"GPON"); break;
1032 case 13: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,"XGPON"); break;
1033 case 14: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*4,(devid+1)*4,"XGPON"); break;
1034 case 15: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*8,(devid+1)*8,"XGPON"); break;
1035 case 16: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"XGPON"); break;
1036 case 18: board_technology = "XGS-PON"; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,"XGS-PON"); break;
1037 case 19: board_technology = "XGS-PON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"XGS-PON"); break;
1038 case 20: board_technology = MIXED_TECH; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,MIXED_TECH); break;
1039 }
1040
1041 switch(dev_cfg.data.chip_family) {
Jason Huang09b73ea2020-01-08 17:52:05 +08001042 case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6862_X: chip_family = "Maple"; break;
1043 case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6865_X: chip_family = "Aspen"; break;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001044 }
1045
Jason Huang09b73ea2020-01-08 17:52:05 +08001046 OPENOLT_LOG(INFO, openolt_log_id, "device %d, pon: %d, version %s, family: %s, board_technology: %s\n",
1047 devid, BCM_MAX_PONS_PER_DEV, bal_version.c_str(), chip_family.c_str(), board_technology.c_str());
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001048
1049 bcmos_usleep(500000);
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001050 }
1051
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001052 /* If all the devices returned errors then we tell the caller that this is an error else we work with
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001053 only the devices that retured success*/
1054 if (num_failed_cfg_gets == BCM_MAX_DEVS_PER_LINE_CARD) {
1055 OPENOLT_LOG(ERROR, openolt_log_id, "device: Query of all the devices failed\n");
1056 return bcm_to_grpc_err(err, "device: All devices failed query");
1057 }
1058
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001059 return Status::OK;
1060}
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -04001061
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001062Status SetStateUplinkIf_(uint32_t intf_id, bool set_state) {
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001063 bcmos_errno err = BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001064 bcmolt_nni_interface_key intf_key = {.id = (bcmolt_interface)intf_id};
1065 bcmolt_nni_interface_set_nni_state nni_interface_set_state;
1066 bcmolt_interface_state state;
Craig Lutgend0bae9b2018-10-18 18:02:07 -05001067
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001068 err = get_nni_interface_status((bcmolt_interface)intf_id, &state);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001069 if (err == BCM_ERR_OK) {
1070 if (set_state && state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) {
Jason Huangbf45ffb2019-10-30 17:29:02 +08001071 OPENOLT_LOG(WARNING, openolt_log_id, "NNI interface: %d already enabled\n", intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001072 OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id);
1073 CreateDefaultSched(intf_id, upstream);
1074 CreateDefaultQueue(intf_id, upstream);
1075 return Status::OK;
1076 } else if (!set_state && state == BCMOLT_INTERFACE_STATE_INACTIVE) {
1077 OPENOLT_LOG(INFO, openolt_log_id, "NNI interface: %d already disabled\n", intf_id);
1078 return Status::OK;
1079 }
Craig Lutgend0bae9b2018-10-18 18:02:07 -05001080 }
1081
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001082 BCMOLT_OPER_INIT(&nni_interface_set_state, nni_interface, set_nni_state, intf_key);
1083 if (set_state) {
1084 BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data,
1085 nni_state, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING);
1086 } else {
1087 BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data,
1088 nni_state, BCMOLT_INTERFACE_OPERATION_INACTIVE);
1089 }
1090 err = bcmolt_oper_submit(dev_id, &nni_interface_set_state.hdr);
1091 if (err != BCM_ERR_OK) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05001092 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to %s NNI interface: %d, err = %s\n",
1093 (set_state)?"enable":"disable", intf_id, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001094 return bcm_to_grpc_err(err, "Failed to enable NNI interface");
1095 }
1096 else {
1097 OPENOLT_LOG(INFO, openolt_log_id, "Successfully %s NNI interface: %d\n", (set_state)?"enable":"disable", intf_id);
1098 if (set_state) {
1099 OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id);
1100 CreateDefaultSched(intf_id, upstream);
1101 CreateDefaultQueue(intf_id, upstream);
1102 }
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -04001103 }
1104
1105 return Status::OK;
1106}
1107
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001108Status DisablePonIf_(uint32_t intf_id) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -05001109 bcmos_errno err;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001110 bcmolt_pon_interface_cfg interface_obj;
Chaitrashree G S73e084d2019-11-20 16:18:59 -05001111 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id};
1112 bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state;
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001113
Chaitrashree G S73e084d2019-11-20 16:18:59 -05001114 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
Girish Gowdrae1db2952021-05-04 00:16:54 -07001115 BCMOLT_MSG_FIELD_GET(&interface_obj, state);
1116
1117 err = bcmolt_cfg_get(dev_id, &interface_obj.hdr);
1118 if (err != BCM_ERR_OK) {
1119 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch pon port status, PON interface %d, err %d err_text=%s \n", intf_id, err, interface_obj.hdr.hdr.err_text);
1120 return bcm_to_grpc_err(err, "Failed to fetch pon port state");
1121 }
1122 if (interface_obj.data.state == BCMOLT_INTERFACE_STATE_INACTIVE) {
1123 OPENOLT_LOG(INFO, openolt_log_id, "PON Interface already inactive, PON interface %d\n", intf_id);
1124 return Status::OK;
1125 }
1126
1127 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
Chaitrashree G S73e084d2019-11-20 16:18:59 -05001128 BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key);
1129 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_DISABLE);
1130
1131 err = bcmolt_cfg_set(dev_id, &interface_obj.hdr);
1132 if (err != BCM_ERR_OK) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07001133 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable discovery of onu, PON interface %d, err = %s (%d(\n", intf_id, interface_obj.hdr.hdr.err_text, err);
Chaitrashree G S73e084d2019-11-20 16:18:59 -05001134 return bcm_to_grpc_err(err, "Failed to disable discovery of onu");
1135 }
1136
1137 BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data,
1138 operation, BCMOLT_INTERFACE_OPERATION_INACTIVE);
1139
1140 err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr);
1141 if (err != BCM_ERR_OK) {
1142 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n , err %d\n", intf_id, err);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001143 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001144 }
1145
Chaitrashree G S73e084d2019-11-20 16:18:59 -05001146 OPENOLT_LOG(INFO, openolt_log_id, "Successfully disabled PON interface: %d\n", intf_id);
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001147 return Status::OK;
1148}
1149
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001150Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
kesavandc1f2db92020-08-31 15:32:06 +05301151 const char *vendor_id, const char *vendor_specific, uint32_t pir, bool omcc_encryption_mode) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001152 bcmos_errno err = BCM_ERR_OK;
1153 bcmolt_onu_cfg onu_cfg;
1154 bcmolt_onu_key onu_key;
1155 bcmolt_serial_number serial_number; /**< ONU serial number */
1156 bcmolt_bin_str_36 registration_id; /**< ONU registration ID */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001157
Girish Gowdra24297032020-03-23 12:32:37 -07001158 bcmolt_onu_set_onu_state onu_oper; /* declare main API struct */
1159 bcmolt_onu_state onu_state;
1160
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001161 onu_key.onu_id = onu_id;
1162 onu_key.pon_ni = intf_id;
1163 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1164 BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
Girish Gowdra24297032020-03-23 12:32:37 -07001165#ifdef TEST_MODE
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001166 // It is impossible to mock the setting of onu_cfg.data.onu_state because
1167 // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot
1168 // set the onu_cfg.data.onu_state. So a new stub function is created and address
1169 // of onu_cfg is passed. This is one-of case where we need to add test specific
1170 // code in production code.
1171 err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg);
Girish Gowdra24297032020-03-23 12:32:37 -07001172#else
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001173 err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
Girish Gowdra24297032020-03-23 12:32:37 -07001174#endif
1175 OPENOLT_LOG(INFO, openolt_log_id, "Activate ONU : old state = %d, current state = %d\n",
1176 onu_cfg.data.onu_old_state, onu_cfg.data.onu_state);
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001177 if (err == BCM_ERR_OK) {
Girish Gowdra24297032020-03-23 12:32:37 -07001178 if (onu_cfg.data.onu_state == BCMOLT_ONU_STATE_ACTIVE) {
1179 OPENOLT_LOG(INFO, openolt_log_id, "ONU is already in ACTIVE state, \
1180not processing this request for pon_intf=%d onu_id=%d\n", intf_id, onu_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001181 return Status::OK;
Girish Gowdra24297032020-03-23 12:32:37 -07001182 } else if (onu_cfg.data.onu_state != BCMOLT_ONU_STATE_NOT_CONFIGURED &&
1183 onu_cfg.data.onu_state != BCMOLT_ONU_STATE_INACTIVE) {
1184 // We need the ONU to be in NOT_CONFIGURED or INACTIVE state to further process the request
1185 OPENOLT_LOG(ERROR, openolt_log_id, "ONU in an invalid state to process the request, \
1186state=%d pon_intf=%d onu_id=%d\n", onu_cfg.data.onu_state, intf_id, onu_id);
1187 return bcm_to_grpc_err(err, "Failed to activate ONU, invalid ONU state");
1188 }
1189 } else {
1190 // This should never happen. BAL GET should succeed for non-existant ONUs too. The state of such ONUs will be NOT_CONFIGURED
1191 OPENOLT_LOG(ERROR, openolt_log_id, "ONU state query failed pon_intf=%d onu_id=%d\n", intf_id, onu_id);
1192 return bcm_to_grpc_err(err, "onu get failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001193 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001194
Girish Gowdra24297032020-03-23 12:32:37 -07001195 // If the ONU is not configured at all we need to first configure it
1196 if (onu_cfg.data.onu_state == BCMOLT_ONU_STATE_NOT_CONFIGURED) {
1197 OPENOLT_LOG(INFO, openolt_log_id, "Configuring ONU %d on PON %d : vendor id %s, \
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001198vendor specific %s, pir %d\n", onu_id, intf_id, vendor_id,
Girish Gowdra24297032020-03-23 12:32:37 -07001199 vendor_specific_to_str(vendor_specific).c_str(), pir);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001200
Girish Gowdra24297032020-03-23 12:32:37 -07001201 memcpy(serial_number.vendor_id.arr, vendor_id, 4);
1202 memcpy(serial_number.vendor_specific.arr, vendor_specific, 4);
1203 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1204 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.serial_number, serial_number);
1205 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.auto_learning, BCMOS_TRUE);
1206 /*set burst and data profiles to fec disabled*/
1207 if (board_technology == "XGS-PON") {
1208 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.ranging_burst_profile, 2);
1209 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.data_burst_profile, 1);
1210 } else if (board_technology == "GPON") {
1211 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.gpon.ds_ber_reporting_interval, 1000000);
1212 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.gpon.omci_port_id, onu_id);
1213 }
1214 err = bcmolt_cfg_set(dev_id, &onu_cfg.hdr);
1215 if (err != BCM_ERR_OK) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07001216 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to configure ONU %d on PON %d, err = %s (%d)\n", onu_id, intf_id, onu_cfg.hdr.hdr.err_text, err);
Girish Gowdra24297032020-03-23 12:32:37 -07001217 return bcm_to_grpc_err(err, "Failed to configure ONU");
1218 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001219 }
Girish Gowdra252f4972020-09-07 21:24:01 -07001220
Burak Gurdaga0523592021-02-24 15:17:47 +00001221// TODO: MOVE THIS TO A NEW METHOD
kesavandc1f2db92020-08-31 15:32:06 +05301222 if (omcc_encryption_mode == true) {
1223 // set the encryption mode for omci port id
1224 bcmolt_itupon_gem_cfg gem_cfg;
1225 bcmolt_itupon_gem_key key = {};
1226 bcmolt_gem_port_configuration configuration = {};
1227 key.pon_ni = intf_id;
1228 key.gem_port_id = onu_id;
1229 bcmolt_control_state encryption_mode;
1230 encryption_mode = BCMOLT_CONTROL_STATE_ENABLE;
1231 BCMOLT_CFG_INIT(&gem_cfg, itupon_gem, key);
1232 BCMOLT_FIELD_SET(&gem_cfg.data, itupon_gem_cfg_data, encryption_mode, encryption_mode);
1233 err = bcmolt_cfg_set(dev_id, &gem_cfg.hdr);
1234 if(err != BCM_ERR_OK) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07001235 OPENOLT_LOG(ERROR, openolt_log_id, "failed to configure omci gem_port encryption mode = %d, err = %s (%d)\n", onu_id, gem_cfg.hdr.hdr.err_text, err);
kesavandc1f2db92020-08-31 15:32:06 +05301236 return bcm_to_grpc_err(err, "Access_Control set ITU PON OMCI Gem port failed");
1237 }
1238 }
Girish Gowdra24297032020-03-23 12:32:37 -07001239 // Now that the ONU is configured, move the ONU to ACTIVE state
1240 memset(&onu_cfg, 0, sizeof(bcmolt_onu_cfg));
1241 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1242 BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
1243 BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key);
1244 BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data,
1245 onu_state, BCMOLT_ONU_OPERATION_ACTIVE);
1246 err = bcmolt_oper_submit(dev_id, &onu_oper.hdr);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001247 if (err != BCM_ERR_OK) {
Girish Gowdra24297032020-03-23 12:32:37 -07001248 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 Subramani89fffc02019-05-13 21:33:20 +00001249 return bcm_to_grpc_err(err, "Failed to activate ONU");
1250 }
Girish Gowdra24297032020-03-23 12:32:37 -07001251 // ONU will eventually get activated after we have submitted the operation request. The adapter will receive an asynchronous
1252 // ONU_ACTIVATION_COMPLETED_INDICATION
1253
1254 OPENOLT_LOG(INFO, openolt_log_id, "Activated ONU, onu_id %d on PON %d\n", onu_id, intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001255
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001256 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001257}
1258
Jonathan Davis70c21812018-07-19 15:32:10 -04001259Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
1260 const char *vendor_id, const char *vendor_specific) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001261 bcmos_errno err = BCM_ERR_OK;
1262 bcmolt_onu_set_onu_state onu_oper; /* declare main API struct */
1263 bcmolt_onu_cfg onu_cfg;
1264 bcmolt_onu_key onu_key; /**< Object key. */
1265 bcmolt_onu_state onu_state;
Jonathan Davis70c21812018-07-19 15:32:10 -04001266
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001267 onu_key.onu_id = onu_id;
1268 onu_key.pon_ni = intf_id;
1269 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1270 BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
1271 err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301272 onu_state = onu_cfg.data.onu_state;
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001273 if (err == BCM_ERR_OK) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001274 switch (onu_state) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001275 case BCMOLT_ONU_STATE_ACTIVE:
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001276 BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key);
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001277 BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data,
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001278 onu_state, BCMOLT_ONU_OPERATION_INACTIVE);
1279 err = bcmolt_oper_submit(dev_id, &onu_oper.hdr);
1280 if (err != BCM_ERR_OK) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05001281 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 Subramani89fffc02019-05-13 21:33:20 +00001282 return bcm_to_grpc_err(err, "Failed to deactivate ONU");
1283 }
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301284 OPENOLT_LOG(INFO, openolt_log_id, "Deactivated ONU, onu_id %d on PON %d\n", onu_id, intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001285 break;
1286 }
Girish Gowdra72cbee92021-11-05 15:16:18 -07001287 } else {
1288 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to deactivate ONU %d on PON %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
1289 return bcm_to_grpc_err(err, "Failed to get onu config");
Jonathan Davis70c21812018-07-19 15:32:10 -04001290 }
1291
1292 return Status::OK;
1293}
1294
1295Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001296 const char *vendor_id, const char *vendor_specific) {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301297 bcmos_errno err = BCM_ERR_OK;
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301298 bcmolt_onu_state onu_state;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001299 Status st;
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001300
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001301 OPENOLT_LOG(INFO, openolt_log_id, "DeleteOnu ONU %d on PON %d : vendor id %s, vendor specific %s\n",
Craig Lutgend0bae9b2018-10-18 18:02:07 -05001302 onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str());
1303
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001304 // Need to deactivate before removing it (BAL rules)
Girish Gowdra72cbee92021-11-05 15:16:18 -07001305 st = DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
1306 if (st.error_code() != grpc::StatusCode::OK) {
1307 return st;
1308 }
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301309
Girish Gowdra72cbee92021-11-05 15:16:18 -07001310 err = get_onu_state((bcmolt_interface)intf_id, onu_id, &onu_state);
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301311 if (err == BCM_ERR_OK) {
Girish Gowdra24297032020-03-23 12:32:37 -07001312 if (onu_state != BCMOLT_ONU_STATE_INACTIVE) {
1313 OPENOLT_LOG(INFO, openolt_log_id, "waiting for onu deactivate complete response: intf_id=%d, onu_id=%d\n",
1314 intf_id, onu_id);
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301315 err = wait_for_onu_deactivate_complete(intf_id, onu_id);
1316 if (err) {
1317 OPENOLT_LOG(ERROR, openolt_log_id, "failed to delete onu intf_id %d, onu_id %d\n",
1318 intf_id, onu_id);
1319 return bcm_to_grpc_err(err, "Failed to delete ONU");
1320 }
1321 }
Girish Gowdra24297032020-03-23 12:32:37 -07001322 else {
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301323 OPENOLT_LOG(INFO, openolt_log_id, "Onu is Inactive, onu_id: %d, not waiting for onu deactivate complete response\n",
1324 intf_id);
1325 }
1326 }
1327 else {
1328 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch Onu status, onu_id = %d, intf_id = %d, err = %s\n",
1329 onu_id, intf_id, bcmos_strerror(err));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301330 return bcm_to_grpc_err(err, "Failed to delete ONU");
1331 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001332
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001333 bcmolt_onu_cfg cfg_obj;
1334 bcmolt_onu_key key;
Jonathan Davis70c21812018-07-19 15:32:10 -04001335
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001336 OPENOLT_LOG(INFO, openolt_log_id, "Processing onu cfg clear for onu_id %d and intf_id %d\n",
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001337 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -04001338
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001339 key.onu_id = onu_id;
1340 key.pon_ni = intf_id;
1341 BCMOLT_CFG_INIT(&cfg_obj, onu, key);
Jonathan Davis70c21812018-07-19 15:32:10 -04001342
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301343 err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr);
Jonathan Davis70c21812018-07-19 15:32:10 -04001344 if (err != BCM_ERR_OK)
1345 {
Girish Gowdra72cbee92021-11-05 15:16:18 -07001346 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL onu_id %d, Interface ID %d, err = %s (%d)\n", onu_id, intf_id, cfg_obj.hdr.hdr.err_text, err);
Jonathan Davis70c21812018-07-19 15:32:10 -04001347 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
1348 }
1349
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301350 OPENOLT_LOG(INFO, openolt_log_id, "Deleted ONU, onu_id %d on PON %d\n", onu_id, intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001351 return Status::OK;
Jonathan Davis70c21812018-07-19 15:32:10 -04001352}
1353
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001354#define MAX_CHAR_LENGTH 20
1355#define MAX_OMCI_MSG_LENGTH 44
1356Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001357 bcmolt_bin_str buf = {};
1358 bcmolt_onu_cpu_packets omci_cpu_packets;
1359 bcmolt_onu_key key;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001360
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001361 key.pon_ni = intf_id;
1362 key.onu_id = onu_id;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001363
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001364 BCMOLT_OPER_INIT(&omci_cpu_packets, onu, cpu_packets, key);
1365 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_OMCI);
1366 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, calc_crc, BCMOS_TRUE);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001367
1368 // ???
1369 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
1370 buf.len = MAX_OMCI_MSG_LENGTH;
1371 } else {
1372 buf.len = pkt.size()/2;
1373 }
1374
1375 /* Send the OMCI packet using the BAL remote proxy API */
1376 uint16_t idx1 = 0;
1377 uint16_t idx2 = 0;
1378 uint8_t arraySend[buf.len];
1379 char str1[MAX_CHAR_LENGTH];
1380 char str2[MAX_CHAR_LENGTH];
1381 memset(&arraySend, 0, buf.len);
1382
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001383 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
1384 sprintf(str1,"%c", pkt[idx1]);
1385 sprintf(str2,"%c", pkt[++idx1]);
1386 strcat(str1,str2);
1387 arraySend[idx2] = strtol(str1, NULL, 16);
1388 }
1389
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001390 buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
1391 memcpy(buf.arr, (uint8_t *)arraySend, buf.len);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001392
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001393 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, number_of_packets, 1);
1394 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_size, buf.len);
1395 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, buffer, buf);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001396
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001397 bcmos_errno err = bcmolt_oper_submit(dev_id, &omci_cpu_packets.hdr);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001398 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05001399 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 Subramani89fffc02019-05-13 21:33:20 +00001400 return bcm_to_grpc_err(err, "send OMCI failed");
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001401 } else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001402 OPENOLT_LOG(DEBUG, omci_log_id, "OMCI request msg of length %d sent to ONU %d on PON %d : %s\n",
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001403 buf.len, onu_id, intf_id, pkt.c_str());
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001404 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001405 free(buf.arr);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001406
1407 return Status::OK;
1408}
1409
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001410Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, uint32_t port_no, uint32_t gemport_id, const std::string pkt) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001411 bcmolt_pon_interface_cpu_packets pon_interface_cpu_packets; /**< declare main API struct */
1412 bcmolt_pon_interface_key key = {.pon_ni = (bcmolt_interface)intf_id}; /**< declare key */
1413 bcmolt_bin_str buf = {};
1414 bcmolt_gem_port_id gem_port_id_array[1];
1415 bcmolt_gem_port_id_list_u8_max_16 gem_port_list = {};
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001416
Craig Lutgen967a1d02018-11-27 10:41:51 -06001417 if (port_no > 0) {
1418 bool found = false;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001419 if (gemport_id == 0) {
1420 bcmos_fastlock_lock(&data_lock);
1421 // Map the port_no to one of the flows that owns it to find a gemport_id for that flow.
1422 // Pick any flow that is mapped with the same port_no.
1423 std::map<uint32_t, std::set<uint32_t> >::const_iterator it = port_to_flows.find(port_no);
1424 if (it != port_to_flows.end() && !it->second.empty()) {
1425 uint32_t flow_id = *(it->second.begin()); // Pick any flow_id out of the bag set
1426 std::map<uint32_t, uint32_t>::const_iterator fit = flowid_to_gemport.find(flow_id);
1427 if (fit != flowid_to_gemport.end()) {
1428 found = true;
1429 gemport_id = fit->second;
1430 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001431 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001432 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001433
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001434 if (!found) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001435 OPENOLT_LOG(ERROR, openolt_log_id, "Packet out failed to find destination for ONU %d port_no %u on PON %d\n",
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001436 onu_id, port_no, intf_id);
1437 return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow for port_no");
1438 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001439 OPENOLT_LOG(INFO, openolt_log_id, "Gem port %u found for ONU %d port_no %u on PON %d\n",
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001440 gemport_id, onu_id, port_no, intf_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001441 }
1442
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001443 gem_port_id_array[0] = gemport_id;
1444 gem_port_list.len = 1;
1445 gem_port_list.arr = gem_port_id_array;
1446 buf.len = pkt.size();
1447 buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
1448 memcpy(buf.arr, (uint8_t *)pkt.data(), buf.len);
1449
1450 /* init the API struct */
1451 BCMOLT_OPER_INIT(&pon_interface_cpu_packets, pon_interface, cpu_packets, key);
1452 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_ETH);
1453 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, calc_crc, BCMOS_TRUE);
1454 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, gem_port_list, gem_port_list);
1455 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, buffer, buf);
1456
1457 OPENOLT_LOG(INFO, openolt_log_id, "Packet out of length %d sent to gemport %d on pon %d port_no %u\n",
1458 (uint8_t)pkt.size(), gemport_id, intf_id, port_no);
1459
1460 /* call API */
1461 bcmolt_oper_submit(dev_id, &pon_interface_cpu_packets.hdr);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001462 }
1463 else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001464 //TODO: Port No is 0, it is coming sender requirement.
1465 OPENOLT_LOG(INFO, openolt_log_id, "port_no %d onu %d on pon %d\n",
1466 port_no, onu_id, intf_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001467 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001468 free(buf.arr);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001469
1470 return Status::OK;
1471}
1472
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001473Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001474 bcmolt_flow_key key = {}; /* declare key */
1475 bcmolt_bin_str buffer = {};
1476 bcmolt_flow_send_eth_packet oper; /* declare main API struct */
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001477
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001478 // TODO: flow_id is currently not passed in UplinkPacket message from voltha.
Girish Gowdra252f4972020-09-07 21:24:01 -07001479 bcmolt_flow_id flow_id = INVALID_FLOW_ID;
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001480
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001481 //validate flow_id and find flow_id/flow type: upstream/ingress type: PON/egress type: NNI
1482 if (get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, FLOW_TYPE) == BCMOLT_FLOW_TYPE_UPSTREAM && \
1483 get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, INGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_PON && \
1484 get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, EGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_NNI)
1485 key.flow_id = flow_id;
1486 else {
Jason Huang09b73ea2020-01-08 17:52:05 +08001487 if (flow_id_counters) {
1488 std::map<flow_pair, int>::iterator it;
1489 for(it = flow_map.begin(); it != flow_map.end(); it++) {
1490 int flow_index = it->first.first;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001491 if (get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, FLOW_TYPE) == BCMOLT_FLOW_TYPE_UPSTREAM && \
1492 get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, INGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_PON && \
1493 get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, EGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_NNI) {
1494 key.flow_id = flow_index;
1495 break;
1496 }
1497 }
1498 }
1499 else {
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001500 OPENOLT_LOG(ERROR, openolt_log_id, "no flow id found for uplink packetout\n");
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001501 return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow id found");
1502 }
1503 }
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001504
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001505 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; /* send from uplink direction */
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001506
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001507 /* Initialize the API struct. */
1508 BCMOLT_OPER_INIT(&oper, flow, send_eth_packet, key);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001509
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001510 buffer.len = pkt.size();
1511 buffer.arr = (uint8_t *)malloc((buffer.len)*sizeof(uint8_t));
1512 memcpy(buffer.arr, (uint8_t *)pkt.data(), buffer.len);
1513 if (buffer.arr == NULL) {
1514 OPENOLT_LOG(ERROR, openolt_log_id, "allocate packet buffer failed\n");
1515 return bcm_to_grpc_err(BCM_ERR_PARM, "allocate packet buffer failed");
1516 }
1517 BCMOLT_FIELD_SET(&oper.data, flow_send_eth_packet_data, buffer, buffer);
1518
1519 bcmos_errno err = bcmolt_oper_submit(dev_id, &oper.hdr);
1520 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05001521 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 Subramani81c56112019-12-19 08:29:55 -05001522 return bcm_to_grpc_err(BCM_ERR_SYSCALL_ERR, "Error sending packets via nni port");
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001523 } else {
1524 OPENOLT_LOG(INFO, openolt_log_id, "sent packets to port %d in upstream direction, flow_id %d \n", intf_id, key.flow_id);
1525 }
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001526
1527 return Status::OK;
1528}
Girish Gowdra252f4972020-09-07 21:24:01 -07001529
Burak Gurdaga0523592021-02-24 15:17:47 +00001530bool get_aes_flag_for_gem_port(const google::protobuf::Map<unsigned int, bool> &gemport_to_aes, uint32_t gemport_id) {
1531 bool aes_flag = false;
1532 for (google::protobuf::Map<unsigned int, bool>::const_iterator it=gemport_to_aes.begin(); it!=gemport_to_aes.end(); it++) {
1533 if (it->first == gemport_id) {
1534 aes_flag = it->second;
1535 break;
1536 }
1537 }
1538 return aes_flag;
1539}
1540
Girish Gowdra252f4972020-09-07 21:24:01 -07001541Status FlowAddWrapper_(const ::openolt::Flow* request) {
1542
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001543 Status st = Status::OK;
Girish Gowdra252f4972020-09-07 21:24:01 -07001544 int32_t access_intf_id = request->access_intf_id();
1545 int32_t onu_id = request->onu_id();
1546 int32_t uni_id = request->uni_id();
1547 uint32_t port_no = request->port_no();
1548 uint64_t voltha_flow_id = request->flow_id();
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001549 uint64_t symmetric_voltha_flow_id = 0;
Girish Gowdra252f4972020-09-07 21:24:01 -07001550 const std::string flow_type = request->flow_type();
1551 int32_t alloc_id = request->alloc_id();
1552 int32_t network_intf_id = request->network_intf_id();
1553 int32_t gemport_id = request->gemport_id();
1554 const ::openolt::Classifier& classifier = request->classifier();
1555 const ::openolt::Action& action = request->action();
1556 int32_t priority = request->priority();
1557 uint64_t cookie = request->cookie();
1558 int32_t group_id = request->group_id();
1559 uint32_t tech_profile_id = request->tech_profile_id();
1560 bool replicate_flow = request->replicate_flow();
1561 const google::protobuf::Map<unsigned int, unsigned int> &pbit_to_gemport = request->pbit_to_gemport();
Burak Gurdaga0523592021-02-24 15:17:47 +00001562 const google::protobuf::Map<unsigned int, bool> &gemport_to_aes = request->gemport_to_aes();
Girish Gowdra252f4972020-09-07 21:24:01 -07001563 uint16_t flow_id;
Burak Gurdaga0523592021-02-24 15:17:47 +00001564 bool enable_encryption;
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001565 // When following conditions are ALL met, it qualifies as datapath flow.
1566 // 1. valid access_intf_id, onu_id, uni_id
1567 // 2. Valid tech_profile_id
1568 // 3. flow_type that is not MULTICAST
1569 // 4. Not a trap-to-host flow.
1570 bool datapathFlow = access_intf_id >= 0 && onu_id >= 0 && uni_id >= 0 && tech_profile_id > 0
1571 && flow_type != multicast && !action.cmd().trap_to_host();
1572
1573 if (datapathFlow) {
1574 const std::string inverse_flow_type = flow_type.compare(upstream) == 0 ? downstream : upstream;
1575 symmetric_datapath_flow_id_map_key key(access_intf_id, onu_id, uni_id, tech_profile_id, inverse_flow_type);
1576 // Find the onu-uni mapping for the pon-gem key
1577 bcmos_fastlock_lock(&symmetric_datapath_flow_id_lock);
1578 auto it = symmetric_datapath_flow_id_map.find(key);
1579 bcmos_fastlock_unlock(&symmetric_datapath_flow_id_lock, 0);
1580 if (it != symmetric_datapath_flow_id_map.end()) {
1581 symmetric_voltha_flow_id = it->second;
1582 }
1583 }
Girish Gowdra252f4972020-09-07 21:24:01 -07001584
1585 // The intf_id variable defaults to access(PON) interface ID.
1586 // For trap-from-nni flow where access interface ID is not valid , change it to NNI interface ID
1587 // This intf_id identifies the pool from which we get the flow_id
1588 uint32_t intf_id = access_intf_id;
1589 if (onu_id < 1) {
1590 onu_id = 1;
1591 }
1592 if (access_intf_id < 0) {
1593 intf_id = network_intf_id;
1594 }
1595
1596 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)
1597 // This is the case of voltha_flow_id (not symmetric_voltha_flow_id)
1598 if (is_voltha_flow_installed(voltha_flow_id)) {
1599 OPENOLT_LOG(INFO, openolt_log_id, "voltha_flow_id=%lu, already installed\n", voltha_flow_id);
1600 return ::Status(grpc::StatusCode::ALREADY_EXISTS, "voltha-flow-already-installed");
1601 }
1602
Girish Gowdra252f4972020-09-07 21:24:01 -07001603 // This is the case of symmetric_voltha_flow_id
1604 // If symmetric_voltha_flow_id is available and valid in the Flow message,
1605 // check if it is installed, and use the corresponding device_flow_id
1606 if (symmetric_voltha_flow_id > 0 && is_voltha_flow_installed(symmetric_voltha_flow_id)) { // symmetric flow found
1607 OPENOLT_LOG(INFO, openolt_log_id, "symmetric flow and the symmetric flow is installed\n");
1608 const device_flow_params *dev_fl_symm_params;
1609 dev_fl_symm_params = get_device_flow_params(symmetric_voltha_flow_id);
1610 if (dev_fl_symm_params == NULL) {
1611 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)
1612 return ::Status(grpc::StatusCode::INTERNAL, "symmetric-flow-details-not-found");
1613 }
1614
1615 if (!replicate_flow) { // No flow replication
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001616 flow_id = dev_fl_symm_params[0].flow_id;
1617 gemport_id = dev_fl_symm_params[0].gemport_id; // overwrite the gemport with symmetric flow gemport
1618 // Should be same as what is coming in this request.
1619 enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id);
1620 ::openolt::Classifier cl = ::openolt::Classifier(classifier);
1621 cl.set_o_pbits(dev_fl_symm_params[0].pbit);
1622 st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id,
1623 flow_type, alloc_id, network_intf_id, gemport_id, cl,
1624 action, priority, cookie, group_id, tech_profile_id, enable_encryption);
1625 if (st.error_code() != grpc::StatusCode::OK && st.error_code() != grpc::StatusCode::ALREADY_EXISTS) {
1626 OPENOLT_LOG(ERROR, openolt_log_id, "failed to install device flow=%u for voltha flow=%lu", flow_id, voltha_flow_id);
Girish Gowdra72cbee92021-11-05 15:16:18 -07001627 free_flow_id(flow_id);
Girish Gowdra252f4972020-09-07 21:24:01 -07001628 return st;
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001629 }
1630
1631 device_flow dev_fl;
1632 dev_fl.is_flow_replicated = false;
1633 dev_fl.symmetric_voltha_flow_id = symmetric_voltha_flow_id;
1634 dev_fl.voltha_flow_id = voltha_flow_id;
Girish Gowdra72bb4652022-01-18 17:04:30 -08001635 dev_fl.flow_type = flow_type;
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001636 memcpy(dev_fl.params, dev_fl_symm_params, sizeof(device_flow_params));
1637 // update voltha flow to cache
1638 update_voltha_flow_to_cache(voltha_flow_id, dev_fl);
Girish Gowdra252f4972020-09-07 21:24:01 -07001639 } else { // Flow to be replicated
1640 OPENOLT_LOG(INFO, openolt_log_id,"symmetric flow and replication is needed\n");
1641 for (uint8_t i=0; i<NUMBER_OF_REPLICATED_FLOWS; i++) {
1642 ::openolt::Classifier cl = ::openolt::Classifier(classifier);
1643 flow_id = dev_fl_symm_params[i].flow_id;
1644 gemport_id = dev_fl_symm_params[i].gemport_id;
Burak Gurdaga0523592021-02-24 15:17:47 +00001645 enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id);
Girish Gowdra252f4972020-09-07 21:24:01 -07001646 cl.set_o_pbits(dev_fl_symm_params[i].pbit);
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001647 st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id,
Girish Gowdrade65ab42020-12-17 23:08:43 -08001648 flow_type, alloc_id, network_intf_id, gemport_id, cl,
Burak Gurdaga0523592021-02-24 15:17:47 +00001649 action, priority, cookie, group_id, tech_profile_id, enable_encryption);
Girish Gowdra252f4972020-09-07 21:24:01 -07001650 if (st.error_code() != grpc::StatusCode::OK && st.error_code() != grpc::StatusCode::ALREADY_EXISTS) {
1651 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);
1652 // On failure remove any successfully replicated flows installed so far for the voltha_flow_id
1653 if (i > 0) {
1654 for (int8_t j = i-1; j >= 0; j--) {
1655 flow_id = dev_fl_symm_params[j].flow_id;
1656 FlowRemove_(flow_id, flow_type);
1657 }
1658 }
Girish Gowdra72cbee92021-11-05 15:16:18 -07001659 // Note: We should not free the flow_ids here because the symmetric flow is already using that flow id.
1660 // A call from voltha adapter should invoke a flow remove and then the flow ids would be freed in the process in this particular case
Girish Gowdra252f4972020-09-07 21:24:01 -07001661 return st;
1662 }
1663 }
1664 device_flow dev_fl;
1665 dev_fl.is_flow_replicated = true;
1666 dev_fl.symmetric_voltha_flow_id = symmetric_voltha_flow_id;
1667 dev_fl.voltha_flow_id = voltha_flow_id;
Girish Gowdra72bb4652022-01-18 17:04:30 -08001668 dev_fl.flow_type = flow_type;
Girish Gowdra252f4972020-09-07 21:24:01 -07001669 memcpy(dev_fl.params, dev_fl_symm_params, sizeof(device_flow_params)*NUMBER_OF_REPLICATED_FLOWS);
1670 // update voltha flow to cache
1671 update_voltha_flow_to_cache(voltha_flow_id, dev_fl);
1672 }
1673 } else { // No symmetric flow found
1674 if (!replicate_flow) { // No flow replication
1675 OPENOLT_LOG(INFO, openolt_log_id, "not a symmetric flow and replication is not needed\n");
1676 flow_id = get_flow_id();
1677 if (flow_id == INVALID_FLOW_ID) {
1678 OPENOLT_LOG(ERROR, openolt_log_id, "could not allocated flow id for voltha-flow-id=%lu\n", voltha_flow_id);
1679 return ::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "flow-ids-exhausted");
1680 }
Burak Gurdaga0523592021-02-24 15:17:47 +00001681 enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id);
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001682 st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id,
Girish Gowdra252f4972020-09-07 21:24:01 -07001683 flow_type, alloc_id, network_intf_id, gemport_id, classifier,
Burak Gurdaga0523592021-02-24 15:17:47 +00001684 action, priority, cookie, group_id, tech_profile_id, enable_encryption);
Girish Gowdra252f4972020-09-07 21:24:01 -07001685 if (st.error_code() == grpc::StatusCode::OK) {
1686 device_flow dev_fl;
1687 dev_fl.is_flow_replicated = false;
1688 dev_fl.symmetric_voltha_flow_id = INVALID_FLOW_ID; // Invalid
1689 dev_fl.voltha_flow_id = voltha_flow_id;
Girish Gowdra72bb4652022-01-18 17:04:30 -08001690 dev_fl.flow_type = flow_type;
Girish Gowdra252f4972020-09-07 21:24:01 -07001691 dev_fl.params[0].flow_id = flow_id;
1692 dev_fl.params[0].gemport_id = gemport_id;
1693 dev_fl.params[0].pbit = classifier.o_pbits();
1694 // update voltha flow to cache
1695 update_voltha_flow_to_cache(voltha_flow_id, dev_fl);
1696 } else {
1697 // Free the flow id on failure
1698 free_flow_id(flow_id);
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001699 return st;
Girish Gowdra252f4972020-09-07 21:24:01 -07001700 }
Girish Gowdra252f4972020-09-07 21:24:01 -07001701 } else { // Flow to be replicated
1702 OPENOLT_LOG(INFO, openolt_log_id,"not a symmetric flow and replication is needed\n");
1703 if (pbit_to_gemport.size() != NUMBER_OF_PBITS) {
1704 OPENOLT_LOG(ERROR, openolt_log_id, "invalid pbit-to-gemport map size=%lu", pbit_to_gemport.size())
1705 return ::Status(grpc::StatusCode::OUT_OF_RANGE, "pbit-to-gemport-map-len-invalid-for-flow-replication");
1706 }
1707 uint16_t flow_ids[NUMBER_OF_REPLICATED_FLOWS];
1708 device_flow dev_fl;
1709 if (get_flow_ids(NUMBER_OF_REPLICATED_FLOWS, flow_ids)) {
1710 uint8_t cnt = 0;
1711 dev_fl.is_flow_replicated = true;
1712 dev_fl.voltha_flow_id = voltha_flow_id;
1713 dev_fl.symmetric_voltha_flow_id = INVALID_FLOW_ID; // invalid
Girish Gowdra72bb4652022-01-18 17:04:30 -08001714 dev_fl.flow_type = flow_type;
Girish Gowdra252f4972020-09-07 21:24:01 -07001715 for (google::protobuf::Map<unsigned int, unsigned int>::const_iterator it=pbit_to_gemport.begin(); it!=pbit_to_gemport.end(); it++) {
1716 dev_fl.params[cnt].flow_id = flow_ids[cnt];
1717 dev_fl.params[cnt].pbit = it->first;
1718 dev_fl.params[cnt].gemport_id = it->second;
1719
1720 ::openolt::Classifier cl = ::openolt::Classifier(classifier);
1721 flow_id = dev_fl.params[cnt].flow_id;
1722 gemport_id = dev_fl.params[cnt].gemport_id;
Burak Gurdaga0523592021-02-24 15:17:47 +00001723 enable_encryption = get_aes_flag_for_gem_port(gemport_to_aes, gemport_id);
Girish Gowdra252f4972020-09-07 21:24:01 -07001724 cl.set_o_pbits(dev_fl.params[cnt].pbit);
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001725 st = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id,
Girish Gowdra252f4972020-09-07 21:24:01 -07001726 flow_type, alloc_id, network_intf_id, gemport_id, cl,
Burak Gurdaga0523592021-02-24 15:17:47 +00001727 action, priority, cookie, group_id, tech_profile_id, enable_encryption);
Girish Gowdra252f4972020-09-07 21:24:01 -07001728 if (st.error_code() != grpc::StatusCode::OK) {
1729 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);
1730 // Remove any successfully replicated flows installed so far for the voltha_flow_id
1731 if (cnt > 0) {
1732 for (int8_t j = cnt-1; j >= 0; j--) {
1733 flow_id = dev_fl.params[j].flow_id;
1734 FlowRemove_(flow_id, flow_type);
1735 }
1736 }
1737 // Free up all the flow IDs on failure
1738 free_flow_ids(NUMBER_OF_REPLICATED_FLOWS, flow_ids);
1739 return st;
1740 }
1741 cnt++;
1742 }
1743 // On successful flow replication update voltha-flow-id to device-flow map to cache
1744 update_voltha_flow_to_cache(voltha_flow_id, dev_fl);
1745 } else {
1746 OPENOLT_LOG(ERROR, openolt_log_id, "could not allocate flow ids for replication voltha-flow-id=%lu\n", voltha_flow_id);
1747 return ::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "flow-ids-exhausted");
1748 }
1749 }
1750 }
1751
Girish Gowdraeec0fc92021-05-12 15:37:55 -07001752 if (datapathFlow) {
1753 // Create the pon-gem to onu-uni mapping
1754 symmetric_datapath_flow_id_map_key key(access_intf_id, onu_id, uni_id, tech_profile_id, flow_type);
1755 bcmos_fastlock_lock(&symmetric_datapath_flow_id_lock);
1756 symmetric_datapath_flow_id_map[key] = voltha_flow_id;
1757 bcmos_fastlock_unlock(&symmetric_datapath_flow_id_lock, 0);
1758 }
1759
1760 return st;
Girish Gowdra252f4972020-09-07 21:24:01 -07001761}
1762
1763
Craig Lutgen967a1d02018-11-27 10:41:51 -06001764Status FlowAdd_(int32_t access_intf_id, int32_t onu_id, int32_t uni_id, uint32_t port_no,
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001765 uint32_t flow_id, const std::string flow_type,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001766 int32_t alloc_id, int32_t network_intf_id,
1767 int32_t gemport_id, const ::openolt::Classifier& classifier,
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001768 const ::openolt::Action& action, int32_t priority_value, uint64_t cookie,
Burak Gurdaga0523592021-02-24 15:17:47 +00001769 int32_t group_id, uint32_t tech_profile_id, bool aes_enabled) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001770 bcmolt_flow_cfg cfg;
1771 bcmolt_flow_key key = { }; /**< Object key. */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001772 int32_t o_vid = -1;
1773 bool single_tag = false;
1774 uint32_t ether_type = 0;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001775 bcmolt_classifier c_val = { };
1776 bcmolt_action a_val = { };
1777 bcmolt_tm_queue_ref tm_val = { };
1778 int tm_qmp_id, tm_q_set_id;
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05001779 bcmolt_egress_qos_type qos_type;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001780
Jason Huang09b73ea2020-01-08 17:52:05 +08001781 OPENOLT_LOG(INFO, openolt_log_id, "flow add received for flow_id=%u, flow_type=%s\n", flow_id, flow_type.c_str());
1782
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001783 key.flow_id = flow_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001784 if (flow_type.compare(upstream) == 0 ) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001785 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001786 } else if (flow_type.compare(downstream) == 0) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001787 key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001788 } else if (flow_type.compare(multicast) == 0) {
1789 key.flow_type = BCMOLT_FLOW_TYPE_MULTICAST;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001790 } else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001791 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001792 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001793 }
1794
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001795 BCMOLT_CFG_INIT(&cfg, flow, key);
1796 BCMOLT_MSG_FIELD_SET(&cfg, cookie, cookie);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001797
Jason Huang09b73ea2020-01-08 17:52:05 +08001798 if (action.cmd().trap_to_host()) {
Girish Gowdra1935e6a2020-10-31 21:48:22 -07001799 Status resp = handle_acl_rule_install(onu_id, flow_id, gemport_id, flow_type, access_intf_id,
Girish Gowdra252f4972020-09-07 21:24:01 -07001800 network_intf_id, classifier);
Jason Huang09b73ea2020-01-08 17:52:05 +08001801 return resp;
1802 }
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001803
1804 if (key.flow_type != BCMOLT_FLOW_TYPE_MULTICAST) {
1805
1806 if (access_intf_id >= 0 && network_intf_id >= 0) {
1807 if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) { //upstream
1808 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1809 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, access_intf_id);
Jason Huang09b73ea2020-01-08 17:52:05 +08001810 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI);
1811 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, network_intf_id);
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001812 } else if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { //downstream
1813 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI);
1814 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, network_intf_id);
1815 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1816 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001817 }
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001818 } else {
1819 OPENOLT_LOG(ERROR, openolt_log_id, "flow network setting invalid\n");
1820 return bcm_to_grpc_err(BCM_ERR_PARM, "flow network setting invalid");
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001821 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001822
Burak Gurdaga0523592021-02-24 15:17:47 +00001823 if (onu_id >= ONU_ID_START) {
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001824 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
1825 }
Burak Gurdaga0523592021-02-24 15:17:47 +00001826 if (gemport_id >= GEM_PORT_ID_START) {
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001827 BCMOLT_MSG_FIELD_SET(&cfg, svc_port_id, gemport_id);
1828 }
Burak Gurdaga0523592021-02-24 15:17:47 +00001829 if (gemport_id >= GEM_PORT_ID_START && port_no != 0) {
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001830 bcmos_fastlock_lock(&data_lock);
1831 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
1832 port_to_flows[port_no].insert(key.flow_id);
1833 flowid_to_gemport[key.flow_id] = gemport_id;
1834 }
1835 else
1836 {
1837 flowid_to_port[key.flow_id] = port_no;
1838 }
1839 bcmos_fastlock_unlock(&data_lock, 0);
1840 }
Girish Gowdra252f4972020-09-07 21:24:01 -07001841
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001842 if (priority_value >= 0) {
1843 BCMOLT_MSG_FIELD_SET(&cfg, priority, priority_value);
1844 }
Girish Gowdra80b0fb92019-11-15 11:40:39 +05301845
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001846 } else { // MULTICAST FLOW
1847 if (group_id >= 0) {
1848 BCMOLT_MSG_FIELD_SET(&cfg, group_id, group_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001849 }
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001850 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI);
1851 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, network_intf_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001852 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001853
1854 {
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001855 if (classifier.eth_type()) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001856 ether_type = classifier.eth_type();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001857 OPENOLT_LOG(DEBUG, openolt_log_id, "classify ether_type 0x%04x\n", classifier.eth_type());
1858 BCMOLT_FIELD_SET(&c_val, classifier, ether_type, classifier.eth_type());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001859 }
1860
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001861 if (classifier.dst_mac().size() > 0) {
1862 bcmos_mac_address d_mac = {};
1863 bcmos_mac_address_init(&d_mac);
1864 memcpy(d_mac.u8, classifier.dst_mac().data(), sizeof(d_mac.u8));
1865 OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_mac %02x:%02x:%02x:%02x:%02x:%02x\n", d_mac.u8[0],
1866 d_mac.u8[1], d_mac.u8[2], d_mac.u8[3], d_mac.u8[4], d_mac.u8[5]);
1867 BCMOLT_FIELD_SET(&c_val, classifier, dst_mac, d_mac);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001868 }
1869
Burak Gurdagc78b9e12019-11-29 11:14:51 +00001870 /*
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001871 if (classifier.src_mac()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001872 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_mac, classifier.src_mac());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001873 }
1874 */
1875
1876 if (classifier.ip_proto()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001877 OPENOLT_LOG(DEBUG, openolt_log_id, "classify ip_proto %d\n", classifier.ip_proto());
1878 BCMOLT_FIELD_SET(&c_val, classifier, ip_proto, classifier.ip_proto());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001879 }
1880
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001881 if (classifier.dst_ip()) {
Girish Gowdraf7feb4b2021-01-08 16:08:52 -08001882 bcmos_ipv4_address d_ip = {};
1883 bcmos_ipv4_address_init(&d_ip);
1884 d_ip.u32 = classifier.dst_ip();
1885 OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_ip %04x\n", d_ip.u32);
1886 BCMOLT_FIELD_SET(&c_val, classifier, dst_ip, d_ip);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001887 }
1888
Girish Gowdraf7feb4b2021-01-08 16:08:52 -08001889 /*
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001890 if (classifier.src_ip()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001891 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_ip, classifier.src_ip());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001892 }
1893 */
1894
1895 if (classifier.src_port()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001896 OPENOLT_LOG(DEBUG, openolt_log_id, "classify src_port %d\n", classifier.src_port());
1897 BCMOLT_FIELD_SET(&c_val, classifier, src_port, classifier.src_port());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001898 }
1899
1900 if (classifier.dst_port()) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001901 OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_port %d\n", classifier.dst_port());
1902 BCMOLT_FIELD_SET(&c_val, classifier, dst_port, classifier.dst_port());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001903 }
1904
1905 if (!classifier.pkt_tag_type().empty()) {
Jason Huang09b73ea2020-01-08 17:52:05 +08001906 if (classifier.o_vid()) {
1907 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_vid %d\n", classifier.o_vid());
1908 BCMOLT_FIELD_SET(&c_val, classifier, o_vid, classifier.o_vid());
1909 }
1910
1911 if (classifier.i_vid()) {
1912 OPENOLT_LOG(DEBUG, openolt_log_id, "classify i_vid %d\n", classifier.i_vid());
1913 BCMOLT_FIELD_SET(&c_val, classifier, i_vid, classifier.i_vid());
1914 }
1915
1916 OPENOLT_LOG(DEBUG, openolt_log_id, "classify tag_type %s\n", classifier.pkt_tag_type().c_str());
1917 if (classifier.pkt_tag_type().compare("untagged") == 0) {
1918 BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_UNTAGGED);
1919 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
1920 BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_SINGLE_TAG);
1921 single_tag = true;
1922
1923 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits());
Girish Gowdra7bcfaf62020-02-17 19:17:20 +05301924 // OpenOlt adapter will send 0xFF in case of no pbit classification
1925 // If it is any other value (0 to 7), it is for outer pbit classification.
1926 // OpenFlow protocol does not provide inner pbit classification (in case of double tagged packets),
1927 // and VOLTHA has not used any workaround to solve this problem (for ex: use metadata field).
1928 // Also there exists no use case for i-pbit classification, so we can safely ignore this for now.
1929 if(0xFF != classifier.o_pbits()){
Jason Huang09b73ea2020-01-08 17:52:05 +08001930 BCMOLT_FIELD_SET(&c_val, classifier, o_pbits, classifier.o_pbits());
Girish Gowdra80b0fb92019-11-15 11:40:39 +05301931 }
Jason Huang09b73ea2020-01-08 17:52:05 +08001932 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
1933 BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001934
Jason Huang09b73ea2020-01-08 17:52:05 +08001935 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits());
Girish Gowdra7bcfaf62020-02-17 19:17:20 +05301936 // Same comments as in case of "single_tag" packets.
1937 // 0xFF means no pbit classification, otherwise a valid PCP (0 to 7).
1938 if(0xFF != classifier.o_pbits()){
Jason Huang09b73ea2020-01-08 17:52:05 +08001939 BCMOLT_FIELD_SET(&c_val, classifier, o_pbits, classifier.o_pbits());
Girish Gowdra80b0fb92019-11-15 11:40:39 +05301940 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001941 }
1942 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001943 BCMOLT_MSG_FIELD_SET(&cfg, classifier, c_val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001944 }
1945
Jason Huang09b73ea2020-01-08 17:52:05 +08001946 const ::openolt::ActionCmd& cmd = action.cmd();
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001947
Jason Huang09b73ea2020-01-08 17:52:05 +08001948 if (cmd.add_outer_tag()) {
1949 OPENOLT_LOG(DEBUG, openolt_log_id, "action add o_tag\n");
1950 BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001951 }
1952
Jason Huang09b73ea2020-01-08 17:52:05 +08001953 if (cmd.remove_outer_tag()) {
1954 OPENOLT_LOG(DEBUG, openolt_log_id, "action pop o_tag\n");
1955 BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG);
1956 }
Girish Gowdraddf9a162020-01-27 12:56:27 +05301957
Jason Huang09b73ea2020-01-08 17:52:05 +08001958 if (action.o_vid()) {
1959 OPENOLT_LOG(DEBUG, openolt_log_id, "action o_vid=%d\n", action.o_vid());
1960 o_vid = action.o_vid();
1961 BCMOLT_FIELD_SET(&a_val, action, o_vid, action.o_vid());
1962 }
1963
1964 if (action.o_pbits()) {
1965 OPENOLT_LOG(DEBUG, openolt_log_id, "action o_pbits=0x%x\n", action.o_pbits());
1966 BCMOLT_FIELD_SET(&a_val, action, o_pbits, action.o_pbits());
1967 }
Girish Gowdraddf9a162020-01-27 12:56:27 +05301968
Jason Huang09b73ea2020-01-08 17:52:05 +08001969 if (action.i_vid()) {
1970 OPENOLT_LOG(DEBUG, openolt_log_id, "action i_vid=%d\n", action.i_vid());
1971 BCMOLT_FIELD_SET(&a_val, action, i_vid, action.i_vid());
1972 }
1973
1974 if (action.i_pbits()) {
1975 OPENOLT_LOG(DEBUG, openolt_log_id, "action i_pbits=0x%x\n", action.i_pbits());
1976 BCMOLT_FIELD_SET(&a_val, action, i_pbits, action.i_pbits());
1977 }
Girish Gowdraddf9a162020-01-27 12:56:27 +05301978
Jason Huang09b73ea2020-01-08 17:52:05 +08001979 BCMOLT_MSG_FIELD_SET(&cfg, action, a_val);
1980
Burak Gurdaga0523592021-02-24 15:17:47 +00001981 if ((access_intf_id >= 0) && (onu_id >= ONU_ID_START)) {
Jason Huang09b73ea2020-01-08 17:52:05 +08001982 qos_type = get_qos_type(access_intf_id, onu_id, uni_id);
1983 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001984 tm_val.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, downstream, tech_profile_id);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001985
Jason Huang09b73ea2020-01-08 17:52:05 +08001986 if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) {
1987 // Queue 0 on DS subscriber scheduler
1988 tm_val.queue_id = 0;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001989
Jason Huang09b73ea2020-01-08 17:52:05 +08001990 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type);
1991 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
1992 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001993
Jason Huang09b73ea2020-01-08 17:52:05 +08001994 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \
1995 downstream.c_str(), tm_val.queue_id, tm_val.sched_id, \
1996 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00001997
Jason Huang09b73ea2020-01-08 17:52:05 +08001998 } else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) {
1999 /* Fetch TM QMP ID mapped to DS subscriber scheduler */
2000 tm_qmp_id = tm_q_set_id = get_tm_qmp_id(tm_val.sched_id, access_intf_id, onu_id, uni_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002001
Jason Huang09b73ea2020-01-08 17:52:05 +08002002 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type);
2003 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
2004 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_qmp_id, tm_qmp_id);
2005 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_q_set_id, tm_q_set_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002006
Jason Huang09b73ea2020-01-08 17:52:05 +08002007 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, q_set_id = %d, sched_id = %d, intf_type %s\n", \
2008 downstream.c_str(), tm_q_set_id, tm_val.sched_id, \
2009 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
2010 }
2011 } else if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) {
2012 // NNI Scheduler ID
2013 tm_val.sched_id = get_default_tm_sched_id(network_intf_id, upstream);
2014 if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) {
2015 // Queue 0 on NNI scheduler
2016 tm_val.queue_id = 0;
2017 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type);
2018 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
2019 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002020
Jason Huang09b73ea2020-01-08 17:52:05 +08002021 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002022 upstream.c_str(), tm_val.queue_id, tm_val.sched_id, \
2023 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
2024
Jason Huang09b73ea2020-01-08 17:52:05 +08002025 } else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) {
2026 /* Fetch TM QMP ID mapped to US NNI scheduler */
2027 tm_qmp_id = tm_q_set_id = get_tm_qmp_id(tm_val.sched_id, access_intf_id, onu_id, uni_id);
2028 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type);
2029 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
2030 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_qmp_id, tm_qmp_id);
2031 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.priority_to_queue.tm_q_set_id, tm_q_set_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002032
Jason Huang09b73ea2020-01-08 17:52:05 +08002033 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, q_set_id = %d, sched_id = %d, intf_type %s\n", \
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002034 upstream.c_str(), tm_q_set_id, tm_val.sched_id, \
2035 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002036 }
Shad Ansari39739bc2018-09-13 21:38:37 +00002037 }
Girish Gowdra80b0fb92019-11-15 11:40:39 +05302038 } else {
2039 tm_val.sched_id = get_default_tm_sched_id(network_intf_id, upstream);
2040 tm_val.queue_id = 0;
2041
2042 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE);
2043 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
2044 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id);
2045
2046 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \
2047 flow_type.c_str(), tm_val.queue_id, tm_val.sched_id, \
2048 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
Shad Ansari06101952018-07-25 00:22:09 +00002049 }
2050
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002051 BCMOLT_MSG_FIELD_SET(&cfg, state, BCMOLT_FLOW_STATE_ENABLE);
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002052
Girish Gowdra252f4972020-09-07 21:24:01 -07002053#ifndef SCALE_AND_PERF
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002054 // BAL 3.1 supports statistics only for unicast flows.
2055 if (key.flow_type != BCMOLT_FLOW_TYPE_MULTICAST) {
2056 BCMOLT_MSG_FIELD_SET(&cfg, statistics, BCMOLT_CONTROL_STATE_ENABLE);
2057 }
Girish Gowdra252f4972020-09-07 21:24:01 -07002058#endif // SCALE_AND_PERF
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002059
Girish Gowdra252f4972020-09-07 21:24:01 -07002060#ifndef SCALE_AND_PERF
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002061#ifdef FLOW_CHECKER
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002062 //Flow Checker, To avoid duplicate flow.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002063 if (flow_id_counters != 0) {
2064 bool b_duplicate_flow = false;
Jason Huang09b73ea2020-01-08 17:52:05 +08002065 std::map<flow_pair, int>::iterator it;
2066
2067 for(it = flow_map.begin(); it != flow_map.end(); it++) {
2068 b_duplicate_flow = (cfg.data.onu_id == get_flow_status(it->first.first, it->first.second, ONU_ID)) && \
2069 (key.flow_type == it->first.second) && \
2070 (cfg.data.svc_port_id == get_flow_status(it->first.first, it->first.second, SVC_PORT_ID)) && \
2071 (cfg.data.priority == get_flow_status(it->first.first, it->first.second, PRIORITY)) && \
2072 (cfg.data.cookie == get_flow_status(it->first.first, it->first.second, COOKIE)) && \
2073 (cfg.data.ingress_intf.intf_type == get_flow_status(it->first.first, it->first.second, INGRESS_INTF_TYPE)) && \
2074 (cfg.data.ingress_intf.intf_id == get_flow_status(it->first.first, it->first.second, INGRESS_INTF_ID)) && \
2075 (cfg.data.egress_intf.intf_type == get_flow_status(it->first.first, it->first.second, EGRESS_INTF_TYPE)) && \
2076 (cfg.data.egress_intf.intf_id == get_flow_status(it->first.first, it->first.second, EGRESS_INTF_ID)) && \
2077 (c_val.o_vid == get_flow_status(it->first.first, it->first.second, CLASSIFIER_O_VID)) && \
2078 (c_val.o_pbits == get_flow_status(it->first.first, it->first.second, CLASSIFIER_O_PBITS)) && \
2079 (c_val.i_vid == get_flow_status(it->first.first, it->first.second, CLASSIFIER_I_VID)) && \
2080 (c_val.i_pbits == get_flow_status(it->first.first, it->first.second, CLASSIFIER_I_PBITS)) && \
2081 (c_val.ether_type == get_flow_status(it->first.first, it->first.second, CLASSIFIER_ETHER_TYPE)) && \
2082 (c_val.ip_proto == get_flow_status(it->first.first, it->first.second, CLASSIFIER_IP_PROTO)) && \
2083 (c_val.src_port == get_flow_status(it->first.first, it->first.second, CLASSIFIER_SRC_PORT)) && \
2084 (c_val.dst_port == get_flow_status(it->first.first, it->first.second, CLASSIFIER_DST_PORT)) && \
2085 (c_val.pkt_tag_type == get_flow_status(it->first.first, it->first.second, CLASSIFIER_PKT_TAG_TYPE)) && \
2086 (cfg.data.egress_qos.type == get_flow_status(it->first.first, it->first.second, EGRESS_QOS_TYPE)) && \
2087 (cfg.data.egress_qos.u.fixed_queue.queue_id == get_flow_status(it->first.first, it->first.second, EGRESS_QOS_QUEUE_ID)) && \
2088 (cfg.data.egress_qos.tm_sched.id == get_flow_status(it->first.first, it->first.second, EGRESS_QOS_TM_SCHED_ID)) && \
2089 (a_val.cmds_bitmask == get_flow_status(it->first.first, it->first.second, ACTION_CMDS_BITMASK)) && \
2090 (a_val.o_vid == get_flow_status(it->first.first, it->first.second, ACTION_O_VID)) && \
2091 (a_val.i_vid == get_flow_status(it->first.first, it->first.second, ACTION_I_VID)) && \
2092 (a_val.o_pbits == get_flow_status(it->first.first, it->first.second, ACTION_O_PBITS)) && \
2093 (a_val.i_pbits == get_flow_status(it->first.first, it->first.second, ACTION_I_PBITS)) && \
2094 (cfg.data.state == get_flow_status(it->first.first, it->first.second, STATE)) && \
2095 (cfg.data.group_id == get_flow_status(it->first.first, it->first.second, GROUP_ID));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002096#ifdef SHOW_FLOW_PARAM
2097 // Flow Parameter
2098 FLOW_PARAM_LOG();
2099#endif
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002100 if (b_duplicate_flow) {
2101 FLOW_LOG(WARNING, "Flow duplicate", 0);
2102 return bcm_to_grpc_err(BCM_ERR_ALREADY, "flow exists");
2103 }
2104 }
2105 }
Girish Gowdra252f4972020-09-07 21:24:01 -07002106#endif // FLOW_CHECKER
2107#endif // SCALE_AND_PERF
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002108
2109 bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg.hdr);
2110 if (err) {
2111 FLOW_LOG(ERROR, "Flow add failed", err);
2112 return bcm_to_grpc_err(err, "flow add failed");
2113 } else {
2114 FLOW_LOG(INFO, "Flow add ok", err);
2115 bcmos_fastlock_lock(&data_lock);
Jason Huang09b73ea2020-01-08 17:52:05 +08002116 flow_map[std::pair<int, int>(key.flow_id,key.flow_type)] = flow_map.size();
2117 flow_id_counters = flow_map.size();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002118 bcmos_fastlock_unlock(&data_lock, 0);
Girish Gowdra252f4972020-09-07 21:24:01 -07002119
2120 }
Burak Gurdaga0523592021-02-24 15:17:47 +00002121
2122 /*
2123 Enable AES encryption on GEM ports if they are used in downstream unicast flows.
2124 Rationale: We can't do upstream encryption in GPON. This change addresses the common denominator (and also minimum viable)
2125 use case for both technologies which is downstream unicast GEM port encryption. Since the downstream traffic is inherently
2126 broadcast to all the ONUs behind a PON port, encrypting the individual subscriber traffic in this direction is important
2127 and considered good enough in terms of security (See Section 12.1 of G.984.3). For upstream unicast and downstream multicast
2128 GEM encryption, we need to make additional changes specific to XGSPON. This will be done as a future work.
2129 */
2130 if (aes_enabled && (access_intf_id >= 0) && (gemport_id >= GEM_PORT_ID_START) && (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM)) {
2131 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);
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +05302132 enable_encryption_for_gem_port(access_intf_id, gemport_id, board_technology);
Burak Gurdaga0523592021-02-24 15:17:47 +00002133 } else {
2134 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);
2135 }
2136
Girish Gowdra252f4972020-09-07 21:24:01 -07002137 return Status::OK;
2138}
2139
2140Status FlowRemoveWrapper_(const ::openolt::Flow* request) {
Girish Gowdraeec0fc92021-05-12 15:37:55 -07002141 int32_t access_intf_id = request->access_intf_id();
2142 int32_t onu_id = request->onu_id();
2143 int32_t uni_id = request->uni_id();
2144 uint32_t tech_profile_id = request->tech_profile_id();
Girish Gowdra252f4972020-09-07 21:24:01 -07002145 uint64_t voltha_flow_id = request->flow_id();
2146 Status st;
2147
2148 // If Voltha flow is not installed, return fail
2149 if (! is_voltha_flow_installed(voltha_flow_id)) {
2150 OPENOLT_LOG(ERROR, openolt_log_id, "voltha_flow_id=%lu not found\n", voltha_flow_id);
2151 return ::Status(grpc::StatusCode::NOT_FOUND, "voltha-flow-not-found");
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002152 }
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -04002153
Girish Gowdra252f4972020-09-07 21:24:01 -07002154 const device_flow *dev_fl = get_device_flow(voltha_flow_id);
2155 if (dev_fl == NULL) {
2156 OPENOLT_LOG(ERROR, openolt_log_id, "device flow for voltha_flow_id=%lu in the cache is NULL\n", voltha_flow_id);
2157 return ::Status(grpc::StatusCode::INTERNAL, "device-flow-null-in-cache");
2158 }
2159 if (dev_fl->is_flow_replicated) {
2160 // Note: Here we are ignoring FlowRemove failures
2161 for (int i=0; i<NUMBER_OF_REPLICATED_FLOWS; i++) {
Girish Gowdra72bb4652022-01-18 17:04:30 -08002162 st = FlowRemove_(dev_fl->params[i].flow_id, dev_fl->flow_type);
Girish Gowdra252f4972020-09-07 21:24:01 -07002163 if (st.error_code() == grpc::StatusCode::OK) {
2164 free_flow_id(dev_fl->params[i].flow_id);
2165 }
2166 }
2167 } else {
2168 // Note: Here we are ignoring FlowRemove failures
Girish Gowdra72bb4652022-01-18 17:04:30 -08002169 st = FlowRemove_(dev_fl->params[0].flow_id, dev_fl->flow_type);
Girish Gowdra252f4972020-09-07 21:24:01 -07002170 if (st.error_code() == grpc::StatusCode::OK) {
2171 free_flow_id(dev_fl->params[0].flow_id);
2172 }
2173 }
2174 // remove the flow from cache on voltha flow removal
2175 remove_voltha_flow_from_cache(voltha_flow_id);
Girish Gowdraeec0fc92021-05-12 15:37:55 -07002176
Girish Gowdra72bb4652022-01-18 17:04:30 -08002177 symmetric_datapath_flow_id_map_key key(access_intf_id, onu_id, uni_id, tech_profile_id, dev_fl->flow_type);
Girish Gowdraeec0fc92021-05-12 15:37:55 -07002178 // Remove onu-uni mapping for the pon-gem key
2179 bcmos_fastlock_lock(&symmetric_datapath_flow_id_lock);
2180 symmetric_datapath_flow_id_map.erase(key);
2181 bcmos_fastlock_unlock(&symmetric_datapath_flow_id_lock, 0);
2182
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002183 return Status::OK;
2184}
2185
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002186Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
2187
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002188 bcmolt_flow_cfg cfg;
2189 bcmolt_flow_key key = { };
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002190
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002191 key.flow_id = (bcmolt_flow_id) flow_id;
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002192 key.flow_id = flow_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002193 if (flow_type.compare(upstream) == 0 ) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002194 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002195 } else if (flow_type.compare(downstream) == 0) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002196 key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002197 } else if(flow_type.compare(multicast) == 0) {
2198 key.flow_type = BCMOLT_FLOW_TYPE_MULTICAST;
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002199 } else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002200 OPENOLT_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002201 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
2202 }
2203
Jason Huang09b73ea2020-01-08 17:52:05 +08002204 OPENOLT_LOG(INFO, openolt_log_id, "flow remove received for flow_id=%u, flow_type=%s\n",
2205 flow_id, flow_type.c_str());
2206
Girish Gowdra1935e6a2020-10-31 21:48:22 -07002207 bcmos_fastlock_lock(&acl_packet_trap_handler_lock);
Jason Huang09b73ea2020-01-08 17:52:05 +08002208 flow_id_flow_direction fl_id_fl_dir(flow_id, flow_type);
2209 int32_t gemport_id = -1;
2210 int32_t intf_id = -1;
2211 int16_t acl_id = -1;
2212 if (flow_to_acl_map.count(fl_id_fl_dir) > 0) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002213
2214 acl_id_intf_id ac_id_if_id = flow_to_acl_map[fl_id_fl_dir];
2215 acl_id = std::get<0>(ac_id_if_id);
2216 intf_id = std::get<1>(ac_id_if_id);
Jason Huang09b73ea2020-01-08 17:52:05 +08002217 // cleanup acl only if it is a valid acl. If not valid acl, it may be datapath flow.
2218 if (acl_id >= 0) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002219 Status resp = handle_acl_rule_cleanup(acl_id, intf_id, flow_type);
Jason Huang09b73ea2020-01-08 17:52:05 +08002220 if (resp.ok()) {
2221 OPENOLT_LOG(INFO, openolt_log_id, "acl removed ok for flow_id = %u with acl_id = %d\n", flow_id, acl_id);
2222 flow_to_acl_map.erase(fl_id_fl_dir);
Girish Gowdra1935e6a2020-10-31 21:48:22 -07002223
2224 // 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
2225 if (trap_to_host_pkt_info_with_vlan_for_flow_id.count(flow_id) > 0) {
2226 trap_to_host_pkt_info_with_vlan pkt_info_with_vlan = trap_to_host_pkt_info_with_vlan_for_flow_id[flow_id];
2227 // Formulate the trap_to_host_pkt_info tuple key
2228 trap_to_host_pkt_info pkt_info(std::get<0>(pkt_info_with_vlan),
2229 std::get<1>(pkt_info_with_vlan),
2230 std::get<2>(pkt_info_with_vlan),
2231 std::get<3>(pkt_info_with_vlan));
2232 // Extract the value corresponding to trap_to_host_pkt_info key from trap_to_host_vlan_ids_for_trap_to_host_pkt_info
2233 // The value is a list of vlan_ids for the given trap_to_host_pkt_info key
2234 // Remove the vlan_id from the list that corresponded to the flow being removed.
2235 if (trap_to_host_vlan_ids_for_trap_to_host_pkt_info.count(pkt_info) > 0) {
2236 trap_to_host_vlan_ids_for_trap_to_host_pkt_info[pkt_info].remove(std::get<4>(pkt_info_with_vlan));
2237 } else {
2238 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",
2239 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));
2240 }
2241
2242 } else {
2243 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);
2244 }
Jason Huang09b73ea2020-01-08 17:52:05 +08002245 } else {
2246 OPENOLT_LOG(ERROR, openolt_log_id, "acl remove error for flow_id = %u with acl_id = %d\n", flow_id, acl_id);
2247 }
Girish Gowdra1935e6a2020-10-31 21:48:22 -07002248 bcmos_fastlock_unlock(&acl_packet_trap_handler_lock, 0);
Jason Huang09b73ea2020-01-08 17:52:05 +08002249 return resp;
2250 }
2251 }
Girish Gowdra1935e6a2020-10-31 21:48:22 -07002252 bcmos_fastlock_unlock(&acl_packet_trap_handler_lock, 0);
Jason Huang09b73ea2020-01-08 17:52:05 +08002253
Girish Gowdra1935e6a2020-10-31 21:48:22 -07002254 bcmos_fastlock_lock(&data_lock);
Craig Lutgen967a1d02018-11-27 10:41:51 -06002255 uint32_t port_no = flowid_to_port[key.flow_id];
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002256 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Craig Lutgen967a1d02018-11-27 10:41:51 -06002257 flowid_to_gemport.erase(key.flow_id);
2258 port_to_flows[port_no].erase(key.flow_id);
2259 if (port_to_flows[port_no].empty()) port_to_flows.erase(port_no);
2260 }
2261 else
2262 {
2263 flowid_to_port.erase(key.flow_id);
2264 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002265 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06002266
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002267 BCMOLT_CFG_INIT(&cfg, flow, key);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002268
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002269 bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002270 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07002271 OPENOLT_LOG(ERROR, openolt_log_id, "Error while removing %s flow, flow_id=%d, err = %s (%d)\n", flow_type.c_str(), flow_id, cfg.hdr.hdr.err_text, err);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002272 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
2273 }
2274
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002275 bcmos_fastlock_lock(&data_lock);
Jason Huang09b73ea2020-01-08 17:52:05 +08002276 if (flow_id_counters != 0) {
2277 std::map<flow_pair, int>::iterator it;
2278 for(it = flow_map.begin(); it != flow_map.end(); it++) {
2279 if (it->first.first == flow_id && it->first.second == key.flow_type) {
2280 flow_id_counters -= 1;
2281 flow_map.erase(it);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002282 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002283 }
2284 }
Jason Huang09b73ea2020-01-08 17:52:05 +08002285 OPENOLT_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
2286
Jason Huang09b73ea2020-01-08 17:52:05 +08002287 flow_to_acl_map.erase(fl_id_fl_dir);
2288
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002289 bcmos_fastlock_unlock(&data_lock, 0);
2290
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04002291 return Status::OK;
2292}
2293
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002294bcmos_errno CreateDefaultSched(uint32_t intf_id, const std::string direction) {
2295 bcmos_errno err;
2296 bcmolt_tm_sched_cfg tm_sched_cfg;
2297 bcmolt_tm_sched_key tm_sched_key = {.id = 1};
2298 tm_sched_key.id = get_default_tm_sched_id(intf_id, direction);
2299
Jason Huangbf45ffb2019-10-30 17:29:02 +08002300 //check TM scheduler has configured or not
2301 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
2302 BCMOLT_MSG_FIELD_GET(&tm_sched_cfg, state);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002303 #ifdef TEST_MODE
2304 // It is impossible to mock the setting of tm_sched_cfg.data.state because
2305 // the actual bcmolt_cfg_get passes the address of tm_sched_cfg.hdr and we cannot
2306 // set the tm_sched_cfg.data.state. So a new stub function is created and address
2307 // of tm_sched_cfg is passed. This is one-of case where we need to add test specific
2308 // code in production code.
2309 err = bcmolt_cfg_get__tm_sched_stub(dev_id, &tm_sched_cfg);
2310 #else
Jason Huangbf45ffb2019-10-30 17:29:02 +08002311 err = bcmolt_cfg_get(dev_id, &tm_sched_cfg.hdr);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002312 #endif
Jason Huangbf45ffb2019-10-30 17:29:02 +08002313 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07002314 OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query TM scheduler, err = %s (%d)\n", tm_sched_cfg.hdr.hdr.err_text, err);
Jason Huangbf45ffb2019-10-30 17:29:02 +08002315 return err;
2316 }
2317 else if (tm_sched_cfg.data.state == BCMOLT_CONFIG_STATE_CONFIGURED) {
2318 OPENOLT_LOG(WARNING, openolt_log_id, "tm scheduler default config has already with id %d\n", tm_sched_key.id);
2319 return BCM_ERR_OK;
2320 }
2321
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002322 // bcmbal_tm_sched_owner
2323 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
2324
2325 /**< The output of the tm_sched object instance */
2326 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_INTERFACE);
2327
2328 if (direction.compare(upstream) == 0) {
2329 // In upstream it is NNI scheduler
2330 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_NNI);
2331 } else if (direction.compare(downstream) == 0) {
2332 // In downstream it is PON scheduler
2333 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_PON);
2334 }
2335
2336 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_id, intf_id);
2337
2338 // bcmbal_tm_sched_type
2339 // set the deafult policy to strict priority
2340 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP);
2341
2342 // num_priorities: Max number of strict priority scheduling elements
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002343 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, NUM_OF_PRIORITIES);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002344
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002345 err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr);
2346 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002347 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create %s scheduler, id %d, intf_id %d, err = %s\n",
2348 direction.c_str(), tm_sched_key.id, intf_id, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002349 return err;
2350 }
2351
2352 OPENOLT_LOG(INFO, openolt_log_id, "Create %s scheduler success, id %d, intf_id %d\n", \
2353 direction.c_str(), tm_sched_key.id, intf_id);
2354 return BCM_ERR_OK;
2355}
2356
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002357bcmos_errno CreateSched(std::string direction, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t port_no,
Girish Gowdra252f4972020-09-07 21:24:01 -07002358 uint32_t alloc_id, ::tech_profile::AdditionalBW additional_bw, uint32_t weight, uint32_t priority,
2359 ::tech_profile::SchedulingPolicy sched_policy, ::tech_profile::TrafficShapingInfo tf_sh_info,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002360 uint32_t tech_profile_id) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002361
2362 bcmos_errno err;
2363
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002364 if (direction == downstream) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002365 bcmolt_tm_sched_cfg tm_sched_cfg;
2366 bcmolt_tm_sched_key tm_sched_key = {.id = 1};
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002367 tm_sched_key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002368
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002369 // bcmbal_tm_sched_owner
2370 // In downstream it is sub_term scheduler
2371 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002372
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002373 /**< The output of the tm_sched object instance */
2374 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_TM_SCHED);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002375
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002376 // bcmbal_tm_sched_parent
2377 // The parent for the sub_term scheduler is the PON scheduler in the downstream
2378 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_id, get_default_tm_sched_id(intf_id, direction));
Girish Gowdra5287fde2021-07-31 00:41:45 +00002379 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_param.type, BCMOLT_TM_SCHED_PARAM_TYPE_PRIORITY);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002380 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_param.u.priority.priority, priority);
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002381 /* removed by BAL v3.0, N/A - No direct attachment point of type ONU, same functionality may
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002382 be achieved using the' virtual' type of attachment.
2383 tm_sched_owner.u.sub_term.intf_id = intf_id;
2384 tm_sched_owner.u.sub_term.sub_term_id = onu_id;
2385 */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002386
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002387 // bcmbal_tm_sched_type
2388 // set the deafult policy to strict priority
2389 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002390
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002391 // num_priorities: Max number of strict priority scheduling elements
2392 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, 8);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002393
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002394 // bcmbal_tm_shaping
2395 if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) {
2396 uint32_t cir = tf_sh_info.cir();
2397 uint32_t pir = tf_sh_info.pir();
2398 uint32_t burst = tf_sh_info.pbs();
2399 OPENOLT_LOG(INFO, openolt_log_id, "applying traffic shaping in DL cir=%u, pir=%u, burst=%u\n",
2400 cir, pir, burst);
2401 BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, pir);
2402 BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, burst);
2403 // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet'
2404 //BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.cir, cir);
2405 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.pir, pir);
2406 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.burst, burst);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002407 }
2408
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002409 err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002410 if (err) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002411 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, \
Girish Gowdra72cbee92021-11-05 15:16:18 -07002412intf_id %d, onu_id %d, uni_id %d, port_no %u, err = %s (%d)\n", tm_sched_key.id, intf_id, onu_id, uni_id, \
2413port_no, tm_sched_cfg.hdr.hdr.err_text, err);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002414 return err;
2415 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002416 OPENOLT_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \
2417uni_id %d, port_no %u\n", tm_sched_key.id, intf_id, onu_id, uni_id, port_no);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002418
2419 } else { //upstream
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002420 bcmolt_itupon_alloc_cfg cfg;
2421 bcmolt_itupon_alloc_key key = { };
2422 key.pon_ni = intf_id;
2423 key.alloc_id = alloc_id;
2424 int bw_granularity = (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY;
Burak Gurdag623fada2021-04-20 22:02:36 +00002425 /*
2426 PIR: Maximum Bandwidth
2427 CIR: Assured Bandwidth
2428 GIR: Fixed Bandwidth
2429 */
Burak Gurdag03919c72020-02-04 22:46:57 +00002430 int pir_bw = tf_sh_info.pir()*125; // conversion from kbps to bytes/sec
2431 int cir_bw = tf_sh_info.cir()*125; // conversion from kbps to bytes/sec
Burak Gurdag623fada2021-04-20 22:02:36 +00002432 int gir_bw = tf_sh_info.gir()*125; // conversion from kbps to bytes/sec
2433 int guaranteed_bw = cir_bw+gir_bw;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002434 //offset to match bandwidth granularity
2435 int offset_pir_bw = pir_bw%bw_granularity;
Burak Gurdag623fada2021-04-20 22:02:36 +00002436 int offset_gir_bw = gir_bw%bw_granularity;
2437 int offset_guaranteed_bw = guaranteed_bw%bw_granularity;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002438
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002439 pir_bw = pir_bw - offset_pir_bw;
Burak Gurdag623fada2021-04-20 22:02:36 +00002440 gir_bw = gir_bw - offset_gir_bw;
2441 guaranteed_bw = guaranteed_bw - offset_guaranteed_bw;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002442
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002443 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002444
Burak Gurdag623fada2021-04-20 22:02:36 +00002445 OPENOLT_LOG(INFO, openolt_log_id, "Creating alloc_id %d with pir = %d bytes/sec, cir = %d bytes/sec, gir = %d bytes/sec, additional_bw = %d.\n", alloc_id, pir_bw, cir_bw, gir_bw, additional_bw);
2446
2447 if (pir_bw == 0) {
2448 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be at least %d bytes/sec\n",
2449 (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY);
2450 return BCM_ERR_PARM;
2451 } else if (pir_bw < guaranteed_bw) {
2452 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed bandwidth (%d)\n",
2453 pir_bw, guaranteed_bw);
2454 return BCM_ERR_PARM;
2455 }
2456
2457 // Setting additional bw eligibility and validating bw provisionings
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002458 switch (additional_bw) {
Burak Gurdag623fada2021-04-20 22:02:36 +00002459
2460 case tech_profile::AdditionalBW::AdditionalBW_BestEffort: //AdditionalBW_BestEffort - For T-Cont types 4 & 5
2461 if (pir_bw == guaranteed_bw) {
2462 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be greater than Guaranteed \
2463bandwidth for additional bandwidth eligibility of type Best Effort\n");
2464 return BCM_ERR_PARM;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002465 }
2466 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_BEST_EFFORT);
2467 break;
Burak Gurdag623fada2021-04-20 22:02:36 +00002468
2469 case tech_profile::AdditionalBW::AdditionalBW_NA: //AdditionalBW_NA - For T-Cont types 3 & 5
2470 if (guaranteed_bw == 0) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002471 OPENOLT_LOG(ERROR, openolt_log_id, "Guaranteed bandwidth must be greater than zero for \
2472additional bandwidth eligibility of type Non-Assured (NA)\n");
2473 return BCM_ERR_PARM;
Burak Gurdag623fada2021-04-20 22:02:36 +00002474 } else if (pir_bw == guaranteed_bw) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002475 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be greater than Guaranteed \
Burak Gurdag623fada2021-04-20 22:02:36 +00002476bandwidth for additional bandwidth eligibility of type Non-Assured\n");
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002477 return BCM_ERR_PARM;
2478 }
2479 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NON_ASSURED);
2480 break;
Burak Gurdag623fada2021-04-20 22:02:36 +00002481
2482 case tech_profile::AdditionalBW::AdditionalBW_None: //AdditionalBW_None - For T-Cont types 1 & 2
2483 if (guaranteed_bw != pir_bw) {
2484 OPENOLT_LOG(ERROR, openolt_log_id, "Guaranteed bandwidth must be equal to maximum bandwidth \
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002485for additional bandwidth eligibility of type None\n");
2486 return BCM_ERR_PARM;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002487 }
2488 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NONE);
2489 break;
Burak Gurdag623fada2021-04-20 22:02:36 +00002490
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002491 default:
Burak Gurdag623fada2021-04-20 22:02:36 +00002492 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid additional bandwidth eligibility value (%d) supplied.\n", additional_bw);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002493 return BCM_ERR_PARM;
Girish Gowdrue075c642019-01-23 04:05:53 -08002494 }
Burak Gurdag623fada2021-04-20 22:02:36 +00002495
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002496 /* CBR Real Time Bandwidth which require shaping of the bandwidth allocations
2497 in a fine granularity. */
2498 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_bw, 0);
Burak Gurdag623fada2021-04-20 22:02:36 +00002499 /* Since we can assign minimum 64000 bytes/sec for cbr_rt_bw, we prefer assigning
2500 gir_bw to cbr_nrt_bw to allow smaller amounts.
2501 TODO: Specify CBR_RT_BW and CBR_NRT_BW separately from VOLTHA */
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002502 /* Fixed Bandwidth with no critical requirement of shaping */
Burak Gurdag623fada2021-04-20 22:02:36 +00002503 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_bw, gir_bw);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002504 /* Dynamic bandwidth which the OLT is committed to allocate upon demand */
Burak Gurdag623fada2021-04-20 22:02:36 +00002505 BCMOLT_MSG_FIELD_SET(&cfg, sla.guaranteed_bw, guaranteed_bw);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002506 /* Maximum allocated bandwidth allowed for this alloc ID */
2507 BCMOLT_MSG_FIELD_SET(&cfg, sla.maximum_bw, pir_bw);
Burak Gurdag623fada2021-04-20 22:02:36 +00002508
2509 if (pir_bw == gir_bw) { // T-Cont Type 1 --> set alloc type to NONE
2510 // the condition cir_bw == 0 is implicitly satistied
2511 OPENOLT_LOG(INFO, openolt_log_id, "Setting alloc type to NONE since maximum bandwidth is equal to fixed bandwidth\n");
2512 BCMOLT_MSG_FIELD_SET(&cfg, sla.alloc_type, BCMOLT_ALLOC_TYPE_NONE);
2513 } else { // For other T-Cont types, set alloc type to NSR. TODO: read the default from a config file.
2514 BCMOLT_MSG_FIELD_SET(&cfg, sla.alloc_type, BCMOLT_ALLOC_TYPE_NSR);
2515 }
2516
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002517 /* Set to True for AllocID with CBR RT Bandwidth that requires compensation
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002518 for skipped allocations during quiet window */
2519 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_compensation, BCMOS_FALSE);
2520 /**< Allocation Profile index for CBR non-RT Bandwidth */
2521 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_ap_index, 0);
2522 /**< Allocation Profile index for CBR RT Bandwidth */
2523 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_ap_index, 0);
2524 /**< Alloc ID Weight used in case of Extended DBA mode */
2525 BCMOLT_MSG_FIELD_SET(&cfg, sla.weight, 0);
2526 /**< Alloc ID Priority used in case of Extended DBA mode */
2527 BCMOLT_MSG_FIELD_SET(&cfg, sla.priority, 0);
2528 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002529
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302530 bcmolt_onu_state onu_state;
2531 bool wait_for_alloc_cfg_cmplt = false;
2532 err = get_onu_state((bcmolt_interface)intf_id, (bcmolt_onu_id)onu_id, &onu_state);
2533 if (err) {
2534 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch onu status, intf_id = %d, onu_id = %d, err = %s\n",
2535 intf_id, onu_id, bcmos_strerror(err));
2536 return err;
2537 } else if (onu_state == BCMOLT_ONU_STATE_ACTIVE) {
2538 wait_for_alloc_cfg_cmplt = true;
2539 }
2540
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002541 err = bcmolt_cfg_set(dev_id, &cfg.hdr);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002542 if (err) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002543 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
Girish Gowdra72cbee92021-11-05 15:16:18 -07002544port_no %u, alloc_id %d, err = %s (%d)\n", intf_id, onu_id,uni_id,port_no,alloc_id, cfg.hdr.hdr.err_text, err);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002545 return err;
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302546 } else if (wait_for_alloc_cfg_cmplt) {
2547 err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_CREATE);
2548 if (err) {
2549 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
Girish Gowdra96461052019-11-22 20:13:59 +05302550port_no %u, alloc_id %d, err = %s\n", intf_id, onu_id,uni_id,port_no,alloc_id, bcmos_strerror(err));
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302551 return err;
Girish Gowdra72cbee92021-11-05 15:16:18 -07002552 }
2553 } else {
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302554 OPENOLT_LOG(INFO, openolt_log_id, "onu not active, not waiting for alloc cfg complete, onu_state = %d, intf = %d, onu=%d\n",
2555 onu_state, intf_id, onu_id);
Girish Gowdra96461052019-11-22 20:13:59 +05302556 }
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302557
Girish Gowdra96461052019-11-22 20:13:59 +05302558 OPENOLT_LOG(INFO, openolt_log_id, "create upstream bandwidth allocation success, intf_id %d, onu_id %d, uni_id %d,\
2559port_no %u, alloc_id %d\n", intf_id, onu_id,uni_id,port_no,alloc_id);
2560
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002561 }
2562
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002563 return BCM_ERR_OK;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002564}
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002565
Girish Gowdra252f4972020-09-07 21:24:01 -07002566Status CreateTrafficSchedulers_(const ::tech_profile::TrafficSchedulers *traffic_scheds) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002567 uint32_t intf_id = traffic_scheds->intf_id();
2568 uint32_t onu_id = traffic_scheds->onu_id();
2569 uint32_t uni_id = traffic_scheds->uni_id();
2570 uint32_t port_no = traffic_scheds->port_no();
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002571 std::string direction;
2572 unsigned int alloc_id;
Girish Gowdra252f4972020-09-07 21:24:01 -07002573 ::tech_profile::SchedulerConfig sched_config;
2574 ::tech_profile::AdditionalBW additional_bw;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002575 uint32_t priority;
2576 uint32_t weight;
Girish Gowdra252f4972020-09-07 21:24:01 -07002577 ::tech_profile::SchedulingPolicy sched_policy;
2578 ::tech_profile::TrafficShapingInfo traffic_shaping_info;
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002579 uint32_t tech_profile_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002580 bcmos_errno err;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002581
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002582 for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002583 ::tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002584
2585 direction = GetDirection(traffic_sched.direction());
2586 if (direction.compare("direction-not-supported") == 0)
2587 return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported");
2588
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002589 alloc_id = traffic_sched.alloc_id();
2590 sched_config = traffic_sched.scheduler();
2591 additional_bw = sched_config.additional_bw();
2592 priority = sched_config.priority();
2593 weight = sched_config.weight();
2594 sched_policy = sched_config.sched_policy();
2595 traffic_shaping_info = traffic_sched.traffic_shaping_info();
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002596 tech_profile_id = traffic_sched.tech_profile_id();
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002597 err = CreateSched(direction, intf_id, onu_id, uni_id, port_no, alloc_id, additional_bw, weight, priority,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002598 sched_policy, traffic_shaping_info, tech_profile_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002599 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002600 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create scheduler, err = %s\n", bcmos_strerror(err));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002601 return bcm_to_grpc_err(err, "Failed to create scheduler");
2602 }
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -07002603 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002604 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002605}
Jonathan Davis70c21812018-07-19 15:32:10 -04002606
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002607bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction, int tech_profile_id) {
Jonathan Davis70c21812018-07-19 15:32:10 -04002608
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002609 bcmos_errno err;
Girish Gowdra72cbee92021-11-05 15:16:18 -07002610 bcmolt_onu_state onu_state;
Girish Gowdra96461052019-11-22 20:13:59 +05302611 uint16_t sched_id;
Jonathan Davis70c21812018-07-19 15:32:10 -04002612
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002613 if (direction == upstream) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002614 bcmolt_itupon_alloc_cfg cfg;
2615 bcmolt_itupon_alloc_key key = { };
2616 key.pon_ni = intf_id;
2617 key.alloc_id = alloc_id;
Girish Gowdra96461052019-11-22 20:13:59 +05302618 sched_id = alloc_id;
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002619
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302620 bcmolt_onu_state onu_state;
2621 bool wait_for_alloc_cfg_cmplt = false;
2622 err = get_onu_state((bcmolt_interface)intf_id, (bcmolt_onu_id)onu_id, &onu_state);
2623 if (err) {
2624 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to fetch onu status, intf_id = %d, onu_id = %d, err = %s\n",
2625 intf_id, onu_id, bcmos_strerror(err));
2626 return err;
2627 } else if (onu_state == BCMOLT_ONU_STATE_ACTIVE) {
2628 wait_for_alloc_cfg_cmplt = true;
2629 }
2630
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002631 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002632 err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
2633 if (err) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07002634 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, intf_id %d, alloc_id %d, err = %s (%d)\n",
2635 direction.c_str(), intf_id, alloc_id, cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002636 return err;
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302637 } else if (wait_for_alloc_cfg_cmplt) {
2638 err = wait_for_alloc_action(intf_id, alloc_id, ALLOC_OBJECT_DELETE);
2639 if (err) {
2640 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
2641pon_intf %u, alloc_id %d, err = %s\n", intf_id, onu_id,uni_id,intf_id,alloc_id, bcmos_strerror(err));
2642 return err;
2643 }
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05302644 } else {
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302645 OPENOLT_LOG(INFO, openolt_log_id, "onu not active, not waiting for alloc cfg complete, onu_state = %d, intf = %d, onu=%d\n",
2646 onu_state, intf_id, onu_id);
Girish Gowdra96461052019-11-22 20:13:59 +05302647 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002648 } else if (direction == downstream) {
2649 bcmolt_tm_sched_cfg cfg;
2650 bcmolt_tm_sched_key key = { };
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002651
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002652 if (is_tm_sched_id_present(intf_id, onu_id, uni_id, direction, tech_profile_id)) {
2653 key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id);
Girish Gowdra96461052019-11-22 20:13:59 +05302654 sched_id = key.id;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002655 } else {
2656 OPENOLT_LOG(INFO, openolt_log_id, "schduler not present in %s, err %d\n", direction.c_str(), err);
2657 return BCM_ERR_OK;
2658 }
Girish Gowdra96461052019-11-22 20:13:59 +05302659
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002660 BCMOLT_CFG_INIT(&cfg, tm_sched, key);
2661 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
2662 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002663 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler, direction = %s, sched_id %d, \
Girish Gowdra72cbee92021-11-05 15:16:18 -07002664intf_id %d, onu_id %d, tech_profile_id %d, err = %s (%d)\n", direction.c_str(), key.id, intf_id, onu_id, tech_profile_id, cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002665 return err;
2666 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002667 }
2668
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002669 OPENOLT_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, id %d, intf_id %d, onu_id %d, tech_profile_id %d\n",
2670 direction.c_str(), sched_id, intf_id, onu_id, tech_profile_id);
2671 free_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002672 return BCM_ERR_OK;
2673}
2674
Girish Gowdra252f4972020-09-07 21:24:01 -07002675Status RemoveTrafficSchedulers_(const ::tech_profile::TrafficSchedulers *traffic_scheds) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002676 uint32_t intf_id = traffic_scheds->intf_id();
2677 uint32_t onu_id = traffic_scheds->onu_id();
2678 uint32_t uni_id = traffic_scheds->uni_id();
2679 std::string direction;
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002680 uint32_t tech_profile_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002681 bcmos_errno err;
2682
2683 for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002684 ::tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002685
2686 direction = GetDirection(traffic_sched.direction());
2687 if (direction.compare("direction-not-supported") == 0)
2688 return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported");
2689
2690 int alloc_id = traffic_sched.alloc_id();
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002691 int tech_profile_id = traffic_sched.tech_profile_id();
2692 err = RemoveSched(intf_id, onu_id, uni_id, alloc_id, direction, tech_profile_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002693 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002694 OPENOLT_LOG(ERROR, openolt_log_id, "Error-removing-traffic-scheduler, err = %s\n",bcmos_strerror(err));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002695 return bcm_to_grpc_err(err, "error-removing-traffic-scheduler");
2696 }
2697 }
2698 return Status::OK;
2699}
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002700
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002701bcmos_errno CreateTrafficQueueMappingProfile(uint32_t sched_id, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, \
2702 std::string direction, std::vector<uint32_t> tmq_map_profile) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002703 bcmos_errno err;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002704 bcmolt_tm_qmp_cfg tm_qmp_cfg;
2705 bcmolt_tm_qmp_key tm_qmp_key;
2706 bcmolt_arr_u8_8 pbits_to_tmq_id = {0};
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002707
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002708 int tm_qmp_id = get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id, tmq_map_profile);
2709 if (tm_qmp_id == -1) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002710 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile. Max allowed tm queue mapping profile count is 16.\n");
2711 return BCM_ERR_RANGE;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002712 }
Girish Gowdruf26cf882019-05-01 23:47:58 -07002713
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002714 tm_qmp_key.id = tm_qmp_id;
2715 for (uint32_t priority=0; priority<tmq_map_profile.size(); priority++) {
2716 pbits_to_tmq_id.arr[priority] = tmq_map_profile[priority];
2717 }
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002718
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002719 BCMOLT_CFG_INIT(&tm_qmp_cfg, tm_qmp, tm_qmp_key);
2720 BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, type, BCMOLT_TM_QMP_TYPE_PBITS);
2721 BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, pbits_to_tmq_id, pbits_to_tmq_id);
Jason Huang09b73ea2020-01-08 17:52:05 +08002722 //BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, ref_count, 0);
2723 //BCMOLT_MSG_FIELD_SET(&tm_qmp_cfg, state, BCMOLT_CONFIG_STATE_CONFIGURED);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002724
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002725 err = bcmolt_cfg_set(dev_id, &tm_qmp_cfg.hdr);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002726 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002727 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile, tm_qmp_id %d, err = %s\n",
2728 tm_qmp_key.id, bcmos_strerror(err));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002729 return err;
2730 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06002731
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002732 OPENOLT_LOG(INFO, openolt_log_id, "Create tm queue mapping profile success, id %d\n", \
2733 tm_qmp_key.id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002734 return BCM_ERR_OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002735}
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002736
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002737bcmos_errno RemoveTrafficQueueMappingProfile(uint32_t tm_qmp_id) {
2738 bcmos_errno err;
2739 bcmolt_tm_qmp_cfg tm_qmp_cfg;
2740 bcmolt_tm_qmp_key tm_qmp_key;
2741 tm_qmp_key.id = tm_qmp_id;
2742
2743 BCMOLT_CFG_INIT(&tm_qmp_cfg, tm_qmp, tm_qmp_key);
2744 err = bcmolt_cfg_clear(dev_id, &tm_qmp_cfg.hdr);
2745 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002746 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove tm queue mapping profile, tm_qmp_id %d, err = %s\n",
2747 tm_qmp_key.id, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002748 return err;
2749 }
2750
2751 OPENOLT_LOG(INFO, openolt_log_id, "Remove tm queue mapping profile success, id %d\n", \
2752 tm_qmp_key.id);
2753 return BCM_ERR_OK;
2754}
2755
2756bcmos_errno CreateDefaultQueue(uint32_t intf_id, const std::string direction) {
2757 bcmos_errno err;
2758
Burak Gurdagc78b9e12019-11-29 11:14:51 +00002759 /* Create default queues on the given PON/NNI scheduler */
2760 for (int queue_id = 0; queue_id < NUMBER_OF_DEFAULT_INTERFACE_QUEUES; queue_id++) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002761 bcmolt_tm_queue_cfg tm_queue_cfg;
2762 bcmolt_tm_queue_key tm_queue_key = {};
2763 tm_queue_key.sched_id = get_default_tm_sched_id(intf_id, direction);
2764 tm_queue_key.id = queue_id;
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05002765 /* DefaultQueues on PON/NNI schedulers are created with egress_qos_type as
2766 BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE - with tm_q_set_id 32768 */
2767 tm_queue_key.tm_q_set_id = BCMOLT_TM_QUEUE_SET_ID_QSET_NOT_USE;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002768
2769 BCMOLT_CFG_INIT(&tm_queue_cfg, tm_queue, tm_queue_key);
2770 BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.type, BCMOLT_TM_SCHED_PARAM_TYPE_PRIORITY);
2771 BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.u.priority.priority, queue_id);
2772
2773 err = bcmolt_cfg_set(dev_id, &tm_queue_cfg.hdr);
2774 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002775 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", \
2776 direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id, tm_queue_key.tm_q_set_id, bcmos_strerror(err));
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002777 return err;
2778 }
2779
2780 OPENOLT_LOG(INFO, openolt_log_id, "Create %s tm_queue success, id %d, sched_id %d, tm_q_set_id %d\n", \
2781 direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id, tm_queue_key.tm_q_set_id);
2782 }
2783 return BCM_ERR_OK;
2784}
2785
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05002786bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002787 bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002788 bcmos_errno err;
2789 bcmolt_tm_queue_cfg cfg;
2790 bcmolt_tm_queue_key key = { };
2791 OPENOLT_LOG(INFO, openolt_log_id, "creating %s queue. access_intf_id = %d, onu_id = %d, uni_id = %d \
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002792gemport_id = %d, tech_profile_id = %d\n", direction.c_str(), access_intf_id, onu_id, uni_id, gemport_id, tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002793
2794 key.sched_id = (direction.compare(upstream) == 0) ? get_default_tm_sched_id(nni_intf_id, direction) : \
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002795 get_tm_sched_id(access_intf_id, onu_id, uni_id, direction, tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002796
2797 if (priority > 7) {
2798 return BCM_ERR_RANGE;
2799 }
2800
2801 /* FIXME: The upstream queues have to be created once only.
2802 The upstream queues on the NNI scheduler are shared by all subscribers.
2803 When the first scheduler comes in, the queues get created, and are re-used by all others.
2804 Also, these queues should be present until the last subscriber exits the system.
2805 One solution is to have these queues always, i.e., create it as soon as OLT is enabled.
2806
2807 There is one queue per gem port and Queue ID is fetched based on priority_q configuration
2808 for each GEM in TECH PROFILE */
2809 key.id = queue_id_list[priority];
2810
2811 if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) {
2812 // Reset the Queue ID to 0, if it is fixed queue, i.e., there is only one queue for subscriber.
2813 key.id = 0;
2814 key.tm_q_set_id = BCMOLT_TM_QUEUE_SET_ID_QSET_NOT_USE;
2815 }
2816 else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) {
2817 key.tm_q_set_id = get_tm_qmp_id(key.sched_id, access_intf_id, onu_id, uni_id);
2818 }
2819 else {
2820 key.tm_q_set_id = BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT;
2821 }
2822
2823 OPENOLT_LOG(INFO, openolt_log_id, "queue assigned queue_id = %d\n", key.id);
2824
2825 BCMOLT_CFG_INIT(&cfg, tm_queue, key);
2826 BCMOLT_MSG_FIELD_SET(&cfg, tm_sched_param.u.priority.priority, priority);
Girish Gowdra5287fde2021-07-31 00:41:45 +00002827 BCMOLT_MSG_FIELD_SET(&cfg, tm_sched_param.type, BCMOLT_TM_SCHED_PARAM_TYPE_PRIORITY);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002828
2829 err = bcmolt_cfg_set(dev_id, &cfg.hdr);
2830 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002831 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, queue_id %d, \
Girish Gowdra72cbee92021-11-05 15:16:18 -07002832sched_id %d, tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, tech_profile_id %d, err = %s (%d)\n", \
2833 direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, tech_profile_id, cfg.hdr.hdr.err_text, err);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002834 return err;
2835 }
2836
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302837 if (direction == upstream || direction == downstream) {
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +05302838 Status st = install_gem_port(access_intf_id, onu_id, uni_id, gemport_id, board_technology);
Girish Gowdra252f4972020-09-07 21:24:01 -07002839 if (st.error_code() != grpc::StatusCode::ALREADY_EXISTS && st.error_code() != grpc::StatusCode::OK) {
2840 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);
2841 return BCM_ERR_INTERNAL;
2842 }
Girish Gowdraeec0fc92021-05-12 15:37:55 -07002843 if (direction == upstream) {
2844 // Create the pon-gem to onu-uni mapping
2845 pon_gem pg(access_intf_id, gemport_id);
2846 onu_uni ou(onu_id, uni_id);
2847 bcmos_fastlock_lock(&pon_gem_to_onu_uni_map_lock);
2848 pon_gem_to_onu_uni_map[pg] = ou;
2849 bcmos_fastlock_unlock(&pon_gem_to_onu_uni_map_lock, 0);
2850 }
Girish Gowdra252f4972020-09-07 21:24:01 -07002851 }
2852
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002853 OPENOLT_LOG(INFO, openolt_log_id, "Created tm_queue, direction %s, id %d, sched_id %d, tm_q_set_id %d, \
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002854intf_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 Subramani89fffc02019-05-13 21:33:20 +00002855 return BCM_ERR_OK;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002856}
2857
Girish Gowdra252f4972020-09-07 21:24:01 -07002858Status CreateTrafficQueues_(const ::tech_profile::TrafficQueues *traffic_queues) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002859 uint32_t intf_id = traffic_queues->intf_id();
2860 uint32_t onu_id = traffic_queues->onu_id();
2861 uint32_t uni_id = traffic_queues->uni_id();
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002862 uint32_t tech_profile_id = traffic_queues->tech_profile_id();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002863 uint32_t sched_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002864 std::string direction;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002865 bcmos_errno err;
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05002866 bcmolt_egress_qos_type qos_type = get_qos_type(intf_id, onu_id, uni_id, traffic_queues->traffic_queues_size());
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002867
2868 if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) {
2869 uint32_t queues_priority_q[traffic_queues->traffic_queues_size()] = {0};
2870 std::string queues_pbit_map[traffic_queues->traffic_queues_size()];
2871 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002872 ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002873
2874 direction = GetDirection(traffic_queue.direction());
2875 if (direction.compare("direction-not-supported") == 0)
2876 return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported");
2877
2878 queues_priority_q[i] = traffic_queue.priority();
2879 queues_pbit_map[i] = traffic_queue.pbit_map();
2880 }
2881
2882 std::vector<uint32_t> tmq_map_profile(8, 0);
2883 tmq_map_profile = get_tmq_map_profile(get_valid_queues_pbit_map(queues_pbit_map, COUNT_OF(queues_pbit_map)), \
2884 queues_priority_q, COUNT_OF(queues_priority_q));
2885 sched_id = (direction.compare(upstream) == 0) ? get_default_tm_sched_id(nni_intf_id, direction) : \
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002886 get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002887
2888 int tm_qmp_id = get_tm_qmp_id(tmq_map_profile);
2889 if (tm_qmp_id == -1) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002890 err = CreateTrafficQueueMappingProfile(sched_id, intf_id, onu_id, uni_id, direction, tmq_map_profile);
2891 if (err != BCM_ERR_OK) {
2892 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile, err = %s\n", bcmos_strerror(err));
2893 return bcm_to_grpc_err(err, "Failed to create tm queue mapping profile");
2894 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002895 } else if (tm_qmp_id != -1 && get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id) == -1) {
2896 OPENOLT_LOG(INFO, openolt_log_id, "tm queue mapping profile present already with id %d\n", tm_qmp_id);
2897 update_sched_qmp_id_map(sched_id, intf_id, onu_id, uni_id, tm_qmp_id);
2898 }
2899 }
2900
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002901 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002902 ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002903
2904 direction = GetDirection(traffic_queue.direction());
2905 if (direction.compare("direction-not-supported") == 0)
2906 return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported");
2907
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002908 err = CreateQueue(direction, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002909
Girish Gowdruf26cf882019-05-01 23:47:58 -07002910 // If the queue exists already, lets not return failure and break the loop.
2911 if (err && err != BCM_ERR_ALREADY) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002912 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create queue, err = %s\n",bcmos_strerror(err));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002913 return bcm_to_grpc_err(err, "Failed to create queue");
2914 }
2915 }
2916 return Status::OK;
2917}
2918
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05002919bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002920 bcmolt_egress_qos_type qos_type, uint32_t priority, uint32_t gemport_id, uint32_t tech_profile_id) {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002921 bcmolt_tm_queue_cfg cfg;
2922 bcmolt_tm_queue_key key = { };
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002923 bcmos_errno err;
2924
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302925 // Gemports are bi-directional (except in multicast case). We create the gem port when we create the
2926 // upstream/downstream queue (see CreateQueue function) and it makes sense to delete them when remove the queues.
2927 // For multicast case we do not manage the install/remove of gem port in agent application. It is managed by BAL.
2928 if (direction == upstream || direction == downstream) {
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +05302929 Status st = remove_gem_port(access_intf_id, onu_id, uni_id, gemport_id, board_technology);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302930 if (st.error_code() != grpc::StatusCode::OK) {
2931 OPENOLT_LOG(ERROR, openolt_log_id, "failed to remove gemport=%d, access_intf=%d, onu_id=%d\n", gemport_id, access_intf_id, onu_id);
Girish Gowdra72cbee92021-11-05 15:16:18 -07002932 // We should further cleanup proceed, do not return error yet..
2933 // return BCM_ERR_INTERNAL;
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302934 }
Girish Gowdraeec0fc92021-05-12 15:37:55 -07002935 if (direction == upstream) {
2936 // Remove the pon-gem to onu-uni mapping
2937 pon_gem pg(access_intf_id, gemport_id);
2938 bcmos_fastlock_lock(&pon_gem_to_onu_uni_map_lock);
2939 pon_gem_to_onu_uni_map.erase(pg);
2940 bcmos_fastlock_unlock(&pon_gem_to_onu_uni_map_lock, 0);
2941 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302942 }
2943
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002944 if (direction == downstream) {
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002945 if (is_tm_sched_id_present(access_intf_id, onu_id, uni_id, direction, tech_profile_id)) {
2946 key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction, tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002947 key.id = queue_id_list[priority];
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002948 } else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002949 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 Gowdruc8ed2ef2019-02-13 08:18:44 -08002950 return BCM_ERR_OK;
2951 }
2952 } else {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002953 /* In the upstream we use pre-created queues on the NNI scheduler that are used by all subscribers.
2954 They should not be removed. So, lets return OK. */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002955 return BCM_ERR_OK;
2956 }
2957
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002958 if (qos_type == BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE) {
2959 key.tm_q_set_id = BCMOLT_TM_QUEUE_SET_ID_QSET_NOT_USE;
2960 // Reset the queue id to 0 when using fixed queue.
2961 key.id = 0;
2962 }
2963 else if (qos_type == BCMOLT_EGRESS_QOS_TYPE_PRIORITY_TO_QUEUE) {
2964 key.tm_q_set_id = get_tm_qmp_id(key.sched_id, access_intf_id, onu_id, uni_id);
2965 }
2966 else {
2967 key.tm_q_set_id = BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT;
2968 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002969
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002970 BCMOLT_CFG_INIT(&cfg, tm_queue, key);
2971 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002972 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05002973 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, direction = %s, queue_id %d, sched_id %d, \
Girish Gowdra72cbee92021-11-05 15:16:18 -07002974tm_q_set_id %d, intf_id %d, onu_id %d, uni_id %d, err = %s (%d)\n",
2975 direction.c_str(), key.id, key.sched_id, key.tm_q_set_id, access_intf_id, onu_id, uni_id, cfg.hdr.hdr.err_text, err);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002976 return err;
2977 }
2978
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002979 OPENOLT_LOG(INFO, openolt_log_id, "Removed tm_queue, direction %s, id %d, sched_id %d, tm_q_set_id %d, \
2980intf_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 Gowdruc8ed2ef2019-02-13 08:18:44 -08002981
2982 return BCM_ERR_OK;
2983}
2984
Girish Gowdra252f4972020-09-07 21:24:01 -07002985Status RemoveTrafficQueues_(const ::tech_profile::TrafficQueues *traffic_queues) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002986 uint32_t intf_id = traffic_queues->intf_id();
2987 uint32_t onu_id = traffic_queues->onu_id();
2988 uint32_t uni_id = traffic_queues->uni_id();
2989 uint32_t port_no = traffic_queues->port_no();
Burak Gurdag2f2618c2020-04-23 13:20:30 +00002990 uint32_t tech_profile_id = traffic_queues->tech_profile_id();
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002991 uint32_t sched_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002992 std::string direction;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002993 bcmos_errno err;
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05002994 bcmolt_egress_qos_type qos_type = get_qos_type(intf_id, onu_id, uni_id, traffic_queues->traffic_queues_size());
Girish Gowdra72cbee92021-11-05 15:16:18 -07002995 Status ret_code = Status::OK;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002996
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002997 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
Girish Gowdra252f4972020-09-07 21:24:01 -07002998 ::tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00002999
3000 direction = GetDirection(traffic_queue.direction());
3001 if (direction.compare("direction-not-supported") == 0)
3002 return bcm_to_grpc_err(BCM_ERR_PARM, "direction-not-supported");
3003
Burak Gurdag2f2618c2020-04-23 13:20:30 +00003004 err = RemoveQueue(direction, intf_id, onu_id, uni_id, qos_type, traffic_queue.priority(), traffic_queue.gemport_id(), tech_profile_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08003005 if (err) {
Thiyagarajan Subramani0890b1f2019-11-22 07:52:47 -05003006 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, err = %s\n",bcmos_strerror(err));
Girish Gowdra72cbee92021-11-05 15:16:18 -07003007 ret_code = bcm_to_grpc_err(err, "Failed to remove one or more queues");
3008 // Do not return here. We should continue to remove the remaining queues and its associated gem ports
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08003009 }
Jonathan Davis70c21812018-07-19 15:32:10 -04003010 }
3011
Burak Gurdag2f2618c2020-04-23 13:20:30 +00003012 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 Subramani89fffc02019-05-13 21:33:20 +00003013 sched_id = (direction.compare(upstream) == 0) ? get_default_tm_sched_id(nni_intf_id, direction) : \
Burak Gurdag2f2618c2020-04-23 13:20:30 +00003014 get_tm_sched_id(intf_id, onu_id, uni_id, direction, tech_profile_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00003015
3016 int tm_qmp_id = get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id);
3017 if (free_tm_qmp_id(sched_id, intf_id, onu_id, uni_id, tm_qmp_id)) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003018 err = RemoveTrafficQueueMappingProfile(tm_qmp_id);
3019 if (err != BCM_ERR_OK) {
3020 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove tm queue mapping profile, err = %s\n", bcmos_strerror(err));
3021 return bcm_to_grpc_err(err, "Failed to remove tm queue mapping profile");
3022 }
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +00003023 }
3024 }
Thiyagarajan Subramani8154d932019-11-13 05:29:06 -05003025 clear_qos_type(intf_id, onu_id, uni_id);
Girish Gowdra72cbee92021-11-05 15:16:18 -07003026 return ret_code;
Jonathan Davis70c21812018-07-19 15:32:10 -04003027}
Jason Huangbf45ffb2019-10-30 17:29:02 +08003028
Girish Gowdra252f4972020-09-07 21:24:01 -07003029Status PerformGroupOperation_(const ::openolt::Group *group_cfg) {
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003030
3031 bcmos_errno err;
3032 bcmolt_group_key key = {};
3033 bcmolt_group_cfg grp_cfg_obj;
3034 bcmolt_group_members_update grp_mem_upd;
3035 bcmolt_members_update_command grp_mem_upd_cmd;
3036 bcmolt_group_member_info member_info = {};
3037 bcmolt_group_member_info_list_u8 members = {};
3038 bcmolt_intf_ref interface_ref = {};
3039 bcmolt_egress_qos egress_qos = {};
3040 bcmolt_tm_sched_ref tm_sched_ref = {};
3041 bcmolt_action a_val = {};
3042
3043 uint32_t group_id = group_cfg->group_id();
3044
3045 OPENOLT_LOG(INFO, openolt_log_id, "PerformGroupOperation request received for Group %d\n", group_id);
3046
3047 if (group_id >= 0) {
3048 key.id = group_id;
3049 }
3050 else {
3051 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid group id %d.\n", group_id);
3052 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid group id");
3053 }
3054
3055 BCMOLT_CFG_INIT(&grp_cfg_obj, group, key);
3056 BCMOLT_FIELD_SET_PRESENT(&grp_cfg_obj.data, group_cfg_data, state);
3057
3058 OPENOLT_LOG(INFO, openolt_log_id, "Checking if Group %d exists...\n",group_id);
3059
3060 err = bcmolt_cfg_get(dev_id, &(grp_cfg_obj.hdr));
3061 if (err != BCM_ERR_OK) {
3062 OPENOLT_LOG(ERROR, openolt_log_id, "Error in querying Group %d, err = %s\n", group_id, bcmos_strerror(err));
3063 return bcm_to_grpc_err(err, "Error in querying group");
3064 }
3065
3066 members.len = group_cfg->members_size();
3067
3068 // IMPORTANT: A member cannot be added to a group if the group type is not determined.
3069 // Group type is determined after a flow is assigned to it.
3070 // Therefore, a group must be created first, then a flow (with multicast type) must be assigned to it.
3071 // Only then we can add members to the group.
3072
3073 // if group does not exist, create it and return.
3074 if (grp_cfg_obj.data.state == BCMOLT_GROUP_STATE_NOT_CONFIGURED) {
3075
3076 if (members.len != 0) {
3077 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);
3078 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Non-empty member list given for non-existent group");
3079 } else {
3080
3081 BCMOLT_CFG_INIT(&grp_cfg_obj, group, key);
3082 BCMOLT_MSG_FIELD_SET(&grp_cfg_obj, cookie, key.id);
3083
3084 /* Setting group actions and action parameters, if any.
3085 Only remove_outer_tag and translate_inner_tag actions and i_vid action parameter
3086 are supported for multicast groups in BAL 3.1.
3087 */
3088 const ::openolt::Action& action = group_cfg->action();
3089 const ::openolt::ActionCmd &cmd = action.cmd();
3090
3091 bcmolt_action_cmd_id cmd_bmask = BCMOLT_ACTION_CMD_ID_NONE;
3092 if (cmd.remove_outer_tag()) {
3093 OPENOLT_LOG(INFO, openolt_log_id, "Action remove_outer_tag applied to Group %d.\n", group_id);
3094 cmd_bmask = (bcmolt_action_cmd_id) (cmd_bmask | BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG);
3095 }
3096
3097 if (cmd.translate_inner_tag()) {
3098 OPENOLT_LOG(INFO, openolt_log_id, "Action translate_inner_tag applied to Group %d.\n", group_id);
3099 cmd_bmask = (bcmolt_action_cmd_id) (cmd_bmask | BCMOLT_ACTION_CMD_ID_XLATE_INNER_TAG);
3100 }
3101
3102 BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, cmd_bmask);
3103
3104 if (action.i_vid()) {
3105 OPENOLT_LOG(INFO, openolt_log_id, "Setting action parameter i_vid=%d for Group %d.\n", action.i_vid(), group_id);
3106 BCMOLT_FIELD_SET(&a_val, action, i_vid, action.i_vid());
3107 }
3108
3109 BCMOLT_MSG_FIELD_SET(&grp_cfg_obj, action, a_val);
3110
3111 // Create group
3112 err = bcmolt_cfg_set(dev_id, &(grp_cfg_obj.hdr));
3113
3114 if (BCM_ERR_OK != err) {
3115 BCM_LOG(ERROR, openolt_log_id, "Failed to create Group %d, err = %s (%d)\n", key.id, bcmos_strerror(err), err);
3116 return bcm_to_grpc_err(err, "Error in creating group");
3117 }
3118
3119 BCM_LOG(INFO, openolt_log_id, "Group %d has been created and configured with empty member list.\n", key.id);
3120 return Status::OK;
3121 }
3122 }
3123
3124 // The group already exists. Continue configuring it according to the update member command.
3125
3126 OPENOLT_LOG(INFO, openolt_log_id, "Configuring existing Group %d.\n",group_id);
3127
3128 // MEMBER LIST CONSTRUCTION
3129 // Note that members.len can be 0 here. if the group already exists and the command is SET then sending
3130 // empty list to the group is a legit operation and this actually empties the member list.
3131 members.arr = (bcmolt_group_member_info*)bcmos_calloc((members.len)*sizeof(bcmolt_group_member_info));
3132
3133 if (!members.arr) {
3134 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to allocate memory for group member list.\n");
3135 return grpc::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "Memory exhausted during member list creation");
3136 }
3137
3138 /* SET GROUP MEMBERS UPDATE COMMAND */
Girish Gowdra252f4972020-09-07 21:24:01 -07003139 ::openolt::Group::GroupMembersCommand command = group_cfg->command();
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003140 switch(command) {
Girish Gowdra252f4972020-09-07 21:24:01 -07003141 case ::openolt::Group::SET_MEMBERS :
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003142 grp_mem_upd_cmd = BCMOLT_MEMBERS_UPDATE_COMMAND_SET;
3143 OPENOLT_LOG(INFO, openolt_log_id, "Setting %d members for Group %d.\n", members.len, group_id);
3144 break;
Girish Gowdra252f4972020-09-07 21:24:01 -07003145 case ::openolt::Group::ADD_MEMBERS :
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003146 grp_mem_upd_cmd = BCMOLT_MEMBERS_UPDATE_COMMAND_ADD;
3147 OPENOLT_LOG(INFO, openolt_log_id, "Adding %d members to Group %d.\n", members.len, group_id);
3148 break;
Girish Gowdra252f4972020-09-07 21:24:01 -07003149 case ::openolt::Group::REMOVE_MEMBERS :
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003150 grp_mem_upd_cmd = BCMOLT_MEMBERS_UPDATE_COMMAND_REMOVE;
3151 OPENOLT_LOG(INFO, openolt_log_id, "Removing %d members from Group %d.\n", members.len, group_id);
3152 break;
3153 default :
3154 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid value %d for group member command.\n", command);
3155 bcmos_free(members.arr);
3156 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid group member command");
3157 }
3158
3159 // SET MEMBERS LIST
3160 for (int i = 0; i < members.len; i++) {
3161
Girish Gowdra252f4972020-09-07 21:24:01 -07003162 if (command == ::openolt::Group::REMOVE_MEMBERS) {
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003163 OPENOLT_LOG(INFO, openolt_log_id, "Removing group member %d from group %d\n",i,key.id);
3164 } else {
3165 OPENOLT_LOG(INFO, openolt_log_id, "Adding group member %d to group %d\n",i,key.id);
3166 }
3167
Girish Gowdra252f4972020-09-07 21:24:01 -07003168 ::openolt::GroupMember *member = (::openolt::GroupMember *) &group_cfg->members()[i];
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003169
3170 // Set member interface type
Girish Gowdra252f4972020-09-07 21:24:01 -07003171 ::openolt::GroupMember::InterfaceType if_type = member->interface_type();
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003172 switch(if_type){
Girish Gowdra252f4972020-09-07 21:24:01 -07003173 case ::openolt::GroupMember::PON :
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003174 BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_type, BCMOLT_INTERFACE_TYPE_PON);
3175 OPENOLT_LOG(INFO, openolt_log_id, "Interface type PON is assigned to GroupMember %d\n",i);
3176 break;
Girish Gowdra252f4972020-09-07 21:24:01 -07003177 case ::openolt::GroupMember::EPON_1G_PATH :
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003178 BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_type, BCMOLT_INTERFACE_TYPE_EPON_1_G);
3179 OPENOLT_LOG(INFO, openolt_log_id, "Interface type EPON_1G is assigned to GroupMember %d\n",i);
3180 break;
Girish Gowdra252f4972020-09-07 21:24:01 -07003181 case ::openolt::GroupMember::EPON_10G_PATH :
Burak Gurdagc78b9e12019-11-29 11:14:51 +00003182 BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_type, BCMOLT_INTERFACE_TYPE_EPON_10_G);
3183 OPENOLT_LOG(INFO, openolt_log_id, "Interface type EPON_10G is assigned to GroupMember %d\n",i);
3184 break;
3185 default :
3186 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid interface type value %d for GroupMember %d.\n",if_type,i);
3187 bcmos_free(members.arr);
3188 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid interface type for a group member");
3189 }
3190
3191 // Set member interface id
3192 if (member->interface_id() >= 0) {
3193 BCMOLT_FIELD_SET(&interface_ref, intf_ref, intf_id, member->interface_id());
3194 OPENOLT_LOG(INFO, openolt_log_id, "Interface %d is assigned to GroupMember %d\n", member->interface_id(), i);
3195 } else {
3196 bcmos_free(members.arr);
3197 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid interface id for a group member");
3198 }
3199
3200 // Set member interface_ref
3201 BCMOLT_FIELD_SET(&member_info, group_member_info, intf, interface_ref);
3202
3203 // Set member gem_port_id. This must be a multicast gemport.
3204 if (member->gem_port_id() >= 0) {
3205 BCMOLT_FIELD_SET(&member_info, group_member_info, svc_port_id, member->gem_port_id());
3206 OPENOLT_LOG(INFO, openolt_log_id, "GEM Port %d is assigned to GroupMember %d\n", member->gem_port_id(), i);
3207 } else {
3208 bcmos_free(members.arr);
3209 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid gem port id for a group member");
3210 }
3211
3212 // Set member scheduler id and queue_id
3213 uint32_t tm_sched_id = get_default_tm_sched_id(member->interface_id(), downstream);
3214 OPENOLT_LOG(INFO, openolt_log_id, "Scheduler %d is assigned to GroupMember %d\n", tm_sched_id, i);
3215 BCMOLT_FIELD_SET(&tm_sched_ref, tm_sched_ref, id, tm_sched_id);
3216 BCMOLT_FIELD_SET(&egress_qos, egress_qos, tm_sched, tm_sched_ref);
3217
3218 // We assume that all multicast traffic destined to a PON port is using the same fixed queue.
3219 uint32_t tm_queue_id;
3220 if (member->priority() >= 0 && member->priority() < NUMBER_OF_DEFAULT_INTERFACE_QUEUES) {
3221 tm_queue_id = queue_id_list[member->priority()];
3222 OPENOLT_LOG(INFO, openolt_log_id, "Queue %d is assigned to GroupMember %d\n", tm_queue_id, i);
3223 BCMOLT_FIELD_SET(&egress_qos, egress_qos, type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE);
3224 BCMOLT_FIELD_SET(&egress_qos.u.fixed_queue, egress_qos_fixed_queue, queue_id, tm_queue_id);
3225 } else {
3226 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid fixed queue priority/ID %d for GroupMember %d\n", member->priority(), i);
3227 bcmos_free(members.arr);
3228 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid queue priority for a group member");
3229 }
3230
3231 BCMOLT_FIELD_SET(&member_info, group_member_info, egress_qos, egress_qos);
3232 BCMOLT_ARRAY_ELEM_SET(&(members), i, member_info);
3233 }
3234
3235 BCMOLT_OPER_INIT(&grp_mem_upd, group, members_update, key);
3236 BCMOLT_MSG_FIELD_SET(&grp_mem_upd, members_cmd.members, members);
3237 BCMOLT_MSG_FIELD_SET(&grp_mem_upd, members_cmd.command, grp_mem_upd_cmd);
3238
3239 err = bcmolt_oper_submit(dev_id, &(grp_mem_upd.hdr));
3240 bcmos_free(members.arr);
3241
3242 if (BCM_ERR_OK != err) {
3243 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);
3244 return bcm_to_grpc_err(err, "Failed to submit members update operation for the group");
3245 }
3246
3247 OPENOLT_LOG(INFO, openolt_log_id, "Successfully submitted members update operation for Group %d\n", key.id);
3248
3249 return Status::OK;
3250}
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003251
3252Status DeleteGroup_(uint32_t group_id) {
3253
3254 bcmos_errno err = BCM_ERR_OK;
3255 bcmolt_group_cfg grp_cfg_obj;
3256 bcmolt_group_key key = {};
3257
3258
3259 OPENOLT_LOG(INFO, openolt_log_id, "Delete request received for group %d\n", group_id);
3260
3261 if (group_id >= 0) {
3262 key.id = group_id;
3263 } else {
3264 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid group id %d.\n", group_id);
3265 return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid group id");
3266 }
3267
3268 /* init the BAL INIT API */
3269 BCMOLT_CFG_INIT(&grp_cfg_obj, group, key);
3270
3271 OPENOLT_LOG(DEBUG, openolt_log_id, "Checking if group %d exists...\n",group_id);
3272
3273 // CONFIGURE GROUP MEMBERS
3274 BCMOLT_FIELD_SET_PRESENT(&grp_cfg_obj.data, group_cfg_data, state);
3275 err = bcmolt_cfg_get(dev_id, &(grp_cfg_obj.hdr));
3276
3277 if (err != BCM_ERR_OK) {
3278 OPENOLT_LOG(ERROR, openolt_log_id, "Error in querying Group %d, err = %s\n", group_id, bcmos_strerror(err));
3279 return bcm_to_grpc_err(err, "Error in querying group");
3280 }
3281
3282 if (grp_cfg_obj.data.state != BCMOLT_GROUP_STATE_NOT_CONFIGURED) {
3283 OPENOLT_LOG(DEBUG, openolt_log_id, "Group %d exists. Will be deleted.\n",group_id);
3284 err = bcmolt_cfg_clear(dev_id, &(grp_cfg_obj.hdr));
3285 if (err != BCM_ERR_OK) {
3286 OPENOLT_LOG(ERROR, openolt_log_id, "Group %d cannot be deleted err = %s (%d).\n", group_id, bcmos_strerror(err), err);
3287 return bcm_to_grpc_err(err, "Failed to delete group");;
3288 }
3289 } else {
3290 OPENOLT_LOG(ERROR, openolt_log_id, "Group %d does not exist.\n", group_id);
3291 return Status(grpc::StatusCode::NOT_FOUND, "Group not found");
3292 }
3293
3294 OPENOLT_LOG(INFO, openolt_log_id, "Group %d has been deleted successfully.\n", group_id);
3295 return Status::OK;
Jason Huang1d9cfce2020-05-20 22:58:47 +08003296}
3297
Girish Gowdra252f4972020-09-07 21:24:01 -07003298Status GetLogicalOnuDistanceZero_(uint32_t intf_id, ::openolt::OnuLogicalDistance* response) {
Jason Huang1d9cfce2020-05-20 22:58:47 +08003299 bcmos_errno err = BCM_ERR_OK;
3300 uint32_t mld = 0;
3301 double LD0;
3302
3303 err = getOnuMaxLogicalDistance(intf_id, &mld);
3304 if (err != BCM_ERR_OK) {
3305 return bcm_to_grpc_err(err, "Failed to retrieve ONU maximum logical distance");
3306 }
3307
3308 LD0 = LOGICAL_DISTANCE(mld*1000, MINIMUM_ONU_RESPONSE_RANGING_TIME, ONU_BIT_TRANSMISSION_DELAY);
3309 OPENOLT_LOG(INFO, openolt_log_id, "The ONU logical distance zero is %f, (PON %d)\n", LD0, intf_id);
3310 response->set_intf_id(intf_id);
3311 response->set_logical_onu_distance_zero(LD0);
3312
3313 return Status::OK;
3314}
3315
Girish Gowdra252f4972020-09-07 21:24:01 -07003316Status GetLogicalOnuDistance_(uint32_t intf_id, uint32_t onu_id, ::openolt::OnuLogicalDistance* response) {
Jason Huang1d9cfce2020-05-20 22:58:47 +08003317 bcmos_errno err = BCM_ERR_OK;
3318 bcmolt_itu_onu_params itu = {};
3319 bcmolt_onu_cfg onu_cfg;
3320 bcmolt_onu_key onu_key = {};
3321 uint32_t mld = 0;
3322 double LDi;
3323
3324 onu_key.pon_ni = intf_id;
3325 onu_key.onu_id = onu_id;
3326
3327 err = getOnuMaxLogicalDistance(intf_id, &mld);
3328 if (err != BCM_ERR_OK) {
3329 return bcm_to_grpc_err(err, "Failed to retrieve ONU maximum logical distance");
3330 }
3331
3332 /* Initialize the API struct. */
3333 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3334 BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
3335 BCMOLT_FIELD_SET_PRESENT(&itu, itu_onu_params, ranging_time);
3336 BCMOLT_FIELD_SET(&onu_cfg.data, onu_cfg_data, itu, itu);
3337 #ifdef TEST_MODE
3338 // It is impossible to mock the setting of onu_cfg.data.onu_state because
3339 // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot
3340 // set the onu_cfg.data.onu_state. So a new stub function is created and address
3341 // of onu_cfg is passed. This is one-of case where we need to add test specific
3342 // code in production code.
3343 err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg);
3344 #else
3345 /* Call API function. */
3346 err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
3347 #endif
3348 if (err != BCM_ERR_OK) {
3349 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);
3350 return bcm_to_grpc_err(err, "Failed to retrieve ONU ranging time");
3351 }
3352
3353 if (onu_cfg.data.onu_state != BCMOLT_ONU_STATE_ACTIVE) {
3354 OPENOLT_LOG(ERROR, openolt_log_id, "ONU is not yet activated (PON %d, ONU id %d)\n", intf_id, onu_id);
3355 return bcm_to_grpc_err(BCM_ERR_PARM, "ONU is not yet activated\n");
3356 }
3357
3358 LDi = LOGICAL_DISTANCE(mld*1000, onu_cfg.data.itu.ranging_time, ONU_BIT_TRANSMISSION_DELAY);
3359 OPENOLT_LOG(INFO, openolt_log_id, "The ONU logical distance is %f, (PON %d, ONU id %d)\n", LDi, intf_id, onu_id);
3360 response->set_intf_id(intf_id);
3361 response->set_onu_id(onu_id);
3362 response->set_logical_onu_distance(LDi);
3363
3364 return Status::OK;
3365}
Burak Gurdag74e3ab82020-12-17 13:35:06 +00003366
3367Status GetOnuStatistics_(uint32_t intf_id, uint32_t onu_id, openolt::OnuStatistics* onu_stats) {
3368 bcmos_errno err;
3369
3370 err = get_onu_statistics((bcmolt_interface_id)intf_id, (bcmolt_onu_id)onu_id, onu_stats);
3371
3372 if (err != BCM_ERR_OK) {
3373 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));
3374 return grpc::Status(grpc::StatusCode::INTERNAL, "retrieval of ONU statistics failed");
3375 }
3376
3377 OPENOLT_LOG(INFO, openolt_log_id, "retrieved ONU statistics for PON ID = %d, ONU ID = %d\n", (int)intf_id, (int)onu_id);
3378 return Status::OK;
3379}
3380
3381Status GetGemPortStatistics_(uint32_t intf_id, uint32_t gemport_id, openolt::GemPortStatistics* gemport_stats) {
3382 bcmos_errno err;
3383
3384 err = get_gemport_statistics((bcmolt_interface_id)intf_id, (bcmolt_gem_port_id)gemport_id, gemport_stats);
3385
3386 if (err != BCM_ERR_OK) {
3387 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));
3388 return grpc::Status(grpc::StatusCode::INTERNAL, "retrieval of GEMPORT statistics failed");
3389 }
3390
3391 OPENOLT_LOG(INFO, openolt_log_id, "retrieved GEMPORT statistics for PON ID = %d, GEMPORT ID = %d\n", (int)intf_id, (int)gemport_id);
3392 return Status::OK;
3393}
Orhan Kupusogluec57af02021-05-12 12:38:17 +00003394
3395Status GetPonRxPower_(uint32_t intf_id, uint32_t onu_id, openolt::PonRxPowerData* response) {
3396 bcmos_errno err = BCM_ERR_OK;
3397
3398 // check the PON intf id
3399 if (intf_id >= MAX_SUPPORTED_PON) {
3400 err = BCM_ERR_PARM;
3401 OPENOLT_LOG(ERROR, openolt_log_id, "invalid pon intf_id - intf_id: %d, onu_id: %d\n",
3402 intf_id, onu_id);
3403 return bcm_to_grpc_err(err, "invalid pon intf_id");
3404 }
3405
3406 bcmolt_onu_rssi_measurement onu_oper; /* declare main API struct */
3407 bcmolt_onu_key onu_key; /**< Object key. */
3408 onu_rssi_compltd_key key(intf_id, onu_id);
3409 Queue<onu_rssi_complete_result> queue;
3410
3411 OPENOLT_LOG(INFO, openolt_log_id, "GetPonRxPower - intf_id %d, onu_id %d\n", intf_id, onu_id);
3412
3413 onu_key.onu_id = onu_id;
3414 onu_key.pon_ni = intf_id;
3415 /* Initialize the API struct. */
3416 BCMOLT_OPER_INIT(&onu_oper, onu, rssi_measurement, onu_key);
3417 err = bcmolt_oper_submit(dev_id, &onu_oper.hdr);
3418 if (err == BCM_ERR_OK) {
3419 // initialize map
3420 bcmos_fastlock_lock(&onu_rssi_wait_lock);
3421 onu_rssi_compltd_map.insert({key, &queue});
3422 bcmos_fastlock_unlock(&onu_rssi_wait_lock, 0);
3423 } else {
3424 OPENOLT_LOG(ERROR, openolt_log_id, "failed to measure rssi rx power - intf_id: %d, onu_id: %d, err = %s (%d): %s\n",
3425 intf_id, onu_id, bcmos_strerror(err), err, onu_oper.hdr.hdr.err_text);
3426 return bcm_to_grpc_err(err, "failed to measure rssi rx power");
3427 }
3428
3429 onu_rssi_complete_result completed{};
3430 if (!queue.pop(completed, ONU_RSSI_COMPLETE_WAIT_TIMEOUT)) {
3431 // invalidate the queue pointer
3432 bcmos_fastlock_lock(&onu_rssi_wait_lock);
3433 onu_rssi_compltd_map[key] = NULL;
3434 bcmos_fastlock_unlock(&onu_rssi_wait_lock, 0);
3435 err = BCM_ERR_TIMEOUT;
3436 OPENOLT_LOG(ERROR, openolt_log_id, "timeout waiting for RSSI Measurement Completed indication intf_id %d, onu_id %d\n",
3437 intf_id, onu_id);
3438 } else {
3439 OPENOLT_LOG(INFO, openolt_log_id, "RSSI Rx power - intf_id: %d, onu_id: %d, status: %s, fail_reason: %d, rx_power_mean_dbm: %f\n",
3440 completed.pon_intf_id, completed.onu_id, completed.status.c_str(), completed.reason, completed.rx_power_mean_dbm);
3441
3442 response->set_intf_id(completed.pon_intf_id);
3443 response->set_onu_id(completed.onu_id);
3444 response->set_status(completed.status);
3445 response->set_fail_reason(static_cast<::openolt::PonRxPowerData_RssiMeasurementFailReason>(completed.reason));
3446 response->set_rx_power_mean_dbm(completed.rx_power_mean_dbm);
3447 }
3448
3449 // Remove entry from map
3450 bcmos_fastlock_lock(&onu_rssi_wait_lock);
3451 onu_rssi_compltd_map.erase(key);
3452 bcmos_fastlock_unlock(&onu_rssi_wait_lock, 0);
3453
3454 if (err == BCM_ERR_OK) {
3455 return Status::OK;
3456 } else {
3457 return bcm_to_grpc_err(err, "timeout waiting for pon rssi measurement complete indication");
3458 }
3459}