Commit d7bf4cd8 authored by kharade's avatar kharade

Added retry for PFCP association request

parent a7d777ee
......@@ -63,6 +63,7 @@
#include "string.hpp"
#include "fqdn.hpp"
#include "smf_config.hpp"
#include "smf_pfcp_association.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -71,6 +72,9 @@ extern "C" {
using namespace smf;
#define PFCP_ASSOC_RETRY_COUNT 10
#define PFCP_ASSOC_RESP_WAIT 2
extern util::async_shell_cmd* async_shell_cmd_inst;
extern smf_app* smf_app_inst;
extern smf_config smf_cfg;
......@@ -367,7 +371,16 @@ void smf_app::start_nf_registration_discovery() {
// verified)
for (std::vector<pfcp::node_id_t>::const_iterator it = smf_cfg.upfs.begin();
it != smf_cfg.upfs.end(); ++it) {
start_upf_association(*it);
for (int i = 0; i < PFCP_ASSOC_RETRY_COUNT; i++) {
start_upf_association(*it);
sleep(PFCP_ASSOC_RESP_WAIT);
std::shared_ptr<pfcp_association> sa = {};
if (not pfcp_associations::get_instance().get_association(*it, sa))
Logger::smf_app().warn(
"Failed to receive PFCP Association Response, Retrying .....!!");
else
break;
}
}
}
......@@ -1412,7 +1425,17 @@ bool smf_app::handle_nf_status_notification(
smf_cfg.upfs.push_back(n);
upf_profile* upf_node_profile =
dynamic_cast<upf_profile*>(profile.get());
start_upf_association(n, std::ref(*upf_node_profile));
for (int i = 0; i < PFCP_ASSOC_RETRY_COUNT; i++) {
start_upf_association(n, std::ref(*upf_node_profile));
sleep(PFCP_ASSOC_RESP_WAIT);
std::shared_ptr<pfcp_association> sa = {};
if (not pfcp_associations::get_instance().get_association(n, sa))
Logger::smf_app().warn(
"Failed to receive PFCP Association Response, Retrying "
".....!!");
else
break;
}
} else {
Logger::smf_app().debug("No IP Addr/FQDN found");
return false;
......
......@@ -270,9 +270,29 @@ bool pfcp_associations::get_association(
std::shared_ptr<pfcp_association>& sa) const {
std::size_t hash_node_id = std::hash<pfcp::node_id_t>{}(node_id);
auto pit = associations.find((int32_t) hash_node_id);
if (pit == associations.end())
if (pit == associations.end()) {
// We didn't found association, may be because hash map is made with
// node_id_type FQDN
if (node_id.node_id_type == pfcp::NODE_ID_TYPE_IPV4_ADDRESS) {
struct hostent* hostname = gethostbyaddr(
&node_id.u1.ipv4_address.s_addr,
sizeof(node_id.u1.ipv4_address.s_addr), AF_INET);
pfcp::node_id_t node_id_tmp = {};
node_id_tmp.node_id_type = pfcp::NODE_ID_TYPE_FQDN;
node_id_tmp.fqdn = hostname->h_name;
Logger::smf_app().debug(
"Hash lookup for association retry: Associated Hostname -> %s",
hostname->h_name);
std::size_t hash_node_id = std::hash<pfcp::node_id_t>{}(node_id_tmp);
auto pit = associations.find((int32_t) hash_node_id);
if (get_association(node_id_tmp, sa)) return true;
}
// We didn't found association, may be because hash map is made with
// node_id_type IP ADDR
// ToDo (Might stuck in recursive loop here)
return false;
else {
} else {
sa = pit->second;
return true;
}
......
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