Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Optimizations #118

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/dm_easy_mesh_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class dm_easy_mesh_ctrl_t :
int get_network_ssid_config(cJSON *parent, char *key);
int get_channel_config(cJSON *parent, char *key, em_get_channel_list_reason_t reason = em_get_channel_list_reason_none);
int get_policy_config(cJSON *parent, char *key);
int get_reference_config(cJSON *parent, char *key);
int get_config(em_long_string_t net_id, em_subdoc_info_t *subdoc);
int set_config(dm_easy_mesh_t *dm);
int copy_config(dm_easy_mesh_t *dm, em_long_string_t net_id);
Expand Down
2 changes: 2 additions & 0 deletions inc/em.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class em_t :
bool is_matching_freq_band(em_freq_band_t *band);
void set_al_type(bool is_al_mac) {m_is_al_em = is_al_mac;}

em_mgr_t *get_mgr() { return m_mgr; }

void orch_execute(em_cmd_t *pcmd);
em_orch_state_t get_orch_state() { return m_orch_state; }
void set_orch_state(em_orch_state_t state);
Expand Down
1 change: 0 additions & 1 deletion inc/em_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class em_agent_t : public em_mgr_t {
static int mgmt_action_frame_cb(char *event_name, raw_data_t *data);
void *get_assoc(void*);
void io(void *data, bool input = true);
bool agent_input(void *data);
bool agent_output(void *data);

em_agent_t();
Expand Down
12 changes: 5 additions & 7 deletions inc/em_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ extern "C"
#define EM_MAX_STA_PER_STEER_POLICY 16
#define EM_MAX_STA_PER_AGENT (EM_MAX_RADIO_PER_AGENT * EM_MAX_STA_PER_BSS)

//#define EM_SUBDOC_BUFF_SZ 4096*100
#define EM_BUFF_SZ_MUL 20
#define EM_SUBDOC_BUFF_SZ EM_IO_BUFF_SZ*EM_BUFF_SZ_MUL
#define EM_MAX_EVENT_DATA_LEN 4096*100
#define EM_MAX_CHANNELS_IN_LIST 9
#define EM_MAX_CMD_GEN_TTL 10
#define EM_MAX_CMD_EXT_TTL 30
Expand Down Expand Up @@ -208,9 +206,9 @@ typedef char em_string_t[16];
typedef char em_small_string_t[8];
typedef char em_tiny_string_t[4];
typedef char em_subdoc_name_space_t[64];
typedef char em_subdoc_data_buff_t[EM_SUBDOC_BUFF_SZ];
typedef char em_subdoc_data_buff_t[0];
typedef char em_status_string_t[EM_IO_BUFF_SZ];
typedef unsigned char em_raw_data_t[EM_SUBDOC_BUFF_SZ];
typedef unsigned char em_raw_data_t[0];


typedef struct {
Expand Down Expand Up @@ -1849,8 +1847,8 @@ typedef enum {
} em_event_type_t;

typedef struct {
unsigned int frame_len;
unsigned char *frame;
unsigned int len;
} __attribute__((__packed__)) em_frame_info_t;

typedef struct {
Expand Down Expand Up @@ -2426,7 +2424,6 @@ typedef enum {
typedef struct {
em_subdoc_name_space_t name;
em_subdoc_data_buff_t buff;
int sz;
} __attribute__((__packed__)) em_subdoc_info_t;

typedef struct {
Expand Down Expand Up @@ -2690,6 +2687,7 @@ typedef struct {
typedef struct {
em_bus_event_type_t type;
em_cmd_params_t params;
unsigned int data_len;
union {
em_subdoc_info_t subdoc;
em_commit_info_t commit;
Expand Down
1 change: 1 addition & 0 deletions inc/em_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class em_channel_t {
virtual int push_event(em_event_t *evt) = 0;

public:
virtual em_mgr_t *get_mgr() = 0;
virtual dm_easy_mesh_t *get_data_model() = 0;
virtual unsigned char *get_radio_interface_mac() = 0;
virtual em_state_t get_state() = 0;
Expand Down
16 changes: 10 additions & 6 deletions inc/em_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class em_cmd_t {
em_cmd_type_t m_type;
em_service_type_t m_svc;
em_cmd_params_t m_param;
em_event_t m_evt;
em_event_t *m_evt;
em_string_t m_name;
queue_t *m_em_candidates;
dm_easy_mesh_t m_data_model;
Expand All @@ -45,18 +45,22 @@ class em_cmd_t {
public:
bool validate();

char *status_to_string(em_cmd_out_status_t status, em_status_string_t str);
char *status_to_string(em_cmd_out_status_t status, char *str);

em_cmd_type_t get_type() { return m_type; }
const char *get_cmd_name() { return m_name; }
const char *get_arg() { return m_param.u.args.fixed_args; }
em_service_type_t get_svc() { return m_svc; }
em_event_t *get_event() { return &m_evt; }
em_event_t *get_event() { return m_evt; }
unsigned int get_event_length() { return (sizeof(em_event_t) + get_event_data_length()); }
unsigned int get_event_data_length();
void set_event_data_length(unsigned int len);
em_cmd_params_t *get_param() { return &m_param; }
em_bus_event_t *get_bus_event() { return &m_evt.u.bevt; }
em_bus_event_t *get_bus_event() { return &m_evt->u.bevt; }
dm_easy_mesh_t *get_data_model() { return &m_data_model; }

void copy_bus_event(em_bus_event_t *evt) { m_evt.type = em_event_type_bus; memcpy(&m_evt.u.bevt, evt, sizeof(em_bus_event_t)); }
void copy_bus_event(em_bus_event_t *evt);
void copy_frame_event(em_frame_event_t *evt);

em_orch_desc_t *get_orch_desc() { return &m_orch_desc[m_orch_op_idx]; }
dm_orch_type_t get_orch_op() { return m_orch_desc[m_orch_op_idx].op; }
Expand Down Expand Up @@ -91,7 +95,7 @@ class em_cmd_t {

void set_start_time() { gettimeofday(&m_start_time, NULL);}

void reset() { memset(&m_evt, 0, sizeof(em_event_t)); memset(&m_param, 0, sizeof(em_cmd_params_t));; }
void reset() { memset(m_evt, 0, sizeof(em_event_t)); memset(&m_param, 0, sizeof(em_cmd_params_t));; }
void init(dm_easy_mesh_t *dm);
void init();
void deinit();
Expand Down
2 changes: 1 addition & 1 deletion inc/em_cmd_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class em_cmd_cli_t : public em_cmd_exec_t {
static em_cmd_t m_client_cmd_spec[];
public:
int get_edited_node(em_network_node_t *node, const char *header, char *buff);
int execute(em_long_string_t result);
int execute(char *result);
int update_platform_defaults(em_subdoc_info_t *info, em_cmd_params_t *param, em_cmd_type_t cmd_type);

em_cmd_cli_t(em_cmd_t& obj);
Expand Down
2 changes: 1 addition & 1 deletion inc/em_cmd_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class em_cmd_ctrl_t : public em_cmd_exec_t {
em_ctrl_t& m_ctrl = g_ctrl;
int m_dsock;
public:
int execute(em_long_string_t result);
int execute(char *result);
int send_result(em_cmd_out_status_t status);

em_cmd_ctrl_t();
Expand Down
5 changes: 4 additions & 1 deletion inc/em_cmd_exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class em_cmd_exec_t {
//char *get_result() { return m_cmd.get_result(); }
bool validate() { return m_cmd.validate(); }
em_event_t *get_event() { return m_cmd.get_event(); }
unsigned int get_event_length() { return m_cmd.get_event_length(); }
unsigned int get_event_data_length() { return m_cmd.get_event_data_length(); }
void set_event_data_length(unsigned int len) { m_cmd.set_event_data_length(len); }
em_cmd_t *get_cmd() { return &m_cmd; }
em_cmd_params_t *get_param() { return m_cmd.get_param(); }
em_cmd_type_t get_type() { return m_cmd.m_type; }
Expand All @@ -50,7 +53,7 @@ class em_cmd_exec_t {
static char *get_path_from_dst_service(em_service_type_t to_svc, em_long_string_t sock_path);
static int load_params_file(const char *filename, char *buff);

virtual int execute(em_long_string_t result) = 0;
virtual int execute(char *result) = 0;
void release_wait();
void wait(struct timespec *time_to_wait);

Expand Down
2 changes: 2 additions & 0 deletions inc/em_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "dm_easy_mesh.h"

class em_cmd_t;
class em_mgr_t;
class em_configuration_t {

int create_autoconfig_resp_msg(unsigned char *buff, em_freq_band_t band, unsigned char *dst);
Expand Down Expand Up @@ -73,6 +74,7 @@ class em_configuration_t {
// helpers
void fill_media_data(em_media_spec_data_t *spec);

virtual em_mgr_t *get_mgr() = 0;
virtual dm_easy_mesh_t *get_data_model() = 0;
virtual em_state_t get_state() = 0;
virtual void set_state(em_state_t state) = 0;
Expand Down
1 change: 0 additions & 1 deletion inc/em_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class em_ctrl_t : public em_mgr_t {
void handle_sta_assoc_event(em_bus_event_t *evt);

void io(void *data, bool input = true);
bool io_process(em_event_t *evt);

dm_easy_mesh_t *get_data_model(const char *net_id, const unsigned char *al_mac = NULL) { return m_data_model.get_data_model(net_id, al_mac); }
dm_easy_mesh_t *create_data_model(const char *net_id, const unsigned char *al_mac, em_profile_type_t profile = em_profile_type_3) { return m_data_model.create_data_model(net_id, al_mac, profile); }
Expand Down
4 changes: 4 additions & 0 deletions inc/em_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class em_mgr_t {

virtual em_service_type_t get_service_type() = 0;

bool io_process(em_event_t *evt);
void io_process(em_bus_event_type_t type, char *data, unsigned int len);
void io_process(em_bus_event_type_t type, unsigned char *data, unsigned int len);

em_mgr_t();
~em_mgr_t();
};
Expand Down
1 change: 1 addition & 0 deletions inc/em_steering.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class em_steering_t {
short create_btm_request_tlv(unsigned char *buff);

public:
virtual em_mgr_t *get_mgr() = 0;
virtual int send_frame(unsigned char *buff, unsigned int len, bool multicast = false) = 0;
virtual dm_easy_mesh_t *get_data_model() = 0;
virtual unsigned char *get_radio_interface_mac() = 0;
Expand Down
48 changes: 7 additions & 41 deletions src/agent/em_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ void em_agent_t::input_listener()
{
wifi_bus_desc_t *desc;
dm_easy_mesh_t dm;
em_event_t evt;
em_bus_event_t *bevt;
raw_data_t data;

bus_init(&m_bus_hdl);
Expand All @@ -426,11 +424,7 @@ void em_agent_t::input_listener()
printf("%s:%d recv data:\r\n%s\r\n", __func__, __LINE__, (char *)data.raw_data.bytes);
}

bevt = &evt.u.bevt;
bevt->type = em_bus_event_type_dev_init;
memcpy(bevt->u.raw_buff, data.raw_data.bytes, data.raw_data_len);

g_agent.agent_input(&evt);
g_agent.io_process(em_bus_event_type_dev_init, (unsigned char *)data.raw_data.bytes, data.raw_data_len);

if (desc->bus_event_subs_fn(&m_bus_hdl, WIFI_WEBCONFIG_DOC_DATA_NORTH, (void *)&em_agent_t::onewifi_cb, NULL, 0) != 0) {
printf("%s:%d bus get failed\n", __func__, __LINE__);
Expand All @@ -457,18 +451,11 @@ void em_agent_t::input_listener()

int em_agent_t::mgmt_action_frame_cb(char *event_name, raw_data_t *data)
{
em_bus_event_t *bevt;
em_event_t evt;
struct ieee80211_mgmt *btm_frame = (struct ieee80211_mgmt *)data->raw_data.bytes;

//printf("Received Frame data for event %s \n", event_name);
if(btm_frame->u.action.u.bss_tm_resp.action == WLAN_WNM_BTM_RESPONSE)
{
bevt = &evt.u.bevt;
bevt->type = em_bus_event_type_btm_response;
memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len);

g_agent.agent_input(&evt);
if (btm_frame->u.action.u.bss_tm_resp.action == WLAN_WNM_BTM_RESPONSE) {
g_agent.io_process(em_bus_event_type_btm_response, (unsigned char *)data->raw_data.bytes, data->raw_data_len);

return 1;
}
Expand All @@ -479,8 +466,6 @@ int em_agent_t::mgmt_action_frame_cb(char *event_name, raw_data_t *data)
int em_agent_t::assoc_stats_cb(char *event_name, raw_data_t *data)
{
//printf("%s:%d recv data:\r\n%s\r\n", __func__, __LINE__, (char *)data->raw_data.bytes);
em_event_t evt;
em_bus_event_t *bevt;
cJSON *json, *assoc_stats_arr;

json = cJSON_Parse((const char *)data->raw_data.bytes);
Expand All @@ -495,33 +480,20 @@ int em_agent_t::assoc_stats_cb(char *event_name, raw_data_t *data)
}
}

bevt = &evt.u.bevt;
bevt->type = em_bus_event_type_sta_link_metrics;
memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len);

g_agent.agent_input(&evt);
g_agent.io_process(em_bus_event_type_sta_link_metrics, (unsigned char *)data->raw_data.bytes, data->raw_data_len);

return 1;
}

int em_agent_t::sta_cb(char *event_name, raw_data_t *data)
{
//printf("%s:%d Recv data from onewifi:\r\n%s\r\n", __func__, __LINE__, (char *)data->raw_data.bytes);
em_event_t evt;
em_bus_event_t *bevt;

bevt = &evt.u.bevt;
bevt->type = em_bus_event_type_sta_list;
memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len);

g_agent.agent_input(&evt);
g_agent.io_process(em_bus_event_type_sta_list, (unsigned char *)data->raw_data.bytes, data->raw_data_len);

}

int em_agent_t::onewifi_cb(char *event_name, raw_data_t *data)
{
em_event_t evt;
em_bus_event_t *bevt;
const char *json_data = (char *)data->raw_data.bytes;
cJSON *json = cJSON_Parse(json_data);

Expand All @@ -535,16 +507,12 @@ int em_agent_t::onewifi_cb(char *event_name, raw_data_t *data)
if ((strcmp(subdoc_name->valuestring, "private") == 0) || (strcmp(subdoc_name->valuestring, "Vap_5G") == 0) ||
(strcmp(subdoc_name->valuestring, "Vap_2.4G") == 0)) {
printf("%s:%d Found SubDocName: private\n", __func__, __LINE__);
bevt = &evt.u.bevt;
bevt->type = em_bus_event_type_onewifi_private_cb;
memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len);
g_agent.io_process(em_bus_event_type_onewifi_private_cb, (unsigned char *)data->raw_data.bytes, data->raw_data_len);

} else if ((strcmp(subdoc_name->valuestring, "radio") == 0) || (strcmp(subdoc_name->valuestring, "radio_5G") == 0) ||
(strcmp(subdoc_name->valuestring, "radio_2.4G") == 0)) {
printf("%s:%d Found SubDocName: radio\n", __func__, __LINE__);
bevt = &evt.u.bevt;
bevt->type = em_bus_event_type_onewifi_radio_cb;
memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len);
g_agent.io_process(em_bus_event_type_onewifi_radio_cb, (unsigned char *)data->raw_data.bytes, data->raw_data_len);

} else {
printf("%s:%d SubDocName not matching private or radio \n", __func__, __LINE__);
Expand All @@ -557,8 +525,6 @@ int em_agent_t::onewifi_cb(char *event_name, raw_data_t *data)
cJSON_Delete(json);
}

g_agent.agent_input(&evt);

}

int em_agent_t::data_model_init(const char *data_model_path)
Expand Down
31 changes: 0 additions & 31 deletions src/agent/em_agent_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,6 @@
#include "util.h"


bool em_agent_t::agent_input(void *data)
{
em_event_t *evt;
em_bus_event_t *inp;
bool ret = true;
em_bus_event_t *bevt;

inp = &((em_event_t *)data)->u.bevt;

if ((inp->type == em_bus_event_type_dev_init) || (inp->type == em_bus_event_type_sta_list) || (inp->type == em_bus_event_type_onewifi_private_cb) || (inp->type == em_bus_event_type_m2ctrl_configuration) || (inp->type == em_bus_event_type_cfg_renew) || (inp->type == em_bus_event_type_channel_pref_query) || (inp->type == em_bus_event_type_channel_sel_req) || (inp->type == em_bus_event_type_onewifi_radio_cb)
|| (inp->type == em_bus_event_type_sta_link_metrics)
|| (inp->type == em_bus_event_type_bss_tm_req)
|| (inp->type == em_bus_event_type_btm_response)) {
evt = (em_event_t *)malloc(sizeof(em_event_t));
evt->type = em_event_type_bus;
bevt = &evt->u.bevt;
bevt->type = inp->type;
memcpy(&bevt->u.raw_buff, inp->u.raw_buff, sizeof(inp->u.raw_buff));
} else {
evt = em_cmd_agent_t::create_event((char *)inp->u.subdoc.buff);
}
if (evt != NULL) {
push_to_queue(evt);
} else {
if (strncmp(m_data_model_path, "sim", strlen("sim")) == 0) {
ret = false;
}
}
return ret;
}

bool em_agent_t::agent_output(void *data)
{
// send configuration to OneWifi after translating
Expand Down
Loading
Loading