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