Commit 1f213b0b authored by nikaeinn's avatar nikaeinn
Browse files

* add options to enb configuration file for the enb agent

* add timer api for the periodic and oneshot operations
* create enb agent task
parent 48ddbc68
...@@ -94,9 +94,8 @@ int timer_handle_signal(siginfo_t *info) ...@@ -94,9 +94,8 @@ int timer_handle_signal(siginfo_t *info)
timer_p = (struct timer_elm_s *)info->si_ptr; timer_p = (struct timer_elm_s *)info->si_ptr;
// LG: To many traces for msc timer: // LG: To many traces for msc timer:
// TMR_DEBUG("Timer with id 0x%lx has expired\n", (long)timer_p->timer); TMR_DEBUG("Timer with id 0x%lx has expired\n", (long)timer_p->timer);
printf("Timer with id 0x%lx has expired\n", (long)timer_p->timer);
#if defined(ENABLE_ITTI)
task_id = timer_p->task_id; task_id = timer_p->task_id;
instance = timer_p->instance; instance = timer_p->instance;
...@@ -106,7 +105,6 @@ int timer_handle_signal(siginfo_t *info) ...@@ -106,7 +105,6 @@ int timer_handle_signal(siginfo_t *info)
timer_expired_p->timer_id = (long)timer_p->timer; timer_expired_p->timer_id = (long)timer_p->timer;
timer_expired_p->arg = timer_p->timer_arg; timer_expired_p->arg = timer_p->timer_arg;
#endif
/* Timer is a one shot timer, remove it */ /* Timer is a one shot timer, remove it */
if (timer_p->type == TIMER_ONE_SHOT) { if (timer_p->type == TIMER_ONE_SHOT) {
...@@ -123,13 +121,16 @@ int timer_handle_signal(siginfo_t *info) ...@@ -123,13 +121,16 @@ int timer_handle_signal(siginfo_t *info)
TMR_DEBUG("Failed to delete timer 0x%lx\n", (long)timer_p->timer); TMR_DEBUG("Failed to delete timer 0x%lx\n", (long)timer_p->timer);
} }
} }
#ifdefined ENABLE_ITTI
/* Notify task of timer expiry */ /* Notify task of timer expiry */
if (itti_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); TMR_DEBUG("Failed to send msg TIMER_HAS_EXPIRED to task %u\n", task_id);
free(message_p); free(message_p);
return -1; return -1;
} }
#if defined(ENB_AGENT_SB_IF)
#endif #endif
return 0; return 0;
...@@ -209,6 +210,11 @@ int timer_setup( ...@@ -209,6 +210,11 @@ int timer_setup(
type == TIMER_PERIODIC ? "periodic" : "single shot", type == TIMER_PERIODIC ? "periodic" : "single shot",
*timer_id, interval_sec, interval_us); *timer_id, interval_sec, interval_us);
printf("Requesting new %s timer with id 0x%lx that expires within "
"%d sec and %d usec\n",
type == TIMER_PERIODIC ? "periodic" : "single shot",
*timer_id, interval_sec, interval_us);
timer_p->timer = timer; timer_p->timer = timer;
/* Lock the queue and insert the timer at the tail */ /* Lock the queue and insert the timer at the tail */
......
...@@ -63,6 +63,8 @@ TASK_DEF(TASK_X2AP, TASK_PRIORITY_MED, 200) ...@@ -63,6 +63,8 @@ TASK_DEF(TASK_X2AP, TASK_PRIORITY_MED, 200)
TASK_DEF(TASK_SCTP, TASK_PRIORITY_MED, 200) TASK_DEF(TASK_SCTP, TASK_PRIORITY_MED, 200)
/// eNB APP task /// eNB APP task
TASK_DEF(TASK_ENB_APP, TASK_PRIORITY_MED, 200) TASK_DEF(TASK_ENB_APP, TASK_PRIORITY_MED, 200)
/// eNB Agent task
TASK_DEF(TASK_ENB_AGENT, TASK_PRIORITY_MED, 200)
// UE tasks and sub-tasks: // UE tasks and sub-tasks:
//// Layer 2 and Layer 1 sub-tasks //// Layer 2 and Layer 1 sub-tasks
......
...@@ -37,7 +37,7 @@ enum progran_err { ...@@ -37,7 +37,7 @@ enum progran_err {
MSG_NOT_VALIDATED = -8; MSG_NOT_VALIDATED = -8;
MSG_OUT_DATED = -9; MSG_OUT_DATED = -9;
// other erros // other erros
UNEXPECTED = -100; UNEXPECTED = -100;
} }
......
...@@ -27,43 +27,82 @@ ...@@ -27,43 +27,82 @@
*******************************************************************************/ *******************************************************************************/
/*! \file /*! \file enb_agent.h
* \brief * \brief top level enb agent receive thread and itti task
* \author * \author Navid Nikaein and Xenofon Foukas
* \date 2016 * \date 2016
* \version 0.1 * \version 0.1
*/ */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include "enb_agent_common.h" #include "enb_agent_common.h"
#include "link_manager.h"
#include "log.h" #include "log.h"
#include "enb_agent.h" #include "enb_agent.h"
typedef uint8_t xid_t; #include "assertions.h"
enb_agent_instance_t enb_agent[NUM_MAX_ENB_AGENT];
msg_context_t shared_ctxt[NUM_MAX_ENB_AGENT];
/* this could also go into enb_agent struct*/
enb_agent_info_t enb_agent_info;
// tx and rx shared context char in_ip[40];
typedef struct { static uint16_t in_port;
message_queue_t *tx_mq;
message_queue_t *rx_mq;
xid_t tx_xid;
xid_t rx_xid;
} msg_context_t;
msg_context_t shared_ctxt;
void *send_thread(void *arg); //void *send_thread(void *args);
void *receive_thread(void *arg); void *receive_thread(void *args);
pthread_t new_thread(void *(*f)(void *), void *b); pthread_t new_thread(void *(*f)(void *), void *b);
err_code_t enb_agent_timeout(void* args);
/*
* enb agent task mainly wakes up the tx thread for periodic and oneshot messages to the controller
* and can interact with other itti tasks
*/
void *enb_agent_task(void *args){
MessageDef *msg_p = NULL;
const char *msg_name = NULL;
instance_t instance;
int result;
itti_mark_task_ready(TASK_ENB_AGENT);
do {
// Wait for a message
itti_receive_msg (TASK_ENB_AGENT, &msg_p);
DevAssert(msg_p != NULL);
msg_name = ITTI_MSG_NAME (msg_p);
instance = ITTI_MSG_INSTANCE (msg_p);
switch (ITTI_MSG_ID(msg_p)) {
case TERMINATE_MESSAGE:
itti_exit_task ();
break;
case MESSAGE_TEST:
LOG_I(ENB_AGENT, "Received %s\n", ITTI_MSG_NAME(msg_p));
break;
case TIMER_HAS_EXPIRED:
enb_agent_process_timeout(msg_p->ittiMsg.timer_has_expired.timer_id, &msg_p->ittiMsg.timer_has_expired.arg);
break;
default:
LOG_E(ENB_AGENT, "Received unexpected message %s\n", msg_name);
break;
}
result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
} while (1);
void *send_thread(void *arg) { return NULL;
}
/*
void *send_thread(void *args) {
msg_context_t *d = arg; msg_context_t *d = args;
void *data; void *data;
int size; int size;
int priority; int priority;
...@@ -81,10 +120,10 @@ error: ...@@ -81,10 +120,10 @@ error:
printf("receive_thread: there was an error\n"); printf("receive_thread: there was an error\n");
return NULL; return NULL;
} }
*/
void *receive_thread(void *args) {
void *receive_thread(void *arg) { msg_context_t *d = args;
msg_context_t *d = arg;
void *data; void *data;
int size; int size;
int priority; int priority;
...@@ -97,10 +136,10 @@ void *receive_thread(void *arg) { ...@@ -97,10 +136,10 @@ void *receive_thread(void *arg) {
err_code = PROTOCOL__PROGRAN_ERR__MSG_DEQUEUING; err_code = PROTOCOL__PROGRAN_ERR__MSG_DEQUEUING;
goto error; goto error;
} }
LOG_D(ENB_APP,"received message with size %d\n", size); LOG_D(ENB_AGENT,"received message with size %d\n", size);
msg=enb_agent_handle_message(d->rx_xid, data, size); msg=enb_agent_handle_message(d->mod_id, d->rx_xid, data, size);
free(data); free(data);
...@@ -115,7 +154,7 @@ void *receive_thread(void *arg) { ...@@ -115,7 +154,7 @@ void *receive_thread(void *arg) {
err_code = PROTOCOL__PROGRAN_ERR__MSG_ENQUEUING; err_code = PROTOCOL__PROGRAN_ERR__MSG_ENQUEUING;
goto error; goto error;
} }
LOG_D(ENB_APP,"sent message with size %d\n", size); LOG_D(ENB_AGENT,"sent message with size %d\n", size);
} }
} }
...@@ -123,7 +162,7 @@ void *receive_thread(void *arg) { ...@@ -123,7 +162,7 @@ void *receive_thread(void *arg) {
return NULL; return NULL;
error: error:
printf("receive_thread: error %d occured\n",err_code); LOG_E(ENB_AGENT,"receive_thread: error %d occured\n",err_code);
return NULL; return NULL;
} }
...@@ -153,50 +192,146 @@ pthread_t new_thread(void *(*f)(void *), void *b) { ...@@ -153,50 +192,146 @@ pthread_t new_thread(void *(*f)(void *), void *b) {
return t; return t;
} }
int enb_agent_start(){ int enb_agent_start(mid_t mod_id, const Enb_properties_array_t* enb_properties){
socket_link_t *link;
message_queue_t *send_queue;
message_queue_t *receive_queue;
link_manager_t *manager;
LOG_I(ENB_APP,"starting enb agent client\n"); //
set_enb_vars(mod_id, RAN_LTE_OAI);
enb_agent[mod_id].mod_id = mod_id;
enb_agent_info.nb_modules+=1;
/*
* check the configuration
*/
if (enb_properties->properties[mod_id]->enb_agent_ipv4_address != NULL) {
strncpy(in_ip, enb_properties->properties[mod_id]->enb_agent_ipv4_address, sizeof(in_ip) );
in_ip[sizeof(in_ip) - 1] = 0; // terminate string
} else {
strcpy(in_ip, DEFAULT_ENB_AGENT_IPv4_ADDRESS );
}
if (enb_properties->properties[mod_id]->enb_agent_port != 0 ) {
in_port = enb_properties->properties[mod_id]->enb_agent_port;
} else {
in_port = DEFAULT_ENB_AGENT_PORT ;
}
LOG_I(ENB_AGENT,"starting enb agent client for module id %d on ipv4 %s, port %d\n",
enb_agent[mod_id].mod_id,
in_ip,
in_port);
//#define TEST_TIMER 0
#if !defined TEST_TIMER
/*
* create a socket
*/
enb_agent[mod_id].link = new_link_client(in_ip, in_port);
if (enb_agent[mod_id].link == NULL) goto error;
LOG_I(ENB_AGENT,"starting enb agent client for module id %d on ipv4 %s, port %d\n",
enb_agent[mod_id].mod_id,
in_ip,
in_port);
/*
* create a message queue
*/
enb_agent[mod_id].send_queue = new_message_queue();
if (enb_agent[mod_id].send_queue == NULL) goto error;
enb_agent[mod_id].receive_queue = new_message_queue();
if (enb_agent[mod_id].receive_queue == NULL) goto error;
/*
* create a link manager
*/
enb_agent[mod_id].manager = create_link_manager(enb_agent[mod_id].send_queue, enb_agent[mod_id].receive_queue, enb_agent[mod_id].link);
if (enb_agent[mod_id].manager == NULL) goto error;
link = new_link_client("127.0.0.1", 2210); memset(&shared_ctxt, 0, sizeof(msg_context_t));
if (link == NULL) goto error;
shared_ctxt[mod_id].mod_id = mod_id;
shared_ctxt[mod_id].tx_mq = enb_agent[mod_id].send_queue;
shared_ctxt[mod_id].rx_mq = enb_agent[mod_id].receive_queue;
send_queue = new_message_queue(); /*
if (send_queue == NULL) goto error; * start the enb agent rx thread
receive_queue = new_message_queue(); */
if (receive_queue == NULL) goto error;
new_thread(receive_thread, &shared_ctxt[mod_id]);
manager = create_link_manager(send_queue, receive_queue, link); #endif
if (manager == NULL) goto error;
/*
* initilize a timer
*/
enb_agent_init_timer();
/*
* start the enb agent task for tx and interaction with the underlying network function
*/
if (itti_create_task (TASK_ENB_AGENT, enb_agent_task, NULL) < 0) {
LOG_E(ENB_AGENT, "Create task for eNB Agent failed\n");
return -1;
}
memset(&shared_ctxt, 0, sizeof(msg_context_t)); #ifdef TEST_TIMER
long timer_id=0;
shared_ctxt.tx_mq = send_queue; enb_agent_timer_args_t timer_args;
shared_ctxt.rx_mq = receive_queue; memset (&timer_args, 0, sizeof(enb_agent_timer_args_t));
timer_args.mod_id = mod_id;
timer_args.cc_actions= ENB_AGENT_ACTION_APPLY;
timer_args.cc_report_flags = PROTOCOL__PRP_CELL_STATS_TYPE__PRCST_NOISE_INTERFERENCE;
timer_args.ue_actions = ENB_AGENT_ACTION_SEND;
timer_args.ue_report_flags = PROTOCOL__PRP_UE_STATS_TYPE__PRUST_BSR | PROTOCOL__PRP_UE_STATS_TYPE__PRUST_DL_CQI;
enb_agent_create_timer(1, 0, ENB_AGENT_DEFAULT, mod_id, ENB_AGENT_TIMER_TYPE_PERIODIC, enb_agent_timeout,(void*)&timer_args, &timer_id);
#endif
new_thread(receive_thread, &shared_ctxt);
// new_thread(send_thread, &shared_ctxt); // new_thread(send_thread, &shared_ctxt);
// while (1) pause(); //while (1) pause();
printf("client ends\n"); LOG_I(ENB_AGENT,"client ends\n");
return 0; return 0;
error: error:
printf("there was an error\n"); LOG_I(ENB_AGENT,"there was an error\n");
return 1; return 1;
} }
int enb_agent_stop(){ int enb_agent_stop(mid_t mod_id){
int i=0;
enb_agent_destroy_timers();
for ( i =0; i < enb_agent_info.nb_modules; i++) {
destroy_link_manager(enb_agent[i].manager);
destroy_message_queue(enb_agent[i].send_queue);
destroy_message_queue(enb_agent[i].receive_queue);
close_link(enb_agent[i].link);
}
}
err_code_t enb_agent_timeout(void* args){
enb_agent_timer_args_t *timer_args = (enb_agent_timer_args_t *) args;
LOG_I(ENB_AGENT, "enb_agent %d timeout\n", timer_args->mod_id);
LOG_I(ENB_AGENT, "eNB action %d ENB flags %d \n", timer_args->cc_actions,timer_args->cc_report_flags);
LOG_I(ENB_AGENT, "UE action %d UE flags %d \n", timer_args->ue_actions,timer_args->ue_report_flags);
return 0;
} }
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
*******************************************************************************/ *******************************************************************************/
/*! \file /*! \file enb_agent.h
* \brief * \brief top level enb agent
* \author * \author Navid Nikaein and Xenofon Foukas
* \date 2016 * \date 2016
* \version 0.1 * \version 0.1
*/ */
...@@ -38,10 +38,13 @@ ...@@ -38,10 +38,13 @@
#ifndef ENB_AGENT_H_ #ifndef ENB_AGENT_H_
#define ENB_AGENT_H_ #define ENB_AGENT_H_
#include "enb_config.h" // for enb properties
#include "enb_agent_common.h"
int enb_agent_start(); int enb_agent_start(mid_t mod_id, const Enb_properties_array_t* enb_properties);
int enb_agent_stop(); int enb_agent_stop(mid_t mod_id);
void *enb_agent_task(void *args);
#endif #endif
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
*******************************************************************************/ *******************************************************************************/
/*! \file /*! \file enb_agent_common.c
* \brief * \brief common primitives for all agents
* \author * \author Navid Nikaein and Xenofon Foukas
* \date 2016 * \date 2016
* \version 0.1 * \version 0.1
*/ */
...@@ -39,6 +39,12 @@ ...@@ -39,6 +39,12 @@
#include "log.h" #include "log.h"
void * enb[NUM_MAX_ENB_AGENT];
void * enb_ue[NUM_MAX_ENB_AGENT];
/*
* message primitives
*/
int enb_agent_serialize_message(Protocol__ProgranMessage *msg, void **buf, int *size) { int enb_agent_serialize_message(Protocol__ProgranMessage *msg, void **buf, int *size) {
*size = protocol__progran_message__get_packed_size(msg); *size = protocol__progran_message__get_packed_size(msg);
...@@ -52,7 +58,7 @@ int enb_agent_serialize_message(Protocol__ProgranMessage *msg, void **buf, int * ...@@ -52,7 +58,7 @@ int enb_agent_serialize_message(Protocol__ProgranMessage *msg, void **buf, int *
return 0; return 0;
error: error:
LOG_E(ENB_APP, "an error occured\n"); // change the com LOG_E(ENB_AGENT, "an error occured\n"); // change the com
return -1; return -1;
} }
...@@ -74,9 +80,7 @@ int enb_agent_deserialize_message(void *data, int size, Protocol__ProgranMessage ...@@ -74,9 +80,7 @@ int enb_agent_deserialize_message(void *data, int size, Protocol__ProgranMessage
int prp_create_header(xid_t xid, Protocol__PrpType type, Protocol__PrpHeader **header) {
int prp_create_header(uint32_t xid, Protocol__PrpType type, Protocol__PrpHeader **header) {
*header = malloc(sizeof(Protocol__PrpHeader)); *header = malloc(sizeof(Protocol__PrpHeader));
if(*header == NULL) if(*header == NULL)
...@@ -98,7 +102,7 @@ int prp_create_header(uint32_t xid, Protocol__PrpType type, Protocol__PrpHeader ...@@ -98,7 +102,7 @@ int prp_create_header(uint32_t xid, Protocol__PrpType type, Protocol__PrpHeader
} }
int enb_agent_hello(uint32_t xid, const void *params, Protocol__ProgranMessage **msg) { int enb_agent_hello(mid_t mod_id, xid_t xid, const void *params, Protocol__ProgranMessage **msg) {
Protocol__PrpHeader *header; Protocol__PrpHeader *header;
if (prp_create_header(xid, PROTOCOL__PRP_TYPE__PRPT_HELLO, &header) != 0) if (prp_create_header(xid, PROTOCOL__PRP_TYPE__PRPT_HELLO, &header) != 0)
...@@ -150,7 +154,7 @@ int enb_agent_destroy_hello(Protocol__ProgranMessage *msg) { ...@@ -150,7 +154,7 @@ int enb_agent_destroy_hello(Protocol__ProgranMessage *msg) {
} }
int enb_agent_echo_request(uint32_t xid, const void* params, Protocol__ProgranMessage **msg) { int enb_agent_echo_request(mid_t mod_id, xid_t xid, const void* params, Protocol__ProgranMessage **msg) {
Protocol__PrpHeader *header; Protocol__PrpHeader *header;
if (prp_create_header(xid, PROTOCOL__PRP_TYPE__PRPT_ECHO_REQUEST, &header) != 0) if (prp_create_header(xid, PROTOCOL__PRP_TYPE__PRPT_ECHO_REQUEST, &header) != 0)
goto error; goto error;
...@@ -199,7 +203,7 @@ int enb_agent_destroy_echo_request(Protocol__ProgranMessage *msg) { ...@@ -199,7 +203,7 @@ int enb_agent_destroy_echo_request(Protocol__ProgranMessage *msg) {
int enb_agent_echo_reply(uint32_t xid, const void *params, Protocol__ProgranMessage **msg) { int enb_agent_echo_reply(mid_t mod_id, xid_t xid, const void *params, Protocol__ProgranMessage **msg) {
Protocol__PrpHeader *header; Protocol__PrpHeader *header;
if (prp_create_header(xid, PROTOCOL__PRP_TYPE__PRPT_ECHO_REPLY, &header) != 0) if (prp_create_header(xid, PROTOCOL__PRP_TYPE__PRPT_ECHO_REPLY, &header) != 0)
goto error; goto error;
...@@ -246,3 +250,263 @@ int enb_agent_destroy_echo_reply(Protocol__ProgranMessage *msg) { ...@@ -246,3 +250,263 @@ int enb_agent_destroy_echo_reply(Protocol__ProgranMessage *msg) {
LOG_E(MAC, "%s: an error occured\n", __FUNCTION__); LOG_E(MAC, "%s: an error occured\n", __FUNCTION__);
return -1; return -1;
} }
/*
* get generic info from RAN
*/