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

update display/add validity time

parent 4311598c
......@@ -35,6 +35,8 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/time_parsers.hpp>
#include <nlohmann/json.hpp>
#include <regex>
......@@ -58,20 +60,20 @@ bool api_conv::profile_api_to_nrf_profile(
profile.get()->set_nf_instance_id(api_profile.getNfInstanceId());
profile.get()->set_nf_instance_name(api_profile.getNfInstanceName());
Logger::nrf_app().debug("............Instance name: %s",
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("............Status: %s",
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("............HeartBeart timer: %d",
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("............Priority: %d",
Logger::nrf_app().debug("\tPriority: %d",
profile.get()->get_nf_priority());
profile.get()->set_nf_capacity(api_profile.getCapacity());
Logger::nrf_app().debug("............Capacity: %d",
Logger::nrf_app().debug("\tCapacity: %d",
profile.get()->get_nf_capacity());
// SNSSAIs
std::vector<Snssai> snssai = api_profile.getSNssais();
......@@ -80,7 +82,7 @@ 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("............SNSSAI (SD, SST): %d, %s", sn.sST,
Logger::nrf_app().debug("\tSNSSAI (SD, SST): %d, %s", sn.sST,
sn.sD.c_str());
}
......@@ -95,7 +97,7 @@ bool api_conv::profile_api_to_nrf_profile(
util::trim(address).c_str());
}
Logger::nrf_app().debug("............IPv4 Addr: %s", address.c_str());
Logger::nrf_app().debug("\tIPv4 Addr: %s", address.c_str());
profile.get()->add_nf_ipv4_addresses(addr4);
}
......@@ -103,14 +105,14 @@ bool api_conv::profile_api_to_nrf_profile(
switch (nf_type) {
case NF_TYPE_AMF: {
Logger::nrf_app().debug("............AMF profile, AMF Info");
Logger::nrf_app().debug("\tAMF profile, AMF Info");
profile.get()->set_nf_type(NF_TYPE_AMF);
amf_info_t info = {};
AmfInfo amf_info_api = api_profile.getAmfInfo();
info.amf_region_id = amf_info_api.getAmfRegionId();
info.amf_set_id = amf_info_api.getAmfSetId();
Logger::nrf_app().debug("............AMF Set ID: %s, AMF Region ID: %s",
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());
......@@ -120,10 +122,10 @@ 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("............AMF GUAMI, AMF_ID: %s",
Logger::nrf_app().debug("\t\tAMF GUAMI, AMF_ID: %s",
guami.amf_id.c_str());
Logger::nrf_app().debug(
"....................., PLMN (MCC: %s, MNC: %s)",
"\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))
......@@ -131,7 +133,7 @@ bool api_conv::profile_api_to_nrf_profile(
->add_amf_info(info);
} break;
case NF_TYPE_SMF: {
Logger::nrf_app().debug("............SMF profile, SMF Info");
Logger::nrf_app().debug("\tSMF profile, SMF Info");
profile.get()->set_nf_type(NF_TYPE_SMF);
smf_info_t info = {};
SmfInfo smf_info_api = api_profile.getSmfInfo();
......@@ -140,13 +142,13 @@ 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(".......................NSSAI SD: %s, SST: %d",
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();
snssai.dnn_smf_info_list.push_back(dnn);
Logger::nrf_app().debug("......................DNN: %s",
Logger::nrf_app().debug("\t\tDNN: %s",
dnn.dnn.c_str());
}
info.snssai_smf_info_list.push_back(snssai);
......@@ -301,10 +303,15 @@ bool api_conv::subscription_api_to_nrf_subscription(
} else {
sub.get()->add_notif_event(NOTIFICATION_TYPE_UNKNOWN_EVENT);
}
//Logger::nrf_app().debug("ReqNotifEvents: %s", n.c_str());
}
}
if (api_sub.validityTimeIsSet()) {
std::string str = api_sub.getValidityTime();
boost::posix_time::ptime p (boost::posix_time::from_iso_string(str));
sub.get()->set_validity_time(p);
Logger::nrf_app().debug("Validity Time: %s", str.c_str());
}
// TODO:
return true;
}
......
......@@ -28,7 +28,11 @@
*/
#include "nrf_app.hpp"
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/time_formatters.hpp>
#include <chrono>
#include "3gpp_29.500.h"
#include "3gpp_29.510.h"
#include "api_conversions.hpp"
......@@ -406,7 +410,7 @@ bool nrf_app::update_nf_profile(const std::string &profile_id,
//------------------------------------------------------------------------------
std::shared_ptr<nrf_profile> nrf_app::find_nf_profile(
const std::string &profile_id) const {
Logger::nrf_app().info("Find a NF profile with ID %s", profile_id.c_str());
//Logger::nrf_app().info("Find a NF profile with ID %s", profile_id.c_str());
std::shared_lock lock(m_instance_id2nrf_profile);
if (instance_id2nrf_profile.count(profile_id) > 0) {
......@@ -420,7 +424,7 @@ std::shared_ptr<nrf_profile> nrf_app::find_nf_profile(
//------------------------------------------------------------------------------
bool nrf_app::find_nf_profile(const std::string &profile_id,
std::shared_ptr<nrf_profile> &p) const {
Logger::nrf_app().info("Find a NF profile with ID %s", profile_id.c_str());
//Logger::nrf_app().info("Find a NF profile with ID %s", profile_id.c_str());
std::shared_lock lock(m_instance_id2nrf_profile);
if (instance_id2nrf_profile.count(profile_id) > 0) {
......@@ -572,16 +576,20 @@ void nrf_app::handle_nf_status_registered(const std::string &profile_id) {
profile_id.c_str());
std::shared_ptr<nrf_profile> profile = {};
Logger::nrf_app().info("\tFind a NF profile with ID %s", profile_id.c_str());
find_nf_profile(profile_id, profile);
if (profile != nullptr) {
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_REGISTERED,
notification_uris);
// send notifications
nrf_client_inst->notify_subscribed_event(profile, notification_uris);
if (notification_uris.size() > 0)
nrf_client_inst->notify_subscribed_event(profile, notification_uris);
else
Logger::nrf_app().debug("\tNo subscription found");
} else {
Logger::nrf_app().error("NF profile not found, profile id %s",
Logger::nrf_app().error("\tNF profile not found, profile id %s",
profile_id.c_str());
}
}
......@@ -648,19 +656,45 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
const uint8_t &notification_type,
std::vector<std::string> &uris) const {
Logger::nrf_app().debug(
"Get the list of subscriptions related to this profile, profile id %s",
"\tGet the list of subscriptions related to this profile, profile id %s",
profile_id.c_str());
std::shared_ptr<nrf_profile> profile = {};
find_nf_profile(profile_id, profile);
if (profile.get() == nullptr) {
// error
return;
}
for (auto s : instance_id2nrf_subscription) {
Logger::nrf_app().info("\tVerifying subscription, subscription id %s", s.first.c_str());
std::string uri;
s.second.get()->get_notification_uri(uri);
//check notification event type
bool match_notif_type = false;
for (auto i : s.second.get()->get_notif_events()) {
if (i == notification_type) {
match_notif_type = true;
break;
}
}
if (!match_notif_type) continue;
// check validity time
boost::posix_time::ptime t(boost::posix_time::microsec_clock::local_time());
Logger::nrf_app().debug("\tCurrent time %s",
boost::posix_time::to_iso_string(t).c_str());
if (t > s.second.get()->get_validity_time()) {
Logger::nrf_app().debug(
"\tThis subscription expires, current time %s, validity time %s",
boost::posix_time::to_iso_string(t).c_str(),
boost::posix_time::to_iso_string(s.second.get()->get_validity_time()).c_str());
continue;
}
subscription_condition_t condition = {};
s.second.get()->get_sub_condition(condition);
......@@ -668,7 +702,7 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
case NF_INSTANCE_ID_COND: {
if (profile_id.compare(condition.nf_instance_id) == 0) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s", s.first.c_str(),
Logger::nrf_app().debug("\tSubscription id %s, uri %s", s.first.c_str(),
uri.c_str());
}
......@@ -677,7 +711,7 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
std::string nf_type = nf_type_e2str[profile.get()->get_nf_type()];
if (nf_type.compare(condition.nf_type) == 0) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s", s.first.c_str(),
Logger::nrf_app().debug("\tSubscription id %s, uri %s", s.first.c_str(),
uri.c_str());
}
} break;
......@@ -687,7 +721,7 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
profile.get()->get_nf_instance_name(service_name);
if (service_name.compare(condition.service_name) == 0) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s", s.first.c_str(),
Logger::nrf_app().debug("\tSubscription id %s, uri %s", s.first.c_str(),
uri.c_str());
}
......@@ -702,7 +736,7 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
0) and
(info.amf_set_id.compare(condition.amf_info.amf_set_id) == 0)) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s",
Logger::nrf_app().debug("\tSubscription id %s, uri %s",
s.first.c_str(), uri.c_str());
}
}
......@@ -725,7 +759,6 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
}
}
//TODO: reqNotifEvents
}
// TODO:
......
......@@ -178,31 +178,32 @@ 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("............Instance ID: %s",
Logger::nrf_app().debug("\tInstance ID: %s",
nf_instance_id.c_str());
Logger::nrf_app().debug("............Instance name: %s",
Logger::nrf_app().debug("\tInstance name: %s",
nf_instance_name.c_str());
Logger::nrf_app().debug("............Instance type: %s",
Logger::nrf_app().debug("\tInstance type: %s",
nf_type_e2str[nf_type].c_str());
Logger::nrf_app().debug("............Status: %s", nf_status.c_str());
Logger::nrf_app().debug("............HeartBeat timer: %d", heartBeat_timer);
Logger::nrf_app().debug("............Priority: %d", priority);
Logger::nrf_app().debug("............Capacity: %d", capacity);
Logger::nrf_app().debug("\tStatus: %s", nf_status.c_str());
Logger::nrf_app().debug("\tHeartBeat timer: %d", heartBeat_timer);
Logger::nrf_app().debug("\tPriority: %d", priority);
Logger::nrf_app().debug("\tCapacity: %d", capacity);
//SNSSAIs
for (auto s : snssais) {
Logger::nrf_app().debug("............NNSSAI(SST, SD): %d, %s", s.sST,
Logger::nrf_app().debug("\tNNSSAI(SST, SD): %d, %s", s.sST,
s.sD.c_str());
}
//IPv4 Addresses
for (auto address : ipv4_addresses) {
Logger::nrf_app().debug("............IPv4 Addr: %s", inet_ntoa(address));
Logger::nrf_app().debug("\tIPv4 Addr: %s", inet_ntoa(address));
}
if (!json_data.empty()) {
Logger::nrf_app().debug("............Json Data: %s",
Logger::nrf_app().debug("\tJson Data: %s",
json_data.dump().c_str());
}
}
......@@ -496,16 +497,16 @@ void amf_profile::get_amf_info(amf_info_t &info) const {
void amf_profile::display() {
nrf_profile::display();
Logger::nrf_app().debug("............AMF Info");
Logger::nrf_app().debug("\tAMF Info");
Logger::nrf_app().debug(
".....................AMF Set ID: %s, AMF Region ID: %s",
"\t\tAMF Set ID: %s, AMF Region ID: %s",
amf_info.amf_set_id.c_str(), amf_info.amf_region_id.c_str());
for (auto g : amf_info.guami_list) {
Logger::nrf_app().debug(".....................AMF GUAMI List, AMF_ID: %s",
Logger::nrf_app().debug("\t\tAMF GUAMI List, AMF_ID: %s",
g.amf_id.c_str());
Logger::nrf_app().debug(
"........................AMF GUAMI List, PLMN (MCC: %s, MNC: %s)",
"\t\tAMF GUAMI List, PLMN (MCC: %s, MNC: %s)",
g.plmn.mcc.c_str(), g.plmn.mnc.c_str());
}
}
......
......@@ -28,7 +28,10 @@
*/
#include "nrf_subscription.hpp"
#include <boost/date_time/posix_time/time_formatters.hpp>
#include <nlohmann/json.hpp>
#include "logger.hpp"
using namespace oai::nrf::app;
......@@ -97,14 +100,29 @@ std::vector<uint8_t> nrf_subscription::get_notif_events() const {
return notif_events;
}
//------------------------------------------------------------------------------
void nrf_subscription::set_validity_time(const boost::posix_time::ptime &t) {
validity_time = t;
}
//------------------------------------------------------------------------------
void nrf_subscription::get_validity_time(boost::posix_time::ptime &t) const {
t = validity_time;
}
//------------------------------------------------------------------------------
boost::posix_time::ptime nrf_subscription::get_validity_time() const {
return validity_time;
}
//------------------------------------------------------------------------------
void nrf_subscription::display() {
Logger::nrf_app().debug("Subscription information");
Logger::nrf_app().debug(".............Sub ID: %s", subscription_id.c_str());
Logger::nrf_app().debug("\tSub ID: %s", subscription_id.c_str());
Logger::nrf_app().debug(".............Notification URI: %s",
Logger::nrf_app().debug("\tNotification URI: %s",
nf_status_notification_uri.c_str());
Logger::nrf_app().debug(".............Subscription condition: %s",
Logger::nrf_app().debug("\tSubscription condition: %s",
sub_condition.to_string().c_str());
std::string notif_events_str = {};
......@@ -112,8 +130,11 @@ void nrf_subscription::display() {
notif_events_str.append(notification_event_type_e2str[n]);
notif_events_str.append(", ");
}
Logger::nrf_app().debug(".............Notification Events: %s",
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());
}
//------------------------------------------------------------------------------
......
......@@ -30,6 +30,8 @@
#ifndef FILE_NRF_SUBSCRIPTION_HPP_SEEN
#define FILE_NRF_SUBSCRIPTION_HPP_SEEN
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/time_parsers.hpp>
#include "3gpp_29.510.h"
#include "logger.hpp"
#include "nrf_event.hpp"
......@@ -42,7 +44,11 @@ using namespace std;
class nrf_subscription {
public:
nrf_subscription(nrf_event &ev) : m_event_sub(ev){};
nrf_subscription(nrf_event &ev) : m_event_sub(ev){
validity_time = boost::posix_time::from_iso_string("20991231T235959Z");
};
nrf_subscription(nrf_subscription const &) = delete;
......@@ -133,6 +139,27 @@ class nrf_subscription {
*/
std::vector<uint8_t> get_notif_events() const;
/*
* Set the validity time
* @param [const boost::posix_time::ptime &]t: validity time
* @return
*/
void set_validity_time(const boost::posix_time::ptime &t);
/*
* Get the validity time
* @param [boost::posix_time::ptime &]t: validity time
* @return
*/
void get_validity_time(boost::posix_time::ptime &t) const;
/*
* Get the validity time
* @param [void]
* @return [boost::posix_time::ptime &] validity time
*/
boost::posix_time::ptime get_validity_time() const;
/*
* Subscribe to be notified when a new NF registered to the NRF
* @param void
......@@ -162,6 +189,8 @@ class nrf_subscription {
std::vector<uint8_t> notif_events;
nrf_event &m_event_sub;
bs2::connection ev_connection;
boost::posix_time::ptime validity_time;
};
} // namespace app
} // namespace nrf
......
......@@ -314,5 +314,5 @@ IF(STATIC_LINKING)
ENDIF(STATIC_LINKING)
target_link_libraries (nrf ${ASAN}
-Wl,--start-group NRF 3GPP_COMMON_TYPES NRF_API CN_UTILS -lnettle ${NETTLE_LIBRARIES} ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lssl -lcrypto gflags glog dl double-conversion folly -Wl,--end-group pthread m rt config++ event boost_system pistache curl)
-Wl,--start-group NRF 3GPP_COMMON_TYPES NRF_API CN_UTILS -lnettle ${NETTLE_LIBRARIES} ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lboost_date_time -lssl -lcrypto gflags glog dl double-conversion folly -Wl,--end-group pthread m rt config++ event boost_system pistache curl)
\ No newline at end of file
......@@ -9,4 +9,4 @@ curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotific
curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"} } }'
curl -X POST -H "Content-Type: application/json" "http://192.168.1.23/nnrf-nfm/v1/subscriptions" -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"}}, "reqNotifEvents":["NF_REGISTERED", "NF_DEREGISTERED"] }'
\ No newline at end of file
curl -X POST -H "Content-Type: application/json" "http://192.168.1.23/nnrf-nfm/v1/subscriptions" -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"}}, "reqNotifEvents":["NF_REGISTERED", "NF_DEREGISTERED"], "validityTime":"20020131T235959" }'
\ No newline at end of file
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