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

add API server for SMF

parent 600c39ae
cmake_minimum_required (VERSION 3.2)
project(smf-api-server)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pg -g3" )
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS} )
target_link_libraries(${PROJECT_NAME} pistache pthread)
# REST API Server for Nsmf_PDUSession
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Pistache](https://github.com/oktal/pistache) Framework.
## Files organization
The Pistache C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model/nlohmann folder
## Namespaces
oai.smf.api
oai.smf.model
/**
* Nsmf_PDUSession
* 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.
*/
#include "IndividualPDUSessionHSMFApi.h"
#include "Helpers.h"
namespace oai {
namespace smf {
namespace api {
using namespace org::openapitools::server::helpers;
using namespace oai::smf::model;
IndividualPDUSessionHSMFApi::IndividualPDUSessionHSMFApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void IndividualPDUSessionHSMFApi::init() {
setupRoutes();
}
void IndividualPDUSessionHSMFApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(*router, base + "/pdu-sessions/:pduSessionRef/release", Routes::bind(&IndividualPDUSessionHSMFApi::release_pdu_session_handler, this));
Routes::Post(*router, base + "/pdu-sessions/:pduSessionRef/modify", 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));
}
void IndividualPDUSessionHSMFApi::release_pdu_session_handler(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;
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
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} 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, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto pduSessionRef = request.param(":pduSessionRef").as<std::string>();
// Getting the body param
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
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} 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");
}
}
}
}
/**
* Nsmf_PDUSession
* 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.
*/
/*
* IndividualPDUSessionHSMFApi.h
*
*
*/
#ifndef IndividualPDUSessionHSMFApi_H_
#define IndividualPDUSessionHSMFApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "HsmfUpdateData.h"
#include "HsmfUpdateError.h"
#include "HsmfUpdatedData.h"
#include "ProblemDetails.h"
#include "ReleaseData.h"
#include <string>
namespace oai {
namespace smf {
namespace api {
using namespace oai::smf::model;
class IndividualPDUSessionHSMFApi {
public:
IndividualPDUSessionHSMFApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~IndividualPDUSessionHSMFApi() {}
void init();
const std::string base = "/nsmf-pdusession/v1";
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 individual_pdu_session_hsmf_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
/// Release
/// </summary>
/// <remarks>
///
/// </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>
virtual void release_pdu_session(const std::string &pduSessionRef, const ReleaseData &releaseData, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Update (initiated by V-SMF)
/// </summary>
/// <remarks>
///
/// </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;
};
}
}
}
#endif /* IndividualPDUSessionHSMFApi_H_ */
/**
* Nsmf_PDUSession
* 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.
*/
#include "IndividualSMContextApi.h"
#include "Helpers.h"
namespace oai {
namespace smf {
namespace api {
using namespace org::openapitools::server::helpers;
using namespace oai::smf::model;
IndividualSMContextApi::IndividualSMContextApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void IndividualSMContextApi::init() {
setupRoutes();
}
void IndividualSMContextApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(*router, base + "/sm-contexts/:smContextRef/release", Routes::bind(&IndividualSMContextApi::release_sm_context_handler, this));
Routes::Post(*router, base + "/sm-contexts/:smContextRef/retrieve", Routes::bind(&IndividualSMContextApi::retrieve_sm_context_handler, this));
Routes::Post(*router, base + "/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));
}
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
SmContextReleaseData smContextReleaseData;
try {
nlohmann::json::parse(request.body()).get_to(smContextReleaseData);
this->release_sm_context(smContextRef, smContextReleaseData, response);
} 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
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void IndividualSMContextApi::retrieve_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
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
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} 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, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto smContextRef = request.param(":smContextRef").as<std::string>();
// Getting the body param
SmContextUpdateData smContextUpdateData;
try {
nlohmann::json::parse(request.body()).get_to(smContextUpdateData);
this->update_sm_context(smContextRef, smContextUpdateData, response);
} 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
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
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");
}
}
}
}
/**
* Nsmf_PDUSession
* 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
*
*
*/
#ifndef IndividualSMContextApi_H_
#define IndividualSMContextApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "ProblemDetails.h"
#include "SmContextReleaseData.h"
#include "SmContextRetrieveData.h"
#include "SmContextRetrievedData.h"
#include "SmContextUpdateData.h"
#include "SmContextUpdateError.h"
#include "SmContextUpdatedData.h"
#include <string>
namespace oai {
namespace smf {
namespace api {
using namespace oai::smf::model;
class IndividualSMContextApi {
public:
IndividualSMContextApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~IndividualSMContextApi() {}
void init();
const std::string base = "/nsmf-pdusession/v1";
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 individual_sm_context_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
/// Release SM Context
/// </summary>
/// <remarks>
///
/// </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>
virtual void release_sm_context(const std::string &smContextRef, const SmContextReleaseData &smContextReleaseData, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Retrieve SM Context
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="smContextRef">SM context reference</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;
/// <summary>
/// Update SM Context
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="smContextRef">SM context reference</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 SmContextUpdateData &smContextUpdateData, Pistache::Http::ResponseWriter &response) = 0;
};
}
}
}
#endif /* IndividualSMContextApi_H_ */
/**
* Nsmf_PDUSession
* 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.
*/
#include "PDUSessionsCollectionApi.h"
#include "Helpers.h"
namespace oai {
namespace smf {
namespace api {
using namespace org::openapitools::server::helpers;
using namespace oai::smf::model;
PDUSessionsCollectionApi::PDUSessionsCollectionApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void PDUSessionsCollectionApi::init() {
setupRoutes();
}
void PDUSessionsCollectionApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(*router, base + "/pdu-sessions", Routes::bind(&PDUSessionsCollectionApi::post_pdu_sessions_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&PDUSessionsCollectionApi::pdu_sessions_collection_api_default_handler, this));
}
void PDUSessionsCollectionApi::post_pdu_sessions_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the body param
PduSessionCreateData pduSessionCreateData;
try {
nlohmann::json::parse(request.body()).get_to(pduSessionCreateData);
this->post_pdu_sessions(pduSessionCreateData, response);
} 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
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void PDUSessionsCollectionApi::pdu_sessions_collection_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
}
}
}
/**
* Nsmf_PDUSession
* 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.
*/
/*
* PDUSessionsCollectionApi.h
*
*
*/
#ifndef PDUSessionsCollectionApi_H_
#define PDUSessionsCollectionApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "PduSessionCreateData.h"
#include "PduSessionCreateError.h"
#include "PduSessionCreatedData.h"
#include "ProblemDetails.h"
namespace oai {
namespace smf {
namespace api {
using namespace oai::smf::model;
class PDUSessionsCollectionApi {
public:
PDUSessionsCollectionApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~PDUSessionsCollectionApi() {}
void init();
const std::string base = "/nsmf-pdusession/v1";
private:
void setupRoutes();
void post_pdu_sessions_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void pdu_sessions_collection_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
/// <summary>
/// Create
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="pduSessionCreateData">representation of the PDU session to be created in the H-SMF</param>
virtual void post_pdu_sessions(const PduSessionCreateData &pduSessionCreateData, Pistache::Http::ResponseWriter &response) = 0;
};
}
}
}