Verified Commit cdab6bea authored by Rohan's avatar Rohan
Browse files

nf discovery service validated

parent aae8130e
Pipeline #27057 passed with stage
in 0 seconds
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <regex> #include <regex>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string> #include <string>
#include "string.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "nrf_config.hpp" #include "nrf_config.hpp"
...@@ -67,6 +68,7 @@ void nrf_http2_server::start() { ...@@ -67,6 +68,7 @@ void nrf_http2_server::start() {
nlohmann::json::parse(msg.c_str()).get_to(nFProfile); nlohmann::json::parse(msg.c_str()).get_to(nFProfile);
this->register_nf_instance_handler(nFProfile, response); this->register_nf_instance_handler(nFProfile, response);
} }
if (request.method().compare("GET") == 0) { if (request.method().compare("GET") == 0) {
nlohmann::json::parse(msg.c_str()).get_to(nFProfile); nlohmann::json::parse(msg.c_str()).get_to(nFProfile);
std::vector<std::string> split_result; std::vector<std::string> split_result;
...@@ -88,11 +90,12 @@ void nrf_http2_server::start() { ...@@ -88,11 +90,12 @@ void nrf_http2_server::start() {
std::string nfType = std::string nfType =
util::get_query_param(querystring, "nf-type"); util::get_query_param(querystring, "nf-type");
uint32_t limit = uint32_t limit =
atoi(util::get_query_param(querystring, "limit").c_str()); stoi(util::get_query_param(querystring, "limit").c_str());
this->get_nf_instances_handler(nfType, limit, response); this->get_nf_instances_handler(nfType, limit, response);
} }
} }
if (request.method().compare("PATCH") == 0 && len > 0) { if (request.method().compare("PATCH") == 0 && len > 0) {
std::vector<PatchItem> patchItem; std::vector<PatchItem> patchItem;
nlohmann::json::parse(msg.c_str()).get_to(patchItem); nlohmann::json::parse(msg.c_str()).get_to(patchItem);
...@@ -102,6 +105,7 @@ void nrf_http2_server::start() { ...@@ -102,6 +105,7 @@ void nrf_http2_server::start() {
nfInstanceID = split_result[split_result.size() - 1].c_str(); nfInstanceID = split_result[split_result.size() - 1].c_str();
this->update_instance_handler(nfInstanceID, patchItem, response); this->update_instance_handler(nfInstanceID, patchItem, response);
} }
if (request.method().compare("DELETE") == 0) { if (request.method().compare("DELETE") == 0) {
std::vector<std::string> split_result; std::vector<std::string> split_result;
boost::split( boost::split(
...@@ -148,7 +152,48 @@ void nrf_http2_server::start() { ...@@ -148,7 +152,48 @@ void nrf_http2_server::start() {
subscriptionID = split_result[split_result.size() - 1].c_str(); subscriptionID = split_result[split_result.size() - 1].c_str();
this->remove_subscription_handler(subscriptionID, response); this->remove_subscription_handler(subscriptionID, response);
} }
} catch (nlohmann::detail::exception& e) {
Logger::nrf_sbi().warn(
"Can not parse the json data (error: %s)!", e.what());
response.write_head(
http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST);
response.end();
return;
}
});
});
// NF Discovery
server.handle(
NNRF_DISC_BASE + nrf_cfg.sbi_api_version + "/nf-instances",
[&](const request& request, const response& response) {
request.on_data([&](const uint8_t* data, std::size_t len) {
std::string msg((char*) data, len);
try {
if (request.method().compare("GET") == 0) {
std::string split_query = request.uri().raw_query;
// Parse query paramaters
std::string nfTypeTarget =
util::get_query_param(split_query, "target-nf-type");
std::string nfTypeReq = util::get_query_param(
split_query.c_str(), "requester-nf-type");
std::string requester_nf_instance_id = util::get_query_param(
split_query.c_str(), "requester-nf-instance-id");
std::string limit_nfs =
util::get_query_param(split_query.c_str(), "limit");
// TODO: other query parameters
Logger::nrf_sbi().debug(
"/nnrf-disc/ query params - nfTypeTarget: %s, nfTypeReq: %s, "
"requester-nf-instance-id: %s, limit_nfs %s",
nfTypeTarget.c_str(), nfTypeReq.c_str(),
requester_nf_instance_id.c_str(), limit_nfs.c_str());
this->search_nf_instances_handler(
nfTypeTarget, nfTypeReq, requester_nf_instance_id, limit_nfs,
response);
}
} catch (nlohmann::detail::exception& e) { } catch (nlohmann::detail::exception& e) {
Logger::nrf_sbi().warn( Logger::nrf_sbi().warn(
"Can not parse the json data (error: %s)!", e.what()); "Can not parse the json data (error: %s)!", e.what());
...@@ -431,38 +476,40 @@ void nrf_http2_server::remove_subscription_handler( ...@@ -431,38 +476,40 @@ void nrf_http2_server::remove_subscription_handler(
} }
void nrf_http2_server::search_nf_instances_handler( void nrf_http2_server::search_nf_instances_handler(
const SubscriptionData& subscriptionData, const response& response) { const std::string& target_nf_type, const std::string& requester_nf_type,
const std::string& requester_nf_instance_id, const std::string& limit_nfs,
const response& response) {
Logger::nrf_sbi().info( Logger::nrf_sbi().info(
"Got a request to discover the set of NF instances that satisfies a " "Got a request to discover the set of NF instances that satisfies a "
"number of input query parameters"); "number of input query parameters");
// ToDo // ToDo
std::string target_nf_type = {}; std::string target_nfType = {};
// if (!targetNfType.isEmpty()) { if (!target_nf_type.empty()) {
// target_nf_type = targetNfType.get(); target_nfType = target_nf_type;
// Logger::nrf_sbi().debug("\tTarget NF type: %s", target_nf_type.c_str()); Logger::nrf_sbi().debug("\tTarget NF type: %s", target_nfType.c_str());
// } }
std::string requester_nf_type = {}; std::string requester_nfType = {};
// if (!requesterNfType.isEmpty()) { if (!requester_nf_type.empty()) {
// requester_nf_type = requesterNfType.get(); requester_nfType = requester_nf_type;
// Logger::nrf_sbi().debug( Logger::nrf_sbi().debug(
// "\tRequested NF type: %s", requester_nf_type.c_str()); "\tRequested NF type: %s", requester_nfType.c_str());
// } }
std::string requester_nf_instance_id = {}; std::string requester_nfInstance_id = {};
// if (!requesterNfInstanceId.isEmpty()) { if (!requester_nf_instance_id.empty()) {
// requester_nf_instance_id = requesterNfInstanceId.get(); requester_nfInstance_id = requester_nf_instance_id;
// Logger::nrf_sbi().debug( Logger::nrf_sbi().debug(
// "\tRequested NF instance id: %s", requester_nf_instance_id.c_str()); "\tRequested NF instance id: %s", requester_nf_instance_id.c_str());
// } }
uint32_t limit_nfs = 0; uint32_t limit_Nfs = 0;
// if (!limit.isEmpty()) { if (!limit_nfs.empty()) {
// limit_nfs = limit.get(); limit_Nfs = stoi(limit_nfs);
// Logger::nrf_sbi().debug( Logger::nrf_sbi().debug(
// "\tMaximum number of NFProfiles to be returned in the response: %d", "\tMaximum number of NFProfiles to be returned in the response: %d",
// limit_nfs); limit_Nfs);
// } }
// TODO: other query parameters // TODO: other query parameters
...@@ -470,8 +517,8 @@ void nrf_http2_server::search_nf_instances_handler( ...@@ -470,8 +517,8 @@ void nrf_http2_server::search_nf_instances_handler(
ProblemDetails problem_details = {}; ProblemDetails problem_details = {};
std::string search_id = {}; std::string search_id = {};
m_nrf_app->handle_search_nf_instances( m_nrf_app->handle_search_nf_instances(
target_nf_type, requester_nf_type, requester_nf_instance_id, limit_nfs, target_nfType, requester_nfType, requester_nfInstance_id, limit_Nfs,
search_id, http_code, 1, problem_details); search_id, http_code, 2, problem_details);
nlohmann::json json_data = {}; nlohmann::json json_data = {};
std::string content_type = "application/json"; std::string content_type = "application/json";
...@@ -485,7 +532,7 @@ void nrf_http2_server::search_nf_instances_handler( ...@@ -485,7 +532,7 @@ void nrf_http2_server::search_nf_instances_handler(
} else { } else {
// convert the profile to Json // convert the profile to Json
if (search_result != nullptr) if (search_result != nullptr)
search_result.get()->to_json(json_data, limit_nfs); search_result.get()->to_json(json_data, limit_Nfs);
} }
// TODO: applying client restrictions in terms of the number of // TODO: applying client restrictions in terms of the number of
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#define FILE_NRF_HTTP2_SERVER_SEEN #define FILE_NRF_HTTP2_SERVER_SEEN
#include "conversions.hpp" #include "conversions.hpp"
#include "string.hpp"
//#include "nrf.h" //#include "nrf.h"
#include "nrf_app.hpp" #include "nrf_app.hpp"
...@@ -69,7 +68,9 @@ class nrf_http2_server { ...@@ -69,7 +68,9 @@ class nrf_http2_server {
void remove_subscription_handler( void remove_subscription_handler(
const std::string& subscriptionID, const response& response); const std::string& subscriptionID, const response& response);
void search_nf_instances_handler( void search_nf_instances_handler(
const SubscriptionData& subscriptionData, const response& response); const std::string& target_nf_type, const std::string& requester_nf_type,
const std::string& requester_nf_instance_id, const std::string& limit_nfs,
const response& response);
void access_token_request_handler( void access_token_request_handler(
const SubscriptionData& subscriptionData, const response& response); const SubscriptionData& subscriptionData, const response& response);
......
...@@ -77,6 +77,7 @@ typedef uint32_t evsub_id_t; ...@@ -77,6 +77,7 @@ typedef uint32_t evsub_id_t;
#define UNASSIGNED_EVSUB_ID ((evsub_id_t) 0x00000000) #define UNASSIGNED_EVSUB_ID ((evsub_id_t) 0x00000000)
#define NNRF_NFM_BASE "/nnrf-nfm/" #define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_DISC_BASE "/nnrf-disc/"
#define NNRF_NFM_NF_INSTANCE "/nf-instances/" #define NNRF_NFM_NF_INSTANCE "/nf-instances/"
#define NNRF_NFM_STATUS_SUBSCRIBE_URL "/subscriptions" #define NNRF_NFM_STATUS_SUBSCRIBE_URL "/subscriptions"
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
#include "string.hpp" #include "string.hpp"
#include <iostream>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
...@@ -89,14 +90,18 @@ std::string& util::trim(std::string& s) { ...@@ -89,14 +90,18 @@ std::string& util::trim(std::string& s) {
} }
// extract query param from given querystring // extract query param from given querystring
std::string& util::get_query_param( std::string query_param_tmp;
std::string& querystring, std::string param) { //
std::string util::get_query_param(std::string querystring, std::string param) {
std::regex reList("([^=]*)=([^&]*)&?"); std::regex reList("([^=]*)=([^&]*)&?");
std::string tmp = param; query_param_tmp.clear();
std::for_each( std::for_each(
std::sregex_iterator(querystring.begin(), querystring.end(), reList), std::sregex_iterator(querystring.begin(), querystring.end(), reList),
std::sregex_iterator(), [param](std::smatch const& match) { std::sregex_iterator(), [param](std::smatch match) {
std::string qs_match_1 = match[1].str(); if (match[1] == param) {
if (qs_match_1 == param) return match[2].str(); query_param_tmp = match[2].str().c_str();
return;
}
}); });
return query_param_tmp;
} }
\ No newline at end of file
...@@ -40,6 +40,6 @@ std::string& rtrim(std::string& s); ...@@ -40,6 +40,6 @@ std::string& rtrim(std::string& s);
// trim from both ends // trim from both ends
std::string& trim(std::string& s); std::string& trim(std::string& s);
// extract query param from given querystring // extract query param from given querystring
std::string& get_query_param(std::string& querystring, std::string param); std::string get_query_param(std::string querystring, std::string param);
} // namespace util } // namespace util
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment