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> |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 36 | #include "bal_indications_queue.h" |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 37 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 38 | /* Global varibles */ |
| 39 | balCoreIpInfo coreIpPortInfo; |
| 40 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 41 | /* extern variables*/ |
| 42 | list_node *bal_ind_queue_tail = NULL; |
| 43 | list_node *bal_ind_queue_head = NULL; |
| 44 | pthread_mutex_t bal_ind_queue_lock; |
| 45 | unsigned int num_of_nodes = 0; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 46 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 47 | /* static variables*/ |
| 48 | static grpc_c_server_t *test_server; |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 49 | static void sigint_handler (int x) { |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 50 | grpc_c_server_destroy(test_server); |
| 51 | exit(0); |
| 52 | } |
| 53 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 54 | void is_grpc_write_pending(int return_value) |
| 55 | { |
| 56 | if (return_value != GRPC_C_WRITE_OK) |
| 57 | { |
| 58 | if(return_value == GRPC_C_WRITE_PENDING) |
| 59 | { |
| 60 | /* TODO: Register call back with grpc-c which will give an indication whenever write was succussful */ |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 61 | ASFVOLT_LOG(ASFVOLT_INFO, "write(%d) is pending, sleep for 5 sec", return_value); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 62 | sleep(5); |
| 63 | } |
| 64 | else |
| 65 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 66 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write %d", return_value); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 72 | /* |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 73 | * This functions gets invoked whenever bal Heartbeat RPC gets called |
| 74 | */ |
| 75 | void bal__bal_api_heartbeat_cb(grpc_c_context_t *context) |
| 76 | { |
| 77 | BalHeartbeat *bal_hb; |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 78 | BalRebootState bal_reboot; |
Rajeswara Rao | b2e441c | 2017-09-20 16:40:21 +0530 | [diff] [blame] | 79 | int ret_val; |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 80 | /* |
| 81 | * Read incoming message into set_cfg |
| 82 | */ |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 83 | if (context->gcc_payload) { |
| 84 | context->gcc_stream->read(context, (void **)&bal_hb, 0); |
| 85 | } |
| 86 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 87 | bal_reboot_state__init(&bal_reboot); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 88 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 89 | bal_reboot.has_is_reboot = 1; |
| 90 | #ifndef BAL_STUB |
| 91 | bal_reboot.is_reboot = is_reboot; |
| 92 | #else |
| 93 | bal_reboot.is_reboot = is_stub_reboot; |
| 94 | #endif |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Write reply back to the client |
| 98 | */ |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 99 | ret_val = context->gcc_stream->write(context, &bal_reboot, -1); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 100 | is_grpc_write_pending(ret_val); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 101 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 102 | grpc_c_status_t status; |
| 103 | status.gcs_code = 0; |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 104 | |
| 105 | /* |
| 106 | * Finish response for RPC |
| 107 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 108 | if (context->gcc_stream->finish(context, &status)) |
| 109 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 110 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 111 | } |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* |
| 115 | * This functions gets invoked whenever Bal reboot gets called |
| 116 | */ |
| 117 | void bal__bal_api_reboot_cb(grpc_c_context_t *context) |
| 118 | { |
| 119 | BalReboot *read_device; |
| 120 | BalErr bal_err; |
Rajeswara Rao | b2e441c | 2017-09-20 16:40:21 +0530 | [diff] [blame] | 121 | int ret_val; |
| 122 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 123 | /* |
| 124 | * Read incoming message into get_cfg |
| 125 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 126 | if (context->gcc_payload) |
| 127 | { |
| 128 | context->gcc_stream->read(context, (void **)&read_device, 0); |
| 129 | } |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 130 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 131 | ASFVOLT_LOG(ASFVOLT_INFO, "Bal Server - Reboot : Device ID is %s",read_device->device_id); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 132 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 133 | /* |
| 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 | */ |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 144 | ret_val = context->gcc_stream->write(context, &bal_err, -1); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 145 | is_grpc_write_pending(ret_val); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 146 | |
| 147 | grpc_c_status_t status; |
| 148 | status.gcs_code = 0; |
| 149 | |
| 150 | /* |
| 151 | * Finish response for RPC |
| 152 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 153 | if (context->gcc_stream->finish(context, &status)) |
| 154 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 155 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 156 | } |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 157 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 158 | ret_val = system("shutdown -r now"); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 159 | sleep(30); /* allow system to shutdown gracefully */ |
| 160 | sync(); /* force shutdown if graceful did not work */ |
| 161 | reboot(RB_AUTOBOOT); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
| 165 | * This functions gets invoked whenever Bal Stats gets called |
| 166 | */ |
| 167 | void bal__bal_cfg_stat_get_cb(grpc_c_context_t *context) |
| 168 | { |
| 169 | BalInterfaceKey *read_stats; |
Rajeswara Rao | b2e441c | 2017-09-20 16:40:21 +0530 | [diff] [blame] | 170 | int ret_val; |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Read incoming message into get_cfg |
| 174 | */ |
| 175 | if (context->gcc_payload) { |
| 176 | context->gcc_stream->read(context, (void **)&read_stats, 0); |
| 177 | } |
| 178 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 179 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Bal Server - Get Stats :NNI port is %d",read_stats->intf_id); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 180 | |
| 181 | BalInterfaceStat get_stats; |
| 182 | memset(&get_stats, 0, sizeof(BalInterfaceStat)); |
| 183 | bal_interface_stat__init(&get_stats); |
| 184 | |
| 185 | BalInterfaceStatData stat_data; |
| 186 | memset(&stat_data, 0, sizeof(BalInterfaceStatData)); |
| 187 | bal_interface_stat_data__init(&stat_data); |
| 188 | |
Rajeswara Rao | 92e3fd4 | 2017-10-26 10:47:03 +0530 | [diff] [blame] | 189 | BalInterfaceKey stat_key; |
| 190 | memset(&stat_key, 0, sizeof(BalInterfaceKey)); |
| 191 | bal_interface_key__init(&stat_key); |
| 192 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 193 | #ifndef BAL_STUB |
| 194 | /* Interface Type, Interface ID |
| 195 | stat_data - Statistics Data */ |
Rajeswara Rao | 92e3fd4 | 2017-10-26 10:47:03 +0530 | [diff] [blame] | 196 | asfvolt16_bal_stats_get(read_stats->intf_type, read_stats->intf_id, &stat_data, &stat_key); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 197 | #else |
| 198 | stub_bal_stats_get(&stat_data); |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 199 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Bal Server - Get Stats In BalStubs : Got all the statistics"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 200 | #endif |
| 201 | |
| 202 | get_stats.data = &stat_data; |
Rajeswara Rao | 92e3fd4 | 2017-10-26 10:47:03 +0530 | [diff] [blame] | 203 | get_stats.key = &stat_key; |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 204 | |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 205 | ret_val = context->gcc_stream->write(context, &get_stats, -1); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 206 | is_grpc_write_pending(ret_val); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 207 | |
| 208 | grpc_c_status_t status; |
| 209 | status.gcs_code = 0; |
| 210 | |
| 211 | /* |
| 212 | * Finish response for RPC |
| 213 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 214 | if (context->gcc_stream->finish(context, &status)) |
| 215 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 216 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status"); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 217 | } |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 221 | * This functions gets invoked whenever bal RPC gets called |
| 222 | */ |
| 223 | void bal__bal_cfg_get_cb(grpc_c_context_t *context) |
| 224 | { |
| 225 | BalCfg *get_cfg; |
| 226 | |
| 227 | /* |
| 228 | * Read incoming message into get_cfg |
| 229 | */ |
| 230 | if (context->gcc_payload) { |
| 231 | context->gcc_stream->read(context, (void **)&get_cfg, 0); |
| 232 | } |
| 233 | |
| 234 | #ifndef BAL_STUB |
| 235 | //asfvolt16_bal_cfg_get(key, get_cfg); |
| 236 | #endif |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * This functions gets invoked whenever bal RPC gets called |
| 241 | */ |
| 242 | void bal__bal_cfg_set_cb(grpc_c_context_t *context) |
| 243 | { |
| 244 | BalCfg *set_cfg; |
| 245 | BalErr bal_err; |
| 246 | int ret_val = 0; |
| 247 | |
| 248 | /* |
| 249 | * Read incoming message into set_cfg |
| 250 | */ |
| 251 | if (context->gcc_payload) { |
| 252 | context->gcc_stream->read(context, (void **)&set_cfg, 0); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * send it to BAL |
| 257 | */ |
| 258 | |
| 259 | bal_err__init(&bal_err); |
| 260 | |
| 261 | bal_err.err= 0; |
| 262 | |
| 263 | /* |
| 264 | * Write reply back to the client |
| 265 | */ |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 266 | |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 267 | ret_val = context->gcc_stream->write(context, &bal_err, -1); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 268 | is_grpc_write_pending(ret_val); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 269 | |
| 270 | grpc_c_status_t status; |
| 271 | status.gcs_code = 0; |
| 272 | |
| 273 | /* |
| 274 | * Finish response for RPC |
| 275 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 276 | if (context->gcc_stream->finish(context, &status)) |
| 277 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 278 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | #ifdef BAL_STUB |
| 282 | pthread_mutex_lock(&lock); |
| 283 | |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 284 | struct QNode *temp = newNode(set_cfg->hdr->obj_type, |
| 285 | BAL_ERRNO__BAL_ERR_OK, |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 286 | set_cfg->device_id); |
| 287 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 288 | switch(set_cfg->hdr->obj_type) |
| 289 | { |
| 290 | case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL: |
| 291 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 292 | ASFVOLT_LOG(ASFVOLT_INFO, "Received Access Terminal Configuration msg"); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 293 | } |
| 294 | break; |
| 295 | case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE: |
| 296 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 297 | ASFVOLT_LOG(ASFVOLT_INFO, "Received PON Interface Configuration msg"); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 298 | temp->intf_id = set_cfg->interface->key->intf_id; |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 299 | ASFVOLT_LOG(ASFVOLT_INFO, "Pon ID = %d", temp->intf_id); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 300 | } |
| 301 | break; |
| 302 | case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL: |
| 303 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 304 | ASFVOLT_LOG(ASFVOLT_INFO, "Received ONU Activation msg"); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 305 | temp->intf_id = set_cfg->terminal->key->intf_id; |
| 306 | temp->onu_id = set_cfg->terminal->key->sub_term_id; |
| 307 | memset(temp->vendor_id, 0, BAL_DEVICE_STR_LEN); |
| 308 | memcpy(temp->vendor_id, |
| 309 | set_cfg->terminal->data->serial_number->vendor_id, |
| 310 | strlen(set_cfg->terminal->data->serial_number->vendor_id)); |
| 311 | memset(temp->vendor_specific, 0, BAL_DEVICE_STR_LEN); |
| 312 | memcpy(temp->vendor_specific, |
| 313 | set_cfg->terminal->data->serial_number->vendor_specific, |
| 314 | strlen(set_cfg->terminal->data->serial_number->vendor_specific)); |
| 315 | } |
| 316 | break; |
| 317 | case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED: |
| 318 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 319 | ASFVOLT_LOG(ASFVOLT_INFO, "Received TM schedule msg"); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 320 | } |
| 321 | break; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 322 | case BAL_OBJ_ID__BAL_OBJ_ID_PACKET: |
| 323 | { |
| 324 | switch(set_cfg->packet->key->packet_send_dest->type) |
| 325 | { |
| 326 | case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL: |
| 327 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 328 | ASFVOLT_LOG(ASFVOLT_INFO, "Received OMCI msg"); |
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 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 335 | ASFVOLT_LOG(ASFVOLT_INFO, "Dest type invalid"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 336 | } |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | break; |
| 341 | default: |
| 342 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 343 | ASFVOLT_LOG(ASFVOLT_INFO, "Received Invalid msg type === %d", set_cfg->hdr->obj_type); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 344 | pthread_mutex_unlock(&lock); |
| 345 | return; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 346 | } |
| 347 | break; |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 348 | } |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 349 | enQueue(set_cfg->hdr->obj_type, temp); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 350 | pthread_mutex_unlock(&lock); |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 351 | sleep(2); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 352 | pthread_cond_signal(&cv); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 353 | #else |
| 354 | if(BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL == set_cfg->hdr->obj_type) |
| 355 | { |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 356 | sleep(5); /* enable this if running with gdb */ |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 357 | } |
| 358 | asfvolt16_bal_cfg_set(set_cfg); |
| 359 | #endif |
| 360 | } |
| 361 | |
| 362 | |
| 363 | /* |
| 364 | * This functions gets invoked whenever bal clear RPC gets called |
| 365 | */ |
| 366 | void bal__bal_cfg_clear_cb(grpc_c_context_t *context) |
| 367 | { |
| 368 | BalKey *clear_key; |
| 369 | |
| 370 | /* |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 371 | * Read incoming message into clear_key |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 372 | */ |
| 373 | if (context->gcc_payload) { |
| 374 | context->gcc_stream->read(context, (void **)&clear_key, 0); |
| 375 | } |
| 376 | |
| 377 | #ifndef BAL_STUB |
| 378 | asfvolt16_bal_cfg_clear(clear_key); |
| 379 | #endif |
| 380 | } |
| 381 | |
| 382 | |
| 383 | /* |
| 384 | * This functions gets invoked whenever bal Init RPC gets called |
| 385 | */ |
| 386 | void bal__bal_api_init_cb(grpc_c_context_t *context) |
| 387 | { |
| 388 | BalInit *bal_init; |
| 389 | BalErr bal_err; |
| 390 | int ret_val; |
| 391 | |
| 392 | /* |
| 393 | * Read incoming message into set_cfg |
| 394 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 395 | if (context->gcc_payload) |
| 396 | { |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 397 | context->gcc_stream->read(context, (void **)&bal_init, 0); |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * send it to BAL |
| 402 | */ |
| 403 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 404 | ASFVOLT_LOG(ASFVOLT_INFO, "Received API Init msg"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 405 | |
| 406 | bal_err__init(&bal_err); |
| 407 | |
| 408 | bal_err.err= 0; |
| 409 | |
| 410 | /* |
| 411 | * Write reply back to the client |
| 412 | */ |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 413 | ret_val = context->gcc_stream->write(context, &bal_err, -1); |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 414 | is_grpc_write_pending(ret_val); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 415 | |
| 416 | grpc_c_status_t status; |
| 417 | status.gcs_code = 0; |
| 418 | |
| 419 | /* |
| 420 | * Finish response for RPC |
| 421 | */ |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 422 | if (context->gcc_stream->finish(context, &status)) |
| 423 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 424 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | #ifndef BAL_STUB |
| 428 | asfvolt16_bal_init(bal_init, &coreIpPortInfo); |
| 429 | #else |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 430 | ASFVOLT_LOG(ASFVOLT_INFO, "Received IP Address == %s", bal_init->voltha_adapter_ip_port); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 431 | stub_bal_init(bal_init); |
| 432 | #endif |
| 433 | |
| 434 | } |
| 435 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 436 | void bal_get_ind__free_mem_access_term_ind(BalIndications *balIndCfg) |
| 437 | { |
| 438 | free(balIndCfg->access_term_ind->data->sw_version); |
| 439 | free(balIndCfg->access_term_ind->data->topology); |
| 440 | free(balIndCfg->access_term_ind->data); |
| 441 | free(balIndCfg->access_term_ind->key); |
| 442 | free(balIndCfg->access_term_ind->hdr); |
| 443 | free(balIndCfg->access_term_ind); |
| 444 | free(balIndCfg); |
| 445 | } |
| 446 | |
| 447 | void bal_get_ind__free_mem_access_term_ind_op_state(BalIndications *balIndCfg) |
| 448 | { |
| 449 | free(balIndCfg->access_term_ind_op_state->data); |
| 450 | free(balIndCfg->access_term_ind_op_state->key); |
| 451 | free(balIndCfg->access_term_ind_op_state->hdr); |
| 452 | free(balIndCfg->access_term_ind_op_state); |
| 453 | free(balIndCfg); |
| 454 | } |
| 455 | |
| 456 | void bal_get_ind__free_mem_flow_op_state(BalIndications *balIndCfg) |
| 457 | { |
| 458 | free(balIndCfg->flow_op_state->data); |
| 459 | free(balIndCfg->flow_op_state->key); |
| 460 | free(balIndCfg->flow_op_state->hdr); |
| 461 | free(balIndCfg->flow_op_state); |
| 462 | free(balIndCfg); |
| 463 | } |
| 464 | |
| 465 | void bal_get_ind__free_mem_flow_ind(BalIndications *balIndCfg) |
| 466 | { |
| 467 | free(balIndCfg->flow_ind->data->action); |
| 468 | free(balIndCfg->flow_ind->data->classifier->src_mac.data); |
| 469 | free(balIndCfg->flow_ind->data->classifier->dst_mac.data); |
| 470 | free(balIndCfg->flow_ind->data->classifier); |
| 471 | free(balIndCfg->flow_ind->data); |
| 472 | free(balIndCfg->flow_ind->key); |
| 473 | free(balIndCfg->flow_ind->hdr); |
| 474 | free(balIndCfg->flow_ind); |
| 475 | free(balIndCfg); |
| 476 | } |
| 477 | |
| 478 | void bal_get_ind__free_mem_group_ind(BalIndications *balIndCfg) |
| 479 | { |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 480 | unsigned int i = 0; |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 481 | free(balIndCfg->group_ind->data->flows->val); |
| 482 | free(balIndCfg->group_ind->data->flows); |
| 483 | for (i = 0; i < balIndCfg->group_ind->data->members->n_val; i++) |
| 484 | { |
| 485 | free(balIndCfg->group_ind->data->members->val[i]->queue); |
| 486 | free(balIndCfg->group_ind->data->members->val[i]->action); |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 487 | free(balIndCfg->group_ind->data->members->val[i]); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 488 | } |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 489 | free(balIndCfg->group_ind->data->members); |
| 490 | free(balIndCfg->group_ind->data); |
| 491 | free(balIndCfg->group_ind->key); |
| 492 | free(balIndCfg->group_ind->hdr); |
| 493 | free(balIndCfg->group_ind); |
| 494 | free(balIndCfg); |
| 495 | } |
| 496 | |
| 497 | void bal_get_ind__free_mem_interface_op_state(BalIndications *balIndCfg) |
| 498 | { |
| 499 | free(balIndCfg->interface_op_state->data); |
| 500 | free(balIndCfg->interface_op_state->key); |
| 501 | free(balIndCfg->interface_op_state->hdr); |
| 502 | free(balIndCfg->interface_op_state); |
| 503 | free(balIndCfg); |
| 504 | } |
| 505 | |
| 506 | void bal_get_ind__free_mem_interface_los(BalIndications *balIndCfg) |
| 507 | { |
| 508 | free(balIndCfg->interface_los->data); |
| 509 | free(balIndCfg->interface_los->hdr); |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 510 | free(balIndCfg->interface_los); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 511 | free(balIndCfg); |
| 512 | } |
| 513 | |
| 514 | void bal_get_ind__free_mem_interface_ind(BalIndications *balIndCfg) |
| 515 | { |
| 516 | free(balIndCfg->interface_ind->data->sub_term_id_list->val); |
| 517 | free(balIndCfg->interface_ind->data->sub_term_id_list); |
| 518 | free(balIndCfg->interface_ind->data); |
| 519 | free(balIndCfg->interface_ind->key); |
| 520 | free(balIndCfg->interface_ind->hdr); |
| 521 | free(balIndCfg->interface_ind); |
| 522 | free(balIndCfg); |
| 523 | } |
| 524 | |
| 525 | void bal_get_ind__free_mem_terminal_op_state(BalIndications *balIndCfg) |
| 526 | { |
| 527 | free(balIndCfg->terminal_op_state->data); |
| 528 | free(balIndCfg->terminal_op_state->key); |
| 529 | free(balIndCfg->terminal_op_state->hdr); |
| 530 | free(balIndCfg->terminal_op_state); |
| 531 | free(balIndCfg); |
| 532 | } |
| 533 | |
| 534 | void bal_get_ind__free_mem_terminal_disc(BalIndications *balIndCfg) |
| 535 | { |
| 536 | free(balIndCfg->terminal_disc->data->serial_number->vendor_specific); |
| 537 | free(balIndCfg->terminal_disc->data->serial_number->vendor_id); |
| 538 | free(balIndCfg->terminal_disc->data->serial_number); |
| 539 | free(balIndCfg->terminal_disc->data); |
| 540 | free(balIndCfg->terminal_disc->key); |
| 541 | free(balIndCfg->terminal_disc->hdr); |
| 542 | free(balIndCfg->terminal_disc); |
| 543 | free(balIndCfg); |
| 544 | } |
| 545 | |
| 546 | void bal_get_ind__free_mem_terminal_alarm(BalIndications *balIndCfg) |
| 547 | { |
| 548 | free(balIndCfg->terminal_alarm->data->alarm); |
| 549 | free(balIndCfg->terminal_alarm->data); |
| 550 | free(balIndCfg->terminal_alarm->key); |
| 551 | free(balIndCfg->terminal_alarm->hdr); |
| 552 | free(balIndCfg->terminal_alarm); |
| 553 | free(balIndCfg); |
| 554 | } |
| 555 | |
| 556 | void bal_get_ind__free_mem_terminal_dgi(BalIndications *balIndCfg) |
| 557 | { |
| 558 | free(balIndCfg->terminal_dgi->data); |
| 559 | free(balIndCfg->terminal_dgi->key); |
| 560 | free(balIndCfg->terminal_dgi->hdr); |
| 561 | free(balIndCfg->terminal_dgi); |
| 562 | free(balIndCfg); |
| 563 | } |
| 564 | |
| 565 | void bal_get_ind__free_mem_terminal_ind(BalIndications *balIndCfg) |
| 566 | { |
| 567 | free(balIndCfg->terminal_ind->data->agg_port_id_list); |
| 568 | free(balIndCfg->terminal_ind->data->serial_number->vendor_specific); |
| 569 | free(balIndCfg->terminal_ind->data->serial_number->vendor_id); |
| 570 | free(balIndCfg->terminal_ind->data->serial_number); |
| 571 | free(balIndCfg->terminal_ind->data->registration_id); |
| 572 | free(balIndCfg->terminal_ind->data->password); |
| 573 | free(balIndCfg->terminal_ind->data); |
| 574 | free(balIndCfg->terminal_ind->key); |
| 575 | free(balIndCfg->terminal_ind->hdr); |
| 576 | free(balIndCfg->terminal_ind); |
| 577 | free(balIndCfg); |
| 578 | } |
| 579 | |
| 580 | void bal_get_ind__free_mem_tm_queue_ind(BalIndications *balIndCfg) |
| 581 | { |
| 582 | switch (balIndCfg->tm_queue_ind->data->bac->type) |
| 583 | { |
| 584 | case BAL_TM_BAC_TYPE__BAL_TM_BAC_TYPE_TAILDROP: |
| 585 | free(balIndCfg->tm_queue_ind->data->bac->taildrop); |
| 586 | break; |
| 587 | case BAL_TM_BAC_TYPE__BAL_TM_BAC_TYPE_WTAILDROP: |
| 588 | /*Nothing to do*/ |
| 589 | break; |
| 590 | case BAL_TM_BAC_TYPE__BAL_TM_BAC_TYPE_RED: |
| 591 | free(balIndCfg->tm_queue_ind->data->bac->red->red); |
| 592 | free(balIndCfg->tm_queue_ind->data->bac->red); |
| 593 | break; |
| 594 | case BAL_TM_BAC_TYPE__BAL_TM_BAC_TYPE_WRED: |
| 595 | free(balIndCfg->tm_queue_ind->data->bac->wred->red); |
| 596 | free(balIndCfg->tm_queue_ind->data->bac->wred->yellow); |
| 597 | free(balIndCfg->tm_queue_ind->data->bac->wred->green); |
| 598 | free(balIndCfg->tm_queue_ind->data->bac->wred); |
| 599 | default: |
| 600 | /*Nothing to do*/ |
| 601 | break; |
| 602 | } |
| 603 | free(balIndCfg->tm_queue_ind->data->bac); |
| 604 | free(balIndCfg->tm_queue_ind->data->rate); |
| 605 | free(balIndCfg->tm_queue_ind->data); |
| 606 | free(balIndCfg->tm_queue_ind->key); |
| 607 | free(balIndCfg->tm_queue_ind); |
| 608 | free(balIndCfg); |
| 609 | } |
| 610 | |
| 611 | void bal_get_ind__free_mem_u_tm_sched_ind(BalIndications *balIndCfg) |
| 612 | { |
| 613 | free(balIndCfg->tm_sched_ind->data); |
| 614 | free(balIndCfg->tm_sched_ind->key); |
| 615 | free(balIndCfg->tm_sched_ind); |
| 616 | free(balIndCfg); |
| 617 | } |
| 618 | |
| 619 | void bal_get_ind__free_mem_u_pkt_data(BalIndications *balIndCfg) |
| 620 | { |
| 621 | free(balIndCfg->pktdata->data->pkt.data); |
| 622 | free(balIndCfg->pktdata->data); |
| 623 | switch(balIndCfg->pktdata->key->packet_send_dest->type) |
| 624 | { |
| 625 | case BAL_DEST_TYPE__BAL_DEST_TYPE_NNI: |
| 626 | free(balIndCfg->pktdata->key->packet_send_dest->nni); |
| 627 | break; |
| 628 | case BAL_DEST_TYPE__BAL_DEST_TYPE_SUB_TERM: |
| 629 | free(balIndCfg->pktdata->key->packet_send_dest->sub_term); |
| 630 | break; |
| 631 | case BAL_DEST_TYPE__BAL_DEST_TYPE_SVC_PORT: |
| 632 | free(balIndCfg->pktdata->key->packet_send_dest->svc_port); |
| 633 | break; |
| 634 | default: |
| 635 | /*Nothing to do*/ |
| 636 | break; |
| 637 | } |
| 638 | free(balIndCfg->pktdata->key->packet_send_dest); |
| 639 | free(balIndCfg->pktdata->key); |
| 640 | free(balIndCfg->pktdata->hdr); |
| 641 | free(balIndCfg->pktdata); |
| 642 | free(balIndCfg); |
| 643 | } |
| 644 | |
| 645 | void bal_get_ind__free_mem_u_bal_omci_resp(BalIndications *balIndCfg) |
| 646 | { |
| 647 | switch(balIndCfg->balomciresp->key->packet_send_dest->type) |
| 648 | { |
| 649 | case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL: |
| 650 | free(balIndCfg->balomciresp->key->packet_send_dest->itu_omci_channel); |
| 651 | break; |
| 652 | default: |
| 653 | /*Nothing to do*/ |
| 654 | break; |
| 655 | } |
| 656 | free(balIndCfg->balomciresp->key->packet_send_dest); |
| 657 | free(balIndCfg->balomciresp->data->pkt.data); |
| 658 | free(balIndCfg->balomciresp->data); |
| 659 | free(balIndCfg->balomciresp->key); |
| 660 | free(balIndCfg->balomciresp->hdr); |
| 661 | free(balIndCfg->balomciresp); |
| 662 | free(balIndCfg); |
| 663 | } |
| 664 | |
| 665 | void bal_get_ind__free_mem_u_bal_oam_resp(BalIndications *balIndCfg) |
| 666 | { |
| 667 | free(balIndCfg->baloamresp->data->pkt.data); |
| 668 | free(balIndCfg->baloamresp->data); |
| 669 | switch(balIndCfg->baloamresp->key->packet_send_dest->type) |
| 670 | { |
| 671 | case BAL_DEST_TYPE__BAL_DEST_TYPE_IEEE_OAM_CHANNEL: |
| 672 | free(balIndCfg->baloamresp->key->packet_send_dest->ieee_oam_channel); |
| 673 | break; |
| 674 | default: |
| 675 | /*Nothing to do*/ |
| 676 | break; |
| 677 | } |
| 678 | free(balIndCfg->baloamresp->key->packet_send_dest); |
| 679 | free(balIndCfg->baloamresp->key); |
| 680 | free(balIndCfg->baloamresp->hdr); |
| 681 | free(balIndCfg->baloamresp); |
| 682 | free(balIndCfg); |
| 683 | } |
| 684 | |
| 685 | void bal_get_ind__free_mem(BalIndications *balIndCfg) |
| 686 | { |
| 687 | switch (balIndCfg->u_case) |
| 688 | { |
| 689 | case BAL_INDICATIONS__U_ACCESS_TERM_IND: |
| 690 | bal_get_ind__free_mem_access_term_ind(balIndCfg); |
| 691 | break; |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 692 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 693 | case BAL_INDICATIONS__U_ACCESS_TERM_IND_OP_STATE: |
| 694 | bal_get_ind__free_mem_access_term_ind_op_state(balIndCfg); |
| 695 | break; |
| 696 | |
| 697 | case BAL_INDICATIONS__U_FLOW_OP_STATE: |
| 698 | bal_get_ind__free_mem_flow_op_state(balIndCfg); |
| 699 | break; |
| 700 | |
| 701 | case BAL_INDICATIONS__U_FLOW_IND: |
| 702 | bal_get_ind__free_mem_flow_ind(balIndCfg); |
| 703 | break; |
| 704 | |
| 705 | case BAL_INDICATIONS__U_GROUP_IND: |
| 706 | bal_get_ind__free_mem_group_ind(balIndCfg); |
| 707 | break; |
| 708 | |
| 709 | case BAL_INDICATIONS__U_INTERFACE_OP_STATE: |
| 710 | bal_get_ind__free_mem_interface_op_state(balIndCfg); |
| 711 | break; |
| 712 | |
| 713 | case BAL_INDICATIONS__U_INTERFACE_LOS: |
| 714 | bal_get_ind__free_mem_interface_los(balIndCfg); |
| 715 | break; |
| 716 | |
| 717 | case BAL_INDICATIONS__U_INTERFACE_IND: |
| 718 | bal_get_ind__free_mem_interface_ind(balIndCfg); |
| 719 | break; |
| 720 | |
| 721 | case BAL_INDICATIONS__U_TERMINAL_OP_STATE: |
| 722 | bal_get_ind__free_mem_terminal_op_state(balIndCfg); |
| 723 | break; |
| 724 | |
| 725 | case BAL_INDICATIONS__U_TERMINAL_DISC: |
| 726 | bal_get_ind__free_mem_terminal_disc(balIndCfg); |
| 727 | break; |
| 728 | |
| 729 | case BAL_INDICATIONS__U_TERMINAL_ALARM: |
| 730 | bal_get_ind__free_mem_terminal_alarm(balIndCfg); |
| 731 | break; |
| 732 | |
| 733 | case BAL_INDICATIONS__U_TERMINAL_DGI: |
| 734 | bal_get_ind__free_mem_terminal_dgi(balIndCfg); |
| 735 | break; |
| 736 | |
| 737 | case BAL_INDICATIONS__U_TERMINAL_IND: |
| 738 | bal_get_ind__free_mem_terminal_ind(balIndCfg); |
| 739 | break; |
| 740 | |
| 741 | case BAL_INDICATIONS__U_TM_QUEUE__IND: |
| 742 | bal_get_ind__free_mem_tm_queue_ind(balIndCfg); |
| 743 | break; |
| 744 | |
| 745 | case BAL_INDICATIONS__U_TM_SCHED__IND: |
| 746 | bal_get_ind__free_mem_u_tm_sched_ind(balIndCfg); |
| 747 | break; |
| 748 | |
| 749 | case BAL_INDICATIONS__U_PKT_DATA: |
| 750 | bal_get_ind__free_mem_u_pkt_data(balIndCfg); |
| 751 | break; |
| 752 | |
| 753 | case BAL_INDICATIONS__U_BAL_OMCI_RESP: |
| 754 | bal_get_ind__free_mem_u_bal_omci_resp(balIndCfg); |
| 755 | break; |
| 756 | |
| 757 | case BAL_INDICATIONS__U_BAL_OAM_RESP: |
| 758 | bal_get_ind__free_mem_u_bal_oam_resp(balIndCfg); |
| 759 | break; |
| 760 | |
| 761 | default: |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 762 | ASFVOLT_LOG(ASFVOLT_ERROR, "Unknown BAL indication %u", balIndCfg->u_case); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 763 | break; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | void bal_get_ind__bal_get_ind_from_device_cb(grpc_c_context_t *context) |
| 768 | { |
| 769 | BalDefault *dummy; |
| 770 | BalIndications *bal_indication; |
| 771 | list_node *node = NULL; |
| 772 | int ret_val = 0; |
| 773 | |
| 774 | /* |
| 775 | * Read incoming message into set_cfg |
| 776 | */ |
| 777 | if (context->gcc_payload) { |
| 778 | context->gcc_stream->read(context, (void **)&dummy, 0); |
| 779 | } |
| 780 | |
| 781 | /* |
| 782 | * send it to BAL |
| 783 | */ |
| 784 | |
| 785 | pthread_mutex_lock(&bal_ind_queue_lock); |
| 786 | node = get_bal_indication_node(); |
| 787 | pthread_mutex_unlock(&bal_ind_queue_lock); |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 788 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 789 | if(node != NULL) |
| 790 | { |
| 791 | bal_indication = node->bal_indication; |
| 792 | bal_indication->ind_present = true; |
| 793 | bal_indication->has_ind_present = true; |
| 794 | } |
| 795 | else |
| 796 | { |
| 797 | bal_indication = malloc(sizeof(BalIndications)); |
| 798 | memset(bal_indication, 0, sizeof(BalIndications)); |
| 799 | bal_indications__init(bal_indication); |
| 800 | bal_indication->ind_present = false; |
| 801 | bal_indication->has_ind_present = true; |
| 802 | } |
| 803 | |
| 804 | /* |
| 805 | * Write reply back to the client |
| 806 | */ |
| 807 | |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 808 | ret_val = context->gcc_stream->write(context, bal_indication, -1); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 809 | is_grpc_write_pending(ret_val); |
| 810 | |
| 811 | grpc_c_status_t status; |
| 812 | status.gcs_code = 0; |
| 813 | |
| 814 | /* |
| 815 | * Finish response for RPC |
| 816 | */ |
| 817 | if (context->gcc_stream->finish(context, &status)) |
| 818 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 819 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to write status"); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 820 | } |
root | 2ca2cc0 | 2017-11-03 19:51:57 +0530 | [diff] [blame] | 821 | |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 822 | /*Free memory for 'bal_indication' and 'node'*/ |
| 823 | if (bal_indication->ind_present) |
| 824 | { |
| 825 | bal_get_ind__free_mem(bal_indication); |
| 826 | free(node); |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | free(bal_indication); |
| 831 | } |
| 832 | } |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 833 | |
| 834 | /* |
| 835 | * This functions gets invoked whenever bal finish RPC gets called |
| 836 | */ |
| 837 | void bal__bal_api_finish_cb(grpc_c_context_t *context) |
| 838 | { |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 839 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 840 | } |
| 841 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 842 | void bal_ind__bal_acc_term_ind_cb(grpc_c_context_t *context) |
| 843 | { |
| 844 | } |
| 845 | void bal_ind__bal_acc_term_oper_sts_cng_ind_cb(grpc_c_context_t *context) |
| 846 | { |
| 847 | } |
| 848 | void bal_ind__bal_flow_oper_sts_cng_cb(grpc_c_context_t *context) |
| 849 | { |
| 850 | } |
| 851 | void bal_ind__bal_flow_ind_cb(grpc_c_context_t *context) |
| 852 | { |
| 853 | } |
| 854 | void bal_ind__bal_group_ind_cb(grpc_c_context_t *context) |
| 855 | { |
| 856 | } |
| 857 | void bal_ind__bal_iface_oper_sts_cng_cb(grpc_c_context_t *context) |
| 858 | { |
| 859 | } |
| 860 | void bal_ind__bal_iface_los_cb(grpc_c_context_t *context) |
| 861 | { |
| 862 | } |
| 863 | void bal_ind__bal_iface_ind_cb(grpc_c_context_t *context) |
| 864 | { |
| 865 | } |
| 866 | void bal_ind__bal_iface_stat_cb(grpc_c_context_t *context) |
| 867 | { |
| 868 | } |
| 869 | void bal_ind__bal_subs_term_oper_sts_cng_cb(grpc_c_context_t *context) |
| 870 | { |
| 871 | } |
| 872 | void bal_ind__bal_subs_term_discovery_ind_cb(grpc_c_context_t *context) |
| 873 | { |
| 874 | } |
| 875 | void bal_ind__bal_subs_term_alarm_ind_cb(grpc_c_context_t *context) |
| 876 | { |
| 877 | } |
| 878 | void bal_ind__bal_subs_term_dgi_ind_cb(grpc_c_context_t *context) |
| 879 | { |
| 880 | } |
| 881 | void bal_ind__bal_subs_term_ind_cb(grpc_c_context_t *context) |
| 882 | { |
| 883 | } |
| 884 | void bal_ind__bal_tm_queue_ind_info_cb(grpc_c_context_t *context) |
| 885 | { |
| 886 | } |
| 887 | void bal_ind__bal_tm_sched_ind_info_cb(grpc_c_context_t *context) |
| 888 | { |
| 889 | } |
| 890 | void bal_ind__bal_pkt_bearer_channel_rx_ind_cb(grpc_c_context_t *context) |
| 891 | { |
| 892 | } |
| 893 | void bal_ind__bal_pkt_omci_channel_rx_ind_cb(grpc_c_context_t *context) |
| 894 | { |
| 895 | } |
| 896 | void bal_ind__bal_pkt_ieee_oam_channel_rx_ind_cb(grpc_c_context_t *context) |
| 897 | { |
| 898 | } |
A R Karthick | 1d25103 | 2017-09-06 09:38:34 -0700 | [diff] [blame] | 899 | |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 900 | /* |
| 901 | ** ASFVOLT_HEX2LOG(ASFVOLT_DEBUG, "OMCI Response with %zd bytes is", |
| 902 | ** balIndCfg.balomciresp->data->pkt.data, balIndCfg.balomciresp->data->pkt.len); |
| 903 | */ |
| 904 | #define SYSLOG_MAX_SIZE 1024 |
| 905 | void asfvolt_hexlog2(int prio, const char *_file_loc, int _file_line, const char *pFormat, void* pData, size_t len) |
| 906 | { |
| 907 | unsigned char *inpPtr = pData; |
| 908 | char tempBuf[SYSLOG_MAX_SIZE]; |
| 909 | size_t idx = 0; |
| 910 | |
| 911 | idx += snprintf(tempBuf+idx, SYSLOG_MAX_SIZE-1, pFormat, len); |
| 912 | while (len-- > 0 && idx < SYSLOG_MAX_SIZE) |
| 913 | { |
| 914 | idx += snprintf(tempBuf+idx, SYSLOG_MAX_SIZE-idx, "%02x", *inpPtr++); |
| 915 | } |
| 916 | ASFVOLT_LOG_LOC(prio, _file_loc, _file_line, "%s", tempBuf); |
| 917 | } |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 918 | |
| 919 | /* |
| 920 | * Takes socket path as argument |
| 921 | */ |
Rajeswara Rao | a3efbca | 2017-09-08 18:01:16 +0530 | [diff] [blame] | 922 | int main (int argc, char **argv) |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 923 | { |
| 924 | int i = 0; |
| 925 | grpc_c_server_t *server = NULL; |
| 926 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 927 | if (argc < 6) |
| 928 | { |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 929 | fprintf(stderr, "Missing socket path argument\n"); |
| 930 | exit(1); |
| 931 | } |
| 932 | |
| 933 | strcpy(coreIpPortInfo.bal_core_arg1, argv[2] /*, strlen(argv[2])*/); |
| 934 | strcpy(coreIpPortInfo.bal_core_ip_port, argv[3]/*, strlen(argv[3])*/); |
| 935 | strcpy(coreIpPortInfo.bal_core_arg2, argv[4]/*, strlen(argv[4])*/); |
| 936 | strcpy(coreIpPortInfo.bal_shared_lib_ip_port, argv[5]/*, strlen(argv[5])*/); |
| 937 | |
| 938 | signal(SIGINT, sigint_handler); |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 939 | |
| 940 | /* |
| 941 | ** syslog initialization |
| 942 | */ |
| 943 | //setlogmask (LOG_UPTO (LOG_NOTICE)); |
| 944 | |
| 945 | openlog (ASFVOLT_SYSLOG_NAME, ASFVOLT_SYSLOG_MODE, LOG_LOCAL1); |
| 946 | |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 947 | /* |
| 948 | * Initialize grpc-c library to be used with vanilla gRPC |
| 949 | */ |
| 950 | grpc_c_init(GRPC_THREADS, NULL); |
| 951 | |
| 952 | /* |
| 953 | * Create server object |
| 954 | */ |
| 955 | test_server = grpc_c_server_create(argv[1]); |
| 956 | |
Rajeswara Rao | 9f1cea1 | 2017-10-10 18:25:29 +0530 | [diff] [blame] | 957 | if (test_server == NULL) |
| 958 | { |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 959 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to create server"); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 960 | exit(1); |
| 961 | } |
| 962 | |
| 963 | /* |
| 964 | * Initialize greeter service |
| 965 | */ |
Kim Kempf | afa1ab4 | 2017-11-13 09:31:47 -0800 | [diff] [blame^] | 966 | ASFVOLT_LOG(ASFVOLT_INFO, "voltha_bal_driver running....."); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 967 | bal__service_init(test_server); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 968 | bal_get_ind__service_init(test_server); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 969 | |
| 970 | /* |
| 971 | * Start server |
| 972 | */ |
| 973 | grpc_c_server_start(test_server); |
| 974 | |
| 975 | #ifdef BAL_STUB |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 976 | create_stub_thread(); |
| 977 | #endif |
| 978 | |
| 979 | /* |
| 980 | * Blocks server to wait to completion |
| 981 | */ |
| 982 | grpc_c_server_wait(test_server); |
| 983 | |
| 984 | /* code added for example Makefile to compile grpc-c along with edgecore driver */ |
| 985 | bal__service_init(server); |
VoLTHA | 753536e | 2017-11-02 20:15:09 +0530 | [diff] [blame] | 986 | bal_get_ind__service_init(server); |
Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 987 | } |