Commit 8b9e891a authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

polish the code for config/context

parent f7ff6e2f
......@@ -655,5 +655,12 @@ bool smf_config::is_dotted_dnn_handled(const std::string& dnn, const pdu_session
return false;
}
//------------------------------------------------------------------------------
std::string smf_config::get_default_dnn()
{
Logger::smf_app().debug( "Default DNN: %s", smf_cfg.apn[0].apn.c_str());
return smf_cfg.apn[0].apn;
}
......@@ -20,12 +20,12 @@
*/
/*! \file smf_config.hpp
* \brief
* \brief
\author Lionel GAUTHIER, Tien-Thinh NGUYEN
\company Eurecom
\date 2019
\email: lionel.gauthier@eurecom.fr, tien-thinh.nguyen@eurecom.fr
*/
*/
#ifndef FILE_SMF_CONFIG_HPP_SEEN
#define FILE_SMF_CONFIG_HPP_SEEN
......@@ -277,6 +277,7 @@ public:
int get_pfcp_node_id(pfcp::node_id_t& node_id);
int get_pfcp_fseid(pfcp::fseid_t& fseid);
bool is_dotted_dnn_handled(const std::string& apn, const pdu_session_type_t& pdn_session_type);
std::string get_default_dnn();
};
} // namespace smf
......
......@@ -25,14 +25,13 @@
\company Eurecom
\date 2019
\email: lionel.gauthier@eurecom.fr, tien-thinh.nguyen@eurecom.fr
*/
*/
#include "itti.hpp"
#include "logger.hpp"
#include "smf_app.hpp"
#include "smf_config.hpp"
#include "smf_context.hpp"
#include "smf_ngap.hpp"
#include "smf_paa_dynamic.hpp"
#include "smf_procedure.hpp"
#include "ProblemDetails.h"
......@@ -40,6 +39,7 @@
#include "3gpp_24.501.h"
#include "SmContextCreatedData.h"
#include <algorithm>
#include "smf_n1_n2.hpp"
extern "C"{
#include "Ngap_PDUSessionResourceSetupResponseTransfer.h"
}
......@@ -358,18 +358,17 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
//Step 3. find pdu_session
std::shared_ptr<dnn_context> sd;
bool find_dnn = find_dnn_context (dnn, sd);
bool find_dnn = find_dnn_context (snssai, dnn, sd);
//step 3.1. create dnn context if not exist
//At this step, this context should be existed
if (nullptr == sd.get()) {
Logger::smf_app().debug("DNN context (dnn_in_use %s) is not existed yet!", dnn.c_str());
dnn_context *d = new (dnn_context);
d->in_use = true;
d->dnn_in_use = dnn;
sd = std::shared_ptr<dnn_context> (new dnn_context());
sd.get()->in_use = true;
sd.get()->dnn_in_use = dnn;
sd.get()->nssai = snssai;
//ambr
sd = std::shared_ptr<dnn_context> (d);
insert_dnn(sd);
} else {
sd.get()->dnn_in_use = dnn;
......@@ -383,12 +382,11 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
if (nullptr == sp.get()){
Logger::smf_app().debug("Create a new PDN connection!");
//create a new pdn connection
smf_pdu_session *p = new (smf_pdu_session);
p->pdn_type.pdn_type = sm_context_req_msg.get_pdu_session_type();
p->pdu_session_id = pdu_session_id; //should check also nas_msg.pdusessionidentity ??
sp = std::shared_ptr<smf_pdu_session>( new smf_pdu_session());
sp.get()->pdn_type.pdn_type = sm_context_req_msg.get_pdu_session_type();
sp.get()->pdu_session_id = pdu_session_id; //should check also nas_msg.pdusessionidentity ??
//amf id
p->amf_id = sm_context_req_msg.get_serving_nf_id();
sp = std::shared_ptr<smf_pdu_session>(p);
sp.get()->amf_id = sm_context_req_msg.get_serving_nf_id();
sd->insert_pdu_session(sp);
} else{
Logger::smf_app().debug("PDN connection is already existed!");
......@@ -438,7 +436,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
ss.get()->find_dnn_configuration(sd->dnn_in_use, sdc);
if (nullptr != sdc.get()){
paa.pdn_type.pdn_type = sdc.get()->pdu_session_types.default_session_type.pdu_session_type;
//TODO: static ip addr
//TODO: static ip address
}
}
......@@ -508,15 +506,15 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
to_json(jsonData, smContextCreatedData);
std::string resBody = jsonData.dump();
std::string smContextRef = sm_context_req_msg.get_supi_prefix() + "-" + smf_supi_to_string(sm_context_req_msg.get_supi());
//Enable to test with tester
// std::string smContextRef = sm_context_req_msg.get_supi_prefix() + "-" + smf_supi_to_string(sm_context_req_msg.get_supi());
std::string smContextRef = std::to_string(smreq->scid);
//headers: Location:
//Contains the URI of the newly created resource, according to the structure: {apiRoot}/nsmf-pdusession/{apiVersion}/sm-contexts/{smContextRef}
//std::string uri = sm_context_req_msg.get_api_root() + "/" + std::to_string(smreq->scid); //smContextRef
std::string uri = sm_context_req_msg.get_api_root() + "/" + smContextRef.c_str(); //smContextRef
std::string uri = sm_context_req_msg.get_api_root() + "/" + smContextRef.c_str();
sm_context_resp->http_response.headers().add<Pistache::Http::Header::Location>(uri);
sm_context_resp->http_response.send(Pistache::Http::Code::Created, resBody);
Logger::smf_app().info( "Create a procedure to process this message!");
session_create_sm_context_procedure* proc = new session_create_sm_context_procedure(sp);
std::shared_ptr<smf_procedure> sproc = std::shared_ptr<smf_procedure>(proc);
......@@ -526,7 +524,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
// error !
Logger::smf_app().info( "PDU SESSION CREATE SM CONTEXT REQUEST procedure failed");
remove_procedure(proc);
//TODO: [Verify] To send PDU Session Establishment Reject to AMF
//TODO: Send N1N2MessageTransfer including PDU Session Establishment Reject to AMF
}
......@@ -558,7 +556,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
//clear the created context??
//TODO:
/*
/*
for (auto it : sm_context_resp->res.bearer_contexts_to_be_created) {
gtpv2c::bearer_context_created_within_create_session_response bcc = {};
cause_t bcc_cause = {.cause_value = NO_RESOURCES_AVAILABLE, .pce = 0, .bce = 0, .cs = 0};
......@@ -566,7 +564,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
bcc.set(bcc_cause);
//sm_context_resp->res.add_bearer_context_created(bcc);
}
*/
*/
//send ITTI message to N11 interface to trigger N1N2MessageTransfer towards AMFs
//with N1SM container with a PDU Session Establishment Reject message
//TODO
......@@ -643,7 +641,7 @@ void smf_context::handle_amf_msg (std::shared_ptr<itti_n11_update_sm_context_req
}
//------------------------------------------------------------------------------
void smf_context::insert_dnn_subscription(snssai_t snssai, std::shared_ptr<session_management_subscription>& ss)
void smf_context::insert_dnn_subscription(const snssai_t& snssai, std::shared_ptr<session_management_subscription>& ss)
{
Logger::smf_app().info( "Insert dnn subscription, key: %d", (uint8_t)snssai.sST);
//std::unique_lock<std::recursive_mutex> lock(m_context);
......@@ -653,7 +651,7 @@ void smf_context::insert_dnn_subscription(snssai_t snssai, std::shared_ptr<sessi
}
//------------------------------------------------------------------------------
bool smf_context::find_dnn_subscription(const snssai_t snssai, std::shared_ptr<session_management_subscription>& ss)
bool smf_context::find_dnn_subscription(const snssai_t& snssai, std::shared_ptr<session_management_subscription>& ss)
{
Logger::smf_app().info( "find_dnn_subscription: %d, map size %d", (uint8_t)snssai.sST, dnn_subscriptions.size());
//std::unique_lock<std::recursive_mutex> lock(m_context);
......@@ -674,12 +672,13 @@ bool smf_context::find_dnn_subscription(const snssai_t snssai, std::shared_ptr<s
return false;
}
//------------------------------------------------------------------------------
bool smf_context::find_dnn_context(const std::string& dnn, std::shared_ptr<dnn_context>& dnn_context)
bool smf_context::find_dnn_context(const snssai_t& nssai, const std::string& dnn, std::shared_ptr<dnn_context>& dnn_context)
{
std::unique_lock<std::recursive_mutex> lock(m_context);
for (auto it : dnns) {
if (0 == dnn.compare(it->dnn_in_use)) {
if ((0 == dnn.compare(it->dnn_in_use)) and ((uint8_t)nssai.sST) == (uint8_t) (it->nssai.sST)) {
dnn_context = it;
return true;
}
......@@ -712,6 +711,22 @@ void smf_context::send_create_session_response_error(oai::smf_server::model::SmC
httpResponse.send(code, resBody);
}
//-----------------------------------------------------------------------------
supi_t smf_context::get_supi() const
{
return supi;
}
//-----------------------------------------------------------------------------
void smf_context::set_supi(supi_t const& s)
{
supi = s;
}
std::size_t smf_context::get_number_dnn_contexts()
{
return dnns.size();
}
//------------------------------------------------------------------------------
bool dnn_context::find_pdu_session(const uint32_t pdu_session_id , std::shared_ptr<smf_pdu_session>& pdn)
{
......
......@@ -25,7 +25,8 @@
\company Eurecom
\date 2019
\email: lionel.gauthier@eurecom.fr, tien-thinh.nguyen@eurecom.fr
*/
*/
#ifndef FILE_SMF_CONTEXT_HPP_SEEN
#define FILE_SMF_CONTEXT_HPP_SEEN
......@@ -118,9 +119,6 @@ public:
void set(const paa_t& paa);
bool get_qos_flow(const pfcp::pdr_id_t& pdr_id, smf_qos_flow& q) {
for (auto it : qos_flows) {
if (it.second.pdr_id_ul.rule_id == pdr_id.rule_id) {
......@@ -174,8 +172,6 @@ public:
std::string toString() const;
void generate_seid();
void set_seid(const uint64_t& seid);
void generate_pdr_id(pfcp::pdr_id_t& pdr_id);
......@@ -184,7 +180,6 @@ public:
void release_far_id(const pfcp::far_id_t& far_id);
void insert_procedure(smf_procedure* proc);
bool ipv4; // IP Address(es): IPv4 address and/or IPv6 prefix
bool ipv6; // IP Address(es): IPv4 address and/or IPv6 prefix
struct in_addr ipv4_address; // IP Address(es): IPv4 address and/or IPv6 prefix
......@@ -224,7 +219,6 @@ public:
util::uint_generator<uint16_t> pdr_id_generator;
util::uint_generator<uint32_t> far_id_generator;
uint32_t pdu_session_id;
std::string amf_id;
// QFI
......@@ -248,10 +242,10 @@ private:
class dnn_context {
public:
dnn_context() : m_context(), in_use(false), pdu_sessions() {
dnn_context() : m_context(), in_use(false), pdu_sessions(), nssai() {
}
dnn_context(std::string dnn) : m_context(), in_use(false), pdu_sessions(), dnn_in_use(dnn) {
dnn_context(std::string dnn) : m_context(), in_use(false), pdu_sessions(), nssai(), dnn_in_use(dnn) {
// apn_ambr = {0};
}
dnn_context(dnn_context& b) = delete;
......@@ -268,6 +262,8 @@ public:
std::string dnn_in_use; // The APN currently used, as received from the SGW.
//ambr_t apn_ambr; // APN AMBR: The maximum aggregated uplink and downlink MBR values to be shared across all Non-GBR bearers, which are established for this APN.
snssai_t nssai;
/* Store all PDU Sessions associated with this DNN context */
std::vector<std::shared_ptr<smf_pdu_session>> pdu_sessions;
......@@ -275,7 +271,6 @@ public:
};
class smf_context;
class smf_context : public std::enable_shared_from_this<smf_context> {
......@@ -306,7 +301,6 @@ public:
*/
void handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_request> smreq);
/*
* Handle messages from AMF (e.g., PDU_SESSION_UPDATESMContextRequest)
* @param [std::shared_ptr<itti_n11_update_sm_context_request] smreq Request message
......@@ -314,15 +308,13 @@ public:
*/
void handle_amf_msg (std::shared_ptr<itti_n11_update_sm_context_request> smreq);
/*
* Find DNN context with name
* @param [const std::string&] dnn
* @param [std::shared_ptr<dnn_context>&] dnn_context dnn context to be found
* @return void
*/
bool find_dnn_context(const std::string& dnn, std::shared_ptr<dnn_context>& dnn_context);
bool find_dnn_context(const snssai_t& nssai, const std::string& dnn, std::shared_ptr<dnn_context>& dnn_context);
/*
* Insert a DNN context into SMF context
......@@ -340,16 +332,69 @@ public:
*/
void send_create_session_response_error(oai::smf_server::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code, Pistache::Http::ResponseWriter& httpResponse);
/*
* Check the validity of the request according to user subscription and local policies
* @param [std::shared_ptr<itti_n11_create_sm_context_request>] smreq
* @return true if the request is valid, otherwise return false
*
*/
bool verify_sm_context_request(std::shared_ptr<itti_n11_create_sm_context_request> smreq);
std::vector<std::shared_ptr<dnn_context>> dnns;
/*
* Insert a session management subscription into the SMF context
* @param [const snssai_t&] snssai
* @param [std::shared_ptr<session_management_subscription>&] ss: pointer to the subscription
* @return void
*/
void insert_dnn_subscription(const snssai_t& snssai, std::shared_ptr<session_management_subscription>& ss);
/*
* Find a session management subscription from a SMF context
* @param [const snssai_t&] snssai
* @param [std::shared_ptr<session_management_subscription>&] ss: pointer to the subscription
* @return void
*/
bool find_dnn_subscription(const snssai_t& snssai, std::shared_ptr<session_management_subscription>& ss);
/*
* Convert all members of this class to string for logging
* @return std::string
*/
std::string toString() const;
/*
* Get the default QoS from the subscription
* @param [const snssai_t&] snssai
* @param [const std::string&] dnn
* @param [subscribed_default_qos_t] default_qos
* @return void
*/
void get_default_qos(const snssai_t& snssai, const std::string& dnn, subscribed_default_qos_t &default_qos);
/*
* Set the value for Supi
* @param [const supi_t&] s
* @return void
*/
void set_supi(const supi_t& s);
/*
* Get Supi member
* @param
* @return supi_t
*/
supi_t get_supi() const;
/*
* Get the number of dnn contexts
* @param
* @return std::size_t: the number of contexts
*/
std::size_t get_number_dnn_contexts();
private:
std::vector<std::shared_ptr<dnn_context>> dnns;
imsi_t imsi; // IMSI (International Mobile Subscriber Identity) is the subscriber permanent identity.
bool imsi_unauthenticated_indicator; // This is an IMSI indicator to show the IMSI is unauthenticated.
// TO BE CHECKED me_identity_t me_identity; // Mobile Equipment Identity (e.g. IMEI/IMEISV).
......@@ -368,18 +413,9 @@ public:
// Big recursive lock
mutable std::recursive_mutex m_context;
/* Insert a session management subscription into the DNN context */
void insert_dnn_subscription(snssai_t snssai, std::shared_ptr<session_management_subscription>& ss);
/* Find the subscription from the DNN context */
bool find_dnn_subscription(const snssai_t snssai, std::shared_ptr<session_management_subscription>& ss);
/* snssai-sst <-> session management subscription */
// snssai-sst <-> session management subscription
std::map<uint8_t, std::shared_ptr<session_management_subscription>> dnn_subscriptions;
supi_t supi;
};
}
......
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