blob: 9bdb72dbda18d4af4ef68f3e5e1df4e87b095b70 [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 Ansari627b5782018-08-13 22:49:32 +000041static Status SchedAdd_(int intf_id, int onu_id, int agg_port_id);
42static Status SchedRemove_(int intf_id, int onu_id, int agg_port_id);
43
44static inline int mk_sched_id(int onu_id) {
45 return 1023 + onu_id;
46}
47
48static inline int mk_agg_port_id(int onu_id) {
49 return 1023 + onu_id;
50}
51
52Status Enable_(int argc, char *argv[]) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000053 bcmbal_access_terminal_cfg acc_term_obj;
54 bcmbal_access_terminal_key key = { };
55
Shad Ansariedef2132018-08-10 22:14:50 +000056 if (!state.is_activated()) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000057 std::cout << "Enable OLT" << std::endl;
Shad Ansari627b5782018-08-13 22:49:32 +000058
59 bcmbal_init(argc, argv, NULL);
60
61 Status status = SubscribeIndication();
62 if (!status.ok()) {
63 std::cout << "ERROR: SubscribeIndication failed - "
64 << status.error_code() << ": " << status.error_message()
65 << std::endl;
66 return status;
67 }
68
Shad Ansarib7b0ced2018-05-11 21:53:32 +000069 key.access_term_id = DEFAULT_ATERM_ID;
70 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
71 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040072 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
73 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000074 std::cout << "ERROR: Failed to enable OLT" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040075 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +000076 }
Shad Ansariedef2132018-08-10 22:14:50 +000077 init_stats();
Shad Ansarib7b0ced2018-05-11 21:53:32 +000078 }
Shad Ansariedef2132018-08-10 22:14:50 +000079
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040080 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +000081 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040082}
83
84Status Disable_() {
85 // bcmbal_access_terminal_cfg acc_term_obj;
86 // bcmbal_access_terminal_key key = { };
87 //
88 // if (state::is_activated) {
89 // std::cout << "Disable OLT" << std::endl;
90 // key.access_term_id = DEFAULT_ATERM_ID;
91 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
92 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
93 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
94 // if (err) {
95 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
96 // return bcm_to_grpc_err(err, "Failed to disable OLT");
97 // }
98 // }
99 // //If already disabled, generate an extra indication ????
100 // return Status::OK;
101 //This fails with Operation Not Supported, bug ???
102
103 //TEMPORARY WORK AROUND
104 Status status = DisableUplinkIf_(0);
105 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000106 state.deactivate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400107 openolt::Indication ind;
108 openolt::OltIndication* olt_ind = new openolt::OltIndication;
109 olt_ind->set_oper_state("down");
110 ind.set_allocated_olt_ind(olt_ind);
111 std::cout << "Disable OLT, add an extra indication" << std::endl;
112 oltIndQ.push(ind);
113 }
114 return status;
115
116}
117
118Status Reenable_() {
119 Status status = EnableUplinkIf_(0);
120 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000121 state.activate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400122 openolt::Indication ind;
123 openolt::OltIndication* olt_ind = new openolt::OltIndication;
124 olt_ind->set_oper_state("up");
125 ind.set_allocated_olt_ind(olt_ind);
126 std::cout << "Reenable OLT, add an extra indication" << std::endl;
127 oltIndQ.push(ind);
128 }
129 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000130}
131
132Status EnablePonIf_(uint32_t intf_id) {
133 bcmbal_interface_cfg interface_obj;
134 bcmbal_interface_key interface_key;
135
136 interface_key.intf_id = intf_id;
137 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
138
139 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
140 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
141
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400142 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
143 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000144 std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400145 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000146 }
147
148 return Status::OK;
149}
150
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400151Status DisableUplinkIf_(uint32_t intf_id) {
152 bcmbal_interface_cfg interface_obj;
153 bcmbal_interface_key interface_key;
154
155 interface_key.intf_id = intf_id;
156 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
157
158 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
159 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
160
161 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
162 if (err) {
163 std::cout << "ERROR: Failed to disable Uplink interface: " << intf_id << std::endl;
164 return bcm_to_grpc_err(err, "Failed to disable Uplink interface");
165 }
166
167 return Status::OK;
168}
169
170Status EnableUplinkIf_(uint32_t intf_id) {
171 bcmbal_interface_cfg interface_obj;
172 bcmbal_interface_key interface_key;
173
174 interface_key.intf_id = intf_id;
175 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
176
177 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
178 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
179
180 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
181 if (err) {
182 std::cout << "ERROR: Failed to enable Uplink interface: " << intf_id << std::endl;
183 return bcm_to_grpc_err(err, "Failed to enable Uplink interface");
184 }
185
186 return Status::OK;
187}
188
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400189Status DisablePonIf_(uint32_t intf_id) {
190 bcmbal_interface_cfg interface_obj;
191 bcmbal_interface_key interface_key;
192
193 interface_key.intf_id = intf_id;
194 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
195
196 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
197 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
198
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400199 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
200 if (err) {
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400201 std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400202 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400203 }
204
205 return Status::OK;
206}
207
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000208Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Shad Ansari06101952018-07-25 00:22:09 +0000209 const char *vendor_id, const char *vendor_specific, uint32_t pir) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000210
211 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
212 bcmbal_subscriber_terminal_key subs_terminal_key;
213 bcmbal_serial_number serial_num = {};
214 bcmbal_registration_id registration_id = {};
215
216 std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
217 std::cout << "Vendor Id " << vendor_id
218 << "Vendor Specific Id " << vendor_specific
Shad Ansari06101952018-07-25 00:22:09 +0000219 << "pir " << pir
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000220 << std::endl;
221
222 subs_terminal_key.sub_term_id = onu_id;
223 subs_terminal_key.intf_id = intf_id;
224 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
225
226 memcpy(serial_num.vendor_id, vendor_id, 4);
227 memcpy(serial_num.vendor_specific, vendor_specific, 4);
228 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
229
Shad Ansaricb004c52018-05-30 18:07:23 +0000230#if 0
231 // Commenting out as this is causing issues with onu activation
232 // with BAL 2.6 (Broadcom CS5248819).
233
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000234 // FIXME - Use a default (all zeros) registration id.
235 memset(registration_id.arr, 0, sizeof(registration_id.arr));
236 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000237#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000238
239 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
240
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400241 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
242 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000243 std::cout << "ERROR: Failed to enable ONU: " << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400244 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000245 }
246
Shad Ansari06101952018-07-25 00:22:09 +0000247 /* Create subscriber's tm_sched */
248 {
249 bcmbal_tm_sched_cfg cfg;
250 bcmbal_tm_sched_key key = { };
251 key.dir = BCMBAL_TM_SCHED_DIR_DS;
252 key.id = intf_id << 7 | onu_id;
253 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
254
255 bcmbal_tm_sched_owner owner = { };
256 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
257 owner.u.sub_term.intf_id = intf_id;
258 owner.u.sub_term.sub_term_id = onu_id;
259 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
260
261 bcmbal_tm_sched_parent parent = { };
262 parent.sched_id = intf_id + 16384;
263 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
264 parent.weight = 1;
265 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
266 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
267
268 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
269
270 bcmbal_tm_shaping shaping = { };
271 shaping.pir = pir;
272 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
273 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
274
275 bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
276 }
277
278 /* Create tm_queue */
279 {
280 bcmbal_tm_queue_cfg cfg;
281 bcmbal_tm_queue_key key = { };
282 key.sched_id = intf_id << 7 | onu_id;
283 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
284 key.id = 0;
285 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
286 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
287 bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
288 }
289
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000290 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id));
291
292 //return Status::OK;
293}
294
Jonathan Davis70c21812018-07-19 15:32:10 -0400295Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
296 const char *vendor_id, const char *vendor_specific) {
297
298 SchedRemove_(intf_id, onu_id, mk_agg_port_id(onu_id));
299
300 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
301 bcmbal_subscriber_terminal_key subs_terminal_key;
302
303 std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl;
304 std::cout << "Vendor Id " << vendor_id
305 << "Vendor Specific Id " << vendor_specific
306 << std::endl;
307
308 subs_terminal_key.sub_term_id = onu_id;
309 subs_terminal_key.intf_id = intf_id;
310 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
311
312 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
313
314 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
315 std::cout << "ERROR: Failed to deactivate ONU: " << std::endl;
316 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
317 }
318
319 return Status::OK;
320}
321
322Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
323 const char *vendor_id, const char *vendor_specific) {
324 bcmos_errno err = BCM_ERR_OK;
325 bcmbal_subscriber_terminal_cfg cfg;
326 bcmbal_subscriber_terminal_key key = { };
327
328 std::cout << "Processing subscriber terminal cfg clear for sub_term_id = "
329 << onu_id << " and intf_id = " << intf_id << std::endl;
330
331 key.sub_term_id = onu_id ;
332 key.intf_id = intf_id ;
333
334 if (0 == key.sub_term_id)
335 {
336 std::cout << "Invalid Key to handle subscriber terminal clear subscriber_terminal_id = "
337 << onu_id << " Interface ID = " << intf_id << std::endl;
338 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
339 }
340
341 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
342
343 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
344 if (err != BCM_ERR_OK)
345 {
346 std::cout << "Failed to clear information for BAL subscriber_terminal_id = "
347 << onu_id << " Interface ID = " << intf_id << std::endl;
348 return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
349 }
350
351 return Status::OK;;
352}
353
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000354#define MAX_CHAR_LENGTH 20
355#define MAX_OMCI_MSG_LENGTH 44
356Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
357 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
358 bcmos_errno err = BCM_ERR_OK;
359
360 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
361 bcmbal_dest proxy_pkt_dest;
362
363 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
364 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
365 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
366
367 // ???
368 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
369 buf.len = MAX_OMCI_MSG_LENGTH;
370 } else {
371 buf.len = pkt.size()/2;
372 }
373
374 /* Send the OMCI packet using the BAL remote proxy API */
375 uint16_t idx1 = 0;
376 uint16_t idx2 = 0;
377 uint8_t arraySend[buf.len];
378 char str1[MAX_CHAR_LENGTH];
379 char str2[MAX_CHAR_LENGTH];
380 memset(&arraySend, 0, buf.len);
381
382 std::cout << "Sending omci msg to ONU of length is "
383 << buf.len
384 << std::endl;
385
386 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
387 sprintf(str1,"%c", pkt[idx1]);
388 sprintf(str2,"%c", pkt[++idx1]);
389 strcat(str1,str2);
390 arraySend[idx2] = strtol(str1, NULL, 16);
391 }
392
393 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
394 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
395
396 std::cout << "After converting bytes to hex "
397 << buf.val << buf.len << std::endl;
398
399 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
400
401 std::cout << "OMCI request msg 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
410Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_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_SUB_TERM,
416 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
417 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
418
419 buf.len = pkt.size();
420 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
421 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
422
423 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
424
425 std::cout << "Packet out of length " << buf.len
426 << " sent to ONU" << onu_id
427 << " through PON " << intf_id << std::endl;
428
429 free(buf.val);
430
431 return Status::OK;
432}
433
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400434Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
435 bcmos_errno err = BCM_ERR_OK;
436 bcmbal_dest proxy_pkt_dest;
437 bcmbal_u8_list_u32_max_2048 buf;
438
439 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
440 proxy_pkt_dest.u.nni.intf_id = intf_id;
441
442 buf.len = pkt.size();
443 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
444 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
445
446 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
447
448 std::cout << "Packet out of length " << buf.len
449 << " sent through uplink port " << intf_id << std::endl;
450
451 free(buf.val);
452
453 return Status::OK;
454}
455
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000456Status FlowAdd_(uint32_t onu_id,
457 uint32_t flow_id, const std::string flow_type,
458 uint32_t access_intf_id, uint32_t network_intf_id,
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400459 uint32_t gemport_id, uint32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000460 const ::openolt::Classifier& classifier,
461 const ::openolt::Action& action) {
462 bcmos_errno err;
463 bcmbal_flow_cfg cfg;
464 bcmbal_flow_key key = { };
465
466 std::cout << "flow add -"
467 << " intf_id:" << access_intf_id
468 << " onu_id:" << onu_id
469 << " flow_id:" << flow_id
470 << " flow_type:" << flow_type
471 << " gemport_id:" << gemport_id
472 << " network_intf_id:" << network_intf_id
473 << std::endl;
474
475 key.flow_id = flow_id;
476 if (flow_type.compare("upstream") == 0 ) {
477 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
478 } else if (flow_type.compare("downstream") == 0) {
479 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
480 } else {
481 std::cout << "Invalid flow type " << flow_type << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400482 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000483 }
484
485 BCMBAL_CFG_INIT(&cfg, flow, key);
486
487 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
488 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
489 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
490 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
491 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400492 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
493
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000494
495 {
496 bcmbal_classifier val = { };
497
498 if (classifier.o_tpid()) {
499 val.o_tpid = classifier.o_tpid();
500 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
501 }
502
503 if (classifier.o_vid()) {
504 val.o_vid = classifier.o_vid();
505 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
506 }
507
508 if (classifier.i_tpid()) {
509 val.i_tpid = classifier.i_tpid();
510 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
511 }
512
513 if (classifier.i_vid()) {
514 val.i_vid = classifier.i_vid();
515 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
516 }
517
518 if (classifier.o_pbits()) {
519 val.o_pbits = classifier.o_pbits();
520 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
521 }
522
523 if (classifier.i_pbits()) {
524 val.i_pbits = classifier.i_pbits();
525 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
526 }
527
528 if (classifier.eth_type()) {
529 val.ether_type = classifier.eth_type();
530 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
531 }
532
533 /*
534 if (classifier.dst_mac()) {
535 val.dst_mac = classifier.dst_mac();
536 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
537 }
538
539 if (classifier.src_mac()) {
540 val.src_mac = classifier.src_mac();
541 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
542 }
543 */
544
545 if (classifier.ip_proto()) {
546 val.ip_proto = classifier.ip_proto();
547 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
548 }
549
550 /*
551 if (classifier.dst_ip()) {
552 val.dst_ip = classifier.dst_ip();
553 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
554 }
555
556 if (classifier.src_ip()) {
557 val.src_ip = classifier.src_ip();
558 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
559 }
560 */
561
562 if (classifier.src_port()) {
563 val.src_port = classifier.src_port();
564 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
565 }
566
567 if (classifier.dst_port()) {
568 val.dst_port = classifier.dst_port();
569 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
570 }
571
572 if (!classifier.pkt_tag_type().empty()) {
573 if (classifier.pkt_tag_type().compare("untagged") == 0) {
574 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
575 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
576 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
577 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
578 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
579 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
580 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
581 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
582 }
583 }
584
585 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
586 }
587
588 {
589 bcmbal_action val = { };
590
591 const ::openolt::ActionCmd& cmd = action.cmd();
592
593 if (cmd.add_outer_tag()) {
594 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
595 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
596 }
597
598 if (cmd.remove_outer_tag()) {
599 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
600 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
601 }
602
603 if (cmd.trap_to_host()) {
604 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
605 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
606 }
607
608 if (action.o_vid()) {
609 val.o_vid = action.o_vid();
610 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
611 }
612
613 if (action.o_pbits()) {
614 val.o_pbits = action.o_pbits();
615 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
616 }
617
618 if (action.o_tpid()) {
619 val.o_tpid = action.o_tpid();
620 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
621 }
622
623 if (action.i_vid()) {
624 val.i_vid = action.i_vid();
625 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
626 }
627
628 if (action.i_pbits()) {
629 val.i_pbits = action.i_pbits();
630 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
631 }
632
633 if (action.i_tpid()) {
634 val.i_tpid = action.i_tpid();
635 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
636 }
637
638 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
639 }
640
641 {
642 bcmbal_tm_sched_id val;
643 val = (bcmbal_tm_sched_id) mk_sched_id(onu_id);
644 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
645 }
646
Shad Ansari06101952018-07-25 00:22:09 +0000647 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
648 bcmbal_tm_queue_ref val = { };
649 val.sched_id = access_intf_id << 7 | onu_id;
650 val.queue_id = 0;
651 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
652 }
653
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400654 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
655 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000656 std::cout << "ERROR: flow add failed" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400657 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000658 }
659
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400660 register_new_flow(key);
661
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000662 return Status::OK;
663}
664
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400665Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
666
667 bcmbal_flow_cfg cfg;
668 bcmbal_flow_key key = { };
669
670 key.flow_id = (bcmbal_flow_id) flow_id;
671 key.flow_id = flow_id;
672 if (flow_type.compare("upstream") == 0 ) {
673 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
674 } else if (flow_type.compare("downstream") == 0) {
675 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
676 } else {
677 std::cout << "Invalid flow type " << flow_type << std::endl;
678 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
679 }
680
681 BCMBAL_CFG_INIT(&cfg, flow, key);
682
683
684 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
685 if (err) {
686 std::cout << "Error " << err << " while removing flow "
687 << flow_id << ", " << flow_type << std::endl;
688 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
689 }
690
691 std::cout << "Flow " << flow_id << ", " << flow_type << " removed";
692 return Status::OK;
693}
694
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000695Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
696 bcmbal_tm_sched_cfg cfg;
697 bcmbal_tm_sched_key key = { };
698 bcmbal_tm_sched_type sched_type;
699
700 key.id = mk_sched_id(onu_id);
701 key.dir = BCMBAL_TM_SCHED_DIR_US;
702
703 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
704
705 {
706 bcmbal_tm_sched_owner val = { };
707
708 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
709 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400710 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 +0000711 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
712 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 -0400713 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
714 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 +0000715
716 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
717 }
718
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400719 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
720 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000721 std::cout << "ERROR: Failed to create upstream DBA sched"
722 << " id:" << key.id
723 << " intf_id:" << intf_id
724 << " onu_id:" << onu_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400725 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000726 //return 1;
727 }
728 std::cout << "create upstream DBA sched"
729 << " id:" << key.id
730 << " intf_id:" << intf_id
731 << " onu_id:" << onu_id << std::endl;
732
733 return Status::OK;
734 //return 0;
735}
Jonathan Davis70c21812018-07-19 15:32:10 -0400736
737Status SchedRemove_(int intf_id, int onu_id, int agg_port_id) {
738 bcmbal_tm_sched_cfg cfg;
739 bcmbal_tm_sched_key key = { };
740 bcmbal_tm_sched_type sched_type;
741
742 key.id = mk_sched_id(onu_id);
743 key.dir = BCMBAL_TM_SCHED_DIR_US;
744
745 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
746
747 if (bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(cfg.hdr))) {
748 std::cout << "ERROR: Failed to remove upstream DBA sched"
749 << " id:" << key.id
750 << " intf_id:" << intf_id
751 << " onu_id:" << onu_id << std::endl;
752 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
753 }
754
755 std::cout << "remove upstream DBA sched"
756 << " id:" << key.id
757 << " intf_id:" << intf_id
758 << " onu_id:" << onu_id << std::endl;
759
760 return Status::OK;
761 //return 0;
762}