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

Add UPF profile

parent 9fe96cdf
......@@ -50,6 +50,21 @@ typedef struct smf_info_s {
std::vector<snssai_smf_info_item_t> snssai_smf_info_list;
} smf_info_t;
typedef struct dnn_upf_info_item_s {
std::string dnn;
// std::vector<std::string> dnai_list
// std::vector<std::string> pdu_session_types
} dnn_upf_info_item_t;
typedef struct snssai_upf_info_item_s {
snssai_t snssai;
std::vector<dnn_upf_info_item_t> dnn_upf_info_list;
} snssai_upf_info_item_t;
typedef struct upf_info_s {
std::vector<snssai_upf_info_item_t> snssai_upf_info_list;
} upf_info_t;
enum subscr_condition_type_e { // TODO: use enum class
UNKNOWN_CONDITION = 0,
NF_INSTANCE_ID_COND = 1,
......@@ -99,7 +114,7 @@ typedef struct subscription_condition_s {
subscription_condition_s(uint8_t t) : type(t) {}
subscription_condition_s(const subscription_condition_s &s)
subscription_condition_s(const subscription_condition_s& s)
: subscription_condition_s() {
type = s.type;
switch (s.type) {
......@@ -136,13 +151,13 @@ typedef struct subscription_condition_s {
}
// TODO:
}
bool operator==(const struct subscription_condition_s &s) const {
bool operator==(const struct subscription_condition_s& s) const {
return (s.type == type);
}
bool operator==(const uint8_t &t) const { return (t == type); }
bool operator==(const uint8_t& t) const { return (t == type); }
subscription_condition_s &operator=(const subscription_condition_s &s) {
subscription_condition_s& operator=(const subscription_condition_s& s) {
type = s.type;
switch (s.type) {
case NF_INSTANCE_ID_COND: {
......@@ -240,7 +255,7 @@ typedef struct nf_service_version_s {
std::string api_version_in_uri; // apiVersionInUri
std::string api_full_version; // apiFullVersion
nf_service_version_s &operator=(const nf_service_version_s &s) {
nf_service_version_s& operator=(const nf_service_version_s& s) {
api_version_in_uri = s.api_version_in_uri;
api_full_version = s.api_full_version;
}
......
......@@ -53,22 +53,22 @@ using namespace oai::nrf;
//------------------------------------------------------------------------------
bool api_conv::profile_api_to_nrf_profile(
const NFProfile &api_profile, std::shared_ptr<nrf_profile> &profile) {
const NFProfile& api_profile, std::shared_ptr<nrf_profile>& profile) {
Logger::nrf_app().debug(
"Convert a json-type profile to a NF profile (profile ID: %s)",
api_profile.getNfInstanceId().c_str());
profile.get()->set_nf_instance_id(api_profile.getNfInstanceId());
profile.get()->set_nf_instance_name(api_profile.getNfInstanceName());
Logger::nrf_app().debug("\tInstance name: %s",
profile.get()->get_nf_instance_name().c_str());
Logger::nrf_app().debug(
"\tInstance name: %s", profile.get()->get_nf_instance_name().c_str());
profile.get()->set_nf_status(api_profile.getNfStatus());
Logger::nrf_app().debug("\tStatus: %s",
profile.get()->get_nf_status().c_str());
Logger::nrf_app().debug(
"\tStatus: %s", profile.get()->get_nf_status().c_str());
profile.get()->set_nf_heartBeat_timer(api_profile.getHeartBeatTimer());
Logger::nrf_app().debug("\tHeartBeart timer: %d",
profile.get()->get_nf_heartBeat_timer());
Logger::nrf_app().debug(
"\tHeartBeart timer: %d", profile.get()->get_nf_heartBeat_timer());
profile.get()->set_nf_priority(api_profile.getPriority());
Logger::nrf_app().debug("\tPriority: %d", profile.get()->get_nf_priority());
profile.get()->set_nf_capacity(api_profile.getCapacity());
......@@ -80,8 +80,8 @@ bool api_conv::profile_api_to_nrf_profile(
sn.sD = s.getSd();
sn.sST = s.getSst();
profile.get()->add_snssai(sn);
Logger::nrf_app().debug("\tSNSSAI (SD, SST): %d, %s", sn.sST,
sn.sD.c_str());
Logger::nrf_app().debug(
"\tSNSSAI (SD, SST): %d, %s", sn.sST, sn.sD.c_str());
}
std::vector<std::string> ipv4_addr_str = api_profile.getIpv4Addresses();
......@@ -91,8 +91,8 @@ bool api_conv::profile_api_to_nrf_profile(
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::nrf_app().warn("Address conversion: Bad value %s",
util::trim(address).c_str());
Logger::nrf_app().warn(
"Address conversion: Bad value %s", util::trim(address).c_str());
}
Logger::nrf_app().debug("\tIPv4 Addr: %s", address.c_str());
......@@ -110,8 +110,8 @@ bool api_conv::profile_api_to_nrf_profile(
info.amf_region_id = amf_info_api.getAmfRegionId();
info.amf_set_id = amf_info_api.getAmfSetId();
Logger::nrf_app().debug("\t\tAMF Set ID: %s, AMF Region ID: %s",
info.amf_set_id.c_str(),
Logger::nrf_app().debug(
"\t\tAMF Set ID: %s, AMF Region ID: %s", info.amf_set_id.c_str(),
info.amf_region_id.c_str());
for (auto g : amf_info_api.getGuamiList()) {
......@@ -120,10 +120,11 @@ bool api_conv::profile_api_to_nrf_profile(
guami.plmn.mcc = g.getPlmnId().getMcc();
guami.plmn.mnc = g.getPlmnId().getMnc();
info.guami_list.push_back(guami);
Logger::nrf_app().debug("\t\tAMF GUAMI, AMF_ID: %s",
guami.amf_id.c_str());
Logger::nrf_app().debug("\t\tAMF GUAMI, PLMN (MCC: %s, MNC: %s)",
guami.plmn.mcc.c_str(), guami.plmn.mnc.c_str());
Logger::nrf_app().debug(
"\t\tAMF GUAMI, AMF_ID: %s", guami.amf_id.c_str());
Logger::nrf_app().debug(
"\t\tAMF GUAMI, PLMN (MCC: %s, MNC: %s)", guami.plmn.mcc.c_str(),
guami.plmn.mnc.c_str());
}
(std::static_pointer_cast<amf_profile>(profile))
.get()
......@@ -139,8 +140,9 @@ bool api_conv::profile_api_to_nrf_profile(
snssai_smf_info_item_t snssai = {};
snssai.snssai.sD = s.getSNssai().getSd();
snssai.snssai.sST = s.getSNssai().getSst();
Logger::nrf_app().debug("\t\tNSSAI SD: %s, SST: %d",
snssai.snssai.sD.c_str(), snssai.snssai.sST);
Logger::nrf_app().debug(
"\t\tNSSAI SD: %s, SST: %d", snssai.snssai.sD.c_str(),
snssai.snssai.sST);
for (auto d : s.getDnnSmfInfoList()) {
dnn_smf_info_item_t dnn = {};
dnn.dnn = d.getDnn();
......@@ -155,7 +157,35 @@ bool api_conv::profile_api_to_nrf_profile(
->add_smf_info(info);
} break;
default: {}
case NF_TYPE_UPF: {
Logger::nrf_app().debug("\tUPF profile, UPF Info");
profile.get()->set_nf_type(NF_TYPE_UPF);
upf_info_t info = {};
UpfInfo upf_info_api = api_profile.getUpfInfo();
for (auto s : upf_info_api.getSNssaiUpfInfoList()) {
snssai_upf_info_item_t snssai = {};
snssai.snssai.sD = s.getSNssai().getSd();
snssai.snssai.sST = s.getSNssai().getSst();
Logger::nrf_app().debug(
"\t\tNSSAI SD: %s, SST: %d", snssai.snssai.sD.c_str(),
snssai.snssai.sST);
for (auto d : s.getDnnUpfInfoList()) {
dnn_upf_info_item_t dnn = {};
dnn.dnn = d.getDnn();
snssai.dnn_upf_info_list.push_back(dnn);
Logger::nrf_app().debug("\t\tDNN: %s", dnn.dnn.c_str());
}
info.snssai_upf_info_list.push_back(snssai);
}
(std::static_pointer_cast<upf_profile>(profile))
.get()
->add_upf_info(info);
} break;
default: {
}
}
// nf_services
......@@ -181,7 +211,7 @@ bool api_conv::profile_api_to_nrf_profile(
//------------------------------------------------------------------------------
bool api_conv::subscription_api_to_nrf_subscription(
const SubscriptionData &api_sub, std::shared_ptr<nrf_subscription> &sub) {
const SubscriptionData& api_sub, std::shared_ptr<nrf_subscription>& sub) {
Logger::nrf_app().debug(
"Convert a json-type Subscription data a NRF subscription data");
sub.get()->set_notification_uri(api_sub.getNfStatusNotificationUri());
......@@ -330,7 +360,7 @@ bool api_conv::subscription_api_to_nrf_subscription(
}
//------------------------------------------------------------------------------
nf_type_t api_conv::string_to_nf_type(const std::string &str) {
nf_type_t api_conv::string_to_nf_type(const std::string& str) {
if (str.compare("NRF") == 0) return NF_TYPE_NRF;
if (str.compare("AMF") == 0) return NF_TYPE_AMF;
if (str.compare("SMF") == 0) return NF_TYPE_SMF;
......@@ -356,7 +386,7 @@ nf_type_t api_conv::string_to_nf_type(const std::string &str) {
}
//------------------------------------------------------------------------------
patch_op_type_t api_conv::string_to_patch_operation(const std::string &str) {
patch_op_type_t api_conv::string_to_patch_operation(const std::string& str) {
if (str.compare("add") == 0) return PATCH_OP_ADD;
if (str.compare("copy") == 0) return PATCH_OP_COPY;
if (str.compare("move") == 0) return PATCH_OP_MOVE;
......@@ -367,7 +397,7 @@ patch_op_type_t api_conv::string_to_patch_operation(const std::string &str) {
return PATCH_OP_UNKNOWN;
}
bool api_conv::validate_uuid(const std::string &str) {
bool api_conv::validate_uuid(const std::string& str) {
// should be verified with Capital letter
static const std::regex e(
"[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}");
......
......@@ -129,6 +129,10 @@ void nrf_app::handle_register_nf_instance(
sn = std::make_shared<smf_profile>(m_event_sub);
} break;
case NF_TYPE_UPF: {
sn = std::make_shared<upf_profile>(m_event_sub);
} break;
default: { sn = std::make_shared<nrf_profile>(m_event_sub); }
}
......
......@@ -239,6 +239,10 @@ void nrf_client::notify_subscribed_event(
std::static_pointer_cast<smf_profile>(profile).get()->to_json(
json_profile);
} break;
case NF_TYPE_UPF: {
std::static_pointer_cast<upf_profile>(profile).get()->to_json(
json_profile);
} break;
default: { profile.get()->to_json(json_profile); }
}
json_data["nfProfile"] = json_profile;
......@@ -296,6 +300,10 @@ void nrf_client::notify_subscribed_event_multi(
std::static_pointer_cast<smf_profile>(profile).get()->to_json(
json_profile);
} break;
case NF_TYPE_UPF: {
std::static_pointer_cast<upf_profile>(profile).get()->to_json(
json_profile);
} break;
default: { profile.get()->to_json(json_profile); }
}
json_data["nfProfile"] = json_profile;
......
......@@ -833,3 +833,125 @@ void smf_profile::to_json(nlohmann::json &data) const {
data["smfInfo"]["sNssaiSmfInfoList"].push_back(tmp);
}
}
//------------------------------------------------------------------------------
void upf_profile::add_upf_info(const upf_info_t &info) { upf_info = info; }
//------------------------------------------------------------------------------
void upf_profile::get_upf_info(upf_info_t &infos) const { infos = upf_info; }
//------------------------------------------------------------------------------
void upf_profile::display() {
nrf_profile::display();
Logger::nrf_app().debug("\tUPF Info");
for (auto s : upf_info.snssai_upf_info_list) {
Logger::nrf_app().debug(
"\t\tSNSSAI UPF Info List, SNSSAI (SD: %s, SST: %d)",
s.snssai.sD.c_str(), s.snssai.sST);
for (auto d : s.dnn_upf_info_list) {
Logger::nrf_app().debug("\t\tSNSSAI UPF Info List, DNN List: %s",
d.dnn.c_str());
}
}
}
//------------------------------------------------------------------------------
bool upf_profile::add_profile_info(const std::string &path,
const std::string &value) {
bool result = nrf_profile::add_profile_info(path, value);
if (result) return true;
// add an element to a list of json object
if (path.compare("upfInfo") == 0) {
Logger::nrf_app().info("Does not support this operation for upfInfo");
return false;
}
if ((path.compare("nfInstanceId") != 0) and
(path.compare("nfInstanceName") != 0) and
(path.compare("nfType") != 0) and (path.compare("nfStatus") != 0) and
(path.compare("heartBeatTimer") != 0) and
(path.compare("sNssais") != 0) and
(path.compare("ipv4Addresses") != 0) and
(path.compare("priority") != 0) and (path.compare("capacity") != 0) and
(path.compare("priority") != 0) and (path.compare("nfServices") != 0) and
(path.compare("upfInfo") != 0)) {
Logger::nrf_app().debug("Add new member: %s", path.c_str());
// add new member
json_data[path] = value;
return true;
}
return false;
}
//------------------------------------------------------------------------------
bool upf_profile::replace_profile_info(const std::string &path,
const std::string &value) {
bool result = nrf_profile::replace_profile_info(path, value);
if (result) return true;
// for UPF info
if (path.compare("upfInfo") == 0) {
Logger::nrf_app().debug("Does not support this operation for amfInfo");
return false;
}
if ((path.compare("nfInstanceId") != 0) and
(path.compare("nfInstanceName") != 0) and
(path.compare("nfType") != 0) and (path.compare("nfStatus") != 0) and
(path.compare("heartBeatTimer") != 0) and
(path.compare("sNssais") != 0) and
(path.compare("ipv4Addresses") != 0) and
(path.compare("priority") != 0) and (path.compare("capacity") != 0) and
(path.compare("priority") != 0) and (path.compare("nfServices") != 0) and
(path.compare("amfInfo") != 0)) {
Logger::nrf_app().debug("Member (%s) not found!", path.c_str());
return false;
}
return false;
}
//------------------------------------------------------------------------------
bool upf_profile::remove_profile_info(const std::string &path) {
bool result = nrf_profile::remove_profile_info(path);
if (result) return true;
// for UPF info
if (path.compare("upfInfo") == 0) {
Logger::nrf_app().debug("Do not support this operation for upfInfo");
return false;
}
if ((path.compare("nfInstanceId") != 0) and
(path.compare("nfInstanceName") != 0) and
(path.compare("nfType") != 0) and (path.compare("nfStatus") != 0) and
(path.compare("heartBeatTimer") != 0) and
(path.compare("sNssais") != 0) and
(path.compare("ipv4Addresses") != 0) and
(path.compare("priority") != 0) and (path.compare("capacity") != 0) and
(path.compare("priority") != 0) and (path.compare("nfServices") != 0) and
(path.compare("upfInfo") != 0)) {
Logger::nrf_app().debug("Member (%s) not found!", path.c_str());
return false;
}
return false;
}
//------------------------------------------------------------------------------
void upf_profile::to_json(nlohmann::json &data) const {
nrf_profile::to_json(data);
// UPF Info
data["upfInfo"]["sNssaiSmfInfoList"] = nlohmann::json::array();
for (auto snssai : upf_info.snssai_upf_info_list) {
nlohmann::json tmp = {};
tmp["sNssai"]["sst"] = snssai.snssai.sST;
tmp["sNssai"]["sd"] = snssai.snssai.sD;
tmp["dnnSmfInfoList"] = nlohmann::json::array();
for (auto d : snssai.dnn_upf_info_list) {
nlohmann::json tmp_dnn = {};
tmp_dnn["dnn"] = d.dnn;
tmp["dnnSmfInfoList"].push_back(tmp_dnn);
}
data["upfInfo"]["sNssaiSmfInfoList"].push_back(tmp);
}
}
......@@ -649,6 +649,74 @@ class smf_profile : public nrf_profile {
private:
smf_info_t smf_info;
};
class upf_profile : public nrf_profile {
public:
upf_profile(nrf_event &ev) : nrf_profile(ev, NF_TYPE_UPF) { upf_info = {}; }
upf_profile(nrf_event &ev, const std::string &id) : nrf_profile(ev, id) {
nf_type = NF_TYPE_UPF;
upf_info = {};
}
upf_profile(upf_profile &b) = delete;
/*
* Add a UPF info
* @param [const upf_info_t &] info: UPF info
* @return void
*/
void add_upf_info(const upf_info_t &info);
/*
* Get list of UPF infos a UPF info
* @param [const upf_info_t &] info: UPF info
* @return void
*/
void get_upf_info(upf_info_t &infos) const;
/*
* Print related-information for a UPF profile
* @param void
* @return void:
*/
void display();
/*
* Update a new value for a member of UPF profile
* @param [const std::string &] path: member name
* @param [const std::string &] value: new value
* @return void
*/
bool replace_profile_info(const std::string &path, const std::string &value);
/*
* Add a new value for a member of NF profile
* @param [const std::string &] path: member name
* @param [const std::string &] value: new value
* @return true if success, otherwise false
*/
bool add_profile_info(const std::string &path, const std::string &value);
/*
* Remove value of a member of NF profile
* @param [const std::string &] path: member name
* @param [const std::string &] value: new value
* @return true if success, otherwise false
*/
bool remove_profile_info(const std::string &path);
/*
* Represent NF profile as json object
* @param [nlohmann::json &] data: Json data
* @return void
*/
void to_json(nlohmann::json &data) const;
private:
upf_info_t upf_info;
};
} // namespace app
} // namespace nrf
} // namespace oai
......
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