Commit 9c9b9f84 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

update N11/N10 and SMF messages

parent 2870865c
...@@ -41,12 +41,42 @@ void qos_flow_context_created::set_qfi(const pfcp::qfi_t& q) ...@@ -41,12 +41,42 @@ void qos_flow_context_created::set_qfi(const pfcp::qfi_t& q)
{ {
qfi = q; qfi = q;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void qos_flow_context_created::set_ul_fteid(const fteid_t& teid) void qos_flow_context_created::set_ul_fteid(const fteid_t& teid)
{ {
ul_fteid = teid; ul_fteid = teid;
} }
//-----------------------------------------------------------------------------
void qos_flow_context_created::set_arp(const arp_5gc_t& a)
{
arp = a;
}
//-----------------------------------------------------------------------------
void qos_flow_context_created::set_priority_level (uint8_t p)
{
priority_level = p;
}
//-----------------------------------------------------------------------------
void qos_flow_context_modified::set_cause(const uint8_t cause)
{
cause_value = cause;
}
//-----------------------------------------------------------------------------
void qos_flow_context_modified::set_qfi(const pfcp::qfi_t& q)
{
qfi = q;
}
//-----------------------------------------------------------------------------
void qos_flow_context_modified::set_ul_fteid(const fteid_t& teid)
{
ul_fteid = teid;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
pdu_session_msg_type_t pdu_session_msg::get_msg_type() const pdu_session_msg_type_t pdu_session_msg::get_msg_type() const
{ {
...@@ -177,12 +207,12 @@ void pdu_session_create_sm_context::set_message_type(uint8_t const& message_type ...@@ -177,12 +207,12 @@ void pdu_session_create_sm_context::set_message_type(uint8_t const& message_type
m_message_type = message_type; m_message_type = message_type;
} }
//-----------------------------------------------------------------------------
std::string pdu_session_create_sm_context_request::get_n1_sm_message() const{ std::string pdu_session_create_sm_context_request::get_n1_sm_message() const{
return m_n1_sm_message; return m_n1_sm_message;
} }
//-----------------------------------------------------------------------------
void pdu_session_create_sm_context_request::set_n1_sm_message(std::string const& value){ void pdu_session_create_sm_context_request::set_n1_sm_message(std::string const& value){
m_n1_sm_message = value; m_n1_sm_message = value;
} }
...@@ -271,11 +301,63 @@ Pistache::Http::Code pdu_session_create_sm_context_response::get_http_code() ...@@ -271,11 +301,63 @@ Pistache::Http::Code pdu_session_create_sm_context_response::get_http_code()
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void pdu_session_create_sm_context_response::set_qos_flow_context(const qos_flow_context_created qos_flow) void pdu_session_create_sm_context_response::set_qos_flow_context(const qos_flow_context_created& qos_flow)
{ {
qos_flow_context = qos_flow; qos_flow_context = qos_flow;
} }
//-----------------------------------------------------------------------------
qos_flow_context_created pdu_session_create_sm_context_response::get_qos_flow_context() const
{
return qos_flow_context;
}
//-----------------------------------------------------------------------------
std::string pdu_session_create_sm_context_response::get_n2_sm_information() const{
return n2_sm_information;
}
//-----------------------------------------------------------------------------
void pdu_session_create_sm_context_response::set_n2_sm_information(std::string const& value){
n2_sm_information = value;
m_n2_sm_info_is_set = true;
}
//-----------------------------------------------------------------------------
std::string pdu_session_create_sm_context_response::get_n1_sm_message() const{
return n1_sm_message;
}
//-----------------------------------------------------------------------------
void pdu_session_create_sm_context_response::set_n1_sm_message(std::string const& value){
n1_sm_message = value;
m_n1_sm_msg_is_set = true;
}
//-----------------------------------------------------------------------------
bool pdu_session_create_sm_context_response::n1_sm_msg_is_set() const
{
return m_n1_sm_msg_is_set;
}
//-----------------------------------------------------------------------------
bool pdu_session_create_sm_context_response::n2_sm_info_is_set() const
{
return m_n2_sm_info_is_set;
}
//-----------------------------------------------------------------------------
void pdu_session_create_sm_context_response::set_amf_url(std::string const& value)
{
amf_url = value;
}
//-----------------------------------------------------------------------------
std::string pdu_session_create_sm_context_response::get_amf_url() const
{
return amf_url;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/* pdu_session_update_sm_context_request */ /* pdu_session_update_sm_context_request */
std::string pdu_session_update_sm_context_request::get_n2_sm_information() const{ std::string pdu_session_update_sm_context_request::get_n2_sm_information() const{
...@@ -285,6 +367,7 @@ std::string pdu_session_update_sm_context_request::get_n2_sm_information() const ...@@ -285,6 +367,7 @@ std::string pdu_session_update_sm_context_request::get_n2_sm_information() const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_n2_sm_information(std::string const& value){ void pdu_session_update_sm_context_request::set_n2_sm_information(std::string const& value){
n2_sm_information = value; n2_sm_information = value;
m_n2_sm_info_is_set = true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -295,8 +378,85 @@ std::string pdu_session_update_sm_context_request::get_n2_sm_info_type() const{ ...@@ -295,8 +378,85 @@ std::string pdu_session_update_sm_context_request::get_n2_sm_info_type() const{
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_n2_sm_info_type(std::string const& value){ void pdu_session_update_sm_context_request::set_n2_sm_info_type(std::string const& value){
n2_sm_info_type = value; n2_sm_info_type = value;
m_n2_sm_info_is_set = true;
}
//-----------------------------------------------------------------------------
std::string pdu_session_update_sm_context_request::get_n1_sm_message() const{
return n1_sm_message;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_n1_sm_message(std::string const& value){
n1_sm_message = value;
m_n1_sm_msg_is_set = true;
}
//-----------------------------------------------------------------------------
bool pdu_session_update_sm_context_request::n1_sm_msg_is_set() const
{
return m_n1_sm_msg_is_set;
}
//-----------------------------------------------------------------------------
bool pdu_session_update_sm_context_request::n2_sm_info_is_set() const
{
return m_n2_sm_info_is_set;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::add_qfi(pfcp::qfi_t const& qfi)
{
qfis.push_back(qfi);
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::get_qfis(std::vector<pfcp::qfi_t>& q)
{
for (auto qfi: qfis){
q.push_back(qfi);
}
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_dl_fteid(fteid_t const& t)
{
dl_fteid = t;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::get_dl_fteid(fteid_t& t)
{
t = dl_fteid;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_upCnx_state(std::string const& value)
{
m_upCnx_state = value;
m_upCnx_state_is_set = true;
}
//-----------------------------------------------------------------------------
bool pdu_session_update_sm_context_request::upCnx_state_is_set() const
{
return m_upCnx_state_is_set;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_rat_type(std::string const& value)
{
m_rat_type = value;
} }
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_request::set_an_type(std::string const& value)
{
m_an_type = value;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::set_cause(uint8_t cause) void pdu_session_update_sm_context_response::set_cause(uint8_t cause)
...@@ -310,4 +470,94 @@ uint8_t pdu_session_update_sm_context_response::get_cause(){ ...@@ -310,4 +470,94 @@ uint8_t pdu_session_update_sm_context_response::get_cause(){
} }
//-----------------------------------------------------------------------------
std::string pdu_session_update_sm_context_response::get_n2_sm_information() const{
return n2_sm_information;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::set_n2_sm_information(std::string const& value){
n2_sm_information = value;
}
//-----------------------------------------------------------------------------
std::string pdu_session_update_sm_context_response::get_n2_sm_info_type() const{
return n2_sm_info_type;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::set_n2_sm_info_type(std::string const& value){
n2_sm_info_type = value;
m_n2_sm_info_is_set = true;
}
//-----------------------------------------------------------------------------
std::string pdu_session_update_sm_context_response::get_n1_sm_message() const{
return n1_sm_message;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::set_n1_sm_message(std::string const& value){
n1_sm_message = value;
m_n1_sm_msg_is_set = true;
}
//-----------------------------------------------------------------------------
std::string pdu_session_update_sm_context_response::get_n1_sm_msg_type() const{
return n2_sm_info_type;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::set_n1_sm_msg_type(std::string const& value){
n2_sm_info_type = value;
m_n2_sm_info_is_set = true;
}
//-----------------------------------------------------------------------------
bool pdu_session_update_sm_context_response::n1_sm_msg_is_set() const
{
return m_n1_sm_msg_is_set;
}
//-----------------------------------------------------------------------------
bool pdu_session_update_sm_context_response::n2_sm_info_is_set() const
{
return m_n2_sm_info_is_set;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::add_qos_flow_context_modified(const qos_flow_context_modified& flow)
{
if ((flow.qfi.qfi >= QOS_FLOW_IDENTIFIER_FIRST) and (flow.qfi.qfi <= QOS_FLOW_IDENTIFIER_LAST)) {
qos_flow_context_modifieds.erase(flow.qfi.qfi);
qos_flow_context_modifieds.insert(std::pair<uint8_t,qos_flow_context_modified>((uint8_t)flow.qfi.qfi, flow));
Logger::smf_app().trace( "pdu_session_update_sm_context_response::add_qos_flow_context(%d) success", flow.qfi.qfi);
} else {
Logger::smf_app().error( "pdu_session_update_sm_context_response::add_qos_flow_context(%d) failed, invalid QFI", flow.qfi.qfi);
}
}
//-----------------------------------------------------------------------------
bool pdu_session_update_sm_context_response::get_qos_flow_context_modified (const pfcp::qfi_t& qfi, qos_flow_context_modified& flow)
{
for (auto it : qos_flow_context_modifieds) {
if (it.second.qfi == qfi) {
flow = it.second;
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
void pdu_session_update_sm_context_response::get_all_qos_flow_context_modifieds (std::map<uint8_t, qos_flow_context_modified>& all_flows)
{
for (auto it : qos_flow_context_modifieds) {
all_flows.insert(std::pair<uint8_t,qos_flow_context_modified>((uint8_t)it.first, it.second));
}
}
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "3gpp_29.244.h" #include "3gpp_29.244.h"
#include "3gpp_24.007.h" #include "3gpp_24.007.h"
#include "3gpp_24.501.h" #include "3gpp_24.501.h"
#include "3gpp_29.571.h"
#include "Guami.h" #include "Guami.h"
#include "RefToBinaryData.h" #include "RefToBinaryData.h"
#include "NgRanTargetId.h" #include "NgRanTargetId.h"
...@@ -57,13 +58,30 @@ public: ...@@ -57,13 +58,30 @@ public:
void set_cause(const uint8_t cause); void set_cause(const uint8_t cause);
void set_qfi(const pfcp::qfi_t& q); void set_qfi(const pfcp::qfi_t& q);
void set_ul_fteid(const fteid_t& teid); void set_ul_fteid(const fteid_t& teid);
void set_arp(const arp_5gc_t& a);
void set_priority_level (uint8_t p);
private:
uint8_t cause_value; uint8_t cause_value;
pfcp::qfi_t qfi; pfcp::qfi_t qfi;
fteid_t ul_fteid; fteid_t ul_fteid;
arp_5gc_t arp;
uint8_t priority_level;//1-127
}; };
class qos_flow_context_modified {
public:
void set_cause(const uint8_t cause);
void set_qfi(const pfcp::qfi_t& q);
void set_ul_fteid(const fteid_t& teid);
uint8_t cause_value;
pfcp::qfi_t qfi;
fteid_t ul_fteid;
};
class pdu_session_msg { class pdu_session_msg {
public: public:
pdu_session_msg(){}; pdu_session_msg(){};
...@@ -249,8 +267,26 @@ public: ...@@ -249,8 +267,26 @@ public:
paa_t get_paa(); paa_t get_paa();
void set_http_code(Pistache::Http::Code code); void set_http_code(Pistache::Http::Code code);
Pistache::Http::Code get_http_code(); Pistache::Http::Code get_http_code();
void set_qos_flow_context(const qos_flow_context_created qos_flow); void set_qos_flow_context(const qos_flow_context_created& qos_flow);
qos_flow_context_created get_qos_flow_context() const;
nlohmann::json n1n2_message_transfer_data; //N1N2MessageTransferReqData from oai::amf::model
std::string get_n2_sm_information() const;
void set_n2_sm_information(std::string const& value);
std::string get_n1_sm_message() const;
void set_n1_sm_message(std::string const& value);
bool n1_sm_msg_is_set() const;
bool n2_sm_info_is_set() const;
std::string n1_sm_message; //N1 SM message
bool m_n1_sm_msg_is_set;
std::string n2_sm_information; //N2 SM info
bool m_n2_sm_info_is_set;
void set_amf_url(std::string const& value);
std::string get_amf_url() const;
private: private:
uint8_t m_cause; uint8_t m_cause;
paa_t m_paa; paa_t m_paa;
...@@ -258,6 +294,7 @@ private: ...@@ -258,6 +294,7 @@ private:
qos_flow_context_created qos_flow_context; qos_flow_context_created qos_flow_context;
supi_t m_supi; supi_t m_supi;
std::string m_supi_prefix; std::string m_supi_prefix;
std::string amf_url;
/* PDU Session establishment accept /* PDU Session establishment accept
ExtendedProtocolDiscriminator extendedprotocoldiscriminator; ExtendedProtocolDiscriminator extendedprotocoldiscriminator;
...@@ -298,17 +335,42 @@ private: ...@@ -298,17 +335,42 @@ private:
}; };
//see SmContextUpdateData (TS29502_Nsmf_PDUSession.yaml) //see SmContextUpdateData (TS29502_Nsmf_PDUSession.yaml)
class pdu_session_update_sm_context_request: public pdu_session_msg { class pdu_session_update_sm_context_request: public pdu_session_msg {
public: public:
pdu_session_update_sm_context_request(): pdu_session_msg(PDU_SESSION_UPDATE_SM_CONTEXT_REQUEST){ }; pdu_session_update_sm_context_request(): pdu_session_msg(PDU_SESSION_UPDATE_SM_CONTEXT_REQUEST){
m_n1_sm_msg_is_set = false;
m_n2_sm_info_is_set = false;
m_5gMm_cause_value = 0;
m_data_forwarding = false;
};
std::string get_n2_sm_information() const; std::string get_n2_sm_information() const;
void set_n2_sm_information(std::string const& value); void set_n2_sm_information(std::string const& value);
std::string get_n2_sm_info_type() const; std::string get_n2_sm_info_type() const;
void set_n2_sm_info_type(std::string const& value); void set_n2_sm_info_type(std::string const& value);
std::string get_n1_sm_message() const;
void set_n1_sm_message(std::string const& value);
bool n1_sm_msg_is_set() const;
bool n2_sm_info_is_set() const;
void add_qfi(pfcp::qfi_t const& qfi);
void get_qfis(std::vector<pfcp::qfi_t>& q);
void set_dl_fteid(fteid_t const& t);
void get_dl_fteid(fteid_t& t);
void set_upCnx_state(std::string const& value);
bool upCnx_state_is_set() const;
void set_rat_type(std::string const& value);
void set_an_type(std::string const& value);
private: private:
std::string n2_sm_information; std::vector<pfcp::qfi_t> qfis;
fteid_t dl_fteid; //AN Tunnel Info
std::string n1_sm_message; //N1 SM message before decoding
bool m_n1_sm_msg_is_set;
std::string n2_sm_information; //N2 SM before decoding
bool m_n2_sm_info_is_set;
std::string n2_sm_info_type; std::string n2_sm_info_type;
//std::string m_Ppei; //std::string m_Ppei;
std::string m_nf_instanceId; std::string m_nf_instanceId;
...@@ -351,6 +413,7 @@ private: ...@@ -351,6 +413,7 @@ private:
type: boolean type: boolean
*/ */
std::string m_upCnx_state; //'#/components/schemas/UpCnxState' std::string m_upCnx_state; //'#/components/schemas/UpCnxState'
bool m_upCnx_state_is_set; //'#/components/schemas/UpCnxState'
oai::smf_server::model::RefToBinaryData m_n1_sm_msg; //n1SmMsg oai::smf_server::model::RefToBinaryData m_n1_sm_msg; //n1SmMsg
oai::smf_server::model::RefToBinaryData m_n2_sm_info; //n2SmInfo oai::smf_server::model::RefToBinaryData m_n2_sm_info; //n2SmInfo
...@@ -396,7 +459,7 @@ private: ...@@ -396,7 +459,7 @@ private:
$ref: '#/components/schemas/Cause' $ref: '#/components/schemas/Cause'
*/ */
//NgApCause m_ngAp_cause; // $ref: '../TS29571_CommonData.yaml#/components/schemas/NgApCause //NgApCause m_ngAp_cause; // $ref: '../TS29571_CommonData.yaml#/components/schemas/NgApCause
unsigned int m_5gMm_cause_value; // 5GMmCause, $ref: '../TS29571_CommonData.yaml#/components/schemas/5GMmCause' uint8_t m_5gMm_cause_value; // 5GMmCause, $ref: '../TS29571_CommonData.yaml#/components/schemas/5GMmCause'
/* /*
sNssai: sNssai:
$ref: '../TS29571_CommonData.yaml#/components/schemas/Snssai' $ref: '../TS29571_CommonData.yaml#/components/schemas/Snssai'
...@@ -426,8 +489,37 @@ public: ...@@ -426,8 +489,37 @@ public:
pdu_session_update_sm_context_response(): pdu_session_msg(PDU_SESSION_UPDATE_SM_CONTEXT_RESPONSE){ }; pdu_session_update_sm_context_response(): pdu_session_msg(PDU_SESSION_UPDATE_SM_CONTEXT_RESPONSE){ };
void set_cause(uint8_t cause); void set_cause(uint8_t cause);
uint8_t get_cause(); uint8_t get_cause();
std::string get_n2_sm_information() const;
void set_n2_sm_information(std::string const& value);
std::string get_n2_sm_info_type() const;
void set_n2_sm_info_type(std::string const& value);
std::string get_n1_sm_message() const;
void set_n1_sm_message(std::string const& value);
std::string get_n1_sm_msg_type() const;
void set_n1_sm_msg_type(std::string const& value);
bool n1_sm_msg_is_set() const;
bool n2_sm_info_is_set() const;
void add_qos_flow_context_modified(const qos_flow_context_modified& qos_flow);
bool get_qos_flow_context_modified (const pfcp::qfi_t& qfi, qos_flow_context_modified& qos_flow);
void get_all_qos_flow_context_modifieds (std::map<uint8_t, qos_flow_context_modified>& all_flows);
private: private:
uint8_t m_cause; uint8_t m_cause;
std::string n1_sm_message; //N1 SM after decoding
bool m_n1_sm_msg_is_set;
std::string n1_sm_msg_type;
std::string n2_sm_information; //N2 SM after decoding
bool m_n2_sm_info_is_set;
std::string n2_sm_info_type;
std::map<uint8_t, qos_flow_context_modified> qos_flow_context_modifieds;
}; };
} }
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#define UDM_CURL_TIMEOUT_MS 100L #define UDM_CURL_TIMEOUT_MS 100L
#define UDM_NUMBER_RETRIES 3 #define UDM_NUMBER_RETRIES 3
#define HTTP_STATUS_OK 200
using namespace smf; using namespace smf;
using namespace std; using namespace std;
...@@ -125,7 +124,7 @@ bool smf_n10::get_sm_data(supi64_t& supi, std::string& dnn, snssai_t& snssai, st ...@@ -125,7 +124,7 @@ bool smf_n10::get_sm_data(supi64_t& supi, std::string& dnn, snssai_t& snssai, st
nlohmann::json jsonData; nlohmann::json jsonData;
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
struct curl_slist *headers = NULL; struct curl_slist *headers = nullptr;
headers = curl_slist_append(headers, "Accept: application/json"); headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "charsets: utf-8"); headers = curl_slist_append(headers, "charsets: utf-8");
...@@ -156,7 +155,7 @@ bool smf_n10::get_sm_data(supi64_t& supi, std::string& dnn, snssai_t& snssai, st ...@@ -156,7 +155,7 @@ bool smf_n10::get_sm_data(supi64_t& supi, std::string& dnn, snssai_t& snssai, st
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
Logger::smf_n10().debug("[get_sm_data] Response from UDM, Http Code: %d ", httpCode); Logger::smf_n10().debug("[get_sm_data] Response from UDM, Http Code: %d ", httpCode);
if (httpCode == HTTP_STATUS_OK) if (static_cast<http_response_codes_e> (httpCode) == http_response_codes_e::HTTP_RESPONSE_CODE_OK)
{ {
Logger::smf_n10().debug("[get_sm_data] Got successful response from UDM, URL: %s ", url.c_str()); Logger::smf_n10().debug("[get_sm_data] Got successful response from UDM, URL: %s ", url.c_str());
//Logger::smf_n10().debug("[get_sm_data] Http Data from UDM: %s ", *httpData.get()); //Logger::smf_n10().debug("[get_sm_data] Http Data from UDM: %s ", *httpData.get());
......
...@@ -39,10 +39,10 @@ ...@@ -39,10 +39,10 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <stdexcept> #include <stdexcept>
//TODO: move to a common file
#define AMF_CURL_TIMEOUT_MS 100L #define AMF_CURL_TIMEOUT_MS 100L
#define AMF_NUMBER_RETRIES 3 #define AMF_NUMBER_RETRIES 3
#define HTTP_STATUS_OK 200
#define DEBUG 1
using namespace smf; using namespace smf;
using namespace std; using namespace std;
...@@ -81,11 +81,16 @@ void smf_n11_task (void *args_p) ...@@ -81,11 +81,16 @@ void smf_n11_task (void *args_p)
switch (msg->msg_type) { switch (msg->msg_type) {
case N11_SESSION_CREATE_SM_CONTEXT_RESPONSE: case N11_SESSION_CREATE_SM_CONTEXT_RESPONSE:
smf_n11_inst->send_msg_to_amf(std::static_pointer_cast<itti_n11_create_sm_context_response>(shared_msg)); smf_n11_inst->send_n1n2_message_transfer_request(std::static_pointer_cast<itti_n11_create_sm_context_response>(shared_msg));
break; break;
case N11_SESSION_UPDATE_SM_CONTEXT_RESPONSE: case N11_SESSION_UPDATE_SM_CONTEXT_RESPONSE:
smf_n11_inst->send_msg_to_amf(std::static_pointer_cast<itti_n11_update_sm_context_response>(shared_msg)); smf_n11_inst->send_pdu_session_update_sm_context_response(std::static_pointer_cast<itti_n11_update_sm_context_response>(shared_msg));
break;
case N11_SESSION_MODIFICATION_REQUEST_SMF_REQUESTED:
//TODO
smf_n11_inst->send_n1n2_message_transfer_request(std::static_pointer_cast<itti_n11_modify_session_request_smf_requested> (shared_msg));
break; break;
case TERMINATE: case TERMINATE:
...@@ -116,8 +121,9 @@ smf_n11::smf_n11 () ...@@ -116,8 +121,9 @@ smf_n11::smf_n11 ()
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_response> sm_context_res) void smf_n11::send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_create_sm_context_response> sm_context_res)
{ {
//TODO: should create N1 SM, N2 SM from Procedure to make sure that in this class we simply do send the message to AMF
//Transfer N1/N2 message via AMF by using N_amf_Communication_N1N2MessageTransfer (see TS29518_Namf_Communication.yaml) //Transfer N1/N2 message via AMF by using N_amf_Communication_N1N2MessageTransfer (see TS29518_Namf_Communication.yaml)
//use curl to send data for the moment //use curl to send data for the moment
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Send Communication_N1N2MessageTransfer to AMF"); Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Send Communication_N1N2MessageTransfer to AMF");
...@@ -128,85 +134,25 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons ...@@ -128,85 +134,25 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
smf_n1_n2 smf_n1_n2_inst; smf_n1_n2 smf_n1_n2_inst;
pdu_session_create_sm_context_response context_res_msg = sm_context_res->res; pdu_session_create_sm_context_response context_res_msg = sm_context_res->res;
//Curl multipart
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
//get supi and put into URL //N1N2MessageTransfer Notification URI??
std::string supi_str; std::string json_part = context_res_msg.n1n2_message_transfer_data.dump();
supi_t supi = context_res_msg.get_supi();
supi_str = context_res_msg.get_supi_prefix() + "-" + smf_supi_to_string (supi);
std::string url = std::string(inet_ntoa (*((struct in_addr *)&smf_cfg.amf_addr.ipv4_addr))) + ":" + std::to_string(smf_cfg.amf_addr.port) + "/namf-comm/v2/ue-contexts/" + supi_str.c_str() +"/n1-n2-messages";
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Sending Communication_N1N2MessageTransfer to AMF, AMF's URL: %s", url.c_str());
//Create N1 SM container & N2 SM Information
//TODO: should uncomment these lines when including UPF in the test
//for the moment, can only test with PDU Session Establishment Reject!!
context_res_msg.set_cause(REQUEST_ACCEPTED);//for testing purpose
if (context_res_msg.get_cause() != REQUEST_ACCEPTED) { //PDU Session Establishment Reject
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] PDU Session Establishment Reject\n");
//pdu_session_msg& msg = context_res_msg;
smf_n1_n2_inst.create_n1_sm_container(context_res_msg, PDU_SESSION_ESTABLISHMENT_REJECT, n1_message, 0); //TODO: need cause?
} else { //PDU Session Establishment Accept
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] PDU Session Establishment Accept \n");
smf_n1_n2_inst.create_n1_sm_container(context_res_msg, PDU_SESSION_ESTABLISHMENT_ACCEPT, n1_message, 0); //TODO: need cause?
//TODO: N2 SM Information (Step 11, section 4.3.2.2.1 @ 3GPP TS 23.502)
smf_n1_n2_inst.create_n2_sm_information(context_res_msg, 1, 1, n2_message);
}
//Fill the json part
//N1SM
message_transfer_req_data["n1MessageContainer"]["n1MessageClass"] = "SM";
message_transfer_req_data["n1MessageContainer"]["n1MessageContent"]["contentId"] = "n1SmMsg"; //part 2
//N2SM
if (context_res_msg.get_cause() == REQUEST_ACCEPTED){
//TODO: fill the content of N1N2MessageTransferReqData
message_transfer_req_data["n2InfoContainer"]["n2InformationClass"] = "SM";
message_transfer_req_data["n2InfoContainer"]["smInfo"]["PduSessionId"] = 1;
//N2InfoContent (section 6.1.6.2.27@3GPP TS 29.518)
//message_transfer_req_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapMessageType"] = 123; //NGAP message -to be verified: doesn't exist in tester (not required!!)
message_transfer_req_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"] = "PDU_RES_SETUP_REQ"; //NGAP message
message_transfer_req_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapData"]["contentId"] = "n2SmMsg"; //part 3
//message_transfer_req_data["n2InfoContainer"]["smInfo"]["sNssai"]["sst"] = 222;
//message_transfer_req_data["n2InfoContainer"]["smInfo"]["sNssai"]["sd"] = "0000D4";
//message_transfer_req_data["n2InfoContainer"]["smInfo"]["nasPDU"] = ;//TODO: Doesn't exist in the spec (maybe N1MessageContainer in Spec!!), but exist in the tester!!
message_transfer_req_data["n2InfoContainer"]["ranInfo"] = "SM";
}
//Others information
message_transfer_req_data["ppi"] = 1; //Don't need this info for the moment
message_transfer_req_data["pduSessionId"] = context_res_msg.get_pdu_session_id();
//message_transfer_req_data["arp"]["priorityLevel"] = 1;
//message_transfer_req_data["arp"]["preemptCap"] = "NOT_PREEMPT";
//message_transfer_req_data["arp"]["preemptVuln"] = "NOT_PREEMPTABLE";
//message_transfer_req_data["5qi"] = ;
std::string json_part = message_transfer_req_data.dump();
//fill the N1SmMsg, N2SmMsg content
std::string n1_msg_hex;
smf_app_inst->convert_string_2_hex(n1_message, n1_msg_hex);
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] n1MessageContent: %s\n ", n1_msg_hex.c_str());
std::string n2_msg_hex;
if (context_res_msg.get_cause() == REQUEST_ACCEPTED){
smf_app_inst->convert_string_2_hex(n2_message, n2_msg_hex);
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] n2SMInformation %s\n ", n2_msg_hex.c_str());
}
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Sending message to AMF....\n "); Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Sending message to AMF....\n ");
if(curl) { if(curl) {
CURLcode res; CURLcode res;
struct curl_slist *headers = NULL; struct curl_slist *headers = nullptr;
struct curl_slist *slist = NULL; struct curl_slist *slist = nullptr;
curl_mime *mime; curl_mime *mime;
curl_mime *alt; curl_mime *alt;
curl_mimepart *part; curl_mimepart *part;
// headers = curl_slist_append(headers, "charsets: utf-8"); //headers = curl_slist_append(headers, "charsets: utf-8");
headers = curl_slist_append(headers, "content-type: multipart/related"); headers = curl_slist_append(headers, "content-type: multipart/related");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); curl_easy_setopt(curl, CURLOPT_URL, context_res_msg.get_amf_url().c_str() );
curl_easy_setopt(curl, CURLOPT_HTTPGET,1); curl_easy_setopt(curl, CURLOPT_HTTPGET,1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, AMF_CURL_TIMEOUT_MS); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, AMF_CURL_TIMEOUT_MS);
...@@ -220,17 +166,18 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons ...@@ -220,17 +166,18 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
//N1 SM Container //N1 SM Container
part = curl_mime_addpart(mime); part = curl_mime_addpart(mime);
curl_mime_data(part, n1_msg_hex.c_str(), CURL_ZERO_TERMINATED); curl_mime_data(part, context_res_msg.get_n1_sm_message().c_str(), CURL_ZERO_TERMINATED);
curl_mime_type(part, "application/vnd.3gpp.5gnas"); curl_mime_type(part, "application/vnd.3gpp.5gnas");
curl_mime_name (part, "n1SmMsg"); curl_mime_name (part, context_res_msg.n1n2_message_transfer_data["n1MessageContainer"]["n1MessageContent"]["contentId"].dump().c_str());
if (sm_context_res->res.get_cause() == REQUEST_ACCEPTED) { if (context_res_msg.get_cause() == REQUEST_ACCEPTED) {
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] add NGAP into the message....\n ");
//N2 SM Information //N2 SM Information
part = curl_mime_addpart(mime); part = curl_mime_addpart(mime);
//TODO: //TODO:
curl_mime_data(part, n2_msg_hex.substr(0,86).c_str(), CURL_ZERO_TERMINATED); //TODO: need to be solved curl_mime_data(part, context_res_msg.get_n2_sm_information().substr(0,86).c_str(), CURL_ZERO_TERMINATED); //TODO: ISSUE need to be solved
curl_mime_type(part, "application/vnd.3gpp.ngap"); curl_mime_type(part, "application/vnd.3gpp.ngap");
curl_mime_name (part, "n2SmMsg"); curl_mime_name (part, context_res_msg.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapData"]["contentId"].dump().c_str());
} }
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
...@@ -239,42 +186,45 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons ...@@ -239,42 +186,45 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
// Response information. // Response information.
long httpCode(0); long httpCode(0);
std::unique_ptr<std::string> httpData(new std::string()); std::unique_ptr<std::string> httpData(new std::string());
/*
// Hook up data handling function. // Hook up data handling function.
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)body.length()); res = curl_easy_perform(curl);
*/ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
int numRetries = 0;
while (numRetries < AMF_NUMBER_RETRIES){ //get cause from the response
res = curl_easy_perform(curl); json response_data;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); try{
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Response from AMF, Http Code: %d ", httpCode); response_data = json::parse(*httpData.get());
} catch (json::exception& e){
if (httpCode == HTTP_STATUS_OK) Logger::smf_n11().error( "Could not get the cause from the response");
{ //Set the default Cause
Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Got successful response from AMF, URL: %s ", url.c_str()); response_data["cause"] = "504 Gateway Timeout";
break; }
} Logger::smf_n11().debug("[SMF N11: N1N2MessageTransfer] Response from AMF, Http Code: %d, cause %s", httpCode, response_data["cause"]);
else
{ //send response to APP to process
Logger::smf_n10().warn("[SMF N11: N1N2MessageTransfer] Couldn't GET response from AMF, URL %s, retry ...", url.c_str()); itti_n11_n1n2_message_transfer_response_status *itti_msg = new itti_n11_n1n2_message_transfer_response_status(TASK_SMF_N11, TASK_SMF_APP);
//retry itti_msg->set_response_code(httpCode);
numRetries++; itti_msg->set_scid(sm_context_res->scid);
} itti_msg->set_cause(response_data["cause"]);
std::shared_ptr<itti_n11_n1n2_message_transfer_response_status> i = std::shared_ptr<itti_n11_n1n2_message_transfer_response_status>(itti_msg);
int ret = itti_inst->send_msg(i);
if (RETURNok != ret) {
Logger::smf_n11().error( "Could not send ITTI message %s to task TASK_SMF_APP", i->get_msg_name());
} }
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
curl_mime_free(mime); curl_mime_free(mime);
} }
//TODO: process the response if necessary
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_update_sm_context_response> sm_context_res) void smf_n11::send_pdu_session_update_sm_context_response(std::shared_ptr<itti_n11_update_sm_context_response> sm_context_res)
{ {
Logger::smf_n11().debug("[SMF N11] Send PDUSessionUpdateContextResponse to AMF "); Logger::smf_n11().debug("[SMF N11] Send PDUSessionUpdateContextResponse to AMF ");
//TODO: to be completed //TODO: to be completed
...@@ -287,3 +237,54 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_update_sm_context_respons ...@@ -287,3 +237,54 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_update_sm_context_respons
*/ */
} }
//------------------------------------------------------------------------------
void smf_n11::send_pdu_session_create_sm_context_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf_server::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code)
{
//TODO: Send multipart message
nlohmann::json jsonData;
to_json(jsonData, smContextCreateError);
std::string resBody = jsonData.dump();
//httpResponse.headers().add<Pistache::Http::Header::Location>(url);
httpResponse.send(code, resBody);
}
void smf_n11::send_pdu_session_create_sm_context_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf_server::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code, std::string& n1_sm_msg )
{
Logger::smf_n11().debug("[SMF N11] Send PDUSessionCreateContextResponse to AMF!");
//TODO: Send multipart message
nlohmann::json jsonData;
to_json(jsonData, smContextCreateError);
jsonData["n1SmMsg"]["contentId"] = "n1SmMsg"; //multipart
std::string resBody = jsonData.dump();
//httpResponse.headers().add<Pistache::Http::Header::Location>(url);
httpResponse.send(code, resBody);
}
//------------------------------------------------------------------------------
void smf_n11::send_pdu_session_create_sm_context_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf_server::model::SmContextCreatedData& smContextCreatedData, Pistache::Http::Code code)
{
Logger::smf_n11().debug("[SMF N11] Send PDUSessionUpdateContextResponse to AMF!");
//TODO: Send multipart message
nlohmann::json jsonData;
to_json(jsonData, smContextCreatedData);
std::string resBody = jsonData.dump();
//http_response.headers().add<Pistache::Http::Header::Location>(uri);
httpResponse.send(code, resBody);
}
//------------------------------------------------------------------------------
void smf_n11::send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_modify_session_request_smf_requested> sm_context_mod)
{
}
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "smf.h" #include "smf.h"
#include "3gpp_29.503.h" #include "3gpp_29.503.h"
#include "smf_context.hpp" #include "smf_context.hpp"
#include "SmContextCreatedData.h"
#include <thread> #include <thread>
#include <map> #include <map>
...@@ -48,8 +49,39 @@ public: ...@@ -48,8 +49,39 @@ public:
smf_n11(); smf_n11();
smf_n11(smf_n11 const&) = delete; smf_n11(smf_n11 const&) = delete;
void operator=(smf_n11 const&) = delete; void operator=(smf_n11 const&) = delete;
void send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_response> sm_context_res); void send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_create_sm_context_response> sm_context_res);
void send_msg_to_amf(std::shared_ptr<itti_n11_update_sm_context_response> sm_context_res); void send_pdu_session_update_sm_context_response(std::shared_ptr<itti_n11_update_sm_context_response> sm_context_res);
void send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_modify_session_request_smf_requested> sm_context_mod);
/*
* Send create session response to AMF
* @param [Pistache::Http::ResponseWriter] httpResponse
* @param [ oai::smf_server::model::SmContextCreateError] smContextCreateError
* @param [Pistache::Http::Code] code, response code
*
*/
void send_pdu_session_create_sm_context_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf_server::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code);
/*
* Send create session response to AMF
* @param [Pistache::Http::ResponseWriter] httpResponse
* @param [ oai::smf_server::model::SmContextCreateError] smContextCreateError
* @param [Pistache::Http::Code] code, response code
* @param [std::string] n1_sm_msg, N1 SM message content
*
*/
void send_pdu_session_create_sm_context_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf_server::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code, std::string& n1_sm_msg );
/*
* Send create session response to AMF
* @param [Pistache::Http::ResponseWriter] httpResponse
* @param [ oai::smf_server::model::SmContextCreatedData] smContextCreatedData
* @param [Pistache::Http::Code] code, response code
*
*/
void send_pdu_session_create_sm_context_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf_server::model::SmContextCreatedData& smContextCreatedData, Pistache::Http::Code code);
}; };
......
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