diff --git a/src/api-server/impl/IndividualSMPolicyDocumentApiImpl.cpp b/src/api-server/impl/IndividualSMPolicyDocumentApiImpl.cpp old mode 100755 new mode 100644 index fb44c5452a738e56317aca05622c6d179260a549..2ab42763810c3c04f12bffb2076b22d38539fdc3 --- a/src/api-server/impl/IndividualSMPolicyDocumentApiImpl.cpp +++ b/src/api-server/impl/IndividualSMPolicyDocumentApiImpl.cpp @@ -38,26 +38,27 @@ void IndividualSMPolicyDocumentApiImpl::delete_sm_policy( std::string problem_description; std::string content_type = "application/problem+json"; nlohmann::json json_data; - int http_code = 0; + http_status_code_e http_code; status_code res = m_smpc_service->delete_sm_policy_handler( smPolicyId, smPolicyDeleteData, problem_description); switch (res) { case status_code::OK: - http_code = HTTP_STATUS_CODE_204_NO_CONTENT; + http_code = http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT; break; case status_code::NOT_FOUND: problem_details.setDetail(problem_description); // This is not defined in the standard problem_details.setCause("SM_POLICY_ID_NOT_FOUND"); - http_code = HTTP_STATUS_CODE_404_NOT_FOUND; + http_code = http_status_code_e::HTTP_STATUS_CODE_404_NOT_FOUND; break; default: problem_details.setDetail("Internal Service Error: Unknown return code."); problem_details.setCause("INTERNAL_ERROR"); - http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = + http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; } if (res == status_code::OK) { @@ -76,7 +77,7 @@ void IndividualSMPolicyDocumentApiImpl::get_sm_policy( std::string problem_description; std::string content_type = "application/problem+json"; nlohmann::json json_data; - int http_code = 0; + http_status_code_e http_code; SmPolicyControl sm_policy_control; @@ -85,7 +86,7 @@ void IndividualSMPolicyDocumentApiImpl::get_sm_policy( switch (res) { case status_code::OK: - http_code = HTTP_STATUS_CODE_200_OK; + http_code = http_status_code_e::HTTP_STATUS_CODE_200_OK; content_type = "application/json"; break; @@ -93,13 +94,14 @@ void IndividualSMPolicyDocumentApiImpl::get_sm_policy( problem_details.setDetail(problem_description); // This is not defined in the standard problem_details.setCause("SM_POLICY_ID_NOT_FOUND"); - http_code = HTTP_STATUS_CODE_404_NOT_FOUND; + http_code = http_status_code_e::HTTP_STATUS_CODE_404_NOT_FOUND; break; default: problem_details.setDetail("Internal Service Error: Unknown return code."); problem_details.setCause("INTERNAL_ERROR"); - http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = + http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; } if (res == status_code::OK) { @@ -122,7 +124,7 @@ void IndividualSMPolicyDocumentApiImpl::update_sm_policy( std::string problem_description = ""; std::string content_type = "application/problem+json"; nlohmann::json json_data; - int http_code = 0; + http_status_code_e http_code; SmPolicyDecision decision_update; @@ -135,26 +137,27 @@ void IndividualSMPolicyDocumentApiImpl::update_sm_policy( switch (res) { case status_code::OK: content_type = "application/json"; - http_code = HTTP_STATUS_CODE_200_OK; + http_code = http_status_code_e::HTTP_STATUS_CODE_200_OK; break; case status_code::INVALID_PARAMETERS: - http_code = HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; problem_details.setCause("ERROR_INITIAL_PARAMETERS"); break; case status_code::CONTEXT_DENIED: // should map to 403 but not defined in standard for this request - http_code = HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; problem_details.setCause("ERROR_INITIAL_PARAMETERS"); break; case status_code::NOT_FOUND: // TODO This is not defined in the standard, but this scenario is missig // we could map it to the 400 Bad request but that is somehow misleading problem_details.setCause("SM_POLICY_ID_NOT_FOUND"); - http_code = HTTP_STATUS_CODE_404_NOT_FOUND; + http_code = http_status_code_e::HTTP_STATUS_CODE_404_NOT_FOUND; break; default: problem_details.setCause("INTERNAL_ERROR"); - http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = + http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; } if (res == status_code::OK) { diff --git a/src/api-server/impl/SMPoliciesCollectionApiImpl.cpp b/src/api-server/impl/SMPoliciesCollectionApiImpl.cpp index 4360683c9326fd29d05a83ef312799293f06286f..fece0e83dc6183b2dcc449c1bfa3af5bbaa62975 100755 --- a/src/api-server/impl/SMPoliciesCollectionApiImpl.cpp +++ b/src/api-server/impl/SMPoliciesCollectionApiImpl.cpp @@ -36,7 +36,7 @@ SMPoliciesCollectionApiImpl::SMPoliciesCollectionApiImpl( void SMPoliciesCollectionApiImpl::create_sm_policy( const SmPolicyContextData& smPolicyContextData, Pistache::Http::ResponseWriter& response) { - int http_code = 500; + http_status_code_e http_code; std::string cause; ProblemDetails problem_details; SmPolicyDecision decision; @@ -51,7 +51,7 @@ void SMPoliciesCollectionApiImpl::create_sm_policy( switch (res) { case status_code::CREATED: - http_code = HTTP_STATUS_CODE_201_CREATED; + http_code = http_status_code_e::HTTP_STATUS_CODE_201_CREATED; location = m_address + base + "/sm-policies/" + association_id; content_type = "application/json"; break; @@ -59,29 +59,29 @@ void SMPoliciesCollectionApiImpl::create_sm_policy( case status_code::USER_UNKOWN: problem_details.setCause("USER_UNKOWN"); problem_details.setDetail(details_string); - http_code = HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; break; case status_code::INVALID_PARAMETERS: problem_details.setCause("ERROR_INITIAL_PARAMETERS"); problem_details.setDetail(details_string); - http_code = HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; break; case status_code::CONTEXT_DENIED: problem_details.setCause("POLICY_CONTEXT_DENIED"); problem_details.setDetail(details_string); - http_code = HTTP_STATUS_CODE_403_FORBIDDEN; + http_code = http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN; break; default: Logger::pcf_app().error("Unknown error code"); - http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; problem_details.setCause("INTERNAL_ERROR"); problem_details.setDetail("Internal Service Error: Unknown return code."); } - if (http_code != HTTP_STATUS_CODE_201_CREATED) { + if (http_code != http_status_code_e::HTTP_STATUS_CODE_201_CREATED) { to_json(json_data, problem_details); } else { to_json(json_data, decision); diff --git a/src/common/3gpp_29.500.h b/src/common/3gpp_29.500.h index f7ab3d88ea813188f6e202f2761a3137df07bfe6..459e09caaf74da7684689bdecd4c0bcb1e04981e 100644 --- a/src/common/3gpp_29.500.h +++ b/src/common/3gpp_29.500.h @@ -4,8 +4,8 @@ * 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 + * file except in compliance with the License. You may obtain a copy of the + * License at * * http://www.openairinterface.org/?page_id=698 * @@ -18,13 +18,20 @@ * For more information about the OpenAirInterface (OAI) Software Alliance: * contact@openairinterface.org */ + +/*! \file 3gpp_29.500.h + \brief + \author Stefan Spettel + \company OpenAirInterface Software Alliance + \email: stefan.spettel@eurecom.fr +*/ + #include <string> #include <vector> -#ifndef FILE_3GPP_29_500_SEEN -#define FILE_3GPP_29_500_SEEN +#pragma once -enum http_status_code_e { +enum class http_status_code_e { HTTP_STATUS_CODE_100_CONTINUE = 100, HTTP_STATUS_CODE_200_OK = 200, HTTP_STATUS_CODE_201_CREATED = 201, @@ -52,7 +59,8 @@ enum http_status_code_e { HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR = 500, HTTP_STATUS_CODE_501_NOT_IMPLEMENTED = 501, HTTP_STATUS_CODE_503_SERVICE_UNAVAILABLE = 503, - HTTP_STATUS_CODE_504_GATEWAY_TIMEOUT = 504 + HTTP_STATUS_CODE_504_GATEWAY_TIMEOUT = 504, + NO_RESPONSE = 0 }; enum protocol_application_error_e { @@ -97,5 +105,3 @@ static const std::vector<std::string> protocol_application_error_e2str{ "UNSPECIFIED_NF_FAILURE", "SYSTEM_FAILURE", "NF_CONGESTION"}; - -#endif // FILE_3GPP_29_500_SEEN diff --git a/src/common/pcf.h b/src/common/pcf.h index 9540bf7bc3a4933b71a5c93adbf78f01791be9fd..da2692a8370d28081accc3f786ce5556066477ba 100644 --- a/src/common/pcf.h +++ b/src/common/pcf.h @@ -27,34 +27,6 @@ #include <netinet/in.h> #include <arpa/inet.h> -// 3GPP TS 29.571 (Common data) -enum http_response_codes_e { - HTTP_RESPONSE_CODE_OK = 200, - HTTP_RESPONSE_CODE_CREATED = 201, - HTTP_RESPONSE_CODE_ACCEPTED = 202, - HTTP_RESPONSE_CODE_NO_CONTENT = 204, - HTTP_RESPONSE_CODE_BAD_REQUEST = 400, - HTTP_RESPONSE_CODE_UNAUTHORIZED = 401, - HTTP_RESPONSE_CODE_FORBIDDEN = 403, - HTTP_RESPONSE_CODE_NOT_FOUND = 404, - HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED = 405, - HTTP_RESPONSE_CODE_REQUEST_TIMEOUT = 408, - HTTP_RESPONSE_CODE_406_NOT_ACCEPTED = 406, - HTTP_RESPONSE_CODE_CONFLICT = 409, - HTTP_RESPONSE_CODE_GONE = 410, - HTTP_RESPONSE_CODE_LENGTH_REQUIRED = 411, - HTTP_RESPONSE_CODE_PRECONDITION_FAILED = 412, - HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE = 413, - HTTP_RESPONSE_CODE_URI_TOO_LONG = 414, - HTTP_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 415, - HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS = 429, - HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500, - HTTP_RESPONSE_CODE_NOT_IMPLEMENTED = 501, - HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE = 503, - HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT = 504, - NO_RESPONE = 0 -}; - #define HEART_BEAT_TIMER 10 #define _unused(x) ((void) (x)) diff --git a/src/pcf_app/pcf_client.cpp b/src/pcf_app/pcf_client.cpp index 8b83eabcaaed3f504e82b984bdc41b03175f9943..1cba62ef7d92c43fccca19574106b5b17289a5a2 100644 --- a/src/pcf_app/pcf_client.cpp +++ b/src/pcf_app/pcf_client.cpp @@ -35,6 +35,7 @@ #include <stdexcept> #include "logger.hpp" +#include "3gpp_29.500.h" #include "pcf.h" #include "pcf_config.hpp" @@ -64,41 +65,41 @@ pcf_client::~pcf_client() { Logger::pcf_app().debug("Delete PCF Client instance..."); } -http_response_codes_e pcf_client::send_post( +http_status_code_e pcf_client::send_post( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) { - return do_request(url, http_methods_e::POST, body, response, resp_headers); + return do_request(url, http_method_e::POST, body, response, resp_headers); } -http_response_codes_e pcf_client::send_get( +http_status_code_e pcf_client::send_get( const std::string& url, std::string& response, std::string& resp_header) { - return do_request(url, http_methods_e::GET, "", response, resp_header); + return do_request(url, http_method_e::GET, "", response, resp_header); } -http_response_codes_e pcf_client::send_put( +http_status_code_e pcf_client::send_put( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) { - return do_request(url, http_methods_e::PUT, body, response, resp_headers); + return do_request(url, http_method_e::PUT, body, response, resp_headers); } -http_response_codes_e pcf_client::send_patch( +http_status_code_e pcf_client::send_patch( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) { - return do_request(url, http_methods_e::PATCH, body, response, resp_headers); + return do_request(url, http_method_e::PATCH, body, response, resp_headers); } -http_response_codes_e pcf_client::send_delete( +http_status_code_e pcf_client::send_delete( const std::string& url, std::string& response, std::string& resp_headers) { - return do_request(url, http_methods_e::DELETE, "", response, resp_headers); + return do_request(url, http_method_e::DELETE, "", response, resp_headers); } -http_response_codes_e pcf_client::do_request( - const std::string& url, const http_methods_e& method, +http_status_code_e pcf_client::do_request( + const std::string& url, const http_method_e& method, const std::string& body, std::string& response, std::string& resp_headers) { CURL* curl = curl_easy_init(); if (!curl) { Logger::pcf_sbi().error("Could not create HTTP Client"); - return http_response_codes_e::NO_RESPONE; + return http_status_code_e::NO_RESPONSE; } prepare_curl_method(curl, method); @@ -147,7 +148,7 @@ http_response_codes_e pcf_client::do_request( url.c_str(), res); curl_slist_free_all(headers); curl_easy_cleanup(curl); - return http_response_codes_e::NO_RESPONE; + return http_status_code_e::NO_RESPONSE; } long http_code = -1; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); @@ -158,25 +159,24 @@ http_response_codes_e pcf_client::do_request( curl_slist_free_all(headers); curl_easy_cleanup(curl); - return http_response_codes_e(http_code); + return http_status_code_e(http_code); } -void pcf_client::prepare_curl_method( - CURL*& curl, const http_methods_e& method) { +void pcf_client::prepare_curl_method(CURL*& curl, const http_method_e& method) { switch (method) { - case GET: + case http_method_e::GET: curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); break; - case POST: + case http_method_e::POST: curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1); break; - case PATCH: + case http_method_e::PATCH: curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH"); break; - case PUT: + case http_method_e::PUT: curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); break; - case DELETE: + case http_method_e::DELETE: curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); break; } diff --git a/src/pcf_app/pcf_client.hpp b/src/pcf_app/pcf_client.hpp index 8940a042c572eb219602f50033d901428067f093..c614b17e427a1df10b56b175bcce8a8bfd38c5ca 100644 --- a/src/pcf_app/pcf_client.hpp +++ b/src/pcf_app/pcf_client.hpp @@ -33,11 +33,11 @@ #include <map> #include <thread> -#include "pcf.h" +#include "3gpp_29.500.h" namespace oai::pcf::app { -enum http_methods_e { POST = 1, GET = 2, PUT = 3, PATCH = 4, DELETE = 5 }; +enum class http_method_e { POST, GET, PUT, PATCH, DELETE }; class pcf_client_iface { public: @@ -49,7 +49,7 @@ class pcf_client_iface { * @param resp_headers Response headers * @return HTTP response code */ - virtual http_response_codes_e send_post( + virtual http_status_code_e send_post( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) = 0; @@ -60,7 +60,7 @@ class pcf_client_iface { * @param resp_header * @return HTTP response code */ - virtual http_response_codes_e send_get( + virtual http_status_code_e send_get( const std::string& url, std::string& response, std::string& resp_header) = 0; @@ -72,7 +72,7 @@ class pcf_client_iface { * @param resp_headers Response headers * @return HTTP response code */ - virtual http_response_codes_e send_put( + virtual http_status_code_e send_put( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) = 0; @@ -84,7 +84,7 @@ class pcf_client_iface { * @param resp_headers Response headers * @return HTTP response code */ - virtual http_response_codes_e send_patch( + virtual http_status_code_e send_patch( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) = 0; @@ -95,41 +95,41 @@ class pcf_client_iface { * @param resp_headers Response headers * @return HTTP response code */ - virtual http_response_codes_e send_delete( + virtual http_status_code_e send_delete( const std::string& url, std::string& response, std::string& resp_headers) = 0; }; class pcf_client : pcf_client_iface { private: - static http_response_codes_e do_request( - const std::string& url, const http_methods_e& method, + static http_status_code_e do_request( + const std::string& url, const http_method_e& method, const std::string& body, std::string& response, std::string& resp_headers); - static void prepare_curl_method(CURL*& curl, const http_methods_e& method); + static void prepare_curl_method(CURL*& curl, const http_method_e& method); public: pcf_client(); virtual ~pcf_client(); - http_response_codes_e send_post( + http_status_code_e send_post( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) override; - http_response_codes_e send_get( + http_status_code_e send_get( const std::string& url, std::string& response, std::string& resp_header) override; - http_response_codes_e send_put( + http_status_code_e send_put( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) override; - http_response_codes_e send_patch( + http_status_code_e send_patch( const std::string& url, const std::string& body, std::string& response, std::string& resp_headers) override; - http_response_codes_e send_delete( + http_status_code_e send_delete( const std::string& url, std::string& response, std::string& resp_headers) override; diff --git a/src/pcf_app/pcf_nrf.cpp b/src/pcf_app/pcf_nrf.cpp index 71d8d87120f7043ce7696c1b06697c312bb536d6..03b3e262c1dbd94204be1fd67922f0fe97672bdf 100644 --- a/src/pcf_app/pcf_nrf.cpp +++ b/src/pcf_app/pcf_nrf.cpp @@ -30,7 +30,7 @@ #include "pcf_nrf.hpp" #include "conversions.hpp" #include "logger.hpp" -#include "pcf.h" +#include "3gpp_29.500.h" #include "pcf_config.hpp" #include "pcf_client.hpp" #include "Snssai.h" @@ -136,11 +136,11 @@ void pcf_nrf::register_to_nrf() { std::string resp_headers; Logger::pcf_sbi().info("Sending NF registration request"); - http_response_codes_e res = + http_status_code_e res = pcf_client_inst->send_put(nrf_url, body.dump(), resp_body, resp_headers); - if (res == http_response_codes_e::HTTP_RESPONSE_CODE_CREATED or - res == http_response_codes_e::HTTP_RESPONSE_CODE_OK) { + if (res == http_status_code_e::HTTP_STATUS_CODE_201_CREATED or + res == http_status_code_e::HTTP_STATUS_CODE_200_OK) { try { if (resp_body.find("REGISTERED") != 0) { start_event_nf_heartbeat(nrf_url); @@ -185,11 +185,11 @@ void pcf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) { nlohmann::json j; to_json(j, patch_item); - http_response_codes_e res = pcf_client_inst->send_patch( + http_status_code_e res = pcf_client_inst->send_patch( nrf_url, j.dump(), body_response, response_headers); - if (res == http_response_codes_e::HTTP_RESPONSE_CODE_OK or - res == http_response_codes_e::HTTP_RESPONSE_CODE_NO_CONTENT) { + if (res == http_status_code_e::HTTP_STATUS_CODE_200_OK or + res == http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { Logger::pcf_sbi().debug("NF heartbeat request successful"); } else { // TODO what should we do in this case? @@ -211,10 +211,10 @@ void pcf_nrf::deregister_to_nrf() { Logger::pcf_sbi().info("Sending NF de-registration request"); - http_response_codes_e res = + http_status_code_e res = pcf_client_inst->send_delete(nrf_url, body_response, response_header); - if (res != http_response_codes_e::HTTP_RESPONSE_CODE_NO_CONTENT) { + if (res != http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { Logger::pcf_sbi().warn( "NF Deregistration failed! Wrong response code: %d", res); } else {