modified version of message chart generator (msc), now events are stored in a contention-free and concurency-free collection (lfds611), resulting in a uniq dump file per executable.

MSC is using an ITTI timer (bad dependancy for executables that are not yet "ITTIzed").


git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7620 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
gauthier
2015-06-23 09:04:17 +00:00
parent 738aadeb75
commit 014010e52d
48 changed files with 709 additions and 613 deletions
+1 -1
View File
@@ -880,7 +880,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
ret = lfds611_queue_new(&itti_desc.tasks[task_id].message_queue, itti_desc.tasks_info[task_id].queue_size);
if (ret < 0) {
if (0 == ret) {
AssertFatal (0, "lfds611_queue_new failed for task %s!\n", itti_get_task_name(task_id));
}
}
+2 -1
View File
@@ -93,7 +93,8 @@ int timer_handle_signal(siginfo_t *info)
/* Get back pointer to timer list element */
timer_p = (struct timer_elm_s *)info->si_ptr;
TMR_DEBUG("Timer with id 0x%lx has expired\n", (long)timer_p->timer);
// LG: To many traces for msc timer:
// TMR_DEBUG("Timer with id 0x%lx has expired\n", (long)timer_p->timer);
task_id = timer_p->task_id;
instance = timer_p->instance;
+457 -437
View File
@@ -27,7 +27,7 @@
*******************************************************************************/
/*! \file msc.c
* \brief Message chart generator logging utility (generated files to processed by a scrip to produce a mscgen input file for generating a sequence diagram document)
* \brief Message chart generator logging utility (generated files to processed by a script to produce a mscgen input file for generating a sequence diagram document)
* \author Lionel GAUTHIER
* \date 2015
* \email: lionel.gauthier@eurecom.fr
@@ -38,296 +38,358 @@
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include "liblfds611.h"
#include "intertask_interface.h"
#include "timer.h"
#include "msc.h"
#include "assertions.h"
//-------------------------------
#define MSC_MAX_QUEUE_ELEMENTS 1024
#define MSC_MAX_PROTO_NAME_LENGTH 16
#define MSC_MAX_MESSAGE_LENGTH 512
//-------------------------------
FILE* msc_fd[MAX_MSC_PROTOS]; // may need to split in more files to avoid overwrites (want to avoid mutexes)
char msc_proto2str[MAX_MSC_PROTOS][MSC_MAX_PROTO_NAME_LENGTH];
uint64_t msc_event_counter = 0;
FILE* g_msc_fd;
char g_msc_proto2str[MAX_MSC_PROTOS][MSC_MAX_PROTO_NAME_LENGTH];
typedef unsigned long msc_message_number_t;
typedef struct msc_queue_item_s {
char *message_str;
uint32_t message_str_size;
uint8_t *message_bin;
uint32_t message_bin_size;
} msc_queue_item_t;
msc_message_number_t g_message_number = 0;
struct lfds611_queue_state *g_msc_message_queue_p;
struct lfds611_stack_state *g_msc_memory_stack_p;
//------------------------------------------------------------------------------
int msc_init(msc_env_t envP)
void *msc_task(void *args_p)
//------------------------------------------------------------------------------
{
int i;
int rv;
MessageDef *received_message_p = NULL;
const char *msg_name = NULL;
instance_t instance = 0;
long timer_id;
itti_mark_task_ready(TASK_MSC);
msc_start_use();
timer_setup(0, // seconds
50000, // usec
TASK_MSC,
INSTANCE_DEFAULT,
TIMER_PERIODIC,
NULL,
&timer_id);
while(1) {
itti_receive_msg(TASK_MSC, &received_message_p);
if (received_message_p != NULL) {
msg_name = ITTI_MSG_NAME (received_message_p);
instance = ITTI_MSG_INSTANCE (received_message_p);
switch (ITTI_MSG_ID(received_message_p)) {
case TIMER_HAS_EXPIRED: {
msc_flush_messages();
}
break;
case TERMINATE_MESSAGE: {
timer_remove(timer_id);
msc_end();
itti_exit_task();
}
break;
case MESSAGE_TEST: {
}
break;
default: {
}
break;
}
}
}
fprintf(stderr, "Task MSC exiting\n");
return NULL;
}
//------------------------------------------------------------------------------
int msc_init(const msc_env_t envP, const int max_threadsP)
//------------------------------------------------------------------------------
{
int i;
int rv;
void *pointer_p;
char msc_filename[256];
fprintf(stderr, "Initializing MSC logs\n");
rv = snprintf(msc_filename, 256, "/tmp/openair.msc.%u.log", envP); // TODO NAME
if ((0 >= rv) || (256 < rv)){
fprintf(stderr, "Error in MSC log file name");
}
g_msc_fd = fopen(msc_filename,"w");
AssertFatal(g_msc_fd != NULL, "Could not open MSC log file %s : %s", msc_filename, strerror(errno));
rv = lfds611_stack_new(&g_msc_memory_stack_p, (lfds611_atom_t)max_threadsP + 2);
if (0 >= rv) {
AssertFatal (0, "lfds611_stack_new failed!\n");
}
rv = lfds611_queue_new(&g_msc_message_queue_p, (lfds611_atom_t)MSC_MAX_QUEUE_ELEMENTS);
AssertFatal (rv, "lfds611_queue_new failed!\n");
msc_start_use();
for (i=0; i < max_threadsP * 30; i++) {
pointer_p = malloc(MSC_MAX_MESSAGE_LENGTH);
AssertFatal (pointer_p, "malloc failed!\n");
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, pointer_p );
AssertFatal (rv, "lfds611_stack_guaranteed_push failed for item %u\n", i);
}
for (i = MIN_MSC_PROTOS; i < MAX_MSC_PROTOS; i++) {
msc_fd[i] = NULL;
switch (i) {
switch (i) {
case MSC_IP_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.ip_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.ip_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_IP_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "IP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (envP == MSC_E_UTRAN_LIPA) {
msc_fd[i] = fopen("/tmp/openair.msc.ip_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.ip_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_NAS_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.nas_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.nas_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_RRC_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.rrc_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.rrc_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_PDCP_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.pdcp_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.pdcp_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_RLC_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.rlc_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.rlc_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_MAC_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.mac_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.mac_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_PHY_UE:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.phy_ue.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.phy_ue.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_PHY_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.phy_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.phy_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_MAC_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.mac_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.mac_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_RLC_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.rlc_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.rlc_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_PDCP_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.pdcp_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.pdcp_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_RRC_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.rrc_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.rrc_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_S1AP_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_EPC) || (envP == MSC_MME)) {
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.s1ap_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.s1ap_enb.log : %s", strerror(errno));
} else {
msc_fd[i] = fopen("/tmp/openair.msc.s1ap_enb.epc.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.s1ap_enb.epc.log : %s", strerror(errno));
}
msc_log_declare_proto(i);
}
break;
case MSC_GTPU_ENB:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.gtpu_enb.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.gtpu_enb.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_GTPU_SGW:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_SGW");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.gtpu_sgw.utran.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.gtpu_sgw.utran.log : %s", strerror(errno));
} else {
msc_fd[i] = fopen("/tmp/openair.msc.gtpu_sgw.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.gtpu_sgw.log : %s", strerror(errno));
}
msc_log_declare_proto(i);
}
break;
case MSC_S1AP_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_MME) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.s1ap_mme.utran.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.s1ap_mme.utran.log : %s", strerror(errno));
} else {
msc_fd[i] = fopen("/tmp/openair.msc.s1ap_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.s1ap_mme.log : %s", strerror(errno));
}
msc_log_declare_proto(i);
}
break;
case MSC_MMEAPP_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MME_APP");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_MME)) {
msc_fd[i] = fopen("/tmp/openair.msc.mme_app.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.mme_app.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_NAS_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_fd[i] = fopen("/tmp/openair.msc.nas_mme.utran.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.nas_mme.utran.log : %s", strerror(errno));
} else {
msc_fd[i] = fopen("/tmp/openair.msc.nas_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.nas_mme.log : %s", strerror(errno));
}
case MSC_RRC_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
break;
case MSC_NAS_EMM_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_EMM");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_MME)) {
msc_fd[i] = fopen("/tmp/openair.msc.nas_emm_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.nas_emm_mme.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_NAS_ESM_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_ESM");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_MME)) {
msc_fd[i] = fopen("/tmp/openair.msc.nas_esm_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.nas_esm_mme.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_SP_GWAPP_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "SP_GW_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (envP == MSC_EPC) {
msc_fd[i] = fopen("/tmp/openair.msc.spgwapp_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.spgwapp_mme.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_S11_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S11_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (envP == MSC_MME) {
msc_fd[i] = fopen("/tmp/openair.msc.s11_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.s11_mme.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_S6A_MME:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S6A");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_MME)) {
msc_fd[i] = fopen("/tmp/openair.msc.s6a_mme.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.s6a_mme.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
case MSC_HSS:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "HSS");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_EPC) || (envP == MSC_MME)) {
msc_fd[i] = fopen("/tmp/openair.msc.hss.log","w");
if (msc_fd[i] == NULL) fprintf(stderr, "Could not open MSC log file /tmp/openair.msc.hss.log : %s", strerror(errno));
msc_log_declare_proto(i);
}
break;
default:
rv = snprintf(&msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "UNKNOWN");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
msc_fd[i] = NULL;
}
}
break;
case MSC_PDCP_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RLC_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_MAC_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PHY_UE:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_UE");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PHY_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PHY_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_MAC_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MAC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RLC_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RLC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_PDCP_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "PDCP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_RRC_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "RRC_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_S1AP_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_GTPU_ENB:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_ENB");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_GTPU_SGW:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "GTPU_SGW");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_S1AP_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S1AP_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_MME) || (envP == MSC_E_UTRAN) || (envP == MSC_E_UTRAN_LIPA)) {
msc_log_declare_proto(i);
}
break;
case MSC_MMEAPP_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "MME_APP");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_NAS_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
msc_log_declare_proto(i);
break;
case MSC_NAS_EMM_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_EMM");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_NAS_ESM_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "NAS_ESM");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_SP_GWAPP_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "SP_GW_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (envP == MSC_MME_GW) {
msc_log_declare_proto(i);
}
break;
case MSC_S11_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S11_MME");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if (envP == MSC_MME) {
msc_log_declare_proto(i);
}
break;
case MSC_S6A_MME:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "S6A");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
case MSC_HSS:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "HSS");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
if ((envP == MSC_MME_GW) || (envP == MSC_MME)) {
msc_log_declare_proto(i);
}
break;
default:
rv = snprintf(&g_msc_proto2str[i][0], MSC_MAX_PROTO_NAME_LENGTH, "UNKNOWN");
if (rv >= MSC_MAX_PROTO_NAME_LENGTH) {g_msc_proto2str[i][MSC_MAX_PROTO_NAME_LENGTH-1] = 0;}
}
}
rv = itti_create_task (TASK_MSC, msc_task, NULL);
AssertFatal (rv == 0, "Create task for MSC failed!\n");
fprintf(stderr, "Initializing MSC logs Done\n");
return 0;
}
//------------------------------------------------------------------------------
void msc_start_use(void)
//------------------------------------------------------------------------------
{
lfds611_queue_use(g_msc_message_queue_p);
lfds611_stack_use(g_msc_memory_stack_p);
}
//------------------------------------------------------------------------------
void msc_flush_messages(void)
//------------------------------------------------------------------------------
{
int rv;
msc_queue_item_t *item_p = NULL;
while ((rv = lfds611_queue_dequeue( g_msc_message_queue_p, &item_p )) == 1) {
if (NULL != item_p->message_str) {
fputs(item_p->message_str, g_msc_fd);
// TODO BIN DATA
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, item_p->message_str );
}
// TODO FREE BIN DATA
free(item_p);
}
fflush(g_msc_fd);
}
//------------------------------------------------------------------------------
void msc_end(void)
//------------------------------------------------------------------------------
{
int rv;
int i;
for (i = MIN_MSC_PROTOS; i < MAX_MSC_PROTOS; i++) {
if (msc_fd[i] != NULL) {
rv = fflush(msc_fd[i]);
if (rv != 0) {
fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
}
rv = fclose(msc_fd[i]);
if (rv != 0) {
fprintf(stderr, "Error while closing MSC log file: %s", strerror(errno));
}
}
if (NULL != g_msc_fd ) {
msc_flush_messages();
rv = fflush(g_msc_fd);
if (rv != 0) {
fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
}
rv = fclose(g_msc_fd);
if (rv != 0) {
fprintf(stderr, "Error while closing MSC log file: %s", strerror(errno));
}
}
}
@@ -337,20 +399,46 @@ void msc_log_declare_proto(
)
//------------------------------------------------------------------------------
{
int rv;
uint64_t local_msc_event_counter = msc_event_counter;
msc_event_counter++;
if ((protoP >= MIN_MSC_PROTOS) && (protoP < MAX_MSC_PROTOS)) {
if (msc_fd[protoP] != NULL) {
rv = fprintf(msc_fd[protoP], "%"PRIu64" [PROTO] %d %s\n", local_msc_event_counter, protoP, &msc_proto2str[protoP][0]);
if (rv < 0) {
fprintf(stderr, "Error while declaring new protocol in MSC log file: %s", strerror(errno));
}
rv = fflush(msc_fd[protoP]);
if (rv != 0) {
fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
}
}
int rv = 0;
msc_queue_item_t *new_item_p = NULL;
char *char_message_p = NULL;
if ((MIN_MSC_PROTOS <= protoP) && (MAX_MSC_PROTOS > protoP)) {
// may be build a memory pool for that also ?
new_item_p = malloc(sizeof(msc_queue_item_t));
if (NULL != new_item_p) {
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
if (0 == rv) {
msc_flush_messages();
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
}
if (1 == rv) {
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [PROTO] %d %s\n", __sync_fetch_and_add (&g_message_number, 1), protoP, &g_msc_proto2str[protoP][0]);
if (0 > rv) {
fprintf(stderr, "Error while declaring new protocol in MSC: %s", strerror(errno));
}
new_item_p->message_str = char_message_p;
new_item_p->message_str_size = rv;
new_item_p->message_bin = NULL;
new_item_p->message_bin_size = 0;
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
if (0 == rv) {
rv = lfds611_queue_guaranteed_enqueue(g_msc_message_queue_p, new_item_p );
if (0 == rv) {
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
free(new_item_p);
}
}
return;
} else {
fprintf(stderr, "Error while lfds611_stack_pop()\n");
}
free(new_item_p);
} else {
fprintf(stderr, "Error while malloc in MSC");
}
}
}
//------------------------------------------------------------------------------
@@ -359,202 +447,134 @@ void msc_log_event(
char *format, ...)
//------------------------------------------------------------------------------
{
va_list args;
int rv;
uint64_t local_msc_event_counter = msc_event_counter;
va_list args;
int rv;
int rv2;
msc_queue_item_t *new_item_p = NULL;
char *char_message_p = NULL;
msc_event_counter++;
if ((protoP < MIN_MSC_PROTOS) || (protoP >= MAX_MSC_PROTOS)) {
if ((MIN_MSC_PROTOS > protoP) || (MAX_MSC_PROTOS <= protoP)) {
return;
}
if (msc_fd[protoP] != NULL) {
rv = fprintf(msc_fd[protoP], "%"PRIu64" [EVENT] %d ", local_msc_event_counter, protoP);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC event : %s", &msc_proto2str[protoP][0]);
new_item_p = malloc(sizeof(msc_queue_item_t));
if (NULL != new_item_p) {
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
if (0 == rv) {
msc_flush_messages();
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
}
if (1 == rv) {
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [EVENT] %d ", __sync_fetch_and_add (&g_message_number, 1), protoP);
if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
goto error_event;
}
va_start(args, format);
rv = vfprintf(msc_fd[protoP], format, args);
rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, format, args);
va_end(args);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC event : %s", &msc_proto2str[protoP][0]);
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
goto error_event;
}
rv = fprintf(msc_fd[protoP], "\n");
if (rv < 0) {
fprintf(stderr, "Error while logging MSC event : %s", &msc_proto2str[protoP][0]);
rv += rv2;
rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC event : %s", &g_msc_proto2str[protoP][0]);
goto error_event;
}
#if 1
rv = fflush(msc_fd[protoP]);
if (rv != 0) {
fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
rv += rv2;
new_item_p->message_str = char_message_p;
new_item_p->message_str_size = rv;
new_item_p->message_bin = NULL;
new_item_p->message_bin_size = 0;
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
if (0 == rv) {
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
free(new_item_p);
}
#endif
} else {
fprintf(stderr, "Error while lfds611_stack_pop()\n");
}
}
return;
error_event:
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
free(new_item_p);
}
//------------------------------------------------------------------------------
void msc_log_rx_message(
const msc_proto_t receiverP,
const msc_proto_t senderP,
const char* bytesP,
void msc_log_message(
const char * const message_operationP,
const msc_proto_t proto1P,
const msc_proto_t proto2P,
const uint8_t * const bytesP,
const unsigned int num_bytes,
char *format, ...)
//------------------------------------------------------------------------------
{
va_list args;
int rv;
uint64_t mac = 0;
uint64_t local_msc_event_counter = msc_event_counter;
va_list args;
uint64_t mac = 0; // TO DO mac on bytesP param
int rv;
int rv2;
msc_queue_item_t *new_item_p = NULL;
char *char_message_p = NULL;
msc_event_counter++;
if ((receiverP < MIN_MSC_PROTOS) || (receiverP >= MAX_MSC_PROTOS) ||
(senderP < MIN_MSC_PROTOS) || (senderP >= MAX_MSC_PROTOS)) {
return;
if ((MIN_MSC_PROTOS > proto1P) || (MAX_MSC_PROTOS <= proto1P) ||
(MIN_MSC_PROTOS > proto2P) || (MAX_MSC_PROTOS <= proto2P) ) {
return;
}
if (msc_fd[receiverP] != NULL) {
rv = fprintf(msc_fd[receiverP], "%"PRIu64" [MESSAGE] %d <- %d %"PRIu64" ",
local_msc_event_counter, receiverP, senderP, mac);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC RX message : %s", &msc_proto2str[receiverP][0]);
new_item_p = malloc(sizeof(msc_queue_item_t));
if (NULL != new_item_p) {
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
if (0 == rv) {
msc_flush_messages();
rv = lfds611_stack_pop(g_msc_memory_stack_p, (void**)&char_message_p);
}
if (1 == rv) {
rv = snprintf(char_message_p, MSC_MAX_MESSAGE_LENGTH, "%"PRIu64" [MESSAGE] %d %s %d %"PRIu64" ",
__sync_fetch_and_add (&g_message_number, 1), proto1P, message_operationP, proto2P, mac);
if ((0 > rv) || (MSC_MAX_MESSAGE_LENGTH < rv)) {
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
goto error_event;
}
va_start(args, format);
rv = vfprintf(msc_fd[receiverP], format, args);
rv2 = vsnprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, format, args);
va_end(args);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC RX message : %s", &msc_proto2str[receiverP][0]);
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
goto error_event;
}
rv = fprintf(msc_fd[receiverP], "\n");
if (rv < 0) {
fprintf(stderr, "Error while logging MSC RX message : %s", &msc_proto2str[receiverP][0]);
}
if ((msc_event_counter & 0x000000000000000F) == 0x000000000000000F) {
fflush(msc_fd[receiverP]);
}
}
}
//------------------------------------------------------------------------------
void msc_log_rx_discarded_message(
const msc_proto_t receiverP,
const msc_proto_t senderP,
const char* bytesP,
const unsigned int num_bytes,
char *format, ...)
//------------------------------------------------------------------------------
{
va_list args;
int rv;
uint64_t mac = 0;
uint64_t local_msc_event_counter = msc_event_counter;
msc_event_counter++;
if ((receiverP < MIN_MSC_PROTOS) || (receiverP >= MAX_MSC_PROTOS) ||
(senderP < MIN_MSC_PROTOS) || (senderP >= MAX_MSC_PROTOS)) {
return;
}
if (msc_fd[receiverP] != NULL) {
rv = fprintf(msc_fd[receiverP], "%"PRIu64" [MESSAGE] %d x- %d %"PRIu64" ",
local_msc_event_counter, receiverP, senderP, mac);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC RX message : %s", &msc_proto2str[receiverP][0]);
}
va_start(args, format);
rv = vfprintf(msc_fd[receiverP], format, args);
va_end(args);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC RX message : %s", &msc_proto2str[receiverP][0]);
}
rv = fprintf(msc_fd[receiverP], "\n");
if (rv < 0) {
fprintf(stderr, "Error while logging MSC RX message : %s", &msc_proto2str[receiverP][0]);
}
if ((msc_event_counter & 0x000000000000000F) == 0x000000000000000F) {
fflush(msc_fd[receiverP]);
}
}
}
//------------------------------------------------------------------------------
void msc_log_tx_message(
const msc_proto_t senderP,
const msc_proto_t receiverP,
const char* bytesP,
const unsigned int num_bytes,
char *format, ...)
//------------------------------------------------------------------------------
{
va_list args;
int rv;
uint64_t mac = 0;
uint64_t local_msc_event_counter = msc_event_counter;
msc_event_counter++;
if ((receiverP < MIN_MSC_PROTOS) || (receiverP >= MAX_MSC_PROTOS) ||
(senderP < MIN_MSC_PROTOS) || (senderP >= MAX_MSC_PROTOS)) {
return;
}
if (msc_fd[senderP] != NULL) {
rv = fprintf(msc_fd[senderP], "%"PRIu64" [MESSAGE] %d -> %d %"PRIu64" ",
local_msc_event_counter, senderP, receiverP, mac);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC TX message : %s", &msc_proto2str[senderP][0]);
}
va_start(args, format);
rv = vfprintf(msc_fd[senderP], format, args);
va_end(args);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC TX message : %s", &msc_proto2str[senderP][0]);
}
rv = fprintf(msc_fd[senderP], "\n");
if (rv < 0) {
fprintf(stderr, "Error while logging MSC TX message : %s", &msc_proto2str[senderP][0]);
}
if ((msc_event_counter & 0x000000000000000F) == 0x000000000000000F) {
fflush(msc_fd[senderP]);
}
}
}
//------------------------------------------------------------------------------
void msc_log_tx_message_failed(
const msc_proto_t senderP,
const msc_proto_t receiverP,
const char* bytesP,
const unsigned int num_bytes,
char *format, ...)
//------------------------------------------------------------------------------
{
va_list args;
int rv;
uint64_t mac = 0;
uint64_t local_msc_event_counter = msc_event_counter;
msc_event_counter++;
if ((receiverP < MIN_MSC_PROTOS) || (receiverP >= MAX_MSC_PROTOS) ||
(senderP < MIN_MSC_PROTOS) || (senderP >= MAX_MSC_PROTOS)) {
return;
}
if (msc_fd[senderP] != NULL) {
rv = fprintf(msc_fd[senderP], "%"PRIu64" [MESSAGE] %d -x %d %"PRIu64" ",
local_msc_event_counter, senderP, receiverP, mac);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC TX message : %s", &msc_proto2str[senderP][0]);
}
va_start(args, format);
rv = vfprintf(msc_fd[senderP], format, args);
va_end(args);
if (rv < 0) {
fprintf(stderr, "Error while logging MSC TX message : %s", &msc_proto2str[senderP][0]);
}
rv = fprintf(msc_fd[senderP], "\n");
if (rv < 0) {
fprintf(stderr, "Error while logging MSC TX message : %s", &msc_proto2str[senderP][0]);
}
if ((msc_event_counter & 0x000000000000000F) == 0x000000000000000F) {
fflush(msc_fd[senderP]);
rv += rv2;
rv2 = snprintf(&char_message_p[rv],MSC_MAX_MESSAGE_LENGTH - rv, "\n");
if ((0 > rv2) || ((MSC_MAX_MESSAGE_LENGTH - rv) < rv2)) {
fprintf(stderr, "Error while logging MSC message : %s/%s", &g_msc_proto2str[proto1P][0], &g_msc_proto2str[proto2P][0]);
goto error_event;
}
rv += rv2;
new_item_p->message_str = char_message_p;
new_item_p->message_str_size = rv;
new_item_p->message_bin = NULL; // TO DO
new_item_p->message_bin_size = 0; // TO DO
rv = lfds611_queue_enqueue( g_msc_message_queue_p, new_item_p );
if (0 == rv) {
fprintf(stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
free(new_item_p);
}
} else {
fprintf(stderr, "Error while lfds611_stack_pop()\n");
msc_flush_messages();
}
}
return;
error_event:
rv = lfds611_stack_guaranteed_push( g_msc_memory_stack_p, char_message_p );
free(new_item_p);
}
+17 -29
View File
@@ -30,12 +30,13 @@
#ifndef MSC_H_
#define MSC_H_
#include <stdarg.h>
#include <stdint.h>
typedef enum {
MIN_MSC_ENV = 0,
MSC_E_UTRAN = MIN_MSC_ENV,
MSC_E_UTRAN_LIPA,
MSC_EPC,
MSC_MME_GW,
MSC_MME,
MSC_SP_GW,
MAX_MSC_ENV
@@ -81,44 +82,31 @@ typedef enum {
(CTXT_Pp)->frame, \
(CTXT_Pp)->subframe
#if defined(MESSAGE_CHART_GENERATOR)
int msc_init(msc_env_t envP);
int msc_init(const msc_env_t envP, const int max_threadsP);
void msc_start_use(void);
void msc_end(void);
void msc_log_declare_proto(const msc_proto_t protoP);
void msc_log_event(const msc_proto_t protoP,char *format, ...);
void msc_log_rx_message(
void msc_log_message(
const char * const message_operationP,
const msc_proto_t receiverP,
const msc_proto_t senderP,
const char* bytesP,
const uint8_t* const bytesP,
const unsigned int num_bytes,
char *format, ...);
void msc_log_rx_discarded_message(
const msc_proto_t receiverP,
const msc_proto_t senderP,
const char* bytesP,
const unsigned int num_bytes,
char *format, ...);
void msc_log_tx_message(
const msc_proto_t senderP,
const msc_proto_t receiverP,
const char* bytesP,
const unsigned int num_bytes,
char *format, ...);
void msc_log_tx_message_failed(
const msc_proto_t senderP,
const msc_proto_t receiverP,
const char* bytesP,
const unsigned int num_bytes,
char *format, ...);
#define MSC_INIT(mScPaRaMs) msc_init(mScPaRaMs)
#define MSC_INIT(arg1,arg2) msc_init(arg1,arg2)
#define MSC_START_USE msc_start_use
#define MSC_END msc_end
#define MSC_LOG_EVENT(mScPaRaMs, fORMAT, aRGS...) msc_log_event(mScPaRaMs, fORMAT, ##aRGS)
#define MSC_LOG_RX_MESSAGE(mScPaRaMs, fORMAT, aRGS...) msc_log_rx_message(mScPaRaMs, fORMAT, ##aRGS)
#define MSC_LOG_RX_DISCARDED_MESSAGE(mScPaRaMs, fORMAT, aRGS...) msc_log_rx_discarded_message(mScPaRaMs, fORMAT, ##aRGS)
#define MSC_LOG_TX_MESSAGE(mScPaRaMs, fORMAT, aRGS...) msc_log_tx_message(mScPaRaMs, fORMAT, ##aRGS)
#define MSC_LOG_TX_MESSAGE_FAILED(mScPaRaMs, fORMAT, aRGS...) msc_log_tx_message_failed(mScPaRaMs, fORMAT, ##aRGS)
#define MSC_LOG_RX_MESSAGE(rECEIVER, sENDER, bYTES, nUMbYTES, fORMAT, aRGS...) msc_log_message("<-",rECEIVER, sENDER, bYTES, nUMbYTES, fORMAT, ##aRGS)
#define MSC_LOG_RX_DISCARDED_MESSAGE(rECEIVER, sENDER, bYTES, nUMbYTES, fORMAT, aRGS...) msc_log_message("x-",rECEIVER, sENDER, bYTES, nUMbYTES, fORMAT, ##aRGS)
#define MSC_LOG_TX_MESSAGE(sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, aRGS...) msc_log_message("->",sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, ##aRGS)
#define MSC_LOG_TX_MESSAGE_FAILED(sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, aRGS...) msc_log_message("-x",sENDER, rECEIVER, bYTES, nUMbYTES, fORMAT, ##aRGS)
#else
#define MSC_INIT(mScPaRaMs)
#define MSC_END
#define MSC_INIT(arg1,arg2)
#define MSC_START_USE(mScPaRaMs)
#define MSC_END(mScPaRaMs)
#define MSC_LOG_EVENT(mScPaRaMs, fORMAT, aRGS...)
#define MSC_LOG_RX_MESSAGE(mScPaRaMs, fORMAT, aRGS...)
#define MSC_LOG_RX_DISCARDED_MESSAGE(mScPaRaMs, fORMAT, aRGS...)