Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 1 | /* |
| 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 Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 16 | #include <signal.h> |
| 17 | #include <stdio.h> |
| 18 | #include <unistd.h> |
| 19 | #include <sys/time.h> |
| 20 | #include "bal_msg_type.grpc-c.h" |
| 21 | #include "bal_osmsg.grpc-c.h" |
| 22 | #include "bal_model_ids.grpc-c.h" |
| 23 | #include "bal_obj.grpc-c.h" |
| 24 | #include "bal_model_types.grpc-c.h" |
| 25 | #include "bal_errno.grpc-c.h" |
| 26 | #include "bal.grpc-c.h" |
| 27 | |
| 28 | #ifdef BAL_STUB |
| 29 | #include "bal_stub.h" |
| 30 | #else |
| 31 | #include "asfvolt16_driver.h" |
| 32 | #endif |
| 33 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 34 | #include <unistd.h> |
| 35 | #include <sys/reboot.h> |
| 36 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 37 | /* Global varibles */ |
| 38 | balCoreIpInfo coreIpPortInfo; |
| 39 | |
| 40 | static grpc_c_server_t *test_server; |
| 41 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 42 | static void sigint_handler (int x) { |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 43 | grpc_c_server_destroy(test_server); |
| 44 | exit(0); |
| 45 | } |
| 46 | |
| 47 | /* |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 48 | * This functions gets invoked whenever bal Heartbeat RPC gets called |
| 49 | */ |
| 50 | void bal__bal_api_heartbeat_cb(grpc_c_context_t *context) |
| 51 | { |
| 52 | BalHeartbeat *bal_hb; |
| 53 | BalErr bal_err; |
| 54 | |
| 55 | /* |
| 56 | * Read incoming message into set_cfg |
| 57 | */ |
| 58 | printf("\nRecevied HeartBeat from Adapter\n"); |
| 59 | if (context->gcc_payload) { |
| 60 | context->gcc_stream->read(context, (void **)&bal_hb, 0); |
| 61 | } |
| 62 | |
| 63 | printf("Received Heart Beat msg\n"); |
| 64 | |
| 65 | bal_err__init(&bal_err); |
| 66 | |
| 67 | bal_err.err= 0; |
| 68 | |
| 69 | /* |
| 70 | * Write reply back to the client |
| 71 | */ |
| 72 | if (!context->gcc_stream->write(context, &bal_err, 0)) { |
| 73 | } else { |
| 74 | printf("Failed to write\n"); |
| 75 | exit(1); |
| 76 | } |
| 77 | |
| 78 | grpc_c_status_t status; |
| 79 | status.gcs_code = 0; |
| 80 | |
| 81 | /* |
| 82 | * Finish response for RPC |
| 83 | */ |
| 84 | if (context->gcc_stream->finish(context, &status)) { |
| 85 | printf("Failed to write status\n"); |
| 86 | exit(1); |
| 87 | } |
| 88 | |
| 89 | sleep(1); |
| 90 | printf("\nSent HeartBeat Response to Adapter\n"); |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * This functions gets invoked whenever Bal reboot gets called |
| 95 | */ |
| 96 | void bal__bal_api_reboot_cb(grpc_c_context_t *context) |
| 97 | { |
| 98 | BalReboot *read_device; |
| 99 | BalErr bal_err; |
| 100 | /* |
| 101 | * Read incoming message into get_cfg |
| 102 | */ |
| 103 | if (context->gcc_payload) { |
| 104 | context->gcc_stream->read(context, (void **)&read_device, 0); |
| 105 | } |
| 106 | |
| 107 | printf("Bal Server - Reboot : ======Entering Function Reboot ==============================\n"); |
| 108 | printf("Bal Server - Reboot : Device ID is %s\n",read_device->device_id); |
| 109 | |
| 110 | sync(); |
| 111 | reboot(RB_AUTOBOOT); |
| 112 | |
| 113 | /* system("init 6"); */ |
| 114 | /* |
| 115 | * send it to BAL |
| 116 | */ |
| 117 | |
| 118 | bal_err__init(&bal_err); |
| 119 | |
| 120 | bal_err.err= 0; |
| 121 | |
| 122 | /* |
| 123 | * Write reply back to the client |
| 124 | */ |
| 125 | if (!context->gcc_stream->write(context, &bal_err, 0)) { |
| 126 | } else { |
| 127 | printf("Bal Server - Reboot Failed to write\n"); |
| 128 | exit(1); |
| 129 | } |
| 130 | |
| 131 | grpc_c_status_t status; |
| 132 | status.gcs_code = 0; |
| 133 | |
| 134 | /* |
| 135 | * Finish response for RPC |
| 136 | */ |
| 137 | if (context->gcc_stream->finish(context, &status)) { |
| 138 | printf("Failed to write status\n"); |
| 139 | exit(1); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * This functions gets invoked whenever Bal Stats gets called |
| 145 | */ |
| 146 | void bal__bal_cfg_stat_get_cb(grpc_c_context_t *context) |
| 147 | { |
| 148 | BalInterfaceKey *read_stats; |
| 149 | |
| 150 | /* |
| 151 | * Read incoming message into get_cfg |
| 152 | */ |
| 153 | if (context->gcc_payload) { |
| 154 | context->gcc_stream->read(context, (void **)&read_stats, 0); |
| 155 | } |
| 156 | |
| 157 | printf("Bal Server - Get Stats :======Entering Function Get Stats ============\n"); |
| 158 | printf("Bal Server - Get Stats :NNI port is %d\n",read_stats->intf_id); |
| 159 | |
| 160 | BalInterfaceStat get_stats; |
| 161 | memset(&get_stats, 0, sizeof(BalInterfaceStat)); |
| 162 | bal_interface_stat__init(&get_stats); |
| 163 | |
| 164 | BalInterfaceStatData stat_data; |
| 165 | memset(&stat_data, 0, sizeof(BalInterfaceStatData)); |
| 166 | bal_interface_stat_data__init(&stat_data); |
| 167 | |
| 168 | #ifndef BAL_STUB |
| 169 | /* Interface Type, Interface ID |
| 170 | stat_data - Statistics Data */ |
| 171 | asfvolt16_bal_stats_get(read_stats->intf_type, read_stats->intf_id, &stat_data); |
| 172 | printf("Bal Server - Get Stats Not In BalStubs : Got all the statistics\n"); |
| 173 | #else |
| 174 | stub_bal_stats_get(&stat_data); |
| 175 | printf("Bal Server - Get Stats In BalStubs : Got all the statistics\n"); |
| 176 | #endif |
| 177 | |
| 178 | get_stats.data = &stat_data; |
| 179 | |
| 180 | if (!context->gcc_stream->write(context, &get_stats, 0)) { |
| 181 | printf("Successfully Written Stats\n"); |
| 182 | } else { |
| 183 | printf("Stats Failed to write\n"); |
| 184 | exit(1); |
| 185 | } |
| 186 | |
| 187 | grpc_c_status_t status; |
| 188 | status.gcs_code = 0; |
| 189 | |
| 190 | /* |
| 191 | * Finish response for RPC |
| 192 | */ |
| 193 | if (context->gcc_stream->finish(context, &status)) { |
| 194 | printf("Failed to write status\n"); |
| 195 | exit(1); |
| 196 | } |
| 197 | |
| 198 | sleep(1); |
| 199 | printf("============ Returning from Stats Function============\n"); |
| 200 | } |
| 201 | |
| 202 | /* |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 203 | * This functions gets invoked whenever bal RPC gets called |
| 204 | */ |
| 205 | void bal__bal_cfg_get_cb(grpc_c_context_t *context) |
| 206 | { |
| 207 | BalCfg *get_cfg; |
| 208 | |
| 209 | /* |
| 210 | * Read incoming message into get_cfg |
| 211 | */ |
| 212 | if (context->gcc_payload) { |
| 213 | context->gcc_stream->read(context, (void **)&get_cfg, 0); |
| 214 | } |
| 215 | |
| 216 | #ifndef BAL_STUB |
| 217 | //asfvolt16_bal_cfg_get(key, get_cfg); |
| 218 | #endif |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * This functions gets invoked whenever bal RPC gets called |
| 223 | */ |
| 224 | void bal__bal_cfg_set_cb(grpc_c_context_t *context) |
| 225 | { |
| 226 | BalCfg *set_cfg; |
| 227 | BalErr bal_err; |
| 228 | int ret_val = 0; |
| 229 | |
| 230 | /* |
| 231 | * Read incoming message into set_cfg |
| 232 | */ |
| 233 | if (context->gcc_payload) { |
| 234 | context->gcc_stream->read(context, (void **)&set_cfg, 0); |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * send it to BAL |
| 239 | */ |
| 240 | |
| 241 | bal_err__init(&bal_err); |
| 242 | |
| 243 | bal_err.err= 0; |
| 244 | |
| 245 | /* |
| 246 | * Write reply back to the client |
| 247 | */ |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 248 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 249 | ret_val = context->gcc_stream->write(context, &bal_err, 0); |
| 250 | if (ret_val != GRPC_C_WRITE_OK) { |
| 251 | if(ret_val == GRPC_C_WRITE_PENDING) { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 252 | printf("write is pending, sleep for 10 sec %d \n", ret_val); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 253 | sleep(10); |
| 254 | } |
| 255 | else { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 256 | printf("Failed to write %d \n", ret_val); |
| 257 | printf("write is pending, sleep for 10 sec: %d\n", ret_val); |
| 258 | sleep(10); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | grpc_c_status_t status; |
| 263 | status.gcs_code = 0; |
| 264 | |
| 265 | /* |
| 266 | * Finish response for RPC |
| 267 | */ |
| 268 | if (context->gcc_stream->finish(context, &status)) { |
| 269 | printf("Failed to write status\n"); |
| 270 | exit(1); |
| 271 | } |
| 272 | |
| 273 | #ifdef BAL_STUB |
| 274 | pthread_mutex_lock(&lock); |
| 275 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 276 | struct QNode *temp = newNode(set_cfg->hdr->obj_type, |
| 277 | BAL_ERRNO__BAL_ERR_OK, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 278 | set_cfg->device_id); |
| 279 | |
| 280 | /* if(set_cfg->hdr->has_obj_type) |
| 281 | { */ |
| 282 | |
| 283 | switch(set_cfg->hdr->obj_type) |
| 284 | { |
| 285 | case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL: |
| 286 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 287 | printf("\n***************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 288 | printf("Received Access Terminal Configuration msg\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 289 | printf("***************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 290 | } |
| 291 | break; |
| 292 | case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE: |
| 293 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 294 | printf("\n***************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 295 | printf("Received PON Interface Configuration msg\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 296 | printf("***************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 297 | temp->intf_id = set_cfg->interface->key->intf_id; |
| 298 | printf("Pon ID = %d\n", temp->intf_id); |
| 299 | } |
| 300 | break; |
| 301 | case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL: |
| 302 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 303 | printf("\n*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 304 | printf("Received ONU Activation msg\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 305 | printf("*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 306 | temp->intf_id = set_cfg->terminal->key->intf_id; |
| 307 | temp->onu_id = set_cfg->terminal->key->sub_term_id; |
| 308 | memset(temp->vendor_id, 0, BAL_DEVICE_STR_LEN); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 309 | memcpy(temp->vendor_id, |
| 310 | set_cfg->terminal->data->serial_number->vendor_id, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 311 | strlen(set_cfg->terminal->data->serial_number->vendor_id)); |
| 312 | memset(temp->vendor_specific, 0, BAL_DEVICE_STR_LEN); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 313 | memcpy(temp->vendor_specific, |
| 314 | set_cfg->terminal->data->serial_number->vendor_specific, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 315 | strlen(set_cfg->terminal->data->serial_number->vendor_specific)); |
| 316 | |
| 317 | } |
| 318 | break; |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 319 | case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED: |
| 320 | { |
| 321 | printf("\n*****************************************************\n"); |
| 322 | printf("Received TM schedule msg\n"); |
| 323 | printf("*****************************************************\n"); |
| 324 | } |
| 325 | break; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 326 | case BAL_OBJ_ID__BAL_OBJ_ID_PACKET: |
| 327 | { |
| 328 | switch(set_cfg->packet->key->packet_send_dest->type) |
| 329 | { |
| 330 | case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL: |
| 331 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 332 | printf("\n*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 333 | printf("Received OMCI msg\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 334 | printf("*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 335 | temp->intf_id = set_cfg->terminal->key->intf_id; |
| 336 | temp->onu_id = set_cfg->terminal->key->sub_term_id; |
| 337 | } |
| 338 | break; |
| 339 | default: |
| 340 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 341 | ("\n*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 342 | printf("Dest type invalid\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 343 | printf("*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 344 | } |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | break; |
| 349 | default: |
| 350 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 351 | ("\n*****************************************************\n"); |
| 352 | printf("Received Invalid msg type === %d \n", set_cfg->hdr->obj_type); |
| 353 | printf("*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 354 | pthread_mutex_unlock(&lock); |
| 355 | return; |
| 356 | } |
| 357 | break; |
| 358 | } |
| 359 | enQueue(set_cfg->hdr->obj_type, temp); |
| 360 | /* |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | printf("BALSTUB:Cfg Set recevied without object type"); |
| 365 | } */ |
| 366 | pthread_mutex_unlock(&lock); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 367 | sleep(2); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 368 | pthread_cond_signal(&cv); |
| 369 | /* |
| 370 | if(BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE == set_cfg->hdr->obj_type) |
| 371 | { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 372 | sleep(5); |
| 373 | struct QNode *temp1 = newNode(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL, |
| 374 | BAL_ERRNO__BAL_ERR_OK, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 375 | set_cfg->device_id); |
| 376 | temp1->intf_id = set_cfg->interface->key->intf_id; |
| 377 | temp1->onu_id = 65535; |
| 378 | printf("sending _onu_discovery_indiaction\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 379 | enQueue(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL, temp1); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 380 | pthread_cond_signal(&cv); |
| 381 | } |
| 382 | */ |
| 383 | #else |
| 384 | if(BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL == set_cfg->hdr->obj_type) |
| 385 | { |
| 386 | sleep(5);//enable this if running with gdb |
| 387 | } |
| 388 | asfvolt16_bal_cfg_set(set_cfg); |
| 389 | #endif |
| 390 | } |
| 391 | |
| 392 | |
| 393 | /* |
| 394 | * This functions gets invoked whenever bal clear RPC gets called |
| 395 | */ |
| 396 | void bal__bal_cfg_clear_cb(grpc_c_context_t *context) |
| 397 | { |
| 398 | BalKey *clear_key; |
| 399 | |
| 400 | /* |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 401 | * Read incoming message into clear_key |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 402 | */ |
| 403 | if (context->gcc_payload) { |
| 404 | context->gcc_stream->read(context, (void **)&clear_key, 0); |
| 405 | } |
| 406 | |
| 407 | #ifndef BAL_STUB |
| 408 | asfvolt16_bal_cfg_clear(clear_key); |
| 409 | #endif |
| 410 | } |
| 411 | |
| 412 | |
| 413 | /* |
| 414 | * This functions gets invoked whenever bal Init RPC gets called |
| 415 | */ |
| 416 | void bal__bal_api_init_cb(grpc_c_context_t *context) |
| 417 | { |
| 418 | BalInit *bal_init; |
| 419 | BalErr bal_err; |
| 420 | int ret_val; |
| 421 | |
| 422 | /* |
| 423 | * Read incoming message into set_cfg |
| 424 | */ |
| 425 | if (context->gcc_payload) { |
| 426 | context->gcc_stream->read(context, (void **)&bal_init, 0); |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * send it to BAL |
| 431 | */ |
| 432 | |
| 433 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 434 | ("\n*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 435 | printf("Received API Init msg\n"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 436 | printf("*****************************************************\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 437 | |
| 438 | bal_err__init(&bal_err); |
| 439 | |
| 440 | bal_err.err= 0; |
| 441 | |
| 442 | /* |
| 443 | * Write reply back to the client |
| 444 | */ |
| 445 | ret_val = context->gcc_stream->write(context, &bal_err, 0); |
| 446 | if (ret_val != GRPC_C_WRITE_OK) { |
| 447 | if(ret_val == GRPC_C_WRITE_PENDING) { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 448 | printf("write is pending, sleep for 10 sec %d \n", ret_val); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 449 | sleep(10); |
| 450 | } |
| 451 | else { |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 452 | printf("Failed to write %d \n", ret_val); |
| 453 | printf("write is pending, sleep for 10 sec: %d\n", ret_val); |
| 454 | sleep(10); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | grpc_c_status_t status; |
| 459 | status.gcs_code = 0; |
| 460 | |
| 461 | /* |
| 462 | * Finish response for RPC |
| 463 | */ |
| 464 | if (context->gcc_stream->finish(context, &status)) { |
| 465 | printf("Failed to write status\n"); |
| 466 | exit(1); |
| 467 | } |
| 468 | |
| 469 | #ifndef BAL_STUB |
| 470 | asfvolt16_bal_init(bal_init, &coreIpPortInfo); |
| 471 | #else |
| 472 | printf("\nRecevied IP Address == %s \n", bal_init->voltha_adapter_ip_port); |
| 473 | stub_bal_init(bal_init); |
| 474 | #endif |
| 475 | |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /* |
| 480 | * This functions gets invoked whenever bal finish RPC gets called |
| 481 | */ |
| 482 | void bal__bal_api_finish_cb(grpc_c_context_t *context) |
| 483 | { |
| 484 | #if 0 |
| 485 | void *finish_init; |
| 486 | |
| 487 | /* |
| 488 | * Read incoming message into set_cfg |
| 489 | */ |
| 490 | if (context->gcc_payload) { |
| 491 | context->gcc_stream->read(context, (void **)&finish_init); |
| 492 | } |
| 493 | #endif |
| 494 | } |
| 495 | |
| 496 | #if 0 |
| 497 | /* |
| 498 | * This functions gets invoked whenever bal finish RPC gets called |
| 499 | */ |
| 500 | void bal_ind__bal_ind_info_cb(grpc_c_context_t *context) |
| 501 | { |
| 502 | #if 0 |
| 503 | void *finish_init; |
| 504 | |
| 505 | /* |
| 506 | * Read incoming message into set_cfg |
| 507 | */ |
| 508 | if (context->gcc_payload) { |
| 509 | context->gcc_stream->read(context, (void **)&finish_init); |
| 510 | } |
| 511 | #endif |
| 512 | } |
| 513 | #endif |
| 514 | |
| 515 | void bal_ind__bal_acc_term_ind_cb(grpc_c_context_t *context) |
| 516 | { |
| 517 | } |
| 518 | void bal_ind__bal_acc_term_oper_sts_cng_ind_cb(grpc_c_context_t *context) |
| 519 | { |
| 520 | } |
| 521 | void bal_ind__bal_flow_oper_sts_cng_cb(grpc_c_context_t *context) |
| 522 | { |
| 523 | } |
| 524 | void bal_ind__bal_flow_ind_cb(grpc_c_context_t *context) |
| 525 | { |
| 526 | } |
| 527 | void bal_ind__bal_group_ind_cb(grpc_c_context_t *context) |
| 528 | { |
| 529 | } |
| 530 | void bal_ind__bal_iface_oper_sts_cng_cb(grpc_c_context_t *context) |
| 531 | { |
| 532 | } |
| 533 | void bal_ind__bal_iface_los_cb(grpc_c_context_t *context) |
| 534 | { |
| 535 | } |
| 536 | void bal_ind__bal_iface_ind_cb(grpc_c_context_t *context) |
| 537 | { |
| 538 | } |
| 539 | void bal_ind__bal_iface_stat_cb(grpc_c_context_t *context) |
| 540 | { |
| 541 | } |
| 542 | void bal_ind__bal_subs_term_oper_sts_cng_cb(grpc_c_context_t *context) |
| 543 | { |
| 544 | } |
| 545 | void bal_ind__bal_subs_term_discovery_ind_cb(grpc_c_context_t *context) |
| 546 | { |
| 547 | } |
| 548 | void bal_ind__bal_subs_term_alarm_ind_cb(grpc_c_context_t *context) |
| 549 | { |
| 550 | } |
| 551 | void bal_ind__bal_subs_term_dgi_ind_cb(grpc_c_context_t *context) |
| 552 | { |
| 553 | } |
| 554 | void bal_ind__bal_subs_term_ind_cb(grpc_c_context_t *context) |
| 555 | { |
| 556 | } |
| 557 | void bal_ind__bal_tm_queue_ind_info_cb(grpc_c_context_t *context) |
| 558 | { |
| 559 | } |
| 560 | void bal_ind__bal_tm_sched_ind_info_cb(grpc_c_context_t *context) |
| 561 | { |
| 562 | } |
| 563 | void bal_ind__bal_pkt_bearer_channel_rx_ind_cb(grpc_c_context_t *context) |
| 564 | { |
| 565 | } |
| 566 | void bal_ind__bal_pkt_omci_channel_rx_ind_cb(grpc_c_context_t *context) |
| 567 | { |
| 568 | } |
| 569 | void bal_ind__bal_pkt_ieee_oam_channel_rx_ind_cb(grpc_c_context_t *context) |
| 570 | { |
| 571 | } |
A R Karthick | 1d25103 | 2017-09-06 09:38:34 -0700 | [diff] [blame] | 572 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 573 | |
| 574 | /* |
| 575 | * Takes socket path as argument |
| 576 | */ |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 577 | int main (int argc, char **argv) |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 578 | { |
| 579 | int i = 0; |
| 580 | grpc_c_server_t *server = NULL; |
| 581 | |
| 582 | if (argc < 6) { |
| 583 | fprintf(stderr, "Missing socket path argument\n"); |
| 584 | exit(1); |
| 585 | } |
| 586 | |
| 587 | strcpy(coreIpPortInfo.bal_core_arg1, argv[2] /*, strlen(argv[2])*/); |
| 588 | strcpy(coreIpPortInfo.bal_core_ip_port, argv[3]/*, strlen(argv[3])*/); |
| 589 | strcpy(coreIpPortInfo.bal_core_arg2, argv[4]/*, strlen(argv[4])*/); |
| 590 | strcpy(coreIpPortInfo.bal_shared_lib_ip_port, argv[5]/*, strlen(argv[5])*/); |
| 591 | |
| 592 | signal(SIGINT, sigint_handler); |
| 593 | /* |
| 594 | * Initialize grpc-c library to be used with vanilla gRPC |
| 595 | */ |
| 596 | grpc_c_init(GRPC_THREADS, NULL); |
| 597 | |
| 598 | /* |
| 599 | * Create server object |
| 600 | */ |
| 601 | test_server = grpc_c_server_create(argv[1]); |
| 602 | |
| 603 | if (test_server == NULL) { |
| 604 | printf("Failed to create server\n"); |
| 605 | exit(1); |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * Initialize greeter service |
| 610 | */ |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame^] | 611 | printf("\nvoltha_bal_driver running.....\n"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 612 | bal__service_init(test_server); |
| 613 | |
| 614 | /* |
| 615 | * Start server |
| 616 | */ |
| 617 | grpc_c_server_start(test_server); |
| 618 | |
| 619 | #ifdef BAL_STUB |
| 620 | printf("\nCreating a stub thread\n"); |
| 621 | create_stub_thread(); |
| 622 | #endif |
| 623 | |
| 624 | /* |
| 625 | * Blocks server to wait to completion |
| 626 | */ |
| 627 | grpc_c_server_wait(test_server); |
| 628 | |
| 629 | /* code added for example Makefile to compile grpc-c along with edgecore driver */ |
| 630 | bal__service_init(server); |
| 631 | |
| 632 | } |