update it

This commit is contained in:
Sukchan Lee 2017-02-28 20:31:06 +09:00
parent 0f88ab773d
commit acb02da4d1
5 changed files with 181 additions and 229 deletions

View File

@ -9,15 +9,12 @@ static pthread_t s6a_stats_th = (pthread_t)NULL;
static void s6a_config_dump(void) static void s6a_config_dump(void)
{ {
d_trace(1, "------- s6a configuration dump: ---------\n"); d_trace(1, "------- s6a configuration dump: ---------\n");
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, " Mode ............... : %s%s\n", d_trace(1, " Mode ............... : %s%s\n",
s6a_config->mode & MODE_MME ? "MME" : "", s6a_config->mode & MODE_MME ? "MME" : "",
s6a_config->mode & MODE_HSS ? "HSS" : ""); s6a_config->mode & MODE_HSS ? "HSS" : "");
d_trace(1, " Destination Realm .. : %s\n", d_trace(1, " Vendor Id .......... : %u\n", s6a_config->vendor_id);
s6a_config->dest_realm ?: "- none -\n"); d_trace(1, " Application Id ..... : %u\n", s6a_config->appli_id);
d_trace(1, " Destination Host ... : %s\n", d_trace(1, " Duration ........... : %d(sec)\n", s6a_config->duration);
s6a_config->dest_host ?: "- none -\n");
d_trace(1, "------- /s6a configuration dump ---------\n"); d_trace(1, "------- /s6a configuration dump ---------\n");
} }
@ -25,7 +22,7 @@ static void s6a_config_dump(void)
static void * s6a_stats(void * arg) static void * s6a_stats(void * arg)
{ {
struct timespec start, now; struct timespec start, now;
struct ta_stats copy; struct s6a_stats copy;
/* Get the start time */ /* Get the start time */
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &start), ); CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &start), );
@ -33,11 +30,11 @@ static void * s6a_stats(void * arg)
/* Now, loop until canceled */ /* Now, loop until canceled */
while (1) { while (1) {
/* Display statistics every XX seconds */ /* Display statistics every XX seconds */
sleep(10); sleep(s6a_config->duration);
/* Now, get the current stats */ /* Now, get the current stats */
CHECK_POSIX_DO( pthread_mutex_lock(&s6a_config->stats_lock), ); CHECK_POSIX_DO( pthread_mutex_lock(&s6a_config->stats_lock), );
memcpy(&copy, &s6a_config->stats, sizeof(struct ta_stats)); memcpy(&copy, &s6a_config->stats, sizeof(struct s6a_stats));
CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->stats_lock), ); CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->stats_lock), );
/* Get the current execution time */ /* Get the current execution time */

View File

