2020-08-13 00:31:22 +00:00
|
|
|
/*
|
|
|
|
* 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 "pfcp-path.h"
|
|
|
|
#include "sxa-handler.h"
|
|
|
|
|
|
|
|
static void node_timeout(ogs_pfcp_xact_t *xact, void *data);
|
|
|
|
|
|
|
|
void sgwc_pfcp_state_initial(ogs_fsm_t *s, sgwc_event_t *e)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
ogs_pfcp_node_t *node = NULL;
|
|
|
|
|
|
|
|
ogs_assert(s);
|
|
|
|
ogs_assert(e);
|
|
|
|
|
|
|
|
sgwc_sm_debug(e);
|
|
|
|
|
|
|
|
node = e->pfcp_node;
|
|
|
|
ogs_assert(node);
|
|
|
|
|
|
|
|
rv = ogs_pfcp_connect(
|
|
|
|
ogs_pfcp_self()->pfcp_sock, ogs_pfcp_self()->pfcp_sock6, node);
|
|
|
|
ogs_assert(rv == OGS_OK);
|
|
|
|
|
2020-08-26 03:05:01 +00:00
|
|
|
node->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr,
|
2020-08-13 00:31:22 +00:00
|
|
|
sgwc_timer_pfcp_no_heartbeat, node);
|
|
|
|
ogs_assert(node->t_no_heartbeat);
|
|
|
|
|
|
|
|
OGS_FSM_TRAN(s, &sgwc_pfcp_state_will_associate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sgwc_pfcp_state_final(ogs_fsm_t *s, sgwc_event_t *e)
|
|
|
|
{
|
|
|
|
ogs_pfcp_node_t *node = NULL;
|
|
|
|
ogs_assert(s);
|
|
|
|
ogs_assert(e);
|
|
|
|
|
|
|
|
sgwc_sm_debug(e);
|
|
|
|
|
|
|
|
node = e->pfcp_node;
|
|
|
|
ogs_assert(node);
|
|
|
|
|
|
|
|
ogs_timer_delete(node->t_no_heartbeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sgwc_pfcp_state_will_associate(ogs_fsm_t *s, sgwc_event_t *e)
|
|
|
|
{
|
|
|
|
char buf[OGS_ADDRSTRLEN];
|
|
|
|
|
|
|
|
ogs_pfcp_node_t *node = NULL;
|
|
|
|
ogs_pfcp_xact_t *xact = NULL;
|
|
|
|
ogs_pfcp_message_t *message = NULL;
|
|
|
|
|
|
|
|
ogs_sockaddr_t *addr = NULL;
|
|
|
|
|
|
|
|
ogs_assert(s);
|
|
|
|
ogs_assert(e);
|
|
|
|
|
|
|
|
sgwc_sm_debug(e);
|
|
|
|
|
|
|
|
node = e->pfcp_node;
|
|
|
|
ogs_assert(node);
|
|
|
|
addr = node->sa_list;
|
|
|
|
ogs_assert(addr);
|
|
|
|
|
|
|
|
switch (e->id) {
|
|
|
|
case OGS_FSM_ENTRY_SIG:
|
|
|
|
if (node->t_association) {
|
|
|
|
ogs_timer_start(node->t_association,
|
2020-08-26 03:05:01 +00:00
|
|
|
ogs_app()->time.message.pfcp.association_interval);
|
2020-08-13 00:31:22 +00:00
|
|
|
|
|
|
|
ogs_pfcp_cp_send_association_setup_request(node, node_timeout);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OGS_FSM_EXIT_SIG:
|
|
|
|
if (node->t_association) {
|
|
|
|
ogs_timer_stop(node->t_association);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SGWC_EVT_SXA_TIMER:
|
|
|
|
switch(e->timer_id) {
|
|
|
|
case SGWC_TIMER_PFCP_ASSOCIATION:
|
|
|
|
node = e->pfcp_node;
|
|
|
|
ogs_assert(node);
|
|
|
|
|
|
|
|
ogs_warn("Retry to association with peer [%s]:%d failed",
|
|
|
|
OGS_ADDR(addr, buf), OGS_PORT(addr));
|
|
|
|
|
|
|
|
ogs_assert(node->t_association);
|
|
|
|
ogs_timer_start(node->t_association,
|
2020-08-26 03:05:01 +00:00
|
|
|
ogs_app()->time.message.pfcp.association_interval);
|
2020-08-13 00:31:22 +00:00
|
|
|
|
|
|
|
ogs_pfcp_cp_send_association_setup_request(node, node_timeout);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ogs_error("Unknown timer[%s:%d]",
|
|
|
|
sgwc_timer_get_name(e->timer_id), e->timer_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SGWC_EVT_SXA_MESSAGE:
|
|
|
|
message = e->pfcp_message;
|
|
|
|
ogs_assert(message);
|
|
|
|
xact = e->pfcp_xact;
|
|
|
|
ogs_assert(xact);
|
|
|
|
|
|
|
|
switch (message->h.type) {
|
|
|
|
case OGS_PFCP_ASSOCIATION_SETUP_REQUEST_TYPE:
|
|
|
|
ogs_pfcp_cp_handle_association_setup_request(node, xact,
|
|
|
|
&message->pfcp_association_setup_request);
|
|
|
|
OGS_FSM_TRAN(s, sgwc_pfcp_state_associated);
|
|
|
|
break;
|
|
|
|
case OGS_PFCP_ASSOCIATION_SETUP_RESPONSE_TYPE:
|
|
|
|
ogs_pfcp_cp_handle_association_setup_response(node, xact,
|
|
|
|
&message->pfcp_association_setup_response);
|
|
|
|
OGS_FSM_TRAN(s, sgwc_pfcp_state_associated);
|
|
|
|
break;
|
|
|
|
default:
|
2020-09-07 02:51:07 +00:00
|
|
|
ogs_warn("cannot handle PFCP message type[%d]",
|
2020-08-13 00:31:22 +00:00
|
|
|
message->h.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ogs_error("Unknown event %s", sgwc_event_get_name(e));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e)
|
|
|
|
{
|
|
|
|
char buf[OGS_ADDRSTRLEN];
|
|
|
|
|
|
|
|
ogs_pfcp_node_t *node = NULL;
|
|
|
|
ogs_pfcp_xact_t *xact = NULL;
|
|
|
|
ogs_pfcp_message_t *message = NULL;
|
|
|
|
|
|
|
|
ogs_sockaddr_t *addr = NULL;
|
|
|
|
sgwc_sess_t *sess = NULL;
|
|
|
|
|
|
|
|
ogs_assert(s);
|
|
|
|
ogs_assert(e);
|
|
|
|
|
|
|
|
sgwc_sm_debug(e);
|
|
|
|
|
|
|
|
node = e->pfcp_node;
|
|
|
|
ogs_assert(node);
|
|
|
|
addr = node->sa_list;
|
|
|
|
ogs_assert(addr);
|
|
|
|
|
|
|
|
switch (e->id) {
|
|
|
|
case OGS_FSM_ENTRY_SIG:
|
2022-08-25 18:46:00 +00:00
|
|
|
ogs_info("PFCP associated [%s]:%d",
|
|
|
|
OGS_ADDR(&node->addr, buf),
|
|
|
|
OGS_PORT(&node->addr));
|
2020-08-13 00:31:22 +00:00
|
|
|
ogs_timer_start(node->t_no_heartbeat,
|
2020-08-26 03:05:01 +00:00
|
|
|
ogs_app()->time.message.pfcp.no_heartbeat_duration);
|
2020-08-13 00:31:22 +00:00
|
|
|
break;
|
|
|
|
case OGS_FSM_EXIT_SIG:
|
2022-08-25 18:46:00 +00:00
|
|
|
ogs_info("PFCP de-associated [%s]:%d",
|
|
|
|
OGS_ADDR(&node->addr, buf),
|
|
|
|
OGS_PORT(&node->addr));
|
2020-08-13 00:31:22 +00:00
|
|
|
ogs_timer_stop(node->t_no_heartbeat);
|
|
|
|
break;
|
|
|
|
case SGWC_EVT_SXA_MESSAGE:
|
|
|
|
message = e->pfcp_message;
|
|
|
|
ogs_assert(message);
|
|
|
|
xact = e->pfcp_xact;
|
|
|
|
ogs_assert(xact);
|
|
|
|
|
2022-06-30 01:35:03 +00:00
|
|
|
if (message->h.seid_presence && message->h.seid != 0) {
|
2020-08-13 00:31:22 +00:00
|
|
|
sess = sgwc_sess_find_by_seid(message->h.seid);
|
2022-06-30 01:35:03 +00:00
|
|
|
} else if (xact->local_seid) { /* rx no SEID or SEID=0 */
|
|
|
|
/* 3GPP TS 29.244 7.2.2.4.2: we receive SEID=0 under some
|
|
|
|
* conditions, such as cause "Session context not found". In those
|
|
|
|
* cases, we still want to identify the local session which
|
|
|
|
* originated the message, so try harder by using the SEID we
|
2022-06-30 01:53:19 +00:00
|
|
|
* locally stored in xact when sending the original request: */
|
2022-06-30 01:35:03 +00:00
|
|
|
sess = sgwc_sess_find_by_seid(xact->local_seid);
|
|
|
|
}
|
2020-08-13 00:31:22 +00:00
|
|
|
|
|
|
|
switch (message->h.type) {
|
|
|
|
case OGS_PFCP_HEARTBEAT_REQUEST_TYPE:
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_assert(true ==
|
|
|
|
ogs_pfcp_handle_heartbeat_request(node, xact,
|
|
|
|
&message->pfcp_heartbeat_request));
|
2020-08-13 00:31:22 +00:00
|
|
|
break;
|
|
|
|
case OGS_PFCP_HEARTBEAT_RESPONSE_TYPE:
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_assert(true ==
|
|
|
|
ogs_pfcp_handle_heartbeat_response(node, xact,
|
|
|
|
&message->pfcp_heartbeat_response));
|
2020-08-13 00:31:22 +00:00
|
|
|
break;
|
|
|
|
case OGS_PFCP_ASSOCIATION_SETUP_REQUEST_TYPE:
|
2022-08-25 18:46:00 +00:00
|
|
|
ogs_warn("PFCP[REQ] has already been associated [%s]:%d",
|
|
|
|
OGS_ADDR(&node->addr, buf),
|
|
|
|
OGS_PORT(&node->addr));
|
2020-08-13 00:31:22 +00:00
|
|
|
ogs_pfcp_cp_handle_association_setup_request(node, xact,
|
|
|
|
&message->pfcp_association_setup_request);
|
|
|
|
break;
|
|
|
|
case OGS_PFCP_ASSOCIATION_SETUP_RESPONSE_TYPE:
|
2022-08-25 18:46:00 +00:00
|
|
|
ogs_warn("PFCP[RSP] has already been associated [%s]:%d",
|
|
|
|
OGS_ADDR(&node->addr, buf),
|
|
|
|
OGS_PORT(&node->addr));
|
2020-08-13 00:31:22 +00:00
|
|
|
ogs_pfcp_cp_handle_association_setup_response(node, xact,
|
|
|
|
&message->pfcp_association_setup_response);
|
|
|
|
break;
|
|
|
|
case OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE:
|
2022-06-30 01:35:03 +00:00
|
|
|
if (!message->h.seid_presence) ogs_error("No SEID");
|
2022-06-30 00:11:38 +00:00
|
|
|
|
2020-08-13 00:31:22 +00:00
|
|
|
sgwc_sxa_handle_session_establishment_response(
|
|
|
|
sess, xact, e->gtp_message,
|
|
|
|
&message->pfcp_session_establishment_response);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE:
|
2022-06-30 01:35:03 +00:00
|
|
|
if (!message->h.seid_presence) ogs_error("No SEID");
|
2022-06-30 00:11:38 +00:00
|
|
|
|
2020-08-13 00:31:22 +00:00
|
|
|
sgwc_sxa_handle_session_modification_response(
|
|
|
|
sess, xact, e->gtp_message,
|
|
|
|
&message->pfcp_session_modification_response);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OGS_PFCP_SESSION_DELETION_RESPONSE_TYPE:
|
2022-06-30 01:35:03 +00:00
|
|
|
if (!message->h.seid_presence) ogs_error("No SEID");
|
2022-06-30 00:11:38 +00:00
|
|
|
|
2020-08-13 00:31:22 +00:00
|
|
|
sgwc_sxa_handle_session_deletion_response(
|
|
|
|
sess, xact, e->gtp_message,
|
|
|
|
&message->pfcp_session_deletion_response);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE:
|
2022-06-30 01:35:03 +00:00
|
|
|
if (!message->h.seid_presence) ogs_error("No SEID");
|
2022-06-30 00:11:38 +00:00
|
|
|
|
2020-08-13 00:31:22 +00:00
|
|
|
sgwc_sxa_handle_session_report_request(
|
|
|
|
sess, xact, &message->pfcp_session_report_request);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ogs_error("Not implemented PFCP message type[%d]",
|
|
|
|
message->h.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SGWC_EVT_SXA_TIMER:
|
|
|
|
switch(e->timer_id) {
|
|
|
|
case SGWC_TIMER_PFCP_NO_HEARTBEAT:
|
|
|
|
node = e->pfcp_node;
|
|
|
|
ogs_assert(node);
|
|
|
|
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_assert(OGS_OK ==
|
|
|
|
ogs_pfcp_send_heartbeat_request(node, node_timeout));
|
2020-08-13 00:31:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ogs_error("Unknown timer[%s:%d]",
|
|
|
|
sgwc_timer_get_name(e->timer_id), e->timer_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SGWC_EVT_SXA_NO_HEARTBEAT:
|
2021-04-12 11:23:51 +00:00
|
|
|
ogs_warn("No Heartbeat from SGW-U [%s]:%d",
|
2020-08-13 00:31:22 +00:00
|
|
|
OGS_ADDR(addr, buf), OGS_PORT(addr));
|
|
|
|
OGS_FSM_TRAN(s, sgwc_pfcp_state_will_associate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ogs_error("Unknown event %s", sgwc_event_get_name(e));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sgwc_pfcp_state_exception(ogs_fsm_t *s, sgwc_event_t *e)
|
|
|
|
{
|
|
|
|
ogs_assert(s);
|
|
|
|
ogs_assert(e);
|
|
|
|
|
|
|
|
sgwc_sm_debug(e);
|
|
|
|
|
|
|
|
switch (e->id) {
|
|
|
|
case OGS_FSM_ENTRY_SIG:
|
|
|
|
break;
|
|
|
|
case OGS_FSM_EXIT_SIG:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ogs_error("Unknown event %s", sgwc_event_get_name(e));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void node_timeout(ogs_pfcp_xact_t *xact, void *data)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
sgwc_event_t *e = NULL;
|
|
|
|
uint8_t type;
|
|
|
|
|
|
|
|
ogs_assert(xact);
|
|
|
|
type = xact->seq[0].type;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case OGS_PFCP_HEARTBEAT_REQUEST_TYPE:
|
|
|
|
ogs_assert(data);
|
|
|
|
|
|
|
|
e = sgwc_event_new(SGWC_EVT_SXA_NO_HEARTBEAT);
|
|
|
|
e->pfcp_node = data;
|
|
|
|
|
2020-08-26 03:05:01 +00:00
|
|
|
rv = ogs_queue_push(ogs_app()->queue, e);
|
2020-08-13 00:31:22 +00:00
|
|
|
if (rv != OGS_OK) {
|
2022-07-16 04:27:18 +00:00
|
|
|
ogs_error("ogs_queue_push() failed:%d", (int)rv);
|
2020-08-13 00:31:22 +00:00
|
|
|
sgwc_event_free(e);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OGS_PFCP_ASSOCIATION_SETUP_REQUEST_TYPE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ogs_error("Not implemented [type:%d]", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|