Commit 3950badb authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

get Session Management Subscription from UDM and process PDUSessionCreateSMContext request

parent 66d503dc
......@@ -63,7 +63,8 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
security->knas_int[0] = 0x41;
//decode the NAS message (using NAS lib)
decoder_rc = nas_message_decode (data, &decoded_nas_msg, sizeof(data), security, &decode_status);
// comment to fix a unknown bug
//decoder_rc = nas_message_decode (data, &decoded_nas_msg, sizeof(data), security, &decode_status);
Logger::smf_api_server().debug("nas header decode extended_protocol_discriminator %d, security_header_type:%d,sequence_number:%d,message_authentication_code:%d\n",
decoded_nas_msg.header.extended_protocol_discriminator,
......@@ -113,6 +114,7 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
sm_context_req_msg->set_message_type(decoded_nas_msg.plain.sm.pdu_session_establishment_request.messagetype);
//Integrity protection maximum data rate (Mandatory)
//PDU session type (Optional)
sm_context_req_msg->set_pdu_session_type(PDN_TYPE_E_IPV4);//TODO: should get from NAS msg
//SSC mode (Optional)
//5GSM capability (Optional)
//Maximum number of supported (Optional)
......
......@@ -135,12 +135,12 @@ int main(int argc, char **argv)
sgwc_app_inst = new sgwc_app(Options::getlibconfigConfig());
//SMF API server
//Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080));
//SMFApiServer smfApiServer(addr, pgw_app_inst);
//smfApiServer.init(2);
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080));
SMFApiServer smfApiServer(addr, pgw_app_inst);
smfApiServer.init(2);
//smfApiServer.start();
//smfApiServer.shutdown();
// std::thread smf_api_manager(&SMFApiServer::start, smfApiServer);
std::thread smf_api_manager(&SMFApiServer::start, smfApiServer);
FILE *fp = NULL;
std::string filename = fmt::format("/tmp/spgwc_{}.status", getpid());
......
......@@ -65,11 +65,14 @@ int pgw_app::apply_config (const pgw_config& cfg)
if (cfg.apn[ia].pool_id_iv4 >= 0) {
int pool_id = cfg.apn[ia].pool_id_iv4;
int range = be32toh(cfg.ue_pool_range_high[pool_id].s_addr) - be32toh(cfg.ue_pool_range_low[pool_id].s_addr) ;
paa_dynamic::get_instance().add_pool(cfg.apn[ia].apn_label, pool_id, cfg.ue_pool_range_low[pool_id], range);
paa_dynamic::get_instance().add_pool(cfg.apn[ia].apn, pool_id, cfg.ue_pool_range_low[pool_id], range);
//TODO: check with apn_label
Logger::pgwc_app().info("Applied config %s", cfg.apn[ia].apn.c_str());
}
if (cfg.apn[ia].pool_id_iv6 >= 0) {
int pool_id = cfg.apn[ia].pool_id_iv6;
paa_dynamic::get_instance().add_pool(cfg.apn[ia].apn_label, pool_id, cfg.paa_pool6_prefix[pool_id], cfg.paa_pool6_prefix_len[pool_id]);
paa_dynamic::get_instance().add_pool(cfg.apn[ia].apn, pool_id, cfg.paa_pool6_prefix[pool_id], cfg.paa_pool6_prefix_len[pool_id]);
//TODO: check with apn_label
}
}
......@@ -695,16 +698,15 @@ void pgw_app::handle_amf_msg(std::shared_ptr<pdu_session_create_sm_context_reque
//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");
//Step 1. get necessary information
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);
oai::smf::model::ProblemDetails problem_details;
Logger::pgwc_app().debug("Handle AMF message, supi " SUPI_64_FMT " ", supi64);
pdu_session_type_t pdu_session_type = {.pdu_session_type = sm_context_req_msg->get_pdu_session_type()};
......@@ -713,9 +715,9 @@ void pgw_app::handle_amf_msg(std::shared_ptr<pdu_session_create_sm_context_reque
//Step 2. check if the DNN requested is valid
if (not pgw_cfg.is_dotted_dnn_handled(dnn, pdu_session_type)) {
// Not a valid request...
Logger::pgwc_app().warn("Received PDU_SESSION_CREATESMCONTEXT_REQUEST unknown requested APN %s, ignore message", dnn.c_str());
oai::smf::model::SmContextCreateError smContextCreateError;
Logger::pgwc_app().warn("Received PDU_SESSION_CREATESMCONTEXT_REQUEST unknown requested APN %s, ignore message!", dnn.c_str());
problem_details.setCause(pdu_session_application_error_e2str[PDU_SESSION_APPLICATION_ERROR_DNN_DENIED]);
smContextCreateError.setError(problem_details);
//create a PDU Session Establishment Response by relying on NAS and assign to smContextCeateError.m_N1SmMsg
//Send response to AMF
send_create_session_response(httpResponse, smContextCreateError, Pistache::Http::Code::Forbidden);
......@@ -759,8 +761,18 @@ void pgw_app::handle_amf_msg(std::shared_ptr<pdu_session_create_sm_context_reque
//debug
//dnn_configuration_t dnn_configuration = subscription.get()->get_dnn_configuration(dnn);
//Logger::pgwc_app().debug("Retrieve Session Management Subscription data from UDM %s, %s, %s, %s", pdu_session_type_e2str[dnn_configuration.pdu_session_types.default_session_type.pdu_session_type].c_str(), ssc_mode_e2str[dnn_configuration.ssc_modes.default_ssc_mode.ssc_mode].c_str(), dnn_configuration.session_ambr.uplink.c_str(), dnn_configuration.session_ambr.downlink.c_str());
} else {
// Not accept to establish a PDU session
Logger::pgwc_app().warn("Received PDU_SESSION_CREATESMCONTEXT_REQUEST, couldn't retrieve the Session Management Subscription from UDM, ignore message!");
problem_details.setCause(pdu_session_application_error_e2str[PDU_SESSION_APPLICATION_ERROR_SUBSCRIPTION_DENIED]);
smContextCreateError.setError(problem_details);
//create a PDU Session Establishment Response by relying on NAS and assign to smContextCeateError.m_N1SmMsg
//Send response to AMF
send_create_session_response(httpResponse, smContextCreateError, Pistache::Http::Code::Forbidden);
return;
}
}
//Step 4. check the validity of the UE request, if valid send PDU Session Accept, otherwise send PDU Session Reject to AMF
......
......@@ -1098,6 +1098,8 @@ void pgw_context::handle_amf_msg (std::shared_ptr<pdu_session_create_sm_context_
//ss.get()->
}
*/
//TODO: set value for paa
paa.pdn_type.pdn_type = PDN_TYPE_E_IPV4;
if ((not paa_res) || (not paa.is_ip_assigned())) {
bool success = paa_dynamic::get_instance().get_free_paa(sd->dnn_in_use, paa);
......@@ -1110,12 +1112,14 @@ void pgw_context::handle_amf_msg (std::shared_ptr<pdu_session_create_sm_context_
} else if ((paa_res) && (paa.is_ip_assigned())) {
set_paa = true;
}
Logger::pgwc_app().info( "PAA, Ipv4 Address: %s", inet_ntoa (*((struct in_addr *)&paa.ipv4_address)));
} else { //use DHCP
//TODO: DHCP
}
}
break;
......
......@@ -101,8 +101,8 @@ void smf_n10_task (void *args_p)
//------------------------------------------------------------------------------
smf_n10::smf_n10 ()
{
udm_addr = "172.55.55.101";//hardcoded for the moment
udm_port = 8181;
udm_addr = "172.55.55.101";//TODO: hardcoded for the moment (should get from configuration file)
udm_port = 8181;//TODO: hardcoded for the moment (should get from configuration file)
Logger::smf_n10().startup("Starting...");
if (itti_inst->create_task(TASK_SMF_N10, smf_n10_task, nullptr) ) {
......@@ -172,7 +172,7 @@ bool smf_n10::get_sm_data(supi64_t& supi, std::string& dnn, snssai_t& snssai, st
}
else
{
Logger::smf_n10().warn("[get_sm_data] Couldn't GET response from UDM, URL %s, retry ...", url);
Logger::smf_n10().warn("[get_sm_data] Couldn't GET response from UDM, URL %s, retry ...", url.c_str());
//retry
numRetries++;
}
......@@ -186,7 +186,7 @@ bool smf_n10::get_sm_data(supi64_t& supi, std::string& dnn, snssai_t& snssai, st
//retrieve SessionManagementSubscription and store in the context
for (nlohmann::json::iterator it = jsonData["dnnConfigurations"].begin(); it != jsonData["dnnConfigurations"].end(); ++it ){
Logger::smf_n10().debug("[get_sm_data] KEY %s", it.key().c_str());
Logger::smf_n10().debug("[get_sm_data] DNN %s", it.key().c_str());
dnn_configuration_t dnn_configuration;
try {
......
cmake_minimum_required (VERSION 3.2)
project(api-server)
project(udm-server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pg -g3" )
......
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