From b45af4a3c92783fec09e9642ed229470c78faa35 Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Wed, 23 Oct 2013 12:18:35 +0000
Subject: [PATCH] Moved files related to assertions, backtrace and signals
 handling into ITTI directory. Renamed all ITTI functions, to make them start
 with module name ("itti_"). Added generic signals handling support in ITTI.
 Changed ITTI log port for oaisim to 10006. Introduce an option to use ITTI in
 oaisim and reoragized code.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4267 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 common/utils/Makefile.inc                     |    2 +
 common/utils/itti/Makefile.am                 |    3 +
 .../UTILS => common/utils/itti}/assertions.h  |    0
 .../UTILS => common/utils/itti}/backtrace.c   |    0
 .../UTILS => common/utils/itti}/backtrace.h   |    0
 common/utils/itti/intertask_interface.c       |  350 ++---
 common/utils/itti/intertask_interface.h       |   37 +-
 common/utils/itti/intertask_interface_init.h  |    2 +-
 .../UTILS => common/utils/itti}/signals.c     |   13 +-
 .../UTILS => common/utils/itti}/signals.h     |    2 +-
 common/utils/itti/timer.c                     |    4 +-
 openair-cn/GTPV1-U/gtpv1u_task.c              |   32 +-
 openair-cn/MME_APP/mme_app_authentication.c   |   16 +-
 openair-cn/MME_APP/mme_app_bearer.c           |    8 +-
 openair-cn/MME_APP/mme_app_main.c             |    8 +-
 openair-cn/MME_APP/s6a_2_nas_cause.c          |    4 +-
 .../NAS/EURECOM-NAS/src/emm/sap/emm_as.c      |    4 +-
 openair-cn/NAS/nas_main.c                     |   18 +-
 openair-cn/OAISIM_MME/oaisim_mme.c            |   14 +-
 openair-cn/OAI_EPC/oai_epc.c                  |   14 +-
 openair-cn/OAI_SGW/oai_sgw.c                  |   13 +-
 openair-cn/S11/s11_mme_session_manager.c      |    4 +-
 openair-cn/S11/s11_mme_task.c                 |   16 +-
 openair-cn/S11/s11_sgw.c                      |   16 +-
 openair-cn/S11/s11_sgw_bearer_manager.c       |    4 +-
 openair-cn/S11/s11_sgw_session_manager.c      |    8 +-
 openair-cn/S1AP/s1ap_mme.c                    |   12 +-
 openair-cn/S1AP/s1ap_mme_handlers.c           |    8 +-
 openair-cn/S1AP/s1ap_mme_itti_messaging.c     |    4 +-
 openair-cn/S1AP/s1ap_mme_nas_procedures.c     |    4 +-
 openair-cn/S6A/s6a_auth_info.c                |    4 +-
 openair-cn/S6A/s6a_task.c                     |    8 +-
 openair-cn/S6A/s6a_up_loc.c                   |    4 +-
 openair-cn/SCTP/sctp_itti_messaging.c         |   12 +-
 openair-cn/SCTP/sctp_primitives_server.c      |    8 +-
 openair-cn/SECU/Makefile.am                   |    1 +
 openair-cn/SGI/sgi_egress.c                   |    8 +-
 openair-cn/SGI/sgi_nf.c                       |    4 +-
 openair-cn/SGI/sgi_task.c                     |   12 +-
 openair-cn/SGW-LITE/sgw_lite_handlers.c       |   56 +-
 openair-cn/SGW-LITE/sgw_lite_task.c           |    8 +-
 openair-cn/TEST/oaisim_mme_itti_test.c        |    4 +-
 openair-cn/UDP/udp_primitives_server.c        |   12 +-
 openair-cn/UTILS/Makefile.am                  |    5 +-
 openair2/COMMON/intertask_interface_conf.h    |    2 +-
 openair3/OPENAIRMME/S1AP/s1ap_mme.c           |    4 +-
 openair3/OPENAIRMME/S1AP/s1ap_mme_encoder.c   |   10 +-
 openair3/OPENAIRMME/S1AP/s1ap_mme_handlers.c  |    8 +-
 targets/SIMU/USER/Makefile                    |    2 +-
 targets/SIMU/USER/oaisim.c                    | 1317 +++++++++--------
 50 files changed, 1090 insertions(+), 1019 deletions(-)
 rename {openair-cn/UTILS => common/utils/itti}/assertions.h (100%)
 rename {openair-cn/UTILS => common/utils/itti}/backtrace.c (100%)
 rename {openair-cn/UTILS => common/utils/itti}/backtrace.h (100%)
 rename {openair-cn/UTILS => common/utils/itti}/signals.c (93%)
 rename {openair-cn/UTILS => common/utils/itti}/signals.h (75%)

diff --git a/common/utils/Makefile.inc b/common/utils/Makefile.inc
index 01397b9628..021f1167c7 100644
--- a/common/utils/Makefile.inc
+++ b/common/utils/Makefile.inc
@@ -2,6 +2,8 @@ ITTI_DIR = $(COMMON_UTILS_DIR)/itti
 
 ITTI_OBJS =  $(ITTI_DIR)/intertask_interface.o
 ITTI_OBJS += $(ITTI_DIR)/intertask_interface_dump.o
+ITTI_OBJS += $(ITTI_DIR)/backtrace.o
+ITTI_OBJS += $(ITTI_DIR)/signals.o
 ITTI_OBJS += $(ITTI_DIR)/timer.o
 
 UTILS_OBJS = $(ITTI_OBJS)
diff --git a/common/utils/itti/Makefile.am b/common/utils/itti/Makefile.am
index eddb2eda7e..a2276a50fc 100644
--- a/common/utils/itti/Makefile.am
+++ b/common/utils/itti/Makefile.am
@@ -17,4 +17,7 @@ libitti_la_SOURCES = 										\
 	udp_message_def.h	udp_messages_types.h				\
 	intertask_interface.c 	intertask_interface.h			\
 	intertask_interface_dump.c intertask_interface_dump.h	\
+	assertions.h											\
+	backtrace.c backtrace.h									\
+	signals.c signals.h										\
 	timer.c	timer.h
\ No newline at end of file
diff --git a/openair-cn/UTILS/assertions.h b/common/utils/itti/assertions.h
similarity index 100%
rename from openair-cn/UTILS/assertions.h
rename to common/utils/itti/assertions.h
diff --git a/openair-cn/UTILS/backtrace.c b/common/utils/itti/backtrace.c
similarity index 100%
rename from openair-cn/UTILS/backtrace.c
rename to common/utils/itti/backtrace.c
diff --git a/openair-cn/UTILS/backtrace.h b/common/utils/itti/backtrace.h
similarity index 100%
rename from openair-cn/UTILS/backtrace.h
rename to common/utils/itti/backtrace.h
diff --git a/common/utils/itti/intertask_interface.c b/common/utils/itti/intertask_interface.c
index 31c0cd65d3..53b8101dbb 100644
--- a/common/utils/itti/intertask_interface.c
+++ b/common/utils/itti/intertask_interface.c
@@ -1,32 +1,32 @@
 /*******************************************************************************
 
-  Eurecom OpenAirInterface
-  Copyright(c) 1999 - 2012 Eurecom
+ Eurecom OpenAirInterface
+ Copyright(c) 1999 - 2012 Eurecom
 
-  This program is free software; you can redistribute it and/or modify it
-  under the terms and conditions of the GNU General Public License,
-  version 2, as published by the Free Software Foundation.
+ This program is free software; you can redistribute it and/or modify it
+ under the terms and conditions of the GNU General Public License,
+ version 2, as published by the Free Software Foundation.
 
-  This program is distributed in the hope it will be useful, but WITHOUT
-  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details.
+ This program is distributed in the hope it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc.,
-  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 
-  The full GNU General Public License is included in this distribution in
-  the file called "COPYING".
+ The full GNU General Public License is included in this distribution in
+ the file called "COPYING".
 
-  Contact Information
-  Openair Admin: openair_admin@eurecom.fr
-  Openair Tech : openair_tech@eurecom.fr
-  Forums       : http://forums.eurecom.fr/openairinterface
-  Address      : EURECOM, Campus SophiaTech, 450 Route des Chappes
-                 06410 Biot FRANCE
+ Contact Information
+ Openair Admin: openair_admin@eurecom.fr
+ Openair Tech : openair_tech@eurecom.fr
+ Forums       : http://forums.eurecom.fr/openairinterface
+ Address      : EURECOM, Campus SophiaTech, 450 Route des Chappes
+ 06410 Biot FRANCE
 
-*******************************************************************************/
+ *******************************************************************************/
 
 #include <pthread.h>
 #include <stdio.h>
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <signal.h>
 
 #include "queue.h"
 #include "assertions.h"
@@ -45,6 +46,7 @@
 #include "intertask_interface_init.h"
 #undef CHECK_PROTOTYPE_ONLY
 
+#include "signals.h"
 #include "timer.h"
 
 int itti_debug = 1;
@@ -58,125 +60,124 @@ int itti_debug = 1;
 #define MESSAGE_SIZE(mESSAGEiD) (sizeof(MessageHeader) + itti_desc.messages_info[mESSAGEiD].size)
 
 typedef enum task_state_s {
-    TASK_STATE_NOT_CONFIGURED,
-    TASK_STATE_STARTING,
-    TASK_STATE_READY,
-    TASK_STATE_MAX,
+    TASK_STATE_NOT_CONFIGURED, TASK_STATE_STARTING, TASK_STATE_READY, TASK_STATE_ENDED, TASK_STATE_MAX,
 } task_state_t;
 
 /* This list acts as a FIFO of messages received by tasks (RRC, NAS, ...) */
 struct message_list_s {
     STAILQ_ENTRY(message_list_s) next_element;
 
-    MessageDef *msg;          ///< Pointer to the message
+    MessageDef *msg; ///< Pointer to the message
 
-    message_number_t message_number;  ///< Unique message number
-    uint32_t message_priority;        ///< Message priority
+    message_number_t message_number; ///< Unique message number
+    uint32_t message_priority; ///< Message priority
 };
 
 typedef struct task_desc_s {
     /* Queue of messages belonging to the task */
-    STAILQ_HEAD(message_queue_head, message_list_s) message_queue;
+    STAILQ_HEAD(message_queue_head, message_list_s)
+    message_queue;
 
     /* Number of messages in the queue */
-    volatile uint32_t   message_in_queue;
+    volatile uint32_t message_in_queue;
     /* Mutex for the message queue */
-    pthread_mutex_t     message_queue_mutex;
+    pthread_mutex_t message_queue_mutex;
     /* Conditional var for message queue and task synchro */
-    pthread_cond_t      message_queue_cond_var;
-    pthread_t           task_thread;
+    pthread_cond_t message_queue_cond_var;
+    pthread_t task_thread;
     volatile task_state_t task_state;
 } task_desc_t;
 
 struct itti_desc_s {
     task_desc_t *tasks;
     /* Current message number. Incremented every call to send_msg_to_task */
-    message_number_t   message_number __attribute__((aligned(8)));
+    message_number_t message_number __attribute__((aligned(8)));
 
     thread_id_t thread_max;
     MessagesIds messages_id_max;
 
+    pthread_t thread_handling_signals;
+
     const char * const *threads_name;
     const message_info_t *messages_info;
 };
 
 static struct itti_desc_s itti_desc;
 
-static inline
-message_number_t increment_message_number(void)
-{
+static inline message_number_t itti_increment_message_number(void) {
     /* Atomic operation supported by GCC: returns the current message number
      * and then increment it by 1.
      * This can be done without mutex.
      */
-    return __sync_fetch_and_add(&itti_desc.message_number, 1);
+    return __sync_fetch_and_add (&itti_desc.message_number, 1);
 }
 
-static inline uint32_t get_message_priority(MessagesIds message_id)
-{
+static inline uint32_t itti_get_message_priority(MessagesIds message_id) {
     DevCheck(message_id < itti_desc.messages_id_max, message_id, itti_desc.messages_id_max, 0);
 
     return (itti_desc.messages_info[message_id].priority);
 }
 
-char *get_message_name(MessagesIds message_id)
-{
+char *itti_get_message_name(MessagesIds message_id) {
     DevCheck(message_id < itti_desc.messages_id_max, message_id, itti_desc.messages_id_max, 0);
 
     return (itti_desc.messages_info[message_id].name);
 }
 
-int send_broadcast_message(MessageDef *message_p)
-{
+int itti_send_broadcast_message(MessageDef *message_p) {
+    thread_id_t origin_thread_id;
     uint32_t i;
     int ret = 0;
-    int temp;
+    int result;
 
-    for (i = THREAD_FIRST; i < itti_desc.thread_max; i++)
-    {
-        MessageDef *new_message_p;
+    if (message_p == NULL) {
+        ITTI_ERROR("Message to broadcast is NULL (%s:%d)\n", __FILE__, __LINE__);
+        return -1;
+    }
 
-        /* Skip tasks which are not running */
-        if (itti_desc.tasks[i].task_state == TASK_STATE_READY)
-        {
-            new_message_p = malloc(sizeof(MessageDef));
+    origin_thread_id = TASK_GET_THREAD_ID(message_p->header.originTaskId);
 
-            if (new_message_p == NULL) {
-                ITTI_ERROR("Failed to allocate memory (%s:%d)\n",
-                           __FILE__, __LINE__);
-                return -1;
-            }
-            memcpy(new_message_p, message_p, sizeof(MessageDef));
-            temp = send_msg_to_task(TASK_SHIFT_THREAD_ID(i), INSTANCE_DEFAULT, new_message_p);
-            if (temp < 0) {
-                ITTI_ERROR("Failed to send broadcast message (%s) to queue (%u:%s)\n",
-                           itti_desc.messages_info[message_p->header.messageId].name, i, itti_desc.threads_name[i]);
-                ret = temp;
-                free(new_message_p);
+    for (i = THREAD_FIRST; i < itti_desc.thread_max; i++) {
+        MessageDef *new_message_p;
+
+        /* Skip task that broadcast the message */
+        if (i != origin_thread_id) {
+            /* Skip tasks which are not running */
+            if (itti_desc.tasks[i].task_state == TASK_STATE_READY) {
+                new_message_p = malloc (sizeof(MessageDef));
+
+                if (new_message_p == NULL) {
+                    ITTI_ERROR("Failed to allocate memory (%s:%d)\n", __FILE__, __LINE__);
+                    return -1;
+                }
+                memcpy (new_message_p, message_p, sizeof(MessageDef));
+                result = itti_send_msg_to_task (TASK_SHIFT_THREAD_ID(i), INSTANCE_DEFAULT, new_message_p);
+                if (result < 0) {
+                    ITTI_ERROR("Failed to send broadcast message (%s) to queue (%u:%s)\n",
+                               itti_desc.messages_info[message_p->header.messageId].name, i, itti_desc.threads_name[i]);
+                    ret = result;
+                    free (new_message_p);
+                }
             }
         }
     }
+    free (message_p);
 
     return ret;
 }
 
-inline MessageDef *alloc_new_message(
-    task_id_t      origin_task_id,
-    MessagesIds message_id)
-{
+inline MessageDef *itti_alloc_new_message(task_id_t origin_task_id, MessagesIds message_id) {
     MessageDef *temp = NULL;
 
-    if ((TASK_GET_THREAD_ID(origin_task_id) >= itti_desc.thread_max) ||
-        (message_id >= itti_desc.messages_id_max))
-    {
+    if (message_id >= itti_desc.messages_id_max) {
+        ITTI_ERROR("Invalid message id %d (%s:%d)\n", message_id, __FILE__, __LINE__);
         return NULL;
     }
 
-    temp = calloc(1, MESSAGE_SIZE(message_id));
+    temp = calloc (1, MESSAGE_SIZE(message_id));
 
     if (temp == NULL) {
-        ITTI_ERROR("Cannot allocate memory for new message (%s:%d)\n",
-                   __FILE__, __LINE__);
+        ITTI_ERROR("Cannot allocate memory for new message (%s:%d)\n", __FILE__, __LINE__);
         return NULL;
     }
 
@@ -187,16 +188,14 @@ inline MessageDef *alloc_new_message(
     return temp;
 }
 
-int send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message)
-{
-    thread_id_t             thread_id = TASK_GET_THREAD_ID(task_id);
-    struct message_list_s  *new;
-    uint32_t                priority;
-    message_number_t        message_number;
-    uint32_t                message_id;
+int itti_send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message) {
+    thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
+    struct message_list_s *new;
+    uint32_t priority;
+    message_number_t message_number;
+    uint32_t message_id;
 
-    if (thread_id >= itti_desc.thread_max)
-    {
+    if (thread_id >= itti_desc.thread_max) {
         return -1;
     }
 
@@ -208,43 +207,41 @@ int send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message
     DevCheck(thread_id < itti_desc.thread_max, thread_id, 0, 0);
     DevCheck(message_id < itti_desc.messages_id_max, itti_desc.messages_id_max, message_id, 0);
 
-    priority = get_message_priority(message_id);
+    priority = itti_get_message_priority (message_id);
 
     /* Lock the mutex to get exclusive access to the list */
-    pthread_mutex_lock(&itti_desc.tasks[thread_id].message_queue_mutex);
+    pthread_mutex_lock (&itti_desc.tasks[thread_id].message_queue_mutex);
 
     /* We cannot send a message if the task is not running */
-    DevCheck(itti_desc.tasks[thread_id].task_state == TASK_STATE_READY,
-             itti_desc.tasks[thread_id].task_state, TASK_STATE_READY, thread_id);
+    DevCheck(itti_desc.tasks[thread_id].task_state == TASK_STATE_READY, itti_desc.tasks[thread_id].task_state,
+             TASK_STATE_READY, thread_id);
 
     /* Check the number of messages in the queue */
-    DevCheck((itti_desc.tasks[thread_id].message_in_queue * sizeof(MessageDef))
-             < ITTI_QUEUE_SIZE_PER_TASK,
-             (itti_desc.tasks[thread_id].message_in_queue * sizeof(MessageDef)),
-             ITTI_QUEUE_SIZE_PER_TASK,
+    DevCheck((itti_desc.tasks[thread_id].message_in_queue * sizeof(MessageDef)) < ITTI_QUEUE_SIZE_PER_TASK,
+             (itti_desc.tasks[thread_id].message_in_queue * sizeof(MessageDef)), ITTI_QUEUE_SIZE_PER_TASK,
              itti_desc.tasks[thread_id].message_in_queue);
 
     /* Allocate new list element */
-    if ((new = (struct message_list_s *)malloc(sizeof(struct message_list_s))) == NULL)
-    {
-        ITTI_ERROR("Cannot allocate memory for new message (%s:%d)\n",
-                   __FILE__, __LINE__);
+    if ((new = (struct message_list_s *) malloc (sizeof(struct message_list_s))) == NULL) {
+        ITTI_ERROR("Cannot allocate memory for new message (%s:%d)\n", __FILE__, __LINE__);
         return -1;
     }
 
     /* Increment the global message number */
-    message_number = increment_message_number();
+    message_number = itti_increment_message_number ();
 
     /* Fill in members */
-    new->msg              = message;
-    new->message_number   = message_number;
+    new->msg = message;
+    new->message_number = message_number;
     new->message_priority = priority;
 
-    itti_dump_queue_message(message_number, message, itti_desc.messages_info[message_id].name, MESSAGE_SIZE(message_id));
+    itti_dump_queue_message (message_number, message, itti_desc.messages_info[message_id].name,
+                             MESSAGE_SIZE(message_id));
 
-    if (STAILQ_EMPTY(&itti_desc.tasks[thread_id].message_queue)) {
-        STAILQ_INSERT_HEAD(&itti_desc.tasks[thread_id].message_queue, new, next_element);
-    } else {
+    if (STAILQ_EMPTY (&itti_desc.tasks[thread_id].message_queue)) {
+        STAILQ_INSERT_HEAD (&itti_desc.tasks[thread_id].message_queue, new, next_element);
+    }
+    else {
 //         struct message_list_s *insert_after = NULL;
 //         struct message_list_s *temp;
 // 
@@ -263,7 +260,7 @@ int send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message
 //             }
 //         }
 //         if (insert_after == NULL) {
-            STAILQ_INSERT_TAIL(&itti_desc.tasks[thread_id].message_queue, new, next_element);
+        STAILQ_INSERT_TAIL (&itti_desc.tasks[thread_id].message_queue, new, next_element);
 //         } else {
 //             STAILQ_INSERT_AFTER(&itti_desc.tasks[thread_id].message_queue, insert_after, new,
 //                                 next_element);
@@ -274,84 +271,78 @@ int send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message
     itti_desc.tasks[thread_id].message_in_queue++;
     if (itti_desc.tasks[thread_id].message_in_queue == 1) {
         /* Emit a signal to wake up target task thread */
-        pthread_cond_signal(&itti_desc.tasks[thread_id].message_queue_cond_var);
+        pthread_cond_signal (&itti_desc.tasks[thread_id].message_queue_cond_var);
     }
     /* Release the mutex */
-    pthread_mutex_unlock(&itti_desc.tasks[thread_id].message_queue_mutex);
-    ITTI_DEBUG("Message %s, number %lu with priority %d successfully sent to queue (%u:%s)\n",
-               itti_desc.messages_info[message_id].name, message_number,
-               priority, thread_id, itti_desc.threads_name[thread_id]);
+    pthread_mutex_unlock (&itti_desc.tasks[thread_id].message_queue_mutex);
+    ITTI_DEBUG(
+            "Message %s, number %lu with priority %d successfully sent to queue (%u:%s)\n",
+            itti_desc.messages_info[message_id].name, message_number, priority, thread_id, itti_desc.threads_name[thread_id]);
     return 0;
 }
 
-void receive_msg(task_id_t task_id, MessageDef **received_msg)
-{
+void itti_receive_msg(task_id_t task_id, MessageDef **received_msg) {
     thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
 
     DevCheck(thread_id < itti_desc.thread_max, thread_id, 0, 0);
     DevAssert(received_msg != NULL);
 
     // Lock the mutex to get exclusive access to the list
-    pthread_mutex_lock(&itti_desc.tasks[thread_id].message_queue_mutex);
+    pthread_mutex_lock (&itti_desc.tasks[thread_id].message_queue_mutex);
 
     if (itti_desc.tasks[thread_id].message_in_queue == 0) {
-        ITTI_DEBUG("Message in queue[(%u:%s)] == 0, waiting\n",
-                   thread_id, itti_desc.threads_name[thread_id]);
+        ITTI_DEBUG("Message in queue[(%u:%s)] == 0, waiting\n", thread_id, itti_desc.threads_name[thread_id]);
         // Wait while list == 0
-        pthread_cond_wait(&itti_desc.tasks[thread_id].message_queue_cond_var,
-                          &itti_desc.tasks[thread_id].message_queue_mutex);
+        pthread_cond_wait (&itti_desc.tasks[thread_id].message_queue_cond_var,
+                           &itti_desc.tasks[thread_id].message_queue_mutex);
         ITTI_DEBUG("Receiver queue[(%u:%s)] got new message notification for task %x\n",
                    thread_id, itti_desc.threads_name[thread_id], task_id);
     }
 
-    if (!STAILQ_EMPTY(&itti_desc.tasks[thread_id].message_queue)) {
-        struct message_list_s *temp = STAILQ_FIRST(
-                                          &itti_desc.tasks[thread_id].message_queue);
+    if (!STAILQ_EMPTY (&itti_desc.tasks[thread_id].message_queue)) {
+        struct message_list_s *temp = STAILQ_FIRST (&itti_desc.tasks[thread_id].message_queue);
 
         /* Update received_msg reference */
         *received_msg = temp->msg;
 
         /* Remove message from queue */
-        STAILQ_REMOVE_HEAD(&itti_desc.tasks[thread_id].message_queue, next_element);
-        free(temp);
+        STAILQ_REMOVE_HEAD (&itti_desc.tasks[thread_id].message_queue, next_element);
+        free (temp);
         itti_desc.tasks[thread_id].message_in_queue--;
     }
     // Release the mutex
-    pthread_mutex_unlock(&itti_desc.tasks[thread_id].message_queue_mutex);
+    pthread_mutex_unlock (&itti_desc.tasks[thread_id].message_queue_mutex);
 }
 
-void poll_msg(task_id_t task_id, instance_t instance, MessageDef **received_msg)
-{
+void itti_poll_msg(task_id_t task_id, instance_t instance, MessageDef **received_msg) {
     thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
 
-    DevCheck (thread_id < itti_desc.thread_max, thread_id, 0, 0);
-    DevAssert (received_msg != NULL);
+    DevCheck(thread_id < itti_desc.thread_max, thread_id, 0, 0);
+    DevAssert(received_msg != NULL);
 
     *received_msg = NULL;
 
-    if (itti_desc.tasks[thread_id].message_in_queue != 0)
-    {
+    if (itti_desc.tasks[thread_id].message_in_queue != 0) {
         struct message_list_s *temp;
 
         // Lock the mutex to get exclusive access to the list
         pthread_mutex_lock (&itti_desc.tasks[thread_id].message_queue_mutex);
 
-        STAILQ_FOREACH(temp, &itti_desc.tasks[thread_id].message_queue, next_element)
+        STAILQ_FOREACH (temp, &itti_desc.tasks[thread_id].message_queue, next_element)
         {
             if ((temp->msg->header.destinationTaskId == task_id)
-                    && ((instance == INSTANCE_ALL) || (temp->msg->header.instance == instance)))
-            {
+                    && ((instance == INSTANCE_ALL) || (temp->msg->header.instance == instance))) {
                 /* Update received_msg reference */
                 *received_msg = temp->msg;
 
                 /* Remove message from queue */
-                STAILQ_REMOVE(&itti_desc.tasks[thread_id].message_queue, temp, message_list_s, next_element);
+                STAILQ_REMOVE (&itti_desc.tasks[thread_id].message_queue, temp, message_list_s, next_element);
                 free (temp);
                 itti_desc.tasks[thread_id].message_in_queue--;
 
-                ITTI_DEBUG("Receiver queue[(%u:%s)] got new message %s, number %lu for task %x\n",
-                           thread_id, itti_desc.threads_name[thread_id], itti_desc.messages_info[temp->msg->header.messageId].name,
-                           temp->message_number, task_id);
+                ITTI_DEBUG(
+                        "Receiver queue[(%u:%s)] got new message %s, number %lu for task %x\n",
+                        thread_id, itti_desc.threads_name[thread_id], itti_desc.messages_info[temp->msg->header.messageId].name, temp->message_number, task_id);
                 break;
             }
         }
@@ -360,16 +351,12 @@ void poll_msg(task_id_t task_id, instance_t instance, MessageDef **received_msg)
         pthread_mutex_unlock (&itti_desc.tasks[thread_id].message_queue_mutex);
     }
 
-    if (*received_msg == NULL)
-    {
+    if (*received_msg == NULL) {
         ITTI_DEBUG("No message in queue[(%u:%s)] for task %x\n", thread_id, itti_desc.threads_name[thread_id], task_id);
     }
 }
 
-int intertask_interface_create_task(task_id_t task_id,
-                                    void *(*start_routine) (void *),
-                                    void *args_p)
-{
+int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *args_p) {
     thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
 
     DevAssert(start_routine != NULL);
@@ -377,76 +364,107 @@ int intertask_interface_create_task(task_id_t task_id,
 
     if (itti_desc.tasks[thread_id].task_state != TASK_STATE_NOT_CONFIGURED) {
         ITTI_ERROR("You are attempting to start an already configured thread"
-                   " for %s thread\n", itti_desc.threads_name[thread_id]);
+        " for %s thread\n",
+                   itti_desc.threads_name[thread_id]);
         return -1;
     }
 
     itti_desc.tasks[thread_id].task_state = TASK_STATE_STARTING;
 
-    if (pthread_create(&itti_desc.tasks[thread_id].task_thread, NULL, start_routine,
-                       args_p) < 0) {
-        ITTI_ERROR("Failed to initialize %s thread: %s:%d\n", itti_desc.threads_name[thread_id],
-                   strerror(errno),
-                   errno);
+    if (pthread_create (&itti_desc.tasks[thread_id].task_thread, NULL, start_routine, args_p) < 0) {
+        ITTI_ERROR("Failed to initialize %s thread: %s:%d\n",
+                   itti_desc.threads_name[thread_id], strerror(errno), errno);
         return -1;
     }
 
     /* Wait till the thread is completely ready */
-    while (itti_desc.tasks[thread_id].task_state != TASK_STATE_READY);
+    while (itti_desc.tasks[thread_id].task_state != TASK_STATE_READY)
+        ;
     return 0;
 }
 
-void intertask_interface_mark_task_ready(task_id_t task_id)
-{
+void itti_mark_task_ready(task_id_t task_id) {
     thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
 
     DevCheck(thread_id < itti_desc.thread_max, thread_id, 0, 0);
     // Lock the mutex to get exclusive access to the list
-    pthread_mutex_lock(&itti_desc.tasks[thread_id].message_queue_mutex);
+    pthread_mutex_lock (&itti_desc.tasks[thread_id].message_queue_mutex);
     itti_desc.tasks[thread_id].task_state = TASK_STATE_READY;
     // Release the mutex
-    pthread_mutex_unlock(&itti_desc.tasks[thread_id].message_queue_mutex);
+    pthread_mutex_unlock (&itti_desc.tasks[thread_id].message_queue_mutex);
+}
+
+void itti_terminate_tasks(task_id_t task_id) {
+    // Sends Terminate signals to all tasks.
+    itti_send_terminate_message (task_id);
+
+    if (itti_desc.thread_handling_signals >= 0) {
+        pthread_kill (itti_desc.thread_handling_signals, SIGUSR1);
+    }
+
+    pthread_exit (NULL);
 }
 
-int intertask_interface_init(thread_id_t thread_max, MessagesIds messages_id_max,
-                             const char * const *threads_name,
-                             const message_info_t *messages_info,
-                             const char * const messages_definition_xml)
-{
+int itti_init(thread_id_t thread_max, MessagesIds messages_id_max, const char * const *threads_name,
+              const message_info_t *messages_info, const char * const messages_definition_xml) {
     int i;
     itti_desc.message_number = 0;
 
+    CHECK_INIT_RETURN(signal_init());
+
     /* Saves threads and messages max values */
     itti_desc.thread_max = thread_max;
     itti_desc.messages_id_max = messages_id_max;
+    itti_desc.thread_handling_signals = -1;
     itti_desc.threads_name = threads_name;
     itti_desc.messages_info = messages_info;
 
     /* Allocates memory for tasks info */
-    itti_desc.tasks = calloc(itti_desc.thread_max, sizeof(task_desc_t));
+    itti_desc.tasks = calloc (itti_desc.thread_max, sizeof(task_desc_t));
 
     /* Initializing each queue and related stuff */
     for (i = THREAD_FIRST; i < itti_desc.thread_max; i++) {
-        STAILQ_INIT(&itti_desc.tasks[i].message_queue);
+        STAILQ_INIT (&itti_desc.tasks[i].message_queue);
         itti_desc.tasks[i].message_in_queue = 0;
         // Initialize mutexes
-        pthread_mutex_init(&itti_desc.tasks[i].message_queue_mutex, NULL);
+        pthread_mutex_init (&itti_desc.tasks[i].message_queue_mutex, NULL);
         // Initialize Cond vars
-        pthread_cond_init(&itti_desc.tasks[i].message_queue_cond_var, NULL);
+        pthread_cond_init (&itti_desc.tasks[i].message_queue_cond_var, NULL);
         itti_desc.tasks[i].task_state = TASK_STATE_NOT_CONFIGURED;
     }
-    itti_dump_init(messages_definition_xml);
+    itti_dump_init (messages_definition_xml);
 
-    timer_init();
+    CHECK_INIT_RETURN(timer_init ());
 
     return 0;
 }
 
-void intertask_interface_send_quit_signal(void)
-{
+void itti_wait_tasks_end(void) {
+    int end = 0;
+    int i;
+
+    itti_desc.thread_handling_signals = pthread_self ();
+
+    /* Handle signals here */
+    while (end == 0) {
+        signal_handle (&end);
+    }
+
+    for (i = THREAD_FIRST; i < itti_desc.thread_max; i++) {
+        /* Skip tasks which are not running */
+        if (itti_desc.tasks[i].task_state == TASK_STATE_READY) {
+            ITTI_DEBUG("Waiting end of thread %s\n", itti_desc.threads_name[i]);
+
+            pthread_join (itti_desc.tasks[i].task_thread, NULL);
+            itti_desc.tasks[i].task_state = TASK_STATE_ENDED;
+        }
+    }
+}
+
+void itti_send_terminate_message(task_id_t task_id) {
     MessageDef *terminate_message_p;
 
-    terminate_message_p = alloc_new_message(TASK_UNKNOWN, TERMINATE_MESSAGE);
+    terminate_message_p = itti_alloc_new_message (task_id, TERMINATE_MESSAGE);
 
-    send_broadcast_message(terminate_message_p);
+    itti_send_broadcast_message (terminate_message_p);
 }
diff --git a/common/utils/itti/intertask_interface.h b/common/utils/itti/intertask_interface.h
index a92a69547b..9b1ac0851a 100644
--- a/common/utils/itti/intertask_interface.h
+++ b/common/utils/itti/intertask_interface.h
@@ -81,7 +81,7 @@ enum task_priorities {
  \param message_p Pointer to the message to send
  @returns < 0 on failure, 0 otherwise
  **/
-int send_broadcast_message(MessageDef *message_p);
+int itti_send_broadcast_message(MessageDef *message_p);
 
 /** \brief Send a message to a task (could be itself)
  \param task_id Task ID
@@ -89,21 +89,21 @@ int send_broadcast_message(MessageDef *message_p);
  \param message Pointer to the message to send
  @returns -1 on failure, 0 otherwise
  **/
-int send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message);
+int itti_send_msg_to_task(task_id_t task_id, instance_t instance, MessageDef *message);
 
 /** \brief Retrieves a message in the queue associated to task_id.
  * If the queue is empty, the thread is blocked till a new message arrives.
  \param task_id Task ID of the receiving task
  \param received_msg Pointer to the allocated message
  **/
-void receive_msg(task_id_t task_id, MessageDef **received_msg);
+void itti_receive_msg(task_id_t task_id, MessageDef **received_msg);
 
 /** \brief Try to retrieves a message in the queue associated to task_id and matching requested instance.
  \param task_id Task ID of the receiving task
  \param instance Instance of the task used for virtualization
  \param received_msg Pointer to the allocated message
  **/
-void poll_msg(task_id_t task_id, instance_t instance, MessageDef **received_msg);
+void itti_poll_msg(task_id_t task_id, instance_t instance, MessageDef **received_msg);
 
 /** \brief Start thread associated to the task
  * \param task_id task to start
@@ -111,30 +111,43 @@ void poll_msg(task_id_t task_id, instance_t instance, MessageDef **received_msg)
  * \param args_p Optional argument to pass to the start routine
  * @returns -1 on failure, 0 otherwise
  **/
-int intertask_interface_create_task(task_id_t task_id,
+int itti_create_task(task_id_t task_id,
                                     void *(*start_routine) (void *),
                                     void *args_p);
 
 /** \brief Mark the task as in ready state
  * \param task_id task to mark as ready
  **/
-void intertask_interface_mark_task_ready(task_id_t task_id);
+void itti_mark_task_ready(task_id_t task_id);
+
+/** \brief Indicate that the task is completed and initiate termination of all tasks.
+ * \param task_id task that is completed
+ **/
+void itti_terminate_tasks(task_id_t task_id);
 
 /** \brief Return the printable string associated with the message
  * \param message_id Id of the message
  **/
-char *get_message_name(MessagesIds message_id);
+char *itti_get_message_name(MessagesIds message_id);
 
 /** \brief Alloc and memset(0) a new itti message.
- \param origin_task_id Task ID of the sending task
- \param message_id Message ID
- @returns NULL in case of failure or newly allocated mesage ref
+ * \param origin_task_id Task ID of the sending task
+ * \param message_id Message ID
+ * @returns NULL in case of failure or newly allocated mesage ref
  **/
-inline MessageDef *alloc_new_message(
+inline MessageDef *itti_alloc_new_message(
     task_id_t      origin_task_id,
     MessagesIds message_id);
 
-void intertask_interface_send_quit_signal(void);
+/** \brief handle signals and wait for all threads to join when the process complete.
+ * This function should be called from the main thread after having created all ITTI tasks.
+ **/
+void itti_wait_tasks_end(void);
+
+/** \brief Send a termination message to all tasks.
+ * \param task_id task that is broadcasting the message.
+ **/
+void itti_send_terminate_message(task_id_t task_id);
 
 #endif /* INTERTASK_INTERFACE_H_ */
 /* @} */
diff --git a/common/utils/itti/intertask_interface_init.h b/common/utils/itti/intertask_interface_init.h
index f3e6f971b0..809022ad24 100644
--- a/common/utils/itti/intertask_interface_init.h
+++ b/common/utils/itti/intertask_interface_init.h
@@ -79,7 +79,7 @@ const message_info_t messages_info[] = {
  * \param threads_name Pointer on the threads name information as created by this include file
  * \param messages_info Pointer on messages information as created by this include file
  **/
-int intertask_interface_init(thread_id_t thread_max, MessagesIds messages_id_max,
+int itti_init(thread_id_t thread_max, MessagesIds messages_id_max,
                              const char * const *threads_name, const message_info_t *messages_info,
                              const char * const messages_definition_xml);
 
diff --git a/openair-cn/UTILS/signals.c b/common/utils/itti/signals.c
similarity index 93%
rename from openair-cn/UTILS/signals.c
rename to common/utils/itti/signals.c
index 51890496d2..1fc62fc0a4 100644
--- a/openair-cn/UTILS/signals.c
+++ b/common/utils/itti/signals.c
@@ -43,13 +43,13 @@
 #include <errno.h>
 
 #include "intertask_interface.h"
-#include "assertions.h"
 #include "timer.h"
 #include "backtrace.h"
+#include "assertions.h"
 
 #include "signals.h"
 
-sigset_t set;
+static sigset_t set;
 
 int signal_init(void)
 {
@@ -74,7 +74,7 @@ int signal_init(void)
 
 extern int timer_handle_signal(siginfo_t *info);
 
-int signal_handle(void)
+int signal_handle(int *end)
 {
     int ret;
     siginfo_t info;
@@ -82,6 +82,7 @@ int signal_handle(void)
     sigemptyset(&set);
 
     sigaddset (&set, SIGTIMER);
+    sigaddset (&set, SIGUSR1);
     sigaddset (&set, SIGABRT);
     sigaddset (&set, SIGSEGV);
     sigaddset (&set, SIGINT);
@@ -110,6 +111,10 @@ int signal_handle(void)
     } else {
         /* Dispatch the signal to sub-handlers */
         switch(info.si_signo) {
+            case SIGUSR1:
+                printf("Received SIGUSR1\n");
+                *end = 1;
+                break;
             case SIGSEGV:   /* Fall through */
             case SIGABRT:
                 printf("Received SIGABORT\n");
@@ -118,7 +123,7 @@ int signal_handle(void)
             case SIGQUIT:
             case SIGINT:
                 printf("Received SIGINT\n");
-                intertask_interface_send_quit_signal();
+                itti_send_terminate_message(TASK_UNKNOWN);
                 printf("All tasks terminated -> exiting '"PACKAGE_NAME"'\n");
                 exit(0);
                 break;
diff --git a/openair-cn/UTILS/signals.h b/common/utils/itti/signals.h
similarity index 75%
rename from openair-cn/UTILS/signals.h
rename to common/utils/itti/signals.h
index 2a56e71841..6901c5f051 100644
--- a/openair-cn/UTILS/signals.h
+++ b/common/utils/itti/signals.h
@@ -3,6 +3,6 @@
 
 int signal_init(void);
 
-int signal_handle(void);
+int signal_handle(int *end);
 
 #endif /* SIGNALS_H_ */
diff --git a/common/utils/itti/timer.c b/common/utils/itti/timer.c
index c34719011a..38cab81ae2 100644
--- a/common/utils/itti/timer.c
+++ b/common/utils/itti/timer.c
@@ -93,7 +93,7 @@ int timer_handle_signal(siginfo_t *info)
 
     task_id = timer_p->task_id;
     instance = timer_p->instance;
-    message_p = alloc_new_message(TASK_TIMER, TIMER_HAS_EXPIRED);
+    message_p = itti_alloc_new_message(TASK_TIMER, TIMER_HAS_EXPIRED);
 
     timer_expired_p = &message_p->msg.timer_has_expired;
 
@@ -116,7 +116,7 @@ int timer_handle_signal(siginfo_t *info)
         }
     }
     /* Notify task of timer expiry */
-    if (send_msg_to_task(task_id, instance, message_p) < 0) {
+    if (itti_send_msg_to_task(task_id, instance, message_p) < 0) {
         TMR_DEBUG("Failed to send msg TIMER_HAS_EXPIRED to task %u\n", task_id);
         free(message_p);
         return -1;
diff --git a/openair-cn/GTPV1-U/gtpv1u_task.c b/openair-cn/GTPV1-U/gtpv1u_task.c
index 6ffdee3df9..b466685041 100644
--- a/openair-cn/GTPV1-U/gtpv1u_task.c
+++ b/openair-cn/GTPV1-U/gtpv1u_task.c
@@ -77,7 +77,7 @@ static int gtpv1u_send_init_udp(uint16_t port_number)
     MessageDef *message_p;
     struct in_addr addr;
 
-    message_p = alloc_new_message(TASK_GTPV1_U, UDP_INIT);
+    message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_INIT);
     if (message_p == NULL) {
         return -1;
     }
@@ -89,7 +89,7 @@ static int gtpv1u_send_init_udp(uint16_t port_number)
     message_p->msg.udp_init.address = inet_ntoa(addr);
     GTPU_DEBUG("Tx UDP_INIT IP addr %s\n", message_p->msg.udp_init.address);
 
-    return send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 }
 
 NwGtpv1uRcT gtpv1u_log_request(NwGtpv1uLogMgrHandleT hLogMgr,
@@ -113,7 +113,7 @@ NwGtpv1uRcT gtpv1u_send_udp_msg(
     MessageDef     *message_p;
     udp_data_req_t *udp_data_req_p;
 
-    message_p = alloc_new_message(TASK_GTPV1_U, UDP_DATA_REQ);
+    message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_DATA_REQ);
 
     udp_data_req_p = &message_p->msg.udp_data_req;
 
@@ -122,7 +122,7 @@ NwGtpv1uRcT gtpv1u_send_udp_msg(
     udp_data_req_p->buffer        = buffer;
     udp_data_req_p->buffer_length = buffer_len;
 
-    return send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 }
 
 /* Callback called when a gtpv1u message arrived on UDP interface */
@@ -150,7 +150,7 @@ NwGtpv1uRcT gtpv1u_process_stack_req(
             }
             GTPU_DEBUG("Received TPDU from gtpv1u stack %u with size %d", pUlpApi->apiInfo.recvMsgInfo.teid, buffer_len);
 
-            message_p = alloc_new_message(TASK_GTPV1_U, GTPV1U_TUNNEL_DATA_IND);
+            message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_TUNNEL_DATA_IND);
             if (message_p == NULL) {
                 return -1;
             }
@@ -163,7 +163,7 @@ NwGtpv1uRcT gtpv1u_process_stack_req(
             } else {
                 memcpy(data_ind_p->buffer, buffer, buffer_len);
                 data_ind_p->length = buffer_len;
-                if (send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p) < 0) {
+                if (itti_send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p) < 0) {
                     GTPU_ERROR("Failed to send message to task\n");
                     free(message_p);
                 }
@@ -223,7 +223,7 @@ static int gtpv1u_create_s1u_tunnel(Gtpv1uCreateTunnelReq *create_tunnel_reqP)
     gtpv1u_teid2enb_info->state       = BEARER_IN_CONFIG;
 
 
-    message_p = alloc_new_message(TASK_GTPV1_U, GTPV1U_CREATE_TUNNEL_RESP);
+    message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_CREATE_TUNNEL_RESP);
     message_p->msg.gtpv1uCreateTunnelResp.S1u_teid      = s1u_teid;
     message_p->msg.gtpv1uCreateTunnelResp.context_teid  = create_tunnel_reqP->context_teid;
     message_p->msg.gtpv1uCreateTunnelResp.eps_bearer_id = create_tunnel_reqP->eps_bearer_id;
@@ -242,7 +242,7 @@ static int gtpv1u_create_s1u_tunnel(Gtpv1uCreateTunnelReq *create_tunnel_reqP)
     		message_p->msg.gtpv1uCreateTunnelResp.S1u_teid,
     		message_p->msg.gtpv1uCreateTunnelResp.eps_bearer_id,
     		message_p->msg.gtpv1uCreateTunnelResp.status);
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 
@@ -253,7 +253,7 @@ static int gtpv1u_delete_s1u_tunnel(Teid_t context_teidP, Teid_t S1U_teidP)
     MessageDef              *message_p;
 
     GTPU_DEBUG("Rx GTPV1U_DELETE_TUNNEL Context %u S1U teid %u\n", context_teidP, S1U_teidP);
-    message_p = alloc_new_message(TASK_GTPV1_U, GTPV1U_DELETE_TUNNEL_RESP);
+    message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_DELETE_TUNNEL_RESP);
 
     message_p->msg.gtpv1uDeleteTunnelResp.S1u_teid     = S1U_teidP;
     message_p->msg.gtpv1uDeleteTunnelResp.context_teid = context_teidP;
@@ -264,7 +264,7 @@ static int gtpv1u_delete_s1u_tunnel(Teid_t context_teidP, Teid_t S1U_teidP)
         message_p->msg.gtpv1uDeleteTunnelResp.status       = -1;
     }
     GTPU_DEBUG("Tx SGW_S1U_ENDPOINT_CREATED Context %u teid %u status %d\n", context_teidP, S1U_teidP, message_p->msg.gtpv1uDeleteTunnelResp.status);
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 
@@ -278,7 +278,7 @@ static int gtpv1u_update_s1u_tunnel(Gtpv1uUpdateTunnelReq *reqP)
     		reqP->context_teid,
     		reqP->sgw_S1u_teid,
     		reqP->enb_S1u_teid);
-    message_p = alloc_new_message(TASK_GTPV1_U, GTPV1U_UPDATE_TUNNEL_RESP);
+    message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_UPDATE_TUNNEL_RESP);
 
     hash_rc = hashtbl_get(gtpv1u_sgw_data.S1U_mapping, reqP->sgw_S1u_teid, (void**)&gtpv1u_teid2enb_info);
 
@@ -296,7 +296,7 @@ static int gtpv1u_update_s1u_tunnel(Gtpv1uUpdateTunnelReq *reqP)
     message_p->msg.gtpv1uUpdateTunnelResp.sgw_S1u_teid  = reqP->sgw_S1u_teid;
     message_p->msg.gtpv1uUpdateTunnelResp.enb_S1u_teid  = reqP->enb_S1u_teid;
     message_p->msg.gtpv1uUpdateTunnelResp.eps_bearer_id = reqP->eps_bearer_id;
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 
@@ -345,14 +345,14 @@ static NwGtpv1uRcT gtpv1u_stop_timer_wrapper(
 
 static void *gtpv1u_thread(void *args)
 {
-    intertask_interface_mark_task_ready(TASK_GTPV1_U);
+    itti_mark_task_ready(TASK_GTPV1_U);
     while(1) {
         /* Trying to fetch a message from the message queue.
          * If the queue is empty, this function will block till a
          * message is sent to the task.
          */
         MessageDef *received_message_p = NULL;
-        receive_msg(TASK_GTPV1_U, &received_message_p);
+        itti_receive_msg(TASK_GTPV1_U, &received_message_p);
         DevAssert(received_message_p != NULL);
 
         switch(received_message_p->header.messageId) {
@@ -453,7 +453,7 @@ static void *gtpv1u_thread(void *args)
                 break;
             default: {
                 GTPU_ERROR("Unkwnon message ID %s:%d\n",
-                           get_message_name(received_message_p->header.messageId),
+                           itti_get_message_name(received_message_p->header.messageId),
                            received_message_p->header.messageId);
             }
             break;
@@ -537,7 +537,7 @@ int gtpv1u_init(const mme_config_t *mme_config_p)
         return -1;
     }
 
-    if (intertask_interface_create_task(TASK_GTPV1_U, &gtpv1u_thread, NULL) < 0) {
+    if (itti_create_task(TASK_GTPV1_U, &gtpv1u_thread, NULL) < 0) {
         GTPU_ERROR("gtpv1u phtread_create: %s", strerror(errno));
         return -1;
     }
diff --git a/openair-cn/MME_APP/mme_app_authentication.c b/openair-cn/MME_APP/mme_app_authentication.c
index edba681e2d..692ef88555 100644
--- a/openair-cn/MME_APP/mme_app_authentication.c
+++ b/openair-cn/MME_APP/mme_app_authentication.c
@@ -54,7 +54,7 @@ int mme_app_request_authentication_info(const mme_app_imsi_t imsi,
 
     DevAssert(plmn != NULL);
 
-    message_p = alloc_new_message(TASK_MME_APP, S6A_AUTH_INFO_REQ);
+    message_p = itti_alloc_new_message(TASK_MME_APP, S6A_AUTH_INFO_REQ);
 
     if (message_p == NULL) return -1;
 
@@ -63,7 +63,7 @@ int mme_app_request_authentication_info(const mme_app_imsi_t imsi,
     memcpy(&auth_info_req->visited_plmn, plmn, sizeof(plmn_t));
     auth_info_req->nb_of_vectors = nb_of_vectors;
 
-    return send_msg_to_task(TASK_S6A, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_S6A, INSTANCE_DEFAULT, message_p);
 }
 
 int mme_app_handle_nas_auth_resp(nas_auth_resp_t *nas_auth_resp_p)
@@ -92,7 +92,7 @@ int mme_app_handle_nas_auth_resp(nas_auth_resp_t *nas_auth_resp_p)
         MessageDef                *message_p;
         s6a_update_location_req_t *s6a_ulr;
 
-        message_p = alloc_new_message(TASK_MME_APP, S6A_UPDATE_LOCATION_REQ);
+        message_p = itti_alloc_new_message(TASK_MME_APP, S6A_UPDATE_LOCATION_REQ);
 
         if (message_p == NULL) {
             return -1;
@@ -106,7 +106,7 @@ int mme_app_handle_nas_auth_resp(nas_auth_resp_t *nas_auth_resp_p)
         /* Check if we already have UE data */
         s6a_ulr->skip_subsriber_data = 0;
 
-        return send_msg_to_task(TASK_S6A, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(TASK_S6A, INSTANCE_DEFAULT, message_p);
     }
     return -1;
 }
@@ -121,7 +121,7 @@ int mme_app_handle_authentication_info_answer(s6a_auth_info_ans_t *s6a_auth_info
 
     DevAssert(s6a_auth_info_ans_p != NULL);
 
-    message_p = alloc_new_message(TASK_MME_APP, NAS_AUTHENTICATION_REQ);
+    message_p = itti_alloc_new_message(TASK_MME_APP, NAS_AUTHENTICATION_REQ);
 
     if (message_p == NULL) {
         return -1;
@@ -172,7 +172,7 @@ int mme_app_handle_authentication_info_answer(s6a_auth_info_ans_t *s6a_auth_info
                    "!= S6A_RESULT_BASE");
     }
 
-    return send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
 }
 
 int mme_app_handle_attach_req(nas_attach_req_t *attach_req_p)
@@ -270,14 +270,14 @@ request_auth:
                 /* We have a vector... USE it */
                 MME_APP_DEBUG("but we have an auth. vector for it, request"
                 " authentication from NAS\n");
-                message_p = alloc_new_message(TASK_MME_APP, NAS_AUTHENTICATION_REQ);
+                message_p = itti_alloc_new_message(TASK_MME_APP, NAS_AUTHENTICATION_REQ);
 
                 nas_auth_req_p = &message_p->msg.nas_auth_req;
 
                 MME_APP_IMSI_TO_STRING(imsi, nas_auth_req_p->imsi);
                 nas_auth_req_p->failure = NAS_FAILURE_OK;
 
-                return send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
+                return itti_send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
             }
         }
     }
diff --git a/openair-cn/MME_APP/mme_app_bearer.c b/openair-cn/MME_APP/mme_app_bearer.c
index 8347f0a922..d431f34fb1 100644
--- a/openair-cn/MME_APP/mme_app_bearer.c
+++ b/openair-cn/MME_APP/mme_app_bearer.c
@@ -115,7 +115,7 @@ int mme_app_create_bearer(s6a_update_location_ans_t *ula_p)
         DevMessage("Not implemented: ACCESS NOT GRANTED, send ESM Failure to NAS\n");
     }
 
-    message_p = alloc_new_message(TASK_MME_APP, SGW_CREATE_SESSION_REQUEST);
+    message_p = itti_alloc_new_message(TASK_MME_APP, SGW_CREATE_SESSION_REQUEST);
 
     /* WARNING:
      * Some parameters should be provided by NAS Layer:
@@ -237,7 +237,7 @@ int mme_app_create_bearer(s6a_update_location_ans_t *ula_p)
     session_request_p->serving_network.mnc[2] = ue_context->e_utran_cgi.plmn.MNCdigit3;
 
     session_request_p->selection_mode = MS_O_N_P_APN_S_V;
-    return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
 }
 
 int mme_app_handle_create_sess_resp(SgwCreateSessionResponse *create_sess_resp_p)
@@ -318,7 +318,7 @@ int mme_app_handle_create_sess_resp(SgwCreateSessionResponse *create_sess_resp_p
         MessageDef *message_p;
         nas_attach_accept_t *attach_accept_p;
 
-        message_p = alloc_new_message(TASK_MME_APP, NAS_ATTACH_ACCEPT);
+        message_p = itti_alloc_new_message(TASK_MME_APP, NAS_ATTACH_ACCEPT);
 
         attach_accept_p = &message_p->msg.nas_attach_accept;
 
@@ -344,7 +344,7 @@ int mme_app_handle_create_sess_resp(SgwCreateSessionResponse *create_sess_resp_p
         memcpy(&attach_accept_p->transparent.ambr, &ue_context_p->subscribed_ambr,
                sizeof(ambr_t));
 
-        return send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
     }
 
     return 0;
diff --git a/openair-cn/MME_APP/mme_app_main.c b/openair-cn/MME_APP/mme_app_main.c
index df27befc10..38c5bcea6e 100644
--- a/openair-cn/MME_APP/mme_app_main.c
+++ b/openair-cn/MME_APP/mme_app_main.c
@@ -49,7 +49,7 @@ void *mme_app_thread(void *args);
 
 void *mme_app_thread(void *args)
 {
-    intertask_interface_mark_task_ready(TASK_MME_APP);
+    itti_mark_task_ready(TASK_MME_APP);
 
     while(1) {
         MessageDef *received_message_p = NULL;
@@ -57,7 +57,7 @@ void *mme_app_thread(void *args)
          * If the queue is empty, this function will block till a
          * message is sent to the task.
          */
-        receive_msg(TASK_MME_APP, &received_message_p);
+        itti_receive_msg(TASK_MME_APP, &received_message_p);
         DevAssert(received_message_p != NULL);
         switch(received_message_p->header.messageId) {
             case S6A_AUTH_INFO_ANS: {
@@ -92,7 +92,7 @@ void *mme_app_thread(void *args)
             } break;
             default: {
                 MME_APP_DEBUG("Unkwnon message ID %s:%d\n",
-                              get_message_name(received_message_p->header.messageId),
+                              itti_get_message_name(received_message_p->header.messageId),
                               received_message_p->header.messageId);
             } break;
         }
@@ -109,7 +109,7 @@ int mme_app_init(const mme_config_t *mme_config_p)
     memset(&mme_app_desc, 0, sizeof(mme_app_desc));
 
     /* Create the thread associated with MME applicative layer */
-    if (intertask_interface_create_task(TASK_MME_APP, &mme_app_thread, NULL) < 0) {
+    if (itti_create_task(TASK_MME_APP, &mme_app_thread, NULL) < 0) {
         MME_APP_ERROR("MME APP create task failed\n");
         return -1;
     }
diff --git a/openair-cn/MME_APP/s6a_2_nas_cause.c b/openair-cn/MME_APP/s6a_2_nas_cause.c
index 38050c11c6..9031c6d007 100644
--- a/openair-cn/MME_APP/s6a_2_nas_cause.c
+++ b/openair-cn/MME_APP/s6a_2_nas_cause.c
@@ -36,10 +36,10 @@
 // {
 //     MessageDef *message_p;
 // 
-//     message_p = alloc_new_message(TASK_MME_APP, TASK_NAS,
+//     message_p = itti_alloc_new_message(TASK_MME_APP, TASK_NAS,
 //                                   SGW_CREATE_SESSION_REQUEST);
 // 
-//     return send_msg_to_task(TASK_NAS, message_p);
+//     return itti_send_msg_to_task(TASK_NAS, message_p);
 // }
 
 int s6a_error_2_nas_cause(uint32_t s6a_error, int experimental)
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c
index 1015c12d7e..7c36078dd8 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c
@@ -1090,13 +1090,13 @@ static int _emm_as_send(const emm_as_t* msg)
             case AS_DL_INFO_TRANSFER_REQ: {
                 int ret;
 
-                message_p = alloc_new_message(TASK_NAS, NAS_DOWNLINK_DATA_IND);
+                message_p = itti_alloc_new_message(TASK_NAS, NAS_DOWNLINK_DATA_IND);
 
                 memcpy(&message_p->msg.nas_dl_data_ind,
                        &as_msg.msg.dl_info_transfer_req,
                        sizeof(nas_dl_data_ind_t));
 
-                ret = send_msg_to_task(TASK_S1AP, 0, message_p);
+                ret = itti_send_msg_to_task(TASK_S1AP, 0, message_p);
 
                 if (ret != -1) {
                     LOG_FUNC_RETURN (RETURNok);
diff --git a/openair-cn/NAS/nas_main.c b/openair-cn/NAS/nas_main.c
index 1ea624d937..6b9fd64372 100644
--- a/openair-cn/NAS/nas_main.c
+++ b/openair-cn/NAS/nas_main.c
@@ -21,13 +21,13 @@
 
 static void *nas_intertask_interface(void *args_p)
 {
-    intertask_interface_mark_task_ready(TASK_NAS);
+    itti_mark_task_ready(TASK_NAS);
 
     while(1) {
         MessageDef *received_message_p;
 
 next_message:
-        receive_msg(TASK_NAS, &received_message_p);
+        itti_receive_msg(TASK_NAS, &received_message_p);
         switch(received_message_p->header.messageId) {
             case NAS_CONNECTION_ESTABLISHMENT_IND: {
 #if defined(DISABLE_USE_NAS)
@@ -37,7 +37,7 @@ next_message:
 
                 NAS_DEBUG("NAS abstraction: Generating NAS ATTACH REQ\n");
 
-                message_p = alloc_new_message(TASK_NAS, NAS_ATTACH_REQ);
+                message_p = itti_alloc_new_message(TASK_NAS, NAS_ATTACH_REQ);
 
                 nas_req_p = &message_p->msg.nas_attach_req;
                 transparent = &message_p->msg.nas_attach_req.transparent;
@@ -48,7 +48,7 @@ next_message:
                 memcpy(transparent, &received_message_p->msg.nas_conn_est_ind.transparent,
                        sizeof(s1ap_initial_ue_message_t));
 
-                send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
+                itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
 #else
                 nas_establish_ind_t *nas_est_ind_p;
 
@@ -61,7 +61,7 @@ next_message:
 #endif
             } break;
             case NAS_ATTACH_ACCEPT: {
-                send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, received_message_p);
+                itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, received_message_p);
                 goto next_message;
             } break;
             case NAS_AUTHENTICATION_REQ: {
@@ -70,17 +70,17 @@ next_message:
 
                 NAS_DEBUG("NAS abstraction: Generating NAS AUTHENTICATION RESPONSE\n");
 
-                message_p = alloc_new_message(TASK_NAS, NAS_AUTHENTICATION_RESP);
+                message_p = itti_alloc_new_message(TASK_NAS, NAS_AUTHENTICATION_RESP);
 
                 nas_resp_p = &message_p->msg.nas_auth_resp;
 
                 memcpy(nas_resp_p->imsi, received_message_p->msg.nas_auth_req.imsi, 16);
 
-                send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
+                itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
             } break;
             default: {
                 NAS_DEBUG("Unkwnon message ID %s:%d\n",
-                          get_message_name(received_message_p->header.messageId),
+                          itti_get_message_name(received_message_p->header.messageId),
                           received_message_p->header.messageId);
             } break;
         }
@@ -98,7 +98,7 @@ int nas_init(const mme_config_t *mme_config_p)
     emm_main_initialize();
 #endif
 
-    if (intertask_interface_create_task(TASK_NAS, &nas_intertask_interface,
+    if (itti_create_task(TASK_NAS, &nas_intertask_interface,
                                         NULL) < 0) {
         NAS_ERROR("Create task failed");
         NAS_DEBUG("Initializing NAS task interface: FAILED\n");
diff --git a/openair-cn/OAISIM_MME/oaisim_mme.c b/openair-cn/OAISIM_MME/oaisim_mme.c
index 28d43613d8..13bd51f89f 100644
--- a/openair-cn/OAISIM_MME/oaisim_mme.c
+++ b/openair-cn/OAISIM_MME/oaisim_mme.c
@@ -41,8 +41,6 @@
 #include "mme_config.h"
 #include "gtpv1u_sgw_defs.h"
 
-#include "signals.h"
-
 #include "intertask_interface_init.h"
 
 #include "sctp_primitives_server.h"
@@ -65,18 +63,12 @@
 
 int main(int argc, char *argv[])
 {
-    /* Initialize signals */
-    CHECK_INIT_RETURN(signal_init());
-
     /* Parse the command line for options and set the mme_config accordingly. */
     CHECK_INIT_RETURN(config_parse_opt_line(argc, argv, &mme_config));
 
     /* Calling each layer init function */
     CHECK_INIT_RETURN(log_init(&mme_config, oai_mme_log_specific));
-    CHECK_INIT_RETURN(intertask_interface_init(THREAD_MAX,
-                                               MESSAGES_ID_MAX, threads_name,
-                                               messages_info,
-                                               messages_definition_xml));
+    CHECK_INIT_RETURN(itti_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml));
 
     CHECK_INIT_RETURN(nas_init(&mme_config));
     CHECK_INIT_RETURN(sctp_init(&mme_config));
@@ -91,9 +83,7 @@ int main(int argc, char *argv[])
 //     if (sgw_lite_init(&mme_config) < 0) return -1;
 
     /* Handle signals here */
-    while(1) {
-        signal_handle();
-    }
+    itti_wait_tasks_end();
 
     return 0;
 }
diff --git a/openair-cn/OAI_EPC/oai_epc.c b/openair-cn/OAI_EPC/oai_epc.c
index ea2aa9a17e..0ef1633d5c 100644
--- a/openair-cn/OAI_EPC/oai_epc.c
+++ b/openair-cn/OAI_EPC/oai_epc.c
@@ -47,7 +47,6 @@
 #include "gtpv1u_sgw_defs.h"
 
 #include "assertions.h"
-#include "signals.h"
 
 #include "intertask_interface_init.h"
 
@@ -70,19 +69,12 @@
 
 int main(int argc, char *argv[])
 {
-    /* Initialize signals. Note that signals should be initialized before
-     * other threads are created as it will block signals for child threads.
-     */
-    CHECK_INIT_RETURN(signal_init());
-
     /* 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(intertask_interface_init(THREAD_MAX, MESSAGES_ID_MAX,
-                                               threads_name, messages_info,
-                                               messages_definition_xml));
+    CHECK_INIT_RETURN(itti_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml));
 
     CHECK_INIT_RETURN(nas_init(&mme_config));
     CHECK_INIT_RETURN(sctp_init(&mme_config));
@@ -97,9 +89,7 @@ int main(int argc, char *argv[])
     CHECK_INIT_RETURN(sgw_lite_init(&mme_config));
 
     /* Handle signals here */
-    while(1) {
-        signal_handle();
-    }
+    itti_wait_tasks_end();
 
     return 0;
 }
diff --git a/openair-cn/OAI_SGW/oai_sgw.c b/openair-cn/OAI_SGW/oai_sgw.c
index 8ab322a04e..b9ce26dea1 100644
--- a/openair-cn/OAI_SGW/oai_sgw.c
+++ b/openair-cn/OAI_SGW/oai_sgw.c
@@ -41,8 +41,6 @@
 #include "assertions.h"
 #include "mme_config.h"
 
-#include "signals.h"
-
 #include "intertask_interface_init.h"
 
 #include "udp_primitives_server.h"
@@ -57,17 +55,12 @@
 
 int main(int argc, char *argv[])
 {
-    /* Initialize signals */
-    CHECK_INIT_RETURN(signal_init());
-
     /* Parse the command line for options and set the mme_config accordingly. */
     CHECK_INIT_RETURN(config_parse_opt_line(argc, argv, &mme_config));
 
     /* Calling each layer init function */
     CHECK_INIT_RETURN(log_init(&mme_config, oai_sgw_log_specific));
-    CHECK_INIT_RETURN(intertask_interface_init(THREAD_MAX, MESSAGES_ID_MAX,
-                                               threads_name, messages_info,
-                                               messages_definition_xml));
+    CHECK_INIT_RETURN(itti_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml));
 
     CHECK_INIT_RETURN(udp_init(&mme_config));
     CHECK_INIT_RETURN(s11_sgw_init(&mme_config));
@@ -77,9 +70,7 @@ int main(int argc, char *argv[])
     CHECK_INIT_RETURN(sgw_lite_init(&mme_config));
 
     /* Handle signals here */
-    while(1) {
-        signal_handle();
-    }
+    itti_wait_tasks_end();
 
     return 0;
 }
diff --git a/openair-cn/S11/s11_mme_session_manager.c b/openair-cn/S11/s11_mme_session_manager.c
index 51255e3d69..94dcbd7bc4 100644
--- a/openair-cn/S11/s11_mme_session_manager.c
+++ b/openair-cn/S11/s11_mme_session_manager.c
@@ -96,7 +96,7 @@ int s11_mme_handle_create_session_response(NwGtpv2cStackHandleT *stack_p,
 
     DevAssert(stack_p != NULL);
 
-    message_p = alloc_new_message(TASK_S11, SGW_CREATE_SESSION_RESPONSE);
+    message_p = itti_alloc_new_message(TASK_S11, SGW_CREATE_SESSION_RESPONSE);
 
     create_session_resp_p = &message_p->msg.sgwCreateSessionResponse;
 
@@ -173,5 +173,5 @@ int s11_mme_handle_create_session_response(NwGtpv2cStackHandleT *stack_p,
     rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
     DevAssert(NW_OK == rc);
 
-    return send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
 }
diff --git a/openair-cn/S11/s11_mme_task.c b/openair-cn/S11/s11_mme_task.c
index bb0fe20189..161f8e58c3 100644
--- a/openair-cn/S11/s11_mme_task.c
+++ b/openair-cn/S11/s11_mme_task.c
@@ -110,7 +110,7 @@ NwRcT s11_mme_send_udp_msg(
     udp_data_req_t *udp_data_req_p;
     int ret = 0;
 
-    message_p = alloc_new_message(TASK_S11, UDP_DATA_REQ);
+    message_p = itti_alloc_new_message(TASK_S11, UDP_DATA_REQ);
 
     udp_data_req_p = &message_p->msg.udp_data_req;
 
@@ -119,7 +119,7 @@ NwRcT s11_mme_send_udp_msg(
     udp_data_req_p->buffer        = buffer;
     udp_data_req_p->buffer_length = buffer_len;
 
-    ret = send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
+    ret = itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 
     return ((ret == 0) ? NW_OK : NW_FAILURE);
 }
@@ -173,10 +173,10 @@ NwRcT s11_mme_stop_timer_wrapper(
 
 static void *s11_mme_thread(void *args)
 {
-    intertask_interface_mark_task_ready(TASK_S11);
+    itti_mark_task_ready(TASK_S11);
     while(1) {
         MessageDef *received_message_p = NULL;
-        receive_msg(TASK_S11, &received_message_p);
+        itti_receive_msg(TASK_S11, &received_message_p);
         assert(received_message_p != NULL);
 
         switch(received_message_p->header.messageId) {
@@ -209,7 +209,7 @@ static void *s11_mme_thread(void *args)
             } break;
             default: {
                 S11_ERROR("Unkwnon message ID %s:%d\n",
-                          get_message_name(received_message_p->header.messageId),
+                          itti_get_message_name(received_message_p->header.messageId),
                           received_message_p->header.messageId);
             }
             break;
@@ -224,7 +224,7 @@ static int s11_send_init_udp(char *address, uint16_t port_number)
 {
     MessageDef *message_p;
 
-    message_p = alloc_new_message(TASK_S11, UDP_INIT);
+    message_p = itti_alloc_new_message(TASK_S11, UDP_INIT);
     if (message_p == NULL) {
         return -1;
     }
@@ -235,7 +235,7 @@ static int s11_send_init_udp(char *address, uint16_t port_number)
 
     S11_DEBUG("Tx UDP_INIT IP addr %s\n", message_p->msg.udp_init.address);
 
-    return send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 }
 
 int s11_mme_init(const mme_config_t *mme_config_p)
@@ -276,7 +276,7 @@ int s11_mme_init(const mme_config_t *mme_config_p)
     logMgr.logReqCallback  = s11_mme_log_wrapper;
     DevAssert(NW_OK == nwGtpv2cSetLogMgrEntity(s11_mme_stack_handle, &logMgr));
 
-    if (intertask_interface_create_task(TASK_S11, &s11_mme_thread, NULL) < 0) {
+    if (itti_create_task(TASK_S11, &s11_mme_thread, NULL) < 0) {
         S11_ERROR("gtpv1u phtread_create: %s\n", strerror(errno));
         goto fail;
     }
diff --git a/openair-cn/S11/s11_sgw.c b/openair-cn/S11/s11_sgw.c
index c5c56bfb84..8c695cd0ad 100644
--- a/openair-cn/S11/s11_sgw.c
+++ b/openair-cn/S11/s11_sgw.c
@@ -110,7 +110,7 @@ NwRcT s11_sgw_send_udp_msg(
     udp_data_req_t *udp_data_req_p;
     int ret = 0;
 
-    message_p = alloc_new_message(TASK_S11, UDP_DATA_REQ);
+    message_p = itti_alloc_new_message(TASK_S11, UDP_DATA_REQ);
 
     udp_data_req_p = &message_p->msg.udp_data_req;
 
@@ -119,7 +119,7 @@ NwRcT s11_sgw_send_udp_msg(
     udp_data_req_p->buffer        = buffer;
     udp_data_req_p->buffer_length = buffer_len;
 
-    ret = send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
+    ret = itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 
     return ret == 0 ? NW_OK : NW_FAILURE;
 }
@@ -185,10 +185,10 @@ NwRcT s11_sgw_stop_timer_wrapper(
 
 static void *s11_sgw_thread(void *args)
 {
-    intertask_interface_mark_task_ready(TASK_S11);
+    itti_mark_task_ready(TASK_S11);
     while(1) {
         MessageDef *received_message_p = NULL;
-        receive_msg(TASK_S11, &received_message_p);
+        itti_receive_msg(TASK_S11, &received_message_p);
         assert(received_message_p != NULL);
 
         switch(received_message_p->header.messageId) {
@@ -235,7 +235,7 @@ static void *s11_sgw_thread(void *args)
             } break;
             default: {
                 S11_ERROR("Unkwnon message ID %s:%d\n",
-                          get_message_name(received_message_p->header.messageId),
+                          itti_get_message_name(received_message_p->header.messageId),
                           received_message_p->header.messageId);
             }
             break;
@@ -250,7 +250,7 @@ static int s11_send_init_udp(char *address, uint16_t port_number)
 {
     MessageDef *message_p;
 
-    message_p = alloc_new_message(TASK_S11, UDP_INIT);
+    message_p = itti_alloc_new_message(TASK_S11, UDP_INIT);
     if (message_p == NULL) {
         return -1;
     }
@@ -261,7 +261,7 @@ static int s11_send_init_udp(char *address, uint16_t port_number)
 
     S11_DEBUG("Tx UDP_INIT IP addr %s\n", message_p->msg.udp_init.address);
 
-    return send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
 }
 
 int s11_sgw_init(const mme_config_t *mme_config_p)
@@ -302,7 +302,7 @@ int s11_sgw_init(const mme_config_t *mme_config_p)
 
     DevAssert(NW_OK == nwGtpv2cSetLogMgrEntity(s11_sgw_stack_handle, &logMgr));
 
-    if (intertask_interface_create_task(TASK_S11, &s11_sgw_thread, NULL) < 0) {
+    if (itti_create_task(TASK_S11, &s11_sgw_thread, NULL) < 0) {
         S11_ERROR("gtpv1u phtread_create: %s\n", strerror(errno));
         goto fail;
     }
diff --git a/openair-cn/S11/s11_sgw_bearer_manager.c b/openair-cn/S11/s11_sgw_bearer_manager.c
index 95185c9e9b..844438a7a0 100644
--- a/openair-cn/S11/s11_sgw_bearer_manager.c
+++ b/openair-cn/S11/s11_sgw_bearer_manager.c
@@ -32,7 +32,7 @@ int s11_sgw_handle_modify_bearer_request(NwGtpv2cStackHandleT *stack_p,
 
     DevAssert(stack_p != NULL);
 
-    message_p = alloc_new_message(TASK_S11, SGW_MODIFY_BEARER_REQUEST);
+    message_p = itti_alloc_new_message(TASK_S11, SGW_MODIFY_BEARER_REQUEST);
 
     modify_bearer_request_p = &message_p->msg.sgwModifyBearerRequest;
 
@@ -159,7 +159,7 @@ int s11_sgw_handle_modify_bearer_request(NwGtpv2cStackHandleT *stack_p,
     rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
     DevAssert(NW_OK == rc);
 
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 int s11_sgw_handle_modify_bearer_response(
diff --git a/openair-cn/S11/s11_sgw_session_manager.c b/openair-cn/S11/s11_sgw_session_manager.c
index 4368720d54..7e52dbe2b8 100644
--- a/openair-cn/S11/s11_sgw_session_manager.c
+++ b/openair-cn/S11/s11_sgw_session_manager.c
@@ -32,7 +32,7 @@ int s11_sgw_handle_create_session_request(NwGtpv2cStackHandleT *stack_p,
 
     DevAssert(stack_p != NULL);
 
-    message_p = alloc_new_message(TASK_S11, SGW_CREATE_SESSION_REQUEST);
+    message_p = itti_alloc_new_message(TASK_S11, SGW_CREATE_SESSION_REQUEST);
 
     create_session_request_p = &message_p->msg.sgwCreateSessionRequest;
 
@@ -244,7 +244,7 @@ int s11_sgw_handle_create_session_request(NwGtpv2cStackHandleT *stack_p,
     rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
     DevAssert(NW_OK == rc);
 
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 int s11_sgw_handle_create_session_response(
@@ -333,7 +333,7 @@ int s11_sgw_handle_delete_session_request(NwGtpv2cStackHandleT *stack_p,
 
     DevAssert(stack_p != NULL);
 
-    message_p = alloc_new_message(TASK_S11, SGW_DELETE_SESSION_REQUEST);
+    message_p = itti_alloc_new_message(TASK_S11, SGW_DELETE_SESSION_REQUEST);
 
     delete_session_request_p = &message_p->msg.sgwDeleteSessionRequest;
 
@@ -444,7 +444,7 @@ int s11_sgw_handle_delete_session_request(NwGtpv2cStackHandleT *stack_p,
     rc = nwGtpv2cMsgDelete(*stack_p, (pUlpApi->hMsg));
     DevAssert(NW_OK == rc);
 
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 int s11_sgw_handle_delete_session_response(
diff --git a/openair-cn/S1AP/s1ap_mme.c b/openair-cn/S1AP/s1ap_mme.c
index 865d005dec..2de7b7a1ef 100644
--- a/openair-cn/S1AP/s1ap_mme.c
+++ b/openair-cn/S1AP/s1ap_mme.c
@@ -68,7 +68,7 @@ void *s1ap_mme_thread(void *args);
 static int s1ap_send_init_sctp(void) {
     // Create and alloc new message
     MessageDef *message_p;
-    message_p = alloc_new_message(TASK_S1AP, SCTP_INIT_MSG);
+    message_p = itti_alloc_new_message(TASK_S1AP, SCTP_INIT_MSG);
     message_p->msg.sctpInit.port = S1AP_PORT_NUMBER;
     message_p->msg.sctpInit.ppid = S1AP_SCTP_PPID;
     message_p->msg.sctpInit.ipv4 = 1;
@@ -81,20 +81,20 @@ static int s1ap_send_init_sctp(void) {
     message_p->msg.sctpInit.nb_ipv6_addr = 0;
     message_p->msg.sctpInit.ipv6_address[0] = "0:0:0:0:0:0:0:1";
 
-    return send_msg_to_task(TASK_SCTP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, INSTANCE_DEFAULT, message_p);
 }
 
 void *s1ap_mme_thread(void *args)
 {
     MessageDef *received_message_p;
 
-    intertask_interface_mark_task_ready(TASK_S1AP);
+    itti_mark_task_ready(TASK_S1AP);
     while(1) {
         /* Trying to fetch a message from the message queue.
          * If the queue is empty, this function will block till a
          * message is sent to the task.
          */
-        receive_msg(TASK_S1AP, &received_message_p);
+        itti_receive_msg(TASK_S1AP, &received_message_p);
         assert(received_message_p != NULL);
         switch(received_message_p->header.messageId) {
             case S1AP_SCTP_NEW_MESSAGE_IND: {
@@ -140,7 +140,7 @@ void *s1ap_mme_thread(void *args)
             } break;
             default: {
                 S1AP_DEBUG("Unkwnon message ID %s:%d\n",
-                           get_message_name(received_message_p->header.messageId),
+                           itti_get_message_name(received_message_p->header.messageId),
                            received_message_p->header.messageId);
             } break;
         }
@@ -170,7 +170,7 @@ int s1ap_mme_init(const mme_config_t *mme_config_p) {
 # endif
 #endif
 
-    if (intertask_interface_create_task(TASK_S1AP, &s1ap_mme_thread, NULL) < 0) {
+    if (itti_create_task(TASK_S1AP, &s1ap_mme_thread, NULL) < 0) {
         S1AP_ERROR("Error while creating S1AP task\n");
         return -1;
     }
diff --git a/openair-cn/S1AP/s1ap_mme_handlers.c b/openair-cn/S1AP/s1ap_mme_handlers.c
index 5aae56e63b..5e0b084faf 100644
--- a/openair-cn/S1AP/s1ap_mme_handlers.c
+++ b/openair-cn/S1AP/s1ap_mme_handlers.c
@@ -445,7 +445,7 @@ int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
         MessageDef        *message_p;
         s1ap_ue_cap_ind_t *ue_cap_ind_p;
 
-        message_p = alloc_new_message(TASK_S1AP, S1AP_UE_CAPABILITIES_IND);
+        message_p = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CAPABILITIES_IND);
 
         DevAssert(message_p != NULL);
 
@@ -461,7 +461,7 @@ int s1ap_mme_handle_ue_cap_indication(uint32_t assoc_id, uint32_t stream,
 
         ue_cap_ind_p->radio_capabilities_length = ue_cap_p->ueRadioCapability.size;
 
-        return send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
     }
     return 0;
 }
@@ -506,7 +506,7 @@ int s1ap_mme_handle_initial_context_setup_response(
 
     ue_ref->s1_ue_state = S1AP_UE_CONNECTED;
 
-    message_p = alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_REQUEST);
+    message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_REQUEST);
 
     if (message_p == NULL) {
         return -1;
@@ -525,7 +525,7 @@ int s1ap_mme_handle_initial_context_setup_response(
     memcpy(&modify_request_p->bearer_context_to_modify.s1_eNB_fteid.ipv4_address,
            eRABSetupItemCtxtSURes_p->transportLayerAddress.buf, 4);
 
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 int s1ap_mme_handle_ue_context_release_request(uint32_t assoc_id,
diff --git a/openair-cn/S1AP/s1ap_mme_itti_messaging.c b/openair-cn/S1AP/s1ap_mme_itti_messaging.c
index 82a4d9b389..574a42653b 100644
--- a/openair-cn/S1AP/s1ap_mme_itti_messaging.c
+++ b/openair-cn/S1AP/s1ap_mme_itti_messaging.c
@@ -36,7 +36,7 @@ int s1ap_mme_itti_send_sctp_request(uint8_t *buffer, uint32_t length,
     MessageDef     *message_p;
     SctpNewDataReq *sctpNewDataReq_p;
 
-    message_p = alloc_new_message(TASK_SCTP, SCTP_NEW_DATA_REQ);
+    message_p = itti_alloc_new_message(TASK_SCTP, SCTP_NEW_DATA_REQ);
 
     sctpNewDataReq_p = &message_p->msg.sctpNewDataReq;
 
@@ -45,7 +45,7 @@ int s1ap_mme_itti_send_sctp_request(uint8_t *buffer, uint32_t length,
     sctpNewDataReq_p->assocId = assoc_id;
     sctpNewDataReq_p->stream  = stream;
 
-    return send_msg_to_task(TASK_SCTP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, INSTANCE_DEFAULT, message_p);
 }
 
 int s1ap_mme_itti_forward_nas_uplink(uint8_t *buffer, uint32_t length)
diff --git a/openair-cn/S1AP/s1ap_mme_nas_procedures.c b/openair-cn/S1AP/s1ap_mme_nas_procedures.c
index 1bf88a3b23..2ffb50b306 100644
--- a/openair-cn/S1AP/s1ap_mme_nas_procedures.c
+++ b/openair-cn/S1AP/s1ap_mme_nas_procedures.c
@@ -127,7 +127,7 @@ int s1ap_mme_handle_initial_ue_message(uint32_t assoc_id, uint32_t stream,
 
             s1ap_initial_ue_message_t *s1ap_p;
 
-            message_p = alloc_new_message(TASK_S1AP, NAS_CONNECTION_ESTABLISHMENT_IND);
+            message_p = itti_alloc_new_message(TASK_S1AP, NAS_CONNECTION_ESTABLISHMENT_IND);
             /* We failed to allocate a new message... */
             if (message_p == NULL) {
                 return -1;
@@ -164,7 +164,7 @@ int s1ap_mme_handle_initial_ue_message(uint32_t assoc_id, uint32_t stream,
             memcpy(con_ind_p->initialNasMsg.data, initialUEMessage_p->nas_pdu.buf,
                    initialUEMessage_p->nas_pdu.size);
 
-            return send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
+            return itti_send_msg_to_task(TASK_NAS, INSTANCE_DEFAULT, message_p);
         }
     }
     return 0;
diff --git a/openair-cn/S6A/s6a_auth_info.c b/openair-cn/S6A/s6a_auth_info.c
index cbcefbee7e..fcc598ba84 100644
--- a/openair-cn/S6A/s6a_auth_info.c
+++ b/openair-cn/S6A/s6a_auth_info.c
@@ -200,7 +200,7 @@ int s6a_aia_cb(struct msg **msg, struct avp *paramavp,
 
     DevAssert(qry != NULL);
 
-    message_p = alloc_new_message(TASK_S6A, S6A_AUTH_INFO_ANS);
+    message_p = itti_alloc_new_message(TASK_S6A, S6A_AUTH_INFO_ANS);
     s6a_auth_info_ans_p = &message_p->msg.s6a_auth_info_ans;
 
     S6A_DEBUG("Received S6A Authentication Information Answer (AIA)\n");
@@ -257,7 +257,7 @@ int s6a_aia_cb(struct msg **msg, struct avp *paramavp,
         DevMessage("We requested E-UTRAN vectors with an immediate response...\n");
     }
 
-    send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
+    itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
 err:
     return 0;
 }
diff --git a/openair-cn/S6A/s6a_task.c b/openair-cn/S6A/s6a_task.c
index 36fc768e7b..d07c4c299e 100644
--- a/openair-cn/S6A/s6a_task.c
+++ b/openair-cn/S6A/s6a_task.c
@@ -67,7 +67,7 @@ static void fd_gnutls_debug(int level, const char *str)
 
 void *s6a_thread(void *args)
 {
-    intertask_interface_mark_task_ready(TASK_S6A);
+    itti_mark_task_ready(TASK_S6A);
 
     while(1) {
         MessageDef *received_message_p = NULL;
@@ -75,7 +75,7 @@ void *s6a_thread(void *args)
          * If the queue is empty, this function will block till a
          * message is sent to the task.
          */
-        receive_msg(TASK_S6A, &received_message_p);
+        itti_receive_msg(TASK_S6A, &received_message_p);
         DevAssert(received_message_p != NULL);
         switch(received_message_p->header.messageId) {
             case S6A_UPDATE_LOCATION_REQ: {
@@ -86,7 +86,7 @@ void *s6a_thread(void *args)
             } break;
             default: {
                 S6A_DEBUG("Unkwnon message ID %s:%d\n",
-                          get_message_name(received_message_p->header.messageId),
+                          itti_get_message_name(received_message_p->header.messageId),
                           received_message_p->header.messageId);
             } break;
         }
@@ -156,7 +156,7 @@ int s6a_init(const mme_config_t *mme_config_p)
     /* Trying to connect to peers */
     CHECK_FCT(s6a_fd_new_peer());
 
-    if (intertask_interface_create_task(TASK_S6A, &s6a_thread, NULL) < 0) {
+    if (itti_create_task(TASK_S6A, &s6a_thread, NULL) < 0) {
         S6A_ERROR("s6a create task\n");
         return -1;
     }
diff --git a/openair-cn/S6A/s6a_up_loc.c b/openair-cn/S6A/s6a_up_loc.c
index d5023d5865..453413b221 100644
--- a/openair-cn/S6A/s6a_up_loc.c
+++ b/openair-cn/S6A/s6a_up_loc.c
@@ -60,7 +60,7 @@ int s6a_ula_cb(struct msg **msg, struct avp *paramavp,
 
     DevAssert(qry != NULL);
 
-    message_p = alloc_new_message(TASK_S6A, S6A_UPDATE_LOCATION_ANS);
+    message_p = itti_alloc_new_message(TASK_S6A, S6A_UPDATE_LOCATION_ANS);
 
     s6a_update_location_ans_p = &message_p->msg.s6a_update_location_ans;
 
@@ -152,7 +152,7 @@ err:
 
     ans = NULL;
 
-    send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
+    itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
 
     S6A_DEBUG("Sending S6A_UPDATE_LOCATION_ANS to task MME_APP\n");
 
diff --git a/openair-cn/SCTP/sctp_itti_messaging.c b/openair-cn/SCTP/sctp_itti_messaging.c
index 8d88a8940a..6614d05dbb 100644
--- a/openair-cn/SCTP/sctp_itti_messaging.c
+++ b/openair-cn/SCTP/sctp_itti_messaging.c
@@ -10,7 +10,7 @@ int sctp_itti_send_new_association(uint32_t assoc_id, uint16_t instreams,
     MessageDef      *message_p;
     sctp_new_peer_t *sctp_new_peer_p;
 
-    message_p = alloc_new_message(TASK_SCTP, SCTP_NEW_ASSOCIATION);
+    message_p = itti_alloc_new_message(TASK_SCTP, SCTP_NEW_ASSOCIATION);
 
     sctp_new_peer_p = &message_p->msg.sctp_new_peer;
 
@@ -18,7 +18,7 @@ int sctp_itti_send_new_association(uint32_t assoc_id, uint16_t instreams,
     sctp_new_peer_p->instreams  = instreams;
     sctp_new_peer_p->outstreams = outstreams;
 
-    return send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
 }
 
 int sctp_itti_send_new_message_ind(int n, uint8_t *buffer, uint32_t assoc_id,
@@ -28,7 +28,7 @@ int sctp_itti_send_new_message_ind(int n, uint8_t *buffer, uint32_t assoc_id,
     MessageDef              *message_p;
     s1ap_sctp_new_msg_ind_t *sctp_new_msg_ind_p;
 
-    message_p = alloc_new_message(TASK_SCTP, S1AP_SCTP_NEW_MESSAGE_IND);
+    message_p = itti_alloc_new_message(TASK_SCTP, S1AP_SCTP_NEW_MESSAGE_IND);
 
     sctp_new_msg_ind_p = &message_p->msg.s1ap_sctp_new_msg_ind;
 
@@ -42,7 +42,7 @@ int sctp_itti_send_new_message_ind(int n, uint8_t *buffer, uint32_t assoc_id,
     sctp_new_msg_ind_p->instreams = instreams;
     sctp_new_msg_ind_p->outstreams = outstreams;
 
-    return send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
 }
 
 int sctp_itti_send_com_down_ind(uint32_t assoc_id)
@@ -50,11 +50,11 @@ int sctp_itti_send_com_down_ind(uint32_t assoc_id)
     MessageDef *message_p;
     sctp_close_association_t *sctp_close_association_p;
 
-    message_p = alloc_new_message(TASK_SCTP, SCTP_CLOSE_ASSOCIATION);
+    message_p = itti_alloc_new_message(TASK_SCTP, SCTP_CLOSE_ASSOCIATION);
 
     sctp_close_association_p = &message_p->msg.sctp_close_association;
 
     sctp_close_association_p->assoc_id = assoc_id;
 
-    return send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
 }
diff --git a/openair-cn/SCTP/sctp_primitives_server.c b/openair-cn/SCTP/sctp_primitives_server.c
index 6000e1b755..2365a4d588 100644
--- a/openair-cn/SCTP/sctp_primitives_server.c
+++ b/openair-cn/SCTP/sctp_primitives_server.c
@@ -583,11 +583,11 @@ void *sctp_receiver_thread(void *args_p)
 
 static void *sctp_intertask_interface(void *args_p)
 {
-    intertask_interface_mark_task_ready(TASK_SCTP);
+    itti_mark_task_ready(TASK_SCTP);
 
     while(1) {
         MessageDef *received_message_p;
-        receive_msg(TASK_SCTP, &received_message_p);
+        itti_receive_msg(TASK_SCTP, &received_message_p);
         switch(received_message_p->header.messageId) {
             case SCTP_INIT_MSG: {
                 SCTP_DEBUG("Received SCTP_INIT_MSG\n");
@@ -616,7 +616,7 @@ static void *sctp_intertask_interface(void *args_p)
             } break;
             default: {
                 SCTP_DEBUG("Unkwnon message ID %s:%d\n",
-                           get_message_name(received_message_p->header.messageId),
+                           itti_get_message_name(received_message_p->header.messageId),
                            received_message_p->header.messageId);
             } break;
         }
@@ -636,7 +636,7 @@ int sctp_init(const mme_config_t *mme_config_p)
     sctp_desc.nb_instreams  = mme_config_p->sctp_config.in_streams;
     sctp_desc.nb_outstreams = mme_config_p->sctp_config.out_streams;
 
-    if (intertask_interface_create_task(TASK_SCTP, &sctp_intertask_interface,
+    if (itti_create_task(TASK_SCTP, &sctp_intertask_interface,
                                         NULL) < 0) {
         SCTP_ERROR("create task failed");
         SCTP_DEBUG("Initializing SCTP task interface: FAILED\n");
diff --git a/openair-cn/SECU/Makefile.am b/openair-cn/SECU/Makefile.am
index 173b3f2766..ffe344779c 100644
--- a/openair-cn/SECU/Makefile.am
+++ b/openair-cn/SECU/Makefile.am
@@ -1,5 +1,6 @@
 AM_CFLAGS = @ADD_CFLAGS@ 	\
 	-I$(top_srcdir)/UTILS	\
+	-I$(top_srcdir)/INTERTASK_INTERFACE	\
 	-I$(top_srcdir)/COMMON
 
 noinst_LTLIBRARIES = libsecu.la
diff --git a/openair-cn/SGI/sgi_egress.c b/openair-cn/SGI/sgi_egress.c
index 6234267a85..80506c524a 100755
--- a/openair-cn/SGI/sgi_egress.c
+++ b/openair-cn/SGI/sgi_egress.c
@@ -146,7 +146,7 @@ void sgi_process_raw_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int
         return;
     }
 
-    message_p               = alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ);
+    message_p               = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ);
     if (message_p == NULL) {
         SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__);
         return;
@@ -167,7 +167,7 @@ void sgi_process_raw_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int
     gtpv1u_tunnel_data_req_p->buffer       = message_payload_p;
     SGI_IF_DEBUG("%s send GTPV1U_TUNNEL_DATA_REQ to GTPV1U S1u_enb_teid %u local_S1u_teid %u size %u\n", __FUNCTION__, gtpv1u_tunnel_data_req_p->S1u_enb_teid, gtpv1u_tunnel_data_req_p->local_S1u_teid, packet_sizeP);
 
-    send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
+    itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
 
 }
 #else
@@ -279,7 +279,7 @@ void sgi_process_raw_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int
         return;
     }
 
-    message_p               = alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ);
+    message_p               = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ);
     if (message_p == NULL) {
         SGI_IF_ERROR("%s OUT OF MEMORY DROP EGRESS PACKET\n", __FUNCTION__);
         return;
@@ -300,7 +300,7 @@ void sgi_process_raw_packet(sgi_data_t *sgi_data_pP, unsigned char* data_pP, int
     gtpv1u_tunnel_data_req_p->buffer       = message_payload_p;
     SGI_IF_DEBUG("%s send GTPV1U_TUNNEL_DATA_REQ to GTPV1U S1u_enb_teid %u local_S1u_teid %u size %u\n", __FUNCTION__, gtpv1u_tunnel_data_req_p->S1u_enb_teid, gtpv1u_tunnel_data_req_p->local_S1u_teid, packet_sizeP);
 
-    send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
+    itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
 
 }
 #endif
diff --git a/openair-cn/SGI/sgi_nf.c b/openair-cn/SGI/sgi_nf.c
index 7bb25f57b6..42d43d948c 100755
--- a/openair-cn/SGI/sgi_nf.c
+++ b/openair-cn/SGI/sgi_nf.c
@@ -211,7 +211,7 @@ static int sgi_nfqueue_callback(struct nfq_q_handle *myQueue, struct nfgenmsg *m
 
   //sgi_print_hex_octets((unsigned char *)pktData, len);
 
-  message_p = alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ);
+  message_p = itti_alloc_new_message(TASK_FW_IP, GTPV1U_TUNNEL_DATA_REQ);
   if (message_p == NULL) {
       return -1;
   }
@@ -233,7 +233,7 @@ static int sgi_nfqueue_callback(struct nfq_q_handle *myQueue, struct nfgenmsg *m
     	  memcpy(data_req_p->buffer, pktData, len);
     	  data_req_p->length = len;
 
-    	  if (send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p) < 0) {
+    	  if (itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p) < 0) {
     		  SGI_IF_ERROR("Failed to send message to task\n");
     		  free(message_p);
     	  }
diff --git a/openair-cn/SGI/sgi_task.c b/openair-cn/SGI/sgi_task.c
index 480ee77590..74772db493 100644
--- a/openair-cn/SGI/sgi_task.c
+++ b/openair-cn/SGI/sgi_task.c
@@ -61,7 +61,7 @@ static void* sgi_task_thread(void *args_p)
         return NULL;
     }
 
-    intertask_interface_mark_task_ready(TASK_FW_IP);
+    itti_mark_task_ready(TASK_FW_IP);
 
     sgi_data_p = (sgi_data_t *)args_p;
 
@@ -72,7 +72,7 @@ static void* sgi_task_thread(void *args_p)
          * message is sent to the task.
          */
         MessageDef *received_message_p;
-        receive_msg(TASK_FW_IP, &received_message_p);
+        itti_receive_msg(TASK_FW_IP, &received_message_p);
         assert(received_message_p != NULL);
         switch(received_message_p->header.messageId) {
             case GTPV1U_TUNNEL_DATA_IND: {
@@ -126,7 +126,7 @@ static int sgi_create_endpoint_request(sgi_data_t *sgi_dataP, SGICreateEndpointR
     SGI_IF_DEBUG("Rx IP_FW_CREATE_SGI_ENDPOINT_REQUEST, Context: S-GW S11 teid %u, S-GW S1U teid %u EPS bearer id %u\n",
     		req_p->context_teid, req_p->sgw_S1u_teid, req_p->eps_bearer_id);
 
-  	message_p               = alloc_new_message(TASK_FW_IP, SGI_CREATE_ENDPOINT_RESPONSE);
+  	message_p               = itti_alloc_new_message(TASK_FW_IP, SGI_CREATE_ENDPOINT_RESPONSE);
     if (message_p == NULL) {
         return -1;
     }
@@ -161,7 +161,7 @@ static int sgi_create_endpoint_request(sgi_data_t *sgi_dataP, SGICreateEndpointR
             }
     	}
     }
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 //------------------------------------------------------
@@ -175,7 +175,7 @@ static int sgi_update_endpoint_request(sgi_data_t *sgi_dataP, SGIUpdateEndpointR
     SGI_IF_DEBUG("Rx IP_FW_UPDATE_SGI_ENDPOINT_REQUEST, Context: S-GW S11 teid %u, S-GW S1U teid %u EPS bearer id %u\n",
     		req_p->context_teid, req_p->sgw_S1u_teid, req_p->eps_bearer_id);
 
-  	message_p               = alloc_new_message(TASK_FW_IP, SGI_UPDATE_ENDPOINT_RESPONSE);
+  	message_p               = itti_alloc_new_message(TASK_FW_IP, SGI_UPDATE_ENDPOINT_RESPONSE);
     if (message_p == NULL) {
         return -1;
     }
@@ -193,7 +193,7 @@ static int sgi_update_endpoint_request(sgi_data_t *sgi_dataP, SGIUpdateEndpointR
         SGI_IF_ERROR("SGI_STATUS_ERROR_CONTEXT_NOT_FOUND Context: S11 teid %u\n", req_p->context_teid);
         sgi_update_endpoint_resp_p->status       = SGI_STATUS_ERROR_CONTEXT_NOT_FOUND;
     }
-    return send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
 }
 
 //-----------------------------------------------------------------------------
diff --git a/openair-cn/SGW-LITE/sgw_lite_handlers.c b/openair-cn/SGW-LITE/sgw_lite_handlers.c
index c1e6727046..84e3f7692e 100644
--- a/openair-cn/SGW-LITE/sgw_lite_handlers.c
+++ b/openair-cn/SGW-LITE/sgw_lite_handlers.c
@@ -164,7 +164,7 @@ int sgw_lite_handle_create_session_request(SgwCreateSessionRequest *session_req_
         * tunnel for S1 user plane interface. If status in response is successfull (0),
         * the tunnel endpoint is locally ready.
         */
-        message_p = alloc_new_message(TASK_SPGW_APP, GTPV1U_CREATE_TUNNEL_REQ);
+        message_p = itti_alloc_new_message(TASK_SPGW_APP, GTPV1U_CREATE_TUNNEL_REQ);
         if (message_p == NULL) {
         	sgw_lite_cm_remove_s11_tunnel(new_endpoint->remote_teid);
             return -1;
@@ -175,7 +175,7 @@ int sgw_lite_handle_create_session_request(SgwCreateSessionRequest *session_req_
         SPGW_APP_DEBUG("Tx GTPV1U_CREATE_TUNNEL_REQ -> TASK_GTPV1_U, Context: S-GW S11 teid %u eps bearer id %d (from session req)\n",
         		message_p->msg.gtpv1uCreateTunnelReq.context_teid,
         		message_p->msg.gtpv1uCreateTunnelReq.eps_bearer_id);
-        return send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
     } else {
         SPGW_APP_WARNING("Could not create new transaction for SESSION_CREATE message\n");
         free(new_endpoint);
@@ -202,7 +202,7 @@ int sgw_lite_handle_sgi_endpoint_created(SGICreateEndpointResp *resp_p)
     to_task = TASK_S11;
 #endif
 
-    message_p = alloc_new_message(TASK_SPGW_APP, SGW_CREATE_SESSION_RESPONSE);
+    message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_CREATE_SESSION_RESPONSE);
 
     if (message_p == NULL) {
         return -1;
@@ -249,7 +249,7 @@ int sgw_lite_handle_sgi_endpoint_created(SGICreateEndpointResp *resp_p)
                    create_session_response_p->bearer_context_created.s1u_sgw_fteid.teid,
                    create_session_response_p->bearer_context_created.eps_bearer_id,
                    create_session_response_p->bearer_context_created.cause);
-    return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+    return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
 }
 
 int sgw_lite_handle_gtpv1uCreateTunnelResp(Gtpv1uCreateTunnelResp *endpoint_created_p)
@@ -287,7 +287,7 @@ int sgw_lite_handle_gtpv1uCreateTunnelResp(Gtpv1uCreateTunnelResp *endpoint_crea
         sgw_lite_display_s11_bearer_context_information_mapping();
 
         /* SEND IP_FW_CREATE_IP_ENDPOINT_REQUEST to FW_IP task */
-        message_p = alloc_new_message(TASK_SPGW_APP, SGI_CREATE_ENDPOINT_REQUEST);
+        message_p = itti_alloc_new_message(TASK_SPGW_APP, SGI_CREATE_ENDPOINT_REQUEST);
         if (message_p == NULL) {
             return -1;
         }
@@ -299,10 +299,10 @@ int sgw_lite_handle_gtpv1uCreateTunnelResp(Gtpv1uCreateTunnelResp *endpoint_crea
 
         //create_sgi_endpoint_req_p->pdn_type = new_bearer_context_information_p->
         // TO DO TFT, QOS
-        return send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p);
     } else {
         SPGW_APP_DEBUG("Rx SGW_S1U_ENDPOINT_CREATED, Context: teid %u NOT FOUND\n", endpoint_created_p->context_teid);
-        message_p = alloc_new_message(TASK_SPGW_APP, SGW_CREATE_SESSION_RESPONSE);
+        message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_CREATE_SESSION_RESPONSE);
         if (message_p == NULL) {
             return -1;
         }
@@ -310,7 +310,7 @@ int sgw_lite_handle_gtpv1uCreateTunnelResp(Gtpv1uCreateTunnelResp *endpoint_crea
         memset(create_session_response_p, 0, sizeof(SgwCreateSessionResponse));
         create_session_response_p->cause                        = CONTEXT_NOT_FOUND;
         create_session_response_p->bearer_context_created.cause = CONTEXT_NOT_FOUND;
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     }
 }
 
@@ -348,7 +348,7 @@ int sgw_lite_handle_gtpv1uUpdateTunnelResp(Gtpv1uUpdateTunnelResp *endpoint_upda
                     new_bearer_context_information_p->sgw_eps_bearer_context_information.trxn,
                     endpoint_updated_p->eps_bearer_id);
 
-            message_p = alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
+            message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
             if (message_p == NULL) {
                 return -1;
             }
@@ -360,10 +360,10 @@ int sgw_lite_handle_gtpv1uUpdateTunnelResp(Gtpv1uUpdateTunnelResp *endpoint_upda
             modify_response_p->cause                                        = CONTEXT_NOT_FOUND;
             modify_response_p->trxn                                         = new_bearer_context_information_p->sgw_eps_bearer_context_information.trxn;
 
-            return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+            return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
         } else if (hash_rc == HASH_TABLE_OK) {
 
-            message_p = alloc_new_message(TASK_SPGW_APP, SGI_UPDATE_ENDPOINT_REQUEST);
+            message_p = itti_alloc_new_message(TASK_SPGW_APP, SGI_UPDATE_ENDPOINT_REQUEST);
             if (message_p == NULL) {
                 return -1;
             }
@@ -374,14 +374,14 @@ int sgw_lite_handle_gtpv1uUpdateTunnelResp(Gtpv1uUpdateTunnelResp *endpoint_upda
             update_request_p->enb_S1u_teid = endpoint_updated_p->enb_S1u_teid;
             update_request_p->eps_bearer_id = endpoint_updated_p->eps_bearer_id;
 
-            return send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p);
+            return itti_send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p);
         }
     } else {
         SPGW_APP_DEBUG("Sending SGW_MODIFY_BEARER_RESPONSE trxn %p bearer %u CONTEXT_NOT_FOUND (s11_bearer_context_information_hashtable)\n",
                 new_bearer_context_information_p->sgw_eps_bearer_context_information.trxn,
                 endpoint_updated_p->eps_bearer_id);
 
-        message_p = alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
+        message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
         if (message_p == NULL) {
             return -1;
         }
@@ -393,7 +393,7 @@ int sgw_lite_handle_gtpv1uUpdateTunnelResp(Gtpv1uUpdateTunnelResp *endpoint_upda
         modify_response_p->choice.bearer_for_removal.cause              = CONTEXT_NOT_FOUND;
         modify_response_p->cause                                        = CONTEXT_NOT_FOUND;
         modify_response_p->trxn                                         = new_bearer_context_information_p->sgw_eps_bearer_context_information.trxn;
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     }
     return -1;
 }
@@ -420,7 +420,7 @@ int sgw_lite_handle_sgi_endpoint_updated(SGIUpdateEndpointResp *resp_p)
                    resp_p->eps_bearer_id,
                    resp_p->status);
 
-    message_p = alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
+    message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
     if (message_p == NULL) {
         return -1;
     }
@@ -444,7 +444,7 @@ int sgw_lite_handle_sgi_endpoint_updated(SGIUpdateEndpointResp *resp_p)
             modify_response_p->cause                                        = CONTEXT_NOT_FOUND;
             modify_response_p->trxn                                         = 0;
 
-            return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+            return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
         } else if (hash_rc == HASH_TABLE_OK) {
             SPGW_APP_DEBUG("Rx SGI_UPDATE_ENDPOINT_RESPONSE: REQUEST_ACCEPTED\n");
 
@@ -456,7 +456,7 @@ int sgw_lite_handle_sgi_endpoint_updated(SGIUpdateEndpointResp *resp_p)
             modify_response_p->cause                                = REQUEST_ACCEPTED;
             modify_response_p->trxn                                 = new_bearer_context_information_p->sgw_eps_bearer_context_information.trxn;
         }
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     } else {
         SPGW_APP_DEBUG("Rx SGI_UPDATE_ENDPOINT_RESPONSE: CONTEXT_NOT_FOUND (S11 context)\n");
 
@@ -467,7 +467,7 @@ int sgw_lite_handle_sgi_endpoint_updated(SGIUpdateEndpointResp *resp_p)
         modify_response_p->cause                                        = CONTEXT_NOT_FOUND;
         modify_response_p->trxn                                         = 0;
 
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     }
 }
 
@@ -504,7 +504,7 @@ int sgw_lite_handle_modify_bearer_request(SgwModifyBearerRequest *modify_bearer_
         hash_rc = hashtbl_is_key_exists (new_bearer_context_information_p->sgw_eps_bearer_context_information.pdn_connection.sgw_eps_bearers, modify_bearer_p->bearer_context_to_modify.eps_bearer_id);
 
         if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
-            message_p = alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
+            message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
             if (message_p == NULL) {
                 return -1;
             }
@@ -515,7 +515,7 @@ int sgw_lite_handle_modify_bearer_request(SgwModifyBearerRequest *modify_bearer_
             modify_response_p->choice.bearer_for_removal.cause              = CONTEXT_NOT_FOUND;
             modify_response_p->cause                                        = CONTEXT_NOT_FOUND;
             modify_response_p->trxn                                         = modify_bearer_p->trxn;
-            return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+            return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
         } else if (hash_rc == HASH_TABLE_OK) {
             // TO DO
             hash_rc = hashtbl_get (new_bearer_context_information_p->sgw_eps_bearer_context_information.pdn_connection.sgw_eps_bearers, modify_bearer_p->bearer_context_to_modify.eps_bearer_id, (void**)&eps_bearer_entry_p);
@@ -523,7 +523,7 @@ int sgw_lite_handle_modify_bearer_request(SgwModifyBearerRequest *modify_bearer_
             eps_bearer_entry_p->enb_teid_for_S1u = modify_bearer_p->bearer_context_to_modify.s1_eNB_fteid.teid;
 
             // UPDATE GTPV1U mapping tables with eNB references (teid, addresses)
-            message_p = alloc_new_message(TASK_SPGW_APP, GTPV1U_UPDATE_TUNNEL_REQ);
+            message_p = itti_alloc_new_message(TASK_SPGW_APP, GTPV1U_UPDATE_TUNNEL_REQ);
             if (message_p == NULL) {
                 return -1;
             }
@@ -540,10 +540,10 @@ int sgw_lite_handle_modify_bearer_request(SgwModifyBearerRequest *modify_bearer_
             //SPGW_APP_DEBUG("Rx MODIFY_BEARER_REQUEST, gtpv1u_update_tunnel_req_p->enb_ip_address_for_S1u = %u\n",modify_bearer_p->enb_ip_address_for_S1u);
             SPGW_APP_DEBUG("Rx MODIFY_BEARER_REQUEST, gtpv1u_update_tunnel_req_p->eps_bearer_id          = %u\n",gtpv1u_update_tunnel_req_p->eps_bearer_id);
 
-            return send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
+            return itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
         }
     } else {
-        message_p = alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
+        message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_MODIFY_BEARER_RESPONSE);
         if (message_p == NULL) {
             return -1;
         }
@@ -554,7 +554,7 @@ int sgw_lite_handle_modify_bearer_request(SgwModifyBearerRequest *modify_bearer_
         modify_response_p->choice.bearer_for_removal.cause              = CONTEXT_NOT_FOUND;
         modify_response_p->cause                                        = CONTEXT_NOT_FOUND;
         modify_response_p->trxn                                         = modify_bearer_p->trxn;
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     }
     return -1;
 }
@@ -574,7 +574,7 @@ int sgw_lite_handle_delete_session_request(SgwDeleteSessionRequest *delete_sessi
     to_task = TASK_S11;
 #endif
 
-    message_p = alloc_new_message(TASK_SPGW_APP, SGW_DELETE_SESSION_RESPONSE);
+    message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_DELETE_SESSION_RESPONSE);
     if (message_p == NULL) {
         return -1;
     }
@@ -609,12 +609,12 @@ int sgw_lite_handle_delete_session_request(SgwDeleteSessionRequest *delete_sessi
         delete_session_resp_p->trxn    = delete_session_req_p->trxn;
         delete_session_resp_p->peer_ip = delete_session_req_p->peer_ip;
 
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     } else {
         /* Context not found... set the cause to CONTEXT_NOT_FOUND
          * 3GPP TS 29.274 #7.2.10.1
          */
-        message_p = alloc_new_message(TASK_SPGW_APP, SGW_DELETE_SESSION_RESPONSE);
+        message_p = itti_alloc_new_message(TASK_SPGW_APP, SGW_DELETE_SESSION_RESPONSE);
         if (message_p == NULL) {
             return -1;
         }
@@ -630,7 +630,7 @@ int sgw_lite_handle_delete_session_request(SgwDeleteSessionRequest *delete_sessi
         delete_session_resp_p->trxn    = delete_session_req_p->trxn;
         delete_session_resp_p->peer_ip = delete_session_req_p->peer_ip;
 
-        return send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
+        return itti_send_msg_to_task(to_task, INSTANCE_DEFAULT, message_p);
     }
 
     return -1;
diff --git a/openair-cn/SGW-LITE/sgw_lite_task.c b/openair-cn/SGW-LITE/sgw_lite_task.c
index 3da1b8c3c2..26eb54d9fe 100644
--- a/openair-cn/SGW-LITE/sgw_lite_task.c
+++ b/openair-cn/SGW-LITE/sgw_lite_task.c
@@ -45,10 +45,10 @@ sgw_app_t    sgw_app;
 
 static void *sgw_lite_intertask_interface(void *args_p)
 {
-    intertask_interface_mark_task_ready(TASK_SPGW_APP);
+    itti_mark_task_ready(TASK_SPGW_APP);
     while(1) {
         MessageDef *received_message_p;
-        receive_msg(TASK_SPGW_APP, &received_message_p);
+        itti_receive_msg(TASK_SPGW_APP, &received_message_p);
         switch(received_message_p->header.messageId) {
             case SGW_CREATE_SESSION_REQUEST: {
                 /* We received a create session request from MME (with GTP abstraction here)
@@ -89,7 +89,7 @@ static void *sgw_lite_intertask_interface(void *args_p)
 
             default: {
                 SPGW_APP_DEBUG("Unkwnon message ID %s:%d\n",
-                               get_message_name(received_message_p->header.messageId),
+                               itti_get_message_name(received_message_p->header.messageId),
                                received_message_p->header.messageId);
             } break;
         }
@@ -102,7 +102,7 @@ static void *sgw_lite_intertask_interface(void *args_p)
 int sgw_lite_init(const mme_config_t *mme_config_p)
 {
     SPGW_APP_DEBUG("Initializing SPGW-APP  task interface\n");
-    if (intertask_interface_create_task(TASK_SPGW_APP,
+    if (itti_create_task(TASK_SPGW_APP,
                                         &sgw_lite_intertask_interface, NULL) < 0) {
         perror("pthread_create");
     	SPGW_APP_DEBUG("Initializing SPGW-APP task interface: ERROR\n");
diff --git a/openair-cn/TEST/oaisim_mme_itti_test.c b/openair-cn/TEST/oaisim_mme_itti_test.c
index af3c32ae76..1896dbf204 100644
--- a/openair-cn/TEST/oaisim_mme_itti_test.c
+++ b/openair-cn/TEST/oaisim_mme_itti_test.c
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
 
     /* Calling each layer init function */
     log_init(&mme_config);
-    intertask_interface_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml);
+    itti_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml);
     sctp_init(&mme_config);
     udp_init(&mme_config);
     s1ap_mme_init(&mme_config);
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
 
     sgw_lite_init(&mme_config);
 
-    message_p = alloc_new_message(TASK_S1AP, MESSAGE_TEST);
+    message_p = itti_alloc_new_message(TASK_S1AP, MESSAGE_TEST);
 
     while(i < (1 << 15)) {
         if (send_broadcast_message(message_p) < 0) {
diff --git a/openair-cn/UDP/udp_primitives_server.c b/openair-cn/UDP/udp_primitives_server.c
index 57d80c58fe..2799ba213e 100644
--- a/openair-cn/UDP/udp_primitives_server.c
+++ b/openair-cn/UDP/udp_primitives_server.c
@@ -164,7 +164,7 @@ void *udp_receiver_thread(void *arg_p)
 
             memcpy(forwarded_buffer, buffer, n);
 
-            message_p = alloc_new_message(TASK_UDP, UDP_DATA_IND);
+            message_p = itti_alloc_new_message(TASK_UDP, UDP_DATA_IND);
 
             DevAssert(message_p != NULL);
 
@@ -177,7 +177,7 @@ void *udp_receiver_thread(void *arg_p)
 
             UDP_DEBUG("Msg of length %d received from %s:%u\n",
                       n, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
-            if (send_msg_to_task(udp_sock_p->task_id, INSTANCE_DEFAULT, message_p) < 0) {
+            if (itti_send_msg_to_task(udp_sock_p->task_id, INSTANCE_DEFAULT, message_p) < 0) {
                 UDP_DEBUG("Failed to send message %d to task %d\n",
                           UDP_DATA_IND, udp_sock_p->task_id);
                 break;
@@ -196,10 +196,10 @@ void *udp_receiver_thread(void *arg_p)
 
 static void *udp_intertask_interface(void *args_p)
 {
-    intertask_interface_mark_task_ready(TASK_UDP);
+    itti_mark_task_ready(TASK_UDP);
     while(1) {
         MessageDef *received_message_p = NULL;
-        receive_msg(TASK_UDP, &received_message_p);
+        itti_receive_msg(TASK_UDP, &received_message_p);
         DevAssert(received_message_p != NULL);
 
         switch (received_message_p->header.messageId) {
@@ -259,7 +259,7 @@ static void *udp_intertask_interface(void *args_p)
             } break;
             default: {
                 UDP_DEBUG("Unkwnon message ID %s:%d\n",
-                          get_message_name(received_message_p->header.messageId),
+                          itti_get_message_name(received_message_p->header.messageId),
                           received_message_p->header.messageId);
             } break;
         }
@@ -276,7 +276,7 @@ int udp_init(const mme_config_t *mme_config_p)
 
     STAILQ_INIT(&udp_socket_list);
 
-    if (intertask_interface_create_task(TASK_UDP, &udp_intertask_interface,
+    if (itti_create_task(TASK_UDP, &udp_intertask_interface,
                                         NULL) < 0) {
         UDP_ERROR("udp pthread_create (%s)\n", strerror(errno));
         return -1;
diff --git a/openair-cn/UTILS/Makefile.am b/openair-cn/UTILS/Makefile.am
index b7d173f8de..a7fd6f96a9 100644
--- a/openair-cn/UTILS/Makefile.am
+++ b/openair-cn/UTILS/Makefile.am
@@ -9,13 +9,10 @@ AM_YFLAGS = -d
 noinst_LTLIBRARIES = libutils.la
 libutils_la_LDFLAGS = -all-static
 libutils_la_SOURCES = \
-	assertions.h	\
-	backtrace.c	backtrace.h	\
 	conversions.h	conversions.c	\
 	enum_string.h	enum_string.c	\
 	log.c log.h	\
 	mme_parser.y mme_scanner.l	\
 	mme_config.c mme_config.h	\
 	mme_default_values.h	\
-	queue.h	tree.h	\
-	signals.c	signals.h
+	queue.h	tree.h
diff --git a/openair2/COMMON/intertask_interface_conf.h b/openair2/COMMON/intertask_interface_conf.h
index 0b906a1c44..bdf0d51f7e 100644
--- a/openair2/COMMON/intertask_interface_conf.h
+++ b/openair2/COMMON/intertask_interface_conf.h
@@ -43,7 +43,7 @@
  ******************************************************************************/
 
 #define ITTI_QUEUE_SIZE_PER_TASK (5 * 1024 * 1024) /* Limit the queue size to 5M */
-#define ITTI_PORT                (10007)
+#define ITTI_PORT                (10006)
 /* This is the queue size for signal dumper */
 #define ITTI_QUEUE_SIZE_MAX      (1 * 1024 * 1024) /* 1 MBytes */
 #define ITTI_DUMP_MAX_CON        (5)    /* Max connections in parallel */
diff --git a/openair3/OPENAIRMME/S1AP/s1ap_mme.c b/openair3/OPENAIRMME/S1AP/s1ap_mme.c
index c039510789..e9f931abe8 100644
--- a/openair3/OPENAIRMME/S1AP/s1ap_mme.c
+++ b/openair3/OPENAIRMME/S1AP/s1ap_mme.c
@@ -73,7 +73,7 @@ static int s1ap_send_init_sctp(void) {
     message_p->msg.sctpS1APInit.ppid = S1AP_SCTP_PPID;
     message_p->msg.sctpS1APInit.address = "0.0.0.0"; //ANY address
 
-    return send_msg_to_task(TASK_SCTP, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, message_p);
 }
 
 void* s1ap_mme_thread(void *args) {
@@ -82,7 +82,7 @@ void* s1ap_mme_thread(void *args) {
          * If the queue is empty, this function will block till a
          * message is sent to the task.
          */
-        receive_msg(TASK_S1AP, &receivedMessage);
+        itti_receive_msg(TASK_S1AP, &receivedMessage);
         assert(receivedMessage != NULL);
         switch(receivedMessage->messageId) {
             case S1AP_SCTP_NEW_MESSAGE_IND:
diff --git a/openair3/OPENAIRMME/S1AP/s1ap_mme_encoder.c b/openair3/OPENAIRMME/S1AP/s1ap_mme_encoder.c
index 99097cb98b..cc603b93d3 100644
--- a/openair3/OPENAIRMME/S1AP/s1ap_mme_encoder.c
+++ b/openair3/OPENAIRMME/S1AP/s1ap_mme_encoder.c
@@ -72,7 +72,7 @@ int s1ap_mme_encode_s1setupresponse(S1SetupResponseIEs_t *s1SetupResponseIEs, ui
         return -1;
     }
 
-    return send_msg_to_task(TASK_SCTP, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, message_p);
 }
 
 int s1ap_mme_encode_s1setupfailure(S1SetupFailureIEs_t *s1SetupFailureIEs, uint32_t assocId) {
@@ -105,7 +105,7 @@ int s1ap_mme_encode_s1setupfailure(S1SetupFailureIEs_t *s1SetupFailureIEs, uint3
         return -1;
     }
 
-    return send_msg_to_task(TASK_SCTP, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, message_p);
 }
 
 int s1ap_mme_encode_initial_context_setup_request(InitialContextSetupRequestIEs_t *initialContextSetupRequestIEs,
@@ -139,7 +139,7 @@ int s1ap_mme_encode_initial_context_setup_request(InitialContextSetupRequestIEs_
         return -1;
     }
 
-    return send_msg_to_task(TASK_SCTP, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, message_p);
 }
 
 int s1ap_mme_encode_downlink_nas_transport(DownlinkNASTransportIEs_t *downlinkNasTransportIEs,
@@ -174,7 +174,7 @@ int s1ap_mme_encode_downlink_nas_transport(DownlinkNASTransportIEs_t *downlinkNa
         return -1;
     }
 
-    return send_msg_to_task(TASK_SCTP, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, message_p);
 }
 
 int s1ap_mme_encode_ue_context_release_command(UEContextReleaseCommandIEs_t *ueContextReleaseCommandIEs,
@@ -206,7 +206,7 @@ int s1ap_mme_encode_ue_context_release_command(UEContextReleaseCommandIEs_t *ueC
         ueContextReleaseCommand_p) < 0)
         goto error;
 
-    return send_msg_to_task(TASK_SCTP, message_p);
+    return itti_send_msg_to_task(TASK_SCTP, message_p);
 error:
     free(message_p);
     return -1;
diff --git a/openair3/OPENAIRMME/S1AP/s1ap_mme_handlers.c b/openair3/OPENAIRMME/S1AP/s1ap_mme_handlers.c
index 9c1eeab280..2a28cf9120 100644
--- a/openair3/OPENAIRMME/S1AP/s1ap_mme_handlers.c
+++ b/openair3/OPENAIRMME/S1AP/s1ap_mme_handlers.c
@@ -350,7 +350,7 @@ int s1ap_mme_handle_initial_ue_message(uint32_t assocId, uint32_t stream, struct
             MessageDef              *message_p;
             SgwCreateSessionRequest *session_request_p;
 
-            message_p = alloc_new_message(TASK_S1AP, TASK_SGW_LITE, SGW_CREATE_SESSION_REQUEST);
+            message_p = itti_alloc_new_message(TASK_S1AP, TASK_SGW_LITE, SGW_CREATE_SESSION_REQUEST);
             if (message_p == NULL) return -1;
 
             /* WARNING:
@@ -400,7 +400,7 @@ int s1ap_mme_handle_initial_ue_message(uint32_t assocId, uint32_t stream, struct
             session_request_p->paa.ipv4_address = 0x00000000;
 
             session_request_p->selection_mode = MS_O_N_P_APN_S_V;
-            return send_msg_to_task(TASK_SGW_LITE, message_p);
+            return itti_send_msg_to_task(TASK_SGW_LITE, message_p);
         }
     }
     return 0;
@@ -485,7 +485,7 @@ int s1ap_mme_handle_initial_context_setup_response(
 
     ue_ref->s1_ue_state = S1AP_UE_CONNECTED;
 
-    message_p = alloc_new_message(TASK_SGW_LITE, TASK_S1AP, SGW_MODIFY_BEARER_REQUEST);
+    message_p = itti_alloc_new_message(TASK_SGW_LITE, TASK_S1AP, SGW_MODIFY_BEARER_REQUEST);
 
     if (message_p == NULL) {
         return -1;
@@ -500,7 +500,7 @@ int s1ap_mme_handle_initial_context_setup_response(
     modify_request_p->bearer_context_to_modify.s1_eNB_fteid.ipv4 = 1;
     memcpy(&modify_request_p->bearer_context_to_modify.s1_eNB_fteid.ipv4_address, eRABSetupItemCtxtSURes_p->transportLayerAddress.buf, 4);
 
-    return send_msg_to_task(TASK_SGW_LITE, message_p);
+    return itti_send_msg_to_task(TASK_SGW_LITE, message_p);
 }
 
 int s1ap_mme_handle_ue_context_release_request(uint32_t assocId, uint32_t stream, struct s1ap_message_s *message) {
diff --git a/targets/SIMU/USER/Makefile b/targets/SIMU/USER/Makefile
index 7cb73c8e10..71f96e3e86 100644
--- a/targets/SIMU/USER/Makefile
+++ b/targets/SIMU/USER/Makefile
@@ -34,7 +34,7 @@ CFLAGS += -DOPENAIR_LTE -DPUCCH #-DOFDMA_ULSCH -DIFFT_FPGA -DIFFT_FPGA_UE
 CFLAGS += -DMAC_CONTEXT=1 -DPHY_CONTEXT=1 -DPHY_ABSTRACTION #-DPHY_ABSTRACTION_UL #-DRLC_UM_TEST_TRAFFIC=1
 CFLAGS += -DNEW_FFT
 #CFLAGS += -DLLR8
-
+CFLAGS += -DPACKAGE_NAME='"oaisim"'
 ifndef OPENAIR2
 OPENAIR2=1
 endif
diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c
index 33dc4ab2bf..f96bed6f78 100644
--- a/targets/SIMU/USER/oaisim.c
+++ b/targets/SIMU/USER/oaisim.c
@@ -33,7 +33,6 @@
 #ifdef IFFT_FPGA
 //#include "PHY/LTE_REFSIG/mod_table.h"
 #endif //IFFT_FPGA
-
 #include "SCHED/defs.h"
 #include "SCHED/vars.h"
 
@@ -47,7 +46,7 @@ char smbv_fname[] = "smbv_config_file.smbv";
 unsigned short smbv_nframes = 4; // how many frames to configure 1,..,4
 unsigned short config_frames[4] = {2,9,11,13};
 // unsigned short config_frames[4] = {1};
-unsigned char  smbv_frame_cnt = 0;
+unsigned char smbv_frame_cnt = 0;
 u8 config_smbv = 0;
 char smbv_ip[16];
 #endif
@@ -61,7 +60,6 @@ char smbv_ip[16];
 #include "UTIL/OMG/omg_constants.h"
 #include "UTIL/FIFO/pad_list.h"
 
-
 //#ifdef PROC
 #include "../PROC/interface.h"
 #include "../PROC/channel_sim_proc.h"
@@ -74,6 +72,7 @@ char smbv_ip[16];
 
 #if defined(ENABLE_ITTI)
 # include "intertask_interface_init.h"
+# include "timer.h"
 #endif
 
 #define RF
@@ -84,10 +83,10 @@ char smbv_ip[16];
 #define N_TRIALS 1
 
 /*
-  DCI0_5MHz_TDD0_t          UL_alloc_pdu;
-  DCI1A_5MHz_TDD_1_6_t      CCCH_alloc_pdu;
-  DCI2_5MHz_2A_L10PRB_TDD_t DLSCH_alloc_pdu1;
-  DCI2_5MHz_2A_M10PRB_TDD_t DLSCH_alloc_pdu2;
+ DCI0_5MHz_TDD0_t          UL_alloc_pdu;
+ DCI1A_5MHz_TDD_1_6_t      CCCH_alloc_pdu;
+ DCI2_5MHz_2A_L10PRB_TDD_t DLSCH_alloc_pdu1;
+ DCI2_5MHz_2A_M10PRB_TDD_t DLSCH_alloc_pdu2;
  */
 
 #define UL_RB_ALLOC computeRIV(lte_frame_parms->N_RB_UL,0,24)
@@ -103,18 +102,17 @@ char smbv_ip[16];
 #define SLEEP_STEP_US       100 //  = 0.01ms could be adaptive, should be as a number of UE
 #define K 2                  // averaging coefficient 
 #define TARGET_SF_TIME_NS 1000000       // 1ms = 1000000 ns
-
 //#ifdef OPENAIR2
 //u16 NODE_ID[1];
 //u8 NB_INST = 2;
 //#endif //OPENAIR2
-u32 frame=0;
+u32 frame = 0;
 //int eMBMS_active = 0;
 char stats_buffer[16384];
 channel_desc_t *eNB2UE[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX];
 channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX];
 //Added for PHY abstraction
-node_desc_t *enb_data[NUMBER_OF_eNB_MAX]; 
+node_desc_t *enb_data[NUMBER_OF_eNB_MAX];
 node_desc_t *ue_data[NUMBER_OF_UE_MAX];
 // Added for PHY abstraction
 extern Node_list ue_node_list;
@@ -122,14 +120,14 @@ extern Node_list enb_node_list;
 extern int pdcp_period, omg_period;
 
 extern double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
-int map1,map2;
+int map1, map2;
 extern double **ShaF;
-double snr_dB, sinr_dB,snr_direction;//,sinr_direction;
+double snr_dB, sinr_dB, snr_direction; //,sinr_direction;
 extern double snr_step;
-extern u8 set_sinr;//,set_snr=0;
+extern u8 set_sinr; //,set_snr=0;
 extern u8 ue_connection_test;
 extern u8 set_seed;
-u8 cooperation_flag;          // for cooperative communication
+u8 cooperation_flag; // for cooperative communication
 extern u8 target_dl_mcs;
 extern u8 target_ul_mcs;
 u8 rate_adaptation_flag;
@@ -152,44 +150,46 @@ int otg_enabled;
 #endif
 
 // this should reflect the channel models in openair1/SIMULATION/TOOLS/defs.h
-mapping small_scale_names[] = {
-  {"custom", custom},
-  {"SCM_A", SCM_A},
-  {"SCM_B", SCM_B},
-  {"SCM_C", SCM_C},
-  {"SCM_D", SCM_D},
-  {"EPA", EPA},
-  {"EVA", EVA},
-  {"ETU", ETU},
-  {"Rayleigh8", Rayleigh8},
-  {"Rayleigh1", Rayleigh1},
-  {"Rayleigh1_800", Rayleigh1_800},
-  {"Rayleigh1_corr", Rayleigh1_corr},
-  {"Rayleigh1_anticorr", Rayleigh1_anticorr},
-  {"Rice8", Rice8},
-  {"Rice1", Rice1},
-  {"Rice1_corr", Rice1_corr},
-  {"Rice1_anticorr", Rice1_anticorr},
-  {"AWGN", AWGN},
-  {NULL, -1}
-};
+mapping small_scale_names[] =
+  {
+    {"custom", custom},
+     {"SCM_A", SCM_A},
+     {"SCM_B", SCM_B},
+     {"SCM_C", SCM_C},
+     {"SCM_D", SCM_D},
+     {"EPA", EPA},
+     {"EVA", EVA},
+     {"ETU", ETU},
+     {"Rayleigh8", Rayleigh8},
+     {"Rayleigh1", Rayleigh1},
+     {"Rayleigh1_800", Rayleigh1_800},
+     {"Rayleigh1_corr", Rayleigh1_corr},
+     {"Rayleigh1_anticorr", Rayleigh1_anticorr},
+     {"Rice8", Rice8},
+     {"Rice1", Rice1},
+     {"Rice1_corr", Rice1_corr},
+     {"Rice1_anticorr", Rice1_anticorr},
+     {"AWGN", AWGN},
+     {NULL, -1}};
 
 //static void *sigh(void *arg);
 void terminate(void);
 
-void 
-help (void) {
-  printf ("Usage: oaisim -h -a -F -C tdd_config -V -R N_RB_DL -e -x transmission_mode -m target_dl_mcs -r(ate_adaptation) -n n_frames -s snr_dB -k ricean_factor -t max_delay -f forgetting factor -A channel_model -z cooperation_flag -u nb_local_ue -U UE mobility -b nb_local_enb -B eNB_mobility -M ethernet_flag -p nb_master -g multicast_group -l log_level -c ocg_enable -T traffic model -D multicast network device\n");
+void help(void) {
+  printf (
+      "Usage: oaisim -h -a -F -C tdd_config -V -R N_RB_DL -e -x transmission_mode -m target_dl_mcs -r(ate_adaptation) -n n_frames -s snr_dB -k ricean_factor -t max_delay -f forgetting factor -A channel_model -z cooperation_flag -u nb_local_ue -U UE mobility -b nb_local_enb -B eNB_mobility -M ethernet_flag -p nb_master -g multicast_group -l log_level -c ocg_enable -T traffic model -D multicast network device\n");
 
   printf ("-h provides this help message!\n");
   printf ("-a Activates PHY abstraction mode\n");
-  printf ("-A set the multipath channel simulation,  options are: SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr,Rayleigh1_anticorr, Rice8,, Rice1, AWGN \n");
+  printf (
+      "-A set the multipath channel simulation,  options are: SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr,Rayleigh1_anticorr, Rice8,, Rice1, AWGN \n");
   printf ("-b Set the number of local eNB\n");
   printf ("-B Set the mobility model for eNB, options are: STATIC, RWP, RWALK, \n");
-  printf ("-c [1,2,3,4] Activate the config generator (OCG) to process the scenario descriptor, or give the scenario manually: -c template_1.xml \n");
+  printf (
+      "-c [1,2,3,4] Activate the config generator (OCG) to process the scenario descriptor, or give the scenario manually: -c template_1.xml \n");
   printf ("-C [0-6] Sets TDD configuration\n");
   printf ("-e Activates extended prefix mode\n");
-  printf ("-E Random number generator seed\n"); 
+  printf ("-E Random number generator seed\n");
   printf ("-f Set the forgetting factor for time-variation\n");
   printf ("-F Activates FDD transmission (TDD is default)\n");
   printf ("-g Set multicast group ID (0,1,2,3) - valid if M is set\n");
@@ -207,7 +207,8 @@ help (void) {
   printf ("    - wireshark: Enable tracing of layers above PHY using an UDP socket\n");
   printf ("    - pcap:      Enable tracing of layers above PHY to a pcap file\n");
   printf ("    - tshark:    Not implemented yet\n");
-  printf ("-Q Activate and set the MBMS service: 0 : not used (default eMBMS disabled), 1: eMBMS and RRC Connection enabled, 2: eMBMS relaying and RRC Connection enabled, 3: eMBMS enabled, RRC Connection disabled, 4: eMBMS relaying enabled, RRC Connection disabled\n");
+  printf (
+      "-Q Activate and set the MBMS service: 0 : not used (default eMBMS disabled), 1: eMBMS and RRC Connection enabled, 2: eMBMS relaying and RRC Connection enabled, 3: eMBMS enabled, RRC Connection disabled, 4: eMBMS relaying enabled, RRC Connection disabled\n");
   printf ("-R [6,15,25,50,75,100] Sets N_RB_DL\n");
   printf ("-r Activates rate adaptation (DL for now)\n");
   printf ("-s snr_dB set a fixed (average) SNR, this deactivates the openair channel model generator (OCM)\n");
@@ -218,7 +219,8 @@ help (void) {
   printf ("-U Set the mobility model for UE, options are: STATIC, RWP, RWALK \n");
   printf ("-V Enable VCD dump, file = openair_vcd_dump.vcd\n");
   printf ("-w number of CBA groups, if not specified or zero, CBA is inactive\n");
-  printf ("-W IP address to connect to SMBV and configure SMBV from config file. Requires compilation with SMBV=1, -W0 uses default IP 192.168.12.201\n");
+  printf (
+      "-W IP address to connect to SMBV and configure SMBV from config file. Requires compilation with SMBV=1, -W0 uses default IP 192.168.12.201\n");
   printf ("-x Set the transmission mode (1,2,5,6 supported for now)\n");
   printf ("-Y Set the global log verbosity (none, low, medium, high, full) \n");
   printf ("-z Set the cooperation flag (0 for no cooperation, 1 for delay diversity and 2 for distributed alamouti\n");
@@ -234,12 +236,12 @@ void log_thread_init() {
 
   log_shutdown = 0;
 
-  if((pthread_mutex_init(&log_lock, NULL) != 0) || (pthread_cond_init(&log_notify, NULL) != 0)) {
+  if ((pthread_mutex_init (&log_lock, NULL) != 0) || (pthread_cond_init (&log_notify, NULL) != 0)) {
     return;
   }
 
-  if (pthread_create(&log_thread, NULL, log_thread_function, (void*) NULL) != 0) {
-    log_thread_finalize();
+  if (pthread_create (&log_thread, NULL, log_thread_function, (void*) NULL) != 0) {
+    log_thread_finalize ();
     return;
   }
 #endif
@@ -252,60 +254,60 @@ int log_thread_finalize() {
 
 #ifndef LOG_NO_THREAD
 
-  if(pthread_mutex_lock(&log_lock) != 0) {
+  if (pthread_mutex_lock (&log_lock) != 0) {
     return -1;
   }
 
   log_shutdown = 1;
 
   /* Wake up LOG thread */
-  if((pthread_cond_broadcast(&log_notify) != 0) || (pthread_mutex_unlock(&log_lock) != 0)) {
+  if ((pthread_cond_broadcast (&log_notify) != 0) || (pthread_mutex_unlock (&log_lock) != 0)) {
     err = -1;
   }
-  if(pthread_join(log_thread, NULL) != 0) {
+  if (pthread_join (log_thread, NULL) != 0) {
     err = -1;
   }
-  if(pthread_mutex_unlock(&log_lock) != 0) {
+  if (pthread_mutex_unlock (&log_lock) != 0) {
     err = -1;
   }
 
-  if(!err) {
+  if (!err) {
     //log_list_free(&log_list);
-    pthread_mutex_lock(&log_lock);
-    pthread_mutex_destroy(&log_lock);
-    pthread_cond_destroy(&log_notify);
+    pthread_mutex_lock (&log_lock);
+    pthread_mutex_destroy (&log_lock);
+    pthread_cond_destroy (&log_notify);
   }
 #endif
 
   return err;
 }
 
-
 #ifdef OPENAIR2
-int omv_write (int pfd,  Node_list enb_node_list, Node_list ue_node_list, Data_Flow_Unit omv_data){
-  int i,j;
-  omv_data.end=0;
+int omv_write(int pfd, Node_list enb_node_list, Node_list ue_node_list, Data_Flow_Unit omv_data) {
+  int i, j;
+  omv_data.end = 0;
   //omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST;
-  for (i=0;i<NB_eNB_INST;i++) {
+  for (i = 0; i < NB_eNB_INST; i++) {
     if (enb_node_list != NULL) {
-      omv_data.geo[i].x = (enb_node_list->node->X_pos < 0.0)? 0.0 : enb_node_list->node->X_pos;
-      omv_data.geo[i].y = (enb_node_list->node->Y_pos < 0.0)? 0.0 : enb_node_list->node->Y_pos;
+      omv_data.geo[i].x = (enb_node_list->node->X_pos < 0.0) ? 0.0 : enb_node_list->node->X_pos;
+      omv_data.geo[i].y = (enb_node_list->node->Y_pos < 0.0) ? 0.0 : enb_node_list->node->Y_pos;
       omv_data.geo[i].z = 1.0;
       omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_enb;
       omv_data.geo[i].node_type = 0; //eNB
       enb_node_list = enb_node_list->next;
-      omv_data.geo[i].Neighbors=0;
-      for (j=NB_eNB_INST; j< NB_UE_INST + NB_eNB_INST ; j++){
-        if (is_UE_active(i,j - NB_eNB_INST ) == 1) {
-          omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors]=  j; 
-          omv_data.geo[i].Neighbors++; 
-          LOG_D(OMG,"[eNB %d][UE %d] is_UE_active(i,j) %d geo (x%d, y%d) num neighbors %d\n", i,j-NB_eNB_INST, is_UE_active(i,j-NB_eNB_INST), 
-                omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
-        } 
-      } 
+      omv_data.geo[i].Neighbors = 0;
+      for (j = NB_eNB_INST; j < NB_UE_INST + NB_eNB_INST; j++) {
+        if (is_UE_active (i, j - NB_eNB_INST) == 1) {
+          omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
+          omv_data.geo[i].Neighbors++;
+          LOG_D(
+              OMG,
+              "[eNB %d][UE %d] is_UE_active(i,j) %d geo (x%d, y%d) num neighbors %d\n", i, j-NB_eNB_INST, is_UE_active(i,j-NB_eNB_INST), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
+        }
+      }
     }
   }
-  for (i=NB_eNB_INST;i<NB_UE_INST+NB_eNB_INST;i++) {
+  for (i = NB_eNB_INST; i < NB_UE_INST + NB_eNB_INST; i++) {
     if (ue_node_list != NULL) {
       omv_data.geo[i].x = (ue_node_list->node->X_pos < 0.0) ? 0.0 : ue_node_list->node->X_pos;
       omv_data.geo[i].y = (ue_node_list->node->Y_pos < 0.0) ? 0.0 : ue_node_list->node->Y_pos;
@@ -322,352 +324,191 @@ int omv_write (int pfd,  Node_list enb_node_list, Node_list ue_node_list, Data_F
       omv_data.geo[i].RSSI[0] = 33;
       omv_data.geo[i].RSSI[1] = 22;
       omv_data.geo[i].RSSI[2] = 11;
-      
+
       ue_node_list = ue_node_list->next;
-      omv_data.geo[i].Neighbors=0;
-      for (j=0; j< NB_eNB_INST ; j++){
-        if (is_UE_active(j,i-NB_eNB_INST) == 1) {
-          omv_data.geo[i].Neighbor[ omv_data.geo[i].Neighbors]=j;       
-          omv_data.geo[i].Neighbors++; 
-          LOG_D(OMG,"[UE %d][eNB %d] is_UE_active  %d geo (x%d, y%d) num neighbors %d\n", i-NB_eNB_INST,j, is_UE_active(j,i-NB_eNB_INST), 
-                omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
-        } 
+      omv_data.geo[i].Neighbors = 0;
+      for (j = 0; j < NB_eNB_INST; j++) {
+        if (is_UE_active (j, i - NB_eNB_INST) == 1) {
+          omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
+          omv_data.geo[i].Neighbors++;
+          LOG_D(
+              OMG,
+              "[UE %d][eNB %d] is_UE_active  %d geo (x%d, y%d) num neighbors %d\n", i-NB_eNB_INST, j, is_UE_active(j,i-NB_eNB_INST), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
+        }
       }
     }
   }
-  LOG_E(OMG,"pfd %d \n", pfd);
-  if( write( pfd, &omv_data, sizeof(struct Data_Flow_Unit) ) == -1 )
-    perror( "write omv failed" );
+  LOG_E(OMG, "pfd %d \n", pfd);
+  if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
+    perror ("write omv failed");
   return 1;
 }
 
-void omv_end (int pfd, Data_Flow_Unit omv_data) {
-  omv_data.end=1;
-  if( write( pfd, &omv_data, sizeof(struct Data_Flow_Unit) ) == -1 )
-    perror( "write omv failed" );
+void omv_end(int pfd, Data_Flow_Unit omv_data) {
+  omv_data.end = 1;
+  if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
+    perror ("write omv failed");
 }
 #endif 
 
-Packet_OTG_List *otg_pdcp_buffer;
 #ifdef OPENAIR2
-  int pfd[2]; // fd for omv : fixme: this could be a local var
-#endif   
-
-int main (int argc, char **argv) {
+int pfd[2]; // fd for omv : fixme: this could be a local var
+#endif
 
-  s32 i;
-  // pointers signal buffers (s = transmit, r,r0 = receive)
-  clock_t t;
+#ifdef OPENAIR2
+static Data_Flow_Unit omv_data;
+#endif //ALU
+static s32 UE_id = 0, eNB_id = 0;
+#ifdef Rel10
+static s32 RN_id=0;
+#endif
 
+void *l2l1_task(void *args_p) {
   // Framing variables
   s32 slot, last_slot, next_slot;
 
-  //FILE *SINRpost;
-  //char SINRpost_fname[512];
-  // sprintf(SINRpost_fname,"postprocSINR.m");
-  //SINRpost = fopen(SINRpost_fname,"w");
-  // variables/flags which are set by user on command-line
-
-#ifdef SMBV
-  strcpy(smbv_ip,DEFAULT_SMBV_IP);
-#endif
-
-  s32 UE_id=0, eNB_id=0;
 #ifdef Rel10
-  s32 RN_id=0;
+  relaying_type_t r_type=no_relay; // no relaying
 #endif
-  
-#ifdef Rel10
-  relaying_type_t r_type=no_relay; // no relaying 
-#endif
-  // time calibration for soft realtime mode  
 
   lte_subframe_t direction;
 
-
-
-  char fname[64],vname[64];
-  // u8 awgn_flag = 0;
-#ifdef XFORMS
-  // current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
-  // at eNB 0, an UL scope for every UE 
-  FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
-  FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
-  char title[255];
-#endif
-
-#ifdef PRINT_STATS
-  int len;
-  FILE *UE_stats[NUMBER_OF_UE_MAX], *UE_stats_th[NUMBER_OF_UE_MAX], *eNB_stats[NUMBER_OF_eNB_MAX], *eNB_avg_thr, *eNB_l2_stats;
-  char UE_stats_filename[255];
-  char eNB_stats_filename[255];
-  char UE_stats_th_filename[255];
-  char eNB_stats_th_filename[255];
- #endif
-
-
-  //time_t t0,t1;
-  //clock_t start, stop;
-  
-
-#ifdef OPENAIR2
-  Data_Flow_Unit omv_data ;
-#endif //ALU
-
-#ifdef PROC
-  int node_id;
-  int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
-#endif
-  //double **s_re2[MAX_eNB+MAX_UE], **s_im2[MAX_eNB+MAX_UE], **r_re2[MAX_eNB+MAX_UE], **r_im2[MAX_eNB+MAX_UE], **r_re02, **r_im02;
-  //double **r_re0_d[MAX_UE][MAX_eNB], **r_im0_d[MAX_UE][MAX_eNB], **r_re0_u[MAX_eNB][MAX_UE],**r_im0_u[MAX_eNB][MAX_UE];
-  //default parameters
-  rate_adaptation_flag = 0;
-  oai_emulation.info.n_frames = 0xffff;//1024;          //10;
-  oai_emulation.info.n_frames_flag = 0;//fixme
-  snr_dB = 30;
-  cooperation_flag = 0;         // default value 0 for no cooperation, 1 for Delay diversity, 2 for Distributed Alamouti
-
-  //Default values if not changed by the user in get_simulation_options();
-  pdcp_period = 1;
-  omg_period = 1; 
-    // start thread for log gen
-  log_thread_init();
-
-  init_oai_emulation(); // to initialize everything !!!
-  
-  // get command-line options
-  get_simulation_options(argc, argv); //Command-line options
-
-  // Initialize VCD LOG module
-  vcd_signal_dumper_init("openair_dump.vcd");
-
-  /*  pthread_t sigth;
-  sigset_t sigblock;
-  sigemptyset(&sigblock);
-  sigaddset(&sigblock, SIGHUP);
-  sigaddset(&sigblock, SIGINT);
-  sigaddset(&sigblock, SIGTERM);
-  pthread_sigmask(SIG_BLOCK, &sigblock, NULL);
-  if (pthread_create(&sigth, NULL, sigh, NULL)) {
-    msg("Pthread for tracing Signals is not created!\n");
-    return -1;
-  } else {
-    msg("Pthread for tracing Signals is created!\n");
-    }*/
-  // configure oaisim with OCG
-  oaisim_config(); // config OMG and OCG, OPT, OTG, OLG
-
-  if (ue_connection_test == 1) {
-    snr_direction = -snr_step;
-    snr_dB=20;
-    sinr_dB=-20;
- }
+  char fname[64], vname[64];
 
 #if defined(ENABLE_ITTI)
-  intertask_interface_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml);
-#endif
+  long timer_id;
 
-#ifdef OPENAIR2
-  init_omv();
- #endif
-  //Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
-  
-  check_and_adjust_params(); 
-   
- 
-#ifdef PRINT_STATS
-  for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
-    sprintf(UE_stats_filename,"UE_stats%d.txt",UE_id);
-    UE_stats[UE_id] = fopen (UE_stats_filename, "w");
-  }
-  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
-    sprintf(eNB_stats_filename,"eNB_stats%d.txt",eNB_id);
-    eNB_stats[eNB_id] = fopen (eNB_stats_filename, "w");
-  }
-  
-  if(abstraction_flag==0){
-    for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
-      sprintf(UE_stats_th_filename,"UE_stats_th%d_tx%d.txt",UE_id,oai_emulation.info.transmission_mode);
-      UE_stats_th[UE_id] = fopen (UE_stats_th_filename, "w");
-    }
-    sprintf(eNB_stats_th_filename,"eNB_stats_th_tx%d.txt",oai_emulation.info.transmission_mode);
-    eNB_avg_thr = fopen (eNB_stats_th_filename, "w"); 
-  } else{
-    for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
-      sprintf(UE_stats_th_filename,"UE_stats_abs_th%d_tx%d.txt",UE_id,oai_emulation.info.transmission_mode);
-      UE_stats_th[UE_id] = fopen (UE_stats_th_filename, "w");
-    }
-    sprintf(eNB_stats_th_filename,"eNB_stats_abs_th_tx%d.txt",oai_emulation.info.transmission_mode);
-    eNB_avg_thr = fopen (eNB_stats_th_filename, "w"); 
-  } 
-#ifdef OPENAIR2
-    eNB_l2_stats = fopen ("eNB_l2_stats.txt", "w");
-    LOG_I(EMU,"eNB_l2_stats=%p\n", eNB_l2_stats);
-#endif 
-
-#endif
-  
-  set_seed = oai_emulation.emulation_config.seed.value;
-  
-  init_otg_pdcp_buffer();
-  
-  init_seed(set_seed);
-
-  init_openair1();
+  itti_mark_task_ready(TASK_L2L1);
 
-  init_openair2();
+  /* Test code */
+  {
+    MessageDef *message_p;
 
-  init_ocm();
+    message_p = itti_alloc_new_message(TASK_L2L1, MESSAGE_TEST);
 
-#ifdef XFORMS
-  eNB_id = 0;
-  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
-      // DL scope at UEs
-      fl_initialize (&argc, argv, NULL, 0, 0);
-      form_ue[UE_id] = create_lte_phy_scope_ue();
-      sprintf (title, "LTE DL SCOPE eNB %d to UE %d", eNB_id, UE_id);
-      fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
-
-      // UL scope at eNB 0
-      fl_initialize (&argc, argv, NULL, 0, 0);
-      form_enb[UE_id] = create_lte_phy_scope_enb();
-      sprintf (title, "LTE UL SCOPE UE %d to eNB %d", UE_id, eNB_id);
-      fl_show_form (form_enb[UE_id]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
-
-      if (openair_daq_vars.use_ia_receiver == 1) {
-          fl_set_button(form_ue[UE_id]->button_0,1);
-          fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON");
-          fl_set_object_color(form_ue[UE_id]->button_0, FL_GREEN, FL_GREEN);
-      }
+    itti_send_msg_to_task(TASK_L2L1, INSTANCE_DEFAULT, message_p);
 
+    /* Request for periodic timer */
+    if (timer_setup(1, 0, TASK_L2L1, INSTANCE_DEFAULT,
+            TIMER_PERIODIC, NULL, &timer_id) < 0)
+    {
+      LOG_E(EMU, "Failed to request new timer with %ds "
+          "of periocidity\n", 1);
+      timer_id = 0;
+    }
   }
 #endif
 
-#ifdef SMBV
-  smbv_init_config(smbv_fname, smbv_nframes);
-  smbv_write_config_from_frame_parms(smbv_fname, &PHY_vars_eNB_g[0]->lte_frame_parms);
-#endif
-
-  init_time();
-
-  init_slot_isr();
-  
-  t = clock();
-
-  LOG_N(EMU,"\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
-  
-
-  for (frame=0; frame<oai_emulation.info.n_frames; frame++) {
+  for (frame = 0; frame < oai_emulation.info.n_frames; frame++) {
     /*
-    // Handling the cooperation Flag
-    if (cooperation_flag == 2)
-      {
-        if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH))
-          PHY_vars_eNB_g[0]->cooperation_flag = 2;
-      }
-    */
-    if (ue_connection_test==1) {
-      if ((frame%20) == 0) {
+     // Handling the cooperation Flag
+     if (cooperation_flag == 2)
+     {
+     if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH))
+     PHY_vars_eNB_g[0]->cooperation_flag = 2;
+     }
+     */
+    if (ue_connection_test == 1) {
+      if ((frame % 20) == 0) {
         snr_dB += snr_direction;
         sinr_dB -= snr_direction;
       }
       if (snr_dB == -20) {
-        snr_direction=snr_step;
-      }
-      else if (snr_dB==20) {
-        snr_direction=-snr_step;
+        snr_direction = snr_step;
       }
+      else
+        if (snr_dB == 20) {
+          snr_direction = -snr_step;
+        }
     }
 
-    oai_emulation.info.frame = frame; 
-    //oai_emulation.info.time_ms += 1;  
+    oai_emulation.info.frame = frame;
+    //oai_emulation.info.time_ms += 1;
     oai_emulation.info.time_s += 0.1; // emu time in s, each frame lasts for 10 ms // JNote: TODO check the coherency of the time and frame (I corrected it to 10 (instead of 0.01)
     // if n_frames not set by the user or is greater than max num frame then set adjust the frame counter
-    if ( (oai_emulation.info.n_frames_flag == 0) || (oai_emulation.info.n_frames >= 0xffff) ){ 
-      frame %=(oai_emulation.info.n_frames-1);
-    } 
-    
-    update_omg(); // frequency is defined in the omg_global params configurable by the user
+    if ((oai_emulation.info.n_frames_flag == 0) || (oai_emulation.info.n_frames >= 0xffff)) {
+      frame %= (oai_emulation.info.n_frames - 1);
+    }
+
+    update_omg (); // frequency is defined in the omg_global params configurable by the user
 
-    update_omg_ocm();
+    update_omg_ocm ();
 
 #ifdef OPENAIR2
     // check if pipe is still open
-    if ((oai_emulation.info.omv_enabled == 1) ){
-      omv_write(pfd[1], enb_node_list, ue_node_list, omv_data);
+    if ((oai_emulation.info.omv_enabled == 1)) {
+      omv_write (pfd[1], enb_node_list, ue_node_list, omv_data);
     }
-#endif    
+#endif
 #ifdef DEBUG_OMG
     if ((((int) oai_emulation.info.time_s) % 100) == 0) {
       for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) {
         get_node_position (UE, UE_id);
       }
     }
-#endif 
+#endif
+
+    update_ocm ();
+
+    for (slot = 0; slot < 20; slot++) {
 
-    update_ocm();
+      wait_for_slot_isr ();
 
-    for (slot=0 ; slot<20 ; slot++) {
+      last_slot = (slot - 1) % 20;
+      if (last_slot < 0)
+        last_slot += 20;
+      next_slot = (slot + 1) % 20;
 
-      wait_for_slot_isr();
+      oai_emulation.info.time_ms = frame * 10 + (slot >> 1);
 
-      last_slot = (slot - 1)%20;
-      if (last_slot <0)
-        last_slot+=20;
-      next_slot = (slot + 1)%20;
-      
-      oai_emulation.info.time_ms = frame * 10 + (slot>>1) ;
-      
-      direction = subframe_select(frame_parms,next_slot>>1);
+      direction = subframe_select (frame_parms, next_slot >> 1);
 
-#ifdef PROC      
+#ifdef PROC
       if(Channel_Flag==1)
-        Channel_Func(s_re2,s_im2,r_re2,r_im2,r_re02,r_im02,r_re0_d,r_im0_d,r_re0_u,r_im0_u,eNB2UE,UE2eNB,enb_data,ue_data,abstraction_flag,frame_parms,slot);
+      Channel_Func(s_re2,s_im2,r_re2,r_im2,r_re02,r_im02,r_re0_d,r_im0_d,r_re0_u,r_im0_u,eNB2UE,UE2eNB,enb_data,ue_data,abstraction_flag,frame_parms,slot);
 
       if(Channel_Flag==0)
 #endif
       {
-        if((next_slot %2) ==0)
-          clear_eNB_transport_info(oai_emulation.info.nb_enb_local);
+        if ((next_slot % 2) == 0)
+          clear_eNB_transport_info (oai_emulation.info.nb_enb_local);
 
-        for (eNB_id=oai_emulation.info.first_enb_local;
-             (eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local)) && (oai_emulation.info.cli_start_enb[eNB_id]==1);
-             eNB_id++) {
+        for (eNB_id = oai_emulation.info.first_enb_local;
+            (eNB_id < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local))
+                && (oai_emulation.info.cli_start_enb[eNB_id] == 1); eNB_id++) {
           //printf ("debug: Nid_cell %d\n", PHY_vars_eNB_g[eNB_id]->lte_frame_parms.Nid_cell);
           //printf ("debug: frame_type %d,tdd_config %d\n", PHY_vars_eNB_g[eNB_id]->lte_frame_parms.frame_type,PHY_vars_eNB_g[eNB_id]->lte_frame_parms.tdd_config);
-          LOG_D(EMU,"PHY procedures eNB %d for frame %d, slot %d (subframe TX %d, RX %d) TDD %d/%d Nid_cell %d\n",
-                eNB_id, frame, slot, next_slot >> 1,last_slot>>1,
-                PHY_vars_eNB_g[eNB_id]->lte_frame_parms.frame_type,
-                PHY_vars_eNB_g[eNB_id]->lte_frame_parms.tdd_config,PHY_vars_eNB_g[eNB_id]->lte_frame_parms.Nid_cell);
+          LOG_D(
+              EMU,
+              "PHY procedures eNB %d for frame %d, slot %d (subframe TX %d, RX %d) TDD %d/%d Nid_cell %d\n", eNB_id, frame, slot, next_slot >> 1, last_slot>>1, PHY_vars_eNB_g[eNB_id]->lte_frame_parms.frame_type, PHY_vars_eNB_g[eNB_id]->lte_frame_parms.tdd_config, PHY_vars_eNB_g[eNB_id]->lte_frame_parms.Nid_cell);
 
           //Appliation: traffic gen
-          update_otg_eNB(eNB_id, oai_emulation.info.time_ms);
+          update_otg_eNB (eNB_id, oai_emulation.info.time_ms);
 
           //IP/OTG to PDCP and PDCP to IP operation
-          pdcp_run(frame, 1, 0, eNB_id);//PHY_vars_eNB_g[eNB_id]->Mod_id
-	  
-	  // PHY_vars_eNB_g[eNB_id]->frame = frame;
-          phy_procedures_eNB_lte (last_slot, next_slot, PHY_vars_eNB_g[eNB_id], abstraction_flag, 
-				  no_relay,NULL);
+          pdcp_run (frame, 1, 0, eNB_id); //PHY_vars_eNB_g[eNB_id]->Mod_id
+
+          // PHY_vars_eNB_g[eNB_id]->frame = frame;
+          phy_procedures_eNB_lte (last_slot, next_slot, PHY_vars_eNB_g[eNB_id], abstraction_flag, no_relay, NULL);
 
 #ifdef PRINT_STATS
-      	if(last_slot==9 && frame%10==0)
-	  if(eNB_avg_thr)
-	    fprintf(eNB_avg_thr,"%d %d\n",PHY_vars_eNB_g[eNB_id]->frame,(PHY_vars_eNB_g[eNB_id]->total_system_throughput)/((PHY_vars_eNB_g[eNB_id]->frame+1)*10));
-	if (eNB_stats[eNB_id]) {
-	  len = dump_eNB_stats(PHY_vars_eNB_g[eNB_id], stats_buffer, 0);
-	  rewind (eNB_stats[eNB_id]);
-	  fwrite (stats_buffer, 1, len, eNB_stats[eNB_id]);
-	  fflush(eNB_stats[eNB_id]);
-	}
+          if(last_slot==9 && frame%10==0)
+          if(eNB_avg_thr)
+          fprintf(eNB_avg_thr,"%d %d\n",PHY_vars_eNB_g[eNB_id]->frame,(PHY_vars_eNB_g[eNB_id]->total_system_throughput)/((PHY_vars_eNB_g[eNB_id]->frame+1)*10));
+          if (eNB_stats[eNB_id]) {
+            len = dump_eNB_stats(PHY_vars_eNB_g[eNB_id], stats_buffer, 0);
+            rewind (eNB_stats[eNB_id]);
+            fwrite (stats_buffer, 1, len, eNB_stats[eNB_id]);
+            fflush(eNB_stats[eNB_id]);
+          }
 #ifdef OPENAIR2
-	if (eNB_l2_stats) {
-	  len = dump_eNB_l2_stats (stats_buffer, 0);
-	  rewind (eNB_l2_stats);
-	  fwrite (stats_buffer, 1, len, eNB_l2_stats);
-	  fflush(eNB_l2_stats);
-	}
-#endif 	
+          if (eNB_l2_stats) {
+            len = dump_eNB_l2_stats (stats_buffer, 0);
+            rewind (eNB_l2_stats);
+            fwrite (stats_buffer, 1, len, eNB_l2_stats);
+            fflush(eNB_l2_stats);
+          }
+#endif
 #endif
         }
         // Call ETHERNET emulation here
@@ -677,277 +518,497 @@ int main (int argc, char **argv) {
           clear_UE_transport_info (oai_emulation.info.nb_ue_local);
 
         for (UE_id = oai_emulation.info.first_ue_local;
-             (UE_id < (oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local)) && (oai_emulation.info.cli_start_ue[UE_id]==1);
-             UE_id++){
-          if (frame >= (UE_id * 20)) {    // activate UE only after 20*UE_id frames so that different UEs turn on separately
-	    
-	    LOG_D(EMU,"PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
-		  UE_id, frame, slot, next_slot >> 1,last_slot>>1);
-
-	    if (PHY_vars_UE_g[UE_id]->UE_mode[0] != NOT_SYNCHED) {
-	      if (frame>0) {
-		PHY_vars_UE_g[UE_id]->frame = frame;
-		
-		//Application
-		update_otg_UE(UE_id, oai_emulation.info.time_ms);
-		
-		//Access layer
-		pdcp_run(frame, 0, UE_id, 0);
-		
-		phy_procedures_UE_lte (last_slot, next_slot, PHY_vars_UE_g[UE_id], 0, abstraction_flag,normal_txrx, 
-				       no_relay,NULL);
-		ue_data[UE_id]->tx_power_dBm = PHY_vars_UE_g[UE_id]->tx_power_dBm;
-	      }
-	    }
-	    else {
-	      if (abstraction_flag==1){
-		LOG_E(EMU, "sync not supported in abstraction mode (UE%d,mode%d)\n", UE_id, PHY_vars_UE_g[UE_id]->UE_mode[0]);
-		exit(-1);
-	      }
-	      if ((frame>0) && (last_slot == (LTE_SLOTS_PER_FRAME-2))) {
-		initial_sync(PHY_vars_UE_g[UE_id],normal_txrx);
-		
-		/*
-		  write_output("dlchan00.m","dlch00",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
-		  if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
-		  write_output("dlchan01.m","dlch01",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][1][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
-		  write_output("dlchan10.m","dlch10",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][2][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
-		  if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
-		  write_output("dlchan11.m","dlch11",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][3][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
-		  write_output("rxsig.m","rxs",PHY_vars_UE_g[0]->lte_ue_common_vars.rxdata[0],PHY_vars_UE_g[0]->lte_frame_parms.samples_per_tti*10,1,1);
-		  write_output("rxsigF.m","rxsF",PHY_vars_UE_g[0]->lte_ue_common_vars.rxdataF[0],2*PHY_vars_UE_g[0]->lte_frame_parms.symbols_per_tti*PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size,2,1);
-		  write_output("pbch_rxF_ext0.m","pbch_ext0",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_ext[0],6*12*4,1,1);
-		  write_output("pbch_rxF_comp0.m","pbch_comp0",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0],6*12*4,1,1);
-		  write_output("pbch_rxF_llr.m","pbch_llr",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr,(frame_parms->Ncp==0) ? 1920 : 1728,1,4);
-		*/
-	      }
-	    }
+            (UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local))
+                && (oai_emulation.info.cli_start_ue[UE_id] == 1); UE_id++) {
+          if (frame >= (UE_id * 20)) { // activate UE only after 20*UE_id frames so that different UEs turn on separately
+
+            LOG_D(
+                EMU,
+                "PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n", UE_id, frame, slot, next_slot >> 1, last_slot>>1);
+
+            if (PHY_vars_UE_g[UE_id]->UE_mode[0] != NOT_SYNCHED) {
+              if (frame > 0) {
+                PHY_vars_UE_g[UE_id]->frame = frame;
+
+                //Application
+                update_otg_UE (UE_id, oai_emulation.info.time_ms);
+
+                //Access layer
+                pdcp_run (frame, 0, UE_id, 0);
+
+                phy_procedures_UE_lte (last_slot, next_slot, PHY_vars_UE_g[UE_id], 0, abstraction_flag, normal_txrx,
+                                       no_relay, NULL);
+                ue_data[UE_id]->tx_power_dBm = PHY_vars_UE_g[UE_id]->tx_power_dBm;
+              }
+            }
+            else {
+              if (abstraction_flag == 1) {
+                LOG_E(
+                    EMU,
+                    "sync not supported in abstraction mode (UE%d,mode%d)\n", UE_id, PHY_vars_UE_g[UE_id]->UE_mode[0]);
+                exit (-1);
+              }
+              if ((frame > 0) && (last_slot == (LTE_SLOTS_PER_FRAME - 2))) {
+                initial_sync (PHY_vars_UE_g[UE_id], normal_txrx);
+
+                /*
+                 write_output("dlchan00.m","dlch00",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
+                 if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
+                 write_output("dlchan01.m","dlch01",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][1][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
+                 write_output("dlchan10.m","dlch10",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][2][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
+                 if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
+                 write_output("dlchan11.m","dlch11",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][3][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
+                 write_output("rxsig.m","rxs",PHY_vars_UE_g[0]->lte_ue_common_vars.rxdata[0],PHY_vars_UE_g[0]->lte_frame_parms.samples_per_tti*10,1,1);
+                 write_output("rxsigF.m","rxsF",PHY_vars_UE_g[0]->lte_ue_common_vars.rxdataF[0],2*PHY_vars_UE_g[0]->lte_frame_parms.symbols_per_tti*PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size,2,1);
+                 write_output("pbch_rxF_ext0.m","pbch_ext0",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_ext[0],6*12*4,1,1);
+                 write_output("pbch_rxF_comp0.m","pbch_comp0",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0],6*12*4,1,1);
+                 write_output("pbch_rxF_llr.m","pbch_llr",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr,(frame_parms->Ncp==0) ? 1920 : 1728,1,4);
+                 */
+              }
+            }
 #ifdef PRINT_STATS
-	    if(last_slot==2 && frame%10==0)
-	      if (UE_stats_th[UE_id])
-		fprintf(UE_stats_th[UE_id],"%d %d\n",frame, PHY_vars_UE_g[UE_id]->bitrate[0]/1000);
-	    if (UE_stats[UE_id]) {
-	      len = dump_ue_stats (PHY_vars_UE_g[UE_id], stats_buffer, 0, normal_txrx, 0);
-	      rewind (UE_stats[UE_id]);
-	      fwrite (stats_buffer, 1, len, UE_stats[UE_id]);
-	      fflush(UE_stats[UE_id]);
-	    }
+            if(last_slot==2 && frame%10==0)
+            if (UE_stats_th[UE_id])
+            fprintf(UE_stats_th[UE_id],"%d %d\n",frame, PHY_vars_UE_g[UE_id]->bitrate[0]/1000);
+            if (UE_stats[UE_id]) {
+              len = dump_ue_stats (PHY_vars_UE_g[UE_id], stats_buffer, 0, normal_txrx, 0);
+              rewind (UE_stats[UE_id]);
+              fwrite (stats_buffer, 1, len, UE_stats[UE_id]);
+              fflush(UE_stats[UE_id]);
+            }
 #endif
-	  }
-	}
+          }
+        }
 #ifdef Rel10
-	for (RN_id=oai_emulation.info.first_rn_local;
-             RN_id<oai_emulation.info.first_rn_local+oai_emulation.info.nb_rn_local;
-	     RN_id++) {
-	  // UE id and eNB id of the RN
-	  UE_id= oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local + RN_id; // NB_UE_INST + RN_id
-	  eNB_id= oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local + RN_id; // NB_eNB_INST + RN_id
-	  // currently only works in FDD
-	  if (oai_emulation.info.eMBMS_active_state == 4){
-	    r_type = multicast_relay;
-	    //LOG_I(EMU,"Activating the multicast relaying\n");
-	  }else {
-	    LOG_E(EMU,"Not supported eMBMS option when relaying is enabled %d\n", r_type);
-	    exit(-1);
-	  }
-	  PHY_vars_RN_g[RN_id]->frame = frame;
-	  if ( oai_emulation.info.frame_type  == 0) {
-	    // RN == UE
-	    if (frame>0) {
-	      if (PHY_vars_UE_g[UE_id]->UE_mode[0] != NOT_SYNCHED) {
-		LOG_D(EMU,"[RN %d] PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
-		      RN_id, UE_id, frame, slot, next_slot >> 1,last_slot>>1);
-		PHY_vars_UE_g[UE_id]->frame = frame;
-		phy_procedures_UE_lte (last_slot, next_slot, PHY_vars_UE_g[UE_id], 0, abstraction_flag,normal_txrx, 
-				       r_type, PHY_vars_RN_g[RN_id]);
-	      } else if (last_slot == (LTE_SLOTS_PER_FRAME-2)) {
-		initial_sync(PHY_vars_UE_g[UE_id],normal_txrx);
-	      }
-	    }
-	    // RN == eNB
-	    LOG_D(EMU,"[RN %d] PHY procedures eNB %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
-	    	  RN_id, eNB_id, frame, slot, next_slot >> 1,last_slot>>1);
-	    phy_procedures_eNB_lte (last_slot, next_slot, PHY_vars_eNB_g[eNB_id], abstraction_flag, 
-				    r_type, PHY_vars_RN_g[RN_id]);
-	  }
-	  else{
-	    LOG_E(EMU,"TDD is not supported for multicast relaying %d\n", r_type);
-	    exit(-1);
-	  }
-	}
+        for (RN_id=oai_emulation.info.first_rn_local;
+            RN_id<oai_emulation.info.first_rn_local+oai_emulation.info.nb_rn_local;
+            RN_id++) {
+          // UE id and eNB id of the RN
+          UE_id= oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local + RN_id;// NB_UE_INST + RN_id
+          eNB_id= oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local + RN_id;// NB_eNB_INST + RN_id
+          // currently only works in FDD
+          if (oai_emulation.info.eMBMS_active_state == 4) {
+            r_type = multicast_relay;
+            //LOG_I(EMU,"Activating the multicast relaying\n");
+          }
+          else {
+            LOG_E(EMU,"Not supported eMBMS option when relaying is enabled %d\n", r_type);
+            exit(-1);
+          }
+          PHY_vars_RN_g[RN_id]->frame = frame;
+          if ( oai_emulation.info.frame_type == 0) {
+            // RN == UE
+            if (frame>0) {
+              if (PHY_vars_UE_g[UE_id]->UE_mode[0] != NOT_SYNCHED) {
+                LOG_D(EMU,"[RN %d] PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
+                    RN_id, UE_id, frame, slot, next_slot >> 1,last_slot>>1);
+                PHY_vars_UE_g[UE_id]->frame = frame;
+                phy_procedures_UE_lte (last_slot, next_slot, PHY_vars_UE_g[UE_id], 0, abstraction_flag,normal_txrx,
+                    r_type, PHY_vars_RN_g[RN_id]);
+              }
+              else if (last_slot == (LTE_SLOTS_PER_FRAME-2)) {
+                initial_sync(PHY_vars_UE_g[UE_id],normal_txrx);
+              }
+            }
+            // RN == eNB
+            LOG_D(EMU,"[RN %d] PHY procedures eNB %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
+                RN_id, eNB_id, frame, slot, next_slot >> 1,last_slot>>1);
+            phy_procedures_eNB_lte (last_slot, next_slot, PHY_vars_eNB_g[eNB_id], abstraction_flag,
+                r_type, PHY_vars_RN_g[RN_id]);
+          }
+          else {
+            LOG_E(EMU,"TDD is not supported for multicast relaying %d\n", r_type);
+            exit(-1);
+          }
+        }
 #endif
-      emu_transport (frame, last_slot, next_slot,direction, oai_emulation.info.frame_type, ethernet_flag);
-      if ((direction  == SF_DL)|| (frame_parms->frame_type==0)){
-         // consider only sec id 0
-	/*	for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
-	  if (abstraction_flag == 0) {
-	    do_OFDM_mod(PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdataF[0],
-			  PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdata[0],
-			  frame,next_slot,
-			  frame_parms);
-	  }
-	  }*/
-	for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
-	  do_DL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,eNB2UE,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,UE_id);
-	}
-      }
-      if ((direction  == SF_UL)|| (frame_parms->frame_type==0)){//if ((subframe<2) || (subframe>4))
-          do_UL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,frame);
-	  /*   
-	       int ccc;
-	       fprintf(SINRpost,"SINRdb For eNB New Subframe : \n ");
-	       for(ccc = 0 ; ccc<301; ccc++)
-	       {
-	       fprintf(SINRpost,"_ %f ", SINRpost_eff[ccc]);
-	       }
-                fprintf(SINRpost,"SINRdb For eNB : %f \n ", SINRpost_eff[ccc]);
-	*/   
-      }
-      if ((direction == SF_S)) {//it must be a special subframe
-        if (next_slot%2==0) {//DL part
-	  /*  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
-	    if (abstraction_flag == 0) {
-	      do_OFDM_mod(PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdataF[0],
-			  PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdata[0],
-			  frame,next_slot,
-			  frame_parms);
-	    }
-	    }*/
-	  for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
-	    do_DL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,eNB2UE,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,UE_id);
-	  }
+        emu_transport (frame, last_slot, next_slot, direction, oai_emulation.info.frame_type, ethernet_flag);
+        if ((direction == SF_DL) || (frame_parms->frame_type == 0)) {
+          // consider only sec id 0
+          /*  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
+           if (abstraction_flag == 0) {
+           do_OFDM_mod(PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdataF[0],
+           PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdata[0],
+           frame,next_slot,
+           frame_parms);
+           }
+           }*/
+          for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
+            do_DL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, eNB2UE, enb_data, ue_data, next_slot, abstraction_flag,
+                       frame_parms, UE_id);
+          }
+        }
+        if ((direction == SF_UL) || (frame_parms->frame_type == 0)) { //if ((subframe<2) || (subframe>4))
+          do_UL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, UE2eNB, enb_data, ue_data, next_slot, abstraction_flag,
+                     frame_parms, frame);
           /*
-            for (aarx=0;aarx<UE2eNB[1][0]->nb_rx;aarx++)
-            for (aatx=0;aatx<UE2eNB[1][0]->nb_tx;aatx++)
-            for (k=0;k<UE2eNB[1][0]->channel_length;k++)
-            printf("SB(%d,%d,%d)->(%f,%f)\n",k,aarx,aatx,UE2eNB[1][0]->ch[aarx+(aatx*UE2eNB[1][0]->nb_rx)][k].r,UE2eNB[1][0]->ch[aarx+(aatx*UE2eNB[1][0]->nb_rx)][k].i);
-          */
+           int ccc;
+           fprintf(SINRpost,"SINRdb For eNB New Subframe : \n ");
+           for(ccc = 0 ; ccc<301; ccc++)
+           {
+           fprintf(SINRpost,"_ %f ", SINRpost_eff[ccc]);
+           }
+           fprintf(SINRpost,"SINRdb For eNB : %f \n ", SINRpost_eff[ccc]);
+           */
         }
-        else {// UL part
-	  do_UL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,frame);
-	          
-	  /*        int ccc;
-            fprintf(SINRpost,"SINRdb For eNB New Subframe : \n ");
-            for(ccc = 0 ; ccc<301; ccc++)
-            {
-              fprintf(SINRpost,"_ %f ", SINRpost_eff[ccc]);
+        if ((direction == SF_S)) { //it must be a special subframe
+          if (next_slot % 2 == 0) { //DL part
+            /*  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
+             if (abstraction_flag == 0) {
+             do_OFDM_mod(PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdataF[0],
+             PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdata[0],
+             frame,next_slot,
+             frame_parms);
+             }
+             }*/
+            for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
+              do_DL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, eNB2UE, enb_data, ue_data, next_slot, abstraction_flag,
+                         frame_parms, UE_id);
             }
-            fprintf(SINRpost,"SINRdb For eNB : %f \n ", SINRpost_eff[ccc]);
+            /*
+             for (aarx=0;aarx<UE2eNB[1][0]->nb_rx;aarx++)
+             for (aatx=0;aatx<UE2eNB[1][0]->nb_tx;aatx++)
+             for (k=0;k<UE2eNB[1][0]->channel_length;k++)
+             printf("SB(%d,%d,%d)->(%f,%f)\n",k,aarx,aatx,UE2eNB[1][0]->ch[aarx+(aatx*UE2eNB[1][0]->nb_rx)][k].r,UE2eNB[1][0]->ch[aarx+(aatx*UE2eNB[1][0]->nb_rx)][k].i);
+             */
           }
-    */    }
-	}
-        if ((last_slot == 1) && (frame == 0)
-          && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) {
+          else { // UL part
+            do_UL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, UE2eNB, enb_data, ue_data, next_slot, abstraction_flag,
+                       frame_parms, frame);
+
+            /*        int ccc;
+             fprintf(SINRpost,"SINRdb For eNB New Subframe : \n ");
+             for(ccc = 0 ; ccc<301; ccc++)
+             {
+             fprintf(SINRpost,"_ %f ", SINRpost_eff[ccc]);
+             }
+             fprintf(SINRpost,"SINRdb For eNB : %f \n ", SINRpost_eff[ccc]);
+             }
+             */}
+        }
+        if ((last_slot == 1) && (frame == 0) && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) {
 
-          write_output ("dlchan0.m", "dlch0",
-                        &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),
+          write_output ("dlchan0.m", "dlch0", &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),
                         (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
-          write_output ("dlchan1.m", "dlch1",
-                        &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]),
+          write_output ("dlchan1.m", "dlch1", &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]),
                         (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
-          write_output ("dlchan2.m", "dlch2",
-                        &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]),
+          write_output ("dlchan2.m", "dlch2", &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]),
                         (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
-          write_output ("pbch_rxF_comp0.m", "pbch_comp0",
-                        PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], 6 * 12 * 4, 1, 1);
-          write_output ("pbch_rxF_llr.m", "pbch_llr",
-                        PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr, (frame_parms->Ncp == 0) ? 1920 : 1728, 1, 4);
+          write_output ("pbch_rxF_comp0.m", "pbch_comp0", PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0],
+                        6 * 12 * 4, 1, 1);
+          write_output ("pbch_rxF_llr.m", "pbch_llr", PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr,
+                        (frame_parms->Ncp == 0) ? 1920 : 1728, 1, 4);
         }
         /*
          if ((last_slot==1) && (frame==1)) {
          write_output("dlsch_rxF_comp0.m","dlsch0_rxF_comp0",PHY_vars_UE->lte_ue_pdsch_vars[eNB_id]->rxdataF_comp[0],300*(-(PHY_vars_UE->lte_frame_parms.Ncp*2)+14),1,1);
          write_output("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE->lte_ue_pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1);
          }
-       */
+         */
 
-        if (next_slot %2 == 0){
+        if (next_slot % 2 == 0) {
           clock_gettime (CLOCK_REALTIME, &time_spec);
           time_last = time_now;
           time_now = (unsigned long) time_spec.tv_nsec;
           td = (int) (time_now - time_last);
-          if (td>0) {
-            td_avg = (int)(((K*(long)td) + (((1<<3)-K)*((long)td_avg)))>>3); // in us
-            LOG_T(EMU,"sleep frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n",
-                  frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
+          if (td > 0) {
+            td_avg = (int) (((K * (long) td) + (((1 << 3) - K) * ((long) td_avg))) >> 3); // in us
+            LOG_T(
+                EMU,
+                "sleep frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n", frame, time_now, time_last, td_avg, td/1000, (td_avg-TARGET_SF_TIME_NS)/1000);
           }
-          if (td_avg<(TARGET_SF_TIME_NS - SF_DEVIATION_OFFSET_NS)){
+          if (td_avg < (TARGET_SF_TIME_NS - SF_DEVIATION_OFFSET_NS)) {
             sleep_time_us += SLEEP_STEP_US;
-            LOG_D(EMU,"Faster than realtime increase the avg sleep time for %d us, frame %d\n",
-                  sleep_time_us,frame);
+            LOG_D(EMU, "Faster than realtime increase the avg sleep time for %d us, frame %d\n", sleep_time_us, frame);
             // LOG_D(EMU,"Faster than realtime increase the avg sleep time for %d us, frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n",    sleep_time_us,frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
           }
-          else if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) {
-            sleep_time_us-= SLEEP_STEP_US;
-            LOG_D(EMU,"Slower than realtime reduce the avg sleep time for %d us, frame %d, time_now\n",
-                  sleep_time_us,frame);
-            //LOG_T(EMU,"Slower than realtime reduce the avg sleep time for %d us, frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n",     sleep_time_us,frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
-          }
+          else
+            if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) {
+              sleep_time_us -= SLEEP_STEP_US;
+              LOG_D(
+                  EMU,
+                  "Slower than realtime reduce the avg sleep time for %d us, frame %d, time_now\n", sleep_time_us, frame);
+              //LOG_T(EMU,"Slower than realtime reduce the avg sleep time for %d us, frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n",     sleep_time_us,frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
+            }
         } // end if next_slot%2
-      }// if Channel_Flag==0
+      } // if Channel_Flag==0
+
+    } //end of slot
 
-    }                          //end of slot
-    
-    if ((frame>=1)&&(frame<=9)&&(abstraction_flag==0)
+    if ((frame >= 1) && (frame <= 9) && (abstraction_flag == 0)
 #ifdef PROC
-      &&(Channel_Flag==0)
+        &&(Channel_Flag==0)
 #endif
-      ){
-      write_output("UEtxsig0.m","txs0", PHY_vars_UE_g[0]->lte_ue_common_vars.txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
-      sprintf(fname,"eNBtxsig%d.m",frame);
-      sprintf(vname,"txs%d",frame);
-      write_output(fname,vname, PHY_vars_eNB_g[0]->lte_eNB_common_vars.txdata[0][0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
-      write_output("eNBtxsigF0.m","txsF0",PHY_vars_eNB_g[0]->lte_eNB_common_vars.txdataF[0][0],PHY_vars_eNB_g[0]->lte_frame_parms.symbols_per_tti*PHY_vars_eNB_g[0]->lte_frame_parms.ofdm_symbol_size,1,1);
-
-      write_output("UErxsig0.m","rxs0", PHY_vars_UE_g[0]->lte_ue_common_vars.rxdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
-      write_output("eNBrxsig0.m","rxs0", PHY_vars_eNB_g[0]->lte_eNB_common_vars.rxdata[0][0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
-    } 
+        ) {
+      write_output ("UEtxsig0.m", "txs0", PHY_vars_UE_g[0]->lte_ue_common_vars.txdata[0], FRAME_LENGTH_COMPLEX_SAMPLES,
+                    1, 1);
+      sprintf (fname, "eNBtxsig%d.m", frame);
+      sprintf (vname, "txs%d", frame);
+      write_output (fname, vname, PHY_vars_eNB_g[0]->lte_eNB_common_vars.txdata[0][0], FRAME_LENGTH_COMPLEX_SAMPLES, 1,
+                    1);
+      write_output (
+          "eNBtxsigF0.m", "txsF0", PHY_vars_eNB_g[0]->lte_eNB_common_vars.txdataF[0][0],
+          PHY_vars_eNB_g[0]->lte_frame_parms.symbols_per_tti * PHY_vars_eNB_g[0]->lte_frame_parms.ofdm_symbol_size, 1,
+          1);
+
+      write_output ("UErxsig0.m", "rxs0", PHY_vars_UE_g[0]->lte_ue_common_vars.rxdata[0], FRAME_LENGTH_COMPLEX_SAMPLES,
+                    1, 1);
+      write_output ("eNBrxsig0.m", "rxs0", PHY_vars_eNB_g[0]->lte_eNB_common_vars.rxdata[0][0],
+                    FRAME_LENGTH_COMPLEX_SAMPLES, 1, 1);
+    }
 
 #ifdef XFORMS
     eNB_id = 0;
     for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
-      phy_scope_UE(form_ue[UE_id], 
-		   PHY_vars_UE_g[UE_id],
-		   eNB_id,
-		   UE_id,
-		   7);
-      
-      phy_scope_eNB(form_enb[UE_id], 
-		    PHY_vars_eNB_g[eNB_id],
-		    UE_id);
-      
+      phy_scope_UE(form_ue[UE_id],
+          PHY_vars_UE_g[UE_id],
+          eNB_id,
+          UE_id,
+          7);
+
+      phy_scope_eNB(form_enb[UE_id],
+          PHY_vars_eNB_g[eNB_id],
+          UE_id);
+
     }
-#endif  
+#endif
 
     // calibrate at the end of each frame if there is some time  left
-    if((sleep_time_us > 0)&& (ethernet_flag ==0)){
-      LOG_I(EMU,"[TIMING] Adjust average frame duration, sleep for %d us\n",sleep_time_us);
-      usleep(sleep_time_us);
-      sleep_time_us=0; // reset the timer, could be done per n SF 
+    if ((sleep_time_us > 0) && (ethernet_flag == 0)) {
+      LOG_I(EMU, "[TIMING] Adjust average frame duration, sleep for %d us\n", sleep_time_us);
+      usleep (sleep_time_us);
+      sleep_time_us = 0; // reset the timer, could be done per n SF
     }
 #ifdef SMBV
     if ((frame == config_frames[0]) || (frame == config_frames[1]) || (frame == config_frames[2]) || (frame == config_frames[3])) {
-        smbv_frame_cnt++;        
+      smbv_frame_cnt++;
+    }
+#endif
+  } //end of frame
+
+#if defined(ENABLE_ITTI)
+  /* Stops test timer */
+  timer_remove(timer_id);
+
+  itti_terminate_tasks(TASK_L2L1);
+#endif
+
+  return NULL;
+}
+
+Packet_OTG_List *otg_pdcp_buffer;
+
+int main(int argc, char **argv) {
+
+  s32 i;
+  // pointers signal buffers (s = transmit, r,r0 = receive)
+  clock_t t;
+
+  //FILE *SINRpost;
+  //char SINRpost_fname[512];
+  // sprintf(SINRpost_fname,"postprocSINR.m");
+  //SINRpost = fopen(SINRpost_fname,"w");
+  // variables/flags which are set by user on command-line
+
+#ifdef SMBV
+  strcpy(smbv_ip,DEFAULT_SMBV_IP);
+#endif
+
+  // time calibration for soft realtime mode  
+
+  // u8 awgn_flag = 0;
+#ifdef XFORMS
+  // current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
+  // at eNB 0, an UL scope for every UE 
+  FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX];
+  FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
+  char title[255];
+#endif
+
+#ifdef PRINT_STATS
+  int len;
+  FILE *UE_stats[NUMBER_OF_UE_MAX], *UE_stats_th[NUMBER_OF_UE_MAX], *eNB_stats[NUMBER_OF_eNB_MAX], *eNB_avg_thr, *eNB_l2_stats;
+  char UE_stats_filename[255];
+  char eNB_stats_filename[255];
+  char UE_stats_th_filename[255];
+  char eNB_stats_th_filename[255];
+#endif
+
+  //time_t t0,t1;
+  //clock_t start, stop;
+
+#ifdef PROC
+  int node_id;
+  int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
+#endif
+  //double **s_re2[MAX_eNB+MAX_UE], **s_im2[MAX_eNB+MAX_UE], **r_re2[MAX_eNB+MAX_UE], **r_im2[MAX_eNB+MAX_UE], **r_re02, **r_im02;
+  //double **r_re0_d[MAX_UE][MAX_eNB], **r_im0_d[MAX_UE][MAX_eNB], **r_re0_u[MAX_eNB][MAX_UE],**r_im0_u[MAX_eNB][MAX_UE];
+  //default parameters
+  rate_adaptation_flag = 0;
+  oai_emulation.info.n_frames = 0xffff; //1024;          //10;
+  oai_emulation.info.n_frames_flag = 0; //fixme
+  snr_dB = 30;
+  cooperation_flag = 0; // default value 0 for no cooperation, 1 for Delay diversity, 2 for Distributed Alamouti
+
+  //Default values if not changed by the user in get_simulation_options();
+  pdcp_period = 1;
+  omg_period = 1;
+  // start thread for log gen
+  log_thread_init ();
+
+  init_oai_emulation (); // to initialize everything !!!
+
+  // get command-line options
+  get_simulation_options (argc, argv); //Command-line options
+
+  // Initialize VCD LOG module
+  vcd_signal_dumper_init ("openair_dump.vcd");
+
+  /*  pthread_t sigth;
+   sigset_t sigblock;
+   sigemptyset(&sigblock);
+   sigaddset(&sigblock, SIGHUP);
+   sigaddset(&sigblock, SIGINT);
+   sigaddset(&sigblock, SIGTERM);
+   pthread_sigmask(SIG_BLOCK, &sigblock, NULL);
+   if (pthread_create(&sigth, NULL, sigh, NULL)) {
+   msg("Pthread for tracing Signals is not created!\n");
+   return -1;
+   } else {
+   msg("Pthread for tracing Signals is created!\n");
+   }*/
+  // configure oaisim with OCG
+  oaisim_config (); // config OMG and OCG, OPT, OTG, OLG
+
+  if (ue_connection_test == 1) {
+    snr_direction = -snr_step;
+    snr_dB = 20;
+    sinr_dB = -20;
+  }
+
+#if defined(ENABLE_ITTI)
+  itti_init(THREAD_MAX, MESSAGES_ID_MAX, threads_name, messages_info, messages_definition_xml);
+#endif
+
+#ifdef OPENAIR2
+  init_omv ();
+#endif
+  //Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
+
+  check_and_adjust_params ();
+
+#ifdef PRINT_STATS
+  for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
+    sprintf(UE_stats_filename,"UE_stats%d.txt",UE_id);
+    UE_stats[UE_id] = fopen (UE_stats_filename, "w");
+  }
+  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
+    sprintf(eNB_stats_filename,"eNB_stats%d.txt",eNB_id);
+    eNB_stats[eNB_id] = fopen (eNB_stats_filename, "w");
+  }
+
+  if(abstraction_flag==0) {
+    for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
+      sprintf(UE_stats_th_filename,"UE_stats_th%d_tx%d.txt",UE_id,oai_emulation.info.transmission_mode);
+      UE_stats_th[UE_id] = fopen (UE_stats_th_filename, "w");
+    }
+    sprintf(eNB_stats_th_filename,"eNB_stats_th_tx%d.txt",oai_emulation.info.transmission_mode);
+    eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
+  }
+  else {
+    for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
+      sprintf(UE_stats_th_filename,"UE_stats_abs_th%d_tx%d.txt",UE_id,oai_emulation.info.transmission_mode);
+      UE_stats_th[UE_id] = fopen (UE_stats_th_filename, "w");
+    }
+    sprintf(eNB_stats_th_filename,"eNB_stats_abs_th_tx%d.txt",oai_emulation.info.transmission_mode);
+    eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
+  }
+#ifdef OPENAIR2
+  eNB_l2_stats = fopen ("eNB_l2_stats.txt", "w");
+  LOG_I(EMU,"eNB_l2_stats=%p\n", eNB_l2_stats);
+#endif 
+
+#endif
+
+  set_seed = oai_emulation.emulation_config.seed.value;
+
+  init_otg_pdcp_buffer ();
+
+  init_seed (set_seed);
+
+  init_openair1 ();
+
+  init_openair2 ();
+
+  init_ocm ();
+
+#ifdef XFORMS
+  eNB_id = 0;
+  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
+    // DL scope at UEs
+    fl_initialize (&argc, argv, NULL, 0, 0);
+    form_ue[UE_id] = create_lte_phy_scope_ue();
+    sprintf (title, "LTE DL SCOPE eNB %d to UE %d", eNB_id, UE_id);
+    fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
+
+    // UL scope at eNB 0
+    fl_initialize (&argc, argv, NULL, 0, 0);
+    form_enb[UE_id] = create_lte_phy_scope_enb();
+    sprintf (title, "LTE UL SCOPE UE %d to eNB %d", UE_id, eNB_id);
+    fl_show_form (form_enb[UE_id]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
+
+    if (openair_daq_vars.use_ia_receiver == 1) {
+      fl_set_button(form_ue[UE_id]->button_0,1);
+      fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON");
+      fl_set_object_color(form_ue[UE_id]->button_0, FL_GREEN, FL_GREEN);
     }
+
+  }
+#endif
+
+#ifdef SMBV
+  smbv_init_config(smbv_fname, smbv_nframes);
+  smbv_write_config_from_frame_parms(smbv_fname, &PHY_vars_eNB_g[0]->lte_frame_parms);
+#endif
+
+  init_time ();
+
+  init_slot_isr ();
+
+  t = clock ();
+
+  LOG_N(EMU, "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
+
+#if defined(ENABLE_ITTI)
+  if (itti_create_task(TASK_L2L1, &l2l1_task, NULL) < 0) {
+    LOG_E(EMU, "Create task failed");
+    LOG_D(EMU, "Initializing L2L1 task interface: FAILED\n");
+    return -1;
+  }
+
+  // Handle signals until all tasks are terminated
+  itti_wait_tasks_end();
+#else
+  l2l1_task (NULL);
 #endif
-  }     //end of frame
 
-  t = clock() - t;
-  printf ("rrc Duration of the simulation: %f seconds\n",((float)t)/CLOCKS_PER_SEC);
+  t = clock () - t;
+  printf ("rrc Duration of the simulation: %f seconds\n", ((float) t) / CLOCKS_PER_SEC);
 
   //  fclose(SINRpost);
-  LOG_I(EMU,">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
+  LOG_I(EMU, ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
 
-  free(otg_pdcp_buffer);
+  free (otg_pdcp_buffer);
 
 #ifdef SMBV
   if (config_smbv) {
-      smbv_send_config (smbv_fname,smbv_ip);
+    smbv_send_config (smbv_fname,smbv_ip);
   }
 #endif
 
   //Perform KPI measurements
-  if (oai_emulation.info.otg_enabled==1)
-    kpi_gen();
+  if (oai_emulation.info.otg_enabled == 1)
+    kpi_gen ();
 
   // relase all rx state
   if (ethernet_flag == 1) {
@@ -955,20 +1016,20 @@ int main (int argc, char **argv) {
   }
 
 #ifdef PROC
-  if (abstraction_flag == 0 && Channel_Flag==0 && Process_Flag==0) 
+  if (abstraction_flag == 0 && Channel_Flag==0 && Process_Flag==0)
 #else
-    if (abstraction_flag == 0)
+  if (abstraction_flag == 0)
 #endif
-    {
+      {
     /*
-       #ifdef IFFT_FPGA
-       free(txdataF2[0]);
-       free(txdataF2[1]);
-       free(txdataF2);
-       free(txdata[0]);
-       free(txdata[1]);
-       free(txdata);
-       #endif
+     #ifdef IFFT_FPGA
+     free(txdataF2[0]);
+     free(txdataF2[1]);
+     free(txdataF2);
+     free(txdata[0]);
+     free(txdata[1]);
+     free(txdata);
+     #endif
      */
 
     for (i = 0; i < 2; i++) {
@@ -988,91 +1049,91 @@ int main (int argc, char **argv) {
 
   // added for PHY abstraction
   if (oai_emulation.info.ocm_enabled == 1) {
-    for (eNB_id = 0; eNB_id < NUMBER_OF_eNB_MAX; eNB_id++) 
-      free(enb_data[eNB_id]); 
-    
+    for (eNB_id = 0; eNB_id < NUMBER_OF_eNB_MAX; eNB_id++)
+      free (enb_data[eNB_id]);
+
     for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++)
-      free(ue_data[UE_id]); 
+      free (ue_data[UE_id]);
   } //End of PHY abstraction changes
 
 #ifdef OPENAIR2
-  mac_top_cleanup();
+  mac_top_cleanup ();
 #endif 
-  
+
 #ifdef PRINT_STATS
   for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
-    if (UE_stats[UE_id]) 
-      fclose (UE_stats[UE_id]);
+    if (UE_stats[UE_id])
+    fclose (UE_stats[UE_id]);
     if(UE_stats_th[UE_id])
-      fclose (UE_stats_th[UE_id]);
+    fclose (UE_stats_th[UE_id]);
   }
   for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
     if (eNB_stats[eNB_id])
-      fclose (eNB_stats[eNB_id]);
+    fclose (eNB_stats[eNB_id]);
   }
   if (eNB_avg_thr)
-    fclose (eNB_avg_thr);
+  fclose (eNB_avg_thr);
   if (eNB_l2_stats)
-    fclose (eNB_l2_stats);
-  
+  fclose (eNB_l2_stats);
+
 #endif
 
   // stop OMG
-  stop_mobility_generator(oai_emulation.info.omg_model_ue);//omg_param_list.mobility_type
+  stop_mobility_generator (oai_emulation.info.omg_model_ue); //omg_param_list.mobility_type
 #ifdef OPENAIR2
   if (oai_emulation.info.omv_enabled == 1)
-    omv_end(pfd[1],omv_data);
+    omv_end (pfd[1], omv_data);
 #endif
-  if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0) && (ShaF != NULL)) 
-    destroyMat(ShaF,map1, map2);
+  if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0) && (ShaF != NULL))
+    destroyMat (ShaF, map1, map2);
+
+  if ((oai_emulation.info.opt_enabled == 1))
+    terminate_opt ();
 
-  if ((oai_emulation.info.opt_enabled == 1) )
-    terminate_opt();
-  
   if (oai_emulation.info.cli_enabled)
-    cli_server_cleanup();
+    cli_server_cleanup ();
 
   //bring oai if down
-  terminate();
-  log_thread_finalize();
-  logClean();
-  vcd_signal_dumper_close();
-  
-  return(0);
+  terminate ();
+  log_thread_finalize ();
+  logClean ();
+  vcd_signal_dumper_close ();
+
+  return (0);
 }
 
 /*
-static void *sigh(void *arg) {
-
-  int signum;
-  sigset_t sigcatch;
-  sigemptyset(&sigcatch);
-  sigaddset(&sigcatch, SIGHUP);
-  sigaddset(&sigcatch, SIGINT);
-  sigaddset(&sigcatch, SIGTERM);
-  
-  for (;;) {
-    sigwait(&sigcatch, &signum);
-    switch (signum) {
-    case SIGHUP:
-    case SIGINT:
-    case SIGTERM:
-      terminate();
-    default:
-      break;
-    }
-  }
-  pthread_exit(NULL);
-}
-*/
+ static void *sigh(void *arg) {
+
+ int signum;
+ sigset_t sigcatch;
+ sigemptyset(&sigcatch);
+ sigaddset(&sigcatch, SIGHUP);
+ sigaddset(&sigcatch, SIGINT);
+ sigaddset(&sigcatch, SIGTERM);
+
+ for (;;) {
+ sigwait(&sigcatch, &signum);
+ switch (signum) {
+ case SIGHUP:
+ case SIGINT:
+ case SIGTERM:
+ terminate();
+ default:
+ break;
+ }
+ }
+ pthread_exit(NULL);
+ }
+ */
 
 void terminate(void) {
   int i;
   char interfaceName[8];
-  for (i=0; i < NUMBER_OF_eNB_MAX+NUMBER_OF_UE_MAX; i++)
-    if (oai_emulation.info.oai_ifup[i]==1){
-    sprintf(interfaceName, "oai%d", i);
-    bringInterfaceUp(interfaceName,0);
-  }
+  for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++)
+    if (oai_emulation.info.oai_ifup[i] == 1) {
+      sprintf (interfaceName, "oai%d", i);
+      bringInterfaceUp (interfaceName, 0);
+    }
 }
 
-- 
GitLab