From 2bac071ba3130e732524b6ba649085d16d99ec1f Mon Sep 17 00:00:00 2001 From: Soumya Munshi <167132989+soumyasmunshi@users.noreply.github.com> Date: Sun, 15 Dec 2024 05:26:03 -0800 Subject: [PATCH] CLI Optimization --- inc/em.h | 7 +- inc/em_base.h | 2 +- inc/em_channel.h | 1 + inc/em_cli.h | 1 - inc/em_cmd_cli.h | 3 +- inc/em_configuration.h | 1 + src/cli/em_cli.cpp | 26 ----- src/cli/em_cmd_cli.cpp | 222 ++++++++++++++++---------------------- src/cli/main.c | 28 ++++- src/cli/main.go | 4 +- src/em/em.cpp | 13 ++- src/em/em_mgr.cpp | 2 +- src/orch/em_orch.cpp | 7 +- src/orch/em_orch_ctrl.cpp | 4 + 14 files changed, 148 insertions(+), 173 deletions(-) diff --git a/inc/em.h b/inc/em.h index 0751b4d..9c4d426 100644 --- a/inc/em.h +++ b/inc/em.h @@ -33,6 +33,8 @@ #include "dm_easy_mesh.h" #include "em_sm.h" +class em_mgr_t; + class em_t : public em_configuration_t, public em_discovery_t, public em_provisioning_t, public em_channel_t, @@ -40,6 +42,7 @@ class em_t : public em_steering_t, public em_policy_cfg_t { dm_easy_mesh_t* m_data_model; + em_mgr_t *m_mgr; em_orch_state_t m_orch_state; em_cmd_t *m_cmd; @@ -65,7 +68,7 @@ class em_t : int start_al_interface(); int send_frame(unsigned char *buff, unsigned int len, bool multicast = false); int send_cmd(em_cmd_type_t type, em_service_type_t svc, unsigned char *buff, unsigned int len); - + int push_event(em_event_t *evt); public: @@ -168,7 +171,7 @@ class em_t : static const char *get_band_type_str(em_freq_band_t band); static const char *state_2_str(em_state_t state); - em_t(em_interface_t *ruid, em_freq_band_t band, dm_easy_mesh_t *dm, em_profile_type_t profile, em_service_type_t type); + em_t(em_interface_t *ruid, em_freq_band_t band, dm_easy_mesh_t *dm, em_mgr_t *mgr, em_profile_type_t profile, em_service_type_t type); ~em_t(); }; diff --git a/inc/em_base.h b/inc/em_base.h index 1989f1d..f81b167 100644 --- a/inc/em_base.h +++ b/inc/em_base.h @@ -200,7 +200,6 @@ typedef char em_subdoc_data_buff_t[EM_SUBDOC_BUFF_SZ]; typedef char em_status_string_t[EM_IO_BUFF_SZ]; typedef unsigned char em_raw_data_t[EM_SUBDOC_BUFF_SZ]; -typedef int (* em_editor_callback_t)(char *); typedef struct { unsigned char dsap; @@ -2709,5 +2708,6 @@ typedef struct em_network_node { struct em_network_node *child[EM_MAX_DM_CHILDREN]; } em_network_node_t; +typedef int (* em_editor_callback_t)(em_network_node_t *); #endif // EM_BASE_H diff --git a/inc/em_channel.h b/inc/em_channel.h index b60808e..c5def6a 100644 --- a/inc/em_channel.h +++ b/inc/em_channel.h @@ -25,6 +25,7 @@ class em_cmd_t; class em_channel_t { virtual int send_frame(unsigned char *buff, unsigned int len, bool multicast = false) = 0; + virtual int push_event(em_event_t *evt) = 0; public: virtual dm_easy_mesh_t *get_data_model() = 0; diff --git a/inc/em_cli.h b/inc/em_cli.h index 5dfff68..3e26974 100644 --- a/inc/em_cli.h +++ b/inc/em_cli.h @@ -28,7 +28,6 @@ class em_cli_t { public: em_editor_callback_t m_editor_cb; - char *exec(char *in, size_t in_len, em_status_string_t out); em_network_node_t *exec(char *in, size_t in_len); int init(em_editor_callback_t func); const char *get_first_cmd_str(); diff --git a/inc/em_cmd_cli.h b/inc/em_cmd_cli.h index 51de331..4f08fec 100644 --- a/inc/em_cmd_cli.h +++ b/inc/em_cmd_cli.h @@ -32,8 +32,7 @@ class em_cmd_cli_t : public em_cmd_exec_t { static em_cmd_t m_client_cmd_spec[]; public: static int load_params_file(const char *filename, char *buff); - int write_params_file(const char *filename, char *buff, const char *net_id, const char *header = NULL); - int edit_params_file(const char *filename); + int get_edited_node(em_network_node_t *node, const char *header, char *buff); int execute(em_long_string_t result); int update_platform_defaults(em_subdoc_info_t *info, em_cmd_params_t *param, em_cmd_type_t cmd_type); diff --git a/inc/em_configuration.h b/inc/em_configuration.h index 1cc9dfc..4ce4644 100644 --- a/inc/em_configuration.h +++ b/inc/em_configuration.h @@ -86,6 +86,7 @@ class em_configuration_t { virtual em_crypto_info_t *get_crypto_info() = 0; virtual em_crypto_t *get_crypto() = 0; virtual int send_frame(unsigned char *buff, unsigned int len, bool multicast = false) = 0; + virtual int push_event(em_event_t *evt) = 0; virtual em_cmd_t *get_current_cmd() = 0; virtual short create_ap_radio_basic_cap(unsigned char *buff) = 0; virtual bool is_al_interface_em() = 0; diff --git a/src/cli/em_cli.cpp b/src/cli/em_cli.cpp index 6d41148..67bbdc3 100644 --- a/src/cli/em_cli.cpp +++ b/src/cli/em_cli.cpp @@ -471,32 +471,6 @@ em_cmd_t& em_cli_t::get_command(char *in, size_t in_len) return em_cmd_cli_t::m_client_cmd_spec[idx]; } -char *em_cli_t::exec(char *in, size_t sz, em_status_string_t out) -{ - em_long_string_t cmd; - em_status_string_t res; - em_cmd_cli_t *cli_cmd; - - snprintf(cmd, sizeof(cmd), "%s", in); - cli_cmd = new em_cmd_cli_t(get_command(cmd, sz)); - - cli_cmd->init(); - - if (cli_cmd->validate() == false) { - cli_cmd->m_cmd.status_to_string(em_cmd_out_status_invalid_input, res); - } else { - if (cli_cmd->execute(res) != 0) { - cli_cmd->m_cmd.status_to_string(em_cmd_out_status_invalid_input, res); - - } - } - - snprintf(out, EM_IO_BUFF_SZ, "%s", res); - delete cli_cmd; - - return out; -} - em_network_node_t *em_cli_t::exec(char *in, size_t sz) { em_long_string_t cmd; diff --git a/src/cli/em_cmd_cli.cpp b/src/cli/em_cmd_cli.cpp index cf254e8..d0d9665 100644 --- a/src/cli/em_cmd_cli.cpp +++ b/src/cli/em_cmd_cli.cpp @@ -161,75 +161,57 @@ int em_cmd_cli_t::load_params_file(const char *filename, char *buff) return sz; } -int em_cmd_cli_t::write_params_file(const char *filename, char *buff, const char *net_id, const char *header) -{ - FILE *fp; - char tmp[EM_IO_BUFF_SZ]; - unsigned int sz = 0; - - em_long_string_t wfa; - cJSON *obj, *res_obj, *wfa_obj; - - obj = cJSON_Parse(buff); - if (obj == NULL) { - printf("%s:%d: Failed to parse\n", __func__, __LINE__); - return -1; - } - - if ((res_obj = cJSON_GetObjectItem(obj, "Result")) == NULL) { - printf("%s:%d: Failed to parse\n", __func__, __LINE__); - cJSON_free(obj); - return -1; - } - - if (header != NULL) { - snprintf(wfa, sizeof(wfa), "wfa-dataelements:%s", header); - wfa_obj = cJSON_CreateObject(); - if (wfa_obj == NULL) { - printf("%s:%d: Failed to parse\n", __func__, __LINE__); - cJSON_free(obj); - return -1; - } - cJSON_AddItemToObject(wfa_obj, wfa, res_obj); - cJSON_AddStringToObject(res_obj, "ID", net_id); - } else { - wfa_obj = res_obj; - } - - cJSON_PrintPreallocated(wfa_obj, tmp, EM_IO_BUFF_SZ, true); - - cJSON_free(obj); - - if ((fp = fopen(filename, "w")) == NULL) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, filename, errno); - return -1; - } else { - fputs(tmp, fp); - fclose(fp); - } - - return strlen(buff); -} - - -int em_cmd_cli_t::edit_params_file(const char *filename) +int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, char *buff) { - char buff[EM_IO_BUFF_SZ]; cJSON *obj; - - m_cli.m_editor_cb((char *)filename); - - if (load_params_file(filename, buff) < 0) { - printf("%s:%d: Failed to load params file\n", __func__, __LINE__); - return -1; - } - - if ((obj = cJSON_Parse(buff)) == NULL) { - printf("%s:%d: Failed to read file\n", __func__, __LINE__); + em_network_node_t *new_node, *tmp; + em_network_node_t *child; + bool found_result = false; + unsigned int i; + char *net_id = m_cmd.m_param.u.args.args[1], *formatted; + + for (i = 0; i < node->num_children; i++) { + child = node->child[i]; + if (strncmp(child->key, "Result", strlen("Result")) == 0) { + found_result = true; + break; + } + } + + if (found_result == false) { + printf("%s:%d: Could not find child with Result\n", __func__, __LINE__); return -1; } + + snprintf(child->key, sizeof(em_long_string_t), "wfa-dataelements:%s", header); - return 0; + tmp = (em_network_node_t *)malloc(sizeof(em_network_node_t)); + memset(tmp, 0, sizeof(em_network_node_t)); + strncpy(tmp->key, "ID", strlen("ID") + 1); + tmp->type = em_network_node_data_type_string; + strncpy(tmp->value_str, net_id, strlen(net_id) + 1); + + child->child[child->num_children] = tmp; + child->num_children++; + + + new_node = (em_network_node_t *)malloc(sizeof(em_network_node_t)); + memset(new_node, 0, sizeof(em_network_node_t)); + new_node->type = node->type; + new_node->child[new_node->num_children] = child; + new_node->num_children++; + + free(node); + + m_cli.m_editor_cb(new_node); + obj = (cJSON *)get_cli()->network_tree_to_json(new_node); + formatted = cJSON_Print((cJSON *)get_cli()->network_tree_to_json(new_node)); + strncpy(buff, formatted, strlen(formatted) + 1); + cJSON_Delete(obj); + + get_cli()->free_network_tree(new_node); + + return strlen(formatted) + 1; } @@ -246,6 +228,7 @@ int em_cmd_cli_t::execute(em_string_t res) unsigned char *tmp; em_long_string_t in, sock_path; em_status_string_t out; + em_network_node_t *node; evt = get_event(); param = get_param(); @@ -341,19 +324,16 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_remove_device: snprintf(in, sizeof(in), "get_device %s 1", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "RemoveDevice"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_remove_device; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "RemoveDevice", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; - } + } break; case em_cmd_type_get_radio: @@ -364,20 +344,16 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_set_radio: snprintf(in, sizeof(in), "get_radio %s 1", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "RadioEnable"); - bevt->type = em_bus_event_type_set_radio; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_set_radio; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "RadioEnable", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; - } + } break; case em_cmd_type_get_ssid: @@ -388,19 +364,16 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_set_ssid: snprintf(in, sizeof(in), "get_ssid %s", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "SetSSID"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_set_ssid; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "SetSSID", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; - } + } break; case em_cmd_type_get_channel: @@ -411,37 +384,30 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_set_channel: snprintf(in, sizeof(in), "get_channel %s 1", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "SetAnticipatedChannelPreference"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_set_channel; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "SetAnticipatedChannelPreference", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; - } + } break; case em_cmd_type_scan_channel: snprintf(in, sizeof(in), "get_channel %s 2", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "ChannelScanRequest"); - bevt->type = em_bus_event_type_set_radio; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_scan_channel; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "ChannelScanRequest", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; - } + } break; case em_cmd_type_get_policy: @@ -453,19 +419,16 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_set_policy: snprintf(in, sizeof(in), "get_policy %s", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "SetPolicy"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_set_policy; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "SetPolicy", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; - } + } break; case em_cmd_type_get_bss: @@ -482,16 +445,13 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_steer_sta: snprintf(in, sizeof(em_long_string_t), "get_sta %s 1", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "ClientSteer"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_steer_sta; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "ClientSteer", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -499,16 +459,13 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_disassoc_sta: snprintf(in, sizeof(em_long_string_t), "get_sta %s 2", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "Disassociate"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_disassoc_sta; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); - return -1; - } info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((info->sz = get_edited_node(node, "Disassociate", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -516,14 +473,15 @@ int em_cmd_cli_t::execute(em_string_t res) case em_cmd_type_btm_sta: snprintf(in, sizeof(em_long_string_t), "get_sta %s 3", m_cmd.m_param.u.args.args[1]); - get_cli()->exec(in, strlen(in), out); - write_params_file(m_cmd.m_param.u.args.fixed_args, out, m_cmd.m_param.u.args.args[1], "BTMRequest"); + if ((node = get_cli()->exec(in, strlen(in))) == NULL) { + return -1; + } bevt->type = em_bus_event_type_btm_sta; - if (edit_params_file(m_cmd.m_param.u.args.fixed_args) != 0) { + info = &bevt->u.subdoc; + if ((info->sz = get_edited_node(node, "BTMRequest", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } - info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); diff --git a/src/cli/main.c b/src/cli/main.c index bd62f01..ec822f9 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -46,12 +46,28 @@ const char *prompt = "<>: "; -int editor(char *args) +int editor(em_network_node_t *node) { em_long_string_t cmd; + cJSON *obj; + FILE *fp = NULL; - snprintf(cmd, sizeof(em_long_string_t), "vi %s", args); - system(cmd); + obj = (cJSON *)network_tree_to_json(node); + if (obj == NULL) { + return -1; + } + + if ((fp = fopen("tmp.json", "w")) == NULL) { + printf("%s:%d: failed to open file error:%d\n", __func__, __LINE__, errno); + return -1; + } else { + fputs(cJSON_Print(obj), fp); + fclose(fp); + } + + system("vi tmp.json"); + + cJSON_Delete(obj); return 0; } @@ -60,6 +76,7 @@ int main(int argc, const char *argv[]) { char *line = NULL; em_network_node_t *node; + cJSON *obj; init(editor); @@ -83,7 +100,10 @@ int main(int argc, const char *argv[]) } if ((node = exec(line, strlen(line))) != NULL) { - print_network_tree(node); + if ((obj = (cJSON *)network_tree_to_json(node)) != NULL) { + printf("%s\n", cJSON_Print(obj)); + cJSON_Delete(obj); + } free_network_tree(node); } } diff --git a/src/cli/main.go b/src/cli/main.go index 48b6691..ff249c4 100644 --- a/src/cli/main.go +++ b/src/cli/main.go @@ -7,7 +7,7 @@ package main #include #include "em_cli_apis.h" -extern int editor_func(char *s); +extern int editor_func(em_network_node_t *node); static int register_editor_cb() { return init(editor_func); @@ -21,7 +21,7 @@ import ( ) //export editor_func -func editor_func(*C.char) C.int { +func editor_func(*C.em_network_node_t) C.int { fmt.Println("Inside Go Callnack") return 0 } diff --git a/src/em/em.cpp b/src/em/em.cpp index c896bb1..094a95e 100644 --- a/src/em/em.cpp +++ b/src/em/em.cpp @@ -853,6 +853,16 @@ short em_t::create_cac_cap_tlv(unsigned char *buff) return len; } +int em_t::push_event(em_event_t *evt) +{ + em_event_t *e; + + e = (em_event_t *)malloc(sizeof(em_event_t)); + memcpy(e, evt, sizeof(em_event_t)); + + m_mgr->push_to_queue(e); +} + int em_t::init() { //m_data_model->print_config(); @@ -929,7 +939,7 @@ const char *em_t::get_band_type_str(em_freq_band_t band) return "band_type_unknown"; } -em_t::em_t(em_interface_t *ruid, em_freq_band_t band, dm_easy_mesh_t *dm, em_profile_type_t profile, em_service_type_t type) +em_t::em_t(em_interface_t *ruid, em_freq_band_t band, dm_easy_mesh_t *dm, em_mgr_t *mgr, em_profile_type_t profile, em_service_type_t type) { memcpy(&m_ruid, ruid, sizeof(em_interface_t)); m_band = band; @@ -941,6 +951,7 @@ em_t::em_t(em_interface_t *ruid, em_freq_band_t band, dm_easy_mesh_t *dm, em_pro RAND_bytes(get_crypto_info()->e_nonce, sizeof(em_nonce_t)); RAND_bytes(get_crypto_info()->r_nonce, sizeof(em_nonce_t)); m_data_model = dm; + m_mgr = mgr; } em_t::~em_t() diff --git a/src/em/em_mgr.cpp b/src/em/em_mgr.cpp index 4fd418d..f0beb75 100644 --- a/src/em/em_mgr.cpp +++ b/src/em/em_mgr.cpp @@ -121,7 +121,7 @@ em_t *em_mgr_t::create_node(em_interface_t *ruid, em_freq_band_t band, dm_easy_m return em; } - em = new em_t(ruid, band, dm, profile, type); + em = new em_t(ruid, band, dm, this, profile, type); em->set_al_type(is_al_mac); if (em->init() != 0) { delete em; diff --git a/src/orch/em_orch.cpp b/src/orch/em_orch.cpp index 003d967..9cfeb59 100644 --- a/src/orch/em_orch.cpp +++ b/src/orch/em_orch.cpp @@ -201,12 +201,13 @@ bool em_orch_t::orchestrate(em_cmd_t *pcmd, em_t *em) //printf("%s:%d: Start orchestartion:%s(%s), em state:%s\n", __func__, __LINE__, //em_cmd_t::get_orch_op_str(pcmd->get_orch_op()), em_cmd_t::get_cmd_type_str(pcmd->m_type), //em_t::state_2_str(em->get_state())); - pcmd->set_start_time(); em->orch_execute(pcmd); } else { //printf("%s:%d: skipping orchestration:%s(%s) because of incorrect state, state:%s\n", __func__, __LINE__, //em_cmd_t::get_orch_op_str(pcmd->get_orch_op()), em_cmd_t::get_cmd_type_str(pcmd->m_type), //em_t::state_2_str(em->get_state())); + update_stats(pcmd); + orch_transient(pcmd, em); } } else if (orch_state == em_orch_state_progress) { @@ -287,6 +288,8 @@ void em_orch_t::handle_timeout() em->set_orch_state(em_orch_state_pending); } + // as soon as command is pushed to active start timing + pcmd->set_start_time(); queue_push(m_active, pcmd); } else { if ((cnt = queue_count(m_pending))) { @@ -299,6 +302,8 @@ void em_orch_t::handle_timeout() // go through active queue and check command states for (i = queue_count(m_active) - 1; i >= 0; i--) { pcmd = (em_cmd_t *)queue_peek(m_active, i); + //printf("%s:%d: Cmd: %s, em candidates: %d\n", __func__, __LINE__, + //em_cmd_t::get_cmd_type_str(pcmd->m_type), queue_count(pcmd->m_em_candidates)); for (j = queue_count(pcmd->m_em_candidates) - 1; j >= 0; j--) { em = (em_t *)queue_peek(pcmd->m_em_candidates, j); ret &= orchestrate(pcmd, em); diff --git a/src/orch/em_orch_ctrl.cpp b/src/orch/em_orch_ctrl.cpp index 079f492..48981e8 100644 --- a/src/orch/em_orch_ctrl.cpp +++ b/src/orch/em_orch_ctrl.cpp @@ -50,6 +50,10 @@ void em_orch_ctrl_t::orch_transient(em_cmd_t *pcmd, em_t *em) stats = (em_cmd_stats_t *)hash_map_get(m_cmd_map, key); assert(stats != NULL); + //printf("%s:%d: Orchestration:%s(%s) state:%s, time in transient:%d\n", __func__, __LINE__, + //em_cmd_t::get_orch_op_str(pcmd->get_orch_op()), em_cmd_t::get_cmd_type_str(pcmd->m_type), + //em_t::state_2_str(em->get_state()), stats->time); + switch (pcmd->m_type) { case em_cmd_type_em_config: if (stats->time > (EM_MAX_CMD_GEN_TTL + EM_MAX_CMD_EXT_TTL)) {