blob: 1178ff2b3305754aebea0c485d4130e55e5e0122 [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
98#if 0
99 /* Access Terminal Operational State Change */
100 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_acc_term_osc_indication_cb;
101 ind_subgroup = bcmbal_access_terminal_auto_id_oper_status_change;
102 cb_cfg.p_subgroup = &ind_subgroup;
103 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
104
105 /* Register to get indication callbacks for flow objects
106 */
107 cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
108
109 /* Flow Operational State Change */
110 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_flow_osc_indication_cb;
111 ind_subgroup = bcmbal_flow_auto_id_oper_status_change;
112 cb_cfg.p_subgroup = &ind_subgroup;
113 err = bcmbal_subscribe_ind(access_term_id, &cb_cfg);
114
115 /* Flow Indication */
116 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_flow_indication_cb;
117 ind_subgroup = bcmbal_flow_auto_id_ind;
118 cb_cfg.p_subgroup = &ind_subgroup;
119 err = bcmbal_subscribe_ind(access_term_id, &cb_cfg);
120
121 /* Register to get indication callbacks for group objects
122 */
123 cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
124 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_group_indication_cb;
125 ind_subgroup = bcmbal_group_auto_id_ind;
126 cb_cfg.p_subgroup = &ind_subgroup;
127 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
128
129 /* Interface Operational State Change */
130 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_osc_indication_cb;
131 ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
132 cb_cfg.p_subgroup = &ind_subgroup;
133 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
134
135 /* Interface los */
136 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_los_indication_cb;
137 ind_subgroup = bcmbal_interface_auto_id_los;
138 cb_cfg.p_subgroup = &ind_subgroup;
139 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
140
141 /* Subscriber Terminal Operational State Change */
142 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_osc_indication_cb;
143 ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
144 cb_cfg.p_subgroup = &ind_subgroup;
145 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
146
147 /* Subscriber Terminal dgi */
148 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_dgi_indication_cb;
149 ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
150 cb_cfg.p_subgroup = &ind_subgroup;
151 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
152
153 /* Register to get indication callbacks for tm queue objects
154 */
155 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_QUEUE;
156 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_tm_queue_indication_cb;
157 ind_subgroup = bcmbal_tm_queue_auto_id_ind;
158 cb_cfg.p_subgroup = &ind_subgroup;
159 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
160
161 /* Register to get indication callbacks for tm sched objects
162 */
163 cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_SCHED;
164 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_tm_sched_indication_cb;
165 ind_subgroup = bcmbal_tm_sched_auto_id_ind;
166 cb_cfg.p_subgroup = &ind_subgroup;
167 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
168
169 /* Bearer Channel Data */
170 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_packet_data_indication_cb;
171 ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
172 cb_cfg.p_subgroup = &ind_subgroup;
173 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
174
175 /* OAM Channel Data - oam response indication */
176 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_oam_data_indication_cb;
177 ind_subgroup = bcmbal_packet_auto_id_ieee_oam_channel_rx;
178 cb_cfg.p_subgroup = &ind_subgroup;
179 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
180
181#endif
182 return err;
183}
184
185
186/********************************************************************
187 * *
188 * gRPC service RPC function implementation *
189 * *
190 ********************************************************************/
191
192/********************************************************************\
193 * Function : asfvolt16_bal_init *
194 * Description : This function will initialize the BAL module *
195 ********************************************************************/
196uint32_t asfvolt16_bal_init(BalInit *bal_init, balCoreIpInfo *coreInfo)
197
198{
199 bcmos_errno err = BCM_ERR_OK;
200
201 char *ip_and_port = NULL;
202 if (NULL == bal_init)
203 {
204 ASFVOLT_LOG(ASFVOLT_ERROR, "Recvied NULL balInit Structure from VOLTHA \n");
205 return BAL_ERRNO__BAL_ERR_PERM;
206 }
207 else
208 {
209 ip_and_port = bal_init->voltha_adapter_ip_port;
210 ASFVOLT_LOG(ASFVOLT_DEBUG,"\nRecevied Adapter IP and Port from VOLTHA is %s\n",ip_and_port);
211 }
212 char *argv[6];
213 /* Initialize BAL */
214 argv[1] = coreInfo->bal_core_arg1;
215 argv[2] = coreInfo->bal_core_ip_port;
216 argv[3] = coreInfo->bal_core_arg2;
217 argv[4] = coreInfo->bal_shared_lib_ip_port;
218 int argc = 5;
219 client = grpc_c_client_init(ip_and_port, "bal_client", NULL);
220
221 /* Init BAL */
222 err = bcmbal_apiend_init_all(argc, argv, NULL,3);
223 if(err != BCM_ERR_OK)
224 {
225 printf("\n Failed in bcmbal_init \n");
226 }
227
228#if 0
229 err = (err != BCM_ERR_OK) ? err : bcmbal_autostart(); /* Execute bal_autostart.ini script if any */
230
231 if (err)
232 {
233 /* Let logger task have enough time to drain its message queue. */
234 usleep(1000000);
235 ASFVOLT_LOG(ASFVOLT_ERROR, "failed to Initialize the BAL\n");
236 return err;
237 }
238#endif
239
240 /* Register the call back functions to handle any
241 * indications from the BAL */
242 bcmbal_cb_cfg cb_cfg = {};
243 uint16_t ind_subgroup;
244
245 cb_cfg.module = BCMOS_MODULE_ID_NONE;
246 /* Register to get indications for access terminal objects
247 */
248 cb_cfg.obj_type = BCMBAL_OBJ_ID_ACCESS_TERMINAL;
249
250 /* Access Terminal Indication */
251 cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_acc_term_indication_cb;
252 ind_subgroup = bcmbal_access_terminal_auto_id_ind;
253 cb_cfg.p_subgroup = &ind_subgroup;
254 err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
255
256 if (err)
257 {
258 ASFVOLT_LOG(ASFVOLT_ERROR, "failed to register call back functions to BAL\n");
259 }
260
261 return err;
262}
263
264/********************************************************************\
265 * Function : asfvolt16_bal_finish *
266 * Description : This function will Un-initialize the BAL module *
267 ********************************************************************/
268uint32_t asfvolt16_bal_finish(void)
269{
270 bcmos_errno err = BCM_ERR_OK;
271
272 /* Un-Initialize the BAL function */
273 bcmbal_apiend_finish();
274
275 return err;
276}
277
278
279/********************************************************************\
280 * Function : asfvolt16_bal_cfg_set *
281 * Description : Handles below configuration *
282 * 1) Access Terminal Cfg *
283 * 2) Interface(PON & NNI) Cfg *
284 * 3) Subscriber Terminal (ONU) cfg *
285 * 4) Flow Cfg *
286 * 5) Group Cfg (In case of Multicast) *
287 ********************************************************************/
288uint32_t asfvolt16_bal_cfg_set(BalCfg *cfg)
289{
290 bcmos_errno err = BCM_ERR_OK;
291 memset(&voltha_device_id, 0, ASFVOLT_MAX_DEVICE_ID_SIZE);
292 strcpy(voltha_device_id,cfg->device_id);
293
294 switch(cfg->hdr->obj_type)
295 {
296 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
297 {
298 err = bal_access_terminal_cfg_set(cfg->cfg);
299 break;
300 }
301 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
302 {
303 err = bal_interface_cfg_set(cfg->interface);
304 break;
305 }
306 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
307 {
308 err = bal_subscriber_terminal_cfg_set(cfg->terminal);
309 break;
310 }
311 case BAL_OBJ_ID__BAL_OBJ_ID_FLOW:
312 {
313 err = bal_flow_cfg_set(cfg->flow);
314 break;
315 }
316 case BAL_OBJ_ID__BAL_OBJ_ID_GROUP:
317 {
318 err = bal_group_cfg_set(cfg->group);
319 break;
320 }
321 case BAL_OBJ_ID__BAL_OBJ_ID_TM_QUEUE:
322 {
323 err = bal_tm_queue_cfg_set(cfg->tm_queue_cfg);
324 break;
325 }
326 case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
327 {
328 err = bal_tm_sched_cfg_set(cfg->tm_sched_cfg);
329 break;
330 }
331 case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
332 {
333 err = bal_packet_cfg_req(cfg->packet);
334 break;
335 }
336 default:
337 {
338 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid objet type for configuration\n");
339 err = BAL_ERRNO__BAL_ERR_INVALID_OP;
340 break;
341 }
342 }
343 return err;
344}
345
346/********************************************************************\
347 * Function : asfvolt16_bal_cfg_clear *
348 * Description : Clears the configuration related to below objects *
349 * 1) Access Terminal Cfg *
350 * 2) Interface(PON & NNI) Cfg *
351 * 3) Subscriber Terminal (ONU) cfg *
352 * 4) Flow Cfg *
353 * 5) Group Cfg (In case of Multicast) *
354 ********************************************************************/
355uint32_t asfvolt16_bal_cfg_clear(BalKey *key)
356{
357 bcmos_errno err = BCM_ERR_OK;
358
359 if(!key->hdr->has_obj_type)
360 {
361 ASFVOLT_LOG(ASFVOLT_ERROR, "object type is not present for clear\n");
362 return BAL_ERRNO__BAL_ERR_INVALID_OP;
363 }
364
365 switch(key->hdr->obj_type)
366 {
367 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
368 {
369 err = bal_access_terminal_cfg_clear(key->access_term_key);
370 break;
371 }
372 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
373 {
374 err = bal_interface_cfg_clear(key->interface_key);
375 break;
376 }
377 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
378 {
379 err = bal_subscriber_terminal_cfg_clear(key->terminal_key);
380 break;
381 }
382 case BAL_OBJ_ID__BAL_OBJ_ID_FLOW:
383 {
384 err = bal_flow_cfg_clear(key->flow_key);
385 break;
386 }
387 case BAL_OBJ_ID__BAL_OBJ_ID_GROUP:
388 {
389 break;
390 }
391 case BAL_OBJ_ID__BAL_OBJ_ID_TM_QUEUE:
392 {
393 err = bal_tm_queue_cfg_clear(key->tm_queue_key);
394 break;
395 }
396 case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
397 {
398 err = bal_tm_sched_cfg_clear(key->tm_sched_key);
399 break;
400 }
401 /*case BAL_KEY__OBJ_PACKET_KEY:
402 {
403 break;
404 }*/
405 default:
406 {
407 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid objet type to handle clear\n");
408 err = BAL_ERRNO__BAL_ERR_INVALID_OP;
409 break;
410 }
411 }
412 return err;
413}
414
415
416/********************************************************************\
417 * Function : asfvolt16_bal_cfg_get *
418 * Description : Get the configuration related to below objects *
419 * 1) Access Terminal Cfg *
420 * 2) Interface(PON & NNI) Cfg *
421 * 3) Subscriber Terminal (ONU) cfg *
422 * 4) Flow Cfg *
423 * 5) Group Cfg (In case of Multicast) *
424 ********************************************************************/
425uint32_t asfvolt16_bal_cfg_get(BalKey *key, BalCfg *cfg)
426{
427 bcmos_errno err = BCM_ERR_OK;
428
429 if(!key->hdr->has_obj_type)
430 {
431 ASFVOLT_LOG(ASFVOLT_ERROR, "object type is not present for get\n");
432 return BAL_ERRNO__BAL_ERR_INVALID_OP;
433 }
434
435 switch(key->hdr->obj_type)
436 {
437 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
438 {
439 err = bal_access_terminal_cfg_get(key->access_term_key, cfg->cfg );
440 break;
441 }
442 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
443 {
444 err = bal_interface_cfg_get(key->interface_key, cfg->interface);
445 break;
446 }
447 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
448 {
449 err = bal_subscriber_terminal_cfg_get(key->terminal_key, cfg->terminal);
450 break;
451 }
452 case BAL_OBJ_ID__BAL_OBJ_ID_FLOW:
453 {
454 err = bal_flow_cfg_get(key->flow_key, cfg->flow);
455 break;
456 }
457 case BAL_OBJ_ID__BAL_OBJ_ID_GROUP:
458 {
459 err = bal_group_cfg_get(key->group_key, cfg->group);
460 break;
461 }
462 case BAL_OBJ_ID__BAL_OBJ_ID_TM_QUEUE:
463 {
464 err = bal_tm_queue_cfg_get(key->tm_queue_key, cfg->tm_queue_cfg);
465 break;
466 }
467 case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
468 {
469 err = bal_tm_sched_cfg_get(key->tm_sched_key, cfg->tm_sched_cfg);
470 break;
471 }
472 case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
473 {
474 break;
475 }
476 default:
477 {
478 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid objet type to handle Get\n");
479 err = BAL_ERRNO__BAL_ERR_INVALID_OP;
480 break;
481 }
482 }
483 return err;
484}
485
486