Configuration for TRACE is added

This commit is contained in:
Sukchan Lee 2017-07-31 22:35:25 +09:00
parent 2749a864ab
commit f7ec3c7c6e
30 changed files with 395 additions and 166 deletions

View File

@ -107,7 +107,7 @@ status_t context_parse_config()
size_t root_tokens = 0;
size_t skip_tokens = 0;
size_t i = 0, j = 1;
size_t i, j, m, n;
for (i = 0, j = 1; j > 0; i++, j--)
{
@ -127,9 +127,46 @@ status_t context_parse_config()
case ROOT:
{
if (jsmntok_equal(json, t, "DB_URI") == 0)
{
self.db_uri = jsmntok_to_string(json, t+1);
}
else if (jsmntok_equal(json, t, "LOG_PATH") == 0)
{
self.log_path = jsmntok_to_string(json, t+1);
}
else if (jsmntok_equal(json, t, "TRACE") == 0)
{
for (m = 1, n = 1; n > 0; m++, n--)
{
n += (t+m)->size;
char *v = jsmntok_to_string(json, t+m+1);
if (jsmntok_equal(json, t+m, "CONTEXT") == 0)
{
if (v) self.trace_level.context = atoi(v);
}
else if (jsmntok_equal(json, t+m, "SM") == 0)
{
if (v) self.trace_level.sm = atoi(v);
}
else if (jsmntok_equal(json, t+m, "S1AP") == 0)
{
if (v) self.trace_level.s1ap = atoi(v);
}
else if (jsmntok_equal(json, t+m, "NAS") == 0)
{
if (v) self.trace_level.nas = atoi(v);
}
else if (jsmntok_equal(json, t+m, "S6A") == 0)
{
if (v) self.trace_level.s6a = atoi(v);
}
else if (jsmntok_equal(json, t+m, "GTP") == 0)
{
if (v) self.trace_level.gtp = atoi(v);
}
}
}
state = SKIP;
skip_tokens = t->size;

View File

@ -29,6 +29,15 @@ typedef struct _context_t {
void *db_client;
char *db_name;
void *database;
struct {
int context;
int sm;
int s1ap;
int nas;
int gtp;
int s6a;
} trace_level;
} context_t;
CORE_DECLARE(status_t) context_init(void);
@ -37,6 +46,7 @@ CORE_DECLARE(context_t*) context_self(void);
CORE_DECLARE(status_t) context_read_file(char *file_path);
CORE_DECLARE(status_t) context_parse_config(void);
CORE_DECLARE(status_t) context_setup_trace_module(void);
CORE_DECLARE(status_t) context_db_init(char *db_uri);
CORE_DECLARE(status_t) context_db_final(void);

View File

@ -22,7 +22,7 @@ static tlv_t* _tlv_add_leaf(
{
tlv_uint8_t *v = (tlv_uint8_t *)msg;
d_trace(1, "V_1B:%02x", v->u8);
d_trace(5, "V_1B:%02x", v->u8);
if (parent_tlv)
tlv = tlv_embed(parent_tlv,
@ -37,7 +37,7 @@ static tlv_t* _tlv_add_leaf(
{
tlv_uint16_t *v = (tlv_uint16_t *)msg;
d_trace(1, "V_2B:%04x", v->u16);
d_trace(5, "V_2B:%04x", v->u16);
v->u16 = htons(v->u16);
@ -55,7 +55,7 @@ static tlv_t* _tlv_add_leaf(
{
tlv_uint24_t *v = (tlv_uint24_t *)msg;
d_trace(1, "V_3B:%06x", v->u24);
d_trace(5, "V_3B:%06x", v->u24);
v->u24 = v->u24 << 8;
v->u24 = htonl(v->u24);
@ -74,7 +74,7 @@ static tlv_t* _tlv_add_leaf(
{
tlv_uint32_t *v = (tlv_uint32_t *)msg;
d_trace(1, "V_4B:%08x", v->u32);
d_trace(5, "V_4B:%08x", v->u32);
v->u32 = htonl(v->u32);
@ -90,8 +90,8 @@ static tlv_t* _tlv_add_leaf(
{
tlv_octet_t *v = (tlv_octet_t *)msg;
d_trace(1, "V_FSTR: ", v->data);
d_trace_hex(1, v->data, v->len);
d_trace(5, "V_FSTR: ", v->data);
d_trace_hex(5, v->data, v->len);
if (parent_tlv)
tlv = tlv_embed(parent_tlv,
@ -108,8 +108,8 @@ static tlv_t* _tlv_add_leaf(
d_assert(v->len > 0, return NULL, "Length is zero");
d_trace(1, "V_VSTR: ", v->data);
d_trace_hex(1, v->data, v->len);
d_trace(5, "V_VSTR: ", v->data);
d_trace_hex(5, v->data, v->len);
if (parent_tlv)
tlv = tlv_embed(parent_tlv,
@ -122,7 +122,7 @@ static tlv_t* _tlv_add_leaf(
}
case TLV_NULL:
{
d_trace(1, "V_NULL" );
d_trace(5, "V_NULL" );
if (parent_tlv)
tlv = tlv_embed(parent_tlv,
@ -179,7 +179,7 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv,
if (desc->ctype == TLV_COMPOUND)
{
d_trace(1, "\nBUILD %sC#%d [%s] T:%d I:%d (vsz=%d) off:%p ",
d_trace(5, "\nBUILD %sC#%d [%s] T:%d I:%d (vsz=%d) off:%p ",
indent, i, desc->name, desc->type, desc->instance,
desc->vsize, p + offset2);
@ -197,7 +197,7 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv,
}
else
{
d_trace(1, "\nBUILD %sL#%d [%s] T:%d L:%d I:%d "
d_trace(5, "\nBUILD %sL#%d [%s] T:%d L:%d I:%d "
"(cls:%d vsz:%d) off:%p ",
indent, i, desc->name, desc->type, desc->length,
desc->instance, desc->ctype, desc->vsize,
@ -224,7 +224,7 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv,
{
if (desc->ctype == TLV_COMPOUND)
{
d_trace(1, "\nBUILD %sC#%d [%s] T:%d I:%d (vsz=%d) off:%p ",
d_trace(5, "\nBUILD %sC#%d [%s] T:%d I:%d (vsz=%d) off:%p ",
indent, i, desc->name, desc->type, desc->instance,
desc->vsize, p + offset);
@ -242,7 +242,7 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv,
}
else
{
d_trace(1, "\nBUILD %sL#%d [%s] T:%d L:%d I:%d "
d_trace(5, "\nBUILD %sL#%d [%s] T:%d L:%d I:%d "
"(cls:%d vsz:%d) off:%p ",
indent, i, desc->name, desc->type, desc->length,
desc->instance, desc->ctype, desc->vsize,
@ -277,7 +277,7 @@ status_t tlv_build_msg(pkbuf_t **pkbuf, tlv_desc_t *desc, void *msg, int mode)
d_assert(desc->child_descs[0], return CORE_ERROR,
"TLV message descriptor has no members");
d_trace(1, "\n[%s] BUILD MESSAGE\n", desc->name);
d_trace(3, "\n[%s] BUILD MESSAGE\n", desc->name);
r = _tlv_add_compound(&root, NULL, desc, msg, 0);
d_assert(r > 0 && root, tlv_free_all(root); return CORE_ERROR,
@ -360,7 +360,7 @@ static status_t _tlv_parse_leaf(void *msg, tlv_desc_t *desc, tlv_t *tlv)
return CORE_ERROR;
}
v->u8 = *(c_uint8_t*)(tlv->value);
d_trace(1, "V_1B:%02x", v->u8);
d_trace(5, "V_1B:%02x", v->u8);
break;
}
case TLV_UINT16:
@ -375,7 +375,7 @@ static status_t _tlv_parse_leaf(void *msg, tlv_desc_t *desc, tlv_t *tlv)
}
v->u16 = ((((c_uint8_t*)tlv->value)[0]<< 8)&0xff00) |
((((c_uint8_t*)tlv->value)[1] )&0x00ff);
d_trace(1, "V_2B:%02x", v->u16);
d_trace(5, "V_2B:%02x", v->u16);
break;
}
case TLV_UINT24:
@ -391,7 +391,7 @@ static status_t _tlv_parse_leaf(void *msg, tlv_desc_t *desc, tlv_t *tlv)
v->u24 = ((((c_uint8_t*)tlv->value)[0]<<16)&0x00ff0000) |
((((c_uint8_t*)tlv->value)[1]<< 8)&0x0000ff00) |
((((c_uint8_t*)tlv->value)[2] )&0x000000ff);
d_trace(1, "V_3B:%06x", v->u24);
d_trace(5, "V_3B:%06x", v->u24);
break;
}
case TLV_UINT32:
@ -408,7 +408,7 @@ static status_t _tlv_parse_leaf(void *msg, tlv_desc_t *desc, tlv_t *tlv)
((((c_uint8_t*)tlv->value)[1]<<16)&0x00ff0000) |
((((c_uint8_t*)tlv->value)[2]<< 8)&0x0000ff00) |
((((c_uint8_t*)tlv->value)[3] )&0x000000ff);
d_trace(1, "V_4B:%08x", v->u32);
d_trace(5, "V_4B:%08x", v->u32);
break;
}
case TLV_FIXED_STR:
@ -425,8 +425,8 @@ static status_t _tlv_parse_leaf(void *msg, tlv_desc_t *desc, tlv_t *tlv)
v->data = tlv->value;
v->len = tlv->length;
d_trace(1, "V_FSTR: ", v->data);
d_trace_hex(1, v->data, v->len);
d_trace(5, "V_FSTR: ", v->data);
d_trace_hex(5, v->data, v->len);
break;
}
case TLV_VAR_STR:
@ -436,8 +436,8 @@ static status_t _tlv_parse_leaf(void *msg, tlv_desc_t *desc, tlv_t *tlv)
v->data = tlv->value;
v->len = tlv->length;
d_trace(1, "V_VSTR: ", v->data);
d_trace_hex(1, v->data, v->len);
d_trace(5, "V_VSTR: ", v->data);
d_trace_hex(5, v->data, v->len);
break;
}
case TLV_NULL:
@ -519,7 +519,7 @@ static status_t _tlv_parse_compound(void *msg, tlv_desc_t *parent_desc,
return CORE_ERROR;
}
d_trace(1, "\nPARSE %sC#%d [%s] T:%d I:%d (vsz=%d) off:%p ",
d_trace(5, "\nPARSE %sC#%d [%s] T:%d I:%d (vsz=%d) off:%p ",
indent, i++, desc->name, desc->type, desc->instance,
desc->vsize, p + offset);
@ -537,7 +537,7 @@ static status_t _tlv_parse_compound(void *msg, tlv_desc_t *parent_desc,
}
else
{
d_trace(1, "\nPARSE %sL#%d [%s] T:%d L:%d I:%d "
d_trace(5, "\nPARSE %sL#%d [%s] T:%d L:%d I:%d "
"(cls:%d vsz:%d) off:%p ",
indent, i++, desc->name, desc->type, desc->length,
desc->instance, desc->ctype, desc->vsize, p + offset);
@ -554,7 +554,7 @@ static status_t _tlv_parse_compound(void *msg, tlv_desc_t *parent_desc,
tlv = tlv->next;
}
d_trace(1, "\n");
d_trace(5, "\n");
return CORE_OK;
}
@ -573,7 +573,7 @@ status_t tlv_parse_msg(void *msg, tlv_desc_t *desc, pkbuf_t *pkbuf, int mode)
d_assert(desc->child_descs[0], return CORE_ERROR,
"TLV message descriptor has no members");
d_trace(1, "\n[%s] PARSE MESSAGE\n", desc->name);
d_trace(3, "\n[%s] PARSE MESSAGE\n", desc->name);
root = tlv_parse_block(pkbuf->len, pkbuf->payload, mode);
if (root == NULL)

View File

@ -86,9 +86,9 @@ status_t gtp_send(net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf)
sent = net_sendto(sock, pkbuf->payload, pkbuf->len,
gnode->addr, gnode->port);
d_trace(1,"Sent %d->%d bytes to [%s:%d]\n", pkbuf->len, sent,
d_trace(50, "Sent %d->%d bytes to [%s:%d]\n", pkbuf->len, sent,
INET_NTOP(&gnode->addr, buf), gnode->port);
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace_hex(50, pkbuf->payload, pkbuf->len);
if (sent < 0 || sent != pkbuf->len)
{
d_error("net_send error (%d:%s)",
@ -122,7 +122,7 @@ pkbuf_t *gtp_handle_echo_req(pkbuf_t *pkb)
}
d_trace(1, "gtp_handle_without_teid(ECHO_REQ)\n");
d_trace(3, "gtp_handle_without_teid(ECHO_REQ)\n");
pkb_resp = pkbuf_alloc(0, 100 /* enough for ECHO_RSP; use smaller buffer */);
d_assert(pkb_resp, return NULL, "Can't allocate pkbuf");

View File

@ -82,6 +82,7 @@ static gtp_xact_t *gtp_xact_create(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, c_uint8_t org, c_uint32_t xid,
c_uint32_t duration, c_uint8_t retry_count)
{
char buf[INET_ADDRSTRLEN];
gtp_xact_t *xact = NULL;
d_assert(context, return NULL, "Null param");
@ -107,8 +108,8 @@ static gtp_xact_t *gtp_xact_create(gtp_xact_ctx_t *context,
list_append(xact->org == GTP_LOCAL_ORIGINATOR ?
&xact->gnode->local_list : &xact->gnode->remote_list, xact);
d_trace(1, "[%d]%s Create : xid = 0x%x\n",
gnode->port,
d_trace(3, "[%s:%d] %s Create : xid = 0x%x\n",
INET_NTOP(&gnode->addr, buf), gnode->port,
xact->org == GTP_LOCAL_ORIGINATOR ? "LOCAL " : "REMOTE",
xact->xid);
@ -117,12 +118,14 @@ static gtp_xact_t *gtp_xact_create(gtp_xact_ctx_t *context,
static status_t gtp_xact_delete(gtp_xact_t *xact)
{
char buf[INET_ADDRSTRLEN];
d_assert(xact, , "Null param");
d_assert(xact->gnode, , "Null param");
d_assert(xact->tm_wait, , "Null param");
d_trace(1, "[%d]%s Delete : xid = 0x%x\n",
xact->gnode->port,
d_trace(3, "[%s:%d] %s Delete : xid = 0x%x\n",
INET_NTOP(&xact->gnode->addr, buf), xact->gnode->port,
xact->org == GTP_LOCAL_ORIGINATOR ? "LOCAL " : "REMOTE",
xact->xid);
@ -205,6 +208,7 @@ status_t gtp_xact_commit(gtp_xact_t *xact,
status_t gtp_xact_associated_commit(gtp_xact_t *xact,
gtp_xact_t *assoc_xact, c_uint8_t type, c_uint32_t teid, pkbuf_t *pkbuf)
{
char buf[INET_ADDRSTRLEN];
gtpv2c_header_t *h = NULL;
d_assert(xact, goto out, "Null param");
@ -212,8 +216,8 @@ status_t gtp_xact_associated_commit(gtp_xact_t *xact,
d_assert(xact->gnode, goto out, "Null param");
d_assert(pkbuf, goto out, "Null param");
d_trace(1, "[%d]%s Commit : xid = 0x%x\n",
xact->gnode->port,
d_trace(3, "[%s:%d] %s Commit : xid = 0x%x\n",
INET_NTOP(&xact->gnode->addr, buf), xact->gnode->port,
xact->org == GTP_LOCAL_ORIGINATOR ? "LOCAL " : "REMOTE",
xact->xid);
@ -246,6 +250,7 @@ out:
status_t gtp_xact_timeout(index_t index)
{
char buf[INET_ADDRSTRLEN];
gtp_xact_t *xact = NULL;
d_assert(index, goto out, "Invalid Index");
@ -254,8 +259,8 @@ status_t gtp_xact_timeout(index_t index)
d_assert(xact->sock, goto out, "Null param");
d_assert(xact->gnode, goto out, "Null param");
d_trace(1, "[%d]%s Timeout : xid = 0x%x\n",
xact->gnode->port,
d_trace(3, "[%s:%d] %s Timeout : xid = 0x%x\n",
INET_NTOP(&xact->gnode->addr, buf), xact->gnode->port,
xact->org == GTP_LOCAL_ORIGINATOR ? "LOCAL " : "REMOTE",
xact->xid);
@ -292,6 +297,7 @@ out:
static gtp_xact_t *gtp_xact_find(
gtp_node_t *gnode, c_uint8_t type, c_uint32_t sqn)
{
char buf[INET_ADDRSTRLEN];
c_uint32_t xid;
gtp_xact_t *xact = NULL;
@ -337,8 +343,8 @@ static gtp_xact_t *gtp_xact_find(
if (xact)
{
d_trace(1, "[%d]%s Find : xid = 0x%x\n",
gnode->port,
d_trace(3, "[%s:%d] %s Find : xid = 0x%x\n",
INET_NTOP(&gnode->addr, buf), gnode->port,
xact->org == GTP_LOCAL_ORIGINATOR ? "LOCAL " : "REMOTE",
xact->xid);
}
@ -352,6 +358,7 @@ status_t gtp_xact_receive(
c_uint8_t *type, c_uint32_t *teid, gtp_message_t *gtp_message,
pkbuf_t *pkbuf)
{
char buf[INET_ADDRSTRLEN];
status_t rv;
gtpv2c_header_t *h = NULL;
gtp_xact_t *new = NULL;
@ -373,8 +380,8 @@ status_t gtp_xact_receive(
}
d_assert(new, goto out1, "Null param");
d_trace(1, "[%d]%s Receive : xid = 0x%x\n",
gnode->port,
d_trace(3, "[%s:%d] %s Receive : xid = 0x%x\n",
INET_NTOP(&gnode->addr, buf), gnode->port,
new->org == GTP_LOCAL_ORIGINATOR ? "LOCAL " : "REMOTE",
new->xid);

View File

@ -222,7 +222,7 @@ static void s1ap_decode_xer_print_message(
void *app_key, s1ap_message_t *message_p),
asn_app_consume_bytes_f *cb, s1ap_message_t *message_p)
{
if (g_trace_mask && TRACE_MODULE >= 3)
if (g_trace_mask && TRACE_MODULE >= 5)
{
char *message_string = core_calloc(HUGE_STRING_LEN, sizeof(c_uint8_t));
s1ap_string_total_size = 0;

View File

@ -391,7 +391,7 @@ static void s1ap_encode_xer_print_message(
void *app_key, s1ap_message_t *message_p),
asn_app_consume_bytes_f *cb, s1ap_message_t *message_p)
{
if (g_trace_mask && TRACE_MODULE >= 3)
if (g_trace_mask && TRACE_MODULE >= 5)
{
char *message_string = core_calloc(HUGE_STRING_LEN, sizeof(c_uint8_t));
s1ap_string_total_size = 0;

View File

@ -83,10 +83,10 @@ static void s6a_fd_logger(int printlevel, const char *format, va_list ap)
switch(printlevel)
{
case FD_LOG_ANNOYING:
d_trace(10, "freeDiameter[%d]: %s\n", printlevel, buffer);
d_trace(5, "freeDiameter[%d]: %s\n", printlevel, buffer);
break;
case FD_LOG_DEBUG:
d_trace(3, "freeDiameter[%d]: %s\n", printlevel, buffer);
d_trace(5, "freeDiameter[%d]: %s\n", printlevel, buffer);
break;
case FD_LOG_NOTICE:
d_trace(1, "freeDiameter[%d]: %s\n", printlevel, buffer);

View File

@ -43,33 +43,33 @@ static void * s6a_stats(void * arg)
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), );
/* Now, display everything */
d_trace(1, "------- app_test statistics ---------\n");
d_trace(3, "------- s6a statistics ---------\n");
if (now.tv_nsec >= start.tv_nsec)
{
d_trace(1, " Executing for: %d.%06ld sec\n",
d_trace(3, " Executing for: %d.%06ld sec\n",
(int)(now.tv_sec - start.tv_sec),
(long)(now.tv_nsec - start.tv_nsec) / 1000);
}
else
{
d_trace(1, " Executing for: %d.%06ld sec\n",
d_trace(3, " Executing for: %d.%06ld sec\n",
(int)(now.tv_sec - 1 - start.tv_sec),
(long)(now.tv_nsec + 1000000000 - start.tv_nsec) / 1000);
}
d_trace(1, " Local: %llu message(s) echoed\n",
d_trace(3, " Local: %llu message(s) echoed\n",
copy.nb_echoed);
d_trace(1, " Remote:\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",
d_trace(3, " Remote:\n");
d_trace(3, " %llu message(s) sent\n", copy.nb_sent);
d_trace(3, " %llu error(s) received\n", copy.nb_errs);
d_trace(3, " %llu answer(s) received\n", copy.nb_recv);
d_trace(3, " fastest: %ld.%06ld sec.\n",
copy.shortest / 1000000, copy.shortest % 1000000);
d_trace(1, " slowest: %ld.%06ld sec.\n",
d_trace(3, " slowest: %ld.%06ld sec.\n",
copy.longest / 1000000, copy.longest % 1000000);
d_trace(1, " Average: %ld.%06ld sec.\n",
d_trace(3, " Average: %ld.%06ld sec.\n",
copy.avg / 1000000, copy.avg % 1000000);
d_trace(1, "-------------------------------------\n");
d_trace(3, "-------------------------------------\n");
}
return NULL; /* never called */

32
main.c
View File

@ -113,38 +113,6 @@ int main(int argc, char *argv[])
}
}
{
#if 0
extern int _s1ap_path;
d_trace_level(&_s1ap_path, 100);
extern int _sgw_path;
d_trace_level(&_sgw_path, 100);
extern int _pgw_path;
d_trace_level(&_pgw_path, 100);
extern int _pgw_context;
d_trace_level(&_pgw_context, 100);
extern int _gtp_xact;
d_trace_level(&_gtp_xact, 100);
extern int _mme_sm;
d_trace_level(&_mme_sm, 100);
extern int _s1ap_sm;
d_trace_level(&_s1ap_sm, 100);
extern int _emm_sm;
d_trace_level(&_emm_sm, 100);
extern int _bearer_sm;
d_trace_level(&_bearer_sm, 100);
extern int _s1ap_recv;
d_trace_level(&_s1ap_recv, 100);
extern int _s1ap_send;
d_trace_level(&_s1ap_send, 100);
extern int _s6a;
d_trace_level(&_s6a, 100);
extern int _tlv_msg;
d_trace_level(&_tlv_msg, 1);
#endif
}
show_version();
d_print("\n");

View File

@ -268,6 +268,37 @@ status_t hss_context_parse_config()
return CORE_OK;
}
status_t hss_context_setup_trace_module()
{
int context = context_self()->trace_level.context;
int sm = context_self()->trace_level.sm;
int s6a = context_self()->trace_level.s6a;
if (context)
{
extern int _context;
d_trace_level(&_context, context);
extern int _hss_context;
d_trace_level(&_hss_context, context);
}
if (sm)
{
extern int _hss_s6a_handler;
d_trace_level(&_hss_s6a_handler, sm);
}
if (s6a)
{
extern int _s6a;
d_trace_level(&_s6a, s6a);
extern int _s6a_init;
d_trace_level(&_s6a_init, s6a);
}
return CORE_OK;
}
status_t hss_db_init()
{
if (context_self()->db_client && context_self()->db_name)

View File

@ -62,6 +62,7 @@ CORE_DECLARE(status_t) hss_context_final(void);
CORE_DECLARE(hss_context_t*) hss_self(void);
CORE_DECLARE(status_t) hss_context_parse_config(void);
CORE_DECLARE(status_t) hss_context_setup_trace_module(void);
CORE_DECLARE(status_t) hss_db_init(void);
CORE_DECLARE(status_t) hss_db_final(void);

View File

@ -13,6 +13,9 @@ status_t hss_initialize(void)
rv = hss_context_parse_config();
if (rv != CORE_OK) return rv;
rv = hss_context_setup_trace_module();
if (rv != CORE_OK) return rv;
rv = hss_db_init();
if (rv != CORE_OK) return rv;

View File

@ -1,4 +1,4 @@
#define TRACE_MODULE _bearer_sm
#define TRACE_MODULE _esm_sm
#include "core_debug.h"

View File

@ -765,6 +765,76 @@ status_t mme_context_parse_config()
return CORE_OK;
}
status_t mme_context_setup_trace_module()
{
int context = context_self()->trace_level.context;
int sm = context_self()->trace_level.sm;
int s1ap = context_self()->trace_level.s1ap;
int s6a = context_self()->trace_level.s6a;
int gtp = context_self()->trace_level.gtp;
if (context)
{
extern int _context;
d_trace_level(&_context, context);
extern int _mme_context;
d_trace_level(&_mme_context, context);
}
if (sm)
{
extern int _mme_sm;
d_trace_level(&_mme_sm, sm);
extern int _s1ap_sm;
d_trace_level(&_s1ap_sm, sm);
extern int _emm_sm;
d_trace_level(&_emm_sm, sm);
extern int _esm_sm;
d_trace_level(&_esm_sm, sm);
extern int _s1ap_handler;
d_trace_level(&_s1ap_handler, sm);
extern int _emm_handler;
d_trace_level(&_emm_handler, sm);
extern int _esm_handler;
d_trace_level(&_esm_handler, sm);
extern int _mme_s11_handler;
d_trace_level(&_mme_s11_handler, sm);
extern int _mme_s6a_handler;
d_trace_level(&_mme_s6a_handler, sm);
}
if (s1ap)
{
extern int _s1ap_path;
d_trace_level(&_s1ap_path, s1ap);
extern int _s1ap_recv;
d_trace_level(&_s1ap_recv, s1ap);
extern int _s1ap_send;
d_trace_level(&_s1ap_send, s1ap);
}
if (s6a)
{
extern int _s6a;
d_trace_level(&_s6a, s6a);
extern int _s6a_init;
d_trace_level(&_s6a_init, s6a);
}
if (gtp)
{
extern int _gtp_path;
d_trace_level(&_gtp_path, gtp);
extern int _mme_s11_path;
d_trace_level(&_mme_s11_path, gtp);
extern int _tlv_msg;
d_trace_level(&_tlv_msg, gtp);
extern int _gtp_xact;
d_trace_level(&_gtp_xact, gtp);
}
return CORE_OK;
}
mme_sgw_t* mme_sgw_add()
{
mme_sgw_t *sgw = NULL;

View File

@ -278,6 +278,7 @@ CORE_DECLARE(status_t) mme_context_final(void);
CORE_DECLARE(mme_context_t*) mme_self(void);
CORE_DECLARE(status_t) mme_context_parse_config(void);
CORE_DECLARE(status_t) mme_context_setup_trace_module(void);
CORE_DECLARE(mme_sgw_t*) mme_sgw_add(void);
CORE_DECLARE(status_t) mme_sgw_remove(mme_sgw_t *sgw);

View File

@ -21,6 +21,9 @@ status_t mme_initialize()
rv = mme_context_parse_config();
if (rv != CORE_OK) return rv;
rv = mme_context_setup_trace_module();
if (rv != CORE_OK) return rv;
ret = mme_s6a_init();
if (ret != 0) return -1;

View File

@ -34,9 +34,9 @@ static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
d_assert(sgw, return -1, "Can't find SGW from [%s:%d]",
INET_NTOP(&gnode.addr, buf), gnode.port);
d_trace(1, "S11_PDU is received from SGW[%s:%d]\n",
d_trace(10, "S11_PDU is received from SGW[%s:%d]\n",
INET_NTOP(&gnode.addr, buf), gnode.port);
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace_hex(10, pkbuf->payload, pkbuf->len);
event_set(&e, MME_EVT_S11_UE_MSG);
event_set_param1(&e, (c_uintptr_t)sock);

View File

@ -126,11 +126,11 @@ out:
/* Display how long it took */
if (ts.tv_nsec > mi->ts.tv_nsec)
d_trace(1, "in %d.%06ld sec\n",
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(1, "in %d.%06ld sec\n",
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);
@ -451,11 +451,11 @@ out:
/* Display how long it took */
if (ts.tv_nsec > mi->ts.tv_nsec)
d_trace(1, "in %d.%06ld sec\n",
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(1, "in %d.%06ld sec\n",
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);

View File

@ -88,8 +88,8 @@ static status_t s1ap_recv(net_sock_t *sock, pkbuf_t *pkbuf)
d_assert(sock, return CORE_ERROR, "Null param");
d_assert(pkbuf, return CORE_ERROR, "Null param");
d_trace(1, "S1AP_PDU is received from eNB-Inf\n");
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace(10, "S1AP_PDU is received from eNB-Inf\n");
d_trace_hex(10, pkbuf->payload, pkbuf->len);
event_set(&e, MME_EVT_S1AP_ENB_MSG);
event_set_param1(&e, (c_uintptr_t)sock->app_index);
@ -168,10 +168,10 @@ status_t s1ap_send(net_sock_t *s, pkbuf_t *pkbuf)
d_assert(pkbuf, return CORE_ERROR, "Null param");
sent = net_send(s, pkbuf->payload, pkbuf->len);
d_trace(1,"Sent %d->%d bytes to [%s:%d]\n",
d_trace(10,"Sent %d->%d bytes to [%s:%d]\n",
pkbuf->len, sent, INET_NTOP(&s->remote.sin_addr.s_addr, buf),
ntohs(s->remote.sin_port));
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace_hex(10, pkbuf->payload, pkbuf->len);
if (sent < 0 || sent != pkbuf->len)
{
d_error("net_send error (%d:%s)",

View File

@ -41,6 +41,37 @@ status_t pgw_context_init()
return CORE_OK;
}
status_t pgw_context_final()
{
d_assert(context_initiaized == 1, return CORE_ERROR,
"PGW context already has been finalized");
gtp_xact_delete_all(&self.s5c_node);
pgw_sess_remove_all();
d_print("%d not freed in pgw_sess_pool[%d] in PGW-Context\n",
index_size(&pgw_sess_pool) - pool_avail(&pgw_sess_pool),
index_size(&pgw_sess_pool));
d_print("%d not freed in pgw_ip_pool[%d] in PGW-Context\n",
index_size(&pgw_ip_pool_pool) - pool_avail(&pgw_ip_pool_pool),
index_size(&pgw_ip_pool_pool));
pool_final(&pgw_ip_pool_pool);
pool_final(&pgw_pdn_pool);
index_final(&pgw_bearer_pool);
index_final(&pgw_sess_pool);
context_initiaized = 0;
return CORE_OK;
}
pgw_context_t* pgw_self()
{
return &self;
}
static status_t pgw_context_prepare()
{
self.s5c_port = GTPV2_C_UDP_PORT;
@ -366,37 +397,43 @@ status_t pgw_context_parse_config()
return CORE_OK;
}
status_t pgw_context_final()
status_t pgw_context_setup_trace_module()
{
d_assert(context_initiaized == 1, return CORE_ERROR,
"PGW context already has been finalized");
int context = context_self()->trace_level.context;
int sm = context_self()->trace_level.sm;
int gtp = context_self()->trace_level.gtp;
gtp_xact_delete_all(&self.s5c_node);
pgw_sess_remove_all();
if (context)
{
extern int _context;
d_trace_level(&_context, context);
extern int _pgw_context;
d_trace_level(&_pgw_context, context);
}
d_print("%d not freed in pgw_sess_pool[%d] in PGW-Context\n",
index_size(&pgw_sess_pool) - pool_avail(&pgw_sess_pool),
index_size(&pgw_sess_pool));
d_print("%d not freed in pgw_ip_pool[%d] in PGW-Context\n",
index_size(&pgw_ip_pool_pool) - pool_avail(&pgw_ip_pool_pool),
index_size(&pgw_ip_pool_pool));
if (sm)
{
extern int _pgw_sm;
d_trace_level(&_pgw_sm, sm);
extern int _pgw_handler;
d_trace_level(&_pgw_handler, sm);
}
pool_final(&pgw_ip_pool_pool);
pool_final(&pgw_pdn_pool);
if (gtp)
{
extern int _gtp_path;
d_trace_level(&_gtp_path, gtp);
extern int _pgw_path;
d_trace_level(&_pgw_path, gtp);
extern int _tlv_msg;
d_trace_level(&_tlv_msg, gtp);
extern int _gtp_xact;
d_trace_level(&_gtp_xact, gtp);
}
index_final(&pgw_bearer_pool);
index_final(&pgw_sess_pool);
context_initiaized = 0;
return CORE_OK;
}
pgw_context_t* pgw_self()
{
return &self;
}
pgw_bearer_t *pgw_sess_add(c_uint8_t id)
{
pgw_sess_t *sess = NULL;

View File

@ -89,11 +89,12 @@ typedef struct _pgw_ip_pool_t {
} pgw_ip_pool_t;
CORE_DECLARE(status_t) pgw_context_init(void);
CORE_DECLARE(status_t) pgw_context_parse_config(void);
CORE_DECLARE(status_t) pgw_context_final(void);
CORE_DECLARE(pgw_context_t*) pgw_self(void);
CORE_DECLARE(status_t) pgw_context_parse_config(void);
CORE_DECLARE(status_t) pgw_context_setup_trace_module(void);
CORE_DECLARE(pgw_bearer_t*) pgw_sess_add(c_uint8_t id);
CORE_DECLARE(status_t ) pgw_sess_remove(pgw_sess_t *sess);
CORE_DECLARE(status_t ) pgw_sess_remove_all();

View File

@ -19,6 +19,9 @@ status_t pgw_initialize()
rv = pgw_context_parse_config();
if (rv != CORE_OK) return rv;
rv = pgw_context_setup_trace_module();
if (rv != CORE_OK) return rv;
rv = pgw_ip_pool_generate();
if (rv != CORE_OK) return rv;

View File

@ -29,8 +29,8 @@ static int _gtpv1_tun_recv_cb(net_link_t *net_link, void *data)
recvbuf->len = n;
d_trace(1, "PDU received from TunTap\n");
d_trace_hex(1, recvbuf->payload, recvbuf->len);
d_trace(50, "PDU received from TunTap\n");
d_trace_hex(50, recvbuf->payload, recvbuf->len);
/* Find the bearer by packet filter */
bearer = pgw_bearer_find_by_packet(recvbuf);
@ -64,7 +64,7 @@ static int _gtpv1_tun_recv_cb(net_link_t *net_link, void *data)
/* Send to SGW */
gnode.addr = bearer->sgw_s5u_addr;
gnode.port = GTPV1_U_UDP_PORT;
d_trace(1, "Send S5U PDU (teid = 0x%x)to SGW(%s)\n",
d_trace(50, "Send S5U PDU (teid = 0x%x)to SGW(%s)\n",
bearer->sgw_s5u_teid,
INET_NTOP(&gnode.addr, buf));
@ -99,8 +99,8 @@ static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
return -1;
}
d_trace(1, "S5-C PDU received from PGW\n");
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace(10, "S5-C PDU received from PGW\n");
d_trace_hex(10, pkbuf->payload, pkbuf->len);
event_set(&e, PGW_EVT_S5C_SESSION_MSG);
event_set_param1(&e, (c_uintptr_t)sock);
@ -133,8 +133,8 @@ static int _gtpv1_u_recv_cb(net_sock_t *sock, void *data)
return -1;
}
d_trace(1, "S5-U PDU received from SGW\n");
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace(50, "S5-U PDU received from SGW\n");
d_trace_hex(50, pkbuf->payload, pkbuf->len);
/* Remove GTP header and send packets to TUN interface */
if (pkbuf_header(pkbuf, -size) != CORE_OK)

View File

@ -40,6 +40,32 @@ status_t sgw_context_init()
return CORE_OK;
}
status_t sgw_context_final()
{
d_assert(context_initialized == 1, return CORE_ERROR,
"SGW context already has been finalized");
gtp_xact_delete_all(&self.s11_node);
gtp_xact_delete_all(&self.s5c_node);
sgw_sess_remove_all();
d_print("%d not freed in sgw_sess_pool[%d] in SGW-Context\n",
index_size(&sgw_sess_pool) - pool_avail(&sgw_sess_pool),
index_size(&sgw_sess_pool));
index_final(&sgw_bearer_pool);
index_final(&sgw_sess_pool);
context_initialized = 0;
return CORE_OK;
}
sgw_context_t* sgw_self()
{
return &self;
}
static status_t sgw_context_prepare()
{
self.s11_port = GTPV2_C_UDP_PORT;
@ -363,32 +389,43 @@ status_t sgw_context_parse_config()
return CORE_OK;
}
status_t sgw_context_final()
status_t sgw_context_setup_trace_module()
{
d_assert(context_initialized == 1, return CORE_ERROR,
"SGW context already has been finalized");
int context = context_self()->trace_level.context;
int sm = context_self()->trace_level.sm;
int gtp = context_self()->trace_level.gtp;
gtp_xact_delete_all(&self.s11_node);
gtp_xact_delete_all(&self.s5c_node);
if (context)
{
extern int _context;
d_trace_level(&_context, context);
extern int _sgw_context;
d_trace_level(&_sgw_context, context);
}
sgw_sess_remove_all();
if (sm)
{
extern int _sgw_sm;
d_trace_level(&_sgw_sm, sm);
extern int _sgw_handler;
d_trace_level(&_sgw_handler, sm);
}
d_print("%d not freed in sgw_sess_pool[%d] in SGW-Context\n",
index_size(&sgw_sess_pool) - pool_avail(&sgw_sess_pool),
index_size(&sgw_sess_pool));
index_final(&sgw_bearer_pool);
index_final(&sgw_sess_pool);
if (gtp)
{
extern int _gtp_path;
d_trace_level(&_gtp_path, gtp);
extern int _sgw_path;
d_trace_level(&_sgw_path, gtp);
extern int _tlv_msg;
d_trace_level(&_tlv_msg, gtp);
extern int _gtp_xact;
d_trace_level(&_gtp_xact, gtp);
}
context_initialized = 0;
return CORE_OK;
}
sgw_context_t* sgw_self()
{
return &self;
}
sgw_bearer_t *sgw_sess_add(c_uint8_t id)
{
sgw_sess_t *sess = NULL;

View File

@ -90,11 +90,12 @@ typedef struct _sgw_bearer_t {
} sgw_bearer_t;
CORE_DECLARE(status_t) sgw_context_init(void);
CORE_DECLARE(status_t) sgw_context_parse_config(void);
CORE_DECLARE(status_t) sgw_context_final(void);
CORE_DECLARE(sgw_context_t*) sgw_self(void);
CORE_DECLARE(status_t) sgw_context_parse_config(void);
CORE_DECLARE(status_t) sgw_context_setup_trace_module(void);
CORE_DECLARE(sgw_bearer_t*) sgw_sess_add(c_uint8_t id);
CORE_DECLARE(status_t ) sgw_sess_remove(sgw_sess_t *sess);
CORE_DECLARE(status_t ) sgw_sess_remove_all();

View File

@ -19,6 +19,9 @@ status_t sgw_initialize()
rv = sgw_context_parse_config();
if (rv != CORE_OK) return rv;
rv = sgw_context_setup_trace_module();
if (rv != CORE_OK) return rv;
rv = thread_create(&sgw_sm_thread, NULL, sgw_sm_main, NULL);
if (rv != CORE_OK) return rv;

View File

@ -31,18 +31,18 @@ static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
if (GTP_COMPARE_NODE(gnode, &sgw_self()->s11_node))
{
d_trace(1, "S11 PDU received from MME\n");
d_trace(10, "S11 PDU received from MME\n");
event_set(&e, SGW_EVT_S11_SESSION_MSG);
}
else if (GTP_COMPARE_NODE(gnode, &sgw_self()->s5c_node))
{
d_trace(1, "S5-C PDU received from PGW\n");
d_trace(10, "S5-C PDU received from PGW\n");
event_set(&e, SGW_EVT_S5C_SESSION_MSG);
}
else
d_assert(0, pkbuf_free(pkbuf); return -1, "Unknown GTP-Node");
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace_hex(10, pkbuf->payload, pkbuf->len);
event_set_param1(&e, (c_uintptr_t)sock);
event_set_param2(&e, (c_uintptr_t)gnode);
@ -77,20 +77,20 @@ static int _gtpv1_s5u_recv_cb(net_sock_t *sock, void *data)
return -1;
}
d_trace(1, "S5-U PDU received from PGW\n");
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace(50, "S5-U PDU received from PGW\n");
d_trace_hex(50, pkbuf->payload, pkbuf->len);
gtp_h = (gtp_header_t *)pkbuf->payload;
if (gtp_h->type == GTPU_MSGTYPE_ECHO_REQ)
{
pkbuf_t *echo_rsp;
d_trace(1,"Received echo-req");
d_trace(3, "Received echo-req");
echo_rsp = gtp_handle_echo_req(pkbuf);
if (echo_rsp)
{
/* Echo reply */
d_trace(1,"Send echo-rsp to peer(PGW) ");
d_trace(3, "Send echo-rsp to peer(PGW) ");
gnode.addr = sock->remote.sin_addr.s_addr;
gnode.port = GTPV1_U_UDP_PORT;
@ -103,7 +103,7 @@ static int _gtpv1_s5u_recv_cb(net_sock_t *sock, void *data)
{
teid = ntohl(gtp_h->teid);
d_trace(1,"Recv GPDU (teid = 0x%x)",teid);
d_trace(50, "Recv GPDU (teid = 0x%x)",teid);
bearer = sgw_bearer_find_by_sgw_s5u_teid(teid);
if (bearer)
@ -141,20 +141,20 @@ static int _gtpv1_s1u_recv_cb(net_sock_t *sock, void *data)
return -1;
}
d_trace(1, "S1-U PDU received from ENB\n");
d_trace_hex(1, pkbuf->payload, pkbuf->len);
d_trace(50, "S1-U PDU received from ENB\n");
d_trace_hex(50, pkbuf->payload, pkbuf->len);
gtp_h = (gtp_header_t *)pkbuf->payload;
if (gtp_h->type == GTPU_MSGTYPE_ECHO_REQ)
{
pkbuf_t *echo_rsp;
d_trace(1,"Received echo-req\n");
d_trace(3, "Received echo-req\n");
echo_rsp = gtp_handle_echo_req(pkbuf);
if (echo_rsp)
{
/* Echo reply */
d_trace(1,"Send echo-rsp to peer(ENB)\n");
d_trace(3, "Send echo-rsp to peer(ENB)\n");
gnode.addr = sock->remote.sin_addr.s_addr;
gnode.port = GTPV1_U_UDP_PORT;
@ -166,7 +166,7 @@ static int _gtpv1_s1u_recv_cb(net_sock_t *sock, void *data)
else if (gtp_h->type == GTPU_MSGTYPE_GPDU)
{
teid = ntohl(gtp_h->teid);
d_trace(1,"Recv GPDU (teid = 0x%x) from ENB\n",teid);
d_trace(50, "Recv GPDU (teid = 0x%x) from ENB\n",teid);
bearer = sgw_bearer_find_by_sgw_s1u_teid(teid);
if (bearer)

View File

@ -1,6 +1,15 @@
{
DB_URI : "mongodb://localhost/nextepc",
LOG_PATH : "@prefix@/var/log/nextepc.log",
TRACE:
{
CONTEXT: 1,
SM: 1,
S1AP: 1,
NAS: 1,
S6A: 1,
GTP: 1,
}
HSS :
{

View File

@ -17,6 +17,8 @@
#include "abts.h"
#include "abts_tests.h"
#include "testutil.h"
#include "core_debug.h"
#include "core_pkbuf.h"
#define ABTS_STAT_SIZE 6
@ -427,6 +429,7 @@ int main(int argc, const char *const argv[]) {
int list_provided = 0;
abts_suite *suite = NULL;
d_trace_global_off();
test_initialize();
quiet = !isatty(STDOUT_FILENO);
@ -448,6 +451,10 @@ int main(int argc, const char *const argv[]) {
quiet = 1;
continue;
}
if (!strcmp(argv[i], "-t")) {
d_trace_global_on();
continue;
}
if (argv[i][0] == '-') {
fprintf(stderr, "Invalid option: `%s'\n", argv[i]);
exit(1);