blob: 4175a7fd3efba59960ada5a18a4f3bdeb69792b6 [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
61#define MAX_TM_SCHED_ID 16384
62#define EAP_ETHER_TYPE 34958
Nicolas Palpacuer967438f2018-09-07 14:41:54 -040063
Craig Lutgen88a22ad2018-10-04 12:30:46 -050064static unsigned int num_of_nni_ports = 0;
65static unsigned int num_of_pon_ports = 0;
Craig Lutgenb2601f02018-10-23 13:04:31 -050066static std::string intf_technologies[MAX_SUPPORTED_INTF];
Craig Lutgen88a22ad2018-10-04 12:30:46 -050067static const std::string UNKNOWN_TECH("unknown");
Craig Lutgenb2601f02018-10-23 13:04:31 -050068static const std::string MIXED_TECH("mixed");
69static std::string board_technology(UNKNOWN_TECH);
Jason Huangd33b4d82019-05-15 18:22:57 +080070static std::string chip_family(UNKNOWN_TECH);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -080071static unsigned int OPENOLT_FIELD_LEN = 200;
Craig Lutgen88a22ad2018-10-04 12:30:46 -050072static std::string firmware_version = "Openolt.2018.10.04";
Nicolas Palpacuerdff96792018-09-06 14:59:32 -040073
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -070074const uint32_t tm_upstream_sched_id_start = 18432;
75const uint32_t tm_downstream_sched_id_start = 16384;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -080076//0 to 3 are default queues. Lets not use them.
77const uint32_t tm_queue_id_start = 4;
78// Upto 8 fixed Upstream. Queue id 0 to 3 are pre-created, lets not use them.
79const uint32_t us_fixed_queue_id_list[8] = {4, 5, 6, 7, 8, 9, 10, 11};
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -070080const std::string upstream = "upstream";
81const std::string downstream = "downstream";
Jason Huangd33b4d82019-05-15 18:22:57 +080082bcmolt_oltid dev_id = 0;
83/* Current session */
84static bcmcli_session *current_session;
85static bcmcli_entry *api_parent_dir;
86bcmos_bool status_bcm_cli_quit = BCMOS_FALSE;
87bcmos_task bal_cli_thread;
88const char *bal_cli_thread_name = "bal_cli_thread";
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -070089
Shad Ansariedef2132018-08-10 22:14:50 +000090State state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040091
Craig Lutgen967a1d02018-11-27 10:41:51 -060092static std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports
93static std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports
94static 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 -080095
96// This represents the Key to 'queue_map' map.
97// Represents (pon_intf_id, onu_id, uni_id, gemport_id, direction)
98typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, std::string> queue_map_key_tuple;
99// 'queue_map' maps queue_map_key_tuple to downstream queue id present
100// on the Subscriber Scheduler
101static std::map<queue_map_key_tuple, int> queue_map;
102// This represents the Key to 'sched_map' map.
103// Represents (pon_intf_id, onu_id, uni_id, direction)
104
105typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string> sched_map_key_tuple;
106// 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or
107// Subscriber (Downstream) Scheduler ID
108static std::map<sched_map_key_tuple, int> sched_map;
109
110
111std::bitset<MAX_TM_QUEUE_ID> tm_queue_bitset;
112std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
113
114static bcmos_fastlock data_lock;
Craig Lutgen967a1d02018-11-27 10:41:51 -0600115
116#define MIN_ALLOC_ID_GPON 256
117#define MIN_ALLOC_ID_XGSPON 1024
118
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800119static bcmos_errno CreateSched(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
120 uint32_t port_no, uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, \
121 uint32_t priority, tech_profile::SchedulingPolicy sched_policy,
122 tech_profile::TrafficShapingInfo traffic_shaping_info);
123static bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, std::string direction);
124static bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, \
125 uint32_t priority, uint32_t gemport_id);
126static 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 +0000127
Jason Huangd33b4d82019-05-15 18:22:57 +0800128uint16_t get_dev_id(void) {
129 return dev_id;
130}
131
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800132/**
133* Returns the default NNI (Upstream direction) or PON (Downstream direction) scheduler
134* Every NNI port and PON port have default scheduler.
135* The NNI0 default scheduler ID is 18432, and NNI1 is 18433 and so on.
136* Similarly, PON0 default scheduler ID is 16384. PON1 is 16385 and so on.
137*
138* @param intf_id NNI or PON interface ID
139* @param direction "upstream" or "downstream"
140*
141* @return default scheduler ID for the given interface.
142*/
143static inline int get_default_tm_sched_id(int intf_id, std::string direction) {
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700144 if (direction.compare(upstream) == 0) {
145 return tm_upstream_sched_id_start + intf_id;
146 } else if (direction.compare(downstream) == 0) {
147 return tm_downstream_sched_id_start + intf_id;
148 }
149 else {
150 BCM_LOG(ERROR, openolt_log_id, "invalid direction - %s\n", direction.c_str());
151 return 0;
152 }
153}
154
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800155/**
156* Gets a unique tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction
157* The tm_queue_id is locally cached in a map, so that it can rendered when necessary.
158* VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem
159*
160* @param intf_id NNI or PON intf ID
161* @param onu_id ONU ID
162* @param uni_id UNI ID
163* @param gemport_id GEM Port ID
164* @param direction Upstream or downstream
165*
166* @return tm_queue_id
167*/
168int get_tm_queue_id(int intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) {
169 queue_map_key_tuple key(intf_id, onu_id, uni_id, gemport_id, direction);
170 int queue_id = -1;
Craig Lutgen967a1d02018-11-27 10:41:51 -0600171
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800172 std::map<queue_map_key_tuple, int>::const_iterator it = queue_map.find(key);
173 if (it != queue_map.end()) {
174 queue_id = it->second;
175 }
176 if (queue_id != -1) {
177 return queue_id;
178 }
179
180 bcmos_fastlock_lock(&data_lock);
181 // Complexity of O(n). Is there better way that can avoid linear search?
182 for (queue_id = 0; queue_id < MAX_TM_QUEUE_ID; queue_id++) {
183 if (tm_queue_bitset[queue_id] == 0) {
184 tm_queue_bitset[queue_id] = 1;
185 break;
186 }
187 }
188 bcmos_fastlock_unlock(&data_lock, 0);
189
190 if (queue_id < MAX_TM_QUEUE_ID) {
191 bcmos_fastlock_lock(&data_lock);
192 queue_map[key] = queue_id;
193 bcmos_fastlock_unlock(&data_lock, 0);
194 return queue_id;
195 } else {
196 return -1;
197 }
Shad Ansari627b5782018-08-13 22:49:32 +0000198}
199
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800200/**
201* Update tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction
202*
203* @param intf_id NNI or PON intf ID
204* @param onu_id ONU ID
205* @param uni_id UNI ID
206* @param gemport_id GEM Port ID
207* @param direction Upstream or downstream
208* @param tm_queue_id tm_queue_id
209*/
210void update_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction,
211 uint32_t queue_id) {
212 queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction);
213 bcmos_fastlock_lock(&data_lock);
214 queue_map[key] = queue_id;
215 bcmos_fastlock_unlock(&data_lock, 0);
216}
217
218/**
219* Free tm_queue_id for a given intf_id, onu_id, uni_id, gemport_id, direction
220*
221* @param intf_id NNI or PON intf ID
222* @param onu_id ONU ID
223* @param uni_id UNI ID
224* @param gemport_id GEM Port ID
225* @param direction Upstream or downstream
226*/
227void free_tm_queue_id(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) {
228 queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction);
229 std::map<queue_map_key_tuple, int>::const_iterator it;
230 bcmos_fastlock_lock(&data_lock);
231 it = queue_map.find(key);
232 if (it != queue_map.end()) {
233 tm_queue_bitset[it->second] = 0;
234 queue_map.erase(it);
235 }
236 bcmos_fastlock_unlock(&data_lock, 0);
237}
238
239/**
240* Gets a unique tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction
241* The tm_sched_id is locally cached in a map, so that it can rendered when necessary.
242* VOLTHA replays whole configuration on OLT reboot, so caching locally is not a problem
243*
244* @param intf_id NNI or PON intf ID
245* @param onu_id ONU ID
246* @param uni_id UNI ID
247* @param gemport_id GEM Port ID
248* @param direction Upstream or downstream
249*
250* @return tm_sched_id
251*/
252uint32_t get_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) {
253 sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction);
254 int sched_id = -1;
255
256 std::map<sched_map_key_tuple, int>::const_iterator it = sched_map.find(key);
257 if (it != sched_map.end()) {
258 sched_id = it->second;
259 }
260 if (sched_id != -1) {
261 return sched_id;
262 }
263
264 bcmos_fastlock_lock(&data_lock);
265 // Complexity of O(n). Is there better way that can avoid linear search?
266 for (sched_id = 0; sched_id < MAX_TM_SCHED_ID; sched_id++) {
267 if (tm_sched_bitset[sched_id] == 0) {
268 tm_sched_bitset[sched_id] = 1;
269 break;
270 }
271 }
272 bcmos_fastlock_unlock(&data_lock, 0);
273
274 if (sched_id < MAX_TM_SCHED_ID) {
275 bcmos_fastlock_lock(&data_lock);
276 sched_map[key] = sched_id;
277 bcmos_fastlock_unlock(&data_lock, 0);
278 return sched_id;
279 } else {
280 return -1;
281 }
282}
283
284/**
285* Free tm_sched_id for a given intf_id, onu_id, uni_id, gemport_id, direction
286*
287* @param intf_id NNI or PON intf ID
288* @param onu_id ONU ID
289* @param uni_id UNI ID
290* @param gemport_id GEM Port ID
291* @param direction Upstream or downstream
292*/
293void free_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction) {
294 sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction);
295 std::map<sched_map_key_tuple, int>::const_iterator it;
296 bcmos_fastlock_lock(&data_lock);
297 it = sched_map.find(key);
298 if (it != sched_map.end()) {
299 tm_sched_bitset[it->second] = 0;
300 sched_map.erase(it);
301 }
302 bcmos_fastlock_unlock(&data_lock, 0);
303}
304
305bool is_tm_sched_id_present(int pon_intf_id, int onu_id, int uni_id, std::string direction) {
306 sched_map_key_tuple key(pon_intf_id, onu_id, uni_id, direction);
307 return sched_map.count(key) > 0 ? true: false;
308}
309
310bool is_tm_queue_id_present(int pon_intf_id, int onu_id, int uni_id, int gemport_id, std::string direction) {
311 queue_map_key_tuple key(pon_intf_id, onu_id, uni_id, gemport_id, direction);
312 return queue_map.count(key) > 0 ? true: false;
Shad Ansari627b5782018-08-13 22:49:32 +0000313}
314
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800315char* openolt_read_sysinfo(char* field_name, char* field_val)
316{
317 FILE *fp;
318 /* Prepare the command*/
319 char command[150];
320
321 snprintf(command, sizeof command, "bash -l -c \"onlpdump -s\" | perl -ne 'print $1 if /%s: (\\S+)/'", field_name);
322 /* Open the command for reading. */
323 fp = popen(command, "r");
324 if (fp == NULL) {
325 /*The client has to check for a Null field value in this case*/
326 BCM_LOG(INFO, openolt_log_id, "Failed to query the %s\n", field_name);
327 return field_val;
328 }
329
330 /*Read the field value*/
331 if (fp) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800332 uint8_t ret;
333 ret = fread(field_val, OPENOLT_FIELD_LEN, 1, fp);
334 if (ret >= OPENOLT_FIELD_LEN)
335 BCM_LOG(INFO, openolt_log_id, "Read data length %u\n", ret);
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800336 pclose(fp);
337 }
338 return field_val;
339}
340
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400341Status GetDeviceInfo_(openolt::DeviceInfo* device_info) {
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500342 device_info->set_vendor(VENDOR_ID);
343 device_info->set_model(MODEL_ID);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400344 device_info->set_hardware_version("");
345 device_info->set_firmware_version(firmware_version);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500346 device_info->set_technology(board_technology);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500347 device_info->set_pon_ports(num_of_pon_ports);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500348
Thiyagarajan Subramani5e973532019-02-02 03:21:43 -0800349 char serial_number[OPENOLT_FIELD_LEN];
350 memset(serial_number, '\0', OPENOLT_FIELD_LEN);
351 openolt_read_sysinfo("Serial Number", serial_number);
352 BCM_LOG(INFO, openolt_log_id, "Fetched device serial number %s\n", serial_number);
353 device_info->set_device_serial_number(serial_number);
354
Craig Lutgenb2601f02018-10-23 13:04:31 -0500355 // Legacy, device-wide ranges. To be deprecated when adapter
356 // is upgraded to support per-interface ranges
Jason Huangd33b4d82019-05-15 18:22:57 +0800357 if (board_technology == "XGPON") {
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500358 device_info->set_onu_id_start(1);
359 device_info->set_onu_id_end(255);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600360 device_info->set_alloc_id_start(MIN_ALLOC_ID_XGSPON);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500361 device_info->set_alloc_id_end(16383);
362 device_info->set_gemport_id_start(1024);
363 device_info->set_gemport_id_end(65535);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500364 device_info->set_flow_id_start(1);
365 device_info->set_flow_id_end(16383);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500366 }
Jason Huangd33b4d82019-05-15 18:22:57 +0800367 else if (board_technology == "GPON") {
Craig Lutgenb2601f02018-10-23 13:04:31 -0500368 device_info->set_onu_id_start(1);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500369 device_info->set_onu_id_end(127);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600370 device_info->set_alloc_id_start(MIN_ALLOC_ID_GPON);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500371 device_info->set_alloc_id_end(767);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500372 device_info->set_gemport_id_start(256);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500373 device_info->set_gemport_id_end(4095);
Craig Lutgenb2601f02018-10-23 13:04:31 -0500374 device_info->set_flow_id_start(1);
375 device_info->set_flow_id_end(16383);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500376 }
Craig Lutgenb2601f02018-10-23 13:04:31 -0500377
378 std::map<std::string, openolt::DeviceInfo::DeviceResourceRanges*> ranges;
379 for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) {
380 std::string intf_technology = intf_technologies[intf_id];
381 openolt::DeviceInfo::DeviceResourceRanges *range = ranges[intf_technology];
382 if(range == nullptr) {
383 range = device_info->add_ranges();
384 ranges[intf_technology] = range;
385 range->set_technology(intf_technology);
386
387 if (intf_technology == "xgspon") {
388 openolt::DeviceInfo::DeviceResourceRanges::Pool* pool;
389
390 pool = range->add_pools();
391 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID);
392 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
393 pool->set_start(1);
394 pool->set_end(255);
395
396 pool = range->add_pools();
397 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID);
398 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH);
399 pool->set_start(1024);
400 pool->set_end(16383);
401
402 pool = range->add_pools();
403 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID);
404 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
405 pool->set_start(1024);
406 pool->set_end(65535);
407
408 pool = range->add_pools();
409 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID);
410 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
411 pool->set_start(1);
412 pool->set_end(16383);
413 }
414 else if (intf_technology == "gpon") {
415 openolt::DeviceInfo::DeviceResourceRanges::Pool* pool;
416
417 pool = range->add_pools();
418 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ONU_ID);
419 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::DEDICATED_PER_INTF);
420 pool->set_start(1);
421 pool->set_end(127);
422
423 pool = range->add_pools();
424 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::ALLOC_ID);
425 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_SAME_TECH);
426 pool->set_start(256);
427 pool->set_end(757);
428
429 pool = range->add_pools();
430 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::GEMPORT_ID);
431 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
432 pool->set_start(256);
433 pool->set_end(4095);
434
435 pool = range->add_pools();
436 pool->set_type(openolt::DeviceInfo::DeviceResourceRanges::Pool::FLOW_ID);
437 pool->set_sharing(openolt::DeviceInfo::DeviceResourceRanges::Pool::SHARED_BY_ALL_INTF_ALL_TECH);
438 pool->set_start(1);
439 pool->set_end(16383);
440 }
441 }
442
443 range->add_intf_ids(intf_id);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500444 }
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400445
446 // FIXME: Once dependency problem is fixed
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500447 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400448 // device_info->set_onu_id_end(XGPON_NUM_OF_ONUS - 1);
449 // device_info->set_alloc_id_start(1024);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500450 // device_info->set_alloc_id_end(XGPON_NUM_OF_ALLOC_IDS * num_of_pon_ports ? - 1);
Nicolas Palpacuerf0b02492018-09-10 10:21:29 -0400451 // device_info->set_gemport_id_start(XGPON_MIN_BASE_SERVICE_PORT_ID);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500452 // device_info->set_gemport_id_end(XGPON_NUM_OF_GEM_PORT_IDS_PER_PON * num_of_pon_ports ? - 1);
453 // device_info->set_pon_ports(num_of_pon_ports);
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400454
455 return Status::OK;
456}
457
Jason Huangd33b4d82019-05-15 18:22:57 +0800458#define CLI_HOST_PROMPT_FORMAT "BCM.%u> "
459
460/* Build CLI prompt */
461static void openolt_cli_get_prompt_cb(bcmcli_session *session, char *buf, uint32_t max_len)
462{
463 snprintf(buf, max_len, CLI_HOST_PROMPT_FORMAT, dev_id);
464}
465
466static int _bal_apiend_cli_thread_handler(long data)
467{
468 char init_string[]="\n";
469 bcmcli_session *sess = current_session;
470 bcmos_task_parm bal_cli_task_p_dummy;
471
472 /* Switch to interactive mode if not stopped in the init script */
473 if (!bcmcli_is_stopped(sess))
474 {
475 /* Force a CLI command prompt
476 * The string passed into the parse function
477 * must be modifiable, so a string constant like
478 * bcmcli_parse(current_session, "\n") will not
479 * work.
480 */
481 bcmcli_parse(sess, init_string);
482
483 /* Process user input until EOF or quit command */
484 bcmcli_driver(sess);
485 };
486 BCM_LOG(INFO, openolt_log_id, "BAL API End CLI terminated\n");
487
488 /* Cleanup */
489 bcmcli_session_close(current_session);
490 bcmcli_token_destroy(NULL);
491 return 0;
492}
493
494/* Init API CLI commands for the current device */
495bcmos_errno bcm_openolt_api_cli_init(bcmcli_entry *parent_dir, bcmcli_session *session)
496{
497 bcmos_errno rc;
498
499 api_parent_dir = parent_dir;
500
501 rc = bcm_api_cli_set_commands(session);
502
503#ifdef BCM_SUBSYSTEM_HOST
504 /* Subscribe for device change indication */
505 rc = rc ? rc : bcmolt_olt_sel_ind_register(_api_cli_olt_change_ind);
506#endif
507
508 return rc;
509}
510
511static bcmos_errno bcm_cli_quit(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms)
512{
513 bcmcli_stop(session);
514 bcmcli_session_print(session, "CLI terminated by 'Quit' command\n");
515 status_bcm_cli_quit = BCMOS_TRUE;
516
517 return BCM_ERR_OK;
518}
519
520int get_status_bcm_cli_quit(void) {
521 return status_bcm_cli_quit;
522}
523
524bcmos_errno bcmolt_apiend_cli_init() {
525 bcmos_errno ret;
526 bcmos_task_parm bal_cli_task_p = {};
527 bcmos_task_parm bal_cli_task_p_dummy;
528
529 /** before creating the task, check if it is already created by the other half of BAL i.e. Core side */
530 if (BCM_ERR_OK != bcmos_task_query(&bal_cli_thread, &bal_cli_task_p_dummy))
531 {
532 /* Create BAL CLI thread */
533 bal_cli_task_p.name = bal_cli_thread_name;
534 bal_cli_task_p.handler = _bal_apiend_cli_thread_handler;
535 bal_cli_task_p.priority = TASK_PRIORITY_CLI;
536
537 ret = bcmos_task_create(&bal_cli_thread, &bal_cli_task_p);
538 if (BCM_ERR_OK != ret)
539 {
540 bcmos_printf("Couldn't create BAL API end CLI thread\n");
541 return ret;
542 }
543 }
544}
545
Shad Ansari627b5782018-08-13 22:49:32 +0000546Status Enable_(int argc, char *argv[]) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800547 bcmos_errno err;
548 bcmolt_host_init_parms init_parms = {};
549 init_parms.transport.type = BCM_HOST_API_CONN_LOCAL;
550 bcmcli_session_parm mon_session_parm;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000551
Shad Ansariedef2132018-08-10 22:14:50 +0000552 if (!state.is_activated()) {
Shad Ansari627b5782018-08-13 22:49:32 +0000553
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500554 vendor_init();
Jason Huangd33b4d82019-05-15 18:22:57 +0800555 /* Initialize host subsystem */
556 err = bcmolt_host_init(&init_parms);
557 if (BCM_ERR_OK != err) {
558 BCM_LOG(ERROR, openolt_log_id, "Failed to init OLT\n");
559 return bcm_to_grpc_err(err, "Failed to init OLT");
560 }
Craig Lutgen967a1d02018-11-27 10:41:51 -0600561
Jason Huangd33b4d82019-05-15 18:22:57 +0800562 /* Create CLI session */
563 memset(&mon_session_parm, 0, sizeof(mon_session_parm));
564 mon_session_parm.get_prompt = openolt_cli_get_prompt_cb;
565 mon_session_parm.access_right = BCMCLI_ACCESS_ADMIN;
566 bcmos_errno rc = bcmcli_session_open(&mon_session_parm, &current_session);
567 BUG_ON(rc != BCM_ERR_OK);
568
569 /* API CLI */
570 bcm_openolt_api_cli_init(NULL, current_session);
571
572 /* Add quit command */
573 BCMCLI_MAKE_CMD_NOPARM(NULL, "quit", "Quit", bcm_cli_quit);
574
575 err = bcmolt_apiend_cli_init();
576 if (BCM_ERR_OK != err) {
577 BCM_LOG(ERROR, openolt_log_id, "Failed to add apiend init\n");
578 return bcm_to_grpc_err(err, "Failed to add apiend init");
579 }
580
581 bcmos_fastlock_init(&data_lock, 0);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500582 BCM_LOG(INFO, openolt_log_id, "Enable OLT - %s-%s\n", VENDOR_ID, MODEL_ID);
583
Jason Huangd33b4d82019-05-15 18:22:57 +0800584 if (bcmolt_api_conn_mgr_is_connected(dev_id))
585 {
586 Status status = SubscribeIndication();
587 if (!status.ok()) {
588 BCM_LOG(ERROR, openolt_log_id, "SubscribeIndication failed - %s : %s\n",
589 grpc_status_code_to_string(status.error_code()).c_str(),
590 status.error_message().c_str());
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400591
Jason Huangd33b4d82019-05-15 18:22:57 +0800592 return status;
593 }
594 bcmos_errno err;
595 bcmolt_odid dev;
596 for (dev = 0; dev < BCM_MAX_DEVS_PER_LINE_CARD; dev++) {
597 bcmolt_device_cfg dev_cfg = { };
598 bcmolt_device_key dev_key = { };
599 dev_key.device_id = dev;
600 BCMOLT_CFG_INIT(&dev_cfg, device, dev_key);
601 BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode);
602 err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr);
603 if (err == BCM_ERR_NOT_CONNECTED) {
604 bcmolt_device_key key = {.device_id = dev};
605 bcmolt_device_connect oper;
606 bcmolt_device_cfg cfg;
607 BCM_LOG(INFO, openolt_log_id, "Enable Maple - %d/%d\n", dev, BCM_MAX_DEVS_PER_LINE_CARD);
608 BCMOLT_OPER_INIT(&oper, device, connect, key);
609 BCMOLT_MSG_FIELD_SET(&oper, inni_config.mode, BCMOLT_INNI_MODE_ALL_10_G_XFI);
610 BCMOLT_MSG_FIELD_SET (&oper, system_mode, BCMOLT_SYSTEM_MODE_XGPON__2_X);
611 err = bcmolt_oper_submit(dev_id, &oper.hdr);
612 if (err)
613 BCM_LOG(ERROR, openolt_log_id, "Enable Maple deivce %d failed\n", dev);
614 bcmos_usleep(200000);
615 }
616 else
617 BCM_LOG(ERROR, openolt_log_id, "Maple deivce %d already connected\n", dev);
618 }
619 init_stats();
Shad Ansari627b5782018-08-13 22:49:32 +0000620 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000621 }
Shad Ansariedef2132018-08-10 22:14:50 +0000622
Jason Huangd33b4d82019-05-15 18:22:57 +0800623 /* Start CLI */
624 BCM_LOG(INFO, def_log_id, "Starting CLI\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400625 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000626 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400627}
628
629Status Disable_() {
630 // bcmbal_access_terminal_cfg acc_term_obj;
631 // bcmbal_access_terminal_key key = { };
632 //
633 // if (state::is_activated) {
634 // std::cout << "Disable OLT" << std::endl;
635 // key.access_term_id = DEFAULT_ATERM_ID;
636 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
637 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
638 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
639 // if (err) {
640 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
641 // return bcm_to_grpc_err(err, "Failed to disable OLT");
642 // }
643 // }
644 // //If already disabled, generate an extra indication ????
645 // return Status::OK;
646 //This fails with Operation Not Supported, bug ???
647
648 //TEMPORARY WORK AROUND
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800649 Status status = DisableUplinkIf_(nni_intf_id);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400650 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000651 state.deactivate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400652 openolt::Indication ind;
653 openolt::OltIndication* olt_ind = new openolt::OltIndication;
654 olt_ind->set_oper_state("down");
655 ind.set_allocated_olt_ind(olt_ind);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400656 BCM_LOG(INFO, openolt_log_id, "Disable OLT, add an extra indication\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400657 oltIndQ.push(ind);
658 }
659 return status;
660
661}
662
663Status Reenable_() {
664 Status status = EnableUplinkIf_(0);
665 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000666 state.activate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400667 openolt::Indication ind;
668 openolt::OltIndication* olt_ind = new openolt::OltIndication;
669 olt_ind->set_oper_state("up");
670 ind.set_allocated_olt_ind(olt_ind);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400671 BCM_LOG(INFO, openolt_log_id, "Reenable OLT, add an extra indication\n");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400672 oltIndQ.push(ind);
673 }
674 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000675}
676
Jason Huangd33b4d82019-05-15 18:22:57 +0800677bcmos_errno get_pon_interface_status(bcmolt_interface pon_ni, bcmolt_interface_state *state) {
678 bcmos_errno err;
679 bcmolt_pon_interface_key pon_key;
680 bcmolt_pon_interface_cfg pon_cfg;
681 pon_key.pon_ni = pon_ni;
682
683 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
684 BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, state);
685 BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, itu);
686 err = bcmolt_cfg_get(dev_id, &pon_cfg.hdr);
687 *state = pon_cfg.data.state;
688 return err;
689}
690
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000691Status EnablePonIf_(uint32_t intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800692 bcmos_errno err = BCM_ERR_OK;
693 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id};
694 bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state;
695 bcmolt_interface_state state;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000696
Jason Huangd33b4d82019-05-15 18:22:57 +0800697 err = get_pon_interface_status((bcmolt_interface)intf_id, &state);
698 if (err == BCM_ERR_OK) {
699 if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) {
700 BCM_LOG(INFO, openolt_log_id, "PON interface: %d already enabled\n", intf_id);
701 return Status::OK;
702 }
703 }
704 BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key);
705 BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data,
706 operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING);
707 err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr);
708 if (err != BCM_ERR_OK) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400709 BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400710 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000711 }
712
713 return Status::OK;
714}
715
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400716Status DisableUplinkIf_(uint32_t intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800717 bcmolt_pon_interface_key intf_key = {.pon_ni = (uint8_t)intf_id};
718 bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400719
Jason Huangd33b4d82019-05-15 18:22:57 +0800720 BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key);
721 BCMOLT_MSG_FIELD_SET(&pon_interface_set_state, operation, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING );
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400722
Jason Huangd33b4d82019-05-15 18:22:57 +0800723 bcmos_errno err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr);
724 if (err == BCM_ERR_OK) {
725 /* Wait for the interface activation to successfully complete */
726 BCM_LOG(DEBUG, openolt_log_id, "PON interface: %d already enabled\n", intf_id);
727 return Status::OK;
728 } else {
729 BCM_LOG(ERROR, openolt_log_id, "Failed to enable PON interface: %d\n", intf_id);
730 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400731 }
732
733 return Status::OK;
734}
735
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500736Status ProbeDeviceCapabilities_() {
Jason Huangd33b4d82019-05-15 18:22:57 +0800737 bcmos_errno err;
738 bcmolt_device_cfg dev_cfg = { };
739 bcmolt_device_key dev_key = { };
740 bcmolt_olt_cfg olt_cfg = { };
741 bcmolt_olt_key olt_key = { };
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500742
Jason Huangd33b4d82019-05-15 18:22:57 +0800743 dev_key.device_id = dev_id;
744 BCMOLT_CFG_INIT(&dev_cfg, device, dev_key);
745 BCMOLT_MSG_FIELD_GET(&dev_cfg, firmware_sw_version);
746 BCMOLT_MSG_FIELD_GET(&dev_cfg, chip_family);
747 BCMOLT_MSG_FIELD_GET(&dev_cfg, system_mode);
748 err = bcmolt_cfg_get(dev_id, &dev_cfg.hdr);
749 if (err) {
750 BCM_LOG(ERROR, openolt_log_id, "device: Failed to query OLT\n");
751 return bcm_to_grpc_err(err, "device: Failed to query OLT");
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500752 }
753
Jason Huangd33b4d82019-05-15 18:22:57 +0800754 bcmolt_topology_map topo_map[BCM_MAX_PONS_PER_OLT] = { };
755 bcmolt_topology topo = { };
756 topo.topology_maps.len = BCM_MAX_PONS_PER_OLT;
757 topo.topology_maps.arr = &topo_map[0];
758 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
759 BCMOLT_MSG_FIELD_GET(&olt_cfg, bal_state);
760 BCMOLT_FIELD_SET_PRESENT(&olt_cfg.data, olt_cfg_data, topology);
761 BCMOLT_CFG_LIST_BUF_SET(&olt_cfg, olt, topo.topology_maps.arr,
762 sizeof(bcmolt_topology_map) * topo.topology_maps.len);
763 err = bcmolt_cfg_get(dev_id, &olt_cfg.hdr);
764 if (err) {
765 BCM_LOG(ERROR, openolt_log_id, "cfg: Failed to query OLT\n");
766 return bcm_to_grpc_err(err, "cfg: Failed to query OLT");
767 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500768
769 std::string bal_version;
Jason Huangd33b4d82019-05-15 18:22:57 +0800770 bal_version += std::to_string(dev_cfg.data.firmware_sw_version.major)
771 + "." + std::to_string(dev_cfg.data.firmware_sw_version.minor)
772 + "." + std::to_string(dev_cfg.data.firmware_sw_version.revision);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500773 firmware_version = "BAL." + bal_version + "__" + firmware_version;
774
Jason Huangd33b4d82019-05-15 18:22:57 +0800775 switch(dev_cfg.data.system_mode) {
776 case 9 ... 12: board_technology = "GPON"; break;
777 case 13 ... 16: board_technology = "XGPON"; break;
778 case 18 ... 20: board_technology = "XGS-PON"; break;
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500779 }
780
Jason Huangd33b4d82019-05-15 18:22:57 +0800781 switch(dev_cfg.data.chip_family) {
782 case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6862_X_: chip_family = "Maple"; break;
783 case BCMOLT_CHIP_FAMILY_CHIP_FAMILY_6865_X_: chip_family = "Aspen"; break;
784 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500785
Jason Huangd33b4d82019-05-15 18:22:57 +0800786 num_of_nni_ports = olt_cfg.data.topology.num_switch_ports;
787 num_of_pon_ports = olt_cfg.data.topology.topology_maps.len;
788
789 BCM_LOG(INFO, openolt_log_id, "OLT capabilitites, oper_state: %s\n",
790 olt_cfg.data.bal_state == BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY
791 ? "up" : "down");
792
793 BCM_LOG(INFO, openolt_log_id, "--------------- version %s object model: %d\n",
794 bal_version.c_str(), BAL_API_VERSION);
795
796 BCM_LOG(INFO, openolt_log_id, "--------------- topology nni:%d pon:%d dev:%d ppd:%d family: %s\n",
797 num_of_nni_ports,
798 num_of_pon_ports,
799 BCM_MAX_DEVS_PER_LINE_CARD,
800 BCM_MAX_PONS_PER_DEV,
801 chip_family.c_str());
802
803 BCM_LOG(INFO, openolt_log_id, "PON num_intfs: %d global board_technology: %s\n",
804 num_of_pon_ports, board_technology.c_str());
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500805
806 return Status::OK;
807}
808
809Status ProbePonIfTechnology_() {
810 // Probe maximum extent possible as configured into BAL driver to determine
811 // which are active in the current BAL topology. And for those
812 // that are active, determine each port's access technology, i.e. "gpon" or "xgspon".
813 for (uint32_t intf_id = 0; intf_id < num_of_pon_ports; ++intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800814 bcmolt_pon_interface_cfg interface_obj;
815 bcmolt_pon_interface_key interface_key;
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500816
Jason Huangd33b4d82019-05-15 18:22:57 +0800817 interface_key.pon_ni = intf_id;
818 BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key);
819 BCMOLT_MSG_FIELD_GET(&interface_obj, gpon_trx);
820 BCMOLT_MSG_FIELD_GET(&interface_obj, xgpon_trx);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500821
Jason Huangd33b4d82019-05-15 18:22:57 +0800822 bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500823 if (err != BCM_ERR_OK) {
Craig Lutgenb2601f02018-10-23 13:04:31 -0500824 intf_technologies[intf_id] = UNKNOWN_TECH;
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500825 if(err != BCM_ERR_RANGE) BCM_LOG(ERROR, openolt_log_id, "Failed to get PON config: %d\n", intf_id);
826 }
827 else {
Jason Huangd33b4d82019-05-15 18:22:57 +0800828 if (board_technology == "XGPON") {
829 switch(interface_obj.data.xgpon_trx.transceiver_type) {
830 case BCMOLT_XGPON_TRX_TYPE_LTH_7222_PC:
831 case BCMOLT_XGPON_TRX_TYPE_WTD_RTXM266_702:
832 case BCMOLT_XGPON_TRX_TYPE_LTH_7222_BC_PLUS:
833 case BCMOLT_XGPON_TRX_TYPE_LTH_7226_PC:
834 case BCMOLT_XGPON_TRX_TYPE_LTH_5302_PC:
835 case BCMOLT_XGPON_TRX_TYPE_LTH_7226_A_PC_PLUS:
836 case BCMOLT_XGPON_TRX_TYPE_D272RR_SSCB_DM:
837 intf_technologies[intf_id] = "XGPON";
838 break;
839 }
840 } else if (board_technology == "GPON") {
841 switch(interface_obj.data.gpon_trx.transceiver_type) {
842 case BCMOLT_TRX_TYPE_SPS_43_48_H_HP_CDE_SD_2013:
843 case BCMOLT_TRX_TYPE_LTE_3680_M:
844 case BCMOLT_TRX_TYPE_SOURCE_PHOTONICS:
845 case BCMOLT_TRX_TYPE_LTE_3680_P_TYPE_C_PLUS:
846 case BCMOLT_TRX_TYPE_LTE_3680_P_BC:
847 intf_technologies[intf_id] = "GPON";
848 break;
849 }
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500850 }
Craig Lutgenb2601f02018-10-23 13:04:31 -0500851
852 if (board_technology != UNKNOWN_TECH) {
853 board_technology = intf_technologies[intf_id];
854 } else if (board_technology != MIXED_TECH && board_technology != intf_technologies[intf_id]) {
855 intf_technologies[intf_id] = MIXED_TECH;
856 }
857
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500858 }
859 }
860
861 return Status::OK;
862}
863
864unsigned NumNniIf_() {return num_of_nni_ports;}
865unsigned NumPonIf_() {return num_of_pon_ports;}
866
Jason Huangd33b4d82019-05-15 18:22:57 +0800867bcmos_errno get_nni_interface_status(bcmolt_interface id, bcmolt_interface_state *state) {
868 bcmos_errno err;
869 bcmolt_nni_interface_key nni_key;
870 bcmolt_nni_interface_cfg nni_cfg;
871 nni_key.id = id;
872
873 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
874 BCMOLT_FIELD_SET_PRESENT(&nni_cfg.data, nni_interface_cfg_data, state);
875 err = bcmolt_cfg_get(dev_id, &nni_cfg.hdr);
876 *state = nni_cfg.data.state;
877 return err;
878}
879
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400880Status EnableUplinkIf_(uint32_t intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800881 bcmos_errno err = BCM_ERR_OK;
882 bcmolt_nni_interface_key intf_key = {.id = (bcmolt_interface)intf_id};
883 bcmolt_nni_interface_set_nni_state nni_interface_set_state;
884 bcmolt_interface_state state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400885
Jason Huangd33b4d82019-05-15 18:22:57 +0800886 err = get_nni_interface_status((bcmolt_interface)intf_id, &state);
887 if (err == BCM_ERR_OK) {
888 if (state == BCMOLT_INTERFACE_STATE_ACTIVE_WORKING) {
889 BCM_LOG(INFO, openolt_log_id, "NNI interface: %d already enabled\n", intf_id);
890 return Status::OK;
891 }
Craig Lutgend0bae9b2018-10-18 18:02:07 -0500892 }
893
Jason Huangd33b4d82019-05-15 18:22:57 +0800894 BCMOLT_OPER_INIT(&nni_interface_set_state, nni_interface, set_nni_state, intf_key);
895 BCMOLT_FIELD_SET(&nni_interface_set_state.data, nni_interface_set_nni_state_data,
896 nni_state, BCMOLT_INTERFACE_OPERATION_ACTIVE_WORKING);
897 err = bcmolt_oper_submit(dev_id, &nni_interface_set_state.hdr);
898 if (err != BCM_ERR_OK) {
899 BCM_LOG(ERROR, openolt_log_id, "Failed to enable NNI interface: %d, err %d\n", intf_id, err);
900 return bcm_to_grpc_err(err, "Failed to enable NNI interface");
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400901 }
902
903 return Status::OK;
904}
905
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400906Status DisablePonIf_(uint32_t intf_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +0800907 bcmolt_pon_interface_cfg interface_obj;
908 bcmolt_pon_interface_key interface_key;
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400909
Jason Huangd33b4d82019-05-15 18:22:57 +0800910 interface_key.pon_ni = intf_id;
911 BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key);
912 BCMOLT_MSG_FIELD_GET(&interface_obj, state);
913 bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400914 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400915 BCM_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n", intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400916 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400917 }
918
919 return Status::OK;
920}
921
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000922Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700923 const char *vendor_id, const char *vendor_specific, uint32_t pir) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000924
Jason Huangd33b4d82019-05-15 18:22:57 +0800925 bcmolt_onu_cfg cfg_obj;
926 bcmolt_onu_key key;
927 bcmolt_serial_number serial_number; /**< ONU serial number */
928 bcmolt_bin_str_36 registration_id; /**< ONU registration ID */
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000929
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700930 BCM_LOG(INFO, openolt_log_id, "Enabling ONU %d on PON %d : vendor id %s, vendor specific %s, pir %d\n",
931 onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str(), pir);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000932
Jason Huangd33b4d82019-05-15 18:22:57 +0800933 key.onu_id = onu_id;
934 key.pon_ni = intf_id;
935 BCMOLT_CFG_INIT(&cfg_obj, onu, key);
936 memcpy(serial_number.vendor_id.arr, vendor_id, 4);
937 memcpy(serial_number.vendor_specific.arr, vendor_specific, 4);
938 BCMOLT_MSG_FIELD_SET(&cfg_obj, itu.serial_number, serial_number);
939 BCMOLT_MSG_FIELD_SET(&cfg_obj, itu.auto_learning, BCMOS_TRUE);
940 /*set burst and data profiles to fec disabled*/
941 BCMOLT_MSG_FIELD_SET(&cfg_obj, itu.xgpon.ranging_burst_profile, 0);
942 BCMOLT_MSG_FIELD_SET(&cfg_obj, itu.xgpon.data_burst_profile, 1);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000943
Jason Huangd33b4d82019-05-15 18:22:57 +0800944 bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg_obj.hdr);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400945 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400946 BCM_LOG(ERROR, openolt_log_id, "Failed to enable ONU %d on PON %d\n", onu_id, intf_id);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400947 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000948 }
Jason Huangd33b4d82019-05-15 18:22:57 +0800949
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700950 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000951}
952
Jonathan Davis70c21812018-07-19 15:32:10 -0400953Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
954 const char *vendor_id, const char *vendor_specific) {
955
Jason Huangd33b4d82019-05-15 18:22:57 +0800956 bcmolt_onu_cfg cfg_obj;
957 bcmolt_onu_key key;
958 bcmolt_serial_number serial_number; /**< ONU serial number */
959 bcmolt_bin_str_36 registration_id; /**< ONU registration ID */
Jonathan Davis70c21812018-07-19 15:32:10 -0400960
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400961 BCM_LOG(INFO, openolt_log_id, "Deactivating ONU %d on PON %d : vendor id %s, vendor specific %s\n",
Craig Lutgend0bae9b2018-10-18 18:02:07 -0500962 onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str());
Jonathan Davis70c21812018-07-19 15:32:10 -0400963
Jason Huangd33b4d82019-05-15 18:22:57 +0800964 key.onu_id= onu_id;
965 key.pon_ni = intf_id;
966 BCMOLT_CFG_INIT(&cfg_obj, onu, key);
967 BCMOLT_MSG_FIELD_SET(&cfg_obj, onu_state, BCMOLT_ONU_STATE_INACTIVE);
Jonathan Davis70c21812018-07-19 15:32:10 -0400968
Jason Huangd33b4d82019-05-15 18:22:57 +0800969 bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg_obj.hdr);
970 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400971 BCM_LOG(ERROR, openolt_log_id, "Failed to deactivate ONU %d on PON %d\n", onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400972 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
973 }
974
975 return Status::OK;
976}
977
978Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700979 const char *vendor_id, const char *vendor_specific) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400980
Craig Lutgend0bae9b2018-10-18 18:02:07 -0500981 BCM_LOG(INFO, openolt_log_id, "DeleteOnu ONU %d on PON %d : vendor id %s, vendor specific %s\n",
982 onu_id, intf_id, vendor_id, vendor_specific_to_str(vendor_specific).c_str());
983
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400984 // Need to deactivate before removing it (BAL rules)
985
986 DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
987 // Sleep to allow the state to propagate
988 // We need the subscriber terminal object to be admin down before removal
989 // Without sleep the race condition is lost by ~ 20 ms
990 std::this_thread::sleep_for(std::chrono::milliseconds(100));
991
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700992 // TODO: Delete the schedulers and queues.
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400993
Jason Huangd33b4d82019-05-15 18:22:57 +0800994 bcmolt_onu_cfg cfg_obj;
995 bcmolt_onu_key key;
Jonathan Davis70c21812018-07-19 15:32:10 -0400996
Nicolas Palpacuer967438f2018-09-07 14:41:54 -0400997 BCM_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
998 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -0400999
Jason Huangd33b4d82019-05-15 18:22:57 +08001000 key.onu_id = onu_id;
1001 key.pon_ni = intf_id;
1002 BCMOLT_CFG_INIT(&cfg_obj, onu, key);
Jonathan Davis70c21812018-07-19 15:32:10 -04001003
Jason Huangd33b4d82019-05-15 18:22:57 +08001004 bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr);
Jonathan Davis70c21812018-07-19 15:32:10 -04001005 if (err != BCM_ERR_OK)
1006 {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001007 BCM_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d\n",
1008 onu_id, intf_id);
Jonathan Davis70c21812018-07-19 15:32:10 -04001009 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
1010 }
1011
Jason Huangd33b4d82019-05-15 18:22:57 +08001012 return Status::OK;
Jonathan Davis70c21812018-07-19 15:32:10 -04001013}
1014
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001015#define MAX_CHAR_LENGTH 20
1016#define MAX_OMCI_MSG_LENGTH 44
1017Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001018 bcmolt_bin_str buf = {};
1019 bcmolt_onu_cpu_packets omci_cpu_packets;
1020 bcmolt_onu_key key;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001021
Jason Huangd33b4d82019-05-15 18:22:57 +08001022 key.pon_ni = intf_id;
1023 key.onu_id = onu_id;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001024
Jason Huangd33b4d82019-05-15 18:22:57 +08001025 BCMOLT_OPER_INIT(&omci_cpu_packets, onu, cpu_packets, key);
1026 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_OMCI);
1027 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, calc_crc, BCMOS_TRUE);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001028
1029 // ???
1030 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
1031 buf.len = MAX_OMCI_MSG_LENGTH;
1032 } else {
1033 buf.len = pkt.size()/2;
1034 }
1035
1036 /* Send the OMCI packet using the BAL remote proxy API */
1037 uint16_t idx1 = 0;
1038 uint16_t idx2 = 0;
1039 uint8_t arraySend[buf.len];
1040 char str1[MAX_CHAR_LENGTH];
1041 char str2[MAX_CHAR_LENGTH];
1042 memset(&arraySend, 0, buf.len);
1043
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001044 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
1045 sprintf(str1,"%c", pkt[idx1]);
1046 sprintf(str2,"%c", pkt[++idx1]);
1047 strcat(str1,str2);
1048 arraySend[idx2] = strtol(str1, NULL, 16);
1049 }
1050
Jason Huangd33b4d82019-05-15 18:22:57 +08001051 buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
1052 memcpy(buf.arr, (uint8_t *)arraySend, buf.len);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001053
Jason Huangd33b4d82019-05-15 18:22:57 +08001054 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, number_of_packets, 1);
1055 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, packet_size, buf.len);
1056 BCMOLT_MSG_FIELD_SET(&omci_cpu_packets, buffer, buf);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001057
Jason Huangd33b4d82019-05-15 18:22:57 +08001058 bcmos_errno err = bcmolt_oper_submit(dev_id, &omci_cpu_packets.hdr);
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001059 if (err) {
1060 BCM_LOG(ERROR, omci_log_id, "Error sending OMCI message to ONU %d on PON %d\n", onu_id, intf_id);
1061 } else {
1062 BCM_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 -05001063 buf.len, onu_id, intf_id, pkt.c_str());
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001064 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001065 free(buf.arr);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001066
1067 return Status::OK;
1068}
1069
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001070Status 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 +08001071 bcmolt_pon_interface_cpu_packets pon_interface_cpu_packets; /**< declare main API struct */
1072 bcmolt_pon_interface_key key = {.pon_ni = (bcmolt_interface)intf_id}; /**< declare key */
1073 bcmolt_bin_str buf = {};
1074 bcmolt_gem_port_id gem_port_id_array[1];
1075 bcmolt_gem_port_id_list_u8_max_16 gem_port_list = {};
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001076
Craig Lutgen967a1d02018-11-27 10:41:51 -06001077 if (port_no > 0) {
1078 bool found = false;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001079 if (gemport_id == 0) {
1080 bcmos_fastlock_lock(&data_lock);
1081 // Map the port_no to one of the flows that owns it to find a gemport_id for that flow.
1082 // Pick any flow that is mapped with the same port_no.
1083 std::map<uint32_t, std::set<uint32_t> >::const_iterator it = port_to_flows.find(port_no);
1084 if (it != port_to_flows.end() && !it->second.empty()) {
1085 uint32_t flow_id = *(it->second.begin()); // Pick any flow_id out of the bag set
1086 std::map<uint32_t, uint32_t>::const_iterator fit = flowid_to_gemport.find(flow_id);
1087 if (fit != flowid_to_gemport.end()) {
1088 found = true;
1089 gemport_id = fit->second;
1090 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001091 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001092 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001093
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001094 if (!found) {
1095 BCM_LOG(ERROR, openolt_log_id, "Packet out failed to find destination for ONU %d port_no %u on PON %d\n",
1096 onu_id, port_no, intf_id);
1097 return grpc::Status(grpc::StatusCode::NOT_FOUND, "no flow for port_no");
1098 }
1099 BCM_LOG(INFO, openolt_log_id, "Gem port %u found for ONU %d port_no %u on PON %d\n",
1100 gemport_id, onu_id, port_no, intf_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001101 }
1102
Jason Huangd33b4d82019-05-15 18:22:57 +08001103 gem_port_id_array[0] = gemport_id;
1104 gem_port_list.len = 1;
1105 gem_port_list.arr = gem_port_id_array;
1106 buf.len = pkt.size();
1107 buf.arr = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
1108 memcpy(buf.arr, (uint8_t *)pkt.data(), buf.len);
1109
1110 /* init the API struct */
1111 BCMOLT_OPER_INIT(&pon_interface_cpu_packets, pon_interface, cpu_packets, key);
1112 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, packet_type, BCMOLT_PACKET_TYPE_ETH);
1113 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, calc_crc, BCMOS_TRUE);
1114 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, gem_port_list, gem_port_list);
1115 BCMOLT_MSG_FIELD_SET(&pon_interface_cpu_packets, buffer, buf);
1116
Craig Lutgen967a1d02018-11-27 10:41:51 -06001117 BCM_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 +08001118 (uint8_t)pkt.size(), gemport_id, intf_id, port_no);
1119
1120 /* call API */
1121 bcmolt_oper_submit(0, &pon_interface_cpu_packets.hdr);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001122 }
1123 else {
Jason Huangd33b4d82019-05-15 18:22:57 +08001124 //TODO: Port No is 0, it is coming sender requirement.
1125 BCM_LOG(INFO, openolt_log_id, "port_no %d onu %d on pon %d\n",
1126 port_no, onu_id, intf_id);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001127 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001128 free(buf.arr);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001129
1130 return Status::OK;
1131}
1132
Jason Huangd33b4d82019-05-15 18:22:57 +08001133Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt, bcmolt_flow_id flow_id) {
1134 bcmolt_flow_cfg cfg;
1135 bcmolt_flow_key key = {}; /* declare key */
1136 bcmolt_bin_str buffer = {};
1137 bcmolt_flow_send_eth_packet oper; /* declare main API struct */
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001138
Jason Huangd33b4d82019-05-15 18:22:57 +08001139 key.flow_id = flow_id;
1140 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; /* send from uplink dirction */
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001141
Jason Huangd33b4d82019-05-15 18:22:57 +08001142 /* Initialize the API struct. */
1143 BCMOLT_OPER_INIT(&oper, flow, send_eth_packet, key);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001144
Jason Huangd33b4d82019-05-15 18:22:57 +08001145 buffer.len = pkt.size();
1146 buffer.arr = (uint8_t *)malloc((buffer.len)*sizeof(uint8_t));
1147 memcpy(buffer.arr, (uint8_t *)pkt.data(), buffer.len);
1148 if (buffer.arr == NULL) {
1149 BCM_LOG(ERROR, openolt_log_id, "allocate pakcet buffer failed\n");
1150 return bcm_to_grpc_err(BCM_ERR_PARM, "allocate pakcet buffer failed");
1151 }
1152 BCMOLT_FIELD_SET(&oper.data, flow_send_eth_packet_data, buffer, buffer);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001153
Jason Huangd33b4d82019-05-15 18:22:57 +08001154 bcmos_errno err = bcmolt_oper_submit(dev_id, &oper.hdr);
1155 if (err)
1156 BCM_LOG(ERROR, omci_log_id, "Error sending packets to port %d\n", intf_id);
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04001157
1158 return Status::OK;
1159}
1160
Jason Huangd33b4d82019-05-15 18:22:57 +08001161uint32_t GetPortNum_(uint32_t flow_id) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001162 bcmos_fastlock_lock(&data_lock);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001163 uint32_t port_no = 0;
1164 std::map<uint32_t, uint32_t >::const_iterator it = flowid_to_port.find(flow_id);
1165 if (it != flowid_to_port.end()) {
1166 port_no = it->second;
1167 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001168 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001169 return port_no;
1170}
1171
1172Status 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 +00001173 uint32_t flow_id, const std::string flow_type,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001174 int32_t alloc_id, int32_t network_intf_id,
1175 int32_t gemport_id, const ::openolt::Classifier& classifier,
Craig Lutgen967a1d02018-11-27 10:41:51 -06001176 const ::openolt::Action& action, int32_t priority_value, uint64_t cookie) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001177 bcmolt_flow_cfg cfg;
1178 bcmolt_flow_key key = { }; /**< Object key. */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001179 int32_t o_vid = -1;
1180 bool single_tag = false;
1181 uint32_t ether_type = 0;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001182
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001183 BCM_LOG(INFO, openolt_log_id, "flow add - intf_id %d, onu_id %d, uni_id %d, port_no %u, flow_id %d, flow_type %s, \
Jason Huangd33b4d82019-05-15 18:22:57 +08001184 gemport_id %d, network_intf_id %d, cookie %"PRIu64"\n", \
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001185 access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type.c_str(), gemport_id, network_intf_id, cookie);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001186
1187 key.flow_id = flow_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001188 if (flow_type.compare(upstream) == 0 ) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001189 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001190 } else if (flow_type.compare(downstream) == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001191 key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001192 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001193 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001194 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001195 }
1196
Jason Huangd33b4d82019-05-15 18:22:57 +08001197 BCMOLT_CFG_INIT(&cfg, flow, key);
1198 BCMOLT_MSG_FIELD_SET(&cfg, cookie, cookie);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001199
Shad Ansari39739bc2018-09-13 21:38:37 +00001200 if (access_intf_id >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001201 if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) {
1202 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1203 BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.intf_id, access_intf_id);
1204 } else if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
1205 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1206 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id);
1207 }
Shad Ansari39739bc2018-09-13 21:38:37 +00001208 }
1209 if (network_intf_id >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001210 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
1211 //TODO: The ingress type is NNI condition
1212 //BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.access_int_id.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_NNI);
1213 //BCMOLT_MSG_FIELD_SET(&cfg, ingress_intf.access_int_id.intf_id, network_intf_id);
1214 //The egress type is PON condition
1215 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_type, BCMOLT_FLOW_INTERFACE_TYPE_PON);
1216 BCMOLT_MSG_FIELD_SET(&cfg, egress_intf.intf_id, access_intf_id);
1217 }
Shad Ansari39739bc2018-09-13 21:38:37 +00001218 }
1219 if (onu_id >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001220 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001221 }
1222 if (gemport_id >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001223 BCMOLT_MSG_FIELD_SET(&cfg, svc_port_id, gemport_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001224 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001225 if (gemport_id >= 0 && port_no != 0) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001226 bcmos_fastlock_lock(&data_lock);
Jason Huangd33b4d82019-05-15 18:22:57 +08001227 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Craig Lutgen967a1d02018-11-27 10:41:51 -06001228 port_to_flows[port_no].insert(key.flow_id);
1229 flowid_to_gemport[key.flow_id] = gemport_id;
1230 }
1231 else
1232 {
1233 flowid_to_port[key.flow_id] = port_no;
1234 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001235 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001236 }
Shad Ansari39739bc2018-09-13 21:38:37 +00001237 if (priority_value >= 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001238 BCMOLT_MSG_FIELD_SET(&cfg, priority, priority_value);
Shad Ansari39739bc2018-09-13 21:38:37 +00001239 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001240
1241 {
Jason Huangd33b4d82019-05-15 18:22:57 +08001242 bcmolt_classifier val = { };
1243 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001244 if (classifier.o_tpid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001245 BCM_LOG(DEBUG, openolt_log_id, "classify o_tpid 0x%04x\n", classifier.o_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001246 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, o_tpid, classifier.o_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001247 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001248 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001249 if (classifier.o_vid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001250 BCM_LOG(DEBUG, openolt_log_id, "classify o_vid %d\n", classifier.o_vid());
Jason Huangd33b4d82019-05-15 18:22:57 +08001251 BCMOLT_FIELD_SET(&val, classifier, o_vid, classifier.o_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001252 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001253 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001254 if (classifier.i_tpid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001255 BCM_LOG(DEBUG, openolt_log_id, "classify i_tpid 0x%04x\n", classifier.i_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001256 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, i_tpid, classifier.i_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001257 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001258 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001259 if (classifier.i_vid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001260 BCM_LOG(DEBUG, openolt_log_id, "classify i_vid %d\n", classifier.i_vid());
Jason Huangd33b4d82019-05-15 18:22:57 +08001261 BCMOLT_FIELD_SET(&val, classifier, i_vid, classifier.i_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001262 }
1263
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001264 if (classifier.eth_type()) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001265 ether_type = classifier.eth_type();
Craig Lutgenecd353a2018-12-12 22:33:17 -06001266 BCM_LOG(DEBUG, openolt_log_id, "classify ether_type 0x%04x\n", classifier.eth_type());
Jason Huangd33b4d82019-05-15 18:22:57 +08001267 BCMOLT_FIELD_SET(&val, classifier, ether_type, classifier.eth_type());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001268 }
1269
1270 /*
1271 if (classifier.dst_mac()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001272 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_mac, classifier.dst_mac());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001273 }
1274
1275 if (classifier.src_mac()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001276 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_mac, classifier.src_mac());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001277 }
1278 */
1279
1280 if (classifier.ip_proto()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001281 BCM_LOG(DEBUG, openolt_log_id, "classify ip_proto %d\n", classifier.ip_proto());
Jason Huangd33b4d82019-05-15 18:22:57 +08001282 BCMOLT_FIELD_SET(&val, classifier, ip_proto, classifier.ip_proto());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001283 }
1284
1285 /*
1286 if (classifier.dst_ip()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001287 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, dst_ip, classifier.dst_ip());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001288 }
1289
1290 if (classifier.src_ip()) {
Craig Lutgen19512312018-11-02 10:14:46 -05001291 BCMBAL_ATTRIBUTE_PROP_SET(&val, classifier, src_ip, classifier.src_ip());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001292 }
1293 */
1294
1295 if (classifier.src_port()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001296 BCM_LOG(DEBUG, openolt_log_id, "classify src_port %d\n", classifier.src_port());
Jason Huangd33b4d82019-05-15 18:22:57 +08001297 BCMOLT_FIELD_SET(&val, classifier, src_port, classifier.src_port());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001298 }
1299
1300 if (classifier.dst_port()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001301 BCM_LOG(DEBUG, openolt_log_id, "classify dst_port %d\n", classifier.dst_port());
Jason Huangd33b4d82019-05-15 18:22:57 +08001302 BCMOLT_FIELD_SET(&val, classifier, dst_port, classifier.dst_port());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001303 }
1304
1305 if (!classifier.pkt_tag_type().empty()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001306 BCM_LOG(DEBUG, openolt_log_id, "classify tag_type %s\n", classifier.pkt_tag_type().c_str());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001307 if (classifier.pkt_tag_type().compare("untagged") == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001308 BCMOLT_FIELD_SET(&val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_UNTAGGED);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001309 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001310 BCMOLT_FIELD_SET(&val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_SINGLE_TAG);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001311 single_tag = true;
1312
Jason Huangd33b4d82019-05-15 18:22:57 +08001313 BCM_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits());
1314 BCMOLT_FIELD_SET(&val, classifier, o_pbits, classifier.o_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001315 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001316 BCMOLT_FIELD_SET(&val, classifier, pkt_tag_type, BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001317
Jason Huangd33b4d82019-05-15 18:22:57 +08001318 BCM_LOG(DEBUG, openolt_log_id, "classify o_pbits 0x%x\n", classifier.o_pbits());
1319 BCMOLT_FIELD_SET(&val, classifier, o_pbits, classifier.o_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001320 }
1321 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001322 BCMOLT_MSG_FIELD_SET(&cfg, classifier, val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001323 }
1324
1325 {
Jason Huangd33b4d82019-05-15 18:22:57 +08001326 bcmolt_action val = { };
1327 bcmolt_api_prop_path path;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001328
1329 const ::openolt::ActionCmd& cmd = action.cmd();
1330
1331 if (cmd.add_outer_tag()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001332 BCM_LOG(INFO, openolt_log_id, "action add o_tag\n");
Jason Huangd33b4d82019-05-15 18:22:57 +08001333 BCMOLT_FIELD_SET(&val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001334 }
1335
1336 if (cmd.remove_outer_tag()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001337 BCM_LOG(INFO, openolt_log_id, "action pop o_tag\n");
Jason Huangd33b4d82019-05-15 18:22:57 +08001338 BCMOLT_FIELD_SET(&val, action, cmds_bitmask, BCMOLT_ACTION_CMD_ID_REMOVE_OUTER_TAG);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001339 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001340 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001341 if (cmd.trap_to_host()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001342 BCM_LOG(INFO, openolt_log_id, "action trap-to-host\n");
Craig Lutgen19512312018-11-02 10:14:46 -05001343 BCMBAL_ATTRIBUTE_PROP_SET(&val, action, cmds_bitmask, BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001344 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001345 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001346 if (action.o_vid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001347 BCM_LOG(INFO, openolt_log_id, "action o_vid=%d\n", action.o_vid());
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001348 o_vid = action.o_vid();
Jason Huangd33b4d82019-05-15 18:22:57 +08001349 BCMOLT_FIELD_SET(&val, action, o_vid, action.o_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001350 }
1351
1352 if (action.o_pbits()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001353 BCM_LOG(INFO, openolt_log_id, "action o_pbits=0x%x\n", action.o_pbits());
Jason Huangd33b4d82019-05-15 18:22:57 +08001354 BCMOLT_FIELD_SET(&val, action, o_pbits, action.o_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001355 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001356 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001357 if (action.o_tpid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001358 BCM_LOG(INFO, openolt_log_id, "action o_tpid=0x%04x\n", action.o_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001359 BCMBAL_ATTRIBUTE_PROP_SET(&val, action, o_tpid, action.o_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001360 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001361 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001362 if (action.i_vid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001363 BCM_LOG(INFO, openolt_log_id, "action i_vid=%d\n", action.i_vid());
Jason Huangd33b4d82019-05-15 18:22:57 +08001364 BCMOLT_FIELD_SET(&val, action, i_vid, action.i_vid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001365 }
1366
1367 if (action.i_pbits()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001368 BCM_LOG(DEBUG, openolt_log_id, "action i_pbits=0x%x\n", action.i_pbits());
Jason Huangd33b4d82019-05-15 18:22:57 +08001369 BCMOLT_FIELD_SET(&val, action, i_pbits, action.i_pbits());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001370 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001371 /* removed by BAL v3.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001372 if (action.i_tpid()) {
Craig Lutgenecd353a2018-12-12 22:33:17 -06001373 BCM_LOG(DEBUG, openolt_log_id, "action i_tpid=0x%04x\n", action.i_tpid());
Craig Lutgen19512312018-11-02 10:14:46 -05001374 BCMBAL_ATTRIBUTE_PROP_SET(&val, action, i_tpid, action.i_tpid());
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001375 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001376 */
1377 BCMOLT_MSG_FIELD_SET(&cfg, action, val);
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001378 }
1379
Shad Ansari39739bc2018-09-13 21:38:37 +00001380 if ((access_intf_id >= 0) && (onu_id >= 0)) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001381 bcmolt_tm_queue_ref val = { };
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001382
Jason Huangd33b4d82019-05-15 18:22:57 +08001383 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001384 if (single_tag && ether_type == EAP_ETHER_TYPE) {
1385 val.sched_id = get_default_tm_sched_id(access_intf_id, downstream);
1386 val.queue_id = 0;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001387 } else {
1388 val.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, downstream); // Subscriber Scheduler
1389 val.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, downstream);
1390 }
Girish Gowdru36501552019-05-01 23:47:58 -07001391 BCM_LOG(INFO, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d\n", \
1392 downstream.c_str(), val.queue_id, val.sched_id);
Jason Huangd33b4d82019-05-15 18:22:57 +08001393
1394 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE);
1395 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, val.sched_id);
1396 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, val.queue_id);
1397 } else if (key.flow_type == BCMOLT_FLOW_TYPE_UPSTREAM) {
1398 /* removed by BAL v3.0. N/A - Alloc ID is out of the scope of BAL. Used for OMCI only.
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001399 bcmbal_tm_sched_id val1;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001400 val1 = get_tm_sched_id(access_intf_id, onu_id, uni_id, upstream); // DBA Scheduler ID
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001401 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val1);
Jason Huangd33b4d82019-05-15 18:22:57 +08001402 */
1403 val.sched_id = get_default_tm_sched_id(network_intf_id, upstream); // NNI Scheduler ID
1404 val.queue_id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, upstream); // Queue on NNI
Girish Gowdru36501552019-05-01 23:47:58 -07001405 BCM_LOG(INFO, openolt_log_id, "direction = %s, queue_id = %d, sched_id = %d\n", \
Jason Huangd33b4d82019-05-15 18:22:57 +08001406 upstream.c_str(), val.queue_id, val.sched_id);
Shad Ansari39739bc2018-09-13 21:38:37 +00001407 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001408 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.type, BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE);
1409 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.tm_sched.id, val.sched_id);
1410 BCMOLT_MSG_FIELD_SET(&cfg , egress_qos.u.fixed_queue.queue_id, val.queue_id);
Shad Ansari06101952018-07-25 00:22:09 +00001411 }
1412
Jason Huangd33b4d82019-05-15 18:22:57 +08001413 BCMOLT_MSG_FIELD_SET(&cfg, state, BCMOLT_FLOW_STATE_ENABLE);
1414 bcmos_errno err = bcmolt_cfg_set(dev_id, &cfg.hdr);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001415 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001416 BCM_LOG(ERROR, openolt_log_id, "Flow add failed\n");
Nicolas Palpacuer73222e02018-07-16 12:20:26 -04001417 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001418 }
1419
1420 return Status::OK;
1421}
1422
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001423Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
1424
Jason Huangd33b4d82019-05-15 18:22:57 +08001425 bcmolt_flow_cfg cfg;
1426 bcmolt_flow_key key = { };
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001427
Jason Huangd33b4d82019-05-15 18:22:57 +08001428 key.flow_id = (bcmolt_flow_id) flow_id;
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001429 key.flow_id = flow_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001430 if (flow_type.compare(upstream) == 0 ) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001431 key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001432 } else if (flow_type.compare(downstream) == 0) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001433 key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001434 } else {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001435 BCM_LOG(WARNING, openolt_log_id, "Invalid flow type %s\n", flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001436 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
1437 }
1438
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001439 bcmos_fastlock_lock(&data_lock);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001440 uint32_t port_no = flowid_to_port[key.flow_id];
Jason Huangd33b4d82019-05-15 18:22:57 +08001441 if (key.flow_type == BCMOLT_FLOW_TYPE_DOWNSTREAM) {
Craig Lutgen967a1d02018-11-27 10:41:51 -06001442 flowid_to_gemport.erase(key.flow_id);
1443 port_to_flows[port_no].erase(key.flow_id);
1444 if (port_to_flows[port_no].empty()) port_to_flows.erase(port_no);
1445 }
1446 else
1447 {
1448 flowid_to_port.erase(key.flow_id);
1449 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001450 bcmos_fastlock_unlock(&data_lock, 0);
Craig Lutgen967a1d02018-11-27 10:41:51 -06001451
Jason Huangd33b4d82019-05-15 18:22:57 +08001452 BCMOLT_CFG_INIT(&cfg, flow, key);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001453
Jason Huangd33b4d82019-05-15 18:22:57 +08001454 bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg.hdr);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001455 if (err) {
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001456 BCM_LOG(ERROR, openolt_log_id, "Error %d while removing flow %d, %s\n",
1457 err, flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001458 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
1459 }
1460
Nicolas Palpacuer967438f2018-09-07 14:41:54 -04001461 BCM_LOG(INFO, openolt_log_id, "Flow %d, %s removed\n", flow_id, flow_type.c_str());
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -04001462 return Status::OK;
1463}
1464
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001465bcmos_errno CreateSched(std::string direction, uint32_t intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t port_no,
1466 uint32_t alloc_id, tech_profile::AdditionalBW additional_bw, uint32_t weight, uint32_t priority,
1467 tech_profile::SchedulingPolicy sched_policy, tech_profile::TrafficShapingInfo tf_sh_info) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001468
1469 bcmos_errno err;
1470
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001471 if (direction == downstream) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001472
Jason Huangd33b4d82019-05-15 18:22:57 +08001473 bcmolt_tm_sched_cfg cfg;
1474 bcmolt_tm_sched_key key = { };
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001475 key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001476
Jason Huangd33b4d82019-05-15 18:22:57 +08001477 BCMOLT_CFG_INIT(&cfg, tm_sched, key);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001478
1479 {
1480 // bcmbal_tm_sched_owner
1481 // In downstream it is sub_term scheduler
Jason Huangd33b4d82019-05-15 18:22:57 +08001482 bcmolt_tm_sched_attachment_point attachment_point; /**< The output of the tm_sched object instance */
1483 BCMOLT_MSG_FIELD_SET(&cfg , attachment_point.u.interface.interface_ref.intf_type, BCMOLT_INTERFACE_TYPE_PON);
1484 BCMOLT_MSG_FIELD_SET(&cfg , attachment_point.u.interface.interface_ref.intf_id, intf_id);
1485 /* removed by BAL v3.0, N/A - No direct attachment point of type ONU, same functionality may
1486 be achieved using the' virtual' type of attachment.
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001487 tm_sched_owner.u.sub_term.intf_id = intf_id;
1488 tm_sched_owner.u.sub_term.sub_term_id = onu_id;
Jason Huangd33b4d82019-05-15 18:22:57 +08001489 */
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001490
1491 // bcmbal_tm_sched_type
1492 // set the deafult policy to strict priority
Jason Huangd33b4d82019-05-15 18:22:57 +08001493 BCMOLT_MSG_FIELD_SET(&cfg, sched_type, BCMOLT_TM_SCHED_TYPE_SP);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001494
1495 // bcmbal_tm_sched_parent
1496 // The parent for the sub_term scheduler is the PON scheduler in the downstream
Jason Huangd33b4d82019-05-15 18:22:57 +08001497
1498 BCMOLT_MSG_FIELD_SET(&cfg , attachment_point.u.tm_sched.tm_sched_id, get_default_tm_sched_id(intf_id, downstream));
1499 BCMOLT_FIELD_SET_PRESENT(&cfg.data.attachment_point.u.tm_sched.tm_sched_param.u.priority, tm_sched_param_priority, priority);
1500 BCMOLT_MSG_FIELD_SET(&cfg , attachment_point.u.tm_sched.tm_sched_param.u.priority.priority, 1);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001501
1502 // num_priorities: Max number of strict priority scheduling elements
Jason Huangd33b4d82019-05-15 18:22:57 +08001503 BCMOLT_MSG_FIELD_SET(&cfg, num_priorities, 8);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001504
1505 // bcmbal_tm_shaping
1506 if (tf_sh_info.cir() >= 0 && tf_sh_info.pir() > 0) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001507 uint32_t cir = tf_sh_info.cir();
1508 uint32_t pir = tf_sh_info.pir();
1509 uint32_t burst = tf_sh_info.pbs();
1510 BCM_LOG(INFO, openolt_log_id, "applying traffic shaping in DL cir=%u, pir=%u, burst=%u\n",
1511 cir, pir, burst);
Jason Huangd33b4d82019-05-15 18:22:57 +08001512 BCMOLT_FIELD_SET_PRESENT(&cfg.data.rate, tm_shaping, pir);
1513 BCMOLT_FIELD_SET_PRESENT(&cfg.data.rate, tm_shaping, burst);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001514 // FIXME: Setting CIR, results in BAL throwing error 'tm_sched minimum rate is not supported yet'
Jason Huangd33b4d82019-05-15 18:22:57 +08001515 BCMOLT_MSG_FIELD_SET(&cfg , rate.cir, cir);
1516 BCMOLT_MSG_FIELD_SET(&cfg , rate.pir, pir);
1517 BCMOLT_MSG_FIELD_SET(&cfg , rate.burst, burst);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001518 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001519 }
1520
Jason Huangd33b4d82019-05-15 18:22:57 +08001521 err = bcmolt_cfg_set(dev_id, &(cfg.hdr));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001522 if (err) {
1523 BCM_LOG(ERROR, openolt_log_id, "Failed to create downstream subscriber scheduler, id %d, intf_id %d, \
1524 onu_id %d, uni_id %d, port_no %u\n", key.id, intf_id, onu_id,uni_id,port_no);
1525 return err;
1526 }
1527 BCM_LOG(INFO, openolt_log_id, "Create downstream subscriber sched, id %d, intf_id %d, onu_id %d, \
1528 uni_id %d, port_no %u\n", key.id,intf_id,onu_id,uni_id,port_no);
1529
1530 } else { //upstream
Jason Huangd33b4d82019-05-15 18:22:57 +08001531 bcmolt_itupon_alloc_cfg cfg;
1532 bcmolt_itupon_alloc_key key = { };
1533 key.pon_ni = intf_id;
1534 key.alloc_id = alloc_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001535
Jason Huangd33b4d82019-05-15 18:22:57 +08001536 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
1537 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
1538 if (additional_bw == 2) //AdditionalBW_BestEffort
1539 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility,
1540 BCMOLT_ADDITIONAL_BW_ELIGIBILITY_BEST_EFFORT);
1541 else if (additional_bw == 3) //AdditionalBW_Auto
1542 BCMOLT_MSG_FIELD_SET(&cfg, sla.additional_bw_eligibility,
1543 BCMOLT_ADDITIONAL_BW_ELIGIBILITY_NON_ASSURED);
1544 /* CBR Real Time Bandwidth which require shaping of the bandwidth allocations
1545 in a fine granularity. */
1546 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_bw, 0);
1547 /* Fixed Bandwidth with no critical requirement of shaping */
1548 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_bw, 0);
1549 /* Dynamic bandwidth which the OLT is committed to allocate upon demand */
1550 BCMOLT_MSG_FIELD_SET(&cfg, sla.guaranteed_bw, 0);
1551 /* Maximum allocated bandwidth allowed for this alloc ID */
1552 BCMOLT_MSG_FIELD_SET(&cfg, sla.maximum_bw, tf_sh_info.pir());
1553 BCMOLT_MSG_FIELD_SET(&cfg, sla.alloc_type, BCMOLT_ALLOC_TYPE_NSR);
1554 /* Set to True for AllocID with CBR RT Bandwidth that requires compensation
1555 for skipped allocations during quiet window */
1556 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_compensation, BCMOS_FALSE);
1557 /**< Allocation Profile index for CBR non-RT Bandwidth */
1558 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_nrt_ap_index, 0);
1559 /**< Allocation Profile index for CBR RT Bandwidth */
1560 BCMOLT_MSG_FIELD_SET(&cfg, sla.cbr_rt_ap_index, 0);
1561 /**< Alloc ID Weight used in case of Extended DBA mode */
1562 BCMOLT_MSG_FIELD_SET(&cfg, sla.weight, 0);
1563 /**< Alloc ID Priority used in case of Extended DBA mode */
1564 BCMOLT_MSG_FIELD_SET(&cfg, sla.priority, 0);
1565 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, 2);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001566
Jason Huangd33b4d82019-05-15 18:22:57 +08001567 err = bcmolt_cfg_set(dev_id, &(cfg.hdr));
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001568 if (err) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001569 BCM_LOG(ERROR, openolt_log_id, "Failed to create upstream DBA sched, intf_id %d, onu_id %d, uni_id %d,\
1570 port_no %u, alloc_id %d\n", intf_id, onu_id,uni_id,port_no,alloc_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001571 return err;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001572 }
Jason Huangd33b4d82019-05-15 18:22:57 +08001573 BCM_LOG(INFO, openolt_log_id, "Create upstream DBA sched, intf_id %d, onu_id %d, uni_id %d, port_no %u, \
1574 alloc_id %d\n", intf_id,onu_id,uni_id,port_no,alloc_id);
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001575 }
1576
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001577 return BCM_ERR_OK;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001578}
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001579
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001580Status CreateTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) {
1581 uint32_t intf_id = traffic_scheds->intf_id();
1582 uint32_t onu_id = traffic_scheds->onu_id();
1583 uint32_t uni_id = traffic_scheds->uni_id();
1584 uint32_t port_no = traffic_scheds->port_no();
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001585 std::string direction;
1586 unsigned int alloc_id;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001587 tech_profile::SchedulerConfig sched_config;
1588 tech_profile::AdditionalBW additional_bw;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001589 uint32_t priority;
1590 uint32_t weight;
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001591 tech_profile::SchedulingPolicy sched_policy;
1592 tech_profile::TrafficShapingInfo traffic_shaping_info;
1593 bcmos_errno err;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001594
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001595 for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) {
1596 tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i);
1597 if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) {
1598 direction = upstream;
1599 } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) {
1600 direction = downstream;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001601 }
1602 else {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001603 BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_sched.direction());
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001604 return Status::CANCELLED;
1605 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001606 alloc_id = traffic_sched.alloc_id();
1607 sched_config = traffic_sched.scheduler();
1608 additional_bw = sched_config.additional_bw();
1609 priority = sched_config.priority();
1610 weight = sched_config.weight();
1611 sched_policy = sched_config.sched_policy();
1612 traffic_shaping_info = traffic_sched.traffic_shaping_info();
1613 err = CreateSched(direction, intf_id, onu_id, uni_id, port_no, alloc_id, additional_bw, weight, priority,
1614 sched_policy, traffic_shaping_info);
1615 if (err) {
1616 return bcm_to_grpc_err(err, "Failed to create scheduler");
1617 }
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -07001618 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001619 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001620}
Jonathan Davis70c21812018-07-19 15:32:10 -04001621
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001622bcmos_errno RemoveSched(int intf_id, int onu_id, int uni_id, std::string direction) {
Jonathan Davis70c21812018-07-19 15:32:10 -04001623
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001624 bcmos_errno err;
Jason Huangd33b4d82019-05-15 18:22:57 +08001625
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001626 if (direction == upstream) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001627 bcmolt_itupon_alloc_cfg cfg;
1628 bcmolt_itupon_alloc_key key = { };
1629 key.pon_ni = intf_id;
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001630
Jason Huangd33b4d82019-05-15 18:22:57 +08001631 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
1632 BCMOLT_MSG_FIELD_SET(&cfg, onu_id, onu_id);
1633 BCMOLT_CFG_INIT(&cfg, itupon_alloc, key);
1634 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
1635 if (err) {
1636 BCM_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, intf_id %d, onu_id %d\n", \
1637 direction.c_str(), intf_id, onu_id);
1638 return err;
1639 }
1640 BCM_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, intf_id %d, onu_id %d\n", \
1641 direction.c_str(), intf_id, onu_id);
1642 } else if (direction == downstream) {
1643 bcmolt_tm_sched_cfg cfg;
1644 bcmolt_tm_sched_key key = { };
Nicolas Palpacuer9c352082018-08-14 16:37:14 -04001645
Jason Huangd33b4d82019-05-15 18:22:57 +08001646 if (is_tm_sched_id_present(intf_id, onu_id, uni_id, direction)) {
1647 key.id = get_tm_sched_id(intf_id, onu_id, uni_id, direction);
1648 } else {
1649 BCM_LOG(INFO, openolt_log_id, "schduler not present in %s\n", direction.c_str());
1650 return BCM_ERR_OK;
1651 }
1652 BCMOLT_CFG_INIT(&cfg, tm_sched, key);
1653 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
1654 if (err) {
1655 BCM_LOG(ERROR, openolt_log_id, "Failed to remove scheduler sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \
1656 direction.c_str(), key.id, intf_id, onu_id);
1657 return err;
1658 }
1659 BCM_LOG(INFO, openolt_log_id, "Removed sched, direction = %s, id %d, intf_id %d, onu_id %d\n", \
1660 direction.c_str(), key.id, intf_id, onu_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001661 }
1662
1663 free_tm_sched_id(intf_id, onu_id, uni_id, direction);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001664 return BCM_ERR_OK;
1665}
1666
1667Status RemoveTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds) {
1668 uint32_t intf_id = traffic_scheds->intf_id();
1669 uint32_t onu_id = traffic_scheds->onu_id();
1670 uint32_t uni_id = traffic_scheds->uni_id();
1671 std::string direction;
1672 bcmos_errno err;
1673
1674 for (int i = 0; i < traffic_scheds->traffic_scheds_size(); i++) {
1675 tech_profile::TrafficScheduler traffic_sched = traffic_scheds->traffic_scheds(i);
1676 if (traffic_sched.direction() == tech_profile::Direction::UPSTREAM) {
1677 direction = upstream;
1678 } else if (traffic_sched.direction() == tech_profile::Direction::DOWNSTREAM) {
1679 direction = downstream;
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001680 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001681 else {
1682 BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_sched.direction());
1683 return Status::CANCELLED;
1684 }
1685 err = RemoveSched(intf_id, onu_id, uni_id, direction);
1686 if (err) {
1687 return bcm_to_grpc_err(err, "error-removing-traffic-scheduler");
1688 }
1689 }
1690 return Status::OK;
1691}
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001692
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001693bcmos_errno CreateQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority,
1694 uint32_t gemport_id) {
1695 bcmos_errno err;
Jason Huangd33b4d82019-05-15 18:22:57 +08001696 bcmolt_tm_queue_cfg cfg;
1697 bcmolt_tm_queue_key key = { };
Girish Gowdru36501552019-05-01 23:47:58 -07001698 BCM_LOG(INFO, openolt_log_id, "creating queue. access_intf_id = %d, onu_id = %d, uni_id = %d \
1699 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 -08001700 if (direction == downstream) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001701 // There is one queue per gem port
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001702 key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction);
1703 key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001704
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001705 } else {
1706 queue_map_key_tuple map_key(access_intf_id, onu_id, uni_id, gemport_id, direction);
1707 if (queue_map.count(map_key) > 0) {
1708 BCM_LOG(INFO, openolt_log_id, "upstream queue exists for intf_id %d, onu_id %d, uni_id %d\n. Not re-creating", \
1709 access_intf_id, onu_id, uni_id);
1710 return BCM_ERR_OK;
1711 }
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001712 key.sched_id = get_default_tm_sched_id(nni_intf_id, direction);
1713 if (priority > 7) {
1714 return BCM_ERR_RANGE;
1715 }
1716 // There are 8 queues (one per p-bit)
1717 key.id = us_fixed_queue_id_list[priority];
1718 update_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction, key.id);
1719 // FIXME: The upstream queues have to be created once only.
1720 // The upstream queues on the NNI scheduler are shared by all subscribers.
1721 // When the first scheduler comes in, the queues get created, and are re-used by all others.
1722 // Also, these queues should be present until the last subscriber exits the system.
1723 // One solution is to have these queues always, i.e., create it as soon as OLT is enabled.
1724 }
Girish Gowdru36501552019-05-01 23:47:58 -07001725 BCM_LOG(INFO, openolt_log_id, "queue assigned queue_id = %d\n", key.id);
1726
Jason Huangd33b4d82019-05-15 18:22:57 +08001727 BCMOLT_CFG_INIT(&cfg, tm_queue, key);
1728 BCMOLT_MSG_FIELD_SET(&cfg, tm_sched_param.u.priority.priority, priority);
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -07001729
Jason Huangd33b4d82019-05-15 18:22:57 +08001730 err = bcmolt_cfg_set(dev_id, &cfg.hdr);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001731 if (err) {
1732 BCM_LOG(ERROR, openolt_log_id, "Failed to create subscriber tm queue, direction = %s, id %d, sched_id %d, \
1733 intf_id %d, onu_id %d, uni_id %d\n", \
1734 direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id);
1735 return err;
1736 }
Craig Lutgen967a1d02018-11-27 10:41:51 -06001737
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001738 BCM_LOG(INFO, openolt_log_id, "Created tm_queue, direction %s, id %d, intf_id %d, onu_id %d, uni_id %d", \
1739 direction.c_str(), key.id, access_intf_id, onu_id, uni_id);
1740
1741 return BCM_ERR_OK;
1742
1743}
1744
1745Status CreateTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) {
1746 uint32_t intf_id = traffic_queues->intf_id();
1747 uint32_t onu_id = traffic_queues->onu_id();
1748 uint32_t uni_id = traffic_queues->uni_id();
1749 std::string direction;
1750 unsigned int alloc_id;
1751 bcmos_errno err;
1752
1753 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
1754 tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
1755 if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) {
1756 direction = upstream;
1757 } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) {
1758 direction = downstream;
1759 }
1760 else {
1761 BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_queue.direction());
1762 return Status::CANCELLED;
1763 }
1764 err = CreateQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id());
Girish Gowdru36501552019-05-01 23:47:58 -07001765 // If the queue exists already, lets not return failure and break the loop.
1766 if (err && err != BCM_ERR_ALREADY) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001767 return bcm_to_grpc_err(err, "Failed to create queue");
1768 }
1769 }
1770 return Status::OK;
1771}
1772
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001773bcmos_errno RemoveQueue(std::string direction, uint32_t access_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t priority,
1774 uint32_t gemport_id) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001775 bcmolt_tm_queue_cfg cfg;
1776 bcmolt_tm_queue_key key = { };
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001777 bcmos_errno err;
1778
1779 if (direction == downstream) {
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001780 if (is_tm_queue_id_present(access_intf_id, onu_id, uni_id, gemport_id, direction) && \
1781 is_tm_sched_id_present(access_intf_id, onu_id, uni_id, direction)) {
Jason Huangd33b4d82019-05-15 18:22:57 +08001782 key.sched_id = get_tm_sched_id(access_intf_id, onu_id, uni_id, direction);
1783 key.id = get_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001784 } else {
1785 BCM_LOG(INFO, openolt_log_id, "queue not present in DS. Not clearing");
1786 return BCM_ERR_OK;
1787 }
1788 } else {
1789 free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
1790 // In the upstream we use pre-created queues on the NNI scheduler that are used by all subscribers.
1791 // They should not be removed. So, lets return OK.
1792 return BCM_ERR_OK;
1793 }
1794
Jason Huangd33b4d82019-05-15 18:22:57 +08001795 BCMOLT_CFG_INIT(&cfg, tm_queue, key);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001796
Jason Huangd33b4d82019-05-15 18:22:57 +08001797 err = bcmolt_cfg_clear(dev_id, &(cfg.hdr));
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001798
1799 if (err) {
1800 BCM_LOG(ERROR, openolt_log_id, "Failed to remove queue, direction = %s, id %d, sched_id %d, intf_id %d, onu_id %d, uni_id %d\n",
Jason Huangd33b4d82019-05-15 18:22:57 +08001801 direction.c_str(), key.id, key.sched_id, access_intf_id, onu_id, uni_id);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -08001802 return err;
1803 }
1804
1805 free_tm_queue_id(access_intf_id, onu_id, uni_id, gemport_id, direction);
1806
1807 return BCM_ERR_OK;
1808}
1809
1810Status RemoveTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues) {
1811 uint32_t intf_id = traffic_queues->intf_id();
1812 uint32_t onu_id = traffic_queues->onu_id();
1813 uint32_t uni_id = traffic_queues->uni_id();
1814 uint32_t port_no = traffic_queues->port_no();
1815 std::string direction;
1816 unsigned int alloc_id;
1817 bcmos_errno err;
1818
1819 for (int i = 0; i < traffic_queues->traffic_queues_size(); i++) {
1820 tech_profile::TrafficQueue traffic_queue = traffic_queues->traffic_queues(i);
1821 if (traffic_queue.direction() == tech_profile::Direction::UPSTREAM) {
1822 direction = upstream;
1823 } else if (traffic_queue.direction() == tech_profile::Direction::DOWNSTREAM) {
1824 direction = downstream;
1825 } else {
1826 BCM_LOG(ERROR, openolt_log_id, "direction-not-supported %d", traffic_queue.direction());
1827 return Status::CANCELLED;
1828 }
1829 err = RemoveQueue(direction, intf_id, onu_id, uni_id, traffic_queue.priority(), traffic_queue.gemport_id());
1830 if (err) {
1831 return bcm_to_grpc_err(err, "Failed to remove queue");
1832 }
Jonathan Davis70c21812018-07-19 15:32:10 -04001833 }
1834
Jonathan Davis70c21812018-07-19 15:32:10 -04001835 return Status::OK;
Jonathan Davis70c21812018-07-19 15:32:10 -04001836}