forked from acouzens/open5gs
update it
This commit is contained in:
parent
c5eeffae47
commit
d1c93ae6dd
|
@ -3,10 +3,12 @@
|
||||||
#include "core_debug.h"
|
#include "core_debug.h"
|
||||||
#include "core_pool.h"
|
#include "core_pool.h"
|
||||||
#include "core_index.h"
|
#include "core_index.h"
|
||||||
|
#include "core_jsmn.h"
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "gtp_path.h"
|
#include "gtp_path.h"
|
||||||
|
|
||||||
|
#include "context.h"
|
||||||
#include "sgw_context.h"
|
#include "sgw_context.h"
|
||||||
|
|
||||||
static sgw_context_t self;
|
static sgw_context_t self;
|
||||||
|
@ -16,27 +18,6 @@ index_declare(sgw_bearer_pool, sgw_bearer_t, MAX_NUM_OF_UE_BEARER);
|
||||||
|
|
||||||
static int context_initialized = 0;
|
static int context_initialized = 0;
|
||||||
|
|
||||||
/* FIXME : Global IP information and port.
|
|
||||||
* This should be read from configuration file or arguments
|
|
||||||
*/
|
|
||||||
static char g_mme_ip_addr[20] = "10.1.35.215";
|
|
||||||
static unsigned int g_mme_gtp_c_port = GTPV2_C_UDP_PORT;
|
|
||||||
|
|
||||||
static char g_sgw_s11_ip_addr[20] = "10.1.35.216";
|
|
||||||
static unsigned int g_sgw_s11_port = GTPV2_C_UDP_PORT;
|
|
||||||
|
|
||||||
static char g_sgw_s5c_ip_addr[20] = "10.1.35.217";
|
|
||||||
static unsigned int g_sgw_s5c_port = GTPV2_C_UDP_PORT;
|
|
||||||
|
|
||||||
static char g_pgw_ip_addr[20] = "10.1.35.219";
|
|
||||||
static unsigned int g_pgw_s5c_port = GTPV2_C_UDP_PORT;
|
|
||||||
|
|
||||||
static char g_sgw_s1u_ip_addr[20] = "10.1.35.216";/* same as g_sgw_s11_ip_addr */
|
|
||||||
static unsigned int g_sgw_s1u_port = GTPV1_U_UDP_PORT;
|
|
||||||
|
|
||||||
static char g_sgw_s5u_ip_addr[20] = "10.1.35.217"; /* same as g_sgw_s5c_ip_addr */
|
|
||||||
static unsigned int g_sgw_s5u_port = GTPV1_U_UDP_PORT;
|
|
||||||
|
|
||||||
status_t sgw_context_init()
|
status_t sgw_context_init()
|
||||||
{
|
{
|
||||||
d_assert(context_initialized == 0, return CORE_ERROR,
|
d_assert(context_initialized == 0, return CORE_ERROR,
|
||||||
|
@ -48,40 +29,340 @@ status_t sgw_context_init()
|
||||||
index_init(&sgw_bearer_pool, MAX_NUM_OF_UE_BEARER);
|
index_init(&sgw_bearer_pool, MAX_NUM_OF_UE_BEARER);
|
||||||
list_init(&self.sess_list);
|
list_init(&self.sess_list);
|
||||||
|
|
||||||
self.sgw_addr = inet_addr(g_sgw_s11_ip_addr);
|
|
||||||
|
|
||||||
/* S11 address and port of SGW */
|
|
||||||
self.s11_addr = inet_addr(g_sgw_s11_ip_addr);
|
|
||||||
self.s11_port = g_sgw_s11_port;
|
|
||||||
|
|
||||||
/* FIXME : It shoud be removed : Peer MME ? */
|
|
||||||
self.s11_node.addr = inet_addr(g_mme_ip_addr);
|
|
||||||
self.s11_node.port = g_mme_gtp_c_port;
|
|
||||||
list_init(&self.s11_node.local_list);
|
list_init(&self.s11_node.local_list);
|
||||||
list_init(&self.s11_node.remote_list);
|
list_init(&self.s11_node.remote_list);
|
||||||
|
|
||||||
/* S5C address and port of SGW */
|
|
||||||
self.s5c_addr = inet_addr(g_sgw_s5c_ip_addr);
|
|
||||||
self.s5c_port = g_sgw_s5c_port;
|
|
||||||
|
|
||||||
/* FIXME : It shoud be removed : Peer PGW ? */
|
|
||||||
self.s5c_node.addr = inet_addr(g_pgw_ip_addr);
|
|
||||||
self.s5c_node.port = g_pgw_s5c_port;
|
|
||||||
list_init(&self.s5c_node.local_list);
|
list_init(&self.s5c_node.local_list);
|
||||||
list_init(&self.s5c_node.remote_list);
|
list_init(&self.s5c_node.remote_list);
|
||||||
|
|
||||||
/* S1U address and port of SGW */
|
|
||||||
self.s1u_addr = inet_addr(g_sgw_s1u_ip_addr);
|
|
||||||
self.s1u_port = g_sgw_s1u_port;
|
|
||||||
|
|
||||||
self.s5u_addr = inet_addr(g_sgw_s5u_ip_addr);
|
|
||||||
self.s5u_port = g_sgw_s5u_port;
|
|
||||||
|
|
||||||
context_initialized = 1;
|
context_initialized = 1;
|
||||||
|
|
||||||
return CORE_OK;
|
return CORE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static status_t sgw_context_prepare()
|
||||||
|
{
|
||||||
|
self.s11_port = GTPV2_C_UDP_PORT;
|
||||||
|
self.s11_node.port = GTPV2_C_UDP_PORT;
|
||||||
|
|
||||||
|
self.s5c_port = GTPV2_C_UDP_PORT;
|
||||||
|
self.s5c_node.port = GTPV2_C_UDP_PORT;
|
||||||
|
|
||||||
|
self.s1u_port = GTPV1_U_UDP_PORT;
|
||||||
|
self.s5u_port = GTPV1_U_UDP_PORT;
|
||||||
|
|
||||||
|
return CORE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static status_t sgw_context_validation()
|
||||||
|
{
|
||||||
|
if (self.s11_node.addr == 0)
|
||||||
|
{
|
||||||
|
d_error("No MME.NEWORK.S11_ADDR in '%s'",
|
||||||
|
context_self()->config.path);
|
||||||
|
return CORE_ERROR;
|
||||||
|
}
|
||||||
|
if (self.s5c_node.addr == 0)
|
||||||
|
{
|
||||||
|
d_error("No PGW.NEWORK.S5C_ADDR in '%s'",
|
||||||
|
context_self()->config.path);
|
||||||
|
return CORE_ERROR;
|
||||||
|
}
|
||||||
|
if (self.s11_addr == 0)
|
||||||
|
{
|
||||||
|
d_error("No SGW.NEWORK.S11_ADDR in '%s'",
|
||||||
|
context_self()->config.path);
|
||||||
|
return CORE_ERROR;
|
||||||
|
}
|
||||||
|
if (self.s5c_addr == 0)
|
||||||
|
{
|
||||||
|
d_error("No SGW.NEWORK.S5C_ADDR in '%s'",
|
||||||
|
context_self()->config.path);
|
||||||
|
return CORE_ERROR;
|
||||||
|
}
|
||||||
|
if (self.s1u_addr == 0)
|
||||||
|
{
|
||||||
|
d_error("No SGW.NEWORK.S1U_ADDR in '%s'",
|
||||||
|
context_self()->config.path);
|
||||||
|
return CORE_ERROR;
|
||||||
|
}
|
||||||
|
if (self.s5u_addr == 0)
|
||||||
|
{
|
||||||
|
d_error("No SGW.NEWORK.S5U_ADDR in '%s'",
|
||||||
|
context_self()->config.path);
|
||||||
|
return CORE_ERROR;
|
||||||
|
}
|
||||||
|
return CORE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t sgw_context_parse_config()
|
||||||
|
{
|
||||||
|
status_t rv;
|
||||||
|
config_t *config = &context_self()->config;
|
||||||
|
|
||||||
|
char *json = config->json;
|
||||||
|
jsmntok_t *token = config->token;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
START, ROOT,
|
||||||
|
MME_START, MME_ROOT,
|
||||||
|
SGW_START, SGW_ROOT,
|
||||||
|
PGW_START, PGW_ROOT,
|
||||||
|
SKIP, STOP
|
||||||
|
} parse_state;
|
||||||
|
parse_state state = START;
|
||||||
|
parse_state stack = STOP;
|
||||||
|
|
||||||
|
size_t root_tokens = 0;
|
||||||
|
size_t mme_tokens = 0;
|
||||||
|
size_t sgw_tokens = 0;
|
||||||
|
size_t pgw_tokens = 0;
|
||||||
|
size_t skip_tokens = 0;
|
||||||
|
int i, j, m, n;
|
||||||
|
int arr, size;
|
||||||
|
|
||||||
|
rv = sgw_context_prepare();
|
||||||
|
if (rv != CORE_OK) return rv;
|
||||||
|
|
||||||
|
for (i = 0, j = 1; j > 0; i++, j--)
|
||||||
|
{
|
||||||
|
jsmntok_t *t = &token[i];
|
||||||
|
|
||||||
|
j += t->size;
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case START:
|
||||||
|
{
|
||||||
|
state = ROOT;
|
||||||
|
root_tokens = t->size;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ROOT:
|
||||||
|
{
|
||||||
|
if (jsmntok_equal(json, t, "MME") == 0)
|
||||||
|
{
|
||||||
|
state = MME_START;
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t, "SGW") == 0)
|
||||||
|
{
|
||||||
|
state = SGW_START;
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t, "PGW") == 0)
|
||||||
|
{
|
||||||
|
state = PGW_START;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = SKIP;
|
||||||
|
stack = ROOT;
|
||||||
|
skip_tokens = t->size;
|
||||||
|
|
||||||
|
root_tokens--;
|
||||||
|
if (root_tokens == 0) state = STOP;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MME_START:
|
||||||
|
{
|
||||||
|
state = MME_ROOT;
|
||||||
|
mme_tokens = t->size;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MME_ROOT:
|
||||||
|
{
|
||||||
|
if (jsmntok_equal(json, t, "NETWORK") == 0)
|
||||||
|
{
|
||||||
|
m = 1;
|
||||||
|
size = 1;
|
||||||
|
|
||||||
|
if ((t+1)->type == JSMN_ARRAY)
|
||||||
|
{
|
||||||
|
m = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (arr = 0; arr < size; arr++)
|
||||||
|
{
|
||||||
|
for (n = 1; n > 0; m++, n--)
|
||||||
|
{
|
||||||
|
n += (t+m)->size;
|
||||||
|
|
||||||
|
if (jsmntok_equal(json, t+m, "S11_ADDR") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s11_node.addr = inet_addr(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S11_PORT") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s11_node.port = atoi(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state = SKIP;
|
||||||
|
stack = MME_ROOT;
|
||||||
|
skip_tokens = t->size;
|
||||||
|
|
||||||
|
mme_tokens--;
|
||||||
|
if (mme_tokens == 0) stack = ROOT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SGW_START:
|
||||||
|
{
|
||||||
|
state = SGW_ROOT;
|
||||||
|
sgw_tokens = t->size;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SGW_ROOT:
|
||||||
|
{
|
||||||
|
if (jsmntok_equal(json, t, "NETWORK") == 0)
|
||||||
|
{
|
||||||
|
m = 1;
|
||||||
|
size = 1;
|
||||||
|
|
||||||
|
if ((t+1)->type == JSMN_ARRAY)
|
||||||
|
{
|
||||||
|
m = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (arr = 0; arr < size; arr++)
|
||||||
|
{
|
||||||
|
for (n = 1; n > 0; m++, n--)
|
||||||
|
{
|
||||||
|
n += (t+m)->size;
|
||||||
|
|
||||||
|
if (jsmntok_equal(json, t+m, "S11_ADDR") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s11_addr = inet_addr(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S11_PORT") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s11_port = atoi(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S5C_ADDR") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s5c_addr = inet_addr(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S5C_PORT") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s5c_port = atoi(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S1U_ADDR") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s1u_addr = inet_addr(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S1U_PORT") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s1u_port = atoi(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S5U_ADDR") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s5u_addr = inet_addr(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S5U_PORT") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s5u_port = atoi(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state = SKIP;
|
||||||
|
stack = SGW_ROOT;
|
||||||
|
skip_tokens = t->size;
|
||||||
|
|
||||||
|
sgw_tokens--;
|
||||||
|
if (sgw_tokens == 0) stack = ROOT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PGW_START:
|
||||||
|
{
|
||||||
|
state = PGW_ROOT;
|
||||||
|
pgw_tokens = t->size;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PGW_ROOT:
|
||||||
|
{
|
||||||
|
if (jsmntok_equal(json, t, "NETWORK") == 0)
|
||||||
|
{
|
||||||
|
m = 1;
|
||||||
|
size = 1;
|
||||||
|
|
||||||
|
if ((t+1)->type == JSMN_ARRAY)
|
||||||
|
{
|
||||||
|
m = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (arr = 0; arr < size; arr++)
|
||||||
|
{
|
||||||
|
for (n = 1; n > 0; m++, n--)
|
||||||
|
{
|
||||||
|
n += (t+m)->size;
|
||||||
|
|
||||||
|
if (jsmntok_equal(json, t+m, "S5C_ADDR") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s5c_node.addr = inet_addr(v);
|
||||||
|
}
|
||||||
|
else if (jsmntok_equal(json, t+m, "S5C_PORT") == 0)
|
||||||
|
{
|
||||||
|
char *v = jsmntok_to_string(json, t+m+1);
|
||||||
|
if (v) self.s5c_node.port = atoi(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state = SKIP;
|
||||||
|
stack = PGW_ROOT;
|
||||||
|
skip_tokens = t->size;
|
||||||
|
|
||||||
|
pgw_tokens--;
|
||||||
|
if (pgw_tokens == 0) stack = ROOT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SKIP:
|
||||||
|
{
|
||||||
|
skip_tokens += t->size;
|
||||||
|
|
||||||
|
skip_tokens--;
|
||||||
|
if (skip_tokens == 0) state = stack;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case STOP:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
d_error("Failed to parse configuration in the state(%u)",
|
||||||
|
state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = sgw_context_validation();
|
||||||
|
if (rv != CORE_OK) return rv;
|
||||||
|
|
||||||
|
return CORE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
status_t sgw_context_final()
|
status_t sgw_context_final()
|
||||||
{
|
{
|
||||||
d_assert(context_initialized == 1, return CORE_ERROR,
|
d_assert(context_initialized == 1, return CORE_ERROR,
|
||||||
|
|
|
@ -90,6 +90,7 @@ typedef struct _sgw_bearer_t {
|
||||||
} sgw_bearer_t;
|
} sgw_bearer_t;
|
||||||
|
|
||||||
CORE_DECLARE(status_t) sgw_context_init(void);
|
CORE_DECLARE(status_t) sgw_context_init(void);
|
||||||
|
CORE_DECLARE(status_t) sgw_context_parse_config(void);
|
||||||
CORE_DECLARE(status_t) sgw_context_final(void);
|
CORE_DECLARE(status_t) sgw_context_final(void);
|
||||||
|
|
||||||
CORE_DECLARE(sgw_context_t*) sgw_self(void);
|
CORE_DECLARE(sgw_context_t*) sgw_self(void);
|
||||||
|
|
|
@ -16,6 +16,9 @@ status_t sgw_initialize()
|
||||||
rv = sgw_context_init();
|
rv = sgw_context_init();
|
||||||
if (rv != CORE_OK) return rv;
|
if (rv != CORE_OK) return rv;
|
||||||
|
|
||||||
|
rv = sgw_context_parse_config();
|
||||||
|
if (rv != CORE_OK) return rv;
|
||||||
|
|
||||||
rv = thread_create(&sgw_sm_thread, NULL, sgw_sm_main, NULL);
|
rv = thread_create(&sgw_sm_thread, NULL, sgw_sm_main, NULL);
|
||||||
if (rv != CORE_OK) return rv;
|
if (rv != CORE_OK) return rv;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue