diff --git a/build/common-build b/build/common-build index fb0498f356198301621c5ca4da3e2c2fca4c9855..0968c25ea2414dac69181dc57a23ee17848c3111 160000 --- a/build/common-build +++ b/build/common-build @@ -1 +1 @@ -Subproject commit fb0498f356198301621c5ca4da3e2c2fca4c9855 +Subproject commit 0968c25ea2414dac69181dc57a23ee17848c3111 diff --git a/build/scripts/build_helper.pcf b/build/scripts/build_helper.pcf index b0a988a6cff933f0e957084482cea97e1e68d48a..4f92a9c4c25b2ed8d913fab8ae92f877efefe420 100644 --- a/build/scripts/build_helper.pcf +++ b/build/scripts/build_helper.pcf @@ -36,6 +36,7 @@ source $THIS_SCRIPT_PATH/../common-build/installation/build_helper.pistache source $THIS_SCRIPT_PATH/../common-build/installation/build_helper.nlohmann source $THIS_SCRIPT_PATH/../common-build/installation/build_helper.nghttp2 source $THIS_SCRIPT_PATH/../common-build/installation/build_helper.yamlcpp +source $THIS_SCRIPT_PATH/../common-build/installation/build_helper.cpr #------------------------------------------------------------------------------- #arg1 is force (0 or 1) (no interactive script) @@ -164,6 +165,9 @@ check_install_pcf_deps() { install_nghttp2_from_git $1 $2 ret=$?;[[ $ret -ne 0 ]] && return $ret + install_cpr_from_git $1 $2 + ret=$?;[[ $ret -ne 0 ]] && return $ret + # latest usage of yaml-cpp suggests that we should be using 0.7+ version # To be sure, let's install from source all the time for the moment if [[ $OS_DISTRO == "ubuntu" ]]; then diff --git a/docker/Dockerfile.pcf.rhel9 b/docker/Dockerfile.pcf.rhel9 index 214f27c449cc7bb9c63e55db6fe5cfd5feac97c1..0e3d96bc15b5581c73c6e0aa498dbcb94d48a593 100644 --- a/docker/Dockerfile.pcf.rhel9 +++ b/docker/Dockerfile.pcf.rhel9 @@ -128,6 +128,7 @@ COPY --from=oai-pcf-builder \ /usr/local/lib64/libspdlog.so \ /usr/local/lib64/libfmt.so \ /usr/local/lib64/libyaml-cpp.so.0.* \ + /usr/local/lib64/libcpr.so.1 \ /usr/lib64/ RUN ldconfig && \ diff --git a/docker/Dockerfile.pcf.rocky9 b/docker/Dockerfile.pcf.rocky9 index 66f404f59fdafbf5f5bea4f5a1e440ae1619dcfe..db574dca7fc2fbdb9298ae5f8e82fe1678ac9e04 100644 --- a/docker/Dockerfile.pcf.rocky9 +++ b/docker/Dockerfile.pcf.rocky9 @@ -106,6 +106,7 @@ COPY --from=oai-pcf-builder \ /usr/local/lib64/libspdlog.so \ /usr/local/lib64/libfmt.so \ /usr/local/lib64/libyaml-cpp.so.0.* \ + /usr/local/lib64/libcpr.so.1 \ /usr/lib64/ RUN ldconfig && \ diff --git a/docker/Dockerfile.pcf.ubuntu b/docker/Dockerfile.pcf.ubuntu index 88966a5ab2024daba8e930e8e20e649786dc9005..2a7a0ca55cbc6bed816192f265fb24b528aecbdc 100644 --- a/docker/Dockerfile.pcf.ubuntu +++ b/docker/Dockerfile.pcf.ubuntu @@ -119,6 +119,7 @@ COPY --from=oai-pcf-builder \ /usr/local/lib/libnghttp2.so.14 \ /usr/local/lib/libnghttp2_asio.so.1 \ /usr/local/lib/libyaml-cpp.so.0.? \ + /usr/local/lib/libcpr.so.1 \ /usr/local/lib/libspdlog.so \ /usr/local/lib/libfmt.so \ ./ diff --git a/src/api-server/CMakeLists.txt b/src/api-server/CMakeLists.txt index 4412458c3016b5ef694a8cc1fb6db63856ba4a98..0ec7a0e19a6e1ae96359c9d9072a046613c918ab 100644 --- a/src/api-server/CMakeLists.txt +++ b/src/api-server/CMakeLists.txt @@ -33,6 +33,8 @@ include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/common_model/common_model.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/pcf/pcf_model.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/smf/smf_model.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/common/common.cmake) file(GLOB PCF_API_SERVER_src_files ${PCF_API_SERVER_DIR}/pcf-api-server.cpp diff --git a/src/api-server/handler/api_response.h b/src/api-server/handler/api_response.h index 3a5597ef7d38e186248404b12ee5004b34589a53..888d73d5bf2e633964fe9922823bd4ff8f83d998 100644 --- a/src/api-server/handler/api_response.h +++ b/src/api-server/handler/api_response.h @@ -37,7 +37,7 @@ namespace oai::pcf::api { struct api_response { - http_status_code_e status_code; + uint16_t status_code; Pistache::Http::Header::Collection headers; std::string body; }; diff --git a/src/api-server/handler/individual_sm_policy_document_api_handler.cpp b/src/api-server/handler/individual_sm_policy_document_api_handler.cpp index 2ec29dd544f57b7a8524b94da9cd618848a12094..427b76d4b7017e58a443ab7e7dca757adcb0de0e 100644 --- a/src/api-server/handler/individual_sm_policy_document_api_handler.cpp +++ b/src/api-server/handler/individual_sm_policy_document_api_handler.cpp @@ -35,6 +35,7 @@ namespace oai::pcf::api { using namespace oai::model::pcf; using namespace oai::model::common; using namespace oai::pcf::app::sm_policy; +using namespace oai::common::sbi; api_response individual_sm_policy_document_api_handler::delete_sm_policy( const std::string& sm_policy_id, @@ -45,27 +46,26 @@ api_response individual_sm_policy_document_api_handler::delete_sm_policy( std::string problem_description; std::string content_type = "application/problem+json"; nlohmann::json json_data; - http_status_code_e http_code; + uint16_t http_code; status_code res = m_smpc_service->delete_sm_policy_handler( sm_policy_id, sm_policy_delete_data, problem_description); switch (res) { case status_code::OK: - http_code = http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT; + http_code = http_status_code::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_e::HTTP_STATUS_CODE_404_NOT_FOUND; + http_code = http_status_code::NOT_FOUND; break; default: problem_details.setDetail("Internal Service Error: Unknown return code."); problem_details.setCause("INTERNAL_ERROR"); - http_code = - http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = http_status_code::INTERNAL_SERVER_ERROR; } response.status_code = http_code; if (res != status_code::OK) { @@ -84,7 +84,7 @@ api_response individual_sm_policy_document_api_handler::get_sm_policy( std::string problem_description; std::string content_type = "application/problem+json"; nlohmann::json json_data; - http_status_code_e http_code; + uint16_t http_code; SmPolicyControl sm_policy_control; @@ -93,7 +93,7 @@ api_response individual_sm_policy_document_api_handler::get_sm_policy( switch (res) { case status_code::OK: - http_code = http_status_code_e::HTTP_STATUS_CODE_200_OK; + http_code = http_status_code::OK; content_type = "application/json"; break; @@ -101,14 +101,13 @@ api_response individual_sm_policy_document_api_handler::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_e::HTTP_STATUS_CODE_404_NOT_FOUND; + http_code = http_status_code::NOT_FOUND; break; default: problem_details.setDetail("Internal Service Error: Unknown return code."); problem_details.setCause("INTERNAL_ERROR"); - http_code = - http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = http_status_code::INTERNAL_SERVER_ERROR; } if (res == status_code::OK) { @@ -132,7 +131,7 @@ api_response individual_sm_policy_document_api_handler::update_sm_policy( std::string problem_description; std::string content_type = "application/problem+json"; nlohmann::json json_data; - http_status_code_e http_code; + uint16_t http_code; SmPolicyDecision decision_update; @@ -145,27 +144,26 @@ api_response individual_sm_policy_document_api_handler::update_sm_policy( switch (res) { case status_code::OK: content_type = "application/json"; - http_code = http_status_code_e::HTTP_STATUS_CODE_200_OK; + http_code = http_status_code::OK; break; case status_code::INVALID_PARAMETERS: - http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code::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_e::HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code::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 missing // 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_e::HTTP_STATUS_CODE_404_NOT_FOUND; + http_code = http_status_code::NOT_FOUND; break; default: problem_details.setCause("INTERNAL_ERROR"); - http_code = - http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = http_status_code::INTERNAL_SERVER_ERROR; } if (res == status_code::OK) { diff --git a/src/api-server/handler/sm_policies_collection_api_handler.cpp b/src/api-server/handler/sm_policies_collection_api_handler.cpp index 301ec20be99200e3c8fe6356fd7fc4b9f2748a8e..e5954d3be492b828b526a0e01c73b96e929e80e1 100644 --- a/src/api-server/handler/sm_policies_collection_api_handler.cpp +++ b/src/api-server/handler/sm_policies_collection_api_handler.cpp @@ -42,10 +42,11 @@ namespace oai::pcf::api { using namespace oai::model::pcf; using namespace oai::model::common; using namespace oai::pcf::app::sm_policy; +using namespace oai::common::sbi; api_response sm_policies_collection_api_handler::create_sm_policy( const SmPolicyContextData& sm_policy_context_data) { - http_status_code_e http_code; + uint16_t http_code; std::string cause; ProblemDetails problem_details; SmPolicyDecision decision; @@ -61,7 +62,7 @@ api_response sm_policies_collection_api_handler::create_sm_policy( switch (res) { case status_code::CREATED: - http_code = http_status_code_e::HTTP_STATUS_CODE_201_CREATED; + http_code = http_status_code::CREATED; location = m_address + sm_policies::get_route() + "/" + association_id; content_type = "application/json"; break; @@ -69,30 +70,29 @@ api_response sm_policies_collection_api_handler::create_sm_policy( case status_code::USER_UNKOWN: problem_details.setCause("USER_UNKOWN"); problem_details.setDetail(details_string); - http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code::BAD_REQUEST; break; case status_code::INVALID_PARAMETERS: problem_details.setCause("ERROR_INITIAL_PARAMETERS"); problem_details.setDetail(details_string); - http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; + http_code = http_status_code::BAD_REQUEST; break; case status_code::CONTEXT_DENIED: problem_details.setCause("POLICY_CONTEXT_DENIED"); problem_details.setDetail(details_string); - http_code = http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN; + http_code = http_status_code::FORBIDDEN; break; default: Logger::pcf_app().error("Unknown error code"); - http_code = - http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; + http_code = http_status_code::INTERNAL_SERVER_ERROR; problem_details.setCause("INTERNAL_ERROR"); problem_details.setDetail("Internal Service Error: Unknown return code."); } - if (http_code != http_status_code_e::HTTP_STATUS_CODE_201_CREATED) { + if (http_code != http_status_code::CREATED) { to_json(json_data, problem_details); } else { to_json(json_data, decision); diff --git a/src/api-server/pcf-http2-server.cpp b/src/api-server/pcf-http2-server.cpp index 29dc57c727305a20bdf2c15a3eb39600e88b2a17..f1b427f48af863c359a771d2e3f8c2d7baf096e6 100644 --- a/src/api-server/pcf-http2-server.cpp +++ b/src/api-server/pcf-http2-server.cpp @@ -46,6 +46,7 @@ using namespace nghttp2::asio_http2::server; using namespace oai::model::pcf; using namespace oai::config::pcf; using namespace oai::pcf::api; +using namespace oai::common::sbi; extern std::unique_ptr<pcf_config> pcf_cfg; @@ -190,16 +191,14 @@ void pcf_http2_server::handle_method_not_exists( Logger::pcf_sbi().warn( "Invalid route/method called: %s : %s", request.method(), request.uri().path); - response.write_head(static_cast<unsigned int>( - http_status_code_e::HTTP_STATUS_CODE_404_NOT_FOUND)); + response.write_head(static_cast<unsigned int>(http_status_code::NOT_FOUND)); response.end("The requested method does not exist"); } void pcf_http2_server::handle_parsing_error( const response& response, const std::exception& ex) { Logger::pcf_sbi().warn("Parsing error: %s", ex.what()); - response.write_head(static_cast<unsigned int>( - http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST)); + response.write_head(static_cast<unsigned int>(http_status_code::BAD_REQUEST)); // for security reasons it is better to not give the internal exception to the // user, we can also decide to change that response.end("Could not parse JSON data"); diff --git a/src/api-server/pcf-http2-server.hpp b/src/api-server/pcf-http2-server.hpp index 6d3d2e836dddb67e4d6869d58f45fb3a1e324e28..2eb4e1732576763b093fe861625e8d2e43cdf46f 100644 --- a/src/api-server/pcf-http2-server.hpp +++ b/src/api-server/pcf-http2-server.hpp @@ -29,8 +29,6 @@ #pragma once -#include "conversions.hpp" -#include "pcf.h" #include "pcf_app.hpp" #include "string.hpp" #include "uint_generator.hpp" @@ -68,7 +66,7 @@ class pcf_http2_server { void stop(); private: - util::uint_generator<uint32_t> m_promise_id_generator; + oai::utils::uint_generator<uint32_t> m_promise_id_generator; std::string m_address; uint32_t m_port; bool running_server; diff --git a/src/common/3gpp_23.003.h b/src/common/3gpp_23.003.h deleted file mode 100644 index 9f47b7f9adfc1a12e025b887c2b410f152162944..0000000000000000000000000000000000000000 --- a/src/common/3gpp_23.003.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file 3gpp_23.003.h - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr - */ -#ifndef FILE_3GPP_23_003_SEEN -#define FILE_3GPP_23_003_SEEN - -#include <stdint.h> - -typedef struct plmn_s { - uint8_t mcc_digit2 : 4; - uint8_t mcc_digit1 : 4; - uint8_t mcc_digit3 : 4; - uint8_t mnc_digit3 : 4; - uint8_t mnc_digit2 : 4; - uint8_t mnc_digit1 : 4; -} plmn_t; - -#define INVALID_TAC_0000 (uint16_t) 0x0000 -#define INVALID_TAC_FFFE (uint16_t) 0xFFFE -#define INVALID_TAC (uint32_t) 0x00000000 - -#define INVALID_TMSI \ - UINT32_MAX /*!< \brief The network shall not allocate a TMSI with all 32 \ - bits equal to 1 (this is because the TMSI must be stored in \ - the SIM, and the SIM uses 4 octets with all bits \ - equal to 1 to indicate that no valid TMSI is \ - available). */ -typedef uint16_t tac_t; -typedef struct tai_s { - plmn_t plmn; /*!< \brief <MCC> + <MNC> */ - tac_t tac; /*!< \brief Tracking Area Code */ -} tai_t; - -typedef struct eci_s { - uint32_t gnb_id : 20; - uint32_t cell_id : 8; - uint32_t empty : 4; -} ci_t; - -typedef struct cgi_s { - plmn_t plmn; - ci_t cell_identity; // 28 bits -} cgi_t; - -typedef struct nr_tai_s /*5G ADD it*/ -{ - plmn_t plmn; - uint32_t tac : 24; -} nr_tai_t; - -typedef struct nr_cell_identity_s /*5G ADD it */ -{ - uint32_t gnb_id; - uint8_t cell_id : 4; -} nr_cell_identity_t; - -typedef struct nr_cgi_s /*5G ADD it */ -{ - plmn_t plmn; - nr_cell_identity_t cell_identity; -} nr_cgi_t; - -typedef struct fiveG_s_tmsi_s /*5G ADD it */ -{ - uint16_t amf_set_id : 10; - uint8_t amf_pointer : 6; - uint32_t fiveG_s_tmsi; // 32 -} fiveG_s_tmsi_t; - -typedef struct fiveG_s_gua_s /*5G ADD it */ -{ - plmn_t plmn; - uint8_t region_id; - uint16_t amf_set_id : 10; - uint8_t amf_pointer : 6; - -} fiveG_s_gua_t; - -typedef struct amf_set_id_s /*5G ADD it*/ -{ - uint16_t amf_set_id : 10; -} amf_set_id_t; - -typedef struct allowed_nssai /*5G ADD it*/ -{ - uint8_t sST; - uint32_t sD : 24; -} allowed_nssai; - -// typedef struct allowed_nssai_s /*5G ADD it*/ -// { -// allowed_nssai* s_nssai; -// uint32_t count; -// } allowed_nssai_t; - -#endif diff --git a/src/common/3gpp_29.500.h b/src/common/3gpp_29.500.h deleted file mode 100644 index 459e09caaf74da7684689bdecd4c0bcb1e04981e..0000000000000000000000000000000000000000 --- a/src/common/3gpp_29.500.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * 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> - -#pragma once - -enum class http_status_code_e { - HTTP_STATUS_CODE_100_CONTINUE = 100, - HTTP_STATUS_CODE_200_OK = 200, - HTTP_STATUS_CODE_201_CREATED = 201, - HTTP_STATUS_CODE_202_ACCEPTED = 202, - HTTP_STATUS_CODE_204_NO_CONTENT = 204, - HTTP_STATUS_CODE_300_MULTIPLE_CHOICES = 300, - HTTP_STATUS_CODE_303_SEE_OTHER = 303, - HTTP_STATUS_CODE_307_TEMPORARY_REDIRECT = 307, - HTTP_STATUS_CODE_308_PERMANENT_REDIRECT = 308, - HTTP_STATUS_CODE_400_BAD_REQUEST = 400, - HTTP_STATUS_CODE_401_UNAUTHORIZED = 401, - HTTP_STATUS_CODE_403_FORBIDDEN = 403, - HTTP_STATUS_CODE_404_NOT_FOUND = 404, - HTTP_STATUS_CODE_405_METHOD_NOT_ALLOWED = 405, - HTTP_STATUS_CODE_406_NOT_ACCEPTABLE = 406, - HTTP_STATUS_CODE_408_REQUEST_TIMEOUT = 408, - HTTP_STATUS_CODE_409_CONFLICT = 409, - HTTP_STATUS_CODE_410_GONE = 410, - HTTP_STATUS_CODE_411_LENGTH_REQUIRED = 411, - HTTP_STATUS_CODE_412_PRECONDITION_FAILED = 412, - HTTP_STATUS_CODE_413_PAYLOAD_TOO_LARGE = 413, - HTTP_STATUS_CODE_414_URI_TOO_LONG = 414, - HTTP_STATUS_CODE_415_UNSUPPORTED_MEDIA_TYPE_NA = 415, - HTTP_STATUS_CODE_429_TOO_MANY_REQUESTS = 429, - 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, - NO_RESPONSE = 0 -}; - -enum protocol_application_error_e { - PROTOCOL_APP_ERROR_INVALID_API = 0, // 400 Bad Request - PROTOCOL_APP_ERROR_INVALID_MSG_FORMAT = 1, // 400 Bad Request - PROTOCOL_APP_ERROR_INVALID_QUERY_PARAM = 2, // 400 Bad Request - PROTOCOL_APP_ERROR_MANDATORY_QUERY_PARAM_INCORRECT = 3, // 400 Bad Request - PROTOCOL_APP_ERROR_OPTIONAL_QUERY_PARAM_INCORRECT = 4, // 400 Bad Request - PROTOCOL_APP_ERROR_MANDATORY_QUERY_PARAM_MISSING = 5, // 400 Bad Request - PROTOCOL_APP_ERROR_MANDATORY_IE_INCORRECT = 6, // 400 Bad Request - PROTOCOL_APP_ERROR_OPTIONAL_IE_INCORRECT = 7, // 400 Bad Request - PROTOCOL_APP_ERROR_MANDATORY_IE_MISSING = 8, // 400 Bad Request - PROTOCOL_APP_ERROR_UNSPECIFIED_MSG_FAILURE = 9, // 400 Bad Request - PROTOCOL_APP_ERROR_MODIFICATION_NOT_ALLOWED = 10, // 403 Forbidden - PROTOCOL_APP_ERROR_SUBSCRIPTION_NOT_FOUND = 11, // 404 Not Found - PROTOCOL_APP_ERROR_RESOURCE_URI_STRUCTURE_NOT_FOUND = 12, // 404 Not Found - PROTOCOL_APP_ERROR_INCORRECT_LENGTH = 13, // 411 Length Required - PROTOCOL_APP_ERROR_NF_CONGESTION_RISK = 14, // 429 Too Many Requests - PROTOCOL_APP_ERROR_INSUFFICIENT_RESOURCES = 15, // 500 Internal Server Error - PROTOCOL_APP_ERROR_UNSPECIFIED_NF_FAILURE = 16, // 500 Internal Server Error - PROTOCOL_APP_ERROR_SYSTEM_FAILURE = 17, // 500 Internal Server Error - PROTOCOL_APP_ERROR_NF_CONGESTION = 18, // 503 Service Unavailable -}; - -static const std::vector<std::string> protocol_application_error_e2str{ - "INVALID_API", - "INVALID_MSG_FORMAT", - "INVALID_QUERY_PARAM", - "MANDATORY_QUERY_PARAM_INCORRECT", - "OPTIONAL_QUERY_PARAM_INCORRECT", - "MANDATORY_QUERY_PARAM_MISSING", - "MANDATORY_IE_INCORRECT", - "OPTIONAL_IE_INCORRECT", - "MANDATORY_IE_MISSING", - "UNSPECIFIED_MSG_FAILURE", - "MODIFICATION_NOT_ALLOWED", - "SUBSCRIPTION_NOT_FOUND", - "RESOURCE_URI_STRUCTURE_NOT_FOUND", - "INCORRECT_LENGTH ", - "NF_CONGESTION_RISK", - "INSUFFICIENT_RESOURCES", - "UNSPECIFIED_NF_FAILURE", - "SYSTEM_FAILURE", - "NF_CONGESTION"}; diff --git a/src/common/3gpp_29.510.h b/src/common/3gpp_29.510.h deleted file mode 100644 index 41eb5ad539d9a03742cc2a4d793ca4ccf05bf86c..0000000000000000000000000000000000000000 --- a/src/common/3gpp_29.510.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef FILE_3GPP_29_510_PCF_SEEN -#define FILE_3GPP_29_510_PCF_SEEN - -#include <vector> -#include <nlohmann/json.hpp> -#include "3gpp_23.003.h" - -// Section 28.4, TS23.003 -typedef struct s_nssai { - uint8_t sST; - std::string sD; - s_nssai(const uint8_t& sst, const std::string sd) : sST(sst), sD(sd) {} - s_nssai() : sST(), sD() {} - s_nssai(const s_nssai& p) : sST(p.sST), sD(p.sD) {} - bool operator==(const struct s_nssai& s) const { - if ((s.sST == this->sST) && (s.sD.compare(this->sD) == 0)) { - return true; - } else { - return false; - } - } - s_nssai& operator=(const s_nssai& s) { - sST = s.sST; - sD = s.sD; - return *this; - } - -} snssai_t; - -typedef struct dnai_s { -} dnai_t; - -typedef struct patch_item_s { - std::string op; - std::string path; - // std::string from; - std::string value; - - nlohmann::json to_json() const { - nlohmann::json json_data = {}; - json_data["op"] = op; - json_data["path"] = path; - json_data["value"] = value; - return json_data; - } -} patch_item_t; - -#define NSSF_CURL_TIMEOUT_MS 100L -#define NNRF_NFM_BASE "/nnrf-nfm/" -#define NSSF_NF_REGISTER_URL "/nf-instances/" - -// #### new data types -typedef struct tac_range_s { - std::string start; - std::string end; - std::string pattern; -} tac_range_t; - -typedef struct tai_range_s { - plmn_t plmnid; - std::vector<tac_range_t> tac_range_list; - // std::string Nid; -} tai_range_t; - -#endif diff --git a/src/common/3gpp_29.571.h b/src/common/3gpp_29.571.h deleted file mode 100644 index 7668a1a75b0cc81f21eeb6c24c1e6a6d03b7e1aa..0000000000000000000000000000000000000000 --- a/src/common/3gpp_29.571.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef FILE_3GPP_29_571_SEEN -#define FILE_3GPP_29_571_SEEN - -#include "3gpp_23.003.h" -#include "3gpp_29.510.h" - -#include <vector> - -enum access_type_e { ACESS_3GPP = 1, ACESS_NON_3GPP = 2 }; - -static const std::vector<std::string> access_type_e2str = { - "3GPP_ACCESS", "NON_3GPP_ACCESS"}; - -typedef struct sd_range_s { - std::string start; - std::string end; -} sd_range_t; - -typedef struct snssai_extension_s { - std::vector<sd_range_t> sd_ranges; - bool wildcard_sd; -} snssai_extension_t; - -typedef struct ext_snssai_s { - snssai_t snssai; - snssai_extension_t snssai_extension; -} ext_snssai_t; -#endif diff --git a/src/common/3gpp_commons.h b/src/common/3gpp_commons.h deleted file mode 100644 index bb61a259873e18943c194918edf2597553518c42..0000000000000000000000000000000000000000 --- a/src/common/3gpp_commons.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file 3gpp_commons.h - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_3GPP_COMMONS_SEEN -#define FILE_3GPP_COMMONS_SEEN - -#include <stdint.h> - -// 8.2 Recovery -typedef struct recovery_s { - uint8_t restart_counter; -} recovery_t; - -#endif /* FILE_3GPP_COMMONS_SEEN */ diff --git a/src/common/common_defs.h b/src/common/common_defs.h deleted file mode 100644 index 6e0f8c5ab2654f6d6cbf4b6829246a51d160c9fa..0000000000000000000000000000000000000000 --- a/src/common/common_defs.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common_defs.h - \brief - \author Sebastien ROUX, Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_COMMON_DEFS_SEEN -#define FILE_COMMON_DEFS_SEEN - -#include <arpa/inet.h> - -#define RETURNclear (int) 2 -#define RETURNerror (int) 1 -#define RETURNok (int) 0 - -//------------------------------------------------------------------------------ -#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR, InAdDr, MeSsAgE) \ - do { \ - if (inet_aton(AdDr_StR, &InAdDr) <= 0) { \ - throw(MeSsAgE); \ - } \ - } while (0) - -#define NIPADDR(addr) \ - (uint8_t)(addr & 0x000000FF), (uint8_t) ((addr & 0x0000FF00) >> 8), \ - (uint8_t) ((addr & 0x00FF0000) >> 16), \ - (uint8_t) ((addr & 0xFF000000) >> 24) - -#ifndef UNUSED -#define UNUSED(x) (void) (x) -#endif - -#endif /* FILE_COMMON_DEFS_SEEN */ diff --git a/src/common/common_root_types.c b/src/common/common_root_types.c deleted file mode 100644 index d48e382bcb95beb35c62be0630f353c87a7b45bd..0000000000000000000000000000000000000000 --- a/src/common/common_root_types.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common_root_types.c - \brief - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ diff --git a/src/common/common_root_types.h b/src/common/common_root_types.h deleted file mode 100644 index 9692c8d5e70ee46d731491545d3e99163309f322..0000000000000000000000000000000000000000 --- a/src/common/common_root_types.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common_root_types.h - \brief - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_COMMON_ROOT_TYPES_SEEN -#define FILE_COMMON_ROOT_TYPES_SEEN - -#include <stdint.h> -#include <inttypes.h> -#include <arpa/inet.h> - -//------------------------------------------------------------------------------ -#define PRIORITY_LEVEL_MAX (15) -#define PRIORITY_LEVEL_MIN (1) -#define BEARERS_PER_UE (11) -#define IMEI_DIGITS_MAX (15) -#define IMEISV_DIGITS_MAX (16) -#define MAX_APN_PER_UE (5) - -#define PROC_ID_FMT "0x%" PRIx64 - -// TEIDs -typedef uint32_t teid_t; -#define TEID_FMT "0x%" PRIx32 -#define TEID_SCAN_FMT SCNx32 -#define INVALID_TEID ((teid_t) 0x00000000) -#define UNASSIGNED_TEID ((teid_t) 0x00000000) - -// SEIDs -typedef uint64_t seid_t; -#define SEID_FMT "0x%" PRIx64 -#define SEID_SCAN_FMT SCNx64 -#define INVALID_SEID ((seid_t) 0x00000000) -#define UNASSIGNED_SEID ((seid_t) 0x00000000) - -//------------------------------------------------------------------------------ -// IMSI -typedef uint64_t imsi64_t; -#define IMSI_64_FMT "%" SCNu64 -#define INVALID_IMSI64 (imsi64_t) 0 - -//------------------------------------------------------------------------------ -typedef uint64_t bitrate_t; -#define PRIORITY_LEVEL_FMT "0x%" PRIu8 -#define QCI_FMT "0x%" PRIu8 -#define QCI_SCAN_FMT SCNu8 - -#define PRE_EMPTION_CAPABILITY_FMT "0x%" PRIu8 -#define PRE_EMPTION_VULNERABILITY_FMT "0x%" PRIu8 - -#endif /* FILE_COMMON_ROOT_TYPES_SEEN */ diff --git a/src/common/endpoint.hpp b/src/common/endpoint.hpp deleted file mode 100644 index f2656413c003434cfb05791547a02334de910aaa..0000000000000000000000000000000000000000 --- a/src/common/endpoint.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file endpoint.hpp - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_ENDPOINT_HPP_SEEN -#define FILE_ENDPOINT_HPP_SEEN - -#include "conversions.hpp" - -#include <arpa/inet.h> -#include <inttypes.h> -#include <sys/socket.h> -#include <string.h> - -class endpoint { - public: - struct sockaddr_storage addr_storage; - socklen_t addr_storage_len; - endpoint() - : addr_storage(), addr_storage_len(sizeof(struct sockaddr_storage)){}; - endpoint(const endpoint& e) - : addr_storage(e.addr_storage), addr_storage_len(e.addr_storage_len){}; - endpoint(const struct sockaddr_storage& addr, const socklen_t len) - : addr_storage(addr), addr_storage_len(len){}; - endpoint(const struct in_addr& addr, const uint16_t port) { - struct sockaddr_in* addr_in = (struct sockaddr_in*) &addr_storage; - addr_in->sin_family = AF_INET; - addr_in->sin_port = htons(port); - addr_in->sin_addr.s_addr = addr.s_addr; - - addr_storage_len = sizeof(struct sockaddr_in); - }; - - endpoint(const struct in6_addr& addr6, const uint16_t port) { - struct sockaddr_in6* addr_in6 = (struct sockaddr_in6*) &addr_storage; - addr_in6->sin6_family = AF_INET6; - addr_in6->sin6_port = htons(port); - addr_in6->sin6_flowinfo = 0; - memcpy(&addr_in6->sin6_addr, &addr6, sizeof(struct in6_addr)); - addr_in6->sin6_scope_id = 0; - - addr_storage_len = sizeof(struct sockaddr_in6); - }; - - uint16_t port() const { - return ntohs(((struct sockaddr_in*) &addr_storage)->sin_port); - } - - sa_family_t family() const { return addr_storage.ss_family; } - - std::string toString() const { - std::string str; - if (addr_storage.ss_family == AF_INET) { - struct sockaddr_in* addr_in = (struct sockaddr_in*) &addr_storage; - str.append(conv::toString(addr_in->sin_addr)); - str.append(":").append(std::to_string(ntohs(addr_in->sin_port))); - } else if (addr_storage.ss_family == AF_INET6) { - struct sockaddr_in6* addr_in6 = (struct sockaddr_in6*) &addr_storage; - str.append(conv::toString(addr_in6->sin6_addr)); - str.append(":").append(std::to_string(ntohs(addr_in6->sin6_port))); - } - return str; - } -}; - -#endif diff --git a/src/common/pcf.h b/src/common/pcf.h deleted file mode 100644 index caa8722a5fc219c816046978309be1b2eba283eb..0000000000000000000000000000000000000000 --- a/src/common/pcf.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef FILE_PCF_SEEN -#define FILE_PCF_SEEN - -#include "3gpp_29.571.h" -#include <nlohmann/json.hpp> -#include <netinet/in.h> -#include <arpa/inet.h> - -#define HEART_BEAT_TIMER 10 - -#define _unused(x) ((void) (x)) - -// typedef struct dnn_pcf_info_item_s { -// std::string dnn; -// } dnn_pcf_info_item_t; - -typedef struct supi_range_s { - std::string start; - std::string end; - std::string pattern; -} supi_range_t; - -typedef struct supi_range_pcf_info_item_s { - supi_range_t supi_range; -} supi_range_pcf_info_item_t; - -typedef struct identity_range_s { - std::string start; - std::string end; - std::string pattern; -} identity_range_t; - -typedef struct identity_range_pcf_info_item_s { - identity_range_t identity_range; -} identity_range_pcf_info_item_t; - -typedef struct pcf_info_s { - std::string groupid; - std::vector<supi_range_pcf_info_item_t> supi_ranges; - std::vector<identity_range_pcf_info_item_t> gpsi_ranges; - std::vector<std::string> dnn_list; -} pcf_info_t; - -typedef struct nf_service_version_s { - std::string api_version_in_uri; // apiVersionInUri - std::string api_full_version; // apiFullVersion - - nf_service_version_s& operator=(const nf_service_version_s& s) { - api_version_in_uri = s.api_version_in_uri; - api_full_version = s.api_full_version; - return *this; - } - - std::string to_string() const { - std::string s = {}; - s.append(", Version ("); - s.append("apiVersionInUri: "); - s.append(api_version_in_uri); - s.append(", apiFullVersion: "); - s.append(api_full_version); - s.append(" )"); - return s; - } -} nf_service_version_t; - -typedef struct ip_endpoint_s { - // struct in6_addr ipv6_address; - struct in_addr ipv4_address; - std::string transport; // TCP - unsigned int port; - std::string to_string() const { - std::string s = {}; - s.append("Ipv4 Address: "); - s.append(inet_ntoa(ipv4_address)); - s.append(", TransportProtocol: "); - s.append(transport); - s.append(", Port: "); - s.append(std::to_string(port)); - return s; - } -} ip_endpoint_t; - -typedef struct nf_service_s { - std::string service_instance_id; - std::string service_name; - std::vector<nf_service_version_t> versions; - std::string scheme; - std::string nf_service_status; - std::vector<ip_endpoint_t> ip_endpoints; - - std::string to_string() const { - std::string s = {}; - s.append("Service Instance ID: "); - s.append(service_instance_id); - s.append(", Service name: "); - s.append(service_name); - for (auto const& v : versions) { - s.append(v.to_string()); - } - s.append(", Scheme: "); - s.append(scheme); - s.append(", Service status: "); - s.append(nf_service_status); - s.append(", IpEndPoints: "); - for (auto endpoint : ip_endpoints) { - s.append(endpoint.to_string()); - } - return s; - } -} nf_service_t; - -#define ROAMING_IND_NON_ROAMING (1) -#define ROAMING_IND_LOCAL_BREAKOUT (2) -#define ROAMING_IND_HOME_ROUTED_ROAMING (3) - -// NF TYPES -#define NF_TYPE_NWDAP "NWDAP" -#define NF_TYPE_PCF "PCF" -#define NF_TYPE_PCF "PCF" -#define NF_TYPE_AMF "AMF" - -// NRF -#define NNRF_NFM_BASE "/nnrf-nfm/" -#define NNRF_DISC_INSTANCES "/nf-instances/" -#define NNRF_NF_STATUS_SUBSCRIBE_URL "/subscriptions" - -// for CURL -#define NF_CURL_TIMEOUT_MS 100L -#define MAX_WAIT_MSECS 10000 // 1 second -#define AMF_NUMBER_RETRIES 3 -#define UDM_NUMBER_RETRIES 3 - -#endif diff --git a/src/common/utils/conversions.cpp b/src/common/utils/conversions.cpp deleted file mode 100644 index 08ed48316d50297bcf972d8b758fc424a59796f4..0000000000000000000000000000000000000000 --- a/src/common/utils/conversions.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file conversions.cpp - \brief - \author Sebastien ROUX - \company Eurecom -*/ -#include "conversions.hpp" -#include "logger.hpp" - -#include <stdlib.h> -#include <stdint.h> -#include <stdbool.h> -#include <ctype.h> -#include <inttypes.h> -#include <arpa/inet.h> - -static const char hex_to_ascii_table[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', -}; - -static const signed char ascii_to_hex_table[0x100] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, - 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1}; - -void conv::hexa_to_ascii(uint8_t* from, char* to, size_t length) { - size_t i; - - for (i = 0; i < length; i++) { - uint8_t upper = (from[i] & 0xf0) >> 4; - uint8_t lower = from[i] & 0x0f; - - to[2 * i] = hex_to_ascii_table[upper]; - to[2 * i + 1] = hex_to_ascii_table[lower]; - } -} - -int conv::ascii_to_hex(uint8_t* dst, const char* h) { - const unsigned char* hex = (const unsigned char*) h; - unsigned i = 0; - - for (;;) { - int high, low; - - while (*hex && isspace(*hex)) hex++; - - if (!*hex) return 1; - - high = ascii_to_hex_table[*hex++]; - - if (high < 0) return 0; - - while (*hex && isspace(*hex)) hex++; - - if (!*hex) return 0; - - low = ascii_to_hex_table[*hex++]; - - if (low < 0) return 0; - - dst[i++] = (high << 4) | low; - } -} - -//------------------------------------------------------------------------------ -std::string conv::mccToString( - const uint8_t digit1, const uint8_t digit2, const uint8_t digit3) { - std::string s = {}; - uint16_t mcc16 = digit1 * 100 + digit2 * 10 + digit3; - // s.append(std::to_string(digit1)).append(std::to_string(digit2)).append(std::to_string(digit3)); - s.append(std::to_string(mcc16)); - return s; -} -//------------------------------------------------------------------------------ -std::string conv::mncToString( - const uint8_t digit1, const uint8_t digit2, const uint8_t digit3) { - std::string s = {}; - uint16_t mcc16 = 0; - - if (digit3 == 0x0F) { - mcc16 = digit1 * 10 + digit2; - } else { - mcc16 = digit1 * 100 + digit2 * 10 + digit3; - } - s.append(std::to_string(mcc16)); - return s; -} - -//------------------------------------------------------------------------------ -struct in_addr conv::fromString(const std::string addr4) { - unsigned char buf[sizeof(struct in6_addr)] = {}; - auto ret = inet_pton(AF_INET, addr4.c_str(), buf); - if (ret != 1) { - Logger::pcf_app().error( - __PRETTY_FUNCTION__ + std::string{" Failed to convert "} + addr4); - } - struct in_addr* ia = (struct in_addr*) buf; - return *ia; -} - -//------------------------------------------------------------------------------ -struct in6_addr conv::fromStringV6(const std::string& addr6) { - unsigned char buf[sizeof(struct in6_addr)] = {}; - struct in6_addr ipv6_addr {}; - if (inet_pton(AF_INET6, addr6.c_str(), buf) == 1) { - memcpy(&ipv6_addr, buf, sizeof(struct in6_addr)); - } - return ipv6_addr; -} - -//------------------------------------------------------------------------------ -std::string conv::toString(const struct in_addr& inaddr) { - std::string s = {}; - char str[INET6_ADDRSTRLEN] = {}; - if (inet_ntop(AF_INET, (const void*) &inaddr, str, INET6_ADDRSTRLEN) == - NULL) { - s.append("Error in_addr"); - } else { - s.append(str); - } - return s; -} -//------------------------------------------------------------------------------ -std::string conv::toString(const struct in6_addr& in6addr) { - std::string s = {}; - char str[INET6_ADDRSTRLEN] = {}; - if (inet_ntop(AF_INET6, (const void*) &in6addr, str, INET6_ADDRSTRLEN) == - nullptr) { - s.append("Error in6_addr"); - } else { - s.append(str); - } - return s; -} diff --git a/src/common/utils/conversions.hpp b/src/common/utils/conversions.hpp deleted file mode 100644 index e35e9d64dd58822e404798389c47b2b45128bee0..0000000000000000000000000000000000000000 --- a/src/common/utils/conversions.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file conversions.hpp - \brief - \author Sebastien ROUX, Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_CONVERSIONS_HPP_SEEN -#define FILE_CONVERSIONS_HPP_SEEN -#include <stdint.h> -#include <string> -#include <netinet/in.h> - -/* Used to format an uint32_t containing an ipv4 address */ -#define IN_ADDR_FMT "%u.%u.%u.%u" -#define PRI_IN_ADDR(aDDRESS) \ - (uint8_t)((aDDRESS.s_addr) & 0x000000ff), \ - (uint8_t) (((aDDRESS.s_addr) & 0x0000ff00) >> 8), \ - (uint8_t) (((aDDRESS.s_addr) & 0x00ff0000) >> 16), \ - (uint8_t) (((aDDRESS.s_addr) & 0xff000000) >> 24) - -#define IPV4_ADDR_DISPLAY_8(aDDRESS) \ - (aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3] - -class conv { - public: - static void hexa_to_ascii(uint8_t* from, char* to, size_t length); - static int ascii_to_hex(uint8_t* dst, const char* h); - static struct in_addr fromString(const std::string addr4); - static struct in6_addr fromStringV6(const std::string& addr6); - static std::string toString(const struct in_addr& inaddr); - static std::string toString(const struct in6_addr& in6addr); - static std::string mccToString( - const uint8_t digit1, const uint8_t digit2, const uint8_t digit3); - static std::string mncToString( - const uint8_t digit1, const uint8_t digit2, const uint8_t digit3); -}; -#endif /* FILE_CONVERSIONS_HPP_SEEN */ diff --git a/src/common/utils/get_gateway_netlink.cpp b/src/common/utils/get_gateway_netlink.cpp deleted file mode 100644 index f257344966852be860356142a26643803f62037e..0000000000000000000000000000000000000000 --- a/src/common/utils/get_gateway_netlink.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* From https://gist.github.com/javiermon/6272065#file-gateway_netlink-c */ -/* - * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <sys/socket.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <net/if.h> - -#include <fstream> // std::ifstream -#include <string> - -#include "common_defs.h" -#include "get_gateway_netlink.hpp" -#include "logger.hpp" - -#define BUFFER_SIZE 4096 - -using namespace std; - -//------------------------------------------------------------------------------ -bool util::get_iface_l2_addr(const std::string& iface, std::string& mac) { - std::string mac_address_path = - fmt::format("/sys/class/net/{}/address", iface); - std::ifstream mac_address_in( - mac_address_path.c_str(), ios_base::in | ios_base::binary); - char wb[32]; - mac_address_in.get(wb, 32); - mac.assign(wb); - Logger::pcf_app().error("Found IFace %s MAC %s", iface.c_str(), mac.c_str()); - mac.erase(std::remove(mac.begin(), mac.end(), ':'), mac.end()); - return true; - // ifr = {}; - // strncpy ((char *) ifr.ifr_name, ifname, IFNAMSIZ); - // if (ioctl(sd, SIOCGIFFLAGS, &ifr) == 0) { - // if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback - // if (ioctl(sd, SIOCGIFHWADDR, &ifr) == 0) { - // memcpy(pdn_mac_address, ifr.ifr_hwaddr.sa_data, 6); - // } - // } - // } -} -//------------------------------------------------------------------------------ -bool util::get_gateway_and_iface(std::string& gw, std::string& iface) { - int received_bytes = 0, msg_len = 0, route_attribute_len = 0; - int sock = -1; - unsigned int msgseq = 0; - struct nlmsghdr *nlh, *nlmsg; - struct rtmsg* route_entry; - // This struct contain route attributes (route type) - struct rtattr* route_attribute; - char gateway_address[INET_ADDRSTRLEN], interface[IF_NAMESIZE + 1]; - char msgbuf[BUFFER_SIZE], buffer[BUFFER_SIZE]; - char* ptr = buffer; - struct timeval tv; - - if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) { - perror("socket failed"); - return false; - } - - memset(msgbuf, 0, sizeof(msgbuf)); - memset(gateway_address, 0, sizeof(gateway_address)); - memset(interface, 0, sizeof(interface)); - memset(buffer, 0, sizeof(buffer)); - - /* point the header and the msg structure pointers into the buffer */ - nlmsg = (struct nlmsghdr*) msgbuf; - - /* Fill in the nlmsg header*/ - nlmsg->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); - nlmsg->nlmsg_type = - RTM_GETROUTE; // Get the routes from kernel routing table . - nlmsg->nlmsg_flags = - NLM_F_DUMP | NLM_F_REQUEST; // The message is a request for dump. - nlmsg->nlmsg_seq = msgseq++; // Sequence of the message packet. - nlmsg->nlmsg_pid = getpid(); // PID of process sending the request. - - /* 1 Sec Timeout to avoid stall */ - tv.tv_sec = 1; - setsockopt( - sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval*) &tv, - sizeof(struct timeval)); - /* send msg */ - if (send(sock, nlmsg, nlmsg->nlmsg_len, 0) < 0) { - perror("send failed"); - return false; - } - - /* receive response */ - do { - received_bytes = recv(sock, ptr, sizeof(buffer) - msg_len, 0); - if (received_bytes < 0) { - perror("Error in recv"); - return false; - } - - nlh = (struct nlmsghdr*) ptr; - - /* Check if the header is valid */ - if ((NLMSG_OK(nlmsg, received_bytes) == 0) || - (nlmsg->nlmsg_type == NLMSG_ERROR)) { - perror("Error in received packet"); - return false; - } - - /* If we received all data break */ - if (nlh->nlmsg_type == NLMSG_DONE) - break; - else { - ptr += received_bytes; - msg_len += received_bytes; - } - - /* Break if its not a multi part message */ - if ((nlmsg->nlmsg_flags & NLM_F_MULTI) == 0) break; - } while ((nlmsg->nlmsg_seq != msgseq) || - (nlmsg->nlmsg_pid != static_cast<unsigned int>(getpid()))); - - /* parse response */ - for (; NLMSG_OK(nlh, received_bytes); nlh = NLMSG_NEXT(nlh, received_bytes)) { - /* Get the route data */ - route_entry = (struct rtmsg*) NLMSG_DATA(nlh); - - /* We are just interested in main routing table */ - if (route_entry->rtm_table != RT_TABLE_MAIN) continue; - - route_attribute = (struct rtattr*) RTM_RTA(route_entry); - route_attribute_len = RTM_PAYLOAD(nlh); - - /* Loop through all attributes */ - for (; RTA_OK(route_attribute, route_attribute_len); - route_attribute = RTA_NEXT(route_attribute, route_attribute_len)) { - switch (route_attribute->rta_type) { - case RTA_OIF: - if_indextoname(*(int*) RTA_DATA(route_attribute), interface); - break; - case RTA_GATEWAY: - inet_ntop( - AF_INET, RTA_DATA(route_attribute), gateway_address, - sizeof(gateway_address)); - break; - default: - break; - } - } - - if ((*gateway_address) && (*interface)) { - gw.assign(gateway_address); - iface.assign(interface); - break; - } - } - close(sock); - return true; -} diff --git a/src/common/utils/get_gateway_netlink.hpp b/src/common/utils/get_gateway_netlink.hpp deleted file mode 100644 index b29d0672abf5ad056c6c470c35c56bfd1731110a..0000000000000000000000000000000000000000 --- a/src/common/utils/get_gateway_netlink.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file get_gateway_netlink.hpp - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ -#ifndef FILE_GET_GATEWAY_NETLINK_HPP_SEEN -#define FILE_GET_GATEWAY_NETLINK_HPP_SEEN - -#include <string> - -namespace util { -bool get_iface_l2_addr(const std::string& iface, std::string& mac); -bool get_gateway_and_iface(std::string& gw, std::string& iface); -} // namespace util -#endif /* FILE_GET_GATEWAY_NETLINK_HPP_SEEN */ diff --git a/src/common/utils/if.cpp b/src/common/utils/if.cpp deleted file mode 100644 index 95e6477c93f27553f8b3f4d2b06fdfda98e938f1..0000000000000000000000000000000000000000 --- a/src/common/utils/if.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* From https://gist.github.com/javiermon/6272065#file-gateway_netlink-c */ -/* - * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "common_defs.h" -#include "if.hpp" -#include "logger.hpp" - -#include <errno.h> -#include <sys/socket.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <net/if.h> -#include <sys/ioctl.h> - -#define BUFFER_SIZE 4096 - -//------------------------------------------------------------------------------ -int get_gateway_and_iface(std::string* gw, std::string* iface) { - int received_bytes = 0, msg_len = 0, route_attribute_len = 0; - int sock = -1; - unsigned int msgseq = 0; - struct nlmsghdr *nlh, *nlmsg; - struct rtmsg* route_entry; - // This struct contain route attributes (route type) - struct rtattr* route_attribute; - char gateway_address[INET_ADDRSTRLEN], interface[IF_NAMESIZE]; - char msgbuf[BUFFER_SIZE], buffer[BUFFER_SIZE]; - char* ptr = buffer; - struct timeval tv; - int rv = RETURNok; - - if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) { - Logger::system().error("socket raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - memset(msgbuf, 0, sizeof(msgbuf)); - memset(gateway_address, 0, sizeof(gateway_address)); - memset(interface, 0, sizeof(interface)); - memset(buffer, 0, sizeof(buffer)); - - /* point the header and the msg structure pointers into the buffer */ - nlmsg = (struct nlmsghdr*) msgbuf; - - /* Fill in the nlmsg header*/ - nlmsg->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); - nlmsg->nlmsg_type = - RTM_GETROUTE; // Get the routes from kernel routing table . - nlmsg->nlmsg_flags = - NLM_F_DUMP | NLM_F_REQUEST; // The message is a request for dump. - nlmsg->nlmsg_seq = msgseq++; // Sequence of the message packet. - nlmsg->nlmsg_pid = getpid(); // PID of process sending the request. - - /* 1 Sec Timeout to avoid stall */ - tv.tv_sec = 1; - setsockopt( - sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval*) &tv, - sizeof(struct timeval)); - /* send msg */ - if (send(sock, nlmsg, nlmsg->nlmsg_len, 0) < 0) { - Logger::system().error("send socket raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - /* receive response */ - do { - received_bytes = recv(sock, ptr, sizeof(buffer) - msg_len, 0); - if (received_bytes < 0) { - Logger::system().error("recv socket raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - nlh = (struct nlmsghdr*) ptr; - - /* Check if the header is valid */ - if ((NLMSG_OK(nlmsg, received_bytes) == 0) || - (nlmsg->nlmsg_type == NLMSG_ERROR)) { - Logger::system().error("recv msg raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - /* If we received all data break */ - if (nlh->nlmsg_type == NLMSG_DONE) - break; - else { - ptr += received_bytes; - msg_len += received_bytes; - } - - /* Break if its not a multi part message */ - if ((nlmsg->nlmsg_flags & NLM_F_MULTI) == 0) break; - } while ((nlmsg->nlmsg_seq != msgseq) || - (nlmsg->nlmsg_pid != static_cast<unsigned int>(getpid()))); - - /* parse response */ - for (; NLMSG_OK(nlh, received_bytes); nlh = NLMSG_NEXT(nlh, received_bytes)) { - /* Get the route data */ - route_entry = (struct rtmsg*) NLMSG_DATA(nlh); - - /* We are just interested in main routing table */ - if (route_entry->rtm_table != RT_TABLE_MAIN) continue; - - route_attribute = (struct rtattr*) RTM_RTA(route_entry); - route_attribute_len = RTM_PAYLOAD(nlh); - - /* Loop through all attributes */ - for (; RTA_OK(route_attribute, route_attribute_len); - route_attribute = RTA_NEXT(route_attribute, route_attribute_len)) { - switch (route_attribute->rta_type) { - case RTA_OIF: - if_indextoname(*(int*) RTA_DATA(route_attribute), interface); - break; - case RTA_GATEWAY: - inet_ntop( - AF_INET, RTA_DATA(route_attribute), gateway_address, - sizeof(gateway_address)); - break; - default: - break; - } - } - - if ((*gateway_address) && (*interface)) { - *gw = std::string(gateway_address); - if (iface) { - *iface = std::string(interface); - } - break; - } else { - rv = RETURNerror; - } - } - close(sock); - return rv; -} - -//------------------------------------------------------------------------------ -int get_inet_addr_from_iface( - const std::string& if_name, struct in_addr& inet_addr) { - struct ifreq ifr; - char str[INET_ADDRSTRLEN]; - - memset(&ifr, 0, sizeof(ifr)); - int fd = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFADDR, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s inet addr: error %s\n", if_name.c_str(), - strerror(errno)); - return RETURNerror; - } - close(fd); - struct sockaddr_in* ipaddr = (struct sockaddr_in*) &ifr.ifr_addr; - // check - if (inet_ntop( - AF_INET, (const void*) &ipaddr->sin_addr, str, INET_ADDRSTRLEN) == - NULL) { - return RETURNerror; - } - inet_addr.s_addr = ipaddr->sin_addr.s_addr; - return RETURNok; -} - -//------------------------------------------------------------------------------ -int get_mtu_from_iface(const std::string& if_name, uint32_t& mtu) { - struct ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - int fd = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFMTU, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s MTU: error %s\n", if_name.c_str(), strerror(errno)); - return RETURNerror; - } - close(fd); - mtu = ifr.ifr_mtu; - return RETURNok; -} - -//------------------------------------------------------------------------------ -int get_inet_addr_infos_from_iface( - const std::string& if_name, struct in_addr& inet_addr, - struct in_addr& inet_network, unsigned int& mtu) { - struct ifreq ifr; - char str[INET_ADDRSTRLEN]; - - inet_addr.s_addr = INADDR_ANY; - inet_network.s_addr = INADDR_ANY; - mtu = 0; - - memset(&ifr, 0, sizeof(ifr)); - int fd = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFADDR, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s inet addr: error %s\n", if_name.c_str(), - strerror(errno)); - return RETURNerror; - } - struct sockaddr_in* ipaddr = (struct sockaddr_in*) &ifr.ifr_addr; - // check - if (inet_ntop( - AF_INET, (const void*) &ipaddr->sin_addr, str, INET_ADDRSTRLEN) == - NULL) { - close(fd); - return RETURNerror; - } - inet_addr.s_addr = ipaddr->sin_addr.s_addr; - - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFNETMASK, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s inet netmask: error %s\n", if_name.c_str(), - strerror(errno)); - return RETURNerror; - } - ipaddr = (struct sockaddr_in*) &ifr.ifr_netmask; - // check - if (inet_ntop( - AF_INET, (const void*) &ipaddr->sin_addr, str, INET_ADDRSTRLEN) == - NULL) { - close(fd); - return RETURNerror; - } - inet_network.s_addr = ipaddr->sin_addr.s_addr; - - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFMTU, &ifr)) { - Logger::system().error( - "Failed to probe %s MTU: error %s\n", if_name.c_str(), strerror(errno)); - } else { - mtu = ifr.ifr_mtu; - } - close(fd); - return RETURNok; -} diff --git a/src/common/utils/if.hpp b/src/common/utils/if.hpp deleted file mode 100644 index ede70f545f7295ad73285b0f76f896e3b79f021a..0000000000000000000000000000000000000000 --- a/src/common/utils/if.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file get_gateway_netlink.h - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ -#ifndef FILE_IF_HPP_SEEN -#define FILE_IF_HPP_SEEN -#include <string> - -int get_gateway_and_iface(std::string* gw /*OUT*/, std::string* iface /*OUT*/); -int get_inet_addr_from_iface( - const std::string& if_name, struct in_addr& inet_addr); -int get_mtu_from_iface(const std::string& if_name, uint32_t& mtu); -int get_inet_addr_infos_from_iface( - const std::string& if_name, struct in_addr& inet_addr, - struct in_addr& inet_netmask, unsigned int& mtu); - -#endif /* FILE_IF_HPP_SEEN */ diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp deleted file mode 100644 index 8846793e410f96d82de5f7b64022b15bf5fdb893..0000000000000000000000000000000000000000 --- a/src/common/utils/string.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ -#include "string.hpp" -#include <iostream> - -#include <algorithm> -#include <functional> -#include <cctype> -#include <locale> -#include <stdarg.h> -#include <regex> - -template<class T> -class Buffer { - public: - explicit Buffer(size_t size) { - msize = size; - mbuf = new T[msize]; - } - ~Buffer() { - if (mbuf) delete[] mbuf; - } - T* get() { return mbuf; } - - private: - Buffer(); - size_t msize; - T* mbuf; -}; - -std::string util::string_format(const char* format, ...) { - va_list args; - - va_start(args, format); - size_t size = vsnprintf(NULL, 0, format, args) + 1; // Extra space for '\0' - va_end(args); - - Buffer<char> buf(size); - - va_start(args, format); - vsnprintf(buf.get(), size, format, args); - va_end(args); - - return std::string(buf.get(), size - 1); // We don't want the '\0' inside -} - -// Licence : https://creativecommons.org/licenses/by-sa/4.0/legalcode -// https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring#217605 - -// trim from start -std::string& util::ltrim(std::string& s) { - s.erase( - s.begin(), - std::find_if( - s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); - return s; -} - -// trim from end -std::string& util::rtrim(std::string& s) { - s.erase( - std::find_if( - s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))) - .base(), - s.end()); - return s; -} - -// trim from both ends -std::string& util::trim(std::string& s) { - return util::ltrim(util::rtrim(s)); -} - -// extract query param from given querystring -std::string query_param_tmp; -// -std::string util::get_query_param(std::string querystring, std::string param) { - std::regex reList("([^=]*)=([^&]*)&?"); - query_param_tmp.clear(); - std::for_each( - std::sregex_iterator(querystring.begin(), querystring.end(), reList), - std::sregex_iterator(), [param](std::smatch match) { - if (match[1] == param) { - query_param_tmp = match[2].str().c_str(); - return; - } - }); - return query_param_tmp; -} \ No newline at end of file diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp deleted file mode 100644 index 5be5c8c89041d971b60b4f0651e639a6ef0878be..0000000000000000000000000000000000000000 --- a/src/common/utils/string.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file string.hpp - \brief - \author Lionel GAUTHIER - \date 2018 - \email: lionel.gauthier@eurecom.fr - */ -#ifndef FILE_STRING_HPP_FILE_SEEN -#define FILE_STRING_HPP_FILE_SEEN - -#include <string> - -namespace util { - -std::string string_format(const char* format, ...); - -std::string& ltrim(std::string& s); -// trim from end -std::string& rtrim(std::string& s); -// trim from both ends -std::string& trim(std::string& s); -// extract query param from given querystring -std::string get_query_param(std::string querystring, std::string param); -} // namespace util -#endif diff --git a/src/common/utils/uint_generator.hpp b/src/common/utils/uint_generator.hpp deleted file mode 100644 index 246373a0d1640693f087d0b3fceb185df3fd1a96..0000000000000000000000000000000000000000 --- a/src/common/utils/uint_generator.hpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file uint_uid_generator.hpp - \author Lionel GAUTHIER - \date 2019 - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_UINT_GENERATOR_HPP_SEEN -#define FILE_UINT_GENERATOR_HPP_SEEN - -#include <mutex> -#include <set> - -namespace util { - -template<class UINT> -class uint_generator { - private: - UINT uid_generator; - std::mutex m_uid_generator; - - std::set<UINT> uid_generated; - std::mutex m_uid_generated; - - public: - uint_generator() : m_uid_generator(), m_uid_generated() { - uid_generator = 0; - uid_generated = {}; - }; - - uint_generator(uint_generator const&) = delete; - void operator=(uint_generator const&) = delete; - - UINT get_uid() { - std::unique_lock<std::mutex> lr(m_uid_generator); - UINT uid = ++uid_generator; - while (true) { - // may happen race conditions here - std::unique_lock<std::mutex> ld(m_uid_generated); - if (uid_generated.count(uid) == 0) { - uid_generated.insert(uid); - ld.unlock(); - lr.unlock(); - return uid; - } - uid = ++uid_generator; - } - } - - void free_uid(UINT uid) { - std::unique_lock<std::mutex> l(m_uid_generated); - uid_generated.erase(uid); - l.unlock(); - } -}; - -template<class UINT> -class uint_uid_generator { - private: - UINT uid_generator; - std::mutex m_uid_generator; - - std::set<UINT> uid_generated; - std::mutex m_uid_generated; - - uint_uid_generator() : m_uid_generator(), m_uid_generated() { - uid_generator = 0; - uid_generated = {}; - }; - - public: - static uint_uid_generator& get_instance() { - static uint_uid_generator instance; - return instance; - } - - uint_uid_generator(uint_uid_generator const&) = delete; - void operator=(uint_uid_generator const&) = delete; - - UINT get_uid() { - std::unique_lock<std::mutex> lr(m_uid_generator); - UINT uid = ++uid_generator; - while (true) { - // may happen race conditions here - std::unique_lock<std::mutex> ld(m_uid_generated); - if (uid_generated.count(uid) == 0) { - uid_generated.insert(uid); - lr.unlock(); - ld.unlock(); - return uid; - } - uid = ++uid_generator; - } - } - - void free_uid(UINT uid) { - std::unique_lock<std::mutex> l(m_uid_generated); - uid_generated.erase(uid); - l.unlock(); - } -}; - -} // namespace util -#endif // FILE_UINT_GENERATOR_HPP_SEEN diff --git a/src/common/utils/utils.cmake b/src/common/utils/utils.cmake index 4184acb536876c4e53b4b07d67336120edda040b..b844f0e79afbdb1bb23fe0f2503b760387a12199 100644 --- a/src/common/utils/utils.cmake +++ b/src/common/utils/utils.cmake @@ -21,14 +21,9 @@ SET(UTILS_DIR ${SRC_TOP_DIR}/common/utils) -## Logger used in NF_TARGET (main) -## TODO for now only use utils actually used by PCF target_include_directories(${NF_TARGET} PUBLIC ${UTILS_DIR}) target_sources(${NF_TARGET} PRIVATE - ${UTILS_DIR}/conversions.cpp - ${UTILS_DIR}/string.cpp ${UTILS_DIR}/fqdn.cpp - ${UTILS_DIR}/if.cpp ${UTILS_DIR}/nf_launch.cpp ${UTILS_DIR}/options.cpp ) diff --git a/src/oai-cn5g-common-src b/src/oai-cn5g-common-src index 411ea5639784eb919a42d4bbfec4ba5b40b88d93..ce3819f54bc32f6af35b1e63b59cc8622961f2d1 160000 --- a/src/oai-cn5g-common-src +++ b/src/oai-cn5g-common-src @@ -1 +1 @@ -Subproject commit 411ea5639784eb919a42d4bbfec4ba5b40b88d93 +Subproject commit ce3819f54bc32f6af35b1e63b59cc8622961f2d1 diff --git a/src/oai_pcf/CMakeLists.txt b/src/oai_pcf/CMakeLists.txt index adcce5452e3f69750a59b938f31345e6a9cbe5be..1315f0adb9eb183e616e9df84a5362cdf0644eb1 100644 --- a/src/oai_pcf/CMakeLists.txt +++ b/src/oai_pcf/CMakeLists.txt @@ -256,6 +256,8 @@ include_directories(${CONFIG_INCLUDE_DIRS}) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) +#CPR +find_package(cpr REQUIRED) ################################################################ # Add sub modules @@ -290,8 +292,10 @@ add_executable(pcf ## Common modules include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/http/http.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger/logger.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config/config.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake) include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils) IF(STATIC_LINKING) @@ -302,4 +306,4 @@ IF(STATIC_LINKING) ENDIF(STATIC_LINKING) target_link_libraries (pcf ${ASAN} -Wl,--start-group PCF PCF_API ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lssl -lcrypto -lfmt -lspdlog dl -Wl,--end-group -pthread m rt event boost_system -lboost_filesystem pistache curl -lyaml-cpp) +pthread m rt event boost_system -lboost_filesystem pistache curl -lyaml-cpp cpr::cpr) diff --git a/src/oai_pcf/main.cpp b/src/oai_pcf/main.cpp index e6f085b17ec3be0dd1a3a38a4b025578b4296bf3..c83f4af5e015b463330261f97ef8aac83446ece0 100644 --- a/src/oai_pcf/main.cpp +++ b/src/oai_pcf/main.cpp @@ -22,12 +22,13 @@ #include "options.hpp" #include "pistache/http.h" #include "nf_launch.hpp" +#include "conversions.hpp" +#include "http_client.hpp" #include <iostream> #include <csignal> #include <thread> -using namespace util; using namespace std; using namespace oai::pcf::app; using namespace oai::config::pcf; @@ -36,10 +37,11 @@ using namespace oai::pcf::api; using namespace oai::config; -std::unique_ptr<pcf_app> pcf_app_inst = nullptr; -std::unique_ptr<pcf_config> pcf_cfg = nullptr; -std::unique_ptr<PCFApiServer> pcf_api_server_1 = nullptr; -std::unique_ptr<pcf_http2_server> pcf_api_server_2 = nullptr; +std::unique_ptr<pcf_app> pcf_app_inst = nullptr; +std::unique_ptr<pcf_config> pcf_cfg = nullptr; +std::unique_ptr<PCFApiServer> pcf_api_server_1 = nullptr; +std::unique_ptr<pcf_http2_server> pcf_api_server_2 = nullptr; +std::shared_ptr<oai::http::http_client> http_client_inst = nullptr; //------------------------------------------------------------------------------ void signal_handler_sigint(int s) { @@ -104,6 +106,11 @@ int main(int argc, char** argv) { } pcf_cfg->display(); + // HTTP Client + http_client_inst = oai::http::http_client::create_instance( + Logger::pcf_client(), oai::common::sbi::kNfDefaultHttpRequestTimeout, + pcf_cfg->local().get_sbi().get_if_name(), pcf_cfg->get_http_version()); + // Event subsystem pcf_event ev; @@ -111,7 +118,7 @@ int main(int argc, char** argv) { pcf_app_inst = std::make_unique<pcf_app>(ev); std::string v4_address = - conv::toString(pcf_cfg->local().get_sbi().get_addr4()); + oai::utils::conv::toString(pcf_cfg->local().get_sbi().get_addr4()); if (pcf_cfg->get_http_version() == 1) { // PCF Pistache API server (HTTP1) diff --git a/src/pcf_app/CMakeLists.txt b/src/pcf_app/CMakeLists.txt index a3a7e62a41dc16e80a8caf11dd5a6bc3ba502c7c..039f035928939243e5cf1e8f445d86355b8ec3ee 100644 --- a/src/pcf_app/CMakeLists.txt +++ b/src/pcf_app/CMakeLists.txt @@ -27,15 +27,23 @@ include_directories(${SRC_TOP_DIR}/api-server/api) include_directories(${SRC_TOP_DIR}/api-server/impl) include_directories(${SRC_TOP_DIR}/api-server/) include_directories(${SRC_TOP_DIR}/pcf_app/sm_policy/) -include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger) -include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config) + +## Common modules +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/http/http.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/common/common.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger/logger.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config/config.cmake) +include(${SRC_TOP_DIR}/common/utils/utils.cmake) + + +include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake) add_library (PCF STATIC pcf_config_types.cpp pcf_config.cpp pcf_app.cpp pcf_nrf.cpp - pcf_client.cpp pcf_profile.cpp pcf_event.cpp pcf_sm_policy_control.cpp @@ -48,8 +56,3 @@ add_library (PCF STATIC sm_policy/policy_storage.cpp sm_policy/policy_provisioning_file.cpp ) - -## Common modules -include(${SRC_TOP_DIR}/common/utils/utils.cmake) - -include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake) diff --git a/src/pcf_app/logger.hpp b/src/pcf_app/logger.hpp index d8a4e3772f3c36b6dc101296a1a5f49e4490d9a1..3e8626be0523beeedc738ac65c8adb3699c2adee 100644 --- a/src/pcf_app/logger.hpp +++ b/src/pcf_app/logger.hpp @@ -31,9 +31,10 @@ #include "logger_base.hpp" -static const std::string PCF_APP = "pcf_app"; -static const std::string PCF_SBI = "pcf_sbi"; -static const std::string SYSTEM = "system "; +static const std::string PCF_APP = "pcf_app"; +static const std::string PCF_SBI = "pcf_sbi"; +static const std::string PCF_CLIENT = "pcf_client"; +static const std::string SYSTEM = "system "; class Logger { public: @@ -43,12 +44,22 @@ class Logger { name, PCF_APP, log_stdout, log_rot_file); oai::logger::logger_registry::register_logger( name, PCF_SBI, log_stdout, log_rot_file); + oai::logger::logger_registry::register_logger( + name, PCF_CLIENT, log_stdout, log_rot_file); + oai::logger::logger_registry::register_logger( + name, LOGGER_COMMON, log_stdout, log_rot_file); oai::logger::logger_registry::register_logger( name, SYSTEM, log_stdout, log_rot_file); } + + static bool should_log(spdlog::level::level_enum level) { + return oai::logger::logger_registry::should_log(level); + } + static void set_level(spdlog::level::level_enum level) { oai::logger::logger_registry::set_level(level); } + static const oai::logger::printf_logger& pcf_app() { return oai::logger::logger_registry::get_logger(PCF_APP); } @@ -57,6 +68,10 @@ class Logger { return oai::logger::logger_registry::get_logger(PCF_SBI); } + static const oai::logger::printf_logger& pcf_client() { + return oai::logger::logger_registry::get_logger(PCF_CLIENT); + } + static const oai::logger::printf_logger& system() { return oai::logger::logger_registry::get_logger(SYSTEM); } diff --git a/src/pcf_app/pcf_app.hpp b/src/pcf_app/pcf_app.hpp index ae97c654b7b8badf9975f04da1ef38cf5d4bb8f1..230394a30a30b05a65b5254c4b5d424f74655ffb 100644 --- a/src/pcf_app/pcf_app.hpp +++ b/src/pcf_app/pcf_app.hpp @@ -29,15 +29,12 @@ #pragma once -#include "common_root_types.h" #include <boost/atomic.hpp> #include <string> #include "3gpp_29.500.h" -#include "pcf.h" #include "pcf_profile.hpp" #include "pcf_event.hpp" -#include "3gpp_29.510.h" #include "PatchItem.h" #include "pcf_sm_policy_control.hpp" #include "sm_policy/policy_storage.hpp" diff --git a/src/pcf_app/pcf_client.cpp b/src/pcf_app/pcf_client.cpp deleted file mode 100644 index dfd73c2244b45736dae34dcd3104be10ed0a2806..0000000000000000000000000000000000000000 --- a/src/pcf_app/pcf_client.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file pcf_client.cpp - \brief - \author Tien-Thinh NGUYEN - \company Eurecom - \date 2020 - \email: Tien-Thinh.Nguyen@eurecom.fr - */ - -#include "pcf_client.hpp" - -#include <curl/curl.h> - -#include <nlohmann/json.hpp> -#include <stdexcept> - -#include "logger.hpp" -#include "3gpp_29.500.h" -#include "pcf.h" -#include "pcf_config.hpp" - -using namespace oai::pcf::app; -using json = nlohmann::json; - -using namespace oai::config::pcf; -extern std::unique_ptr<pcf_config> pcf_cfg; - -//------------------------------------------------------------------------------ -// To read content of the response from NF -static std::size_t callback( - const char* in, std::size_t size, std::size_t num, std::string* out) { - const std::size_t totalBytes(size * num); - out->append(in, totalBytes); - return totalBytes; -} - -//------------------------------------------------------------------------------ -pcf_client::pcf_client() { - curl_global_init(CURL_GLOBAL_ALL); -} - -//------------------------------------------------------------------------------ -pcf_client::~pcf_client() { - curl_global_cleanup(); - Logger::pcf_app().debug("Delete PCF Client instance..."); -} - -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_method_e::POST, body, response, resp_headers); -} - -http_status_code_e pcf_client::send_get( - const std::string& url, std::string& response, std::string& resp_header) { - return do_request(url, http_method_e::GET, "", response, resp_header); -} - -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_method_e::PUT, body, response, resp_headers); -} - -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_method_e::PATCH, body, response, resp_headers); -} - -http_status_code_e pcf_client::send_delete( - const std::string& url, std::string& response, std::string& resp_headers) { - return do_request(url, http_method_e::DELETE, "", response, resp_headers); -} - -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_status_code_e::NO_RESPONSE; - } - prepare_curl_method(curl, method); - - // other CURL options - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, NF_CURL_TIMEOUT_MS); - curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1); - curl_easy_setopt( - curl, CURLOPT_INTERFACE, - pcf_cfg->local().get_sbi().get_if_name().c_str()); - - if (pcf_cfg->get_http_version() == 2) { - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - // we use a self-signed test server, skip verification during debugging - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt( - curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE); - } - - // Custom headers - struct curl_slist* headers = nullptr; - if (!body.empty()) { - std::string content_type = "Content-Type: application/json"; - headers = curl_slist_append(headers, content_type.c_str()); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.length()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); - } - // to prevent splitting it into two HTTP messages - headers = curl_slist_append(headers, "Expect: "); - - // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); - - std::string body_response; - std::string http_headers_response; - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body_response); - curl_easy_setopt(curl, CURLOPT_HEADERDATA, &http_headers_response); - - CURLcode res = curl_easy_perform(curl); - - if (res != CURLE_OK) { - Logger::pcf_sbi().warn( - "Could not perform HTTP request to %s. CURL Error code: %d", - url.c_str(), res); - curl_slist_free_all(headers); - curl_easy_cleanup(curl); - return http_status_code_e::NO_RESPONSE; - } - long http_code = -1; - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); - - response.append(body_response); - resp_headers.append(http_headers_response); - - curl_slist_free_all(headers); - curl_easy_cleanup(curl); - - return http_status_code_e(http_code); -} - -void pcf_client::prepare_curl_method(CURL*& curl, const http_method_e& method) { - switch (method) { - case http_method_e::GET: - curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); - break; - case http_method_e::POST: - curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1); - break; - case http_method_e::PATCH: - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - break; - case http_method_e::PUT: - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - break; - 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 deleted file mode 100644 index 5792ca95d6367edd53dcc60ef795459a5d0f5d73..0000000000000000000000000000000000000000 --- a/src/pcf_app/pcf_client.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * 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 - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file pcf_client.hpp - \author Tien-Thinh NGUYEN - \company Eurecom - \date 2020 - \email: Tien-Thinh.Nguyen@eurecom.fr - */ - -#pragma once - -#include <curl/curl.h> - -#include <map> -#include <thread> -#include "3gpp_29.500.h" - -namespace oai::pcf::app { - -enum class http_method_e { POST, GET, PUT, PATCH, DELETE }; - -class pcf_client_iface { - public: - /** - * Send a POST request to the URl specified in url - * @param url URL to send the request to - * @param body body to send in JSON representation - * @param response Response - * @param resp_headers Response headers - * @return HTTP response code - */ - virtual http_status_code_e send_post( - const std::string& url, const std::string& body, std::string& response, - std::string& resp_headers) = 0; - - /** - * Send a GET request to the URL specified in url - * @param url URL to send the request to - * @param response - * @param resp_header - * @return HTTP response code - */ - virtual http_status_code_e send_get( - const std::string& url, std::string& response, - std::string& resp_header) = 0; - - /** - * Send a PUT request to the URL specified in url - * @param url URL to send the request to - * @param body body to send in JSON representation - * @param response Response - * @param resp_headers Response headers - * @return HTTP response code - */ - virtual http_status_code_e send_put( - const std::string& url, const std::string& body, std::string& response, - std::string& resp_headers) = 0; - - /** - * Send a PATCH request to the URL specified in url - * @param url URL to send the request to - * @param body body to send in JSON representation - * @param response Response - * @param resp_headers Response headers - * @return HTTP response code - */ - virtual http_status_code_e send_patch( - const std::string& url, const std::string& body, std::string& response, - std::string& resp_headers) = 0; - - /** - * Send a DELETE request to the URL specified in url - * @param url URL to send the request to - * @param response Response - * @param resp_headers Response headers - * @return HTTP response code - */ - 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_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_method_e& method); - - public: - pcf_client(); - virtual ~pcf_client(); - - http_status_code_e send_post( - const std::string& url, const std::string& body, std::string& response, - std::string& resp_headers) override; - - http_status_code_e send_get( - const std::string& url, std::string& response, - std::string& resp_header) override; - - http_status_code_e send_put( - const std::string& url, const std::string& body, std::string& response, - std::string& resp_headers) override; - - http_status_code_e send_patch( - const std::string& url, const std::string& body, std::string& response, - std::string& resp_headers) override; - - http_status_code_e send_delete( - const std::string& url, std::string& response, - std::string& resp_headers) override; - - pcf_client(pcf_client const&) = delete; -}; -} // namespace oai::pcf::app diff --git a/src/pcf_app/pcf_event.hpp b/src/pcf_app/pcf_event.hpp index 337efe75a62d08ce7837205ea4f3db56f57f61f2..ab598b44c97a10c19e4fb817c1a06bc7b7388089 100644 --- a/src/pcf_app/pcf_event.hpp +++ b/src/pcf_app/pcf_event.hpp @@ -33,7 +33,6 @@ #include <boost/signals2.hpp> namespace bs2 = boost::signals2; -#include "pcf.h" #include "pcf_event_sig.hpp" #include "task_manager.hpp" diff --git a/src/pcf_app/pcf_nrf.cpp b/src/pcf_app/pcf_nrf.cpp index 8b7d00e7cf74a050cfe53e01f13d0b6e0dbf07f1..f92dd82f978f5cb32cf3ccacace248ea79652cc4 100644 --- a/src/pcf_app/pcf_nrf.cpp +++ b/src/pcf_app/pcf_nrf.cpp @@ -28,17 +28,17 @@ */ #include "pcf_nrf.hpp" -#include "conversions.hpp" #include "logger.hpp" #include "3gpp_29.500.h" +#include "3gpp_29.510.h" #include "pcf_config.hpp" -#include "pcf_client.hpp" #include "Snssai.h" #include "api_defs.h" +#include "http_client.hpp" +#include "sbi_helper.hpp" #include <boost/uuid/random_generator.hpp> #include <boost/uuid/uuid_io.hpp> -#include <stdexcept> using namespace oai::pcf::app; using namespace oai::config::pcf; @@ -47,24 +47,19 @@ using namespace boost::placeholders; using namespace std; extern std::unique_ptr<pcf_config> pcf_cfg; +extern std::shared_ptr<oai::http::http_client> http_client_inst; //------------------------------------------------------------------------------ pcf_nrf::pcf_nrf(pcf_event& ev) : m_event_sub(ev) { m_pcf_instance_id = to_string(boost::uuids::random_generator()()); - generate_nrf_api_url(); generate_pcf_profile(); + nf_addr_t nf_addr; + nf_addr.api_version = + pcf_cfg->get_nf(config::NRF_CONFIG_NAME)->get_sbi().get_api_version(); + nf_addr.uri_root = + pcf_cfg->get_nf(config::NRF_CONFIG_NAME)->get_sbi().get_url(); - m_pcf_client_inst = std::make_unique<pcf_client>(); -} - -//------------------------------------------------------------------------------ -void pcf_nrf::generate_nrf_api_url() { - m_nrf_url = pcf_cfg->get_nf(config::NRF_CONFIG_NAME)->get_sbi().get_url(); - m_nrf_url.append(NNRF_NFM_BASE) - .append( - pcf_cfg->get_nf(config::NRF_CONFIG_NAME)->get_sbi().get_api_version()) - .append(NNRF_DISC_INSTANCES) - .append(m_pcf_instance_id); + sbi_helper::get_nrf_nf_instance_uri(nf_addr, m_pcf_instance_id, m_nrf_url); } //--------------------------------------------------------------------------------------------- @@ -108,12 +103,12 @@ void pcf_nrf::generate_pcf_profile() { pcf_info_item.dnn_list.emplace_back("oai"); pcf_info_item.dnn_list.emplace_back("oai.ipv4"); pcf_info_item.dnn_list.emplace_back("ims"); - supi_range_pcf_info_item_t supi_ranges; + supi_range_info_item_t supi_ranges; supi_ranges.supi_range.start = "208950000000031"; supi_ranges.supi_range.pattern = "^imsi-20895[31-131]{10}$"; supi_ranges.supi_range.end = "208950000000131"; pcf_info_item.supi_ranges.push_back(supi_ranges); - identity_range_pcf_info_item_t gpsi_ranges; + identity_range_info_item_t gpsi_ranges; gpsi_ranges.identity_range.start = "752740000"; gpsi_ranges.identity_range.pattern = "^gpsi-75274[0-9]{4}$"; gpsi_ranges.identity_range.end = "752749999"; @@ -129,17 +124,15 @@ void pcf_nrf::register_to_nrf() { nlohmann::json body; m_nf_instance_profile.to_json(body); - std::string resp_body; - std::string resp_headers; - Logger::pcf_sbi().info("Sending NF registration request"); - http_status_code_e res = m_pcf_client_inst->send_put( - m_nrf_url, body.dump(), resp_body, resp_headers); + auto request = http_client_inst->prepare_json_request(m_nrf_url, body.dump()); + auto http_response = + http_client_inst->send_http_request(method_e::PUT, request); - if (res == http_status_code_e::HTTP_STATUS_CODE_201_CREATED || - res == http_status_code_e::HTTP_STATUS_CODE_200_OK) { + if (http_response.status_code == http_status_code::CREATED || + http_response.status_code == http_status_code::OK) { try { - if (resp_body.find("REGISTERED") != 0) { + if (http_response.body.find("REGISTERED") != 0) { start_event_nf_heartbeat(m_nrf_url); } Logger::pcf_sbi().debug("NF registration successful"); @@ -149,7 +142,7 @@ void pcf_nrf::register_to_nrf() { } else { Logger::pcf_sbi().warn( "NF registration failed: Wrong response code: %d", - static_cast<int>(res)); + http_response.status_code); } } //------------------------------------------------------------------------------ @@ -166,8 +159,7 @@ void pcf_nrf::start_event_nf_heartbeat(std::string& /* remoteURI */) { } //--------------------------------------------------------------------------------------------- -void pcf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) { - _unused(ms); +void pcf_nrf::trigger_nf_heartbeat_procedure(uint64_t /* ms */) { PatchItem patch_item = {}; std::vector<PatchItem> patch_items; PatchOperation op; @@ -178,24 +170,22 @@ void pcf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) { patch_items.push_back(patch_item); Logger::pcf_sbi().info("Sending NF heartbeat request"); - std::string body_response; - std::string response_headers; - nlohmann::json j; to_json(j, patch_item); - http_status_code_e res = m_pcf_client_inst->send_patch( - m_nrf_url, j.dump(), body_response, response_headers); + auto request = http_client_inst->prepare_json_request(m_nrf_url, j.dump()); + auto http_response = + http_client_inst->send_http_request(method_e::PATCH, request); - if (res == http_status_code_e::HTTP_STATUS_CODE_200_OK || - res == http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { + if (http_response.status_code == http_status_code::OK || + http_response.status_code == http_status_code::NO_CONTENT) { Logger::pcf_sbi().debug("NF heartbeat request successful"); } else { // TODO what should we do in this case? // We disconnect, but we dont trigger anything else Logger::pcf_sbi().warn( "NF heartbeat request failed. Wrong response code %d", - static_cast<int>(res)); + http_response.status_code); m_task_connection.disconnect(); } } @@ -211,14 +201,16 @@ void pcf_nrf::deregister_to_nrf() { Logger::pcf_sbi().info("Sending NF de-registration request"); - http_status_code_e res = - m_pcf_client_inst->send_delete(m_nrf_url, body_response, response_header); + http::request req; + req.uri = m_nrf_url; + auto http_response = + http_client_inst->send_http_request(method_e::DELETE, req); - if (res == http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { + if (http_response.status_code == http_status_code::NO_CONTENT) { Logger::pcf_sbi().info("NF Deregistration successful"); } else { Logger::pcf_sbi().warn( "NF Deregistration failed! Wrong response code: %d", - static_cast<int>(res)); + http_response.status_code); } } diff --git a/src/pcf_app/pcf_nrf.hpp b/src/pcf_app/pcf_nrf.hpp index 6905462ad6636d59cb85b67e0570256136264f0a..75d159e1068a33d0761968454e33e89b9ff8fade 100644 --- a/src/pcf_app/pcf_nrf.hpp +++ b/src/pcf_app/pcf_nrf.hpp @@ -29,21 +29,20 @@ #pragma once -#include "common_root_types.h" #include <boost/atomic.hpp> #include <string> #include "3gpp_29.500.h" -#include "pcf.h" #include "pcf_profile.hpp" #include "pcf_event.hpp" -#include "3gpp_29.510.h" #include "PatchItem.h" -#include "pcf_client.hpp" +#include "sbi_helper.hpp" namespace oai::pcf::app { class pcf_nrf { + const uint32_t HEART_BEAT_TIMER = 10; + public: explicit pcf_nrf(pcf_event& ev); pcf_nrf(pcf_nrf const&) = delete; @@ -70,7 +69,6 @@ class pcf_nrf { void deregister_to_nrf(); private: - std::unique_ptr<oai::pcf::app::pcf_client> m_pcf_client_inst; pcf_profile m_nf_instance_profile; // PCF profile std::string m_pcf_instance_id; // PCF instance id // for Event Handling @@ -78,23 +76,6 @@ class pcf_nrf { bs2::connection m_task_connection; std::string m_nrf_url; - /* - * Get pcf API Root - * @param [std::string& ] api_root: pcf's API Root - * @return void - */ - - /** - * Generate PCF API root based on the configuration and stores it in nrf_url - * @return Generated API root - */ - void generate_nrf_api_url(); - - /* - * Generate an SMF profile for this instance - * @param [void] - * @return void - */ /** * Generate PCF profile and stores it in nf_instance_profile */ diff --git a/src/pcf_app/pcf_profile.cpp b/src/pcf_app/pcf_profile.cpp index e3f7ed438a2c84823db9dccbfdcddf5d5bd5b96c..91a4835e553eb61b5c5beee910b1445d002672e3 100644 --- a/src/pcf_app/pcf_profile.cpp +++ b/src/pcf_app/pcf_profile.cpp @@ -35,8 +35,8 @@ #include "string.hpp" using namespace std; -// using namespace pcf; using namespace oai::pcf::app; +using namespace oai::common::sbi; //------------------------------------------------------------------------------ void nf_profile::set_nf_instance_id(const std::string& instance_id) { @@ -204,7 +204,7 @@ void nf_profile::display() const { Logger::pcf_app().debug("\tSNSSAI:"); } for (auto s : snssais) { - Logger::pcf_app().debug("\t\t SST %d, SD %s", s.sST, s.sD.c_str()); + Logger::pcf_app().debug("\t\t SST %d, SD %d", s.sst, s.sd); } if (!fqdn.empty()) { Logger::pcf_app().debug("\tFQDN: %s", fqdn.c_str()); @@ -236,8 +236,8 @@ void nf_profile::to_json(nlohmann::json& data) const { data["sNssais"] = nlohmann::json::array(); for (auto s : snssais) { nlohmann::json tmp = {}; - tmp["sst"] = s.sST; - tmp["sd"] = s.sD; + tmp["sst"] = s.sst; + tmp["sd"] = s.sd; data["sNssais"].push_back(tmp); } if (!fqdn.empty()) { @@ -282,9 +282,8 @@ void nf_profile::from_json(const nlohmann::json& data) { // sNssais if (data.find("sNssais") != data.end()) { for (auto it : data["sNssais"]) { - snssai_t s = {}; - s.sST = it["sst"].get<int>(); - s.sD = it["sd"].get<std::string>(); + snssai_t s(it["sst"].get<int>(), it["sd"].get<std::string>()); + snssais.push_back(s); } } @@ -300,11 +299,13 @@ void nf_profile::from_json(const nlohmann::json& data) { struct in_addr addr4 = {}; std::string address = it.get<std::string>(); unsigned char buf_in_addr[sizeof(struct in_addr)]; - if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) { + if (inet_pton(AF_INET, oai::utils::trim(address).c_str(), buf_in_addr) == + 1) { memcpy(&addr4, buf_in_addr, sizeof(struct in_addr)); } else { Logger::pcf_app().warn( - "Address conversion: Bad value %s", util::trim(address).c_str()); + "Address conversion: Bad value %s", + oai::utils::trim(address).c_str()); } add_nf_ipv4_addresses(addr4); } @@ -373,7 +374,7 @@ void pcf_profile::display() const { Logger::pcf_app().debug(" SNSSAI:"); } for (auto s : snssais) { - Logger::pcf_app().debug(" SST, SD: %d, %s", s.sST, s.sD.c_str()); + Logger::pcf_app().debug(s.to_model_snssai().to_string(4)); } // IPv4 Addresses @@ -489,9 +490,7 @@ void pcf_profile::from_json(const nlohmann::json& data) { // sNssais if (data.find("sNssais") != data.end()) { for (auto it : data["sNssais"]) { - snssai_t s = {}; - s.sST = it["sst"].get<int>(); - s.sD = it["sd"].get<std::string>(); + snssai_t s(it["sst"].get<int>(), it["sd"].get<std::string>()); snssais.push_back(s); } } @@ -502,11 +501,13 @@ void pcf_profile::from_json(const nlohmann::json& data) { struct in_addr addr4 = {}; std::string address = it.get<std::string>(); unsigned char buf_in_addr[sizeof(struct in_addr)]; - if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) { + if (inet_pton(AF_INET, oai::utils::trim(address).c_str(), buf_in_addr) == + 1) { memcpy(&addr4, buf_in_addr, sizeof(struct in_addr)); } else { Logger::pcf_app().warn( - "Address conversion: Bad value %s", util::trim(address).c_str()); + "Address conversion: Bad value %s", + oai::utils::trim(address).c_str()); } add_nf_ipv4_addresses(addr4); } @@ -533,7 +534,7 @@ void pcf_profile::from_json(const nlohmann::json& data) { if (info.find("supiRanges") != info.end()) { nlohmann::json supi_ranges = data["pcfInfo"]["supiRanges"]; for (auto d : supi_ranges) { - supi_range_pcf_info_item_t supi; + supi_range_info_item_t supi; supi.supi_range.start = d["start"]; supi.supi_range.end = d["end"]; supi.supi_range.pattern = d["pattern"]; @@ -543,7 +544,7 @@ void pcf_profile::from_json(const nlohmann::json& data) { if (info.find("gpsiRanges") != info.end()) { nlohmann::json gpsi_ranges = data["pcfInfo"]["gpsiRanges"]; for (auto d : gpsi_ranges) { - identity_range_pcf_info_item_t gpsi; + identity_range_info_item_t gpsi; gpsi.identity_range.start = d["start"]; gpsi.identity_range.end = d["end"]; gpsi.identity_range.pattern = d["pattern"]; diff --git a/src/pcf_app/pcf_profile.hpp b/src/pcf_app/pcf_profile.hpp index 1576efbfe1f2002870035813c09da620b94c2cfd..2c6277ed73d4588ac05e59485a054365a2f6535f 100644 --- a/src/pcf_app/pcf_profile.hpp +++ b/src/pcf_app/pcf_profile.hpp @@ -40,10 +40,9 @@ #include <vector> #include "logger.hpp" -#include "pcf.h" +#include "3gpp_23.003.h" +#include "3gpp_29.510.h" -// namespace oai { -// namespace pcf { namespace oai::pcf::app { using namespace std; @@ -371,21 +370,21 @@ class pcf_profile : public nf_profile { * @param [std::vector<nf_service_t> &] n: nf_service * @return void */ - void set_nf_services(const std::vector<nf_service_t>& n); + void set_nf_services(const std::vector<oai::common::sbi::nf_service_t>& n); /* * Add nf service * @param [snssai_t &] n: nf service * @return void */ - void add_nf_service(const nf_service_t& n); + void add_nf_service(const oai::common::sbi::nf_service_t& n); /* * Get NF services * @param [std::vector<snssai_t> &] n: store instance's nf services * @return void: */ - void get_nf_services(std::vector<nf_service_t>& n) const; + void get_nf_services(std::vector<oai::common::sbi::nf_service_t>& n) const; /* * Set custom info @@ -406,7 +405,7 @@ class pcf_profile : public nf_profile { * @param [pcf_info_t &] s: pcf info * @return void */ - void set_pcf_info(const pcf_info_t& s); + void set_pcf_info(const oai::common::sbi::pcf_info_t& s); /* * Add an snssai_pcf_info_item to the pcf info @@ -420,7 +419,7 @@ class pcf_profile : public nf_profile { * @param [pcf_info_t &] s: store instance's pcf info * @return void: */ - void get_pcf_info(pcf_info_t& s) const; + void get_pcf_info(oai::common::sbi::pcf_info_t& s) const; /* * Print related-information for NF profile @@ -451,13 +450,11 @@ class pcf_profile : public nf_profile { void handle_heartbeart_timeout(uint64_t ms); protected: - std::vector<nf_service_t> nf_services; + std::vector<oai::common::sbi::nf_service_t> nf_services; nlohmann::json custom_info; // store extra json data - pcf_info_t pcf_info; + oai::common::sbi::pcf_info_t pcf_info; }; -// } // namespace app } // namespace oai::pcf::app -// } // namespace oai #endif diff --git a/src/pcf_app/pcf_sm_policy_control.cpp b/src/pcf_app/pcf_sm_policy_control.cpp index b6f80fa11790b2d86b6cef066354e17228342b27..45a2b86247ce26804e73135de33fde632c2239e4 100644 --- a/src/pcf_app/pcf_sm_policy_control.cpp +++ b/src/pcf_app/pcf_sm_policy_control.cpp @@ -28,21 +28,13 @@ */ #include "pcf_sm_policy_control.hpp" -#include "conversions.hpp" #include "logger.hpp" -#include "pcf.h" #include "pcf_config.hpp" -#include "pcf_client.hpp" -#include "Snssai.h" -#include "TrafficControlData.h" #include "sm_policy/policy_decision.hpp" -#include <boost/uuid/random_generator.hpp> #include <boost/uuid/uuid_io.hpp> -#include <stdexcept> #include <unordered_map> #include <map> -#include <shared_mutex> #include <memory> #include <string> diff --git a/src/pcf_app/pcf_sm_policy_control.hpp b/src/pcf_app/pcf_sm_policy_control.hpp index f098dd6026b65f45aefeadf46346743ab865b220..5be6ef43379376e7eea60f12d89a91c730517102 100644 --- a/src/pcf_app/pcf_sm_policy_control.hpp +++ b/src/pcf_app/pcf_sm_policy_control.hpp @@ -125,7 +125,7 @@ class pcf_smpc { std::string& problem_details); private: - util::uint_generator<uint32_t> m_association_id_generator; + oai::utils::uint_generator<uint32_t> m_association_id_generator; std::unordered_map< std::string, oai::pcf::app::sm_policy::individual_sm_association>