forked from acouzens/open5gs
P-CSCF diameter module is added
This commit is contained in:
parent
9e8ced5835
commit
f717eeb3ae
|
@ -5,7 +5,7 @@ bin_PROGRAMS = testrx
|
|||
testrx_SOURCES = \
|
||||
abts.h abts_tests.h testutil.h \
|
||||
abts.c testutil.c testpacket.h testpacket.c testapp.h testapp.c \
|
||||
volte_test.c \
|
||||
pcscf_fd_path.c volte_test.c \
|
||||
$(NULL)
|
||||
|
||||
testrx_LDADD = \
|
||||
|
|
|
@ -0,0 +1,331 @@
|
|||
#define TRACE_MODULE _pcscf_fd_path
|
||||
|
||||
#include "core_debug.h"
|
||||
#include "core_pool.h"
|
||||
#include "core_lib.h"
|
||||
|
||||
#include "gtp/gtp_xact.h"
|
||||
|
||||
#include "fd/fd_lib.h"
|
||||
#include "fd/rx/rx_dict.h"
|
||||
|
||||
#include "pcscf_fd_path.h"
|
||||
|
||||
#define MAX_NUM_SESSION_STATE 32
|
||||
|
||||
static struct session_handler *pgw_rx_reg = NULL;
|
||||
static fd_config_t fd_config;
|
||||
|
||||
struct sess_state {
|
||||
struct timespec ts; /* Time of sending the message */
|
||||
};
|
||||
|
||||
pool_declare(pgw_rx_sess_pool, struct sess_state, MAX_NUM_SESSION_STATE);
|
||||
|
||||
static void pgw_rx_aaa_cb(void *data, struct msg **msg);
|
||||
|
||||
void pgw_rx_send_aar()
|
||||
{
|
||||
struct msg *req = NULL;
|
||||
struct avp *avp;
|
||||
#if 0
|
||||
struct avp *avpch1, *avpch2;
|
||||
#else
|
||||
struct avp *avpch1;
|
||||
#endif
|
||||
union avp_value val;
|
||||
struct sess_state *mi = NULL, *svg;
|
||||
struct session *session = NULL;
|
||||
|
||||
c_uint32_t addr = 0x0100007f;
|
||||
|
||||
/* Create the random value to store with the session */
|
||||
pool_alloc_node(&pgw_rx_sess_pool, &mi);
|
||||
d_assert(mi, return, "malloc failed: %s", strerror(errno));
|
||||
|
||||
/* Create the request */
|
||||
CHECK_FCT_DO( fd_msg_new(rx_cmd_aar, MSGFL_ALLOC_ETEID, &req), goto out );
|
||||
{
|
||||
struct msg_hdr * h;
|
||||
CHECK_FCT_DO( fd_msg_hdr( req, &h ), goto out );
|
||||
h->msg_appl = RX_APPLICATION_ID;
|
||||
}
|
||||
|
||||
/* Create a new session */
|
||||
#define RX_APP_SID_OPT "app_rx"
|
||||
CHECK_FCT_DO( fd_msg_new_session(req, (os0_t)RX_APP_SID_OPT,
|
||||
CONSTSTRLEN(RX_APP_SID_OPT)), goto out );
|
||||
CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, req, &session, NULL),
|
||||
goto out );
|
||||
|
||||
/* Set Origin-Host & Origin-Realm */
|
||||
CHECK_FCT_DO( fd_msg_add_origin(req, 0), goto out );
|
||||
|
||||
/* Set the Destination-Realm AVP */
|
||||
CHECK_FCT_DO( fd_msg_avp_new(fd_destination_realm, 0, &avp), goto out );
|
||||
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_setvalue(avp, &val), goto out );
|
||||
CHECK_FCT_DO( fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp), goto out );
|
||||
|
||||
/* Set the Auth-Application-Id AVP */
|
||||
CHECK_FCT_DO( fd_msg_avp_new(fd_auth_application_id, 0, &avp), goto out );
|
||||
val.i32 = RX_APPLICATION_ID;
|
||||
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 Subscription-Id */
|
||||
CHECK_FCT_DO( fd_msg_avp_new(rx_subscription_id, 0, &avp),
|
||||
goto out );
|
||||
|
||||
CHECK_FCT_DO( fd_msg_avp_new(rx_subscription_id_type, 0, &avpch1),
|
||||
goto out );
|
||||
val.i32 = RX_SUBSCRIPTION_ID_TYPE_END_USER_IMSI;
|
||||
CHECK_FCT_DO( fd_msg_avp_setvalue (avpch1, &val), goto out );
|
||||
CHECK_FCT_DO( fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1), goto out );
|
||||
|
||||
#define RX_APP_IMSI_BCD "0123456789012345"
|
||||
CHECK_FCT_DO( fd_msg_avp_new(rx_subscription_id_data, 0, &avpch1),
|
||||
goto out );
|
||||
val.os.data = (c_uint8_t *)RX_APP_IMSI_BCD;
|
||||
val.os.len = strlen(RX_APP_IMSI_BCD);
|
||||
CHECK_FCT_DO( fd_msg_avp_setvalue (avpch1, &val), goto out );
|
||||
CHECK_FCT_DO( fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1), goto out );
|
||||
|
||||
CHECK_FCT_DO( fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp), goto out );
|
||||
|
||||
/* Set Framed-IP-Address */
|
||||
CHECK_FCT_DO( fd_msg_avp_new(rx_framed_ip_address, 0, &avp),
|
||||
goto out );
|
||||
val.os.data = (c_uint8_t*)&addr;
|
||||
val.os.len = 4;
|
||||
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 );
|
||||
|
||||
/* 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(pgw_rx_reg, session, &mi), goto out );
|
||||
|
||||
/* Send the request */
|
||||
CHECK_FCT_DO( fd_msg_send(&req, pgw_rx_aaa_cb, svg), goto out );
|
||||
|
||||
/* Increment the counter */
|
||||
CHECK_POSIX_DO( pthread_mutex_lock(&fd_logger_self()->stats_lock), );
|
||||
fd_logger_self()->stats.nb_sent++;
|
||||
CHECK_POSIX_DO( pthread_mutex_unlock(&fd_logger_self()->stats_lock), );
|
||||
|
||||
out:
|
||||
pool_free_node(&pgw_rx_sess_pool, mi);
|
||||
return;
|
||||
}
|
||||
|
||||
static void pgw_rx_aaa_cb(void *data, struct msg **msg)
|
||||
{
|
||||
struct sess_state *mi = NULL;
|
||||
struct timespec ts;
|
||||
struct session *session;
|
||||
#if 0
|
||||
struct avp *avp, *avpch1, *avpch2, *avpch3, *avpch4;
|
||||
#else
|
||||
struct avp *avp, *avpch1;
|
||||
#endif
|
||||
struct avp_hdr *hdr;
|
||||
unsigned long dur;
|
||||
int error = 0;
|
||||
int new;
|
||||
c_int32_t result_code;
|
||||
|
||||
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return );
|
||||
|
||||
/* Search the session, retrieve its data */
|
||||
CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &session, &new),
|
||||
return );
|
||||
d_assert(new == 0, return, );
|
||||
|
||||
CHECK_FCT_DO( fd_sess_state_retrieve(pgw_rx_reg, session, &mi), return );
|
||||
d_assert(mi && (void *)mi == data, return, );
|
||||
|
||||
/* Value of Result Code */
|
||||
CHECK_FCT_DO( fd_msg_search_avp(*msg, fd_result_code, &avp), return );
|
||||
if (avp)
|
||||
{
|
||||
CHECK_FCT_DO( fd_msg_avp_hdr(avp, &hdr), return);
|
||||
result_code = hdr->avp_value->i32;
|
||||
d_trace(3, "Result Code: %d\n", hdr->avp_value->i32);
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK_FCT_DO( fd_msg_search_avp(*msg,
|
||||
fd_experimental_result, &avp), return );
|
||||
if (avp)
|
||||
{
|
||||
CHECK_FCT_DO( fd_avp_search_avp(avp,
|
||||
fd_experimental_result_code, &avpch1), return );
|
||||
if (avpch1)
|
||||
{
|
||||
CHECK_FCT_DO( fd_msg_avp_hdr(avpch1, &hdr), return);
|
||||
result_code = hdr->avp_value->i32;
|
||||
d_trace(3, "Experimental Result Code: %d\n",
|
||||
result_code);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
d_error("no Result-Code");
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Value of Origin-Host */
|
||||
CHECK_FCT_DO( fd_msg_search_avp(*msg, fd_origin_host, &avp), return );
|
||||
if (avp)
|
||||
{
|
||||
CHECK_FCT_DO( fd_msg_avp_hdr(avp, &hdr), return );
|
||||
d_trace(3, "From '%.*s' ",
|
||||
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
d_error("no_Origin-Host ");
|
||||
error++;
|
||||
}
|
||||
|
||||
/* Value of Origin-Realm */
|
||||
CHECK_FCT_DO( fd_msg_search_avp(*msg, fd_origin_realm, &avp), return );
|
||||
if (avp)
|
||||
{
|
||||
CHECK_FCT_DO( fd_msg_avp_hdr(avp, &hdr), return );
|
||||
d_trace(3, "('%.*s') ",
|
||||
(int)hdr->avp_value->os.len, hdr->avp_value->os.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
d_error("no_Origin-Realm ");
|
||||
error++;
|
||||
}
|
||||
|
||||
if (result_code != ER_DIAMETER_SUCCESS)
|
||||
{
|
||||
d_warn("ERROR DIAMETER Result Code(%d)", result_code);
|
||||
error++;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
/* Free the message */
|
||||
CHECK_POSIX_DO( pthread_mutex_lock(&fd_logger_self()->stats_lock), );
|
||||
dur = ((ts.tv_sec - mi->ts.tv_sec) * 1000000) +
|
||||
((ts.tv_nsec - mi->ts.tv_nsec) / 1000);
|
||||
if (fd_logger_self()->stats.nb_recv)
|
||||
{
|
||||
/* Ponderate in the avg */
|
||||
fd_logger_self()->stats.avg = (fd_logger_self()->stats.avg *
|
||||
fd_logger_self()->stats.nb_recv + dur) /
|
||||
(fd_logger_self()->stats.nb_recv + 1);
|
||||
/* Min, max */
|
||||
if (dur < fd_logger_self()->stats.shortest)
|
||||
fd_logger_self()->stats.shortest = dur;
|
||||
if (dur > fd_logger_self()->stats.longest)
|
||||
fd_logger_self()->stats.longest = dur;
|
||||
}
|
||||
else
|
||||
{
|
||||
fd_logger_self()->stats.shortest = dur;
|
||||
fd_logger_self()->stats.longest = dur;
|
||||
fd_logger_self()->stats.avg = dur;
|
||||
}
|
||||
if (error)
|
||||
fd_logger_self()->stats.nb_errs++;
|
||||
else
|
||||
fd_logger_self()->stats.nb_recv++;
|
||||
|
||||
CHECK_POSIX_DO( pthread_mutex_unlock(&fd_logger_self()->stats_lock), );
|
||||
|
||||
/* Display how long it took */
|
||||
if (ts.tv_nsec > mi->ts.tv_nsec)
|
||||
d_trace(3, "in %d.%06ld sec\n",
|
||||
(int)(ts.tv_sec - mi->ts.tv_sec),
|
||||
(long)(ts.tv_nsec - mi->ts.tv_nsec) / 1000);
|
||||
else
|
||||
d_trace(3, "in %d.%06ld sec\n",
|
||||
(int)(ts.tv_sec + 1 - mi->ts.tv_sec),
|
||||
(long)(1000000000 + ts.tv_nsec - mi->ts.tv_nsec) / 1000);
|
||||
|
||||
CHECK_FCT_DO( fd_msg_free(*msg), return );
|
||||
*msg = NULL;
|
||||
|
||||
pool_free_node(&pgw_rx_sess_pool, mi);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void pcscf_fd_config()
|
||||
{
|
||||
memset(&fd_config, 0, sizeof(fd_config_t));
|
||||
|
||||
fd_config.cnf_diamid = "pcscf.localdomain";
|
||||
fd_config.cnf_diamrlm = "localdomain";
|
||||
fd_config.cnf_port = DIAMETER_PORT;
|
||||
fd_config.cnf_port_tls = DIAMETER_SECURE_PORT;
|
||||
fd_config.cnf_flags.no_sctp = 1;
|
||||
fd_config.cnf_addr = "127.0.0.1";
|
||||
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dbg_msg_dumps.so";
|
||||
fd_config.ext[fd_config.num_of_ext].conf = "0x8888";
|
||||
fd_config.num_of_ext++;
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dict_rfc5777.so";
|
||||
fd_config.num_of_ext++;
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dict_mip6i.so";
|
||||
fd_config.num_of_ext++;
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dict_nasreq.so";
|
||||
fd_config.num_of_ext++;
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dict_nas_mipv6.so";
|
||||
fd_config.num_of_ext++;
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dict_dcca.so";
|
||||
fd_config.num_of_ext++;
|
||||
fd_config.ext[fd_config.num_of_ext].module = "dict_dcca_3gpp.so";
|
||||
fd_config.num_of_ext++;
|
||||
|
||||
fd_config.conn[fd_config.num_of_conn].identity = "pcrf.localdomain";
|
||||
fd_config.conn[fd_config.num_of_conn].addr = "127.0.0.5";
|
||||
fd_config.num_of_conn++;
|
||||
}
|
||||
|
||||
int pcscf_fd_init(void)
|
||||
{
|
||||
pool_init(&pgw_rx_sess_pool, MAX_NUM_SESSION_STATE);
|
||||
|
||||
pcscf_fd_config();
|
||||
|
||||
CHECK_FCT( fd_init(FD_MODE_CLIENT, NULL, &fd_config) );
|
||||
|
||||
CHECK_FCT( rx_dict_init() );
|
||||
|
||||
CHECK_FCT( fd_sess_handler_create(&pgw_rx_reg, (void *)free, NULL, NULL) );
|
||||
|
||||
/* Advertise the support for the application in the peer */
|
||||
CHECK_FCT( fd_disp_app_support(rx_application, fd_vendor, 1, 0) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pcscf_fd_final(void)
|
||||
{
|
||||
CHECK_FCT_DO( fd_sess_handler_destroy(&pgw_rx_reg, NULL), );
|
||||
|
||||
fd_final();
|
||||
|
||||
if (pool_used(&pgw_rx_sess_pool))
|
||||
d_error("%d not freed in pgw_rx_sess_pool[%d] of S6A-SM",
|
||||
pool_used(&pgw_rx_sess_pool), pool_size(&pgw_rx_sess_pool));
|
||||
d_trace(3, "%d not freed in pgw_rx_sess_pool[%d] of S6A-SM\n",
|
||||
pool_used(&pgw_rx_sess_pool), pool_size(&pgw_rx_sess_pool));
|
||||
|
||||
pool_final(&pgw_rx_sess_pool);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __PCSCF_FD_PATH_H__
|
||||
#define __PCSCF_FD_PATH_H__
|
||||
|
||||
#include "core_errno.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
CORE_DECLARE(int) pcscf_fd_init(void);
|
||||
CORE_DECLARE(void) pcscf_fd_final(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __PCSCF_FD_PATH_H__ */
|
||||
|
|
@ -145,4 +145,5 @@ pcrf:
|
|||
connect:
|
||||
- identity: pgw.localdomain
|
||||
addr: 127.0.0.2
|
||||
# port: 3868
|
||||
- identity: pcscf.localdomain
|
||||
addr: 127.0.0.1
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "app/context.h"
|
||||
#include "app/app.h"
|
||||
|
||||
#include "pcscf_fd_path.h"
|
||||
|
||||
static semaphore_id pcrf_sem1 = 0;
|
||||
static semaphore_id pcrf_sem2 = 0;
|
||||
|
||||
|
@ -284,6 +286,9 @@ status_t test_app_initialize(const char *config_path, const char *log_path)
|
|||
rv = app_did_initialize();
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
rv = pcscf_fd_init();
|
||||
if (rv != CORE_OK) return CORE_ERROR;
|
||||
|
||||
return CORE_OK;;
|
||||
}
|
||||
|
||||
|
@ -291,6 +296,8 @@ void test_app_terminate(void)
|
|||
{
|
||||
app_will_terminate();
|
||||
|
||||
pcscf_fd_final();
|
||||
|
||||
/* if (context_self()->parameter.no_mme == 0) */
|
||||
{
|
||||
if (mme_sem2) semaphore_post(mme_sem2);
|
||||
|
|
Loading…
Reference in New Issue