From 74a53a0f129e7c39806305b0ad3a019d2ee355bb Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Wed, 6 May 2015 11:55:57 +0000
Subject: [PATCH] better handling of s1ap ue context release request, better
 mscgen logs

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7382 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/MME_APP/mme_app_bearer.c         |  60 ++++++-
 openair-cn/MME_APP/mme_app_context.c        |   2 +-
 openair-cn/MME_APP/mme_app_itti_messaging.h |   6 +-
 openair-cn/MME_APP/mme_app_main.c           |   5 +
 openair-cn/NAS/EURECOM-NAS/src/nas_proc.c   |  10 +-
 openair-cn/NAS/nas_itti_messaging.c         |   2 +-
 openair-cn/NAS/nas_itti_messaging.h         |   8 +-
 openair-cn/S1AP/s1ap_common.h               |   2 +
 openair-cn/S1AP/s1ap_mme.c                  |   8 +
 openair-cn/S1AP/s1ap_mme_handlers.c         | 174 +++++++++++++++++---
 openair-cn/S1AP/s1ap_mme_handlers.h         |   3 +
 openair-cn/S1AP/s1ap_mme_itti_messaging.c   |   4 +-
 openair-cn/S1AP/s1ap_mme_itti_messaging.h   |   7 +-
 openair-cn/S1AP/s1ap_mme_nas_procedures.c   |  34 ++--
 openair-cn/S1AP/s1ap_mme_retransmission.c   |   4 +-
 openair-cn/SGW-LITE/sgw_lite_handlers.c     |   4 +-
 openair-cn/SGW-LITE/sgw_lite_task.c         |  30 ++--
 openair-cn/SGW-LITE/spgw_config.c           |   4 +-
 targets/SCRIPTS/msc_gen.py                  |  48 ++++--
 19 files changed, 322 insertions(+), 93 deletions(-)

diff --git a/openair-cn/MME_APP/mme_app_bearer.c b/openair-cn/MME_APP/mme_app_bearer.c
index 5c027aa1a26..e28f40b0091 100644
--- a/openair-cn/MME_APP/mme_app_bearer.c
+++ b/openair-cn/MME_APP/mme_app_bearer.c
@@ -51,9 +51,11 @@
 #include "msc.h"
 
 
+//------------------------------------------------------------------------------
 int
 mme_app_send_s11_release_access_bearers_req(
   struct ue_context_s * const ue_context_pP)
+//------------------------------------------------------------------------------
 {
   uint8_t                     i                 = 0;
   task_id_t                   to_task           = TASK_UNKNOWN;
@@ -85,16 +87,19 @@ mme_app_send_s11_release_access_bearers_req(
   		(to_task == TASK_S11) ? MSC_S11_MME:MSC_SP_GWAPP_MME,
   		NULL,0,
   		"0 SGW_RELEASE_ACCESS_BEARERS_REQUEST teid %u ebi %u",
-  		SGW_RELEASE_ACCESS_BEARERS_REQUEST(message_p).teid,
+  		release_access_bearers_request_p->teid,
   		release_access_bearers_request_p->list_of_rabs[0]);
 
   itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
 }
 
 
+
+//------------------------------------------------------------------------------
 int
 mme_app_send_s11_create_session_req(
   struct ue_context_s * const ue_context_pP)
