Commit 97168b49 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

integrate NAS into the code

parent c4ecfddc
...@@ -1022,7 +1022,6 @@ static int _nas_message_plain_decode ( ...@@ -1022,7 +1022,6 @@ static int _nas_message_plain_decode (
* Decode 5G Session Management L3 message * Decode 5G Session Management L3 message
*/ */
bytes = sm_msg_decode (&msg->sm, (uint8_t *) buffer, length); bytes = sm_msg_decode (&msg->sm, (uint8_t *) buffer, length);
printf("\ndukl esm_msg_decode\n");
} else { } else {
/* /*
* Discard L3 messages with not supported protocol discriminator * Discard L3 messages with not supported protocol discriminator
......
This diff is collapsed.
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
#include "pistache/router.h" #include "pistache/router.h"
#include "smf_msg.hpp" #include "smf_msg.hpp"
extern "C"{
#include "nas_message.h"
#include "mmData.h"
}
#include <map> #include <map>
#include <set> #include <set>
#include <shared_mutex> #include <shared_mutex>
...@@ -177,6 +182,45 @@ public: ...@@ -177,6 +182,45 @@ public:
*/ */
void send_create_session_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code); void send_create_session_response(Pistache::Http::ResponseWriter& httpResponse, oai::smf::model::SmContextCreateError& smContextCreateError, Pistache::Http::Code code);
/*
* Create N1 SM Container to send to AMF (using NAS lib)
* @param [std::shared_ptr<itti_n11_create_sm_context_response>] sm_context_res
* @param [uint8_t] msg_type Type of N1 message
* @param [std::string&] nas_msg_str store NAS message in form of string
*
*/
void create_n1_sm_container(std::shared_ptr<itti_n11_create_sm_context_response> sm_context_res, uint8_t msg_type, std::string& nas_msg_str, uint8_t sm_cause = 0);
//for testing purpose!!
void create_n1_sm_container(uint8_t msg_type, std::string& nas_msg_str, uint8_t sm_cause = 0);
/*
* Create N1 SM Container to send to AMF (using NAS lib)
* @param [std::shared_ptr<itti_n11_create_sm_context_request>] sm_context_req
* @param [uint8_t] msg_type Type of N1 message
* @param [std::string&] nas_msg_str store NAS message in form of string
*
*/
void create_n1_sm_container(std::shared_ptr<itti_n11_create_sm_context_request> sm_context_req, uint8_t msg_type, std::string& nas_msg_str, uint8_t sm_cause = 0);
/*
* Create N2 SM Information to send to AMF (using NAS lib)
* @param [std::shared_ptr<itti_n11_create_sm_context_response>] sm_context_res
* @param [uint8_t] msg_type Type of N2 message
* @param [std::string&] ngap_msg_str store NGAP message in form of string
*
*/
void create_n2_sm_information(std::shared_ptr<itti_n11_create_sm_context_response> sm_context_res, uint8_t ngap_msg_type, uint8_t ngap_ie_type, std::string& ngap_msg_str);
/*
* Decode N1 SM Container into the NAS mesasge (using NAS lib)
* @param [nas_message_t&] nas_msg Store NAS message after decoded
* @param [std::string&] n1_sm_msg N1 SM Container from AMF
* @return status of the decode process
*/
uint8_t decode_nas_message_n1_sm_container(nas_message_t& nas_msg, std::string& n1_sm_msg);
}; };
} }
#include "smf_config.hpp" #include "smf_config.hpp"
......
...@@ -399,6 +399,7 @@ void pgw_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req ...@@ -399,6 +399,7 @@ void pgw_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
itti_n11_create_sm_context_response *sm_context_resp = new itti_n11_create_sm_context_response(TASK_PGWC_APP, TASK_SMF_N11, smreq->http_response); itti_n11_create_sm_context_response *sm_context_resp = new itti_n11_create_sm_context_response(TASK_PGWC_APP, TASK_SMF_N11, smreq->http_response);
std::shared_ptr<itti_n11_create_sm_context_response> sm_context_resp_pending = std::shared_ptr<itti_n11_create_sm_context_response>(sm_context_resp); std::shared_ptr<itti_n11_create_sm_context_response> sm_context_resp_pending = std::shared_ptr<itti_n11_create_sm_context_response>(sm_context_resp);
sm_context_resp->res.set_supi(supi); sm_context_resp->res.set_supi(supi);
sm_context_resp->res.set_cause(REQUEST_ACCEPTED);
//Step 3. find pdn_connection //Step 3. find pdn_connection
std::shared_ptr<dnn_context> sd; std::shared_ptr<dnn_context> sd;
...@@ -543,14 +544,13 @@ void pgw_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req ...@@ -543,14 +544,13 @@ void pgw_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
//} //}
} }
//Send reply to AMF //Send reply to AMF (PDUSession_CreateSMContextResponse including Cause, SMContextId)
//location header contains the URI of the created resource //location header contains the URI of the created resource
Logger::pgwc_app().info("Sending response to AMF!"); Logger::pgwc_app().info("Sending response to AMF!");
nlohmann::json jsonData; nlohmann::json jsonData;
oai::smf::model::SmContextCreatedData smContextCreatedData; oai::smf::model::SmContextCreatedData smContextCreatedData;
//include only SmfServiceInstanceId (See section 6.1.6.2.3, 3GPP TS 29.502 v16.0.0) //include only SmfServiceInstanceId (See section 6.1.6.2.3, 3GPP TS 29.502 v16.0.0)
to_json(jsonData, smContextCreatedData); to_json(jsonData, smContextCreatedData);
std::string resBody = jsonData.dump(); std::string resBody = jsonData.dump();
sm_context_resp->http_response.send(Pistache::Http::Code::Created, resBody); sm_context_resp->http_response.send(Pistache::Http::Code::Created, resBody);
...@@ -570,9 +570,51 @@ void pgw_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req ...@@ -570,9 +570,51 @@ void pgw_context::handle_amf_msg (std::shared_ptr<itti_n11_create_sm_context_req
//un-subscribe to the modifications of Session Management Subscription data for (SUPI, DNN, S-NSSAI) //un-subscribe to the modifications of Session Management Subscription data for (SUPI, DNN, S-NSSAI)
} }
//step 9. send ITTI message to SMF N11 for the pending session? //step 9. if error when establishing the pdu session, send ITTI message to APP to trigger N1N2MessageTransfer towards AMFs
if (sm_context_resp->res.get_cause() != REQUEST_ACCEPTED) {
//clear pco, ambr
//TODO:
//free paa
paa_t free_paa = {};
free_paa = sm_context_resp->res.get_paa();
if (free_paa.is_ip_assigned()){
switch (sp->pdn_type.pdn_type) {
case PDN_TYPE_E_IPV4:
case PDN_TYPE_E_IPV4V6:
paa_dynamic::get_instance().release_paa (sd->dnn_in_use, free_paa.ipv4_address);
break;
case PDN_TYPE_E_IPV6:
case PDN_TYPE_E_NON_IP:
default:;
}
//sm_context_resp->res.clear_paa(); //TODO:
}
//clear the created context??
//TODO: //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};
bcc.set(it.eps_bearer_id);
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
//sm_context_resp_pending->res.set
Logger::pgwc_app().info( "Sending ITTI message %s to task TASK_SMF_N11", sm_context_resp_pending->get_msg_name());
int ret = itti_inst->send_msg(sm_context_resp_pending);
if (RETURNok != ret) {
Logger::pgwc_app().error( "Could not send ITTI message %s to task TASK_SMF_N11", sm_context_resp_pending->get_msg_name());
}
}
} }
......
...@@ -159,7 +159,6 @@ class pdu_session_create_sm_context_response { ...@@ -159,7 +159,6 @@ class pdu_session_create_sm_context_response {
public: public:
pdu_session_create_sm_context_response(){ } pdu_session_create_sm_context_response(){ }
supi_t get_supi() const; supi_t get_supi() const;
void set_supi(supi_t const& value); void set_supi(supi_t const& value);
pdu_session_id_t get_pdu_session_id() const; pdu_session_id_t get_pdu_session_id() const;
...@@ -176,7 +175,6 @@ private: ...@@ -176,7 +175,6 @@ private:
pdu_session_id_t m_pdu_session_id; pdu_session_id_t m_pdu_session_id;
uint8_t m_cause; uint8_t m_cause;
paa_t m_paa; paa_t m_paa;
//Pistache::Http::ResponseWriter m_http_response;
Pistache::Http::Code m_code; Pistache::Http::Code m_code;
}; };
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "itti.hpp" #include "itti.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "smf_n11.hpp" #include "smf_n11.hpp"
#include "pgw_app.hpp"
#include <curl/curl.h> #include <curl/curl.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
...@@ -39,6 +40,7 @@ ...@@ -39,6 +40,7 @@
#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 HTTP_STATUS_OK 200
#define DEBUG 1
using namespace pgwc; using namespace pgwc;
using namespace std; using namespace std;
...@@ -46,6 +48,7 @@ using json = nlohmann::json; ...@@ -46,6 +48,7 @@ using json = nlohmann::json;
extern itti_mw *itti_inst; extern itti_mw *itti_inst;
extern smf_n11 *smf_n11_inst; extern smf_n11 *smf_n11_inst;
extern pgwc::pgw_app *pgw_app_inst;
void smf_n11_task (void*); void smf_n11_task (void*);
/* /*
...@@ -119,6 +122,8 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons ...@@ -119,6 +122,8 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
//use curl to send data for the moment //use curl to send data for the moment
nlohmann::json jsonData; nlohmann::json jsonData;
std::string n1_message;
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
struct curl_slist *headers = NULL; struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json"); headers = curl_slist_append(headers, "Accept: application/json");
...@@ -132,9 +137,19 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons ...@@ -132,9 +137,19 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
std::string url = amf_addr + ":" + std::to_string(amf_port) + "/namf-comm/v1/ue-contexts/" + std::to_string(supi64) +"/n1-n2-messages"; std::string url = amf_addr + ":" + std::to_string(amf_port) + "/namf-comm/v1/ue-contexts/" + std::to_string(supi64) +"/n1-n2-messages";
Logger::smf_n11().debug("[get_sm_data] UDM's URL: %s ", url.c_str()); Logger::smf_n11().debug("[get_sm_data] UDM's URL: %s ", url.c_str());
//TODO: fill the content of N1N2MessageTransferReqData //N1 SM container
if (sm_context_res->res.get_cause() != REQUEST_ACCEPTED) { //PDU Session Establishment Reject
pgw_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_REJECT, n1_message); //need cause?
} else { //PDU Session Establishment Accept
pgw_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_REJECT, n1_message); //need cause?
//pgw_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_ACCPET, n1_message); //need cause?
}
jsonData["n1MessageContainer"]["n1MessageClass"] = "SM"; jsonData["n1MessageContainer"]["n1MessageClass"] = "SM";
jsonData["n1MessageContainer"]["n1MessageContent"]["contentId"] = "n1MessageContent"; jsonData["n1MessageContainer"]["n1MessageContent"]["contentId"] = n1_message.c_str();
Logger::smf_n11().debug("n1MessageContent: %s\n ", n1_message.c_str());
//TODO: fill the content of N1N2MessageTransferReqData
//jsonData["n2InfoContainer"]["n2InformationClass"] = "SM"; //jsonData["n2InfoContainer"]["n2InformationClass"] = "SM";
//jsonData["n2InfoContainer"]["smInfo"]["PduSessionId"] = 123; //jsonData["n2InfoContainer"]["smInfo"]["PduSessionId"] = 123;
//jsonData["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapMessageType"] = 123; //NGAP message //jsonData["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapMessageType"] = 123; //NGAP message
...@@ -187,7 +202,7 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons ...@@ -187,7 +202,7 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
//TODO: process the response if neccessary //TODO: process the response if necessary
} }
......
...@@ -287,7 +287,7 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab ...@@ -287,7 +287,7 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
//address, interface identifier, Session-AMBR, selected PDU Session Type, Reflective QoS Timer (if available), //address, interface identifier, Session-AMBR, selected PDU Session Type, Reflective QoS Timer (if available),
//P-CSCF address(es), [Always-on PDU Session]))) //P-CSCF address(es), [Always-on PDU Session])))
//send ITTI message to APP to trigger N1N2MessageTransfer towards AMFs //send ITTI message to N11 interface to trigger N1N2MessageTransfer towards AMFs
Logger::pgwc_app().info( "Sending ITTI message %s to task TASK_SMF_N11", n11_triggered_pending->get_msg_name()); Logger::pgwc_app().info( "Sending ITTI message %s to task TASK_SMF_N11", n11_triggered_pending->get_msg_name());
int ret = itti_inst->send_msg(n11_triggered_pending); int ret = itti_inst->send_msg(n11_triggered_pending);
......
...@@ -38,7 +38,8 @@ ...@@ -38,7 +38,8 @@
"n2SmInfo": {"contentId":"n2SmInfo"}, "n2SmInfo": {"contentId":"n2SmInfo"},
"n1SmMsg": {"contentId":"n1SmMsg"} "n1SmMsg": {"contentId":"n1SmMsg"}
}, },
"binaryDataN1SmMessage":"00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 02 00 55 00 01 40 00 40 84 3c 25 7f 00 00 01 7f 00 00 01 df b0 96 0c ea 4c f5 4b 00 00 00 00 00 03 00 35 20 bc ec 86 00 00 00 00 00 00 00 00 00 0f 40 21 00 00 01 00 26 00 1a 19 2e 03 1f c1 00 ff 93 a2 39 0f 61 62 63 64 65 66 40 67 68 69 6a 6b 2e 6c 6d" "binaryDataN1SmMessage":"2e031fc100ff93a2390f616263646566406768696a6b2e6c6d",
"binaryDataN1SmMessage_full":"00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 02 00 55 00 01 40 00 40 84 3c 25 7f 00 00 01 7f 00 00 01 df b0 96 0c ea 4c f5 4b 00 00 00 00 00 03 00 35 20 bc ec 86 00 00 00 00 00 00 00 00 00 0f 40 21 00 00 01 00 26 00 1a 19 2e 03 1f c1 00 ff 93 a2 39 0f 61 62 63 64 65 66 40 67 68 69 6a 6b 2e 6c 6d"
} }
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