blob: ae54c56bf40aeae0f5c87d59618b0e6f8837e306 [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
Shad Ansariedef2132018-08-10 22:14:50 +000039State state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040040
Shad Ansarib7b0ced2018-05-11 21:53:32 +000041Status Enable_() {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000042 bcmbal_access_terminal_cfg acc_term_obj;
43 bcmbal_access_terminal_key key = { };
44
Shad Ansariedef2132018-08-10 22:14:50 +000045 if (!state.is_activated()) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000046 std::cout << "Enable OLT" << std::endl;
47 key.access_term_id = DEFAULT_ATERM_ID;
48 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
49 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040050 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
51 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000052 std::cout << "ERROR: Failed to enable OLT" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040053 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +000054 }
Shad Ansariedef2132018-08-10 22:14:50 +000055 init_stats();
Shad Ansarib7b0ced2018-05-11 21:53:32 +000056 }
Shad Ansariedef2132018-08-10 22:14:50 +000057
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040058 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +000059 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040060}
61
62Status Disable_() {
63 // bcmbal_access_terminal_cfg acc_term_obj;
64 // bcmbal_access_terminal_key key = { };
65 //
66 // if (state::is_activated) {
67 // std::cout << "Disable OLT" << std::endl;
68 // key.access_term_id = DEFAULT_ATERM_ID;
69 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
70 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
71 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
72 // if (err) {
73 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
74 // return bcm_to_grpc_err(err, "Failed to disable OLT");
75 // }
76 // }
77 // //If already disabled, generate an extra indication ????
78 // return Status::OK;
79 //This fails with Operation Not Supported, bug ???
80
81 //TEMPORARY WORK AROUND
82 Status status = DisableUplinkIf_(0);
83 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +000084 state.deactivate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040085 openolt::Indication ind;
86 openolt::OltIndication* olt_ind = new openolt::OltIndication;
87 olt_ind->set_oper_state("down");
88 ind.set_allocated_olt_ind(olt_ind);
89 std::cout << "Disable OLT, add an extra indication" << std::endl;
90 oltIndQ.push(ind);
91 }
92 return status;
93
94}
95
96Status Reenable_() {
97 Status status = EnableUplinkIf_(0);
98 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +000099 state.activate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400100 openolt::Indication ind;
101 openolt::OltIndication* olt_ind = new openolt::OltIndication;
102 olt_ind->set_oper_state("up");
103 ind.set_allocated_olt_ind(olt_ind);
104 std::cout << "Reenable OLT, add an extra indication" << std::endl;
105 oltIndQ.push(ind);
106 }
107 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000108}
109
110Status EnablePonIf_(uint32_t intf_id) {
111 bcmbal_interface_cfg interface_obj;
112 bcmbal_interface_key interface_key;
113
114 interface_key.intf_id = intf_id;
115 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
116
117 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
118 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
119
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400120 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
121 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000122 std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400123 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000124 }
125
126 return Status::OK;
127}
128
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400129Status DisableUplinkIf_(uint32_t intf_id) {
130 bcmbal_interface_cfg interface_obj;
131 bcmbal_interface_key interface_key;
132
133 interface_key.intf_id = intf_id;
134 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
135
136 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
137 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
138
139 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
140 if (err) {
141 std::cout << "ERROR: Failed to disable Uplink interface: " << intf_id << std::endl;
142 return bcm_to_grpc_err(err, "Failed to disable Uplink interface");
143 }
144
145 return Status::OK;
146}
147
148Status EnableUplinkIf_(uint32_t intf_id) {
149 bcmbal_interface_cfg interface_obj;
150 bcmbal_interface_key interface_key;
151
152 interface_key.intf_id = intf_id;
153 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
154
155 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
156 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
157
158 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
159 if (err) {
160 std::cout << "ERROR: Failed to enable Uplink interface: " << intf_id << std::endl;
161 return bcm_to_grpc_err(err, "Failed to enable Uplink interface");
162 }
163
164 return Status::OK;
165}
166
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400167Status DisablePonIf_(uint32_t intf_id) {
168 bcmbal_interface_cfg interface_obj;
169 bcmbal_interface_key interface_key;
170
171 interface_key.intf_id = intf_id;
172 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
173
174 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
175 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
176
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400177 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
178 if (err) {
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400179 std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400180 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400181 }
182
183 return Status::OK;
184}
185
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000186Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Shad Ansari06101952018-07-25 00:22:09 +0000187 const char *vendor_id, const char *vendor_specific, uint32_t pir) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000188
189 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
190 bcmbal_subscriber_terminal_key subs_terminal_key;
191 bcmbal_serial_number serial_num = {};
192 bcmbal_registration_id registration_id = {};
193
194 std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
195 std::cout << "Vendor Id " << vendor_id
196 << "Vendor Specific Id " << vendor_specific
Shad Ansari06101952018-07-25 00:22:09 +0000197 << "pir " << pir
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000198 << std::endl;
199
200 subs_terminal_key.sub_term_id = onu_id;
201 subs_terminal_key.intf_id = intf_id;
202 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
203
204 memcpy(serial_num.vendor_id, vendor_id, 4);
205 memcpy(serial_num.vendor_specific, vendor_specific, 4);
206 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
207
Shad Ansaricb004c52018-05-30 18:07:23 +0000208#if 0
209 // Commenting out as this is causing issues with onu activation
210 // with BAL 2.6 (Broadcom CS5248819).
211
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000212 // FIXME - Use a default (all zeros) registration id.
213 memset(registration_id.arr, 0, sizeof(registration_id.arr));
214 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000215#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000216
217 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
218
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400219 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
220 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000221 std::cout << "ERROR: Failed to enable ONU: " << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400222 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000223 }
224
Shad Ansari06101952018-07-25 00:22:09 +0000225 /* Create subscriber's tm_sched */
226 {
227 bcmbal_tm_sched_cfg cfg;
228 bcmbal_tm_sched_key key = { };
229 key.dir = BCMBAL_TM_SCHED_DIR_DS;
230 key.id = intf_id << 7 | onu_id;
231 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
232
233 bcmbal_tm_sched_owner owner = { };
234 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
235 owner.u.sub_term.intf_id = intf_id;
236 owner.u.sub_term.sub_term_id = onu_id;
237 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
238
239 bcmbal_tm_sched_parent parent = { };
240 parent.sched_id = intf_id + 16384;
241 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
242 parent.weight = 1;
243 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
244 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
245
246 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
247
248 bcmbal_tm_shaping shaping = { };
249 shaping.pir = pir;
250 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
251 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
252
253 bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
254 }
255
256 /* Create tm_queue */
257 {
258 bcmbal_tm_queue_cfg cfg;
259 bcmbal_tm_queue_key key = { };
260 key.sched_id = intf_id << 7 | onu_id;
261 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
262 key.id = 0;
263 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
264 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
265 bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
266 }
267
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000268 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id));
269
270 //return Status::OK;
271}
272
Jonathan Davis70c21812018-07-19 15:32:10 -0400273Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
274 const char *vendor_id, const char *vendor_specific) {
275
276 SchedRemove_(intf_id, onu_id, mk_agg_port_id(onu_id));
277
278 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
279 bcmbal_subscriber_terminal_key subs_terminal_key;
280
281 std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl;
282 std::cout << "Vendor Id " << vendor_id
283 << "Vendor Specific Id " << vendor_specific
284 << std::endl;
285
286 subs_terminal_key.sub_term_id = onu_id;
287 subs_terminal_key.intf_id = intf_id;
288 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
289
290 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
291
292 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
293 std::cout << "ERROR: Failed to deactivate ONU: " << std::endl;
294 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
295 }
296
297 return Status::OK;
298}
299
300Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
301 const char *vendor_id, const char *vendor_specific) {
302 bcmos_errno err = BCM_ERR_OK;
303 bcmbal_subscriber_terminal_cfg cfg;
304 bcmbal_subscriber_terminal_key key = { };
305
306 std::cout << "Processing subscriber terminal cfg clear for sub_term_id = "
307 << onu_id << " and intf_id = " << intf_id << std::endl;
308
309 key.sub_term_id = onu_id ;
310 key.intf_id = intf_id ;
311
312 if (0 == key.sub_term_id)
313 {
314 std::cout << "Invalid Key to handle subscriber terminal clear subscriber_terminal_id = "
315 << onu_id << " Interface ID = " << intf_id << std::endl;
316 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
317 }
318
319 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
320
321 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
322 if (err != BCM_ERR_OK)
323 {
324 std::cout << "Failed to clear information for BAL subscriber_terminal_id = "
325 << onu_id << " Interface ID = " << intf_id << std::endl;
326 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
327 }
328
329 return Status::OK;;
330}
331
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000332#define MAX_CHAR_LENGTH 20
333#define MAX_OMCI_MSG_LENGTH 44
334Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
335 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
336 bcmos_errno err = BCM_ERR_OK;
337
338 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
339 bcmbal_dest proxy_pkt_dest;
340
341 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
342 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
343 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
344
345 // ???
346 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
347 buf.len = MAX_OMCI_MSG_LENGTH;
348 } else {
349 buf.len = pkt.size()/2;
350 }
351
352 /* Send the OMCI packet using the BAL remote proxy API */
353 uint16_t idx1 = 0;
354 uint16_t idx2 = 0;
355 uint8_t arraySend[buf.len];
356 char str1[MAX_CHAR_LENGTH];
357 char str2[MAX_CHAR_LENGTH];
358 memset(&arraySend, 0, buf.len);
359
360 std::cout << "Sending omci msg to ONU of length is "
361 << buf.len
362 << std::endl;
363
364 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
365 sprintf(str1,"%c", pkt[idx1]);
366 sprintf(str2,"%c", pkt[++idx1]);
367 strcat(str1,str2);
368 arraySend[idx2] = strtol(str1, NULL, 16);
369 }
370
371 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
372 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
373
374 std::cout << "After converting bytes to hex "
375 << buf.val << buf.len << std::endl;
376
377 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
378
379 std::cout << "OMCI request msg of length " << buf.len
380 << " sent to ONU" << onu_id
381 << " through PON " << intf_id << std::endl;
382
383 free(buf.val);
384
385 return Status::OK;
386}
387
388Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
389 bcmos_errno err = BCM_ERR_OK;
390 bcmbal_dest proxy_pkt_dest;
391 bcmbal_u8_list_u32_max_2048 buf;
392
393 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
394 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
395 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
396
397 buf.len = pkt.size();
398 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
399 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
400
401 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
402
403 std::cout << "Packet out of length " << buf.len
404 << " sent to ONU" << onu_id
405 << " through PON " << intf_id << std::endl;
406
407 free(buf.val);
408
409 return Status::OK;
410}
411
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400412Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
413 bcmos_errno err = BCM_ERR_OK;
414 bcmbal_dest proxy_pkt_dest;
415 bcmbal_u8_list_u32_max_2048 buf;
416
417 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
418 proxy_pkt_dest.u.nni.intf_id = intf_id;
419
420 buf.len = pkt.size();
421 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
422 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
423
424 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
425
426 std::cout << "Packet out of length " << buf.len
427 << " sent through uplink port " << intf_id << std::endl;
428
429 free(buf.val);
430
431 return Status::OK;
432}
433
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000434Status FlowAdd_(uint32_t onu_id,
435 uint32_t flow_id, const std::string flow_type,
436 uint32_t access_intf_id, uint32_t network_intf_id,
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400437 uint32_t gemport_id, uint32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000438 const ::openolt::Classifier& classifier,
439 const ::openolt::Action& action) {
440 bcmos_errno err;
441 bcmbal_flow_cfg cfg;
442 bcmbal_flow_key key = { };
443
444 std::cout << "flow add -"
445 << " intf_id:" << access_intf_id
446 << " onu_id:" << onu_id
447 << " flow_id:" << flow_id
448 << " flow_type:" << flow_type
449 << " gemport_id:" << gemport_id
450 << " network_intf_id:" << network_intf_id
451 << std::endl;
452
453 key.flow_id = flow_id;
454 if (flow_type.compare("upstream") == 0 ) {
455 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
456 } else if (flow_type.compare("downstream") == 0) {
457 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
458 } else {
459 std::cout << "Invalid flow type " << flow_type << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400460 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000461 }
462
463 BCMBAL_CFG_INIT(&cfg, flow, key);
464
465 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
466 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
467 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
468 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
469 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400470 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
471
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000472
473 {
474 bcmbal_classifier val = { };
475
476 if (classifier.o_tpid()) {
477 val.o_tpid = classifier.o_tpid();
478 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
479 }
480
481 if (classifier.o_vid()) {
482 val.o_vid = classifier.o_vid();
483 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
484 }
485
486 if (classifier.i_tpid()) {
487 val.i_tpid = classifier.i_tpid();
488 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
489 }
490
491 if (classifier.i_vid()) {
492 val.i_vid = classifier.i_vid();
493 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
494 }
495
496 if (classifier.o_pbits()) {
497 val.o_pbits = classifier.o_pbits();
498 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
499 }
500
501 if (classifier.i_pbits()) {
502 val.i_pbits = classifier.i_pbits();
503 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
504 }
505
506 if (classifier.eth_type()) {
507 val.ether_type = classifier.eth_type();
508 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
509 }
510
511 /*
512 if (classifier.dst_mac()) {
513 val.dst_mac = classifier.dst_mac();
514 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
515 }
516
517 if (classifier.src_mac()) {
518 val.src_mac = classifier.src_mac();
519 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
520 }
521 */
522
523 if (classifier.ip_proto()) {
524 val.ip_proto = classifier.ip_proto();
525 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
526 }
527
528 /*
529 if (classifier.dst_ip()) {
530 val.dst_ip = classifier.dst_ip();
531 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
532 }
533
534 if (classifier.src_ip()) {
535 val.src_ip = classifier.src_ip();
536 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
537 }
538 */
539
540 if (classifier.src_port()) {
541 val.src_port = classifier.src_port();
542 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
543 }
544
545 if (classifier.dst_port()) {
546 val.dst_port = classifier.dst_port();
547 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
548 }
549
550 if (!classifier.pkt_tag_type().empty()) {
551 if (classifier.pkt_tag_type().compare("untagged") == 0) {
552 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
553 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
554 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
555 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
556 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
557 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
558 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
559 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
560 }
561 }
562
563 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
564 }
565
566 {
567 bcmbal_action val = { };
568
569 const ::openolt::ActionCmd& cmd = action.cmd();
570
571 if (cmd.add_outer_tag()) {
572 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
573 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
574 }
575
576 if (cmd.remove_outer_tag()) {
577 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
578 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
579 }
580
581 if (cmd.trap_to_host()) {
582 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
583 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
584 }
585
586 if (action.o_vid()) {
587 val.o_vid = action.o_vid();
588 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
589 }
590
591 if (action.o_pbits()) {
592 val.o_pbits = action.o_pbits();
593 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
594 }
595
596 if (action.o_tpid()) {
597 val.o_tpid = action.o_tpid();
598 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
599 }
600
601 if (action.i_vid()) {
602 val.i_vid = action.i_vid();
603 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
604 }
605
606 if (action.i_pbits()) {
607 val.i_pbits = action.i_pbits();
608 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
609 }
610
611 if (action.i_tpid()) {
612 val.i_tpid = action.i_tpid();
613 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
614 }
615
616 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
617 }
618
619 {
620 bcmbal_tm_sched_id val;
621 val = (bcmbal_tm_sched_id) mk_sched_id(onu_id);
622 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
623 }
624
Shad Ansari06101952018-07-25 00:22:09 +0000625 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
626 bcmbal_tm_queue_ref val = { };
627 val.sched_id = access_intf_id << 7 | onu_id;
628 val.queue_id = 0;
629 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
630 }
631
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400632 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
633 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000634 std::cout << "ERROR: flow add failed" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400635 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000636 }
637
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400638 register_new_flow(key);
639
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000640 return Status::OK;
641}
642
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400643Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
644
645 bcmbal_flow_cfg cfg;
646 bcmbal_flow_key key = { };
647
648 key.flow_id = (bcmbal_flow_id) flow_id;
649 key.flow_id = flow_id;
650 if (flow_type.compare("upstream") == 0 ) {
651 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
652 } else if (flow_type.compare("downstream") == 0) {
653 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
654 } else {
655 std::cout << "Invalid flow type " << flow_type << std::endl;
656 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
657 }
658
659 BCMBAL_CFG_INIT(&cfg, flow, key);
660
661
662 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
663 if (err) {
664 std::cout << "Error " << err << " while removing flow "
665 << flow_id << ", " << flow_type << std::endl;
666 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
667 }
668
669 std::cout << "Flow " << flow_id << ", " << flow_type << " removed";
670 return Status::OK;
671}
672
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000673Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
674 bcmbal_tm_sched_cfg cfg;
675 bcmbal_tm_sched_key key = { };
676 bcmbal_tm_sched_type sched_type;
677
678 key.id = mk_sched_id(onu_id);
679 key.dir = BCMBAL_TM_SCHED_DIR_US;
680
681 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
682
683 {
684 bcmbal_tm_sched_owner val = { };
685
686 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
687 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400688 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 +0000689 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
690 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 -0400691 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
692 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 +0000693
694 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
695 }
696
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400697 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
698 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000699 std::cout << "ERROR: Failed to create upstream DBA sched"
700 << " id:" << key.id
701 << " intf_id:" << intf_id
702 << " onu_id:" << onu_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400703 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000704 //return 1;
705 }
706 std::cout << "create upstream DBA sched"
707 << " id:" << key.id
708 << " intf_id:" << intf_id
709 << " onu_id:" << onu_id << std::endl;
710
711 return Status::OK;
712 //return 0;
713}
Jonathan Davis70c21812018-07-19 15:32:10 -0400714
715Status SchedRemove_(int intf_id, int onu_id, int agg_port_id) {
716 bcmbal_tm_sched_cfg cfg;
717 bcmbal_tm_sched_key key = { };
718 bcmbal_tm_sched_type sched_type;
719
720 key.id = mk_sched_id(onu_id);
721 key.dir = BCMBAL_TM_SCHED_DIR_US;
722
723 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
724
725 if (bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(cfg.hdr))) {
726 std::cout << "ERROR: Failed to remove upstream DBA sched"
727 << " id:" << key.id
728 << " intf_id:" << intf_id
729 << " onu_id:" << onu_id << std::endl;
730 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
731 }
732
733 std::cout << "remove upstream DBA sched"
734 << " id:" << key.id
735 << " intf_id:" << intf_id
736 << " onu_id:" << onu_id << std::endl;
737
738 return Status::OK;
739 //return 0;
740}