Commit 64e521a2 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Get Static IP addr from UDM

parent f61ad481
......@@ -50,6 +50,14 @@ typedef struct ssc_mode_s {
ssc_mode = ssc_mode_e::SSC_MODE_1; // default mode
}
}
ssc_mode_s& operator=(const ssc_mode_s& s) {
ssc_mode = s.ssc_mode;
return *this;
}
virtual ~ssc_mode_s(){};
} ssc_mode_t;
typedef struct pdu_session_types_s {
......@@ -144,6 +152,33 @@ typedef struct ip_address_s {
}
};
ip_address_s& operator=(const struct in_addr& a) {
ip_address_type = IP_ADDRESS_TYPE_IPV4_ADDRESS;
u1.ipv4_address.s_addr = a.s_addr;
return *this;
}
ip_address_s& operator=(const struct in6_addr& a) {
ip_address_type = IP_ADDRESS_TYPE_IPV6_ADDRESS;
u1.ipv6_address.s6_addr32[0] = a.s6_addr32[0];
u1.ipv6_address.s6_addr32[1] = a.s6_addr32[1];
u1.ipv6_address.s6_addr32[2] = a.s6_addr32[2];
u1.ipv6_address.s6_addr32[3] = a.s6_addr32[3];
return *this;
}
ip_address_s& operator=(const ipv6_prefix_t& a) {
ip_address_type = IP_ADDRESS_TYPE_IPV6_PREFIX;
u1.ipv6_prefix.prefix_len = a.prefix_len;
u1.ipv6_prefix.prefix.s6_addr32[0] = a.prefix.s6_addr32[0];
u1.ipv6_prefix.prefix.s6_addr32[1] = a.prefix.s6_addr32[1];
u1.ipv6_prefix.prefix.s6_addr32[2] = a.prefix.s6_addr32[2];
u1.ipv6_prefix.prefix.s6_addr32[3] = a.prefix.s6_addr32[3];
return *this;
}
virtual ~ip_address_s(){};
std::string to_string() const {
if (IP_ADDRESS_TYPE_IPV4_ADDRESS == this->ip_address_type) {
return conv::toString(u1.ipv4_address);
......
......@@ -35,6 +35,9 @@
#include <pistache/http.h>
#include <pistache/mime.h>
#include <nlohmann/json.hpp>
#include <boost/algorithm/string/split.hpp>
//#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include "common_defs.h"
#include "itti.hpp"
......@@ -833,7 +836,7 @@ void smf_sbi::subscribe_upf_status_notify(
//------------------------------------------------------------------------------
bool smf_sbi::get_sm_data(
const supi64_t& supi, const std::string& dnn, const snssai_t& snssai,
std::shared_ptr<session_management_subscription> subscription) {
std::shared_ptr<session_management_subscription>& subscription) {
nlohmann::json jsonData = {};
std::string query_str = {};
query_str = "?single-nssai={\"sst\":" + std::to_string(snssai.sST) +
......@@ -950,7 +953,7 @@ bool smf_sbi::get_sm_data(
}
}
// session_ambr: Optional
// session_ambr (Optional)
if (it.value().find("sessionAmbr") != it.value().end()) {
dnn_configuration->session_ambr.uplink =
it.value()["sessionAmbr"]["uplink"];
......@@ -961,9 +964,69 @@ bool smf_sbi::get_sm_data(
dnn_configuration->session_ambr.uplink.c_str(),
dnn_configuration->session_ambr.downlink.c_str());
}
// Optional: Static IP Address
// Static IP Addresses (Optional)
if (it.value().find("staticIpAddress") != it.value().end()) {
for (const auto& ip_addr : it.value()["staticIpAddress"]) {
if (ip_addr.find("ipv4Addr") != ip_addr.end()) {
struct in_addr ue_ipv4_addr = {};
std::string ue_ip_str = ip_addr["ipv4Addr"].get<std::string>();
// ip_addr.at("ipv4Addr").get_to(ue_ip_str);
IPV4_STR_ADDR_TO_INADDR(
util::trim(ue_ip_str).c_str(), ue_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR UE IP ADDR !");
ip_address_t ue_ip = {};
ue_ip = ue_ipv4_addr;
dnn_configuration->static_ip_addresses.push_back(ue_ip);
} else if (ip_addr.find("ipv6Addr") != ip_addr.end()) {
unsigned char buf_in6_addr[sizeof(struct in6_addr)];
struct in6_addr ue_ipv6_addr;
std::string ue_ip_str = ip_addr["ipv6Addr"].get<std::string>();
if (inet_pton(
AF_INET6, util::trim(ue_ip_str).c_str(), buf_in6_addr) ==
1) {
memcpy(&ue_ipv6_addr, buf_in6_addr, sizeof(struct in6_addr));
} else {
Logger::smf_app().error(
"Bad UE IPv6 Addr %s", ue_ip_str.c_str());
throw("Bad UE IPv6 Addr %s", ue_ip_str.c_str());
}
ip_address_t ue_ip = {};
ue_ip = ue_ipv6_addr;
dnn_configuration->static_ip_addresses.push_back(ue_ip);
} else if (ip_addr.find("ipv6Prefix") != ip_addr.end()) {
unsigned char buf_in6_addr[sizeof(struct in6_addr)];
struct in6_addr ipv6_prefix;
std::string prefix_str = ip_addr["ipv6Prefix"].get<std::string>();
std::vector<std::string> words = {};
boost::split(
words, prefix_str, boost::is_any_of("/"),
boost::token_compress_on);
if (words.size() != 2) {
Logger::smf_app().error(
"Bad value for UE IPv6 Prefix %s", prefix_str.c_str());
return RETURNerror;
}
if (inet_pton(
AF_INET6, util::trim(words.at(0)).c_str(),
buf_in6_addr) == 1) {
memcpy(&ipv6_prefix, buf_in6_addr, sizeof(struct in6_addr));
} else {
Logger::smf_app().error(
"Bad UE IPv6 Addr %s", words.at(0).c_str());
throw("Bad UE IPv6 Addr %s", words.at(0).c_str());
}
ip_address_t ue_ip = {};
ipv6_prefix_t ue_ipv6_prefix = {};
ue_ipv6_prefix.prefix_len = std::stoi(util::trim(words.at(1)));
ue_ipv6_prefix.prefix = ipv6_prefix;
ue_ip = ue_ipv6_prefix;
dnn_configuration->static_ip_addresses.push_back(ue_ip);
}
}
}
......@@ -973,6 +1036,9 @@ bool smf_sbi::get_sm_data(
Logger::smf_sbi().warn(
"Exception message %s, exception id %d ", e.what(), e.id);
return false;
} catch (std::exception& e) {
Logger::smf_sbi().warn("Exception message %s", e.what());
return false;
}
}
return true;
......
......@@ -157,7 +157,7 @@ class smf_sbi {
*/
bool get_sm_data(
const supi64_t& supi, const std::string& dnn, const snssai_t& snssai,
std::shared_ptr<session_management_subscription> subscription);
std::shared_ptr<session_management_subscription>& subscription);
/*
* Subscribe to be notify from UDM
......
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