From 734f6a51352bb18446668d61edae3f776739f8a6 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Fri, 8 Mar 2024 14:51:21 +0800 Subject: [PATCH] rename config -> options --- src/config/config.cpp | 158 +++++++++--------- src/config/config.h | 10 +- src/ip_reassembly/ip_reassembly.cpp | 28 ++-- src/ip_reassembly/ip_reassembly.h | 4 +- .../test/gtest_ipv4_reassembly.cpp | 24 +-- .../test/gtest_ipv6_reassembly.cpp | 24 +-- src/packet_io/packet_io.cpp | 30 ++-- src/packet_io/packet_io.h | 4 +- src/packet_io/packet_io_dumpfile.cpp | 6 +- src/packet_io/packet_io_dumpfile.h | 4 +- src/packet_io/packet_io_marsio.cpp | 10 +- src/packet_io/packet_io_marsio.h | 4 +- src/session/session_manager.cpp | 104 ++++++------ src/session/session_manager.h | 4 +- src/session/test/gtest_filter_tcp_dupkt.cpp | 22 +-- .../test/gtest_filter_udp_eviction.cpp | 20 +-- .../test/gtest_overload_evict_tcp_sess.cpp | 18 +- .../test/gtest_overload_evict_udp_sess.cpp | 18 +- .../gtest_state_tcp_active_to_closing.cpp | 12 +- .../test/gtest_state_tcp_init_to_opening.cpp | 16 +- ...opening_to_active_to_closing_to_closed.cpp | 2 +- .../gtest_state_tcp_opening_to_active.cpp | 4 +- .../gtest_state_tcp_opening_to_closing.cpp | 16 +- ...p_init_to_opening_to_active_to_closing.cpp | 2 +- ...t_state_udp_init_to_opening_to_closing.cpp | 4 +- src/session/test/gtest_timeout_tcp_data.cpp | 6 +- .../test/gtest_timeout_tcp_half_closed.cpp | 12 +- .../test/gtest_timeout_tcp_handshake.cpp | 6 +- src/session/test/gtest_timeout_tcp_init.cpp | 12 +- src/session/test/gtest_timeout_udp_data.cpp | 8 +- src/session/test/test_utils.h | 62 +++---- src/stellar/stellar.cpp | 18 +- 32 files changed, 336 insertions(+), 336 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index b9bf209..e56aae6 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -7,7 +7,7 @@ // return 0: success // retuun -1: failed -static int parse_device_config(struct device_config *dev_cfg, toml_table_t *conf_file_handle) +static int parse_device_options(struct device_options *dev_opts, toml_table_t *conf_file_handle) { const char *ptr; toml_table_t *device_table; @@ -25,7 +25,7 @@ static int parse_device_config(struct device_config *dev_cfg, toml_table_t *conf CONFIG_LOG_ERROR("config file missing device.device_base"); return -1; } - dev_cfg->device_base = atoi(ptr); + dev_opts->device_base = atoi(ptr); ptr = toml_raw_in(device_table, "device_offset"); if (ptr == NULL) @@ -33,14 +33,14 @@ static int parse_device_config(struct device_config *dev_cfg, toml_table_t *conf CONFIG_LOG_ERROR("config file missing device.device_offset"); return -1; } - dev_cfg->device_offset = atoi(ptr); + dev_opts->device_offset = atoi(ptr); return 0; } // return 0: success // retuun -1: failed -static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_table_t *conf_file_handle) +static int parse_packet_io_options(struct packet_io_options *pkt_io_opts, toml_table_t *conf_file_handle) { const char *ptr; toml_table_t *packet_io_table; @@ -61,11 +61,11 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl } if (strcmp(ptr, "dumpfile") == 0) { - pkt_io_cfg->mode = PACKET_IO_DUMPFILE; + pkt_io_opts->mode = PACKET_IO_DUMPFILE; } else if (strcmp(ptr, "marsio") == 0) { - pkt_io_cfg->mode = PACKET_IO_MARSIO; + pkt_io_opts->mode = PACKET_IO_MARSIO; } else { @@ -73,7 +73,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl return -1; } - if (pkt_io_cfg->mode == PACKET_IO_DUMPFILE) + if (pkt_io_opts->mode == PACKET_IO_DUMPFILE) { ptr = toml_raw_in(packet_io_table, "dumpfile_dir"); if (ptr == NULL) @@ -82,7 +82,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl return -1; } // skip "" - strncpy(pkt_io_cfg->dumpfile_dir, ptr + 1, strlen(ptr) - 2); + strncpy(pkt_io_opts->dumpfile_dir, ptr + 1, strlen(ptr) - 2); } else { @@ -92,7 +92,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl CONFIG_LOG_ERROR("config file missing packet_io.app_symbol"); return -1; } - strncpy(pkt_io_cfg->app_symbol, ptr, sizeof(pkt_io_cfg->app_symbol) - 1); + strncpy(pkt_io_opts->app_symbol, ptr, sizeof(pkt_io_opts->app_symbol) - 1); ptr = toml_raw_in(packet_io_table, "dev_symbol"); if (ptr == NULL) @@ -100,7 +100,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl CONFIG_LOG_ERROR("config file missing packet_io.dev_symbol"); return -1; } - strncpy(pkt_io_cfg->dev_symbol, ptr, sizeof(pkt_io_cfg->dev_symbol) - 1); + strncpy(pkt_io_opts->dev_symbol, ptr, sizeof(pkt_io_opts->dev_symbol) - 1); } ptr = toml_raw_in(packet_io_table, "nr_threads"); @@ -114,7 +114,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl CONFIG_LOG_ERROR("config file invalid packet_io.nr_threads %d, range [1, %d]", atoi(ptr), MAX_THREAD_NUM); return -1; } - pkt_io_cfg->nr_threads = atoi(ptr); + pkt_io_opts->nr_threads = atoi(ptr); mask_array = toml_array_in(packet_io_table, "cpu_mask"); if (mask_array == NULL) @@ -122,7 +122,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl CONFIG_LOG_ERROR("config file missing packet_io.cpu_mask"); return -1; } - for (uint8_t i = 0; i < pkt_io_cfg->nr_threads; i++) + for (uint8_t i = 0; i < pkt_io_opts->nr_threads; i++) { ptr = toml_raw_at(mask_array, i); if (ptr == NULL) @@ -130,7 +130,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl CONFIG_LOG_ERROR("config file missing packet_io.cpu_mask[%d]", i); return -1; } - pkt_io_cfg->cpu_mask[i] = atoi(ptr); + pkt_io_opts->cpu_mask[i] = atoi(ptr); } return 0; @@ -138,7 +138,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl // return 0: success // retuun -1: failed -static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg, toml_table_t *conf_file_handle) +static int parse_ip_reassembly_options(struct ip_reassembly_options *ip_reass_opts, toml_table_t *conf_file_handle) { const char *ptr; toml_table_t *ip_reass_table; @@ -156,7 +156,7 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg, CONFIG_LOG_ERROR("config file missing ip_reassembly.enable"); return -1; } - ip_reass_cfg->enable = atoi(ptr); + ip_reass_opts->enable = atoi(ptr); ptr = toml_raw_in(ip_reass_table, "timeout"); if (ptr == NULL) @@ -164,7 +164,7 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg, CONFIG_LOG_ERROR("config file missing ip_reassembly.timeout"); return -1; } - ip_reass_cfg->timeout = atoi(ptr); + ip_reass_opts->timeout = atoi(ptr); ptr = toml_raw_in(ip_reass_table, "bucket_entries"); if (ptr == NULL) @@ -172,7 +172,7 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg, CONFIG_LOG_ERROR("config file missing ip_reassembly.bucket_entries"); return -1; } - ip_reass_cfg->bucket_entries = atoi(ptr); + ip_reass_opts->bucket_entries = atoi(ptr); ptr = toml_raw_in(ip_reass_table, "bucket_num"); if (ptr == NULL) @@ -180,14 +180,14 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg, CONFIG_LOG_ERROR("config file missing ip_reassembly.bucket_num"); return -1; } - ip_reass_cfg->bucket_num = atoi(ptr); + ip_reass_opts->bucket_num = atoi(ptr); return 0; } // return 0: success // retuun -1: failed -static int parse_session_manager_section(struct session_manager_config *sess_mgr_cfg, toml_table_t *conf_file_handle) +static int parse_session_manager_options(struct session_manager_options *sess_mgr_opts, toml_table_t *conf_file_handle) { const char *ptr; toml_table_t *sess_mgr_table; @@ -206,7 +206,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.max_tcp_session_num"); return -1; } - sess_mgr_cfg->max_tcp_session_num = atoll(ptr); + sess_mgr_opts->max_tcp_session_num = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "max_udp_session_num"); if (ptr == NULL) @@ -214,7 +214,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.max_udp_session_num"); return -1; } - sess_mgr_cfg->max_udp_session_num = atoll(ptr); + sess_mgr_opts->max_udp_session_num = atoll(ptr); // session overload (1: evict old session, 0: bypass new session) ptr = toml_raw_in(sess_mgr_table, "tcp_overload_evict_old_sess"); @@ -223,7 +223,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_overload_evict_old_sess"); return -1; } - sess_mgr_cfg->tcp_overload_evict_old_sess = atoi(ptr); + sess_mgr_opts->tcp_overload_evict_old_sess = atoi(ptr); ptr = toml_raw_in(sess_mgr_table, "udp_overload_evict_old_sess"); if (ptr == NULL) @@ -231,7 +231,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.udp_overload_evict_old_sess"); return -1; } - sess_mgr_cfg->udp_overload_evict_old_sess = atoi(ptr); + sess_mgr_opts->udp_overload_evict_old_sess = atoi(ptr); // TCP timeout ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_init"); @@ -240,7 +240,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_init"); return -1; } - sess_mgr_cfg->tcp_timeout_init = atoll(ptr); + sess_mgr_opts->tcp_timeout_init = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_handshake"); if (ptr == NULL) @@ -248,7 +248,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_handshake"); return -1; } - sess_mgr_cfg->tcp_timeout_handshake = atoll(ptr); + sess_mgr_opts->tcp_timeout_handshake = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_data"); if (ptr == NULL) @@ -256,7 +256,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_data"); return -1; } - sess_mgr_cfg->tcp_timeout_data = atoll(ptr); + sess_mgr_opts->tcp_timeout_data = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_half_closed"); if (ptr == NULL) @@ -264,7 +264,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_half_closed"); return -1; } - sess_mgr_cfg->tcp_timeout_half_closed = atoll(ptr); + sess_mgr_opts->tcp_timeout_half_closed = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_time_wait"); if (ptr == NULL) @@ -272,7 +272,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_time_wait"); return -1; } - sess_mgr_cfg->tcp_timeout_time_wait = atoll(ptr); + sess_mgr_opts->tcp_timeout_time_wait = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_discard"); if (ptr == NULL) @@ -280,7 +280,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_discard"); return -1; } - sess_mgr_cfg->tcp_timeout_discard = atoll(ptr); + sess_mgr_opts->tcp_timeout_discard = atoll(ptr); // UDP timeout ptr = toml_raw_in(sess_mgr_table, "udp_timeout_data"); @@ -289,7 +289,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.udp_timeout_data"); return -1; } - sess_mgr_cfg->udp_timeout_data = atoll(ptr); + sess_mgr_opts->udp_timeout_data = atoll(ptr); // TCP duplicate packet filter ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_enable"); @@ -298,7 +298,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_enable"); return -1; } - sess_mgr_cfg->tcp_dupkt_filter_enable = atoi(ptr); + sess_mgr_opts->tcp_dupkt_filter_enable = atoi(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_capacity"); if (ptr == NULL) @@ -306,7 +306,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_capacity"); return -1; } - sess_mgr_cfg->tcp_dupkt_filter_capacity = atoll(ptr); + sess_mgr_opts->tcp_dupkt_filter_capacity = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_timeout"); if (ptr == NULL) @@ -314,7 +314,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_timeout"); return -1; } - sess_mgr_cfg->tcp_dupkt_filter_timeout = atoll(ptr); + sess_mgr_opts->tcp_dupkt_filter_timeout = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_error_rate"); if (ptr == NULL) @@ -322,7 +322,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_error_rate"); return -1; } - sess_mgr_cfg->tcp_dupkt_filter_error_rate = atof(ptr); + sess_mgr_opts->tcp_dupkt_filter_error_rate = atof(ptr); // UDP eviction filter ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_enable"); @@ -331,7 +331,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_enable"); return -1; } - sess_mgr_cfg->udp_eviction_filter_enable = atoi(ptr); + sess_mgr_opts->udp_eviction_filter_enable = atoi(ptr); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_capacity"); if (ptr == NULL) @@ -339,7 +339,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_capacity"); return -1; } - sess_mgr_cfg->udp_eviction_filter_capacity = atoll(ptr); + sess_mgr_opts->udp_eviction_filter_capacity = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_timeout"); if (ptr == NULL) @@ -347,7 +347,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_timeout"); return -1; } - sess_mgr_cfg->udp_eviction_filter_timeout = atoll(ptr); + sess_mgr_opts->udp_eviction_filter_timeout = atoll(ptr); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_error_rate"); if (ptr == NULL) @@ -355,7 +355,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_error_rate"); return -1; } - sess_mgr_cfg->udp_eviction_filter_error_rate = atof(ptr); + sess_mgr_opts->udp_eviction_filter_error_rate = atof(ptr); return 0; } @@ -385,22 +385,22 @@ int config_load(struct config *cfg, const char *cfg_file) goto error_out; } - if (parse_device_config(&cfg->dev_cfg, conf_file_handle) != 0) + if (parse_device_options(&cfg->dev_opts, conf_file_handle) != 0) { goto error_out; } - if (parse_packet_io_config(&cfg->pkt_io_cfg, conf_file_handle) != 0) + if (parse_packet_io_options(&cfg->pkt_io_opts, conf_file_handle) != 0) { goto error_out; } - if (parse_ip_reassembly_config(&cfg->ip_reass_cfg, conf_file_handle) != 0) + if (parse_ip_reassembly_options(&cfg->ip_reass_opts, conf_file_handle) != 0) { goto error_out; } - if (parse_session_manager_section(&cfg->sess_mgr_cfg, conf_file_handle) != 0) + if (parse_session_manager_options(&cfg->sess_mgr_opts, conf_file_handle) != 0) { goto error_out; } @@ -428,61 +428,61 @@ void config_dump(struct config *cfg) return; } - struct device_config *dev_cfg = &cfg->dev_cfg; - struct packet_io_config *pkt_io_cfg = &cfg->pkt_io_cfg; - struct ip_reassembly_config *ip_reass_cfg = &cfg->ip_reass_cfg; - struct session_manager_config *sess_mgr_cfg = &cfg->sess_mgr_cfg; + struct device_options *dev_opts = &cfg->dev_opts; + struct packet_io_options *pkt_io_opts = &cfg->pkt_io_opts; + struct ip_reassembly_options *ip_reass_opts = &cfg->ip_reass_opts; + struct session_manager_options *sess_mgr_opts = &cfg->sess_mgr_opts; // device config - CONFIG_LOG_DEBUG("device->device_base : %d", dev_cfg->device_base); - CONFIG_LOG_DEBUG("device->device_offset : %d", dev_cfg->device_offset); + CONFIG_LOG_DEBUG("device->device_base : %d", dev_opts->device_base); + CONFIG_LOG_DEBUG("device->device_offset : %d", dev_opts->device_offset); // packet io config - CONFIG_LOG_DEBUG("packet_io->mode : %s", pkt_io_cfg->mode == PACKET_IO_DUMPFILE ? "dumpfile" : "marsio"); - if (pkt_io_cfg->mode == PACKET_IO_DUMPFILE) + CONFIG_LOG_DEBUG("packet_io->mode : %s", pkt_io_opts->mode == PACKET_IO_DUMPFILE ? "dumpfile" : "marsio"); + if (pkt_io_opts->mode == PACKET_IO_DUMPFILE) { - CONFIG_LOG_DEBUG("packet_io->dumpfile_dir : %s", pkt_io_cfg->dumpfile_dir); + CONFIG_LOG_DEBUG("packet_io->dumpfile_dir : %s", pkt_io_opts->dumpfile_dir); } else { - CONFIG_LOG_DEBUG("packet_io->app_symbol : %s", pkt_io_cfg->app_symbol); - CONFIG_LOG_DEBUG("packet_io->dev_symbol : %s", pkt_io_cfg->dev_symbol); + CONFIG_LOG_DEBUG("packet_io->app_symbol : %s", pkt_io_opts->app_symbol); + CONFIG_LOG_DEBUG("packet_io->dev_symbol : %s", pkt_io_opts->dev_symbol); } - CONFIG_LOG_DEBUG("packet_io->nr_threads : %d", pkt_io_cfg->nr_threads); - for (uint8_t i = 0; i < pkt_io_cfg->nr_threads; i++) + CONFIG_LOG_DEBUG("packet_io->nr_threads : %d", pkt_io_opts->nr_threads); + for (uint8_t i = 0; i < pkt_io_opts->nr_threads; i++) { - CONFIG_LOG_DEBUG("packet_io->cpu_mask[%03d] : %d", i, pkt_io_cfg->cpu_mask[i]); + CONFIG_LOG_DEBUG("packet_io->cpu_mask[%03d] : %d", i, pkt_io_opts->cpu_mask[i]); } // ip reassemble config - CONFIG_LOG_DEBUG("ip_reassembly->enable : %d", ip_reass_cfg->enable); - CONFIG_LOG_DEBUG("ip_reassembly->timeout : %d", ip_reass_cfg->timeout); - CONFIG_LOG_DEBUG("ip_reassembly->bucket_entries : %d", ip_reass_cfg->bucket_entries); - CONFIG_LOG_DEBUG("ip_reassembly->bucket_num : %d", ip_reass_cfg->bucket_num); + CONFIG_LOG_DEBUG("ip_reassembly->enable : %d", ip_reass_opts->enable); + CONFIG_LOG_DEBUG("ip_reassembly->timeout : %d", ip_reass_opts->timeout); + CONFIG_LOG_DEBUG("ip_reassembly->bucket_entries : %d", ip_reass_opts->bucket_entries); + CONFIG_LOG_DEBUG("ip_reassembly->bucket_num : %d", ip_reass_opts->bucket_num); // session manager config - CONFIG_LOG_DEBUG("session_manager->max_tcp_session_num : %ld", sess_mgr_cfg->max_tcp_session_num); - CONFIG_LOG_DEBUG("session_manager->max_udp_session_num : %ld", sess_mgr_cfg->max_udp_session_num); + CONFIG_LOG_DEBUG("session_manager->max_tcp_session_num : %ld", sess_mgr_opts->max_tcp_session_num); + CONFIG_LOG_DEBUG("session_manager->max_udp_session_num : %ld", sess_mgr_opts->max_udp_session_num); - CONFIG_LOG_DEBUG("session_manager->tcp_overload_evict_old_sess : %d", sess_mgr_cfg->tcp_overload_evict_old_sess); - CONFIG_LOG_DEBUG("session_manager->udp_overload_evict_old_sess : %d", sess_mgr_cfg->udp_overload_evict_old_sess); + CONFIG_LOG_DEBUG("session_manager->tcp_overload_evict_old_sess : %d", sess_mgr_opts->tcp_overload_evict_old_sess); + CONFIG_LOG_DEBUG("session_manager->udp_overload_evict_old_sess : %d", sess_mgr_opts->udp_overload_evict_old_sess); - CONFIG_LOG_DEBUG("session_manager->tcp_timeout_init : %ld", sess_mgr_cfg->tcp_timeout_init); - CONFIG_LOG_DEBUG("session_manager->tcp_timeout_handshake : %ld", sess_mgr_cfg->tcp_timeout_handshake); - CONFIG_LOG_DEBUG("session_manager->tcp_timeout_data : %ld", sess_mgr_cfg->tcp_timeout_data); - CONFIG_LOG_DEBUG("session_manager->tcp_timeout_half_closed : %ld", sess_mgr_cfg->tcp_timeout_half_closed); - CONFIG_LOG_DEBUG("session_manager->tcp_timeout_time_wait : %ld", sess_mgr_cfg->tcp_timeout_time_wait); - CONFIG_LOG_DEBUG("session_manager->tcp_timeout_discard : %ld", sess_mgr_cfg->tcp_timeout_discard); + CONFIG_LOG_DEBUG("session_manager->tcp_timeout_init : %ld", sess_mgr_opts->tcp_timeout_init); + CONFIG_LOG_DEBUG("session_manager->tcp_timeout_handshake : %ld", sess_mgr_opts->tcp_timeout_handshake); + CONFIG_LOG_DEBUG("session_manager->tcp_timeout_data : %ld", sess_mgr_opts->tcp_timeout_data); + CONFIG_LOG_DEBUG("session_manager->tcp_timeout_half_closed : %ld", sess_mgr_opts->tcp_timeout_half_closed); + CONFIG_LOG_DEBUG("session_manager->tcp_timeout_time_wait : %ld", sess_mgr_opts->tcp_timeout_time_wait); + CONFIG_LOG_DEBUG("session_manager->tcp_timeout_discard : %ld", sess_mgr_opts->tcp_timeout_discard); - CONFIG_LOG_DEBUG("session_manager->udp_timeout_data : %ld", sess_mgr_cfg->udp_timeout_data); + CONFIG_LOG_DEBUG("session_manager->udp_timeout_data : %ld", sess_mgr_opts->udp_timeout_data); - CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_enable : %d", sess_mgr_cfg->tcp_dupkt_filter_enable); - CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_capacity : %ld", sess_mgr_cfg->tcp_dupkt_filter_capacity); - CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_timeout : %ld", sess_mgr_cfg->tcp_dupkt_filter_timeout); - CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_error_rate : %f", sess_mgr_cfg->tcp_dupkt_filter_error_rate); + CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_enable : %d", sess_mgr_opts->tcp_dupkt_filter_enable); + CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_capacity : %ld", sess_mgr_opts->tcp_dupkt_filter_capacity); + CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_timeout : %ld", sess_mgr_opts->tcp_dupkt_filter_timeout); + CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_error_rate : %f", sess_mgr_opts->tcp_dupkt_filter_error_rate); - CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_enable : %d", sess_mgr_cfg->udp_eviction_filter_enable); - CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_capacity : %ld", sess_mgr_cfg->udp_eviction_filter_capacity); - CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_timeout : %ld", sess_mgr_cfg->udp_eviction_filter_timeout); - CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_error_rate : %f", sess_mgr_cfg->udp_eviction_filter_error_rate); + CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_enable : %d", sess_mgr_opts->udp_eviction_filter_enable); + CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_capacity : %ld", sess_mgr_opts->udp_eviction_filter_capacity); + CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_timeout : %ld", sess_mgr_opts->udp_eviction_filter_timeout); + CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_error_rate : %f", sess_mgr_opts->udp_eviction_filter_error_rate); } diff --git a/src/config/config.h b/src/config/config.h index 2fd6d2e..85a0a7f 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -22,7 +22,7 @@ extern "C" fprintf(stderr, "DEBUG (config), " format "\n", ##__VA_ARGS__); #endif -struct device_config +struct device_options { uint8_t device_base; uint8_t device_offset; @@ -30,10 +30,10 @@ struct device_config struct config { - struct device_config dev_cfg; - struct packet_io_config pkt_io_cfg; - struct ip_reassembly_config ip_reass_cfg; - struct session_manager_config sess_mgr_cfg; + struct device_options dev_opts; + struct packet_io_options pkt_io_opts; + struct ip_reassembly_options ip_reass_opts; + struct session_manager_options sess_mgr_opts; }; int config_load(struct config *cfg, const char *cfg_file); diff --git a/src/ip_reassembly/ip_reassembly.cpp b/src/ip_reassembly/ip_reassembly.cpp index c87fc57..98d5740 100644 --- a/src/ip_reassembly/ip_reassembly.cpp +++ b/src/ip_reassembly/ip_reassembly.cpp @@ -110,7 +110,7 @@ struct ip_flow struct ip_reassembly { - // config + // options bool enable; uint32_t timeout; uint32_t bucket_entries; @@ -189,29 +189,29 @@ static inline int is_power_of_2(uint32_t n) return n && !(n & (n - 1)); } -static inline int ip_reassembly_check_config(const struct ip_reassembly_config *config) +static inline int ip_reassembly_check_options(const struct ip_reassembly_options *opts) { - if (config == NULL) + if (opts == NULL) { - IP_REASSEMBLE_DEBUG("invalid config"); + IP_REASSEMBLE_DEBUG("invalid options"); return -1; } - if (config->enable) + if (opts->enable) { - if (config->timeout == 0) + if (opts->timeout == 0) { IP_REASSEMBLE_DEBUG("invalid timeout"); return -1; } - if (config->bucket_entries == 0 || is_power_of_2(config->bucket_entries) == 0) + if (opts->bucket_entries == 0 || is_power_of_2(opts->bucket_entries) == 0) { IP_REASSEMBLE_DEBUG("invalid bucket entries, must be power of 2"); return -1; } - if (config->bucket_num == 0) + if (opts->bucket_num == 0) { IP_REASSEMBLE_DEBUG("invalid bucket num"); return -1; @@ -752,9 +752,9 @@ error_out_overlap: * Public API ******************************************************************************/ -struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_config *config) +struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts) { - if (ip_reassembly_check_config(config) != 0) + if (ip_reassembly_check_options(opts) != 0) { return NULL; } @@ -765,10 +765,10 @@ struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_config *confi IP_REASSEMBLE_ERROR("unable to allocate memory"); return NULL; } - mgr->enable = config->enable; - mgr->timeout = config->timeout; - mgr->bucket_entries = config->bucket_entries; - mgr->bucket_num = config->bucket_num; + mgr->enable = opts->enable; + mgr->timeout = opts->timeout; + mgr->bucket_entries = opts->bucket_entries; + mgr->bucket_num = opts->bucket_num; if (!mgr->enable) { diff --git a/src/ip_reassembly/ip_reassembly.h b/src/ip_reassembly/ip_reassembly.h index 0315a96..d1c8b6d 100644 --- a/src/ip_reassembly/ip_reassembly.h +++ b/src/ip_reassembly/ip_reassembly.h @@ -12,7 +12,7 @@ extern "C" #define IP_REASSEMBLE_DEBUG(format, ...) LOG_DEBUG("ip_reassembly", format, ##__VA_ARGS__) #define IP_REASSEMBLE_ERROR(format, ...) LOG_ERROR("ip_reassembly", format, ##__VA_ARGS__) -struct ip_reassembly_config +struct ip_reassembly_options { bool enable; @@ -50,7 +50,7 @@ struct ip_reassembly_stat uint64_t ip6_flow_bypass_dup_last_frag; }; -struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_config *config); +struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts); void ip_reassembly_free(struct ip_reassembly *mgr); void ip_reassembly_expire(struct ip_reassembly *mgr); void ip_reassembly_print_stat(struct ip_reassembly *mgr); diff --git a/src/ip_reassembly/test/gtest_ipv4_reassembly.cpp b/src/ip_reassembly/test/gtest_ipv4_reassembly.cpp index 0955015..73c4c11 100644 --- a/src/ip_reassembly/test/gtest_ipv4_reassembly.cpp +++ b/src/ip_reassembly/test/gtest_ipv4_reassembly.cpp @@ -198,7 +198,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -207,7 +207,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -293,7 +293,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -302,7 +302,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -387,7 +387,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE) struct packet pkt; struct packet *new_pkt; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -396,7 +396,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -445,7 +445,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -454,7 +454,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -551,7 +551,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -560,7 +560,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -656,7 +656,7 @@ TEST(IPV4_REASSEMBLE, FULL) struct packet pkt; struct packet *new_pkt; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 1, @@ -665,7 +665,7 @@ TEST(IPV4_REASSEMBLE, FULL) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), diff --git a/src/ip_reassembly/test/gtest_ipv6_reassembly.cpp b/src/ip_reassembly/test/gtest_ipv6_reassembly.cpp index f73d38b..ce9892a 100644 --- a/src/ip_reassembly/test/gtest_ipv6_reassembly.cpp +++ b/src/ip_reassembly/test/gtest_ipv6_reassembly.cpp @@ -609,7 +609,7 @@ TEST(IPV6_REASSEMBLE, NORMAL) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -618,7 +618,7 @@ TEST(IPV6_REASSEMBLE, NORMAL) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -719,7 +719,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE) struct packet pkt; struct packet *new_pkt; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -728,7 +728,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -777,7 +777,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -786,7 +786,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -899,7 +899,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG) struct packet *new_pkt; const struct layer_record *layer; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -908,7 +908,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -1021,7 +1021,7 @@ TEST(IPV6_REASSEMBLE, FULL) struct packet *new_pkt; struct in6_addr src_addr; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 1, @@ -1030,7 +1030,7 @@ TEST(IPV6_REASSEMBLE, FULL) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), @@ -1092,7 +1092,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP) struct packet pkt; struct packet *new_pkt; struct ip_reassembly *mgr; - struct ip_reassembly_config config = { + struct ip_reassembly_options opts = { .enable = true, .timeout = 1, .bucket_entries = 16, @@ -1101,7 +1101,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP) timestamp_update(); - mgr = ip_reassembly_new(&config); + mgr = ip_reassembly_new(&opts); EXPECT_TRUE(mgr != NULL); // ip_reassembly_print_stat(mgr); check_stat(ip_reassembly_get_stat(mgr), diff --git a/src/packet_io/packet_io.cpp b/src/packet_io/packet_io.cpp index 5fa2472..ebf4839 100644 --- a/src/packet_io/packet_io.cpp +++ b/src/packet_io/packet_io.cpp @@ -5,7 +5,7 @@ #include "packet_io_marsio.h" #include "packet_io_dumpfile.h" -typedef void *new_cb(void *config); +typedef void *new_cb(void *options); typedef void free_cb(void *handle); typedef void *stat_cb(void *handle); typedef int init_cb(void *handle, uint16_t thread_id); @@ -23,7 +23,7 @@ struct packet_io send_cb *on_send; }; -struct packet_io *packet_io_new(struct packet_io_config *config) +struct packet_io *packet_io_new(struct packet_io_options *opts) { struct packet_io *handle = (struct packet_io *)calloc(1, sizeof(struct packet_io)); if (handle == NULL) @@ -32,21 +32,21 @@ struct packet_io *packet_io_new(struct packet_io_config *config) return NULL; } - struct packet_io_marsio_confg marsio_config; - strncpy(marsio_config.app_symbol, config->app_symbol, sizeof(marsio_config.app_symbol)); - strncpy(marsio_config.dev_symbol, config->dev_symbol, sizeof(marsio_config.dev_symbol)); - memcpy(marsio_config.cpu_mask, config->cpu_mask, sizeof(marsio_config.cpu_mask)); - marsio_config.nr_threads = config->nr_threads; + struct packet_io_marsio_opts marsio_opts; + strncpy(marsio_opts.app_symbol, opts->app_symbol, sizeof(marsio_opts.app_symbol)); + strncpy(marsio_opts.dev_symbol, opts->dev_symbol, sizeof(marsio_opts.dev_symbol)); + memcpy(marsio_opts.cpu_mask, opts->cpu_mask, sizeof(marsio_opts.cpu_mask)); + marsio_opts.nr_threads = opts->nr_threads; - struct packet_io_dumpfile_confg dumpfile_config; - strncpy(dumpfile_config.dumpfile_dir, config->dumpfile_dir, sizeof(dumpfile_config.dumpfile_dir)); - dumpfile_config.nr_threads = config->nr_threads; + struct packet_io_dumpfile_opts dumpfile_opts; + strncpy(dumpfile_opts.dumpfile_dir, opts->dumpfile_dir, sizeof(dumpfile_opts.dumpfile_dir)); + dumpfile_opts.nr_threads = opts->nr_threads; - void *_config = NULL; + void *_opts = NULL; - if (config->mode == PACKET_IO_MARSIO) + if (opts->mode == PACKET_IO_MARSIO) { - _config = &marsio_config; + _opts = &marsio_opts; handle->on_new = (new_cb *)packet_io_marsio_new; handle->on_free = (free_cb *)packet_io_marsio_free; handle->on_stat = (stat_cb *)packet_io_marsio_stat; @@ -56,7 +56,7 @@ struct packet_io *packet_io_new(struct packet_io_config *config) } else { - _config = &dumpfile_config; + _opts = &dumpfile_opts; handle->on_new = (new_cb *)packet_io_dumpfile_new; handle->on_free = (free_cb *)packet_io_dumpfile_free; handle->on_stat = (stat_cb *)packet_io_dumpfile_stat; @@ -65,7 +65,7 @@ struct packet_io *packet_io_new(struct packet_io_config *config) handle->on_send = (send_cb *)packet_io_dumpfile_send; } - handle->handle = handle->on_new(_config); + handle->handle = handle->on_new(_opts); if (handle->handle == NULL) { goto error_out; diff --git a/src/packet_io/packet_io.h b/src/packet_io/packet_io.h index 46d28b1..0e9b1d2 100644 --- a/src/packet_io/packet_io.h +++ b/src/packet_io/packet_io.h @@ -37,7 +37,7 @@ enum packet_io_mode PACKET_IO_MARSIO = 1, }; -struct packet_io_config +struct packet_io_options { enum packet_io_mode mode; @@ -53,7 +53,7 @@ struct packet_io_config }; struct packet_io; -struct packet_io *packet_io_new(struct packet_io_config *config); +struct packet_io *packet_io_new(struct packet_io_options *opts); void packet_io_free(struct packet_io *handle); void packet_io_print_stat(struct packet_io *handle); struct packet_io_stat *packet_io_get_stat(struct packet_io *handle); diff --git a/src/packet_io/packet_io_dumpfile.cpp b/src/packet_io/packet_io_dumpfile.cpp index 6b50825..9675058 100644 --- a/src/packet_io/packet_io_dumpfile.cpp +++ b/src/packet_io/packet_io_dumpfile.cpp @@ -91,7 +91,7 @@ static void *dumpfile_thread_cycle(void *arg) * Public API ******************************************************************************/ -struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_confg *config) +struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_opts *opts) { pthread_t tid; struct packet_io_dumpfile *handle = (struct packet_io_dumpfile *)calloc(1, sizeof(struct packet_io_dumpfile)); @@ -101,8 +101,8 @@ struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_conf return NULL; } - handle->nr_threads = config->nr_threads; - strncpy(handle->dumpfile_dir, config->dumpfile_dir, sizeof(handle->dumpfile_dir)); + handle->nr_threads = opts->nr_threads; + strncpy(handle->dumpfile_dir, opts->dumpfile_dir, sizeof(handle->dumpfile_dir)); for (uint16_t i = 0; i < handle->nr_threads; i++) { diff --git a/src/packet_io/packet_io_dumpfile.h b/src/packet_io/packet_io_dumpfile.h index 50d5e02..871aac2 100644 --- a/src/packet_io/packet_io_dumpfile.h +++ b/src/packet_io/packet_io_dumpfile.h @@ -8,7 +8,7 @@ extern "C" #include "packet.h" -struct packet_io_dumpfile_confg +struct packet_io_dumpfile_opts { char dumpfile_dir[256]; uint8_t nr_threads; @@ -16,7 +16,7 @@ struct packet_io_dumpfile_confg struct packet_io_dumpfile; -struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_confg *config); +struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_opts *opts); void packet_io_dumpfile_free(struct packet_io_dumpfile *handle); struct packet_io_stat *packet_io_dumpfile_stat(struct packet_io_dumpfile *handle); diff --git a/src/packet_io/packet_io_marsio.cpp b/src/packet_io/packet_io_marsio.cpp index bc156d6..45eba36 100644 --- a/src/packet_io/packet_io_marsio.cpp +++ b/src/packet_io/packet_io_marsio.cpp @@ -65,14 +65,14 @@ static int is_keepalive_packet(const char *data, int len) * Public API ******************************************************************************/ -struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_confg *config) +struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_opts *opts) { int opt = 1; cpu_set_t coremask; CPU_ZERO(&coremask); - for (uint8_t i = 0; i < config->nr_threads; i++) + for (uint8_t i = 0; i < opts->nr_threads; i++) { - CPU_SET(config->cpu_mask[i], &coremask); + CPU_SET(opts->cpu_mask[i], &coremask); } struct packet_io_marsio *handle = (struct packet_io_marsio *)calloc(1, sizeof(struct packet_io_marsio)); @@ -92,13 +92,13 @@ struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_confg *con marsio_option_set(handle->mr_ins, MARSIO_OPT_THREAD_MASK_IN_CPUSET, &coremask, sizeof(coremask)); marsio_option_set(handle->mr_ins, MARSIO_OPT_EXIT_WHEN_ERR, &opt, sizeof(opt)); - if (marsio_init(handle->mr_ins, config->app_symbol) != 0) + if (marsio_init(handle->mr_ins, opts->app_symbol) != 0) { PACKET_IO_LOG_ERROR("unable to init marsio instance"); goto error_out; } - handle->mr_dev = marsio_open_device(handle->mr_ins, config->dev_symbol, config->nr_threads, config->nr_threads); + handle->mr_dev = marsio_open_device(handle->mr_ins, opts->dev_symbol, opts->nr_threads, opts->nr_threads); if (handle->mr_dev == NULL) { PACKET_IO_LOG_ERROR("unable to open marsio device"); diff --git a/src/packet_io/packet_io_marsio.h b/src/packet_io/packet_io_marsio.h index ac50793..41c0698 100644 --- a/src/packet_io/packet_io_marsio.h +++ b/src/packet_io/packet_io_marsio.h @@ -8,7 +8,7 @@ extern "C" #include "packet.h" -struct packet_io_marsio_confg +struct packet_io_marsio_opts { char app_symbol[64]; char dev_symbol[64]; @@ -18,7 +18,7 @@ struct packet_io_marsio_confg struct packet_io_marsio; -struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_confg *config); +struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_opts *opts); void packet_io_marsio_free(struct packet_io_marsio *handle); struct packet_io_stat *packet_io_marsio_stat(struct packet_io_marsio *handle); diff --git a/src/session/session_manager.cpp b/src/session/session_manager.cpp index d82fb1b..fae6d2b 100644 --- a/src/session/session_manager.cpp +++ b/src/session/session_manager.cpp @@ -27,7 +27,7 @@ struct session_manager struct dupkt_filter *tcp_dupkt_filter; struct eviction_filter *udp_eviction_filter; - struct session_manager_config config; + struct session_manager_options opts; /*************************************************************** * session manager status @@ -66,7 +66,7 @@ static inline void tcp_half_closed_timeout_cb(struct session *sess, void *arg); static inline void tcp_time_wait_timeout_cb(struct session *sess, void *arg); static inline void udp_data_timeout_cb(struct session *sess, void *arg); -static inline int session_manager_check_config(struct session_manager_config *config); +static inline int session_manager_check_options(struct session_manager_options *opts); static inline uint64_t session_manager_alloc_session_id(void); static inline int session_manager_update_tcp_filter(struct session_manager *mgr, struct session *sess, const struct packet *pkt, enum session_dir curr_dir); @@ -181,123 +181,123 @@ static inline void udp_data_timeout_cb(struct session *sess, void *arg) } // return 0: success -// return -1: invalid config -static inline int session_manager_check_config(struct session_manager_config *config) +// return -1: invalid opts +static inline int session_manager_check_options(struct session_manager_options *opts) { - if (config == NULL) + if (opts == NULL) { - SESSION_LOG_ERROR("invalid config"); + SESSION_LOG_ERROR("invalid opts"); return -1; } // max session number - if (config->max_tcp_session_num < 2) + if (opts->max_tcp_session_num < 2) { SESSION_LOG_ERROR("invalid max tcp session number"); return -1; } - if (config->max_udp_session_num < 2) + if (opts->max_udp_session_num < 2) { SESSION_LOG_ERROR("invalid max udp session number"); return -1; } // session overload - if (config->tcp_overload_evict_old_sess != 0 && config->tcp_overload_evict_old_sess != 1) + if (opts->tcp_overload_evict_old_sess != 0 && opts->tcp_overload_evict_old_sess != 1) { SESSION_LOG_ERROR("invalid tcp overload evict old session, support range: 0-1"); return -1; } - if (config->udp_overload_evict_old_sess != 0 && config->udp_overload_evict_old_sess != 1) + if (opts->udp_overload_evict_old_sess != 0 && opts->udp_overload_evict_old_sess != 1) { SESSION_LOG_ERROR("invalid udp overload evict old session, support range: 0-1"); return -1; } - // TCP timeout config - if (config->tcp_timeout_init < 1 || config->tcp_timeout_init > 60) + // TCP timeout opts + if (opts->tcp_timeout_init < 1 || opts->tcp_timeout_init > 60) { SESSION_LOG_ERROR("invalid tcp timeout init, support range: 1-60"); return -1; } - if (config->tcp_timeout_handshake < 1 || config->tcp_timeout_handshake > 60) + if (opts->tcp_timeout_handshake < 1 || opts->tcp_timeout_handshake > 60) { SESSION_LOG_ERROR("invalid tcp timeout handshake, support range: 1-60"); return -1; } - if (config->tcp_timeout_data < 1 || config->tcp_timeout_data > 15999999) + if (opts->tcp_timeout_data < 1 || opts->tcp_timeout_data > 15999999) { SESSION_LOG_ERROR("invalid tcp timeout data, support range: 1-15,999,999"); return -1; } - if (config->tcp_timeout_half_closed < 1 || config->tcp_timeout_half_closed > 604800) + if (opts->tcp_timeout_half_closed < 1 || opts->tcp_timeout_half_closed > 604800) { SESSION_LOG_ERROR("invalid tcp timeout half closed, support range: 1-604,800"); return -1; } - if (config->tcp_timeout_time_wait < 1 || config->tcp_timeout_time_wait > 600) + if (opts->tcp_timeout_time_wait < 1 || opts->tcp_timeout_time_wait > 600) { SESSION_LOG_ERROR("invalid tcp timeout time wait, support range: 1-600"); return -1; } - if (config->tcp_timeout_discard < 1 || config->tcp_timeout_discard > 15999999) + if (opts->tcp_timeout_discard < 1 || opts->tcp_timeout_discard > 15999999) { SESSION_LOG_ERROR("invalid tcp timeout discard, support range: 1-15,999,999"); return -1; } - // UDP timeout config - if (config->udp_timeout_data < 1 || config->udp_timeout_data > 15999999) + // UDP timeout opts + if (opts->udp_timeout_data < 1 || opts->udp_timeout_data > 15999999) { SESSION_LOG_ERROR("invalid udp timeout data, support range: 1-15,999,999"); return -1; } - // TCP duplicate packet filter config - if (config->tcp_dupkt_filter_enable != 0 && config->tcp_dupkt_filter_enable != 1) + // TCP duplicate packet filter opts + if (opts->tcp_dupkt_filter_enable != 0 && opts->tcp_dupkt_filter_enable != 1) { SESSION_LOG_ERROR("invalid tcp dupkt filter enable, support range: 0-1"); return -1; } - if (config->tcp_dupkt_filter_enable) + if (opts->tcp_dupkt_filter_enable) { - if (config->tcp_dupkt_filter_capacity == 0) + if (opts->tcp_dupkt_filter_capacity == 0) { SESSION_LOG_ERROR("invalid tcp dupkt filter capacity"); return -1; } - if (config->tcp_dupkt_filter_timeout < 1 || config->tcp_dupkt_filter_timeout > 60) + if (opts->tcp_dupkt_filter_timeout < 1 || opts->tcp_dupkt_filter_timeout > 60) { SESSION_LOG_ERROR("invalid tcp dupkt filter timeout, support range: 1-60"); return -1; } - if (config->tcp_dupkt_filter_error_rate < 0 || config->tcp_dupkt_filter_error_rate > 1) + if (opts->tcp_dupkt_filter_error_rate < 0 || opts->tcp_dupkt_filter_error_rate > 1) { SESSION_LOG_ERROR("invalid tcp dupkt filter error rate, support range: 0-1"); return -1; } } - // UDP eviction filter config - if (config->udp_eviction_filter_enable != 0 && config->udp_eviction_filter_enable != 1) + // UDP eviction filter opts + if (opts->udp_eviction_filter_enable != 0 && opts->udp_eviction_filter_enable != 1) { SESSION_LOG_ERROR("invalid udp eviction filter enable, support range: 0-1"); return -1; } - if (config->udp_eviction_filter_enable) + if (opts->udp_eviction_filter_enable) { - if (config->udp_eviction_filter_capacity == 0) + if (opts->udp_eviction_filter_capacity == 0) { SESSION_LOG_ERROR("invalid udp eviction filter capacity"); return -1; } - if (config->udp_eviction_filter_timeout < 1 || config->udp_eviction_filter_timeout > 60) + if (opts->udp_eviction_filter_timeout < 1 || opts->udp_eviction_filter_timeout > 60) { SESSION_LOG_ERROR("invalid udp eviction filter timeout, support range: 1-60"); return -1; } - if (config->udp_eviction_filter_error_rate < 0 || config->udp_eviction_filter_error_rate > 1) + if (opts->udp_eviction_filter_error_rate < 0 || opts->udp_eviction_filter_error_rate > 1) { SESSION_LOG_ERROR("invalid udp eviction filter error rate, support range: 0-1"); return -1; @@ -633,13 +633,13 @@ static inline void session_manager_update_session_packet(struct session_manager static inline void session_manager_update_udp_to_opening(struct session_manager *mgr, struct session *sess) { session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING); - session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->config.udp_timeout_data); + session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->opts.udp_timeout_data); } static inline void session_manager_update_udp_to_active(struct session_manager *mgr, struct session *sess) { session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE); - session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->config.udp_timeout_data); + session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->opts.udp_timeout_data); } static inline void session_manager_update_udp_to_closing(struct session_manager *mgr, struct session *sess) @@ -655,18 +655,18 @@ static inline void session_manager_update_tcp_to_opening(struct session_manager session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING); if (opening_by_syn) { - session_manager_update_session_timer(mgr, sess, tcp_init_timeout_cb, mgr->config.tcp_timeout_init); + session_manager_update_session_timer(mgr, sess, tcp_init_timeout_cb, mgr->opts.tcp_timeout_init); } else { - session_manager_update_session_timer(mgr, sess, tcp_handshake_timeout_cb, mgr->config.tcp_timeout_handshake); + session_manager_update_session_timer(mgr, sess, tcp_handshake_timeout_cb, mgr->opts.tcp_timeout_handshake); } } static inline void session_manager_update_tcp_to_active(struct session_manager *mgr, struct session *sess) { session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE); - session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->config.tcp_timeout_data); + session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->opts.tcp_timeout_data); } static inline void session_manager_update_tcp_to_closing(struct session_manager *mgr, struct session *sess, int enable_time_wait) @@ -674,7 +674,7 @@ static inline void session_manager_update_tcp_to_closing(struct session_manager session_manager_update_session_state(mgr, sess, SESSION_STATE_CLOSING); if (enable_time_wait) { - session_manager_update_session_timer(mgr, sess, tcp_time_wait_timeout_cb, mgr->config.tcp_timeout_time_wait); + session_manager_update_session_timer(mgr, sess, tcp_time_wait_timeout_cb, mgr->opts.tcp_timeout_time_wait); } else { @@ -724,7 +724,7 @@ static inline void session_manager_handle_tcp_on_opening(struct session_manager SESSION_LOG_DEBUG("TCP %s FIN received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_FIN_RECVED ? "C2S" : "S2C"), session_get_id(sess)); // still opening, only update timeout session_set_closing_reason(sess, (tcp_mod_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN); - session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->config.tcp_timeout_half_closed); + session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->opts.tcp_timeout_half_closed); return; } @@ -732,7 +732,7 @@ static inline void session_manager_handle_tcp_on_opening(struct session_manager { SESSION_LOG_DEBUG("TCP %s ACK received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_ACK_RECVED ? "C2S" : "S2C"), session_get_id(sess)); // still opening, only update timeout - session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->config.tcp_timeout_data); + session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->opts.tcp_timeout_data); return; } @@ -783,7 +783,7 @@ static inline void session_manager_handle_tcp_on_active(struct session_manager * SESSION_LOG_DEBUG("TCP %s FIN received, session %lu active -> active", (tcp_curr_state & TCP_C2S_FIN_RECVED) ? "C2S" : "S2C", session_get_id(sess)); // still active session_set_closing_reason(sess, (tcp_curr_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN); - session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->config.tcp_timeout_half_closed); + session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->opts.tcp_timeout_half_closed); return; } @@ -815,9 +815,9 @@ static inline struct session *session_manager_new_tcp_session(struct session_man return NULL; } - if (mgr->tcp_sess_num >= mgr->config.max_tcp_session_num - 1) + if (mgr->tcp_sess_num >= mgr->opts.max_tcp_session_num - 1) { - if (mgr->config.tcp_overload_evict_old_sess) + if (mgr->opts.tcp_overload_evict_old_sess) { struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->tcp_sess_table); assert(evicted_sess); @@ -826,7 +826,7 @@ static inline struct session *session_manager_new_tcp_session(struct session_man } else { - if (mgr->tcp_sess_num >= mgr->config.max_tcp_session_num) + if (mgr->tcp_sess_num >= mgr->opts.max_tcp_session_num) { mgr->tcp_overload_evict_new_sess_num++; return NULL; @@ -866,9 +866,9 @@ static inline struct session *session_manager_new_udp_session(struct session_man return NULL; } - if (mgr->udp_sess_num >= mgr->config.max_udp_session_num - 1) + if (mgr->udp_sess_num >= mgr->opts.max_udp_session_num - 1) { - if (mgr->config.udp_overload_evict_old_sess) + if (mgr->opts.udp_overload_evict_old_sess) { struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->udp_sess_table); assert(evicted_sess); @@ -877,7 +877,7 @@ static inline struct session *session_manager_new_udp_session(struct session_man } else { - if (mgr->udp_sess_num >= mgr->config.max_udp_session_num) + if (mgr->udp_sess_num >= mgr->opts.max_udp_session_num) { mgr->udp_overload_evict_new_sess_num++; return NULL; @@ -1029,9 +1029,9 @@ static inline void session_manager_evicte_session(struct session_manager *mgr, s * Public API ******************************************************************************/ -struct session_manager *session_manager_new(struct session_manager_config *config) +struct session_manager *session_manager_new(struct session_manager_options *opts) { - if (session_manager_check_config(config)) + if (session_manager_check_options(opts)) { return NULL; } @@ -1042,8 +1042,8 @@ struct session_manager *session_manager_new(struct session_manager_config *confi return NULL; } - memcpy(&mgr->config, config, sizeof(struct session_manager_config)); - mgr->sess_pool = session_pool_new(mgr->config.max_tcp_session_num + mgr->config.max_udp_session_num); + memcpy(&mgr->opts, opts, sizeof(struct session_manager_options)); + mgr->sess_pool = session_pool_new(mgr->opts.max_tcp_session_num + mgr->opts.max_udp_session_num); if (mgr->sess_pool == NULL) { goto error; @@ -1079,13 +1079,13 @@ struct session_manager *session_manager_new(struct session_manager_config *confi goto error; } - mgr->tcp_dupkt_filter = dupkt_filter_new(mgr->config.tcp_dupkt_filter_enable, mgr->config.tcp_dupkt_filter_capacity, mgr->config.tcp_dupkt_filter_error_rate, mgr->config.tcp_dupkt_filter_timeout); + mgr->tcp_dupkt_filter = dupkt_filter_new(mgr->opts.tcp_dupkt_filter_enable, mgr->opts.tcp_dupkt_filter_capacity, mgr->opts.tcp_dupkt_filter_error_rate, mgr->opts.tcp_dupkt_filter_timeout); if (mgr->tcp_dupkt_filter == NULL) { goto error; } - mgr->udp_eviction_filter = eviction_filter_new(mgr->config.udp_eviction_filter_enable, mgr->config.udp_eviction_filter_capacity, mgr->config.udp_eviction_filter_error_rate, mgr->config.udp_eviction_filter_timeout); + mgr->udp_eviction_filter = eviction_filter_new(mgr->opts.udp_eviction_filter_enable, mgr->opts.udp_eviction_filter_capacity, mgr->opts.udp_eviction_filter_error_rate, mgr->opts.udp_eviction_filter_timeout); if (mgr->udp_eviction_filter == NULL) { goto error; diff --git a/src/session/session_manager.h b/src/session/session_manager.h index 74d2e68..65cacf9 100644 --- a/src/session/session_manager.h +++ b/src/session/session_manager.h @@ -12,7 +12,7 @@ extern "C" #define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__) #define SESSION_LOG_DEBUG(format, ...) LOG_DEBUG("session", format, ##__VA_ARGS__) -struct session_manager_config +struct session_manager_options { // max session number uint64_t max_tcp_session_num; @@ -47,7 +47,7 @@ struct session_manager_config }; struct session_manager; -struct session_manager *session_manager_new(struct session_manager_config *config); +struct session_manager *session_manager_new(struct session_manager_options *opts); void session_manager_free(struct session_manager *mgr); // only use the packet six-tuple to find the session, not update it diff --git a/src/session/test/gtest_filter_tcp_dupkt.cpp b/src/session/test/gtest_filter_tcp_dupkt.cpp index 445118f..760e29b 100644 --- a/src/session/test/gtest_filter_tcp_dupkt.cpp +++ b/src/session/test/gtest_filter_tcp_dupkt.cpp @@ -9,7 +9,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYN_DUP) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -61,7 +61,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, S2C_DUP) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // S2C SYNACK Packet @@ -116,7 +116,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SKIP_FILTER) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -178,13 +178,13 @@ TEST(TCP_DUPKT_FILTER_DISABLE, C2S_DUPKT) struct packet pkt; struct session *sess = NULL; struct session_manager *mgr = NULL; - struct session_manager_config _config; - memcpy(&_config, &config, sizeof(struct session_manager_config)); - _config.tcp_dupkt_filter_enable = 0; + struct session_manager_options _opts; + memcpy(&_opts, &opts, sizeof(struct session_manager_options)); + _opts.tcp_dupkt_filter_enable = 0; timestamp_update(); - mgr = session_manager_new(&_config); + mgr = session_manager_new(&_opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -233,13 +233,13 @@ TEST(TCP_DUPKT_FILTER_DISABLE, S2C_DUP) struct packet pkt; struct session *sess = NULL; struct session_manager *mgr = NULL; - struct session_manager_config _config; - memcpy(&_config, &config, sizeof(struct session_manager_config)); - _config.tcp_dupkt_filter_enable = 0; + struct session_manager_options _opts; + memcpy(&_opts, &opts, sizeof(struct session_manager_options)); + _opts.tcp_dupkt_filter_enable = 0; timestamp_update(); - mgr = session_manager_new(&_config); + mgr = session_manager_new(&_opts); EXPECT_TRUE(mgr != NULL); // S2C SYNACK Packet diff --git a/src/session/test/gtest_filter_udp_eviction.cpp b/src/session/test/gtest_filter_udp_eviction.cpp index e288a0f..b3886e5 100644 --- a/src/session/test/gtest_filter_udp_eviction.cpp +++ b/src/session/test/gtest_filter_udp_eviction.cpp @@ -9,7 +9,7 @@ TEST(UDP_EVICTION_FILTER_ENABLE, HIT_FILTER_THEN_EVICT_SESS) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet @@ -43,13 +43,13 @@ TEST(UDP_EVICTION_FILTER_ENABLE, MISS_FILTER_THEN_NEW_SESS) struct packet pkt; struct session *sess = NULL; struct session_manager *mgr = NULL; - struct session_manager_config _config; - memcpy(&_config, &config, sizeof(struct session_manager_config)); - _config.udp_eviction_filter_timeout = 2; + struct session_manager_options _opts; + memcpy(&_opts, &opts, sizeof(struct session_manager_options)); + _opts.udp_eviction_filter_timeout = 2; timestamp_update(); - mgr = session_manager_new(&_config); + mgr = session_manager_new(&_opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet @@ -66,7 +66,7 @@ TEST(UDP_EVICTION_FILTER_ENABLE, MISS_FILTER_THEN_NEW_SESS) __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // wait udp eviction filter timeout - sleep(_config.udp_eviction_filter_timeout); + sleep(_opts.udp_eviction_filter_timeout); timestamp_update(); // C2S REQ Packet @@ -91,13 +91,13 @@ TEST(UDP_EVICTION_FILTER_DISABLE, MISS_FILTER_THEN_NEW_SESS) struct packet pkt; struct session *sess = NULL; struct session_manager *mgr = NULL; - struct session_manager_config _config; - memcpy(&_config, &config, sizeof(struct session_manager_config)); - _config.udp_eviction_filter_enable = 0; + struct session_manager_options _opts; + memcpy(&_opts, &opts, sizeof(struct session_manager_options)); + _opts.udp_eviction_filter_enable = 0; timestamp_update(); - mgr = session_manager_new(&_config); + mgr = session_manager_new(&_opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet diff --git a/src/session/test/gtest_overload_evict_tcp_sess.cpp b/src/session/test/gtest_overload_evict_tcp_sess.cpp index 3203a0f..2274399 100644 --- a/src/session/test/gtest_overload_evict_tcp_sess.cpp +++ b/src/session/test/gtest_overload_evict_tcp_sess.cpp @@ -19,10 +19,10 @@ TEST(OVERLOAD, EVICT_TCP_OLD_SESS) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); - for (uint64_t i = 0; i < config.max_tcp_session_num; i++) + for (uint64_t i = 0; i < opts.max_tcp_session_num; i++) { // C2S SYN Packet printf("\n====================== new session (%lu) ======================\n\n", i + 1); @@ -37,7 +37,7 @@ TEST(OVERLOAD, EVICT_TCP_OLD_SESS) __session_dispatch(sess); session_manager_print_stat(mgr); - if (i == config.max_tcp_session_num - 1) + if (i == opts.max_tcp_session_num - 1) { __session_manager_check_counter(mgr, i, 0, 1, // tcp_opening_sess_num, tcp_active_sess_num, tcp_closing_sess_num, @@ -91,16 +91,16 @@ TEST(OVERLOAD, EVICT_TCP_NEW_SESS) struct session *sess = NULL; struct session_manager *mgr = NULL; char buffer[1500] = {0}; - struct session_manager_config _config; - memcpy(&_config, &config, sizeof(struct session_manager_config)); - _config.tcp_overload_evict_old_sess = 0; + struct session_manager_options _opts; + memcpy(&_opts, &opts, sizeof(struct session_manager_options)); + _opts.tcp_overload_evict_old_sess = 0; timestamp_update(); - mgr = session_manager_new(&_config); + mgr = session_manager_new(&_opts); EXPECT_TRUE(mgr != NULL); - for (uint64_t i = 0; i <= _config.max_tcp_session_num; i++) + for (uint64_t i = 0; i <= _opts.max_tcp_session_num; i++) { // C2S SYN Packet printf("\n====================== new session (%lu) ======================\n\n", i + 1); @@ -111,7 +111,7 @@ TEST(OVERLOAD, EVICT_TCP_NEW_SESS) printf("<= packet parse\n\n"); sess = session_manager_update_session(mgr, &pkt); - if (i == _config.max_tcp_session_num) + if (i == _opts.max_tcp_session_num) { EXPECT_TRUE(sess == NULL); __session_manager_check_counter(mgr, diff --git a/src/session/test/gtest_overload_evict_udp_sess.cpp b/src/session/test/gtest_overload_evict_udp_sess.cpp index bdd2b75..79b1ec5 100644 --- a/src/session/test/gtest_overload_evict_udp_sess.cpp +++ b/src/session/test/gtest_overload_evict_udp_sess.cpp @@ -19,10 +19,10 @@ TEST(OVERLOAD, EVICT_UDP_OLD_SESS) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); - for (uint64_t i = 0; i < config.max_udp_session_num; i++) + for (uint64_t i = 0; i < opts.max_udp_session_num; i++) { // C2S REQ Packet printf("\n====================== new session (%lu) ======================\n\n", i + 1); @@ -37,7 +37,7 @@ TEST(OVERLOAD, EVICT_UDP_OLD_SESS) __session_dispatch(sess); session_manager_print_stat(mgr); - if (i == config.max_udp_session_num - 1) + if (i == opts.max_udp_session_num - 1) { __session_manager_check_counter(mgr, 0, 0, 0, // tcp_opening_sess_num, tcp_active_sess_num, tcp_closing_sess_num, @@ -91,16 +91,16 @@ TEST(OVERLOAD, EVICT_UDP_NEW_SESS) struct session *sess = NULL; struct session_manager *mgr = NULL; char buffer[1500] = {0}; - struct session_manager_config _config; - memcpy(&_config, &config, sizeof(struct session_manager_config)); - _config.udp_overload_evict_old_sess = 0; + struct session_manager_options _opts; + memcpy(&_opts, &opts, sizeof(struct session_manager_options)); + _opts.udp_overload_evict_old_sess = 0; timestamp_update(); - mgr = session_manager_new(&_config); + mgr = session_manager_new(&_opts); EXPECT_TRUE(mgr != NULL); - for (uint64_t i = 0; i <= _config.max_udp_session_num; i++) + for (uint64_t i = 0; i <= _opts.max_udp_session_num; i++) { // C2S REQ Packet printf("\n====================== new session (%lu) ======================\n\n", i + 1); @@ -111,7 +111,7 @@ TEST(OVERLOAD, EVICT_UDP_NEW_SESS) printf("<= packet parse\n\n"); sess = session_manager_update_session(mgr, &pkt); - if (i == _config.max_udp_session_num) + if (i == _opts.max_udp_session_num) { EXPECT_TRUE(sess == NULL); __session_manager_check_counter(mgr, diff --git a/src/session/test/gtest_state_tcp_active_to_closing.cpp b/src/session/test/gtest_state_tcp_active_to_closing.cpp index a4b994a..7527c85 100644 --- a/src/session/test/gtest_state_tcp_active_to_closing.cpp +++ b/src/session/test/gtest_state_tcp_active_to_closing.cpp @@ -91,7 +91,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_FIN_FIN) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet & C2S DATA Packet @@ -182,7 +182,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_RST) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet & C2S DATA Packet @@ -246,7 +246,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_RST) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet & C2S DATA Packet @@ -308,7 +308,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_DATA_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet & C2S DATA Packet @@ -336,7 +336,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet & C2S DATA Packet @@ -393,7 +393,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet & C2S DATA Packet diff --git a/src/session/test/gtest_state_tcp_init_to_opening.cpp b/src/session/test/gtest_state_tcp_init_to_opening.cpp index 22bedf8..258166a 100644 --- a/src/session/test/gtest_state_tcp_init_to_opening.cpp +++ b/src/session/test/gtest_state_tcp_init_to_opening.cpp @@ -16,7 +16,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -71,7 +71,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // SYNACK Packet @@ -126,7 +126,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -216,7 +216,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK_ACK) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -342,7 +342,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_RETRANSMISSION) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -440,7 +440,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK_RETRANSMISSION) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // SYNACK Packet @@ -536,7 +536,7 @@ TEST(TCP_INIT_TO_OPENING, BY_C2S_ASMMETRIC) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -626,7 +626,7 @@ TEST(TCP_INIT_TO_OPENING, BY_S2C_ASMMETRIC) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // SYNACK Packet diff --git a/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp b/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp index c124699..b924992 100644 --- a/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp +++ b/src/session/test/gtest_state_tcp_init_to_opening_to_active_to_closing_to_closed.cpp @@ -12,7 +12,7 @@ TEST(TCP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING_TO_CLOSED, TEST) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet diff --git a/src/session/test/gtest_state_tcp_opening_to_active.cpp b/src/session/test/gtest_state_tcp_opening_to_active.cpp index 554150d..c702d57 100644 --- a/src/session/test/gtest_state_tcp_opening_to_active.cpp +++ b/src/session/test/gtest_state_tcp_opening_to_active.cpp @@ -16,7 +16,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYN_C2S_DATA) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -105,7 +105,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYNACK_S2C_DATA) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // SYNACK Packet diff --git a/src/session/test/gtest_state_tcp_opening_to_closing.cpp b/src/session/test/gtest_state_tcp_opening_to_closing.cpp index 51aaaa4..f0c62c7 100644 --- a/src/session/test/gtest_state_tcp_opening_to_closing.cpp +++ b/src/session/test/gtest_state_tcp_opening_to_closing.cpp @@ -57,7 +57,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_FIN_FIN) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -148,7 +148,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_RST) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -212,7 +212,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_RST) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -274,7 +274,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_INIT_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -302,7 +302,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_HANDSHAKE_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -360,7 +360,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_DATA_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -452,7 +452,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -509,7 +509,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet diff --git a/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp b/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp index 2368b79..a6ec9b6 100644 --- a/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp +++ b/src/session/test/gtest_state_udp_init_to_opening_to_active_to_closing.cpp @@ -20,7 +20,7 @@ TEST(UDP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING, TEST) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet diff --git a/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp b/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp index 2046b92..7383197 100644 --- a/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp +++ b/src/session/test/gtest_state_udp_init_to_opening_to_closing.cpp @@ -18,7 +18,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_C2S) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet @@ -75,7 +75,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_S2C) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // S2C RESP Packet diff --git a/src/session/test/gtest_timeout_tcp_data.cpp b/src/session/test/gtest_timeout_tcp_data.cpp index ca3ff90..bd51843 100644 --- a/src/session/test/gtest_timeout_tcp_data.cpp +++ b/src/session/test/gtest_timeout_tcp_data.cpp @@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_DATA) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -28,8 +28,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_DATA) __session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); - __session_manager_check_tcp_timeout_data(mgr, &config); - __session_manager_check_tcp_timeout_time_wait(mgr, &config); + __session_manager_check_tcp_timeout_data(mgr, &opts); + __session_manager_check_tcp_timeout_time_wait(mgr, &opts); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/src/session/test/gtest_timeout_tcp_half_closed.cpp b/src/session/test/gtest_timeout_tcp_half_closed.cpp index 9fd19c3..ad7760a 100644 --- a/src/session/test/gtest_timeout_tcp_half_closed.cpp +++ b/src/session/test/gtest_timeout_tcp_half_closed.cpp @@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED1) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -28,8 +28,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED1) __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); - __session_manager_check_tcp_timeout_half_closed(mgr, &config, SESSION_STATE_OPENING); - __session_manager_check_tcp_timeout_time_wait(mgr, &config); + __session_manager_check_tcp_timeout_half_closed(mgr, &opts, SESSION_STATE_OPENING); + __session_manager_check_tcp_timeout_time_wait(mgr, &opts); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -46,7 +46,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED2) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -72,8 +72,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED2) __session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); - __session_manager_check_tcp_timeout_half_closed(mgr, &config, SESSION_STATE_ACTIVE); - __session_manager_check_tcp_timeout_time_wait(mgr, &config); + __session_manager_check_tcp_timeout_half_closed(mgr, &opts, SESSION_STATE_ACTIVE); + __session_manager_check_tcp_timeout_time_wait(mgr, &opts); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/src/session/test/gtest_timeout_tcp_handshake.cpp b/src/session/test/gtest_timeout_tcp_handshake.cpp index 19b4ff5..53d7151 100644 --- a/src/session/test/gtest_timeout_tcp_handshake.cpp +++ b/src/session/test/gtest_timeout_tcp_handshake.cpp @@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HANDSHAKE) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // SYNACK Packet @@ -21,8 +21,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_HANDSHAKE) __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); - __session_manager_check_tcp_timeout_handshake(mgr, &config); - __session_manager_check_tcp_timeout_time_wait(mgr, &config); + __session_manager_check_tcp_timeout_handshake(mgr, &opts); + __session_manager_check_tcp_timeout_time_wait(mgr, &opts); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/src/session/test/gtest_timeout_tcp_init.cpp b/src/session/test/gtest_timeout_tcp_init.cpp index 47516a5..6d92baa 100644 --- a/src/session/test/gtest_timeout_tcp_init.cpp +++ b/src/session/test/gtest_timeout_tcp_init.cpp @@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT1) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S SYN Packet @@ -21,8 +21,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT1) __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); - __session_manager_check_tcp_timeout_init(mgr, &config); - __session_manager_check_tcp_timeout_time_wait(mgr, &config); + __session_manager_check_tcp_timeout_init(mgr, &opts); + __session_manager_check_tcp_timeout_time_wait(mgr, &opts); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -39,7 +39,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT2) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // S2C SYNACK Packet @@ -51,8 +51,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT2) __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); - __session_manager_check_tcp_timeout_init(mgr, &config); - __session_manager_check_tcp_timeout_time_wait(mgr, &config); + __session_manager_check_tcp_timeout_init(mgr, &opts); + __session_manager_check_tcp_timeout_time_wait(mgr, &opts); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/src/session/test/gtest_timeout_udp_data.cpp b/src/session/test/gtest_timeout_udp_data.cpp index 2f33284..e691b6b 100644 --- a/src/session/test/gtest_timeout_udp_data.cpp +++ b/src/session/test/gtest_timeout_udp_data.cpp @@ -9,7 +9,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA1) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet @@ -21,7 +21,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA1) __session_manager_check_counter(mgr, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0); - __session_manager_check_udp_timeout_data(mgr, &config, SESSION_STATE_OPENING); + __session_manager_check_udp_timeout_data(mgr, &opts, SESSION_STATE_OPENING); EXPECT_TRUE(session_manager_get_expired_session(mgr) == NULL); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -39,7 +39,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA2) timestamp_update(); - mgr = session_manager_new(&config); + mgr = session_manager_new(&opts); EXPECT_TRUE(mgr != NULL); // C2S REQ Packet @@ -58,7 +58,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA2) __session_manager_check_counter(mgr, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0); - __session_manager_check_udp_timeout_data(mgr, &config, SESSION_STATE_ACTIVE); + __session_manager_check_udp_timeout_data(mgr, &opts, SESSION_STATE_ACTIVE); EXPECT_TRUE(session_manager_get_expired_session(mgr) == NULL); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/src/session/test/test_utils.h b/src/session/test/test_utils.h index d64e7af..4ad3eb9 100644 --- a/src/session/test/test_utils.h +++ b/src/session/test/test_utils.h @@ -15,7 +15,7 @@ extern "C" #include "ipv4_utils.h" #include "test_packets.h" -struct session_manager_config config = { +struct session_manager_options opts = { // max session number .max_tcp_session_num = 3, .max_udp_session_num = 3, @@ -112,20 +112,20 @@ __attribute__((unused)) static void __session_manager_check_counter(struct sessi EXPECT_TRUE(counter.udp_overload_evict_old_sess_num == udp_overload_evict_old_sess_num); } -__attribute__((unused)) static void __session_manager_check_tcp_timeout_init(struct session_manager *mgr, struct session_manager_config *config) +__attribute__((unused)) static void __session_manager_check_tcp_timeout_init(struct session_manager *mgr, struct session_manager_options *opts) { struct session *sess; uint64_t interval; - uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_init; + uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_init; printf("\n=> tcp_timeout_init\n"); - for (uint64_t i = 0; i <= config->tcp_timeout_init; i++) + for (uint64_t i = 0; i <= opts->tcp_timeout_init; i++) { timestamp_update(); sess = session_manager_get_expired_session(mgr); interval = session_manager_get_expire_interval(mgr); - if (i == config->tcp_timeout_init) + if (i == opts->tcp_timeout_init) { printf("timeout_time: %lu, curr_time: %lu, session expired\n", timeout_time, timestamp_get_sec()); @@ -139,7 +139,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_init(str printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", timeout_time, timestamp_get_sec(), interval); - EXPECT_TRUE(interval <= config->tcp_timeout_init); + EXPECT_TRUE(interval <= opts->tcp_timeout_init); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); EXPECT_TRUE(sess == NULL); } @@ -148,20 +148,20 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_init(str printf("<= tcp_timeout_init\n\n"); } -__attribute__((unused)) static void __session_manager_check_tcp_timeout_handshake(struct session_manager *mgr, struct session_manager_config *config) +__attribute__((unused)) static void __session_manager_check_tcp_timeout_handshake(struct session_manager *mgr, struct session_manager_options *opts) { struct session *sess; uint64_t interval; - uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_handshake; + uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_handshake; printf("\n=> tcp_timeout_handshake\n"); - for (uint64_t i = 0; i <= config->tcp_timeout_handshake; i++) + for (uint64_t i = 0; i <= opts->tcp_timeout_handshake; i++) { timestamp_update(); sess = session_manager_get_expired_session(mgr); interval = session_manager_get_expire_interval(mgr); - if (i == config->tcp_timeout_handshake) + if (i == opts->tcp_timeout_handshake) { printf("timeout_time: %lu, curr_time: %lu, session expired\n", timeout_time, timestamp_get_sec()); @@ -175,7 +175,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_handshak printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", timeout_time, timestamp_get_sec(), interval); - EXPECT_TRUE(interval <= config->tcp_timeout_handshake); + EXPECT_TRUE(interval <= opts->tcp_timeout_handshake); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); EXPECT_TRUE(sess == NULL); } @@ -184,20 +184,20 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_handshak printf("<= tcp_timeout_handshake\n\n"); } -__attribute__((unused)) static void __session_manager_check_tcp_timeout_data(struct session_manager *mgr, struct session_manager_config *config) +__attribute__((unused)) static void __session_manager_check_tcp_timeout_data(struct session_manager *mgr, struct session_manager_options *opts) { struct session *sess; uint64_t interval; - uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_data; + uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_data; printf("\n=> tcp_timeout_data\n"); - for (uint64_t i = 0; i <= config->tcp_timeout_data; i++) + for (uint64_t i = 0; i <= opts->tcp_timeout_data; i++) { timestamp_update(); sess = session_manager_get_expired_session(mgr); interval = session_manager_get_expire_interval(mgr); - if (i == config->tcp_timeout_data) + if (i == opts->tcp_timeout_data) { printf("timeout_time: %lu, curr_time: %lu, session expired\n", timeout_time, timestamp_get_sec()); @@ -211,7 +211,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_data(str printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", timeout_time, timestamp_get_sec(), interval); - EXPECT_TRUE(interval <= config->tcp_timeout_data); + EXPECT_TRUE(interval <= opts->tcp_timeout_data); __session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); EXPECT_TRUE(sess == NULL); } @@ -220,22 +220,22 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_data(str printf("<= tcp_timeout_data\n\n"); } -__attribute__((unused)) static void __session_manager_check_tcp_timeout_half_closed(struct session_manager *mgr, struct session_manager_config *config, enum session_state curr_state) +__attribute__((unused)) static void __session_manager_check_tcp_timeout_half_closed(struct session_manager *mgr, struct session_manager_options *opts, enum session_state curr_state) { EXPECT_TRUE(curr_state == SESSION_STATE_OPENING || curr_state == SESSION_STATE_ACTIVE); struct session *sess; uint64_t interval; - uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_half_closed; + uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_half_closed; printf("\n=> tcp_timeout_half_closed\n"); - for (uint64_t i = 0; i <= config->tcp_timeout_half_closed; i++) + for (uint64_t i = 0; i <= opts->tcp_timeout_half_closed; i++) { timestamp_update(); sess = session_manager_get_expired_session(mgr); interval = session_manager_get_expire_interval(mgr); - if (i == config->tcp_timeout_half_closed) + if (i == opts->tcp_timeout_half_closed) { printf("timeout_time: %lu, curr_time: %lu, session expired\n", timeout_time, timestamp_get_sec()); @@ -249,7 +249,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_half_clo printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", timeout_time, timestamp_get_sec(), interval); - EXPECT_TRUE(interval <= config->tcp_timeout_half_closed); + EXPECT_TRUE(interval <= opts->tcp_timeout_half_closed); if (curr_state == SESSION_STATE_OPENING) { __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -265,20 +265,20 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_half_clo printf("<= tcp_timeout_half_closed\n\n"); } -__attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wait(struct session_manager *mgr, struct session_manager_config *config) +__attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wait(struct session_manager *mgr, struct session_manager_options *opts) { struct session *sess; uint64_t interval; - uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_time_wait; + uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_time_wait; printf("\n=> tcp_timeout_time_wait\n"); - for (uint64_t i = 0; i <= config->tcp_timeout_time_wait; i++) + for (uint64_t i = 0; i <= opts->tcp_timeout_time_wait; i++) { timestamp_update(); sess = session_manager_get_expired_session(mgr); interval = session_manager_get_expire_interval(mgr); - if (i == config->tcp_timeout_time_wait) + if (i == opts->tcp_timeout_time_wait) { printf("timeout_time: %lu, curr_time: %lu, session expired\n", timeout_time, timestamp_get_sec()); @@ -292,7 +292,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wai printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", timeout_time, timestamp_get_sec(), interval); - EXPECT_TRUE(interval <= config->tcp_timeout_init); + EXPECT_TRUE(interval <= opts->tcp_timeout_init); __session_manager_check_counter(mgr, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); EXPECT_TRUE(sess == NULL); } @@ -301,22 +301,22 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wai printf("<= tcp_timeout_time_wait\n\n"); } -__attribute__((unused)) static void __session_manager_check_udp_timeout_data(struct session_manager *mgr, struct session_manager_config *config, enum session_state curr_state) +__attribute__((unused)) static void __session_manager_check_udp_timeout_data(struct session_manager *mgr, struct session_manager_options *opts, enum session_state curr_state) { EXPECT_TRUE(curr_state == SESSION_STATE_OPENING || curr_state == SESSION_STATE_ACTIVE); struct session *sess; uint64_t interval; - uint64_t timeout_time = timestamp_get_sec() + config->udp_timeout_data; + uint64_t timeout_time = timestamp_get_sec() + opts->udp_timeout_data; printf("\n=> udp_timeout_data\n"); - for (uint64_t i = 0; i <= config->udp_timeout_data; i++) + for (uint64_t i = 0; i <= opts->udp_timeout_data; i++) { timestamp_update(); sess = session_manager_get_expired_session(mgr); interval = session_manager_get_expire_interval(mgr); - if (i == config->udp_timeout_data) + if (i == opts->udp_timeout_data) { printf("timeout_time: %lu, curr_time: %lu, session expired\n", timeout_time, timestamp_get_sec()); @@ -330,7 +330,7 @@ __attribute__((unused)) static void __session_manager_check_udp_timeout_data(str printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", timeout_time, timestamp_get_sec(), interval); - EXPECT_TRUE(interval <= config->udp_timeout_data); + EXPECT_TRUE(interval <= opts->udp_timeout_data); if (curr_state == SESSION_STATE_OPENING) { __session_manager_check_counter(mgr, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0); diff --git a/src/stellar/stellar.cpp b/src/stellar/stellar.cpp index f9ec838..3d6a27f 100644 --- a/src/stellar/stellar.cpp +++ b/src/stellar/stellar.cpp @@ -48,10 +48,10 @@ struct stellar_context stellar_context; struct stellar_context *stellar_ctx = &stellar_context; // config -struct device_config *dev_cfg = &stellar_context.config.dev_cfg; -struct packet_io_config *pkt_io_cfg = &stellar_context.config.pkt_io_cfg; -struct ip_reassembly_config *ip_reass_cfg = &stellar_context.config.ip_reass_cfg; -struct session_manager_config *sess_mgr_cfg = &stellar_context.config.sess_mgr_cfg; +struct device_options *dev_opts = &stellar_context.config.dev_opts; +struct packet_io_options *pkt_io_opts = &stellar_context.config.pkt_io_opts; +struct ip_reassembly_options *ip_reass_opts = &stellar_context.config.ip_reass_opts; +struct session_manager_options *sess_mgr_opts = &stellar_context.config.sess_mgr_opts; static const char *log_config_file = "./conf/log.toml"; static const char *stellar_config_file = "./conf/stellar.toml"; @@ -207,14 +207,14 @@ static int thread_context_init(struct stellar_context *ctx, uint8_t nr_threads) threads_ctx->need_exit = 0; threads_ctx->is_runing = 0; - threads_ctx->sess_mgr = session_manager_new(sess_mgr_cfg); + threads_ctx->sess_mgr = session_manager_new(sess_mgr_opts); if (threads_ctx->sess_mgr == NULL) { STELLAR_LOG_ERROR("unable to create session manager"); return -1; } - threads_ctx->ip_mgr = ip_reassembly_new(ip_reass_cfg); + threads_ctx->ip_mgr = ip_reassembly_new(ip_reass_opts); if (threads_ctx->ip_mgr == NULL) { STELLAR_LOG_ERROR("unable to create ip reassemble manager"); @@ -298,7 +298,7 @@ int main(int argc, char **argv) config_dump(&stellar_ctx->config); - if (id_generator_init(dev_cfg->device_base, dev_cfg->device_offset) != 0) + if (id_generator_init(dev_opts->device_base, dev_opts->device_offset) != 0) { STELLAR_LOG_ERROR("unable to init id generator"); return -1; @@ -306,8 +306,8 @@ int main(int argc, char **argv) // TODO load plugin - uint8_t nr_threads = pkt_io_cfg->nr_threads; - stellar_ctx->packet_io = packet_io_new(pkt_io_cfg); + uint8_t nr_threads = pkt_io_opts->nr_threads; + stellar_ctx->packet_io = packet_io_new(pkt_io_opts); if (stellar_ctx->packet_io == NULL) { STELLAR_LOG_ERROR("unable to create packet io");