open5gs/src/pgw/pgw_context.c

218 lines
4.4 KiB
C
Raw Normal View History

2017-04-06 11:44:52 +00:00
#define TRACE_MODULE _pgw_context
2017-03-30 15:15:13 +00:00
#include "core_debug.h"
#include "core_pool.h"
#include "core_index.h"
#include "gtp_path.h"
2017-04-06 10:20:33 +00:00
#include "pgw_context.h"
2017-04-04 02:26:59 +00:00
2017-04-06 11:44:52 +00:00
static pgw_context_t self;
2017-03-30 15:15:13 +00:00
2017-04-11 09:59:10 +00:00
index_declare(pgw_sess_pool, pgw_sess_t, MAX_NUM_OF_UE);
2017-04-12 04:45:57 +00:00
pool_declare(pgw_pdn_pool, pdn_t, MAX_NUM_OF_UE_PDN);
2017-04-06 14:29:20 +00:00
2017-04-06 12:44:30 +00:00
static int context_initiaized = 0;
2017-03-30 15:15:13 +00:00
2017-04-06 11:44:52 +00:00
status_t pgw_context_init()
2017-03-30 15:15:13 +00:00
{
2017-04-06 12:44:30 +00:00
d_assert(context_initiaized == 0, return CORE_ERROR,
2017-03-30 15:15:13 +00:00
"MME context already has been initialized");
2017-04-06 11:44:52 +00:00
memset(&self, 0, sizeof(pgw_context_t));
2017-03-30 15:15:13 +00:00
2017-04-11 09:59:10 +00:00
index_init(&pgw_sess_pool, MAX_NUM_OF_UE);
list_init(&self.sess_list);
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
pool_init(&pgw_pdn_pool, MAX_NUM_OF_UE_PDN);
2017-03-30 15:15:13 +00:00
self.s5c_addr = inet_addr("127.0.0.1");
self.s5c_port = GTPV2_C_UDP_PORT + 3;
self.s5c_node.addr = inet_addr("127.0.0.1");
self.s5c_node.port = GTPV2_C_UDP_PORT + 2;
2017-04-03 06:31:57 +00:00
list_init(&self.s5c_node.local_list);
list_init(&self.s5c_node.remote_list);
2017-03-30 15:15:13 +00:00
self.s5u_addr = inet_addr("127.0.0.1");
self.s5u_port = GTPV1_U_UDP_PORT + 1;
self.s5u_node.addr = inet_addr("127.0.0.1");
self.s5u_node.port = GTPV1_U_UDP_PORT;
2017-04-06 12:44:30 +00:00
context_initiaized = 1;
2017-03-30 15:15:13 +00:00
return CORE_OK;
}
2017-04-06 11:44:52 +00:00
status_t pgw_context_final()
2017-03-30 15:15:13 +00:00
{
2017-04-06 12:44:30 +00:00
d_assert(context_initiaized == 1, return CORE_ERROR,
2017-03-30 15:15:13 +00:00
"HyperCell context already has been finalized");
2017-04-11 13:44:57 +00:00
gtp_xact_delete_all(&self.s5c_node);
pgw_sess_remove_all();
2017-04-08 01:50:29 +00:00
d_print("%d not freed in pgw_sess_pool[%d] in PGW-Context\n",
2017-04-11 09:59:10 +00:00
index_size(&pgw_sess_pool) - pool_avail(&pgw_sess_pool),
index_size(&pgw_sess_pool));
2017-04-12 01:05:23 +00:00
2017-04-11 09:59:10 +00:00
index_final(&pgw_sess_pool);
2017-04-12 01:05:23 +00:00
pool_final(&pgw_pdn_pool);
2017-04-06 14:29:20 +00:00
2017-04-06 12:44:30 +00:00
context_initiaized = 0;
2017-03-30 15:15:13 +00:00
return CORE_OK;
}
2017-04-06 11:44:52 +00:00
pgw_context_t* pgw_self()
2017-03-30 15:15:13 +00:00
{
return &self;
}
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
pgw_sess_t *pgw_sess_add()
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
pgw_sess_t *sess = NULL;
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
index_alloc(&pgw_sess_pool, &sess);
d_assert(sess, return NULL, "Null param");
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
sess->teid = sess->index; /* derived from an index */
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
list_init(&sess->pdn_list);
list_append(&self.sess_list, sess);
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
return sess;
2017-04-12 01:05:23 +00:00
}
2017-04-12 04:45:57 +00:00
status_t pgw_sess_remove(pgw_sess_t *sess)
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
d_assert(sess, return CORE_ERROR, "Null param");
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
pgw_pdn_remove_all(sess);
list_remove(&self.sess_list, sess);
index_free(&pgw_sess_pool, sess);
2017-04-12 01:05:23 +00:00
return CORE_OK;
}
2017-04-12 04:45:57 +00:00
status_t pgw_sess_remove_all()
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
pgw_sess_t *enb = NULL, *next_enb = NULL;
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
enb = pgw_sess_first();
while (enb)
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
next_enb = pgw_sess_next(enb);
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
pgw_sess_remove(enb);
2017-04-12 01:05:23 +00:00
2017-04-12 04:45:57 +00:00
enb = next_enb;
2017-04-12 01:05:23 +00:00
}
return CORE_OK;
}
2017-04-12 04:45:57 +00:00
pgw_sess_t* pgw_sess_find(index_t index)
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
d_assert(index, return NULL, "Invalid Index");
return index_find(&pgw_sess_pool, index);
2017-04-12 01:05:23 +00:00
}
2017-04-12 04:45:57 +00:00
pgw_sess_t* pgw_sess_find_by_teid(c_uint32_t teid)
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
return pgw_sess_find(teid);
2017-04-12 01:05:23 +00:00
}
2017-04-12 04:45:57 +00:00
pgw_sess_t* pgw_sess_first()
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
return list_first(&self.sess_list);
2017-04-12 01:05:23 +00:00
}
2017-04-12 04:45:57 +00:00
pgw_sess_t* pgw_sess_next(pgw_sess_t *enb)
2017-04-12 01:05:23 +00:00
{
2017-04-12 04:45:57 +00:00
return list_next(enb);
2017-04-12 01:05:23 +00:00
}
2017-04-12 04:45:57 +00:00
pdn_t* pgw_pdn_add(pgw_sess_t *sess, c_int8_t *apn)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
pdn_t *pdn = NULL;
2017-04-06 14:29:20 +00:00
2017-04-08 01:50:29 +00:00
d_assert(sess, return NULL, "Null param");
2017-04-12 04:45:57 +00:00
d_assert(apn, return NULL, "Null param");
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
pool_alloc_node(&pgw_pdn_pool, &pdn);
d_assert(pdn, return NULL, "PDN context allocation failed");
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
memset(pdn, 0, sizeof(pdn_t));
strcpy(pdn->apn, apn);
pdn->context = sess;
list_append(&sess->pdn_list, pdn);
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
return pdn;
2017-04-06 14:29:20 +00:00
}
2017-04-12 04:45:57 +00:00
status_t pgw_pdn_remove(pdn_t *pdn)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
pgw_sess_t *sess = NULL;
d_assert(pdn, return CORE_ERROR, "Null param");
sess = pdn->context;
2017-04-08 01:50:29 +00:00
d_assert(sess, return CORE_ERROR, "Null param");
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
list_remove(&sess->pdn_list, pdn);
pool_free_node(&pgw_pdn_pool, pdn);
2017-04-06 14:29:20 +00:00
return CORE_OK;
}
2017-04-12 04:45:57 +00:00
status_t pgw_pdn_remove_all(pgw_sess_t *sess)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
pdn_t *pdn = NULL, *next_pdn = NULL;
d_assert(sess, return CORE_ERROR, "Null param");
2017-04-11 09:59:10 +00:00
2017-04-12 04:45:57 +00:00
pdn = list_first(&sess->pdn_list);
while (pdn)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
next_pdn = list_next(pdn);
2017-04-11 09:59:10 +00:00
2017-04-12 04:45:57 +00:00
pgw_pdn_remove(pdn);
2017-04-11 09:59:10 +00:00
2017-04-12 04:45:57 +00:00
pdn = next_pdn;
2017-04-06 14:29:20 +00:00
}
return CORE_OK;
}
2017-04-12 04:45:57 +00:00
pdn_t* pgw_pdn_find_by_apn(pgw_sess_t *sess, c_int8_t *apn)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
pdn_t *pdn = NULL;
d_assert(sess, return NULL, "Null param");
2017-04-06 14:29:20 +00:00
2017-04-12 04:45:57 +00:00
pdn = list_first(&sess->pdn_list);
while (pdn)
{
if (strcmp(pdn->apn, apn) == 0)
break;
pdn = list_next(pdn);
}
return pdn;
2017-04-06 14:29:20 +00:00
}
2017-04-12 04:45:57 +00:00
pdn_t* pgw_pdn_first(pgw_sess_t *sess)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
d_assert(sess, return NULL, "Null param");
return list_first(&sess->pdn_list);
2017-04-06 14:29:20 +00:00
}
2017-04-12 04:45:57 +00:00
pdn_t* pgw_pdn_next(pdn_t *pdn)
2017-04-06 14:29:20 +00:00
{
2017-04-12 04:45:57 +00:00
return list_next(pdn);
2017-04-06 14:29:20 +00:00
}
2017-04-12 04:45:57 +00:00