Commit 17550447 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

code cleanup

parent db6b092a
This diff is collapsed.
......@@ -43,7 +43,6 @@ namespace spgwu {
#define TASK_SPGWU_NRF_TIMEOUT_NRF_HEARTBEAT (1)
#define TASK_SPGWU_NRF_TIMEOUT_NRF_DEREGISTRATION (2)
class spgwu_nrf {
private:
std::thread::id thread_id;
......@@ -55,40 +54,30 @@ class spgwu_nrf {
public:
spgwu_nrf();
spgwu_nrf(spgwu_nrf const &) = delete;
void operator=(spgwu_nrf const &) = delete;
spgwu_nrf(spgwu_nrf const&) = delete;
void operator=(spgwu_nrf const&) = delete;
/*
* Send NF instance registration to NRF
* @param [std::shared_ptr<itti_nrf_register_nf_instance_request>] msg:
* Content of message to be sent
* @param [std::string &] url: NRF's URL
* @return void
*/
void register_nf_instance(
std::shared_ptr<itti_nrf_register_nf_instance_request> msg);
void send_register_nf_instance(std::string &url);
void send_update_nf_instance(std::string &url, nlohmann::json &data);
void send_register_nf_instance(std::string& url);
/*
* Send NF instance update to NRF
* @param [std::shared_ptr<itti_nrf_update_nf_instance_request>] msg: Content
* of message to be sent
* Send NF instance registration to NRF
* @param [std::string &] url: NRF's URL
* @param [nlohmann::json &] data: Json data to be sent
* @return void
*/
void send_update_nf_instance(std::string& url, nlohmann::json& data);
/*
* Send NF deregister to NRF
* @param [std::shared_ptr<itti_nrf_deregister_nf_instance>] msg: Content
* of message to be sent
* @param [std::string &] url: NRF's URL
* @return void
*/
void deregister_nf_instance(
std::shared_ptr<itti_nrf_deregister_nf_instance> msg);
void send_deregister_nf_instance(std::string& url);
/*
* Trigger NF instance registration to NRF
......@@ -98,32 +87,26 @@ class spgwu_nrf {
void register_to_nrf();
/*
* Generate a random UUID for SMF instance
* Generate a random UUID for UPF instance
* @param [void]
* @return void
*/
void generate_uuid();
/*
* Generate a SMF profile for this instance
* Generate a UPF profile for this instance
* @param [void]
* @return void
*/
void generate_upf_profile();
/*
* Send request to N11 task to trigger NF instance registration to NRF
* @param [void]
* @return void
*/
void trigger_nf_registration_request();
/*
* Send request to N11 task to trigger NF instance deregistration to NRF
* @param [void]
* will be executed when NRF Heartbeat timer expires
* @param [timer_id_t] timer_id
* @param [uint64_t] arg2_user
* @return void
*/
void trigger_nf_deregistration();
void timer_nrf_heartbeat_timeout(timer_id_t timer_id, uint64_t arg2_user);
/*
* will be executed when NRF Heartbeat timer expires
......@@ -131,9 +114,7 @@ class spgwu_nrf {
* @param [uint64_t] arg2_user
* @return void
*/
void timer_nrf_heartbeat_timeout(timer_id_t timer_id, uint64_t arg2_user);
void timer_nrf_deregistration(timer_id_t timer_id, uint64_t arg2_user);
};
} // namespace smf
} // namespace spgwu
#endif /* FILE_SPGWU_NRF_HPP_SEEN */
......@@ -38,25 +38,27 @@ using namespace std;
using namespace spgwu;
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_instance_id(const std::string &instance_id) {
void spgwu_profile::set_nf_instance_id(const std::string& instance_id) {
nf_instance_id = instance_id;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_instance_id(std::string &instance_id) const {
void spgwu_profile::get_nf_instance_id(std::string& instance_id) const {
instance_id = nf_instance_id;
}
//------------------------------------------------------------------------------
std::string spgwu_profile::get_nf_instance_id() const { return nf_instance_id; }
std::string spgwu_profile::get_nf_instance_id() const {
return nf_instance_id;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_instance_name(const std::string &instance_name) {
void spgwu_profile::set_nf_instance_name(const std::string& instance_name) {
nf_instance_name = instance_name;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_instance_name(std::string &instance_name) const {
void spgwu_profile::get_nf_instance_name(std::string& instance_name) const {
instance_name = nf_instance_name;
}
......@@ -66,90 +68,118 @@ std::string spgwu_profile::get_nf_instance_name() const {
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_type(const std::string &type) { nf_type = type; }
void spgwu_profile::set_nf_type(const std::string& type) {
nf_type = type;
}
//------------------------------------------------------------------------------
std::string spgwu_profile::get_nf_type() const { return nf_type; }
std::string spgwu_profile::get_nf_type() const {
return nf_type;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_status(const std::string &status) {
void spgwu_profile::set_nf_status(const std::string& status) {
nf_status = status;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_status(std::string &status) const {
void spgwu_profile::get_nf_status(std::string& status) const {
status = nf_status;
}
//------------------------------------------------------------------------------
std::string spgwu_profile::get_nf_status() const { return nf_status; }
std::string spgwu_profile::get_nf_status() const {
return nf_status;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_heartBeat_timer(const int32_t &timer) {
void spgwu_profile::set_nf_heartBeat_timer(const int32_t& timer) {
heartBeat_timer = timer;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_heartBeat_timer(int32_t &timer) const {
void spgwu_profile::get_nf_heartBeat_timer(int32_t& timer) const {
timer = heartBeat_timer;
}
//------------------------------------------------------------------------------
int32_t spgwu_profile::get_nf_heartBeat_timer() const { return heartBeat_timer; }
int32_t spgwu_profile::get_nf_heartBeat_timer() const {
return heartBeat_timer;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_priority(const uint16_t &p) { priority = p; }
void spgwu_profile::set_nf_priority(const uint16_t& p) {
priority = p;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_priority(uint16_t &p) const { p = priority; }
void spgwu_profile::get_nf_priority(uint16_t& p) const {
p = priority;
}
//------------------------------------------------------------------------------
uint16_t spgwu_profile::get_nf_priority() const { return priority; }
uint16_t spgwu_profile::get_nf_priority() const {
return priority;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_capacity(const uint16_t &c) { capacity = c; }
void spgwu_profile::set_nf_capacity(const uint16_t& c) {
capacity = c;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_capacity(uint16_t &c) const { c = capacity; }
void spgwu_profile::get_nf_capacity(uint16_t& c) const {
c = capacity;
}
//------------------------------------------------------------------------------
uint16_t spgwu_profile::get_nf_capacity() const { return capacity; }
uint16_t spgwu_profile::get_nf_capacity() const {
return capacity;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_snssais(const std::vector<snssai_t> &s) {
void spgwu_profile::set_nf_snssais(const std::vector<snssai_t>& s) {
snssais = s;
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_snssais(std::vector<snssai_t> &s) const {
void spgwu_profile::get_nf_snssais(std::vector<snssai_t>& s) const {
s = snssais;
}
//------------------------------------------------------------------------------
void spgwu_profile::add_snssai(const snssai_t &s) { snssais.push_back(s); }
void spgwu_profile::add_snssai(const snssai_t& s) {
snssais.push_back(s);
}
//------------------------------------------------------------------------------
void spgwu_profile::set_nf_ipv4_addresses(const std::vector<struct in_addr> &a) {
void spgwu_profile::set_nf_ipv4_addresses(
const std::vector<struct in_addr>& a) {
ipv4_addresses = a;
}
//------------------------------------------------------------------------------
void spgwu_profile::add_nf_ipv4_addresses(const struct in_addr &a) {
void spgwu_profile::add_nf_ipv4_addresses(const struct in_addr& a) {
ipv4_addresses.push_back(a);
}
//------------------------------------------------------------------------------
void spgwu_profile::get_nf_ipv4_addresses(std::vector<struct in_addr> &a) const {
void spgwu_profile::get_nf_ipv4_addresses(
std::vector<struct in_addr>& a) const {
a = ipv4_addresses;
}
//------------------------------------------------------------------------------
void spgwu_profile::set_upf_info(const upf_info_t &s) { upf_info = s; }
void spgwu_profile::set_upf_info(const upf_info_t& s) {
upf_info = s;
}
//------------------------------------------------------------------------------
void spgwu_profile::add_upf_info_item(const snssai_upf_info_item_t &s) {
void spgwu_profile::add_upf_info_item(const snssai_upf_info_item_t& s) {
upf_info.snssai_upf_info_list.push_back(s);
}
//------------------------------------------------------------------------------
void spgwu_profile::get_upf_info(upf_info_t &s) const { s = upf_info; }
void spgwu_profile::get_upf_info(upf_info_t& s) const {
s = upf_info;
}
//------------------------------------------------------------------------------
void spgwu_profile::display() const {
......@@ -185,8 +215,8 @@ void spgwu_profile::display() const {
}
for (auto s : upf_info.snssai_upf_info_list) {
Logger::spgwu_app().debug("\t\tParameters supported by the UPF:");
Logger::spgwu_app().debug("\t\t\tSNSSAI (SST %d, SD %s)", s.snssai.sST,
s.snssai.sD.c_str());
Logger::spgwu_app().debug(
"\t\t\tSNSSAI (SST %d, SD %s)", s.snssai.sST, s.snssai.sD.c_str());
for (auto d : s.dnn_upf_info_list) {
Logger::spgwu_app().debug("\t\t\tDNN %s", d.dnn.c_str());
}
......@@ -194,7 +224,7 @@ void spgwu_profile::display() const {
}
//------------------------------------------------------------------------------
void spgwu_profile::to_json(nlohmann::json &data) const {
void spgwu_profile::to_json(nlohmann::json& data) const {
data["nfInstanceId"] = nf_instance_id;
data["nfInstanceName"] = nf_instance_name;
data["nfType"] = nf_type;
......@@ -239,7 +269,7 @@ void spgwu_profile::to_json(nlohmann::json &data) const {
}
//------------------------------------------------------------------------------
void spgwu_profile::from_json(const nlohmann::json &data) {
void spgwu_profile::from_json(const nlohmann::json& data) {
if (data.find("nfInstanceId") != data.end()) {
nf_instance_id = data["nfInstanceId"].get<std::string>();
}
......@@ -281,8 +311,8 @@ void spgwu_profile::from_json(const nlohmann::json &data) {
if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) {
memcpy(&addr4, buf_in_addr, sizeof(struct in_addr));
} else {
Logger::spgwu_app().warn("Address conversion: Bad value %s",
util::trim(address).c_str());
Logger::spgwu_app().warn(
"Address conversion: Bad value %s", util::trim(address).c_str());
}
// Logger::spgwu_app().debug("\tIPv4 Addr: %s", address.c_str());
add_nf_ipv4_addresses(addr4);
......@@ -333,7 +363,8 @@ void spgwu_profile::from_json(const nlohmann::json &data) {
//------------------------------------------------------------------------------
void spgwu_profile::handle_heartbeart_timeout(uint64_t ms) {
Logger::spgwu_app().info("Handle heartbeart timeout profile %s, time %d",
nf_instance_id.c_str(), ms);
Logger::spgwu_app().info(
"Handle heartbeart timeout profile %s, time %d", nf_instance_id.c_str(),
ms);
set_nf_status("SUSPENDED");
}
......@@ -44,7 +44,7 @@
namespace spgwu {
//using namespace std;
// using namespace std;
class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
public:
......@@ -59,7 +59,7 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
nf_status = "";
}
spgwu_profile(const std::string &id)
spgwu_profile(const std::string& id)
: nf_instance_id(id),
heartBeat_timer(0),
snssais(),
......@@ -71,7 +71,7 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
nf_status = "";
}
spgwu_profile &operator=(const spgwu_profile &s) {
spgwu_profile& operator=(const spgwu_profile& s) {
nf_instance_id = s.nf_instance_id;
heartBeat_timer = s.heartBeat_timer;
snssais = s.snssais;
......@@ -94,13 +94,13 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [const std::string &] instance_id: instance id
* @return void
*/
void set_nf_instance_id(const std::string &instance_id);
void set_nf_instance_id(const std::string& instance_id);
/*
* Get NF instance ID
* @param [std::string &] instance_id: store instance id
* @return void:
*/
void get_nf_instance_id(std::string &instance_id) const;
void get_nf_instance_id(std::string& instance_id) const;
/*
* Get NF instance ID
......@@ -114,14 +114,14 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [const std::string &] instance_name: instance name
* @return void
*/
void set_nf_instance_name(const std::string &instance_name);
void set_nf_instance_name(const std::string& instance_name);
/*
* Get NF instance ID
* @param [std::string &] instance_name: store instance name
* @return void:
*/
void get_nf_instance_name(std::string &instance_name) const;
void get_nf_instance_name(std::string& instance_name) const;
/*
* Get NF instance name
......@@ -135,14 +135,14 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [const std::string &] status: instance status
* @return void
*/
void set_nf_status(const std::string &status);
void set_nf_status(const std::string& status);
/*
* Get NF instance status
* @param [std::string &] status: store instance status
* @return void:
*/
void get_nf_status(std::string &status) const;
void get_nf_status(std::string& status) const;
/*
* Get NF status
......@@ -163,21 +163,21 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [const nf_type_t &] type: nf type
* @return void
*/
void set_nf_type(const std::string &type);
void set_nf_type(const std::string& type);
/*
* Set NF instance heartBeat_timer
* @param [const std::string &] timer: heartBeat_timer
* @return void
*/
void set_nf_heartBeat_timer(const int32_t &timer);
void set_nf_heartBeat_timer(const int32_t& timer);
/*
* Get NF instance heartBeat_timer
* @param [std::string &] timer: store heartBeat_timer
* @return void:
*/
void get_nf_heartBeat_timer(int32_t &timer) const;
void get_nf_heartBeat_timer(int32_t& timer) const;
/*
* Get NF heartBeat_timer
......@@ -191,14 +191,14 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [const uint16_t] p: instance priority
* @return void
*/
void set_nf_priority(const uint16_t &p);
void set_nf_priority(const uint16_t& p);
/*
* Get NF instance priority
* @param [uint16_t] p: store instance priority
* @return void:
*/
void get_nf_priority(uint16_t &p) const;
void get_nf_priority(uint16_t& p) const;
/*
* Get NF instance priority
......@@ -212,14 +212,14 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [const uint16_t] c: instance capacity
* @return void
*/
void set_nf_capacity(const uint16_t &c);
void set_nf_capacity(const uint16_t& c);
/*
* Get NF instance priority
* @param [uint16_t ] c: store instance capacity
* @return void:
*/
void get_nf_capacity(uint16_t &c) const;
void get_nf_capacity(uint16_t& c) const;
/*
* Get NF instance priority
......@@ -233,63 +233,63 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [std::vector<snssai_t> &] s: SNSSAIs
* @return void
*/
void set_nf_snssais(const std::vector<snssai_t> &s);
void set_nf_snssais(const std::vector<snssai_t>& s);
/*
* Add SNSSAI
* @param [snssai_t &] s: SNSSAI
* @return void
*/
void add_snssai(const snssai_t &s);
void add_snssai(const snssai_t& s);
/*
* Get NF instance SNSSAIs
* @param [std::vector<snssai_t> &] s: store instance's SNSSAIs
* @return void:
*/
void get_nf_snssais(std::vector<snssai_t> &s) const;
void get_nf_snssais(std::vector<snssai_t>& s) const;
/*
* Set NF instance ipv4_addresses
* @param [std::vector<struct in_addr> &] a: ipv4_addresses
* @return void
*/
void set_nf_ipv4_addresses(const std::vector<struct in_addr> &a);
void set_nf_ipv4_addresses(const std::vector<struct in_addr>& a);
/*
* Add an IPv4 address to the list of addresses
* @param [const struct in_addr &] a: ipv4_address
* @return void
*/
void add_nf_ipv4_addresses(const struct in_addr &a);
void add_nf_ipv4_addresses(const struct in_addr& a);
/*
* Get NF instance ipv4_addresses
* @param [std::vector<struct in_addr> &] a: store instance's ipv4_addresses
* @return void:
*/
void get_nf_ipv4_addresses(std::vector<struct in_addr> &a) const;
void get_nf_ipv4_addresses(std::vector<struct in_addr>& a) const;
/*
* Set upf info
* @param [upf_info_t &] s: upf info
* @return void
*/
void set_upf_info(const upf_info_t &s);
void set_upf_info(const upf_info_t& s);
/*
* Add an snssai_upf_info_item to the upf info
* @param [const snssai_upf_info_item_t &] s: snssai_smf_info_item
* @return void
*/
void add_upf_info_item(const snssai_upf_info_item_t &s);
void add_upf_info_item(const snssai_upf_info_item_t& s);
/*
* Get NF instance smf info
* @param [smf_info_t &] s: store instance's smf info
* @return void:
*/
void get_upf_info(upf_info_t &s) const;
void get_upf_info(upf_info_t& s) const;
/*
* Print related-information for NF profile
......@@ -303,14 +303,14 @@ class spgwu_profile : public std::enable_shared_from_this<spgwu_profile> {
* @param [nlohmann::json &] data: Json data
* @return void
*/
void to_json(nlohmann::json &data) const;
void to_json(nlohmann::json& data) const;
/*
* Covert from a json represetation to SMF profile
* @param [nlohmann::json &] data: Json data
* @return void
*/
void from_json(const nlohmann::json &data);
void from_json(const nlohmann::json& data);
/*
* Handle heartbeart timeout event
......
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