blob: 5bf3a6244803825766d2e94381b0d1f118176a81 [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"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000029
30extern "C"
31{
32#include <bcmos_system.h>
33#include <bal_api.h>
34#include <bal_api_end.h>
35}
36
37Status Enable_() {
38 static bool enabled = false;
39 bcmbal_access_terminal_cfg acc_term_obj;
40 bcmbal_access_terminal_key key = { };
41
42 if (!enabled) {
43 std::cout << "Enable OLT" << std::endl;
44 key.access_term_id = DEFAULT_ATERM_ID;
45 BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
46 BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
47 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr))) {
48 std::cout << "ERROR: Failed to enable OLT" << std::endl;
49 return Status(grpc::StatusCode::INTERNAL, "Failed to enable OLT");
50 }
51 enabled = true;
52 }
53 return Status::OK;
54}
55
56Status EnablePonIf_(uint32_t intf_id) {
57 bcmbal_interface_cfg interface_obj;
58 bcmbal_interface_key interface_key;
59
60 interface_key.intf_id = intf_id;
61 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
62
63 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
64 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
65
66 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr))) {
67 std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
68 return Status(grpc::StatusCode::INTERNAL, "Failed to enable PON interface");
69 }
70
71 return Status::OK;
72}
73
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -040074Status DisablePonIf_(uint32_t intf_id) {
75 bcmbal_interface_cfg interface_obj;
76 bcmbal_interface_key interface_key;
77
78 interface_key.intf_id = intf_id;
79 interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
80
81 BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
82 BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN);
83
84 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr))) {
85 std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl;
86 return Status(grpc::StatusCode::INTERNAL, "Failed to disable PON interface");
87 }
88
89 return Status::OK;
90}
91
Shad Ansarib7b0ced2018-05-11 21:53:32 +000092Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
93 const char *vendor_id, const char *vendor_specific) {
94
95 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
96 bcmbal_subscriber_terminal_key subs_terminal_key;
97 bcmbal_serial_number serial_num = {};
98 bcmbal_registration_id registration_id = {};
99
100 std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
101 std::cout << "Vendor Id " << vendor_id
102 << "Vendor Specific Id " << vendor_specific
103 << std::endl;
104
105 subs_terminal_key.sub_term_id = onu_id;
106 subs_terminal_key.intf_id = intf_id;
107 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
108
109 memcpy(serial_num.vendor_id, vendor_id, 4);
110 memcpy(serial_num.vendor_specific, vendor_specific, 4);
111 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
112
Shad Ansaricb004c52018-05-30 18:07:23 +0000113#if 0
114 // Commenting out as this is causing issues with onu activation
115 // with BAL 2.6 (Broadcom CS5248819).
116
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000117 // FIXME - Use a default (all zeros) registration id.
118 memset(registration_id.arr, 0, sizeof(registration_id.arr));
119 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
Shad Ansaricb004c52018-05-30 18:07:23 +0000120#endif
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000121
122 BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
123
124 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
125 std::cout << "ERROR: Failed to enable ONU: " << std::endl;
126 return Status(grpc::StatusCode::INTERNAL, "Failed to enable ONU");
127 }
128
129 return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id));
130
131 //return Status::OK;
132}
133
134#define MAX_CHAR_LENGTH 20
135#define MAX_OMCI_MSG_LENGTH 44
136Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
137 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
138 bcmos_errno err = BCM_ERR_OK;
139
140 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
141 bcmbal_dest proxy_pkt_dest;
142
143 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
144 proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
145 proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
146
147 // ???
148 if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
149 buf.len = MAX_OMCI_MSG_LENGTH;
150 } else {
151 buf.len = pkt.size()/2;
152 }
153
154 /* Send the OMCI packet using the BAL remote proxy API */
155 uint16_t idx1 = 0;
156 uint16_t idx2 = 0;
157 uint8_t arraySend[buf.len];
158 char str1[MAX_CHAR_LENGTH];
159 char str2[MAX_CHAR_LENGTH];
160 memset(&arraySend, 0, buf.len);
161
162 std::cout << "Sending omci msg to ONU of length is "
163 << buf.len
164 << std::endl;
165
166 for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
167 sprintf(str1,"%c", pkt[idx1]);
168 sprintf(str2,"%c", pkt[++idx1]);
169 strcat(str1,str2);
170 arraySend[idx2] = strtol(str1, NULL, 16);
171 }
172
173 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
174 memcpy(buf.val, (uint8_t *)arraySend, buf.len);
175
176 std::cout << "After converting bytes to hex "
177 << buf.val << buf.len << std::endl;
178
179 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
180
181 std::cout << "OMCI request msg of length " << buf.len
182 << " sent to ONU" << onu_id
183 << " through PON " << intf_id << std::endl;
184
185 free(buf.val);
186
187 return Status::OK;
188}
189
190Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
191 bcmos_errno err = BCM_ERR_OK;
192 bcmbal_dest proxy_pkt_dest;
193 bcmbal_u8_list_u32_max_2048 buf;
194
195 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM,
196 proxy_pkt_dest.u.sub_term.sub_term_id = onu_id;
197 proxy_pkt_dest.u.sub_term.intf_id = intf_id;
198
199 buf.len = pkt.size();
200 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
201 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
202
203 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
204
205 std::cout << "Packet out of length " << buf.len
206 << " sent to ONU" << onu_id
207 << " through PON " << intf_id << std::endl;
208
209 free(buf.val);
210
211 return Status::OK;
212}
213
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400214Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) {
215 bcmos_errno err = BCM_ERR_OK;
216 bcmbal_dest proxy_pkt_dest;
217 bcmbal_u8_list_u32_max_2048 buf;
218
219 proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI,
220 proxy_pkt_dest.u.nni.intf_id = intf_id;
221
222 buf.len = pkt.size();
223 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
224 memcpy(buf.val, (uint8_t *)pkt.data(), buf.len);
225
226 err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len);
227
228 std::cout << "Packet out of length " << buf.len
229 << " sent through uplink port " << intf_id << std::endl;
230
231 free(buf.val);
232
233 return Status::OK;
234}
235
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000236Status FlowAdd_(uint32_t onu_id,
237 uint32_t flow_id, const std::string flow_type,
238 uint32_t access_intf_id, uint32_t network_intf_id,
239 uint32_t gemport_id,
240 const ::openolt::Classifier& classifier,
241 const ::openolt::Action& action) {
242 bcmos_errno err;
243 bcmbal_flow_cfg cfg;
244 bcmbal_flow_key key = { };
245
246 std::cout << "flow add -"
247 << " intf_id:" << access_intf_id
248 << " onu_id:" << onu_id
249 << " flow_id:" << flow_id
250 << " flow_type:" << flow_type
251 << " gemport_id:" << gemport_id
252 << " network_intf_id:" << network_intf_id
253 << std::endl;
254
255 key.flow_id = flow_id;
256 if (flow_type.compare("upstream") == 0 ) {
257 key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
258 } else if (flow_type.compare("downstream") == 0) {
259 key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
260 } else {
261 std::cout << "Invalid flow type " << flow_type << std::endl;
262 return Status::CANCELLED;
263 }
264
265 BCMBAL_CFG_INIT(&cfg, flow, key);
266
267 BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
268 BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
269 BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
270 BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
271 BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
272
273 {
274 bcmbal_classifier val = { };
275
276 if (classifier.o_tpid()) {
277 val.o_tpid = classifier.o_tpid();
278 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
279 }
280
281 if (classifier.o_vid()) {
282 val.o_vid = classifier.o_vid();
283 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
284 }
285
286 if (classifier.i_tpid()) {
287 val.i_tpid = classifier.i_tpid();
288 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
289 }
290
291 if (classifier.i_vid()) {
292 val.i_vid = classifier.i_vid();
293 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
294 }
295
296 if (classifier.o_pbits()) {
297 val.o_pbits = classifier.o_pbits();
298 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
299 }
300
301 if (classifier.i_pbits()) {
302 val.i_pbits = classifier.i_pbits();
303 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
304 }
305
306 if (classifier.eth_type()) {
307 val.ether_type = classifier.eth_type();
308 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
309 }
310
311 /*
312 if (classifier.dst_mac()) {
313 val.dst_mac = classifier.dst_mac();
314 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
315 }
316
317 if (classifier.src_mac()) {
318 val.src_mac = classifier.src_mac();
319 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
320 }
321 */
322
323 if (classifier.ip_proto()) {
324 val.ip_proto = classifier.ip_proto();
325 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
326 }
327
328 /*
329 if (classifier.dst_ip()) {
330 val.dst_ip = classifier.dst_ip();
331 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
332 }
333
334 if (classifier.src_ip()) {
335 val.src_ip = classifier.src_ip();
336 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
337 }
338 */
339
340 if (classifier.src_port()) {
341 val.src_port = classifier.src_port();
342 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
343 }
344
345 if (classifier.dst_port()) {
346 val.dst_port = classifier.dst_port();
347 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
348 }
349
350 if (!classifier.pkt_tag_type().empty()) {
351 if (classifier.pkt_tag_type().compare("untagged") == 0) {
352 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
353 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
354 } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
355 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
356 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
357 } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
358 val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
359 val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
360 }
361 }
362
363 BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
364 }
365
366 {
367 bcmbal_action val = { };
368
369 const ::openolt::ActionCmd& cmd = action.cmd();
370
371 if (cmd.add_outer_tag()) {
372 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
373 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
374 }
375
376 if (cmd.remove_outer_tag()) {
377 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
378 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
379 }
380
381 if (cmd.trap_to_host()) {
382 val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
383 val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
384 }
385
386 if (action.o_vid()) {
387 val.o_vid = action.o_vid();
388 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
389 }
390
391 if (action.o_pbits()) {
392 val.o_pbits = action.o_pbits();
393 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
394 }
395
396 if (action.o_tpid()) {
397 val.o_tpid = action.o_tpid();
398 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
399 }
400
401 if (action.i_vid()) {
402 val.i_vid = action.i_vid();
403 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
404 }
405
406 if (action.i_pbits()) {
407 val.i_pbits = action.i_pbits();
408 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
409 }
410
411 if (action.i_tpid()) {
412 val.i_tpid = action.i_tpid();
413 val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
414 }
415
416 BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
417 }
418
419 {
420 bcmbal_tm_sched_id val;
421 val = (bcmbal_tm_sched_id) mk_sched_id(onu_id);
422 BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
423 }
424
425 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr))) {
426 std::cout << "ERROR: flow add failed" << std::endl;
427 return Status(grpc::StatusCode::INTERNAL, "flow add failed");
428 }
429
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400430 register_new_flow(key);
431
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000432 return Status::OK;
433}
434
435Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
436 bcmbal_tm_sched_cfg cfg;
437 bcmbal_tm_sched_key key = { };
438 bcmbal_tm_sched_type sched_type;
439
440 key.id = mk_sched_id(onu_id);
441 key.dir = BCMBAL_TM_SCHED_DIR_US;
442
443 BCMBAL_CFG_INIT(&cfg, tm_sched, key);
444
445 {
446 bcmbal_tm_sched_owner val = { };
447
448 val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
449 val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
Nicolas Palpacuer0f19b1a2018-06-07 17:29:31 -0400450 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 +0000451 val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
452 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 -0400453 val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
454 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 +0000455
456 BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
457 }
458
459 if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr))) {
460 std::cout << "ERROR: Failed to create upstream DBA sched"
461 << " id:" << key.id
462 << " intf_id:" << intf_id
463 << " onu_id:" << onu_id << std::endl;
464 return Status(grpc::StatusCode::INTERNAL, "Failed to create upstream DBA sched");
465 //return 1;
466 }
467 std::cout << "create upstream DBA sched"
468 << " id:" << key.id
469 << " intf_id:" << intf_id
470 << " onu_id:" << onu_id << std::endl;
471
472 return Status::OK;
473 //return 0;
474}