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