Commit 6b206342 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Fix issue for NFListRetrieval

parent 89656255
......@@ -12,7 +12,7 @@
#include "NFInstancesStoreApiImpl.h"
#include "logger.hpp"
#include "nrf_app.hpp"
#include "3gpp_29.500.h"
namespace oai {
namespace nrf {
......@@ -54,13 +54,35 @@ void NFInstancesStoreApiImpl::get_nf_instances(
}
int http_code = 0;
m_nrf_app->handle_get_nf_instances(nf_type, limit_item, http_code, 1);
std::vector<std::string> uris = {};
ProblemDetails problem_details = {};
m_nrf_app->handle_get_nf_instances(nf_type, uris, limit_item, http_code, 1, problem_details);
nlohmann::json json_data = { };
//to_json(json_data, nf_profile);
//response.send(Pistache::Http::Code::Ok, json_data.dump().c_str());
nlohmann::json json_data = {};
//TODO: std::string content_type = "application/3gppHal+json";
std::string content_type = "application/json";
if (http_code != HTTP_STATUS_CODE_200_OK) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
} else {
// convert URIs to Json
json_data["_links"]["item"] = nlohmann::json::array();
json_data["_links"]["self"] = "";
for (auto u : uris) {
nlohmann::json json_item = {};
json_item["href"] = u;
json_data["_links"]["item"].push_back(json_item);
}
}
Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());
// content type
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void NFInstancesStoreApiImpl::options_nf_instances(
Pistache::Http::ResponseWriter &response) {
......
......@@ -235,16 +235,27 @@ void nrf_app::handle_update_nf_instance(
}
//------------------------------------------------------------------------------
void nrf_app::handle_get_nf_instances(const std::string &nf_type,
const uint32_t &limit_item,
int &http_code,
const uint8_t http_version) {
void nrf_app::handle_get_nf_instances(
const std::string &nf_type, std::vector<std::string> &uris,
const uint32_t &limit_item, int &http_code, const uint8_t http_version,
oai::nrf::model::ProblemDetails &problem_details) {
Logger::nrf_app().info(
"Handle Retrieve a collection of NF Instances (HTTP version %d)",
http_version);
// TODO: verify if the NF Service Consumer is allowed to retrieve the
// registered NF instances
std::vector<std::shared_ptr<nrf_profile>> profiles = {};
nf_type_t type = api_conv::string_to_nf_type(nf_type);
if (type == NF_TYPE_UNKNOWN) {
Logger::nrf_app().debug("Unknown requested nf_type: %s", nf_type.c_str());
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
problem_details.setCause(
protocol_application_error_e2str[MANDATORY_IE_INCORRECT]);
return;
}
http_code = HTTP_STATUS_CODE_200_OK;
find_nf_profiles(type, profiles);
if (profiles.size() == 0) {
......@@ -252,6 +263,13 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
}
for (auto profile : profiles) {
std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" +
std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE +
nrf_cfg.sbi_api_version + NNRF_NFM_NF_INSTANCE +
profile.get()->get_nf_instance_id();
uris.push_back(instance_uri);
profile.get()->display();
}
}
......
......@@ -76,14 +76,19 @@ class nrf_app {
/*
* Handle a Get NF Instance Information
* @param [const std::string &] nf_type: NF's type
* @param [std::vector<std::string> &] uris: List of registered NFs in the NRF
* that satisfy the retrieval filter
* criteria
* @param [const uint32_t &] limit_item: Maximum number of items returned
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void handle_get_nf_instances(const std::string &nf_type,
const uint32_t &limit_item, int &http_code,
const uint8_t http_version);
void handle_get_nf_instances(
const std::string &nf_type, std::vector<std::string> &uris,
const uint32_t &limit_item, int &http_code, const uint8_t http_version,
oai::nrf::model::ProblemDetails &problem_details);
/*
* Handle a Update NF Instance request
......@@ -163,9 +168,9 @@ class nrf_app {
* @return void
*/
void handle_update_subscription(const std::string &sub_id,
const std::vector<PatchItem> &patchItem,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details);
const std::vector<PatchItem> &patchItem,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details);
/*
* Insert a nrf profile
......@@ -236,7 +241,8 @@ class nrf_app {
/*
* Add a subscription
* @param [const std::string &] sub_id: Subscription ID
* @param [std::shared_ptr<nrf_subscription> &] s: shared_pointer to the subscription to be added
* @param [std::shared_ptr<nrf_subscription> &] s: shared_pointer to the
* subscription to be added
* @return true if successful, otherwise, return false
*/
bool add_subscription(const std::string &sub_id,
......@@ -273,7 +279,8 @@ class nrf_app {
/*
* Verify whether a subscription is authorized
* @param [std::shared_ptr<nrf_subscription> &] s: shared_pointer to the subscription
* @param [std::shared_ptr<nrf_subscription> &] s: shared_pointer to the
* subscription
* @return true if this sub is authorized, otherwise, return false
*/
bool authorize_subscription(const std::shared_ptr<nrf_subscription> &s) const;
......@@ -345,7 +352,8 @@ class nrf_app {
* Get the list of subscriptions to the profile with notification type
* @param [const std::string &] profile_id: Profile ID of the NF
* @param [const uint8_t &] notification_type: requested notification type
* @param [std::vector<std::string> &] uris: vector stores list of uri of subscribed NFs
* @param [std::vector<std::string> &] uris: vector stores list of uri of
* subscribed NFs
* @return void
*/
void get_subscription_list(const std::string &profile_id,
......
......@@ -112,11 +112,12 @@ void nrf_client::notify_subscribed_event(
// Fill the json part
nlohmann::json json_data = {};
json_data["event"] = notification_event_type_e2str[event_type];
std::vector<struct in_addr> instance_addrs = {};
profile.get()->get_nf_ipv4_addresses(instance_addrs);
//TODO: use the first IPv4 addr for now
std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" +
std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE +
nrf_cfg.sbi_api_version + NNRF_NFM_NF_INSTANCE +
profile.get()->get_nf_instance_id();
std::string(inet_ntoa(*((struct in_addr *)&(instance_addrs[0]))));
Logger::nrf_app().debug("NF instance URI: %s", instance_uri.c_str());
json_data["nfInstanceUri"] = instance_uri;
......@@ -228,11 +229,18 @@ void nrf_client::notify_subscribed_event(
// Fill the json part
nlohmann::json json_data = {};
json_data["event"] = "NF_REGISTERED";
/*
std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" +
std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE +
nrf_cfg.sbi_api_version + NNRF_NFM_NF_INSTANCE +
profile.get()->get_nf_instance_id();
*/
std::vector<struct in_addr> instance_addrs = {};
profile.get()->get_nf_ipv4_addresses(instance_addrs);
//TODO: use the first IPv4 addr for now
std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&(instance_addrs[0]))));
Logger::nrf_app().debug("NF instance URI: %s", instance_uri.c_str());
json_data["nfInstanceUri"] = instance_uri;
std::string body = json_data.dump();
......
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