Commit b187b9c8 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

generate SM Context ID and use this id as a key to store the corresponding...

generate SM Context ID and use this id as a key to store the corresponding context e.g., (supi, dnn, pdu_session_id)
parent 32af1613
......@@ -37,16 +37,12 @@ void IndividualSMContextApiImpl::update_sm_context(const std::string &smContextR
Logger::smf_api_server().info("update_sm_contexts...");
//Get the SmContextUpdateData from this message and process in smf_app
smf::pdu_session_update_sm_context_request sm_context_req_msg = {};
//smContextRef in our case is Supi
supi_t supi = {.length = 0};
smf_string_to_supi(&supi, smContextRef.c_str());
//supi64_t supi64 = smf_supi_to_u64(supi);
sm_context_req_msg.set_supi(supi);
//TODO: initialize necessary values for sm context req from smContextUpdateData and smContextRef
std::shared_ptr<itti_n11_update_sm_context_request> itti_msg = std::make_shared<itti_n11_update_sm_context_request>(TASK_SMF_N11, TASK_SMF_APP, response);
std::shared_ptr<itti_n11_update_sm_context_request> itti_msg = std::make_shared<itti_n11_update_sm_context_request>(TASK_SMF_N11, TASK_SMF_APP, response, smContextRef);
itti_msg->req = sm_context_req_msg;
itti_msg->scid = smContextRef;
m_smf_app->handle_amf_msg(itti_msg);
}
......
......@@ -56,6 +56,15 @@ typedef uint64_t seid_t;
#define INVALID_SEID ((seid_t)0x00000000)
#define UNASSIGNED_SEID ((seid_t)0x00000000)
// SM Context IDs (SCIDs)
typedef uint32_t scid_t;
#define SCID_FMT "0x%" PRIx32
#define SCID_SCAN_FMT SCNx32
#define INVALID_SCID ((scid_t)0x00000000)
#define UNASSIGNED_SCID ((scid_t)0x00000000)
//------------------------------------------------------------------------------
// IMSI
typedef uint64_t imsi64_t;
......
......@@ -58,9 +58,10 @@ public:
itti_n11_create_sm_context_request(const itti_n11_create_sm_context_request& i, const task_id_t orig, const task_id_t dest) :
itti_n11_msg(i, orig, dest), req(i.req), http_response(i.http_response) {}
const char* get_msg_name() {return "N11_SESSION_CREATE_SM_CONTEXT_REQUEST";};
void set_scid(scid_t id) {scid = id;};
smf::pdu_session_create_sm_context_request req;
Pistache::Http::ResponseWriter& http_response;
scid_t scid; //SM Context ID
};
......@@ -84,14 +85,15 @@ class itti_n11_update_sm_context_request : public itti_n11_msg {
public:
itti_n11_update_sm_context_request(const task_id_t orig, const task_id_t dest, Pistache::Http::ResponseWriter& response):
itti_n11_msg(N11_SESSION_UPDATE_SM_CONTEXT_REQUEST, orig, dest), http_response(response) {}
itti_n11_update_sm_context_request(const itti_n11_update_sm_context_request& i) : itti_n11_msg(i), req(i.req), http_response(i.http_response) {}
itti_n11_update_sm_context_request(const task_id_t orig, const task_id_t dest, Pistache::Http::ResponseWriter& response, const std::string id):
itti_n11_msg(N11_SESSION_UPDATE_SM_CONTEXT_REQUEST, orig, dest), http_response(response), scid(id) {}
itti_n11_update_sm_context_request(const itti_n11_update_sm_context_request& i) : itti_n11_msg(i), req(i.req), http_response(i.http_response), scid(i.scid) {}
itti_n11_update_sm_context_request(const itti_n11_update_sm_context_request& i, const task_id_t orig, const task_id_t dest) :
itti_n11_msg(i, orig, dest), req(i.req), http_response(i.http_response) {}
itti_n11_msg(i, orig, dest), req(i.req), http_response(i.http_response), scid(i.scid) {}
const char* get_msg_name() {return "N11_SESSION_UPDATE_SM_CONTEXT_REQUEST";};
smf::pdu_session_update_sm_context_request req;
Pistache::Http::ResponseWriter& http_response;
std::string scid; //SM Context ID
};
//-----------------------------------------------------------------------------
......
......@@ -128,6 +128,19 @@ uint64_t smf_app::generate_seid() {
return seid;
}
//------------------------------------------------------------------------------
void smf_app::generate_smf_context_ref(std::string& smf_ref)
{
smf_ref = std::to_string(sm_context_ref_generator.get_uid());
}
//------------------------------------------------------------------------------
scid_t smf_app::generate_smf_context_ref()
{
return sm_context_ref_generator.get_uid();
}
//------------------------------------------------------------------------------
bool smf_app::is_seid_n4_exist(const uint64_t& seid) const
{
......@@ -438,6 +451,10 @@ void smf_app::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_request
return;
}
}
// generate a SMF context Id and store the corresponding information in a map (SM_Context_ID, (supi, dnn, pdu_session_id))
scid_t scid = generate_smf_context_ref();
set_scid_2_smf_context(scid, supi, dnn, pdu_session_id);
smreq->set_scid(scid);
//Step 5. let the context handle the message
//in this step, SMF will send N4 Session Establishment/Modification to UPF (step 10a, section 4.3.2 3GPP 23.502)
......@@ -457,6 +474,20 @@ void smf_app::handle_amf_msg (std::shared_ptr<itti_n11_update_sm_context_request
std::string n1_container; //N1 SM container
//SM Context ID, N2 SM information, Request Type
//SM Context ID - uint32_t in our case
scid_t scid;
try {
scid = std::stoi(smreq->scid);
}
/*catch (const std::out_of_range& err){
} catch (const std::invalid_argument& err){
}*/
catch (const std::exception& err) {
//TODO: reject with invalid context
}
//Step 1. get necessary information (N2 SM information)
supi_t supi = smreq->req.get_supi();
supi64_t supi64 = smf_supi_to_u64(supi);
......@@ -516,6 +547,20 @@ void smf_app::set_supi_2_smf_context(const supi64_t& supi, std::shared_ptr<smf_c
supi2smf_context[supi] = sc;
}
//------------------------------------------------------------------------------
void smf_app::set_scid_2_smf_context(const scid_t& id, supi_t supi, std::string dnn, pdu_session_id_t pdu_session_id)
{
std::shared_lock lock(m_scid2smf_context);
scid2smf_context[id] = std::make_tuple(supi, dnn, pdu_session_id);
}
//------------------------------------------------------------------------------
std::tuple<supi_t, std::string, pdu_session_id_t> smf_app::scid_2_smf_context(const scid_t& scid) const
{
std::shared_lock lock(m_scid2smf_context);
return scid2smf_context.at(scid);
}
//------------------------------------------------------------------------------
bool smf_app::use_local_configuration_subscription_data(const std::string& dnn_selection_mode)
{
......
......@@ -72,6 +72,12 @@ private:
std::map<supi64_t, std::shared_ptr<smf_context>> supi2smf_context;
mutable std::shared_mutex m_supi2smf_context;
util::uint_generator<uint32_t> sm_context_ref_generator;
std::map<scid_t, std::tuple<supi_t, std::string, pdu_session_id_t>> scid2smf_context;
mutable std::shared_mutex m_scid2smf_context;
int apply_config(const smf_config& cfg);
int pco_push_protocol_or_container_id(protocol_configuration_options_t& pco, pco_protocol_or_container_id_t * const poc_id /* STOLEN_REF poc_id->contents*/);
......@@ -112,6 +118,12 @@ public:
bool is_seid_n4_exist(const uint64_t& s) const;
void free_seid_n4(const uint64_t& seid);
void generate_smf_context_ref(std::string& smf_ref);
scid_t generate_smf_context_ref();
void set_scid_2_smf_context(const scid_t& id, supi_t supi, std::string dnn, pdu_session_id_t pdu_session_id);
std::tuple<supi_t, std::string, pdu_session_id_t> scid_2_smf_context(const scid_t& scid) const;
/*
* Handle PDUSession_CreateSMContextRequest from AMF
* @param [std::shared_ptr<itti_n11_create_sm_context_request>&] Request message
......
......@@ -532,7 +532,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
//}
}
//Send reply to AMF (PDUSession_CreateSMContextResponse including Cause, SMContextId)
//(step 5 (4.3.2.2.1 TS 23.502)) Send reply to AMF (PDUSession_CreateSMContextResponse including Cause, SMContextId)
//location header contains the URI of the created resource
Logger::smf_app().info("Sending response to AMF!");
nlohmann::json jsonData;
......@@ -544,8 +544,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
//headers: Location:
//Contains the URI of the newly created resource, according to the structure: {apiRoot}/nsmf-pdusession/{apiVersion}/sm-contexts/{smContextRef}
std::string uri = sm_context_req_msg.get_api_root() + std::to_string(supi64); //smContextRef
std::string uri = sm_context_req_msg.get_api_root() + std::to_string(smreq->scid); //smContextRef
sm_context_resp->http_response.headers().add<Pistache::Http::Header::Location>(uri);
......@@ -615,7 +614,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
}
//------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_update_sm_context_request> smreq)
{
......
......@@ -86,6 +86,7 @@ class pdu_session_update_sm_context_request: public pdu_session_msg {
public:
pdu_session_update_sm_context_request(): pdu_session_msg(){ };
private:
//
//std::string m_Ppei;
std::string m_nf_instanceId;
oai::smf_server::model::Guami m_guami;
......
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