open5gs/lib/s6a/s6a_app.c

136 lines
3.7 KiB
C
Raw Normal View History

2017-02-27 12:29:32 +00:00
#define TRACE_MODULE _s6a_app
2017-02-24 01:50:49 +00:00
#include "s6a_app.h"
2017-02-27 12:29:32 +00:00
struct s6a_conf *s6a_conf = NULL;
static struct s6a_conf _conf;
static pthread_t s6a_stats_th = (pthread_t)NULL;
2017-02-24 01:50:49 +00:00
2017-02-27 12:29:32 +00:00
static int s6a_conf_init(void)
2017-02-24 01:50:49 +00:00
{
2017-02-27 12:29:32 +00:00
s6a_conf = &_conf;
memset(s6a_conf, 0, sizeof(struct s6a_conf));
2017-02-24 01:50:49 +00:00
/* Set the default values */
2017-02-27 12:29:32 +00:00
s6a_conf->vendor_id = 10415; /* 3GPP Vendor ID */
s6a_conf->appli_id = 16777251; /* 3GPP S6A Application ID */
s6a_conf->mode = MODE_SERV | MODE_CLI;
s6a_conf->dest_realm = strdup(fd_g_config->cnf_diamrlm);
s6a_conf->dest_host = NULL;
2017-02-24 01:50:49 +00:00
/* Initialize the mutex */
2017-02-27 12:29:32 +00:00
CHECK_POSIX( pthread_mutex_init(&s6a_conf->stats_lock, NULL) );
2017-02-24 01:50:49 +00:00
return 0;
}
2017-02-27 12:29:32 +00:00
static void s6a_conf_dump(void)
2017-02-24 01:50:49 +00:00
{
2017-02-27 12:29:32 +00:00
LOG_N( "------- s6a configuration dump: ---------");
LOG_N( " Vendor Id .......... : %u", s6a_conf->vendor_id);
LOG_N( " Application Id ..... : %u", s6a_conf->appli_id);
LOG_N( " Mode ............... : %s%s",
s6a_conf->mode & MODE_SERV ? "Serv" : "",
s6a_conf->mode & MODE_CLI ? "Cli" : "");
LOG_N( " Destination Realm .. : %s",
s6a_conf->dest_realm ?: "- none -");
LOG_N( " Destination Host ... : %s",
s6a_conf->dest_host ?: "- none -");
LOG_N( "------- /s6a configuration dump ---------");
2017-02-24 01:50:49 +00:00
}
/* Function to display statistics periodically */
2017-02-27 12:29:32 +00:00
static void * s6a_stats(void * arg) {
2017-02-24 01:50:49 +00:00
struct timespec start, now;
struct ta_stats copy;
/* Get the start time */
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &start), );
/* Now, loop until canceled */
while (1) {
/* Display statistics every XX seconds */
2017-02-27 12:29:32 +00:00
sleep(10);
2017-02-24 01:50:49 +00:00
/* Now, get the current stats */
2017-02-27 12:29:32 +00:00
CHECK_POSIX_DO( pthread_mutex_lock(&s6a_conf->stats_lock), );
memcpy(&copy, &s6a_conf->stats, sizeof(struct ta_stats));
CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_conf->stats_lock), );
2017-02-24 01:50:49 +00:00
/* Get the current execution time */
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), );
/* Now, display everything */
fd_log_debug( "------- app_test statistics ---------");
if (now.tv_nsec >= start.tv_nsec) {
fd_log_debug( " Executing for: %d.%06ld sec",
(int)(now.tv_sec - start.tv_sec),
(long)(now.tv_nsec - start.tv_nsec) / 1000);
} else {
fd_log_debug( " Executing for: %d.%06ld sec",
(int)(now.tv_sec - 1 - start.tv_sec),
(long)(now.tv_nsec + 1000000000 - start.tv_nsec) / 1000);
}
2017-02-27 12:29:32 +00:00
if (s6a_conf->mode & MODE_SERV) {
2017-02-24 01:50:49 +00:00
fd_log_debug( " Server: %llu message(s) echoed", copy.nb_echoed);
}
2017-02-27 12:29:32 +00:00
if (s6a_conf->mode & MODE_CLI) {
2017-02-24 01:50:49 +00:00
fd_log_debug( " Client:");
fd_log_debug( " %llu message(s) sent", copy.nb_sent);
fd_log_debug( " %llu error(s) received", copy.nb_errs);
fd_log_debug( " %llu answer(s) received", copy.nb_recv);
}
fd_log_debug( "-------------------------------------");
}
return NULL; /* never called */
}
/* entry point */
int s6a_app_init(void)
2017-02-24 01:50:49 +00:00
{
/* Initialize configuration */
2017-02-27 12:29:32 +00:00
CHECK_FCT( s6a_conf_init() );
2017-02-24 01:50:49 +00:00
2017-02-27 12:29:32 +00:00
s6a_conf_dump();
2017-02-24 01:50:49 +00:00
/* Install objects definitions for this test application */
2017-02-27 13:14:58 +00:00
CHECK_FCT( s6a_dict_init() );
#if 0
2017-02-24 01:50:49 +00:00
/* Install the handlers for incoming messages */
if (ta_conf->mode & MODE_SERV) {
CHECK_FCT( ta_serv_init() );
}
/* Start the signal handler thread */
if (ta_conf->mode & MODE_CLI) {
CHECK_FCT( ta_cli_init() );
2017-02-24 01:50:49 +00:00
}
/* Advertise the support for the test application in the peer */
CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) );
2017-02-27 12:29:32 +00:00
#endif
2017-02-24 01:50:49 +00:00
/* Start the statistics thread */
2017-02-27 12:29:32 +00:00
CHECK_POSIX( pthread_create(&s6a_stats_th, NULL, s6a_stats, NULL) );
2017-02-24 01:50:49 +00:00
return 0;
}
/* Unload */
void s6a_app_final(void)
2017-02-24 01:50:49 +00:00
{
2017-02-27 12:29:32 +00:00
#if 0
2017-02-24 01:50:49 +00:00
if (ta_conf->mode & MODE_CLI)
ta_cli_fini();
if (ta_conf->mode & MODE_SERV)
ta_serv_fini();
2017-02-27 12:29:32 +00:00
#endif
CHECK_FCT_DO( fd_thr_term(&s6a_stats_th), );
CHECK_POSIX_DO( pthread_mutex_destroy(&s6a_conf->stats_lock), );
2017-02-24 01:50:49 +00:00
}