contine to re-archi GTP

This commit is contained in:
Sukchan Lee 2017-08-31 10:48:14 +09:00
parent 829047f763
commit faf8268a3d
17 changed files with 175 additions and 90 deletions

View File

@ -3,8 +3,8 @@
noinst_LTLIBRARIES = libgtp.la
libgtp_la_SOURCES = \
gtp_tlv.h gtp_types.h gtp_path.h gtp_xact.h \
gtp_tlv.c gtp_types.c gtp_path.c gtp_xact.c
gtp_message.h gtp_types.h gtp_path.h gtp_xact.h \
gtp_message.c gtp_types.c gtp_path.c gtp_xact.c
libgtp_la_DEPENDENCIES = \
$(top_srcdir)/lib/base/libbase.la

View File

@ -26,12 +26,12 @@
/*******************************************************************************
* This file had been created by gtp_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-07-27 00:04:53.815790 by acetcom
* Created on: 2017-08-31 10:18:49.801691 by acetcom
* from 29274-d80.docx
******************************************************************************/
#include "core_debug.h"
#include "gtp_tlv.h"
#include "gtp_message.h"
tlv_desc_t tlv_desc_imsi_0 =
{

View File

@ -26,7 +26,7 @@
/*******************************************************************************
* This file had been created by gtp_tlv.py script v0.1.0
* Please do not modify this file but regenerate it via script.
* Created on: 2017-07-27 00:04:53.794907 by acetcom
* Created on: 2017-08-31 10:18:49.786605 by acetcom
* from 29274-d80.docx
******************************************************************************/
@ -39,6 +39,46 @@
extern "C" {
#endif /* __cplusplus */
/* 5.1 General format */
#define GTPV2C_HEADER_LEN 12
#define GTPV2C_TEID_LEN 4
typedef struct _gtp_header_t {
union {
struct {
ED4(c_uint8_t version:3;,
c_uint8_t piggybacked:1;,
c_uint8_t teid_presence:1;,
c_uint8_t spare1:3;)
};
/* GTU-U flags */
#define GTPU_FLAGS_PN 0x1
#define GTPU_FLAGS_S 0x2
c_uint8_t flags;
};
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) htonl(((__xid) << 8))
#define GTP_SQN_TO_XID(__sqn) (ntohl(__sqn) >> 8)
c_uint32_t sqn;
};
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
c_uint32_t sqn_only;
};
} __attribute__ ((packed)) gtp_header_t;
/* GTP-U message type, defined in 3GPP TS 29.281 Release 11 */
#define GTPU_MSGTYPE_ECHO_REQ 1
#define GTPU_MSGTYPE_ECHO_RSP 2
#define GTPU_MSGTYPE_ERR_IND 26
#define GTPU_MSGTYPE_SUPP_EXTHDR_NOTI 31
#define GTPU_MSGTYPE_END_MARKER 254
#define GTPU_MSGTYPE_GPDU 255
/* GTPv2-C message type */
#define GTP_ECHO_REQUEST_TYPE 1
#define GTP_ECHO_RESPONSE_TYPE 2
#define GTP_VERSION_NOT_SUPPORTED_INDICATION_TYPE 3
@ -1066,6 +1106,7 @@ typedef struct _gtp_modify_access_bearers_response_t {
} gtp_modify_access_bearers_response_t;
typedef struct _gtp_message_t {
gtp_header_t h;
union {
gtp_echo_request_t echo_request;
gtp_echo_response_t echo_response;

View File

@ -4,6 +4,7 @@
#include "core_net.h"
#include "types.h"
#include "gtp_message.h"
#include "gtp_path.h"
status_t gtp_listen(net_sock_t **sock,

View File

@ -15,25 +15,6 @@ extern "C" {
#define GTP_COMPARE_NODE(__id1, __id2) \
(((__id1)->addr) == ((__id2)->addr) && ((__id1)->port) == ((__id2)->port))
/* GTP-U message type, defined in 3GPP TS 29.281 Release 11 */
#define GTPU_MSGTYPE_ECHO_REQ 1
#define GTPU_MSGTYPE_ECHO_RSP 2
#define GTPU_MSGTYPE_ERR_IND 26
#define GTPU_MSGTYPE_SUPP_EXTHDR_NOTI 31
#define GTPU_MSGTYPE_END_MARKER 254
#define GTPU_MSGTYPE_GPDU 255
/* GTU-U flags */
#define GTPU_FLAGS_PN 0x1
#define GTPU_FLAGS_S 0x2
typedef struct _gtp_header
{
c_uint8_t flags;
c_uint8_t type;
c_uint16_t length;
c_uint32_t teid;
} gtp_header_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 */

View File

@ -16,32 +16,17 @@
(GTP_XACT_LOCAL_DURATION * GTP_XACT_LOCAL_RETRY_COUNT) /* 9 seconds */
#define GTP_XACT_REMOTE_RETRY_COUNT 1
/* 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) htonl(((__xid) << 8))
#define GTP_SQN_TO_XID(__sqn) (ntohl(__sqn) >> 8)
c_uint32_t sqn;
};
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
c_uint32_t sqn_only;
};
} __attribute__ ((packed)) gtpv2c_header_t;
typedef enum {
GTP_XACT_UNKNOWN_STAGE,
GTP_XACT_INITIAL_STAGE,
GTP_XACT_INTERMEDIATE_STAGE,
GTP_XACT_FINAL_STAGE,
} gtp_xact_stage_t;
index_declare(gtp_xact_pool, gtp_xact_t, SIZE_OF_GTP_XACT_POOL);
static gtp_xact_stage_t gtp_xact_get_stage(c_uint8_t type, c_uint32_t sqn);
status_t gtp_xact_init(gtp_xact_ctx_t *context,
tm_service_t *tm_service, c_uintptr_t event)
{
@ -203,7 +188,7 @@ status_t gtp_xact_associated_commit(gtp_xact_t *xact,
gtp_xact_t *assoc_xact, c_uint8_t type, c_uint32_t teid, pkbuf_t *pkbuf)
{
char buf[INET_ADDRSTRLEN];
gtpv2c_header_t *h = NULL;
gtp_header_t *h = NULL;
d_assert(xact, goto out, "Null param");
d_assert(xact->sock, goto out, "Null param");
@ -221,7 +206,7 @@ status_t gtp_xact_associated_commit(gtp_xact_t *xact,
h = pkbuf->payload;
d_assert(h, goto out, "Null param");
memset(h, 0, sizeof(gtpv2c_header_t));
memset(h, 0, sizeof(gtp_header_t));
h->version = 2;
h->teid_presence = 1;
h->type = type;
@ -296,37 +281,24 @@ static gtp_xact_t *gtp_xact_find_by_sqn(
gtp_xact_t *xact = NULL;
d_assert(gnode, return NULL, "Null param");
switch(type)
switch(gtp_xact_get_stage(type, sqn))
{
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:
case GTP_DOWNLINK_DATA_NOTIFICATION_TYPE:
case GTP_XACT_INITIAL_STAGE:
xact = list_first(&gnode->remote_list);
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:
case GTP_DOWNLINK_DATA_NOTIFICATION_ACKNOWLEDGE_TYPE:
case GTP_XACT_INTERMEDIATE_STAGE:
xact = list_first(&gnode->local_list);
break;
case GTP_XACT_FINAL_STAGE:
if (sqn & GTP_MAX_XACT_ID)
xact = list_first(&gnode->remote_list);
else
xact = list_first(&gnode->local_list);
break;
default:
d_error("Not implemented GTPv2 Message Type(%d)", type);
return NULL;
d_assert(0, return NULL, "Unknown stage");
}
xid = GTP_SQN_TO_XID(sqn);
@ -356,7 +328,7 @@ status_t gtp_xact_receive(
{
char buf[INET_ADDRSTRLEN];
status_t rv;
gtpv2c_header_t *h = NULL;
gtp_header_t *h = NULL;
gtp_xact_t *new = NULL;
d_assert(pkbuf, return CORE_ERROR, "Null param");
@ -449,3 +421,52 @@ gtp_xact_t *gtp_xact_find(index_t index)
return index_find(&gtp_xact_pool, index);
}
static gtp_xact_stage_t gtp_xact_get_stage(c_uint8_t type, c_uint32_t sqn)
{
gtp_xact_stage_t stage = GTP_XACT_UNKNOWN_STAGE;
switch(type)
{
case GTP_CREATE_SESSION_REQUEST_TYPE:
case GTP_MODIFY_BEARER_REQUEST_TYPE:
case GTP_DELETE_SESSION_REQUEST_TYPE:
case GTP_MODIFY_BEARER_COMMAND_TYPE:
case GTP_DELETE_BEARER_COMMAND_TYPE:
case GTP_BEARER_RESOURCE_COMMAND_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:
case GTP_DOWNLINK_DATA_NOTIFICATION_TYPE:
stage = GTP_XACT_INITIAL_STAGE;
break;
case GTP_CREATE_BEARER_REQUEST_TYPE:
case GTP_UPDATE_BEARER_REQUEST_TYPE:
case GTP_DELETE_BEARER_REQUEST_TYPE:
if (sqn & GTP_MAX_XACT_ID)
stage = GTP_XACT_INTERMEDIATE_STAGE;
else
stage = GTP_XACT_INITIAL_STAGE;
break;
case GTP_CREATE_SESSION_RESPONSE_TYPE:
case GTP_MODIFY_BEARER_RESPONSE_TYPE:
case GTP_DELETE_SESSION_RESPONSE_TYPE:
case GTP_MODIFY_BEARER_FAILURE_INDICATION_TYPE:
case GTP_DELETE_BEARER_FAILURE_INDICATION_TYPE:
case GTP_BEARER_RESOURCE_FAILURE_INDICATION_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:
case GTP_DOWNLINK_DATA_NOTIFICATION_ACKNOWLEDGE_TYPE:
stage = GTP_XACT_FINAL_STAGE;
break;
default:
d_error("Not implemented GTPv2 Message Type(%d)", type);
break;
}
return stage;
}

View File

@ -8,7 +8,7 @@
#include "core_timer.h"
#include "gtp_path.h"
#include "gtp_tlv.h"
#include "gtp_message.h"
#ifdef __cplusplus
extern "C" {

View File

@ -383,7 +383,7 @@ type_list["APN Restriction"]["size"] = 1 # Type : 127
type_list["Selection Mode"]["size"] = 1 # Type : 128
type_list["Node Type"]["size"] = 1 # Type : 128
f = open(outdir + 'gtp_tlv.h', 'w')
f = open(outdir + 'gtp_message.h', 'w')
output_header_to_file(f)
f.write("""#ifndef __GTP_TLV_H__
#define __GTP_TLV_H__
@ -394,6 +394,46 @@ f.write("""#ifndef __GTP_TLV_H__
extern "C" {
#endif /* __cplusplus */
/* 5.1 General format */
#define GTPV2C_HEADER_LEN 12
#define GTPV2C_TEID_LEN 4
typedef struct _gtp_header_t {
union {
struct {
ED4(c_uint8_t version:3;,
c_uint8_t piggybacked:1;,
c_uint8_t teid_presence:1;,
c_uint8_t spare1:3;)
};
/* GTU-U flags */
#define GTPU_FLAGS_PN 0x1
#define GTPU_FLAGS_S 0x2
c_uint8_t flags;
};
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) htonl(((__xid) << 8))
#define GTP_SQN_TO_XID(__sqn) (ntohl(__sqn) >> 8)
c_uint32_t sqn;
};
/* sqn : 31bit ~ 8bit, spare : 7bit ~ 0bit */
c_uint32_t sqn_only;
};
} __attribute__ ((packed)) gtp_header_t;
/* GTP-U message type, defined in 3GPP TS 29.281 Release 11 */
#define GTPU_MSGTYPE_ECHO_REQ 1
#define GTPU_MSGTYPE_ECHO_RSP 2
#define GTPU_MSGTYPE_ERR_IND 26
#define GTPU_MSGTYPE_SUPP_EXTHDR_NOTI 31
#define GTPU_MSGTYPE_END_MARKER 254
#define GTPU_MSGTYPE_GPDU 255
/* GTPv2-C message type */
""")
tmp = [(k, v["type"]) for k, v in msg_list.items()]
@ -482,6 +522,7 @@ for (k, v) in sorted_msg_list:
f.write("\n")
f.write("typedef struct _gtp_message_t {\n")
f.write(" gtp_header_t h;\n")
f.write(" union {\n")
for (k, v) in sorted_msg_list:
if "ies" in msg_list[k]:
@ -502,10 +543,10 @@ CORE_DECLARE(status_t) gtp_build_msg(
""")
f.close()
f = open(outdir + 'gtp_tlv.c', 'w')
f = open(outdir + 'gtp_message.c', 'w')
output_header_to_file(f)
f.write("""#include "core_debug.h"
#include "gtp_tlv.h"
#include "gtp_message.h"
""")

