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