update it

This commit is contained in:
Sukchan Lee 2017-03-27 19:12:45 +09:00
parent 1f3ddd2639
commit 1ee084c58b
7 changed files with 200 additions and 67 deletions

View File

@ -29,6 +29,14 @@ extern "C" {
#define event_get_param3(__ptr_e) ((__ptr_e)->param3)
#define event_get_param4(__ptr_e) ((__ptr_e)->param4)
#define event_timer(__tm_service, __ptr_e, __duration, __param) \
event_timer_create((__tm_service), TIMER_TYPE_ONE_SHOT, \
(__duration), (__ptr_e), (__param))
#define event_timer_periodic(__tm_service, __ptr_e, __duration, __param) \
event_timer_create((__tm_service), TIMER_TYPE_PERIODIC, \
(__duration), (__ptr_e), (__param))
typedef struct {
fsm_event_t event;
c_uintptr_t param1;
@ -85,13 +93,6 @@ CORE_DECLARE(tm_block_id) event_timer_create(
tm_service_t *tm_service, tm_type_e type, c_uint32_t duration,
c_uintptr_t event, c_uintptr_t param);
/**
* Delete a timer
*/
CORE_DECLARE(status_t) event_timer_delete(tm_block_id id);
char* event_get_name(event_t *e);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -94,9 +94,6 @@ tm_block_id event_timer_create(tm_service_t *tm_service, tm_type_e type,
{
tm_block_id id;
d_assert(type == TIMER_TYPE_ONE_SHOT || type == TIMER_TYPE_PERIODIC,
return 0, "param 'type' is invalid");
id = tm_create(tm_service);
d_assert(id, return 0, "tm_create() failed");
@ -105,12 +102,3 @@ tm_block_id event_timer_create(tm_service_t *tm_service, tm_type_e type,
return id;
}
status_t event_timer_delete(tm_block_id id)
{
d_assert(id, return CORE_ERROR, "param 'id' is zero");
tm_delete(id);
return CORE_OK;
}

View File

@ -17,11 +17,13 @@ typedef struct _msq_desc_t {
unsigned char *pool;
} msg_desc_t;
pool_declare(msgqpool, msg_desc_t, 4);
#define SIZE_OF_MSGQ_POOL 5 /* MME 1, SGW 2, PGW 2 */
pool_declare(msgqpool, msg_desc_t, SIZE_OF_MSGQ_POOL);
status_t msgq_init(void)
{
pool_init(&msgqpool, 4);
pool_init(&msgqpool, SIZE_OF_MSGQ_POOL);
return CORE_OK;
}

View File

@ -15,13 +15,6 @@ extern "C" {
#define GTP_COMPARE_NODE(__id1, __id2) \
(((__id1)->addr) == ((__id2)->addr) && ((__id1)->port) == ((__id2)->port))
/**
* This structure keeps active transactions and their histrory */
typedef struct _gtp_xact_info_t {
list_t local_xlist; /**< List of local initiated transactions */
list_t remote_xlist; /**< List of Remote initiated transactions */
} gtp_xact_info_t;
/**
* This structure represents the commonalities of GTP node such as MME, SGW,
* PGW gateway. Some of members may not be used by the specific type of node */
@ -30,11 +23,11 @@ typedef struct _gtp_node_t {
c_uint32_t addr; /**< Network byte order IP Address */
c_uint16_t port; /**< Host byte order Port number */
net_sock_t *sock; /**< Network Socket */
gtp_xact_info_t xi; /**< Transaction information */
net_sock_t *s; /**< Network socket */
/**< List of local initiated transactions */
list_t local_xlist;
/**< List of Remote initiated transactions */
list_t remote_xlist;
} gtp_node_t;
CORE_DECLARE(status_t) gtp_listen(net_sock_t **sock,

View File

@ -9,27 +9,6 @@
extern "C" {
#endif /* __cplusplus */
/* 5.1 General format */
#define GTPV2C_HEADER_LEN 12
#define GTPV2C_TEID_LEN 4
typedef struct _gtpv2c_header_t {
ED4(c_uint8_t version:3;,
c_uint8_t piggybacked:1;,
c_uint8_t teid_presence:1;,
c_uint8_t spare1:3;)
c_uint8_t type;
c_uint16_t length;
union {
struct {
c_uint32_t teid;
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
c_uint32_t sqn;
};
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
c_uint32_t spare2;
};
} __attribute__ ((packed)) gtpv2c_header_t;
/* 8.7 Aggregate Maximum Bit Rate (AMBR) */
typedef struct _gtp_ambr_t {
c_uint32_t uplink;

View File

@ -1,8 +1,10 @@
#define TRACE_MODULE _gtp_xact
#include "core_debug.h"
#include "core_pool.h"
#include "core_event.h"
#include "gtp_xact.h"
#include "gtp_tlv.h"
#define SIZE_OF_GTP_XACT_POOL 32
@ -12,14 +14,36 @@
((__id2) > (__id1) ? ((__id2) - (__id1) < 0x7fffff ? -1 : 1) : \
(__id1) > (__id2) ? ((__id1) - (__id2) < 0x7fffff ? 1 : -1) : 0)
static int g_gtp_xact_initialized = 0;
/* 5.1 General format */
#define GTPV2C_HEADER_LEN 12
#define GTPV2C_TEID_LEN 4
typedef struct _gtpv2c_header_t {
ED4(c_uint8_t version:3;,
c_uint8_t piggybacked:1;,
c_uint8_t teid_presence:1;,
c_uint8_t spare1:3;)
c_uint8_t type;
c_uint16_t length;
union {
struct {
c_uint32_t teid;
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
#define GTP_XID_TO_SQN(__xid) ((__xid) << 8)
#define GTP_SQN_TO_XID(__sqn) ((__sqn) >> 8)
c_uint32_t sqn;
};
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
c_uint32_t spare2;
};
} __attribute__ ((packed)) gtpv2c_header_t;
static int g_gtp_xact_initialized = 0;
pool_declare(gtp_xact_pool, gtp_xact_ctx_t, SIZE_OF_GTP_XACT_POOL);
/**
* Initialize the transaction framework
*/
status_t gtp_xact_init(void)
status_t gtp_xact_init()
{
d_assert(g_gtp_xact_initialized == 0, return CORE_ERROR,
"XACTION already has been initialized");
@ -46,20 +70,94 @@ status_t gtp_xact_final(void)
return CORE_OK;
}
/**
* Config Transaction
*/
void gtp_xact_config(gtp_xact_config_t *config, tm_service_t *tm_service,
c_uintptr_t event, c_uint32_t duration, int retry_count)
{
memset(config, 0, sizeof(gtp_xact_config_t));
config->g_xact_id = 1;
config->tm_service = tm_service;
config->event = event;;
config->duration = duration;;
config->retry_count = retry_count;;
}
/**
* Create a new transaction which was initiated by local ASN node.
*/
status_t gtp_xact_new_local(gtp_xact_ctx_t **xact, c_uint8_t type,
pkbuf_t *pkb, gtp_node_t *gnode)
status_t gtp_xact_new_local(gtp_xact_config_t *config,
gtp_xact_ctx_t **xact, c_uint8_t type, net_sock_t *sock,
gtp_node_t *gnode, pkbuf_t *pkbuf)
{
gtp_xact_ctx_t *new = NULL;
d_assert(xact, return CORE_ERROR, "Null param");
d_assert(sock, return CORE_ERROR, "Null param");
d_assert(gnode, return CORE_ERROR, "Null param");
d_assert(pkbuf, return CORE_ERROR, "Null param");
pool_alloc_node(&gtp_xact_pool, &new);
d_assert(new, return CORE_ERROR, "Transaction allocation failed");
memset(new, 0, sizeof(gtp_xact_ctx_t));
new->xid = GTP_XACT_NEXT_ID(config->g_xact_id);
new->org = GTP_LOCAL_ORIGINATOR;
new->type = type;
new->sock = sock;
new->gnode = gnode;
new->pkbuf = pkbuf;
new->tm_wait = event_timer(config->tm_service, config->event,
config->duration, (c_uintptr_t)new);
d_assert(new->tm_wait, return CORE_ERROR, "Timer allocation failed");
new->retry_count = config->retry_count;
list_append(&gnode->local_xlist, new);
*xact = new;
return CORE_OK;
}
/**
* Create a new transaction which was initiated by remote node
*/
status_t gtp_xact_new_remote(gtp_xact_ctx_t **xact)
status_t gtp_xact_new_remote(gtp_xact_config_t *config,
gtp_xact_ctx_t **xact, net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf)
{
gtpv2c_header_t *h = NULL;
gtp_xact_ctx_t *new = NULL;
d_assert(xact, return CORE_ERROR, "Null param");
d_assert(sock, return CORE_ERROR, "Null param");
d_assert(gnode, return CORE_ERROR, "Null param");
d_assert(pkbuf, return CORE_ERROR, "Null param");
d_assert(pkbuf->payload, return CORE_ERROR, "Null param");
pool_alloc_node(&gtp_xact_pool, &new);
d_assert(new, return CORE_ERROR, "Transaction allocation failed");
memset(new, 0, sizeof(gtp_xact_ctx_t));
h = pkbuf->payload;
new->xid = GTP_SQN_TO_XID(h->sqn);
new->org = GTP_REMOTE_ORIGINATOR;
new->type = h->type;
new->sock = sock;
new->gnode = gnode;
new->pkbuf = pkbuf;
new->tm_wait = event_timer(config->tm_service, config->event,
config->duration * config->retry_count, (c_uintptr_t)new);
d_assert(new->tm_wait, return CORE_ERROR, "Timer allocation failed");
new->retry_count = 1;
list_append(&gnode->remote_xlist, new);
*xact = new;
return CORE_OK;
}
/**
@ -67,6 +165,16 @@ status_t gtp_xact_new_remote(gtp_xact_ctx_t **xact)
*/
status_t gtp_xact_delete(gtp_xact_ctx_t *xact)
{
d_assert(xact, return CORE_ERROR, "Null param");
d_assert(xact->tm_wait, return CORE_ERROR, "Null param");
d_assert(xact->gnode, return CORE_ERROR, "Null param");
tm_delete(xact->tm_wait);
list_remove(xact->org == GTP_LOCAL_ORIGINATOR ? &xact->gnode->local_xlist :
&xact->gnode->remote_xlist, xact);
pool_free_node(&gtp_xact_pool, xact);
return CORE_OK;
}
@ -97,7 +205,55 @@ status_t gtp_xact_commit(gtp_xact_ctx_t *xact)
/**
* Find the transaction with the given ASN header
*/
gtp_xact_ctx_t * gtp_xact_find()
gtp_xact_ctx_t *gtp_xact_find(gtp_node_t *gnode, pkbuf_t *pkbuf)
{
return CORE_OK;
gtpv2c_header_t *h = NULL;
c_uint32_t xid;
gtp_xact_ctx_t *xact = NULL;
d_assert(gnode, return NULL, "Null param");
d_assert(pkbuf, return NULL, "Null param");
d_assert(pkbuf->payload, return NULL, "Null param");
h = pkbuf->payload;
switch(h->type)
{
case GTP_CREATE_SESSION_REQUEST_TYPE:
case GTP_MODIFY_BEARER_REQUEST_TYPE:
case GTP_DELETE_SESSION_REQUEST_TYPE:
case GTP_CREATE_BEARER_REQUEST_TYPE:
case GTP_UPDATE_BEARER_REQUEST_TYPE:
case GTP_DELETE_BEARER_REQUEST_TYPE:
case GTP_RELEASE_ACCESS_BEARERS_REQUEST_TYPE:
case GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_REQUEST_TYPE:
case GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_REQUEST_TYPE:
xact = list_first(&gnode->local_xlist);
break;
case GTP_CREATE_SESSION_RESPONSE_TYPE:
case GTP_MODIFY_BEARER_RESPONSE_TYPE:
case GTP_DELETE_SESSION_RESPONSE_TYPE:
case GTP_CREATE_BEARER_RESPONSE_TYPE:
case GTP_UPDATE_BEARER_RESPONSE_TYPE:
case GTP_DELETE_BEARER_RESPONSE_TYPE:
case GTP_RELEASE_ACCESS_BEARERS_RESPONSE_TYPE:
case GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_RESPONSE_TYPE:
case GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_RESPONSE_TYPE:
xact = list_first(&gnode->remote_xlist);
break;
default:
d_error("Not implemented GTPv2 Message Type(%d)", h->type);
return NULL;
}
xid = GTP_SQN_TO_XID(h->sqn);
while(xact)
{
if (xact->xid == xid)
break;
xact = list_next(xact);
}
return xact;
}

View File

@ -12,7 +12,17 @@
extern "C" {
#endif /* __cplusplus */
#define GTP_MAX_MESSAGE_TYPE 256
/**
* Transaction Configuration
*/
typedef struct _gtp_xact_config_t {
c_uint32_t g_xact_id;
tm_service_t *tm_service;
c_uintptr_t event;
c_uint32_t duration;
int retry_count;
} gtp_xact_config_t;
/**
* Transaction context
@ -26,8 +36,10 @@ typedef struct _gtp_xact_ctx_t {
#define GTP_REMOTE_ORIGINATOR 1
c_uint8_t org; /**< Transaction' originator.
local or remote */
gtp_node_t *gnode; /**< RElevant GTP node context */
void *xctx; /**< Relevant context */
c_uint8_t type; /**< GTPv2-C Message Type */
net_sock_t *sock; /**< GTP Socket */
gtp_node_t *gnode; /**< Relevant GTP node context */
pkbuf_t *pkbuf; /**< Relevant GTP node context */
tm_block_id tm_wait; /**< Timer waiting for next message */
int retry_count; /**< Retry count waiting for next message */
@ -46,13 +58,15 @@ CORE_DECLARE(status_t) gtp_xact_final(void);
/**
* Create a new transaction which was initiated by local ASN node.
*/
CORE_DECLARE(status_t) gtp_xact_new_local(gtp_xact_ctx_t **xact, c_uint8_t type,
pkbuf_t *pkb, gtp_node_t *gnode);
CORE_DECLARE(status_t) gtp_xact_new_local(gtp_xact_config_t *config,
gtp_xact_ctx_t **xact, c_uint8_t type, net_sock_t *sock,
gtp_node_t *gnode, pkbuf_t *pkbuf);
/**
* Create a new transaction which was initiated by remote node
*/
CORE_DECLARE(status_t) gtp_xact_new_remote(gtp_xact_ctx_t **xact);
CORE_DECLARE(status_t) gtp_xact_new_remote(gtp_xact_config_t *config,
gtp_xact_ctx_t **xact, net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf);
/**
* Delete a transaction
@ -77,7 +91,7 @@ CORE_DECLARE(status_t) gtp_xact_commit(gtp_xact_ctx_t *xact);
/**
* Find the transaction with the given ASN header
*/
CORE_DECLARE(gtp_xact_ctx_t *) gtp_xact_find();
CORE_DECLARE(gtp_xact_ctx_t *) gtp_xact_find(gtp_node_t *gnode, pkbuf_t *pkbuf);
#ifdef __cplusplus
}