Commit f813c1ee authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Code cleanup/format

parent f3d2068d
......@@ -115,7 +115,7 @@ void nrf_client::notify_subscribed_event(
std::vector<struct in_addr> instance_addrs = {};
profile.get()->get_nf_ipv4_addresses(instance_addrs);
//TODO: use the first IPv4 addr for now
// 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());
......@@ -238,7 +238,7 @@ void nrf_client::notify_subscribed_event(
*/
std::vector<struct in_addr> instance_addrs = {};
profile.get()->get_nf_ipv4_addresses(instance_addrs);
//TODO: use the first IPv4 addr for now
// 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());
......
......@@ -63,7 +63,7 @@ class nrf_client {
* @return void
*/
void notify_subscribed_event(const std::shared_ptr<nrf_profile> &profile,
const uint8_t &event_type,
const uint8_t &event_type,
const std::vector<std::string> &uris);
/*
......
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -62,7 +62,7 @@ int nrf_config::load_interface(const Setting &if_cfg, interface_cfg_t &cfg) {
if_cfg.lookupValue(NRF_CONFIG_STRING_INTERFACE_NAME, cfg.if_name);
util::trim(cfg.if_name);
if (not boost::iequals(cfg.if_name, "none")) {
std::string address = { };
std::string address = {};
if_cfg.lookupValue(NRF_CONFIG_STRING_IPV4_ADDRESS, address);
util::trim(address);
if (boost::iequals(address, "read")) {
......@@ -70,36 +70,36 @@ int nrf_config::load_interface(const Setting &if_cfg, interface_cfg_t &cfg) {
cfg.mtu)) {
Logger::nrf_app().error(
"Could not read %s network interface configuration", cfg.if_name);
return RETURNerror ;
return RETURNerror;
}
} else {
std::vector < std::string > words;
std::vector<std::string> words;
boost::split(words, address, boost::is_any_of("/"),
boost::token_compress_on);
if (words.size() != 2) {
Logger::nrf_app().error(
"Bad value " NRF_CONFIG_STRING_IPV4_ADDRESS " = %s in config file",
address.c_str());
return RETURNerror ;
Logger::nrf_app().error("Bad value " NRF_CONFIG_STRING_IPV4_ADDRESS
" = %s in config file",
address.c_str());
return RETURNerror;
}
unsigned char buf_in_addr[sizeof(struct in6_addr)];
if (inet_pton(AF_INET, util::trim(words.at(0)).c_str(), buf_in_addr)
== 1) {
if (inet_pton(AF_INET, util::trim(words.at(0)).c_str(), buf_in_addr) ==
1) {
memcpy(&cfg.addr4, buf_in_addr, sizeof(struct in_addr));
} else {
Logger::nrf_app().error(
"In conversion: Bad value " NRF_CONFIG_STRING_IPV4_ADDRESS " = %s in config file",
"In conversion: Bad value " NRF_CONFIG_STRING_IPV4_ADDRESS
" = %s in config file",
util::trim(words.at(0)).c_str());
return RETURNerror ;
return RETURNerror;
}
cfg.network4.s_addr = htons(
ntohs(cfg.addr4.s_addr)
& 0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1)))));
cfg.network4.s_addr =
htons(ntohs(cfg.addr4.s_addr) &
0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1)))));
}
if_cfg.lookupValue(NRF_CONFIG_STRING_PORT, cfg.port);
}
return RETURNok ;
return RETURNok;
}
//------------------------------------------------------------------------------
......@@ -126,7 +126,7 @@ int nrf_config::load(const string &config_file) {
const Setting &nrf_cfg = root[NRF_CONFIG_STRING_NRF_CONFIG];
} catch (const SettingNotFoundException &nfex) {
Logger::nrf_app().error("%s : %s", nfex.what(), nfex.getPath());
return RETURNerror ;
return RETURNerror;
}
const Setting &nrf_cfg = root[NRF_CONFIG_STRING_NRF_CONFIG];
......@@ -146,25 +146,26 @@ int nrf_config::load(const string &config_file) {
}
try {
const Setting &sbi_cfg = nrf_cfg[NRF_CONFIG_STRING_INTERFACE_SBI];
load_interface(sbi_cfg, sbi);
//HTTP2 port
if (!(sbi_cfg.lookupValue(NRF_CONFIG_STRING_SBI_HTTP2_PORT, sbi_http2_port))) {
// HTTP2 port
if (!(sbi_cfg.lookupValue(NRF_CONFIG_STRING_SBI_HTTP2_PORT,
sbi_http2_port))) {
Logger::nrf_app().error(NRF_CONFIG_STRING_SBI_HTTP2_PORT "failed");
throw(NRF_CONFIG_STRING_SBI_HTTP2_PORT "failed");
}
//SBI API VERSION
if (!(sbi_cfg.lookupValue(NRF_CONFIG_STRING_API_VERSION, sbi_api_version))) {
// SBI API VERSION
if (!(sbi_cfg.lookupValue(NRF_CONFIG_STRING_API_VERSION,
sbi_api_version))) {
Logger::nrf_app().error(NRF_CONFIG_STRING_API_VERSION "failed");
throw(NRF_CONFIG_STRING_API_VERSION "failed");
}
} catch (const SettingNotFoundException &nfex) {
Logger::nrf_app().error("%s : %s", nfex.what(), nfex.getPath());
return RETURNerror ;
return RETURNerror;
}
return true;
......@@ -185,10 +186,7 @@ void nrf_config::display() {
Logger::nrf_app().info(" HTTP2 port ..........: %d", sbi_http2_port);
Logger::nrf_app().info(" API version..........: %s",
sbi_api_version.c_str());
}
//------------------------------------------------------------------------------
nrf_config::~nrf_config() {
}
nrf_config::~nrf_config() {}
......@@ -73,6 +73,7 @@ void nrf_profile::set_nf_type(const nf_type_t &type) { nf_type = type; }
//------------------------------------------------------------------------------
nf_type_t nrf_profile::get_nf_type() const { return nf_type; }
//------------------------------------------------------------------------------
void nrf_profile::set_nf_status(const std::string &status) {
std::unique_lock lock(heartbeart_mutex);
......@@ -130,6 +131,7 @@ void nrf_profile::get_nf_snssais(std::vector<snssai_t> &s) const {
//------------------------------------------------------------------------------
void nrf_profile::add_snssai(const snssai_t &s) { snssais.push_back(s); }
//------------------------------------------------------------------------------
void nrf_profile::set_nf_ipv4_addresses(const std::vector<struct in_addr> &a) {
ipv4_addresses = a;
......@@ -157,9 +159,7 @@ void nrf_profile::get_json_data(nlohmann::json &data) const {
//------------------------------------------------------------------------------
void nrf_profile::display() {
Logger::nrf_app().debug("NF instance info");
Logger::nrf_app().debug("\tInstance ID: %s", nf_instance_id.c_str());
Logger::nrf_app().debug("\tInstance name: %s", nf_instance_name.c_str());
Logger::nrf_app().debug("\tInstance type: %s",
nf_type_e2str[nf_type].c_str());
......@@ -419,7 +419,6 @@ void nrf_profile::to_json(nlohmann::json &data) const {
nlohmann::json tmp = inet_ntoa(address);
data["ipv4Addresses"].push_back(tmp);
}
data["priority"] = priority;
data["capacity"] = capacity;
data["json_data"] = json_data;
......@@ -496,18 +495,23 @@ bool nrf_profile::unsubscribe_heartbeat_timeout_nfregistration() {
//------------------------------------------------------------------------------
void nrf_profile::handle_heartbeart_timeout(uint64_t ms) {
Logger::nrf_app().info("\nHandle heartbeart timeout profile %s, time %d",
nf_instance_id.c_str(), ms);
Logger::nrf_app().info(
"\nHandle heartbeart timeout, NF instance ID %s, time %d",
nf_instance_id.c_str(), ms);
set_nf_status("SUSPENDED");
}
//------------------------------------------------------------------------------
void nrf_profile::handle_heartbeart_timeout_nfregistration(uint64_t ms) {
Logger::nrf_app().info(
"\nHandle the first Heartbeat timeout NF instance id %s, current time %d",
"\nHandle the first Heartbeat timeout, NF instance ID %s, current time "
"%d",
nf_instance_id.c_str(), ms);
// Set status to SUSPENDED and unsubscribe to the HBT
set_nf_status("SUSPENDED");
if (!is_updated) {
set_nf_status("SUSPENDED");
set_status_updated(false);
}
unsubscribe_heartbeat_timeout_nfregistration();
}
......@@ -517,7 +521,8 @@ void nrf_profile::handle_heartbeart_timeout_nfupdate(uint64_t ms) {
std::chrono::system_clock::now().time_since_epoch())
.count();
Logger::nrf_app().info(
"\nHandle heartbeart timeout (NF update) profile %s, time %ld, current "
"\nHandle heartbeart timeout (NF update), NF instance ID %s, time %ld, "
"current "
"ms %ld",
nf_instance_id.c_str(), ms, current_ms);
if (!is_updated) {
......@@ -547,8 +552,7 @@ void amf_profile::display() {
amf_info.amf_region_id.c_str());
for (auto g : amf_info.guami_list) {
Logger::nrf_app().debug("\t\tAMF GUAMI List, AMF_ID: %s",
g.amf_id.c_str());
Logger::nrf_app().debug("\t\tAMF GUAMI List, AMF_ID: %s", g.amf_id.c_str());
Logger::nrf_app().debug("\t\tAMF GUAMI List, PLMN (MCC: %s, MNC: %s)",
g.plmn.mcc.c_str(), g.plmn.mnc.c_str());
}
......@@ -561,7 +565,7 @@ bool amf_profile::replace_profile_info(const std::string &path,
if (result) return true;
// for AMF info
if (path.compare("amfInfo") == 0) {
Logger::nrf_app().debug("Does not support this operation for amfInfo");
Logger::nrf_app().debug("Do not support this operation for amfInfo");
return false;
}
......@@ -588,7 +592,7 @@ bool amf_profile::add_profile_info(const std::string &path,
// add an element to a list of json object
if (path.compare("amfInfo") == 0) {
Logger::nrf_app().info("Does not support this operation for amfInfo");
Logger::nrf_app().info("Do not support this operation for amfInfo");
return false;
}
......@@ -615,7 +619,7 @@ bool amf_profile::remove_profile_info(const std::string &path) {
if (result) return true;
// for AMF info
if (path.compare("amfInfo") == 0) {
Logger::nrf_app().debug("Does not support this operation for amfInfo");
Logger::nrf_app().debug("Do not support this operation for amfInfo");
return false;
}
......@@ -660,9 +664,7 @@ void smf_profile::get_smf_info(smf_info_t &infos) const { infos = smf_info; }
//------------------------------------------------------------------------------
void smf_profile::display() {
nrf_profile::display();
Logger::nrf_app().debug("............SMF Info");
for (auto s : smf_info.snssai_smf_info_list) {
Logger::nrf_app().debug(
"....................SNSSAI SMF Info List, SNSSAI (SD: %s, SST: %d)",
......@@ -700,7 +702,6 @@ bool smf_profile::add_profile_info(const std::string &path,
json_data[path] = value;
return true;
}
return false;
}
......@@ -736,7 +737,7 @@ bool smf_profile::remove_profile_info(const std::string &path) {
if (result) return true;
// for SMF info
if (path.compare("smfInfo") == 0) {
Logger::nrf_app().debug("Does not support this operation for smfInfo");
Logger::nrf_app().debug("Do not support this operation for smfInfo");
return false;
}
......
......@@ -60,7 +60,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
ipv4_addresses(),
priority(0),
capacity(0),
heartbeart_mutex(){
heartbeart_mutex() {
nf_instance_name = "";
nf_status = "";
json_data = {};
......@@ -75,7 +75,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
ipv4_addresses(),
priority(0),
capacity(0),
heartbeart_mutex(){
heartbeart_mutex() {
nf_instance_name = "";
nf_status = "";
json_data = {};
......@@ -92,7 +92,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
priority(0),
capacity(0),
nf_type(NF_TYPE_UNKNOWN),
heartbeart_mutex(){
heartbeart_mutex() {
nf_instance_name = "";
nf_status = "";
json_data = {};
......@@ -344,30 +344,54 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
virtual void to_json(nlohmann::json &data) const;
/*
* Subscribe to task tick to be notified (every Interval period)
* Subscribe to the HBT timeout event (after receiving NF Update)
* @param [uint64_t] ms: current time
* @return void
*/
void subscribe_heartbeat_timeout_nfupdate(uint64_t ms);
/*
* Subscribe to the HBT timeout event (after receiving NF Registration)
* @param [uint64_t] ms: current time
* @return void
*/
void subscribe_heartbeat_timeout_nfregistration(uint64_t ms);
/*
* Handle heartbeart timeout event
* @param [uint64_t] ms: current time
* @return void
*/
void handle_heartbeart_timeout(uint64_t ms);
/*
* Handle heartbeart timeout event after NF Registration
* @param [uint64_t] ms: current time
* @return void
*/
void handle_heartbeart_timeout_nfregistration(uint64_t ms);
/*
* Handle heartbeart timeout event after NF Update
* @param [uint64_t] ms: current time
* @return void
*/
void handle_heartbeart_timeout_nfupdate(uint64_t ms);
/*
* Unubscribe to task tick event
* Unubscribe to HBT event (after NF Registration)
* @param void
* @return void
*/
bool unsubscribe_heartbeat_timeout_nfupdate();
bool unsubscribe_heartbeat_timeout_nfregistration();
/*
* Unubscribe to HBT event (after NF Update)
* @param void
* @return void
*/
bool unsubscribe_heartbeat_timeout_nfupdate();
/*
* Set status updated to true
* @param void
......@@ -377,11 +401,14 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
protected:
nrf_event &m_event_sub;
bs2::connection task_connection; //connection for the task tick for heartbeart
bs2::connection first_hb_connection; //connection for the first heartbearttimer
bs2::connection
task_connection; // connection for the HBT timeout (after NF Update)
bs2::connection first_hb_connection; // connection for first HBT timeout
// (after NF Registration)
bool first_update;
bool is_updated;
mutable std::shared_mutex heartbeart_mutex;
// From NFProfile (Section 6.1.6.2.2@3GPP TS 29.510 V16.0.0 (2019-06))
std::string nf_instance_id;
std::string nf_instance_name;
......@@ -473,6 +500,7 @@ class amf_profile : public nrf_profile {
amf_profile(amf_profile &b) = delete;
~amf_profile() {}
/*
* Add an AMF info
* @param [const amf_info_t &] info: AMF info
......@@ -554,7 +582,6 @@ class smf_profile : public nrf_profile {
*/
void get_smf_info(smf_info_t &infos) const;
/*
* Print related-information for a SMF profile
* @param void
......
......@@ -36,19 +36,13 @@
using namespace oai::nrf::app;
//------------------------------------------------------------------------------
void nrf_search_result::set_search_id(const std::string &id) {
search_id = id;
}
void nrf_search_result::set_search_id(const std::string &id) { search_id = id; }
//------------------------------------------------------------------------------
void nrf_search_result::get_search_id(std::string &id) const {
id = search_id;
}
void nrf_search_result::get_search_id(std::string &id) const { id = search_id; }
//------------------------------------------------------------------------------
std::string nrf_search_result::get_search_id() const {
return search_id;
}
std::string nrf_search_result::get_search_id() const { return search_id; }
//------------------------------------------------------------------------------
void nrf_search_result::set_nf_instances(
......@@ -69,7 +63,8 @@ void nrf_search_result::get_nf_instances(
}
//------------------------------------------------------------------------------
std::vector<std::shared_ptr<nrf_profile>> nrf_search_result::get_nf_instances() const {
std::vector<std::shared_ptr<nrf_profile>> nrf_search_result::get_nf_instances()
const {
return nf_instances;
}
......@@ -126,16 +121,17 @@ void nrf_search_result::display() {
}
//------------------------------------------------------------------------------
void nrf_search_result::to_json(nlohmann::json &data, const uint32_t &limit_nfs) const {
data = { };
void nrf_search_result::to_json(nlohmann::json &data,
const uint32_t &limit_nfs) const {
data = {};
data["validityPeriod"] = validity_period;
data["nfInstances"] = nlohmann::json::array();
uint32_t limit = limit_nfs>0?limit_nfs:nf_instances.size();
uint32_t limit = limit_nfs > 0 ? limit_nfs : nf_instances.size();
int i = 0;
for (auto instance : nf_instances) {
if (i < limit) {
nlohmann::json instance_json = { };
nlohmann::json instance_json = {};
instance.get()->to_json(instance_json);
data["nfInstances"].push_back(instance_json);
} else {
......
......@@ -42,16 +42,15 @@ using namespace std;
class nrf_search_result {
public:
nrf_search_result() {
limit_nf_instances = 10; //default value, TODO: to be removed
}
;
nrf_search_result(nrf_search_result const&) = delete;
limit_nf_instances = 10; // default value, TODO: to be removed
};
nrf_search_result(nrf_search_result const &) = delete;
virtual ~nrf_search_result() {
Logger::nrf_app().debug("Delete NRF Subscription instance...");
}
void operator=(nrf_search_result const&) = delete;
void operator=(nrf_search_result const &) = delete;
/*
* Set the search id
......@@ -145,14 +144,16 @@ class nrf_search_result {
/*
* Set the maximum number of NFProfiles to be returned in the response
* @param [const uint32_t &] l: the maximum number of NFProfiles to be returned in the response
* @param [const uint32_t &] l: the maximum number of NFProfiles to be
* returned in the response
* @return void
*/
void set_limit_nf_instances(const uint32_t &l);
/*
* Get the maximum number of NFProfiles to be returned in the response
* @param [uint32_t &] l: the maximum number of NFProfiles to be returned in the response
* @param [uint32_t &] l: the maximum number of NFProfiles to be returned in
* the response
* @return void
*/
void get_limit_nf_instances(uint32_t &l) const;
......@@ -174,8 +175,8 @@ class nrf_search_result {
/*
* Represent NF profile as json object
* @param [nlohmann::json &] data: Json data
* @param [uint32_t &] limit_nfs: maximum number of NF profiles stored in the json data
* 0, means without any restriction
* @param [uint32_t &] limit_nfs: maximum number of NF profiles stored in the
* json data 0, means without any restriction
* @return void
*/
void to_json(nlohmann::json &data, const uint32_t &limit_nfs) const;
......
......@@ -123,18 +123,18 @@ void nrf_subscription::display() {
Logger::nrf_app().debug("\tNotification URI: %s",
nf_status_notification_uri.c_str());
Logger::nrf_app().debug("\tSubscription condition: %s",
sub_condition.to_string().c_str());
sub_condition.to_string().c_str());
std::string notif_events_str = {};
for (auto n: notif_events){
notif_events_str.append(notification_event_type_e2str[n]);
notif_events_str.append(", ");
for (auto n : notif_events) {
notif_events_str.append(notification_event_type_e2str[n]);
notif_events_str.append(", ");
}
Logger::nrf_app().debug("\tNotification Events: %s",
notif_events_str.c_str());
Logger::nrf_app().debug("\tValidity time: %s",
boost::posix_time::to_iso_string(validity_time).c_str());
notif_events_str.c_str());
Logger::nrf_app().debug(
"\tValidity time: %s",
boost::posix_time::to_iso_string(validity_time).c_str());
}
//------------------------------------------------------------------------------
......
......@@ -44,10 +44,8 @@ using namespace std;
class nrf_subscription {
public:
nrf_subscription(nrf_event &ev) : m_event_sub(ev){
validity_time = boost::posix_time::from_iso_string("20991231T235959Z");
nrf_subscription(nrf_event &ev) : m_event_sub(ev) {
validity_time = boost::posix_time::from_iso_string("20991231T235959Z");
};
nrf_subscription(nrf_subscription const &) = delete;
......@@ -190,7 +188,6 @@ class nrf_subscription {
nrf_event &m_event_sub;
bs2::connection ev_connection;
boost::posix_time::ptime validity_time;
};
} // namespace app
} // namespace nrf
......
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -38,42 +38,41 @@
using namespace oai::nrf::app;
namespace oai {
namespace nrf {
namespace app {
namespace nrf {
namespace app {
class nrf_event;
class task_manager {
class nrf_event;
class task_manager {
public:
task_manager(nrf_event& ev);
public:
task_manager(nrf_event& ev);
/*
* Manage the tasks
* @param [void]
* @return void
*/
void manage_tasks();
/*
* Manage the tasks
* @param [void]
* @return void
*/
void manage_tasks();
/*
* Run the tasks (for the moment, simply call function manage_tasks)
* @param [void]
* @return void
*/
void run();
/*
* Run the tasks (for the moment, simply call function manage_tasks)
* @param [void]
* @return void
*/
void run();
private:
/*
* Make sure that the task tick run every 1ms
* @param [void]
* @return void
*/
void wait_for_cycle();
private: