gtp's net_sock_t to sock_id. GTP-U is failed

This commit is contained in:
Sukchan Lee 2017-11-23 00:19:28 +09:00
parent b1023fac1d
commit 2f49e6024d
23 changed files with 127 additions and 140 deletions

View File

@ -2,7 +2,6 @@
#define __CORE_ARCH_NETWORK_H__
#include "core_list.h"
#include "core_index.h"
#include "core_network.h"
#if HAVE_ARPA_INET_H
@ -23,7 +22,6 @@ extern "C" {
typedef struct _sock_t {
lnode_t node;
index_t index;
int family;

View File

@ -1,5 +1,6 @@
#define TRACE_MODULE _sock
#include "core_pool.h"
#include "core_debug.h"
#include "core_pkbuf.h"
@ -11,7 +12,7 @@ static int max_fd;
static list_t fd_list;
static fd_set read_fds;
index_declare(sock_pool, sock_t, MAX_SOCK_POOL_SIZE);
pool_declare(sock_pool, sock_t, MAX_SOCK_POOL_SIZE);
static status_t sononblock(int sd);
static status_t soblock(int sd);
@ -20,7 +21,7 @@ static void fd_dispatch(fd_set *fds);
status_t sock_init(void)
{
index_init(&sock_pool, MAX_SOCK_POOL_SIZE);
pool_init(&sock_pool, MAX_SOCK_POOL_SIZE);
max_fd = 0;
list_init(&fd_list);
@ -30,7 +31,7 @@ status_t sock_init(void)
}
status_t sock_final(void)
{
index_final(&sock_pool);
pool_final(&sock_pool);
return CORE_OK;
}
@ -39,7 +40,7 @@ status_t sock_create(sock_id *new)
{
sock_t *sock = NULL;
index_alloc(&sock_pool, &sock);
pool_alloc_node(&sock_pool, &sock);
d_assert(sock, return CORE_ENOMEM,);
memset(sock, 0, sizeof(sock_t));
@ -61,7 +62,7 @@ status_t sock_delete(sock_id id)
close(sock->fd);
sock->fd = -1;
index_free(&sock_pool, sock);
pool_free_node(&sock_pool, sock);
return CORE_OK;
}
@ -178,7 +179,7 @@ status_t sock_accept(sock_id *new, sock_id id)
return CORE_ERROR;
}
index_alloc(&sock_pool, &new_sock);
pool_alloc_node(&sock_pool, &new_sock);
d_assert(new_sock, return CORE_ENOMEM,);
memset(new_sock, 0, sizeof(sock_t));
@ -276,14 +277,11 @@ ssize_t core_recvfrom(sock_id id,
{
sock_t *sock = (sock_t *)id;
ssize_t size;
socklen_t addrlen;
socklen_t addrlen = sizeof(struct sockaddr_storage);
d_assert(id, return -1,);
d_assert(from, return -1,);
addrlen = sockaddr_len(from);
d_assert(addrlen, return -1,);
size = recvfrom(sock->fd, buf, len, flags, &from->sa, &addrlen);
if (size < 0)
{
@ -341,7 +339,7 @@ int sock_is_registered(sock_id id)
d_assert(id, return CORE_ERROR,);
for (iter = list_first(&fd_list); iter != NULL; iter = list_next(iter))
{
if (iter->index == sock->index)
if (iter == sock)
{
return 1;
}

View File

@ -1,41 +1,31 @@
#define TRACE_MODULE _gtp_path
#include "core_debug.h"
#include "core_pkbuf.h"
#include "core_net.h"
#include "types.h"
#include "gtp_message.h"
#include "gtp_path.h"
status_t gtp_listen(net_sock_t **sock,
net_sock_handler handler, c_uint32_t ipv4, c_uint16_t port, void *data)
status_t gtp_listen(sock_id *sock,
sock_handler handler, c_uint32_t ipv4, c_uint16_t port, void *data)
{
char buf[CORE_ADDRSTRLEN];
int rc;
status_t rv;
c_sockaddr_t addr;
memset(&addr, 0, sizeof(c_sockaddr_t));
addr.sin.sin_addr.s_addr = ipv4;
addr.c_sa_family = AF_INET;
addr.c_sa_port = htons(port);
rc = net_listen_ext(sock, SOCK_DGRAM, IPPROTO_UDP, 0, ipv4, port);
if (rc != 0)
{
d_error("Can't establish GTP[%s:%d] path(%d:%s)",
CORE_NTOP(&addr, buf), ntohs(addr.c_sa_port),
errno, strerror(errno));
return CORE_ERROR;
}
rc = net_register_sock(*sock, handler, data);
if (rc != 0)
{
d_error("Can't establish GTP path(%d:%s)",
errno, strerror(errno));
net_close(*sock);
return CORE_ERROR;
}
rv = udp_socket(sock, AF_INET);
d_assert(rv == CORE_OK, return CORE_ERROR,);
rv = sock_bind(*sock, &addr);
d_assert(rv == CORE_OK, return CORE_ERROR,);
rv = sock_register(*sock, handler, NULL);
d_assert(rv == CORE_OK, return CORE_ERROR,);
d_trace(1, "gtp_listen() %s:%d\n",
CORE_NTOP(&addr, buf), ntohs(addr.c_sa_port));
@ -43,21 +33,20 @@ status_t gtp_listen(net_sock_t **sock,
return CORE_OK;
}
status_t gtp_close(net_sock_t *sock)
status_t gtp_close(sock_id sock)
{
d_assert(sock, return CORE_ERROR, "Null param");
d_assert(sock, return CORE_ERROR,);
net_unregister_sock(sock);
net_close(sock);
sock_delete(sock);
return CORE_OK;
}
status_t gtp_recv(net_sock_t *sock, pkbuf_t **pkbuf)
status_t gtp_recv(sock_id sock, pkbuf_t **pkbuf)
{
int r;
ssize_t size;
d_assert(sock, return CORE_ERROR, "Null param");
d_assert(sock, return CORE_ERROR,);
*pkbuf = pkbuf_alloc(0, MAX_SDU_LEN);
if ((*pkbuf) == NULL)
@ -67,37 +56,37 @@ status_t gtp_recv(net_sock_t *sock, pkbuf_t **pkbuf)
d_fatal("Can't allocate pkbuf");
/* Read data from socket to exit from select */
net_read(sock, tmp_buf, MAX_SDU_LEN, 0);
core_recv(sock, tmp_buf, MAX_SDU_LEN, 0);
return CORE_ERROR;
}
r = net_read(sock, (*pkbuf)->payload, (*pkbuf)->len, 0);
if (r <= 0)
size = core_recv(sock, (*pkbuf)->payload, (*pkbuf)->len, 0);
if (size <= 0)
{
pkbuf_free((*pkbuf));
if (sock->sndrcv_errno != EAGAIN)
if (errno != EAGAIN)
{
d_warn("net_read failed(%d:%s)",
sock->sndrcv_errno, strerror(sock->sndrcv_errno));
d_warn("net_read failed(%d:%s)", errno, strerror(errno));
}
return CORE_ERROR;
}
else
{
(*pkbuf)->len = r;
(*pkbuf)->len = size;
return CORE_OK;;
}
}
status_t gtp_recvfrom(net_sock_t *sock, pkbuf_t **pkbuf, c_sockaddr_t *from)
status_t gtp_recvfrom(sock_id sock, pkbuf_t **pkbuf, c_sockaddr_t *from)
{
int r;
ssize_t size;
d_assert(sock, return CORE_ERROR, "Null param");
d_assert(sock, return CORE_ERROR,);
d_assert(from, return CORE_ERROR,);
*pkbuf = pkbuf_alloc(0, MAX_SDU_LEN);
if ((*pkbuf) == NULL)
@ -107,27 +96,26 @@ status_t gtp_recvfrom(net_sock_t *sock, pkbuf_t **pkbuf, c_sockaddr_t *from)
d_fatal("Can't allocate pkbuf");
/* Read data from socket to exit from select */
net_read(sock, tmp_buf, MAX_SDU_LEN, 0);
core_recv(sock, tmp_buf, MAX_SDU_LEN, 0);
return CORE_ERROR;
}
r = net_read(sock, (*pkbuf)->payload, (*pkbuf)->len, 0);
if (r <= 0)
size = core_recvfrom(sock, (*pkbuf)->payload, (*pkbuf)->len, 0, from);
if (size <= 0)
{
pkbuf_free((*pkbuf));
if (sock->sndrcv_errno != EAGAIN)
if (errno != EAGAIN)
{
d_warn("net_read failed(%d:%s)",
sock->sndrcv_errno, strerror(sock->sndrcv_errno));
d_warn("core_recv failed(%d:%s)", errno, strerror(errno));
}
return CORE_ERROR;
}
else
{
(*pkbuf)->len = r;
(*pkbuf)->len = size;
return CORE_OK;;
}
@ -137,22 +125,20 @@ status_t gtp_send(gtp_node_t *gnode, pkbuf_t *pkbuf)
{
char buf[CORE_ADDRSTRLEN];
ssize_t sent;
net_sock_t *sock = NULL;
sock_id sock = 0;
d_assert(gnode, return CORE_ERROR, "Null param");
d_assert(pkbuf, return CORE_ERROR, "Null param");
sock = gnode->sock;
d_assert(sock, return CORE_ERROR, "Null param");
sent = sendto(sock->sock_id, pkbuf->payload, pkbuf->len, 0,
&gnode->addr.sa, sizeof(gnode->addr.sin));
sent = core_sendto(sock, pkbuf->payload, pkbuf->len, 0, &gnode->addr);
d_trace(50, "Sent %d->%d bytes to [%s:%d]\n", pkbuf->len, sent,
CORE_NTOP(&gnode->addr, buf), ntohs(gnode->addr.c_sa_port));
d_trace_hex(50, pkbuf->payload, pkbuf->len);
if (sent < 0 || sent != pkbuf->len)
{
d_error("net_send error (%d:%s)",
sock->sndrcv_errno, strerror(sock->sndrcv_errno));
d_error("core_sendto failed(%d:%s)", errno, strerror(errno));
return CORE_ERROR;
}

View File

@ -2,7 +2,6 @@
#define __GTP_PATH_H__
#include "core_pkbuf.h"
#include "core_net.h"
#include "core_network.h"
#include "core_list.h"
@ -20,18 +19,18 @@ typedef struct _gtp_node_t {
lnode_t node; /**< A node of list_t */
c_sockaddr_t addr; /**< Network byte order IP Address */
net_sock_t *sock; /**< Socket Descriptor */
sock_id sock; /**< Socket Descriptor */
list_t local_list;
list_t remote_list;
} gtp_node_t;
CORE_DECLARE(status_t) gtp_listen(net_sock_t **sock,
net_sock_handler handler, c_uint32_t addr, c_uint16_t port, void *data);
CORE_DECLARE(status_t) gtp_close(net_sock_t *sock);
CORE_DECLARE(status_t) gtp_listen(sock_id *sock,
sock_handler handler, c_uint32_t addr, c_uint16_t port, void *data);
CORE_DECLARE(status_t) gtp_close(sock_id sock);
CORE_DECLARE(status_t) gtp_recv(net_sock_t *sock, pkbuf_t **pkbuf);
CORE_DECLARE(status_t) gtp_recvfrom(net_sock_t *sock,
CORE_DECLARE(status_t) gtp_recv(sock_id sock, pkbuf_t **pkbuf);
CORE_DECLARE(status_t) gtp_recvfrom(sock_id sock,
pkbuf_t **pkbuf, c_sockaddr_t *from);
CORE_DECLARE(status_t) gtp_send(gtp_node_t *gnode, pkbuf_t *pkbuf);

View File

@ -4,7 +4,6 @@
#include "core_pkbuf.h"
#include "core_list.h"
#include "core_index.h"
#include "core_net.h"
#include "core_timer.h"
#include "gtp_path.h"

View File

@ -4,7 +4,6 @@
#include "core_list.h"
#include "core_index.h"
#include "core_errno.h"
#include "core_net.h"
#include "core_sha2.h"
#include "core_hash.h"
@ -57,7 +56,7 @@ typedef struct _mme_context_t {
c_uint32_t gtpc_addr; /* MME GTPC local address */
c_uint16_t gtpc_port; /* MME GTPC local port */
net_sock_t *gtpc_sock; /* MME GTPC local listen socket */
sock_id gtpc_sock; /* MME GTPC local listen socket */
c_uint32_t s5c_addr; /* PGW S5C remote address */
c_uint16_t s5c_port; /* PGW S5C remote port */

View File

@ -1,13 +1,12 @@
#define TRACE_MODULE _mme_s11_path
#include "core_debug.h"
#include "core_pkbuf.h"
#include "core_net.h"
#include "mme_event.h"
#include "mme_gtp_path.h"
#include "mme_s11_build.h"
static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
static int _gtpv2_c_recv_cb(sock_id sock, void *data)
{
status_t rv;
event_t e;

View File

@ -119,7 +119,7 @@ static void *THREAD_FUNC net_main(thread_id id, void *data)
{
while (!thread_should_stop())
{
net_fds_read_run(EVENT_LOOP_TIMEOUT);
sock_select_loop(EVENT_LOOP_TIMEOUT);
}
return NULL;

View File

@ -1,5 +1,6 @@
#define TRACE_MODULE _mme_sm
#include "core_debug.h"
#include "core_net.h"
#include "s1ap_message.h"
#include "nas_message.h"

View File

@ -1,6 +1,7 @@
#define TRACE_MODULE _s1ap_build
#include "core_debug.h"
#include "core_net.h"
#include "s6a_message.h"

View File

@ -1,6 +1,7 @@
#define TRACE_MODULE _s1ap_handler
#include "core_debug.h"
#include "core_net.h"
#include "mme_event.h"

View File

@ -2,6 +2,7 @@
#include "core_debug.h"
#include "core_thread.h"
#include "core_net.h"
#include "mme_event.h"

View File

@ -792,8 +792,10 @@ pgw_bearer_t* pgw_bearer_find_by_packet(pkbuf_t *pkt)
hash_index_t *hi = NULL;
pgw_sess_t *sess = NULL;
struct ip *iph = NULL;
#if 0 /* ADDR */
char buf1[INET_ADDRSTRLEN];
char buf2[INET_ADDRSTRLEN];
#endif
d_assert(pkt, return NULL, "pkt is NULL");
@ -805,10 +807,12 @@ pgw_bearer_t* pgw_bearer_find_by_packet(pkbuf_t *pkt)
return NULL;
}
#if 0 /* ADDR */
d_trace(50, "Src(%s)-> Dst(%s), Protocol: %d\n",
INET_NTOP(&iph->ip_src.s_addr,buf1),
INET_NTOP(&iph->ip_dst.s_addr,buf2),
iph->ip_p);
#endif
/* TODO: Need to use the method of FAST matching algorithm and
* implementation .
@ -818,9 +822,11 @@ pgw_bearer_t* pgw_bearer_find_by_packet(pkbuf_t *pkt)
for (hi = pgw_sess_first(); hi; hi = pgw_sess_next(hi))
{
sess = pgw_sess_this(hi);
#if 0 /* ADDR */
d_trace(50, "Dst(%s) in Pkt : PAA(%s) in PDN\n",
INET_NTOP(&iph->ip_dst.s_addr,buf1),
INET_NTOP(&sess->pdn.paa.ipv4_addr, buf2));
#endif
if (iph->ip_dst.s_addr == sess->pdn.paa.ipv4_addr)
{

View File

@ -3,7 +3,6 @@
#include "core_list.h"
#include "core_errno.h"
#include "core_net.h"
#include "core_hash.h"
#include "gtp_types.h"
@ -24,11 +23,11 @@ typedef struct _pgw_context_t {
c_uint32_t gtpc_addr; /* PGW GTP-C local address */
c_uint32_t gtpc_port; /* PGW GTP-C local port */
net_sock_t* gtpc_sock; /* PGW GTP-C local listen socket */
sock_id gtpc_sock; /* PGW GTP-C local listen socket */
c_uint32_t gtpu_addr; /* PGW GTP-U local address */
c_uint32_t gtpu_port; /* PGW GTP-U local port */
net_sock_t* gtpu_sock; /* PGW GTP-U local listen socket */
sock_id gtpu_sock; /* PGW GTP-U local listen socket */
const char* fd_conf_path; /* PGW freeDiameter conf path */
@ -36,7 +35,7 @@ typedef struct _pgw_context_t {
tm_service_t tm_service; /* Timer Service */
struct {
net_link_t* tun_link; /* PGW Tun Interace for U-plane */
sock_id tun_link; /* PGW Tun Interace for U-plane */
const char *if_name;
struct {
c_uint32_t addr;

View File

@ -1,7 +1,6 @@
#define TRACE_MODULE _pgw_gtp_path
#include "core_debug.h"
#include "core_pkbuf.h"
#include "core_net.h"
#include "types.h"
#include "gtp_path.h"
@ -10,7 +9,7 @@
#include "pgw_event.h"
#include "pgw_gtp_path.h"
static int _gtpv1_tun_recv_cb(net_link_t *net_link, void *data)
static int _gtpv1_tun_recv_cb(sock_id sock, void *data)
{
pkbuf_t *recvbuf = NULL;
int n;
@ -20,7 +19,7 @@ static int _gtpv1_tun_recv_cb(net_link_t *net_link, void *data)
recvbuf = pkbuf_alloc(GTPV1U_HEADER_LEN, MAX_SDU_LEN);
d_assert(recvbuf, return -1, "pkbuf_alloc error");
n = net_link_read(net_link, recvbuf->payload, recvbuf->len, 0);
n = core_recv(sock, recvbuf->payload, recvbuf->len, 0);
if (n <= 0)
{
pkbuf_free(recvbuf);
@ -68,7 +67,7 @@ static int _gtpv1_tun_recv_cb(net_link_t *net_link, void *data)
gnode.sock = pgw_self()->gtpu_sock;
d_trace(50, "Send S5U PDU (teid = 0x%x)to SGW(%s)\n",
bearer->sgw_s5u_teid,
INET_NTOP(&gnode.addr, buf));
CORE_NTOP(&gnode.addr, buf));
rv = gtp_send(&gnode, recvbuf);
}
@ -82,7 +81,7 @@ static int _gtpv1_tun_recv_cb(net_link_t *net_link, void *data)
}
static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
static int _gtpv2_c_recv_cb(sock_id sock, void *data)
{
event_t e;
status_t rv;
@ -115,7 +114,7 @@ static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
return 0;
}
static int _gtpv1_u_recv_cb(net_sock_t *sock, void *data)
static int _gtpv1_u_recv_cb(sock_id sock, void *data)
{
status_t rv;
pkbuf_t *pkbuf = NULL;
@ -144,8 +143,8 @@ static int _gtpv1_u_recv_cb(net_sock_t *sock, void *data)
return -1;
}
if (net_link_write(pgw_self()->ue_network[(c_uintptr_t)data].tun_link,
pkbuf->payload, pkbuf->len) <= 0)
if (core_send(pgw_self()->ue_network[(c_uintptr_t)data].tun_link,
pkbuf->payload, pkbuf->len, 0) <= 0)
{
d_error("Can not send packets to tuntap");
}
@ -160,7 +159,9 @@ status_t pgw_gtp_open()
status_t rv;
int i;
int rc;
#if 0 /* ADDR */
char buf[INET_ADDRSTRLEN];
#endif
rv = gtp_listen(&pgw_self()->gtpc_sock, _gtpv2_c_recv_cb,
pgw_self()->gtpc_addr, pgw_self()->gtpc_port, NULL);
@ -192,7 +193,7 @@ status_t pgw_gtp_open()
*/
/* Open Tun interface */
rc = net_tun_open(&pgw_self()->ue_network[i].tun_link,
rc = tun_open(&pgw_self()->ue_network[i].tun_link,
(char *)pgw_self()->ue_network[i].if_name, 0);
if (rc != 0)
{
@ -212,25 +213,31 @@ status_t pgw_gtp_open()
/* Set P-to-P IP address with Netmask
* Note that Linux will skip this configuration */
rc = net_tun_set_ipv4(pgw_self()->ue_network[i].tun_link,
rc = tun_set_ipv4(pgw_self()->ue_network[i].tun_link,
pgw_self()->ue_network[i].ipv4.addr,
pgw_self()->ue_network[i].ipv4.bits);
if (rc != 0)
{
#if 0 /* ADDR */
d_error("Can not configure tun(dev : %s for %s/%d)",
pgw_self()->ue_network[i].if_name,
INET_NTOP(&pgw_self()->ue_network[i].ipv4.addr, buf),
pgw_self()->ue_network[i].ipv4.bits);
#else
d_error("Can not configure tun(dev : %s for /%d)",
pgw_self()->ue_network[i].if_name,
pgw_self()->ue_network[i].ipv4.bits);
#endif
return CORE_ERROR;
}
rc = net_register_link(pgw_self()->ue_network[i].tun_link,
rc = sock_register(pgw_self()->ue_network[i].tun_link,
_gtpv1_tun_recv_cb, (void *)(c_uintptr_t)i);
if (rc != 0)
{
d_error("Can not register tun(dev : %s)",
pgw_self()->ue_network[i].if_name);
net_tun_close(pgw_self()->ue_network[i].tun_link);
sock_delete(pgw_self()->ue_network[i].tun_link);
return CORE_ERROR;
}
}
@ -240,27 +247,13 @@ status_t pgw_gtp_open()
status_t pgw_gtp_close()
{
status_t rv;
int i;
rv = gtp_close(pgw_self()->gtpc_sock);
if (rv != CORE_OK)
{
d_error("Can't close GTP-C Path for MME");
return rv;
}
rv = gtp_close(pgw_self()->gtpu_sock);
if (rv != CORE_OK)
{
d_error("Can't close GTP-U Path for MME");
return rv;
}
sock_delete(pgw_self()->gtpc_sock);
sock_delete(pgw_self()->gtpu_sock);
for (i = 0; i < pgw_self()->num_of_ue_network; i++)
{
net_unregister_link(pgw_self()->ue_network[i].tun_link);
net_tun_close(pgw_self()->ue_network[i].tun_link);
sock_delete(pgw_self()->ue_network[i].tun_link);
}
return CORE_OK;

View File

@ -78,7 +78,7 @@ static void *THREAD_FUNC pgw_main(thread_id id, void *data)
#define EVENT_LOOP_TIMEOUT 10 /* 10ms */
while ((!thread_should_stop()))
{
net_fds_read_run(EVENT_LOOP_TIMEOUT);
sock_select_loop(EVENT_LOOP_TIMEOUT);
do
{
rv = event_recv(pgw_self()->queue_id, &event);

View File

@ -3,7 +3,6 @@
#include "core_list.h"
#include "core_errno.h"
#include "core_net.h"
#include "core_event.h"
#include "core_hash.h"
@ -24,11 +23,11 @@ typedef gtp_node_t sgw_pgw_t;
typedef struct _sgw_context_t {
c_uint32_t gtpc_addr; /* GTP-U local address */
c_uint32_t gtpc_port; /* GTP-U local port */
net_sock_t* gtpc_sock; /* GTP-U local listen socket */
sock_id gtpc_sock; /* GTP-U local listen socket */
c_uint32_t gtpu_addr; /* GTP-U local address */
c_uint32_t gtpu_port; /* GTP-U local port */
net_sock_t* gtpu_sock; /* GTP-U local listen socket */
sock_id gtpu_sock; /* GTP-U local listen socket */
msgq_id queue_id; /* Queue for processing SGW control plane */
tm_service_t tm_service;/* Timer Service */

View File

@ -1,7 +1,6 @@
#define TRACE_MODULE _sgw_path
#include "core_debug.h"
#include "core_pkbuf.h"
#include "core_net.h"
#include "types.h"
#include "gtp_types.h"
@ -11,7 +10,7 @@
#include "sgw_event.h"
#include "sgw_gtp_path.h"
static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
static int _gtpv2_c_recv_cb(sock_id sock, void *data)
{
event_t e;
status_t rv;
@ -60,7 +59,7 @@ static int _gtpv2_c_recv_cb(net_sock_t *sock, void *data)
return 0;
}
static int _gtpv1_u_recv_cb(net_sock_t *sock, void *data)
static int _gtpv1_u_recv_cb(sock_id sock, void *data)
{
status_t rv;
pkbuf_t *pkbuf = NULL;
@ -98,9 +97,9 @@ static int _gtpv1_u_recv_cb(net_sock_t *sock, void *data)
/* Echo reply */
d_trace(3, "Send echo-rsp to peer\n");
gnode.addr.sin.sin_addr.s_addr = sock->remote.sin_addr.s_addr;
gnode.addr.c_sa_port = sock->remote.sin_port;
gnode.addr.c_sa_family = AF_INET;
gnode.addr.sin.sin_addr.s_addr = from.sin.sin_addr.s_addr;
gnode.addr.c_sa_port = from.c_sa_port;
gnode.addr.c_sa_family = from.c_sa_family;
gnode.sock = sock;
gtp_send(&gnode, echo_rsp);

View File

@ -67,7 +67,7 @@ static void *THREAD_FUNC sgw_main(thread_id id, void *data)
#define EVENT_LOOP_TIMEOUT 10 /* 10ms */
while ((!thread_should_stop()))
{
net_fds_read_run(EVENT_LOOP_TIMEOUT);
sock_select_loop(EVENT_LOOP_TIMEOUT);
do
{
rv = event_recv(sgw_self()->queue_id, &event);

View File

@ -19,7 +19,7 @@ static void attach_test1(abts_case *tc, void *data)
{
status_t rv;
sock_id sock;
net_sock_t *gtpu;
sock_id gtpu;
pkbuf_t *sendbuf;
pkbuf_t *recvbuf;
s1ap_message_t message;
@ -143,7 +143,7 @@ static void attach_test1(abts_case *tc, void *data)
/* eNB connects to SGW */
gtpu = testgtpu_enb_connect();
ABTS_PTR_NOTNULL(tc, gtpu);
ABTS_INT_NEQUAL(tc, 0, gtpu);
/* Send S1-Setup Reqeust */
rv = tests1ap_build_setup_req(

View File

@ -11,29 +11,37 @@
extern int test_only_control_plane;
net_sock_t *testgtpu_enb_connect(void)
sock_id testgtpu_enb_connect(void)
{
char buf[INET_ADDRSTRLEN];
int rc;
status_t rv;
mme_context_t *mme = mme_self();
net_sock_t *sock = NULL;
sock_id sock = 0;
c_sockaddr_t addr;
if (test_only_control_plane) return (net_sock_t *)1;
if (test_only_control_plane) return 1;
if (!mme) return NULL;
if (!mme) return 0;
rc = net_listen_ext(&sock, SOCK_DGRAM, IPPROTO_UDP,
0, mme->gtpc_addr, GTPV1_U_UDP_PORT);
if (rc != 0) return NULL;
memset(&addr, 0, sizeof(c_sockaddr_t));
addr.sin.sin_addr.s_addr = mme->gtpc_addr;
addr.c_sa_family = AF_INET;
addr.c_sa_port = htons(GTPV1_U_UDP_PORT);
rv = udp_socket(&sock, AF_INET);
d_assert(rv == CORE_OK, return 0,);
rv = sock_bind(sock, &addr);
d_assert(rv == CORE_OK, return 0,);
return sock;
}
status_t testgtpu_enb_close(net_sock_t *sock)
status_t testgtpu_enb_close(sock_id sock)
{
if (test_only_control_plane) return CORE_OK;
return net_close(sock);
return sock_delete(sock);
}
static uint16_t in_cksum(uint16_t *addr, int len)
@ -63,7 +71,7 @@ static uint16_t in_cksum(uint16_t *addr, int len)
return answer;
}
int testgtpu_enb_send(net_sock_t *sock, c_uint32_t src_ip, c_uint32_t dst_ip)
int testgtpu_enb_send(sock_id sock, c_uint32_t src_ip, c_uint32_t dst_ip)
{
hash_index_t *hi = NULL;
mme_ue_t *mme_ue = NULL;
@ -152,7 +160,7 @@ int testgtpu_enb_send(net_sock_t *sock, c_uint32_t src_ip, c_uint32_t dst_ip)
return 0;
}
int testgtpu_enb_read(net_sock_t *sock, pkbuf_t *recvbuf)
int testgtpu_enb_read(sock_id sock, pkbuf_t *recvbuf)
{
int rc = 0;
@ -160,14 +168,14 @@ int testgtpu_enb_read(net_sock_t *sock, pkbuf_t *recvbuf)
while(1)
{
rc = net_read(sock, recvbuf->payload, recvbuf->len, 0);
rc = core_recv(sock, recvbuf->payload, recvbuf->len, 0);
if (rc == -2)
{
continue;
}
else if (rc <= 0)
{
if (sock->sndrcv_errno == EAGAIN)
if (errno == EAGAIN)
{
continue;
}

View File

@ -13,11 +13,11 @@ CORE_DECLARE(status_t) tests1ap_enb_close(sock_id id);
CORE_DECLARE(status_t) tests1ap_enb_send(sock_id id, pkbuf_t *sendbuf);
CORE_DECLARE(int) tests1ap_enb_read(sock_id id, pkbuf_t *recvbuf);
CORE_DECLARE(net_sock_t) *testgtpu_enb_connect(void);
CORE_DECLARE(status_t) testgtpu_enb_close(net_sock_t *sock);
CORE_DECLARE(int) testgtpu_enb_send(net_sock_t *sock,
CORE_DECLARE(sock_id) testgtpu_enb_connect(void);
CORE_DECLARE(status_t) testgtpu_enb_close(sock_id sock);
CORE_DECLARE(int) testgtpu_enb_send(sock_id sock,
c_uint32_t src_ip, c_uint32_t dst_ip);
CORE_DECLARE(int) testgtpu_enb_read(net_sock_t *sock, pkbuf_t *recvbuf);
CORE_DECLARE(int) testgtpu_enb_read(sock_id sock, pkbuf_t *recvbuf);
CORE_DECLARE(status_t) tests1ap_build_setup_req(
pkbuf_t **pkbuf, S1ap_ENB_ID_PR present, c_uint32_t enb_id);

View File

@ -4,6 +4,7 @@
#include "core_pkbuf.h"
#include "core_lib.h"
#include "core_network.h"
#include "core_net.h"
#include "mme_context.h"
#include "s1ap_path.h"