TSG-14351 tsg-service-chaining-engine通过Mock Mrzcpd进行单元测试

This commit is contained in:
luwenpeng
2023-03-30 17:44:33 +08:00
parent 0e85d3c9c5
commit 0f45abedc8
32 changed files with 1482 additions and 19 deletions

View File

@@ -65,6 +65,7 @@ static struct session_table_addr g_handle_addr;
static struct sf_status *g_sf_status = NULL;
int sleep_ms = 300;
int enable = 1;
char path[BFD_PATHLEN];
char hc_dev_name[HC_DEV_NAME_LEN];
char local_address[HC_LOCAL_ADDRESS_LEN];
@@ -98,11 +99,17 @@ void health_check_session_init(const char *profile)
{
memset(&g_handle, 0, sizeof(g_handle));
pthread_rwlock_init(&g_handle.rwlock, NULL);
MESA_load_profile_int_def(profile, "bfdd", "enable", &enable, 1);
MESA_load_profile_string_def(profile, "bfdd", "path", path, sizeof(path), "/var/run/frr/bfdd.vty");
MESA_load_profile_string_def(profile, "bfdd", "device", hc_dev_name, sizeof(hc_dev_name), "eth0");
MESA_load_profile_string_def(profile, "bfdd", "local_address", local_address, sizeof(local_address), "127.0.0.1");
MESA_load_profile_string_def(profile, "bfdd", "gateway", gateway_address, sizeof(gateway_address), "127.0.0.1");
if (enable == 0)
{
return;
}
g_sf_status = sf_status_create(profile);
// TODO: 循环获取?
get_mac_by_addr(gateway_address, default_gw_mac);
@@ -204,6 +211,10 @@ uint64_t health_check_session_add(int profile_id, const struct health_check *pol
struct node_addr *node = NULL;
struct session_iterm *tmp = NULL;
if (enable == 0)
{
return 1;
}
session_id = health_check_get_session_id();
if (session_id == 0) {
LOG_ERROR("health check get session id failed!");
@@ -251,6 +262,11 @@ int health_check_session_del(uint64_t session_id, int profile_id)
struct bfd_vtysh_client client;
struct session_iterm *tmp = NULL;
if (enable == 0)
{
return 0;
}
tmp = health_check_get_iterm_by_id(session_id);
if (!tmp) {
LOG_DEBUG("health check session table delete: session id [%lu] not exists", session_id);
@@ -291,6 +307,11 @@ int health_check_session_get_status(uint64_t session_id)
int status = 0;
struct session_iterm *tmp = NULL;
if (enable == 0)
{
return 1;
}
pthread_rwlock_rdlock(&g_handle.rwlock);
HASH_FIND(hh1, g_handle.root_by_id, &session_id, sizeof(session_id), tmp);
if (!tmp) {
@@ -311,6 +332,11 @@ int health_check_session_set_status(uint64_t session_id, int is_active)
{
struct session_iterm *tmp = NULL;
if (enable == 0)
{
return 0;
}
pthread_rwlock_wrlock(&g_handle.rwlock);
HASH_FIND(hh1, g_handle.root_by_id, &session_id, sizeof(session_id), tmp);
if (!tmp) {
@@ -455,6 +481,10 @@ int health_check_session_get_mac(uint64_t session_id, char *mac_buff)
struct session_iterm *tmp = NULL;
uint8_t init_mac[HC_MAC_LEN] = {0};
if (enable == 0)
{
return 0;
}
pthread_rwlock_rdlock(&g_handle.rwlock);
HASH_FIND(hh1, g_handle.root_by_id, &session_id, sizeof(session_id), tmp);
if (!tmp) {