blob: 24bca9da5b7a9ec882b5ef5fbdfec56165e2e7ac [file] [log] [blame]
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301/*
2** Copyright 2017-present Open Networking Foundation
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8** http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17#include <stdio.h>
18#include <bcmos_system.h>
19#include <bal_api.h>
20
21#undef _SYS_QUEUE_H_
22
23#include "asfvolt16_driver.h"
24#include "bal_access_terminal_hdlr.h"
25#include "bal_subscriber_terminal_hdlr.h"
26#include "bal_flow_hdlr.h"
27#include "bal_group_hdlr.h"
28#include "bal_interface_hdlr.h"
29#include "bal_tmqueue_hdlr.h"
30#include "bal_tmsched_hdlr.h"
31#include "bal_packet_hdlr.h"
32#include "bal_indications_hdlr.h"
33
34bcmbal_access_term_id access_term_id = DEFAULT_ATERM_ID;
35
36/********************************************************************\
37 * Function : bal_register_indication_cbs *
38 * Description : Registering the Call back function to handle the *
39 * indciations from BAL *
40 ********************************************************************/
41uint32_t bal_register_indication_cbs()
42{
43 bcmos_errno err = BCM_ERR_OK;
44 bcmbal_cb_cfg cb_cfg = {};
45 uint16_t ind_subgroup;
46 ASFVOLT_LOG(ASFVOLT_DEBUG, "Subscription for other messages\n");
47
48 cb_cfg.module = BCMOS_MODULE_ID_NONE;
49
50 /* Register to get indications for interface objects
51 */
52 cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
53
54 /* Interface los */
55 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_los_indication_cb;
56 ind_subgroup = bcmbal_interface_auto_id_los;
57 cb_cfg.p_subgroup = &ind_subgroup;
58 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
59
60 /* Interface Indication */
61 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_indication_cb;
62 ind_subgroup = bcmbal_interface_auto_id_ind;
63 cb_cfg.p_subgroup = &ind_subgroup;
64 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
65
66 /* Register to get indications for subscriber terminal objects
67 */
68 cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
69
70 /* Subscriber Terminal Alarm */
71 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_alarm_indication_cb;
72 ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_alarm;
73 cb_cfg.p_subgroup = &ind_subgroup;
74 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
75
76 /* Subscriber Terminal Discovery */
77 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_disc_indication_cb;
78 ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_disc;
79 cb_cfg.p_subgroup = &ind_subgroup;
80 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
81
82 /* Subscriber Terminal Indication */
83 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_indication_cb;
84 ind_subgroup = bcmbal_subscriber_terminal_auto_id_ind;
85 cb_cfg.p_subgroup = &ind_subgroup;
86 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
87
88 /* Register to get indication callbacks for OMCI objects
89 */
90 cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
91
92 ind_subgroup = BCMBAL_IND_SUBGROUP(packet, itu_omci_channel_rx);
93 cb_cfg.p_object_key_info = NULL;
94 cb_cfg.p_subgroup = &ind_subgroup;
95 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler )bal_omci_data_indication_cb;
96 bcmbal_subscribe_ind(0, &cb_cfg);
97
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053098 /* Bearer Channel Data */
99 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_packet_data_indication_cb;
100 ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
101 cb_cfg.p_subgroup = &ind_subgroup;
102 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
103
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530104#if 0
105 /* Access Terminal Operational State Change */
106 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_acc_term_osc_indication_cb;
107 ind_subgroup = bcmbal_access_terminal_auto_id_oper_status_change;
108 cb_cfg.p_subgroup = &ind_subgroup;
109 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
110
111 /* Register to get indication callbacks for flow objects
112 */
113 cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
114
115 /* Flow Operational State Change */
116 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_flow_osc_indication_cb;
117 ind_subgroup = bcmbal_flow_auto_id_oper_status_change;
118 cb_cfg.p_subgroup = &ind_subgroup;
119 err = bcmbal_subscribe_ind(access_term_id, &cb_cfg);
120
121 /* Flow Indication */
122 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_flow_indication_cb;
123 ind_subgroup = bcmbal_flow_auto_id_ind;
124 cb_cfg.p_subgroup = &ind_subgroup;
125 err = bcmbal_subscribe_ind(access_term_id, &cb_cfg);
126
127 /* Register to get indication callbacks for group objects
128 */
129 cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
130 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_group_indication_cb;
131 ind_subgroup = bcmbal_group_auto_id_ind;
132 cb_cfg.p_subgroup = &ind_subgroup;
133 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
134
135 /* Interface Operational State Change */
136 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_osc_indication_cb;
137 ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
138 cb_cfg.p_subgroup = &ind_subgroup;
139 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
140
141 /* Interface los */
142 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_los_indication_cb;
143 ind_subgroup = bcmbal_interface_auto_id_los;
144 cb_cfg.p_subgroup = &ind_subgroup;
145 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
146
147 /* Subscriber Terminal Operational State Change */
148 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_osc_indication_cb;
149 ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
150 cb_cfg.p_subgroup = &ind_subgroup;
151 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
152
153 /* Subscriber Terminal dgi */
154 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_dgi_indication_cb;
155 ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
156 cb_cfg.p_subgroup = &ind_subgroup;
157 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
158
159 /* Register to get indication callbacks for tm queue objects
160 */
161 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_QUEUE;
162 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_tm_queue_indication_cb;
163 ind_subgroup = bcmbal_tm_queue_auto_id_ind;
164 cb_cfg.p_subgroup = &ind_subgroup;
165 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
166
167 /* Register to get indication callbacks for tm sched objects
168 */
169 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_SCHED;
170 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_tm_sched_indication_cb;
171 ind_subgroup = bcmbal_tm_sched_auto_id_ind;
172 cb_cfg.p_subgroup = &ind_subgroup;
173 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
174
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530175
176 /* OAM Channel Data - oam response indication */
177 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_oam_data_indication_cb;
178 ind_subgroup = bcmbal_packet_auto_id_ieee_oam_channel_rx;
179 cb_cfg.p_subgroup = &ind_subgroup;
180 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
181
182#endif
183 return err;
184}
185
186
187/********************************************************************
188 * *
189 * gRPC service RPC function implementation *
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530190 * *
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530191 ********************************************************************/
192
193/********************************************************************\
194 * Function : asfvolt16_bal_init *
195 * Description : This function will initialize the BAL module *
196 ********************************************************************/
197uint32_t asfvolt16_bal_init(BalInit *bal_init, balCoreIpInfo *coreInfo)
198
199{
200 bcmos_errno err = BCM_ERR_OK;
201
202 char *ip_and_port = NULL;
203 if (NULL == bal_init)
204 {
205 ASFVOLT_LOG(ASFVOLT_ERROR, "Recvied NULL balInit Structure from VOLTHA \n");
206 return BAL_ERRNO__BAL_ERR_PERM;
207 }
208 else
209 {
210 ip_and_port = bal_init->voltha_adapter_ip_port;
211 ASFVOLT_LOG(ASFVOLT_DEBUG,"\nRecevied Adapter IP and Port from VOLTHA is %s\n",ip_and_port);
212 }
213 char *argv[6];
214 /* Initialize BAL */
215 argv[1] = coreInfo->bal_core_arg1;
216 argv[2] = coreInfo->bal_core_ip_port;
217 argv[3] = coreInfo->bal_core_arg2;
218 argv[4] = coreInfo->bal_shared_lib_ip_port;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530219 int argc = 5;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530220 client = grpc_c_client_init(ip_and_port, "bal_client", NULL);
221
222 /* Init BAL */
223 err = bcmbal_apiend_init_all(argc, argv, NULL,3);
224 if(err != BCM_ERR_OK)
225 {
226 printf("\n Failed in bcmbal_init \n");
227 }
228
229#if 0
230 err = (err != BCM_ERR_OK) ? err : bcmbal_autostart(); /* Execute bal_autostart.ini script if any */
231
232 if (err)
233 {
234 /* Let logger task have enough time to drain its message queue. */
235 usleep(1000000);
236 ASFVOLT_LOG(ASFVOLT_ERROR, "failed to Initialize the BAL\n");
237 return err;
238 }
239#endif
240
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530241 /* Register the call back functions to handle any
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530242 * indications from the BAL */
243 bcmbal_cb_cfg cb_cfg = {};
244 uint16_t ind_subgroup;
245
246 cb_cfg.module = BCMOS_MODULE_ID_NONE;
247 /* Register to get indications for access terminal objects
248 */
249 cb_cfg.obj_type = BCMBAL_OBJ_ID_ACCESS_TERMINAL;
250
251 /* Access Terminal Indication */
252 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_acc_term_indication_cb;
253 ind_subgroup = bcmbal_access_terminal_auto_id_ind;
254 cb_cfg.p_subgroup = &ind_subgroup;
255 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
256
257 if (err)
258 {
259 ASFVOLT_LOG(ASFVOLT_ERROR, "failed to register call back functions to BAL\n");
260 }
261
262 return err;
263}
264
265/********************************************************************\
266 * Function : asfvolt16_bal_finish *
267 * Description : This function will Un-initialize the BAL module *
268 ********************************************************************/
269uint32_t asfvolt16_bal_finish(void)
270{
271 bcmos_errno err = BCM_ERR_OK;
272
273 /* Un-Initialize the BAL function */
274 bcmbal_apiend_finish();
275
276 return err;
277}
278
279
280/********************************************************************\
281 * Function : asfvolt16_bal_cfg_set *
282 * Description : Handles below configuration *
283 * 1) Access Terminal Cfg *
284 * 2) Interface(PON & NNI) Cfg *
285 * 3) Subscriber Terminal (ONU) cfg *
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530286 * 4) Flow Cfg *
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530287 * 5) Group Cfg (In case of Multicast) *
288 ********************************************************************/
289uint32_t asfvolt16_bal_cfg_set(BalCfg *cfg)
290{
291 bcmos_errno err = BCM_ERR_OK;
292 memset(&voltha_device_id, 0, ASFVOLT_MAX_DEVICE_ID_SIZE);
293 strcpy(voltha_device_id,cfg->device_id);
294
295 switch(cfg->hdr->obj_type)
296 {
297 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
298 {
299 err = bal_access_terminal_cfg_set(cfg->cfg);
300 break;
301 }
302 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
303 {
304 err = bal_interface_cfg_set(cfg->interface);
305 break;
306 }
307 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
308 {
309 err = bal_subscriber_terminal_cfg_set(cfg->terminal);
310 break;
311 }
312 case BAL_OBJ_ID__BAL_OBJ_ID_FLOW:
313 {
314 err = bal_flow_cfg_set(cfg->flow);
315 break;
316 }
317 case BAL_OBJ_ID__BAL_OBJ_ID_GROUP:
318 {
319 err = bal_group_cfg_set(cfg->group);
320 break;
321 }
322 case BAL_OBJ_ID__BAL_OBJ_ID_TM_QUEUE:
323 {
324 err = bal_tm_queue_cfg_set(cfg->tm_queue_cfg);
325 break;
326 }
327 case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
328 {
329 err = bal_tm_sched_cfg_set(cfg->tm_sched_cfg);
330 break;
331 }
332 case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
333 {
334 err = bal_packet_cfg_req(cfg->packet);
335 break;
336 }
337 default:
338 {
339 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid objet type for configuration\n");
340 err = BAL_ERRNO__BAL_ERR_INVALID_OP;
341 break;
342 }
343 }
344 return err;
345}
346
347/********************************************************************\
348 * Function : asfvolt16_bal_cfg_clear *
349 * Description : Clears the configuration related to below objects *
350 * 1) Access Terminal Cfg *
351 * 2) Interface(PON & NNI) Cfg *
352 * 3) Subscriber Terminal (ONU) cfg *
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530353 * 4) Flow Cfg *
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530354 * 5) Group Cfg (In case of Multicast) *
355 ********************************************************************/
356uint32_t asfvolt16_bal_cfg_clear(BalKey *key)
357{
358 bcmos_errno err = BCM_ERR_OK;
359
360 if(!key->hdr->has_obj_type)
361 {
362 ASFVOLT_LOG(ASFVOLT_ERROR, "object type is not present for clear\n");
363 return BAL_ERRNO__BAL_ERR_INVALID_OP;
364 }
365
366 switch(key->hdr->obj_type)
367 {
368 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
369 {
370 err = bal_access_terminal_cfg_clear(key->access_term_key);
371 break;
372 }
373 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
374 {
375 err = bal_interface_cfg_clear(key->interface_key);
376 break;
377 }
378 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
379 {
380 err = bal_subscriber_terminal_cfg_clear(key->terminal_key);
381 break;
382 }
383 case BAL_OBJ_ID__BAL_OBJ_ID_FLOW:
384 {
385 err = bal_flow_cfg_clear(key->flow_key);
386 break;
387 }
388 case BAL_OBJ_ID__BAL_OBJ_ID_GROUP:
389 {
390 break;
391 }
392 case BAL_OBJ_ID__BAL_OBJ_ID_TM_QUEUE:
393 {
394 err = bal_tm_queue_cfg_clear(key->tm_queue_key);
395 break;
396 }
397 case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
398 {
399 err = bal_tm_sched_cfg_clear(key->tm_sched_key);
400 break;
401 }
402 /*case BAL_KEY__OBJ_PACKET_KEY:
403 {
404 break;
405 }*/
406 default:
407 {
408 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid objet type to handle clear\n");
409 err = BAL_ERRNO__BAL_ERR_INVALID_OP;
410 break;
411 }
412 }
413 return err;
414}
415
416
417/********************************************************************\
418 * Function : asfvolt16_bal_cfg_get *
419 * Description : Get the configuration related to below objects *
420 * 1) Access Terminal Cfg *
421 * 2) Interface(PON & NNI) Cfg *
422 * 3) Subscriber Terminal (ONU) cfg *
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530423 * 4) Flow Cfg *
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530424 * 5) Group Cfg (In case of Multicast) *
425 ********************************************************************/
426uint32_t asfvolt16_bal_cfg_get(BalKey *key, BalCfg *cfg)
427{
428 bcmos_errno err = BCM_ERR_OK;
429
430 if(!key->hdr->has_obj_type)
431 {
432 ASFVOLT_LOG(ASFVOLT_ERROR, "object type is not present for get\n");
433 return BAL_ERRNO__BAL_ERR_INVALID_OP;
434 }
435
436 switch(key->hdr->obj_type)
437 {
438 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
439 {
440 err = bal_access_terminal_cfg_get(key->access_term_key, cfg->cfg );
441 break;
442 }
443 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
444 {
445 err = bal_interface_cfg_get(key->interface_key, cfg->interface);
446 break;
447 }
448 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
449 {
450 err = bal_subscriber_terminal_cfg_get(key->terminal_key, cfg->terminal);
451 break;
452 }
453 case BAL_OBJ_ID__BAL_OBJ_ID_FLOW:
454 {
455 err = bal_flow_cfg_get(key->flow_key, cfg->flow);
456 break;
457 }
458 case BAL_OBJ_ID__BAL_OBJ_ID_GROUP:
459 {
460 err = bal_group_cfg_get(key->group_key, cfg->group);
461 break;
462 }
463 case BAL_OBJ_ID__BAL_OBJ_ID_TM_QUEUE:
464 {
465 err = bal_tm_queue_cfg_get(key->tm_queue_key, cfg->tm_queue_cfg);
466 break;
467 }
468 case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
469 {
470 err = bal_tm_sched_cfg_get(key->tm_sched_key, cfg->tm_sched_cfg);
471 break;
472 }
473 case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
474 {
475 break;
476 }
477 default:
478 {
479 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid objet type to handle Get\n");
480 err = BAL_ERRNO__BAL_ERR_INVALID_OP;
481 break;
482 }
483 }
484 return err;
485}
486
487