blob: d75629703e026d4dbeb5550d7b068b2df98a6f58 [file] [log] [blame]
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001/*
Nicolas Palpacuerb78def42018-06-07 12:55:26 -04002 Copyright (C) 2018 Open Networking Foundation
Shad Ansarib7b0ced2018-05-11 21:53:32 +00003
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <iostream>
19#include <memory>
20#include <string>
21
22#include "Queue.h"
23#include <iostream>
24#include <sstream>
Nicolas Palpacuer9c352082018-08-14 16:37:14 -040025#include <chrono>
26#include <thread>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000027
28#include "core.h"
29#include "indications.h"
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -040030#include "stats_collection.h"
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040031#include "error_format.h"
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040032#include "state.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000033
34extern "C"
35{
36#include <bcmos_system.h>
37#include <bal_api.h>
38#include <bal_api_end.h>
39}
40
Shad Ansariedef2132018-08-10 22:14:50 +000041State state;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040042
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -070043static Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir);
44static Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id);
Shad Ansari627b5782018-08-13 22:49:32 +000045
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -040046static inline int mk_sched_id(int intf_id, int onu_id) {
47 return 1023 + intf_id * 112 + onu_id;
Shad Ansari627b5782018-08-13 22:49:32 +000048}
49
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -040050static inline int mk_agg_port_id(int intf_id, int onu_id) {
51 return 1023 + intf_id * 112 + onu_id;
Shad Ansari627b5782018-08-13 22:49:32 +000052}
53
54Status Enable_(int argc, char *argv[]) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000055 bcmbal_access_terminal_cfg acc_term_obj;
56 bcmbal_access_terminal_key key = { };
57
Shad Ansariedef2132018-08-10 22:14:50 +000058 if (!state.is_activated()) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000059 std::cout << "Enable OLT" << std::endl;
Shad Ansari627b5782018-08-13 22:49:32 +000060
61 bcmbal_init(argc, argv, NULL);
62
63 Status status = SubscribeIndication();
64 if (!status.ok()) {
65 std::cout << "ERROR: SubscribeIndication failed - "
66 << status.error_code() << ": " << status.error_message()
67 << std::endl;
68 return status;
69 }
70
Shad Ansarib7b0ced2018-05-11 21:53:32 +000071 key.access_term_id = DEFAULT_ATERM_ID;
72 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
73 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040074 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
75 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +000076 std::cout << "ERROR: Failed to enable OLT" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -040077 return bcm_to_grpc_err(err, "Failed to enable OLT");
Shad Ansarib7b0ced2018-05-11 21:53:32 +000078 }
Shad Ansariedef2132018-08-10 22:14:50 +000079 init_stats();
Shad Ansarib7b0ced2018-05-11 21:53:32 +000080 }
Shad Ansariedef2132018-08-10 22:14:50 +000081
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040082 //If already enabled, generate an extra indication ????
Shad Ansarib7b0ced2018-05-11 21:53:32 +000083 return Status::OK;
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -040084}
85
86Status Disable_() {
87 // bcmbal_access_terminal_cfg acc_term_obj;
88 // bcmbal_access_terminal_key key = { };
89 //
90 // if (state::is_activated) {
91 // std::cout << "Disable OLT" << std::endl;
92 // key.access_term_id = DEFAULT_ATERM_ID;
93 // BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
94 // BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_DOWN);
95 // bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr));
96 // if (err) {
97 // std::cout << "ERROR: Failed to disable OLT" << std::endl;
98 // return bcm_to_grpc_err(err, "Failed to disable OLT");
99 // }
100 // }
101 // //If already disabled, generate an extra indication ????
102 // return Status::OK;
103 //This fails with Operation Not Supported, bug ???
104
105 //TEMPORARY WORK AROUND
106 Status status = DisableUplinkIf_(0);
107 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000108 state.deactivate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400109 openolt::Indication ind;
110 openolt::OltIndication* olt_ind = new openolt::OltIndication;
111 olt_ind->set_oper_state("down");
112 ind.set_allocated_olt_ind(olt_ind);
113 std::cout << "Disable OLT, add an extra indication" << std::endl;
114 oltIndQ.push(ind);
115 }
116 return status;
117
118}
119
120Status Reenable_() {
121 Status status = EnableUplinkIf_(0);
122 if (status.ok()) {
Shad Ansariedef2132018-08-10 22:14:50 +0000123 state.activate();
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400124 openolt::Indication ind;
125 openolt::OltIndication* olt_ind = new openolt::OltIndication;
126 olt_ind->set_oper_state("up");
127 ind.set_allocated_olt_ind(olt_ind);
128 std::cout << "Reenable OLT, add an extra indication" << std::endl;
129 oltIndQ.push(ind);
130 }
131 return status;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000132}
133
134Status EnablePonIf_(uint32_t intf_id) {
135 bcmbal_interface_cfg interface_obj;
136 bcmbal_interface_key interface_key;
137
138 interface_key.intf_id = intf_id;
139 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
140
141 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
142 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
143
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400144 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
145 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000146 std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400147 return bcm_to_grpc_err(err, "Failed to enable PON interface");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000148 }
149
150 return Status::OK;
151}
152
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400153Status DisableUplinkIf_(uint32_t intf_id) {
154 bcmbal_interface_cfg interface_obj;
155 bcmbal_interface_key interface_key;
156
157 interface_key.intf_id = intf_id;
158 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
159
160 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
161 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
162
163 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
164 if (err) {
165 std::cout << "ERROR: Failed to disable Uplink interface: " << intf_id << std::endl;
166 return bcm_to_grpc_err(err, "Failed to disable Uplink interface");
167 }
168
169 return Status::OK;
170}
171
172Status EnableUplinkIf_(uint32_t intf_id) {
173 bcmbal_interface_cfg interface_obj;
174 bcmbal_interface_key interface_key;
175
176 interface_key.intf_id = intf_id;
177 interface_key.intf_type = BCMBAL_INTF_TYPE_NNI;
178
179 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
180 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
181
182 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
183 if (err) {
184 std::cout << "ERROR: Failed to enable Uplink interface: " << intf_id << std::endl;
185 return bcm_to_grpc_err(err, "Failed to enable Uplink interface");
186 }
187
188 return Status::OK;
189}
190
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400191Status DisablePonIf_(uint32_t intf_id) {
192 bcmbal_interface_cfg interface_obj;
193 bcmbal_interface_key interface_key;
194
195 interface_key.intf_id = intf_id;
196 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
197
198 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
199 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
200
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400201 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr));
202 if (err) {
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400203 std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400204 return bcm_to_grpc_err(err, "Failed to disable PON interface");
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400205 }
206
207 return Status::OK;
208}
209
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000210Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700211 const char *vendor_id, const char *vendor_specific, uint32_t pir,
212 uint32_t agg_port_id, uint32_t sched_id) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000213
214 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
215 bcmbal_subscriber_terminal_key subs_terminal_key;
216 bcmbal_serial_number serial_num = {};
217 bcmbal_registration_id registration_id = {};
218
219 std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
220 std::cout << "Vendor Id " << vendor_id
221 << "Vendor Specific Id " << vendor_specific
Shad Ansari06101952018-07-25 00:22:09 +0000222 << "pir " << pir
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000223 << std::endl;
224
225 subs_terminal_key.sub_term_id = onu_id;
226 subs_terminal_key.intf_id = intf_id;
227 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
228
229 memcpy(serial_num.vendor_id, vendor_id, 4);
230 memcpy(serial_num.vendor_specific, vendor_specific, 4);
231 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
232
Shad Ansaricb004c52018-05-30 18:07:23 +0000233#if 0
234 // Commenting out as this is causing issues with onu activation
235 // with BAL 2.6 (Broadcom CS5248819).
236
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000237 // FIXME - Use a default (all zeros) registration id.
238 memset(registration_id.arr, 0, sizeof(registration_id.arr));
239 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000240#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000241
242 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
243
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400244 bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
245 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000246 std::cout << "ERROR: Failed to enable ONU: " << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400247 return bcm_to_grpc_err(err, "Failed to enable ONU");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000248 }
249
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700250 if (agg_port_id != 0) {
251 return SchedAdd_(intf_id, onu_id, agg_port_id, sched_id, pir);
252 } else {
253 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), sched_id, pir);
254 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000255
256 //return Status::OK;
257}
258
Jonathan Davis70c21812018-07-19 15:32:10 -0400259Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
260 const char *vendor_id, const char *vendor_specific) {
261
Jonathan Davis70c21812018-07-19 15:32:10 -0400262 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
263 bcmbal_subscriber_terminal_key subs_terminal_key;
264
265 std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl;
266 std::cout << "Vendor Id " << vendor_id
267 << "Vendor Specific Id " << vendor_specific
268 << std::endl;
269
270 subs_terminal_key.sub_term_id = onu_id;
271 subs_terminal_key.intf_id = intf_id;
272 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
273
274 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN);
275
276 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
277 std::cout << "ERROR: Failed to deactivate ONU: " << std::endl;
278 return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU");
279 }
280
281 return Status::OK;
282}
283
284Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700285 const char *vendor_id, const char *vendor_specific,
286 uint32_t agg_port_id, uint32_t sched_id) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400287
288 // Need to deactivate before removing it (BAL rules)
289
290 DeactivateOnu_(intf_id, onu_id, vendor_id, vendor_specific);
291 // Sleep to allow the state to propagate
292 // We need the subscriber terminal object to be admin down before removal
293 // Without sleep the race condition is lost by ~ 20 ms
294 std::this_thread::sleep_for(std::chrono::milliseconds(100));
295
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700296 if (agg_port_id != 0) {
297 SchedRemove_(intf_id, onu_id, agg_port_id, sched_id);
298 } else {
299 SchedRemove_(intf_id, onu_id, mk_agg_port_id(intf_id, onu_id), sched_id);
300 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400301
Jonathan Davis70c21812018-07-19 15:32:10 -0400302 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
Nicolas Palpacuer135ce812018-08-30 09:04:34 -0400360 // std::cout << "Sending omci msg to ONU of length is "
361 // << buf.len
362 // << std::endl;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000363
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);
Nicolas Palpacuer135ce812018-08-30 09:04:34 -0400373 //
374 // std::cout << "After converting bytes to hex "
375 // << buf.val << buf.len << std::endl;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000376
377 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
378
Nicolas Palpacuer135ce812018-08-30 09:04:34 -0400379 // std::cout << "OMCI request msg of length " << buf.len
380 // << " sent to ONU" << onu_id
381 // << " through PON " << intf_id << std::endl;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000382
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,
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700437 uint32_t gemport_id, uint32_t sched_id,
438 uint32_t priority_value,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000439 const ::openolt::Classifier& classifier,
440 const ::openolt::Action& action) {
441 bcmos_errno err;
442 bcmbal_flow_cfg cfg;
443 bcmbal_flow_key key = { };
444
445 std::cout << "flow add -"
446 << " intf_id:" << access_intf_id
447 << " onu_id:" << onu_id
448 << " flow_id:" << flow_id
449 << " flow_type:" << flow_type
450 << " gemport_id:" << gemport_id
451 << " network_intf_id:" << network_intf_id
452 << std::endl;
453
454 key.flow_id = flow_id;
455 if (flow_type.compare("upstream") == 0 ) {
456 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
457 } else if (flow_type.compare("downstream") == 0) {
458 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
459 } else {
460 std::cout << "Invalid flow type " << flow_type << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400461 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000462 }
463
464 BCMBAL_CFG_INIT(&cfg, flow, key);
465
466 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
467 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
468 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
469 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
470 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
Nicolas Palpacuerd6cf5aa2018-07-16 15:14:39 -0400471 BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value);
472
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000473
474 {
475 bcmbal_classifier val = { };
476
477 if (classifier.o_tpid()) {
478 val.o_tpid = classifier.o_tpid();
479 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
480 }
481
482 if (classifier.o_vid()) {
483 val.o_vid = classifier.o_vid();
484 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
485 }
486
487 if (classifier.i_tpid()) {
488 val.i_tpid = classifier.i_tpid();
489 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
490 }
491
492 if (classifier.i_vid()) {
493 val.i_vid = classifier.i_vid();
494 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
495 }
496
497 if (classifier.o_pbits()) {
498 val.o_pbits = classifier.o_pbits();
499 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
500 }
501
502 if (classifier.i_pbits()) {
503 val.i_pbits = classifier.i_pbits();
504 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
505 }
506
507 if (classifier.eth_type()) {
508 val.ether_type = classifier.eth_type();
509 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
510 }
511
512 /*
513 if (classifier.dst_mac()) {
514 val.dst_mac = classifier.dst_mac();
515 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
516 }
517
518 if (classifier.src_mac()) {
519 val.src_mac = classifier.src_mac();
520 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
521 }
522 */
523
524 if (classifier.ip_proto()) {
525 val.ip_proto = classifier.ip_proto();
526 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
527 }
528
529 /*
530 if (classifier.dst_ip()) {
531 val.dst_ip = classifier.dst_ip();
532 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
533 }
534
535 if (classifier.src_ip()) {
536 val.src_ip = classifier.src_ip();
537 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
538 }
539 */
540
541 if (classifier.src_port()) {
542 val.src_port = classifier.src_port();
543 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
544 }
545
546 if (classifier.dst_port()) {
547 val.dst_port = classifier.dst_port();
548 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
549 }
550
551 if (!classifier.pkt_tag_type().empty()) {
552 if (classifier.pkt_tag_type().compare("untagged") == 0) {
553 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
554 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
555 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
556 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
557 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
558 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
559 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
560 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
561 }
562 }
563
564 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
565 }
566
567 {
568 bcmbal_action val = { };
569
570 const ::openolt::ActionCmd& cmd = action.cmd();
571
572 if (cmd.add_outer_tag()) {
573 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
574 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
575 }
576
577 if (cmd.remove_outer_tag()) {
578 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
579 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
580 }
581
582 if (cmd.trap_to_host()) {
583 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
584 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
585 }
586
587 if (action.o_vid()) {
588 val.o_vid = action.o_vid();
589 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
590 }
591
592 if (action.o_pbits()) {
593 val.o_pbits = action.o_pbits();
594 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
595 }
596
597 if (action.o_tpid()) {
598 val.o_tpid = action.o_tpid();
599 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
600 }
601
602 if (action.i_vid()) {
603 val.i_vid = action.i_vid();
604 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
605 }
606
607 if (action.i_pbits()) {
608 val.i_pbits = action.i_pbits();
609 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
610 }
611
612 if (action.i_tpid()) {
613 val.i_tpid = action.i_tpid();
614 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
615 }
616
617 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
618 }
619
620 {
621 bcmbal_tm_sched_id val;
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700622 if (sched_id != 0) {
623 val = sched_id;
624 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400625 val = (bcmbal_tm_sched_id) mk_sched_id(access_intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700626 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000627 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
628 }
629
Shad Ansari06101952018-07-25 00:22:09 +0000630 if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) {
631 bcmbal_tm_queue_ref val = { };
632 val.sched_id = access_intf_id << 7 | onu_id;
633 val.queue_id = 0;
634 BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val);
635 }
636
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400637 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
638 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000639 std::cout << "ERROR: flow add failed" << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400640 return bcm_to_grpc_err(err, "flow add failed");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000641 }
642
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400643 // register_new_flow(key);
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400644
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000645 return Status::OK;
646}
647
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400648Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
649
650 bcmbal_flow_cfg cfg;
651 bcmbal_flow_key key = { };
652
653 key.flow_id = (bcmbal_flow_id) flow_id;
654 key.flow_id = flow_id;
655 if (flow_type.compare("upstream") == 0 ) {
656 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
657 } else if (flow_type.compare("downstream") == 0) {
658 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
659 } else {
660 std::cout << "Invalid flow type " << flow_type << std::endl;
661 return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
662 }
663
664 BCMBAL_CFG_INIT(&cfg, flow, key);
665
666
667 bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
668 if (err) {
669 std::cout << "Error " << err << " while removing flow "
670 << flow_id << ", " << flow_type << std::endl;
671 return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
672 }
673
674 std::cout << "Flow " << flow_id << ", " << flow_type << " removed";
675 return Status::OK;
676}
677
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700678Status SchedAdd_(int intf_id, int onu_id, int agg_port_id, int sched_id, int pir) {
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400679
680 bcmos_errno err;
681
682 /* Downstream */
683
684 /* Create subscriber's tm_sched */
685 {
686 bcmbal_tm_sched_cfg cfg;
687 bcmbal_tm_sched_key key = { };
688 key.dir = BCMBAL_TM_SCHED_DIR_DS;
689 key.id = intf_id << 7 | onu_id;
690 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
691
692 bcmbal_tm_sched_owner owner = { };
693 owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM;
694 owner.u.sub_term.intf_id = intf_id;
695 owner.u.sub_term.sub_term_id = onu_id;
696 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner);
697
698 bcmbal_tm_sched_parent parent = { };
699 parent.sched_id = intf_id + 16384;
700 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID;
701 parent.weight = 1;
702 parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT;
703 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent);
704
705 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ);
706
707 bcmbal_tm_shaping shaping = { };
708 shaping.pir = pir;
709 shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR;
710 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping);
711
712 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
713 if (err) {
714 std::cout << "ERROR: Failed to create subscriber downstream sched"
715 << " id:" << key.id
716 << " intf_id:" << intf_id
717 << " onu_id:" << onu_id << std::endl;
718 return bcm_to_grpc_err(err, "Failed to create subscriber downstream sched");
719 }
720 }
721
722 /* Create tm_queue */
723 {
724 bcmbal_tm_queue_cfg cfg;
725 bcmbal_tm_queue_key key = { };
726 key.sched_id = intf_id << 7 | onu_id;
727 key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
728 key.id = 0;
729
730 BCMBAL_CFG_INIT(&cfg, tm_queue, key);
731 BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1);
732 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
733
734 if (err) {
735 std::cout << "ERROR: Failed to create subscriber downstream tm queue"
736 << " id: " << key.id
737 << " sched_id: " << key.sched_id
738 << " intf_id: " << intf_id
739 << " onu_id: " << onu_id << std::endl;
740 return bcm_to_grpc_err(err, "Failed to create subscriber downstream tm queue");
741 }
742
743 }
744
745 /* Upstream */
746
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000747 bcmbal_tm_sched_cfg cfg;
748 bcmbal_tm_sched_key key = { };
749 bcmbal_tm_sched_type sched_type;
750
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700751 if (sched_id != 0) {
752 key.id = sched_id;
753 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400754 key.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700755 }
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000756 key.dir = BCMBAL_TM_SCHED_DIR_US;
757
758 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
759
760 {
761 bcmbal_tm_sched_owner val = { };
762
763 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
764 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400765 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 +0000766 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
767 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 -0400768 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
769 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 +0000770
771 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
772 }
773
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400774 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr));
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400775 if (err) {
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000776 std::cout << "ERROR: Failed to create upstream DBA sched"
777 << " id:" << key.id
778 << " intf_id:" << intf_id
779 << " onu_id:" << onu_id << std::endl;
Nicolas Palpacuer73222e02018-07-16 12:20:26 -0400780 return bcm_to_grpc_err(err, "Failed to create upstream DBA sched");
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000781 }
782 std::cout << "create upstream DBA sched"
783 << " id:" << key.id
784 << " intf_id:" << intf_id
785 << " onu_id:" << onu_id << std::endl;
786
787 return Status::OK;
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000788}
Jonathan Davis70c21812018-07-19 15:32:10 -0400789
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700790Status SchedRemove_(int intf_id, int onu_id, int agg_port_id, int sched_id) {
Jonathan Davis70c21812018-07-19 15:32:10 -0400791
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400792 bcmos_errno err;
Jonathan Davis70c21812018-07-19 15:32:10 -0400793
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400794 /* Upstream */
Jonathan Davis70c21812018-07-19 15:32:10 -0400795
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400796 bcmbal_tm_sched_cfg tm_cfg_us;
797 bcmbal_tm_sched_key tm_key_us = { };
798
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700799 if (sched_id != 0) {
800 tm_key_us.id = sched_id;
801 } else {
Nicolas Palpacuer8ebaa262018-08-16 14:56:47 -0400802 tm_key_us.id = mk_sched_id(intf_id, onu_id);
Girish Gowdru1cdf6ce2018-08-27 02:43:02 -0700803 }
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400804 tm_key_us.dir = BCMBAL_TM_SCHED_DIR_US;
805
806 BCMBAL_CFG_INIT(&tm_cfg_us, tm_sched, tm_key_us);
807
808 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_us.hdr));
809 if (err) {
810 std::cout << "ERROR: Failed to remove upstream DBA sched"
811 << " id:" << tm_key_us.id
Jonathan Davis70c21812018-07-19 15:32:10 -0400812 << " intf_id:" << intf_id
813 << " onu_id:" << onu_id << std::endl;
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400814 return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched");
Jonathan Davis70c21812018-07-19 15:32:10 -0400815 }
816
817 std::cout << "remove upstream DBA sched"
Nicolas Palpacuer9c352082018-08-14 16:37:14 -0400818 << " id:" << tm_key_us.id
819 << " intf_id:" << intf_id
820 << " onu_id:" << onu_id << std::endl;
821
822 /* Downstream */
823
824 // Queue
825
826 bcmbal_tm_queue_cfg queue_cfg;
827 bcmbal_tm_queue_key queue_key = { };
828 queue_key.sched_id = intf_id << 7 | onu_id;
829 queue_key.sched_dir = BCMBAL_TM_SCHED_DIR_DS;
830 queue_key.id = 0;
831
832 BCMBAL_CFG_INIT(&queue_cfg, tm_queue, queue_key);
833
834 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(queue_cfg.hdr));
835 if (err) {
836 std::cout << "ERROR: Failed to remove downstream tm queue"
837 << " id:" << queue_key.id
838 << " sched_id:" << queue_key.sched_id
839 << " intf_id:" << intf_id
840 << " onu_id:" << onu_id << std::endl;
841 return Status(grpc::StatusCode::INTERNAL, "Failed to remove downstream tm queue");
842 }
843
844 std::cout << "remove upstream DBA sched"
845 << " id:" << queue_key.id
846 << " sched_id:" << queue_key.sched_id
847 << " intf_id:" << intf_id
848 << " onu_id:" << onu_id << std::endl;
849
850 // Sheduler
851
852 bcmbal_tm_sched_cfg tm_cfg_ds;
853 bcmbal_tm_sched_key tm_key_ds = { };
854 tm_key_ds.dir = BCMBAL_TM_SCHED_DIR_DS;
855 tm_key_ds.id = intf_id << 7 | onu_id;
856 BCMBAL_CFG_INIT(&tm_cfg_ds, tm_sched, tm_key_ds);
857
858 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(tm_cfg_ds.hdr));
859 if (err) {
860 std::cout << "ERROR: Failed to remove sub downstream sched"
861 << " id:" << tm_key_us.id
862 << " intf_id:" << intf_id
863 << " onu_id:" << onu_id << std::endl;
864 return Status(grpc::StatusCode::INTERNAL, "Failed to remove sub downstream sched");
865 }
866
867 std::cout << "remove sub downstream sched"
868 << " id:" << tm_key_us.id
Jonathan Davis70c21812018-07-19 15:32:10 -0400869 << " intf_id:" << intf_id
870 << " onu_id:" << onu_id << std::endl;
871
872 return Status::OK;
873 //return 0;
874}