@ -31,13 +31,12 @@ struct s6a_config_t {
char *pi_diamid; char *pi_diamid;
c_uint16_t pic_port; /* port to connect to. 0: default. */ c_uint16_t pic_port; /* port to connect to. 0: default. */
c_uint32_t vendor_id; /* default 999999 */ int mode; /* default MODE_MME | MODE_HSS */
c_uint32_t appli_id; /* default 123456 */ c_uint32_t vendor_id; /* default 10415 */
int mode; /* default MODE_SERV | MODE_CLI */ c_uint32_t appli_id; /* default 16777251 */
char *dest_realm; /* default local realm */
char *dest_host; /* default NULL */ int duration; /* default 10 */
char *user_name; /* default NULL */ struct s6a_stats {
struct ta_stats {
unsigned long long nb_echoed; /* server */ unsigned long long nb_echoed; /* server */
unsigned long long nb_sent; /* client */ unsigned long long nb_sent; /* client */
unsigned long long nb_recv; /* client */ unsigned long long nb_recv; /* client */

View File

@ -97,16 +97,10 @@ static int s6a_common_config(void)
s6a_config = &g_conf; s6a_config = &g_conf;
/* Set the default values */ /* Set the default values */
s6a_config->mode = MODE_MME | MODE_HSS;
s6a_config->vendor_id = 10415; /* 3GPP Vendor ID */ s6a_config->vendor_id = 10415; /* 3GPP Vendor ID */
s6a_config->appli_id = 16777251; /* 3GPP S6A Application ID */ s6a_config->appli_id = 16777251; /* 3GPP S6A Application ID */
s6a_config->mode = MODE_MME | MODE_HSS; s6a_config->duration = 10; /* 10 seconds */
#if 0
s6a_config->dest_realm = strdup(fd_g_config->cnf_diamrlm);
#else
s6a_config->dest_realm = strdup(MME_REALM);
#endif
s6a_config->dest_host = NULL;
s6a_config->user_name = strdup("01045238277");
return 0; return 0;
} }

View File

@ -42,7 +42,7 @@ int s6a_fd_init(const char *conffile)
{ {
CHECK_FCT_DO( s6a_config_apply(), goto error ); CHECK_FCT_DO( s6a_config_apply(), goto error );
} }
/* Start the servers */ /* Start the servers */
CHECK_FCT_DO( fd_core_start(), goto error ); CHECK_FCT_DO( fd_core_start(), goto error );

View File

@ -6,237 +6,199 @@
#include "s6a_auth.h" #include "s6a_auth.h"
struct sess_state { struct sess_state {
c_int32_t randval; /* a random value to store in Test-AVP */ c_int32_t randval; /* a random value to store in Test-AVP */
struct timespec ts; /* Time of sending the message */ struct timespec ts; /* Time of sending the message */
} ; } ;
/* Cb called when an answer is received */ /* Cb called when an answer is received */
static void s6a_aia_cb(void * data, struct msg ** msg) static void s6a_aia_cb(void * data, struct msg ** msg)
{ {
struct sess_state * mi = NULL; struct sess_state *mi = NULL;
struct timespec ts; struct timespec ts;
struct session * sess; struct session *sess;
struct avp * avp; struct avp *avp;
struct avp_hdr * hdr; struct avp_hdr *hdr;
unsigned long dur; unsigned long dur;
int error = 0; int error = 0;
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return ); CHECK_SYS_DO(clock_gettime(CLOCK_REALTIME, &ts), return);
/* Search the session, retrieve its data */ /* Search the session, retrieve its data */
{ {
int new; int new;
CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &sess, &new), CHECK_FCT_DO(fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &sess, &new),
return ); return );
d_assert(new == 0, return, "fd_msg_sess_get() failed"); d_assert(new == 0, return, "fd_msg_sess_get() failed");
CHECK_FCT_DO( fd_sess_state_retrieve( s6a_mme_reg, sess, &mi ), CHECK_FCT_DO(fd_sess_state_retrieve( s6a_mme_reg, sess, &mi),
return ); return );
d_assert((void *)mi == data, return, "fd_sess_state_retrieve() failed"); d_assert((void *)mi == data, return, "fd_sess_state_retrieve() failed");
} }
/* Now log content of the answer */ /* Value of Result Code */
fprintf(stderr, "RECV "); CHECK_FCT_DO(fd_msg_search_avp(*msg, s6a_result_code, &avp), return);
if (avp)
#if 0 {
/* Value of Test-AVP */ CHECK_FCT_DO(fd_msg_avp_hdr( avp, &hdr ), return);
CHECK_FCT_DO( fd_msg_search_avp ( *msg, s6a_avp, &avp), return ); if (hdr->avp_value->i32 != 2001)
if (avp) { error++;
CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return ); }
if (hdr->avp_value->i32 == mi->randval) { else
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++;
}
#endif
/* Value of Result Code */
CHECK_FCT_DO( fd_msg_search_avp ( *msg, s6a_result_code, &avp),
return );
if (avp) {
CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
d_info("Status: %d ", hdr->avp_value->i32);
if (hdr->avp_value->i32 != 2001)
error++;
} else {
d_error("no_Result-Code"); d_error("no_Result-Code");
error++; error++;
} }
/* Value of Origin-Host */ /* Value of Origin-Host */
CHECK_FCT_DO( fd_msg_search_avp ( *msg, s6a_origin_host, &avp), return ); CHECK_FCT_DO(fd_msg_search_avp( *msg, s6a_origin_host, &avp), return);
if (avp) { if (avp)
CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return ); {
CHECK_FCT_DO(fd_msg_avp_hdr( avp, &hdr ), return);
d_info("From '%.*s' ", d_info("From '%.*s' ",
(int)hdr->avp_value->os.len, hdr->avp_value->os.data); (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
} else { }
else
{
d_error("no_Origin-Host "); d_error("no_Origin-Host ");
error++; error++;
} }
/* Value of Origin-Realm */ /* Value of Origin-Realm */
CHECK_FCT_DO( fd_msg_search_avp ( *msg, s6a_origin_realm, &avp), return ); CHECK_FCT_DO(fd_msg_search_avp( *msg, s6a_origin_realm, &avp), return);
if (avp) { if (avp)
CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return ); {
CHECK_FCT_DO(fd_msg_avp_hdr(avp, &hdr), return);
d_info("('%.*s') ", d_info("('%.*s') ",
(int)hdr->avp_value->os.len, hdr->avp_value->os.data); (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
} else { }
else
{
d_error("no_Origin-Realm "); d_error("no_Origin-Realm ");
error++; error++;
} }
CHECK_POSIX_DO( pthread_mutex_lock(&s6a_config->stats_lock), ); CHECK_POSIX_DO(pthread_mutex_lock(&s6a_config->stats_lock),);
dur = ((ts.tv_sec - mi->ts.tv_sec) * 1000000) + dur = ((ts.tv_sec - mi->ts.tv_sec) * 1000000) +
((ts.tv_nsec - mi->ts.tv_nsec) / 1000); ((ts.tv_nsec - mi->ts.tv_nsec) / 1000);
if (s6a_config->stats.nb_recv) { if (s6a_config->stats.nb_recv)
/* Ponderate in the avg */ {
s6a_config->stats.avg = (s6a_config->stats.avg * /* Ponderate in the avg */
s6a_config->stats.avg = (s6a_config->stats.avg *
s6a_config->stats.nb_recv + dur) / (s6a_config->stats.nb_recv + 1); s6a_config->stats.nb_recv + dur) / (s6a_config->stats.nb_recv + 1);
/* Min, max */ /* Min, max */
if (dur < s6a_config->stats.shortest) if (dur < s6a_config->stats.shortest)
s6a_config->stats.shortest = dur; s6a_config->stats.shortest = dur;
if (dur > s6a_config->stats.longest) if (dur > s6a_config->stats.longest)
s6a_config->stats.longest = dur; s6a_config->stats.longest = dur;
} else { }
s6a_config->stats.shortest = dur; else
s6a_config->stats.longest = dur; {
s6a_config->stats.avg = dur; s6a_config->stats.shortest = dur;
} s6a_config->stats.longest = dur;
if (error) s6a_config->stats.avg = dur;
s6a_config->stats.nb_errs++; }
else if (error)
s6a_config->stats.nb_recv++; s6a_config->stats.nb_errs++;
CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->stats_lock), ); else
s6a_config->stats.nb_recv++;
/* Display how long it took */ CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->stats_lock), );
if (ts.tv_nsec > mi->ts.tv_nsec) {
/* Display how long it took */
if (ts.tv_nsec > mi->ts.tv_nsec)
d_info("in %d.%06ld sec", d_info("in %d.%06ld sec",
(int)(ts.tv_sec - mi->ts.tv_sec), (int)(ts.tv_sec - mi->ts.tv_sec),
(long)(ts.tv_nsec - mi->ts.tv_nsec) / 1000); (long)(ts.tv_nsec - mi->ts.tv_nsec) / 1000);
} else { else
d_info("in %d.%06ld sec", d_info("in %d.%06ld sec",
(int)(ts.tv_sec + 1 - mi->ts.tv_sec), (int)(ts.tv_sec + 1 - mi->ts.tv_sec),
(long)(1000000000 + ts.tv_nsec - mi->ts.tv_nsec) / 1000); (long)(1000000000 + ts.tv_nsec - mi->ts.tv_nsec) / 1000);
}
/* Free the message */
/* Free the message */ CHECK_FCT_DO(fd_msg_free(*msg), return);
CHECK_FCT_DO(fd_msg_free(*msg), return); *msg = NULL;
*msg = NULL;
free(mi);
free(mi);
return;
return;
} }
status_t s6_send_auth_req() status_t s6_send_auth_req()
{ {
struct msg * req = NULL; struct msg *req = NULL;
struct avp * avp; struct avp *avp;
union avp_value val; union avp_value val;
struct sess_state * mi = NULL, *svg; struct sess_state *mi = NULL, *svg;
struct session *sess = NULL; struct session *sess = NULL;
/* Create the request */ /* Create the request */
CHECK_FCT_DO( fd_msg_new( s6a_cmd_air, CHECK_FCT_DO(fd_msg_new( s6a_cmd_air,
MSGFL_ALLOC_ETEID, &req ), goto out ); MSGFL_ALLOC_ETEID, &req ), goto out);
/* Create a new session */ /* Create a new session */
#define TEST_APP_SID_OPT "app_s6a" #define S6A_APP_SID_OPT "app_s6a"
CHECK_FCT_DO( fd_msg_new_session( req, (os0_t)TEST_APP_SID_OPT, CHECK_FCT_DO(fd_msg_new_session(req, (os0_t)S6A_APP_SID_OPT,
CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out ); CONSTSTRLEN(S6A_APP_SID_OPT)), goto out);
CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, req, &sess, NULL), CHECK_FCT_DO(fd_msg_sess_get(fd_g_config->cnf_dict, req, &sess, NULL),
goto out ); goto out);
/* Create the random value to store with the session */ /* Create the random value to store with the session */
mi = malloc(sizeof(struct sess_state)); mi = malloc(sizeof(struct sess_state));
d_assert(mi, goto out, "malloc failed: %s", strerror(errno)); d_assert(mi, goto out, "malloc failed: %s", strerror(errno));
mi->randval = (int32_t)random(); mi->randval = (int32_t)random();
/* Now set all AVPs values */ /* Set the Destination-Realm AVP */
CHECK_FCT_DO(fd_msg_avp_new(s6a_destination_realm, 0, &avp), goto out);
/* Set the Destination-Realm AVP */ val.os.data = (unsigned char *)(fd_g_config->cnf_diamrlm);
{ val.os.len = strlen(fd_g_config->cnf_diamrlm);
CHECK_FCT_DO( fd_msg_avp_new ( s6a_destination_realm, 0, &avp ), CHECK_FCT_DO(fd_msg_avp_setvalue(avp, &val), goto out);
goto out ); CHECK_FCT_DO(fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp), goto out);
val.os.data = (unsigned char *)(s6a_config->dest_realm);
val.os.len = strlen(s6a_config->dest_realm); /* Set Origin-Host & Origin-Realm */
CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out ); CHECK_FCT_DO(fd_msg_add_origin(req, 0), goto out);
CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ),
goto out ); /* Set the User-Name AVP if needed*/
} #define S6A_USER_NAME "01045238277"
CHECK_FCT_DO(fd_msg_avp_new(s6a_user_name, 0, &avp), goto out);
/* Set the Destination-Host AVP if needed*/ val.os.data = (unsigned char *)(S6A_USER_NAME);
if (s6a_config->dest_host) { val.os.len = strlen(S6A_USER_NAME);
CHECK_FCT_DO( fd_msg_avp_new ( s6a_destination_host, 0, &avp ), CHECK_FCT_DO(fd_msg_avp_setvalue(avp, &val), goto out);
goto out ); CHECK_FCT_DO(fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp), goto out);
val.os.data = (unsigned char *)(s6a_config->dest_host);
val.os.len = strlen(s6a_config->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 (s6a_config->user_name) {
CHECK_FCT_DO( fd_msg_avp_new ( s6a_user_name, 0, &avp ), goto out );
val.os.data = (unsigned char *)(s6a_config->user_name);
val.os.len = strlen(s6a_config->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 Auth-Session-Statee AVP if needed*/ /* Set the Auth-Session-Statee AVP if needed*/
{ CHECK_FCT_DO(fd_msg_avp_new(s6a_auth_session_state, 0, &avp), goto out);
CHECK_FCT_DO( fd_msg_avp_new ( s6a_auth_session_state, 0, &avp ), val.i32 = 1;
goto out ); CHECK_FCT_DO(fd_msg_avp_setvalue(avp, &val), goto out);
val.i32 = 1; CHECK_FCT_DO(fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp), goto out);
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 Visited-PLMN-Id AVP if needed*/ /* Set the Visited-PLMN-Id AVP if needed*/
{ c_uint8_t plmn[3] = { 0x00, 0xf1, 0x10 };
c_uint8_t plmn[3] = { 0x00, 0xf1, 0x10 }; CHECK_FCT_DO(fd_msg_avp_new(s6a_visited_plmn_id, 0, &avp), goto out);
CHECK_FCT_DO( fd_msg_avp_new ( s6a_visited_plmn_id, 0, &avp ), val.os.data = plmn;
goto out ); val.os.len = 3;
val.os.data = plmn; CHECK_FCT_DO(fd_msg_avp_setvalue(avp, &val ), goto out);
val.os.len = 3; CHECK_FCT_DO(fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp), goto out);
CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &mi->ts), goto out );
goto out );
} /* Keep a pointer to the session data for debug purpose,
* in real life we would not need it */
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &mi->ts), goto out ); svg = mi;
/* Keep a pointer to the session data for debug purpose, in real life we would not need it */ /* Store this value in the session */
svg = mi; CHECK_FCT_DO(fd_sess_state_store(s6a_mme_reg, sess, &mi), goto out);
/* Store this value in the session */ /* Log sending the message */
CHECK_FCT_DO( fd_sess_state_store ( s6a_mme_reg, sess, &mi ), goto out ); d_info("SEND %x to '%s' (-)\n", svg->randval, fd_g_config->cnf_diamrlm);
/* Log sending the message */ /* Send the request */
d_info("SEND %x to '%s' (%s)\n", svg->randval, CHECK_FCT_DO(fd_msg_send(&req, s6a_aia_cb, svg), goto out);
s6a_config->dest_realm, s6a_config->dest_host?:"-" );
/* Send the request */
CHECK_FCT_DO( fd_msg_send( &req, s6a_aia_cb, svg ), goto out );
/* Increment the counter */ /* Increment the counter */
CHECK_POSIX_DO( pthread_mutex_lock(&s6a_config->stats_lock), ); CHECK_POSIX_DO( pthread_mutex_lock(&s6a_config->stats_lock), );
s6a_config->stats.nb_sent++; s6a_config->stats.nb_sent++;
CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->stats_lock), ); CHECK_POSIX_DO( pthread_mutex_unlock(&s6a_config->stats_lock), );
out: out:
return CORE_OK; return CORE_OK;
} }