diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 9537477913ec77e281a83ad1d6b39e96c3f08aa9..c74dd51252c2127f5f884994747f7db2c347cab1 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -398,7 +398,7 @@ add_boolean_option(OAISIM False "specific to oaisim")
 add_boolean_option(OAI_NW_DRIVER_USE_NETLINK True "????")
 add_boolean_option(USE_MME False "this flag is used only one time in lte-softmodem.c")
 add_list_string_option(PACKAGE_NAME "NotDefined" "As per attribute name")
-add_boolean_option(MESSAGE_CHART_GENERATOR True "For generating sequence diagrams")
+add_boolean_option(MESSAGE_CHART_GENERATOR False         "For generating sequence diagrams")
 add_boolean_option(MESSAGE_CHART_GENERATOR_RLC_MAC False "trace RLC-MAC exchanges in sequence diagrams")
 add_boolean_option(MESSAGE_CHART_GENERATOR_PHY     False "trace some PHY exchanges in sequence diagrams")
 ########################
@@ -1327,7 +1327,7 @@ set(lfds ${OPENAIR2_DIR}/UTIL/LFDS/liblfds6.1.1/liblfds611/src/)
 file(GLOB lfds_queue ${lfds}/lfds611_queue/*.c)
 file(GLOB lfds_ring ${lfds}/lfds611_ringbuffer/*.c)
 file(GLOB lfds_slist ${lfds}/lfds611_slist/*.c)
-file(GLOB lfds_stack ${lfds}/lfds611_stack/*.c/)
+file(GLOB lfds_stack ${lfds}/lfds611_stack/*.c)
 file(GLOB lfds_freelist ${lfds}/lfds611_freelist/*.c)
 
 include_directories(${lfds})
@@ -1462,16 +1462,21 @@ add_executable(lte-softmodem
   ${XFORMS_SOURCE}
   ${XFORMS_SOURCE_SOFTMODEM}
   )
+if (MESSAGE_CHART_GENERATOR)
+target_link_libraries (lte-softmodem
+  -Wl,--start-group
+  RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS MSC L2 ${RAL_LIB} ${NAS_LIB} ${ITTI_LIB} ${MIH_LIB}
+  -Wl,--end-group )
+else (MESSAGE_CHART_GENERATOR)
 target_link_libraries (lte-softmodem
   -Wl,--start-group
   RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS L2 ${RAL_LIB} ${NAS_LIB} ${ITTI_LIB} ${MIH_LIB}
   -Wl,--end-group )
+endif(MESSAGE_CHART_GENERATOR)
 target_link_libraries (lte-softmodem ${LIBXML2_LIBRARIES})
 target_link_libraries (lte-softmodem pthread m ${CONFIG_LIBRARIES} rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} sctp ${option_HW_lib} ${XFORMS_LIBRARIES} )
 target_link_libraries (lte-softmodem ${LIBBOOST_LIBRARIES})
-if (MESSAGE_CHART_GENERATOR)
-  target_link_libraries (lte-softmodem MSC)
-endif()
+
 
 # EPC is ??? nodes implementation in one process
 ################################
@@ -1483,15 +1488,21 @@ add_executable(mme_gw
   ${OPENAIRCN_DIR}/SCTP/sctp_primitives_server.c
   ${OPENAIRCN_DIR}/NAS/nas_main.c
   )
+if (MESSAGE_CHART_GENERATOR)
+target_link_libraries (mme_gw
+  -Wl,--start-group
+   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA S6A SGW MME_APP LFDS MSC ${ITTI_LIB} CN_UTILS HASHTABLE
+  -Wl,--end-group
+  pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
+  )
+else (MESSAGE_CHART_GENERATOR)
 target_link_libraries (mme_gw
   -Wl,--start-group
    NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA S6A SGW MME_APP LFDS ${ITTI_LIB} CN_UTILS HASHTABLE
   -Wl,--end-group
   pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
   )
-if (MESSAGE_CHART_GENERATOR)
-  target_link_libraries (mme_gw MSC)
-endif()
+endif(MESSAGE_CHART_GENERATOR)
 
 # Default parameters
 # Does not work on simple install (fqdn in /etc/hosts 127.0.1.1)
@@ -1572,15 +1583,21 @@ add_executable(oai_sgw
   ${OPENAIRCN_DIR}/OAI_SGW/oai_sgw_log.c
   ${OPENAIRCN_DIR}/OAI_SGW/oai_sgw.c
   )
+if (MESSAGE_CHART_GENERATOR)
+target_link_libraries (oai_sgw
+  -Wl,--start-group
+  GTPV1U SECU_CN SECU_OSA S6A SGW CN_UTILS LFDS MSC ${ITTI_LIB}
+  -Wl,--end-group
+  pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
+  )
+else (MESSAGE_CHART_GENERATOR)
 target_link_libraries (oai_sgw
   -Wl,--start-group
   GTPV1U SECU_CN SECU_OSA S6A SGW CN_UTILS LFDS ${ITTI_LIB}
   -Wl,--end-group
   pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
   )
-if (MESSAGE_CHART_GENERATOR)
-  target_link_libraries (oai_sgw MSC)
-endif()
+endif(MESSAGE_CHART_GENERATOR)
 
 # USIM process
 #################
@@ -1632,18 +1649,23 @@ add_executable(oaisim
   ${XFORMS_SOURCE}
 )
 target_include_directories(oaisim PUBLIC  ${OPENAIR_TARGETS}/SIMU/USER)
+if (MESSAGE_CHART_GENERATOR)
+target_link_libraries (oaisim
+  -Wl,--start-group
+  RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS MSC L2 ${RAL_LIB} ${NAS_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
+  -Wl,--end-group )
+else(MESSAGE_CHART_GENERATOR)
 target_link_libraries (oaisim
   -Wl,--start-group
   RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS L2 ${RAL_LIB} ${NAS_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
   -Wl,--end-group )
+endif(MESSAGE_CHART_GENERATOR)
 target_link_libraries (oaisim ${LIBXML2_LIBRARIES} ${LAPACK_LIBRARIES})
 target_link_libraries (oaisim pthread m ${CONFIG_LIBRARIES} rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES}  ${NETTLE_LIBRARIES} sctp ${option_HW_lib}
   ${ATLAS_LIBRARIES} ${XFORMS_LIBRARIES} ${OPENPGM_LIBRARIES})
 #Force link with forms, regardless XFORMS option
 target_link_libraries (oaisim forms)
-if (MESSAGE_CHART_GENERATOR)
-  target_link_libraries (oaisim MSC)
-endif()
+
 
 
 # A all in one network simulator
@@ -1668,18 +1690,22 @@ add_executable(oaisim_nos1
   ${XFORMS_SOURCE}
 )
 target_include_directories(oaisim_nos1 PUBLIC  ${OPENAIR_TARGETS}/SIMU/USER)
+if (MESSAGE_CHART_GENERATOR)
+target_link_libraries (oaisim_nos1
+  -Wl,--start-group
+  RRC_LIB    SECU_CN UTIL HASHTABLE  UDP SCHED_LIB PHY LFDS MSC L2 ${RAL_LIB} ${NAS_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
+  -Wl,--end-group )
+else(MESSAGE_CHART_GENERATOR)
 target_link_libraries (oaisim_nos1
   -Wl,--start-group
   RRC_LIB    SECU_CN UTIL HASHTABLE  UDP SCHED_LIB PHY LFDS L2 ${RAL_LIB} ${NAS_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
   -Wl,--end-group )
+endif(MESSAGE_CHART_GENERATOR)
 target_link_libraries (oaisim_nos1 ${LIBXML2_LIBRARIES} ${LAPACK_LIBRARIES})
 target_link_libraries (oaisim_nos1 pthread m ${CONFIG_LIBRARIES} rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES}  ${NETTLE_LIBRARIES}  ${option_HW_lib}
   ${ATLAS_LIBRARIES} ${XFORMS_LIBRARIES} ${OPENPGM_LIBRARIES})
 #Force link with forms, regardless XFORMS option
 target_link_libraries (oaisim_nos1 forms)
-if (MESSAGE_CHART_GENERATOR)
-  target_link_libraries (oaisim_nos1 MSC)
-endif()
 
 
 # Unitary tests for each piece of L1: example, mbmssim is MBMS L1 simulator
@@ -1721,13 +1747,21 @@ add_executable(test_s1c_mme
   ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c.c
   ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c_scenario.h
   ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c_scenario1.c
+  ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c_scenario.c
+  ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c_scenario.h
+  ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c_s1ap.c
+  ${OPENAIRCN_DIR}/TEST/oaisim_mme_test_s1c_s1ap.h
   ${OPENAIR2_DIR}/ENB_APP/enb_config.c
   ${OPENAIR2_DIR}/ENB_APP/enb_config.h
-  ${s1ap_h}
+  ${OPENAIR2_DIR}/COMMON/commonDef.h
+  ${OPENAIR2_DIR}/COMMON/messages_def.h
+  ${OPENAIR2_DIR}/COMMON/messages_types.h
+  ${OPENAIRCN_DIR}/S1AP/s1ap_eNB_defs.h
+  ${S1AP_DIR}/s1ap_eNB_management_procedures.c
   ${OPENAIR_BIN_DIR}/messages_xml.h
   )
 target_link_libraries (test_s1c_mme
-  -Wl,--start-group SECU_CN S1AP_LIB S1AP_ENB SCTP_CLIENT UTIL LFDS ${ITTI_LIB} -Wl,--end-group pthread m rt crypt sctp ${LIBXML2_LIBRARIES} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
+  -Wl,--start-group SECU_CN S1AP_LIB  SCTP_CLIENT UTIL LFDS ${ITTI_LIB} -Wl,--end-group pthread m rt crypt sctp ${LIBXML2_LIBRARIES} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
   )
 
 
@@ -1738,21 +1772,18 @@ target_link_libraries (test_s1c_mme
 
 #  ???
 ###########################
-add_executable(oaisim_mme
-  ${OPENAIR_BIN_DIR}/messages_xml.h
-  ${OPENAIRCN_DIR}/OAISIM_MME/oai_mme_log.c
-  ${OPENAIRCN_DIR}/OAISIM_MME/oaisim_mme.c
-  ${OPENAIRCN_DIR}/NAS/nas_main.c
-)
-target_link_libraries (oaisim_mme
-  -Wl,--start-group
-   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA S6A S11 SGW MME_APP LFDS MSC ${ITTI_LIB} CN_UTILS HASHTABLE
-  -Wl,--end-group
-  pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
-)
-if (MESSAGE_CHART_GENERATOR)
-  target_link_libraries (oaisim_mme MSC)
-endif()
+#add_executable(oaisim_mme
+#  ${OPENAIR_BIN_DIR}/messages_xml.h
+#  ${OPENAIRCN_DIR}/OAISIM_MME/oai_mme_log.c
+#  ${OPENAIRCN_DIR}/OAISIM_MME/oaisim_mme.c
+#  ${OPENAIRCN_DIR}/NAS/nas_main.c
+#)
+#target_link_libraries (oaisim_mme
+#  -Wl,--start-group
+#   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA S6A S11 SGW MME_APP LFDS MSC ${ITTI_LIB} CN_UTILS HASHTABLE
+#  -Wl,--end-group
+#  pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
+#)
 
 ##################################################
 # Generated specific cases is not regular code
diff --git a/cmake_targets/autotests/test.0101/CMakeLists.txt b/cmake_targets/autotests/test.0101/CMakeLists.txt
index c398c2343a644ee576e22f27f42e39920582b8ab..75e8542cd513d245e5ab24e506547dcf244f5dea 100644
--- a/cmake_targets/autotests/test.0101/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0101/CMakeLists.txt
@@ -15,11 +15,7 @@ set ( ENABLE_RAL False )
 set ( ENABLE_SECURITY False )
 set ( ENABLE_STANDALONE_EPC False )
 set ( ENABLE_USE_CPU_EXECUTION_TIME True )
-set ( ENABLE_USE_GTPU_IN_KERNEL False )
 set ( ENABLE_USE_MME False )
-set ( ENABLE_USE_NETFILTER_FOR_SGI False )
-set ( ENABLE_USE_PCAP_FOR_SGI False )
-set ( ENABLE_USE_RAW_SOCKET_FOR_SGI False )
 set ( ENABLE_VCD_FIFO True )
 set ( ENB_MODE True )
 set ( EPC_BUILD False )
@@ -28,7 +24,6 @@ set ( JUMBO_FRAME True )
 set ( LARGE_SCALE False )
 set ( LINK_ENB_PDCP_TO_GTPV1U False )
 set ( LINK_ENB_PDCP_TO_IP_DRIVER False )
-set ( LINK_PDCP_TO_GTPV1U False )
 set ( LINUX_LIST False )
 set ( LINUX True )
 set ( LOCALIZATION False )
@@ -36,6 +31,9 @@ set ( LOG_NO_THREAD True )
 set ( LOWLATENCY False )
 set ( MAC_CONTEXT 1 )
 set ( MAX_NUM_CCs 1 )
+set ( MESSAGE_CHART_GENERATOR         False )
+set ( MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set ( MESSAGE_CHART_GENERATOR_PHY     False )
 set ( MIH_C_MEDIEVAL_EXTENSIONS True )
 set ( MSG_PRINT False )
 set ( MU_RECEIVER False )
diff --git a/cmake_targets/autotests/test.0102/CMakeLists.txt b/cmake_targets/autotests/test.0102/CMakeLists.txt
index dd0a607ed909ae6c2f271f0cde9a08ae2eff876c..a9c09dbd325e2f6d458f04647067ebdc782062d7 100644
--- a/cmake_targets/autotests/test.0102/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0102/CMakeLists.txt
@@ -15,11 +15,7 @@ set ( ENABLE_RAL False )
 set ( ENABLE_SECURITY False )
 set ( ENABLE_STANDALONE_EPC False )
 set ( ENABLE_USE_CPU_EXECUTION_TIME True )
-set ( ENABLE_USE_GTPU_IN_KERNEL False )
 set ( ENABLE_USE_MME False )
-set ( ENABLE_USE_NETFILTER_FOR_SGI False )
-set ( ENABLE_USE_PCAP_FOR_SGI False )
-set ( ENABLE_USE_RAW_SOCKET_FOR_SGI False )
 set ( ENABLE_VCD_FIFO True )
 set ( ENB_MODE True )
 set ( EPC_BUILD False )
@@ -28,7 +24,6 @@ set ( JUMBO_FRAME True )
 set ( LARGE_SCALE False )
 set ( LINK_ENB_PDCP_TO_GTPV1U False )
 set ( LINK_ENB_PDCP_TO_IP_DRIVER False )
-set ( LINK_PDCP_TO_GTPV1U False )
 set ( LINUX_LIST False )
 set ( LINUX True )
 set ( LOCALIZATION False )
@@ -36,6 +31,9 @@ set ( LOG_NO_THREAD True )
 set ( LOWLATENCY False )
 set ( MAC_CONTEXT 1 )
 set ( MAX_NUM_CCs 1 )
+set ( MESSAGE_CHART_GENERATOR         False )
+set ( MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set ( MESSAGE_CHART_GENERATOR_PHY     False )
 set ( MIH_C_MEDIEVAL_EXTENSIONS True )
 set ( MSG_PRINT False )
 set ( MU_RECEIVER False )
diff --git a/cmake_targets/autotests/test.0103/CMakeLists.txt b/cmake_targets/autotests/test.0103/CMakeLists.txt
index 2ca2c6c57646a340db330f9f9b2d8513dbd4484e..f669263a959e5dcf834ca7c26c886be9cecbb8b0 100644
--- a/cmake_targets/autotests/test.0103/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0103/CMakeLists.txt
@@ -15,11 +15,7 @@ set ( ENABLE_RAL False )
 set ( ENABLE_SECURITY False )
 set ( ENABLE_STANDALONE_EPC False )
 set ( ENABLE_USE_CPU_EXECUTION_TIME True )
-set ( ENABLE_USE_GTPU_IN_KERNEL False )
 set ( ENABLE_USE_MME False )
-set ( ENABLE_USE_NETFILTER_FOR_SGI False )
-set ( ENABLE_USE_PCAP_FOR_SGI False )
-set ( ENABLE_USE_RAW_SOCKET_FOR_SGI False )
 set ( ENABLE_VCD_FIFO True )
 set ( ENB_MODE True )
 set ( EPC_BUILD False )
@@ -28,7 +24,6 @@ set ( JUMBO_FRAME True )
 set ( LARGE_SCALE False )
 set ( LINK_ENB_PDCP_TO_GTPV1U False )
 set ( LINK_ENB_PDCP_TO_IP_DRIVER False )
-set ( LINK_PDCP_TO_GTPV1U False )
 set ( LINUX False )
 set ( LINUX_LIST False )
 set ( LOCALIZATION False )
@@ -36,6 +31,9 @@ set ( LOG_NO_THREAD True )
 set ( LOWLATENCY False )
 set ( MAC_CONTEXT 1 )
 set ( MAX_NUM_CCs 1 )
+set ( MESSAGE_CHART_GENERATOR         False )
+set ( MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set ( MESSAGE_CHART_GENERATOR_PHY     False )
 set ( MIH_C_MEDIEVAL_EXTENSIONS True )
 set ( MSG_PRINT False )
 set ( MU_RECEIVER False )
diff --git a/cmake_targets/autotests/test.0104/CMakeLists.txt b/cmake_targets/autotests/test.0104/CMakeLists.txt
index 6f93e687e5d0a4cca1dc22440035b27034576f23..eab37127a72375744e2a737e31a1e31dff13c188 100644
--- a/cmake_targets/autotests/test.0104/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0104/CMakeLists.txt
@@ -10,4 +10,8 @@ set(RANDOM_BF False)
 set(PBS_SIM False)
 set(PERFECT_CE True)
 
+set(MESSAGE_CHART_GENERATOR         False)
+set(MESSAGE_CHART_GENERATOR_RLC_MAC False)
+set(MESSAGE_CHART_GENERATOR_PHY     False)
+
 include(${CMAKE_CURRENT_SOURCE_DIR}/../../CMakeLists.txt)
diff --git a/cmake_targets/autotests/test.0106/CMakeLists.txt b/cmake_targets/autotests/test.0106/CMakeLists.txt
index cc84cd5962726eb14514aa1b2d180be64b225a95..e44ab35d707eba09c54e37a913d2707a28aee5f8 100644
--- a/cmake_targets/autotests/test.0106/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0106/CMakeLists.txt
@@ -17,7 +17,7 @@ set(ENABLE_VCD_FIFO True)
 set(HARD_RT False)
 set(JUMBO_FRAME True)
 set(LARGE_SCALE False)
-set(LINK_PDCP_TO_GTPV1U False)
+set(LINK_ENB_PDCP_TO_GTPV1U False)
 set(LINUX_LIST False)
 set(LINUX True)
 set(LOCALIZATION False)
@@ -25,6 +25,9 @@ set(LOG_NO_THREAD True)
 set(LOWLATENCY False)
 set(MAC_CONTEXT 1)
 set(MAX_NUM_CCs 1)
+set(MESSAGE_CHART_GENERATOR         False )
+set(MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set(MESSAGE_CHART_GENERATOR_PHY     False )
 set(MIH_C_MEDIEVAL_EXTENSIONS True)
 set(MSG_PRINT False)
 set(MU_RECEIVER False)
diff --git a/cmake_targets/autotests/test.0107/CMakeLists.txt b/cmake_targets/autotests/test.0107/CMakeLists.txt
index a99358a2ad5a32252397a0287547edf0e16b4ff3..84f9a7e7ff30db98d5c2ea36ab5a2a61f9175320 100644
--- a/cmake_targets/autotests/test.0107/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0107/CMakeLists.txt
@@ -15,11 +15,7 @@ set ( ENABLE_RAL False )
 set ( ENABLE_SECURITY False )
 set ( ENABLE_STANDALONE_EPC False )
 set ( ENABLE_USE_CPU_EXECUTION_TIME True )
-set ( ENABLE_USE_GTPU_IN_KERNEL False )
 set ( ENABLE_USE_MME False )
-set ( ENABLE_USE_NETFILTER_FOR_SGI False )
-set ( ENABLE_USE_PCAP_FOR_SGI False )
-set ( ENABLE_USE_RAW_SOCKET_FOR_SGI False )
 set ( ENABLE_VCD_FIFO True )
 set ( ENB_MODE True )
 set ( EPC_BUILD False )
@@ -28,7 +24,6 @@ set ( JUMBO_FRAME True )
 set ( LARGE_SCALE False )
 set ( LINK_ENB_PDCP_TO_GTPV1U False )
 set ( LINK_ENB_PDCP_TO_IP_DRIVER False )
-set ( LINK_PDCP_TO_GTPV1U False )
 set ( LINUX_LIST False )
 set ( LINUX True )
 set ( LOCALIZATION False )
@@ -36,6 +31,9 @@ set ( LOG_NO_THREAD True )
 set ( LOWLATENCY False )
 set ( MAC_CONTEXT 1 )
 set ( MAX_NUM_CCs 1 )
+set ( MESSAGE_CHART_GENERATOR         False )
+set ( MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set ( MESSAGE_CHART_GENERATOR_PHY     False )
 set ( MIH_C_MEDIEVAL_EXTENSIONS True )
 set ( MSG_PRINT False )
 set ( MU_RECEIVER False )
diff --git a/cmake_targets/autotests/test.0108/CMakeLists.txt b/cmake_targets/autotests/test.0108/CMakeLists.txt
index daa83facf499b2f7c6825c8e7466b9725e1a0e24..22708235ee819b0cca91a26a2f425ac76c163df8 100644
--- a/cmake_targets/autotests/test.0108/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0108/CMakeLists.txt
@@ -17,7 +17,7 @@ set(ENABLE_VCD_FIFO True)
 set(HARD_RT False)
 set(JUMBO_FRAME True)
 set(LARGE_SCALE False)
-set(LINK_PDCP_TO_GTPV1U False)
+set(LINK_ENB_PDCP_TO_GTPV1U False)
 set(LINUX_LIST False)
 set(LINUX True)
 set(LOCALIZATION False)
@@ -25,6 +25,9 @@ set(LOG_NO_THREAD True)
 set(LOWLATENCY False)
 set(MAC_CONTEXT 1)
 set(MAX_NUM_CCs 1)
+set(MESSAGE_CHART_GENERATOR         False)
+set(MESSAGE_CHART_GENERATOR_RLC_MAC False)
+set(MESSAGE_CHART_GENERATOR_PHY     False)
 set(MIH_C_MEDIEVAL_EXTENSIONS True)
 set(MSG_PRINT False)
 set(MU_RECEIVER False)
@@ -34,7 +37,6 @@ set(NAS_UE True)
 set(NEW_FFT True)
 set(NO_RRM True)
 set(OAI_EMU True)
-set(OAI_EMU True)
 set(OAI_NW_DRIVER_TYPE_ETHERNET False)
 set(OPENAIR1 False)
 set(OPENAIR2 True)
diff --git a/cmake_targets/autotests/test.0114/CMakeLists.txt b/cmake_targets/autotests/test.0114/CMakeLists.txt
index 893b203b07c1124ee690a86591f1718ddd649d23..b7970ec7c20356772d111d4fdc76aea7332b0f6a 100644
--- a/cmake_targets/autotests/test.0114/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0114/CMakeLists.txt
@@ -17,7 +17,7 @@ set(ENABLE_VCD_FIFO True)
 set(HARD_RT False)
 set(JUMBO_FRAME True)
 set(LARGE_SCALE False)
-set(LINK_PDCP_TO_GTPV1U False)
+set(LINK_ENB_PDCP_TO_GTPV1U False)
 set(LINUX_LIST False)
 set(LINUX True)
 set(LOCALIZATION False)
diff --git a/cmake_targets/autotests/test.0115/CMakeLists.txt b/cmake_targets/autotests/test.0115/CMakeLists.txt
index 83936f11593e11ee201c64d60120af73dff70739..42f9932da4d32ec417fdcb0eb687ab3fd1551a38 100644
--- a/cmake_targets/autotests/test.0115/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0115/CMakeLists.txt
@@ -15,11 +15,7 @@ set ( ENABLE_RAL True )
 set ( ENABLE_SECURITY False )
 set ( ENABLE_STANDALONE_EPC False )
 set ( ENABLE_USE_CPU_EXECUTION_TIME True )
-set ( ENABLE_USE_GTPU_IN_KERNEL False )
 set ( ENABLE_USE_MME False )
-set ( ENABLE_USE_NETFILTER_FOR_SGI False )
-set ( ENABLE_USE_PCAP_FOR_SGI False )
-set ( ENABLE_USE_RAW_SOCKET_FOR_SGI False )
 set ( ENABLE_VCD_FIFO True )
 set ( ENB_MODE True )
 set ( EPC_BUILD False )
@@ -28,7 +24,6 @@ set ( JUMBO_FRAME True )
 set ( LARGE_SCALE False )
 set ( LINK_ENB_PDCP_TO_GTPV1U False )
 set ( LINK_ENB_PDCP_TO_IP_DRIVER False )
-set ( LINK_PDCP_TO_GTPV1U False )
 set ( LINUX_LIST False )
 set ( LINUX True )
 set ( LOCALIZATION False )
@@ -36,6 +31,9 @@ set ( LOG_NO_THREAD True )
 set ( LOWLATENCY False )
 set ( MAC_CONTEXT 1 )
 set ( MAX_NUM_CCs 1 )
+set ( MESSAGE_CHART_GENERATOR         False )
+set ( MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set ( MESSAGE_CHART_GENERATOR_PHY     False )
 set ( MIH_C_MEDIEVAL_EXTENSIONS True )
 set ( MSG_PRINT False )
 set ( MU_RECEIVER False )
diff --git a/cmake_targets/autotests/test.0120/CMakeLists.txt b/cmake_targets/autotests/test.0120/CMakeLists.txt
index dd0a607ed909ae6c2f271f0cde9a08ae2eff876c..a9c09dbd325e2f6d458f04647067ebdc782062d7 100644
--- a/cmake_targets/autotests/test.0120/CMakeLists.txt
+++ b/cmake_targets/autotests/test.0120/CMakeLists.txt
@@ -15,11 +15,7 @@ set ( ENABLE_RAL False )
 set ( ENABLE_SECURITY False )
 set ( ENABLE_STANDALONE_EPC False )
 set ( ENABLE_USE_CPU_EXECUTION_TIME True )
-set ( ENABLE_USE_GTPU_IN_KERNEL False )
 set ( ENABLE_USE_MME False )
-set ( ENABLE_USE_NETFILTER_FOR_SGI False )
-set ( ENABLE_USE_PCAP_FOR_SGI False )
-set ( ENABLE_USE_RAW_SOCKET_FOR_SGI False )
 set ( ENABLE_VCD_FIFO True )
 set ( ENB_MODE True )
 set ( EPC_BUILD False )
@@ -28,7 +24,6 @@ set ( JUMBO_FRAME True )
 set ( LARGE_SCALE False )
 set ( LINK_ENB_PDCP_TO_GTPV1U False )
 set ( LINK_ENB_PDCP_TO_IP_DRIVER False )
-set ( LINK_PDCP_TO_GTPV1U False )
 set ( LINUX_LIST False )
 set ( LINUX True )
 set ( LOCALIZATION False )
@@ -36,6 +31,9 @@ set ( LOG_NO_THREAD True )
 set ( LOWLATENCY False )
 set ( MAC_CONTEXT 1 )
 set ( MAX_NUM_CCs 1 )
+set ( MESSAGE_CHART_GENERATOR         False )
+set ( MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set ( MESSAGE_CHART_GENERATOR_PHY     False )
 set ( MIH_C_MEDIEVAL_EXTENSIONS True )
 set ( MSG_PRINT False )
 set ( MU_RECEIVER False )
diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index bfc0a6e2d442ca5defbdb4ed80ee046f4e2440ad..f7a8cc945508129473e9e879f837a129d2b3dac8 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -459,13 +459,13 @@ function main() {
     echo "set(RRC_ASN1_VERSION \"${REL}\")" >>  $cmake_file
     echo "set(ENABLE_VCD_FIFO $VCD_TIMING )" >>  $cmake_file
     echo 'include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)' >> $cmake_file
-    [ "$CLEAN" = "1" ] && rm -rf $DIR/oaisim_mme_build_oai/build
-    mkdir -p $DIR/oaisim_mme_build_oai/build
-    cd $DIR/oaisim_mme_build_oai/build
-    cmake ..
-    compilations \
-	  oaisim_mme_build_oai oaisim_mme \
-	  oaisim_mme $dbin/oaisim_mme.$REL
+    #[ "$CLEAN" = "1" ] && rm -rf $DIR/oaisim_mme_build_oai/build
+    #mkdir -p $DIR/oaisim_mme_build_oai/build
+    #cd $DIR/oaisim_mme_build_oai/build
+    #cmake ..
+    #compilations \
+	#  oaisim_mme_build_oai oaisim_mme \
+	#  oaisim_mme $dbin/oaisim_mme.$REL
   fi
 
   # EPC compilation
diff --git a/cmake_targets/epc_build_oai/CMakeLists.template b/cmake_targets/epc_build_oai/CMakeLists.template
index b26a42445f30b14abaf59d39abc5445de24255ac..da80f6d4d252b9622b0550cc64394d8724230474 100644
--- a/cmake_targets/epc_build_oai/CMakeLists.template
+++ b/cmake_targets/epc_build_oai/CMakeLists.template
@@ -26,7 +26,7 @@ set (  FLAG_GTPV1U_KERNEL_THREAD_SOCK_NO_WAIT False)
 set (  HARD_RT False )
 set (  JUMBO_FRAME False )
 set (  LARGE_SCALE False )
-set (  LINK_PDCP_TO_GTPV1U False )
+set (  LINK_ENB_PDCP_TO_GTPV1U False )
 set (  LINUX_LIST False )
 set (  LINUX False )
 set (  LOCALIZATION False )
diff --git a/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template b/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template
index c531d9f7eb2bed957d8c0d86b0bf01c3ad5c34d0..6a4d128bbf79b05855a488ba96554d09675d2714 100644
--- a/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template
+++ b/cmake_targets/oaisim_noS1_build_oai/CMakeLists.template
@@ -31,9 +31,9 @@ set (  LOG_NO_THREAD 1 )
 set (  LOWLATENCY False )
 set (  MAC_CONTEXT 1 )
 set (  MAX_NUM_CCs 1 )
-set (  MESSAGE_CHART_GENERATOR         True )
-set (  MESSAGE_CHART_GENERATOR_RLC_MAC True )
-set (  MESSAGE_CHART_GENERATOR_PHY     True )
+set (  MESSAGE_CHART_GENERATOR         False )
+set (  MESSAGE_CHART_GENERATOR_RLC_MAC False )
+set (  MESSAGE_CHART_GENERATOR_PHY     False )
 set (  MIH_C_MEDIEVAL_EXTENSIONS False )
 set (  MSG_PRINT False )
 set (  MU_RECEIVER False )
diff --git a/cmake_targets/tools/run_enb_ue_virt_noS1 b/cmake_targets/tools/run_enb_ue_virt_noS1
index 82f302ff2e6bd025ee49493e08788456a8a7bf1a..0665762003da30af023addbb4f3b241ab17e7269 100755
--- a/cmake_targets/tools/run_enb_ue_virt_noS1
+++ b/cmake_targets/tools/run_enb_ue_virt_noS1
@@ -130,7 +130,6 @@ function main()
 
       -m | --mscgen)
         MSC_DIR=$2
-        # can omit file name if last arg on the line
         if [ -d  "$MSC_DIR" ]; then
           echo "setting mscgen log files to dir: $MSC_DIR"
           run_mscgen=1
@@ -146,10 +145,10 @@ function main()
         exe_arguments="$exe_arguments -V /tmp/oai_gtk_wave.vcd"
         shift ;
         ;;
-      -W | ----wireshark-l2)
+      -W | --wireshark-l2)
         echo "setting l2 pcap dump output"
         exe_arguments="$exe_arguments -P wireshark"
-        shift 2;
+        shift 1;
         ;;
       *)   
         echo "Unknown option $1"
@@ -196,11 +195,11 @@ function main()
   fi
    
   if [ $run_gdb -eq 0 ]; then 
-    exec $SUDO $OPENAIR_DIR/targets/bin/oaisim_nos1 $exe_arguments | tee /tmp/enb_ue_nos1.log.txt
+    exec $SUDO $OPENAIR_DIR/targets/bin/oaisim_nos1.Rel10 $exe_arguments | tee /tmp/enb_ue_nos1.log.txt
   else
     touch      ~/.gdb_enb_ue_nos1
     chmod 777  ~/.gdb_enb_ue_nos1
-    echo "file $OPENAIR_DIR/targets/bin/oaisim_nos1" > ~/.gdb_enb_ue_nos1
+    echo "file $OPENAIR_DIR/targets/bin/oaisim_nos1.Rel10" > ~/.gdb_enb_ue_nos1
     echo "set args $exe_arguments" >> ~/.gdb_enb_ue_nos1
     echo "run"                        >> ~/.gdb_enb_ue_nos1
     cat ~/.gdb_enb_ue_nos1
diff --git a/common/utils/itti/intertask_interface.c b/common/utils/itti/intertask_interface.c
index 3207e82463e292b2bd0548465e92d485391e2b0f..7bb06121e4cddb3577504c34403fd3249f4d7369 100644
--- a/common/utils/itti/intertask_interface.c
+++ b/common/utils/itti/intertask_interface.c
@@ -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));
     }
   }
diff --git a/common/utils/itti/timer.c b/common/utils/itti/timer.c
index ec63c9fe9d0659b5af41389f0c16603841a95549..25f70f04d791e8e8e964237936a7ba158458aad4 100644
--- a/common/utils/itti/timer.c
+++ b/common/utils/itti/timer.c
@@ -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;
diff --git a/common/utils/msc/msc.c b/common/utils/msc/msc.c
index dcb620381f9d30d2ab69f753521fc81f5a74beb4..6429cfb46e7865c9e4890b0583d8dbbab72f1eff 100644
--- a/common/utils/msc/msc.c
+++ b/common/utils/msc/msc.c
@@ -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,523 +38,543 @@
 #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_end(void)
+void msc_flush_messages(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));
-		  }
-	  }
+  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_log_declare_proto(
-    const msc_proto_t  protoP
-  )
+void msc_end(void)
 //------------------------------------------------------------------------------
 {
   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));
-      }
+  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));
     }
   }
 }
+
 //------------------------------------------------------------------------------
-void msc_log_event(
-    const msc_proto_t  protoP,
-    char *format, ...)
+void msc_log_declare_proto(
+    const msc_proto_t  protoP
+  )
 //------------------------------------------------------------------------------
 {
-  va_list    args;
-  int        rv;
-  uint64_t local_msc_event_counter = msc_event_counter;
+  int               rv             = 0;
+  msc_queue_item_t *new_item_p     = NULL;
+  char             *char_message_p = NULL;
 
-  msc_event_counter++;
+  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) {
 
-  if ((protoP < MIN_MSC_PROTOS) || (protoP >= MAX_MSC_PROTOS)) {
-      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]);
-      }
-      va_start(args, format);
-      rv = vfprintf(msc_fd[protoP], format, args);
-      va_end(args);
-      if (rv < 0) {
-         fprintf(stderr, "Error while logging MSC event : %s", &msc_proto2str[protoP][0]);
-      }
-      rv = fprintf(msc_fd[protoP], "\n");
-      if (rv < 0) {
-         fprintf(stderr, "Error while logging MSC event : %s", &msc_proto2str[protoP][0]);
-      }
-#if 1
-	  rv = fflush(msc_fd[protoP]);
-	  if (rv != 0) {
-		  fprintf(stderr, "Error while flushing stream of MSC log file: %s", strerror(errno));
+	  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");
 	  }
-#endif
+      free(new_item_p);
+	} else {
+      fprintf(stderr, "Error while malloc in MSC");
+	}
   }
 }
 //------------------------------------------------------------------------------
-void msc_log_rx_message(
-    const msc_proto_t  receiverP,
-    const msc_proto_t  senderP,
-    const char*        bytesP,
-    const unsigned int num_bytes,
+void msc_log_event(
+    const msc_proto_t  protoP,
     char *format, ...)
 //------------------------------------------------------------------------------
 {
-  va_list    args;
-  int        rv;
-  uint64_t   mac = 0;
-  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 ((receiverP < MIN_MSC_PROTOS) || (receiverP >= MAX_MSC_PROTOS) ||
-      (senderP < MIN_MSC_PROTOS)   || (senderP >= MAX_MSC_PROTOS)) {
+  if ((MIN_MSC_PROTOS > protoP) || (MAX_MSC_PROTOS <= protoP)) {
       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]);
-      }
-      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_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++;
+  new_item_p = malloc(sizeof(msc_queue_item_t));
+  if (NULL != new_item_p) {
 
-  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]);
+    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[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 event : %s", &g_msc_proto2str[protoP][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]);
+      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;
       }
+      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);
+	  }
+    } 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_tx_message(
-    const msc_proto_t  senderP,
-    const msc_proto_t  receiverP,
-    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 (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]);
-      }
+  if ((MIN_MSC_PROTOS > proto1P) || (MAX_MSC_PROTOS <= proto1P) ||
+	  (MIN_MSC_PROTOS > proto2P)   || (MAX_MSC_PROTOS <= proto2P)  ) {
+    return;
   }
-}
-
-//------------------------------------------------------------------------------
-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++;
+  new_item_p = malloc(sizeof(msc_queue_item_t));
+  if (NULL != new_item_p) {
 
-  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]);
+    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[senderP], 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 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 ((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;
       }
-      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);
 }
 
 
diff --git a/common/utils/msc/msc.h b/common/utils/msc/msc.h
index c7d541e5a69b694fa349d99005e44416915fc59d..e3b70e575e983d4e281afdc2c318f863c811f686 100644
--- a/common/utils/msc/msc.h
+++ b/common/utils/msc/msc.h
@@ -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...)
diff --git a/openair-cn/COMMON/tasks_def.h b/openair-cn/COMMON/tasks_def.h
index 0334eb45c68dae9b1675484395bb1e5a6be826aa..e2577780522996a1d642c17045779479025997b6 100644
--- a/openair-cn/COMMON/tasks_def.h
+++ b/openair-cn/COMMON/tasks_def.h
@@ -51,3 +51,5 @@ TASK_DEF(TASK_SCTP,     TASK_PRIORITY_MED, 200)
 TASK_DEF(TASK_SPGW_APP, TASK_PRIORITY_MED, 200)
 /// UDP task
 TASK_DEF(TASK_UDP,      TASK_PRIORITY_MED, 200)
+//MESSAGE GENERATOR TASK
+TASK_DEF(TASK_MSC,      TASK_PRIORITY_MED,          200)
diff --git a/openair-cn/GTPV1-U/GTPUAH/xt_GTPUAH.c b/openair-cn/GTPV1-U/GTPUAH/xt_GTPUAH.c
index 1da3edbdb2deb99709a059065fdd27e3c27a9f64..d9f86331377184d01c0eeae10ddf3a7f97babbf7 100755
--- a/openair-cn/GTPV1-U/GTPUAH/xt_GTPUAH.c
+++ b/openair-cn/GTPV1-U/GTPUAH/xt_GTPUAH.c
@@ -52,9 +52,9 @@
 #    error "Kernel version is not defined!!!! Exiting."
 #endif
 
-#define TRACE_IN_KERN_LOG 1
+#define GTPU_TRACE_IN_KERN_LOG 0
 
-#if defined(TRACE_IN_KERN_LOG)
+#if defined(GTPU_TRACE_IN_KERN_LOG)
 #define PR_INFO(fORMAT, aRGS...) pr_info(fORMAT, ##aRGS)
 #else
 #define PR_INFO(fORMAT, aRGS...)
diff --git a/openair-cn/GTPV1-U/gtpv1u_eNB.c b/openair-cn/GTPV1-U/gtpv1u_eNB.c
index 5514483b67e706978dbd1a31ac9eba46a80cd971..b9735f728f9c2ded2594c3190d5ee6e9e4a93b4f 100644
--- a/openair-cn/GTPV1-U/gtpv1u_eNB.c
+++ b/openair-cn/GTPV1-U/gtpv1u_eNB.c
@@ -1000,6 +1000,7 @@ void *gtpv1u_eNB_task(void *args)
   rc = gtpv1u_eNB_init();
   AssertFatal(rc == 0, "gtpv1u_eNB_init Failed");
   itti_mark_task_ready(TASK_GTPV1_U);
+  MSC_START_USE();
 
   while(1) {
     /* Trying to fetch a message from the message queue.
diff --git a/openair-cn/GTPV1-U/gtpv1u_task.c b/openair-cn/GTPV1-U/gtpv1u_task.c
index 74d95b63e90769f8b831bd2bc4fd60ce75e10152..01f569349b41b1c541532fa243c37822fde882f3 100644
--- a/openair-cn/GTPV1-U/gtpv1u_task.c
+++ b/openair-cn/GTPV1-U/gtpv1u_task.c
@@ -50,6 +50,7 @@
 #include "NwLog.h"
 #include "gtpv1u_sgw_defs.h"
 #include "NwGtpv1uPrivate.h"
+#include "msc.h"
 
 //static NwGtpv1uStackHandleT gtpv1u_stack = 0;
 static gtpv1u_data_t        gtpv1u_sgw_data;
@@ -390,6 +391,7 @@ static NwGtpv1uRcT gtpv1u_stop_timer_wrapper(
 static void *gtpv1u_thread(void *args)
 {
   itti_mark_task_ready(TASK_GTPV1_U);
+  MSC_START_USE();
 
   while(1) {
     /* Trying to fetch a message from the message queue.
diff --git a/openair-cn/MME_APP/mme_app_main.c b/openair-cn/MME_APP/mme_app_main.c
index 22ebe296584374fd65f1037bf420c4a9d36f3b77..ddd00e1fafa27c7a119ff9b548582d8f2778a118 100644
--- a/openair-cn/MME_APP/mme_app_main.c
+++ b/openair-cn/MME_APP/mme_app_main.c
@@ -51,6 +51,7 @@ void *mme_app_thread(void *args);
 void *mme_app_thread(void *args)
 {
   itti_mark_task_ready(TASK_MME_APP);
+  MSC_START_USE();
 
   while(1) {
     MessageDef *received_message_p = NULL;
diff --git a/openair-cn/NAS/EURECOM-NAS/src/util/nas_timer.c b/openair-cn/NAS/EURECOM-NAS/src/util/nas_timer.c
index 4eea8c36cefb96a851f5d360f579756555ce8111..f1363433f2b3bbaaf7048f5e70ef82256fe3d9ed 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/util/nas_timer.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/util/nas_timer.c
@@ -60,6 +60,7 @@ Description Timer utilities
 #endif
 #include "nas_timer.h"
 #include "commonDef.h"
+#include "msc.h"
 
 /****************************************************************************/
 /****************  E X T E R N A L    D E F I N I T I O N S  ****************/
diff --git a/openair-cn/NAS/nas_main.c b/openair-cn/NAS/nas_main.c
index e2f9000285aa9b39273010b11e6e889afca66e43..88939f93c248f342ad633d7005a55d52b686e741 100644
--- a/openair-cn/NAS/nas_main.c
+++ b/openair-cn/NAS/nas_main.c
@@ -34,8 +34,8 @@
 
 #include "intertask_interface.h"
 #include "mme_config.h"
-
 #include "nas_defs.h"
+#include "msc.h"
 
 #if !defined(DISABLE_USE_NAS)
 # include "nas_network.h"
@@ -52,6 +52,7 @@
 static void *nas_intertask_interface(void *args_p)
 {
   itti_mark_task_ready(TASK_NAS_MME);
+  MSC_START_USE();
 
   while(1) {
     MessageDef *received_message_p;
diff --git a/openair-cn/NAS/nas_ue_task.c b/openair-cn/NAS/nas_ue_task.c
index ef9b7af02a2c05d79a22eee2d19d4719c164791b..48c15a4835c65b6924fc0b26b452853bfdf3ee38 100644
--- a/openair-cn/NAS/nas_ue_task.c
+++ b/openair-cn/NAS/nas_ue_task.c
@@ -36,6 +36,7 @@
 # include "user_api.h"
 # include "nas_parser.h"
 # include "nas_proc.h"
+# include "msc.h"
 
 # define NAS_UE_AUTOSTART 1
 
@@ -76,7 +77,7 @@ void *nas_ue_task(void *args_p)
   int                   result;
 
   itti_mark_task_ready (TASK_NAS_UE);
-
+  MSC_START_USE();
   /* Initialize UE NAS (EURECOM-NAS) */
   {
     /* Initialize user interface (to exchange AT commands with user process) */
diff --git a/openair-cn/OAI_EPC/oai_epc.c b/openair-cn/OAI_EPC/oai_epc.c
index c7808275771006da2ec5711058963732e7c6b3f0..aea64ab3c7153e67405723f2ae71936e8cb029d7 100644
--- a/openair-cn/OAI_EPC/oai_epc.c
+++ b/openair-cn/OAI_EPC/oai_epc.c
@@ -67,15 +67,15 @@
 
 int main(int argc, char *argv[])
 {
-  /* Parse the command line for options and set the mme_config accordingly. */
-  CHECK_INIT_RETURN(config_parse_opt_line(argc, argv, &mme_config) < 0);
 
-  /* Calling each layer init function */
-  CHECK_INIT_RETURN(log_init(&mme_config, oai_epc_log_specific));
   CHECK_INIT_RETURN(itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX,
                               tasks_info, messages_info, messages_definition_xml,
                               mme_config.itti_config.log_file));
+  /* Parse the command line for options and set the mme_config accordingly. */
+  CHECK_INIT_RETURN(config_parse_opt_line(argc, argv, &mme_config) < 0);
 
+  /* Calling each layer init function */
+  CHECK_INIT_RETURN(log_init(&mme_config, oai_epc_log_specific));
   CHECK_INIT_RETURN(nas_init(&mme_config));
   CHECK_INIT_RETURN(sctp_init(&mme_config));
   CHECK_INIT_RETURN(udp_init(&mme_config));
diff --git a/openair-cn/S1AP/s1ap_eNB.c b/openair-cn/S1AP/s1ap_eNB.c
index 8841127929f42232d40880802669b6cac3214881..46e968457bd47bca5339e9e705d4c5d61a97acd5 100644
--- a/openair-cn/S1AP/s1ap_eNB.c
+++ b/openair-cn/S1AP/s1ap_eNB.c
@@ -56,7 +56,7 @@
 #include "s1ap_eNB_itti_messaging.h"
 
 #include "s1ap_eNB_ue_context.h" // test, to be removed
-
+#include "msc.h"
 
 #include "assertions.h"
 #include "conversions.h"
@@ -264,6 +264,7 @@ void *s1ap_eNB_task(void *arg)
   s1ap_eNB_prepare_internal_data();
 
   itti_mark_task_ready(TASK_S1AP);
+  MSC_START_USE();
 
   while (1) {
     itti_receive_msg(TASK_S1AP, &received_msg);
diff --git a/openair-cn/S1AP/s1ap_mme.c b/openair-cn/S1AP/s1ap_mme.c
index 5112ec30ced8814ced4100b004d28c06ecfbbe48..a599d32c680d14b1871f5ebbf54d704416c171a6 100644
--- a/openair-cn/S1AP/s1ap_mme.c
+++ b/openair-cn/S1AP/s1ap_mme.c
@@ -48,6 +48,7 @@
 
 #include "s1ap_mme_nas_procedures.h"
 #include "s1ap_mme_retransmission.h"
+#include "msc.h"
 
 #define S1AP_DEBUG_LIST
 #ifdef S1AP_DEBUG_LIST
@@ -95,6 +96,7 @@ void *s1ap_mme_thread(void *args)
   MessageDef *received_message_p;
 
   itti_mark_task_ready(TASK_S1AP);
+  MSC_START_USE();
 
   while(1) {
     /* Trying to fetch a message from the message queue.
diff --git a/openair-cn/S6A/s6a_task.c b/openair-cn/S6A/s6a_task.c
index 9849b6caba32e0443638735bb3a5962572fcaa33..2ee79ac3ab052298fc33e32f3f65445d91927ca7 100644
--- a/openair-cn/S6A/s6a_task.c
+++ b/openair-cn/S6A/s6a_task.c
@@ -45,6 +45,7 @@
 #include "s6a_messages.h"
 
 #include "assertions.h"
+#include "msc.h"
 
 #if defined(DISABLE_USE_HSS)
 # error "Disabling HSS support is currently not supported   \
@@ -67,6 +68,7 @@ static void fd_gnutls_debug(int level, const char *str)
 void *s6a_thread(void *args)
 {
   itti_mark_task_ready(TASK_S6A);
+  MSC_START_USE();
 
   while(1) {
     MessageDef *received_message_p = NULL;
diff --git a/openair-cn/SCTP/sctp_eNB_task.c b/openair-cn/SCTP/sctp_eNB_task.c
index 8a7e50ee5f762199772ae2d04fe0b02c5c2e1d87..e2238fddca10f5ea9ee8fbf4887dc60da5cbf93f 100644
--- a/openair-cn/SCTP/sctp_eNB_task.c
+++ b/openair-cn/SCTP/sctp_eNB_task.c
@@ -55,6 +55,7 @@
 #include "sctp_default_values.h"
 #include "sctp_common.h"
 #include "sctp_eNB_itti_messaging.h"
+#include "msc.h"
 
 /* Used to format an uint32_t containing an ipv4 address */
 #define IPV4_ADDR    "%u.%u.%u.%u"
@@ -805,6 +806,7 @@ void *sctp_eNB_task(void *arg)
   STAILQ_INIT(&sctp_cnx_list);
 
   itti_mark_task_ready(TASK_SCTP);
+  MSC_START_USE();
 
   while (1) {
     itti_receive_msg(TASK_SCTP, &received_msg);
diff --git a/openair-cn/SCTP/sctp_primitives_server.c b/openair-cn/SCTP/sctp_primitives_server.c
index 59f7f53aa6262972a405473e9d9081553490f968..654d0b6f4d25616689b062dbe2b2c1cf06921bb0 100644
--- a/openair-cn/SCTP/sctp_primitives_server.c
+++ b/openair-cn/SCTP/sctp_primitives_server.c
@@ -60,6 +60,7 @@
 
 #include "sctp_common.h"
 #include "sctp_itti_messaging.h"
+#include "msc.h"
 
 #define SCTP_DUMP_LIST
 
@@ -553,6 +554,7 @@ void *sctp_receiver_thread(void *args_p)
 
   FD_SET(sctp_arg_p->sd, &master);
   fdmax = sctp_arg_p->sd; /* so far, it's this one*/
+  MSC_START_USE();
 
   while(1) {
 
@@ -616,6 +618,7 @@ void *sctp_receiver_thread(void *args_p)
 static void *sctp_intertask_interface(void *args_p)
 {
   itti_mark_task_ready(TASK_SCTP);
+  MSC_START_USE();
 
   while(1) {
     MessageDef *received_message_p;
diff --git a/openair-cn/SGW-LITE/sgw_lite_task.c b/openair-cn/SGW-LITE/sgw_lite_task.c
index 46a51d2207472414e0bd97b8c13a76324b832810..27f5836bb41a97f2fce4d673333ea282ee501520 100644
--- a/openair-cn/SGW-LITE/sgw_lite_task.c
+++ b/openair-cn/SGW-LITE/sgw_lite_task.c
@@ -49,6 +49,7 @@
 #include "hashtable.h"
 #include "spgw_config.h"
 #include "pgw_lite_paa.h"
+#include "msc.h"
 
 spgw_config_t spgw_config;
 sgw_app_t     sgw_app;
@@ -57,6 +58,7 @@ pgw_app_t     pgw_app;
 static void *sgw_lite_intertask_interface(void *args_p)
 {
   itti_mark_task_ready(TASK_SPGW_APP);
+  MSC_START_USE();
 
   while(1) {
     MessageDef *received_message_p;
diff --git a/openair-cn/TEST/oaisim_mme_test_s1c.c b/openair-cn/TEST/oaisim_mme_test_s1c.c
index ff271eebaff8c8eb5431c8de0d021d208eff8a80..f199d19cdc838499c01d10bd3066db3d18861be6 100644
--- a/openair-cn/TEST/oaisim_mme_test_s1c.c
+++ b/openair-cn/TEST/oaisim_mme_test_s1c.c
@@ -61,13 +61,19 @@
 static void get_options (int argc, char **argv);
 static uint32_t eNB_app_register(const uint32_t enb_id_start, const uint32_t enb_id_end, const Enb_properties_array_t *enb_properties);
 static void    *eNB_app_task    (void *args_p);
-static void     mme_test_s1_start_test(instance_t instance);
+void     mme_test_s1_start_test(instance_t instance);
 //------------------------------------------------------------------------------
 static char                    *conf_config_file_name = NULL;
 static char                    *itti_dump_file        = NULL;
 const Enb_properties_array_t   *enb_properties        = NULL;
 int16_t                         glog_level            = LOG_INFO;
 int16_t                         glog_verbosity        = LOG_MED;
+s1c_test_t                      s1c_test = {
+	    0, // scenario_index
+	    0, // tx_next_message_index
+	    0, // rx_next_message_index
+	    0  // assoc_id
+      };
 
 //------------------------------------------------------------------------------
 static void get_options (int argc, char **argv)
@@ -228,7 +234,7 @@ static void *eNB_app_task(void *args_p)
       /* Check if all register eNB requests have been processed */
       if (register_enb_pending == 0) {
         if (registered_enb == enb_nb) {
-          mme_test_s1_start_test();
+          mme_test_s1_start_test(instance);
 
 
         } else {
@@ -288,10 +294,10 @@ void mme_test_s1_start_test(instance_t instance)
 //------------------------------------------------------------------------------
 {
 	s1ap_eNB_itti_send_sctp_data_req(instance,
-			int32_t assoc_id,
-			s1ap_scenario1[scenario_message_index].buffer,
-			s1ap_scenario1[scenario_message_index].buf_len,
-			s1ap_scenario1[scenario_message_index].sctp_stream_id);
+			s1c_test.assoc_id,
+			s1ap_scenarios[s1c_test.scenario_index][s1c_test.tx_next_message_index].buffer,
+			s1ap_scenarios[s1c_test.scenario_index][s1c_test.tx_next_message_index].buf_len,
+			s1ap_scenarios[s1c_test.scenario_index][s1c_test.tx_next_message_index].sctp_stream_id);
 }
 
 
diff --git a/openair-cn/TEST/oaisim_mme_test_s1c.h b/openair-cn/TEST/oaisim_mme_test_s1c.h
index 107a7a6d7d77aaeb1432726e2295dbc776be4bc5..af59dd1a23822153f1e4d51256fed2542078ba64 100644
--- a/openair-cn/TEST/oaisim_mme_test_s1c.h
+++ b/openair-cn/TEST/oaisim_mme_test_s1c.h
@@ -28,4 +28,12 @@
 *******************************************************************************/
 
 
+typedef struct s1c_test_s {
+    int     scenario_index;
+    int     tx_next_message_index;
+    int     rx_next_message_index;
+    int32_t assoc_id;
+}s1c_test_t;
+
+void     mme_test_s1_start_test(instance_t instance);
 void     mme_test_s1_notify_sctp_data_ind(uint32_t assoc_id, int32_t stream, const uint8_t * const data, const uint32_t data_length);
diff --git a/openair-cn/TEST/oaisim_mme_test_s1c_scenario.h b/openair-cn/TEST/oaisim_mme_test_s1c_scenario.h
index 993b42ff8da72270ea7b71973517b5e9789a3fe7..25bbdb9c87e43b0d55c182791de02e9172f1a94f 100644
--- a/openair-cn/TEST/oaisim_mme_test_s1c_scenario.h
+++ b/openair-cn/TEST/oaisim_mme_test_s1c_scenario.h
@@ -26,6 +26,7 @@
    Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
 
 *******************************************************************************/
+#include <stdlib.h>
 #include <stdint.h>
 
 #define MME_TEST_S1_MAX_BUF_LENGTH (1024)
@@ -36,14 +37,15 @@ typedef enum entity_s{
   ENB
 } entity_t;
 
-typedef struct s1ap_test_s{
+typedef struct s1ap_message_test_s{
   char    *procedure_name;
   uint8_t  buffer[MME_TEST_S1_MAX_BUF_LENGTH];
   uint16_t dont_check[MME_TEST_S1_MAX_BYTES_TEST]; // bytes index test that can be omitted
   uint32_t buf_len;
   entity_t originating;
   uint16_t sctp_stream_id;
-} s1ap_test_t;
+  uint32_t assoc_id;
+} s1ap_message_test_t;
 
 void     fail (const char *format, ...);
 void     success (const char *format, ...);
diff --git a/openair-cn/TEST/oaisim_mme_test_s1c_scenario1.c b/openair-cn/TEST/oaisim_mme_test_s1c_scenario1.c
index d9c775a79d914c4a223135e156290d80d6e7155a..93d7e5fedf1486b95287738d435ce39df59e732c 100644
--- a/openair-cn/TEST/oaisim_mme_test_s1c_scenario1.c
+++ b/openair-cn/TEST/oaisim_mme_test_s1c_scenario1.c
@@ -26,12 +26,13 @@
    Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
 
 *******************************************************************************/
+#include <stdlib.h>
 #include "oaisim_mme_test_s1c_scenario.h"
 
 
 // Description succesfull attach of UE, release UE.
 
-s1ap_test_t s1ap_scenario1[] = {
+s1ap_message_test_t s1ap_scenario1[] = {
   {
     .procedure_name = "id-initialUEMessage",
     .buffer = {
diff --git a/openair-cn/UDP/udp_eNB_task.c b/openair-cn/UDP/udp_eNB_task.c
index ce29ebc9e08db5b8712388d12a7053a558861b17..32b3317fcf34b6c972d76fa8db16c48a1bb5ec68 100644
--- a/openair-cn/UDP/udp_eNB_task.c
+++ b/openair-cn/UDP/udp_eNB_task.c
@@ -51,6 +51,7 @@
 
 #include "UTIL/LOG/log.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
+#include "msc.h"
 
 
 #define IPV4_ADDR    "%u.%u.%u.%u"
@@ -304,6 +305,7 @@ void *udp_eNB_task(void *args_p)
   udp_enb_init(NULL);
 
   itti_mark_task_ready(TASK_UDP);
+  MSC_START_USE();
 
   while(1) {
     itti_receive_msg(TASK_UDP, &received_message_p);
diff --git a/openair-cn/UDP/udp_primitives_server.c b/openair-cn/UDP/udp_primitives_server.c
index e1eb177a5c0a9919e8bc6a7d6603439e72fc473c..6639331ee84fd70e13a9bb5304d4e50f0c59a49b 100644
--- a/openair-cn/UDP/udp_primitives_server.c
+++ b/openair-cn/UDP/udp_primitives_server.c
@@ -53,6 +53,7 @@
 
 #include "assertions.h"
 #include "conversions.h"
+#include "msc.h"
 
 #define UDP_DEBUG(x, args...) do { fprintf(stdout, "[UDP] [D]"x, ##args); } while(0)
 #define UDP_ERROR(x, args...) do { fprintf(stderr, "[UDP] [E]"x, ##args); } while(0)
@@ -330,6 +331,7 @@ static void *udp_intertask_interface(void *args_p)
   struct epoll_event *events    = NULL;
 
   itti_mark_task_ready(TASK_UDP);
+  MSC_START_USE();
 
   while(1) {
     MessageDef *received_message_p = NULL;
diff --git a/openair-cn/UTILS/mme_config.c b/openair-cn/UTILS/mme_config.c
index 15eb3bd8189fbe6a969801648f2b400e890b98b6..dc6aea613ce5ecb42de70ad5cc14988811ba3f01 100644
--- a/openair-cn/UTILS/mme_config.c
+++ b/openair-cn/UTILS/mme_config.c
@@ -41,6 +41,7 @@
 
 #include <arpa/inet.h> /* To provide inet_addr */
 
+#include "intertask_interface.h"
 #include "assertions.h"
 #include "msc.h"
 #include "mme_config.h"
@@ -693,7 +694,7 @@ int config_parse_opt_line(int argc, char *argv[], mme_config_t *mme_config_p)
 
     case 'm': {
       fprintf(stdout, "Logging Message chart(mscgen)\n");
-      MSC_INIT(MSC_EPC);
+      MSC_INIT(MSC_MME_GW, THREAD_MAX+TASK_MAX);
     }
     break;
 
diff --git a/openair2/COMMON/tasks_def.h b/openair2/COMMON/tasks_def.h
index e9ba7e10c62668c4454c4cb909f53a7df54baad0..1da78c6131c3757313a07bdd9d08a054e79a3f3b 100644
--- a/openair2/COMMON/tasks_def.h
+++ b/openair2/COMMON/tasks_def.h
@@ -77,3 +77,6 @@ TASK_DEF(TASK_RRC_UE,   TASK_PRIORITY_MED,          200)
 TASK_DEF(TASK_NAS_UE,   TASK_PRIORITY_MED,          200)
 TASK_DEF(TASK_RAL_UE,   TASK_PRIORITY_MED,          200)
 
+//MESSAGE GENERATOR TASK
+TASK_DEF(TASK_MSC,      TASK_PRIORITY_MED,          200)
+
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c
index 1119e1a16ee510f8f135a0506bef11f63c66c242..524dd2022b81cb0a0a6dcdac4de2deb67bb40e07 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c
@@ -67,6 +67,8 @@
 
 #include "pdcp.h"
 #include "pdcp_primitives.h"
+#include "msc.h"
+
 
 #define PDCP_QUEUE_NB_ELEMENTS 200
 
@@ -219,7 +221,7 @@ void *pdcp_netlink_thread_fct(void *arg)
   pdcp_thread_read_state = 0;
   memset(nl_rx_buf, 0, NL_MAX_PAYLOAD);
   LOG_I(PDCP, "[NETLINK_THREAD] binding to fd  %d\n",nas_sock_fd);
-
+  MSC_START_USE();
   while (1) {
 
     len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c
index 936566c8e171c1780c0638df0279203008e4e685..4f0d11e23586f58e9985eacf24b324bbaf6610e6 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c
@@ -44,6 +44,7 @@
 #include "PHY/extern.h" //for PHY_vars
 #include "UTIL/LOG/log.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
+#include "msc.h"
 
 #define OPENAIR_THREAD_STACK_SIZE    8192
 #define OPENAIR_THREAD_PRIORITY        255
@@ -64,6 +65,7 @@ static void *pdcp_thread_main(void* param)
   uint8_t eNB_flag = !UE_flag;
 
   LOG_I(PDCP,"This is pdcp_thread eNB_flag = %d\n",eNB_flag);
+  MSC_START_USE();
 
   while (!oai_exit) {
 
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index b6dd677d4d370c9b1bfcabe08dfb0214bc6fa4c4..bfb4f8aa382a6335a241c6b6f9f9b25fc5bae6ed 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -1048,6 +1048,8 @@ static void* eNB_thread_tx( void* param )
   // set default return value
   eNB_thread_tx_status[proc->subframe] = 0;
 
+  MSC_START_USE();
+
 #ifdef RTAI
   RT_TASK *task;
   char task_name[8];
@@ -1235,6 +1237,8 @@ static void* eNB_thread_rx( void* param )
   // set default return value
   eNB_thread_rx_status[proc->subframe] = 0;
 
+  MSC_START_USE();
+
 #ifdef RTAI
   RT_TASK *task;
   char task_name[8];
@@ -2473,8 +2477,6 @@ int main( int argc, char **argv )
  
   get_options (argc, argv); //Command-line options
  
-  // initialize mscgen log
-  MSC_INIT(MSC_E_UTRAN);
   
   // initialize the log (see log.h for details)
   set_glog(glog_level, glog_verbosity);
@@ -2560,6 +2562,9 @@ int main( int argc, char **argv )
 
   itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, itti_dump_file);
 #endif
+  // initialize mscgen log after ITTI
+  MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX);
+
 #ifdef OPENAIR2
 
   if (opt_type != OPT_NONE) {
diff --git a/targets/SCRIPTS/msc_gen.py b/targets/SCRIPTS/msc_gen.py
index 64cea278f4edf48b4fd29daac018c276cfc03c23..ed5d337fc2dc009a4f48cb75ec2c421db1254006 100755
--- a/targets/SCRIPTS/msc_gen.py
+++ b/targets/SCRIPTS/msc_gen.py
@@ -2,7 +2,9 @@
 # -*- coding: utf-8 -*-
 
 # The aim of this script is to collect some traces from oai stack and generate a sequence diagram image (png or jpeg).
-
+#
+# It is supposed that a protocol name (MSC_NEW_STR) starts with...its name (RRC, MAC, NAS, S1AP, etc) then is followed by an underscore and whatever (RRC_UE,  RRC_eNB)
+#   Like this it is possible to distinguish between PDUS, SDUs or other messages only by reading source ans destination
 
 import sys
 import subprocess
@@ -20,6 +22,9 @@ 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")
+parser.add_argument("--no_message", "-M", type=str,help="Trace PDUs, not messages, SDUs", default="no")
+parser.add_argument("--no_pdu", "-P", type=str,help="Trace messages, SDUs, not PDUs", default="no")
+parser.add_argument("--no_event", "-E", type=str,help="Do not trace events", default="no")
 args = parser.parse_args()
 
 MSCGEN_OUTPUT_TYPE       = "png"
@@ -30,8 +35,10 @@ MSC_MSG_STR              = '[MESSAGE]'
 MSC_BOX_STR              = '[EVENT]'
 
 
-# This list is filled as follow : g_proto_names[module_id_int] = (proto_name)
+# This list is filled as follow : g_proto_names[module_id_int] = (proto_name), example RRC_UE
 g_proto_names = []
+# This list is filled as follow : g_proto_names[module_id_int] = (basename proto_name) example: RRC
+g_proto_types = []
 
 
 
@@ -83,38 +90,14 @@ g_sequence_generator = 0
 
 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',
-        args.dir+'/openair.msc.pdcp_ue.log',
-        args.dir+'/openair.msc.rrc_ue.log',
-        args.dir+'/openair.msc.rlc_ue.log',
-        args.dir+'/openair.msc.mac_ue.log',
-        args.dir+'/openair.msc.phy_ue.log',
-        args.dir+'/openair.msc.phy_enb.log',
-        args.dir+'/openair.msc.mac_enb.log',
-        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.gtpu_sgw.utran.log',
-        args.dir+'/openair.msc.s1ap_mme.utran.log',
-        args.dir+'/openair.msc.nas_mme.utran.log']
+    g_filenames = [    
+        args.dir+'/openair.msc.0.log',
+        args.dir+'/openair.msc.1.log']
 elif "EPC" == args.profile.strip():
     g_filenames = [        
-        args.dir+'/openair.msc.s1ap_enb.epc.log',
-        args.dir+'/openair.msc.mme_app.log',
-        args.dir+'/openair.msc.nas_mme.log',
-        args.dir+'/openair.msc.nas_emm_mme.log',
-        args.dir+'/openair.msc.nas_esm_mme.log',
-        args.dir+'/openair.msc.spgwapp_mme.log',
-        args.dir+'/openair.msc.s11_mme.log',
-        args.dir+'/openair.msc.s6a_mme.log',
-        args.dir+'/openair.msc.gtpu_sgw.log',
-        args.dir+'/openair.msc.s1ap_mme.log',
-        args.dir+'/openair.msc.hss.log']
+        args.dir+'/openair.msc.2.log',
+        args.dir+'/openair.msc.3.log',
+        args.dir+'/openair.msc.4.log']
 
 def sequence_number_generator():
     global g_sequence_generator
@@ -145,8 +128,8 @@ def parse_oai_log_files():
             # split file content in lines
             lines = fcontent.splitlines()
             for line in lines:
+                print ("INPUT LINE:  %s " % line)
                 if line.strip() != ""  and not line.strip().startswith('#'):
-                    print ("INPUT LINE:  %s " % line)
                     partition = line.split(' ',3)
                     event_id = int(partition[0]) + event_id_offset
                     event_type = partition[1]
@@ -156,8 +139,13 @@ def parse_oai_log_files():
                         if len(g_proto_names) <= entity_id:
                             for i in range(len(g_proto_names),(entity_id +1)):
                                 g_proto_names.append("NotDeclared")
+                                g_proto_types.append("NotDeclared")
                         g_proto_names[entity_id] = entity_name
-
+                        partition_name1 = entity_name.split('_',1);
+                        partition_name2 = partition_name1[0].split('-',1);
+                        partition_name3 = partition_name2[0].split();
+                        g_proto_types[entity_id] = partition_name3
+                        print ("entity name %s , entity type %s" % (g_proto_names[entity_id],g_proto_types[entity_id]) )
                     # if line is a trace of a message between 2 protocol entities or layers
                     elif MSC_MSG_STR == event_type:
                         #print ("partition[3]:%s" % partition[3])
@@ -278,6 +266,7 @@ def get_new_file_descriptor():
     global g_page_index
     l_file_name = g_base_file_name + str(g_page_index)+'.txt'
     l_file = open(l_file_name, "wb")
+    print "Generating mscgen input file ",l_file_name;
     return l_file
 
 
@@ -301,10 +290,26 @@ msc_chart_write_header(g_file)
 for event_id_int in sorted(g_messages.iterkeys()):
     message = g_messages[event_id_int]
     if 'tx' in message['type']:
+        if "yes" == args.no_message.strip():
+            if g_proto_types[message['tx']] != g_proto_types[message['rx']]:
+                continue
+        if "yes" == args.no_pdu.strip():
+            if g_proto_types[message['tx']] == g_proto_types[message['rx']]:
+                continue   
         g_file.write("  %s=>%s [ label = \"(%d|%s) %s\", linecolour=%s , textcolour=%s ] ;\n" % (g_proto_names[message['tx']], g_proto_names[message['rx']], event_id_int, message['time'], message['message'], message['line_color'], message['text_color']))
+
     elif 'rx' in message['type']:
+        if "yes" == args.no_message.strip():
+            if g_proto_types[message['tx']] != g_proto_types[message['rx']]:
+                continue
+        if "yes" == args.no_pdu.strip():
+            if g_proto_types[message['tx']] == g_proto_types[message['rx']]:
+                continue   
         g_file.write("  %s<=%s [ label = \"(%d|%s) %s\", linecolour=%s , textcolour=%s ] ;\n" % (g_proto_names[message['rx']], g_proto_names[message['tx']], event_id_int, message['time'], message['message'], message['line_color'], message['text_color']))
+
     elif 'box' in message['type']:
+        if "yes" == args.no_event.strip():
+            continue  
         g_file.write("  %s note %s [ label = \"%s\", textcolour=%s ] ;\n" % (g_proto_names[message['tx']], g_proto_names[message['rx']], message['message'], message['text_color']))
 
     g_message_index = g_message_index + 1
diff --git a/targets/SIMU/USER/oaisim_config.c b/targets/SIMU/USER/oaisim_config.c
index dfaf025080e336230ffcbe69fd6d11e182b4a612..ae75f6aae89cc806ea6cf9c0823fbce51cd71b05 100644
--- a/targets/SIMU/USER/oaisim_config.c
+++ b/targets/SIMU/USER/oaisim_config.c
@@ -337,6 +337,7 @@ void oaisim_config(void)
 
 #if defined(ENABLE_ITTI)
   itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, oai_emulation.info.itti_dump_file);
+  MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX);
 #endif
 
   // init ocg if enabled, otherwise take the params form the init_oai_emulation()
@@ -351,8 +352,7 @@ void oaisim_config(void)
     }
   }
 
-  // init other comps
-  MSC_INIT(MSC_E_UTRAN);
+
 #ifdef ENABLE_RAL
   mRAL_init_default_values();
   eRAL_init_default_values();
diff --git a/targets/build_oai.bash b/targets/build_oai.bash
index 65198e71b72dc9ac737564237e62e1df2544afa9..c6c7edd56a69021c70eca08503ebcc89028dd92b 100755
--- a/targets/build_oai.bash
+++ b/targets/build_oai.bash
@@ -337,9 +337,9 @@ build_enb(){
     OAISIM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
     
     if [ $ENB_S1 -eq 1 ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_PDCP_TO_GTPV1U=1  SECU=1 "
-        #OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_PDCP_TO_GTPV1U=1  SECU=1 "
-	OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES ENABLE_ITTI=1 LINK_PDCP_TO_GTPV1U=1  SECU=1 "
+        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_ENB_PDCP_TO_GTPV1U=1  SECU=1 "
+        #OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_ENB_PDCP_TO_GTPV1U=1  SECU=1 "
+	OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES ENABLE_ITTI=1 LINK_ENB_PDCP_TO_GTPV1U=1  SECU=1 "
     fi 
     
     if [ $DEBUG -eq 0 ]; then