Commit 4ca31398 authored by Stefan Spettel's avatar Stefan Spettel

refact(pcf): Changed class hierarchy and simplified interaction with smf_n7 in...

refact(pcf): Changed class hierarchy and simplified interaction with smf_n7 in smf_context.cpp, added stubs for all CRUD methods
Signed-off-by: default avatarStefan Spettel <stefan.spettel@eurecom.fr>
parent c95fe15a
/**
* Npcf_SMPolicyControl API
* Session Management Policy Control Service © 2020, 3GPP Organizational
* Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.1.alpha-5
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "SmPolicyDeleteData.h"
#include "Helpers.h"
#include <sstream>
namespace oai {
namespace smf_server {
namespace model {
SmPolicyDeleteData::SmPolicyDeleteData() {
m_UserLocationInfoIsSet = false;
m_UeTimeZone = "";
m_UeTimeZoneIsSet = false;
m_ServingNetworkIsSet = false;
m_UserLocationInfoTime = "";
m_UserLocationInfoTimeIsSet = false;
// m_RanNasRelCausesIsSet = false;
// m_AccuUsageReportsIsSet = false;
// m_PduSessRelCauseIsSet = false;
}
void SmPolicyDeleteData::validate() const {
std::stringstream msg;
if (!validate(msg)) {
// throw
// org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool SmPolicyDeleteData::validate(std::stringstream& msg) const {
return validate(msg, "");
}
bool SmPolicyDeleteData::validate(
std::stringstream& msg, const std::string& pathPrefix) const {
bool success = true;
const std::string _pathPrefix =
pathPrefix.empty() ? "SmPolicyDeleteData" : pathPrefix;
/*
if (ranNasRelCausesIsSet()) {
const std::vector<RanNasRelCause>& value = m_RanNasRelCauses;
const std::string currentValuePath = _pathPrefix + ".ranNasRelCauses";
if (value.size() < 1) {
success = false;
msg << currentValuePath << ": must have at least 1 elements;";
}
{ // Recursive validation of array elements
const std::string oldValuePath = currentValuePath;
int i = 0;
for (const RanNasRelCause& value : value) {
const std::string currentValuePath =
oldValuePath + "[" + std::to_string(i) + "]";
success = value.validate(msg, currentValuePath + ".ranNasRelCauses") &&
success;
i++;
}
}
}
if (accuUsageReportsIsSet()) {
const std::vector<AccuUsageReport>& value = m_AccuUsageReports;
const std::string currentValuePath = _pathPrefix + ".accuUsageReports";
if (value.size() < 1) {
success = false;
msg << currentValuePath << ": must have at least 1 elements;";
}
{ // Recursive validation of array elements
const std::string oldValuePath = currentValuePath;
int i = 0;
for (const AccuUsageReport& value : value) {
const std::string currentValuePath =
oldValuePath + "[" + std::to_string(i) + "]";
success = value.validate(msg, currentValuePath + ".accuUsageReports") &&
success;
i++;
}
}
}
*/
return success;
}
bool SmPolicyDeleteData::operator==(const SmPolicyDeleteData& rhs) const {
return
((!userLocationInfoIsSet() && !rhs.userLocationInfoIsSet()) ||
(userLocationInfoIsSet() && rhs.userLocationInfoIsSet() &&
getUserLocationInfo() == rhs.getUserLocationInfo())) &&
((!ueTimeZoneIsSet() && !rhs.ueTimeZoneIsSet()) ||
(ueTimeZoneIsSet() && rhs.ueTimeZoneIsSet() &&
getUeTimeZone() == rhs.getUeTimeZone())) &&
((!servingNetworkIsSet() && !rhs.servingNetworkIsSet()) ||
(servingNetworkIsSet() && rhs.servingNetworkIsSet() &&
getServingNetwork() == rhs.getServingNetwork())) &&
((!userLocationInfoTimeIsSet() && !rhs.userLocationInfoTimeIsSet()) ||
(userLocationInfoTimeIsSet() && rhs.userLocationInfoTimeIsSet() &&
getUserLocationInfoTime() == rhs.getUserLocationInfoTime()))
/* &&
((!ranNasRelCausesIsSet() && !rhs.ranNasRelCausesIsSet()) ||
(ranNasRelCausesIsSet() && rhs.ranNasRelCausesIsSet() &&
getRanNasRelCauses() == rhs.getRanNasRelCauses())) &&
((!accuUsageReportsIsSet() && !rhs.accuUsageReportsIsSet()) ||
(accuUsageReportsIsSet() && rhs.accuUsageReportsIsSet() &&
getAccuUsageReports() == rhs.getAccuUsageReports())) &&
((!pduSessRelCauseIsSet() && !rhs.pduSessRelCauseIsSet()) ||
(pduSessRelCauseIsSet() && rhs.pduSessRelCauseIsSet() &&
getPduSessRelCause() == rhs.getPduSessRelCause()))
*/
;
}
bool SmPolicyDeleteData::operator!=(const SmPolicyDeleteData& rhs) const {
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const SmPolicyDeleteData& o) {
j = nlohmann::json();
if (o.userLocationInfoIsSet()) j["userLocationInfo"] = o.m_UserLocationInfo;
if (o.ueTimeZoneIsSet()) j["ueTimeZone"] = o.m_UeTimeZone;
if (o.servingNetworkIsSet()) j["servingNetwork"] = o.m_ServingNetwork;
if (o.userLocationInfoTimeIsSet())
j["userLocationInfoTime"] = o.m_UserLocationInfoTime;
/*
if (o.ranNasRelCausesIsSet() || !o.m_RanNasRelCauses.empty())
j["ranNasRelCauses"] = o.m_RanNasRelCauses;
if (o.accuUsageReportsIsSet() || !o.m_AccuUsageReports.empty())
j["accuUsageReports"] = o.m_AccuUsageReports;
if (o.pduSessRelCauseIsSet()) j["pduSessRelCause"] = o.m_PduSessRelCause;
*/
}
void from_json(const nlohmann::json& j, SmPolicyDeleteData& o) {
if (j.find("userLocationInfo") != j.end()) {
j.at("userLocationInfo").get_to(o.m_UserLocationInfo);
o.m_UserLocationInfoIsSet = true;
}
if (j.find("ueTimeZone") != j.end()) {
j.at("ueTimeZone").get_to(o.m_UeTimeZone);
o.m_UeTimeZoneIsSet = true;
}
if (j.find("servingNetwork") != j.end()) {
j.at("servingNetwork").get_to(o.m_ServingNetwork);
o.m_ServingNetworkIsSet = true;
}
if (j.find("userLocationInfoTime") != j.end()) {
j.at("userLocationInfoTime").get_to(o.m_UserLocationInfoTime);
o.m_UserLocationInfoTimeIsSet = true;
}
/*
if (j.find("ranNasRelCauses") != j.end()) {
j.at("ranNasRelCauses").get_to(o.m_RanNasRelCauses);
o.m_RanNasRelCausesIsSet = true;
}
if (j.find("accuUsageReports") != j.end()) {
j.at("accuUsageReports").get_to(o.m_AccuUsageReports);
o.m_AccuUsageReportsIsSet = true;
}
if (j.find("pduSessRelCause") != j.end()) {
j.at("pduSessRelCause").get_to(o.m_PduSessRelCause);
o.m_PduSessRelCauseIsSet = true;
}
*/
}
UserLocation SmPolicyDeleteData::getUserLocationInfo() const {
return m_UserLocationInfo;
}
void SmPolicyDeleteData::setUserLocationInfo(UserLocation const& value) {
m_UserLocationInfo = value;
m_UserLocationInfoIsSet = true;
}
bool SmPolicyDeleteData::userLocationInfoIsSet() const {
return m_UserLocationInfoIsSet;
}
void SmPolicyDeleteData::unsetUserLocationInfo() {
m_UserLocationInfoIsSet = false;
}
std::string SmPolicyDeleteData::getUeTimeZone() const {
return m_UeTimeZone;
}
void SmPolicyDeleteData::setUeTimeZone(std::string const& value) {
m_UeTimeZone = value;
m_UeTimeZoneIsSet = true;
}
bool SmPolicyDeleteData::ueTimeZoneIsSet() const {
return m_UeTimeZoneIsSet;
}
void SmPolicyDeleteData::unsetUeTimeZone() {
m_UeTimeZoneIsSet = false;
}
PlmnIdNid SmPolicyDeleteData::getServingNetwork() const {
return m_ServingNetwork;
}
void SmPolicyDeleteData::setServingNetwork(PlmnIdNid const& value) {
m_ServingNetwork = value;
m_ServingNetworkIsSet = true;
}
bool SmPolicyDeleteData::servingNetworkIsSet() const {
return m_ServingNetworkIsSet;
}
void SmPolicyDeleteData::unsetServingNetwork() {
m_ServingNetworkIsSet = false;
}
std::string SmPolicyDeleteData::getUserLocationInfoTime() const {
return m_UserLocationInfoTime;
}
void SmPolicyDeleteData::setUserLocationInfoTime(std::string const& value) {
m_UserLocationInfoTime = value;
m_UserLocationInfoTimeIsSet = true;
}
bool SmPolicyDeleteData::userLocationInfoTimeIsSet() const {
return m_UserLocationInfoTimeIsSet;
}
void SmPolicyDeleteData::unsetUserLocationInfoTime() {
m_UserLocationInfoTimeIsSet = false;
}
/*
std::vector<RanNasRelCause> SmPolicyDeleteData::getRanNasRelCauses() const {
return m_RanNasRelCauses;
}
void SmPolicyDeleteData::setRanNasRelCauses(
std::vector<RanNasRelCause> const& value) {
m_RanNasRelCauses = value;
m_RanNasRelCausesIsSet = true;
}
bool SmPolicyDeleteData::ranNasRelCausesIsSet() const {
return m_RanNasRelCausesIsSet;
}
void SmPolicyDeleteData::unsetRanNasRelCauses() {
m_RanNasRelCausesIsSet = false;
}
std::vector<AccuUsageReport> SmPolicyDeleteData::getAccuUsageReports() const {
return m_AccuUsageReports;
}
void SmPolicyDeleteData::setAccuUsageReports(
std::vector<AccuUsageReport> const& value) {
m_AccuUsageReports = value;
m_AccuUsageReportsIsSet = true;
}
bool SmPolicyDeleteData::accuUsageReportsIsSet() const {
return m_AccuUsageReportsIsSet;
}
void SmPolicyDeleteData::unsetAccuUsageReports() {
m_AccuUsageReportsIsSet = false;
}
PduSessionRelCause SmPolicyDeleteData::getPduSessRelCause() const {
return m_PduSessRelCause;
}
void SmPolicyDeleteData::setPduSessRelCause(PduSessionRelCause const& value) {
m_PduSessRelCause = value;
m_PduSessRelCauseIsSet = true;
}
bool SmPolicyDeleteData::pduSessRelCauseIsSet() const {
return m_PduSessRelCauseIsSet;
}
void SmPolicyDeleteData::unsetPduSessRelCause() {
m_PduSessRelCauseIsSet = false;
}
*/
} // namespace model
} // namespace smf_server
} // namespace oai
/**
* Npcf_SMPolicyControl API
* Session Management Policy Control Service © 2020, 3GPP Organizational
* Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.1.alpha-5
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
* SmPolicyDeleteData.h
*
*
*/
#ifndef SmPolicyDeleteData_H_
#define SmPolicyDeleteData_H_
//#include "PduSessionRelCause.h"
#include "PlmnIdNid.h"
#include <string>
#include "UserLocation.h"
//#include "AccuUsageReport.h"
#include <vector>
//#include "RanNasRelCause.h"
#include <nlohmann/json.hpp>
namespace oai {
namespace smf_server {
namespace model {
/// <summary>
///
/// </summary>
class SmPolicyDeleteData {
public:
SmPolicyDeleteData();
virtual ~SmPolicyDeleteData() = default;
/// <summary>
/// Validate the current data in the model. Throws a ValidationException on
/// failure.
/// </summary>
void validate() const;
/// <summary>
/// Validate the current data in the model. Returns false on error and writes
/// an error message into the given stringstream.
/// </summary>
bool validate(std::stringstream& msg) const;
/// <summary>
/// Helper overload for validate. Used when one model stores another model and
/// calls it's validate. Not meant to be called outside that case.
/// </summary>
bool validate(std::stringstream& msg, const std::string& pathPrefix) const;
bool operator==(const SmPolicyDeleteData& rhs) const;
bool operator!=(const SmPolicyDeleteData& rhs) const;
/////////////////////////////////////////////
/// SmPolicyDeleteData members
/// <summary>
///
/// </summary>
UserLocation getUserLocationInfo() const;
void setUserLocationInfo(UserLocation const& value);
bool userLocationInfoIsSet() const;
void unsetUserLocationInfo();
/// <summary>
///
/// </summary>
std::string getUeTimeZone() const;
void setUeTimeZone(std::string const& value);
bool ueTimeZoneIsSet() const;
void unsetUeTimeZone();
/// <summary>
///
/// </summary>
PlmnIdNid getServingNetwork() const;
void setServingNetwork(PlmnIdNid const& value);
bool servingNetworkIsSet() const;
void unsetServingNetwork();
/// <summary>
///
/// </summary>
std::string getUserLocationInfoTime() const;
void setUserLocationInfoTime(std::string const& value);
bool userLocationInfoTimeIsSet() const;
void unsetUserLocationInfoTime();
/// <summary>
/// Contains the RAN and/or NAS release cause.
/// </summary>
/*
std::vector<RanNasRelCause> getRanNasRelCauses() const;
void setRanNasRelCauses(std::vector<RanNasRelCause> const& value);
bool ranNasRelCausesIsSet() const;
void unsetRanNasRelCauses();
*/
/// <summary>
/// Contains the usage report
/// </summary>
/*
std::vector<AccuUsageReport> getAccuUsageReports() const;
void setAccuUsageReports(std::vector<AccuUsageReport> const& value);
bool accuUsageReportsIsSet() const;
void unsetAccuUsageReports();
/// <summary>
///
/// </summary>
PduSessionRelCause getPduSessRelCause() const;
void setPduSessRelCause(PduSessionRelCause const& value);
bool pduSessRelCauseIsSet() const;
void unsetPduSessRelCause();
*/
friend void to_json(nlohmann::json& j, const SmPolicyDeleteData& o);
friend void from_json(const nlohmann::json& j, SmPolicyDeleteData& o);
protected:
UserLocation m_UserLocationInfo;
bool m_UserLocationInfoIsSet;
std::string m_UeTimeZone;
bool m_UeTimeZoneIsSet;
PlmnIdNid m_ServingNetwork;
bool m_ServingNetworkIsSet;
std::string m_UserLocationInfoTime;
bool m_UserLocationInfoTimeIsSet;
// std::vector<RanNasRelCause> m_RanNasRelCauses;
// bool m_RanNasRelCausesIsSet;
// std::vector<AccuUsageReport> m_AccuUsageReports;
// bool m_AccuUsageReportsIsSet;
// PduSessionRelCause m_PduSessRelCause;
// bool m_PduSessRelCauseIsSet;
};
} // namespace model
} // namespace smf_server
} // namespace oai
#endif /* SmPolicyDeleteData_H_ */
This diff is collapsed.
This diff is collapsed.
...@@ -1499,69 +1499,35 @@ void smf_context::handle_pdu_session_create_sm_context_request( ...@@ -1499,69 +1499,35 @@ void smf_context::handle_pdu_session_create_sm_context_request(
// Maximum Data Rate // Maximum Data Rate
// TODO: (Optional) Secondary authentication/authorization // TODO: (Optional) Secondary authentication/authorization
// Step 5. PCF selection // Step 5. Create SM Policy Association with PCF or local PCC rules
std::string smContextRef = std::to_string(smreq->scid); std::string smContextRef = std::to_string(smreq->scid);
oai::smf_server::model::SmPolicyDecision policy_decision; oai::smf_server::model::SmPolicyDecision policy_decision;
n7::policy_association policy_ass;
bool use_pcf_policy = false; bool use_pcf_policy = false;
if (!smf_cfg.use_local_pcc_rules) { if (!smf_cfg.use_local_pcc_rules) {
std::string pcf_addr; policy_ass.set_context(
std::string pcf_api_version; smf_supi_to_string(smreq->req.get_supi()), smreq->req.get_dnn(), snssai,
oai::smf_server::model::Snssai snssai_model; plmn, smreq->req.get_pdu_session_id(),
snssai_model.setSst(snssai.sST); smreq->req.get_pdu_session_type());
snssai_model.setSd(snssai.sD);
oai::smf_server::model::PlmnId plmn_id_model; // TODO what is the exact meaning of SCID? Is this unique per registration
std::string mnc_string = std::to_string(plmn.mnc_digit1) + // or unique per PDU session?
std::to_string(plmn.mnc_digit2) + policy_ass.id = smreq->scid;
std::to_string(plmn.mnc_digit3);
std::string mcc_string = std::to_string(plmn.mcc_digit1) + n7::sm_policy_status_code status =
std::to_string(plmn.mcc_digit2) + n7::smf_n7::get_instance().create_sm_policy_association(policy_ass);
std::to_string(plmn.mcc_digit3); if (status != n7::sm_policy_status_code::CREATED) {
plmn_id_model.setMnc(mnc_string);
plmn_id_model.setMcc(mcc_string);
// get the PCF (either from config file, DNS or NRF based on local config)
bool pcf_found = n7::smf_n7::get_instance().discover_pcf(
pcf_addr, pcf_api_version, snssai_model, plmn_id_model, dnn);
if (pcf_found) {
oai::smf_server::model::SmPolicyContextData context;
context.setPduSessionId(pdu_session_id);
std::string supi_string = smf_supi_to_string(smreq->req.get_supi());
// TODO only support imsi SUPI, not NAI
context.setSupi("imsi-" + supi_string);
oai::smf_server::model::PduSessionType pdu_session_type;
// hacky
pdu_session_type_t pdu_type = smreq->req.get_pdu_session_type();
from_json(pdu_type.toString(), pdu_session_type);
context.setPduSessionType(pdu_session_type);
context.setDnn(smreq->req.get_dnn());
// TODO which notification URI should we use for PCF updates?
// atm it is
// {apiRoot}/nsmf-pdusession/{apiVersion}/sm-contexts-policy/{smContextRef}
std::string notification_uri =
smreq->req.get_api_root() + "-policy/" + smContextRef;
n7::sm_policy_status_code status =
n7::smf_n7::get_instance().create_sm_policy_association(
pcf_addr, pcf_api_version, context, policy_decision);
if (status != n7::sm_policy_status_code::CREATED) {
Logger::smf_n7().info(
"PCF SM Policy Association Creation was not successful. Continue "
"using local rules");
use_pcf_policy = false;
// Here, the standard says that we could reject the PDU session or allow
// the PDU session applying local policies 29.512 Chapter 4.2.2.2
// TODO I propose to have this behavior configurable, for now we
// continue
} else {
use_pcf_policy = true;
}
} else {
Logger::smf_n7().info( Logger::smf_n7().info(
"PCF can not be found. Continue with local PCC rules"); "PCF SM Policy Association Creation was not successful. Continue "
"using default rules");
use_pcf_policy = false;
// Here, the standard says that we could reject the PDU session or allow
// the PDU session applying local policies 29.512 Chapter 4.2.2.2
// TODO I propose to have this behavior configurable, for now we
// continue
} else {
use_pcf_policy = true;
} }
} }
// TODO use the PCC rules also for QoS and other policy information // TODO use the PCC rules also for QoS and other policy information
......
...@@ -41,34 +41,92 @@ using namespace oai::smf_server::model; ...@@ -41,34 +41,92 @@ using namespace oai::smf_server::model;
extern smf_config smf_cfg; extern smf_config smf_cfg;
extern smf_sbi* smf_sbi_inst; extern smf_sbi* smf_sbi_inst;
sm_policy_status_code smf_n7::create_sm_policy_association( uint32_t smf_n7::select_pcf(const SmPolicyContextData& context) {
const std::string pcf_addr, const std::string pcf_api_version,
const oai::smf_server::model::SmPolicyContextData& context,
oai::smf_server::model::SmPolicyDecision& policy_decision) {
// TODO abstraction: Here we should choose between local PCC rules and PCF // TODO abstraction: Here we should choose between local PCC rules and PCF
// client // client
return policy_api_client.send_create_policy_association( // TODO PCF selection
pcf_addr, pcf_api_version, context, policy_decision);
if (policy_storages.empty()) {
// TODO choose between local PCC rules and PCF client, for now only PCF
// client
PlmnId plmn_id = {};
plmn_id.setMcc(context.getServingNetwork().getMcc());
plmn_id.setMnc(context.getServingNetwork().getMnc());
std::shared_ptr<smf_pcf_client> storage = smf_pcf_client::discover_pcf(
context.getSliceInfo(), plmn_id, context.getDnn());
if (storage) {
// TODO for now, only use the first PCF
policy_storages.insert(1, storage);
return 1; // ID is always 1, only one PF
} else {
return -1;
}
}
} }
bool smf_n7::discover_pcf( sm_policy_status_code smf_n7::create_sm_policy_association(
std::string& addr, std::string& api_version, const Snssai snssai, policy_association& association) {
const PlmnId plmn_id, const std::string dnn) { uint32_t pcf_id = select_pcf(association.context);
if (pcf_id == 0) {
return sm_policy_status_code::PCF_NOT_AVAILABLE;
}
/*std::shared_ptr<policy_storage> store;
try {
store = policy_storages.at(pcf_id);
} catch (std::exception) {
return sm_policy_status_code::PCF_NOT_AVAILABLE;
} */
folly::AtomicHashMap<uint32_t, std::shared_ptr<policy_storage>>::iterator it =
policy_storages.find(pcf_id);
if (it == policy_storages.end()) {
return sm_policy_status_code::PCF_NOT_AVAILABLE;
}
return it->second->create_policy_association(association);
// return store->create_policy_association(association);
}
smf_n7::~smf_n7() {
Logger::smf_n7().info("Deleting SMF N7 instance...");
}
///////////////////////////////////////////////////////////////////////////
/////////////////////// smf_pcf_client ////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
std::shared_ptr<smf_pcf_client> smf_pcf_client::discover_pcf(
const Snssai snssai, const PlmnId plmn_id, const std::string dnn) {
if (smf_cfg.use_local_pcc_rules) { if (smf_cfg.use_local_pcc_rules) {
Logger::smf_n7().info("Local PCC rules are enabled, do not discover PCF"); Logger::smf_n7().info("Local PCC rules are enabled, do not discover PCF");
return false; return nullptr;
} }
std::string pcf_addr;
std::string api_version;
if (smf_cfg.discover_pcf) { if (smf_cfg.discover_pcf) {
return discover_pcf_with_nrf(addr, api_version, snssai, plmn_id, dnn); if (!discover_pcf_with_nrf(pcf_addr, api_version, snssai, plmn_id, dnn)) {
Logger::smf_n7().warn("Could not discover PCF from NRF");
return nullptr;
}
} else { } else {
return discover_pcf_from_config_file( if (!discover_pcf_from_config_file(
addr, api_version, snssai, plmn_id, dnn); pcf_addr, api_version, snssai, plmn_id, dnn)) {
Logger::smf_n7().warn("Could not discover PCF from config file");
return nullptr;
}
} }
Logger::smf_n7().info("Created new PCF connection: %s", pcf_addr.c_str());
return std::make_unique<smf_pcf_client>(pcf_addr, api_version);
} }
bool smf_n7::discover_pcf_with_nrf( bool smf_pcf_client::discover_pcf_with_nrf(
std::string& addr, std::string& api_version, const Snssai snssai, std::string& addr, std::string& api_version, const Snssai snssai,
const PlmnId plmn_id, const std::string dnn) { const PlmnId plmn_id, const std::string dnn) {
Logger::smf_n7().debug("Discover PCF with NRF"); Logger::smf_n7().debug("Discover PCF with NRF");
...@@ -76,7 +134,7 @@ bool smf_n7::discover_pcf_with_nrf( ...@@ -76,7 +134,7 @@ bool smf_n7::discover_pcf_with_nrf(
return false; return false;
} }
bool smf_n7::discover_pcf_from_config_file( bool smf_pcf_client::discover_pcf_from_config_file(
std::string& addr, std::string& api_version, const Snssai snssai, std::string& addr, std::string& api_version, const Snssai snssai,
const PlmnId plmn_id, const std::string dnn) { const PlmnId plmn_id, const std::string dnn) {
// TODO ignore snssai, plmn_id and dnn, because it is not part of // TODO ignore snssai, plmn_id and dnn, because it is not part of
...@@ -116,25 +174,14 @@ bool smf_n7::discover_pcf_from_config_file( ...@@ -116,25 +174,14 @@ bool smf_n7::discover_pcf_from_config_file(
} }
} }
} }
smf_n7::~smf_n7() {
Logger::smf_n7().info("Deleting SMF N7 instance...");
}
///////////////////////////////////////////////////////////////////////////
/////////////////////// smf_pcf_client ////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
sm_policy_status_code smf_pcf_client::send_create_policy_association( sm_policy_status_code smf_pcf_client::create_policy_association(
const std::string pcf_addr, const std::string pcf_api_version, policy_association& association) {
const SmPolicyContextData& context, SmPolicyDecision& policy_decision) {
nlohmann::json json_data; nlohmann::json json_data;
to_json(json_data, context); to_json(json_data, association.context);
Logger::smf_n7().info("Sending PCF SM policy association creation request"); Logger::smf_n7().info("Sending PCF SM policy association creation request");
std::string url = "http://" + pcf_addr + "/" + sm_api_name + "/" +
pcf_api_version + "/" + sm_api_policy_resource_part;
std::string response_data; std::string response_data;
// generate a promise for the curl handle // generate a promise for the curl handle
...@@ -150,7 +197,7 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association( ...@@ -150,7 +197,7 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association(
// Create a new curl easy handle and add to the multi handle // Create a new curl easy handle and add to the multi handle
if (!smf_sbi_inst->curl_create_handle( if (!smf_sbi_inst->curl_create_handle(
url, json_data.dump(), response_data, pid_ptr, "POST", root_uri, json_data.dump(), response_data, pid_ptr, "POST",
smf_cfg.http_version)) { smf_cfg.http_version)) {
Logger::smf_sbi().warn( Logger::smf_sbi().warn(
"Could not create a new handle to send message to PCF"); "Could not create a new handle to send message to PCF");
...@@ -159,10 +206,6 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association( ...@@ -159,10 +206,6 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association(
} }
// Wait for the response // Wait for the response
// TODO what happens if PCF is not reachable? Should check that scenario
// TODO it seems that it just hangs and is stuck "forever".. The problem is
// that the CURL ERROR CODE in curl_release_handles are just ignored. e.g when
// I have an error code 28, does that mean that this thread is just stuck?
uint32_t response_code = smf_sbi_inst->get_available_response(f); uint32_t response_code = smf_sbi_inst->get_available_response(f);
...@@ -170,10 +213,10 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association( ...@@ -170,10 +213,10 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association(
Logger::smf_sbi().debug("Response data %s", response_data.c_str()); Logger::smf_sbi().debug("Response data %s", response_data.c_str());
if (response_code == http_status_code_e::HTTP_STATUS_CODE_201_CREATED) { if (response_code == http_status_code_e::HTTP_STATUS_CODE_201_CREATED) {
from_json(response_data, policy_decision); from_json(response_data, association.decision);
Logger::smf_n7().info( Logger::smf_n7().info(
"Successfully created SM Policy Association for SUPI %s", "Successfully created SM Policy Association for SUPI %s",
context.getSupi().c_str()); association.context.getSupi().c_str());
return sm_policy_status_code::CREATED; return sm_policy_status_code::CREATED;
} }
...@@ -213,4 +256,27 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association( ...@@ -213,4 +256,27 @@ sm_policy_status_code smf_pcf_client::send_create_policy_association(
"%s -- Details: %s - %s", info.c_str(), "%s -- Details: %s - %s", info.c_str(),
problem_details.getCause().c_str(), problem_details.getDetail().c_str()); problem_details.getCause().c_str(), problem_details.getDetail().c_str());
return response; return response;
}
sm_policy_status_code smf_pcf_client::remove_policy_association(
uint32_t policy_id, const SmPolicyDeleteData& delete_data) {
// TODO
return sm_policy_status_code::INTERNAL_ERROR;
}
sm_policy_status_code smf_pcf_client::update_policy_association(
uint32_t policy_id, const SmPolicyUpdateContextData& update_data,
policy_association& association) {
// TODO
return sm_policy_status_code::INTERNAL_ERROR;
}
sm_policy_status_code smf_pcf_client::get_policy_association(
uint32_t policy_id, policy_association& association) {
// TODO
return sm_policy_status_code::INTERNAL_ERROR;
}
smf_pcf_client::~smf_pcf_client() {
Logger::smf_n7().debug("Deleting PCF client instance");
} }
\ No newline at end of file
This diff is collapsed.
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