intermediate

This commit is contained in:
Sukchan Lee 2017-02-13 14:01:38 +09:00
parent 733dc301af
commit 0edd783ff8
5 changed files with 24 additions and 30 deletions

View File

@ -157,14 +157,14 @@ status_t enb_ctx_remove_all()
return CORE_OK;
}
enb_ctx_t* enb_ctx_find_by_ip(c_uint32_t ip)
enb_ctx_t* enb_ctx_find_by_sock(net_sock_t *sock)
{
enb_ctx_t *enb = NULL;
enb = list_first(&g_enb_list);
while (enb)
{
if (ip == enb->ip)
if (sock == enb->s1_sock)
break;
enb = list_next(enb);

View File

@ -61,10 +61,8 @@ typedef struct _enb_ctx_t {
lnode_t node; /**< A node of list_t */
enb_s1_sm_t s1_sm; /**< eNB S1 state machine */
net_sock_t *s1_sock;
c_uint32_t ip; /** Network byte order */
c_uint32_t id;
} enb_ctx_t;
@ -107,7 +105,7 @@ CORE_DECLARE(mme_ctx_t*) mme_self(void);
CORE_DECLARE(enb_ctx_t*) enb_ctx_add(void);
CORE_DECLARE(status_t) enb_ctx_remove(enb_ctx_t *enb);
CORE_DECLARE(status_t) enb_ctx_remove_all(void);
CORE_DECLARE(enb_ctx_t*) enb_ctx_find_by_ip(c_uint32_t ip);
CORE_DECLARE(enb_ctx_t*) enb_ctx_find_by_sock(net_sock_t *sock);
CORE_DECLARE(enb_ctx_t*) enb_ctx_find_by_id(c_uint32_t id);
CORE_DECLARE(enb_ctx_t*) enb_ctx_first(void);
CORE_DECLARE(enb_ctx_t*) enb_ctx_next(enb_ctx_t *enb);

View File

@ -10,6 +10,7 @@
#include "core_timer.h"
#include "core_fsm.h"
#include "core_pkbuf.h"
#include "core_net.h"
#ifdef __cplusplus
extern "C" {
@ -47,7 +48,6 @@ typedef struct {
typedef struct {
pkbuf_t *pkb;
c_uint32_t ip_addr;
} msg_event_t;
typedef struct {
@ -108,14 +108,12 @@ typedef struct {
#define event_get_param4(__ptr_e) \
((__ptr_e)->param4)
#define event_set_msg(__ptr_e, __p_pkb, __p_ip_addr) \
#define event_set_msg(__ptr_e, __p_pkb) \
(event_is_msg(__ptr_e) ? \
(((__ptr_e)->u.m.pkb = (__p_pkb)), \
((__ptr_e)->u.m.ip_addr = (__p_ip_addr)), \
CORE_OK) : CORE_ERROR)
#define event_get_msg_pkb(__ptr_e) ((__ptr_e)->u.m.pkb)
#define event_get_msg_ip_addr(__ptr_e) ((__ptr_e)->u.m.ip_addr)
#define event_get_msg(__ptr_e) ((__ptr_e)->u.m.pkb)
/**
* Create event message queue

View File

@ -61,12 +61,10 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
net_sock_t *sock = (net_sock_t *)event_get_param1(e);
d_assert(sock, break, "Null param");
c_uint32_t ip_addr = sock->remote.sin_addr.s_addr;
d_trace(1, "eNB-S1 accepted[%s] in master_sm module\n",
INET_NTOP(&sock->remote.sin_addr.s_addr, buf));
enb_ctx_t *enb = enb_ctx_find_by_ip(ip_addr);
enb_ctx_t *enb = enb_ctx_find_by_sock(sock);
if (!enb)
{
rc = net_register_sock(sock, _s1_recv_cb, (void*)s->queue_id);
@ -74,7 +72,6 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
enb_ctx_t *enb = enb_ctx_add();
d_assert(enb, break, "Null param");
enb->ip = sock->remote.sin_addr.s_addr;
enb->s1_sock = sock;
fsm_create((fsm_t*)&enb->s1_sm,
@ -87,7 +84,7 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
else
{
d_warn("eNB context duplicated with IP-address [%s]!!!",
INET_NTOP(&ip_addr, buf));
INET_NTOP(&sock->remote.sin_addr.s_addr, buf));
net_close(sock);
d_warn("S1 Socket Closed");
}
@ -96,8 +93,10 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
}
case EVT_S1_ENB_INF:
{
c_uint32_t ip_addr = event_get_msg_ip_addr(e);
enb_ctx_t *enb = enb_ctx_find_by_ip(ip_addr);
net_sock_t *sock = (net_sock_t *)event_get_param1(e);
d_assert(sock, break, "Null param");
enb_ctx_t *enb = enb_ctx_find_by_sock(sock);
if (enb)
{
fsm_dispatch((fsm_t*)&enb->s1_sm, (fsm_event_t*)e);
@ -105,7 +104,7 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
else
{
d_error("eNB context is not created[%s]",
INET_NTOP(&ip_addr, buf));
INET_NTOP(&sock->remote.sin_addr.s_addr, buf));
}
break;
}
@ -114,13 +113,10 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
net_sock_t *sock = (net_sock_t *)event_get_param1(e);
d_assert(sock, break, "Null param");
c_uint32_t ip_addr = (c_uint32_t)event_get_param2(e);
d_info("Socket[%s] connection refused", INET_NTOP(&ip_addr, buf));
d_info("Socket[%s] connection refused",
INET_NTOP(&sock->remote.sin_addr.s_addr, buf));
net_unregister_sock(sock);
net_close(sock);
enb_ctx_t *enb = enb_ctx_find_by_ip(ip_addr);
enb_ctx_t *enb = enb_ctx_find_by_sock(sock);
if (enb)
{
/* Remove eNB S1 state machine if exist */
@ -136,8 +132,12 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
else
{
d_error("Can't find eNB-S1 for [%s]!!!",
INET_NTOP(&ip_addr, buf));
INET_NTOP(&sock->remote.sin_addr.s_addr, buf));
}
net_unregister_sock(sock);
net_close(sock);
break;
}
default:
@ -150,7 +150,7 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
/* If event was packet type, its buffer allocated by data-plane should
* be freed here */
if (event_is_msg(e))
pkbuf_free(event_get_msg_pkb(e));
pkbuf_free(event_get_msg(e));
}
void mme_state_exception(mme_sm_t *s, event_t *e)

View File

@ -95,8 +95,8 @@ static status_t s1_recv(net_sock_t *net_sock, pkbuf_t *pkb, msgq_id queue_id)
d_trace(1, "S1AP_PDU is received from eNB-Inf\n");
d_trace_hex(1, pkb->payload, pkb->len);
event_set(&e, EVT_S1_ENB_INF, 0);
event_set_msg(&e, pkb, net_sock->remote.sin_addr.s_addr);
event_set(&e, EVT_S1_ENB_INF, (c_uintptr_t)net_sock);
event_set_msg(&e, pkb);
return event_send(queue_id, &e);
}
@ -106,7 +106,6 @@ int _s1_recv_cb(net_sock_t *net_sock, void *data)
status_t rv;
pkbuf_t *pkb;
ssize_t r;
c_uint32_t ip_addr = net_sock->remote.sin_addr.s_addr;
msgq_id queue_id = (msgq_id)data;
d_assert(net_sock, return -1, "Null param");
@ -144,7 +143,6 @@ int _s1_recv_cb(net_sock_t *net_sock, void *data)
event_t e;
event_set(&e, EVT_LO_ENB_S1_CONNREFUSED, (c_uintptr_t)net_sock);
event_set_param2(&e, (c_uintptr_t)ip_addr);
event_send(queue_id, &e);
return -1;