View File

@ -3,7 +3,7 @@
#include "core_debug.h"
#include "gtp_types.h"
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "types.h"
#include "mme_context.h"

View File

@ -1,7 +1,7 @@
#ifndef __MME_S11_BUILD_H__
#define __MME_S11_BUILD_H__
#include "gtp_tlv.h"
#include "gtp_message.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,7 +1,7 @@
#ifndef __MME_S11_HANDLER_H__
#define __MME_S11_HANDLER_H__
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "mme_context.h"

View File

@ -3,7 +3,7 @@
#include "core_debug.h"
#include "nas_message.h"
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "mme_event.h"

View File

@ -1,7 +1,7 @@
#ifndef __PGW_GX_HANDLER_H__
#define __PGW_GX_HANDLER_H__
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "pgw_context.h"

View File

@ -1,7 +1,7 @@
#ifndef __PGW_S5C_HANDLER_H__
#define __PGW_S5C_HANDLER_H__
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "pgw_context.h"

View File

@ -1,7 +1,7 @@
#ifndef __SGW_HANDLER_H__
#define __SGW_HANDLER_H__
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "sgw_context.h"

View File

@ -429,10 +429,6 @@ int main(int argc, const char *const argv[]) {
int list_provided = 0;
abts_suite *suite = NULL;
rv = test_initialize();
if (rv != CORE_OK)
return EXIT_FAILURE;
d_trace_global_off();
quiet = !isatty(STDOUT_FILENO);
@ -465,6 +461,10 @@ int main(int argc, const char *const argv[]) {
list_provided = 1;
}
rv = test_initialize();
if (rv != CORE_OK)
return EXIT_FAILURE;
if (list_provided) {
/* Waste a little space here, because it is easier than counting the
* number of tests listed. Besides it is at most three char *.

View File

@ -5,7 +5,7 @@
#include "types.h"
#include "gtp_types.h"
#include "gtp_tlv.h"
#include "gtp_message.h"
#include "testutil.h"