blob: 238ce9611b59ea70e71276eefff189142820b887 [file] [log] [blame]
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001/*
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04002 Copyright (C) 2018 Open Networking Foundation
Shad Ansarib7b0ced2018-05-11 21:53:32 +00003
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <iostream>
19#include <memory>
20#include <string>
21
22#include "Queue.h"
23#include <iostream>
24#include <sstream>
Nicolas Palpacuer9c352082018-08-14 16:37:14 -040025#include <chrono>
26#include <thread>
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080027#include <bitset>
Jason Huangd33b4d82019-05-15 18:22:57 +080028#include <inttypes.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000029
Craig Lutgen88a22ad2018-10-04 12:30:46 -050030#include "device.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000031#include "core.h"
32#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040033#include "stats_collection.h"
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040034#include "error_format.h"
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040035#include "state.h"
Craig Lutgen88a22ad2018-10-04 12:30:46 -050036#include "utils.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000037
38extern "C"
39{
Jason Huangd33b4d82019-05-15 18:22:57 +080040#include <bcmolt_api.h>
41#include <bcmolt_host_api.h>
42#include <bcmolt_api_model_supporting_enums.h>
43#include <bal_version.h>
44#include <bcmolt_api_conn_mgr.h>
45//CLI header files
46#include <bcmcli_session.h>
47#include <bcmcli.h>
48#include <bcm_api_cli.h>
49#include <bcmos_common.h>
50#include <bcm_config.h>
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -040051// FIXME : dependency problem
52// #include <bcm_common_gpon.h>
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040053// #include <bcm_dev_log_task.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000054}
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040055dev_log_id openolt_log_id = bcm_dev_log_id_register("OPENOLT", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
56dev_log_id omci_log_id = bcm_dev_log_id_register("OMCI", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
57
Craig Lutgen88a22ad2018-10-04 12:30:46 -050058#define MAX_SUPPORTED_INTF 16
59#define BAL_RSC_MANAGER_BASE_TM_SCHED_ID 16384
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080060#define MAX_TM_QUEUE_ID 8192
Jason Huangb6843dc2019-07-22 17:46:06 +080061#define MAX_TM_SCHED_ID 4075
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080062#define EAP_ETHER_TYPE 34958
Jason Huangb6843dc2019-07-22 17:46:06 +080063#define XGS_BANDWIDTH_GRANULARITY 16000
64#define GPON_BANDWIDTH_GRANULARITY 32000
65#define FILL_ARRAY(ARRAY,START,END,VALUE) for(int i=START;i<END;ARRAY[i++]=VALUE);
66
67#define GET_FLOW_INTERFACE_TYPE(type) \
68 (type == BCMOLT_FLOW_INTERFACE_TYPE_PON) ? "PON" : \
69 (type == BCMOLT_FLOW_INTERFACE_TYPE_NNI) ? "NNI" : \
70 (type == BCMOLT_FLOW_INTERFACE_TYPE_HOST) ? "HOST" : "unknown"
71#define GET_PKT_TAG_TYPE(type) \
72 (type == BCMOLT_PKT_TAG_TYPE_UNTAGGED) ? "UNTAG" : \
73 (type == BCMOLT_PKT_TAG_TYPE_SINGLE_TAG) ? "SINGLE_TAG" : \
74 (type == BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG) ? "DOUBLE_TAG" : "unknown"
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040075
Craig Lutgen88a22ad2018-10-04 12:30:46 -050076static unsigned int num_of_nni_ports = 0;
77static unsigned int num_of_pon_ports = 0;
Craig Lutgenb2601f02018-10-23 13:04:31 -050078static std::string intf_technologies[MAX_SUPPORTED_INTF];
Craig Lutgen88a22ad2018-10-04 12:30:46 -050079static const std::string UNKNOWN_TECH("unknown");
Craig Lutgenb2601f02018-10-23 13:04:31 -050080static const std::string MIXED_TECH("mixed");
81static std::string board_technology(UNKNOWN_TECH);
Jason Huangd33b4d82019-05-15 18:22:57 +080082static std::string chip_family(UNKNOWN_TECH);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -080083static unsigned int OPENOLT_FIELD_LEN = 200;
Jason Huangb6843dc2019-07-22 17:46:06 +080084static std::string firmware_version = "Openolt.2019.07.01";
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040085
Jason Huangb6843dc2019-07-22 17:46:06 +080086const uint32_t tm_upstream_sched_id_start = 4092;
87const uint32_t tm_downstream_sched_id_start = 4076;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080088//0 to 3 are default queues. Lets not use them.
89const uint32_t tm_queue_id_start = 4;
90// Upto 8 fixed Upstream. Queue id 0 to 3 are pre-created, lets not use them.
91const uint32_t us_fixed_queue_id_list[8] = {4, 5, 6, 7, 8, 9, 10, 11};
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -070092const std::string upstream = "upstream";
93const std::string downstream = "downstream";
Jason Huangd33b4d82019-05-15 18:22:57 +080094bcmolt_oltid dev_id = 0;
95/* Current session */
96static bcmcli_session *current_session;
97static bcmcli_entry *api_parent_dir;
98bcmos_bool status_bcm_cli_quit = BCMOS_FALSE;
99bcmos_task bal_cli_thread;
100const char *bal_cli_thread_name = "bal_cli_thread";
Jason Huangb6843dc2019-07-22 17:46:06 +0800101uint16_t flow_id_counters = 0;
102int flow_id_data[16384][2];
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700103
Shad Ansariedef2132018-08-10 22:14:50 +0000104State state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400105
Craig Lutgen967a1d02018-11-27 10:41:51 -0600106static std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports
107static std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports
108static std::map<uint32_t, std::set<uint32_t> > port_to_flows; // For mapping logical ports to downstream flows
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800109
110// This represents the Key to 'queue_map' map.
111// Represents (pon_intf_id, onu_id, uni_id, gemport_id, direction)
112typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, std::string> queue_map_key_tuple;
113// 'queue_map' maps queue_map_key_tuple to downstream queue id present
114// on the Subscriber Scheduler
115static std::map<queue_map_key_tuple, int> queue_map;
116// This represents the Key to 'sched_map' map.
117// Represents (pon_intf_id, onu_id, uni_id, direction)
118
119typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string> sched_map_key_tuple;
120// 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or
121// Subscriber (Downstream) Scheduler ID
122static std::map<sched_map_key_tuple, int> sched_map;
123
124
125std::bitset<MAX_TM_QUEUE_ID> tm_queue_bitset;
126std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
127
128static bcmos_fastlock data_lock;
Craig Lutgen967a1d02018-11-27 10:41:51 -0600129
130#define MIN_ALLOC_ID_GPON 256
131#define MIN_ALLOC_ID_XGSPON 1024
132
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800133static bcmos_errno CreateSched(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
134 uint32_t port_no, uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, \
135 uint32_t priority, tech_profile::SchedulingPolicy sched_policy,
136 tech_profile::TrafficShapingInfo traffic_shaping_info);
Jason Huangb6843dc2019-07-22 17:46:06 +0800137static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800138static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
139 uint32_t priority, uint32_t gemport_id);
140static bcmos_errno RemoveQueue(std::string direction, int intf_id, int onu_id, int uni_id, uint32_t port_no, int alloc_id);
Shad Ansari627b5782018-08-13 22:49:32 +0000141
Jason Huangd33b4d82019-05-15 18:22:57 +0800142uint16_t get_dev_id(void) {
143 return dev_id;
144}
145
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800146/**
147* Returns the default NNI (Upstream direction) or PON (Downstream direction) scheduler
148* Every NNI port and PON port have default scheduler.
149* The NNI0 default scheduler ID is 18432, and NNI1 is 18433 and so on.
150* Similarly, PON0 default scheduler ID is 16384. PON1 is 16385 and so on.
151*
152* @param intf_id NNI or PON interface ID
153* @param direction "upstream" or "downstream"
154*
155* @return default scheduler ID for the given interface.
156*/
157static inline int get_default_tm_sched_id(int intf_id, std::string direction) {
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700158 if (direction.compare(upstream) == 0) {
159 return tm_upstream_sched_id_start + intf_id;
160 } else if (direction.compare(downstream) == 0) {
161 return tm_downstream_sched_id_start + intf_id;
162 }
163 else {
Jason Huangb6843dc2019-07-22 17:46:06 +0800164 OPENOLT_LOG(ERROR, openolt_log_id, "invalid direction - %s\n", direction.c_str());
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700165 return 0;
166 }
167}
168
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800169/**
170* Gets a unique tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction
171* The tm_queue_id is locally cached in a map, so that it can rendered when necessary.
172* VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem
173*
174* @param intf_id NNI or PON intf ID
175* @param onu_id ONU ID
176* @param uni_id UNI ID
177* @param gemport_id GEM Port ID
178* @param direction Upstream or downstream
179*
180* @return tm_queue_id
181*/
182int get_tm_queue_id(int intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) {
183 queue_map_key_tuple key(intf_id, onu_id, uni_id, gemport_id, direction);
184 int queue_id = -1;
Craig Lutgen967a1d02018-11-27 10:41:51 -0600185
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800186 std::map<queue_map_key_tuple, int>::const_iterator it = queue_map.find(key);
187 if (it != queue_map.end()) {
188 queue_id = it->second;
189 }
190 if (queue_id != -1) {
191 return queue_id;
192 }
193
194 bcmos_fastlock_lock(&data_lock);
195 // Complexity of O(n). Is there better way that can avoid linear search?
196 for (queue_id = 0; queue_id < MAX_TM_QUEUE_ID; queue_id++) {
197 if (tm_queue_bitset[queue_id] == 0) {
198 tm_queue_bitset[queue_id] = 1;
199 break;
200 }
201 }
202 bcmos_fastlock_unlock(&data_lock, 0);
203
204 if (queue_id < MAX_TM_QUEUE_ID) {
205 bcmos_fastlock_lock(&data_lock);
206 queue_map[key] = queue_id;
207 bcmos_fastlock_unlock(&data_lock, 0);
208 return queue_id;
209 } else {
210 return -1;
211 }
Shad Ansari627b5782018-08-13 22:49:32 +0000212}
213
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800214/**
215* Update tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction
216*
217* @param intf_id NNI or PON intf ID
218* @param onu_id ONU ID
219* @param uni_id UNI ID
220* @param gemport_id GEM Port ID
221* @param direction Upstream or downstream
222* @param tm_queue_id tm_queue_id
223*/
224void update_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction,
225 uint32_t queue_id) {
226 queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction);
227 bcmos_fastlock_lock(&data_lock);
228 queue_map[key] = queue_id;
229 bcmos_fastlock_unlock(&data_lock, 0);
230}
231
232/**
233* Free tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction
234*
235* @param intf_id NNI or PON intf ID
236* @param onu_id ONU ID
237* @param uni_id UNI ID
238* @param gemport_id GEM Port ID
239* @param direction Upstream or downstream
240*/
241void free_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) {
242 queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction);
243 std::map<queue_map_key_tuple, int>::const_iterator it;
244 bcmos_fastlock_lock(&data_lock);
245 it = queue_map.find(key);
246 if (it != queue_map.end()) {
247 tm_queue_bitset[it->second] = 0;
248 queue_map.erase(it);
249 }
250 bcmos_fastlock_unlock(&data_lock, 0);
251}
252
253/**
254* Gets a unique tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction
255* The tm_sched_id is locally cached in a map, so that it can rendered when necessary.
256* VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem
257*
258* @param intf_id NNI or PON intf ID
259* @param onu_id ONU ID
260* @param uni_id UNI ID
261* @param gemport_id GEM Port ID
262* @param direction Upstream or downstream
263*
264* @return tm_sched_id
265*/
266uint32_t get_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) {
267 sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction);
268 int sched_id = -1;
269
270 std::map<sched_map_key_tuple, int>::const_iterator it = sched_map.find(key);
271 if (it != sched_map.end()) {
272 sched_id = it->second;
273 }
274 if (sched_id != -1) {
275 return sched_id;
276 }
277
278 bcmos_fastlock_lock(&data_lock);
279 // Complexity of O(n). Is there better way that can avoid linear search?
280 for (sched_id = 0; sched_id < MAX_TM_SCHED_ID; sched_id++) {
281 if (tm_sched_bitset[sched_id] == 0) {
282 tm_sched_bitset[sched_id] = 1;
283 break;
284 }
285 }
286 bcmos_fastlock_unlock(&data_lock, 0);
287
288 if (sched_id < MAX_TM_SCHED_ID) {
289 bcmos_fastlock_lock(&data_lock);
290 sched_map[key] = sched_id;
291 bcmos_fastlock_unlock(&data_lock, 0);
292 return sched_id;
293 } else {
294 return -1;
295 }
296}
297
298/**
299* Free tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction
300*
301* @param intf_id NNI or PON intf ID
302* @param onu_id ONU ID
303* @param uni_id UNI ID
304* @param gemport_id GEM Port ID
305* @param direction Upstream or downstream
306*/
307void free_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) {
308 sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction);
309 std::map<sched_map_key_tuple, int>::const_iterator it;
310 bcmos_fastlock_lock(&data_lock);
311 it = sched_map.find(key);
312 if (it != sched_map.end()) {
313 tm_sched_bitset[it->second] = 0;
314 sched_map.erase(it);
315 }
316 bcmos_fastlock_unlock(&data_lock, 0);
317}
318
319bool is_tm_sched_id_present(int pon_intf_id, int onu_id, int uni_id, std::string direction) {
320 sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction);
321 return sched_map.count(key) > 0 ? true: false;
322}
323
324bool is_tm_queue_id_present(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) {
325 queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction);
326 return queue_map.count(key) > 0 ? true: false;
Shad Ansari627b5782018-08-13 22:49:32 +0000327}
328
Jason Huangb6843dc2019-07-22 17:46:06 +0800329inline const char *get_flow_acton_command(uint32_t command) {
330 char actions[200] = { };
331 char *s_actions_ptr = actions;
332 if (command & BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG) strcat(s_actions_ptr, "ADD_OUTER_TAG|");
333 if (command & BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG) strcat(s_actions_ptr, "REMOVE_OUTER_TAG|");
334 if (command & BCMOLT_ACTION_CMD_ID_XLATE_OUTER_TAG) strcat(s_actions_ptr, "TRANSLATE_OUTER_TAG|");
335 if (command & BCMOLT_ACTION_CMD_ID_ADD_INNER_TAG) strcat(s_actions_ptr, "ADD_INNTER_TAG|");
336 if (command & BCMOLT_ACTION_CMD_ID_REMOVE_INNER_TAG) strcat(s_actions_ptr, "REMOVE_INNER_TAG|");
337 if (command & BCMOLT_ACTION_CMD_ID_XLATE_INNER_TAG) strcat(s_actions_ptr, "TRANSLATE_INNER_TAG|");
338 if (command & BCMOLT_ACTION_CMD_ID_REMARK_OUTER_PBITS) strcat(s_actions_ptr, "REMOVE_OUTER_PBITS|");
339 if (command & BCMOLT_ACTION_CMD_ID_REMARK_INNER_PBITS) strcat(s_actions_ptr, "REMAKE_INNER_PBITS|");
340 return s_actions_ptr;
341}
342
Jason Huang88795222019-06-13 19:28:44 +0800343char* openolt_read_sysinfo(const char* field_name, char* field_val)
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800344{
345 FILE *fp;
346 /* Prepare the command*/
347 char command[150];
348
349 snprintf(command, sizeof command, "bash -l -c \"onlpdump -s\" | perl -ne 'print $1 if /%s: (\\S+)/'", field_name);
350 /* Open the command for reading. */
351 fp = popen(command, "r");
352 if (fp == NULL) {
353 /*The client has to check for a Null field value in this case*/
Jason Huangb6843dc2019-07-22 17:46:06 +0800354 OPENOLT_LOG(INFO, openolt_log_id, "Failed to query the %s\n", field_name);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800355 return field_val;
356 }
357
358 /*Read the field value*/
359 if (fp) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800360 uint8_t ret;
361 ret = fread(field_val, OPENOLT_FIELD_LEN, 1, fp);
362 if (ret >= OPENOLT_FIELD_LEN)
Jason Huangb6843dc2019-07-22 17:46:06 +0800363 OPENOLT_LOG(INFO, openolt_log_id, "Read data length %u\n", ret);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800364 pclose(fp);
365 }
366 return field_val;
367}
368
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400369Status GetDeviceInfo_(openolt::DeviceInfo* device_info) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500370 device_info->set_vendor(VENDOR_ID);
371 device_info->set_model(MODEL_ID);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400372 device_info->set_hardware_version("");
373 device_info->set_firmware_version(firmware_version);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500374 device_info->set_technology(board_technology);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500375 device_info->set_pon_ports(num_of_pon_ports);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500376
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800377 char serial_number[OPENOLT_FIELD_LEN];
378 memset(serial_number, '\0', OPENOLT_FIELD_LEN);
379 openolt_read_sysinfo("Serial Number", serial_number);
Jason Huangb6843dc2019-07-22 17:46:06 +0800380 OPENOLT_LOG(INFO, openolt_log_id, "Fetched device serial number %s\n", serial_number);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800381 device_info->set_device_serial_number(serial_number);
382
Craig Lutgenb2601f02018-10-23 13:04:31 -0500383 // Legacy, device-wide ranges. To be deprecated when adapter
384 // is upgraded to support per-interface ranges
Jason Huangb1fad572019-05-28 19:02:30 +0800385 if (board_technology == "XGS-PON") {
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500386 device_info->set_onu_id_start(1);
387 device_info->set_onu_id_end(255);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600388 device_info->set_alloc_id_start(MIN_ALLOC_ID_XGSPON);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500389 device_info->set_alloc_id_end(16383);
390 device_info->set_gemport_id_start(1024);
391 device_info->set_gemport_id_end(65535);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500392 device_info->set_flow_id_start(1);
393 device_info->set_flow_id_end(16383);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500394 }
Jason Huangd33b4d82019-05-15 18:22:57 +0800395 else if (board_technology == "GPON") {
Craig Lutgenb2601f02018-10-23 13:04:31 -0500396 device_info->set_onu_id_start(1);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500397 device_info->set_onu_id_end(127);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600398 device_info->set_alloc_id_start(MIN_ALLOC_ID_GPON);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500399 device_info->set_alloc_id_end(767);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500400 device_info->set_gemport_id_start(256);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500401 device_info->set_gemport_id_end(4095);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500402 device_info->set_flow_id_start(1);
403 device_info->set_flow_id_end(16383);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500404 }
Craig Lutgenb2601f02018-10-23 13:04:31 -0500405
406 std::map<std::string, openolt::DeviceInfo::DeviceResourceRanges*> ranges;
407 for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) {
408 std::string intf_technology = intf_technologies[intf_id];
409 openolt::DeviceInfo::DeviceResourceRanges *range = ranges[intf_technology];
410 if(range == nullptr) {
411 range = device_info->add_ranges();
412 ranges[intf_technology] = range;
413 range->set_technology(intf_technology);
414
Jason Huangb6843dc2019-07-22 17:46:06 +0800415 if (intf_technology == "XGS-PON") {
Craig Lutgenb2601f02018-10-23 13:04:31 -0500416 openolt::DeviceInfo::DeviceResourceRanges::Pool* pool;
417
418 pool = range->add_pools();
419 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID);
420 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
421 pool->set_start(1);
422 pool->set_end(255);
423
424 pool = range->add_pools();
425 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID);
426 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH);
427 pool->set_start(1024);
428 pool->set_end(16383);
429
430 pool = range->add_pools();
431 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID);
432 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
433 pool->set_start(1024);
434 pool->set_end(65535);
435
436 pool = range->add_pools();
437 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID);
438 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
439 pool->set_start(1);
440 pool->set_end(16383);
441 }
Jason Huangb6843dc2019-07-22 17:46:06 +0800442 else if (intf_technology == "GPON") {
Craig Lutgenb2601f02018-10-23 13:04:31 -0500443 openolt::DeviceInfo::DeviceResourceRanges::Pool* pool;
444
445 pool = range->add_pools();
446 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID);
447 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
448 pool->set_start(1);
449 pool->set_end(127);
450
451 pool = range->add_pools();
452 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID);
453 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH);
454 pool->set_start(256);
455 pool->set_end(757);
456
457 pool = range->add_pools();
458 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID);
459 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
460 pool->set_start(256);
461 pool->set_end(4095);
462
463 pool = range->add_pools();
464 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID);
465 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
466 pool->set_start(1);
467 pool->set_end(16383);
468 }
469 }
470
471 range->add_intf_ids(intf_id);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500472 }
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400473
474 // FIXME: Once dependency problem is fixed
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500475 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400476 // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1);
477 // device_info->set_alloc_id_start(1024);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500478 // device_info->set_alloc_id_end(XGPON_NUM_OF_ALLOC_IDS * num_of_pon_ports ? - 1);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400479 // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500480 // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1);
481 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400482
483 return Status::OK;
484}
485
Jason Huang88795222019-06-13 19:28:44 +0800486Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state)
487{
Jason Huangb6843dc2019-07-22 17:46:06 +0800488 openolt::Indication ind;
489 openolt::IntfOperIndication* intf_oper_ind = new openolt::IntfOperIndication;
Jason Huang88795222019-06-13 19:28:44 +0800490
Jason Huangb6843dc2019-07-22 17:46:06 +0800491 intf_oper_ind->set_type(type);
492 intf_oper_ind->set_intf_id(intf_id);
493 intf_oper_ind->set_oper_state(state);
494 ind.set_allocated_intf_oper_ind(intf_oper_ind);
495 oltIndQ.push(ind);
Jason Huang88795222019-06-13 19:28:44 +0800496 return Status::OK;
497}
498
Jason Huangd33b4d82019-05-15 18:22:57 +0800499#define CLI_HOST_PROMPT_FORMAT "BCM.%u> "
500
501/* Build CLI prompt */
502static void openolt_cli_get_prompt_cb(bcmcli_session *session, char *buf, uint32_t max_len)
503{
504 snprintf(buf, max_len, CLI_HOST_PROMPT_FORMAT, dev_id);
505}
506
507static int _bal_apiend_cli_thread_handler(long data)
508{
509 char init_string[]="\n";
510 bcmcli_session *sess = current_session;
511 bcmos_task_parm bal_cli_task_p_dummy;
Jason Huangb6843dc2019-07-22 17:46:06 +0800512
Jason Huangd33b4d82019-05-15 18:22:57 +0800513 /* Switch to interactive mode if not stopped in the init script */
514 if (!bcmcli_is_stopped(sess))
515 {
516 /* Force a CLI command prompt
517 * The string passed into the parse function
518 * must be modifiable, so a string constant like
519 * bcmcli_parse(current_session, "\n") will not
520 * work.
521 */
522 bcmcli_parse(sess, init_string);
Jason Huangb6843dc2019-07-22 17:46:06 +0800523
Jason Huangd33b4d82019-05-15 18:22:57 +0800524 /* Process user input until EOF or quit command */
525 bcmcli_driver(sess);
526 };
Jason Huangb6843dc2019-07-22 17:46:06 +0800527 OPENOLT_LOG(INFO, openolt_log_id, "BAL API End CLI terminated\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800528
529 /* Cleanup */
530 bcmcli_session_close(current_session);
Jason Huangb6843dc2019-07-22 17:46:06 +0800531 bcmcli_token_destroy(NULL);
Jason Huangd33b4d82019-05-15 18:22:57 +0800532 return 0;
533}
534
535/* Init API CLI commands for the current device */
536bcmos_errno bcm_openolt_api_cli_init(bcmcli_entry *parent_dir, bcmcli_session *session)
537{
538 bcmos_errno rc;
539
540 api_parent_dir = parent_dir;
541
542 rc = bcm_api_cli_set_commands(session);
543
544#ifdef BCM_SUBSYSTEM_HOST
545 /* Subscribe for device change indication */
546 rc = rc ? rc : bcmolt_olt_sel_ind_register(_api_cli_olt_change_ind);
547#endif
548
549 return rc;
550}
551
552static bcmos_errno bcm_cli_quit(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms)
553{
554 bcmcli_stop(session);
555 bcmcli_session_print(session, "CLI terminated by 'Quit' command\n");
556 status_bcm_cli_quit = BCMOS_TRUE;
557
558 return BCM_ERR_OK;
559}
560
561int get_status_bcm_cli_quit(void) {
562 return status_bcm_cli_quit;
563}
564
565bcmos_errno bcmolt_apiend_cli_init() {
566 bcmos_errno ret;
567 bcmos_task_parm bal_cli_task_p = {};
568 bcmos_task_parm bal_cli_task_p_dummy;
569
570 /** before creating the task, check if it is already created by the other half of BAL i.e. Core side */
571 if (BCM_ERR_OK != bcmos_task_query(&bal_cli_thread, &bal_cli_task_p_dummy))
572 {
573 /* Create BAL CLI thread */
574 bal_cli_task_p.name = bal_cli_thread_name;
575 bal_cli_task_p.handler = _bal_apiend_cli_thread_handler;
576 bal_cli_task_p.priority = TASK_PRIORITY_CLI;
Jason Huangb6843dc2019-07-22 17:46:06 +0800577
Jason Huangd33b4d82019-05-15 18:22:57 +0800578 ret = bcmos_task_create(&bal_cli_thread, &bal_cli_task_p);
579 if (BCM_ERR_OK != ret)
580 {
581 bcmos_printf("Couldn't create BAL API end CLI thread\n");
582 return ret;
583 }
584 }
585}
586
Shad Ansari627b5782018-08-13 22:49:32 +0000587Status Enable_(int argc, char *argv[]) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800588 bcmos_errno err;
589 bcmolt_host_init_parms init_parms = {};
590 init_parms.transport.type = BCM_HOST_API_CONN_LOCAL;
591 bcmcli_session_parm mon_session_parm;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000592
Shad Ansariedef2132018-08-10 22:14:50 +0000593 if (!state.is_activated()) {
Shad Ansari627b5782018-08-13 22:49:32 +0000594
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500595 vendor_init();
Jason Huangd33b4d82019-05-15 18:22:57 +0800596 /* Initialize host subsystem */
597 err = bcmolt_host_init(&init_parms);
598 if (BCM_ERR_OK != err) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800599 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to init OLT\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800600 return bcm_to_grpc_err(err, "Failed to init OLT");
601 }
Craig Lutgen967a1d02018-11-27 10:41:51 -0600602
Jason Huangd33b4d82019-05-15 18:22:57 +0800603 /* Create CLI session */
604 memset(&mon_session_parm, 0, sizeof(mon_session_parm));
605 mon_session_parm.get_prompt = openolt_cli_get_prompt_cb;
606 mon_session_parm.access_right = BCMCLI_ACCESS_ADMIN;
607 bcmos_errno rc = bcmcli_session_open(&mon_session_parm, &current_session);
608 BUG_ON(rc != BCM_ERR_OK);
609
610 /* API CLI */
611 bcm_openolt_api_cli_init(NULL, current_session);
612
613 /* Add quit command */
614 BCMCLI_MAKE_CMD_NOPARM(NULL, "quit", "Quit", bcm_cli_quit);
615
616 err = bcmolt_apiend_cli_init();
617 if (BCM_ERR_OK != err) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800618 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to add apiend init\n");
Jason Huangd33b4d82019-05-15 18:22:57 +0800619 return bcm_to_grpc_err(err, "Failed to add apiend init");
620 }
621
622 bcmos_fastlock_init(&data_lock, 0);
Jason Huangb6843dc2019-07-22 17:46:06 +0800623 OPENOLT_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500624
Jason Huangd33b4d82019-05-15 18:22:57 +0800625 if (bcmolt_api_conn_mgr_is_connected(dev_id))
626 {
627 Status status = SubscribeIndication();
628 if (!status.ok()) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800629 OPENOLT_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +0800630 grpc_status_code_to_string(status.error_code()).c_str(),
631 status.error_message().c_str());
Jason Huangd33b4d82019-05-15 18:22:57 +0800632 return status;
633 }
634 bcmos_errno err;
635 bcmolt_odid dev;
Jason Huangb6843dc2019-07-22 17:46:06 +0800636 OPENOLT_LOG(INFO, openolt_log_id, "Enabling PON %d Devices ... \n", BCM_MAX_DEVS_PER_LINE_CARD);
Jason Huangd33b4d82019-05-15 18:22:57 +0800637 for (dev = 0; dev < BCM_MAX_DEVS_PER_LINE_CARD; dev++) {
638 bcmolt_device_cfg dev_cfg = { };
639 bcmolt_device_key dev_key = { };
640 dev_key.device_id = dev;
641 BCMOLT_CFG_INIT(&dev_cfg, device, dev_key);
642 BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode);
643 err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr);
644 if (err == BCM_ERR_NOT_CONNECTED) {
645 bcmolt_device_key key = {.device_id = dev};
646 bcmolt_device_connect oper;
Jason Huangd33b4d82019-05-15 18:22:57 +0800647 BCMOLT_OPER_INIT(&oper, device, connect, key);
648 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI);
Jason Huangb1fad572019-05-28 19:02:30 +0800649 BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_XGS__2_X);
Jason Huangd33b4d82019-05-15 18:22:57 +0800650 err = bcmolt_oper_submit(dev_id, &oper.hdr);
651 if (err)
Jason Huangb6843dc2019-07-22 17:46:06 +0800652 OPENOLT_LOG(ERROR, openolt_log_id, "Enable PON deivce %d failed\n", dev);
Jason Huangd33b4d82019-05-15 18:22:57 +0800653 bcmos_usleep(200000);
654 }
Jason Huangb1fad572019-05-28 19:02:30 +0800655 else {
Jason Huangb6843dc2019-07-22 17:46:06 +0800656 OPENOLT_LOG(WARNING, openolt_log_id, "PON deivce %d already connected\n", dev);
Jason Huangb1fad572019-05-28 19:02:30 +0800657 state.activate();
658 }
Jason Huangd33b4d82019-05-15 18:22:57 +0800659 }
660 init_stats();
Shad Ansari627b5782018-08-13 22:49:32 +0000661 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000662 }
Shad Ansariedef2132018-08-10 22:14:50 +0000663
Jason Huangd33b4d82019-05-15 18:22:57 +0800664 /* Start CLI */
Jason Huangb6843dc2019-07-22 17:46:06 +0800665 OPENOLT_LOG(INFO, def_log_id, "Starting CLI\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400666 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000667 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400668}
669
670Status Disable_() {
671 // bcmbal_access_terminal_cfg acc_term_obj;
672 // bcmbal_access_terminal_key key = { };
673 //
674 // if (state::is_activated) {
675 // std::cout << "Disable OLT" << std::endl;
676 // key.access_term_id = DEFAULT_ATERM_ID;
677 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
678 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
679 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
680 // if (err) {
681 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
682 // return bcm_to_grpc_err(err, "Failed to disable OLT");
683 // }
684 // }
685 // //If already disabled, generate an extra indication ????
686 // return Status::OK;
687 //This fails with Operation Not Supported, bug ???
688
689 //TEMPORARY WORK AROUND
Jason Huangb6843dc2019-07-22 17:46:06 +0800690 Status status = SetStateUplinkIf_(nni_intf_id, false);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400691 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000692 state.deactivate();
Jason Huangb6843dc2019-07-22 17:46:06 +0800693 OPENOLT_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n");
Jason Huang88795222019-06-13 19:28:44 +0800694 pushOltOperInd(nni_intf_id, "nni", "up");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400695 }
696 return status;
697
698}
699
700Status Reenable_() {
Jason Huangb6843dc2019-07-22 17:46:06 +0800701 Status status = SetStateUplinkIf_(0, true);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400702 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000703 state.activate();
Jason Huangb6843dc2019-07-22 17:46:06 +0800704 OPENOLT_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n");
Jason Huang88795222019-06-13 19:28:44 +0800705 pushOltOperInd(0, "nni", "up");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400706 }
707 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000708}
709
Jason Huangd33b4d82019-05-15 18:22:57 +0800710bcmos_errno get_pon_interface_status(bcmolt_interface pon_ni, bcmolt_interface_state *state) {
711 bcmos_errno err;
712 bcmolt_pon_interface_key pon_key;
713 bcmolt_pon_interface_cfg pon_cfg;
714 pon_key.pon_ni = pon_ni;
715
716 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
717 BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, state);
718 BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, itu);
719 err = bcmolt_cfg_get(dev_id, &pon_cfg.hdr);
720 *state = pon_cfg.data.state;
721 return err;
722}
723
Jason Huangb6843dc2019-07-22 17:46:06 +0800724inline uint64_t get_flow_status(uint16_t flow_id, uint16_t flow_type, uint16_t data_id) {
Jason Huang439d24f2019-06-26 03:25:05 +0800725 bcmos_errno err;
726 bcmolt_flow_key flow_key;
727 bcmolt_flow_cfg flow_cfg;
728
729 flow_key.flow_id = flow_id;
Jason Huangb6843dc2019-07-22 17:46:06 +0800730 flow_key.flow_type = (bcmolt_flow_type)flow_type;
Jason Huang439d24f2019-06-26 03:25:05 +0800731
732 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
733
734 switch (data_id) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800735 case ONU_ID: //onu_id
736 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, onu_id);
Jason Huang439d24f2019-06-26 03:25:05 +0800737 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
738 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800739 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get onu_id\n");
Jason Huang439d24f2019-06-26 03:25:05 +0800740 return err;
741 }
Jason Huangb6843dc2019-07-22 17:46:06 +0800742 return flow_cfg.data.onu_id;
743 case FLOW_TYPE:
Jason Huang439d24f2019-06-26 03:25:05 +0800744 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
745 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800746 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get flow_type\n");
Jason Huang439d24f2019-06-26 03:25:05 +0800747 return err;
748 }
Jason Huangb6843dc2019-07-22 17:46:06 +0800749 return flow_cfg.key.flow_type;
Jason Huang439d24f2019-06-26 03:25:05 +0800750 case SVC_PORT_ID: //svc_port_id
751 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, svc_port_id);
752 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
753 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800754 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get svc_port_id\n");
Jason Huang439d24f2019-06-26 03:25:05 +0800755 return err;
756 }
757 return flow_cfg.data.svc_port_id;
Jason Huangb6843dc2019-07-22 17:46:06 +0800758 case PRIORITY:
759 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, priority);
760 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
761 if (err) {
762 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get priority\n");
763 return err;
764 }
765 return flow_cfg.data.priority;
Jason Huang439d24f2019-06-26 03:25:05 +0800766 case COOKIE: //cookie
767 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, cookie);
768 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
769 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800770 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get cookie\n");
Jason Huang439d24f2019-06-26 03:25:05 +0800771 return err;
772 }
773 return flow_cfg.data.cookie;
Jason Huangb6843dc2019-07-22 17:46:06 +0800774 case INGRESS_INTF_TYPE: //ingress intf_type
775 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf);
776 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
777 if (err) {
778 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_type\n");
779 return err;
780 }
781 return flow_cfg.data.ingress_intf.intf_type;
782 case EGRESS_INTF_TYPE: //egress intf_type
783 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_intf);
784 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
785 if (err) {
786 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_type\n");
787 return err;
788 }
789 return flow_cfg.data.egress_intf.intf_type;
790 case INGRESS_INTF_ID: //ingress intf_id
791 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, ingress_intf);
792 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
793 if (err) {
794 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get ingress intf_id\n");
795 return err;
796 }
797 return flow_cfg.data.ingress_intf.intf_id;
798 case EGRESS_INTF_ID: //egress intf_id
799 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_intf);
800 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
801 if (err) {
802 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress intf_id\n");
803 return err;
804 }
805 return flow_cfg.data.egress_intf.intf_id;
806 case CLASSIFIER_O_VID:
807 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
808 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
809 if (err) {
810 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_vid\n");
811 return err;
812 }
813 return flow_cfg.data.classifier.o_vid;
814 case CLASSIFIER_O_PBITS:
815 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
816 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
817 if (err) {
818 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier o_pbits\n");
819 return err;
820 }
821 return flow_cfg.data.classifier.o_pbits;
822 case CLASSIFIER_I_VID:
823 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
824 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
825 if (err) {
826 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_vid\n");
827 return err;
828 }
829 return flow_cfg.data.classifier.i_vid;
830 case CLASSIFIER_I_PBITS:
831 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
832 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
833 if (err) {
834 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier i_pbits\n");
835 return err;
836 }
837 return flow_cfg.data.classifier.i_pbits;
838 case CLASSIFIER_ETHER_TYPE:
839 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
840 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
841 if (err) {
842 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ether_type\n");
843 return err;
844 }
845 return flow_cfg.data.classifier.ether_type;
846 case CLASSIFIER_IP_PROTO:
847 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
848 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
849 if (err) {
850 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier ip_proto\n");
851 return err;
852 }
853 return flow_cfg.data.classifier.ip_proto;
854 case CLASSIFIER_SRC_PORT:
855 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
856 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
857 if (err) {
858 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier src_port\n");
859 return err;
860 }
861 return flow_cfg.data.classifier.src_port;
862 case CLASSIFIER_DST_PORT:
863 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
864 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
865 if (err) {
866 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier dst_port\n");
867 return err;
868 }
869 return flow_cfg.data.classifier.dst_port;
870 case CLASSIFIER_PKT_TAG_TYPE:
871 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, classifier);
872 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
873 if (err) {
874 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get classifier pkt_tag_type\n");
875 return err;
876 }
877 return flow_cfg.data.classifier.pkt_tag_type;
878 case EGRESS_QOS_TYPE:
879 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos);
880 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
881 if (err) {
882 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos type\n");
883 return err;
884 }
885 return flow_cfg.data.egress_qos.type;
886 case EGRESS_QOS_QUEUE_ID:
887 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos);
888 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
889 if (err) {
890 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos queue_id\n");
891 return err;
892 }
893 switch (flow_cfg.data.egress_qos.type) {
894 case BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE:
895 return flow_cfg.data.egress_qos.u.fixed_queue.queue_id;
896 case BCMOLT_EGRESS_QOS_TYPE_TC_TO_QUEUE:
897 return flow_cfg.data.egress_qos.u.tc_to_queue.tc_to_queue_id;
898 case BCMOLT_EGRESS_QOS_TYPE_PBIT_TO_TC:
899 return flow_cfg.data.egress_qos.u.pbit_to_tc.tc_to_queue_id;
900 case BCMOLT_EGRESS_QOS_TYPE_NONE:
901 default:
902 return -1;
903 }
904 case EGRESS_QOS_TM_SCHED_ID:
905 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, egress_qos);
906 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
907 if (err) {
908 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get egress_qos tm_sched_id\n");
909 return err;
910 }
911 return flow_cfg.data.egress_qos.tm_sched.id;
912 case ACTION_CMDS_BITMASK:
913 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
914 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
915 if (err) {
916 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action cmds_bitmask\n");
917 return err;
918 }
919 return flow_cfg.data.action.cmds_bitmask;
920 case ACTION_O_VID:
921 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
922 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
923 if (err) {
924 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_vid\n");
925 return err;
926 }
927 return flow_cfg.data.action.o_vid;
928 case ACTION_O_PBITS:
929 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
930 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
931 if (err) {
932 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action o_pbits\n");
933 return err;
934 }
935 return flow_cfg.data.action.o_pbits;
936 case ACTION_I_VID:
937 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
938 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
939 if (err) {
940 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_vid\n");
941 return err;
942 }
943 return flow_cfg.data.action.i_vid;
944 case ACTION_I_PBITS:
945 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, action);
946 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
947 if (err) {
948 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get action i_pbits\n");
949 return err;
950 }
951 return flow_cfg.data.action.i_pbits;
952 case STATE:
953 BCMOLT_FIELD_SET_PRESENT(&flow_cfg.data, flow_cfg_data, state);
954 err = bcmolt_cfg_get(dev_id, &flow_cfg.hdr);
955 if (err) {
956 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get state\n");
957 return err;
958 }
959 return flow_cfg.data.state;
Jason Huang439d24f2019-06-26 03:25:05 +0800960 default:
961 return BCM_ERR_INTERNAL;
962 }
963
Jason Huangb6843dc2019-07-22 17:46:06 +0800964 return err;
Jason Huang439d24f2019-06-26 03:25:05 +0800965}
966
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000967Status EnablePonIf_(uint32_t intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800968 bcmos_errno err = BCM_ERR_OK;
Jason Huangb1fad572019-05-28 19:02:30 +0800969 bcmolt_pon_interface_cfg interface_obj;
Jason Huangd33b4d82019-05-15 18:22:57 +0800970 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id};
971 bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state;
972 bcmolt_interface_state state;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000973
Jason Huangd33b4d82019-05-15 18:22:57 +0800974 err = get_pon_interface_status((bcmolt_interface)intf_id, &state);
975 if (err == BCM_ERR_OK) {
976 if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800977 OPENOLT_LOG(INFO, openolt_log_id, "PON interface: %d already enabled\n", intf_id);
Jason Huangd33b4d82019-05-15 18:22:57 +0800978 return Status::OK;
979 }
980 }
Jason Huangb1fad572019-05-28 19:02:30 +0800981 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
Jason Huangd33b4d82019-05-15 18:22:57 +0800982 BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key);
Jason Huangb1fad572019-05-28 19:02:30 +0800983 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_ENABLE);
984 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.interval, 5000);
985 BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.onu_post_discovery_mode,
986 BCMOLT_ONU_POST_DISCOVERY_MODE_ACTIVATE);
Jason Huangb6843dc2019-07-22 17:46:06 +0800987 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.los, true);
988 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.onu_alarms, true);
989 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.tiwi, true);
990 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.ack_timeout, true);
991 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.sfi, true);
992 BCMOLT_MSG_FIELD_SET(&interface_obj, itu.automatic_onu_deactivation.loki, true);
Jason Huangd33b4d82019-05-15 18:22:57 +0800993 BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data,
994 operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING);
Jason Huangb1fad572019-05-28 19:02:30 +0800995
996 err = bcmolt_cfg_set(dev_id, &interface_obj.hdr);
997 if (err != BCM_ERR_OK) {
Jason Huangb6843dc2019-07-22 17:46:06 +0800998 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable discovery onu, PON interface %d, err %d\n", intf_id, err);
Jason Huangb1fad572019-05-28 19:02:30 +0800999 return bcm_to_grpc_err(err, "Failed to enable discovery onu");
1000 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001001 err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr);
1002 if (err != BCM_ERR_OK) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001003 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001004 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001005 }
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001006 else {
Jason Huangb6843dc2019-07-22 17:46:06 +08001007 OPENOLT_LOG(INFO, openolt_log_id, "Successfully enabled PON interface: %d\n", intf_id);
1008 OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for PON interface: %d\n", intf_id);
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001009 CreateDefaultSchedQueue_(intf_id, downstream);
1010 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001011
1012 return Status::OK;
1013}
1014
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001015Status ProbeDeviceCapabilities_() {
Jason Huangd33b4d82019-05-15 18:22:57 +08001016 bcmos_errno err;
1017 bcmolt_device_cfg dev_cfg = { };
1018 bcmolt_device_key dev_key = { };
1019 bcmolt_olt_cfg olt_cfg = { };
1020 bcmolt_olt_key olt_key = { };
Jason Huangd33b4d82019-05-15 18:22:57 +08001021 bcmolt_topology_map topo_map[BCM_MAX_PONS_PER_OLT] = { };
1022 bcmolt_topology topo = { };
Jason Huangb6843dc2019-07-22 17:46:06 +08001023
Jason Huangd33b4d82019-05-15 18:22:57 +08001024 topo.topology_maps.len = BCM_MAX_PONS_PER_OLT;
1025 topo.topology_maps.arr = &topo_map[0];
1026 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
1027 BCMOLT_MSG_FIELD_GET(&olt_cfg, bal_state);
1028 BCMOLT_FIELD_SET_PRESENT(&olt_cfg.data, olt_cfg_data, topology);
1029 BCMOLT_CFG_LIST_BUF_SET(&olt_cfg, olt, topo.topology_maps.arr,
1030 sizeof(bcmolt_topology_map) * topo.topology_maps.len);
1031 err = bcmolt_cfg_get(dev_id, &olt_cfg.hdr);
1032 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001033 OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query OLT\n");
Jason Huangd33b4d82019-05-15 18:22:57 +08001034 return bcm_to_grpc_err(err, "cfg: Failed to query OLT");
1035 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001036
Jason Huangd33b4d82019-05-15 18:22:57 +08001037 num_of_nni_ports = olt_cfg.data.topology.num_switch_ports;
1038 num_of_pon_ports = olt_cfg.data.topology.topology_maps.len;
1039
Jason Huangb6843dc2019-07-22 17:46:06 +08001040 OPENOLT_LOG(INFO, openolt_log_id, "OLT capabilitites, oper_state: %s\n",
Jason Huangd33b4d82019-05-15 18:22:57 +08001041 olt_cfg.data.bal_state == BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY
1042 ? "up" : "down");
1043
Jason Huangb6843dc2019-07-22 17:46:06 +08001044 OPENOLT_LOG(INFO, openolt_log_id, "topology nni: %d pon: %d dev: %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +08001045 num_of_nni_ports,
1046 num_of_pon_ports,
Jason Huangb6843dc2019-07-22 17:46:06 +08001047 BCM_MAX_DEVS_PER_LINE_CARD);
Jason Huangd33b4d82019-05-15 18:22:57 +08001048
Jason Huangb6843dc2019-07-22 17:46:06 +08001049 for (int devid = 0; devid < BCM_MAX_DEVS_PER_LINE_CARD; devid++) {
1050 dev_key.device_id = devid;
1051 BCMOLT_CFG_INIT(&dev_cfg, device, dev_key);
1052 BCMOLT_MSG_FIELD_GET(&dev_cfg, firmware_sw_version);
1053 BCMOLT_MSG_FIELD_GET(&dev_cfg, chip_family);
1054 BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode);
1055 err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr);
1056 if (err) {
1057 OPENOLT_LOG(ERROR, openolt_log_id, "device: Failed to query OLT\n");
1058 return bcm_to_grpc_err(err, "device: Failed to query OLT");
1059 }
1060
1061 std::string bal_version;
1062 bal_version += std::to_string(dev_cfg.data.firmware_sw_version.major)
1063 + "." + std::to_string(dev_cfg.data.firmware_sw_version.minor)
1064 + "." + std::to_string(dev_cfg.data.firmware_sw_version.revision);
1065 firmware_version = "BAL." + bal_version + "__" + firmware_version;
1066
1067 switch(dev_cfg.data.system_mode) {
1068 case 10: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*4,(devid+1)*4,"GPON"); break;
1069 case 11: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*8,(devid+1)*8,"GPON"); break;
1070 case 12: board_technology = "GPON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"GPON"); break;
1071 case 13: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,"XGPON"); break;
1072 case 14: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*4,(devid+1)*4,"XGPON"); break;
1073 case 15: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*8,(devid+1)*8,"XGPON"); break;
1074 case 16: board_technology = "XGPON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"XGPON"); break;
1075 case 18: board_technology = "XGS-PON"; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,"XGS-PON"); break;
1076 case 19: board_technology = "XGS-PON"; FILL_ARRAY(intf_technologies,devid*16,(devid+1)*16,"XGS-PON"); break;
1077 case 20: board_technology = MIXED_TECH; FILL_ARRAY(intf_technologies,devid*2,(devid+1)*2,MIXED_TECH); break;
1078 }
1079
1080 switch(dev_cfg.data.chip_family) {
1081 case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6862_X_: chip_family = "Maple"; break;
1082 case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6865_X_: chip_family = "Aspen"; break;
1083 }
1084
1085 OPENOLT_LOG(INFO, openolt_log_id, "device %d, pon: %d, version %s object model: %d, family: %s, board_technology: %s\n",
1086 devid, BCM_MAX_PONS_PER_DEV, bal_version.c_str(), BAL_API_VERSION, chip_family.c_str(), board_technology.c_str());
1087
1088 bcmos_usleep(500000);
1089 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001090
1091 return Status::OK;
1092}
Jason Huangb6843dc2019-07-22 17:46:06 +08001093#if 0
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001094Status ProbePonIfTechnology_() {
1095 // Probe maximum extent possible as configured into BAL driver to determine
1096 // which are active in the current BAL topology. And for those
1097 // that are active, determine each port's access technology, i.e. "gpon" or "xgspon".
1098 for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001099 bcmolt_pon_interface_cfg interface_obj;
1100 bcmolt_pon_interface_key interface_key;
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001101
Jason Huangd33b4d82019-05-15 18:22:57 +08001102 interface_key.pon_ni = intf_id;
1103 BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key);
Jason Huangb6843dc2019-07-22 17:46:06 +08001104 if (board_technology == "XGS-PON")
1105 BCMOLT_MSG_FIELD_GET(&interface_obj, xgs_ngpon2_trx);
1106 else if (board_technology == "GPON")
1107 BCMOLT_MSG_FIELD_GET(&interface_obj, gpon_trx);
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001108
Jason Huangd33b4d82019-05-15 18:22:57 +08001109 bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr);
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001110 if (err != BCM_ERR_OK) {
Craig Lutgenb2601f02018-10-23 13:04:31 -05001111 intf_technologies[intf_id] = UNKNOWN_TECH;
Jason Huangb6843dc2019-07-22 17:46:06 +08001112 if(err != BCM_ERR_RANGE) OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get PON config: %d err %d\n", intf_id, err);
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001113 }
1114 else {
Jason Huangb1fad572019-05-28 19:02:30 +08001115 if (board_technology == "XGS-PON") {
Jason Huangd33b4d82019-05-15 18:22:57 +08001116 switch(interface_obj.data.xgpon_trx.transceiver_type) {
1117 case BCMOLT_XGPON_TRX_TYPE_LTH_7222_PC:
1118 case BCMOLT_XGPON_TRX_TYPE_WTD_RTXM266_702:
1119 case BCMOLT_XGPON_TRX_TYPE_LTH_7222_BC_PLUS:
1120 case BCMOLT_XGPON_TRX_TYPE_LTH_7226_PC:
1121 case BCMOLT_XGPON_TRX_TYPE_LTH_5302_PC:
1122 case BCMOLT_XGPON_TRX_TYPE_LTH_7226_A_PC_PLUS:
1123 case BCMOLT_XGPON_TRX_TYPE_D272RR_SSCB_DM:
Jason Huangb1fad572019-05-28 19:02:30 +08001124 intf_technologies[intf_id] = "XGS-PON";
Jason Huangd33b4d82019-05-15 18:22:57 +08001125 break;
1126 }
1127 } else if (board_technology == "GPON") {
1128 switch(interface_obj.data.gpon_trx.transceiver_type) {
1129 case BCMOLT_TRX_TYPE_SPS_43_48_H_HP_CDE_SD_2013:
1130 case BCMOLT_TRX_TYPE_LTE_3680_M:
1131 case BCMOLT_TRX_TYPE_SOURCE_PHOTONICS:
1132 case BCMOLT_TRX_TYPE_LTE_3680_P_TYPE_C_PLUS:
Jason Huangb6843dc2019-07-22 17:46:06 +08001133 case BCMOLT_TRX_TYPE_LTE_3680_P_BC:
Jason Huangd33b4d82019-05-15 18:22:57 +08001134 intf_technologies[intf_id] = "GPON";
1135 break;
1136 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001137 }
Craig Lutgenb2601f02018-10-23 13:04:31 -05001138
1139 if (board_technology != UNKNOWN_TECH) {
1140 board_technology = intf_technologies[intf_id];
1141 } else if (board_technology != MIXED_TECH && board_technology != intf_technologies[intf_id]) {
1142 intf_technologies[intf_id] = MIXED_TECH;
1143 }
1144
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001145 }
1146 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001147 return Status::OK;
1148}
Jason Huangb6843dc2019-07-22 17:46:06 +08001149#endif
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001150unsigned NumNniIf_() {return num_of_nni_ports;}
1151unsigned NumPonIf_() {return num_of_pon_ports;}
1152
Jason Huangd33b4d82019-05-15 18:22:57 +08001153bcmos_errno get_nni_interface_status(bcmolt_interface id, bcmolt_interface_state *state) {
1154 bcmos_errno err;
1155 bcmolt_nni_interface_key nni_key;
1156 bcmolt_nni_interface_cfg nni_cfg;
1157 nni_key.id = id;
1158
1159 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
1160 BCMOLT_FIELD_SET_PRESENT(&nni_cfg.data, nni_interface_cfg_data, state);
1161 err = bcmolt_cfg_get(dev_id, &nni_cfg.hdr);
1162 *state = nni_cfg.data.state;
1163 return err;
1164}
1165
Jason Huangb6843dc2019-07-22 17:46:06 +08001166Status SetStateUplinkIf_(uint32_t intf_id, bool set_state) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001167 bcmos_errno err = BCM_ERR_OK;
1168 bcmolt_nni_interface_key intf_key = {.id = (bcmolt_interface)intf_id};
1169 bcmolt_nni_interface_set_nni_state nni_interface_set_state;
1170 bcmolt_interface_state state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -04001171
Jason Huangd33b4d82019-05-15 18:22:57 +08001172 err = get_nni_interface_status((bcmolt_interface)intf_id, &state);
1173 if (err == BCM_ERR_OK) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001174 if (set_state && state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) {
1175 OPENOLT_LOG(INFO, openolt_log_id, "NNI interface: %d already enabled\n", intf_id);
1176 OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id);
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001177 CreateDefaultSchedQueue_(intf_id, upstream);
Jason Huangd33b4d82019-05-15 18:22:57 +08001178 return Status::OK;
Jason Huangb6843dc2019-07-22 17:46:06 +08001179 } else if (!set_state && state == BCMOLT_INTERFACE_STATE_INACTIVE) {
1180 OPENOLT_LOG(INFO, openolt_log_id, "NNI interface: %d already disabled\n", intf_id);
1181 return Status::OK;
Jason Huangd33b4d82019-05-15 18:22:57 +08001182 }
Craig Lutgend0bae9b2018-10-18 18:02:07 -05001183 }
1184
Jason Huangd33b4d82019-05-15 18:22:57 +08001185 BCMOLT_OPER_INIT(&nni_interface_set_state, nni_interface, set_nni_state, intf_key);
Jason Huangb6843dc2019-07-22 17:46:06 +08001186 if (set_state) {
1187 BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data,
1188 nni_state, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING);
1189 } else {
1190 BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data,
1191 nni_state, BCMOLT_INTERFACE_OPERATION_INACTIVE);
1192 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001193 err = bcmolt_oper_submit(dev_id, &nni_interface_set_state.hdr);
1194 if (err != BCM_ERR_OK) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001195 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to %s NNI interface: %d, err %d\n",
1196 (set_state)?"enable":"disable", intf_id, err);
Jason Huangd33b4d82019-05-15 18:22:57 +08001197 return bcm_to_grpc_err(err, "Failed to enable NNI interface");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -04001198 }
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001199 else {
Jason Huangb6843dc2019-07-22 17:46:06 +08001200 OPENOLT_LOG(INFO, openolt_log_id, "Successfully %s NNI interface: %d\n", (set_state)?"enable":"disable", intf_id);
1201 if (set_state) {
1202 OPENOLT_LOG(INFO, openolt_log_id, "Initializing tm sched creation for NNI interface: %d\n", intf_id);
1203 CreateDefaultSchedQueue_(intf_id, upstream);
1204 }
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001205 }
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -04001206
1207 return Status::OK;
1208}
1209
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001210Status DisablePonIf_(uint32_t intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001211 bcmolt_pon_interface_cfg interface_obj;
1212 bcmolt_pon_interface_key interface_key;
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001213
Jason Huangd33b4d82019-05-15 18:22:57 +08001214 interface_key.pon_ni = intf_id;
1215 BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key);
1216 BCMOLT_MSG_FIELD_GET(&interface_obj, state);
1217 bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001218 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001219 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001220 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -04001221 }
1222
1223 return Status::OK;
1224}
1225
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001226Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001227 const char *vendor_id, const char *vendor_specific, uint32_t pir) {
Jason Huangb1fad572019-05-28 19:02:30 +08001228 bcmos_errno err = BCM_ERR_OK;
1229 bcmolt_onu_cfg onu_cfg;
1230 bcmolt_onu_key onu_key;
Jason Huangd33b4d82019-05-15 18:22:57 +08001231 bcmolt_serial_number serial_number; /**< ONU serial number */
1232 bcmolt_bin_str_36 registration_id; /**< ONU registration ID */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001233
Jason Huangb1fad572019-05-28 19:02:30 +08001234 onu_key.onu_id = onu_id;
1235 onu_key.pon_ni = intf_id;
1236 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1237 BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
1238 err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
1239 if (err == BCM_ERR_OK) {
1240 if ((onu_cfg.data.onu_state == BCMOLT_ONU_STATE_PROCESSING ||
1241 onu_cfg.data.onu_state == BCMOLT_ONU_STATE_ACTIVE) ||
1242 (onu_cfg.data.onu_state == BCMOLT_ONU_STATE_INACTIVE &&
Jason Huangb6843dc2019-07-22 17:46:06 +08001243 onu_cfg.data.onu_old_state == BCMOLT_ONU_STATE_NOT_CONFIGURED))
Jason Huangb1fad572019-05-28 19:02:30 +08001244 return Status::OK;
1245 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001246
Jason Huangb6843dc2019-07-22 17:46:06 +08001247 OPENOLT_LOG(INFO, openolt_log_id, "Enabling ONU %d on PON %d : vendor id %s, \
1248vendor specific %s, pir %d\n", onu_id, intf_id, vendor_id,
Jason Huangb1fad572019-05-28 19:02:30 +08001249 vendor_specific_to_str(vendor_specific).c_str(), pir);
1250
Jason Huangd33b4d82019-05-15 18:22:57 +08001251 memcpy(serial_number.vendor_id.arr, vendor_id, 4);
1252 memcpy(serial_number.vendor_specific.arr, vendor_specific, 4);
Jason Huangb1fad572019-05-28 19:02:30 +08001253 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1254 BCMOLT_MSG_FIELD_SET(&onu_cfg, onu_rate, BCMOLT_ONU_RATE_RATE_10G_DS_10G_US);
1255 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.serial_number, serial_number);
1256 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.auto_learning, BCMOS_TRUE);
1257 /*set burst and data profiles to fec disabled*/
1258 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.ranging_burst_profile, 0);
1259 BCMOLT_MSG_FIELD_SET(&onu_cfg, itu.xgpon.data_burst_profile, 1);
Jason Huangb6843dc2019-07-22 17:46:06 +08001260 err = bcmolt_cfg_set(dev_id, &onu_cfg.hdr);
Jason Huangb1fad572019-05-28 19:02:30 +08001261 if (err != BCM_ERR_OK) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001262 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to set activate ONU %d on PON %d, err %d\n", onu_id, intf_id, err);
Jason Huangb1fad572019-05-28 19:02:30 +08001263 return bcm_to_grpc_err(err, "Failed to activate ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001264 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001265
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001266 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001267}
1268
Jonathan Davis70c21812018-07-19 15:32:10 -04001269Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
1270 const char *vendor_id, const char *vendor_specific) {
Jason Huangb1fad572019-05-28 19:02:30 +08001271 bcmos_errno err = BCM_ERR_OK;
1272 bcmolt_onu_set_onu_state onu_oper; /* declare main API struct */
1273 bcmolt_onu_cfg onu_cfg;
1274 bcmolt_onu_key onu_key; /**< Object key. */
1275 bcmolt_onu_state onu_state;
Jonathan Davis70c21812018-07-19 15:32:10 -04001276
Jason Huangb1fad572019-05-28 19:02:30 +08001277 onu_key.onu_id = onu_id;
1278 onu_key.pon_ni = intf_id;
1279 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1280 BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
1281 err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
1282 if (err == BCM_ERR_OK) {
1283 switch (onu_state) {
1284 case BCMOLT_ONU_OPERATION_ACTIVE:
1285 BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key);
1286 BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data,
1287 onu_state, BCMOLT_ONU_OPERATION_INACTIVE);
1288 err = bcmolt_oper_submit(dev_id, &onu_oper.hdr);
1289 if (err != BCM_ERR_OK) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001290 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to \
1291deactivate ONU %d on PON %d, err %d\n", onu_id, intf_id, err);
Jason Huangb1fad572019-05-28 19:02:30 +08001292 return bcm_to_grpc_err(err, "Failed to deactivate ONU");
1293 }
1294 break;
1295 }
Jonathan Davis70c21812018-07-19 15:32:10 -04001296 }
1297
1298 return Status::OK;
1299}
1300
1301Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001302 const char *vendor_id, const char *vendor_specific) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001303
Jason Huangb6843dc2019-07-22 17:46:06 +08001304 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 -05001305 onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str());
1306
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001307 // Need to deactivate before removing it (BAL rules)
1308
1309 DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
1310 // Sleep to allow the state to propagate
1311 // We need the subscriber terminal object to be admin down before removal
1312 // Without sleep the race condition is lost by ~ 20 ms
1313 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1314
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001315 // TODO: Delete the schedulers and queues.
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001316
Jason Huangd33b4d82019-05-15 18:22:57 +08001317 bcmolt_onu_cfg cfg_obj;
1318 bcmolt_onu_key key;
Jonathan Davis70c21812018-07-19 15:32:10 -04001319
Jason Huangb6843dc2019-07-22 17:46:06 +08001320 OPENOLT_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001321 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -04001322
Jason Huangd33b4d82019-05-15 18:22:57 +08001323 key.onu_id = onu_id;
1324 key.pon_ni = intf_id;
1325 BCMOLT_CFG_INIT(&cfg_obj, onu, key);
Jonathan Davis70c21812018-07-19 15:32:10 -04001326
Jason Huangb6843dc2019-07-22 17:46:06 +08001327 bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr);
Jonathan Davis70c21812018-07-19 15:32:10 -04001328 if (err != BCM_ERR_OK)
1329 {
Jason Huangb6843dc2019-07-22 17:46:06 +08001330 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n",
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001331 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -04001332 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
1333 }
1334
Jason Huangd33b4d82019-05-15 18:22:57 +08001335 return Status::OK;
Jonathan Davis70c21812018-07-19 15:32:10 -04001336}
1337
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001338#define MAX_CHAR_LENGTH 20
1339#define MAX_OMCI_MSG_LENGTH 44
1340Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001341 bcmolt_bin_str buf = {};
1342 bcmolt_onu_cpu_packets omci_cpu_packets;
1343 bcmolt_onu_key key;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001344
Jason Huangd33b4d82019-05-15 18:22:57 +08001345 key.pon_ni = intf_id;
1346 key.onu_id = onu_id;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001347
Jason Huangd33b4d82019-05-15 18:22:57 +08001348 BCMOLT_OPER_INIT(&omci_cpu_packets, onu, cpu_packets, key);
1349 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_OMCI);
1350 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, calc_crc, BCMOS_TRUE);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001351
1352 // ???
1353 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
1354 buf.len = MAX_OMCI_MSG_LENGTH;
1355 } else {
1356 buf.len = pkt.size()/2;
1357 }
1358
1359 /* Send the OMCI packet using the BAL remote proxy API */
1360 uint16_t idx1 = 0;
1361 uint16_t idx2 = 0;
1362 uint8_t arraySend[buf.len];
1363 char str1[MAX_CHAR_LENGTH];
1364 char str2[MAX_CHAR_LENGTH];
1365 memset(&arraySend, 0, buf.len);
1366
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001367 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
1368 sprintf(str1,"%c", pkt[idx1]);
1369 sprintf(str2,"%c", pkt[++idx1]);
1370 strcat(str1,str2);
1371 arraySend[idx2] = strtol(str1, NULL, 16);
1372 }
1373
Jason Huangd33b4d82019-05-15 18:22:57 +08001374 buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
1375 memcpy(buf.arr, (uint8_t *)arraySend, buf.len);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001376
Jason Huangd33b4d82019-05-15 18:22:57 +08001377 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, number_of_packets, 1);
1378 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_size, buf.len);
1379 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, buffer, buf);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001380
Jason Huangd33b4d82019-05-15 18:22:57 +08001381 bcmos_errno err = bcmolt_oper_submit(dev_id, &omci_cpu_packets.hdr);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001382 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001383 OPENOLT_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id);
1384 return bcm_to_grpc_err(err, "send OMCI failed");
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001385 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08001386 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 -05001387 buf.len, onu_id, intf_id, pkt.c_str());
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001388 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001389 free(buf.arr);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001390
1391 return Status::OK;
1392}
1393
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001394Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, uint32_t port_no, uint32_t gemport_id, const std::string pkt) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001395 bcmolt_pon_interface_cpu_packets pon_interface_cpu_packets; /**< declare main API struct */
1396 bcmolt_pon_interface_key key = {.pon_ni = (bcmolt_interface)intf_id}; /**< declare key */
1397 bcmolt_bin_str buf = {};
1398 bcmolt_gem_port_id gem_port_id_array[1];
1399 bcmolt_gem_port_id_list_u8_max_16 gem_port_list = {};
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001400
Craig Lutgen967a1d02018-11-27 10:41:51 -06001401 if (port_no > 0) {
1402 bool found = false;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001403 if (gemport_id == 0) {
1404 bcmos_fastlock_lock(&data_lock);
1405 // Map the port_no to one of the flows that owns it to find a gemport_id for that flow.
1406 // Pick any flow that is mapped with the same port_no.
1407 std::map<uint32_t, std::set<uint32_t> >::const_iterator it = port_to_flows.find(port_no);
1408 if (it != port_to_flows.end() && !it->second.empty()) {
1409 uint32_t flow_id = *(it->second.begin()); // Pick any flow_id out of the bag set
1410 std::map<uint32_t, uint32_t>::const_iterator fit = flowid_to_gemport.find(flow_id);
1411 if (fit != flowid_to_gemport.end()) {
1412 found = true;
1413 gemport_id = fit->second;
1414 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001415 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001416 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001417
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001418 if (!found) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001419 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 -08001420 onu_id, port_no, intf_id);
1421 return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow for port_no");
1422 }
Jason Huangb6843dc2019-07-22 17:46:06 +08001423 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 -08001424 gemport_id, onu_id, port_no, intf_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001425 }
1426
Jason Huangd33b4d82019-05-15 18:22:57 +08001427 gem_port_id_array[0] = gemport_id;
1428 gem_port_list.len = 1;
1429 gem_port_list.arr = gem_port_id_array;
1430 buf.len = pkt.size();
1431 buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
1432 memcpy(buf.arr, (uint8_t *)pkt.data(), buf.len);
1433
1434 /* init the API struct */
1435 BCMOLT_OPER_INIT(&pon_interface_cpu_packets, pon_interface, cpu_packets, key);
1436 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_ETH);
1437 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, calc_crc, BCMOS_TRUE);
1438 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, gem_port_list, gem_port_list);
1439 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, buffer, buf);
1440
Jason Huangb6843dc2019-07-22 17:46:06 +08001441 OPENOLT_LOG(INFO, openolt_log_id, "Packet out of length %d sent to gemport %d on pon %d port_no %u\n",
Jason Huangd33b4d82019-05-15 18:22:57 +08001442 (uint8_t)pkt.size(), gemport_id, intf_id, port_no);
1443
1444 /* call API */
Jason Huangb6843dc2019-07-22 17:46:06 +08001445 bcmolt_oper_submit(dev_id, &pon_interface_cpu_packets.hdr);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001446 }
1447 else {
Jason Huangd33b4d82019-05-15 18:22:57 +08001448 //TODO: Port No is 0, it is coming sender requirement.
Jason Huangb6843dc2019-07-22 17:46:06 +08001449 OPENOLT_LOG(INFO, openolt_log_id, "port_no %d onu %d on pon %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +08001450 port_no, onu_id, intf_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001451 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001452 free(buf.arr);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001453
1454 return Status::OK;
1455}
1456
Jason Huangd33b4d82019-05-15 18:22:57 +08001457Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt, bcmolt_flow_id flow_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001458 bcmolt_flow_key key = {}; /* declare key */
1459 bcmolt_bin_str buffer = {};
1460 bcmolt_flow_send_eth_packet oper; /* declare main API struct */
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001461
Jason Huangb6843dc2019-07-22 17:46:06 +08001462 //validate flow_id and find flow_id/flow type: upstream/ingress type: PON/egress type: NNI
1463 if (get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, FLOW_TYPE) == BCMOLT_FLOW_TYPE_UPSTREAM && \
1464 get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, INGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_PON && \
1465 get_flow_status(flow_id, BCMOLT_FLOW_TYPE_UPSTREAM, EGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_NNI)
1466 key.flow_id = flow_id;
1467 else {
1468 if (flow_id_counters != 0) {
1469 for (int flowid=0; flowid < flow_id_counters; flowid++) {
1470 int flow_index = flow_id_data[flowid][0];
1471 if (get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, FLOW_TYPE) == BCMOLT_FLOW_TYPE_UPSTREAM && \
1472 get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, INGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_PON && \
1473 get_flow_status(flow_index, BCMOLT_FLOW_TYPE_UPSTREAM, EGRESS_INTF_TYPE) == BCMOLT_FLOW_INTERFACE_TYPE_NNI) {
1474 key.flow_id = flow_index;
1475 break;
1476 }
1477 }
1478 }
1479 else
1480 return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow id found");
1481 }
1482
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001483 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; /* send from uplink direction */
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001484
Jason Huangd33b4d82019-05-15 18:22:57 +08001485 /* Initialize the API struct. */
1486 BCMOLT_OPER_INIT(&oper, flow, send_eth_packet, key);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001487
Jason Huangd33b4d82019-05-15 18:22:57 +08001488 buffer.len = pkt.size();
1489 buffer.arr = (uint8_t *)malloc((buffer.len)*sizeof(uint8_t));
1490 memcpy(buffer.arr, (uint8_t *)pkt.data(), buffer.len);
1491 if (buffer.arr == NULL) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001492 OPENOLT_LOG(ERROR, openolt_log_id, "allocate pakcet buffer failed\n");
Jason Huangd33b4d82019-05-15 18:22:57 +08001493 return bcm_to_grpc_err(BCM_ERR_PARM, "allocate pakcet buffer failed");
1494 }
1495 BCMOLT_FIELD_SET(&oper.data, flow_send_eth_packet_data, buffer, buffer);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001496
Jason Huangd33b4d82019-05-15 18:22:57 +08001497 bcmos_errno err = bcmolt_oper_submit(dev_id, &oper.hdr);
Jason Huangb6843dc2019-07-22 17:46:06 +08001498 if (err) {
1499 OPENOLT_LOG(ERROR, openolt_log_id, "Error sending packets to port %d, flow_id %d, err %d\n", intf_id, key.flow_id, err);
1500 } else {
1501 OPENOLT_LOG(INFO, openolt_log_id, "sent packets to port %d in upstream direction (flow_id %d)\n", intf_id, key.flow_id);
1502 }
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001503
1504 return Status::OK;
1505}
1506
Jason Huangd33b4d82019-05-15 18:22:57 +08001507uint32_t GetPortNum_(uint32_t flow_id) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001508 bcmos_fastlock_lock(&data_lock);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001509 uint32_t port_no = 0;
1510 std::map<uint32_t, uint32_t >::const_iterator it = flowid_to_port.find(flow_id);
1511 if (it != flowid_to_port.end()) {
1512 port_no = it->second;
1513 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001514 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001515 return port_no;
1516}
1517
Jason Huangb6843dc2019-07-22 17:46:06 +08001518#define FLOW_LOG(level,msg,err) \
1519 do { \
1520 OPENOLT_LOG(level, openolt_log_id, "--------> %s (flow_id %d) err: %d <--------\n", msg, key.flow_id, err); \
1521 OPENOLT_LOG(level, openolt_log_id, "intf_id %d, onu_id %d, uni_id %d, port_no %u, cookie %"PRIu64"\n", \
1522 access_intf_id, onu_id, uni_id, port_no, cookie); \
1523 OPENOLT_LOG(level, openolt_log_id, "flow_type %s, queue_id %d, sched_id %d\n", flow_type.c_str(), \
1524 cfg.data.egress_qos.u.fixed_queue.queue_id, cfg.data.egress_qos.tm_sched.id); \
1525 OPENOLT_LOG(level, openolt_log_id, "Ingress(intfd_type %s, intf_id %d), Egress(intf_type %s, intf_id %d)\n", \
1526 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type), cfg.data.ingress_intf.intf_id, \
1527 GET_FLOW_INTERFACE_TYPE(cfg.data.egress_intf.intf_type), cfg.data.egress_intf.intf_id); \
1528 OPENOLT_LOG(level, openolt_log_id, "classifier(o_vid %d, o_pbits %d, i_vid %d, i_pbits %d, ether type 0x%x)\n", \
1529 c_val.o_vid, c_val.o_pbits, c_val.i_vid, c_val.i_pbits, classifier.eth_type()); \
1530 OPENOLT_LOG(level, openolt_log_id, "classifier(ip_proto 0x%x, gemport_id %d, src_port %d, dst_port %d, pkt_tag_type %s)\n", \
1531 c_val.ip_proto, gemport_id, c_val.src_port, c_val.dst_port, GET_PKT_TAG_TYPE(c_val.pkt_tag_type)); \
1532 OPENOLT_LOG(level, openolt_log_id, "action(cmds_bitmask %s, o_vid %d, o_pbits %d, i_vid %d, i_pbits %d)\n\n", \
1533 get_flow_acton_command(a_val.cmds_bitmask), a_val.o_vid, a_val.o_pbits, a_val.i_vid, a_val.i_pbits); \
1534 } while(0)
1535
1536#define FLOW_PARAM_LOG() \
1537 do { \
1538 OPENOLT_LOG(INFO, openolt_log_id, "--------> flow comparison (now before) <--------\n"); \
1539 OPENOLT_LOG(INFO, openolt_log_id, "flow_id (%d %d)\n", \
1540 key.flow_id, flow_index); \
1541 OPENOLT_LOG(INFO, openolt_log_id, "onu_id (%d %lu)\n", \
1542 cfg.data.onu_id , get_flow_status(flow_index, flow_id_data[flowid][1], ONU_ID)); \
1543 OPENOLT_LOG(INFO, openolt_log_id, "type (%d %lu)\n", \
1544 key.flow_type, get_flow_status(flow_index, flow_id_data[flowid][1], FLOW_TYPE)); \
1545 OPENOLT_LOG(INFO, openolt_log_id, "svc_port_id (%d %lu)\n", \
1546 cfg.data.svc_port_id, get_flow_status(flow_index, flow_id_data[flowid][1], SVC_PORT_ID)); \
1547 OPENOLT_LOG(INFO, openolt_log_id, "priority (%d %lu)\n", \
1548 cfg.data.priority, get_flow_status(flow_index, flow_id_data[flowid][1], PRIORITY)); \
1549 OPENOLT_LOG(INFO, openolt_log_id, "cookie (%lu %lu)\n", \
1550 cfg.data.cookie, get_flow_status(flow_index, flow_id_data[flowid][1], COOKIE)); \
1551 OPENOLT_LOG(INFO, openolt_log_id, "ingress intf_type (%s %s)\n", \
1552 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type), \
1553 GET_FLOW_INTERFACE_TYPE(get_flow_status(flow_index, flow_id_data[flowid][1], INGRESS_INTF_TYPE))); \
1554 OPENOLT_LOG(INFO, openolt_log_id, "ingress intf id (%d %lu)\n", \
1555 cfg.data.ingress_intf.intf_id , get_flow_status(flow_index, flow_id_data[flowid][1], INGRESS_INTF_ID)); \
1556 OPENOLT_LOG(INFO, openolt_log_id, "egress intf_type (%d %lu)\n", \
1557 cfg.data.egress_intf.intf_type , get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_INTF_TYPE)); \
1558 OPENOLT_LOG(INFO, openolt_log_id, "egress intf_id (%d %lu)\n", \
1559 cfg.data.egress_intf.intf_id , get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_INTF_ID)); \
1560 OPENOLT_LOG(INFO, openolt_log_id, "classifier o_vid (%d %lu)\n", \
1561 c_val.o_vid , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_O_VID)); \
1562 OPENOLT_LOG(INFO, openolt_log_id, "classifier o_pbits (%d %lu)\n", \
1563 c_val.o_pbits , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_O_PBITS)); \
1564 OPENOLT_LOG(INFO, openolt_log_id, "classifier i_vid (%d %lu)\n", \
1565 c_val.i_vid , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_I_VID)); \
1566 OPENOLT_LOG(INFO, openolt_log_id, "classifier i_pbits (%d %lu)\n", \
1567 c_val.i_pbits , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_I_PBITS)); \
1568 OPENOLT_LOG(INFO, openolt_log_id, "classifier ether_type (0x%x 0x%lx)\n", \
1569 c_val.ether_type , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_ETHER_TYPE)); \
1570 OPENOLT_LOG(INFO, openolt_log_id, "classifier ip_proto (%d %lu)\n", \
1571 c_val.ip_proto , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_IP_PROTO)); \
1572 OPENOLT_LOG(INFO, openolt_log_id, "classifier src_port (%d %lu)\n", \
1573 c_val.src_port , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_SRC_PORT)); \
1574 OPENOLT_LOG(INFO, openolt_log_id, "classifier dst_port (%d %lu)\n", \
1575 c_val.dst_port , get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_DST_PORT)); \
1576 OPENOLT_LOG(INFO, openolt_log_id, "classifier pkt_tag_type (%s %s)\n", \
1577 GET_PKT_TAG_TYPE(c_val.pkt_tag_type), \
1578 GET_PKT_TAG_TYPE(get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_PKT_TAG_TYPE))); \
1579 OPENOLT_LOG(INFO, openolt_log_id, "classifier egress_qos type (%d %lu)\n", \
1580 cfg.data.egress_qos.type , get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_QOS_TYPE)); \
1581 OPENOLT_LOG(INFO, openolt_log_id, "classifier egress_qos queue_id (%d %lu)\n", \
1582 cfg.data.egress_qos.u.fixed_queue.queue_id, \
1583 get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_QOS_QUEUE_ID)); \
1584 OPENOLT_LOG(INFO, openolt_log_id, "classifier egress_qos sched_id (%d %lu)\n", \
1585 cfg.data.egress_qos.tm_sched.id, \
1586 get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_QOS_TM_SCHED_ID)); \
1587 OPENOLT_LOG(INFO, openolt_log_id, "classifier cmds_bitmask (%s %s)\n", \
1588 get_flow_acton_command(a_val.cmds_bitmask), \
1589 get_flow_acton_command(get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_CMDS_BITMASK))); \
1590 OPENOLT_LOG(INFO, openolt_log_id, "action o_vid (%d %lu)\n", \
1591 a_val.o_vid , get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_O_VID)); \
1592 OPENOLT_LOG(INFO, openolt_log_id, "action i_vid (%d %lu)\n", \
1593 a_val.i_vid , get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_I_VID)); \
1594 OPENOLT_LOG(INFO, openolt_log_id, "action o_pbits (%d %lu)\n", \
1595 a_val.o_pbits , get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_O_PBITS)); \
1596 OPENOLT_LOG(INFO, openolt_log_id, "action i_pbits (%d %lu)\n\n", \
1597 a_val.i_pbits, get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_I_PBITS)); \
1598 } while(0)
1599
1600#define FLOW_CHECKER
1601//#define SHOW_FLOW_PARAM
1602
Craig Lutgen967a1d02018-11-27 10:41:51 -06001603Status 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 +00001604 uint32_t flow_id, const std::string flow_type,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001605 int32_t alloc_id, int32_t network_intf_id,
1606 int32_t gemport_id, const ::openolt::Classifier& classifier,
Craig Lutgen967a1d02018-11-27 10:41:51 -06001607 const ::openolt::Action& action, int32_t priority_value, uint64_t cookie) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001608 bcmolt_flow_cfg cfg;
1609 bcmolt_flow_key key = { }; /**< Object key. */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001610 int32_t o_vid = -1;
1611 bool single_tag = false;
1612 uint32_t ether_type = 0;
Jason Huangb6843dc2019-07-22 17:46:06 +08001613 bcmolt_classifier c_val = { };
1614 bcmolt_action a_val = { };
1615 bcmolt_tm_queue_ref tm_val = { };
1616 //Pre-defined Fixed Queue, It decides the type by caller, TODO
1617 bcmolt_egress_qos_type qos_type = BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001618
1619 key.flow_id = flow_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001620 if (flow_type.compare(upstream) == 0 ) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001621 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001622 } else if (flow_type.compare(downstream) == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001623 key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001624 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08001625 OPENOLT_LOG(ERROR, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001626 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001627 }
1628
Jason Huangd33b4d82019-05-15 18:22:57 +08001629 BCMOLT_CFG_INIT(&cfg, flow, key);
1630 BCMOLT_MSG_FIELD_SET(&cfg, cookie, cookie);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001631
Jason Huangb6843dc2019-07-22 17:46:06 +08001632 if (access_intf_id >= 0 && network_intf_id >= 0) {
1633 if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) { //upstream
Jason Huangd33b4d82019-05-15 18:22:57 +08001634 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1635 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, access_intf_id);
Jason Huangb6843dc2019-07-22 17:46:06 +08001636 if (classifier.eth_type() == EAP_ETHER_TYPE || //EAPOL packet
1637 (classifier.ip_proto() == 17 && classifier.src_port() == 68 && classifier.dst_port() == 67)) { //DHCP packet
1638 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_HOST);
1639 } else {
1640 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI);
1641 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, network_intf_id);
1642 }
1643 } else if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) { //downstream
1644 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI);
1645 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, network_intf_id);
Jason Huangd33b4d82019-05-15 18:22:57 +08001646 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1647 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id);
1648 }
Jason Huangb6843dc2019-07-22 17:46:06 +08001649 } else {
1650 OPENOLT_LOG(ERROR, openolt_log_id, "flow network setting invalid\n");
1651 return bcm_to_grpc_err(BCM_ERR_PARM, "flow network setting invalid");
Shad Ansari39739bc2018-09-13 21:38:37 +00001652 }
Jason Huangb6843dc2019-07-22 17:46:06 +08001653
Shad Ansari39739bc2018-09-13 21:38:37 +00001654 if (onu_id >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001655 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001656 }
1657 if (gemport_id >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001658 BCMOLT_MSG_FIELD_SET(&cfg, svc_port_id, gemport_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001659 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001660 if (gemport_id >= 0 && port_no != 0) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001661 bcmos_fastlock_lock(&data_lock);
Jason Huangd33b4d82019-05-15 18:22:57 +08001662 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Craig Lutgen967a1d02018-11-27 10:41:51 -06001663 port_to_flows[port_no].insert(key.flow_id);
1664 flowid_to_gemport[key.flow_id] = gemport_id;
1665 }
1666 else
1667 {
1668 flowid_to_port[key.flow_id] = port_no;
1669 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001670 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001671 }
Shad Ansari39739bc2018-09-13 21:38:37 +00001672 if (priority_value >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001673 BCMOLT_MSG_FIELD_SET(&cfg, priority, priority_value);
Shad Ansari39739bc2018-09-13 21:38:37 +00001674 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001675
1676 {
Jason Huangd33b4d82019-05-15 18:22:57 +08001677 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001678 if (classifier.o_tpid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001679 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_tpid 0x%04x\n", classifier.o_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001680 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_tpid, classifier.o_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001681 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001682 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001683 if (classifier.o_vid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001684 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_vid %d\n", classifier.o_vid());
1685 BCMOLT_FIELD_SET(&c_val, classifier, o_vid, classifier.o_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001686 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001687 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001688 if (classifier.i_tpid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001689 OPENOLT_LOG(DEBUG, openolt_log_id, "classify i_tpid 0x%04x\n", classifier.i_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001690 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, i_tpid, classifier.i_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001691 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001692 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001693 if (classifier.i_vid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001694 OPENOLT_LOG(DEBUG, openolt_log_id, "classify i_vid %d\n", classifier.i_vid());
1695 BCMOLT_FIELD_SET(&c_val, classifier, i_vid, classifier.i_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001696 }
1697
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001698 if (classifier.eth_type()) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001699 ether_type = classifier.eth_type();
Jason Huangb6843dc2019-07-22 17:46:06 +08001700 OPENOLT_LOG(DEBUG, openolt_log_id, "classify ether_type 0x%04x\n", classifier.eth_type());
1701 BCMOLT_FIELD_SET(&c_val, classifier, ether_type, classifier.eth_type());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001702 }
1703
1704 /*
1705 if (classifier.dst_mac()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001706 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_mac, classifier.dst_mac());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001707 }
1708
1709 if (classifier.src_mac()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001710 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_mac, classifier.src_mac());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001711 }
1712 */
1713
1714 if (classifier.ip_proto()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001715 OPENOLT_LOG(DEBUG, openolt_log_id, "classify ip_proto %d\n", classifier.ip_proto());
1716 BCMOLT_FIELD_SET(&c_val, classifier, ip_proto, classifier.ip_proto());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001717 }
1718
1719 /*
1720 if (classifier.dst_ip()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001721 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_ip, classifier.dst_ip());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001722 }
1723
1724 if (classifier.src_ip()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001725 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_ip, classifier.src_ip());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001726 }
1727 */
1728
1729 if (classifier.src_port()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001730 OPENOLT_LOG(DEBUG, openolt_log_id, "classify src_port %d\n", classifier.src_port());
1731 BCMOLT_FIELD_SET(&c_val, classifier, src_port, classifier.src_port());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001732 }
1733
1734 if (classifier.dst_port()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001735 OPENOLT_LOG(DEBUG, openolt_log_id, "classify dst_port %d\n", classifier.dst_port());
1736 BCMOLT_FIELD_SET(&c_val, classifier, dst_port, classifier.dst_port());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001737 }
1738
1739 if (!classifier.pkt_tag_type().empty()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001740 OPENOLT_LOG(DEBUG, openolt_log_id, "classify tag_type %s\n", classifier.pkt_tag_type().c_str());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001741 if (classifier.pkt_tag_type().compare("untagged") == 0) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001742 BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_UNTAGGED);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001743 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001744 BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_SINGLE_TAG);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001745 single_tag = true;
1746
Jason Huangb6843dc2019-07-22 17:46:06 +08001747 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits());
1748 BCMOLT_FIELD_SET(&c_val, classifier, o_pbits, classifier.o_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001749 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001750 BCMOLT_FIELD_SET(&c_val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001751
Jason Huangb6843dc2019-07-22 17:46:06 +08001752 OPENOLT_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits());
1753 BCMOLT_FIELD_SET(&c_val, classifier, o_pbits, classifier.o_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001754 }
1755 }
Jason Huangb6843dc2019-07-22 17:46:06 +08001756 BCMOLT_MSG_FIELD_SET(&cfg, classifier, c_val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001757 }
1758
Jason Huangb6843dc2019-07-22 17:46:06 +08001759 if (cfg.data.egress_intf.intf_type != BCMOLT_FLOW_INTERFACE_TYPE_HOST) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001760 const ::openolt::ActionCmd& cmd = action.cmd();
1761
1762 if (cmd.add_outer_tag()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001763 OPENOLT_LOG(DEBUG, openolt_log_id, "action add o_tag\n");
1764 BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001765 }
1766
1767 if (cmd.remove_outer_tag()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001768 OPENOLT_LOG(DEBUG, openolt_log_id, "action pop o_tag\n");
1769 BCMOLT_FIELD_SET(&a_val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001770 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001771 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001772 if (cmd.trap_to_host()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001773 OPENOLT_LOG(INFO, openolt_log_id, "action trap-to-host\n");
Craig Lutgen19512312018-11-02 10:14:46 -05001774 BCMBAL_ATTRIBUTE_PROP_SET(&val, action, cmds_bitmask, BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001775 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001776 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001777 if (action.o_vid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001778 OPENOLT_LOG(DEBUG, openolt_log_id, "action o_vid=%d\n", action.o_vid());
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001779 o_vid = action.o_vid();
Jason Huangb6843dc2019-07-22 17:46:06 +08001780 BCMOLT_FIELD_SET(&a_val, action, o_vid, action.o_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001781 }
1782
1783 if (action.o_pbits()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001784 OPENOLT_LOG(DEBUG, openolt_log_id, "action o_pbits=0x%x\n", action.o_pbits());
1785 BCMOLT_FIELD_SET(&a_val, action, o_pbits, action.o_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001786 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001787 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001788 if (action.o_tpid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001789 OPENOLT_LOG(INFO, openolt_log_id, "action o_tpid=0x%04x\n", action.o_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001790 BCMBAL_ATTRIBUTE_PROP_SET(&val, action, o_tpid, action.o_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001791 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001792 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001793 if (action.i_vid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001794 OPENOLT_LOG(DEBUG, openolt_log_id, "action i_vid=%d\n", action.i_vid());
1795 BCMOLT_FIELD_SET(&a_val, action, i_vid, action.i_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001796 }
1797
1798 if (action.i_pbits()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001799 OPENOLT_LOG(DEBUG, openolt_log_id, "action i_pbits=0x%x\n", action.i_pbits());
1800 BCMOLT_FIELD_SET(&a_val, action, i_pbits, action.i_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001801 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001802 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001803 if (action.i_tpid()) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001804 OPENOLT_LOG(DEBUG, openolt_log_id, "action i_tpid=0x%04x\n", action.i_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001805 BCMBAL_ATTRIBUTE_PROP_SET(&val, action, i_tpid, action.i_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001806 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001807 */
Jason Huangb6843dc2019-07-22 17:46:06 +08001808 BCMOLT_MSG_FIELD_SET(&cfg, action, a_val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001809 }
1810
Shad Ansari39739bc2018-09-13 21:38:37 +00001811 if ((access_intf_id >= 0) && (onu_id >= 0)) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001812 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001813 if (single_tag && ether_type == EAP_ETHER_TYPE) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001814 tm_val.sched_id = get_default_tm_sched_id(access_intf_id, downstream);
1815 tm_val.queue_id = 0;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001816 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08001817 tm_val.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, downstream); // Subscriber Scheduler
1818 tm_val.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, downstream);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001819 }
Jason Huangb6843dc2019-07-22 17:46:06 +08001820 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \
1821 downstream.c_str(), tm_val.queue_id, tm_val.sched_id, GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
Jason Huangd33b4d82019-05-15 18:22:57 +08001822
Jason Huangb6843dc2019-07-22 17:46:06 +08001823 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type);
1824 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
1825 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id);
Jason Huangd33b4d82019-05-15 18:22:57 +08001826 } else if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) {
1827 /* removed by BAL v3.0. N/A - Alloc ID is out of the scope of BAL. Used for OMCI only.
Jason Huangb6843dc2019-07-22 17:46:06 +08001828 bcmbal_tm_sched_id val1;
1829 val1 = get_tm_sched_id(access_intf_id, onu_id, uni_id, upstream); // DBA Scheduler ID
1830 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val1);
1831 */
1832 tm_val.sched_id = get_default_tm_sched_id(network_intf_id, upstream); // NNI Scheduler ID
1833 tm_val.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, upstream); // Queue on NNI
1834 OPENOLT_LOG(DEBUG, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d, intf_type %s\n", \
1835 upstream.c_str(), tm_val.queue_id, tm_val.sched_id, GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type));
1836 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, qos_type);
1837 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, tm_val.sched_id);
1838 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, tm_val.queue_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001839 }
Shad Ansari06101952018-07-25 00:22:09 +00001840 }
1841
Jason Huangd33b4d82019-05-15 18:22:57 +08001842 BCMOLT_MSG_FIELD_SET(&cfg, state, BCMOLT_FLOW_STATE_ENABLE);
Jason Huangb6843dc2019-07-22 17:46:06 +08001843#ifdef FLOW_CHECKER
1844 //Flow Checker, To avoid duplicate flow.
1845 if (flow_id_counters != 0) {
1846 bool b_duplicate_flow = false;
1847 for (int flowid=0; flowid < flow_id_counters; flowid++) {
1848 int flow_index = flow_id_data[flowid][0];
1849 b_duplicate_flow = (cfg.data.onu_id == get_flow_status(flow_index, flow_id_data[flowid][1], ONU_ID)) && \
1850 (key.flow_type == flow_id_data[flowid][1]) && \
1851 (cfg.data.svc_port_id == get_flow_status(flow_index, flow_id_data[flowid][1], SVC_PORT_ID)) && \
1852 (cfg.data.priority == get_flow_status(flow_index, flow_id_data[flowid][1], PRIORITY)) && \
1853 (cfg.data.cookie == get_flow_status(flow_index, flow_id_data[flowid][1], COOKIE)) && \
1854 (cfg.data.ingress_intf.intf_type == get_flow_status(flow_index, flow_id_data[flowid][1], INGRESS_INTF_TYPE)) && \
1855 (cfg.data.ingress_intf.intf_id == get_flow_status(flow_index, flow_id_data[flowid][1], INGRESS_INTF_ID)) && \
1856 (cfg.data.egress_intf.intf_type == get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_INTF_TYPE)) && \
1857 (cfg.data.egress_intf.intf_id == get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_INTF_ID)) && \
1858 (c_val.o_vid == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_O_VID)) && \
1859 (c_val.o_pbits == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_O_PBITS)) && \
1860 (c_val.i_vid == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_I_VID)) && \
1861 (c_val.i_pbits == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_I_PBITS)) && \
1862 (c_val.ether_type == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_ETHER_TYPE)) && \
1863 (c_val.ip_proto == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_IP_PROTO)) && \
1864 (c_val.src_port == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_SRC_PORT)) && \
1865 (c_val.dst_port == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_DST_PORT)) && \
1866 (c_val.pkt_tag_type == get_flow_status(flow_index, flow_id_data[flowid][1], CLASSIFIER_PKT_TAG_TYPE)) && \
1867 (cfg.data.egress_qos.type == get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_QOS_TYPE)) && \
1868 (cfg.data.egress_qos.u.fixed_queue.queue_id == get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_QOS_QUEUE_ID)) && \
1869 (cfg.data.egress_qos.tm_sched.id == get_flow_status(flow_index, flow_id_data[flowid][1], EGRESS_QOS_TM_SCHED_ID)) && \
1870 (a_val.cmds_bitmask == get_flow_status(flowid, flow_id_data[flowid][1], ACTION_CMDS_BITMASK)) && \
1871 (a_val.o_vid == get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_O_VID)) && \
1872 (a_val.i_vid == get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_I_VID)) && \
1873 (a_val.o_pbits == get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_O_PBITS)) && \
1874 (a_val.i_pbits == get_flow_status(flow_index, flow_id_data[flowid][1], ACTION_I_PBITS)) && \
1875 (cfg.data.state == get_flow_status(flowid, flow_id_data[flowid][1], STATE));
1876#ifdef SHOW_FLOW_PARAM
1877 // Flow Parameter
1878 FLOW_PARAM_LOG();
1879#endif
1880
1881 if (b_duplicate_flow) {
1882 FLOW_LOG(WARNING, "Flow duplicate", 0);
1883 return bcm_to_grpc_err(BCM_ERR_ALREADY, "flow exists");
1884 }
1885 }
1886 }
1887#endif
1888
Jason Huangd33b4d82019-05-15 18:22:57 +08001889 bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg.hdr);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001890 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001891 FLOW_LOG(ERROR, "Flow add failed", err);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001892 return bcm_to_grpc_err(err, "flow add failed");
Jason Huangb6843dc2019-07-22 17:46:06 +08001893 } else {
1894 FLOW_LOG(INFO, "Flow add ok", err);
1895 bcmos_fastlock_lock(&data_lock);
1896 flow_id_data[flow_id_counters][0] = key.flow_id;
1897 flow_id_data[flow_id_counters][1] = key.flow_type;
1898 flow_id_counters += 1;
1899 bcmos_fastlock_unlock(&data_lock, 0);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001900 }
1901
1902 return Status::OK;
1903}
1904
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001905Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
1906
Jason Huangd33b4d82019-05-15 18:22:57 +08001907 bcmolt_flow_cfg cfg;
1908 bcmolt_flow_key key = { };
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001909
Jason Huangd33b4d82019-05-15 18:22:57 +08001910 key.flow_id = (bcmolt_flow_id) flow_id;
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001911 key.flow_id = flow_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001912 if (flow_type.compare(upstream) == 0 ) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001913 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001914 } else if (flow_type.compare(downstream) == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001915 key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001916 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08001917 OPENOLT_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001918 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
1919 }
1920
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001921 bcmos_fastlock_lock(&data_lock);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001922 uint32_t port_no = flowid_to_port[key.flow_id];
Jason Huangd33b4d82019-05-15 18:22:57 +08001923 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Craig Lutgen967a1d02018-11-27 10:41:51 -06001924 flowid_to_gemport.erase(key.flow_id);
1925 port_to_flows[port_no].erase(key.flow_id);
1926 if (port_to_flows[port_no].empty()) port_to_flows.erase(port_no);
1927 }
1928 else
1929 {
1930 flowid_to_port.erase(key.flow_id);
1931 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001932 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001933
Jason Huangd33b4d82019-05-15 18:22:57 +08001934 BCMOLT_CFG_INIT(&cfg, flow, key);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001935
Jason Huangd33b4d82019-05-15 18:22:57 +08001936 bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001937 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08001938 OPENOLT_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n",
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001939 err, flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001940 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
1941 }
1942
Jason Huangb6843dc2019-07-22 17:46:06 +08001943 bcmos_fastlock_lock(&data_lock);
1944 for (int flowid=0; flowid < flow_id_counters; flowid++) {
1945 if (flow_id_data[flowid][0] == flow_id && flow_id_data[flowid][1] == key.flow_type) {
1946 flow_id_counters -= 1;
1947 for (int i=flowid; i < flow_id_counters; i++) {
1948 flow_id_data[i][0] = flow_id_data[i + 1][0];
1949 flow_id_data[i][1] = flow_id_data[i + 1][1];
1950 }
1951 break;
1952 }
1953 }
1954 bcmos_fastlock_unlock(&data_lock, 0);
1955
1956 OPENOLT_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001957 return Status::OK;
1958}
1959
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001960Status CreateDefaultSchedQueue_(uint32_t intf_id, const std::string direction) {
1961 bcmos_errno err;
1962 bcmolt_tm_sched_cfg tm_sched_cfg;
1963 bcmolt_tm_sched_key tm_sched_key = {.id = 1};
1964 tm_sched_key.id = get_default_tm_sched_id(intf_id, direction);
1965
1966 // bcmbal_tm_sched_owner
1967 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
1968
1969 /**< The output of the tm_sched object instance */
1970 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_INTERFACE);
1971
1972 if (direction.compare(upstream) == 0) {
1973 // In upstream it is NNI scheduler
1974 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_NNI);
1975 } else if (direction.compare(downstream) == 0) {
1976 // In downstream it is PON scheduler
1977 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_PON);
1978 }
1979
1980 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.interface.interface_ref.intf_id, intf_id);
1981
1982 // bcmbal_tm_sched_type
1983 // set the deafult policy to strict priority
1984 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP);
1985
1986 // num_priorities: Max number of strict priority scheduling elements
Jason Huangb6843dc2019-07-22 17:46:06 +08001987 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, 8);
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001988
1989 // bcmbal_tm_shaping
1990 uint32_t cir = 1000000;
1991 uint32_t pir = 1000000;
1992 uint32_t burst = 65536;
Jason Huangb6843dc2019-07-22 17:46:06 +08001993 OPENOLT_LOG(INFO, openolt_log_id, "applying traffic shaping in %s pir=%u, burst=%u\n",
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07001994 direction.c_str(), pir, burst);
1995 BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, pir);
1996 BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, burst);
1997 // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet'
1998 // BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.cir, cir);
1999 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.pir, pir);
2000 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.burst, burst);
2001
2002 err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr);
2003 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002004 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create %s scheduler, id %d, intf_id %d, err %d\n", direction.c_str(), tm_sched_key.id, intf_id, err);
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002005 return Status(grpc::StatusCode::INTERNAL, "Failed to create %s scheduler", direction.c_str());
2006 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002007 OPENOLT_LOG(INFO, openolt_log_id, "Create %s scheduler success, id %d, intf_id %d\n", direction.c_str(), tm_sched_key.id, intf_id);
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002008
2009 // Create 4 Queues for each default PON scheduler
2010 for (int queue_id = 0; queue_id < 4; queue_id++) {
2011 bcmolt_tm_queue_cfg tm_queue_cfg;
2012 bcmolt_tm_queue_key tm_queue_key = {};
2013 tm_queue_key.sched_id = get_default_tm_sched_id(intf_id, direction);
2014 tm_queue_key.id = queue_id;
2015
2016 BCMOLT_CFG_INIT(&tm_queue_cfg, tm_queue, tm_queue_key);
2017 BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.type, BCMOLT_TM_SCHED_PARAM_TYPE_PRIORITY);
2018 BCMOLT_MSG_FIELD_SET(&tm_queue_cfg, tm_sched_param.u.priority.priority, queue_id);
2019
2020 err = bcmolt_cfg_set(dev_id, &tm_queue_cfg.hdr);
2021 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002022 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create %s tm queue, id %d, sched_id %d\n", \
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002023 direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id);
2024 return Status(grpc::StatusCode::INTERNAL, "Failed to create %s tm queue", direction.c_str());
2025 }
2026
Jason Huangb6843dc2019-07-22 17:46:06 +08002027 OPENOLT_LOG(INFO, openolt_log_id, "Create %s tm_queue success, id %d, sched_id %d\n", \
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002028 direction.c_str(), tm_queue_key.id, tm_queue_key.sched_id);
2029 }
2030 return Status::OK;
2031}
2032
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002033bcmos_errno CreateSched(std::string direction, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t port_no,
2034 uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, uint32_t priority,
2035 tech_profile::SchedulingPolicy sched_policy, tech_profile::TrafficShapingInfo tf_sh_info) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002036
2037 bcmos_errno err;
2038
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002039 if (direction == downstream) {
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002040 bcmolt_tm_sched_cfg tm_sched_cfg;
2041 bcmolt_tm_sched_key tm_sched_key = {.id = 1};
2042 tm_sched_key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002043
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002044 // bcmbal_tm_sched_owner
2045 // In downstream it is sub_term scheduler
2046 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002047
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002048 /**< The output of the tm_sched object instance */
2049 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.type, BCMOLT_TM_SCHED_OUTPUT_TYPE_TM_SCHED);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002050
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002051 // bcmbal_tm_sched_parent
2052 // The parent for the sub_term scheduler is the PON scheduler in the downstream
2053 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_id, get_default_tm_sched_id(intf_id, direction));
2054 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, attachment_point.u.tm_sched.tm_sched_param.u.priority.priority, priority);
2055 /* removed by BAL v3.0, N/A - No direct attachment point of type ONU, same functionality may
2056 be achieved using the' virtual' type of attachment.
2057 tm_sched_owner.u.sub_term.intf_id = intf_id;
2058 tm_sched_owner.u.sub_term.sub_term_id = onu_id;
2059 */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002060
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002061 // bcmbal_tm_sched_type
2062 // set the deafult policy to strict priority
2063 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002064
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002065 // num_priorities: Max number of strict priority scheduling elements
2066 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, num_priorities, 8);
Jason Huangd33b4d82019-05-15 18:22:57 +08002067
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002068 // bcmbal_tm_shaping
2069 if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) {
2070 uint32_t cir = tf_sh_info.cir();
2071 uint32_t pir = tf_sh_info.pir();
2072 uint32_t burst = tf_sh_info.pbs();
Jason Huangb6843dc2019-07-22 17:46:06 +08002073 OPENOLT_LOG(INFO, openolt_log_id, "applying traffic shaping in DL cir=%u, pir=%u, burst=%u\n",
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002074 cir, pir, burst);
2075 BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, pir);
2076 BCMOLT_FIELD_SET_PRESENT(&tm_sched_cfg.data.rate, tm_shaping, burst);
2077 // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet'
2078 //BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.cir, cir);
2079 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.pir, pir);
2080 BCMOLT_MSG_FIELD_SET(&tm_sched_cfg, rate.burst, burst);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002081 }
2082
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002083 err = bcmolt_cfg_set(dev_id, &tm_sched_cfg.hdr);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002084 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002085 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, \
2086intf_id %d, onu_id %d, uni_id %d, port_no %u\n", tm_sched_key.id, intf_id, onu_id, \
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002087 uni_id, port_no);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002088 return err;
2089 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002090 OPENOLT_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \
2091uni_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 -08002092
2093 } else { //upstream
Jason Huangd33b4d82019-05-15 18:22:57 +08002094 bcmolt_itupon_alloc_cfg cfg;
Thiyagarajan Subramani0695c982019-06-05 07:30:50 -07002095 bcmolt_itupon_alloc_key key = { };
Jason Huangd33b4d82019-05-15 18:22:57 +08002096 key.pon_ni = intf_id;
2097 key.alloc_id = alloc_id;
Jason Huangb6843dc2019-07-22 17:46:06 +08002098 int bw_granularity = (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY;
2099 int pir_bw = tf_sh_info.pir();
2100 int cir_bw = tf_sh_info.cir();
2101 //offset to match bandwidth granularity
2102 int offset_pir_bw = pir_bw%bw_granularity;
2103 int offset_cir_bw = cir_bw%bw_granularity;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002104
Jason Huangb6843dc2019-07-22 17:46:06 +08002105 pir_bw = pir_bw - offset_pir_bw;
2106 cir_bw = cir_bw - offset_cir_bw;
2107
2108 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
2109
2110 switch (additional_bw) {
2111 case 2: //AdditionalBW_BestEffort
2112 if (pir_bw == 0) {
2113 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \
2114%d bytes/sec\n", (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY);
2115 } else if (pir_bw < cir_bw) {
2116 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \
2117bandwidth (%d)\n", pir_bw, cir_bw);
2118 return BCM_ERR_PARM;
2119 } else if (pir_bw == cir_bw) {
2120 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be greater than Guaranteed \
2121bandwidth for additional bandwidth eligibility of type best_effort\n");
2122 return BCM_ERR_PARM;
2123 }
2124 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_BEST_EFFORT);
2125 break;
2126 case 1: //AdditionalBW_NA
2127 if (pir_bw == 0) {
2128 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \
2129%d bytes/sec\n", (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY);
2130 return BCM_ERR_PARM;
2131 } else if (cir_bw == 0) {
2132 OPENOLT_LOG(ERROR, openolt_log_id, "Guaranteed bandwidth must be greater than zero for \
2133additional bandwidth eligibility of type Non-Assured (NA)\n");
2134 return BCM_ERR_PARM;
2135 } else if (pir_bw < cir_bw) {
2136 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \
2137bandwidth (%d)\n", pir_bw, cir_bw);
2138 return BCM_ERR_PARM;
2139 } else if (pir_bw == cir_bw) {
2140 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be greater than Guaranteed \
2141bandwidth for additional bandwidth eligibility of type non_assured\n");
2142 return BCM_ERR_PARM;
2143 }
2144 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NON_ASSURED);
2145 break;
2146 case 0: //AdditionalBW_None
2147 if (pir_bw == 0) {
2148 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \
214916000 bytes/sec\n");
2150 return BCM_ERR_PARM;
2151 } else if (cir_bw == 0) {
2152 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be equal to Guaranteed bandwidth \
2153for additional bandwidth eligibility of type None\n");
2154 return BCM_ERR_PARM;
2155 } else if (pir_bw > cir_bw) {
2156 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be equal to Guaranteed bandwidth \
2157for additional bandwidth eligibility of type None\n");
2158 OPENOLT_LOG(ERROR, openolt_log_id, "set Maximum bandwidth (%d) to Guaranteed \
2159bandwidth in None eligibility\n", pir_bw);
2160 cir_bw = pir_bw;
2161 } else if (pir_bw < cir_bw) {
2162 OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \
2163bandwidth (%d)\n", pir_bw, cir_bw);
2164 OPENOLT_LOG(ERROR, openolt_log_id, "set Maximum bandwidth (%d) to Guaranteed \
2165bandwidth in None eligibility\n", pir_bw);
2166 cir_bw = pir_bw;
2167 }
2168 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility, BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NONE);
2169 break;
2170 default:
2171 return BCM_ERR_PARM;
2172 }
2173 /* CBR Real Time Bandwidth which require shaping of the bandwidth allocations
Jason Huangd33b4d82019-05-15 18:22:57 +08002174 in a fine granularity. */
2175 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_bw, 0);
2176 /* Fixed Bandwidth with no critical requirement of shaping */
2177 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_bw, 0);
2178 /* Dynamic bandwidth which the OLT is committed to allocate upon demand */
Jason Huangb6843dc2019-07-22 17:46:06 +08002179 BCMOLT_MSG_FIELD_SET(&cfg, sla.guaranteed_bw, cir_bw);
Jason Huangd33b4d82019-05-15 18:22:57 +08002180 /* Maximum allocated bandwidth allowed for this alloc ID */
Jason Huangb6843dc2019-07-22 17:46:06 +08002181 BCMOLT_MSG_FIELD_SET(&cfg, sla.maximum_bw, pir_bw);
Jason Huangd33b4d82019-05-15 18:22:57 +08002182 BCMOLT_MSG_FIELD_SET(&cfg, sla.alloc_type, BCMOLT_ALLOC_TYPE_NSR);
2183 /* Set to True for AllocID with CBR RT Bandwidth that requires compensation
2184 for skipped allocations during quiet window */
2185 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_compensation, BCMOS_FALSE);
2186 /**< Allocation Profile index for CBR non-RT Bandwidth */
2187 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_ap_index, 0);
2188 /**< Allocation Profile index for CBR RT Bandwidth */
2189 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_ap_index, 0);
2190 /**< Alloc ID Weight used in case of Extended DBA mode */
2191 BCMOLT_MSG_FIELD_SET(&cfg, sla.weight, 0);
2192 /**< Alloc ID Priority used in case of Extended DBA mode */
2193 BCMOLT_MSG_FIELD_SET(&cfg, sla.priority, 0);
Jason Huangb6843dc2019-07-22 17:46:06 +08002194 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002195
Jason Huangb6843dc2019-07-22 17:46:06 +08002196 err = bcmolt_cfg_set(dev_id, &cfg.hdr);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002197 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002198 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d,\
2199port_no %u, alloc_id %d, err %d\n", intf_id, onu_id,uni_id,port_no,alloc_id, err);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002200 return err;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002201 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002202 OPENOLT_LOG(INFO, openolt_log_id, "Create upstream bandwidth allocation, intf_id %d, onu_id %d, uni_id %d, port_no %u, \
2203alloc_id %d\n", intf_id,onu_id,uni_id,port_no,alloc_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002204 }
2205
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002206 return BCM_ERR_OK;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002207}
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002208
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002209Status CreateTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) {
2210 uint32_t intf_id = traffic_scheds->intf_id();
2211 uint32_t onu_id = traffic_scheds->onu_id();
2212 uint32_t uni_id = traffic_scheds->uni_id();
2213 uint32_t port_no = traffic_scheds->port_no();
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002214 std::string direction;
2215 unsigned int alloc_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002216 tech_profile::SchedulerConfig sched_config;
2217 tech_profile::AdditionalBW additional_bw;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002218 uint32_t priority;
2219 uint32_t weight;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002220 tech_profile::SchedulingPolicy sched_policy;
2221 tech_profile::TrafficShapingInfo traffic_shaping_info;
2222 bcmos_errno err;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002223
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002224 for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) {
2225 tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i);
2226 if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) {
2227 direction = upstream;
2228 } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) {
2229 direction = downstream;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002230 }
2231 else {
Jason Huangb6843dc2019-07-22 17:46:06 +08002232 OPENOLT_LOG(ERROR, openolt_log_id, "direction-not-supported %d\n", traffic_sched.direction());
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002233 return Status::CANCELLED;
2234 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002235 alloc_id = traffic_sched.alloc_id();
2236 sched_config = traffic_sched.scheduler();
2237 additional_bw = sched_config.additional_bw();
2238 priority = sched_config.priority();
2239 weight = sched_config.weight();
2240 sched_policy = sched_config.sched_policy();
2241 traffic_shaping_info = traffic_sched.traffic_shaping_info();
2242 err = CreateSched(direction, intf_id, onu_id, uni_id, port_no, alloc_id, additional_bw, weight, priority,
2243 sched_policy, traffic_shaping_info);
2244 if (err) {
2245 return bcm_to_grpc_err(err, "Failed to create scheduler");
2246 }
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -07002247 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002248 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00002249}
Jonathan Davis70c21812018-07-19 15:32:10 -04002250
Jason Huangb6843dc2019-07-22 17:46:06 +08002251bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, int alloc_id, std::string direction) {
Jonathan Davis70c21812018-07-19 15:32:10 -04002252
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002253 bcmos_errno err;
Jason Huangb6843dc2019-07-22 17:46:06 +08002254
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002255 if (direction == upstream) {
Jason Huangd33b4d82019-05-15 18:22:57 +08002256 bcmolt_itupon_alloc_cfg cfg;
2257 bcmolt_itupon_alloc_key key = { };
2258 key.pon_ni = intf_id;
Jason Huangb6843dc2019-07-22 17:46:06 +08002259 key.alloc_id = alloc_id;
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002260
Jason Huangd33b4d82019-05-15 18:22:57 +08002261 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
Jason Huangb6843dc2019-07-22 17:46:06 +08002262 err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
Jason Huangd33b4d82019-05-15 18:22:57 +08002263 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002264 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, intf_id %d, alloc_id %d, err %d\n", \
2265 direction.c_str(), intf_id, alloc_id, err);
Jason Huangd33b4d82019-05-15 18:22:57 +08002266 return err;
2267 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002268 OPENOLT_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, intf_id %d, alloc_id %d\n", \
2269 direction.c_str(), intf_id, alloc_id);
Jason Huangd33b4d82019-05-15 18:22:57 +08002270 } else if (direction == downstream) {
2271 bcmolt_tm_sched_cfg cfg;
2272 bcmolt_tm_sched_key key = { };
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04002273
Jason Huangd33b4d82019-05-15 18:22:57 +08002274 if (is_tm_sched_id_present(intf_id, onu_id, uni_id, direction)) {
2275 key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction);
2276 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08002277 OPENOLT_LOG(INFO, openolt_log_id, "schduler not present in %s, err %d\n", direction.c_str(), err);
Jason Huangd33b4d82019-05-15 18:22:57 +08002278 return BCM_ERR_OK;
2279 }
2280 BCMOLT_CFG_INIT(&cfg, tm_sched, key);
2281 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
2282 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002283 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \
Jason Huangd33b4d82019-05-15 18:22:57 +08002284 direction.c_str(), key.id, intf_id, onu_id);
2285 return err;
2286 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002287 OPENOLT_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \
Jason Huangd33b4d82019-05-15 18:22:57 +08002288 direction.c_str(), key.id, intf_id, onu_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002289 }
2290
2291 free_tm_sched_id(intf_id, onu_id, uni_id, direction);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002292 return BCM_ERR_OK;
2293}
2294
2295Status RemoveTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) {
2296 uint32_t intf_id = traffic_scheds->intf_id();
2297 uint32_t onu_id = traffic_scheds->onu_id();
2298 uint32_t uni_id = traffic_scheds->uni_id();
2299 std::string direction;
2300 bcmos_errno err;
2301
2302 for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) {
2303 tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i);
2304 if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) {
2305 direction = upstream;
2306 } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) {
2307 direction = downstream;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002308 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002309 else {
Jason Huangb6843dc2019-07-22 17:46:06 +08002310 OPENOLT_LOG(ERROR, openolt_log_id, "direction-not-supported %d\n", traffic_sched.direction());
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002311 return Status::CANCELLED;
2312 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002313 int alloc_id = traffic_sched.alloc_id();
2314 err = RemoveSched(intf_id, onu_id, uni_id, alloc_id, direction);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002315 if (err) {
2316 return bcm_to_grpc_err(err, "error-removing-traffic-scheduler");
2317 }
2318 }
2319 return Status::OK;
2320}
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002321
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002322bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority,
2323 uint32_t gemport_id) {
2324 bcmos_errno err;
Jason Huangd33b4d82019-05-15 18:22:57 +08002325 bcmolt_tm_queue_cfg cfg;
2326 bcmolt_tm_queue_key key = { };
Jason Huangb6843dc2019-07-22 17:46:06 +08002327 OPENOLT_LOG(INFO, openolt_log_id, "creating queue. access_intf_id = %d, onu_id = %d, uni_id = %d \
2328gemport_id = %d, direction = %s\n", access_intf_id, onu_id, uni_id, gemport_id, direction.c_str());
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002329 if (direction == downstream) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002330 // There is one queue per gem port
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002331 key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction);
2332 key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002333
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002334 } else {
2335 queue_map_key_tuple map_key(access_intf_id, onu_id, uni_id, gemport_id, direction);
2336 if (queue_map.count(map_key) > 0) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002337 OPENOLT_LOG(INFO, openolt_log_id, "upstream queue exists for intf_id %d, onu_id %d, uni_id %d\n. Not re-creating", \
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002338 access_intf_id, onu_id, uni_id);
2339 return BCM_ERR_OK;
2340 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002341 key.sched_id = get_default_tm_sched_id(nni_intf_id, direction);
2342 if (priority > 7) {
2343 return BCM_ERR_RANGE;
2344 }
2345 // There are 8 queues (one per p-bit)
2346 key.id = us_fixed_queue_id_list[priority];
2347 update_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction, key.id);
2348 // FIXME: The upstream queues have to be created once only.
2349 // The upstream queues on the NNI scheduler are shared by all subscribers.
2350 // When the first scheduler comes in, the queues get created, and are re-used by all others.
2351 // Also, these queues should be present until the last subscriber exits the system.
2352 // One solution is to have these queues always, i.e., create it as soon as OLT is enabled.
2353 }
Jason Huangb6843dc2019-07-22 17:46:06 +08002354 OPENOLT_LOG(INFO, openolt_log_id, "queue assigned queue_id = %d\n", key.id);
Girish Gowdru36501552019-05-01 23:47:58 -07002355
Jason Huangd33b4d82019-05-15 18:22:57 +08002356 BCMOLT_CFG_INIT(&cfg, tm_queue, key);
2357 BCMOLT_MSG_FIELD_SET(&cfg, tm_sched_param.u.priority.priority, priority);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07002358
Jason Huangd33b4d82019-05-15 18:22:57 +08002359 err = bcmolt_cfg_set(dev_id, &cfg.hdr);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002360 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002361 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, id %d, sched_id %d, \
2362intf_id %d, onu_id %d, uni_id %d, err %d\n", \
2363 direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id, err);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002364 return err;
2365 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06002366
Jason Huangb6843dc2019-07-22 17:46:06 +08002367 OPENOLT_LOG(INFO, openolt_log_id, "Created tm_queue, direction %s, id %d, intf_id %d, onu_id %d, uni_id %d\n", \
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002368 direction.c_str(), key.id, access_intf_id, onu_id, uni_id);
2369
2370 return BCM_ERR_OK;
2371
2372}
2373
2374Status CreateTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) {
2375 uint32_t intf_id = traffic_queues->intf_id();
2376 uint32_t onu_id = traffic_queues->onu_id();
2377 uint32_t uni_id = traffic_queues->uni_id();
2378 std::string direction;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002379 bcmos_errno err;
2380
2381 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
2382 tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
2383 if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) {
2384 direction = upstream;
2385 } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) {
2386 direction = downstream;
2387 }
2388 else {
Jason Huangb6843dc2019-07-22 17:46:06 +08002389 OPENOLT_LOG(ERROR, openolt_log_id, "direction-not-supported %d\n", traffic_queue.direction());
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002390 return Status::CANCELLED;
2391 }
2392 err = CreateQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id());
Girish Gowdru36501552019-05-01 23:47:58 -07002393 // If the queue exists already, lets not return failure and break the loop.
2394 if (err && err != BCM_ERR_ALREADY) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002395 return bcm_to_grpc_err(err, "Failed to create queue");
2396 }
2397 }
2398 return Status::OK;
2399}
2400
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002401bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority,
2402 uint32_t gemport_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +08002403 bcmolt_tm_queue_cfg cfg;
2404 bcmolt_tm_queue_key key = { };
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002405 bcmos_errno err;
2406
2407 if (direction == downstream) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002408 if (is_tm_queue_id_present(access_intf_id, onu_id, uni_id, gemport_id, direction) && \
2409 is_tm_sched_id_present(access_intf_id, onu_id, uni_id, direction)) {
Jason Huangd33b4d82019-05-15 18:22:57 +08002410 key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction);
2411 key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002412 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08002413 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 -08002414 return BCM_ERR_OK;
2415 }
2416 } else {
2417 free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
2418 // In the upstream we use pre-created queues on the NNI scheduler that are used by all subscribers.
2419 // They should not be removed. So, lets return OK.
2420 return BCM_ERR_OK;
2421 }
2422
Jason Huangd33b4d82019-05-15 18:22:57 +08002423 BCMOLT_CFG_INIT(&cfg, tm_queue, key);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002424
Jason Huangd33b4d82019-05-15 18:22:57 +08002425 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002426
2427 if (err) {
Jason Huangb6843dc2019-07-22 17:46:06 +08002428 OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove queue, direction = %s, id %d, sched_id %d, intf_id %d, onu_id %d, uni_id %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +08002429 direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002430 return err;
2431 }
2432
2433 free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
2434
2435 return BCM_ERR_OK;
2436}
2437
2438Status RemoveTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) {
2439 uint32_t intf_id = traffic_queues->intf_id();
2440 uint32_t onu_id = traffic_queues->onu_id();
2441 uint32_t uni_id = traffic_queues->uni_id();
2442 uint32_t port_no = traffic_queues->port_no();
2443 std::string direction;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002444 bcmos_errno err;
2445
2446 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
2447 tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
2448 if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) {
2449 direction = upstream;
2450 } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) {
2451 direction = downstream;
2452 } else {
Jason Huangb6843dc2019-07-22 17:46:06 +08002453 OPENOLT_LOG(ERROR, openolt_log_id, "direction-not-supported %d\n", traffic_queue.direction());
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08002454 return Status::CANCELLED;
2455 }
2456 err = RemoveQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id());
2457 if (err) {
2458 return bcm_to_grpc_err(err, "Failed to remove queue");
2459 }
Jonathan Davis70c21812018-07-19 15:32:10 -04002460 }
2461
Jonathan Davis70c21812018-07-19 15:32:10 -04002462 return Status::OK;
Jonathan Davis70c21812018-07-19 15:32:10 -04002463}