move stellar_core/stellar_stat from core to infra
This commit is contained in:
@@ -60,7 +60,7 @@ void stellar_emit_datapath_telemetry(struct packet *pkt, const char * module, c
|
|||||||
|
|
||||||
int stellar_get_worker_thread_num(struct stellar *st);
|
int stellar_get_worker_thread_num(struct stellar *st);
|
||||||
uint16_t stellar_get_current_thread_index();
|
uint16_t stellar_get_current_thread_index();
|
||||||
// only send user crafted packet, can't send packet which come from network
|
// only send user build packet, can't send packet which come from network
|
||||||
void stellar_send_build_packet(struct stellar *st, struct packet *pkt);
|
void stellar_send_build_packet(struct stellar *st, struct packet *pkt);
|
||||||
|
|
||||||
struct stellar;
|
struct stellar;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
set(INFRA tuple packet_parser packet_io ip_reassembly tcp_reassembly session_manager plugin_manager core)
|
set(INFRA tuple packet_parser packet_io ip_reassembly tcp_reassembly session_manager plugin_manager)
|
||||||
set(DEPS bitmap dablooms interval_tree logger nmx_pool rbtree timeout toml)
|
set(DEPS bitmap dablooms interval_tree logger nmx_pool rbtree timeout toml)
|
||||||
set(DECODERS http lpi)
|
set(DECODERS http lpi)
|
||||||
set(WHOLE_ARCHIVE ${DEPS} ${INFRA} ${DECODERS})
|
set(WHOLE_ARCHIVE ${DEPS} ${INFRA} ${DECODERS})
|
||||||
@@ -9,13 +9,13 @@ endforeach()
|
|||||||
|
|
||||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/stellar_lib.c "")
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/stellar_lib.c "")
|
||||||
|
|
||||||
add_library(stellar_lib SHARED stellar_lib.c)
|
add_library(stellar_lib SHARED stellar_lib.c stellar_core.c stellar_stat.c)
|
||||||
set_target_properties(stellar_lib PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
|
set_target_properties(stellar_lib PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
|
||||||
target_link_libraries(stellar_lib PRIVATE pthread -Wl,--whole-archive ${WHOLE_ARCHIVE} -Wl,--no-whole-archive)
|
target_link_libraries(stellar_lib PRIVATE pthread -Wl,--whole-archive ${WHOLE_ARCHIVE} -Wl,--no-whole-archive)
|
||||||
target_link_options(stellar_lib PRIVATE -rdynamic)
|
target_link_options(stellar_lib PRIVATE -rdynamic)
|
||||||
set_target_properties(stellar_lib PROPERTIES OUTPUT_NAME "stellar")
|
set_target_properties(stellar_lib PROPERTIES OUTPUT_NAME "stellar")
|
||||||
|
|
||||||
add_executable(stellar main.c)
|
add_executable(stellar main.c stellar_core.c stellar_stat.c)
|
||||||
set_target_properties(stellar PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
|
set_target_properties(stellar PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
|
||||||
target_link_libraries(stellar PRIVATE pthread -Wl,--whole-archive ${WHOLE_ARCHIVE} -Wl,--no-whole-archive)
|
target_link_libraries(stellar PRIVATE pthread -Wl,--whole-archive ${WHOLE_ARCHIVE} -Wl,--no-whole-archive)
|
||||||
target_link_options(stellar PRIVATE -rdynamic)
|
target_link_options(stellar PRIVATE -rdynamic)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
|
|
||||||
add_library(core stellar_stat.c stellar_core.c)
|
|
||||||
target_link_libraries(core PUBLIC packet_io ip_reassembly plugin_manager)
|
|
||||||
@@ -9,7 +9,7 @@ target_include_directories(packet_parser PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
|||||||
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/deps/uthash)
|
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/deps/uthash)
|
||||||
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/deps/logger)
|
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/deps/logger)
|
||||||
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
||||||
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/infra/core)
|
target_include_directories(packet_parser PUBLIC ${CMAKE_SOURCE_DIR}/infra)
|
||||||
target_link_libraries(packet_parser tuple logger dablooms)
|
target_link_libraries(packet_parser tuple logger dablooms)
|
||||||
|
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
@@ -79,7 +79,7 @@ static void update_gtp1_hdr(struct gtp1_hdr *gtp, int trim_len)
|
|||||||
gtp1_hdr_set_msg_len(gtp, msg_len - trim_len);
|
gtp1_hdr_set_msg_len(gtp, msg_len - trim_len);
|
||||||
if (gtp1_hdr_get_seq_flag(gtp) && gtp1_hdr_get_seq(gtp))
|
if (gtp1_hdr_get_seq_flag(gtp) && gtp1_hdr_get_seq(gtp))
|
||||||
{
|
{
|
||||||
PACKET_CRAFT_LOG_ERROR("crafted packets may be dropped by intermediate devices, the GTPv1 layer requires a sequence number");
|
PACKET_CRAFT_LOG_ERROR("build packets may be dropped by intermediate devices, the GTPv1 layer requires a sequence number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ static void update_gtp2_hdr(struct gtp2_hdr *gtp, int trim_len)
|
|||||||
gtp2_hdr_set_msg_len(gtp, msg_len - trim_len);
|
gtp2_hdr_set_msg_len(gtp, msg_len - trim_len);
|
||||||
if (gtp2_hdr_get_seq(gtp))
|
if (gtp2_hdr_get_seq(gtp))
|
||||||
{
|
{
|
||||||
PACKET_CRAFT_LOG_ERROR("crafted packets may be dropped by intermediate devices, the GTPv2 layer requires a sequence number");
|
PACKET_CRAFT_LOG_ERROR("build packets may be dropped by intermediate devices, the GTPv2 layer requires a sequence number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
add_library(plugin_manager plugin_manager.c)
|
add_library(plugin_manager plugin_manager.c)
|
||||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
target_include_directories(plugin_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/include/)
|
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/include/)
|
||||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/core)
|
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/)
|
||||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/packet_parser)
|
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/packet_parser)
|
||||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/session_manager)
|
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/session_manager)
|
||||||
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/tuple)
|
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/tuple)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ add_library(session_manager
|
|||||||
session_transition.c
|
session_transition.c
|
||||||
)
|
)
|
||||||
target_include_directories(session_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
target_include_directories(session_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/core)
|
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/)
|
||||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
||||||
target_link_libraries(session_manager timeout packet_parser tcp_reassembly)
|
target_link_libraries(session_manager timeout packet_parser tcp_reassembly)
|
||||||
|
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ static int stellar_thread_init(struct stellar *st)
|
|||||||
struct stellar_thread *thread = &runtime->threads[i];
|
struct stellar_thread *thread = &runtime->threads[i];
|
||||||
thread->idx = i;
|
thread->idx = i;
|
||||||
thread->is_runing = 0;
|
thread->is_runing = 0;
|
||||||
|
thread->st = st;
|
||||||
|
|
||||||
config->sess_mgr_cfg->session_id_seed = config->instance_id << 8 | i;
|
config->sess_mgr_cfg->session_id_seed = config->instance_id << 8 | i;
|
||||||
thread->sess_mgr = session_manager_new(config->sess_mgr_cfg, now_ms);
|
thread->sess_mgr = session_manager_new(config->sess_mgr_cfg, now_ms);
|
||||||
@@ -334,30 +335,11 @@ static int stellar_thread_init(struct stellar *st)
|
|||||||
CORE_LOG_ERROR("unable to create ip reassemble manager");
|
CORE_LOG_ERROR("unable to create ip reassemble manager");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
thread->st = st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stellar_thread_clean(struct stellar *st)
|
|
||||||
{
|
|
||||||
struct stellar_runtime *runtime = &st->runtime;
|
|
||||||
struct stellar_config *config = &st->config;
|
|
||||||
|
|
||||||
CORE_LOG_FATAL("cleaning worker thread context ...");
|
|
||||||
for (uint16_t i = 0; i < config->pkt_io_cfg->nr_worker_thread; i++)
|
|
||||||
{
|
|
||||||
struct stellar_thread *thread = &runtime->threads[i];
|
|
||||||
if (ATOMIC_READ(&thread->is_runing) == 0)
|
|
||||||
{
|
|
||||||
ip_reassembly_free(thread->ip_reass);
|
|
||||||
session_manager_free(thread->sess_mgr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CORE_LOG_FATAL("worker thread context cleaned");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int stellar_thread_run(struct stellar *st)
|
static int stellar_thread_run(struct stellar *st)
|
||||||
{
|
{
|
||||||
struct stellar_runtime *runtime = &st->runtime;
|
struct stellar_runtime *runtime = &st->runtime;
|
||||||
@@ -381,16 +363,16 @@ static void stellar_thread_join(struct stellar *st)
|
|||||||
struct stellar_runtime *runtime = &st->runtime;
|
struct stellar_runtime *runtime = &st->runtime;
|
||||||
struct stellar_config *config = &st->config;
|
struct stellar_config *config = &st->config;
|
||||||
|
|
||||||
CORE_LOG_FATAL("waiting worker thread stop ...");
|
CORE_LOG_FATAL("waiting worker thread exit");
|
||||||
for (uint16_t i = 0; i < config->pkt_io_cfg->nr_worker_thread; i++)
|
for (uint16_t i = 0; i < config->pkt_io_cfg->nr_worker_thread; i++)
|
||||||
{
|
{
|
||||||
struct stellar_thread *thread = &runtime->threads[i];
|
struct stellar_thread *thread = &runtime->threads[i];
|
||||||
while (ATOMIC_READ(&thread->is_runing) == 1)
|
pthread_join(thread->tid, NULL);
|
||||||
{
|
|
||||||
usleep(1000); // 1ms
|
ip_reassembly_free(thread->ip_reass);
|
||||||
}
|
session_manager_free(thread->sess_mgr);
|
||||||
}
|
}
|
||||||
CORE_LOG_FATAL("all worker thread stoped");
|
CORE_LOG_FATAL("all worker thread exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg_file, const char *log_cfg_file)
|
struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg_file, const char *log_cfg_file)
|
||||||
@@ -429,9 +411,7 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
|
|||||||
}
|
}
|
||||||
__thread_local_logger = runtime->logger;
|
__thread_local_logger = runtime->logger;
|
||||||
CORE_LOG_FATAL("stellar start (version: %s)\n %s", version, logo_str);
|
CORE_LOG_FATAL("stellar start (version: %s)\n %s", version, logo_str);
|
||||||
CORE_LOG_FATAL("stellar config file : %s", stellar_cfg_file);
|
CORE_LOG_FATAL("stellar config file: %s, plugin config file: %s, log config file: %s", stellar_cfg_file, plugin_cfg_file, log_cfg_file);
|
||||||
CORE_LOG_FATAL("plugin config file : %s", plugin_cfg_file);
|
|
||||||
CORE_LOG_FATAL("log config file : %s", log_cfg_file);
|
|
||||||
|
|
||||||
if (load_and_validate_toml_integer_config(stellar_cfg_file, "instance.id", (uint64_t *)&config->instance_id, 0, 4095) != 0)
|
if (load_and_validate_toml_integer_config(stellar_cfg_file, "instance.id", (uint64_t *)&config->instance_id, 0, 4095) != 0)
|
||||||
{
|
{
|
||||||
@@ -463,11 +443,10 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
|
|||||||
CORE_LOG_ERROR("unable to create stellar stat config");
|
CORE_LOG_ERROR("unable to create stellar stat config");
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
session_manager_config_print(config->sess_mgr_cfg);
|
|
||||||
ip_reassembly_config_print(config->ip_reass_cfg);
|
|
||||||
packet_io_config_print(config->pkt_io_cfg);
|
|
||||||
stellar_stat_config_print(config->stat_cfg);
|
stellar_stat_config_print(config->stat_cfg);
|
||||||
|
packet_io_config_print(config->pkt_io_cfg);
|
||||||
|
ip_reassembly_config_print(config->ip_reass_cfg);
|
||||||
|
session_manager_config_print(config->sess_mgr_cfg);
|
||||||
|
|
||||||
runtime->stat = stellar_stat_new(config->stat_cfg, clock_get_real_time_ms());
|
runtime->stat = stellar_stat_new(config->stat_cfg, clock_get_real_time_ms());
|
||||||
if (runtime->stat == NULL)
|
if (runtime->stat == NULL)
|
||||||
@@ -544,7 +523,6 @@ void stellar_run(struct stellar *st)
|
|||||||
}
|
}
|
||||||
|
|
||||||
stellar_thread_join(st);
|
stellar_thread_join(st);
|
||||||
stellar_stat_output(runtime->stat, UINT64_MAX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void stellar_free(struct stellar *st)
|
void stellar_free(struct stellar *st)
|
||||||
@@ -554,7 +532,6 @@ void stellar_free(struct stellar *st)
|
|||||||
struct stellar_runtime *runtime = &st->runtime;
|
struct stellar_runtime *runtime = &st->runtime;
|
||||||
struct stellar_config *config = &st->config;
|
struct stellar_config *config = &st->config;
|
||||||
|
|
||||||
stellar_thread_clean(st);
|
|
||||||
packet_io_free(runtime->packet_io);
|
packet_io_free(runtime->packet_io);
|
||||||
plugin_manager_exit(runtime->plug_mgr);
|
plugin_manager_exit(runtime->plug_mgr);
|
||||||
stellar_stat_free(runtime->stat);
|
stellar_stat_free(runtime->stat);
|
||||||
@@ -593,11 +570,6 @@ void stellar_reload_log_level(struct stellar *st)
|
|||||||
* Stellar Utility Function
|
* Stellar Utility Function
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
struct packet_io *stellar_get_packet_io(const struct stellar *st)
|
|
||||||
{
|
|
||||||
return st->runtime.packet_io;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct plugin_manager_schema *stellar_get_plugin_manager(const struct stellar *st)
|
struct plugin_manager_schema *stellar_get_plugin_manager(const struct stellar *st)
|
||||||
{
|
{
|
||||||
return st->runtime.plug_mgr;
|
return st->runtime.plug_mgr;
|
||||||
@@ -608,32 +580,12 @@ void stellar_set_plugin_manger(struct stellar *st, struct plugin_manager_schema
|
|||||||
st->runtime.plug_mgr = plug_mgr;
|
st->runtime.plug_mgr = plug_mgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct session_manager *stellar_get_session_manager(const struct stellar *st)
|
// only send user build packet, can't send packet which come from network
|
||||||
{
|
|
||||||
uint16_t idx = stellar_get_current_thread_index();
|
|
||||||
return st->runtime.threads[idx].sess_mgr;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t stellar_get_current_thread_index()
|
|
||||||
{
|
|
||||||
if (__current_thread_idx == UINT16_MAX)
|
|
||||||
{
|
|
||||||
printf("get current thread index before set\n");
|
|
||||||
abort();
|
|
||||||
return UINT16_MAX;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return __current_thread_idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// only send user crafted packet, can't send packet which come from network
|
|
||||||
void stellar_send_build_packet(struct stellar *st, struct packet *pkt)
|
void stellar_send_build_packet(struct stellar *st, struct packet *pkt)
|
||||||
{
|
{
|
||||||
uint16_t thr_idx = stellar_get_current_thread_index();
|
uint16_t thr_idx = stellar_get_current_thread_index();
|
||||||
struct packet_io *packet_io = stellar_get_packet_io(st);
|
struct packet_io *packet_io = st->runtime.packet_io;
|
||||||
struct session_manager *sess_mgr = stellar_get_session_manager(st);
|
struct session_manager *sess_mgr = st->runtime.threads[thr_idx].sess_mgr;
|
||||||
session_manager_record_duplicated_packet(sess_mgr, pkt);
|
session_manager_record_duplicated_packet(sess_mgr, pkt);
|
||||||
|
|
||||||
if (packet_get_origin_ctx(pkt))
|
if (packet_get_origin_ctx(pkt))
|
||||||
@@ -653,6 +605,20 @@ int stellar_get_worker_thread_num(struct stellar *st)
|
|||||||
return st->config.pkt_io_cfg->nr_worker_thread;
|
return st->config.pkt_io_cfg->nr_worker_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t stellar_get_current_thread_index()
|
||||||
|
{
|
||||||
|
if (__current_thread_idx == UINT16_MAX)
|
||||||
|
{
|
||||||
|
printf("get current thread index before set\n");
|
||||||
|
abort();
|
||||||
|
return UINT16_MAX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return __current_thread_idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct logger *stellar_get_logger(struct stellar *st)
|
struct logger *stellar_get_logger(struct stellar *st)
|
||||||
{
|
{
|
||||||
if (st)
|
if (st)
|
||||||
@@ -7,14 +7,10 @@ extern "C"
|
|||||||
|
|
||||||
#include "stellar/stellar.h"
|
#include "stellar/stellar.h"
|
||||||
|
|
||||||
struct packet_io *stellar_get_packet_io(const struct stellar *st);
|
|
||||||
struct session_manager *stellar_get_session_manager(const struct stellar *st);
|
|
||||||
struct plugin_manager_schema *stellar_get_plugin_manager(const struct stellar *st);
|
|
||||||
// TODO fix plugin manager, delete this function
|
// TODO fix plugin manager, delete this function
|
||||||
|
struct plugin_manager_schema *stellar_get_plugin_manager(const struct stellar *st);
|
||||||
void stellar_set_plugin_manger(struct stellar *st, struct plugin_manager_schema *plug_mgr);
|
void stellar_set_plugin_manger(struct stellar *st, struct plugin_manager_schema *plug_mgr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
add_library(debug_plugin SHARED debug_plugin.c)
|
add_library(debug_plugin SHARED debug_plugin.c)
|
||||||
target_link_libraries(debug_plugin stellar_lib session_manager packet_parser)
|
target_link_libraries(debug_plugin stellar_lib session_manager packet_parser)
|
||||||
target_include_directories(debug_plugin PUBLIC ${CMAKE_SOURCE_DIR}/include/)
|
target_include_directories(debug_plugin PUBLIC ${CMAKE_SOURCE_DIR}/include/)
|
||||||
target_include_directories(debug_plugin PUBLIC ${CMAKE_SOURCE_DIR}/infra/core/utils)
|
target_include_directories(debug_plugin PUBLIC ${CMAKE_SOURCE_DIR}/infra)
|
||||||
set_target_properties(debug_plugin PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
|
set_target_properties(debug_plugin PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
|
||||||
|
|
||||||
file(COPY ./conf/ DESTINATION ./conf/)
|
file(COPY ./conf/ DESTINATION ./conf/)
|
||||||
Reference in New Issue
Block a user