update it

This commit is contained in:
Sukchan Lee 2017-03-29 23:19:31 +09:00
parent 6dc54ce7ba
commit 4865da28da
6 changed files with 93 additions and 118 deletions

View File

@ -96,7 +96,5 @@ status_t gtp_send(net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf)
return CORE_ERROR;
}
pkbuf_free(pkbuf);
return CORE_OK;
}

View File

@ -9,28 +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

@ -5,7 +5,6 @@
#include "gtp_xact.h"
#include "gtp_tlv.h"
#include "gtp_types.h"
#define SIZE_OF_GTP_XACT_POOL 32
@ -15,15 +14,34 @@
((__id2) > (__id1) ? ((__id2) - (__id1) < 0x7fffff ? -1 : 1) : \
(__id1) > (__id2) ? ((__id1) - (__id2) < 0x7fffff ? 1 : -1) : 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 gtp_xact_pool_initialized = 0;
pool_declare(gtp_xact_pool, gtp_xact_t, SIZE_OF_GTP_XACT_POOL);
/**
* Initialize the transaction framework
*/
status_t gtp_xact_init(gtp_xact_ctx_t *context, tm_service_t *tm_service,
c_uintptr_t event, c_uint32_t duration, int retry_count)
{
@ -45,9 +63,6 @@ status_t gtp_xact_init(gtp_xact_ctx_t *context, tm_service_t *tm_service,
return CORE_OK;
}
/**
* Finalize the transaction framework
*/
status_t gtp_xact_final(void)
{
if (gtp_xact_pool_initialized == 1)
@ -59,11 +74,8 @@ status_t gtp_xact_final(void)
return CORE_OK;
}
/**
* Create a new transaction which was initiated by local ASN node.
*/
gtp_xact_t *gtp_xact_new_local(gtp_xact_ctx_t *context,
c_uint8_t type, net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf)
net_sock_t *sock, gtp_node_t *gnode, c_uint8_t type, pkbuf_t *pkbuf)
{
gtp_xact_t *xact = NULL;
@ -93,9 +105,6 @@ gtp_xact_t *gtp_xact_new_local(gtp_xact_ctx_t *context,
return xact;
}
/**
* Create a new transaction which was initiated by remote node
*/
gtp_xact_t *gtp_xact_new_remote(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf)
{
@ -125,23 +134,19 @@ gtp_xact_t *gtp_xact_new_remote(gtp_xact_ctx_t *context,
d_assert(xact->tm_wait, return NULL, "Timer allocation failed");
xact->retry_count = 1;
tm_start(xact->tm_wait);
list_append(&gnode->remote_xlist, xact);
return xact;
}
/**
* Delete a transaction
*/
status_t gtp_xact_delete(gtp_xact_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");
d_assert(xact->tm_wait, return CORE_ERROR, "Null param");
tm_delete(xact->tm_wait);
d_assert(xact->gnode, return CORE_ERROR, "Null param");
list_remove(xact->org == GTP_LOCAL_ORIGINATOR ? &xact->gnode->local_xlist :
&xact->gnode->remote_xlist, xact);
pool_free_node(&gtp_xact_pool, xact);
@ -149,9 +154,6 @@ status_t gtp_xact_delete(gtp_xact_t *xact)
return CORE_OK;
}
/**
* Apply and commit the updated of the transcation
*/
status_t gtp_xact_commit(gtp_xact_t *xact)
{
status_t rv;
@ -161,6 +163,14 @@ status_t gtp_xact_commit(gtp_xact_t *xact)
gtpv2c_header_t *h = NULL;
d_assert(xact, return CORE_ERROR, "Null param");
if (xact->retry_count == 0)
{
d_warn("No Response. Give up");
gtp_xact_delete(xact);
return CORE_OK;
}
d_assert(xact->tm_wait, return CORE_ERROR, "Null param");
sock = xact->sock;
@ -187,14 +197,12 @@ status_t gtp_xact_commit(gtp_xact_t *xact)
return CORE_ERROR;
}
xact->retry_count--;
tm_start(xact->tm_wait);
return CORE_OK;
}
/**
* Find the transaction with the given ASN header
*/
gtp_xact_t *gtp_xact_find(gtp_node_t *gnode, pkbuf_t *pkbuf)
{
gtpv2c_header_t *h = NULL;
@ -247,3 +255,47 @@ gtp_xact_t *gtp_xact_find(gtp_node_t *gnode, pkbuf_t *pkbuf)
return xact;
}
gtp_xact_t *gtp_xact_recv(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf)
{
gtp_xact_t *xact = NULL;
gtpv2c_header_t *h = NULL;
d_assert(context, return NULL, "Null param");
d_assert(sock, return NULL, "Null param");
d_assert(gnode, return NULL, "Null param");
d_assert(pkbuf, return NULL, "Null param");
h = pkbuf->payload;
d_assert(h, return NULL, "Null param");
xact = gtp_xact_find(gnode, pkbuf);
if (!xact)
{
xact = gtp_xact_new_remote(context, sock, gnode, pkbuf);
}
if (h->teid_presence)
pkbuf_header(pkbuf, -GTPV2C_HEADER_LEN);
else
pkbuf_header(pkbuf, -(GTPV2C_HEADER_LEN-GTPV2C_TEID_LEN));
return xact;
}
status_t gtp_xact_send(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, c_uint8_t type, pkbuf_t *pkbuf)
{
gtp_xact_t *xact = NULL;
d_assert(context, 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");
xact = gtp_xact_new_local(context, sock, gnode, type, pkbuf);
d_assert(xact, return CORE_ERROR, "Null param");
return gtp_xact_commit(xact);
}

View File

@ -46,54 +46,24 @@ typedef struct _gtp_xact_t {
} gtp_xact_t;
/**
* Initialize the transaction framework
*/
CORE_DECLARE(status_t) gtp_xact_init(gtp_xact_ctx_t *context,
tm_service_t *tm_service, c_uintptr_t event, c_uint32_t duration,
int retry_count);
/**
* Finalize the transaction framework
*/
CORE_DECLARE(status_t) gtp_xact_final(void);
/**
* Create a new transaction which was initiated by local ASN node.
*/
CORE_DECLARE(gtp_xact_t *) gtp_xact_new_local(gtp_xact_ctx_t *context,
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
*/
net_sock_t *sock, gtp_node_t *gnode, c_uint8_t type, pkbuf_t *pkbuf);
CORE_DECLARE(gtp_xact_t *) gtp_xact_new_remote(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf);
/**
* Delete a transaction
*/
CORE_DECLARE(status_t) gtp_xact_delete(gtp_xact_t *xact);
/**
* Update the transaction with the new packet to be sent for the next step
*/
CORE_DECLARE(status_t) gtp_xact_update_tx(gtp_xact_t *xact, pkbuf_t *pkb);
/**
* Update the transaction with the new received packet for the next step
*/
CORE_DECLARE(status_t) gtp_xact_update_rx(gtp_xact_t *xact);
/**
* Apply and commit the updated of the transcation
*/
CORE_DECLARE(gtp_xact_t *) gtp_xact_find(gtp_node_t *gnode, pkbuf_t *pkbuf);
CORE_DECLARE(status_t) gtp_xact_commit(gtp_xact_t *xact);
/**
* Find the transaction with the given ASN header
*/
CORE_DECLARE(gtp_xact_t *) gtp_xact_find(gtp_node_t *gnode, pkbuf_t *pkbuf);
CORE_DECLARE(gtp_xact_t *) gtp_xact_recv(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, pkbuf_t *pkbuf);
CORE_DECLARE(status_t) gtp_xact_send(gtp_xact_ctx_t *context,
net_sock_t *sock, gtp_node_t *gnode, c_uint8_t type, pkbuf_t *pkbuf);
#ifdef __cplusplus
}

View File

@ -83,13 +83,10 @@ status_t mme_s11_close()
#include "gtp_tlv.h"
status_t mme_s11_send_to_sgw(void *sgw, pkbuf_t *pkbuf)
{
gtp_xact_t *xact = NULL;
d_assert(sgw, return CORE_ERROR, "Null param");
d_assert(pkbuf, return CORE_ERROR, "Null param");
xact = gtp_xact_new_local(&mme_self()->gtp_xact_ctx,
GTP_CREATE_SESSION_REQUEST_TYPE,
mme_self()->s11_sock, sgw, pkbuf);
return gtp_xact_commit(xact);
return gtp_xact_send(&mme_self()->gtp_xact_ctx, mme_self()->s11_sock, sgw,
GTP_CREATE_SESSION_REQUEST_TYPE, pkbuf);
}

View File

@ -1,8 +1,6 @@
#define TRACE_MODULE _sgw_sm
#include "core_debug.h"
#include "gtp_types.h"
#include "sm.h"
#include "context.h"
#include "event.h"
@ -65,37 +63,19 @@ void sgw_state_operational(sgw_sm_t *s, event_t *e)
gtp_node_t *gnode = (gtp_node_t *)event_get_param2(e);
pkbuf_t *pkbuf = (pkbuf_t *)event_get_param3(e);
gtp_xact_t *xact = NULL;
gtpv2c_header_t *h = NULL;
gtp_message_t gtp_message;
d_assert(sock, break, "Null param");
d_assert(gnode, break, "Null param");
d_assert(pkbuf, break, "Null param");
h = pkbuf->payload;
d_assert(h, break, "Null param");
xact = gtp_xact_find(gnode, pkbuf);
if (!xact)
{
xact = gtp_xact_new_remote(&sgw_self()->gtp_xact_ctx,
sock, gnode, pkbuf);
}
xact = gtp_xact_recv(&sgw_self()->gtp_xact_ctx, sock, gnode, pkbuf);
d_assert(xact, break, "Null param");
if (h->teid_presence)
pkbuf_header(pkbuf, -GTPV2C_HEADER_LEN);
else
pkbuf_header(pkbuf, -(GTPV2C_HEADER_LEN-GTPV2C_TEID_LEN));
rv = gtp_parse_msg(xact->type, &gtp_message, pkbuf);
d_assert(rv == CORE_OK, break, "parse error");
rv = gtp_parse_msg(h->type, &gtp_message, pkbuf);
if (rv != CORE_OK)
{
d_error("failed to parse GTPv2-C TLV message(type:%d)",
h->type);
pkbuf_free(pkbuf);
}
switch(h->type)
switch(xact->type)
{
case GTP_CREATE_SESSION_REQUEST_TYPE:
{