+//------------------------------------------------------------------------------
 {
   uint8_t                     i                 = 0;
   task_id_t                   to_task           = TASK_UNKNOWN;
@@ -266,9 +271,11 @@ mme_app_send_s11_create_session_req(
 
 
 
+//------------------------------------------------------------------------------
 int
 mme_app_handle_nas_pdn_connectivity_req(
   nas_pdn_connectivity_req_t * const nas_pdn_connectivity_req_pP)
+//------------------------------------------------------------------------------
 {
   struct ue_context_s *ue_context_p = NULL;
   uint64_t             imsi         = 0;
@@ -335,9 +342,11 @@ mme_app_handle_nas_pdn_connectivity_req(
 
 
 // sent by NAS
+//------------------------------------------------------------------------------
 void
 mme_app_handle_conn_est_cnf(
   const nas_conn_est_cnf_t * const nas_conn_est_cnf_pP)
+//------------------------------------------------------------------------------
 {
   struct ue_context_s                    *ue_context_p        = NULL;
   MessageDef                             *message_p           = NULL;
@@ -355,7 +364,7 @@ mme_app_handle_conn_est_cnf(
 	MSC_LOG_EVENT(
 	    		MSC_MMEAPP_MME,
 	    		"NAS_CONNECTION_ESTABLISHMENT_CNF Unknown ue %u",nas_conn_est_cnf_pP->UEid);
-	MME_APP_ERROR("UE context doesn't exist for UE 0x%08X/dec%u\n",
+	MME_APP_ERROR("UE context doesn't exist for UE %06"PRIX32"/dec%u\n",
                   nas_conn_est_cnf_pP->UEid,
                   nas_conn_est_cnf_pP->UEid);
     return;
@@ -427,9 +436,11 @@ mme_app_handle_conn_est_cnf(
 
 
 // sent by S1AP
+//------------------------------------------------------------------------------
 void
 mme_app_handle_conn_est_ind(
   const mme_app_connection_establishment_ind_t * const conn_est_ind_pP)
+//------------------------------------------------------------------------------
 {
   struct ue_context_s *ue_context_p  = NULL;
   MessageDef          *message_p     = NULL;
@@ -443,7 +454,7 @@ mme_app_handle_conn_est_ind(
 
 
   if (ue_context_p == NULL) {
-    MME_APP_DEBUG("We didn't find this mme_ue_s1ap_id in list of UE: 0x%08x/dec%u\n",
+    MME_APP_DEBUG("We didn't find this mme_ue_s1ap_id in list of UE: %06"PRIX32"/dec%u\n",
                   conn_est_ind_pP->mme_ue_s1ap_id,
                   conn_est_ind_pP->mme_ue_s1ap_id);
     MME_APP_DEBUG("UE context doesn't exist -> create one\n");
@@ -488,9 +499,11 @@ mme_app_handle_conn_est_ind(
 
 
 
+//------------------------------------------------------------------------------
 int
 mme_app_handle_create_sess_resp(
   const SgwCreateSessionResponse * const create_sess_resp_pP)
+//------------------------------------------------------------------------------
 {
   struct ue_context_s *ue_context_p     = NULL;
   bearer_context_t    *current_bearer_p = NULL;
@@ -763,9 +776,11 @@ mme_app_handle_create_sess_resp(
 
 
 
+//------------------------------------------------------------------------------
 void
 mme_app_handle_initial_context_setup_rsp(
   const mme_app_initial_context_setup_rsp_t * const initial_ctxt_setup_rsp_pP)
+//------------------------------------------------------------------------------
 {
   struct ue_context_s *ue_context_p  = NULL;
   MessageDef          *message_p     = NULL;
@@ -832,3 +847,42 @@ mme_app_handle_initial_context_setup_rsp(
   itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
 }
 
+
+
+//------------------------------------------------------------------------------
+void mme_app_handle_release_access_bearers_resp(
+		const SgwReleaseAccessBearersResponse * const rel_access_bearers_rsp_pP)
+//------------------------------------------------------------------------------
+{
+	  MessageDef          *message_p     = NULL;
+	  struct ue_context_s *ue_context_p  = NULL;
+
+	  ue_context_p = mme_ue_context_exists_s11_teid(&mme_app_desc.mme_ue_contexts,
+			  rel_access_bearers_rsp_pP->teid);
+
+
+	  if (ue_context_p == NULL) {
+	    MME_APP_DEBUG("We didn't find this teid in list of UE: %06"PRIX32"\n",
+	    		rel_access_bearers_rsp_pP->teid);
+	    return;
+	  }
+
+	  message_p = itti_alloc_new_message(TASK_MME_APP, S1AP_UE_CONTEXT_RELEASE_COMMAND);
+
+	  AssertFatal(message_p != NULL, "itti_alloc_new_message Failed");
+	  memset((void*)&message_p->ittiMsg.s1ap_ue_context_release_command,
+	         0,
+	         sizeof(s1ap_ue_context_release_command_t));
+
+	  S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).mme_ue_s1ap_id       = ue_context_p->mme_ue_s1ap_id;
+	  MSC_LOG_TX_MESSAGE(
+	  		MSC_MMEAPP_MME,
+	  		MSC_S1AP_MME,
+	  		NULL,0,
+	  		"0 S1AP_UE_CONTEXT_RELEASE_COMMAND mme_ue_s1ap_id %06"PRIX32" ",
+	  		S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).mme_ue_s1ap_id);
+
+
+	  itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
+}
+
diff --git a/openair-cn/MME_APP/mme_app_context.c b/openair-cn/MME_APP/mme_app_context.c
index 589710d45ab..9d555a47dde 100644
--- a/openair-cn/MME_APP/mme_app_context.c
+++ b/openair-cn/MME_APP/mme_app_context.c
@@ -462,7 +462,7 @@ void mme_app_handle_s1ap_ue_context_release_req(const s1ap_ue_context_release_re
 	MSC_LOG_EVENT(
    		MSC_MMEAPP_MME,
    		"S1AP_UE_CONTEXT_RELEASE_REQ Unknown ue %u",s1ap_ue_context_release_req->mme_ue_s1ap_id);
-    MME_APP_ERROR("UE context doesn't exist for UE 0x%08X/dec%u\n",
+    MME_APP_ERROR("UE context doesn't exist for UE 0x%06"PRIX32"/dec%u\n",
     		s1ap_ue_context_release_req->mme_ue_s1ap_id,
     		s1ap_ue_context_release_req->mme_ue_s1ap_id);
     return;
diff --git a/openair-cn/MME_APP/mme_app_itti_messaging.h b/openair-cn/MME_APP/mme_app_itti_messaging.h
index f4cbab06b27..3096a86bc45 100644
--- a/openair-cn/MME_APP/mme_app_itti_messaging.h
+++ b/openair-cn/MME_APP/mme_app_itti_messaging.h
@@ -39,7 +39,7 @@ mme_app_itti_auth_fail(
   MessageDef *message_p;
 
   MSC_LOG_TX_MESSAGE(MSC_MMEAPP_MME, MSC_NAS_MME,NULL,0,
-  		"NAS_AUTHENTICATION_PARAM_FAIL ue  %u cause %u",ue_id, cause);
+  		"NAS_AUTHENTICATION_PARAM_FAIL ue  %06"PRIX32" cause %u",ue_id, cause);
 
   message_p = itti_alloc_new_message(TASK_MME_APP, NAS_AUTHENTICATION_PARAM_FAIL);
 
@@ -50,7 +50,7 @@ mme_app_itti_auth_fail(
   		MSC_MMEAPP_MME,
   		MSC_NAS_MME,
   		NULL,0,
-  		"0 NAS_AUTHENTICATION_PARAM_FAIL ue_id %u cause %u",
+  		"0 NAS_AUTHENTICATION_PARAM_FAIL ue_id %06"PRIX32" cause %u",
   		ue_id, cause);
 
   itti_send_msg_to_task(TASK_NAS_MME, INSTANCE_DEFAULT, message_p);
@@ -75,7 +75,7 @@ static inline void mme_app_itti_auth_rsp(
   		MSC_MMEAPP_MME,
   		MSC_NAS_MME,
   		NULL,0,
-  		"0 NAS_AUTHENTICATION_PARAM_RSP ue_id %u nb_vectors %u",
+  		"0 NAS_AUTHENTICATION_PARAM_RSP ue_id %06"PRIX32" nb_vectors %u",
   		ue_id, nb_vectors);
   itti_send_msg_to_task(TASK_NAS_MME, INSTANCE_DEFAULT, message_p);
 }
diff --git a/openair-cn/MME_APP/mme_app_main.c b/openair-cn/MME_APP/mme_app_main.c
index 9026532bc5a..15807140c93 100644
--- a/openair-cn/MME_APP/mme_app_main.c
+++ b/openair-cn/MME_APP/mme_app_main.c
@@ -87,6 +87,11 @@ void *mme_app_thread(void *args)
     }
     break;
 
+    case SGW_RELEASE_ACCESS_BEARERS_RESPONSE: {
+        mme_app_handle_release_access_bearers_resp(&received_message_p->ittiMsg.sgwReleaseAccessBearersResponse);
+    }
+    break;
+
 #if defined(DISABLE_USE_NAS)
 
     case NAS_ATTACH_REQ: {
diff --git a/openair-cn/NAS/EURECOM-NAS/src/nas_proc.c b/openair-cn/NAS/EURECOM-NAS/src/nas_proc.c
index 2d504afb80b..662dd6dfaaa 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/nas_proc.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/nas_proc.c
@@ -1359,7 +1359,7 @@ int nas_proc_establish_ind(UInt32_t ueid, tac_t tac,
     		MSC_NAS_MME,
     		MSC_NAS_EMM_MME,
     		NULL,0,
-    		"0 EMMAS_ESTABLISH_REQ ue id %u tac %u", ueid, tac);
+    		"0 EMMAS_ESTABLISH_REQ ue id %06"PRIX32" tac %u", ueid, tac);
     /*
      * Notify the EMM procedure call manager that NAS signalling
      * connection establishment indication message has been received
@@ -1402,7 +1402,7 @@ int nas_proc_dl_transfer_cnf(UInt32_t ueid)
   		MSC_NAS_MME,
   		MSC_NAS_EMM_MME,
   		NULL,0,
-  		"0 EMMAS_DATA_IND dl_transfer_conf ue id %u", ueid);
+  		"0 EMMAS_DATA_IND dl_transfer_conf ue id %06"PRIX32"", ueid);
 
   /*
    * Notify the EMM procedure call manager that downlink NAS message
@@ -1445,7 +1445,7 @@ int nas_proc_dl_transfer_rej(UInt32_t ueid)
   		MSC_NAS_MME,
   		MSC_NAS_EMM_MME,
   		NULL,0,
-  		"0 EMMAS_DATA_IND dl_transfer_reject ue id %u", ueid);
+  		"0 EMMAS_DATA_IND dl_transfer_reject ue id %06"PRIX32"", ueid);
 
   /*
    * Notify the EMM procedure call manager that transmission
@@ -1494,7 +1494,7 @@ int nas_proc_ul_transfer_ind(UInt32_t ueid, const Byte_t *data, UInt32_t len)
     		MSC_NAS_MME,
     		MSC_NAS_EMM_MME,
     		NULL,0,
-    		"0 EMMAS_DATA_IND ue id %u len %u", ueid, len);
+    		"0 EMMAS_DATA_IND ue id %06"PRIX32" len %u", ueid, len);
 
     emm_sap.primitive = EMMAS_DATA_IND;
     emm_sap.u.emm_as.u.data.ueid = ueid;
@@ -1561,7 +1561,7 @@ int nas_proc_deregister_ue(UInt32_t ue_id)
   		MSC_NAS_MME,
   		MSC_NAS_EMM_MME,
   		NULL,0,
-  		"0 EMMCN_DEREGISTER_UE ue_id %u",ue_id);
+  		"0 EMMCN_DEREGISTER_UE ue_id %06"PRIX32"",ue_id);
 
   emm_sap.primitive = EMMCN_DEREGISTER_UE;
   emm_sap.u.emm_cn.u.deregister.UEid = ue_id;
diff --git a/openair-cn/NAS/nas_itti_messaging.c b/openair-cn/NAS/nas_itti_messaging.c
index cbe9def44d4..8f7dac65319 100644
--- a/openair-cn/NAS/nas_itti_messaging.c
+++ b/openair-cn/NAS/nas_itti_messaging.c
@@ -205,7 +205,7 @@ int nas_itti_dl_data_req(const uint32_t ue_id, void *const data,
   	  	MSC_NAS_MME,
   	  	MSC_S1AP_MME,
   	  	NULL,0,
-  	  	"0 NAS_DOWNLINK_DATA_REQ ue id %u len %u", ue_id, length);
+  	  	"0 NAS_DOWNLINK_DATA_REQ ue id %06"PRIX32" len %u", ue_id, length);
 
   return itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
 }
diff --git a/openair-cn/NAS/nas_itti_messaging.h b/openair-cn/NAS/nas_itti_messaging.h
index 7e3634af910..b9d422a6134 100644
--- a/openair-cn/NAS/nas_itti_messaging.h
+++ b/openair-cn/NAS/nas_itti_messaging.h
@@ -129,7 +129,7 @@ static inline void nas_itti_pdn_connectivity_req(
   	  	MSC_NAS_MME,
   	  	MSC_MMEAPP_MME,
   	  	NULL,0,
-  	  	"0 NAS_PDN_CONNECTIVITY_REQ ue id %u IMSI %X",
+  	  	"0 NAS_PDN_CONNECTIVITY_REQ ue id %06"PRIX32" IMSI %X",
   	  	ueidP, NAS_PDN_CONNECTIVITY_REQ(message_p).imsi);
 
   itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
@@ -162,7 +162,7 @@ static inline void nas_itti_establish_cnf(
   	  	MSC_NAS_MME,
   	  	MSC_MMEAPP_MME,
   	  	NULL,0,
-  	  	"0 NAS_CONNECTION_ESTABLISHMENT_CNF ue id %u len %u sea %x sia %x ",
+  	  	"0 NAS_CONNECTION_ESTABLISHMENT_CNF ue id %06"PRIX32" len %u sea %x sia %x ",
   	  ue_idP, lengthP, selected_encryption_algorithmP, selected_integrity_algorithmP);
 
   itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
@@ -209,7 +209,7 @@ static inline void nas_itti_auth_info_req(
   	  	MSC_NAS_MME,
   	  	MSC_MMEAPP_MME,
   	  	NULL,0,
-  	  	"0 NAS_AUTHENTICATION_PARAM_REQ ue id %u IMSI %s ",
+  	  	"0 NAS_AUTHENTICATION_PARAM_REQ ue id %06"PRIX32" IMSI %s ",
   	  ue_idP, NAS_AUTHENTICATION_PARAM_REQ(message_p).imsi);
 
   itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
@@ -246,7 +246,7 @@ static inline void nas_itti_establish_rej(
   	  	MSC_NAS_MME,
   	  	MSC_MMEAPP_MME,
   	  	NULL,0,
-  	  	"0 NAS_AUTHENTICATION_PARAM_REQ ue id %u IMSI %s (establish reject)",
+  	  	"0 NAS_AUTHENTICATION_PARAM_REQ ue id %06"PRIX32" IMSI %s (establish reject)",
   	  ue_idP, NAS_AUTHENTICATION_PARAM_REQ(message_p).imsi);
 
   itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
diff --git a/openair-cn/S1AP/s1ap_common.h b/openair-cn/S1AP/s1ap_common.h
index 4847c1b4414..0024812fd27 100644
--- a/openair-cn/S1AP/s1ap_common.h
+++ b/openair-cn/S1AP/s1ap_common.h
@@ -397,6 +397,8 @@ inline void ASN_DEBUG(const char *fmt, ...);
 # define TRUE  (!FALSE)
 #endif
 
+#define S1AP_UE_ID_FMT  "0x%06"PRIX32
+
 extern int asn_debug;
 extern int asn1_xer_print;
 
diff --git a/openair-cn/S1AP/s1ap_mme.c b/openair-cn/S1AP/s1ap_mme.c
index 431228c0aac..5112ec30ced 100644
--- a/openair-cn/S1AP/s1ap_mme.c
+++ b/openair-cn/S1AP/s1ap_mme.c
@@ -156,6 +156,11 @@ void *s1ap_mme_thread(void *args)
     }
     break;
 
+    case S1AP_UE_CONTEXT_RELEASE_COMMAND: {
+        s1ap_handle_ue_context_release_command(&received_message_p->ittiMsg.s1ap_ue_context_release_command);
+    }
+    break;
+
 #if defined(DISABLE_USE_NAS)
 
     case NAS_ATTACH_ACCEPT: {
@@ -436,6 +441,9 @@ void s1ap_remove_ue(ue_description_t *ue_ref)
   /* Remove any attached timer */
   //     s1ap_timer_remove_ue(ue_ref->mme_ue_s1ap_id);
 
+  STAILQ_REMOVE(&eNB_ref->ue_list_head, ue_ref, ue_description_s, ue_entries);
+  eNB_ref->nb_ue_associated--;
+
   /* Freeing memory */
   free(ue_ref);
   ue_ref = NULL;
diff --git a/openair-cn/S1AP/s1ap_mme_handlers.c b/openair-cn/S1AP/s1ap_mme_handlers.c
index 3682bb45dfc..88bef4db48c 100644
--- a/openair-cn/S1AP/s1ap_mme_handlers.c
+++ b/openair-cn/S1AP/s1ap_mme_handlers.c
@@ -115,15 +115,17 @@ s1ap_message_decoded_callback messages_callback[][3] = {
 #endif
 };
 
-static const char *direction2String[] = {
+const char *s1ap_direction2String[] = {
   "", /* Nothing */
   "Originating message", /* originating message */
   "Successfull outcome", /* successfull outcome */
   "UnSuccessfull outcome", /* successfull outcome */
 };
 
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_message(uint32_t assoc_id, uint32_t stream,
                             struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   /* Checking procedure Code and direction of message */
   if ((message->procedureCode > (sizeof(messages_callback) / (3 * sizeof(
@@ -141,7 +143,7 @@ int s1ap_mme_handle_message(uint32_t assoc_id, uint32_t stream,
   if (messages_callback[message->procedureCode][message->direction-1] == NULL) {
     S1AP_DEBUG("[SCTP %d] No handler for procedureCode %d in %s\n", assoc_id,
                (int)message->procedureCode,
-               direction2String[(int)message->direction]);
+               s1ap_direction2String[(int)message->direction]);
     return -2;
   }
 
@@ -150,7 +152,9 @@ int s1ap_mme_handle_message(uint32_t assoc_id, uint32_t stream,
            assoc_id, stream, message);
 }
 
+//------------------------------------------------------------------------------
 int s1ap_mme_set_cause(S1ap_Cause_t *cause_p, S1ap_Cause_PR cause_type, long cause_value)
+//------------------------------------------------------------------------------
 {
   DevAssert(cause_p != NULL);
 
@@ -184,9 +188,11 @@ int s1ap_mme_set_cause(S1ap_Cause_t *cause_p, S1ap_Cause_PR cause_type, long cau
   return 0;
 }
 
+//------------------------------------------------------------------------------
 int s1ap_mme_generate_s1_setup_failure(
   uint32_t assoc_id, S1ap_Cause_PR cause_type, long cause_value,
   long time_to_wait)
+//------------------------------------------------------------------------------
 {
   uint8_t *buffer_p;
   uint32_t length;
@@ -216,7 +222,7 @@ int s1ap_mme_generate_s1_setup_failure(
   		MSC_S1AP_MME,
   		MSC_S1AP_ENB,
   		NULL,0,
-  		"0 SETUP_FAILURE assoc_id %u cause %u value %u",
+  		"0 S1Setup/unsuccessfulOutcome  assoc_id %u cause %u value %u",
   		assoc_id, cause_type, cause_value);
   return s1ap_mme_itti_send_sctp_request(buffer_p, length, assoc_id, 0);
 }
@@ -225,8 +231,10 @@ int s1ap_mme_generate_s1_setup_failure(
 //************************** Management procedures ***************************//
 ////////////////////////////////////////////////////////////////////////////////
 
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_s1_setup_request(uint32_t assoc_id, uint32_t stream,
                                      struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   if (hss_associated) {
     S1ap_S1SetupRequestIEs_t *s1SetupRequest_p;
@@ -243,6 +251,14 @@ int s1ap_mme_handle_s1_setup_request(uint32_t assoc_id, uint32_t stream,
     /* We received a new valid S1 Setup Request on a stream != 0.
      * This should not happen -> reject eNB s1 setup request.
      */
+    MSC_LOG_RX_MESSAGE(
+    		MSC_S1AP_MME,
+    		MSC_S1AP_ENB,
+    		NULL,0,
+    		"0 S1Setup/%s assoc_id %u stream %u",
+    		s1ap_direction2String[message->direction],
+    		assoc_id, stream);
+
     if (stream != 0) {
       S1AP_ERROR("Received new s1 setup request on stream != 0\n");
       /* Send a s1 setup failure with protocol cause unspecified */
@@ -364,8 +380,10 @@ int s1ap_mme_handle_s1_setup_request(uint32_t assoc_id, uint32_t stream,
   }
 }
 
+//------------------------------------------------------------------------------
 static
 int s1ap_generate_s1_setup_response(eNB_description_t *eNB_association)
+//------------------------------------------------------------------------------
 {
   int i;
   int enc_rval = 0;
@@ -442,15 +460,17 @@ int s1ap_generate_s1_setup_response(eNB_description_t *eNB_association)
   		MSC_S1AP_MME,
   		MSC_S1AP_ENB,
   		NULL,0,
-  		"0 SETUP_RESPONSE assoc_id %u",
+  		"0 S1Setup/successfulOutcome assoc_id %u",
   		eNB_association->sctp_assoc_id);
   /* Non-UE signalling -> stream 0 */
   return s1ap_mme_itti_send_sctp_request(buffer, length, eNB_association->sctp_assoc_id,
                                          0);
 }
 
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
                                       struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   ue_description_t *ue_ref;
   S1ap_UECapabilityInfoIndicationIEs_t *ue_cap_p;
@@ -459,14 +479,23 @@ int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
 
   ue_cap_p = &message->msg.s1ap_UECapabilityInfoIndicationIEs;
 
+  MSC_LOG_RX_MESSAGE(
+	  	MSC_S1AP_MME,
+	  	MSC_S1AP_ENB,
+  		NULL,0,
+  		"0 UECapabilityInfoIndication/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" ",
+		s1ap_direction2String[message->direction],
+		ue_cap_p->eNB_UE_S1AP_ID,
+		ue_cap_p->mme_ue_s1ap_id);
+
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(ue_cap_p->mme_ue_s1ap_id)) == NULL) {
-    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: 0x%08x\n",
+    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: "S1AP_UE_ID_FMT"\n",
                (uint32_t)ue_cap_p->mme_ue_s1ap_id);
     return -1;
   }
 
   if (ue_ref->eNB_ue_s1ap_id != ue_cap_p->eNB_UE_S1AP_ID) {
-    S1AP_DEBUG("Mismatch in eNB UE S1AP ID, known: 0x%06x, received: 0x%06x\n",
+    S1AP_DEBUG("Mismatch in eNB UE S1AP ID, known: "S1AP_UE_ID_FMT", received: "S1AP_UE_ID_FMT"\n",
                ue_ref->eNB_ue_s1ap_id, (uint32_t)ue_cap_p->eNB_UE_S1AP_ID);
     return -1;
   }
@@ -474,7 +503,7 @@ int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
   /* Just display a warning when message received over wrong stream */
   if (ue_ref->sctp_stream_recv != stream) {
     S1AP_ERROR("Received ue capability indication for "
-               "(MME UE S1AP ID/eNB UE S1AP ID) (0x%08x/0x%06x) over wrong stream "
+               "(MME UE S1AP ID/eNB UE S1AP ID) ("S1AP_UE_ID_FMT"/"S1AP_UE_ID_FMT") over wrong stream "
                "expecting %u, received on %u\n",
                (uint32_t)ue_cap_p->mme_ue_s1ap_id, ue_ref->eNB_ue_s1ap_id,
                ue_ref->sctp_stream_recv, stream);
@@ -505,7 +534,7 @@ int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
     		MSC_S1AP_MME,
     		MSC_MMEAPP_MME,
     		NULL,0,
-    		"0 S1AP_UE_CAPABILITIES_IND eNB_ue_s1ap_id %u mme_ue_s1ap_id %u len %u",
+    		"0 S1AP_UE_CAPABILITIES_IND eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
     	    ue_cap_ind_p->eNB_ue_s1ap_id,
     	    ue_cap_ind_p->mme_ue_s1ap_id,
     	    ue_cap_ind_p->radio_capabilities_length);
@@ -519,10 +548,12 @@ int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
 //******************* Context Management procedures **************************//
 ////////////////////////////////////////////////////////////////////////////////
 
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_initial_context_setup_response(
   uint32_t assoc_id,
   uint32_t stream,
   struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
 
   S1ap_InitialContextSetupResponseIEs_t *initialContextSetupResponseIEs_p = NULL;
@@ -532,9 +563,18 @@ int s1ap_mme_handle_initial_context_setup_response(
 
   initialContextSetupResponseIEs_p = &message->msg.s1ap_InitialContextSetupResponseIEs;
 
+  MSC_LOG_RX_MESSAGE(
+	  	MSC_S1AP_MME,
+	  	MSC_S1AP_ENB,
+  		NULL,0,
+  		"0 InitialContextSetup/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
+		s1ap_direction2String[message->direction],
+  		initialContextSetupResponseIEs_p->eNB_UE_S1AP_ID,
+  		initialContextSetupResponseIEs_p->mme_ue_s1ap_id);
+
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(
                   (uint32_t)initialContextSetupResponseIEs_p->mme_ue_s1ap_id)) == NULL) {
-    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: 0x%08x %u(10)\n",
+    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: "S1AP_UE_ID_FMT" %u(10)\n",
                (uint32_t)initialContextSetupResponseIEs_p->mme_ue_s1ap_id,
                (uint32_t)initialContextSetupResponseIEs_p->mme_ue_s1ap_id);
     return -1;
@@ -542,7 +582,7 @@ int s1ap_mme_handle_initial_context_setup_response(
 
   if (ue_ref->eNB_ue_s1ap_id !=
       initialContextSetupResponseIEs_p->eNB_UE_S1AP_ID) {
-    S1AP_DEBUG("Mismatch in eNB UE S1AP ID, known: 0x%06x %u(10), received: 0x%06x %u(10)\n",
+    S1AP_DEBUG("Mismatch in eNB UE S1AP ID, known: "S1AP_UE_ID_FMT" %u(10), received: 0x%06x %u(10)\n",
                ue_ref->eNB_ue_s1ap_id,
                ue_ref->eNB_ue_s1ap_id,
                (uint32_t)initialContextSetupResponseIEs_p->eNB_UE_S1AP_ID,
@@ -585,7 +625,7 @@ int s1ap_mme_handle_initial_context_setup_response(
   		MSC_S1AP_MME,
   		MSC_MMEAPP_MME,
   		NULL,0,
-  		"0 MME_APP_INITIAL_CONTEXT_SETUP_RSP mme_ue_s1ap_id %u ebi %u s1u enb teid %u",
+  		"0 MME_APP_INITIAL_CONTEXT_SETUP_RSP mme_ue_s1ap_id "S1AP_UE_ID_FMT" ebi %u s1u enb teid %u",
   		MME_APP_INITIAL_CONTEXT_SETUP_RSP(message_p).mme_ue_s1ap_id,
   		MME_APP_INITIAL_CONTEXT_SETUP_RSP(message_p).eps_bearer_id,
   		MME_APP_INITIAL_CONTEXT_SETUP_RSP(message_p).bearer_s1u_enb_fteid.teid);
@@ -594,9 +634,10 @@ int s1ap_mme_handle_initial_context_setup_response(
 }
 
 
-
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
     uint32_t stream, struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   S1ap_UEContextReleaseRequestIEs_t *ueContextReleaseRequest_p = NULL;
   ue_description_t                  *ue_ref                    = NULL;
@@ -604,6 +645,15 @@ int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
 
   ueContextReleaseRequest_p = &message->msg.s1ap_UEContextReleaseRequestIEs;
 
+  MSC_LOG_RX_MESSAGE(
+	  	MSC_S1AP_MME,
+	  	MSC_S1AP_ENB,
+  		NULL,0,
+  		"0 UEContextReleaseRequest/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
+		s1ap_direction2String[message->direction],
+		ueContextReleaseRequest_p->eNB_UE_S1AP_ID,
+		ueContextReleaseRequest_p->mme_ue_s1ap_id);
+
   /* The UE context release procedure is initiated if the cause is != than user inactivity.
    * TS36.413 #8.3.2.2.
    */
@@ -624,12 +674,12 @@ int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
     /* MME doesn't know the MME UE S1AP ID provided.
      * TODO
      */
-    S1AP_DEBUG("UE_CONTEXT_RELEASE_REQUEST ignored cause could not get context with mme_ue_s1ap_id 0x%08x %u(10)\n",
+    S1AP_DEBUG("UE_CONTEXT_RELEASE_REQUEST ignored cause could not get context with mme_ue_s1ap_id "S1AP_UE_ID_FMT" %u(10)\n",
                ueContextReleaseRequest_p->mme_ue_s1ap_id,
                ueContextReleaseRequest_p->mme_ue_s1ap_id);
     MSC_LOG_EVENT(
     		MSC_S1AP_MME,
-    		"0 UE_CONTEXT_RELEASE_REQUEST ignored, no context mme_ue_s1ap_id",
+    		"0 UE_CONTEXT_RELEASE_REQUEST ignored, no context mme_ue_s1ap_id "S1AP_UE_ID_FMT" ",
     		ueContextReleaseRequest_p->mme_ue_s1ap_id);
     return -1;
   } else {
@@ -645,9 +695,9 @@ int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
       message_p = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_REQ);
 
       AssertFatal(message_p != NULL,"itti_alloc_new_message Failed");
-      memset((void*)&message_p->ittiMsg.mme_app_initial_context_setup_rsp,
+      memset((void*)&message_p->ittiMsg.s1ap_ue_context_release_req,
     	         0,
-    	         sizeof(mme_app_initial_context_setup_rsp_t));
+    	         sizeof(s1ap_ue_context_release_req_t));
 
       S1AP_UE_CONTEXT_RELEASE_REQ(message_p).mme_ue_s1ap_id                      = ue_ref->mme_ue_s1ap_id;
 
@@ -655,18 +705,18 @@ int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
     	  		MSC_S1AP_MME,
     	  		MSC_MMEAPP_MME,
     	  		NULL,0,
-    	  		"0 S1AP_UE_CONTEXT_RELEASE_REQ mme_ue_s1ap_id %u ",
+    	  		"0 S1AP_UE_CONTEXT_RELEASE_REQ mme_ue_s1ap_id "S1AP_UE_ID_FMT" ",
     	  		S1AP_UE_CONTEXT_RELEASE_REQ(message_p).mme_ue_s1ap_id);
 
       return itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
 
     } else {
       // TODO
-      S1AP_DEBUG("UE_CONTEXT_RELEASE_REQUEST ignored, cause mismatch eNB_ue_s1ap_id: ctxt 0x%08x != request 0x%08x",
+      S1AP_DEBUG("UE_CONTEXT_RELEASE_REQUEST ignored, cause mismatch eNB_ue_s1ap_id: ctxt "S1AP_UE_ID_FMT" != request "S1AP_UE_ID_FMT" ",
           		ue_ref->eNB_ue_s1ap_id, ueContextReleaseRequest_p->eNB_UE_S1AP_ID);
       MSC_LOG_EVENT(
           		MSC_S1AP_MME,
-          		"0 UE_CONTEXT_RELEASE_REQUEST ignored, cause mismatch eNB_ue_s1ap_id: ctxt 0x%08x != request 0x%08x",
+          		"0 UE_CONTEXT_RELEASE_REQUEST ignored, cause mismatch eNB_ue_s1ap_id: ctxt "S1AP_UE_ID_FMT" != request "S1AP_UE_ID_FMT" ",
           		ue_ref->eNB_ue_s1ap_id, ueContextReleaseRequest_p->eNB_UE_S1AP_ID);
       return -1;
     }
@@ -675,8 +725,10 @@ int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
   return 0;
 }
 
+//------------------------------------------------------------------------------
 static int s1ap_mme_generate_ue_context_release_command(
   ue_description_t *ue_ref)
+//------------------------------------------------------------------------------
 {
   uint8_t *buffer;
   uint32_t length;
@@ -709,26 +761,78 @@ static int s1ap_mme_generate_ue_context_release_command(
     S1ap_CauseRadioNetwork_release_due_to_eutran_generated_reason;
 
   if (s1ap_mme_encode_pdu(&message, &buffer, &length) < 0) {
+    MSC_LOG_EVENT(
+    		MSC_S1AP_MME,
+    		"0 UEContextRelease/initiatingMessage eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" encoding failed",
+    		ue_ref->eNB_ue_s1ap_id,
+    		ue_ref->mme_ue_s1ap_id);
     return -1;
   }
+  MSC_LOG_TX_MESSAGE(
+	  		MSC_S1AP_MME,
+	  		MSC_S1AP_ENB,
+	  		NULL,0,
+	  		"0 UEContextRelease/initiatingMessage eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT"",
+	  		ue_ref->eNB_ue_s1ap_id,ue_ref->mme_ue_s1ap_id);
 
   return s1ap_mme_itti_send_sctp_request(buffer, length, ue_ref->eNB->sctp_assoc_id,
                                          ue_ref->sctp_stream_send);
 }
 
+
+//------------------------------------------------------------------------------
+int s1ap_handle_ue_context_release_command(
+		const s1ap_ue_context_release_command_t * const ue_context_release_command_pP)
+//------------------------------------------------------------------------------
+{
+  ue_description_t *ue_ref_p = NULL;
+
+  if ((ue_ref_p = s1ap_is_ue_mme_id_in_list(
+		  ue_context_release_command_pP->mme_ue_s1ap_id)) == NULL) {
+    /* MME doesn't know the MME UE S1AP ID provided.
+     * TODO
+     */
+    S1AP_DEBUG("UE_CONTEXT_RELEASE_COMMAND ignored cause could not get context with mme_ue_s1ap_id "S1AP_UE_ID_FMT" %u(10)\n",
+    		ue_context_release_command_pP->mme_ue_s1ap_id,
+    		ue_context_release_command_pP->mme_ue_s1ap_id);
+    MSC_LOG_EVENT(
+    		MSC_S1AP_MME,
+    		"0 UE_CONTEXT_RELEASE_COMMAND ignored, no context mme_ue_s1ap_id",
+    		ue_context_release_command_pP->mme_ue_s1ap_id);
+    return -1;
+  } else {
+    return s1ap_mme_generate_ue_context_release_command(ue_ref_p);
+  }
+  return -1;
+}
+
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_ue_context_release_complete(uint32_t assoc_id,
     uint32_t stream, struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   S1ap_UEContextReleaseCompleteIEs_t *ueContextReleaseComplete_p;
   ue_description_t *ue_ref = NULL;
 
   ueContextReleaseComplete_p = &message->msg.s1ap_UEContextReleaseCompleteIEs;
+  MSC_LOG_RX_MESSAGE(
+	  	MSC_S1AP_MME,
+	  	MSC_S1AP_ENB,
+  		NULL,0,
+  		"0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
+		s1ap_direction2String[message->direction],
+		ueContextReleaseComplete_p->eNB_UE_S1AP_ID,
+		ueContextReleaseComplete_p->mme_ue_s1ap_id);
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(
                   ueContextReleaseComplete_p->mme_ue_s1ap_id)) == NULL) {
     /* MME doesn't know the MME UE S1AP ID provided.
      * TODO
      */
+	MSC_LOG_EVENT(
+			MSC_S1AP_MME,
+			"0 UEContextReleaseComplete ignored, no context mme_ue_s1ap_id "S1AP_UE_ID_FMT" ",
+			ueContextReleaseComplete_p->mme_ue_s1ap_id);
     return -1;
   }
 
@@ -736,23 +840,37 @@ int s1ap_mme_handle_ue_context_release_complete(uint32_t assoc_id,
    * TODO: inform NAS and remove e-RABS.
    */
   s1ap_remove_ue(ue_ref);
-  S1AP_DEBUG("Removed UE %u\n",
+  S1AP_DEBUG("Removed UE "S1AP_UE_ID_FMT"\n",
              (uint32_t)ueContextReleaseComplete_p->mme_ue_s1ap_id);
   return 0;
 }
 
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_initial_context_setup_failure(uint32_t assoc_id,
     uint32_t stream, struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   S1ap_InitialContextSetupFailureIEs_t *initialContextSetupFailureIEs_p;
 
   ue_description_t *ue_ref = NULL;
 
   initialContextSetupFailureIEs_p = &message->msg.s1ap_InitialContextSetupFailureIEs;
+  MSC_LOG_RX_MESSAGE(
+	  	MSC_S1AP_MME,
+	  	MSC_S1AP_ENB,
+  		NULL,0,
+  		"0 InitialContextSetup/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u",
+		s1ap_direction2String[message->direction],
+		initialContextSetupFailureIEs_p->eNB_UE_S1AP_ID,
+		initialContextSetupFailureIEs_p->mme_ue_s1ap_id);
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(
                   initialContextSetupFailureIEs_p->mme_ue_s1ap_id)) == NULL) {
     /* MME doesn't know the MME UE S1AP ID provided. */
+	MSC_LOG_EVENT(
+			MSC_S1AP_MME,
+			"0 InitialContextSetupFailure ignored, no context mme_ue_s1ap_id "S1AP_UE_ID_FMT" ",
+			initialContextSetupFailureIEs_p->mme_ue_s1ap_id);
     return -1;
   }
 
@@ -761,9 +879,13 @@ int s1ap_mme_handle_initial_context_setup_failure(uint32_t assoc_id,
     return -1;
   }
 
-  S1AP_DEBUG("Removed UE %u\n",
-             (uint32_t)initialContextSetupFailureIEs_p->mme_ue_s1ap_id);
   s1ap_remove_ue(ue_ref);
+  MSC_LOG_EVENT(
+			MSC_S1AP_MME,
+			"0 Removed UE mme_ue_s1ap_id "S1AP_UE_ID_FMT" ",
+			initialContextSetupFailureIEs_p->mme_ue_s1ap_id);
+  S1AP_DEBUG("Removed UE "S1AP_UE_ID_FMT"\n",
+             (uint32_t)initialContextSetupFailureIEs_p->mme_ue_s1ap_id);
   return 0;
 }
 
@@ -771,8 +893,10 @@ int s1ap_mme_handle_initial_context_setup_failure(uint32_t assoc_id,
 //************************ Handover signalling *******************************//
 ////////////////////////////////////////////////////////////////////////////////
 
+//------------------------------------------------------------------------------
 int s1ap_mme_handle_path_switch_request(uint32_t assoc_id, uint32_t stream,
                                         struct s1ap_message_s *message)
+//------------------------------------------------------------------------------
 {
   S1ap_PathSwitchRequestIEs_t *pathSwitchRequest_p;
   ue_description_t *ue_ref;
@@ -783,7 +907,7 @@ int s1ap_mme_handle_path_switch_request(uint32_t assoc_id, uint32_t stream,
   // eNB UE S1AP ID is limited to 24 bits
   eNB_ue_s1ap_id = (uint32_t)(pathSwitchRequest_p->eNB_UE_S1AP_ID & 0x00ffffff);
 
-  S1AP_DEBUG("Path Switch Request message received from eNB UE S1AP ID: %d\n",
+  S1AP_DEBUG("Path Switch Request message received from eNB UE S1AP ID: "S1AP_UE_ID_FMT"\n",
              (int)eNB_ue_s1ap_id);
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(
@@ -808,7 +932,9 @@ int s1ap_mme_handle_path_switch_request(uint32_t assoc_id, uint32_t stream,
   return 0;
 }
 
+//------------------------------------------------------------------------------
 int s1ap_handle_sctp_deconnection(uint32_t assoc_id)
+//------------------------------------------------------------------------------
 {
   int current_ue_index = 0;
   int handled_ues      = 0;
@@ -874,7 +1000,9 @@ int s1ap_handle_sctp_deconnection(uint32_t assoc_id)
   return 0;
 }
 
+//------------------------------------------------------------------------------
 int s1ap_handle_new_association(sctp_new_peer_t *sctp_new_peer_p)
+//------------------------------------------------------------------------------
 {
   eNB_description_t *eNB_association;
 
diff --git a/openair-cn/S1AP/s1ap_mme_handlers.h b/openair-cn/S1AP/s1ap_mme_handlers.h
index 9343b46569e..fc00d8c8af8 100644
--- a/openair-cn/S1AP/s1ap_mme_handlers.h
+++ b/openair-cn/S1AP/s1ap_mme_handlers.h
@@ -63,6 +63,9 @@ int s1ap_mme_handle_path_switch_request(uint32_t assoc_id, uint32_t stream,
 int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
     uint32_t stream, struct s1ap_message_s *message_p);
 
+int s1ap_handle_ue_context_release_command(
+		const s1ap_ue_context_release_command_t * const ue_context_release_command_pP);
+
 int s1ap_mme_handle_ue_context_release_complete(uint32_t assoc_id,
     uint32_t stream, struct s1ap_message_s *message_p);
 
diff --git a/openair-cn/S1AP/s1ap_mme_itti_messaging.c b/openair-cn/S1AP/s1ap_mme_itti_messaging.c
index 4a58400899a..1c2a90be614 100644
--- a/openair-cn/S1AP/s1ap_mme_itti_messaging.c
+++ b/openair-cn/S1AP/s1ap_mme_itti_messaging.c
@@ -59,7 +59,7 @@ int s1ap_mme_itti_nas_uplink_ind(const uint32_t ue_id, uint8_t * const buffer,
   		MSC_S1AP_MME,
   		MSC_NAS_MME,
   		NULL,0,
-  		"0 NAS_UPLINK_DATA_IND ue_id %u len %u",
+  		"0 NAS_UPLINK_DATA_IND ue_id "S1AP_UE_ID_FMT" len %u",
   		NAS_UL_DATA_IND(message_p).UEid,
   		NAS_UL_DATA_IND(message_p).nasMsg.length);
 
@@ -80,7 +80,7 @@ int s1ap_mme_itti_nas_downlink_cnf(const uint32_t ue_id,
   		MSC_S1AP_MME,
   		MSC_NAS_MME,
   		NULL,0,
-  		"0 NAS_DOWNLINK_DATA_CNF ue_id %u errCode %u",
+  		"0 NAS_DOWNLINK_DATA_CNF ue_id "S1AP_UE_ID_FMT" errCode %u",
   		NAS_DL_DATA_CNF(message_p).UEid,
   		NAS_DL_DATA_CNF(message_p).errCode);
 
diff --git a/openair-cn/S1AP/s1ap_mme_itti_messaging.h b/openair-cn/S1AP/s1ap_mme_itti_messaging.h
index 807e4d6ca82..28ad9863c6f 100644
--- a/openair-cn/S1AP/s1ap_mme_itti_messaging.h
+++ b/openair-cn/S1AP/s1ap_mme_itti_messaging.h
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include "intertask_interface.h"
+#include "s1ap_common.h"
 #include "msc.h"
 
 #ifndef S1AP_MME_ITTI_MESSAGING_H_
@@ -73,7 +74,7 @@ static inline void s1ap_mme_itti_mme_app_establish_ind(
   		MSC_S1AP_MME,
   		MSC_MMEAPP_MME,
   		NULL,0,
-  		"0 MME_APP_CONNECTION_ESTABLISHMENT_IND ue_id %u as cause %u  tac %u len %u",
+  		"0 MME_APP_CONNECTION_ESTABLISHMENT_IND ue_id "S1AP_UE_ID_FMT" as cause %u  tac %u len %u",
   		ue_id,
   		MME_APP_CONNECTION_ESTABLISHMENT_IND(message_p).nas.asCause,
   		MME_APP_CONNECTION_ESTABLISHMENT_IND(message_p).nas.tac,
@@ -107,7 +108,7 @@ static inline void s1ap_mme_itti_nas_establish_ind(
   		MSC_S1AP_MME,
   		MSC_NAS_MME,
   		NULL,0,
-  		"0 NAS_CONNECTION_ESTABLISHMENT_IND ue_id %u as cause %u  tac %u len %u",
+  		"0 NAS_CONNECTION_ESTABLISHMENT_IND ue_id "S1AP_UE_ID_FMT" as cause %u  tac %u len %u",
   		ue_id,
   		NAS_CONN_EST_IND(message_p).nas.asCause,
   		NAS_CONN_EST_IND(message_p).nas.tac,
@@ -138,7 +139,7 @@ static inline void s1ap_mme_itti_nas_non_delivery_ind(
   		MSC_S1AP_MME,
   		MSC_NAS_MME,
   		NULL,0,
-  		"0 NAS_DOWNLINK_DATA_REJ ue_id %u len %u",
+  		"0 NAS_DOWNLINK_DATA_REJ ue_id "S1AP_UE_ID_FMT" len %u",
   		ue_id,
   		NAS_DL_DATA_REJ(message_p).nasMsg.length);
 
diff --git a/openair-cn/S1AP/s1ap_mme_nas_procedures.c b/openair-cn/S1AP/s1ap_mme_nas_procedures.c
index ff8f5102974..4b8229e73b7 100644
--- a/openair-cn/S1AP/s1ap_mme_nas_procedures.c
+++ b/openair-cn/S1AP/s1ap_mme_nas_procedures.c
@@ -56,6 +56,7 @@
 static uint32_t mme_ue_s1ap_id = 0;
 static uint8_t  mme_ue_s1ap_id_has_wrapped = 0;
 
+extern const char *s1ap_direction2String[];
 
 
 int s1ap_mme_handle_initial_ue_message(uint32_t assoc_id, uint32_t stream,
@@ -68,6 +69,14 @@ int s1ap_mme_handle_initial_ue_message(uint32_t assoc_id, uint32_t stream,
 
   initialUEMessage_p = &message->msg.s1ap_InitialUEMessageIEs;
 
+  MSC_LOG_RX_MESSAGE(
+  		MSC_S1AP_MME,
+  		MSC_S1AP_ENB,
+  		NULL,0,
+  		"0 initialUEMessage/%s assoc_id %u stream %u "S1AP_UE_ID_FMT" ",
+  		s1ap_direction2String[message->direction],
+  		assoc_id, stream, initialUEMessage_p->eNB_UE_S1AP_ID);
+
   if ((eNB_ref = s1ap_is_eNB_assoc_id_in_list(assoc_id)) == NULL) {
     S1AP_DEBUG("Unkwnon eNB on assoc_id %d\n", assoc_id);
     return -1;
@@ -76,7 +85,7 @@ int s1ap_mme_handle_initial_ue_message(uint32_t assoc_id, uint32_t stream,
   // eNB UE S1AP ID is limited to 24 bits
   eNB_ue_s1ap_id = (uint32_t)(initialUEMessage_p->eNB_UE_S1AP_ID & 0x00ffffff);
 
-  S1AP_DEBUG("New Initial UE message received with eNB UE S1AP ID: 0x%06x\n",
+  S1AP_DEBUG("New Initial UE message received with eNB UE S1AP ID: "S1AP_UE_ID_FMT"\n",
              eNB_ue_s1ap_id);
 
   ue_ref = s1ap_is_ue_eNB_id_in_list(eNB_ref, eNB_ue_s1ap_id);
@@ -168,14 +177,15 @@ int s1ap_mme_handle_uplink_nas_transport(uint32_t assoc_id, uint32_t stream,
 	  	MSC_S1AP_MME,
 	    MSC_S1AP_ENB,
   		NULL,0,
-  		"0 UPLINK_NAS_TRANSPORT mme_ue_s1ap_id %u eNB_ue_s1ap_id %u nas len %u",
+  		"0 uplinkNASTransport/%s mme_ue_s1ap_id "S1AP_UE_ID_FMT" eNB_ue_s1ap_id "S1AP_UE_ID_FMT" nas len %u",
+  		s1ap_direction2String[message->direction],
   		uplinkNASTransport_p->mme_ue_s1ap_id,
   		uplinkNASTransport_p->eNB_UE_S1AP_ID,
   		uplinkNASTransport_p->nas_pdu.size);
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(uplinkNASTransport_p->mme_ue_s1ap_id))
       == NULL) {
-    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: %d\n",
+    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: "S1AP_UE_ID_FMT"\n",
                (int)uplinkNASTransport_p->mme_ue_s1ap_id);
     return -1;
   }
@@ -215,7 +225,8 @@ int s1ap_mme_handle_nas_non_delivery(uint32_t assoc_id, uint32_t stream,
 	  	MSC_S1AP_MME,
 	    MSC_S1AP_ENB,
   		NULL,0,
-  		"0 NAS_NON_DELIVERY_IND mme_ue_s1ap_id %u eNB_ue_s1ap_id %u cause %u nas len %u",
+  		"0 NASNonDeliveryIndication/%s mme_ue_s1ap_id "S1AP_UE_ID_FMT" eNB_ue_s1ap_id "S1AP_UE_ID_FMT" cause %u nas len %u",
+  		s1ap_direction2String[message->direction],
   		nasNonDeliveryIndication_p->mme_ue_s1ap_id,
   		nasNonDeliveryIndication_p->eNB_UE_S1AP_ID,
   		nasNonDeliveryIndication_p->cause,
@@ -223,7 +234,7 @@ int s1ap_mme_handle_nas_non_delivery(uint32_t assoc_id, uint32_t stream,
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(nasNonDeliveryIndication_p->mme_ue_s1ap_id))
       == NULL) {
-    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: %d\n",
+    S1AP_DEBUG("No UE is attached to this mme UE s1ap id: "S1AP_UE_ID_FMT"\n",
                (int)nasNonDeliveryIndication_p->mme_ue_s1ap_id);
     return -1;
   }
@@ -252,7 +263,7 @@ int s1ap_generate_downlink_nas_transport(const uint32_t ue_id, void * const data
     /* If the UE-associated logical S1-connection is not established,
      * the MME shall allocate a unique MME UE S1AP ID to be used for the UE.
      */
-    S1AP_DEBUG("Unknown UE MME ID %08X, This case is not handled right now\n", ue_id);
+    S1AP_DEBUG("Unknown UE MME ID "S1AP_UE_ID_FMT", This case is not handled right now\n", ue_id);
 
     return -1;
   } else {
@@ -284,7 +295,7 @@ int s1ap_generate_downlink_nas_transport(const uint32_t ue_id, void * const data
       return -1;
     }
 
-    S1AP_DEBUG("Send S1ap_ProcedureCode_id_downlinkNASTransport ue_id = 0x%08X mme_ue_s1ap_id = 0x%08X eNB_UE_S1AP_ID = 0x%08X\n",
+    S1AP_DEBUG("Send S1ap_ProcedureCode_id_downlinkNASTransport ue_id = "S1AP_UE_ID_FMT" mme_ue_s1ap_id = "S1AP_UE_ID_FMT" eNB_UE_S1AP_ID = "S1AP_UE_ID_FMT"\n",
                ue_id,
                downlinkNasTransport->mme_ue_s1ap_id,
                downlinkNasTransport->eNB_UE_S1AP_ID);
@@ -293,7 +304,7 @@ int s1ap_generate_downlink_nas_transport(const uint32_t ue_id, void * const data
     		MSC_S1AP_MME,
     		MSC_S1AP_ENB,
     		NULL,0,
-    		"0 DOWNLINK_NAS_TRANSPORT ue_id %u mme_ue_s1ap_id %u eNB_ue_s1ap_id %u nas length %u",
+    		"0 downlinkNASTransport/initiatingMessage ue_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" eNB_ue_s1ap_id"S1AP_UE_ID_FMT" nas length %u",
     		ue_id,
     		downlinkNasTransport->mme_ue_s1ap_id,
     		downlinkNasTransport->eNB_UE_S1AP_ID,
@@ -331,7 +342,7 @@ int s1ap_handle_attach_accepted(nas_attach_accept_t *attach_accept_p)
   initial_p = &attach_accept_p->transparent;
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(initial_p->mme_ue_s1ap_id)) == NULL) {
-    S1AP_DEBUG("This mme ue s1ap id (%08x) is not attached to any UE context\n",
+    S1AP_DEBUG("This mme ue s1ap id ("S1AP_UE_ID_FMT") is not attached to any UE context\n",
                initial_p->mme_ue_s1ap_id);
     return -1;
   }
@@ -603,7 +614,7 @@ void s1ap_handle_conn_est_cnf(const mme_app_connection_establishment_cnf_t * con
   DevAssert(conn_est_cnf_pP != NULL);
 
   if ((ue_ref = s1ap_is_ue_mme_id_in_list(conn_est_cnf_pP->nas_conn_est_cnf.UEid)) == NULL) {
-    S1AP_DEBUG("This mme ue s1ap id (%08x) is not attached to any UE context\n",
+    S1AP_DEBUG("This mme ue s1ap id ("S1AP_UE_ID_FMT") is not attached to any UE context\n",
                conn_est_cnf_pP->nas_conn_est_cnf.UEid);
 
     DevParam(conn_est_cnf_pP->nas_conn_est_cnf.UEid, 0, 0);
@@ -739,10 +750,11 @@ void s1ap_handle_conn_est_cnf(const mme_app_connection_establishment_cnf_t * con
   		MSC_S1AP_MME,
   		MSC_S1AP_ENB,
   		NULL,0,
-  		"0 INITIAL_CONTEXT_SETUP mme_ue_s1ap_id %u eNB_ue_s1ap_id %u nas length %u",
+  		"0 InitialContextSetup/initiatingMessage mme_ue_s1ap_id "S1AP_UE_ID_FMT" eNB_ue_s1ap_id "S1AP_UE_ID_FMT" nas length %u",
   		initialContextSetupRequest_p->mme_ue_s1ap_id,
   		initialContextSetupRequest_p->eNB_UE_S1AP_ID,
   		nas_pdu.size);
+
   s1ap_mme_itti_send_sctp_request(
     buffer_p,
     length,
diff --git a/openair-cn/S1AP/s1ap_mme_retransmission.c b/openair-cn/S1AP/s1ap_mme_retransmission.c
index 1595462d0ed..0ce368ffa83 100644
--- a/openair-cn/S1AP/s1ap_mme_retransmission.c
+++ b/openair-cn/S1AP/s1ap_mme_retransmission.c
@@ -113,7 +113,7 @@ int s1ap_handle_timer_expiry(timer_has_expired_t *timer_has_expired)
 
   if ((find = RB_FIND(s1ap_timer_map, &s1ap_timer_tree, &elm)) == NULL) {
     S1AP_WARN("Timer id 0x%lx has not been found in tree. Maybe the timer "
-              "reference has been removed before receiving tiemr signal\n",
+              "reference has been removed before receiving timer signal\n",
               timer_has_expired->timer_id);
     return 0;
   }
@@ -132,7 +132,7 @@ int s1ap_timer_remove_ue(uint32_t mme_ue_s1ap_id)
 {
   struct s1ap_timer_map_s *find;
 
-  S1AP_DEBUG("Removing timer associated with UE 0x%08x\n",
+  S1AP_DEBUG("Removing timer associated with UE "S1AP_UE_ID_FMT"\n",
              mme_ue_s1ap_id);
 
   DevAssert(mme_ue_s1ap_id != 0);
diff --git a/openair-cn/SGW-LITE/sgw_lite_handlers.c b/openair-cn/SGW-LITE/sgw_lite_handlers.c
index ca751ad5554..67830537564 100644
--- a/openair-cn/SGW-LITE/sgw_lite_handlers.c
+++ b/openair-cn/SGW-LITE/sgw_lite_handlers.c
@@ -758,7 +758,7 @@ sgw_lite_handle_sgi_endpoint_updated(
         ret = snprintf(cmd,
                        256,
                        "iptables -t mangle -I %s -d %u.%u.%u.%u -m mark --mark 0 -j GTPUAH --own-ip %u.%u.%u.%u --own-tun %u --peer-ip %u.%u.%u.%u --peer-tun %u --action add",
-                       (spgw_config.sgw_config.local_to_eNB) ? "INPUT":"POSTROUTING",
+                       (spgw_config.sgw_config.local_to_eNB) ? "FORWARD":"POSTROUTING",
                        eps_bearer_entry_p->paa.ipv4_address[0],
                        eps_bearer_entry_p->paa.ipv4_address[1],
                        eps_bearer_entry_p->paa.ipv4_address[2],
@@ -789,7 +789,7 @@ sgw_lite_handle_sgi_endpoint_updated(
       ret = snprintf(cmd,
                      256,
                      "iptables -t mangle -I %s -d %u.%u.%u.%u -m mark --mark %u -j GTPUAH --own-ip %u.%u.%u.%u --own-tun %u --peer-ip %u.%u.%u.%u --peer-tun %u --action add",
-                     (spgw_config.sgw_config.local_to_eNB) ? "INPUT":"POSTROUTING",
+                     (spgw_config.sgw_config.local_to_eNB) ? "FORWARD":"POSTROUTING",
                      eps_bearer_entry_p->paa.ipv4_address[0],
                      eps_bearer_entry_p->paa.ipv4_address[1],
                      eps_bearer_entry_p->paa.ipv4_address[2],
diff --git a/openair-cn/SGW-LITE/sgw_lite_task.c b/openair-cn/SGW-LITE/sgw_lite_task.c
index c2349af66c6..7d1c6584781 100644
--- a/openair-cn/SGW-LITE/sgw_lite_task.c
+++ b/openair-cn/SGW-LITE/sgw_lite_task.c
@@ -138,28 +138,33 @@ int sgw_lite_init(char* config_file_name_pP)
 {
   SPGW_APP_DEBUG("Initializing SPGW-APP  task interface\n");
 #if defined (ENABLE_USE_GTPU_IN_KERNEL)
-  spgw_system("modprobe ip_tables", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("modprobe x_tables", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("modprobe ip_tables",    SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("modprobe x_tables",     SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("iptables -P INPUT ACCEPT", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("iptables -F INPUT", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -F INPUT",     SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("iptables -P OUTPUT ACCEPT", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("iptables -F OUTPUT", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -F OUTPUT",    SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("iptables -P FORWARD ACCEPT", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("iptables -F FORWARD", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("iptables -t nat -F", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -F FORWARD",   SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -t nat    -F", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("iptables -t mangle -F", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("iptables -t filter -F", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("iptables -t raw -F", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("ip route flush cache", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -t raw    -F", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -t nat    -Z", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -t mangle -Z", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -t filter -Z", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("iptables -t raw    -Z", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("ip route flush cache",  SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("rmmod xt_GTPUAH xt_GTPURH > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod iptable_raw    > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod iptable_mangle > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod iptable_nat    > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod iptable_filter > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod ip_tables      > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("rmmod xt_state xt_mark xt_GTPUAH xt_GTPURH xt_tcpudp xt_connmark ipt_LOG ipt_MASQUERADE > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("rmmod xt_state xt_mark xt_tcpudp xt_connmark ipt_LOG ipt_MASQUERADE > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod x_tables       > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("rmmod nf_conntrack_netlink nfnetlink nf_nat nf_conntrack_ipv4 nf_conntrack  > /dev/null 2>&1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("modprobe ip_tables", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("modprobe ip_tables",      SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("modprobe iptable_filter", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("modprobe iptable_mangle", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("modprobe iptable_nat",    SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
@@ -167,10 +172,9 @@ int sgw_lite_init(char* config_file_name_pP)
   spgw_system("modprobe ipt_MASQUERADE", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("modprobe ipt_LOG",        SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("modprobe nf_conntrack",   SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("modprobe nf_conntrack_ipv4",   SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("modprobe nf_conntrack_ipv4", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("modprobe nf_nat",         SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("modprobe x_tables", SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
-  spgw_system("sysctl -w net.ipv4.netfilter.ip_conntrack_max=16000", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
+  spgw_system("modprobe x_tables",       SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   spgw_system("sysctl -w net.ipv4.ip_forward=1", SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("sysctl -w net.ipv4.conf.all.accept_local=1",SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
   spgw_system("sysctl -w net.ipv4.conf.all.log_martians=1",SPGW_WARN_ON_ERROR, __FILE__, __LINE__);
diff --git a/openair-cn/SGW-LITE/spgw_config.c b/openair-cn/SGW-LITE/spgw_config.c
index 66f5f2e5602..7eb8dfaf813 100755
--- a/openair-cn/SGW-LITE/spgw_config.c
+++ b/openair-cn/SGW-LITE/spgw_config.c
@@ -296,14 +296,14 @@ int spgw_config_process(spgw_config_t* config_pP)
       ret = -1;
     }
   }
-  if (snprintf(system_cmd, 256,
+ /* if (snprintf(system_cmd, 256,
 	               "iptables -I INPUT -t mangle -i %s ! --protocol sctp   -j CONNMARK --restore-mark",
 	               config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI) > 0) {
     ret += spgw_system(system_cmd, SPGW_ABORT_ON_ERROR, __FILE__, __LINE__);
   } else {
 	SPGW_APP_ERROR("Restore mark\n");
 	ret = -1;
-  }
+  }*/
   if (snprintf(system_cmd, 256,
                "iptables -I PREROUTING -t mangle -i %s ! --protocol sctp   -j CONNMARK --restore-mark",
                config_pP->pgw_config.ipv4.pgw_interface_name_for_SGI) > 0) {
diff --git a/targets/SCRIPTS/msc_gen.py b/targets/SCRIPTS/msc_gen.py
index 49331b36993..f81b72a8e8b 100755
--- a/targets/SCRIPTS/msc_gen.py
+++ b/targets/SCRIPTS/msc_gen.py
@@ -19,9 +19,9 @@ import argparse
 parser = argparse.ArgumentParser()
 parser.add_argument("--diag_rlc_um", "-u", type=str,help="Try to find RLC protocol diagnostics", default="no")
 parser.add_argument("--dir", "-d", type=str,help="Directory where msc logs can be found", default="/tmp")
+parser.add_argument("--profile", "-p", type=str,help="E_UTRAN, EPC", default="EPC")
 args = parser.parse_args()
 
-
 MSCGEN_OUTPUT_TYPE       = "png"
 MAX_MESSAGES_PER_PAGE    = 36
 
@@ -80,22 +80,10 @@ g_diag_rlc_sn = {}
 
 g_sequence_generator = 0
 
-def sequence_number_generator():
-    global g_sequence_generator
-    l_seq = g_sequence_generator
-    g_sequence_generator = g_sequence_generator + 1
-    return l_seq
-
-def file_is_empty(fpath):  
-    return False if os.path.isfile(fpath) and os.path.getsize(fpath) > 0 else True
 
-def parse_oai_log_files():
-    global g_entities_dic
-    global g_entities
-    global g_messages
-    global g_final_display_order_list
-    #open TXT file that contain OAI filtered traces for mscgen
-    filenames = [
+g_filenames = []
+if "E_UTRAN" == args.profile.strip():
+    g_filenames = [
         args.dir+'/openair.msc.ip_ue.log',
         args.dir+'/openair.msc.ip_enb.log',
         args.dir+'/openair.msc.nas_ue.log',
@@ -109,6 +97,14 @@ def parse_oai_log_files():
         args.dir+'/openair.msc.rlc_enb.log',
         args.dir+'/openair.msc.pdcp_enb.log',
         args.dir+'/openair.msc.rrc_enb.log',
+        args.dir+'/openair.msc.s1ap_enb.log',
+        args.dir+'/openair.msc.gtpu_enb.log',
+        args.dir+'/openair.msc.mme_app.log',
+        args.dir+'/openair.msc.nas_mme.log',
+        args.dir+'/openair.msc.gtpu_sgw.log',
+        args.dir+'/openair.msc.s1ap_mme.log']
+elif "EPC" == args.profile.strip():
+    g_filenames = [        
         args.dir+'/openair.msc.s1ap_enb.log',
         args.dir+'/openair.msc.gtpu_enb.log',
         args.dir+'/openair.msc.mme_app.log',
@@ -122,9 +118,25 @@ def parse_oai_log_files():
         args.dir+'/openair.msc.s1ap_mme.log',
         args.dir+'/openair.msc.hss.log']
 
+def sequence_number_generator():
+    global g_sequence_generator
+    l_seq = g_sequence_generator
+    g_sequence_generator = g_sequence_generator + 1
+    return l_seq
+
+def file_is_empty(fpath):  
+    return False if os.path.isfile(fpath) and os.path.getsize(fpath) > 0 else True
+
+def parse_oai_log_files():
+    global g_entities_dic
+    global g_entities
+    global g_messages
+    global g_final_display_order_list
+    #open TXT file that contain OAI filtered traces for mscgen
+
     # we may insert diagnostic events
     event_id_offset = 0
-    for filename in filenames:
+    for filename in g_filenames:
         if file_is_empty(filename):
             continue
         try:
@@ -136,7 +148,7 @@ def parse_oai_log_files():
             lines = fcontent.splitlines()
             for line in lines:
                 if line.strip() != ""  and not line.strip().startswith('#'):
-                    #print ("INPUT LINE:  %s " % line)
+                    print ("INPUT LINE:  %s " % line)
                     partition = line.split(' ',3)
                     event_id = int(partition[0]) + event_id_offset
                     event_type = partition[1]
-- 
GitLab