Skip to content

Commit

Permalink
[pfcp] adding pfcp session-set-delete message
Browse files Browse the repository at this point in the history
  • Loading branch information
spencersevilla committed Jan 19, 2024
1 parent 55ed5d1 commit a55503a
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 0 deletions.
81 changes: 81 additions & 0 deletions lib/pfcp/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,87 @@ ogs_pkbuf_t *ogs_pfcp_up_build_association_setup_response(uint8_t type,
return pkbuf;
}

ogs_pkbuf_t *ogs_pfcp_cp_build_session_set_deletion_request(uint8_t type)
{
ogs_pfcp_message_t * pfcp_message = NULL;
ogs_pfcp_session_set_deletion_request_t *req = NULL;
ogs_pkbuf_t *pkbuf = NULL;

ogs_pfcp_node_id_t node_id;
int node_id_len = 0, rv;

ogs_debug("Session Set Deletion Request");

pfcp_message = ogs_calloc(1, sizeof(*pfcp_message));
if (!pfcp_message) {
ogs_error("ogs_calloc() failed");
return NULL;
}

req = &pfcp_message->pfcp_session_set_deletion_request;

rv = ogs_pfcp_sockaddr_to_node_id(&node_id, &node_id_len);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_sockaddr_to_node_id() failed");
ogs_free(pfcp_message);
return NULL;
}
req->node_id.presence = 1;
req->node_id.data = &node_id;
req->node_id.len = node_id_len;

pfcp_message->h.type = type;
pkbuf = ogs_pfcp_build_msg(pfcp_message);
ogs_expect(pkbuf);

ogs_free(pfcp_message);

return pkbuf;
}

ogs_pkbuf_t *ogs_pfcp_up_build_session_set_deletion_response(uint8_t type, uint8_t cause)
{
ogs_pfcp_message_t *pfcp_message = NULL;
ogs_pfcp_session_set_deletion_response_t *rsp = NULL;
ogs_pkbuf_t *pkbuf = NULL;

ogs_pfcp_node_id_t node_id;
int node_id_len = 0, rv;

ogs_debug("Session Set Deletion Response");

pfcp_message = ogs_calloc(1, sizeof(*pfcp_message));
if (!pfcp_message) {
ogs_error("ogs_calloc() failed");
return NULL;
}

rsp = &pfcp_message->pfcp_session_set_deletion_response;

// node id
rv = ogs_pfcp_sockaddr_to_node_id(&node_id, &node_id_len);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_sockaddr_to_node_id() failed");
ogs_free(pfcp_message);
return NULL;
}
rsp->node_id.presence = 1;
rsp->node_id.data = &node_id;
rsp->node_id.len = node_id_len;

// cause
rsp->cause.presence = 1;
rsp->cause.u8 = cause;

pfcp_message->h.type = type;
pkbuf = ogs_pfcp_build_msg(pfcp_message);
ogs_expect(pkbuf);

ogs_free(pfcp_message);

return pkbuf;
}

static struct {
ogs_pfcp_f_teid_t f_teid;
char dnn[OGS_MAX_DNN_LEN+1];
Expand Down
4 changes: 4 additions & 0 deletions lib/pfcp/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ ogs_pkbuf_t *ogs_pfcp_up_build_association_setup_request(uint8_t type);
ogs_pkbuf_t *ogs_pfcp_up_build_association_setup_response(uint8_t type,
uint8_t cause);

ogs_pkbuf_t *ogs_pfcp_cp_build_session_set_deletion_request(uint8_t type);
ogs_pkbuf_t *ogs_pfcp_up_build_session_set_deletion_response(uint8_t type,
uint8_t cause);

void ogs_pfcp_pdrbuf_init(void);
void ogs_pfcp_pdrbuf_clear(void);

Expand Down
69 changes: 69 additions & 0 deletions lib/pfcp/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,75 @@ int ogs_pfcp_cp_send_association_setup_response(ogs_pfcp_xact_t *xact,
return rv;
}

int ogs_pfcp_cp_send_session_set_deletion_request(ogs_pfcp_node_t *node,
void (*cb)(ogs_pfcp_xact_t *xact, void *data))
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_pfcp_header_t h;
ogs_pfcp_xact_t *xact = NULL;

ogs_assert(node);

memset(&h, 0, sizeof(ogs_pfcp_header_t));
h.type = OGS_PFCP_SESSION_SET_DELETION_REQUEST_TYPE;
h.seid = 0;

xact = ogs_pfcp_xact_local_create(node, cb, node);
if (!xact) {
ogs_error("ogs_pfcp_xact_local_create() failed");
return OGS_ERROR;
}

pkbuf = ogs_pfcp_cp_build_session_set_deletion_request(h.type);
if (!pkbuf) {
ogs_error("ogs_pfcp_cp_build_session_set_deletion_request() failed");
return OGS_ERROR;
}

rv = ogs_pfcp_xact_update_tx(xact, &h, pkbuf);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_xact_update_tx() failed");
return OGS_ERROR;
}

