diff --git a/src/pcf_app/pcf_app.cpp b/src/pcf_app/pcf_app.cpp index d785cf34c5d5be292a19d2893c9906d4b2c6dec1..31248f0ab12b5cd4d60f9db1a1c736f111780107 100644 --- a/src/pcf_app/pcf_app.cpp +++ b/src/pcf_app/pcf_app.cpp @@ -22,8 +22,8 @@ /*! \file pcf_app.cpp \brief \author Rohan Kharade - \company Openairinterface Software Allianse - \date 2021 + \company Openairinterface Software Alliance + \date 2022 \email: rohan.kharade@openairinterface.org */ @@ -43,16 +43,16 @@ using namespace std; extern std::unique_ptr<pcf_config> pcf_cfg; //------------------------------------------------------------------------------ -pcf_app::pcf_app(pcf_event& ev) : event_sub(ev) { +pcf_app::pcf_app(pcf_event& ev) : m_event_sub(ev) { Logger::pcf_app().startup("Starting..."); Logger::pcf_app().startup("Reading local Policy configuration..."); m_policy_storage = std::make_shared<sm_policy::policy_storage>(); - provisioning_file = + m_provisioning_file = std::make_shared<sm_policy::policy_provisioning_file>(m_policy_storage); - if (!provisioning_file->read_all_policy_files()) { + if (!m_provisioning_file->read_all_policy_files()) { Logger::pcf_app().error( "Cannot read policy configuration from file. Exiting"); exit(-1); @@ -60,27 +60,25 @@ pcf_app::pcf_app(pcf_event& ev) : event_sub(ev) { // Register to NRF if (pcf_cfg->pcf_features.register_nrf) { - pcf_nrf_inst = std::make_unique<pcf_nrf>(ev); - pcf_nrf_inst->register_to_nrf(); + m_pcf_nrf_inst = std::make_unique<pcf_nrf>(ev); + m_pcf_nrf_inst->register_to_nrf(); Logger::pcf_app().info("NRF TASK Created "); } - pcf_smpc_service = std::make_shared<pcf_smpc>(m_policy_storage); + m_pcf_smpc_service = std::make_shared<pcf_smpc>(m_policy_storage); } //------------------------------------------------------------------------------ pcf_app::~pcf_app() { Logger::pcf_app().debug("Delete PCF_APP instance..."); - pcf_smpc_service = nullptr; - pcf_nrf_inst = nullptr; } std::shared_ptr<pcf_smpc> pcf_app::get_pcf_smpc_service() { - return pcf_smpc_service; + return m_pcf_smpc_service; } void pcf_app::stop() { - if (pcf_nrf_inst) { - pcf_nrf_inst->deregister_to_nrf(); + if (m_pcf_nrf_inst) { + m_pcf_nrf_inst->deregister_to_nrf(); } } \ No newline at end of file diff --git a/src/pcf_app/pcf_app.hpp b/src/pcf_app/pcf_app.hpp index 2bea9c30b228746b55c615a929a36f6d25b2b51d..ae97c654b7b8badf9975f04da1ef38cf5d4bb8f1 100644 --- a/src/pcf_app/pcf_app.hpp +++ b/src/pcf_app/pcf_app.hpp @@ -22,13 +22,12 @@ /*! \file pcf_app.hpp \brief \author Rohan Kharade - \company Openairinterface Software Allianse - \date 2021 + \company OpenAirInterface Software Alliance + \date 2022 \email: rohan.kharade@openairinterface.org */ -#ifndef FILE_PCF_APP_HPP_SEEN -#define FILE_PCF_APP_HPP_SEEN +#pragma once #include "common_root_types.h" #include <boost/atomic.hpp> @@ -58,24 +57,23 @@ class pcf_app { std::shared_ptr<pcf_smpc> get_pcf_smpc_service(); /** - * Stops all the ongoing processes and procedures of the PCF APP layer, + * Stop all the ongoing processes and procedures of the PCF APP layer, * deregisters at NRF */ void stop(); private: - pcf_profile nf_instance_profile; // PCF profile - std::string pcf_instance_id; // PCF instance id + pcf_profile m_nf_instance_profile; // PCF profile + std::string m_pcf_instance_id; // PCF instance id // for Event Handling - pcf_event& event_sub; - bs2::connection task_connection; + pcf_event& m_event_sub; + bs2::connection m_task_connection; - std::shared_ptr<pcf_smpc> pcf_smpc_service; + std::shared_ptr<pcf_smpc> m_pcf_smpc_service; std::shared_ptr<oai::pcf::app::sm_policy::policy_storage> m_policy_storage; - std::unique_ptr<oai::pcf::app::pcf_nrf> pcf_nrf_inst; + std::unique_ptr<oai::pcf::app::pcf_nrf> m_pcf_nrf_inst; std::shared_ptr<oai::pcf::app::sm_policy::policy_provisioning_file> - provisioning_file; + m_provisioning_file; }; } // namespace oai::pcf::app -#endif /* FILE_PCF_APP_HPP_SEEN */ diff --git a/src/pcf_app/pcf_client.cpp b/src/pcf_app/pcf_client.cpp index 1cba62ef7d92c43fccca19574106b5b17289a5a2..b544e2c57d73de5a3876c521950d7c437f8e10a0 100644 --- a/src/pcf_app/pcf_client.cpp +++ b/src/pcf_app/pcf_client.cpp @@ -133,12 +133,15 @@ http_status_code_e pcf_client::do_request( // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); - auto body_response = std::make_unique<std::string>(); - auto http_headers_response = std::make_unique<std::string>(); + // auto body_response = std::make_unique<std::string>(); + // auto http_headers_response = std::make_unique<std::string>(); + + std::string body_response; + std::string http_headers_response; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, body_response.get()); - curl_easy_setopt(curl, CURLOPT_HEADERDATA, http_headers_response.get()); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body_response); + curl_easy_setopt(curl, CURLOPT_HEADERDATA, &http_headers_response); CURLcode res = curl_easy_perform(curl); @@ -153,8 +156,8 @@ http_status_code_e pcf_client::do_request( long http_code = -1; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); - response.append(*body_response); - resp_headers.append(*http_headers_response); + response.append(body_response); + resp_headers.append(http_headers_response); curl_slist_free_all(headers); curl_easy_cleanup(curl); diff --git a/src/pcf_app/pcf_client.hpp b/src/pcf_app/pcf_client.hpp index c614b17e427a1df10b56b175bcce8a8bfd38c5ca..5792ca95d6367edd53dcc60ef795459a5d0f5d73 100644 --- a/src/pcf_app/pcf_client.hpp +++ b/src/pcf_app/pcf_client.hpp @@ -26,8 +26,7 @@ \email: Tien-Thinh.Nguyen@eurecom.fr */ -#ifndef FILE_PCF_CLIENT_HPP_SEEN -#define FILE_PCF_CLIENT_HPP_SEEN +#pragma once #include <curl/curl.h> @@ -42,7 +41,7 @@ enum class http_method_e { POST, GET, PUT, PATCH, DELETE }; class pcf_client_iface { public: /** - * Sends a POST request to the URl specified in url + * 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 @@ -65,7 +64,7 @@ class pcf_client_iface { std::string& resp_header) = 0; /** - * Sends a PUT request to the URL specified in url + * 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 @@ -77,7 +76,7 @@ class pcf_client_iface { std::string& resp_headers) = 0; /** - * Sends a PATCH request to the URL specified in url + * 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 @@ -89,7 +88,7 @@ class pcf_client_iface { std::string& resp_headers) = 0; /** - * Sends a DELETE request to the URL specified in url + * 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 @@ -136,4 +135,3 @@ class pcf_client : pcf_client_iface { pcf_client(pcf_client const&) = delete; }; } // namespace oai::pcf::app -#endif /* FILE_PCF_CLIENT_HPP_SEEN */ diff --git a/src/pcf_app/pcf_nrf.cpp b/src/pcf_app/pcf_nrf.cpp index 03b3e262c1dbd94204be1fd67922f0fe97672bdf..b0ade2e91d80f595f2b965f3ec48c3bb34ddfe00 100644 --- a/src/pcf_app/pcf_nrf.cpp +++ b/src/pcf_app/pcf_nrf.cpp @@ -48,38 +48,38 @@ using namespace std; extern std::unique_ptr<pcf_config> pcf_cfg; //------------------------------------------------------------------------------ -pcf_nrf::pcf_nrf(pcf_event& ev) : event_sub(ev) { - pcf_instance_id = to_string(boost::uuids::random_generator()()); +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(); - pcf_client_inst = std::make_unique<pcf_client>(); + m_pcf_client_inst = std::make_unique<pcf_client>(); } //------------------------------------------------------------------------------ void pcf_nrf::generate_nrf_api_url() { - nrf_url = ""; - nrf_url.append(conv::toString(pcf_cfg->nrf_addr.ipv4_addr)) + m_nrf_url = ""; + m_nrf_url.append(conv::toString(pcf_cfg->nrf_addr.ipv4_addr)) .append(":") .append(to_string(pcf_cfg->nrf_addr.port)) .append(NNRF_NFM_BASE) .append(pcf_cfg->nrf_addr.api_version) .append(NNRF_DISC_INSTANCES) - .append(pcf_instance_id); + .append(m_pcf_instance_id); } //--------------------------------------------------------------------------------------------- void pcf_nrf::generate_pcf_profile() { // TODO: remove hardcoded values // generate UUID - nf_instance_profile.set_nf_instance_id(pcf_instance_id); - nf_instance_profile.set_nf_instance_name("OAI-PCF"); - nf_instance_profile.set_nf_type("PCF"); - nf_instance_profile.set_nf_status("REGISTERED"); - nf_instance_profile.set_nf_heartBeat_timer(50); - nf_instance_profile.set_nf_priority(1); - nf_instance_profile.set_nf_capacity(100); - nf_instance_profile.add_nf_ipv4_addresses(pcf_cfg->sbi.addr4); + m_nf_instance_profile.set_nf_instance_id(m_pcf_instance_id); + m_nf_instance_profile.set_nf_instance_name("OAI-PCF"); + m_nf_instance_profile.set_nf_type("PCF"); + m_nf_instance_profile.set_nf_status("REGISTERED"); + m_nf_instance_profile.set_nf_heartBeat_timer(50); + m_nf_instance_profile.set_nf_priority(1); + m_nf_instance_profile.set_nf_capacity(100); + m_nf_instance_profile.add_nf_ipv4_addresses(pcf_cfg->sbi.addr4); // NF services nf_service_t nf_service = {}; @@ -100,7 +100,7 @@ void pcf_nrf::generate_pcf_profile() { if (pcf_cfg->pcf_features.use_http2) endpoint.port = pcf_cfg->sbi.http2_port; nf_service.ip_endpoints.push_back(endpoint); - nf_instance_profile.add_nf_service(nf_service); + m_nf_instance_profile.add_nf_service(nf_service); // PCF info pcf_info_t pcf_info_item; @@ -119,31 +119,29 @@ void pcf_nrf::generate_pcf_profile() { gpsi_ranges.identity_range.pattern = "^gpsi-75274[0-9]{4}$"; gpsi_ranges.identity_range.end = "752749999"; pcf_info_item.gpsi_ranges.push_back(gpsi_ranges); - nf_instance_profile.set_pcf_info(pcf_info_item); + m_nf_instance_profile.set_pcf_info(pcf_info_item); // ToDo: rxDiamHost, rxDiamRealm, v2xSupportInd. // Display the profile - nf_instance_profile.display(); + m_nf_instance_profile.display(); } //--------------------------------------------------------------------------------------------- void pcf_nrf::register_to_nrf() { - nlohmann::json response_data = {}; - - nlohmann::json body{}; - nf_instance_profile.to_json(body); + 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 = - pcf_client_inst->send_put(nrf_url, body.dump(), resp_body, resp_headers); + http_status_code_e res = m_pcf_client_inst->send_put( + m_nrf_url, body.dump(), resp_body, resp_headers); - if (res == http_status_code_e::HTTP_STATUS_CODE_201_CREATED or + if (res == http_status_code_e::HTTP_STATUS_CODE_201_CREATED || res == http_status_code_e::HTTP_STATUS_CODE_200_OK) { try { if (resp_body.find("REGISTERED") != 0) { - start_event_nf_heartbeat(nrf_url); + start_event_nf_heartbeat(m_nrf_url); } Logger::pcf_sbi().debug("NF registration successful"); } catch (nlohmann::json::exception& e) { @@ -162,7 +160,7 @@ void pcf_nrf::start_event_nf_heartbeat(std::string& remoteURI) { .count(); const uint64_t interval = HEART_BEAT_TIMER * 1000; // ms - task_connection = event_sub.subscribe_task_nf_heartbeat( + m_task_connection = m_event_sub.subscribe_task_nf_heartbeat( boost::bind(&pcf_nrf::trigger_nf_heartbeat_procedure, this, _1), interval, ms + interval); } @@ -185,10 +183,10 @@ void pcf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) { nlohmann::json j; to_json(j, patch_item); - http_status_code_e res = pcf_client_inst->send_patch( - nrf_url, j.dump(), body_response, response_headers); + http_status_code_e res = m_pcf_client_inst->send_patch( + m_nrf_url, j.dump(), body_response, response_headers); - if (res == http_status_code_e::HTTP_STATUS_CODE_200_OK or + if (res == http_status_code_e::HTTP_STATUS_CODE_200_OK || res == http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { Logger::pcf_sbi().debug("NF heartbeat request successful"); } else { @@ -196,7 +194,7 @@ void pcf_nrf::trigger_nf_heartbeat_procedure(uint64_t ms) { // We disconnect, but we dont trigger anything else Logger::pcf_sbi().warn( "NF heartbeat request failed. Wrong response code %d", res); - task_connection.disconnect(); + m_task_connection.disconnect(); } } //------------------------------------------------------------------------------ @@ -212,12 +210,12 @@ void pcf_nrf::deregister_to_nrf() { Logger::pcf_sbi().info("Sending NF de-registration request"); http_status_code_e res = - pcf_client_inst->send_delete(nrf_url, body_response, response_header); + m_pcf_client_inst->send_delete(m_nrf_url, body_response, response_header); - if (res != http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { + if (res == http_status_code_e::HTTP_STATUS_CODE_204_NO_CONTENT) { + Logger::pcf_sbi().info("NF Deregistration successful"); + } else { Logger::pcf_sbi().warn( "NF Deregistration failed! Wrong response code: %d", res); - } else { - Logger::pcf_sbi().info("NF Deregistration successful"); } } diff --git a/src/pcf_app/pcf_nrf.hpp b/src/pcf_app/pcf_nrf.hpp index 52a3826f96da8382fa67fcf597044b1d1b85f84f..6905462ad6636d59cb85b67e0570256136264f0a 100644 --- a/src/pcf_app/pcf_nrf.hpp +++ b/src/pcf_app/pcf_nrf.hpp @@ -27,8 +27,7 @@ \email: rohan.kharade@openairinterface.org */ -#ifndef FILE_PCF_NRF_HPP_SEEN -#define FILE_PCF_NRF_HPP_SEEN +#pragma once #include "common_root_types.h" #include <boost/atomic.hpp> @@ -71,13 +70,13 @@ class pcf_nrf { void deregister_to_nrf(); private: - std::unique_ptr<oai::pcf::app::pcf_client> pcf_client_inst; - pcf_profile nf_instance_profile; // PCF profile - std::string pcf_instance_id; // PCF instance id + 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 - pcf_event& event_sub; - bs2::connection task_connection; - std::string nrf_url; + pcf_event& m_event_sub; + bs2::connection m_task_connection; + std::string m_nrf_url; /* * Get pcf API Root @@ -92,14 +91,13 @@ class pcf_nrf { void generate_nrf_api_url(); /* - * Generate a SMF profile for this instance + * Generate an SMF profile for this instance * @param [void] * @return void */ /** - * Generates PCF profile and stores it in nf_instance_profile + * Generate PCF profile and stores it in nf_instance_profile */ void generate_pcf_profile(); }; } // namespace oai::pcf::app -#endif /* FILE_PCF_NRF_HPP_SEEN */