Initial commit
Change-Id: I6a4444e3c193dae437cd7929f4c39aba7b749efa
diff --git a/extensions/test_app/CMakeLists.txt b/extensions/test_app/CMakeLists.txt
new file mode 100644
index 0000000..7557445
--- /dev/null
+++ b/extensions/test_app/CMakeLists.txt
@@ -0,0 +1,31 @@
+# The test_app extension
+PROJECT("Test Diameter Application" C)
+
+# Parser files
+BISON_FILE(ta_conf.y)
+FLEX_FILE(ta_conf.l)
+SET_SOURCE_FILES_PROPERTIES(lex.ta_conf.c ta_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
+
+# List of source files
+SET( APP_TEST_SRC
+ test_app.h
+ test_app.c
+ lex.ta_conf.c
+ ta_conf.tab.c
+ ta_conf.tab.h
+ ta_dict.c
+ ta_cli.c
+ ta_bench.c
+ ta_serv.c
+)
+
+# Compile as a module
+FD_ADD_EXTENSION(test_app ${APP_TEST_SRC})
+
+
+####
+## INSTALL section ##
+
+INSTALL(TARGETS test_app
+ LIBRARY DESTINATION ${INSTALL_EXTENSIONS_SUFFIX}
+ COMPONENT freeDiameter-debug-tools)
diff --git a/extensions/test_app/ta_bench.c b/extensions/test_app/ta_bench.c
new file mode 100644
index 0000000..95aa246
--- /dev/null
+++ b/extensions/test_app/ta_bench.c
@@ -0,0 +1,336 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2015, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Create and send a message, and receive it */
+
+#include "test_app.h"
+#include <stdio.h>
+
+#ifndef __APPLE__ /* they deprecated the semaphore there... */
+#include <semaphore.h>
+
+#define my_sem_t sem_t
+#define my_sem_init sem_init
+#define my_sem_destroy sem_destroy
+#define my_sem_timedwait sem_timedwait
+#define my_sem_post sem_post
+
+#else // on APPLE
+#include <sched.h>
+#include <dispatch/dispatch.h>
+
+#define my_sem_t dispatch_semaphore_t
+
+static int my_sem_init(my_sem_t * s, int pshared, unsigned int value ) {
+ *s = dispatch_semaphore_create(value);
+ if (*s == NULL)
+ return ENOMEM;
+ return 0;
+}
+
+static int my_sem_destroy(my_sem_t *s) {
+ dispatch_release(*s);
+ *s = NULL;
+ return 0;
+}
+
+static int my_sem_timedwait(my_sem_t * s, struct timespec *ts) {
+ struct timespec tsn;
+ int64_t nsec;
+ dispatch_time_t when;
+
+ CHECK_SYS( clock_gettime(CLOCK_REALTIME, &tsn) );
+
+ nsec = (ts->tv_sec * 1000000000) + ts->tv_nsec
+ - (tsn.tv_sec * 1000000000) - tsn.tv_nsec;
+
+ when = dispatch_time ( DISPATCH_TIME_NOW, nsec );
+
+ return dispatch_semaphore_wait ( *s, when ) ? ETIMEDOUT : 0;
+}
+
+static int my_sem_post(my_sem_t *s) {
+ dispatch_semaphore_signal(*s);
+ return 0;
+}
+
+#endif // APPLE
+
+
+
+struct ta_mess_info {
+ int32_t randval; /* a random value to store in Test-AVP */
+ struct timespec ts; /* Time of sending the message */
+};
+
+static my_sem_t ta_sem; /* To handle the concurrency */
+
+/* Cb called when an answer is received */
+static void ta_cb_ans(void * data, struct msg ** msg)
+{
+ struct ta_mess_info * mi = (struct ta_mess_info *)data;
+ struct timespec ts;
+ struct avp * avp;
+ struct avp_hdr * hdr;
+ unsigned long dur;
+
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return );
+
+ /* Value of Result Code */
+ CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_res_code, &avp), return );
+ if (avp) {
+ CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
+ }
+ if (!avp || !hdr || hdr->avp_value->i32 != 2001) {
+ /* error */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ ta_conf->stats.nb_errs++;
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+ goto end;
+ }
+
+ /* Check value of Test-AVP */
+ CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_avp, &avp), return );
+ if (avp) {
+ CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
+ ASSERT(hdr->avp_value->i32 == mi->randval);
+ }
+
+ /* Compute how long it took */
+ dur = ((ts.tv_sec - mi->ts.tv_sec) * 1000000) + ((ts.tv_nsec - mi->ts.tv_nsec) / 1000);
+
+ /* Add this value to the stats */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+
+ if (ta_conf->stats.nb_recv) {
+ /* Ponderate in the avg */
+ ta_conf->stats.avg = (ta_conf->stats.avg * ta_conf->stats.nb_recv + dur) / (ta_conf->stats.nb_recv + 1);
+ /* Min, max */
+ if (dur < ta_conf->stats.shortest)
+ ta_conf->stats.shortest = dur;
+ if (dur > ta_conf->stats.longest)
+ ta_conf->stats.longest = dur;
+ } else {
+ ta_conf->stats.shortest = dur;
+ ta_conf->stats.longest = dur;
+ ta_conf->stats.avg = dur;
+ }
+ ta_conf->stats.nb_recv++;
+
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+end:
+ /* Free the message */
+ CHECK_FCT_DO(fd_msg_free(*msg), );
+ *msg = NULL;
+
+ free(mi);
+
+ /* Post the semaphore */
+ CHECK_SYS_DO( my_sem_post(&ta_sem), );
+
+ return;
+}
+
+/* Create a test message */
+static void ta_bench_test_message()
+{
+ struct msg * req = NULL;
+ struct avp * avp;
+ union avp_value val;
+ struct ta_mess_info * mi = NULL;
+
+ TRACE_DEBUG(FULL, "Creating a new message for sending.");
+
+ /* Create the request */
+ CHECK_FCT_DO( fd_msg_new( ta_cmd_r, MSGFL_ALLOC_ETEID, &req ), goto out );
+
+ /* Create a new session */
+ #define TEST_APP_SID_OPT "app_testb"
+ CHECK_FCT_DO( fd_msg_new_session( req, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out );
+
+ /* Create the random value to store with the session */
+ mi = malloc(sizeof(struct ta_mess_info));
+ if (mi == NULL) {
+ fd_log_debug("malloc failed: %s", strerror(errno));
+ goto out;
+ }
+
+ mi->randval = (int32_t)random();
+
+ /* Now set all AVPs values */
+
+ /* Set the Destination-Realm AVP */
+ {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_dest_realm, 0, &avp ), goto out );
+ val.os.data = (unsigned char *)(ta_conf->dest_realm);
+ val.os.len = strlen(ta_conf->dest_realm);
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set the Destination-Host AVP if needed*/
+ if (ta_conf->dest_host) {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_dest_host, 0, &avp ), goto out );
+ val.os.data = (unsigned char *)(ta_conf->dest_host);
+ val.os.len = strlen(ta_conf->dest_host);
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set Origin-Host & Origin-Realm */
+ CHECK_FCT_DO( fd_msg_add_origin ( req, 0 ), goto out );
+
+ /* Set the User-Name AVP if needed*/
+ if (ta_conf->user_name) {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_user_name, 0, &avp ), goto out );
+ val.os.data = (unsigned char *)(ta_conf->user_name);
+ val.os.len = strlen(ta_conf->user_name);
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set the Test-AVP AVP */
+ {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_avp, 0, &avp ), goto out );
+ val.i32 = mi->randval;
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &mi->ts), goto out );
+
+ /* Send the request */
+ CHECK_FCT_DO( fd_msg_send( &req, ta_cb_ans, mi ), goto out );
+
+ /* Increment the counter */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ ta_conf->stats.nb_sent++;
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+out:
+ return;
+}
+
+/* The function called when the signal is received */
+static void ta_bench_start() {
+ struct timespec end_time, now;
+ struct ta_stats start, end;
+ int nsec = 0;
+
+ /* Save the initial stats */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ memcpy(&start, &ta_conf->stats, sizeof(struct ta_stats));
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+ /* We will run for ta_conf->bench_duration seconds */
+ LOG_N("Starting benchmark client, %ds", ta_conf->bench_duration);
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &end_time), );
+ end_time.tv_sec += ta_conf->bench_duration;
+
+ /* Now loop until timeout is reached */
+ do {
+ /* Do not create more that NB_CONCURRENT_MESSAGES in paralel */
+ int ret = my_sem_timedwait(&ta_sem, &end_time);
+ if (ret == -1) {
+ ret = errno;
+ if (ret != ETIMEDOUT) {
+ CHECK_POSIX_DO(ret, ); /* Just to log it */
+ }
+ break;
+ }
+
+ /* Update the current time */
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), );
+
+ if (!TS_IS_INFERIOR(&now, &end_time))
+ break;
+
+ /* Create and send a new test message */
+ ta_bench_test_message();
+ } while (1);
+
+ do {
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), ); /* Re-read the time because we might have spent some time wiating for the mutex */
+ memcpy(&end, &ta_conf->stats, sizeof(struct ta_stats));
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+ /* Now, display the statistics */
+ LOG_N( "------- app_test Benchmark results, end sending +%ds ---------", nsec);
+ if (now.tv_nsec >= end_time.tv_nsec) {
+ LOG_N( " Executing for: %d.%06ld sec",
+ (int)(now.tv_sec + ta_conf->bench_duration - end_time.tv_sec),
+ (long)(now.tv_nsec - end_time.tv_nsec) / 1000);
+ } else {
+ LOG_N( " Executing for: %d.%06ld sec",
+ (int)(now.tv_sec + ta_conf->bench_duration - 1 - end_time.tv_sec),
+ (long)(now.tv_nsec + 1000000000 - end_time.tv_nsec) / 1000);
+ }
+ LOG_N( " %llu messages sent", end.nb_sent - start.nb_sent);
+ LOG_N( " %llu error(s) received", end.nb_errs - start.nb_errs);
+ LOG_N( " %llu answer(s) received", end.nb_recv - start.nb_recv);
+ LOG_N( " Overall:");
+ LOG_N( " fastest: %ld.%06ld sec.", end.shortest / 1000000, end.shortest % 1000000);
+ LOG_N( " slowest: %ld.%06ld sec.", end.longest / 1000000, end.longest % 1000000);
+ LOG_N( " Average: %ld.%06ld sec.", end.avg / 1000000, end.avg % 1000000);
+ LOG_N( " Throughput: %llu messages / sec", (end.nb_recv - start.nb_recv) / (( now.tv_sec + ta_conf->bench_duration - end_time.tv_sec ) + ((now.tv_nsec - end_time.tv_nsec) / 1000000000)));
+ LOG_N( "-------------------------------------");
+
+ nsec ++;
+ sleep(1);
+ } while ( (end.nb_sent - start.nb_sent) > (end.nb_errs - start.nb_errs) + (end.nb_recv - start.nb_recv) );
+ LOG_N( "--------------- Test Complete --------------");
+
+}
+
+
+int ta_bench_init(void)
+{
+ CHECK_SYS( my_sem_init( &ta_sem, 0, ta_conf->bench_concur) );
+
+ CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.bench", ta_bench_start ) );
+
+ return 0;
+}
+
+void ta_bench_fini(void)
+{
+ // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
+
+ CHECK_SYS_DO( my_sem_destroy(&ta_sem), );
+
+ return;
+};
diff --git a/extensions/test_app/ta_cli.c b/extensions/test_app/ta_cli.c
new file mode 100644
index 0000000..686338a
--- /dev/null
+++ b/extensions/test_app/ta_cli.c
@@ -0,0 +1,293 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2015, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Create and send a message, and receive it */
+
+/* Note that we use both sessions and the argument to answer callback to pass the same value.
+ * This is just for the purpose of checking everything went OK.
+ */
+
+#include "test_app.h"
+
+#include <stdio.h>
+
+static struct session_handler * ta_cli_reg = NULL;
+
+struct sess_state {
+ int32_t randval; /* a random value to store in Test-AVP */
+ struct timespec ts; /* Time of sending the message */
+} ;
+
+/* Cb called when an answer is received */
+static void ta_cb_ans(void * data, struct msg ** msg)
+{
+ struct sess_state * mi = NULL;
+ struct timespec ts;
+ struct session * sess;
+ struct avp * avp;
+ struct avp_hdr * hdr;
+ unsigned long dur;
+ int error = 0;
+
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return );
+
+ /* Search the session, retrieve its data */
+ {
+ int new;
+ CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &sess, &new), return );
+ ASSERT( new == 0 );
+
+ CHECK_FCT_DO( fd_sess_state_retrieve( ta_cli_reg, sess, &mi ), return );
+ ASSERT( (void *)mi == data );
+ }
+
+ /* Now log content of the answer */
+ fprintf(stderr, "RECV ");
+
+ /* Value of Test-AVP */
+ CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_avp, &avp), return );
+ if (avp) {
+ CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
+ if (hdr->avp_value->i32 == mi->randval) {
+ fprintf(stderr, "%x (%s) ", hdr->avp_value->i32, "Ok");
+ } else {
+ fprintf(stderr, "%x (%s) ", hdr->avp_value->i32, "PROBLEM");
+ error++;
+ }
+ } else {
+ fprintf(stderr, "no_Test-AVP ");
+ error++;
+ }
+
+ /* Value of Result Code */
+ CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_res_code, &avp), return );
+ if (avp) {
+ CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
+ fprintf(stderr, "Status: %d ", hdr->avp_value->i32);
+ if (hdr->avp_value->i32 != 2001)
+ error++;
+ } else {
+ fprintf(stderr, "no_Result-Code ");
+ error++;
+ }
+
+ /* Value of Origin-Host */
+ CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_origin_host, &avp), return );
+ if (avp) {
+ CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
+ fprintf(stderr, "From '%.*s' ", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
+ } else {
+ fprintf(stderr, "no_Origin-Host ");
+ error++;
+ }
+
+ /* Value of Origin-Realm */
+ CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_origin_realm, &avp), return );
+ if (avp) {
+ CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
+ fprintf(stderr, "('%.*s') ", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
+ } else {
+ fprintf(stderr, "no_Origin-Realm ");
+ error++;
+ }
+
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ dur = ((ts.tv_sec - mi->ts.tv_sec) * 1000000) + ((ts.tv_nsec - mi->ts.tv_nsec) / 1000);
+ if (ta_conf->stats.nb_recv) {
+ /* Ponderate in the avg */
+ ta_conf->stats.avg = (ta_conf->stats.avg * ta_conf->stats.nb_recv + dur) / (ta_conf->stats.nb_recv + 1);
+ /* Min, max */
+ if (dur < ta_conf->stats.shortest)
+ ta_conf->stats.shortest = dur;
+ if (dur > ta_conf->stats.longest)
+ ta_conf->stats.longest = dur;
+ } else {
+ ta_conf->stats.shortest = dur;
+ ta_conf->stats.longest = dur;
+ ta_conf->stats.avg = dur;
+ }
+
+ if (error)
+ ta_conf->stats.nb_errs++;
+ else
+ ta_conf->stats.nb_recv++;
+
+
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+ /* Display how long it took */
+ if (ts.tv_nsec > mi->ts.tv_nsec) {
+ fprintf(stderr, "in %d.%06ld sec",
+ (int)(ts.tv_sec - mi->ts.tv_sec),
+ (long)(ts.tv_nsec - mi->ts.tv_nsec) / 1000);
+ } else {
+ fprintf(stderr, "in %d.%06ld sec",
+ (int)(ts.tv_sec + 1 - mi->ts.tv_sec),
+ (long)(1000000000 + ts.tv_nsec - mi->ts.tv_nsec) / 1000);
+ }
+ fprintf(stderr, "\n");
+ fflush(stderr);
+
+ /* Free the message */
+ CHECK_FCT_DO(fd_msg_free(*msg), return);
+ *msg = NULL;
+
+ free(mi);
+
+ return;
+}
+
+/* Create a test message */
+static void ta_cli_test_message()
+{
+ struct msg * req = NULL;
+ struct avp * avp;
+ union avp_value val;
+ struct sess_state * mi = NULL, *svg;
+ struct session *sess = NULL;
+
+ TRACE_DEBUG(FULL, "Creating a new message for sending.");
+
+ /* Create the request */
+ CHECK_FCT_DO( fd_msg_new( ta_cmd_r, MSGFL_ALLOC_ETEID, &req ), goto out );
+
+ /* Create a new session */
+ #define TEST_APP_SID_OPT "app_test"
+ CHECK_FCT_DO( fd_msg_new_session( req, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out );
+ CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, req, &sess, NULL), goto out );
+
+ /* Create the random value to store with the session */
+ mi = malloc(sizeof(struct sess_state));
+ if (mi == NULL) {
+ fd_log_debug("malloc failed: %s", strerror(errno));
+ goto out;
+ }
+
+ mi->randval = (int32_t)random();
+
+ /* Now set all AVPs values */
+
+ /* Set the Destination-Realm AVP */
+ {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_dest_realm, 0, &avp ), goto out );
+ val.os.data = (unsigned char *)(ta_conf->dest_realm);
+ val.os.len = strlen(ta_conf->dest_realm);
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set the Destination-Host AVP if needed*/
+ if (ta_conf->dest_host) {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_dest_host, 0, &avp ), goto out );
+ val.os.data = (unsigned char *)(ta_conf->dest_host);
+ val.os.len = strlen(ta_conf->dest_host);
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set Origin-Host & Origin-Realm */
+ CHECK_FCT_DO( fd_msg_add_origin ( req, 0 ), goto out );
+
+ /* Set the User-Name AVP if needed*/
+ if (ta_conf->user_name) {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_user_name, 0, &avp ), goto out );
+ val.os.data = (unsigned char *)(ta_conf->user_name);
+ val.os.len = strlen(ta_conf->user_name);
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set the Test-AVP AVP */
+ {
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_avp, 0, &avp ), goto out );
+ val.i32 = mi->randval;
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ /* Set the Test-Payload-AVP AVP */
+ if (ta_conf->long_avp_id) {
+ int l;
+ CHECK_FCT_DO( fd_msg_avp_new ( ta_avp_long, 0, &avp ), goto out );
+ CHECK_MALLOC_DO( val.os.data = malloc(ta_conf->long_avp_len), goto out);
+ val.os.len = ta_conf->long_avp_len;
+ for (l=0; l < ta_conf->long_avp_len; l++)
+ val.os.data[l]=l;
+ CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
+ free(val.os.data);
+ CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
+ }
+
+ CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &mi->ts), goto out );
+
+ /* Keep a pointer to the session data for debug purpose, in real life we would not need it */
+ svg = mi;
+
+ /* Store this value in the session */
+ CHECK_FCT_DO( fd_sess_state_store ( ta_cli_reg, sess, &mi ), goto out );
+
+ /* Log sending the message */
+ fprintf(stderr, "SEND %x to '%s' (%s)\n", svg->randval, ta_conf->dest_realm, ta_conf->dest_host?:"-" );
+ fflush(stderr);
+
+ /* Send the request */
+ CHECK_FCT_DO( fd_msg_send( &req, ta_cb_ans, svg ), goto out );
+
+ /* Increment the counter */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ ta_conf->stats.nb_sent++;
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+out:
+ return;
+}
+
+int ta_cli_init(void)
+{
+ CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, (void *)free, NULL, NULL) );
+
+ CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.cli", ta_cli_test_message ) );
+
+ return 0;
+}
+
+void ta_cli_fini(void)
+{
+ // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
+
+ CHECK_FCT_DO( fd_sess_handler_destroy(&ta_cli_reg, NULL), /* continue */ );
+
+ return;
+};
diff --git a/extensions/test_app/ta_conf.l b/extensions/test_app/ta_conf.l
new file mode 100644
index 0000000..1bae950
--- /dev/null
+++ b/extensions/test_app/ta_conf.l
@@ -0,0 +1,177 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2013, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Lex extension's configuration parser.
+ *
+ * The configuration file contains a default priority, and a list of peers with optional overwite priority.
+ * -- see the app_test.conf.sample file for more detail.
+ */
+
+%{
+#include "test_app.h"
+/* Include yacc tokens definitions */
+#include "ta_conf.tab.h"
+
+/* Update the column information */
+#define YY_USER_ACTION { \
+ yylloc->first_column = yylloc->last_column + 1; \
+ yylloc->last_column = yylloc->first_column + yyleng - 1; \
+}
+
+/* Avoid warning with newer flex */
+#define YY_NO_INPUT
+
+%}
+
+%option bison-bridge bison-locations
+%option noyywrap
+%option nounput
+
+%%
+
+ /* Update the line count */
+\n {
+ yylloc->first_line++;
+ yylloc->last_line++;
+ yylloc->last_column=0;
+ }
+
+ /* Eat all spaces but not new lines */
+([[:space:]]{-}[\n])+ ;
+ /* Eat all comments */
+#.*$ ;
+
+ /* Recognize any integer */
+[-]?[[:digit:]]+ {
+ /* Convert this to an integer value */
+ int ret=0;
+ ret = sscanf(yytext, "%i", &yylval->integer);
+ if (ret != 1) {
+ /* No matching: an error occurred */
+ fd_log_debug("Unable to convert the value '%s' to a valid number: %s", yytext, strerror(errno));
+ return LEX_ERROR; /* trig an error in yacc parser */
+ /* Maybe we could REJECT instead of failing here? */
+ }
+ return INTEGER;
+ }
+
+ /* Recognize quoted strings -- we do not support escaped \" in the string currently. */
+\"[^\"]+\" {
+ /* Match a quoted string. Let's be very permissive. */
+ yylval->string = strdup(yytext+1);
+ if (!yylval->string) {
+ fd_log_debug("Unable to copy the string '%s': %s", yytext, strerror(errno));
+ TRACE_DEBUG(INFO, "strdup failed");
+ return LEX_ERROR; /* trig an error in yacc parser */
+ }
+ yylval->string[strlen(yytext) - 2] = '\0';
+ return QSTRING;
+ }
+
+ /* Recognize the tokens */
+(?i:"vendor-id") {
+ return VENDOR_ID;
+ }
+
+(?i:"appli-id") {
+ return APPLI_ID;
+ }
+
+(?i:"cmd-id") {
+ return CMD_ID;
+ }
+
+(?i:"avp-id") {
+ return AVP_ID;
+ }
+
+(?i:"long-avp-id") {
+ return LONG_AVP_ID;
+ }
+
+(?i:"long-avp-len") {
+ return LONG_AVP_LEN;
+ }
+
+(?i:"mode") {
+ return MODE;
+ }
+
+(?i:"server") {
+ yylval->integer = MODE_SERV;
+ return INTEGER;
+ }
+
+(?i:"client") {
+ yylval->integer = MODE_CLI;
+ return INTEGER;
+ }
+
+(?i:"both") {
+ yylval->integer = MODE_SERV | MODE_CLI;
+ return INTEGER;
+ }
+
+(?i:"dest-realm") {
+ return DEST_REALM;
+ }
+
+(?i:"dest-host") {
+ return DEST_HOST;
+ }
+
+(?i:"user-name") {
+ return USER_NAME;
+ }
+
+(?i:"Signal") {
+ return SIGNAL;
+ }
+
+(?i:"Benchmark") {
+ return BENCH;
+ }
+
+
+ /* Valid single characters for yyparse */
+[=;] { return yytext[0]; }
+
+ /* Unrecognized sequence, if it did not match any previous pattern */
+[^[:space:]"*=>;\n]+ {
+ fd_log_debug("Unrecognized text on line %d col %d: '%s'.", yylloc->first_line, yylloc->first_column, yytext);
+ return LEX_ERROR;
+ }
+
+%%
diff --git a/extensions/test_app/ta_conf.y b/extensions/test_app/ta_conf.y
new file mode 100644
index 0000000..52e3648
--- /dev/null
+++ b/extensions/test_app/ta_conf.y
@@ -0,0 +1,239 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2013, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Yacc extension's configuration parser.
+ * See doc/app_test.conf.sample for configuration file format
+ */
+
+/* For development only : */
+%debug
+%error-verbose
+
+/* The parser receives the configuration file filename as parameter */
+%parse-param {char * conffile}
+
+/* Keep track of location */
+%locations
+%pure-parser
+
+%{
+#include "test_app.h"
+#include "ta_conf.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */
+
+#include <string.h>
+#include <errno.h>
+
+/* Forward declaration */
+int yyparse(char * conffile);
+
+/* Parse the configuration file */
+int ta_conf_handle(char * conffile)
+{
+ extern FILE * ta_confin;
+ int ret;
+
+ TRACE_ENTRY("%p", conffile);
+
+ TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
+
+ ta_confin = fopen(conffile, "r");
+ if (ta_confin == NULL) {
+ ret = errno;
+ fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
+ TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file.");
+ return ret;
+ }
+
+ ret = yyparse(conffile);
+
+ fclose(ta_confin);
+
+ if (ret != 0) {
+ TRACE_DEBUG (INFO, "Unable to parse the configuration file.");
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+/* The Lex parser prototype */
+int ta_conflex(YYSTYPE *lvalp, YYLTYPE *llocp);
+
+/* Function to report the errors */
+void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
+{
+ TRACE_DEBUG(INFO, "Error in configuration parsing");
+
+ if (ploc->first_line != ploc->last_line)
+ fd_log_debug("%s:%d.%d-%d.%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s);
+ else if (ploc->first_column != ploc->last_column)
+ fd_log_debug("%s:%d.%d-%d : %s", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s);
+ else
+ fd_log_debug("%s:%d.%d : %s", conffile, ploc->first_line, ploc->first_column, s);
+}
+
+%}
+
+/* Values returned by lex for token */
+%union {
+ char *string; /* The string is allocated by strdup in lex.*/
+ int integer; /* Store integer values */
+}
+
+/* In case of error in the lexical analysis */
+%token LEX_ERROR
+
+/* Key words */
+%token VENDOR_ID
+%token APPLI_ID
+%token CMD_ID
+%token AVP_ID
+%token LONG_AVP_ID
+%token LONG_AVP_LEN
+%token MODE
+%token DEST_REALM
+%token DEST_HOST
+%token USER_NAME
+%token SIGNAL
+%token BENCH
+
+/* Tokens and types for routing table definition */
+/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
+%token <string> QSTRING
+
+/* An integer value */
+%token <integer> INTEGER
+
+
+
+/* -------------------------------------- */
+%%
+
+ /* The grammar definition */
+conffile: /* empty grammar is OK */
+ | conffile vendor
+ | conffile appli
+ | conffile cmd
+ | conffile avp
+ | conffile long_avp_id
+ | conffile long_avp_len
+ | conffile mode
+ | conffile dstrealm
+ | conffile dsthost
+ | conffile usrname
+ | conffile signal
+ | conffile bench
+ ;
+
+vendor: VENDOR_ID '=' INTEGER ';'
+ {
+ ta_conf->vendor_id = $3;
+ }
+ ;
+
+appli: APPLI_ID '=' INTEGER ';'
+ {
+ ta_conf->appli_id = $3;
+ }
+ ;
+
+cmd: CMD_ID '=' INTEGER ';'
+ {
+ ta_conf->cmd_id = $3;
+ }
+ ;
+
+avp: AVP_ID '=' INTEGER ';'
+ {
+ ta_conf->avp_id = $3;
+ }
+ ;
+
+long_avp_id: LONG_AVP_ID '=' INTEGER ';'
+ {
+ ta_conf->long_avp_id = $3;
+ }
+ ;
+
+long_avp_len: LONG_AVP_LEN '=' INTEGER ';'
+ {
+ ta_conf->long_avp_len = $3;
+ }
+ ;
+
+mode: MODE '=' INTEGER ';'
+ {
+ ta_conf->mode = $3 | (ta_conf->mode & ~3); /* overwrite the 2 lsb */
+ }
+ ;
+
+bench: BENCH ';'
+ {
+ ta_conf->mode |= MODE_BENCH;
+ }
+ | BENCH INTEGER INTEGER ';'
+ {
+ ta_conf->mode |= MODE_BENCH;
+ ta_conf->bench_duration = $2;
+ ta_conf->bench_concur = $3;
+ }
+ ;
+
+dstrealm: DEST_REALM '=' QSTRING ';'
+ {
+ free(ta_conf->dest_realm);
+ ta_conf->dest_realm = $3;
+ }
+ ;
+
+dsthost: DEST_HOST '=' QSTRING ';'
+ {
+ free(ta_conf->dest_host);
+ ta_conf->dest_host = $3;
+ }
+ ;
+
+usrname: USER_NAME '=' QSTRING ';'
+ {
+ free(ta_conf->user_name);
+ ta_conf->user_name = $3;
+ }
+ ;
+
+signal: SIGNAL '=' INTEGER ';'
+ {
+ ta_conf->signal = $3;
+ }
+ ;
diff --git a/extensions/test_app/ta_dict.c b/extensions/test_app/ta_dict.c
new file mode 100644
index 0000000..2b9c6b3
--- /dev/null
+++ b/extensions/test_app/ta_dict.c
@@ -0,0 +1,166 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2013, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Install the dictionary objects */
+
+#include "test_app.h"
+
+struct dict_object * ta_vendor = NULL;
+struct dict_object * ta_appli = NULL;
+struct dict_object * ta_cmd_r = NULL;
+struct dict_object * ta_cmd_a = NULL;
+struct dict_object * ta_avp = NULL;
+struct dict_object * ta_avp_long = NULL;
+
+struct dict_object * ta_sess_id = NULL;
+struct dict_object * ta_origin_host = NULL;
+struct dict_object * ta_origin_realm = NULL;
+struct dict_object * ta_dest_host = NULL;
+struct dict_object * ta_dest_realm = NULL;
+struct dict_object * ta_user_name = NULL;
+struct dict_object * ta_res_code = NULL;
+
+int ta_dict_init(void)
+{
+ TRACE_DEBUG(FULL, "Initializing the dictionary for test");
+
+ /* Create the Test Vendor */
+ {
+ struct dict_vendor_data data;
+ data.vendor_id = ta_conf->vendor_id;
+ data.vendor_name = "app_test vendor";
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_VENDOR, &data, NULL, &ta_vendor));
+ }
+
+ /* Create the Test Application */
+ {
+ struct dict_application_data data;
+ data.application_id = ta_conf->appli_id;
+ data.application_name = "app_test application";
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_APPLICATION, &data, ta_vendor, &ta_appli));
+ }
+
+ /* Create the Test-Request & Test-Answer commands */
+ {
+ struct dict_cmd_data data;
+ data.cmd_code = ta_conf->cmd_id;
+ data.cmd_name = "Test-Request";
+ data.cmd_flag_mask = CMD_FLAG_PROXIABLE | CMD_FLAG_REQUEST;
+ data.cmd_flag_val = CMD_FLAG_PROXIABLE | CMD_FLAG_REQUEST;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_COMMAND, &data, ta_appli, &ta_cmd_r));
+ data.cmd_name = "Test-Answer";
+ data.cmd_flag_val = CMD_FLAG_PROXIABLE;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_COMMAND, &data, ta_appli, &ta_cmd_a));
+ }
+
+ /* Create the Test AVP */
+ {
+ struct dict_avp_data data;
+ data.avp_code = ta_conf->avp_id;
+ data.avp_vendor = ta_conf->vendor_id;
+ data.avp_name = "Test-AVP";
+ data.avp_flag_mask = AVP_FLAG_VENDOR;
+ data.avp_flag_val = AVP_FLAG_VENDOR;
+ data.avp_basetype = AVP_TYPE_INTEGER32;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_AVP, &data, NULL, &ta_avp));
+ }
+
+ /* Create the Test Payload AVP */
+ if (ta_conf->long_avp_id) {
+ struct dict_avp_data data;
+ data.avp_code = ta_conf->long_avp_id;
+ data.avp_vendor = ta_conf->vendor_id;
+ data.avp_name = "Test-Payload-AVP";
+ data.avp_flag_mask = AVP_FLAG_VENDOR;
+ data.avp_flag_val = AVP_FLAG_VENDOR;
+ data.avp_basetype = AVP_TYPE_OCTETSTRING;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_AVP, &data, NULL, &ta_avp_long));
+ }
+
+ /* Now resolve some other useful AVPs */
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &ta_sess_id, ENOENT) );
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &ta_origin_host, ENOENT) );
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Realm", &ta_origin_realm, ENOENT) );
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &ta_dest_host, ENOENT) );
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &ta_dest_realm, ENOENT) );
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &ta_user_name, ENOENT) );
+ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Result-Code", &ta_res_code, ENOENT) );
+
+ /* Create the rules for Test-Request and Test-Answer */
+ {
+ struct dict_rule_data data;
+ data.rule_min = 1;
+ data.rule_max = 1;
+
+ /* Session-Id is in first position */
+ data.rule_avp = ta_sess_id;
+ data.rule_position = RULE_FIXED_HEAD;
+ data.rule_order = 1;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL));
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL));
+
+ data.rule_position = RULE_REQUIRED;
+ /* Test-AVP is mandatory */
+ data.rule_avp = ta_avp;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL));
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL));
+
+ /* idem for Origin Host and Realm */
+ data.rule_avp = ta_origin_host;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL));
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL));
+
+ data.rule_avp = ta_origin_realm;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL));
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL));
+
+ /* And Result-Code is mandatory for answers only */
+ data.rule_avp = ta_res_code;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL));
+
+ /* And Destination-Realm for requests only */
+ data.rule_avp = ta_dest_realm;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL));
+
+ /* And Destination-Host optional for requests only */
+ data.rule_position = RULE_OPTIONAL;
+ data.rule_min = 0;
+ data.rule_avp = ta_dest_host;
+ CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL));
+
+ }
+
+ return 0;
+}
diff --git a/extensions/test_app/ta_serv.c b/extensions/test_app/ta_serv.c
new file mode 100644
index 0000000..848c9de
--- /dev/null
+++ b/extensions/test_app/ta_serv.c
@@ -0,0 +1,154 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2013, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Install the dispatch callbacks */
+
+#include "test_app.h"
+
+static struct disp_hdl * ta_hdl_fb = NULL; /* handler for fallback cb */
+static struct disp_hdl * ta_hdl_tr = NULL; /* handler for Test-Request req cb */
+
+/* Default callback for the application. */
+static int ta_fb_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act)
+{
+ /* This CB should never be called */
+ TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
+
+ fd_log_debug("Unexpected message received!");
+
+ return ENOTSUP;
+}
+
+/* Callback for incoming Test-Request messages */
+static int ta_tr_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act)
+{
+ struct msg *ans, *qry;
+ struct avp * a;
+
+ TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
+
+ if (msg == NULL)
+ return EINVAL;
+
+ /* Value of Origin-Host */
+ if (! (ta_conf->mode & MODE_BENCH)) {
+ fprintf(stderr, "ECHO Test-Request received from ");
+ CHECK_FCT( fd_msg_search_avp ( *msg, ta_origin_host, &a) );
+ if (a) {
+ struct avp_hdr * hdr;
+ CHECK_FCT( fd_msg_avp_hdr( a, &hdr ) );
+ fprintf(stderr, "'%.*s'", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
+ } else {
+ fprintf(stderr, "no_Origin-Host");
+ }
+ fprintf(stderr, ", replying...\n");
+ }
+
+ /* Create answer header */
+ qry = *msg;
+ CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
+ ans = *msg;
+
+ /* Set the Test-AVP AVP */
+ {
+ struct avp * src = NULL;
+ struct avp_hdr * hdr = NULL;
+
+ CHECK_FCT( fd_msg_search_avp ( qry, ta_avp, &src) );
+ CHECK_FCT( fd_msg_avp_hdr( src, &hdr ) );
+
+ CHECK_FCT( fd_msg_avp_new ( ta_avp, 0, &avp ) );
+ CHECK_FCT( fd_msg_avp_setvalue( avp, hdr->avp_value ) );
+ CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
+ }
+
+ /* Set the Test-Payload-AVP AVP */
+ if (ta_conf->long_avp_id) {
+ struct avp * src = NULL;
+ struct avp_hdr * hdr = NULL;
+
+ CHECK_FCT( fd_msg_search_avp ( qry, ta_avp_long, &src) );
+ CHECK_FCT( fd_msg_avp_hdr( src, &hdr ) );
+
+ CHECK_FCT( fd_msg_avp_new ( ta_avp_long, 0, &avp ) );
+ CHECK_FCT( fd_msg_avp_setvalue( avp, hdr->avp_value ) );
+ CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) );
+ }
+
+
+ /* Set the Origin-Host, Origin-Realm, Result-Code AVPs */
+ CHECK_FCT( fd_msg_rescode_set( ans, "DIAMETER_SUCCESS", NULL, NULL, 1 ) );
+
+ /* Send the answer */
+ CHECK_FCT( fd_msg_send( msg, NULL, NULL ) );
+
+ /* Add this value to the stats */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ ta_conf->stats.nb_echoed++;
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+ return 0;
+}
+
+int ta_serv_init(void)
+{
+ struct disp_when data;
+
+ TRACE_DEBUG(FULL, "Initializing dispatch callbacks for test");
+
+ memset(&data, 0, sizeof(data));
+ data.app = ta_appli;
+ data.command = ta_cmd_r;
+
+ /* fallback CB if command != Test-Request received */
+ CHECK_FCT( fd_disp_register( ta_fb_cb, DISP_HOW_APPID, &data, NULL, &ta_hdl_fb ) );
+
+ /* Now specific handler for Test-Request */
+ CHECK_FCT( fd_disp_register( ta_tr_cb, DISP_HOW_CC, &data, NULL, &ta_hdl_tr ) );
+
+ return 0;
+}
+
+void ta_serv_fini(void)
+{
+ if (ta_hdl_fb) {
+ (void) fd_disp_unregister(&ta_hdl_fb, NULL);
+ }
+ if (ta_hdl_tr) {
+ (void) fd_disp_unregister(&ta_hdl_tr, NULL);
+ }
+
+ return;
+}
diff --git a/extensions/test_app/test_app.c b/extensions/test_app/test_app.c
new file mode 100644
index 0000000..a89f281
--- /dev/null
+++ b/extensions/test_app/test_app.c
@@ -0,0 +1,223 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2013, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/*
+ * Test application for freeDiameter.
+ */
+
+#include "test_app.h"
+
+/* Initialize the configuration */
+struct ta_conf * ta_conf = NULL;
+static struct ta_conf _conf;
+static pthread_t ta_stats_th = (pthread_t)NULL;
+
+static int ta_conf_init(void)
+{
+ ta_conf = &_conf;
+ memset(ta_conf, 0, sizeof(struct ta_conf));
+
+ /* Set the default values */
+ ta_conf->vendor_id = 999999; /* Dummy value */
+ ta_conf->appli_id = 0xffffff; /* dummy value */
+ ta_conf->cmd_id = 0xfffffe; /* Experimental */
+ ta_conf->avp_id = 0xffffff; /* dummy value */
+ ta_conf->long_avp_len = 5000;
+ ta_conf->mode = MODE_SERV | MODE_CLI;
+ ta_conf->dest_realm = strdup(fd_g_config->cnf_diamrlm);
+ ta_conf->dest_host = NULL;
+ ta_conf->signal = TEST_APP_DEFAULT_SIGNAL;
+ ta_conf->bench_concur = 100;
+ ta_conf->bench_duration = 10;
+
+ /* Initialize the mutex */
+ CHECK_POSIX( pthread_mutex_init(&ta_conf->stats_lock, NULL) );
+
+ return 0;
+}
+
+static void ta_conf_dump(void)
+{
+ if (!TRACE_BOOL(INFO))
+ return;
+ fd_log_debug( "------- app_test configuration dump: ---------");
+ fd_log_debug( " Vendor Id .......... : %u", ta_conf->vendor_id);
+ fd_log_debug( " Application Id ..... : %u", ta_conf->appli_id);
+ fd_log_debug( " Command Id ......... : %u", ta_conf->cmd_id);
+ fd_log_debug( " AVP Id ............. : %u", ta_conf->avp_id);
+ fd_log_debug( " Long AVP Id ........ : %u", ta_conf->long_avp_id);
+ fd_log_debug( " Long AVP len ....... : %zu", ta_conf->long_avp_len);
+ fd_log_debug( " Mode ............... : %s%s%s", ta_conf->mode & MODE_SERV ? "Serv" : "", ta_conf->mode & MODE_CLI ? "Cli" : "", ta_conf->mode & MODE_BENCH ? " (Benchmark)" : "");
+ fd_log_debug( " Destination Realm .. : %s", ta_conf->dest_realm ?: "- none -");
+ fd_log_debug( " Destination Host ... : %s", ta_conf->dest_host ?: "- none -");
+ fd_log_debug( " Signal ............. : %i", ta_conf->signal);
+ fd_log_debug( "------- /app_test configuration dump ---------");
+}
+
+/* Function to display statistics periodically */
+static void * ta_stats(void * arg) {
+
+ 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 */
+ sleep(ta_conf->bench_duration + 3);
+
+ /* Now, get the current stats */
+ CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
+ memcpy(©, &ta_conf->stats, sizeof(struct ta_stats));
+ CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
+
+ /* 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);
+ }
+
+ if (ta_conf->mode & MODE_SERV) {
+ fd_log_debug( " Server: %llu message(s) echoed", copy.nb_echoed);
+ }
+ if (ta_conf->mode & MODE_CLI) {
+ 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( " fastest: %ld.%06ld sec.", copy.shortest / 1000000, copy.shortest % 1000000);
+ fd_log_debug( " slowest: %ld.%06ld sec.", copy.longest / 1000000, copy.longest % 1000000);
+ fd_log_debug( " Average: %ld.%06ld sec.", copy.avg / 1000000, copy.avg % 1000000);
+ }
+ fd_log_debug( "-------------------------------------");
+ }
+
+ return NULL; /* never called */
+}
+
+static struct fd_hook_hdl * hookhdl[2] = { NULL, NULL };
+static void ta_hook_cb_silent(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) {
+}
+static void ta_hook_cb_oneline(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) {
+ char * buf = NULL;
+ size_t len;
+
+ CHECK_MALLOC_DO( fd_msg_dump_summary(&buf, &len, NULL, msg, NULL, 0, 0),
+ { LOG_E("Error while dumping a message"); return; } );
+
+ LOG_N("{%d} %s: %s", type, (char *)other ?:"<nil>", buf ?:"<nil>");
+
+ free(buf);
+}
+
+
+/* entry point */
+static int ta_entry(char * conffile)
+{
+ TRACE_ENTRY("%p", conffile);
+
+ /* Initialize configuration */
+ CHECK_FCT( ta_conf_init() );
+
+ /* Parse configuration file */
+ if (conffile != NULL) {
+ CHECK_FCT( ta_conf_handle(conffile) );
+ }
+
+ TRACE_DEBUG(INFO, "Extension Test_App initialized with configuration: '%s'", conffile);
+ ta_conf_dump();
+
+ /* Install objects definitions for this test application */
+ CHECK_FCT( ta_dict_init() );
+
+ /* 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) {
+ if (ta_conf->mode & MODE_BENCH) {
+ CHECK_FCT( ta_bench_init() );
+ } else {
+ CHECK_FCT( ta_cli_init() );
+ }
+ }
+
+ /* Advertise the support for the test application in the peer */
+ CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) );
+
+ if (ta_conf->mode & MODE_BENCH) {
+ /* Register an empty hook to disable the default handling */
+ CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_DATA_RECEIVED, HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_SENT, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL ),
+ ta_hook_cb_silent, NULL, NULL, &hookhdl[0]) );
+ CHECK_FCT( fd_hook_register( HOOK_MASK( HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED ),
+ ta_hook_cb_oneline, NULL, NULL, &hookhdl[1]) );
+
+ }
+
+ /* Start the statistics thread */
+ CHECK_POSIX( pthread_create(&ta_stats_th, NULL, ta_stats, NULL) );
+
+ return 0;
+}
+
+/* Unload */
+void fd_ext_fini(void)
+{
+ if (ta_conf->mode & MODE_CLI)
+ ta_cli_fini();
+ if (ta_conf->mode & MODE_SERV)
+ ta_serv_fini();
+ if (hookhdl[0])
+ fd_hook_unregister( hookhdl[0] );
+ if (hookhdl[1])
+ fd_hook_unregister( hookhdl[1] );
+ CHECK_FCT_DO( fd_thr_term(&ta_stats_th), );
+ CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), );
+}
+
+EXTENSION_ENTRY("test_app", ta_entry);
diff --git a/extensions/test_app/test_app.h b/extensions/test_app/test_app.h
new file mode 100644
index 0000000..8d01a45
--- /dev/null
+++ b/extensions/test_app/test_app.h
@@ -0,0 +1,117 @@
+/*********************************************************************************************************
+* Software License Agreement (BSD License) *
+* Author: Sebastien Decugis <sdecugis@freediameter.net> *
+* *
+* Copyright (c) 2013, WIDE Project and NICT *
+* All rights reserved. *
+* *
+* Redistribution and use of this software in source and binary forms, with or without modification, are *
+* permitted provided that the following conditions are met: *
+* *
+* * Redistributions of source code must retain the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer. *
+* *
+* * Redistributions in binary form must reproduce the above *
+* copyright notice, this list of conditions and the *
+* following disclaimer in the documentation and/or other *
+* materials provided with the distribution. *
+* *
+* * Neither the name of the WIDE Project or NICT nor the *
+* names of its contributors may be used to endorse or *
+* promote products derived from this software without *
+* specific prior written permission of WIDE Project and *
+* NICT. *
+* *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
+* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
+* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+*********************************************************************************************************/
+
+/* Header file for the app_test extension.
+ *
+ * This extension provides a way to send configurable messages on the network
+ *
+ * See the app_test.conf.sample file for the format of the configuration file.
+ */
+
+#include <freeDiameter/extension.h>
+#include <signal.h>
+
+#ifndef TEST_APP_DEFAULT_SIGNAL
+#define TEST_APP_DEFAULT_SIGNAL SIGUSR1
+#endif /* TEST_APP_DEFAULT_SIGNAL */
+
+
+/* Mode for the extension */
+#define MODE_SERV 0x1
+#define MODE_CLI 0x2
+#define MODE_BENCH 0x4
+
+/* The module configuration */
+struct ta_conf {
+ uint32_t vendor_id; /* default 999999 */
+ uint32_t appli_id; /* default 123456 */
+ uint32_t cmd_id; /* default 234567 */
+ uint32_t avp_id; /* default 345678 */
+ uint32_t long_avp_id; /* default 0 */
+ size_t long_avp_len; /* default 5000 */
+ int mode; /* default MODE_SERV | MODE_CLI */
+ char * dest_realm; /* default local realm */
+ char * dest_host; /* default NULL */
+ char * user_name; /* default NULL */
+ int signal; /* default TEST_APP_DEFAULT_SIGNAL */
+ int bench_concur; /* default 100 */
+ int bench_duration; /* default 10 */
+ struct ta_stats {
+ unsigned long long nb_echoed; /* server */
+ unsigned long long nb_sent; /* client */
+ unsigned long long nb_recv; /* client */
+ unsigned long long nb_errs; /* client */
+ unsigned long shortest; /* fastest answer, in microseconds */
+ unsigned long longest; /* slowest answer, in microseconds */
+ unsigned long avg; /* average answer time, in microseconds */
+ } stats;
+ pthread_mutex_t stats_lock;
+};
+extern struct ta_conf * ta_conf;
+
+/* Parse the configuration file */
+int ta_conf_handle(char * conffile);
+
+/* Handle incoming messages (server) */
+int ta_serv_init(void);
+void ta_serv_fini(void);
+
+/* Create outgoing message (client) */
+int ta_cli_init(void);
+void ta_cli_fini(void);
+
+/* Benchmark flavour */
+int ta_bench_init(void);
+void ta_bench_fini(void);
+
+/* Initialize dictionary definitions */
+int ta_dict_init(void);
+
+
+/* Some global variables for dictionary */
+extern struct dict_object * ta_vendor;
+extern struct dict_object * ta_appli;
+extern struct dict_object * ta_cmd_r;
+extern struct dict_object * ta_cmd_a;
+extern struct dict_object * ta_avp;
+extern struct dict_object * ta_avp_long;
+
+extern struct dict_object * ta_sess_id;
+extern struct dict_object * ta_origin_host;
+extern struct dict_object * ta_origin_realm;
+extern struct dict_object * ta_dest_host;
+extern struct dict_object * ta_dest_realm;
+extern struct dict_object * ta_user_name;
+extern struct dict_object * ta_res_code;