🧪 test(enable lpi plus test): lpi test
This commit is contained in:
@@ -12,16 +12,22 @@
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
#include "lpi_plus/lpi_plus_internal.h"
|
||||
#include "stellar/lpi_plus.h"
|
||||
#include "gtest_lpip.h"
|
||||
|
||||
struct test_lpip_env
|
||||
{
|
||||
struct module_manager *mod_mgr;
|
||||
struct session_manager *sess_mgr;
|
||||
struct lpi_plus *lpip;
|
||||
int l7_exdata_idx;
|
||||
int session_num;
|
||||
};
|
||||
|
||||
#ifndef MAX_APPID_NUM
|
||||
#define MAX_APPID_NUM 8
|
||||
#endif
|
||||
|
||||
struct test_lpip_exdata
|
||||
{
|
||||
int appid[MAX_APPID_NUM];
|
||||
@@ -35,6 +41,7 @@ void stellar_test_result_setup()
|
||||
{
|
||||
if(g_result_json!=NULL)return;
|
||||
g_result_json=cJSON_CreateArray();
|
||||
return;
|
||||
}
|
||||
|
||||
char *stellar_test_result_json_export()
|
||||
@@ -111,41 +118,25 @@ static void gtest_lpip_exdata_free(int idx __attribute__((unused)), void *ex_ptr
|
||||
}
|
||||
|
||||
|
||||
static void gtest_lpip_on_appid_msg(struct session *sess, int appid[], int packet_sequence[],size_t appid_num, void *args)
|
||||
void gtest_lpip_on_packet(struct packet *pkt, struct module *mod)
|
||||
{
|
||||
if(sess==NULL || appid==NULL || args==NULL)return;
|
||||
struct test_lpip_env *env = (struct test_lpip_env *)args;
|
||||
struct test_lpip_exdata *test_appid_exdata=session_get_exdata(sess, env->l7_exdata_idx);
|
||||
if(test_appid_exdata==NULL)
|
||||
|
||||
struct test_lpip_env *env = (struct test_lpip_env *)module_get_ctx(mod);
|
||||
struct session *sess=packet_exdata_to_session(env->sess_mgr, pkt);
|
||||
struct test_lpip_exdata *test_appid_exdata=session_get_exdata(sess, env->l7_exdata_idx);
|
||||
if (test_appid_exdata==NULL)
|
||||
{
|
||||
test_appid_exdata = CALLOC(struct test_lpip_exdata, 1);
|
||||
test_appid_exdata->sess=sess;
|
||||
|
||||
}
|
||||
memcpy(test_appid_exdata->appid, appid, appid_num*sizeof(appid[0]));
|
||||
test_appid_exdata->appid_num=appid_num;
|
||||
session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata);
|
||||
return;
|
||||
}
|
||||
|
||||
static void on_session(struct session *sess, enum session_state state, struct packet *pkt, void *args)
|
||||
{
|
||||
if (state == SESSION_STATE_CLOSED)
|
||||
{
|
||||
assert(pkt == NULL);
|
||||
return;
|
||||
session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata);
|
||||
}
|
||||
|
||||
struct test_lpip_env *env = (struct test_lpip_env *)args;
|
||||
if (session_get_current_state(sess) == SESSION_STATE_OPENING)
|
||||
size_t appid_num=0;
|
||||
int32_t *appid = packet_exdata_to_lpip_appid(env->lpip, pkt, &appid_num);
|
||||
if(appid_num>0 && appid!=NULL)
|
||||
{
|
||||
struct test_lpip_exdata *test_appid_exdata = session_get_exdata(sess, env->l7_exdata_idx);
|
||||
if (test_appid_exdata == NULL)
|
||||
{
|
||||
test_appid_exdata = CALLOC(struct test_lpip_exdata, 1);
|
||||
test_appid_exdata->sess=sess;
|
||||
session_set_exdata(sess, env->l7_exdata_idx, test_appid_exdata);
|
||||
}
|
||||
test_appid_exdata->appid_num=appid_num;
|
||||
memcpy(test_appid_exdata->appid, appid, sizeof(*appid)*appid_num);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -156,27 +147,19 @@ struct module *gtest_lpip_module_init(struct module_manager *mod_mgr)
|
||||
struct module *lpip_mod = module_manager_get_module(mod_mgr, LPI_PLUS_MODULE_NAME);
|
||||
env->lpip=module_to_lpi_plus(lpip_mod);
|
||||
struct module *sess_mgr_mod=module_manager_get_module(mod_mgr, SESSION_MANAGER_MODULE_NAME);
|
||||
struct session_manager *sess_mgr = module_to_session_manager(sess_mgr_mod);
|
||||
if(sess_mgr == NULL)
|
||||
env->sess_mgr = module_to_session_manager(sess_mgr_mod);
|
||||
if(env->sess_mgr == NULL)
|
||||
{
|
||||
perror("gtest_lpi_plugin_load:stellar_module_get_session_manager failed !!!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
session_manager_subscribe_udp(sess_mgr, on_session, env);
|
||||
session_manager_subscribe_tcp(sess_mgr, on_session, env);
|
||||
|
||||
env->l7_exdata_idx = session_manager_new_session_exdata_index(sess_mgr, "EXDATA_L7", gtest_lpip_exdata_free, env);
|
||||
|
||||
lpi_plus_appid_subscribe(env->lpip, gtest_lpip_on_appid_msg, env);
|
||||
env->l7_exdata_idx = session_manager_new_session_exdata_index(env->sess_mgr, "EXDATA_L7", gtest_lpip_exdata_free, env);
|
||||
printf("gtest_lpip_module_init OK!\n");
|
||||
|
||||
return module_new("TEST_LPIP", env);
|
||||
return module_new(GTEST_LPIP_MODULE_NAME, env);
|
||||
}
|
||||
|
||||
void gtest_lpip_module_exit(struct module_manager *mod_mgr, struct module *mod)
|
||||
void gtest_lpip_module_exit(struct module_manager *mod_mgr __unused, struct module *mod)
|
||||
{
|
||||
assert(mod_mgr!=NULL);
|
||||
struct test_lpip_env *env = (struct test_lpip_env *)module_get_ctx(mod);
|
||||
free(env);
|
||||
printf("gtest_lpip_module_exit OK!\n");
|
||||
|
||||
Reference in New Issue
Block a user