- Set the number of UEs in units of AMF/MME instead of gNB/eNB. - See default value as shown below Number of UEs per AMF/MME : 4,096 Number of gNB/eNB per AMF/MME : 32
250 lines
6.2 KiB
C
250 lines
6.2 KiB
C
/*
|
|
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
|
|
*
|
|
* This file is part of Open5GS.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "core-config-private.h"
|
|
|
|
#if HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
#include "ogs-core.h"
|
|
#include "ogs-poll-private.h"
|
|
|
|
static void epoll_init(ogs_pollset_t *pollset);
|
|
static void epoll_cleanup(ogs_pollset_t *pollset);
|
|
static int epoll_add(ogs_poll_t *poll);
|
|
static int epoll_remove(ogs_poll_t *poll);
|
|
static int epoll_process(ogs_pollset_t *pollset, ogs_time_t timeout);
|
|
|
|
const ogs_pollset_actions_t ogs_epoll_actions = {
|
|
epoll_init,
|
|
epoll_cleanup,
|
|
|
|
epoll_add,
|
|
epoll_remove,
|
|
epoll_process,
|
|
|
|
ogs_notify_pollset,
|
|
};
|
|
|
|
struct epoll_map_s {
|
|
ogs_poll_t *read;
|
|
ogs_poll_t *write;
|
|
};
|
|
|
|
struct epoll_context_s {
|
|
int epfd;
|
|
|
|
ogs_hash_t *map_hash;
|
|
struct epoll_event *event_list;
|
|
};
|
|
|
|
static void epoll_init(ogs_pollset_t *pollset)
|
|
{
|
|
struct epoll_context_s *context = NULL;
|
|
ogs_assert(pollset);
|
|
|
|
context = ogs_calloc(1, sizeof *context);
|
|
ogs_assert(context);
|
|
pollset->context = context;
|
|
|
|
context->event_list = ogs_calloc(
|
|
pollset->capacity, sizeof(struct epoll_event));
|
|
ogs_assert(context->event_list);
|
|
|
|
context->map_hash = ogs_hash_make();
|
|
ogs_assert(context->map_hash);
|
|
|
|
context->epfd = epoll_create(pollset->capacity);
|
|
ogs_assert(context->epfd >= 0);
|
|
|
|
ogs_notify_init(pollset);
|
|
}
|
|
|
|
static void epoll_cleanup(ogs_pollset_t *pollset)
|
|
{
|
|
struct epoll_context_s *context = NULL;
|
|
|
|
ogs_assert(pollset);
|
|
context = pollset->context;
|
|
ogs_assert(context);
|
|
|
|
ogs_notify_final(pollset);
|
|
close(context->epfd);
|
|
ogs_free(context->event_list);
|
|
ogs_hash_destroy(context->map_hash);
|
|
|
|
ogs_free(context);
|
|
}
|
|
|
|
static int epoll_add(ogs_poll_t *poll)
|
|
{
|
|
int rv, op;
|
|
ogs_pollset_t *pollset = NULL;
|
|
struct epoll_context_s *context = NULL;
|
|
struct epoll_map_s *map = NULL;
|
|
struct epoll_event ee;
|
|
|
|
ogs_assert(poll);
|
|
pollset = poll->pollset;
|
|
ogs_assert(pollset);
|
|
context = pollset->context;
|
|
ogs_assert(context);
|
|
|
|
map = ogs_hash_get(context->map_hash, &poll->fd, sizeof(poll->fd));
|
|
if (!map) {
|
|
map = ogs_calloc(1, sizeof(*map));
|
|
ogs_assert(map);
|
|
|
|
op = EPOLL_CTL_ADD;
|
|
ogs_hash_set(context->map_hash, &poll->fd, sizeof(poll->fd), map);
|
|
} else {
|
|
op = EPOLL_CTL_MOD;
|
|
}
|
|
|
|
if (poll->when & OGS_POLLIN)
|
|
map->read = poll;
|
|
if (poll->when & OGS_POLLOUT)
|
|
map->write = poll;
|
|
|
|
ee.events = 0;
|
|
if (map->read)
|
|
ee.events |= (EPOLLIN|EPOLLRDHUP);
|
|
if (map->write)
|
|
ee.events |= EPOLLOUT;
|
|
ee.data.ptr = map;
|
|
|
|
rv = epoll_ctl(context->epfd, op, poll->fd, &ee);
|
|
if (rv < 0) {
|
|
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
|
|
"epoll_ctl[%d] failed", op);
|
|
return OGS_ERROR;
|
|
}
|
|
|
|
return OGS_OK;
|
|
}
|
|
|
|
static int epoll_remove(ogs_poll_t *poll)
|
|
{
|
|
int rv, op;
|
|
ogs_pollset_t *pollset = NULL;
|
|
struct epoll_context_s *context = NULL;
|
|
struct epoll_map_s *map = NULL;
|
|
struct epoll_event ee;
|
|
|
|
ogs_assert(poll);
|
|
pollset = poll->pollset;
|
|
ogs_assert(pollset);
|
|
context = pollset->context;
|
|
ogs_assert(context);
|
|
|
|
map = ogs_hash_get(context->map_hash, &poll->fd, sizeof(poll->fd));
|
|
ogs_assert(map);
|
|
|
|
if (poll->when & OGS_POLLIN)
|
|
map->read = NULL;
|
|
if (poll->when & OGS_POLLOUT)
|
|
map->write = NULL;
|
|
|
|
ee.events = 0;
|
|
if (map->read)
|
|
ee.events |= (EPOLLIN|EPOLLRDHUP);
|
|
if (map->write)
|
|
ee.events |= EPOLLOUT;
|
|
|
|
if (map->read || map->write) {
|
|
op = EPOLL_CTL_MOD;
|
|
ee.data.ptr = map;
|
|
} else {
|
|
op = EPOLL_CTL_DEL;
|
|
ee.data.ptr = NULL;
|
|
|
|
ogs_free(map);
|
|
ogs_hash_set(context->map_hash, &poll->fd, sizeof(poll->fd), NULL);
|
|
}
|
|
|
|
rv = epoll_ctl(context->epfd, op, poll->fd, &ee);
|
|
if (rv < 0) {
|
|
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
|
|
"epoll_remove[%d] failed", op);
|
|
return OGS_ERROR;
|
|
}
|
|
|
|
return OGS_OK;
|
|
}
|
|
|
|
static int epoll_process(ogs_pollset_t *pollset, ogs_time_t timeout)
|
|
{
|
|
struct epoll_context_s *context = NULL;
|
|
int num_of_poll;
|
|
int i;
|
|
|
|
ogs_assert(pollset);
|
|
context = pollset->context;
|
|
ogs_assert(context);
|
|
|
|
num_of_poll = epoll_wait(context->epfd, context->event_list,
|
|
pollset->capacity,
|
|
timeout == OGS_INFINITE_TIME ? OGS_INFINITE_TIME :
|
|
ogs_time_to_msec(timeout));
|
|
if (num_of_poll < 0) {
|
|
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "epoll failed");
|
|
return OGS_ERROR;
|
|
} else if (num_of_poll == 0) {
|
|
return OGS_TIMEUP;
|
|
}
|
|
|
|
for (i = 0; i < num_of_poll; i++) {
|
|
struct epoll_map_s *map = NULL;
|
|
uint32_t received;
|
|
short when = 0;
|
|
|
|
received = context->event_list[i].events;
|
|
if (received & (EPOLLERR|EPOLLHUP)) {
|
|
when = OGS_POLLIN|OGS_POLLOUT;
|
|
} else {
|
|
if (received & (EPOLLIN|EPOLLRDHUP)) {
|
|
when |= OGS_POLLIN;
|
|
}
|
|
if (received & EPOLLOUT) {
|
|
when |= OGS_POLLOUT;
|
|
}
|
|
}
|
|
|
|
if (!when)
|
|
continue;
|
|
|
|
map = context->event_list[i].data.ptr;
|
|
ogs_assert(map);
|
|
|
|
if (map->read && map->write && map->read == map->write) {
|
|
map->read->handler(when, map->read->fd, map->read->data);
|
|
} else {
|
|
if (map->read && (when & OGS_POLLIN))
|
|
map->read->handler(when, map->read->fd, map->read->data);
|
|
if (map->write && (when & OGS_POLLOUT))
|
|
map->write->handler(when, map->write->fd, map->write->data);
|
|
}
|
|
}
|
|
|
|
return OGS_OK;
|
|
}
|