Commit 19a39d92 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add pti/session id/message type/request type check

parent 1f30ee44
......@@ -38,6 +38,9 @@
#include "string.hpp"
#include "SmContextCreateError.h"
#include "3gpp_29.502.h"
#include "3gpp_24.007.h"
#include "smf.h"
#include "3gpp_24.501.h"
#include <stdexcept>
#include <iostream>
......@@ -696,21 +699,60 @@ void pgw_app::send_create_session_response(Pistache::Http::ResponseWriter& httpR
void pgw_app::handle_amf_msg(std::shared_ptr<pdu_session_create_sm_context_request>& sm_context_req_msg, Pistache::Http::ResponseWriter &httpResponse){
//handle PDU Session Create SM Context Request as specified in section 4.3.2 3GPP TS 23.502
Logger::pgwc_app().info("Handle AMF message");
oai::smf::model::SmContextCreateError smContextCreateError;
oai::smf::model::ProblemDetails problem_details;
//Step 1. get necessary information
std::string dnn = sm_context_req_msg->get_dnn();
snssai_t snssai = sm_context_req_msg->get_snssai();
std::string requestType = sm_context_req_msg->get_request_type();
supi_t supi = sm_context_req_msg->get_supi();
supi64_t supi64 = smf_supi_to_u64(supi);
Logger::pgwc_app().debug("Handle AMF message, supi " SUPI_64_FMT " ", supi64);
std::string dnn = sm_context_req_msg->get_dnn();
snssai_t snssai = sm_context_req_msg->get_snssai();
procedure_transaction_id_t pti = sm_context_req_msg->get_pti();
pdu_session_type_t pdu_session_type = {.pdu_session_type = sm_context_req_msg->get_pdu_session_type()};
Logger::pgwc_app().debug("Handle AMF message, _pdusessiontype: %d", pdu_session_type.pdu_session_type);
pdu_session_id_t pdu_session_id = sm_context_req_msg->get_pdu_session_id();
uint8_t message_type = sm_context_req_msg->get_message_type();
request_type_t request_type = sm_context_req_msg->get_request_type();
Logger::pgwc_app().info("Handle a PDU Session Create SM Context Request message from AMF, supi " SUPI_64_FMT ", dnn %s, snssai_sst %d", supi64, dnn.c_str(), snssai.sST );
//check pti
if ((pti.procedure_transaction_id == PROCEDURE_TRANSACTION_IDENTITY_UNASSIGNED) || (pti.procedure_transaction_id > PROCEDURE_TRANSACTION_IDENTITY_LAST)){
Logger::pgwc_app().warn(" Invalid PTI value (pti = %d)\n", pti.procedure_transaction_id);
problem_details.setCause(pdu_session_application_error_e2str[PDU_SESSION_APPLICATION_ERROR_N1_SM_ERROR]);
smContextCreateError.setError(problem_details);
//create a PDU Session Establishment Response by relying on NAS and assign to smContextCeateError.m_N1SmMsg
//TODO: (24.501 (section 7.3.1)) NAS N1 SM message: response with a 5GSM STATUS message including cause "#81 Invalid PTI value"
//Send response to AMF
send_create_session_response(httpResponse, smContextCreateError, Pistache::Http::Code::Forbidden);
}
//check pdu session id
if ((pdu_session_id == PDU_SESSION_IDENTITY_UNASSIGNED) || (pdu_session_id > PDU_SESSION_IDENTITY_LAST)){
Logger::pgwc_app().warn(" Invalid PDU Session ID value (psi = %d)\n", pdu_session_id);
//TODO: (24.501 (section 7.3.2)) NAS N1 SM message: ignore the message
//return;
}
//check message type
if (message_type != PDU_SESSION_ESTABLISHMENT_REQUEST) {
Logger::pgwc_app().warn("Invalid message type (message type = %d)\n", message_type);
//TODO:
problem_details.setCause(pdu_session_application_error_e2str[PDU_SESSION_APPLICATION_ERROR_N1_SM_ERROR]);
smContextCreateError.setError(problem_details);
//create a PDU Session Establishment Response by relying on NAS and assign to smContextCeateError.m_N1SmMsg
//TODO: (24.501 (section 7.4)) implementation dependent->do similar to UE: response with a 5GSM STATUS message including cause "#98 message type not compatible with protocol state."
//Send response to AMF
send_create_session_response(httpResponse, smContextCreateError, Pistache::Http::Code::Forbidden);
}
//check request type
if ((request_type & 0x07) != INITIAL_REQUEST){
Logger::pgwc_app().warn("Invalid request type (request type = %s)\n", request_type_e2str[request_type & 0x07]);
//TODO:
}
//Step 2. check if the DNN requested is valid
if (not pgw_cfg.is_dotted_dnn_handled(dnn, pdu_session_type)) {
......
......@@ -35,7 +35,7 @@
#include "pgwc_procedure.hpp"
#include "ProblemDetails.h"
#include "3gpp_29.502.h"
#include "3gpp_24.501.h"
#include <algorithm>
......@@ -992,7 +992,7 @@ void pgw_context::handle_amf_msg (std::shared_ptr<pdu_session_create_sm_context_
//Step 1. get necessary information
std::string dnn = sm_context_req_msg->get_dnn();
snssai_t snssai = sm_context_req_msg->get_snssai();
std::string requestType = sm_context_req_msg->get_request_type();
request_type_t request_type = sm_context_req_msg->get_request_type();
supi_t supi = sm_context_req_msg->get_supi();
supi64_t supi64 = smf_supi_to_u64(supi);
uint32_t pdu_session_id = sm_context_req_msg->get_pdu_session_id();
......
......@@ -33,6 +33,7 @@
#include "pgw_pfcp_association.hpp"
#include "pgwc_procedure.hpp"
#include "pgw_context.hpp"
#include "SmContextCreatedData.h"
#include <algorithm> // std::search
......@@ -370,70 +371,85 @@ void session_establishment_procedure::handle_itti_msg (itti_sxab_session_establi
{
Logger::pgwc_app().info( "session_establishment_procedure handle itti_sxab_session_establishment_response: pdu-session-id %d", n11_trigger.get()->get_pdu_session_id());
pfcp::cause_t cause = {};
resp.pfcp_ies.get(cause);
if (cause.cause_value == pfcp::CAUSE_VALUE_REQUEST_ACCEPTED) {
resp.pfcp_ies.get(ppc->up_fseid);
}
for (auto it : resp.pfcp_ies.created_pdrs) {
pfcp::pdr_id_t pdr_id = {};
pfcp::far_id_t far_id = {};
if (it.get(pdr_id)) {
pgw_eps_bearer b = {};
if (ppc->get_eps_bearer(pdr_id, b)) {
pfcp::fteid_t local_up_fteid = {};
if (it.get(local_up_fteid)) {
xgpp_conv::pfcp_to_core_fteid(local_up_fteid, b.pgw_fteid_s5_s8_up);
b.pgw_fteid_s5_s8_up.interface_type = S5_S8_PGW_GTP_U;
// comment if SPGW-C allocate up fteid
pgw_eps_bearer b2 = b;
ppc->add_eps_bearer(b2);
}
// uncomment if SPGW-C allocate up fteid
// ppc->add_eps_bearer(b);
} else {
Logger::pgwc_app().error( "Could not get EPS bearer for created_pdr %d", pdr_id.rule_id);
}
} else {
Logger::pgwc_app().error( "Could not get pdr_id for created_pdr in %s", resp.pfcp_ies.get_msg_name());
}
}
ebi_t ebi = {};
ebi.ebi = n11_trigger.get()->get_pdu_session_id();
pgw_eps_bearer b = {};
gtpv2c::bearer_context_created_within_create_session_response bcc = {};
::cause_t bcc_cause = {.cause_value = REQUEST_ACCEPTED, .pce = 0, .bce = 0, .cs = 0};
if (not ppc->get_eps_bearer(ebi, b)) {
bcc_cause.cause_value = SYSTEM_FAILURE;
} else {
if (b.pgw_fteid_s5_s8_up.is_zero()) {
bcc_cause.cause_value = SYSTEM_FAILURE;
} else {
bcc.set(b.pgw_fteid_s5_s8_up, 2);
}
}
bcc.set(b.ebi);
bcc.set(bcc_cause);
// only if modified bcc.set(bearer_level_qos);
// s5_triggered_pending->gtp_ies.add_bearer_context_created(bcc);
// }
//Send reply to AMF
pfcp::cause_t cause = {};
resp.pfcp_ies.get(cause);
if (cause.cause_value == pfcp::CAUSE_VALUE_REQUEST_ACCEPTED) {
resp.pfcp_ies.get(ppc->up_fseid);
}
for (auto it : resp.pfcp_ies.created_pdrs) {
pfcp::pdr_id_t pdr_id = {};
pfcp::far_id_t far_id = {};
if (it.get(pdr_id)) {
pgw_eps_bearer b = {};
if (ppc->get_eps_bearer(pdr_id, b)) {
pfcp::fteid_t local_up_fteid = {};
if (it.get(local_up_fteid)) {
xgpp_conv::pfcp_to_core_fteid(local_up_fteid, b.pgw_fteid_s5_s8_up);
b.pgw_fteid_s5_s8_up.interface_type = S5_S8_PGW_GTP_U;
// comment if SPGW-C allocate up fteid
pgw_eps_bearer b2 = b;
ppc->add_eps_bearer(b2);
}
// uncomment if SPGW-C allocate up fteid
// ppc->add_eps_bearer(b);
} else {
Logger::pgwc_app().error( "Could not get EPS bearer for created_pdr %d", pdr_id.rule_id);
}
} else {
Logger::pgwc_app().error( "Could not get pdr_id for created_pdr in %s", resp.pfcp_ies.get_msg_name());
}
}
ebi_t ebi = {};
ebi.ebi = n11_trigger.get()->get_pdu_session_id();
pgw_eps_bearer b = {};
gtpv2c::bearer_context_created_within_create_session_response bcc = {};
::cause_t bcc_cause = {.cause_value = REQUEST_ACCEPTED, .pce = 0, .bce = 0, .cs = 0};
if (not ppc->get_eps_bearer(ebi, b)) {
bcc_cause.cause_value = SYSTEM_FAILURE;
} else {
if (b.pgw_fteid_s5_s8_up.is_zero()) {
bcc_cause.cause_value = SYSTEM_FAILURE;
} else {
bcc.set(b.pgw_fteid_s5_s8_up, 2);
}
}
bcc.set(b.ebi);
bcc.set(bcc_cause);
// only if modified bcc.set(bearer_level_qos);
// s5_triggered_pending->gtp_ies.add_bearer_context_created(bcc);
// }
//Send reply to AMF
Logger::pgwc_app().info( "Sending response to AMF!");
nlohmann::json jsonData;
oai::smf::model::SmContextCreateError smContextCreateError;
oai::smf::model::ProblemDetails problem_details;
problem_details.setCause("[PDU_SESSION_APPLICATION_ERROR_SUBSCRIPTION_DENIED"); //TODO: add causes to header file
smContextCreateError.setError(problem_details);
to_json(jsonData, smContextCreateError);
std::string resBody = jsonData.dump();
//issue: httpResponse has been free!!!
//(n11_triggered_pending->get_http_response()).send(Pistache::Http::Code::Forbidden,resBody);
//n11_triggered_pending.get()->send_msg_to_amf(resBody);
nlohmann::json jsonData;
oai::smf::model::SmContextCreatedData smContextCreatedData;
//PduSessionId
smContextCreatedData.setPduSessionId(n11_trigger.get()->get_pdu_session_id());
//Snssai
oai::smf::model::Snssai snssai;
snssai.setSst(n11_trigger.get()->get_snssai().sST);
snssai.setSd(n11_trigger.get()->get_snssai().sD);
smContextCreatedData.setSNssai(snssai);
//UpCnxState
//N2SmInfo (use NAS to encode)
//TODO:
//N2SmInfoType
//TODO: smContextCreatedData.setN2SmInfoType();
//std::vector<EbiArpMapping> m_AllocatedEbiList
//HoState
//Gpsi
//SmfServiceInstanceId - SMF instance ID
//RecoveryTime;
//SupportedFeatures
to_json(jsonData, smContextCreatedData);
std::string resBody = jsonData.dump();
//issue: httpResponse has been free!!!
n11_triggered_pending.get()->set_http_code(Pistache::Http::Code::Created);
n11_triggered_pending.get()->send_msg_to_amf(resBody);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment