blob: 9cf93654deaa49b9c291cc0df67afac6d5b730d7 [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>
25
26#include "core.h"
27#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040028#include "stats_collection.h"
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040029#include "error_format.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000030
31extern "C"
32{
33#include <bcmos_system.h>
34#include <bal_api.h>
35#include <bal_api_end.h>
36}
37
38Status Enable_() {
39 static bool enabled = false;
40 bcmbal_access_terminal_cfg acc_term_obj;
41 bcmbal_access_terminal_key key = { };
42
43 if (!enabled) {
44 std::cout << "Enable OLT" << std::endl;
45 key.access_term_id = DEFAULT_ATERM_ID;
46 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
47 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040048 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
49 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000050 std::cout << "ERROR: Failed to enable OLT" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040051 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +000052 }
53 enabled = true;
54 }
55 return Status::OK;
56}
57
58Status EnablePonIf_(uint32_t intf_id) {
59 bcmbal_interface_cfg interface_obj;
60 bcmbal_interface_key interface_key;
61
62 interface_key.intf_id = intf_id;
63 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
64
65 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
66 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
67
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040068 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
69 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000070 std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040071 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +000072 }
73
74 return Status::OK;
75}
76
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -040077Status DisablePonIf_(uint32_t intf_id) {
78 bcmbal_interface_cfg interface_obj;
79 bcmbal_interface_key interface_key;
80
81 interface_key.intf_id = intf_id;
82 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
83
84 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
85 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
86
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040087 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
88 if (err) {
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -040089 std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040090 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -040091 }
92
93 return Status::OK;
94}
95
Shad Ansarib7b0ced2018-05-11 21:53:32 +000096Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
97 const char *vendor_id, const char *vendor_specific) {
98
99 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
100 bcmbal_subscriber_terminal_key subs_terminal_key;
101 bcmbal_serial_number serial_num = {};
102 bcmbal_registration_id registration_id = {};
103
104 std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
105 std::cout << "Vendor Id " << vendor_id
106 << "Vendor Specific Id " << vendor_specific
107 << std::endl;
108
109 subs_terminal_key.sub_term_id = onu_id;
110 subs_terminal_key.intf_id = intf_id;
111 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
112
113 memcpy(serial_num.vendor_id, vendor_id, 4);
114 memcpy(serial_num.vendor_specific, vendor_specific, 4);
115 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
116
Shad Ansaricb004c52018-05-30 18:07:23 +0000117#if 0
118 // Commenting out as this is causing issues with onu activation
119 // with BAL 2.6 (Broadcom CS5248819).
120
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000121 // FIXME - Use a default (all zeros) registration id.
122 memset(registration_id.arr, 0, sizeof(registration_id.arr));
123 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000124#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000125
126 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
127
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400128 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
129 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000130 std::cout << "ERROR: Failed to enable ONU: " << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400131 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000132 }
133
134 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id));
135
136 //return Status::OK;
137}
138
Jonathan Davis70c21812018-07-19 15:32:10 -0400139Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
140 const char *vendor_id, const char *vendor_specific) {
141
142 SchedRemove_(intf_id, onu_id, mk_agg_port_id(onu_id));
143
144 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
145 bcmbal_subscriber_terminal_key subs_terminal_key;
146
147 std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl;
148 std::cout << "Vendor Id " << vendor_id
149 << "Vendor Specific Id " << vendor_specific
150 << std::endl;
151
152 subs_terminal_key.sub_term_id = onu_id;
153 subs_terminal_key.intf_id = intf_id;
154 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
155
156 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
157
158 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
159 std::cout << "ERROR: Failed to deactivate ONU: " << std::endl;
160 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
161 }
162
163 return Status::OK;
164}
165
166Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
167 const char *vendor_id, const char *vendor_specific) {
168 bcmos_errno err = BCM_ERR_OK;
169 bcmbal_subscriber_terminal_cfg cfg;
170 bcmbal_subscriber_terminal_key key = { };
171
172 std::cout << "Processing subscriber terminal cfg clear for sub_term_id = "
173 << onu_id << " and intf_id = " << intf_id << std::endl;
174
175 key.sub_term_id = onu_id ;
176 key.intf_id = intf_id ;
177
178 if (0 == key.sub_term_id)
179 {
180 std::cout << "Invalid Key to handle subscriber terminal clear subscriber_terminal_id = "
181 << onu_id << " Interface ID = " << intf_id << std::endl;
182 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
183 }
184
185 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
186
187 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
188 if (err != BCM_ERR_OK)
189 {
190 std::cout << "Failed to clear information for BAL subscriber_terminal_id = "
191 << onu_id << " Interface ID = " << intf_id << std::endl;
192 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
193 }
194
195 return Status::OK;;
196}
197
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000198#define MAX_CHAR_LENGTH 20
199#define MAX_OMCI_MSG_LENGTH 44
200Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
201 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
202 bcmos_errno err = BCM_ERR_OK;
203
204 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
205 bcmbal_dest proxy_pkt_dest;
206
207 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
208 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
209 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
210
211 // ???
212 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
213 buf.len = MAX_OMCI_MSG_LENGTH;
214 } else {
215 buf.len = pkt.size()/2;
216 }
217
218 /* Send the OMCI packet using the BAL remote proxy API */
219 uint16_t idx1 = 0;
220 uint16_t idx2 = 0;
221 uint8_t arraySend[buf.len];
222 char str1[MAX_CHAR_LENGTH];
223 char str2[MAX_CHAR_LENGTH];
224 memset(&arraySend, 0, buf.len);
225
226 std::cout << "Sending omci msg to ONU of length is "
227 << buf.len
228 << std::endl;
229
230 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
231 sprintf(str1,"%c", pkt[idx1]);
232 sprintf(str2,"%c", pkt[++idx1]);
233 strcat(str1,str2);
234 arraySend[idx2] = strtol(str1, NULL, 16);
235 }
236
237 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
238 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
239
240 std::cout << "After converting bytes to hex "
241 << buf.val << buf.len << std::endl;
242
243 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
244
245 std::cout << "OMCI request msg of length " << buf.len
246 << " sent to ONU" << onu_id
247 << " through PON " << intf_id << std::endl;
248
249 free(buf.val);
250
251 return Status::OK;
252}
253
254Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
255 bcmos_errno err = BCM_ERR_OK;
256 bcmbal_dest proxy_pkt_dest;
257 bcmbal_u8_list_u32_max_2048 buf;
258
259 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
260 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
261 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
262
263 buf.len = pkt.size();
264 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
265 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
266
267 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
268
269 std::cout << "Packet out of length " << buf.len
270 << " sent to ONU" << onu_id
271 << " through PON " << intf_id << std::endl;
272
273 free(buf.val);
274
275 return Status::OK;
276}
277
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400278Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
279 bcmos_errno err = BCM_ERR_OK;
280 bcmbal_dest proxy_pkt_dest;
281 bcmbal_u8_list_u32_max_2048 buf;
282
283 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
284 proxy_pkt_dest.u.nni.intf_id = intf_id;
285
286 buf.len = pkt.size();
287 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
288 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
289
290 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
291
292 std::cout << "Packet out of length " << buf.len
293 << " sent through uplink port " << intf_id << std::endl;
294
295 free(buf.val);
296
297 return Status::OK;
298}
299
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000300Status FlowAdd_(uint32_t onu_id,
301 uint32_t flow_id, const std::string flow_type,
302 uint32_t access_intf_id, uint32_t network_intf_id,
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400303 uint32_t gemport_id, uint32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000304 const ::openolt::Classifier& classifier,
305 const ::openolt::Action& action) {
306 bcmos_errno err;
307 bcmbal_flow_cfg cfg;
308 bcmbal_flow_key key = { };
309
310 std::cout << "flow add -"
311 << " intf_id:" << access_intf_id
312 << " onu_id:" << onu_id
313 << " flow_id:" << flow_id
314 << " flow_type:" << flow_type
315 << " gemport_id:" << gemport_id
316 << " network_intf_id:" << network_intf_id
317 << std::endl;
318
319 key.flow_id = flow_id;
320 if (flow_type.compare("upstream") == 0 ) {
321 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
322 } else if (flow_type.compare("downstream") == 0) {
323 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
324 } else {
325 std::cout << "Invalid flow type " << flow_type << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400326 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000327 }
328
329 BCMBAL_CFG_INIT(&cfg, flow, key);
330
331 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
332 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
333 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
334 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
335 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400336 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
337
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000338
339 {
340 bcmbal_classifier val = { };
341
342 if (classifier.o_tpid()) {
343 val.o_tpid = classifier.o_tpid();
344 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
345 }
346
347 if (classifier.o_vid()) {
348 val.o_vid = classifier.o_vid();
349 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
350 }
351
352 if (classifier.i_tpid()) {
353 val.i_tpid = classifier.i_tpid();
354 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
355 }
356
357 if (classifier.i_vid()) {
358 val.i_vid = classifier.i_vid();
359 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
360 }
361
362 if (classifier.o_pbits()) {
363 val.o_pbits = classifier.o_pbits();
364 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
365 }
366
367 if (classifier.i_pbits()) {
368 val.i_pbits = classifier.i_pbits();
369 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
370 }
371
372 if (classifier.eth_type()) {
373 val.ether_type = classifier.eth_type();
374 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
375 }
376
377 /*
378 if (classifier.dst_mac()) {
379 val.dst_mac = classifier.dst_mac();
380 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
381 }
382
383 if (classifier.src_mac()) {
384 val.src_mac = classifier.src_mac();
385 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
386 }
387 */
388
389 if (classifier.ip_proto()) {
390 val.ip_proto = classifier.ip_proto();
391 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
392 }
393
394 /*
395 if (classifier.dst_ip()) {
396 val.dst_ip = classifier.dst_ip();
397 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
398 }
399
400 if (classifier.src_ip()) {
401 val.src_ip = classifier.src_ip();
402 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
403 }
404 */
405
406 if (classifier.src_port()) {
407 val.src_port = classifier.src_port();
408 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
409 }
410
411 if (classifier.dst_port()) {
412 val.dst_port = classifier.dst_port();
413 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
414 }
415
416 if (!classifier.pkt_tag_type().empty()) {
417 if (classifier.pkt_tag_type().compare("untagged") == 0) {
418 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
419 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
420 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
421 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
422 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
423 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
424 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
425 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
426 }
427 }
428
429 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
430 }
431
432 {
433 bcmbal_action val = { };
434
435 const ::openolt::ActionCmd& cmd = action.cmd();
436
437 if (cmd.add_outer_tag()) {
438 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
439 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
440 }
441
442 if (cmd.remove_outer_tag()) {
443 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
444 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
445 }
446
447 if (cmd.trap_to_host()) {
448 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
449 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
450 }
451
452 if (action.o_vid()) {
453 val.o_vid = action.o_vid();
454 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
455 }
456
457 if (action.o_pbits()) {
458 val.o_pbits = action.o_pbits();
459 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
460 }
461
462 if (action.o_tpid()) {
463 val.o_tpid = action.o_tpid();
464 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
465 }
466
467 if (action.i_vid()) {
468 val.i_vid = action.i_vid();
469 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
470 }
471
472 if (action.i_pbits()) {
473 val.i_pbits = action.i_pbits();
474 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
475 }
476
477 if (action.i_tpid()) {
478 val.i_tpid = action.i_tpid();
479 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
480 }
481
482 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
483 }
484
485 {
486 bcmbal_tm_sched_id val;
487 val = (bcmbal_tm_sched_id) mk_sched_id(onu_id);
488 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
489 }
490
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400491 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
492 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000493 std::cout << "ERROR: flow add failed" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400494 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000495 }
496
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400497 register_new_flow(key);
498
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000499 return Status::OK;
500}
501
502Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
503 bcmbal_tm_sched_cfg cfg;
504 bcmbal_tm_sched_key key = { };
505 bcmbal_tm_sched_type sched_type;
506
507 key.id = mk_sched_id(onu_id);
508 key.dir = BCMBAL_TM_SCHED_DIR_US;
509
510 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
511
512 {
513 bcmbal_tm_sched_owner val = { };
514
515 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
516 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400517 val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_INTF_ID;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000518 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
519 val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_SUB_TERM_ID;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400520 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
521 val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_AGG_PORT_ID;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000522
523 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
524 }
525
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400526 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
527 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000528 std::cout << "ERROR: Failed to create upstream DBA sched"
529 << " id:" << key.id
530 << " intf_id:" << intf_id
531 << " onu_id:" << onu_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400532 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000533 //return 1;
534 }
535 std::cout << "create upstream DBA sched"
536 << " id:" << key.id
537 << " intf_id:" << intf_id
538 << " onu_id:" << onu_id << std::endl;
539
540 return Status::OK;
541 //return 0;
542}
Jonathan Davis70c21812018-07-19 15:32:10 -0400543
544Status SchedRemove_(int intf_id, int onu_id, int agg_port_id) {
545 bcmbal_tm_sched_cfg cfg;
546 bcmbal_tm_sched_key key = { };
547 bcmbal_tm_sched_type sched_type;
548
549 key.id = mk_sched_id(onu_id);
550 key.dir = BCMBAL_TM_SCHED_DIR_US;
551
552 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
553
554 if (bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(cfg.hdr))) {
555 std::cout << "ERROR: Failed to remove upstream DBA sched"
556 << " id:" << key.id
557 << " intf_id:" << intf_id
558 << " onu_id:" << onu_id << std::endl;
559 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
560 }
561
562 std::cout << "remove upstream DBA sched"
563 << " id:" << key.id
564 << " intf_id:" << intf_id
565 << " onu_id:" << onu_id << std::endl;
566
567 return Status::OK;
568 //return 0;
569}