feature: TSG-21852 service_function_status support fieldstat4

This commit is contained in:
luwenpeng
2024-07-19 10:02:07 +08:00
parent 9e63902c0d
commit c8d40f1347
15 changed files with 222 additions and 229 deletions

View File

@@ -31,6 +31,7 @@
#define PACKET_SIZE 64
#define HC_DEV_NAME_LEN 16
#define HC_LOCAL_ADDRESS_LEN 64
#define TIMESPEC_TO_MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000)
struct session_table
{
@@ -74,7 +75,7 @@ static struct session_table_addr g_handle_bfd;
static struct session_table_addr g_handle_none;
static struct sf_status *g_sf_status = NULL;
int sleep_ms = 300;
int next_check_wait_ms = 300;
int enable = 1;
int icmp_cycle_time_s = 10;
char path[BFD_PATHLEN];
@@ -335,7 +336,7 @@ static int send_icmp_cycle()
return pid;
}
void health_check_session_init(const char *profile)
void health_check_session_init(const char *profile, struct kafka *kfk)
{
char default_gw_mac_str[32] = { 0 };
memset(&g_handle, 0, sizeof(g_handle));
@@ -358,7 +359,7 @@ void health_check_session_init(const char *profile)
return;
}
g_sf_status = sf_status_create(profile);
g_sf_status = sf_status_create(profile, kfk);
if (strlen(gateway_address) > 0) {
health_check_method_table_add(&g_handle_none, gateway_address);
}
@@ -503,7 +504,7 @@ uint64_t health_check_session_add(int profile_id, int vsys_id, const struct heal
// return 0 : success
// return -1 : key not exist
int health_check_session_del(uint64_t session_id, int profile_id)
int health_check_session_del(uint64_t session_id, int profile_id, int vsys_id)
{
int ret = 0;
struct session_iterm *tmp = NULL;
@@ -533,7 +534,10 @@ int health_check_session_del(uint64_t session_id, int profile_id)
end:
HASH_DELETE(hh1, g_handle.root_by_id, tmp);
sf_status_delete(g_sf_status, profile_id);
struct sf_status_key key = {0};
key.vsys_id = vsys_id;
key.sf_profile_id = profile_id;
sf_status_delete(g_sf_status, &key);
pthread_rwlock_unlock(&g_handle.rwlock);
free(tmp);
tmp = NULL;
@@ -623,7 +627,7 @@ static int get_mac_by_addr(char *addr, uint8_t *buf)
static void *_health_check_session_foreach(void *arg)
{
int is_active = 0;
int interval_s = sf_status_get_interval(g_sf_status);
int ouput_interval_ms = sf_status_get_ouput_interval_ms(g_sf_status);
struct bfd_vtysh_client client;
struct session_iterm *tmp = NULL;
struct session_iterm *node = NULL;
@@ -632,10 +636,10 @@ static void *_health_check_session_foreach(void *arg)
struct sockaddr_in addr;
struct timespec current_time;
struct timespec g_status_last_send_time;
struct timespec last_output_time;
clock_gettime(CLOCK_MONOTONIC, &current_time);
clock_gettime(CLOCK_MONOTONIC, &g_status_last_send_time);
last_output_time = current_time;
health_check_session_init_bfd_client(&client);
bfd_vtysh_connect(&client);
@@ -661,7 +665,10 @@ static void *_health_check_session_foreach(void *arg)
is_active = 0;
}
sf_status_update(g_sf_status, node->vsys_id, node->profile_id, is_active, 0);
struct sf_status_key key = {0};
key.vsys_id = node->vsys_id;
key.sf_profile_id = node->profile_id;
sf_status_update(g_sf_status, &key, is_active, 0);
if (node->is_active != is_active) {
node->is_active = is_active;
if (node->is_active == 1) {
@@ -673,41 +680,31 @@ static void *_health_check_session_foreach(void *arg)
health_check_method_table_set_mac(&g_handle_bfd, node->policy.address, init_mac);
}
}
if (sleep_ms > node->policy.interval_ms)
sleep_ms = node->policy.interval_ms;
if (next_check_wait_ms > node->policy.interval_ms)
next_check_wait_ms = node->policy.interval_ms;
}
pthread_rwlock_unlock(&g_handle.rwlock);
clock_gettime(CLOCK_MONOTONIC, &current_time);
if (current_time.tv_sec - g_status_last_send_time.tv_sec >= interval_s)
int next_output_wait_ms = ouput_interval_ms - (TIMESPEC_TO_MSEC(current_time) - TIMESPEC_TO_MSEC(last_output_time));
if (next_output_wait_ms <= 0)
{
sf_status_send(g_sf_status);
clock_gettime(CLOCK_MONOTONIC, &g_status_last_send_time);
next_output_wait_ms = 0;
}
// interval_s : 1000 ms
// sleep_ms : 900 ms
if (interval_s * 1000 > sleep_ms)
if (next_output_wait_ms >= next_check_wait_ms)
{
usleep(sleep_ms * 1000);
usleep(next_check_wait_ms * 1000);
}
// interval_s : 900 ms
// sleep_ms : 1000 ms
else
{
int tmp_time = sleep_ms;
while(tmp_time > interval_s * 1000) {
usleep(interval_s * 1000 * 1000);
usleep(next_output_wait_ms * 1000);
clock_gettime(CLOCK_MONOTONIC, &current_time);
if (current_time.tv_sec - g_status_last_send_time.tv_sec >= interval_s)
{
sf_status_send(g_sf_status);
clock_gettime(CLOCK_MONOTONIC, &g_status_last_send_time);
}
tmp_time -= interval_s * 1000;
}
usleep(tmp_time * 1000);
clock_gettime(CLOCK_MONOTONIC, &current_time);
sf_status_output(g_sf_status);
last_output_time = current_time;
usleep((next_check_wait_ms - next_output_wait_ms) * 1000);
}
}
bfd_vtysh_close(&client);