blob: 12b7fcf014a903f43d06a9e259910a9481af5186 [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*/
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053016#include <signal.h>
17#include <stdio.h>
root85905d12018-03-21 16:18:51 +053018#include <string.h>
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053019#include <unistd.h>
root5be94e52018-02-15 22:30:14 +053020#include <string.h>
21#include <stdlib.h>
Girish Gowdru9ebd8b22018-09-26 03:21:03 -070022#include <stdbool.h>
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053023#include <sys/time.h>
24#include "bal_msg_type.grpc-c.h"
25#include "bal_osmsg.grpc-c.h"
26#include "bal_model_ids.grpc-c.h"
27#include "bal_obj.grpc-c.h"
28#include "bal_model_types.grpc-c.h"
29#include "bal_errno.grpc-c.h"
30#include "bal.grpc-c.h"
root5be94e52018-02-15 22:30:14 +053031#include "asfvolt.grpc-c.h"
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053032
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053033#include "asfvolt16_driver.h"
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053034
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053035#include <sys/reboot.h>
VoLTHA753536e2017-11-02 20:15:09 +053036#include "bal_indications_queue.h"
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053037
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053038/* Global varibles */
39balCoreIpInfo coreIpPortInfo;
40
VoLTHA753536e2017-11-02 20:15:09 +053041/* extern variables*/
42list_node *bal_ind_queue_tail = NULL;
43list_node *bal_ind_queue_head = NULL;
44pthread_mutex_t bal_ind_queue_lock;
45unsigned int num_of_nodes = 0;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053046
VoLTHA753536e2017-11-02 20:15:09 +053047/* static variables*/
48static grpc_c_server_t *test_server;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053049static void sigint_handler (int x) {
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053050 grpc_c_server_destroy(test_server);
51 exit(0);
52}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -070053static bool is_init_done = false;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053054
root5be94e52018-02-15 22:30:14 +053055/*MACRO Definitions*/
root85905d12018-03-21 16:18:51 +053056#define ASFVOLT_FIELD_LEN 200
root5be94e52018-02-15 22:30:14 +053057
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053058void is_grpc_write_pending(int return_value)
59{
60 if (return_value != GRPC_C_WRITE_OK)
61 {
62 if(return_value == GRPC_C_WRITE_PENDING)
63 {
64 /* TODO: Register call back with grpc-c which will give an indication whenever write was succussful */
Kim Kempfafa1ab42017-11-13 09:31:47 -080065 ASFVOLT_LOG(ASFVOLT_INFO, "write(%d) is pending, sleep for 5 sec", return_value);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053066 sleep(5);
67 }
68 else
69 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080070 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write %d", return_value);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053071 }
72 }
73
74}
75
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053076/*
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053077 * This functions gets invoked whenever bal Heartbeat RPC gets called
78 */
79void bal__bal_api_heartbeat_cb(grpc_c_context_t *context)
80{
81 BalHeartbeat *bal_hb;
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053082 BalRebootState bal_reboot;
Rajeswara Raob2e441c2017-09-20 16:40:21 +053083 int ret_val;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053084 /*
85 * Read incoming message into set_cfg
86 */
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053087 if (context->gcc_payload) {
88 context->gcc_stream->read(context, (void **)&bal_hb, 0);
89 }
90
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053091 bal_reboot_state__init(&bal_reboot);
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053092
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053093 bal_reboot.has_is_reboot = 1;
Rajeswara Rao9f1cea12017-10-10 18:25:29 +053094 bal_reboot.is_reboot = is_reboot;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +053095
96 /*
97 * Write reply back to the client
98 */
root2ca2cc02017-11-03 19:51:57 +053099 ret_val = context->gcc_stream->write(context, &bal_reboot, -1);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530100 is_grpc_write_pending(ret_val);
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530101
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530102 grpc_c_status_t status;
103 status.gcs_code = 0;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530104
105 /*
106 * Finish response for RPC
107 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530108 if (context->gcc_stream->finish(context, &status))
109 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800110 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530111 }
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530112}
113
114/*
115 * This functions gets invoked whenever Bal reboot gets called
116 */
117void bal__bal_api_reboot_cb(grpc_c_context_t *context)
118{
119 BalReboot *read_device;
120 BalErr bal_err;
Rajeswara Raob2e441c2017-09-20 16:40:21 +0530121 int ret_val;
122
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530123 /*
124 * Read incoming message into get_cfg
125 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530126 if (context->gcc_payload)
127 {
128 context->gcc_stream->read(context, (void **)&read_device, 0);
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700129 ASFVOLT_LOG(ASFVOLT_INFO, "Bal Server - Reboot : Device ID is %s",read_device->device_id);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530130 }
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530131
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530132
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530133 /*
134 * send it to BAL
135 */
136
137 bal_err__init(&bal_err);
138
139 bal_err.err= 0;
140
141 /*
142 * Write reply back to the client
143 */
root2ca2cc02017-11-03 19:51:57 +0530144 ret_val = context->gcc_stream->write(context, &bal_err, -1);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530145 is_grpc_write_pending(ret_val);
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530146
147 grpc_c_status_t status;
148 status.gcs_code = 0;
149
150 /*
151 * Finish response for RPC
152 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530153 if (context->gcc_stream->finish(context, &status))
154 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800155 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530156 }
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530157
VoLTHA753536e2017-11-02 20:15:09 +0530158 ret_val = system("shutdown -r now");
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530159 sleep(30); /* allow system to shutdown gracefully */
160 sync(); /* force shutdown if graceful did not work */
161 reboot(RB_AUTOBOOT);
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530162}
163
164/*
root5be94e52018-02-15 22:30:14 +0530165This function reads the specified field from the 'onldump -o' command.
166If the field was successfully read, it returns the field value.
167If it failed to read the field, then null charecter is returned
168*/
169char* asfvolt_read_sysinfo(char* field_name, char* field_val)
170{
171 FILE *fp;
172 /* Prepare the command*/
173 char command[150];
174
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700175 snprintf(command, sizeof command, "bash -l -c \"onlpdump -s\" | perl -ne 'print $1 if /%s: (\\S+)/'", field_name);
root5be94e52018-02-15 22:30:14 +0530176 /* Open the command for reading. */
177 fp = popen(command, "r");
178 if (fp == NULL) {
179 /*The client has to check for a Null mac address in this case*/
180 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to query the mac address");
181 return field_val;
182 }
183
184 /*Read the field value*/
185 if (fp) {
186 fread(field_val, ASFVOLT_FIELD_LEN, 1, fp);
187 pclose(fp);
188 }
189 return field_val;
190}
191
192/*
193 * This functions gets invoked whenever AsfvoltGetSystemInfo RPC gets called
194 */
195void asfvolt__asfvolt_get_system_info_cb(grpc_c_context_t *context)
196{
197 BalDefault *dummy;
198 AsfSystemInfo asf_system_info;
199 char product_name[ASFVOLT_FIELD_LEN] = "\0";
200 char part_num[ASFVOLT_FIELD_LEN] = "\0";
201 char serial_num[ASFVOLT_FIELD_LEN] = "\0";
202 char mac_address[ASFVOLT_FIELD_LEN] = "\0";
203 char mac_range[ASFVOLT_FIELD_LEN] = "\0";
204 char manufacturer[ASFVOLT_FIELD_LEN] = "\0";
205 char manufacturer_date[ASFVOLT_FIELD_LEN] = "\0";
206 char vendor[ASFVOLT_FIELD_LEN] = "\0";
207 char platform_name[ASFVOLT_FIELD_LEN] = "\0";
208 char label_revision[ASFVOLT_FIELD_LEN] = "\0";
209 char coutry_code[ASFVOLT_FIELD_LEN] = "\0";
210 char diag_version[ASFVOLT_FIELD_LEN] = "\0";
211 char onie_version[ASFVOLT_FIELD_LEN] = "\0";
212 int ret_val;
213
214 if (context->gcc_payload) {
215 context->gcc_stream->read(context, (void **)&dummy, 0);
216 }
217
218 asf_system_info__init(&asf_system_info);
219
220 asf_system_info.product_name = asfvolt_read_sysinfo("Product Name", product_name);
221 asf_system_info.part_num = asfvolt_read_sysinfo("Part Number", part_num);
222 asf_system_info.serial_num = asfvolt_read_sysinfo("Serial Number", serial_num);
223 asf_system_info.mac_address = asfvolt_read_sysinfo("MAC", mac_address);
224 asf_system_info.mac_range = asfvolt_read_sysinfo("MAC Range", mac_range);
225 asf_system_info.manufacturer = asfvolt_read_sysinfo("Manufacturer", manufacturer);
226 asf_system_info.manufacture_date = asfvolt_read_sysinfo("Manufacture Date", manufacturer_date);
227 asf_system_info.vendor = asfvolt_read_sysinfo("Vendor", vendor);
228 asf_system_info.platform_name = asfvolt_read_sysinfo("Platform Name", platform_name);
229 asf_system_info.label_revision = asfvolt_read_sysinfo("Label Revision", label_revision);
230 asf_system_info.country_code = asfvolt_read_sysinfo("Country Code", coutry_code);
231 asf_system_info.diag_version = asfvolt_read_sysinfo("Diag Version", diag_version);
232 asf_system_info.onie_version = asfvolt_read_sysinfo("ONIE Version", onie_version);
233
234 /*
235 * Write reply back to the client
236 */
237 ret_val = context->gcc_stream->write(context, &asf_system_info, -1);
238 is_grpc_write_pending(ret_val);
239
240 grpc_c_status_t status;
241 status.gcs_code = 0;
242
243 /*
244 * Finish response for RPC
245 */
246 if (context->gcc_stream->finish(context, &status))
247 {
248 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
249 }
250}
251
252/*
root85905d12018-03-21 16:18:51 +0530253This function reads the SFP presence map information from 'onlpdump -p' system command
254and returns a bitmap with the presence information.
255*/
256unsigned int asfvolt_read_sfp_presence_bitmap(void)
257{
258 char command[150];
259 char sfp_presence_output[ASFVOLT_FIELD_LEN];
260 unsigned int sfp_presence_bitmap = 0;
261 char delim[2] = " ";
262 char *field = NULL;
263 FILE *fp;
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700264 snprintf(command, sizeof command, "bash -l -c \"onlpdump -p\" | perl -ne 'print $1 if /Presence: ([0-9 ]+)/'");
root85905d12018-03-21 16:18:51 +0530265 /* Open the command for reading. */
266 fp = popen(command, "r");
267 if (fp == NULL) {
268 /*The client has to check for a Null mac address in this case*/
269 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to query the sfp presence map");
270 return sfp_presence_bitmap;
271 }
272
273 /*Read the field value*/
274 fread(sfp_presence_output, ASFVOLT_FIELD_LEN, 1, fp);
275 pclose(fp);
276
277 field = strtok(sfp_presence_output, delim);
278 while (field != NULL) {
279 sfp_presence_bitmap |= (1 << atoi(field));
280 field = strtok(NULL, delim);
281 }
282
283 return sfp_presence_bitmap;
284}
285
286/*
287 * This functions gets invoked whenever AsfvoltGetSfpPresenceBitmap RPC gets called
288 */
289void asfvolt__asfvolt_get_sfp_presence_bitmap_cb(grpc_c_context_t *context)
290{
291 BalDefault *dummy;
292 AsfSfpPresenceBitmap sfp_presence_bitmap;
293 int ret_val;
294
295 if (context->gcc_payload) {
296 context->gcc_stream->read(context, (void **)&dummy, 0);
297 }
298
299 asf_sfp_presence_bitmap__init(&sfp_presence_bitmap);
300
301 sfp_presence_bitmap.bitmap = asfvolt_read_sfp_presence_bitmap();
302 sfp_presence_bitmap.has_bitmap = true;
303
304 /*
305 * Write reply back to the client
306 */
307 ret_val = context->gcc_stream->write(context, &sfp_presence_bitmap, -1);
308 is_grpc_write_pending(ret_val);
309
310 grpc_c_status_t status;
311 status.gcs_code = 0;
312
313 /*
314 * Finish response for RPC
315 */
316 if (context->gcc_stream->finish(context, &status))
317 {
318 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
319 }
320}
321
322/*
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530323 * This functions gets invoked whenever Bal Stats gets called
324 */
325void bal__bal_cfg_stat_get_cb(grpc_c_context_t *context)
326{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700327 BalInterfaceKey *read_stats = 0;
Rajeswara Raob2e441c2017-09-20 16:40:21 +0530328 int ret_val;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530329
330 /*
331 * Read incoming message into get_cfg
332 */
333 if (context->gcc_payload) {
334 context->gcc_stream->read(context, (void **)&read_stats, 0);
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700335 ASFVOLT_LOG(ASFVOLT_DEBUG, "Bal Server - Get Stats :NNI port is %d",read_stats->intf_id);
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530336 }
337
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530338
339 BalInterfaceStat get_stats;
340 memset(&get_stats, 0, sizeof(BalInterfaceStat));
341 bal_interface_stat__init(&get_stats);
342
343 BalInterfaceStatData stat_data;
344 memset(&stat_data, 0, sizeof(BalInterfaceStatData));
345 bal_interface_stat_data__init(&stat_data);
346
Rajeswara Rao92e3fd42017-10-26 10:47:03 +0530347 BalInterfaceKey stat_key;
348 memset(&stat_key, 0, sizeof(BalInterfaceKey));
349 bal_interface_key__init(&stat_key);
350
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530351 /* Interface Type, Interface ID
352 stat_data - Statistics Data */
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700353 if ((read_stats) && (is_init_done == true)) {
354 asfvolt16_bal_stats_get(read_stats->intf_type, read_stats->intf_id, &stat_data, &stat_key);
355 }
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530356
357 get_stats.data = &stat_data;
Rajeswara Rao92e3fd42017-10-26 10:47:03 +0530358 get_stats.key = &stat_key;
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530359
root2ca2cc02017-11-03 19:51:57 +0530360 ret_val = context->gcc_stream->write(context, &get_stats, -1);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530361 is_grpc_write_pending(ret_val);
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530362
363 grpc_c_status_t status;
364 status.gcs_code = 0;
365
366 /*
367 * Finish response for RPC
368 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530369 if (context->gcc_stream->finish(context, &status))
370 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800371 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530372 }
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530373}
374
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700375void bal_cfg_get__free_mem_sub_term_cfg_get(BalCfg *balCfgRsp)
376{
377 free(balCfgRsp->terminal->data->password);
378 free(balCfgRsp->terminal->data->registration_id);
379 free(balCfgRsp->terminal->data->serial_number->vendor_id);
380 free(balCfgRsp->terminal->data->serial_number->vendor_specific);
381 free(balCfgRsp->terminal->data->serial_number);
382}
383
384void bal_cfg_get__free_mem(BalCfg *balCfgRsp)
385{
386 switch (balCfgRsp->hdr->obj_type)
387 {
388 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
389 break;
390
391 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
392 break;
393
394 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
395 bal_cfg_get__free_mem_sub_term_cfg_get(balCfgRsp);
396 break;
397
398 default:
399 break;
400 }
401}
402
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530403/*
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530404 * This functions gets invoked whenever bal RPC gets called
405 */
406void bal__bal_cfg_get_cb(grpc_c_context_t *context)
407{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700408 BalKey *bal_key = 0;
409 int ret_val;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530410
411 /*
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700412 * Read incoming message into bal_key
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530413 */
414 if (context->gcc_payload) {
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700415 context->gcc_stream->read(context, (void **)&bal_key, 0);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530416 }
417
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700418 /*
419 * send it to BAL
420 */
421 BalCfg get_cfg_resp;
422 memset(&get_cfg_resp, 0, sizeof(BalCfg));
423 bal_cfg__init(&get_cfg_resp);
424
425 BalObj hdr_cfg;
426 memset(&hdr_cfg, 0, sizeof(BalObj));
427 bal_obj__init(&hdr_cfg);
428 get_cfg_resp.hdr = &hdr_cfg;
429
430 BalCommMsgHdr comm_hdr;
431 memset(&comm_hdr, 0, sizeof(BalCommMsgHdr));
432 bal_comm_msg_hdr__init(&comm_hdr);
433 get_cfg_resp.hdr->comm_hdr = &comm_hdr;
434
435 if (bal_key) {
436 switch(bal_key->hdr->obj_type)
437 {
438 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
439 {
440 ASFVOLT_LOG(ASFVOLT_ERROR, "Bal Get For Access Terminal Received\n");
441
442 get_cfg_resp.obj_case = BAL_CFG__OBJ_CFG;
443
444 get_cfg_resp.hdr->obj_type = BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL;
445
446 BalAccessTerminalCfg access_term_cfg;
447 memset(&access_term_cfg, 0, sizeof(BalAccessTerminalCfg));
448 bal_access_terminal_cfg__init(&access_term_cfg);
449 get_cfg_resp.cfg = &access_term_cfg;
450
451 BalAccessTerminalCfgData access_term_cfg_data;
452 memset(&access_term_cfg_data, 0, sizeof(BalAccessTerminalCfgData));
453 bal_access_terminal_cfg_data__init(&access_term_cfg_data);
454 get_cfg_resp.cfg->data = &access_term_cfg_data;
455
456 BalTopology access_term_cfg_data_topology;
457 memset(&access_term_cfg_data_topology, 0, sizeof(BalTopology));
458 bal_topology__init(&access_term_cfg_data_topology);
459 get_cfg_resp.cfg->data->topology = &access_term_cfg_data_topology;
460
461 BalSwVersion access_term_cfg_data_sw_version;
462 memset(&access_term_cfg_data_sw_version, 0, sizeof(BalSwVersion));
463 bal_sw_version__init(&access_term_cfg_data_sw_version);
464 get_cfg_resp.cfg->data->sw_version = &access_term_cfg_data_sw_version;
465
466 BalAccessTerminalKey access_term_key;
467 memset(&access_term_key, 0, sizeof(BalAccessTerminalKey));
468 bal_access_terminal_key__init(&access_term_key);
469 get_cfg_resp.cfg->key = &access_term_key;
470
471 if (is_init_done == true) {
472 asfvolt16_bal_cfg_get(&get_cfg_resp);
473 }
474 }
475 break;
476
477 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
478 {
479 BalInterfaceCfg intf_cfg;
480 memset(&intf_cfg, 0, sizeof(BalInterfaceCfg));
481 bal_interface_cfg__init(&intf_cfg);
482 get_cfg_resp.interface = &intf_cfg;
483
484 BalInterfaceCfgData intf_cfg_data;
485 memset(&intf_cfg_data, 0, sizeof(BalInterfaceCfgData));
486 bal_interface_cfg_data__init(&intf_cfg_data);
487 get_cfg_resp.interface->data = &intf_cfg_data;
488
489 BalInterfaceKey intf_key;
490 memset(&intf_key, 0, sizeof(BalInterfaceKey));
491 bal_interface_key__init(&intf_key);
492 get_cfg_resp.interface->key = &intf_key;
493
494 if (is_init_done == true) {
495 asfvolt16_bal_cfg_get(&get_cfg_resp);
496 }
497 }
498 break;
499
500 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
501 {
502 ASFVOLT_LOG(ASFVOLT_ERROR, "Bal Get For Subscriber Terminal Received\n");
503
504 get_cfg_resp.obj_case = BAL_CFG__OBJ_TERMINAL;
505
506 get_cfg_resp.hdr->obj_type = BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL;
507
508 BalSubscriberTerminalCfg sub_term_cfg;
509 memset(&sub_term_cfg, 0, sizeof(BalSubscriberTerminalCfg));
510 bal_subscriber_terminal_cfg__init(&sub_term_cfg);
511 get_cfg_resp.terminal = &sub_term_cfg;
512
513 BalSubscriberTerminalCfgData sub_term_cfg_data;
514 memset(&sub_term_cfg_data, 0, sizeof(BalSubscriberTerminalCfgData));
515 bal_subscriber_terminal_cfg_data__init(&sub_term_cfg_data);
516 get_cfg_resp.terminal->data = &sub_term_cfg_data;
517
518 BalSerialNumber serial_number;
519 memset(&serial_number, 0, sizeof(BalSerialNumber));
520 bal_serial_number__init(&serial_number);
521 get_cfg_resp.terminal->data->serial_number = &serial_number;
522
523 BalSubscriberTerminalKey sub_term_key;
524 memset(&sub_term_key, 0, sizeof(BalSubscriberTerminalKey));
525 bal_subscriber_terminal_key__init(&sub_term_key);
526 get_cfg_resp.terminal->key = &sub_term_key;
527
528 get_cfg_resp.terminal->key->has_sub_term_id = true;
529 get_cfg_resp.terminal->key->sub_term_id = bal_key->terminal_key->sub_term_id;
530
531 get_cfg_resp.terminal->key->has_intf_id = true;
532 get_cfg_resp.terminal->key->intf_id = bal_key->terminal_key->intf_id;
533
534 if (is_init_done == true) {
535 asfvolt16_bal_cfg_get(&get_cfg_resp);
536 }
537 }
538 break;
539 default:
540 {
541 ASFVOLT_LOG(ASFVOLT_ERROR, "Bal Get not implemented for %d object type", bal_key->hdr->obj_type);
542 }
543 break;
544 }
545 }
546
547 /*
548 * Write reply back to the client
549 */
550 ret_val = context->gcc_stream->write(context, &get_cfg_resp, -1);
551 is_grpc_write_pending(ret_val);
552
553 grpc_c_status_t status;
554 status.gcs_code = 0;
555
556 /*
557 * Finish response for RPC
558 */
559 if (context->gcc_stream->finish(context, &status))
560 {
561 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
562 }
563 bal_cfg_get__free_mem(&get_cfg_resp);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530564}
565
566/*
567 * This functions gets invoked whenever bal RPC gets called
568 */
569void bal__bal_cfg_set_cb(grpc_c_context_t *context)
570{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700571 BalCfg *set_cfg = 0;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530572 BalErr bal_err;
573 int ret_val = 0;
574
575 /*
576 * Read incoming message into set_cfg
577 */
578 if (context->gcc_payload) {
579 context->gcc_stream->read(context, (void **)&set_cfg, 0);
580 }
581
582 /*
583 * send it to BAL
584 */
585
586 bal_err__init(&bal_err);
587
588 bal_err.err= 0;
589
590 /*
591 * Write reply back to the client
592 */
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530593
root2ca2cc02017-11-03 19:51:57 +0530594 ret_val = context->gcc_stream->write(context, &bal_err, -1);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530595 is_grpc_write_pending(ret_val);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530596
597 grpc_c_status_t status;
598 status.gcs_code = 0;
599
600 /*
601 * Finish response for RPC
602 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530603 if (context->gcc_stream->finish(context, &status))
604 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800605 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530606 }
607
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700608 if (set_cfg) {
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530609
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700610 if(BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL == set_cfg->hdr->obj_type)
611 {
612 sleep(5); /* enable this if running with gdb */
613 }
614
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530615
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700616 asfvolt16_bal_cfg_set(set_cfg);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530617 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530618}
619
620
621/*
622 * This functions gets invoked whenever bal clear RPC gets called
623 */
624void bal__bal_cfg_clear_cb(grpc_c_context_t *context)
625{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700626 BalKey *clear_key = 0;
Girish Gowdru50278de2017-11-23 12:35:41 +0530627 BalErr bal_err;
628 int ret_val = 0;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530629
630 /*
Rajeswara Raoa3efbca2017-09-08 18:01:16 +0530631 * Read incoming message into clear_key
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530632 */
633 if (context->gcc_payload) {
634 context->gcc_stream->read(context, (void **)&clear_key, 0);
635 }
636
Girish Gowdru50278de2017-11-23 12:35:41 +0530637 /*
638 * send it to BAL
639 */
640
641 bal_err__init(&bal_err);
642
643 bal_err.err= 0;
644
645 /*
646 * Write reply back to the client
647 */
648
649 ret_val = context->gcc_stream->write(context, &bal_err, 0);
650 is_grpc_write_pending(ret_val);
651
652 grpc_c_status_t status;
653 status.gcs_code = 0;
654
655 /*
656 * Finish response for RPC
657 */
658 if (context->gcc_stream->finish(context, &status))
659 {
660 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
661 }
662
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700663 if (clear_key) {
664 asfvolt16_bal_cfg_clear(clear_key);
665 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530666}
667
668
669/*
670 * This functions gets invoked whenever bal Init RPC gets called
671 */
672void bal__bal_api_init_cb(grpc_c_context_t *context)
673{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700674 BalInit *bal_init = 0;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530675 BalErr bal_err;
676 int ret_val;
677
678 /*
679 * Read incoming message into set_cfg
680 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530681 if (context->gcc_payload)
682 {
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530683 context->gcc_stream->read(context, (void **)&bal_init, 0);
684 }
685
686 /*
687 * send it to BAL
688 */
689
Kim Kempfafa1ab42017-11-13 09:31:47 -0800690 ASFVOLT_LOG(ASFVOLT_INFO, "Received API Init msg");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530691
692 bal_err__init(&bal_err);
693
694 bal_err.err= 0;
695
696 /*
697 * Write reply back to the client
698 */
root2ca2cc02017-11-03 19:51:57 +0530699 ret_val = context->gcc_stream->write(context, &bal_err, -1);
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530700 is_grpc_write_pending(ret_val);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530701
702 grpc_c_status_t status;
703 status.gcs_code = 0;
704
705 /*
706 * Finish response for RPC
707 */
Rajeswara Rao9f1cea12017-10-10 18:25:29 +0530708 if (context->gcc_stream->finish(context, &status))
709 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800710 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530711 }
712
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700713 if (bal_init) {
714 asfvolt16_bal_init(bal_init, &coreIpPortInfo);
715 }
716 is_init_done = true;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530717}
718
VoLTHA753536e2017-11-02 20:15:09 +0530719
720void bal_get_ind__free_mem_access_term_ind_op_state(BalIndications *balIndCfg)
721{
722 free(balIndCfg->access_term_ind_op_state->data);
723 free(balIndCfg->access_term_ind_op_state->key);
VoLTHA753536e2017-11-02 20:15:09 +0530724 free(balIndCfg->access_term_ind_op_state);
725 free(balIndCfg);
726}
727
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700728void bal_get_ind__free_mem_access_term_proc_err(BalIndications *balIndCfg)
729{
730 free(balIndCfg->access_term_proc_err->key);
731 free(balIndCfg->access_term_proc_err);
732 free(balIndCfg);
733}
734
VoLTHA753536e2017-11-02 20:15:09 +0530735void bal_get_ind__free_mem_flow_op_state(BalIndications *balIndCfg)
736{
737 free(balIndCfg->flow_op_state->data);
738 free(balIndCfg->flow_op_state->key);
VoLTHA753536e2017-11-02 20:15:09 +0530739 free(balIndCfg->flow_op_state);
740 free(balIndCfg);
741}
742
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700743void bal_get_ind__free_mem_flow_proc_err(BalIndications *balIndCfg)
VoLTHA753536e2017-11-02 20:15:09 +0530744{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700745 free(balIndCfg->flow_proc_err->key);
746 free(balIndCfg->flow_proc_err);
VoLTHA753536e2017-11-02 20:15:09 +0530747 free(balIndCfg);
748}
749
750void bal_get_ind__free_mem_interface_op_state(BalIndications *balIndCfg)
751{
752 free(balIndCfg->interface_op_state->data);
753 free(balIndCfg->interface_op_state->key);
VoLTHA753536e2017-11-02 20:15:09 +0530754 free(balIndCfg->interface_op_state);
755 free(balIndCfg);
756}
757
758void bal_get_ind__free_mem_interface_los(BalIndications *balIndCfg)
759{
760 free(balIndCfg->interface_los->data);
root2ca2cc02017-11-03 19:51:57 +0530761 free(balIndCfg->interface_los);
VoLTHA753536e2017-11-02 20:15:09 +0530762 free(balIndCfg);
763}
764
VoLTHA753536e2017-11-02 20:15:09 +0530765void bal_get_ind__free_mem_terminal_op_state(BalIndications *balIndCfg)
766{
767 free(balIndCfg->terminal_op_state->data);
768 free(balIndCfg->terminal_op_state->key);
VoLTHA753536e2017-11-02 20:15:09 +0530769 free(balIndCfg->terminal_op_state);
770 free(balIndCfg);
771}
772
773void bal_get_ind__free_mem_terminal_disc(BalIndications *balIndCfg)
774{
775 free(balIndCfg->terminal_disc->data->serial_number->vendor_specific);
776 free(balIndCfg->terminal_disc->data->serial_number->vendor_id);
777 free(balIndCfg->terminal_disc->data->serial_number);
778 free(balIndCfg->terminal_disc->data);
779 free(balIndCfg->terminal_disc->key);
VoLTHA753536e2017-11-02 20:15:09 +0530780 free(balIndCfg->terminal_disc);
781 free(balIndCfg);
782}
783
784void bal_get_ind__free_mem_terminal_alarm(BalIndications *balIndCfg)
785{
786 free(balIndCfg->terminal_alarm->data->alarm);
787 free(balIndCfg->terminal_alarm->data);
788 free(balIndCfg->terminal_alarm->key);
VoLTHA753536e2017-11-02 20:15:09 +0530789 free(balIndCfg->terminal_alarm);
790 free(balIndCfg);
791}
792
793void bal_get_ind__free_mem_terminal_dgi(BalIndications *balIndCfg)
794{
795 free(balIndCfg->terminal_dgi->data);
796 free(balIndCfg->terminal_dgi->key);
VoLTHA753536e2017-11-02 20:15:09 +0530797 free(balIndCfg->terminal_dgi);
798 free(balIndCfg);
799}
800
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700801void bal_get_ind__free_mem_terminal_dowi(BalIndications *balIndCfg)
VoLTHA753536e2017-11-02 20:15:09 +0530802{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700803 free(balIndCfg->terminal_dowi->data);
804 free(balIndCfg->terminal_dowi->key);
805 free(balIndCfg->terminal_dowi);
VoLTHA753536e2017-11-02 20:15:09 +0530806 free(balIndCfg);
807}
808
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700809void bal_get_ind__free_mem_terminal_looci(BalIndications *balIndCfg)
VoLTHA753536e2017-11-02 20:15:09 +0530810{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700811 free(balIndCfg->terminal_looci->data);
812 free(balIndCfg->terminal_looci->key);
813 free(balIndCfg->terminal_looci);
VoLTHA753536e2017-11-02 20:15:09 +0530814 free(balIndCfg);
815}
816
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700817void bal_get_ind__free_mem_terminal_proc_err(BalIndications *balIndCfg)
VoLTHA753536e2017-11-02 20:15:09 +0530818{
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700819 free(balIndCfg->terminal_proc_err->key);
820 free(balIndCfg->terminal_proc_err);
821 free(balIndCfg);
822}
823
824void bal_get_ind__free_mem_terminal_sdi(BalIndications *balIndCfg)
825{
826 free(balIndCfg->terminal_sdi->data);
827 free(balIndCfg->terminal_sdi->key);
828 free(balIndCfg->terminal_sdi);
829 free(balIndCfg);
830}
831
832void bal_get_ind__free_mem_terminal_sfi(BalIndications *balIndCfg)
833{
834 free(balIndCfg->terminal_sfi->data);
835 free(balIndCfg->terminal_sfi->key);
836 free(balIndCfg->terminal_sfi);
837 free(balIndCfg);
838}
839
840void bal_get_ind__free_mem_terminal_sufi(BalIndications *balIndCfg)
841{
842 free(balIndCfg->terminal_sufi->data);
843 free(balIndCfg->terminal_sufi->key);
844 free(balIndCfg->terminal_sufi);
845 free(balIndCfg);
846}
847
848void bal_get_ind__free_mem_terminal_sub_term_act_fail(BalIndications *balIndCfg)
849{
850 free(balIndCfg->terminal_sub_term_act_fail->data);
851 free(balIndCfg->terminal_sub_term_act_fail->key);
852 free(balIndCfg->terminal_sub_term_act_fail);
853 free(balIndCfg);
854}
855
856void bal_get_ind__free_mem_terminal_tiwi(BalIndications *balIndCfg)
857{
858 free(balIndCfg->terminal_tiwi->data);
859 free(balIndCfg->terminal_tiwi->key);
860 free(balIndCfg->terminal_tiwi);
861 free(balIndCfg);
862}
863
864void bal_get_ind__free_mem_tm_sched_osc(BalIndications *balIndCfg)
865{
866 free(balIndCfg->tm_sched_oper_stats_change->data);
867 free(balIndCfg->tm_sched_oper_stats_change->key);
868 free(balIndCfg->tm_sched_oper_stats_change);
VoLTHA753536e2017-11-02 20:15:09 +0530869 free(balIndCfg);
870}
871
872void bal_get_ind__free_mem_u_pkt_data(BalIndications *balIndCfg)
873{
874 free(balIndCfg->pktdata->data->pkt.data);
875 free(balIndCfg->pktdata->data);
876 switch(balIndCfg->pktdata->key->packet_send_dest->type)
877 {
878 case BAL_DEST_TYPE__BAL_DEST_TYPE_NNI:
879 free(balIndCfg->pktdata->key->packet_send_dest->nni);
880 break;
881 case BAL_DEST_TYPE__BAL_DEST_TYPE_SUB_TERM:
882 free(balIndCfg->pktdata->key->packet_send_dest->sub_term);
883 break;
884 case BAL_DEST_TYPE__BAL_DEST_TYPE_SVC_PORT:
885 free(balIndCfg->pktdata->key->packet_send_dest->svc_port);
886 break;
887 default:
888 /*Nothing to do*/
889 break;
890 }
891 free(balIndCfg->pktdata->key->packet_send_dest);
892 free(balIndCfg->pktdata->key);
VoLTHA753536e2017-11-02 20:15:09 +0530893 free(balIndCfg->pktdata);
894 free(balIndCfg);
895}
896
897void bal_get_ind__free_mem_u_bal_omci_resp(BalIndications *balIndCfg)
898{
899 switch(balIndCfg->balomciresp->key->packet_send_dest->type)
900 {
901 case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL:
902 free(balIndCfg->balomciresp->key->packet_send_dest->itu_omci_channel);
903 break;
904 default:
905 /*Nothing to do*/
906 break;
907 }
908 free(balIndCfg->balomciresp->key->packet_send_dest);
909 free(balIndCfg->balomciresp->data->pkt.data);
910 free(balIndCfg->balomciresp->data);
911 free(balIndCfg->balomciresp->key);
VoLTHA753536e2017-11-02 20:15:09 +0530912 free(balIndCfg->balomciresp);
913 free(balIndCfg);
914}
915
916void bal_get_ind__free_mem_u_bal_oam_resp(BalIndications *balIndCfg)
917{
918 free(balIndCfg->baloamresp->data->pkt.data);
919 free(balIndCfg->baloamresp->data);
920 switch(balIndCfg->baloamresp->key->packet_send_dest->type)
921 {
922 case BAL_DEST_TYPE__BAL_DEST_TYPE_IEEE_OAM_CHANNEL:
923 free(balIndCfg->baloamresp->key->packet_send_dest->ieee_oam_channel);
924 break;
925 default:
926 /*Nothing to do*/
927 break;
928 }
929 free(balIndCfg->baloamresp->key->packet_send_dest);
930 free(balIndCfg->baloamresp->key);
VoLTHA753536e2017-11-02 20:15:09 +0530931 free(balIndCfg->baloamresp);
932 free(balIndCfg);
933}
934
935void bal_get_ind__free_mem(BalIndications *balIndCfg)
936{
937 switch (balIndCfg->u_case)
938 {
VoLTHA753536e2017-11-02 20:15:09 +0530939 case BAL_INDICATIONS__U_ACCESS_TERM_IND_OP_STATE:
940 bal_get_ind__free_mem_access_term_ind_op_state(balIndCfg);
941 break;
942
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700943 case BAL_INDICATIONS__U_ACCESS_TERM_PROC_ERR:
944 bal_get_ind__free_mem_access_term_proc_err(balIndCfg);
945 break;
946
VoLTHA753536e2017-11-02 20:15:09 +0530947 case BAL_INDICATIONS__U_FLOW_OP_STATE:
948 bal_get_ind__free_mem_flow_op_state(balIndCfg);
949 break;
950
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700951 case BAL_INDICATIONS__U_FLOW_PROC_ERR:
952 bal_get_ind__free_mem_flow_proc_err(balIndCfg);
VoLTHA753536e2017-11-02 20:15:09 +0530953 break;
954
955 case BAL_INDICATIONS__U_INTERFACE_OP_STATE:
956 bal_get_ind__free_mem_interface_op_state(balIndCfg);
957 break;
958
959 case BAL_INDICATIONS__U_INTERFACE_LOS:
960 bal_get_ind__free_mem_interface_los(balIndCfg);
961 break;
962
VoLTHA753536e2017-11-02 20:15:09 +0530963 case BAL_INDICATIONS__U_TERMINAL_OP_STATE:
964 bal_get_ind__free_mem_terminal_op_state(balIndCfg);
965 break;
966
967 case BAL_INDICATIONS__U_TERMINAL_DISC:
968 bal_get_ind__free_mem_terminal_disc(balIndCfg);
969 break;
970
971 case BAL_INDICATIONS__U_TERMINAL_ALARM:
972 bal_get_ind__free_mem_terminal_alarm(balIndCfg);
973 break;
974
975 case BAL_INDICATIONS__U_TERMINAL_DGI:
976 bal_get_ind__free_mem_terminal_dgi(balIndCfg);
977 break;
978
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700979 case BAL_INDICATIONS__U_TERMINAL_DOWI:
980 bal_get_ind__free_mem_terminal_dowi(balIndCfg);
VoLTHA753536e2017-11-02 20:15:09 +0530981 break;
982
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700983 case BAL_INDICATIONS__U_TERMINAL_LOOCI:
984 bal_get_ind__free_mem_terminal_looci(balIndCfg);
VoLTHA753536e2017-11-02 20:15:09 +0530985 break;
986
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700987 case BAL_INDICATIONS__U_TERMINAL_PROC_ERR:
988 bal_get_ind__free_mem_terminal_proc_err(balIndCfg);
989 break;
990
991 case BAL_INDICATIONS__U_TERMINAL_SDI:
992 bal_get_ind__free_mem_terminal_sdi(balIndCfg);
993 break;
994
995 case BAL_INDICATIONS__U_TERMINAL_SFI:
996 bal_get_ind__free_mem_terminal_sfi(balIndCfg);
997 break;
998
999 case BAL_INDICATIONS__U_TERMINAL_SUFI:
1000 bal_get_ind__free_mem_terminal_sufi(balIndCfg);
1001 break;
1002
1003 case BAL_INDICATIONS__U_TERMINAL_SUB_TERM_ACT_FAIL:
1004 bal_get_ind__free_mem_terminal_sub_term_act_fail(balIndCfg);
1005 break;
1006
1007 case BAL_INDICATIONS__U_TERMINAL_TIWI:
1008 bal_get_ind__free_mem_terminal_tiwi(balIndCfg);
1009 break;
1010
1011 case BAL_INDICATIONS__U_TM_SCHED_OPER_STATS_CHANGE:
1012 bal_get_ind__free_mem_tm_sched_osc(balIndCfg);
VoLTHA753536e2017-11-02 20:15:09 +05301013 break;
1014
1015 case BAL_INDICATIONS__U_PKT_DATA:
1016 bal_get_ind__free_mem_u_pkt_data(balIndCfg);
1017 break;
1018
1019 case BAL_INDICATIONS__U_BAL_OMCI_RESP:
1020 bal_get_ind__free_mem_u_bal_omci_resp(balIndCfg);
1021 break;
1022
1023 case BAL_INDICATIONS__U_BAL_OAM_RESP:
1024 bal_get_ind__free_mem_u_bal_oam_resp(balIndCfg);
1025 break;
1026
1027 default:
Kim Kempfafa1ab42017-11-13 09:31:47 -08001028 ASFVOLT_LOG(ASFVOLT_ERROR, "Unknown BAL indication %u", balIndCfg->u_case);
VoLTHA753536e2017-11-02 20:15:09 +05301029 break;
1030 }
1031}
1032
1033void bal_get_ind__bal_get_ind_from_device_cb(grpc_c_context_t *context)
1034{
1035 BalDefault *dummy;
1036 BalIndications *bal_indication;
1037 list_node *node = NULL;
1038 int ret_val = 0;
1039
1040 /*
1041 * Read incoming message into set_cfg
1042 */
1043 if (context->gcc_payload) {
1044 context->gcc_stream->read(context, (void **)&dummy, 0);
1045 }
1046
1047 /*
1048 * send it to BAL
1049 */
1050
1051 pthread_mutex_lock(&bal_ind_queue_lock);
1052 node = get_bal_indication_node();
1053 pthread_mutex_unlock(&bal_ind_queue_lock);
root2ca2cc02017-11-03 19:51:57 +05301054
VoLTHA753536e2017-11-02 20:15:09 +05301055 if(node != NULL)
1056 {
1057 bal_indication = node->bal_indication;
1058 bal_indication->ind_present = true;
1059 bal_indication->has_ind_present = true;
1060 }
1061 else
1062 {
1063 bal_indication = malloc(sizeof(BalIndications));
1064 memset(bal_indication, 0, sizeof(BalIndications));
1065 bal_indications__init(bal_indication);
1066 bal_indication->ind_present = false;
1067 bal_indication->has_ind_present = true;
1068 }
1069
1070 /*
1071 * Write reply back to the client
1072 */
1073
root2ca2cc02017-11-03 19:51:57 +05301074 ret_val = context->gcc_stream->write(context, bal_indication, -1);
VoLTHA753536e2017-11-02 20:15:09 +05301075 is_grpc_write_pending(ret_val);
1076
1077 grpc_c_status_t status;
1078 status.gcs_code = 0;
1079
1080 /*
1081 * Finish response for RPC
1082 */
1083 if (context->gcc_stream->finish(context, &status))
1084 {
Kim Kempfafa1ab42017-11-13 09:31:47 -08001085 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status");
VoLTHA753536e2017-11-02 20:15:09 +05301086 }
root2ca2cc02017-11-03 19:51:57 +05301087
VoLTHA753536e2017-11-02 20:15:09 +05301088 /*Free memory for 'bal_indication' and 'node'*/
1089 if (bal_indication->ind_present)
1090 {
1091 bal_get_ind__free_mem(bal_indication);
1092 free(node);
1093 }
1094 else
1095 {
1096 free(bal_indication);
1097 }
1098}
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301099
1100/*
1101 * This functions gets invoked whenever bal finish RPC gets called
1102 */
1103void bal__bal_api_finish_cb(grpc_c_context_t *context)
1104{
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301105
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301106}
1107
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001108void bal_ind__bal_acc_term_oper_sts_cng_ind_cb(grpc_c_context_t *context)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301109{
1110}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001111void bal_ind__bal_acc_term_cfg_cb(grpc_c_context_t *context)
1112{
1113}
1114void bal_ind__bal_acc_term_proc_err_cb(grpc_c_context_t *context)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301115{
1116}
1117void bal_ind__bal_flow_oper_sts_cng_cb(grpc_c_context_t *context)
1118{
1119}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001120void bal_ind__bal_flow_proc_err_cb(grpc_c_context_t *context)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301121{
1122}
1123void bal_ind__bal_iface_oper_sts_cng_cb(grpc_c_context_t *context)
1124{
1125}
1126void bal_ind__bal_iface_los_cb(grpc_c_context_t *context)
1127{
1128}
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301129void bal_ind__bal_iface_stat_cb(grpc_c_context_t *context)
1130{
1131}
1132void bal_ind__bal_subs_term_oper_sts_cng_cb(grpc_c_context_t *context)
1133{
1134}
1135void bal_ind__bal_subs_term_discovery_ind_cb(grpc_c_context_t *context)
1136{
1137}
1138void bal_ind__bal_subs_term_alarm_ind_cb(grpc_c_context_t *context)
1139{
1140}
1141void bal_ind__bal_subs_term_dgi_ind_cb(grpc_c_context_t *context)
1142{
1143}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001144void bal_ind__bal_subs_term_proc_err_cb(grpc_c_context_t *context)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301145{
1146}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001147void bal_ind__bal_subs_term_dowi_ind_cb(grpc_c_context_t *context)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301148{
1149}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001150void bal_ind__bal_subs_term_looci_ind_cb(grpc_c_context_t *context)
1151{
1152}
1153void bal_ind__bal_subs_term_sdi_ind_cb(grpc_c_context_t *context)
1154{
1155}
1156void bal_ind__bal_subs_term_sfi_ind_cb(grpc_c_context_t *context)
1157{
1158}
1159void bal_ind__bal_subs_term_sufi_ind_cb(grpc_c_context_t *context)
1160{
1161}
1162void bal_ind__bal_subs_term_tiwi_ind_cb(grpc_c_context_t *context)
1163{
1164}
1165void bal_ind__bal_sub_term_act_fail_ind_cb(grpc_c_context_t *context)
1166{
1167}
1168void bal_ind__bal_tm_sched_oper_stats_change_cb(grpc_c_context_t *context)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301169{
1170}
1171void bal_ind__bal_pkt_bearer_channel_rx_ind_cb(grpc_c_context_t *context)
1172{
1173}
1174void bal_ind__bal_pkt_omci_channel_rx_ind_cb(grpc_c_context_t *context)
1175{
1176}
1177void bal_ind__bal_pkt_ieee_oam_channel_rx_ind_cb(grpc_c_context_t *context)
1178{
1179}
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001180void bal_ind__bal_sys_profile_ind_cb(grpc_c_context_t *context)
1181{
1182}
A R Karthick1d251032017-09-06 09:38:34 -07001183
Kim Kempfafa1ab42017-11-13 09:31:47 -08001184/*
1185** ASFVOLT_HEX2LOG(ASFVOLT_DEBUG, "OMCI Response with %zd bytes is",
1186** balIndCfg.balomciresp->data->pkt.data, balIndCfg.balomciresp->data->pkt.len);
1187*/
1188#define SYSLOG_MAX_SIZE 1024
1189void asfvolt_hexlog2(int prio, const char *_file_loc, int _file_line, const char *pFormat, void* pData, size_t len)
1190{
1191 unsigned char *inpPtr = pData;
1192 char tempBuf[SYSLOG_MAX_SIZE];
1193 size_t idx = 0;
1194
1195 idx += snprintf(tempBuf+idx, SYSLOG_MAX_SIZE-1, pFormat, len);
1196 while (len-- > 0 && idx < SYSLOG_MAX_SIZE)
1197 {
1198 idx += snprintf(tempBuf+idx, SYSLOG_MAX_SIZE-idx, "%02x", *inpPtr++);
1199 }
1200 ASFVOLT_LOG_LOC(prio, _file_loc, _file_line, "%s", tempBuf);
1201}
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301202
1203/*
1204 * Takes socket path as argument
1205 */
Rajeswara Raoa3efbca2017-09-08 18:01:16 +05301206int main (int argc, char **argv)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301207{
1208 int i = 0;
1209 grpc_c_server_t *server = NULL;
1210
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001211 if (argc < 4)
Rajeswara Rao9f1cea12017-10-10 18:25:29 +05301212 {
Girish Gowdru9ebd8b22018-09-26 03:21:03 -07001213 fprintf(stderr, "Missing arguments\n");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301214 exit(1);
1215 }
1216
1217 strcpy(coreIpPortInfo.bal_core_arg1, argv[2] /*, strlen(argv[2])*/);
1218 strcpy(coreIpPortInfo.bal_core_ip_port, argv[3]/*, strlen(argv[3])*/);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301219
1220 signal(SIGINT, sigint_handler);
Kim Kempfafa1ab42017-11-13 09:31:47 -08001221
1222 /*
1223 ** syslog initialization
1224 */
1225 //setlogmask (LOG_UPTO (LOG_NOTICE));
1226
1227 openlog (ASFVOLT_SYSLOG_NAME, ASFVOLT_SYSLOG_MODE, LOG_LOCAL1);
1228
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301229 /*
1230 * Initialize grpc-c library to be used with vanilla gRPC
1231 */
1232 grpc_c_init(GRPC_THREADS, NULL);
1233
1234 /*
1235 * Create server object
1236 */
1237 test_server = grpc_c_server_create(argv[1]);
1238
Rajeswara Rao9f1cea12017-10-10 18:25:29 +05301239 if (test_server == NULL)
1240 {
Kim Kempfafa1ab42017-11-13 09:31:47 -08001241 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to create server");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301242 exit(1);
1243 }
1244
1245 /*
1246 * Initialize greeter service
1247 */
Kim Kempfafa1ab42017-11-13 09:31:47 -08001248 ASFVOLT_LOG(ASFVOLT_INFO, "voltha_bal_driver running.....");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301249 bal__service_init(test_server);
VoLTHA753536e2017-11-02 20:15:09 +05301250 bal_get_ind__service_init(test_server);
root5be94e52018-02-15 22:30:14 +05301251 asfvolt__service_init(test_server);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301252
1253 /*
1254 * Start server
1255 */
1256 grpc_c_server_start(test_server);
1257
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301258 /*
1259 * Blocks server to wait to completion
1260 */
1261 grpc_c_server_wait(test_server);
1262
1263 /* code added for example Makefile to compile grpc-c along with edgecore driver */
1264 bal__service_init(server);
VoLTHA753536e2017-11-02 20:15:09 +05301265 bal_get_ind__service_init(server);
root5be94e52018-02-15 22:30:14 +05301266 asfvolt__service_init(server);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301267}