2017-02-27 12:29:32 +00:00
|
|
|
#define TRACE_MODULE _s6a_app
|
2017-02-24 01:50:49 +00:00
|
|
|
|
2017-02-28 11:01:46 +00:00
|
|
|
#include "core_debug.h"
|
|
|
|
|
2017-02-24 01:50:49 +00:00
|
|
|
#include "s6a_app.h"
|
|
|
|
|
2017-02-27 12:29:32 +00:00
|
|
|
static pthread_t s6a_stats_th = (pthread_t)NULL;
|
2017-02-24 01:50:49 +00:00
|
|
|
|
2017-02-28 02:21:10 +00:00
|
|
|
static void s6a_config_dump(void)
|
2017-02-24 01:50:49 +00:00
|
|
|
{
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, "------- s6a configuration dump: ---------\n");
|
|
|
|
d_trace(1, " Mode ............... : %s%s\n",
|
2017-02-28 02:21:10 +00:00
|
|
|
s6a_config->mode & MODE_MME ? "MME" : "",
|
|
|
|
s6a_config->mode & MODE_HSS ? "HSS" : "");
|
2017-02-28 11:31:06 +00:00
|
|
|
d_trace(1, " Vendor Id .......... : %u\n", s6a_config->vendor_id);
|
|
|
|
d_trace(1, " Application Id ..... : %u\n", s6a_config->appli_id);
|
|
|
|
d_trace(1, " Duration ........... : %d(sec)\n", s6a_config->duration);
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, "------- /s6a configuration dump ---------\n");
|
2017-02-24 01:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Function to display statistics periodically */
|
2017-02-28 03:03:53 +00:00
|
|
|
static void * s6a_stats(void * arg)
|
|
|
|
{
|
2017-02-24 01:50:49 +00:00
|
|
|
struct timespec start, now;
|
2017-02-28 11:31:06 +00:00
|
|
|
struct s6a_stats copy;
|
2017-02-24 01:50:49 +00:00
|
|
|
|
|
|
|
/* 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-28 11:31:06 +00:00
|
|
|
sleep(s6a_config->duration);
|
2017-02-24 01:50:49 +00:00
|
|
|
|
|
|
|
/* Now, get the current stats */
|
2017-02-28 02:21:10 +00:00
|
|
|
CHECK_POSIX_DO( pthread_mutex_lock(&s6a_config->stats_lock), );
|
2017-02-28 11:31:06 +00:00
|
|
|
memcpy(©, &s6a_config->stats, sizeof(struct s6a_stats));
|
2017-02-28 02:21:10 +00:00
|
|
|
CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->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 */
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, "------- app_test statistics ---------\n");
|
2017-02-28 10:40:44 +00:00
|
|
|
if (now.tv_nsec >= start.tv_nsec)
|
|
|
|
{
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, " Executing for: %d.%06ld sec\n",
|
2017-02-24 01:50:49 +00:00
|
|
|
(int)(now.tv_sec - start.tv_sec),
|
|
|
|
(long)(now.tv_nsec - start.tv_nsec) / 1000);
|
2017-02-28 10:40:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, " Executing for: %d.%06ld sec\n",
|
2017-02-24 01:50:49 +00:00
|
|
|
(int)(now.tv_sec - 1 - start.tv_sec),
|
|
|
|
(long)(now.tv_nsec + 1000000000 - start.tv_nsec) / 1000);
|
|
|
|
}
|
|
|
|
|
2017-02-28 10:40:44 +00:00
|
|
|
if (s6a_config->mode & MODE_HSS)
|
|
|
|
{
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, " HSS: %llu message(s) echoed\n",
|
2017-02-28 10:40:44 +00:00
|
|
|
copy.nb_echoed);
|
2017-02-24 01:50:49 +00:00
|
|
|
}
|
2017-02-28 10:40:44 +00:00
|
|
|
if (s6a_config->mode & MODE_MME)
|
|
|
|
{
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, " MME:\n");
|
|
|
|
d_trace(1, " %llu message(s) sent\n", copy.nb_sent);
|
|
|
|
d_trace(1, " %llu error(s) received\n", copy.nb_errs);
|
|
|
|
d_trace(1, " %llu answer(s) received\n", copy.nb_recv);
|
|
|
|
d_trace(1, " fastest: %ld.%06ld sec.\n",
|
|
|
|
copy.shortest / 1000000, copy.shortest % 1000000);
|
|
|
|
d_trace(1, " slowest: %ld.%06ld sec.\n",
|
|
|
|
copy.longest / 1000000, copy.longest % 1000000);
|
|
|
|
d_trace(1, " Average: %ld.%06ld sec.\n",
|
|
|
|
copy.avg / 1000000, copy.avg % 1000000);
|
2017-02-24 01:50:49 +00:00
|
|
|
}
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace(1, "-------------------------------------\n");
|
2017-02-24 01:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL; /* never called */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entry point */
|
2017-02-28 02:21:10 +00:00
|
|
|
int s6a_app_init(int mode)
|
2017-02-24 01:50:49 +00:00
|
|
|
{
|
2017-02-28 11:01:46 +00:00
|
|
|
d_trace_level(&_s6a_app, 1);
|
|
|
|
|
2017-02-28 03:03:53 +00:00
|
|
|
/* Configure Application Mode(MME, HSS) */
|
|
|
|
s6a_config->mode = mode;
|
|
|
|
|
2017-02-28 02:21:10 +00:00
|
|
|
/* Initialize the mutex */
|
|
|
|
CHECK_POSIX( pthread_mutex_init(&s6a_config->stats_lock, NULL) );
|
2017-02-24 01:50:49 +00:00
|
|
|
|
2017-02-28 02:21:10 +00:00
|
|
|
s6a_config_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() );
|
2017-02-24 01:50:49 +00:00
|
|
|
|
|
|
|
/* Start the signal handler thread */
|
2017-02-28 02:21:10 +00:00
|
|
|
if (s6a_config->mode & MODE_MME) {
|
2017-02-28 03:03:53 +00:00
|
|
|
CHECK_FCT( s6a_mme_init() );
|
2017-02-24 01:50:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 02:21:10 +00:00
|
|
|
/* Install the handlers for incoming messages */
|
|
|
|
if (s6a_config->mode & MODE_HSS) {
|
2017-02-28 03:03:53 +00:00
|
|
|
CHECK_FCT( s6a_hss_init() );
|
2017-02-28 02:21:10 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 01:50:49 +00:00
|
|
|
/* Advertise the support for the test application in the peer */
|
2017-02-27 14:01:15 +00:00
|
|
|
CHECK_FCT( fd_disp_app_support ( s6a_appli, s6a_vendor, 1, 0 ) );
|
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 */
|
2017-02-24 13:56:02 +00:00
|
|
|
void s6a_app_final(void)
|
2017-02-24 01:50:49 +00:00
|
|
|
{
|
2017-02-28 02:21:10 +00:00
|
|
|
if (s6a_config->mode & MODE_MME)
|
2017-02-28 03:03:53 +00:00
|
|
|
s6a_mme_final();
|
2017-02-28 02:21:10 +00:00
|
|
|
if (s6a_config->mode & MODE_HSS)
|
2017-02-28 03:03:53 +00:00
|
|
|
s6a_hss_final();
|
2017-02-27 12:29:32 +00:00
|
|
|
|
|
|
|
CHECK_FCT_DO( fd_thr_term(&s6a_stats_th), );
|
2017-02-28 02:21:10 +00:00
|
|
|
CHECK_POSIX_DO( pthread_mutex_destroy(&s6a_config->stats_lock), );
|
2017-02-24 01:50:49 +00:00
|
|
|
}
|