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

update Release SM Context procedure

parent 076b8645
......@@ -87,25 +87,61 @@ void IndividualSMContextApi::setupRoutes() {
void IndividualSMContextApi::release_sm_context_handler(
const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response) {
// Getting the path params
auto smContextRef = request.param(":smContextRef").as<std::string>();
// Getting the body param
Logger::smf_api_server().debug("");
Logger::smf_api_server().info(
"Received a SM context Release request from AMF.");
Logger::smf_api_server().debug("Request body: %s\n", request.body().c_str());
SmContextReleaseMessage smContextReleaseMessage = { };
//simple parser
mime_parser sp = { };
sp.parse(request.body());
SmContextReleaseData smContextReleaseData;
std::vector<mime_part> parts = { };
sp.get_mime_parts(parts);
uint8_t size = parts.size();
Logger::smf_api_server().debug("Number of MIME parts %d", size);
// Getting the body param
SmContextReleaseData smContextReleaseData = { };
try {
nlohmann::json::parse(request.body()).get_to(smContextReleaseData);
this->release_sm_context(smContextRef, smContextReleaseData, response);
if (size > 0) {
nlohmann::json::parse(parts[0].body.c_str()).get_to(smContextReleaseData);
} else {
nlohmann::json::parse(request.body().c_str()).get_to(
smContextReleaseData);
}
smContextReleaseMessage.setJsonData(smContextReleaseData);
for (int i = 1; i < size; i++) {
if (parts[i].content_type.compare("application/vnd.3gpp.ngap") == 0) {
smContextReleaseMessage.setBinaryDataN2SmInformation(parts[i].body);
Logger::smf_api_server().debug("N2 SM information is set");
}
}
// Getting the path params
auto smContextRef = request.param(":smContextRef").as<std::string>();
this->release_sm_context(smContextRef, smContextReleaseMessage, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
Logger::smf_api_server().warn(
"Error in parsing json (error: %s), send a msg with a 400 error code to AMF",
e.what());
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception &e) {
//send a 500 error
Logger::smf_api_server().warn(
"Error (%s ), send a msg with a 500 error code to AMF", e.what());
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void IndividualSMContextApi::retrieve_sm_context_handler(
......
......@@ -98,7 +98,7 @@ class IndividualSMContextApi {
/// <param name="smContextReleaseData">representation of the data to be sent to the SMF when releasing the SM context (optional)</param>
virtual void release_sm_context(
const std::string &smContextRef,
const SmContextReleaseData &smContextReleaseData,
const SmContextReleaseMessage &smContextReleaseMessage,
Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
......
......@@ -52,13 +52,41 @@ IndividualSMContextApiImpl::IndividualSMContextApiImpl(
void IndividualSMContextApiImpl::release_sm_context(
const std::string &smContextRef,
const SmContextReleaseData &smContextReleaseData,
const SmContextReleaseMessage &smContextReleaseMessage,
Pistache::Http::ResponseWriter &response) {
//TODO: to be updated as update_sm_context_handler
Logger::smf_api_server().info("release_sm_context...");
//Get the SmContextReleaseData from this message and process in smf_app
Logger::smf_api_server().info(
"Received a PDUSession_ReleaseSMContext Request from AMF.");
smf::pdu_session_release_sm_context_request sm_context_req_msg = { };
SmContextReleaseData smContextReleaseData = smContextReleaseMessage
.getJsonData();
if (smContextReleaseData.n2SmInfoIsSet()) {
//N2 SM (for Session establishment)
std::string n2_sm_information = smContextReleaseMessage
.getBinaryDataN2SmInformation();
Logger::smf_api_server().debug("N2 SM Information %s",
n2_sm_information.c_str());
boost::shared_ptr<boost::promise<smf::pdu_session_release_sm_context_response> > p =
std::string n2_sm_info_type = smContextReleaseData.getN2SmInfoType();
sm_context_req_msg.set_n2_sm_information(n2_sm_information);
sm_context_req_msg.set_n2_sm_info_type(n2_sm_info_type);
}
//Step 2. TODO: initialize necessary values for sm context req from smContextReleaseData
// cause:
// ngApCause:
// 5gMmCauseValue:
// ueLocation:
//ueTimeZone:
//addUeLocation:
//vsmfReleaseOnly:
//ismfReleaseOnly:
boost::shared_ptr
< boost::promise<smf::pdu_session_release_sm_context_response> > p =
boost::make_shared<
boost::promise<smf::pdu_session_release_sm_context_response> >();
boost::shared_future<smf::pdu_session_release_sm_context_response> f;
......@@ -69,16 +97,11 @@ void IndividualSMContextApiImpl::release_sm_context(
Logger::smf_api_server().debug("Promise ID generated %d", promise_id);
m_smf_app->add_promise(promise_id, p);
//handle Nsmf_PDUSession_UpdateSMContext Request
Logger::smf_api_server().info(
"Received a PDUSession_ReleaseSMContext Request: PDU Session Release request from AMF.");
//Step 3. Handle the itti_n11_release_sm_context_request message in smf_app
std::shared_ptr<itti_n11_release_sm_context_request> itti_msg =
std::make_shared<itti_n11_release_sm_context_request>(TASK_SMF_N11,
TASK_SMF_APP,
promise_id,
smContextRef);
itti_msg->scid = smContextRef;
std::make_shared < itti_n11_release_sm_context_request
> (TASK_SMF_N11, TASK_SMF_APP, promise_id, smContextRef);
itti_msg->req = sm_context_req_msg;
itti_msg->http_version = 1;
m_smf_app->handle_pdu_session_release_sm_context_request(itti_msg);
......@@ -86,7 +109,9 @@ void IndividualSMContextApiImpl::release_sm_context(
smf::pdu_session_release_sm_context_response sm_context_response = f.get();
Logger::smf_api_server().debug("Got result for promise ID %d", promise_id);
//TODO: process the response
response.send(Pistache::Http::Code(sm_context_response.get_http_code()));
}
void IndividualSMContextApiImpl::retrieve_sm_context(
......
......@@ -76,7 +76,7 @@ class IndividualSMContextApiImpl :
void release_sm_context(
const std::string &smContextRef,
const SmContextReleaseData &smContextReleaseData,
const SmContextReleaseMessage &smContextReleaseMessage,
Pistache::Http::ResponseWriter &response);
void retrieve_sm_context(const std::string &smContextRef,
const SmContextRetrieveData &smContextRetrieveData,
......
......@@ -417,6 +417,15 @@ class pdu_session_release_sm_context_request : public pdu_session_msg {
}
;
private:
//From smContextReleaseData
// cause:
// ngApCause:
// 5gMmCauseValue:
// ueLocation:
//ueTimeZone:
//addUeLocation:
//vsmfReleaseOnly:
//ismfReleaseOnly:
};
//---------------------------------------------------------------------------------------
......
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