Commit 5ff8b7f4 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Code cleanup API server

parent 40faab75
/**
* Nsmf_PDUSession
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "IndividualPDUSessionHSMFApi.h"
......@@ -38,77 +39,76 @@ void IndividualPDUSessionHSMFApi::setupRoutes() {
Routes::Post(
*router,
base + smf_cfg.sbi_api_version + "/pdu-sessions/:pduSessionRef/release",
Routes::bind(&IndividualPDUSessionHSMFApi::release_pdu_session_handler,
this));
Routes::bind(
&IndividualPDUSessionHSMFApi::release_pdu_session_handler, this));
Routes::Post(
*router,
base + smf_cfg.sbi_api_version + "/pdu-sessions/:pduSessionRef/modify",
Routes::bind(&IndividualPDUSessionHSMFApi::update_pdu_session_handler,
this));
Routes::bind(
&IndividualPDUSessionHSMFApi::update_pdu_session_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(
Routes::bind(
&IndividualPDUSessionHSMFApi::individual_pdu_session_hsmf_api_default_handler,
this));
router->addCustomHandler(Routes::bind(
&IndividualPDUSessionHSMFApi::
individual_pdu_session_hsmf_api_default_handler,
this));
}
void IndividualPDUSessionHSMFApi::release_pdu_session_handler(
const Pistache::Rest::Request &request,
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
// Getting the path params
auto pduSessionRef = request.param(":pduSessionRef").as<std::string>();
// Getting the body param
ReleaseData releaseData = { };
ReleaseData releaseData = {};
try {
nlohmann::json::parse(request.body()).get_to(releaseData);
this->release_pdu_session(pduSessionRef, releaseData, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
} catch (nlohmann::detail::exception& e) {
// send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception &e) {
//send a 500 error
} catch (std::exception& e) {
// send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void IndividualPDUSessionHSMFApi::update_pdu_session_handler(
const Pistache::Rest::Request &request,
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
// Getting the path params
auto pduSessionRef = request.param(":pduSessionRef").as<std::string>();
// Getting the body param
HsmfUpdateData hsmfUpdateData = { };
HsmfUpdateData hsmfUpdateData = {};
try {
nlohmann::json::parse(request.body()).get_to(hsmfUpdateData);
this->update_pdu_session(pduSessionRef, hsmfUpdateData, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
} catch (nlohmann::detail::exception& e) {
// send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception &e) {
//send a 500 error
} catch (std::exception& e) {
// send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void IndividualPDUSessionHSMFApi::individual_pdu_session_hsmf_api_default_handler(
const Pistache::Rest::Request&, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found,
"The requested method does not exist");
}
}
}
void IndividualPDUSessionHSMFApi::
individual_pdu_session_hsmf_api_default_handler(
const Pistache::Rest::Request&,
Pistache::Http::ResponseWriter response) {
response.send(
Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace api
} // namespace smf_server
} // namespace oai
/**
* Nsmf_PDUSession
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
* IndividualPDUSessionHSMFApi.h
*
*
*
*/
#ifndef IndividualPDUSessionHSMFApi_H_
......@@ -39,8 +41,7 @@ using namespace oai::smf_server::model;
class IndividualPDUSessionHSMFApi {
public:
IndividualPDUSessionHSMFApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~IndividualPDUSessionHSMFApi() {
}
virtual ~IndividualPDUSessionHSMFApi() {}
void init();
const std::string base = "/nsmf-pdusession/";
......@@ -48,12 +49,14 @@ class IndividualPDUSessionHSMFApi {
private:
void setupRoutes();
void release_pdu_session_handler(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void update_pdu_session_handler(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void release_pdu_session_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void update_pdu_session_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void individual_pdu_session_hsmf_api_default_handler(
const Pistache::Rest::Request &request,
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
......@@ -65,10 +68,11 @@ class IndividualPDUSessionHSMFApi {
///
/// </remarks>
/// <param name="pduSessionRef">PDU session reference</param>
/// <param name="releaseData">representation of the data to be sent to H-SMF when releasing the PDU session (optional)</param>
/// <param name="releaseData">representation of the data to be sent to H-SMF
/// when releasing the PDU session (optional)</param>
virtual void release_pdu_session(
const std::string &pduSessionRef, const ReleaseData &releaseData,
Pistache::Http::ResponseWriter &response) = 0;
const std::string& pduSessionRef, const ReleaseData& releaseData,
Pistache::Http::ResponseWriter& response) = 0;
/// <summary>
/// Update (initiated by V-SMF)
......@@ -77,16 +81,15 @@ class IndividualPDUSessionHSMFApi {
///
/// </remarks>
/// <param name="pduSessionRef">PDU session reference</param>
/// <param name="hsmfUpdateData">representation of the updates to apply to the PDU session</param>
virtual void update_pdu_session(const std::string &pduSessionRef,
const HsmfUpdateData &hsmfUpdateData,
Pistache::Http::ResponseWriter &response) = 0;
/// <param name="hsmfUpdateData">representation of the updates to apply to the
/// PDU session</param>
virtual void update_pdu_session(
const std::string& pduSessionRef, const HsmfUpdateData& hsmfUpdateData,
Pistache::Http::ResponseWriter& response) = 0;
};
}
}
}
} // namespace api
} // namespace smf_server
} // namespace oai
#endif /* IndividualPDUSessionHSMFApi_H_ */
/**
* Nsmf_PDUSession
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
......@@ -15,9 +16,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -68,50 +69,51 @@ void IndividualSMContextApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(
*router, base + smf_cfg.sbi_api_version + "/sm-contexts/:smContextRef/release",
*router,
base + smf_cfg.sbi_api_version + "/sm-contexts/:smContextRef/release",
Routes::bind(&IndividualSMContextApi::release_sm_context_handler, this));
Routes::Post(
*router, base + smf_cfg.sbi_api_version + "/sm-contexts/:smContextRef/retrieve",
*router,
base + smf_cfg.sbi_api_version + "/sm-contexts/:smContextRef/retrieve",
Routes::bind(&IndividualSMContextApi::retrieve_sm_context_handler, this));
Routes::Post(
*router, base + smf_cfg.sbi_api_version + "/sm-contexts/:smContextRef/modify",
*router,
base + smf_cfg.sbi_api_version + "/sm-contexts/:smContextRef/modify",
Routes::bind(&IndividualSMContextApi::update_sm_context_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(
Routes::bind(
&IndividualSMContextApi::individual_sm_context_api_default_handler,
this));
router->addCustomHandler(Routes::bind(
&IndividualSMContextApi::individual_sm_context_api_default_handler,
this));
}
void IndividualSMContextApi::release_sm_context_handler(
const Pistache::Rest::Request &request,
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
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 = { };
SmContextReleaseMessage smContextReleaseMessage = {};
//simple parser
mime_parser sp = { };
// simple parser
mime_parser sp = {};
sp.parse(request.body());
std::vector<mime_part> parts = { };
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 = { };
SmContextReleaseData smContextReleaseData = {};
try {
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);
nlohmann::json::parse(request.body().c_str())
.get_to(smContextReleaseData);
}
smContextReleaseMessage.setJsonData(smContextReleaseData);
......@@ -127,68 +129,66 @@ void IndividualSMContextApi::release_sm_context_handler(
auto smContextRef = request.param(":smContextRef").as<std::string>();
this->release_sm_context(smContextRef, smContextReleaseMessage, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
} 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",
"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
} 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(
const Pistache::Rest::Request &request,
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
SmContextRetrieveData smContextRetrieveData = { };
SmContextRetrieveData smContextRetrieveData = {};
try {
nlohmann::json::parse(request.body()).get_to(smContextRetrieveData);
this->retrieve_sm_context(smContextRef, smContextRetrieveData, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
} catch (nlohmann::detail::exception& e) {
// send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception &e) {
//send a 500 error
} catch (std::exception& e) {
// send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void IndividualSMContextApi::update_sm_context_handler(
const Pistache::Rest::Request &request,
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
Logger::smf_api_server().debug("");
Logger::smf_api_server().info(
"Received a SM context update request from AMF.");
Logger::smf_api_server().debug("Request body: %s\n", request.body().c_str());
SmContextUpdateMessage smContextUpdateMessage = { };
SmContextUpdateMessage smContextUpdateMessage = {};
//simple parser
mime_parser sp = { };
// simple parser
mime_parser sp = {};
sp.parse(request.body());
std::vector<mime_part> parts = { };
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
SmContextUpdateData smContextUpdateData = { };
SmContextUpdateData smContextUpdateData = {};
try {
if (size > 0) {
nlohmann::json::parse(parts[0].body.c_str()).get_to(smContextUpdateData);
......@@ -202,8 +202,8 @@ void IndividualSMContextApi::update_sm_context_handler(
if (parts[i].content_type.compare("application/vnd.3gpp.5gnas") == 0) {
smContextUpdateMessage.setBinaryDataN1SmMessage(parts[i].body);
Logger::smf_api_server().debug("N1 SM message is set");
} else if (parts[i].content_type.compare("application/vnd.3gpp.ngap")
== 0) {
} else if (
parts[i].content_type.compare("application/vnd.3gpp.ngap") == 0) {
smContextUpdateMessage.setBinaryDataN2SmInformation(parts[i].body);
Logger::smf_api_server().debug("N2 SM information is set");
}
......@@ -213,15 +213,16 @@ void IndividualSMContextApi::update_sm_context_handler(
auto smContextRef = request.param(":smContextRef").as<std::string>();
this->update_sm_context(smContextRef, smContextUpdateMessage, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
} 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",
"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
} 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());
......@@ -231,11 +232,10 @@ void IndividualSMContextApi::update_sm_context_handler(
void IndividualSMContextApi::individual_sm_context_api_default_handler(
const Pistache::Rest::Request&, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found,
"The requested method does not exist");
}
}
}
response.send(
Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace api
} // namespace smf_server
} // namespace oai
/**
* Nsmf_PDUSession
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* IndividualSMContextApi.h
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
......@@ -20,9 +16,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -36,6 +32,12 @@
* contact@openairinterface.org
*/
/*
* IndividualSMContextApi.h
*
*
*/
#ifndef IndividualSMContextApi_H_
#define IndividualSMContextApi_H_
......@@ -67,8 +69,7 @@ using namespace oai::smf_server::model;
class IndividualSMContextApi {
public:
IndividualSMContextApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~IndividualSMContextApi() {
}
virtual ~IndividualSMContextApi() {}
void init();
const std::string base = "/nsmf-pdusession/";
......@@ -76,14 +77,17 @@ class IndividualSMContextApi {
private:
void setupRoutes();
void release_sm_context_handler(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void retrieve_sm_context_handler(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void update_sm_context_handler(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void release_sm_context_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void retrieve_sm_context_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void update_sm_context_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void individual_sm_context_api_default_handler(
const Pistache::Rest::Request &request,
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
......@@ -95,11 +99,12 @@ class IndividualSMContextApi {
///
/// </remarks>
/// <param name="smContextRef">SM context reference</param>
/// <param name="smContextReleaseData">representation of the data to be sent to the SMF when releasing the SM context (optional)</param>
/// <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 SmContextReleaseMessage &smContextReleaseMessage,
Pistache::Http::ResponseWriter &response) = 0;
const std::string& smContextRef,
const SmContextReleaseMessage& smContextReleaseMessage,
Pistache::Http::ResponseWriter& response) = 0;
/// <summary>
/// Retrieve SM Context
......@@ -108,11 +113,12 @@ class IndividualSMContextApi {
///
/// </remarks>
/// <param name="smContextRef">SM context reference</param>
/// <param name="smContextRetrieveData">parameters used to retrieve the SM context (optional)</param>
/// <param name="smContextRetrieveData">parameters used to retrieve the SM
/// context (optional)</param>
virtual void retrieve_sm_context(
const std::string &smContextRef,
const SmContextRetrieveData &smContextRetrieveData,
Pistache::Http::ResponseWriter &response) = 0;
const std::string& smContextRef,
const SmContextRetrieveData& smContextRetrieveData,
Pistache::Http::ResponseWriter& response) = 0;
/// <summary>
/// Update SM Context
......@@ -121,17 +127,16 @@ class IndividualSMContextApi {
///
/// </remarks>
/// <param name="smContextRef">SM context reference</param>
/// <param name="smContextUpdateData">representation of the updates to apply to the SM context</param>
/// <param name="smContextUpdateData">representation of the updates to apply
/// to the SM context</param>
virtual void update_sm_context(
const std::string &smContextRef,
const SmContextUpdateMessage &smContextUpdateMessage,
Pistache::Http::ResponseWriter &response) = 0;
const std::string& smContextRef,
const SmContextUpdateMessage& smContextUpdateMessage,
Pistache::Http::ResponseWriter& response) = 0;
};
}
}
}
} // namespace api
} // namespace smf_server
} // namespace oai
#endif /* IndividualSMContextApi_H_ */
/**
* Nsmf_EventExposure
* Session Management Event Exposure Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
*