Commit c4e3c774 authored by nikaeinn's avatar nikaeinn

*updates for OAI E-UTRAN and LTEBox EPC IOT



git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5209 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent ee9a31b9
...@@ -42,8 +42,9 @@ Address : EURECOM, ...@@ -42,8 +42,9 @@ Address : EURECOM,
/* When gtpv1u is compiled for eNB use MACRO from UTILS/log.h, /* When gtpv1u is compiled for eNB use MACRO from UTILS/log.h,
* otherwise use standard fprintf as logger. * otherwise use standard fprintf as logger.
*/ */
#if defined(ENB_MODE) //#if defined(ENB_MODE)
# define GTPU_DEBUG(x, args...) LOG_D(GTPU, x, ##args) #if 0
# define GTPU_DEBUG(x, args...) LOG_I(GTPU, x, ##args)
# define GTPU_INFO(x, args...) LOG_I(GTPU, x, ##args) # define GTPU_INFO(x, args...) LOG_I(GTPU, x, ##args)
# define GTPU_WARN(x, args...) LOG_W(GTPU, x, ##args) # define GTPU_WARN(x, args...) LOG_W(GTPU, x, ##args)
# define GTPU_ERROR(x, args...) LOG_E(GTPU, x, ##args) # define GTPU_ERROR(x, args...) LOG_E(GTPU, x, ##args)
......
...@@ -492,6 +492,7 @@ gtpv1u_new_data_req( ...@@ -492,6 +492,7 @@ gtpv1u_new_data_req(
stack_req.apiInfo.sendtoInfo.teid = bearer_p->teid_sgw; stack_req.apiInfo.sendtoInfo.teid = bearer_p->teid_sgw;
stack_req.apiInfo.sendtoInfo.ipAddr = bearer_p->sgw_ip_addr; stack_req.apiInfo.sendtoInfo.ipAddr = bearer_p->sgw_ip_addr;
LOG_W(GTPU, "TX TO TEID %u addr 0x%x\n",bearer_p->teid_sgw, bearer_p->sgw_ip_addr);
rc = nwGtpv1uGpduMsgNew(gtpv1u_data_p->gtpv1u_stack, rc = nwGtpv1uGpduMsgNew(gtpv1u_data_p->gtpv1u_stack,
bearer_p->teid_sgw, bearer_p->teid_sgw,
NW_FALSE, NW_FALSE,
...@@ -533,6 +534,7 @@ static int gtpv1u_create_s1u_tunnel(gtpv1u_enb_create_tunnel_req_t *create_tunne ...@@ -533,6 +534,7 @@ static int gtpv1u_create_s1u_tunnel(gtpv1u_enb_create_tunnel_req_t *create_tunne
hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS; hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS;
int i; int i;
ebi_t eps_bearer_id = 0; ebi_t eps_bearer_id = 0;
int ipv4_addr = 0;
message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_ENB_CREATE_TUNNEL_RESP); message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_ENB_CREATE_TUNNEL_RESP);
GTPV1U_ENB_CREATE_TUNNEL_RESP(message_p).ue_index = create_tunnel_req_pP->ue_index; GTPV1U_ENB_CREATE_TUNNEL_RESP(message_p).ue_index = create_tunnel_req_pP->ue_index;
...@@ -576,7 +578,8 @@ static int gtpv1u_create_s1u_tunnel(gtpv1u_enb_create_tunnel_req_t *create_tunne ...@@ -576,7 +578,8 @@ static int gtpv1u_create_s1u_tunnel(gtpv1u_enb_create_tunnel_req_t *create_tunne
} else if (hash_rc == HASH_TABLE_OK) { } else if (hash_rc == HASH_TABLE_OK) {
gtpv1u_ue_data_p->ue_id = create_tunnel_req_pP->ue_index; gtpv1u_ue_data_p->ue_id = create_tunnel_req_pP->ue_index;
gtpv1u_ue_data_p->instance_id = 0; // TO DO gtpv1u_ue_data_p->instance_id = 0; // TO DO
#warning "TO DO TO DO gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].sgw_ip_addr" ipv4_addr =
#warning "TO DO TO DO gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].sgw_ip_addr = (uint32_t)(create_tunnel_req_pP->sgw_addr[i].buffer;"
gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].state = BEARER_IN_CONFIG; gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].state = BEARER_IN_CONFIG;
gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].teid_eNB = s1u_teid; gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].teid_eNB = s1u_teid;
gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].teid_sgw = create_tunnel_req_pP->sgw_S1u_teid[i]; gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].teid_sgw = create_tunnel_req_pP->sgw_S1u_teid[i];
......
...@@ -406,9 +406,9 @@ extern int asn1_xer_print; ...@@ -406,9 +406,9 @@ extern int asn1_xer_print;
# include "s1ap_eNB_default_values.h" # include "s1ap_eNB_default_values.h"
# define S1AP_ERROR(x, args...) LOG_E(S1AP, x, ##args) # define S1AP_ERROR(x, args...) LOG_E(S1AP, x, ##args)
# define S1AP_WARN(x, args...) LOG_W(S1AP, x, ##args) # define S1AP_WARN(x, args...) LOG_W(S1AP, x, ##args)
# define S1AP_TRAF(x, args...) LOG_T(S1AP, x, ##args) # define S1AP_TRAF(x, args...) LOG_I(S1AP, x, ##args)
# define S1AP_INFO(x, args...) LOG_I(S1AP, x, ##args) # define S1AP_INFO(x, args...) LOG_I(S1AP, x, ##args)
# define S1AP_DEBUG(x, args...) LOG_D(S1AP, x, ##args) # define S1AP_DEBUG(x, args...) LOG_I(S1AP, x, ##args)
#else #else
# include "mme_default_values.h" # include "mme_default_values.h"
# define S1AP_ERROR(x, args...) do { fprintf(stdout, "[S1AP][E]"x, ##args); } while(0) # define S1AP_ERROR(x, args...) do { fprintf(stdout, "[S1AP][E]"x, ##args); } while(0)
......
...@@ -82,8 +82,8 @@ static int s1ap_eNB_decode_initiating_message(s1ap_message *message, ...@@ -82,8 +82,8 @@ static int s1ap_eNB_decode_initiating_message(s1ap_message *message,
default: default:
S1AP_ERROR("Unknown procedure ID (%d) for initiating message\n", S1AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
(int)initiating_p->procedureCode); (int)initiating_p->procedureCode);
AssertFatal( 0 , "Unknown procedure ID (%d) for initiating message\n", //AssertFatal( 0 , "Unknown procedure ID (%d) for initiating message\n",
(int)initiating_p->procedureCode); // (int)initiating_p->procedureCode);
return -1; return -1;
} }
......
...@@ -402,14 +402,14 @@ void s1ap_eNB_nas_non_delivery_ind(instance_t instance, ...@@ -402,14 +402,14 @@ void s1ap_eNB_nas_non_delivery_ind(instance_t instance,
int s1ap_eNB_initial_ctxt_resp( int s1ap_eNB_initial_ctxt_resp(
instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p) instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p)
{ {
s1ap_eNB_instance_t *s1ap_eNB_instance_p; s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL;
struct s1ap_eNB_ue_context_s *ue_context_p; struct s1ap_eNB_ue_context_s *ue_context_p = NULL;
S1ap_InitialContextSetupResponseIEs_t *initial_ies_p; S1ap_InitialContextSetupResponseIEs_t *initial_ies_p = NULL;
s1ap_message message; s1ap_message message;
uint8_t *buffer; uint8_t *buffer = NULL;
uint32_t length; uint32_t length;
int ret = -1; int ret = -1;
int i; int i;
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
# include "UTIL/LOG/log.h" # include "UTIL/LOG/log.h"
# define SCTP_ERROR(x, args...) LOG_E(SCTP, x, ##args) # define SCTP_ERROR(x, args...) LOG_E(SCTP, x, ##args)
# define SCTP_WARN(x, args...) LOG_W(SCTP, x, ##args) # define SCTP_WARN(x, args...) LOG_W(SCTP, x, ##args)
# define SCTP_DEBUG(x, args...) LOG_D(SCTP, x, ##args) # define SCTP_DEBUG(x, args...) LOG_I(SCTP, x, ##args)
#else #else
# define SCTP_ERROR(x, args...) do { fprintf(stderr, "[SCTP][E]"x, ##args); } while(0) # define SCTP_ERROR(x, args...) do { fprintf(stderr, "[SCTP][E]"x, ##args); } while(0)
# define SCTP_DEBUG(x, args...) do { fprintf(stdout, "[SCTP][D]"x, ##args); } while(0) # define SCTP_DEBUG(x, args...) do { fprintf(stdout, "[SCTP][D]"x, ##args); } while(0)
......
...@@ -549,17 +549,17 @@ inline void sctp_eNB_read_from_socket(struct sctp_cnx_list_elm_s *sctp_cnx) ...@@ -549,17 +549,17 @@ inline void sctp_eNB_read_from_socket(struct sctp_cnx_list_elm_s *sctp_cnx)
} else { } else {
sctp_cnx->nb_messages++; sctp_cnx->nb_messages++;
if (sinfo.sinfo_ppid != sctp_cnx->ppid) { if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) {
/* Mismatch in Payload Protocol Identifier, /* Mismatch in Payload Protocol Identifier,
* may be we received unsollicited traffic from stack other than S1AP. * may be we received unsollicited traffic from stack other than S1AP.
*/ */
SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n", SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n",
sinfo.sinfo_ppid, sctp_cnx->ppid); ntohl(sinfo.sinfo_ppid), sctp_cnx->ppid);
} }
SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n", SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n",
sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port), sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port),
sinfo.sinfo_stream, sinfo.sinfo_ppid); sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid));
sctp_itti_send_new_message_ind(sctp_cnx->task_id, sctp_itti_send_new_message_ind(sctp_cnx->task_id,
sinfo.sinfo_assoc_id, sinfo.sinfo_assoc_id,
......
/******************************************************************************* /*******************************************************************************
Eurecom OpenAirInterface core network
Eurecom OpenAirInterface Copyright(c) 1999 - 2014 Eurecom
Copyright(c) 1999 - 2014 Eurecom
This program is free software; you can redistribute it and/or modify it
This program is free software; you can redistribute it and/or modify it under the terms and conditions of the GNU General Public License,
under the terms and conditions of the GNU General Public License, version 2, as published by the Free Software Foundation.
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
This program is distributed in the hope it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
more details.
You should have received a copy of the GNU General Public License along with
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.,
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
The full GNU General Public License is included in this distribution in the file called "COPYING".
the file called "COPYING".
Contact Information
Contact Information Openair Admin: openair_admin@eurecom.fr
Openair Admin: openair_admin@eurecom.fr Openair Tech : openair_tech@eurecom.fr
Openair Tech : openair_tech@eurecom.fr Forums : http://forums.eurecom.fsr/openairinterface
Forums : http://forums.eurecom.fr/openairinterface Address : EURECOM,
Address : EURECOM, Campus SophiaTech, 450 Route des Chappes Campus SophiaTech,
06410 Biot FRANCE 450 Route des Chappes,
CS 50193
06904 Biot Sophia Antipolis cedex,
FRANCE
*******************************************************************************/ *******************************************************************************/
/*! \file udp_eNB_task.c
* \brief
* \author Sebastien ROUX, Lionel Gauthier
* \company Eurecom
* \email: lionel.gauthier@eurecom.fr
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -53,7 +61,6 @@ ...@@ -53,7 +61,6 @@
(uint8_t)(((aDDRESS) & 0x00ff0000) >> 16), \ (uint8_t)(((aDDRESS) & 0x00ff0000) >> 16), \
(uint8_t)(((aDDRESS) & 0xff000000) >> 24) (uint8_t)(((aDDRESS) & 0xff000000) >> 24)
static void *udp_receiver_thread(void *arg_p);
struct udp_socket_desc_s { struct udp_socket_desc_s {
int sd; /* Socket descriptor to use */ int sd; /* Socket descriptor to use */
...@@ -72,10 +79,38 @@ static STAILQ_HEAD(udp_socket_list_s, udp_socket_desc_s) udp_socket_list; ...@@ -72,10 +79,38 @@ static STAILQ_HEAD(udp_socket_list_s, udp_socket_desc_s) udp_socket_list;
static pthread_mutex_t udp_socket_list_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t udp_socket_list_mutex = PTHREAD_MUTEX_INITIALIZER;
static
struct udp_socket_desc_s *
udp_eNB_get_socket_desc(task_id_t task_id);
void udp_eNB_process_file_descriptors(
struct epoll_event *events,
int nb_events);
static
int
udp_eNB_create_socket(
int port,
char *ip_addr,
task_id_t task_id);
int
udp_eNB_send_to(
int sd,
uint16_t port,
uint32_t address,
const uint8_t *buffer,
uint32_t length);
void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP);
void *udp_eNB_task(void *args_p);
int udp_enb_init(const Enb_properties_t *enb_config_p);
/* @brief Retrieve the descriptor associated with the task_id /* @brief Retrieve the descriptor associated with the task_id
*/ */
static static
struct udp_socket_desc_s *udp_get_socket_desc(task_id_t task_id) struct udp_socket_desc_s *udp_eNB_get_socket_desc(task_id_t task_id)
{ {
struct udp_socket_desc_s *udp_sock_p = NULL; struct udp_socket_desc_s *udp_sock_p = NULL;
...@@ -90,11 +125,31 @@ struct udp_socket_desc_s *udp_get_socket_desc(task_id_t task_id) ...@@ -90,11 +125,31 @@ struct udp_socket_desc_s *udp_get_socket_desc(task_id_t task_id)
return udp_sock_p; return udp_sock_p;
} }
void udp_eNB_process_file_descriptors(struct epoll_event *events, int nb_events)
{
int i;
struct udp_socket_desc_s *udp_sock_p = NULL;
if (events == NULL) {
return;
}
for (i = 0; i < nb_events; i++) {
STAILQ_FOREACH(udp_sock_p, &udp_socket_list, entries) {
if (udp_sock_p->sd == events[i].data.fd) {
LOG_D(UDP_, "Found matching task desc\n");
udp_eNB_receiver(udp_sock_p);
break;
}
}
}
}
static static
int udp_create_socket(int port, char *ip_addr, task_id_t task_id) int udp_eNB_create_socket(int port, char *ip_addr, task_id_t task_id)
{ {
struct udp_socket_desc_s *thread_arg; struct udp_socket_desc_s *udp_socket_desc_p = NULL;
int sd, rc; int sd, rc;
struct sockaddr_in sin; struct sockaddr_in sin;
...@@ -118,53 +173,83 @@ int udp_create_socket(int port, char *ip_addr, task_id_t task_id) ...@@ -118,53 +173,83 @@ int udp_create_socket(int port, char *ip_addr, task_id_t task_id)
} }
/* Create a new descriptor for this connection */ /* Create a new descriptor for this connection */
thread_arg = calloc(1, sizeof(struct udp_socket_desc_s)); udp_socket_desc_p = calloc(1, sizeof(struct udp_socket_desc_s));
DevAssert(thread_arg != NULL); DevAssert(udp_socket_desc_p != NULL);
thread_arg->sd = sd; udp_socket_desc_p->sd = sd;
thread_arg->local_address = ip_addr; udp_socket_desc_p->local_address = ip_addr;
thread_arg->local_port = port; udp_socket_desc_p->local_port = port;
thread_arg->task_id = task_id; udp_socket_desc_p->task_id = task_id;
if (pthread_create(&thread_arg->listener_thread, NULL, LOG_I(UDP_, "Inserting new descriptor for task %d, sd %d\n", udp_socket_desc_p->task_id, udp_socket_desc_p->sd);
&udp_receiver_thread, (void *)thread_arg) < 0) { pthread_mutex_lock(&udp_socket_list_mutex);
LOG_E(UDP_, "Pthred_create failed (%s)\n", strerror(errno)); STAILQ_INSERT_TAIL(&udp_socket_list, udp_socket_desc_p, entries);
return -1; pthread_mutex_unlock(&udp_socket_list_mutex);
}
itti_subscribe_event_fd(TASK_UDP, sd);
LOG_I(UDP_, "Initializing UDP for local address %s with port %d: DONE\n", ip_addr, port); LOG_I(UDP_, "Initializing UDP for local address %s with port %d: DONE\n", ip_addr, port);
return sd; return sd;
} }
static void *udp_receiver_thread(void *arg_p) int
udp_eNB_send_to(
int sd,
uint16_t port,
uint32_t address,
const uint8_t *buffer,
uint32_t length)
{ {
struct udp_socket_desc_s *udp_sock_p; struct sockaddr_in to;
uint8_t buffer[2048]; socklen_t to_length;
udp_sock_p = (struct udp_socket_desc_s *)arg_p; if (sd <= 0 || ((buffer == NULL) && (length > 0))) {
LOG_D(UDP_, "Inserting new descriptor for task %d, sd %d\n", udp_sock_p->task_id, udp_sock_p->sd); LOG_E(UDP_, "udp_send_to: bad param\n");
pthread_mutex_lock(&udp_socket_list_mutex); return -1;
STAILQ_INSERT_TAIL(&udp_socket_list, udp_sock_p, entries); }
pthread_mutex_unlock(&udp_socket_list_mutex);
while (1) { memset(&to, 0, sizeof(struct sockaddr_in));
to_length = sizeof(to);
to.sin_family = AF_INET;
to.sin_port = htons(port);
to.sin_addr.s_addr = address;
if (sendto(sd, (void *)buffer, (size_t)length, 0, (struct sockaddr *)&to,
to_length) < 0) {
LOG_E(UDP_,
"[SD %d] Failed to send data to "IPV4_ADDR" on port %d, buffer size %u\n",
sd, IPV4_ADDR_FORMAT(address), port, length);
return -1;
}
LOG_I(UDP_, "[SD %d] Successfully sent to "IPV4_ADDR
" on port %d, buffer size %u, buffer address %x\n",
sd, IPV4_ADDR_FORMAT(address), port, length, buffer);
return 0;
}
void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP)
{
uint8_t l_buffer[2048];
int n; int n;
socklen_t from_len; socklen_t from_len;
struct sockaddr_in addr; struct sockaddr_in addr;
MessageDef *message_p = NULL;
udp_data_ind_t *udp_data_ind_p = NULL;
uint8_t *forwarded_buffer = NULL;
while (1) {
from_len = (socklen_t)sizeof(struct sockaddr_in); from_len = (socklen_t)sizeof(struct sockaddr_in);
if ((n = recvfrom(udp_sock_p->sd, buffer, sizeof(buffer), 0, LOG_I(UDP_, "before recvfrom sd %d\n", udp_sock_pP->sd);
if ((n = recvfrom(udp_sock_pP->sd, l_buffer, sizeof(l_buffer), 0,
(struct sockaddr *)&addr, &from_len)) < 0) { (struct sockaddr *)&addr, &from_len)) < 0) {
LOG_E(UDP_, "Recvfrom failed %s\n", strerror(errno)); LOG_E(UDP_, "Recvfrom failed %s\n", strerror(errno));
break; break;
} else { } else {
MessageDef *message_p = NULL;
udp_data_ind_t *udp_data_ind_p;
uint8_t *forwarded_buffer = NULL;
forwarded_buffer = calloc(n, sizeof(uint8_t)); forwarded_buffer = calloc(n, sizeof(uint8_t));
memcpy(forwarded_buffer, buffer, n); memcpy(forwarded_buffer, l_buffer, n);
message_p = itti_alloc_new_message(TASK_UDP, UDP_DATA_IND); message_p = itti_alloc_new_message(TASK_UDP, UDP_DATA_IND);
DevAssert(message_p != NULL); DevAssert(message_p != NULL);
udp_data_ind_p = &message_p->ittiMsg.udp_data_ind; udp_data_ind_p = &message_p->ittiMsg.udp_data_ind;
...@@ -173,42 +258,53 @@ static void *udp_receiver_thread(void *arg_p) ...@@ -173,42 +258,53 @@ static void *udp_receiver_thread(void *arg_p)
udp_data_ind_p->peer_port = htons(addr.sin_port); udp_data_ind_p->peer_port = htons(addr.sin_port);
udp_data_ind_p->peer_address = addr.sin_addr.s_addr; udp_data_ind_p->peer_address = addr.sin_addr.s_addr;
LOG_D(UDP_, "Msg of length %d received from %s:%u\n", LOG_I(UDP_, "Msg of length %d received from %s:%u\n",
n, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); n, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
if (itti_send_msg_to_task(udp_sock_p->task_id, INSTANCE_DEFAULT, message_p) < 0) { if (itti_send_msg_to_task(udp_sock_pP->task_id, INSTANCE_DEFAULT, message_p) < 0) {
LOG_D(UDP_, "Failed to send message %d to task %d\n", LOG_I(UDP_, "Failed to send message %d to task %d\n",
UDP_DATA_IND, udp_sock_p->task_id); UDP_DATA_IND,
udp_sock_pP->task_id);
break; break;
} }
} }
} }
close(udp_sock_p->sd); //close(udp_sock_p->sd);
udp_sock_p->sd = -1; //udp_sock_p->sd = -1;
pthread_mutex_lock(&udp_socket_list_mutex);
STAILQ_REMOVE(&udp_socket_list, udp_sock_p, udp_socket_desc_s, entries);
pthread_mutex_unlock(&udp_socket_list_mutex);
return NULL; //pthread_mutex_lock(&udp_socket_list_mutex);
//STAILQ_REMOVE(&udp_socket_list, udp_sock_p, udp_socket_desc_s, entries);
//pthread_mutex_unlock(&udp_socket_list_mutex);
} }
void *udp_eNB_task(void *args_p) void *udp_eNB_task(void *args_p)
{ {
int nb_events;
struct epoll_event *events;
MessageDef *received_message_p = NULL;
const char *msg_name = NULL;
instance_t instance = 0;
udp_enb_init(NULL);
itti_mark_task_ready(TASK_UDP); itti_mark_task_ready(TASK_UDP);
while(1) { while(1) {
MessageDef *received_message_p = NULL;
itti_receive_msg(TASK_UDP, &received_message_p); itti_receive_msg(TASK_UDP, &received_message_p);
DevAssert(received_message_p != NULL); if (received_message_p != NULL) {
msg_name = ITTI_MSG_NAME (received_message_p);
instance = ITTI_MSG_INSTANCE (received_message_p);
switch (ITTI_MSG_ID(received_message_p)) switch (ITTI_MSG_ID(received_message_p))
{ {
case UDP_INIT: { case UDP_INIT: {
udp_init_t *udp_init_p; udp_init_t *udp_init_p;
udp_init_p = &received_message_p->ittiMsg.udp_init; udp_init_p = &received_message_p->ittiMsg.udp_init;
udp_create_socket(udp_init_p->port, udp_init_p->address, udp_eNB_create_socket(
udp_init_p->port,
udp_init_p->address,
ITTI_MSG_ORIGIN_ID(received_message_p)); ITTI_MSG_ORIGIN_ID(received_message_p));
} break; } break;
case UDP_DATA_REQ: { case UDP_DATA_REQ: {
int udp_sd = -1; int udp_sd = -1;
ssize_t bytes_written; ssize_t bytes_written;
...@@ -226,11 +322,13 @@ void *udp_eNB_task(void *args_p) ...@@ -226,11 +322,13 @@ void *udp_eNB_task(void *args_p)
peer_addr.sin_addr.s_addr = udp_data_req_p->peer_address; peer_addr.sin_addr.s_addr = udp_data_req_p->peer_address;
pthread_mutex_lock(&udp_socket_list_mutex); pthread_mutex_lock(&udp_socket_list_mutex);
udp_sock_p = udp_get_socket_desc(ITTI_MSG_ORIGIN_ID(received_message_p)); udp_sock_p = udp_eNB_get_socket_desc(ITTI_MSG_ORIGIN_ID(received_message_p));
if (udp_sock_p == NULL) { if (udp_sock_p == NULL) {
LOG_E(UDP_, "Failed to retrieve the udp socket descriptor " LOG_E(UDP_,
"associated with task %d\n", ITTI_MSG_ORIGIN_ID(received_message_p)); "Failed to retrieve the udp socket descriptor "
"associated with task %d\n",
ITTI_MSG_ORIGIN_ID(received_message_p));
pthread_mutex_unlock(&udp_socket_list_mutex); pthread_mutex_unlock(&udp_socket_list_mutex);
if (udp_data_req_p->buffer) { if (udp_data_req_p->buffer) {
free(udp_data_req_p->buffer); free(udp_data_req_p->buffer);
...@@ -240,13 +338,17 @@ void *udp_eNB_task(void *args_p) ...@@ -240,13 +338,17 @@ void *udp_eNB_task(void *args_p)
udp_sd = udp_sock_p->sd; udp_sd = udp_sock_p->sd;
pthread_mutex_unlock(&udp_socket_list_mutex); pthread_mutex_unlock(&udp_socket_list_mutex);
LOG_D(UDP_, "[%d] Sending message of size %u to "IPV4_ADDR" and port %u\n", LOG_I(UDP_, "[%d] Sending message of size %u to "IPV4_ADDR" and port %u\n",
udp_sd, udp_data_req_p->buffer_length, udp_sd,
udp_data_req_p->buffer_length,
IPV4_ADDR_FORMAT(udp_data_req_p->peer_address), IPV4_ADDR_FORMAT(udp_data_req_p->peer_address),
udp_data_req_p->peer_port); udp_data_req_p->peer_port);
bytes_written = sendto(udp_sd, udp_data_req_p->buffer, bytes_written = sendto(
udp_data_req_p->buffer_length, 0, udp_sd,
udp_data_req_p->buffer,
udp_data_req_p->buffer_length,
0,
(struct sockaddr *)&peer_addr, (struct sockaddr *)&peer_addr,
sizeof(struct sockaddr_in)); sizeof(struct sockaddr_in));
...@@ -255,27 +357,37 @@ void *udp_eNB_task(void *args_p) ...@@ -255,27 +357,37 @@ void *udp_eNB_task(void *args_p)
"(%d:%s)\n", errno, strerror(errno)); "(%d:%s)\n", errno, strerror(errno));
} }
} break; } break;
case TERMINATE_MESSAGE: { case TERMINATE_MESSAGE: {
itti_exit_task(); itti_exit_task();
} break; } break;