blob: eacbf27847c3b9dba0399d6906c931cd907046fe [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"
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040030#include "state.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000031
32extern "C"
33{
34#include <bcmos_system.h>
35#include <bal_api.h>
36#include <bal_api_end.h>
37}
38
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040039
Shad Ansarib7b0ced2018-05-11 21:53:32 +000040Status Enable_() {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000041 bcmbal_access_terminal_cfg acc_term_obj;
42 bcmbal_access_terminal_key key = { };
43
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040044 if (!state::is_activated()) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000045 std::cout << "Enable OLT" << std::endl;
46 key.access_term_id = DEFAULT_ATERM_ID;
47 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
48 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040049 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
50 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000051 std::cout << "ERROR: Failed to enable OLT" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040052 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +000053 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +000054 }
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040055 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +000056 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040057
58}
59
60Status Disable_() {
61 // bcmbal_access_terminal_cfg acc_term_obj;
62 // bcmbal_access_terminal_key key = { };
63 //
64 // if (state::is_activated) {
65 // std::cout << "Disable OLT" << std::endl;
66 // key.access_term_id = DEFAULT_ATERM_ID;
67 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
68 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
69 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
70 // if (err) {
71 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
72 // return bcm_to_grpc_err(err, "Failed to disable OLT");
73 // }
74 // }
75 // //If already disabled, generate an extra indication ????
76 // return Status::OK;
77 //This fails with Operation Not Supported, bug ???
78
79 //TEMPORARY WORK AROUND
80 Status status = DisableUplinkIf_(0);
81 if (status.ok()) {
82 state::deactivate();
83 openolt::Indication ind;
84 openolt::OltIndication* olt_ind = new openolt::OltIndication;
85 olt_ind->set_oper_state("down");
86 ind.set_allocated_olt_ind(olt_ind);
87 std::cout << "Disable OLT, add an extra indication" << std::endl;
88 oltIndQ.push(ind);
89 }
90 return status;
91
92}
93
94Status Reenable_() {
95 Status status = EnableUplinkIf_(0);
96 if (status.ok()) {
97 state::activate();
98 openolt::Indication ind;
99 openolt::OltIndication* olt_ind = new openolt::OltIndication;
100 olt_ind->set_oper_state("up");
101 ind.set_allocated_olt_ind(olt_ind);
102 std::cout << "Reenable OLT, add an extra indication" << std::endl;
103 oltIndQ.push(ind);
104 }
105 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000106}
107
108Status EnablePonIf_(uint32_t intf_id) {
109 bcmbal_interface_cfg interface_obj;
110 bcmbal_interface_key interface_key;
111
112 interface_key.intf_id = intf_id;
113 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
114
115 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
116 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
117
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400118 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
119 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000120 std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400121 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000122 }
123
124 return Status::OK;
125}
126
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400127Status DisableUplinkIf_(uint32_t intf_id) {
128 bcmbal_interface_cfg interface_obj;
129 bcmbal_interface_key interface_key;
130
131 interface_key.intf_id = intf_id;
132 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
133
134 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
135 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
136
137 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
138 if (err) {
139 std::cout << "ERROR: Failed to disable Uplink interface: " << intf_id << std::endl;
140 return bcm_to_grpc_err(err, "Failed to disable Uplink interface");
141 }
142
143 return Status::OK;
144}
145
146Status EnableUplinkIf_(uint32_t intf_id) {
147 bcmbal_interface_cfg interface_obj;
148 bcmbal_interface_key interface_key;
149
150 interface_key.intf_id = intf_id;
151 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
152
153 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
154 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
155
156 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
157 if (err) {
158 std::cout << "ERROR: Failed to enable Uplink interface: " << intf_id << std::endl;
159 return bcm_to_grpc_err(err, "Failed to enable Uplink interface");
160 }
161
162 return Status::OK;
163}
164
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400165Status DisablePonIf_(uint32_t intf_id) {
166 bcmbal_interface_cfg interface_obj;
167 bcmbal_interface_key interface_key;
168
169 interface_key.intf_id = intf_id;
170 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
171
172 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
173 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
174
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400175 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
176 if (err) {
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400177 std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400178 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400179 }
180
181 return Status::OK;
182}
183
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000184Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Shad Ansari06101952018-07-25 00:22:09 +0000185 const char *vendor_id, const char *vendor_specific, uint32_t pir) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000186
187 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
188 bcmbal_subscriber_terminal_key subs_terminal_key;
189 bcmbal_serial_number serial_num = {};
190 bcmbal_registration_id registration_id = {};
191
192 std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
193 std::cout << "Vendor Id " << vendor_id
194 << "Vendor Specific Id " << vendor_specific
Shad Ansari06101952018-07-25 00:22:09 +0000195 << "pir " << pir
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000196 << std::endl;
197
198 subs_terminal_key.sub_term_id = onu_id;
199 subs_terminal_key.intf_id = intf_id;
200 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
201
202 memcpy(serial_num.vendor_id, vendor_id, 4);
203 memcpy(serial_num.vendor_specific, vendor_specific, 4);
204 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
205
Shad Ansaricb004c52018-05-30 18:07:23 +0000206#if 0
207 // Commenting out as this is causing issues with onu activation
208 // with BAL 2.6 (Broadcom CS5248819).
209
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000210 // FIXME - Use a default (all zeros) registration id.
211 memset(registration_id.arr, 0, sizeof(registration_id.arr));
212 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000213#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000214
215 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
216
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400217 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
218 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000219 std::cout << "ERROR: Failed to enable ONU: " << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400220 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000221 }
222
Shad Ansari06101952018-07-25 00:22:09 +0000223 /* Create subscriber's tm_sched */
224 {
225 bcmbal_tm_sched_cfg cfg;
226 bcmbal_tm_sched_key key = { };
227 key.dir = BCMBAL_TM_SCHED_DIR_DS;
228 key.id = intf_id << 7 | onu_id;
229 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
230
231 bcmbal_tm_sched_owner owner = { };
232 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
233 owner.u.sub_term.intf_id = intf_id;
234 owner.u.sub_term.sub_term_id = onu_id;
235 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
236
237 bcmbal_tm_sched_parent parent = { };
238 parent.sched_id = intf_id + 16384;
239 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
240 parent.weight = 1;
241 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
242 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
243
244 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
245
246 bcmbal_tm_shaping shaping = { };
247 shaping.pir = pir;
248 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
249 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
250
251 bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
252 }
253
254 /* Create tm_queue */
255 {
256 bcmbal_tm_queue_cfg cfg;
257 bcmbal_tm_queue_key key = { };
258 key.sched_id = intf_id << 7 | onu_id;
259 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
260 key.id = 0;
261 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
262 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
263 bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
264 }
265
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000266 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id));
267
268 //return Status::OK;
269}
270
Jonathan Davis70c21812018-07-19 15:32:10 -0400271Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
272 const char *vendor_id, const char *vendor_specific) {
273
274 SchedRemove_(intf_id, onu_id, mk_agg_port_id(onu_id));
275
276 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
277 bcmbal_subscriber_terminal_key subs_terminal_key;
278
279 std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl;
280 std::cout << "Vendor Id " << vendor_id
281 << "Vendor Specific Id " << vendor_specific
282 << std::endl;
283
284 subs_terminal_key.sub_term_id = onu_id;
285 subs_terminal_key.intf_id = intf_id;
286 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
287
288 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
289
290 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
291 std::cout << "ERROR: Failed to deactivate ONU: " << std::endl;
292 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
293 }
294
295 return Status::OK;
296}
297
298Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
299 const char *vendor_id, const char *vendor_specific) {
300 bcmos_errno err = BCM_ERR_OK;
301 bcmbal_subscriber_terminal_cfg cfg;
302 bcmbal_subscriber_terminal_key key = { };
303
304 std::cout << "Processing subscriber terminal cfg clear for sub_term_id = "
305 << onu_id << " and intf_id = " << intf_id << std::endl;
306
307 key.sub_term_id = onu_id ;
308 key.intf_id = intf_id ;
309
310 if (0 == key.sub_term_id)
311 {
312 std::cout << "Invalid Key to handle subscriber terminal clear subscriber_terminal_id = "
313 << onu_id << " Interface ID = " << intf_id << std::endl;
314 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
315 }
316
317 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
318
319 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
320 if (err != BCM_ERR_OK)
321 {
322 std::cout << "Failed to clear information for BAL subscriber_terminal_id = "
323 << onu_id << " Interface ID = " << intf_id << std::endl;
324 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
325 }
326
327 return Status::OK;;
328}
329
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000330#define MAX_CHAR_LENGTH 20
331#define MAX_OMCI_MSG_LENGTH 44
332Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
333 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
334 bcmos_errno err = BCM_ERR_OK;
335
336 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
337 bcmbal_dest proxy_pkt_dest;
338
339 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
340 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
341 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
342
343 // ???
344 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
345 buf.len = MAX_OMCI_MSG_LENGTH;
346 } else {
347 buf.len = pkt.size()/2;
348 }
349
350 /* Send the OMCI packet using the BAL remote proxy API */
351 uint16_t idx1 = 0;
352 uint16_t idx2 = 0;
353 uint8_t arraySend[buf.len];
354 char str1[MAX_CHAR_LENGTH];
355 char str2[MAX_CHAR_LENGTH];
356 memset(&arraySend, 0, buf.len);
357
358 std::cout << "Sending omci msg to ONU of length is "
359 << buf.len
360 << std::endl;
361
362 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
363 sprintf(str1,"%c", pkt[idx1]);
364 sprintf(str2,"%c", pkt[++idx1]);
365 strcat(str1,str2);
366 arraySend[idx2] = strtol(str1, NULL, 16);
367 }
368
369 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
370 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
371
372 std::cout << "After converting bytes to hex "
373 << buf.val << buf.len << std::endl;
374
375 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
376
377 std::cout << "OMCI request msg of length " << buf.len
378 << " sent to ONU" << onu_id
379 << " through PON " << intf_id << std::endl;
380
381 free(buf.val);
382
383 return Status::OK;
384}
385
386Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
387 bcmos_errno err = BCM_ERR_OK;
388 bcmbal_dest proxy_pkt_dest;
389 bcmbal_u8_list_u32_max_2048 buf;
390
391 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
392 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
393 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
394
395 buf.len = pkt.size();
396 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
397 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
398
399 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
400
401 std::cout << "Packet out of length " << buf.len
402 << " sent to ONU" << onu_id
403 << " through PON " << intf_id << std::endl;
404
405 free(buf.val);
406
407 return Status::OK;
408}
409
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400410Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
411 bcmos_errno err = BCM_ERR_OK;
412 bcmbal_dest proxy_pkt_dest;
413 bcmbal_u8_list_u32_max_2048 buf;
414
415 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
416 proxy_pkt_dest.u.nni.intf_id = intf_id;
417
418 buf.len = pkt.size();
419 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
420 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
421
422 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
423
424 std::cout << "Packet out of length " << buf.len
425 << " sent through uplink port " << intf_id << std::endl;
426
427 free(buf.val);
428
429 return Status::OK;
430}
431
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000432Status FlowAdd_(uint32_t onu_id,
433 uint32_t flow_id, const std::string flow_type,
434 uint32_t access_intf_id, uint32_t network_intf_id,
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400435 uint32_t gemport_id, uint32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000436 const ::openolt::Classifier& classifier,
437 const ::openolt::Action& action) {
438 bcmos_errno err;
439 bcmbal_flow_cfg cfg;
440 bcmbal_flow_key key = { };
441
442 std::cout << "flow add -"
443 << " intf_id:" << access_intf_id
444 << " onu_id:" << onu_id
445 << " flow_id:" << flow_id
446 << " flow_type:" << flow_type
447 << " gemport_id:" << gemport_id
448 << " network_intf_id:" << network_intf_id
449 << std::endl;
450
451 key.flow_id = flow_id;
452 if (flow_type.compare("upstream") == 0 ) {
453 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
454 } else if (flow_type.compare("downstream") == 0) {
455 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
456 } else {
457 std::cout << "Invalid flow type " << flow_type << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400458 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000459 }
460
461 BCMBAL_CFG_INIT(&cfg, flow, key);
462
463 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
464 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
465 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
466 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
467 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400468 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
469
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000470
471 {
472 bcmbal_classifier val = { };
473
474 if (classifier.o_tpid()) {
475 val.o_tpid = classifier.o_tpid();
476 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
477 }
478
479 if (classifier.o_vid()) {
480 val.o_vid = classifier.o_vid();
481 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
482 }
483
484 if (classifier.i_tpid()) {
485 val.i_tpid = classifier.i_tpid();
486 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
487 }
488
489 if (classifier.i_vid()) {
490 val.i_vid = classifier.i_vid();
491 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
492 }
493
494 if (classifier.o_pbits()) {
495 val.o_pbits = classifier.o_pbits();
496 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
497 }
498
499 if (classifier.i_pbits()) {
500 val.i_pbits = classifier.i_pbits();
501 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
502 }
503
504 if (classifier.eth_type()) {
505 val.ether_type = classifier.eth_type();
506 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
507 }
508
509 /*
510 if (classifier.dst_mac()) {
511 val.dst_mac = classifier.dst_mac();
512 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
513 }
514
515 if (classifier.src_mac()) {
516 val.src_mac = classifier.src_mac();
517 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
518 }
519 */
520
521 if (classifier.ip_proto()) {
522 val.ip_proto = classifier.ip_proto();
523 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
524 }
525
526 /*
527 if (classifier.dst_ip()) {
528 val.dst_ip = classifier.dst_ip();
529 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
530 }
531
532 if (classifier.src_ip()) {
533 val.src_ip = classifier.src_ip();
534 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
535 }
536 */
537
538 if (classifier.src_port()) {
539 val.src_port = classifier.src_port();
540 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
541 }
542
543 if (classifier.dst_port()) {
544 val.dst_port = classifier.dst_port();
545 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
546 }
547
548 if (!classifier.pkt_tag_type().empty()) {
549 if (classifier.pkt_tag_type().compare("untagged") == 0) {
550 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
551 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
552 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
553 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
554 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
555 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
556 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
557 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
558 }
559 }
560
561 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
562 }
563
564 {
565 bcmbal_action val = { };
566
567 const ::openolt::ActionCmd& cmd = action.cmd();
568
569 if (cmd.add_outer_tag()) {
570 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
571 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
572 }
573
574 if (cmd.remove_outer_tag()) {
575 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
576 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
577 }
578
579 if (cmd.trap_to_host()) {
580 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
581 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
582 }
583
584 if (action.o_vid()) {
585 val.o_vid = action.o_vid();
586 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
587 }
588
589 if (action.o_pbits()) {
590 val.o_pbits = action.o_pbits();
591 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
592 }
593
594 if (action.o_tpid()) {
595 val.o_tpid = action.o_tpid();
596 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
597 }
598
599 if (action.i_vid()) {
600 val.i_vid = action.i_vid();
601 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
602 }
603
604 if (action.i_pbits()) {
605 val.i_pbits = action.i_pbits();
606 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
607 }
608
609 if (action.i_tpid()) {
610 val.i_tpid = action.i_tpid();
611 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
612 }
613
614 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
615 }
616
617 {
618 bcmbal_tm_sched_id val;
619 val = (bcmbal_tm_sched_id) mk_sched_id(onu_id);
620 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
621 }
622
Shad Ansari06101952018-07-25 00:22:09 +0000623 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
624 bcmbal_tm_queue_ref val = { };
625 val.sched_id = access_intf_id << 7 | onu_id;
626 val.queue_id = 0;
627 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
628 }
629
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400630 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
631 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000632 std::cout << "ERROR: flow add failed" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400633 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000634 }
635
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400636 register_new_flow(key);
637
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000638 return Status::OK;
639}
640
641Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
642 bcmbal_tm_sched_cfg cfg;
643 bcmbal_tm_sched_key key = { };
644 bcmbal_tm_sched_type sched_type;
645
646 key.id = mk_sched_id(onu_id);
647 key.dir = BCMBAL_TM_SCHED_DIR_US;
648
649 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
650
651 {
652 bcmbal_tm_sched_owner val = { };
653
654 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
655 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400656 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 +0000657 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
658 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 -0400659 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
660 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 +0000661
662 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
663 }
664
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400665 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
666 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000667 std::cout << "ERROR: Failed to create upstream DBA sched"
668 << " id:" << key.id
669 << " intf_id:" << intf_id
670 << " onu_id:" << onu_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400671 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000672 //return 1;
673 }
674 std::cout << "create upstream DBA sched"
675 << " id:" << key.id
676 << " intf_id:" << intf_id
677 << " onu_id:" << onu_id << std::endl;
678
679 return Status::OK;
680 //return 0;
681}
Jonathan Davis70c21812018-07-19 15:32:10 -0400682
683Status SchedRemove_(int intf_id, int onu_id, int agg_port_id) {
684 bcmbal_tm_sched_cfg cfg;
685 bcmbal_tm_sched_key key = { };
686 bcmbal_tm_sched_type sched_type;
687
688 key.id = mk_sched_id(onu_id);
689 key.dir = BCMBAL_TM_SCHED_DIR_US;
690
691 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
692
693 if (bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(cfg.hdr))) {
694 std::cout << "ERROR: Failed to remove upstream DBA sched"
695 << " id:" << key.id
696 << " intf_id:" << intf_id
697 << " onu_id:" << onu_id << std::endl;
698 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
699 }
700
701 std::cout << "remove upstream DBA sched"
702 << " id:" << key.id
703 << " intf_id:" << intf_id
704 << " onu_id:" << onu_id << std::endl;
705
706 return Status::OK;
707 //return 0;
708}