[5GC/EPC] tested with concurrent 500 UEs (#949)

Fix the memory problem in many simulatneous connections test
This commit is contained in:
Sukchan Lee 2021-04-29 22:01:34 +09:00
parent 03e74c93e8
commit a58214da76
26 changed files with 205 additions and 146 deletions

View File

@ -375,7 +375,7 @@ $ ./build/tests/app/app ## Both 5G Core and EPC with ./build/configs/sample.yaml
```bash
$ sudo apt install curl
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
$ sudo apt install nodejs
```

View File

@ -71,9 +71,12 @@ static void recalculate_pool_size(void)
#define MAX_NUM_OF_TIMER 16
self.pool.timer = self.max.ue * MAX_NUM_OF_TIMER;
self.pool.message = self.max.ue;
self.pool.event = self.max.ue;
self.pool.packet = self.max.ue * OGS_MAX_NUM_OF_PACKET_BUFFER;
self.pool.nf = self.max.gnb;
self.pool.packet = self.max.ue * OGS_MAX_NUM_OF_PACKET_BUFFER;
#define MAX_NUM_OF_SOCKET 4 /* Num of socket per NF */
self.pool.socket = self.pool.nf * MAX_NUM_OF_SOCKET;
@ -89,11 +92,8 @@ static void recalculate_pool_size(void)
#define MAX_NUM_OF_SBI_MESSAGE 4 /* Num of HTTP(s) Request/Response per NF */
#define MAX_NUM_OF_NF_SUBSCRIPTION 4 /* Num of Subscription per NF */
self.pool.nf_service = self.pool.nf * MAX_NUM_OF_NF_SERVICE;
self.pool.sbi_message = self.pool.nf * MAX_NUM_OF_SBI_MESSAGE;
self.pool.nf_subscription = self.pool.nf * MAX_NUM_OF_NF_SUBSCRIPTION;
self.pool.event = self.max.ue;
#define MAX_CSMAP_POOL 128
self.pool.csmap = MAX_CSMAP_POOL; /* Num of TAI-LAI Mapping Table */

View File

@ -117,12 +117,13 @@ typedef struct ogs_app_context_s {
uint64_t tunnel;
uint64_t nf_service;
uint64_t nf_subscription;
uint64_t sbi_message;
uint64_t csmap;
uint64_t message;
uint64_t event;
uint64_t timer;
uint64_t socket;
uint64_t gtp_xact;
uint64_t gtp_node;

View File

@ -258,7 +258,7 @@ unsigned int ogs_hashfunc_default(const char *char_key, int *klen)
}
static ogs_hash_entry_t **find_entry(ogs_hash_t *ht,
const void *key, int klen, const void *val)
const void *key, int klen, const void *val, const char *file_line)
{
ogs_hash_entry_t **hep, *he;
unsigned int hash;
@ -283,7 +283,7 @@ static ogs_hash_entry_t **find_entry(ogs_hash_t *ht,
if ((he = ht->free) != NULL)
ht->free = he->next;
else
he = ogs_malloc(sizeof(*he));
he = ogs_malloc_debug(sizeof(*he), file_line);
he->next = NULL;
he->hash = hash;
he->key = key;
@ -294,7 +294,8 @@ static ogs_hash_entry_t **find_entry(ogs_hash_t *ht,
return hep;
}
void *ogs_hash_get(ogs_hash_t *ht, const void *key, int klen)
void *ogs_hash_get_debug(ogs_hash_t *ht,
const void *key, int klen, const char *file_line)
{
ogs_hash_entry_t *he;
@ -302,14 +303,15 @@ void *ogs_hash_get(ogs_hash_t *ht, const void *key, int klen)
ogs_assert(key);
ogs_assert(klen);
he = *find_entry(ht, key, klen, NULL);
he = *find_entry(ht, key, klen, NULL, file_line);
if (he)
return (void *)he->val;
else
return NULL;
}
void ogs_hash_set(ogs_hash_t *ht, const void *key, int klen, const void *val)
void ogs_hash_set_debug(ogs_hash_t *ht,
const void *key, int klen, const void *val, const char *file_line)
{
ogs_hash_entry_t **hep;
@ -317,7 +319,7 @@ void ogs_hash_set(ogs_hash_t *ht, const void *key, int klen, const void *val)
ogs_assert(key);
ogs_assert(klen);
hep = find_entry(ht, key, klen, val);
hep = find_entry(ht, key, klen, val, file_line);
if (*hep) {
if (!val) {
/* delete entry */
@ -338,8 +340,8 @@ void ogs_hash_set(ogs_hash_t *ht, const void *key, int klen, const void *val)
/* else key not present and val==NULL */
}
void *ogs_hash_get_or_set(ogs_hash_t *ht,
const void *key, int klen, const void *val)
void *ogs_hash_get_or_set_debug(ogs_hash_t *ht,
const void *key, int klen, const void *val, const char *file_line)
{
ogs_hash_entry_t **hep;
@ -347,7 +349,7 @@ void *ogs_hash_get_or_set(ogs_hash_t *ht,
ogs_assert(key);
ogs_assert(klen);
hep = find_entry(ht, key, klen, val);
hep = find_entry(ht, key, klen, val, file_line);
if (*hep) {
val = (*hep)->val;
/* check that the collision rate isn't too high */

View File

@ -54,10 +54,18 @@ ogs_hash_t *ogs_hash_make(void);
ogs_hash_t *ogs_hash_make_custom(ogs_hashfunc_t ogs_hash_func);
void ogs_hash_destroy(ogs_hash_t *ht);
void ogs_hash_set(ogs_hash_t *ht, const void *key, int klen, const void *val);
void *ogs_hash_get(ogs_hash_t *ht, const void *key, int klen);
void *ogs_hash_get_or_set(ogs_hash_t *ht,
const void *key, int klen, const void *val);
#define ogs_hash_set(ht, key, klen, val) \
ogs_hash_set_debug(ht, key, klen, val, OGS_FILE_LINE)
void ogs_hash_set_debug(ogs_hash_t *ht,
const void *key, int klen, const void *val, const char *file_line);
#define ogs_hash_get(ht, key, klen) \
ogs_hash_get_debug(ht, key, klen, OGS_FILE_LINE)
void *ogs_hash_get_debug(ogs_hash_t *ht,
const void *key, int klen, const char *file_line);
#define ogs_hash_get_or_set(ht, key, klen, val) \
ogs_hash_get_or_set_debug(ht, key, klen, val, OGS_FILE_LINE)
void *ogs_hash_get_or_set_debug(ogs_hash_t *ht,
const void *key, int klen, const void *val, const char *file_line);
ogs_hash_index_t *ogs_hash_first(ogs_hash_t *ht);
ogs_hash_index_t *ogs_hash_next(ogs_hash_index_t *hi);

View File

@ -202,6 +202,8 @@ static ogs_inline ogs_uint24_t ogs_htobe24(ogs_uint24_t x)
#define OGS_MAX_FILEPATH_LEN 256
#define OGS_MAX_IFNAME_LEN 32
#define OGS_FILE_LINE __FILE__ ":" OGS_STRINGIFY(__LINE__)
#ifdef __cplusplus
}
#endif

View File

@ -22,7 +22,7 @@
#undef OGS_LOG_DOMAIN
#define OGS_LOG_DOMAIN __ogs_mem_domain
void *ogs_malloc(size_t size)
void *ogs_malloc_debug(size_t size, const char *file_line)
{
size_t headroom = 0;
ogs_pkbuf_t *pkbuf = NULL;
@ -30,7 +30,7 @@ void *ogs_malloc(size_t size)
ogs_assert(size);
headroom = sizeof(ogs_pkbuf_t *);
pkbuf = ogs_pkbuf_alloc(NULL, headroom + size);
pkbuf = ogs_pkbuf_alloc_debug(NULL, headroom + size, file_line);
ogs_assert(pkbuf);
ogs_pkbuf_reserve(pkbuf, headroom);
memcpy(pkbuf->head, &pkbuf, headroom);
@ -54,18 +54,18 @@ void ogs_free(void *ptr)
ogs_pkbuf_free(pkbuf);
}
void *ogs_calloc(size_t nmemb, size_t size)
void *ogs_calloc_debug(size_t nmemb, size_t size, const char *file_line)
{
void *ptr = NULL;
ptr = ogs_malloc(nmemb * size);
ptr = ogs_malloc_debug(nmemb * size, file_line);
ogs_assert(ptr);
memset(ptr, 0, nmemb * size);
return ptr;
}
void *ogs_realloc(void *ptr, size_t size)
void *ogs_realloc_debug(void *ptr, size_t size, const char *file_line)
{
size_t headroom = 0;
ogs_pkbuf_t *pkbuf = NULL;
@ -89,7 +89,7 @@ void *ogs_realloc(void *ptr, size_t size)
if (size > (cluster->size - headroom)) {
void *new = NULL;
new = ogs_malloc(size);
new = ogs_malloc_debug(size, file_line);
ogs_assert(new);
memcpy(new, ptr, pkbuf->len);

View File

@ -44,10 +44,13 @@ extern "C" {
memcpy((__dST), (__sRC), sizeof(*(__sRC))*sizeof(uint8_t)); \
} while(0)
void *ogs_malloc(size_t size);
#define ogs_malloc(size) ogs_malloc_debug(size, OGS_FILE_LINE)
void *ogs_malloc_debug(size_t size, const char *file_line);
void ogs_free(void *ptr);
void *ogs_calloc(size_t nmemb, size_t size);
void *ogs_realloc(void *ptr, size_t size);
#define ogs_calloc(nmemb, size) ogs_calloc_debug(nmemb, size, OGS_FILE_LINE)
void *ogs_calloc_debug(size_t nmemb, size_t size, const char *file_line);
#define ogs_realloc(ptr, size) ogs_realloc_debug(ptr, size, OGS_FILE_LINE)
void *ogs_realloc_debug(void *ptr, size_t size, const char *file_line);
#ifdef __cplusplus
}

View File

@ -97,7 +97,7 @@ void ogs_pkbuf_default_init(ogs_pkbuf_config_t *config)
config->cluster_512_pool = 4096;
config->cluster_1024_pool = 1024;
config->cluster_2048_pool = 512;
config->cluster_8192_pool = 128;
config->cluster_8192_pool = 512;
config->cluster_big_pool = 8;
}
@ -143,11 +143,29 @@ ogs_pkbuf_pool_t *ogs_pkbuf_pool_create(ogs_pkbuf_config_t *config)
return pool;
}
#define ogs_pkbuf_pool_final(pool) do { \
if (((pool)->size != (pool)->avail)) { \
int i; \
ogs_error("%d in '%s[%d]' were not released.", \
(pool)->size - (pool)->avail, (pool)->name, (pool)->size); \
for (i = 0; i < (pool)->size; i++) { \
ogs_pkbuf_t *pkbuf = (pool)->index[i]; \
if (pkbuf) { \
ogs_log_print(OGS_LOG_ERROR, "SIZE[%d] is not freed. (%s)\n", \
pkbuf->len, pkbuf->file_line); \
} \
} \
} \
free((pool)->free); \
free((pool)->array); \
free((pool)->index); \
} while (0)
void ogs_pkbuf_pool_destroy(ogs_pkbuf_pool_t *pool)
{
ogs_assert(pool);
ogs_pool_final(&pool->pkbuf);
ogs_pkbuf_pool_final(&pool->pkbuf);
ogs_pool_final(&pool->cluster);
ogs_pool_final(&pool->cluster_128);
@ -163,7 +181,8 @@ void ogs_pkbuf_pool_destroy(ogs_pkbuf_pool_t *pool)
ogs_pool_free(&pkbuf_pool, pool);
}
ogs_pkbuf_t *ogs_pkbuf_alloc(ogs_pkbuf_pool_t *pool, unsigned int size)
ogs_pkbuf_t *ogs_pkbuf_alloc_debug(
ogs_pkbuf_pool_t *pool, unsigned int size, const char *file_line)
{
ogs_pkbuf_t *pkbuf = NULL;
ogs_cluster_t *cluster = NULL;
@ -199,6 +218,8 @@ ogs_pkbuf_t *ogs_pkbuf_alloc(ogs_pkbuf_pool_t *pool, unsigned int size)
pkbuf->tail = cluster->buffer;
pkbuf->end = cluster->buffer + size;
pkbuf->file_line = file_line; /* For debug */
pkbuf->pool = pool;
return pkbuf;

View File

@ -50,6 +50,8 @@ typedef struct ogs_pkbuf_s {
unsigned char *tail;
unsigned char *data;
unsigned char *end;
const char *file_line;
ogs_pkbuf_pool_t *pool;
} ogs_pkbuf_t;
@ -74,7 +76,10 @@ void ogs_pkbuf_default_destroy(void);
ogs_pkbuf_pool_t *ogs_pkbuf_pool_create(ogs_pkbuf_config_t *config);
void ogs_pkbuf_pool_destroy(ogs_pkbuf_pool_t *pool);
ogs_pkbuf_t *ogs_pkbuf_alloc(ogs_pkbuf_pool_t *pool, unsigned int size);
#define ogs_pkbuf_alloc(pool, size) \
ogs_pkbuf_alloc_debug(pool, size, OGS_FILE_LINE)
ogs_pkbuf_t *ogs_pkbuf_alloc_debug(
ogs_pkbuf_pool_t *pool, unsigned int size, const char *file_line);
void ogs_pkbuf_free(ogs_pkbuf_t *pkbuf);
void *ogs_pkbuf_put_data(

View File

@ -124,12 +124,6 @@ void ogs_pollset_remove(ogs_poll_t *poll)
ogs_pool_free(&pollset->pool, poll);
}
ogs_poll_t *ogs_pollset_cycle(ogs_pollset_t *pollset, ogs_poll_t *poll)
{
ogs_assert(pollset);
return ogs_pool_cycle(&pollset->pool, poll);
}
void *ogs_pollset_self_handler_data(void)
{
return &self_handler_data;

View File

@ -40,7 +40,6 @@ ogs_poll_t *ogs_pollset_add(ogs_pollset_t *pollset, short when,
ogs_socket_t fd, ogs_poll_handler_f handler, void *data);
void ogs_pollset_remove(ogs_poll_t *poll);
ogs_poll_t *ogs_pollset_cycle(ogs_pollset_t *pollset, ogs_poll_t *poll);
void *ogs_pollset_self_handler_data(void);
typedef struct ogs_pollset_actions_s {

View File

@ -120,7 +120,7 @@ char *ogs_slprintf(char *str, char *last, const char *format, ...)
return r;
}
char *ogs_strdup(const char *s)
char *ogs_strdup_debug(const char *s, const char *file_line)
{
char *res;
size_t len;
@ -129,11 +129,11 @@ char *ogs_strdup(const char *s)
return NULL;
len = strlen(s) + 1;
res = ogs_memdup(s, len);
res = ogs_memdup_debug(s, len, file_line);
return res;
}
char *ogs_strndup(const char *s, size_t n)
char *ogs_strndup_debug(const char *s, size_t n, const char *file_line)
{
char *res;
const char *end;
@ -144,20 +144,20 @@ char *ogs_strndup(const char *s, size_t n)
end = memchr(s, '\0', n);
if (end != NULL)
n = end - s;
res = ogs_malloc(n + 1);
res = ogs_malloc_debug(n + 1, file_line);
memcpy(res, s, n);
res[n] = '\0';
return res;
}
void *ogs_memdup(const void *m, size_t n)
void *ogs_memdup_debug(const void *m, size_t n, const char *file_line)
{
void *res;
if (m == NULL)
return NULL;
res = ogs_malloc(n);
res = ogs_malloc_debug(n, file_line);
memcpy(res, m, n);
return res;
}
@ -195,7 +195,7 @@ char *ogs_cpystrn(char *dst, const char *src, size_t dst_size)
*
* https://github.com/babelouest/orcania.git
*/
char *ogs_msprintf(const char *message, ...)
char *ogs_msprintf_debug(const char *file_line, const char *message, ...)
{
va_list argp, argp_cpy;
size_t out_len = 0;
@ -206,7 +206,7 @@ char *ogs_msprintf(const char *message, ...)
in some architectures,
vsnprintf can modify argp */
out_len = vsnprintf(NULL, 0, message, argp);
out = ogs_malloc(out_len + sizeof(char));
out = ogs_malloc_debug(out_len + sizeof(char), file_line);
if (out == NULL) {
va_end(argp);
va_end(argp_cpy);
@ -219,7 +219,8 @@ char *ogs_msprintf(const char *message, ...)
return out;
}
char *ogs_mstrcatf(char *source, const char *message, ...)
char *ogs_mstrcatf_debug(
char *source, const char *file_line, const char *message, ...)
{
va_list argp, argp_cpy;
char *out = NULL, *message_formatted = NULL;
@ -236,7 +237,8 @@ char *ogs_mstrcatf(char *source, const char *message, ...)
if (message_formatted != NULL) {
vsnprintf(message_formatted,
(message_formatted_len+sizeof(char)), message, argp_cpy);
out = ogs_msprintf("%s%s", source, message_formatted);
out = ogs_msprintf_debug(
file_line, "%s%s", source, message_formatted);
ogs_free(message_formatted);
ogs_free(source);
}
@ -248,7 +250,7 @@ char *ogs_mstrcatf(char *source, const char *message, ...)
in some architectures,
vsnprintf can modify argp */
out_len = vsnprintf(NULL, 0, message, argp);
out = ogs_malloc(out_len+sizeof(char));
out = ogs_malloc_debug(out_len+sizeof(char), file_line);
if (out != NULL) {
vsnprintf(out, (out_len+sizeof(char)), message, argp_cpy);
}

View File

@ -75,9 +75,12 @@ char *ogs_vslprintf(char *str, char *last, const char *format, va_list ap)
char *ogs_slprintf(char *str, char *last, const char *format, ...)
OGS_GNUC_PRINTF(3, 4);
char *ogs_strdup(const char *s);
char *ogs_strndup(const char *s, size_t n);
void *ogs_memdup(const void *m, size_t n);
#define ogs_strdup(s) ogs_strdup_debug(s, OGS_FILE_LINE)
char *ogs_strdup_debug(const char *s, const char *file_line);
#define ogs_strndup(s, n) ogs_strndup_debug(s, n, OGS_FILE_LINE)
char *ogs_strndup_debug(const char *s, size_t n, const char *file_line);
#define ogs_memdup(m, n) ogs_memdup_debug(m, n, OGS_FILE_LINE)
void *ogs_memdup_debug(const void *m, size_t n, const char *file_line);
char *ogs_cpystrn(char *dst, const char *src, size_t dst_size);
@ -91,10 +94,14 @@ char *ogs_cpystrn(char *dst, const char *src, size_t dst_size);
*
* https://github.com/babelouest/orcania.git
*/
char *ogs_msprintf(const char *message, ...)
OGS_GNUC_PRINTF(1, 2);
char *ogs_mstrcatf(char *source, const char *message, ...)
#define ogs_msprintf(...) ogs_msprintf_debug(OGS_FILE_LINE, __VA_ARGS__)
char *ogs_msprintf_debug(const char *file_line, const char *message, ...)
OGS_GNUC_PRINTF(2, 3);
#define ogs_mstrcatf(source, ...) \
ogs_mstrcatf_debug(source, OGS_FILE_LINE, __VA_ARGS__)
char *ogs_mstrcatf_debug(
char *source, const char *file_line, const char *message, ...)
OGS_GNUC_PRINTF(3, 4);
char *ogs_trimwhitespace(char *str);

View File

@ -40,8 +40,7 @@ void ogs_sbi_context_init(void)
ogs_log_install_domain(&__ogs_sbi_domain, "sbi", ogs_core()->log.level);
ogs_sbi_message_init(
ogs_app()->pool.sbi_message, ogs_app()->pool.sbi_message);
ogs_sbi_message_init(ogs_app()->pool.message, ogs_app()->pool.message);
ogs_sbi_server_init(ogs_app()->pool.nf, ogs_app()->pool.event);
ogs_sbi_client_init(ogs_app()->pool.event, ogs_app()->pool.event);
@ -49,7 +48,7 @@ void ogs_sbi_context_init(void)
ogs_pool_init(&nf_instance_pool, ogs_app()->pool.nf);
ogs_pool_init(&nf_service_pool, ogs_app()->pool.nf_service);
ogs_pool_init(&xact_pool, ogs_app()->pool.sbi_message);
ogs_pool_init(&xact_pool, ogs_app()->pool.message);
ogs_list_init(&self.subscription_list);
ogs_pool_init(&subscription_pool, ogs_app()->pool.nf_subscription);

View File

@ -579,16 +579,6 @@ int ogs_sbi_parse_response(
return OGS_OK;
}
void ogs_sbi_header_set(ogs_hash_t *ht, const void *key, const void *val)
{
ogs_hash_set(ht, key, strlen(key), ogs_strdup(val));
}
void *ogs_sbi_header_get(ogs_hash_t *ht, const void *key)
{
return ogs_hash_get(ht, key, strlen(key));
}
ogs_pkbuf_t *ogs_sbi_find_part_by_content_id(
ogs_sbi_message_t *message, char *content_id)
{
@ -1568,12 +1558,13 @@ static void build_content(
http->content = build_json(message);
if (http->content) {
http->content_length = strlen(http->content);
if (message->http.content_type)
if (message->http.content_type) {
ogs_sbi_header_set(http->headers,
OGS_SBI_CONTENT_TYPE, message->http.content_type);
else
} else {
ogs_sbi_header_set(http->headers,
OGS_SBI_CONTENT_TYPE, OGS_SBI_CONTENT_JSON_TYPE);
}
}
}
}
@ -1874,7 +1865,9 @@ static void http_message_free(ogs_sbi_http_message_t *http)
if (http->params) {
ogs_hash_index_t *hi;
for (hi = ogs_hash_first(http->params); hi; hi = ogs_hash_next(hi)) {
char *key = (char *)ogs_hash_this_key(hi);
char *val = ogs_hash_this_val(hi);
ogs_free(key);
ogs_free(val);
}
ogs_hash_destroy(http->params);
@ -1883,7 +1876,9 @@ static void http_message_free(ogs_sbi_http_message_t *http)
if (http->headers) {
ogs_hash_index_t *hi;
for (hi = ogs_hash_first(http->headers); hi; hi = ogs_hash_next(hi)) {
char *key = (char *)ogs_hash_this_key(hi);
char *val = ogs_hash_this_val(hi);
ogs_free(key);
ogs_free(val);
}
ogs_hash_destroy(http->headers);

View File

@ -403,8 +403,10 @@ ogs_sbi_response_t *ogs_sbi_build_response(
int ogs_sbi_parse_response(
ogs_sbi_message_t *message, ogs_sbi_response_t *response);
void ogs_sbi_header_set(ogs_hash_t *ht, const void *key, const void *val);
void *ogs_sbi_header_get(ogs_hash_t *ht, const void *key);
#define ogs_sbi_header_set(ht, key, val) \
ogs_hash_set(ht, ogs_strdup(key), strlen(key), ogs_strdup(val))
#define ogs_sbi_header_get(ht, key) \
ogs_hash_get(ht, key, strlen(key))
ogs_pkbuf_t *ogs_sbi_find_part_by_content_id(
ogs_sbi_message_t *message, char *content_id);

View File

@ -402,7 +402,7 @@ static void notify_connection(void *cls,
*socket_context = poll.read;
break;
case MHD_CONNECTION_NOTIFY_CLOSED:
poll.read = ogs_pollset_cycle(ogs_app()->pollset, *socket_context);
poll.read = *socket_context;
if (poll.read)
ogs_pollset_remove(poll.read);
break;
@ -535,12 +535,10 @@ static void notify_completed(
enum MHD_RequestTerminationCode toe)
{
ogs_sbi_request_t *request = *con_cls;
ogs_poll_t *poll = NULL;
ogs_assert(request);
poll = ogs_pollset_cycle(ogs_app()->pollset, request->poll.write);
if (poll)
ogs_pollset_remove(poll);
if (request->poll.write)
ogs_pollset_remove(request->poll.write);
ogs_sbi_request_free(request);
}

View File

@ -464,7 +464,6 @@ static ogs_sbi_session_t *session_add(
static void session_remove(ogs_sbi_session_t *sbi_sess)
{
ogs_sbi_server_t *server = NULL;
ogs_poll_t *poll = NULL;
ogs_pkbuf_t *pkbuf = NULL, *next_pkbuf = NULL;
ogs_assert(sbi_sess);
@ -475,13 +474,11 @@ static void session_remove(ogs_sbi_session_t *sbi_sess)
stream_remove_all(sbi_sess);
poll = ogs_pollset_cycle(ogs_app()->pollset, sbi_sess->poll.read);
ogs_assert(poll);
ogs_pollset_remove(poll);
ogs_assert(sbi_sess->poll.read);
ogs_pollset_remove(sbi_sess->poll.read);
poll = ogs_pollset_cycle(ogs_app()->pollset, sbi_sess->poll.write);
if (poll)
ogs_pollset_remove(poll);
if (sbi_sess->poll.write)
ogs_pollset_remove(sbi_sess->poll.write);
ogs_list_for_each_safe(&sbi_sess->write_queue, next_pkbuf, pkbuf)
ogs_pkbuf_free(pkbuf);
@ -1236,6 +1233,7 @@ static void session_write_callback(short when, ogs_socket_t fd, void *data)
if (ogs_list_empty(&sbi_sess->write_queue) == true) {
ogs_assert(sbi_sess->poll.write);
ogs_pollset_remove(sbi_sess->poll.write);
sbi_sess->poll.write = NULL;
return;
}
@ -1255,8 +1253,6 @@ static void session_write_to_buffer(
ogs_sock_t *sock = NULL;
ogs_socket_t fd = INVALID_SOCKET;
ogs_poll_t *poll = NULL;
ogs_assert(pkbuf);
ogs_assert(sbi_sess);
@ -1267,8 +1263,7 @@ static void session_write_to_buffer(
ogs_list_add(&sbi_sess->write_queue, pkbuf);
poll = ogs_pollset_cycle(ogs_app()->pollset, sbi_sess->poll.write);
if (!poll)
if (!sbi_sess->poll.write)
sbi_sess->poll.write = ogs_pollset_add(ogs_app()->pollset,
OGS_POLLOUT, fd, session_write_callback, sbi_sess);
}

View File

@ -146,9 +146,18 @@ static void *internal_realloc(void *pointer, size_t size)
#endif
#else
#include "ogs-core.h"
#define internal_malloc ogs_malloc
#define internal_free ogs_free
#define internal_realloc ogs_realloc
static void *internal_malloc(size_t size)
{
return ogs_malloc(size);
}
static void internal_free(void *pointer)
{
ogs_free(pointer);
}
static void *internal_realloc(void *pointer, size_t size)
{
return ogs_realloc(pointer, size);
}
#endif
static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc };

View File

@ -76,15 +76,12 @@ int ogs_sctp_senddata(ogs_sock_t *sock,
void ogs_sctp_write_to_buffer(ogs_sctp_sock_t *sctp, ogs_pkbuf_t *pkbuf)
{
ogs_poll_t *poll = NULL;
ogs_assert(sctp);
ogs_assert(pkbuf);
ogs_list_add(&sctp->write_queue, pkbuf);
poll = ogs_pollset_cycle(ogs_app()->pollset, sctp->poll.write);
if (!poll) {
if (!sctp->poll.write) {
ogs_assert(sctp->sock);
sctp->poll.write = ogs_pollset_add(ogs_app()->pollset,
OGS_POLLOUT, sctp->sock->fd, sctp_write_callback, sctp);
@ -100,6 +97,7 @@ static void sctp_write_callback(short when, ogs_socket_t fd, void *data)
if (ogs_list_empty(&sctp->write_queue) == true) {
ogs_assert(sctp->poll.write);
ogs_pollset_remove(sctp->poll.write);
sctp->poll.write = NULL;
return;
}
@ -113,7 +111,6 @@ static void sctp_write_callback(short when, ogs_socket_t fd, void *data)
void ogs_sctp_flush_and_destroy(ogs_sctp_sock_t *sctp)
{
ogs_poll_t *poll = NULL;
ogs_pkbuf_t *pkbuf = NULL, *next_pkbuf = NULL;
ogs_assert(sctp);
@ -122,13 +119,11 @@ void ogs_sctp_flush_and_destroy(ogs_sctp_sock_t *sctp)
ogs_free(sctp->addr);
if (sctp->type == SOCK_STREAM) {
poll = ogs_pollset_cycle(ogs_app()->pollset, sctp->poll.read);
ogs_assert(poll);
ogs_pollset_remove(poll);
ogs_assert(sctp->poll.read);
ogs_pollset_remove(sctp->poll.read);
poll = ogs_pollset_cycle(ogs_app()->pollset, sctp->poll.write);
if (poll)
ogs_pollset_remove(poll);
if (sctp->poll.write)
ogs_pollset_remove(sctp->poll.write);
ogs_sctp_destroy(sctp->sock);

View File

@ -68,6 +68,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
int state = AMF_CREATE_SM_CONTEXT_NO_STATE;
ogs_sbi_stream_t *stream = NULL;
ogs_sbi_request_t *sbi_request = NULL;
OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL;
ogs_sbi_nf_instance_t *nf_instance = NULL;
ogs_sbi_subscription_t *subscription = NULL;
@ -345,17 +346,21 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
amf_ue = (amf_ue_t *)sbi_xact->sbi_object;
ogs_assert(amf_ue);
amf_ue = amf_ue_cycle(amf_ue);
ogs_assert(amf_ue);
ogs_assert(OGS_FSM_STATE(&amf_ue->sm));
e->amf_ue = amf_ue;
e->sbi.message = &sbi_message;;
ogs_sbi_xact_remove(sbi_xact);
ogs_fsm_dispatch(&amf_ue->sm, e);
amf_ue = amf_ue_cycle(amf_ue);
if (amf_ue) {
ogs_assert(OGS_FSM_STATE(&amf_ue->sm));
e->amf_ue = amf_ue;
e->sbi.message = &sbi_message;;
ogs_fsm_dispatch(&amf_ue->sm, e);
} else {
ogs_error("UE(amf_ue) Context has already been removed");
}
break;
CASE(OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION)
@ -364,6 +369,11 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
sess = (amf_sess_t *)sbi_xact->sbi_object;
ogs_assert(sess);
state = sbi_xact->state;
ogs_sbi_xact_remove(sbi_xact);
sess = amf_sess_cycle(sess);
/*
@ -401,10 +411,6 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
e->sess = sess;
e->sbi.message = &sbi_message;;
state = sbi_xact->state;
ogs_sbi_xact_remove(sbi_xact);
SWITCH(sbi_message.h.resource.component[2])
CASE(OGS_SBI_RESOURCE_NAME_MODIFY)
amf_nsmf_pdusession_handle_update_sm_context(
@ -460,6 +466,11 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
sess = (amf_sess_t *)sbi_xact->sbi_object;
ogs_assert(sess);
state = sbi_xact->state;
ogs_sbi_xact_remove(sbi_xact);
sess = amf_sess_cycle(sess);
ogs_assert(sess);
@ -474,10 +485,6 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
e->sess = sess;
e->sbi.message = &sbi_message;;
state = sbi_xact->state;
ogs_sbi_xact_remove(sbi_xact);
amf_nnssf_nsselection_handle_get(sess, &sbi_message);
break;
@ -527,6 +534,10 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
sbi_object = sbi_xact->sbi_object;
ogs_assert(sbi_object);
target_nf_type = sbi_xact->target_nf_type;
ogs_sbi_xact_remove(sbi_xact);
ogs_assert(sbi_object->type > OGS_SBI_OBJ_BASE &&
sbi_object->type < OGS_SBI_OBJ_TOP);
@ -556,12 +567,9 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e)
default:
ogs_fatal("Not implemented [%s:%d]",
OpenAPI_nf_type_ToString(sbi_xact->target_nf_type),
sbi_object->type);
OpenAPI_nf_type_ToString(target_nf_type), sbi_object->type);
ogs_assert_if_reached();
}
ogs_sbi_xact_remove(sbi_xact);
break;
default:

View File

@ -273,15 +273,17 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e)
ausf_ue = (ausf_ue_t *)sbi_xact->sbi_object;
ogs_assert(ausf_ue);
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
ausf_ue = ausf_ue_cycle(ausf_ue);
ogs_assert(ausf_ue);
ogs_assert(OGS_FSM_STATE(&ausf_ue->sm));
e->ausf_ue = ausf_ue;
e->sbi.message = &message;
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
ogs_fsm_dispatch(&ausf_ue->sm, e);
if (OGS_FSM_CHECK(&ausf_ue->sm, ausf_ue_state_exception)) {

View File

@ -49,6 +49,8 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e)
ogs_sbi_object_t *sbi_object = NULL;
ogs_sbi_xact_t *sbi_xact = NULL;
OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL;
pcf_ue_t *pcf_ue = NULL;
pcf_sess_t *sess = NULL;
@ -318,14 +320,16 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e)
pcf_ue = (pcf_ue_t *)sbi_xact->sbi_object;
ogs_assert(pcf_ue);
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
pcf_ue = pcf_ue_cycle(pcf_ue);
ogs_assert(pcf_ue);
e->pcf_ue = pcf_ue;
e->sbi.message = &message;
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
ogs_fsm_dispatch(&pcf_ue->sm, e);
if (OGS_FSM_CHECK(&pcf_ue->sm, pcf_am_state_exception)) {
@ -340,6 +344,11 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e)
sess = (pcf_sess_t *)sbi_xact->sbi_object;
ogs_assert(sess);
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
sess = pcf_sess_cycle(sess);
ogs_assert(sess);
@ -350,9 +359,6 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e)
e->sess = sess;
e->sbi.message = &message;
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
ogs_fsm_dispatch(&sess->sm, e);
if (OGS_FSM_CHECK(&sess->sm, pcf_am_state_exception)) {
@ -421,6 +427,14 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e)
sbi_object = sbi_xact->sbi_object;
ogs_assert(sbi_object);
stream = sbi_xact->assoc_stream;
ogs_assert(stream);
target_nf_type = sbi_xact->target_nf_type;
ogs_sbi_xact_remove(sbi_xact);
ogs_assert(sbi_object->type > OGS_SBI_OBJ_BASE &&
sbi_object->type < OGS_SBI_OBJ_TOP);
@ -439,16 +453,10 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e)
default:
ogs_fatal("Not implemented [%s:%d]",
OpenAPI_nf_type_ToString(sbi_xact->target_nf_type),
sbi_object->type);
OpenAPI_nf_type_ToString(target_nf_type), sbi_object->type);
ogs_assert_if_reached();
}
stream = sbi_xact->assoc_stream;
ogs_assert(stream);
ogs_sbi_xact_remove(sbi_xact);
ogs_error("Cannot receive SBI message");
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL,

View File

@ -518,6 +518,12 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e)
sess = (smf_sess_t *)sbi_xact->sbi_object;
ogs_assert(sess);
e->sbi.data = sbi_xact->assoc_stream;
e->sbi.state = sbi_xact->state;
ogs_sbi_xact_remove(sbi_xact);
sess = smf_sess_cycle(sess);
ogs_assert(sess);
smf_ue = sess->smf_ue;
@ -528,10 +534,6 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e)
e->sess = sess;
e->sbi.message = &sbi_message;
e->sbi.data = sbi_xact->assoc_stream;
e->sbi.state = sbi_xact->state;
ogs_sbi_xact_remove(sbi_xact);
ogs_fsm_dispatch(&sess->sm, e);
if (OGS_FSM_CHECK(&sess->sm, smf_gsm_state_exception)) {

View File

@ -302,14 +302,16 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e)
udm_ue = (udm_ue_t *)sbi_xact->sbi_object;
ogs_assert(udm_ue);
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
udm_ue = udm_ue_cycle(udm_ue);
ogs_assert(udm_ue);
e->udm_ue = udm_ue;
e->sbi.message = &message;
e->sbi.data = sbi_xact->assoc_stream;
ogs_sbi_xact_remove(sbi_xact);
ogs_fsm_dispatch(&udm_ue->sm, e);
if (OGS_FSM_CHECK(&udm_ue->sm, udm_ue_state_exception)) {