rv = ogs_pfcp_xact_commit(xact);
ogs_expect(rv == OGS_OK);

return rv;
}

int ogs_pfcp_up_send_session_set_deletion_response(ogs_pfcp_xact_t *xact,
uint8_t cause)
{
int rv;
ogs_pkbuf_t *pkbuf = NULL;
ogs_pfcp_header_t h;

ogs_assert(xact);

memset(&h, 0, sizeof(ogs_pfcp_header_t));
h.type = OGS_PFCP_SESSION_SET_DELETION_RESPONSE_TYPE;
h.seid = 0;

pkbuf = ogs_pfcp_up_build_session_set_deletion_response(h.type, cause);
if (!pkbuf) {
ogs_error("ogs_pfcp_up_build_session_set_deletion_response() failed");
return OGS_ERROR;
}

rv = ogs_pfcp_xact_update_tx(xact, &h, pkbuf);
if (rv != OGS_OK) {
ogs_error("ogs_pfcp_xact_update_tx() failed");
return OGS_ERROR;
}

rv = ogs_pfcp_xact_commit(xact);
ogs_expect(rv == OGS_OK);

return rv;
}

int ogs_pfcp_up_send_association_setup_request(ogs_pfcp_node_t *node,
void (*cb)(ogs_pfcp_xact_t *xact, void *data))
{
Expand Down
5 changes: 5 additions & 0 deletions lib/pfcp/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ int ogs_pfcp_cp_send_association_setup_request(ogs_pfcp_node_t *node,
int ogs_pfcp_cp_send_association_setup_response(ogs_pfcp_xact_t *xact,
uint8_t cause);

int ogs_pfcp_cp_send_session_set_deletion_request(ogs_pfcp_node_t *node,
void (*cb)(ogs_pfcp_xact_t *xact, void *data));
int ogs_pfcp_up_send_session_set_deletion_response(ogs_pfcp_xact_t *xact,
uint8_t cause);

int ogs_pfcp_up_send_association_setup_request(ogs_pfcp_node_t *node,
void (*cb)(ogs_pfcp_xact_t *xact, void *data));
int ogs_pfcp_up_send_association_setup_response(ogs_pfcp_xact_t *xact,
Expand Down
2 changes: 2 additions & 0 deletions lib/pfcp/xact.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ static ogs_pfcp_xact_stage_t ogs_pfcp_xact_get_stage(uint8_t type, uint32_t xid)
case OGS_PFCP_SESSION_ESTABLISHMENT_REQUEST_TYPE:
case OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE:
case OGS_PFCP_SESSION_DELETION_REQUEST_TYPE:
case OGS_PFCP_SESSION_SET_DELETION_REQUEST_TYPE:
case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE:
stage = PFCP_XACT_INITIAL_STAGE;
break;
Expand All @@ -766,6 +767,7 @@ static ogs_pfcp_xact_stage_t ogs_pfcp_xact_get_stage(uint8_t type, uint32_t xid)
case OGS_PFCP_SESSION_ESTABLISHMENT_RESPONSE_TYPE:
case OGS_PFCP_SESSION_MODIFICATION_RESPONSE_TYPE:
case OGS_PFCP_SESSION_DELETION_RESPONSE_TYPE:
case OGS_PFCP_SESSION_SET_DELETION_RESPONSE_TYPE:
case OGS_PFCP_SESSION_REPORT_RESPONSE_TYPE:
stage = PFCP_XACT_FINAL_STAGE;
break;
Expand Down
6 changes: 6 additions & 0 deletions src/sgwc/pfcp-sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ void sgwc_pfcp_state_associated(ogs_fsm_t *s, sgwc_event_t *e)
stats_update_sgwc_sessions();
break;

case OGS_PFCP_SESSION_SET_DELETION_RESPONSE_TYPE:
sgwc_sxa_handle_session_set_deletion_response(
xact, &message->pfcp_session_set_deletion_response);
stats_update_sgwc_sessions();
break;

case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE:
if (!message->h.seid_presence) ogs_error("No SEID");

Expand Down
14 changes: 14 additions & 0 deletions src/sgwc/sxa-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,20 @@ void sgwc_sxa_handle_session_deletion_response(
ogs_error("Session has already been removed");
}

void sgwc_sxa_handle_session_set_deletion_response(
ogs_pfcp_xact_t *pfcp_xact,
ogs_pfcp_session_set_deletion_response_t *pfcp_rsp)
{
ogs_debug("Session Set Deletion Response");

ogs_assert(pfcp_xact);
ogs_assert(pfcp_rsp);

ogs_pfcp_xact_commit(pfcp_xact);

return;
}

void sgwc_sxa_handle_session_report_request(
sgwc_sess_t *sess, ogs_pfcp_xact_t *pfcp_xact,
ogs_pfcp_session_report_request_t *pfcp_req)
Expand Down
3 changes: 3 additions & 0 deletions src/sgwc/sxa-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void sgwc_sxa_handle_session_deletion_response(
sgwc_sess_t *sess, ogs_pfcp_xact_t *pfcp_xact,
ogs_gtp2_message_t *gtp_message,
ogs_pfcp_session_deletion_response_t *pfcp_rsp);
void sgwc_sxa_handle_session_set_deletion_response(
ogs_pfcp_xact_t *pfcp_xact,
ogs_pfcp_session_set_deletion_response_t *pfcp_rsp);
void sgwc_sxa_handle_session_report_request(
sgwc_sess_t *sess, ogs_pfcp_xact_t *pfcp_xact,
ogs_pfcp_session_report_request_t *pfcp_req);
Expand Down
4 changes: 4 additions & 0 deletions src/sgwu/pfcp-sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ void sgwu_pfcp_state_associated(ogs_fsm_t *s, sgwu_event_t *e)
sgwu_sxa_handle_session_deletion_request(
sess, xact, &message->pfcp_session_deletion_request);
break;
case OGS_PFCP_SESSION_SET_DELETION_REQUEST_TYPE:
sgwu_sxa_handle_session_set_deletion_request(
node, xact, &message->pfcp_session_set_deletion_request);
break;
case OGS_PFCP_SESSION_REPORT_RESPONSE_TYPE:
sgwu_sxa_handle_session_report_response(
sess, xact, &message->pfcp_session_report_response);
Expand Down
20 changes: 20 additions & 0 deletions src/sgwu/sxa-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,26 @@ void sgwu_sxa_handle_session_deletion_request(
sgwu_sess_remove(sess);
}

void sgwu_sxa_handle_session_set_deletion_request(
ogs_pfcp_node_t *node, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_set_deletion_request_t *req)
{
sgwu_sess_t *sess = NULL, *next = NULL;;
ogs_assert(node);
ogs_assert(xact);
ogs_assert(req);

ogs_debug("Session Set Deletion Request");

ogs_list_for_each_safe(&sgwu_self()->sess_list, next, sess) {
if (sess->pfcp_node == node) {
sgwu_sess_remove(sess);
}
}

ogs_pfcp_up_send_session_set_deletion_response(xact, OGS_PFCP_CAUSE_REQUEST_ACCEPTED);
}

void sgwu_sxa_handle_session_report_response(
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_report_response_t *rsp)
Expand Down
3 changes: 3 additions & 0 deletions src/sgwu/sxa-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void sgwu_sxa_handle_session_modification_request(
void sgwu_sxa_handle_session_deletion_request(
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_deletion_request_t *req);
void sgwu_sxa_handle_session_set_deletion_request(
ogs_pfcp_node_t *node, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_set_deletion_request_t *req);

void sgwu_sxa_handle_session_report_response(
sgwu_sess_t *sess, ogs_pfcp_xact_t *xact,
Expand Down
13 changes: 13 additions & 0 deletions src/smf/n4-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,19 @@ uint8_t smf_epc_n4_handle_session_deletion_response(
return OGS_PFCP_CAUSE_REQUEST_ACCEPTED;
}

void smf_epc_n4_handle_session_set_deletion_response(
ogs_pfcp_xact_t *xact, ogs_pfcp_session_set_deletion_response_t *rsp)
{
ogs_debug("Session Set Deletion Response");

ogs_assert(xact);
ogs_assert(rsp);

ogs_pfcp_xact_commit(xact);

return;
}

void smf_n4_handle_session_report_request(
smf_sess_t *sess, ogs_pfcp_xact_t *pfcp_xact,
ogs_pfcp_session_report_request_t *pfcp_req)
Expand Down
2 changes: 2 additions & 0 deletions src/smf/n4-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void smf_epc_n4_handle_session_modification_response(
uint8_t smf_epc_n4_handle_session_deletion_response(
smf_sess_t *sess, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_deletion_response_t *rsp);
void smf_epc_n4_handle_session_set_deletion_response(
ogs_pfcp_xact_t *xact, ogs_pfcp_session_set_deletion_response_t *rsp);

void smf_n4_handle_session_report_request(
smf_sess_t *sess, ogs_pfcp_xact_t *pfcp_xact,
Expand Down
5 changes: 5 additions & 0 deletions src/smf/pfcp-sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e)
ogs_fsm_dispatch(&sess->sm, e);
break;

case OGS_PFCP_SESSION_SET_DELETION_RESPONSE_TYPE:
smf_epc_n4_handle_session_set_deletion_response(
xact, &message->pfcp_session_set_deletion_response);
break;

case OGS_PFCP_SESSION_REPORT_REQUEST_TYPE:
if (!message->h.seid_presence) ogs_error("No SEID");

Expand Down
20 changes: 20 additions & 0 deletions src/upf/n4-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ void upf_n4_handle_session_deletion_request(
upf_sess_remove(sess);
}

void upf_n4_handle_session_set_deletion_request(
ogs_pfcp_node_t *node, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_set_deletion_request_t *req)
{
upf_sess_t *sess = NULL, *next = NULL;;
ogs_assert(node);
ogs_assert(xact);
ogs_assert(req);

ogs_debug("Session Set Deletion Request");

ogs_list_for_each_safe(&upf_self()->sess_list, next, sess) {
if (sess->pfcp_node == node) {
upf_sess_remove(sess);
}
}

ogs_pfcp_up_send_session_set_deletion_response(xact, OGS_PFCP_CAUSE_REQUEST_ACCEPTED);
}

void upf_n4_handle_session_report_response(
upf_sess_t *sess, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_report_response_t *rsp)
Expand Down
3 changes: 3 additions & 0 deletions src/upf/n4-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void upf_n4_handle_session_modification_request(
void upf_n4_handle_session_deletion_request(
upf_sess_t *sess, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_deletion_request_t *req);
void upf_n4_handle_session_set_deletion_request(
ogs_pfcp_node_t *node, ogs_pfcp_xact_t *xact,
ogs_pfcp_session_set_deletion_request_t *req);

void upf_n4_handle_session_report_response(
upf_sess_t *sess, ogs_pfcp_xact_t *xact,
Expand Down
4 changes: 4 additions & 0 deletions src/upf/pfcp-sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ void upf_pfcp_state_associated(ogs_fsm_t *s, upf_event_t *e)
upf_n4_handle_session_deletion_request(
sess, xact, &message->pfcp_session_deletion_request);
break;
case OGS_PFCP_SESSION_SET_DELETION_REQUEST_TYPE:
upf_n4_handle_session_set_deletion_request(
node, xact, &message->pfcp_session_set_deletion_request);
break;
case OGS_PFCP_SESSION_REPORT_RESPONSE_TYPE:
upf_n4_handle_session_report_response(
sess, xact, &message->pfcp_session_report_response);
Expand Down

0 comments on commit a55503a

Please sign in to comment.