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

update N11/Procedures

parent db28ce0d
......@@ -137,10 +137,8 @@ void smf_n11::send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_create
pdu_session_create_sm_context_response context_res_msg = sm_context_res->res;
std::string n1_message = context_res_msg.get_n1_sm_message();
std::string n2_message = context_res_msg.get_n2_sm_information();
//format string as hex
unsigned char *n1_msg_hex = smf_app_inst->format_string_as_hex(n1_message);
unsigned char *n2_msg_hex = smf_app_inst->format_string_as_hex(n2_message);
CURL *curl = curl_easy_init();
......@@ -179,8 +177,11 @@ void smf_n11::send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_create
curl_mime_type(part, "application/vnd.3gpp.5gnas");
curl_mime_name (part, context_res_msg.n1n2_message_transfer_data["n1MessageContainer"]["n1MessageContent"]["contentId"].dump().c_str());
if (context_res_msg.get_cause() == REQUEST_ACCEPTED) {
Logger::smf_n11().debug("Add N2 SM Information (NGAP) into the message: %s (bytes %d)", context_res_msg.get_n2_sm_information().c_str(), context_res_msg.get_n2_sm_information().length()/2);
auto n2_sm_found = context_res_msg.n1n2_message_transfer_data.count("n2InfoContainer");
if (n2_sm_found >0) {
std::string n2_message = context_res_msg.get_n2_sm_information();
unsigned char *n2_msg_hex = smf_app_inst->format_string_as_hex(n2_message);
Logger::smf_n11().debug("Add N2 SM Information (NGAP) into the message: %s (bytes %d)", n2_message.c_str(), n2_message.length()/2);
part = curl_mime_addpart(mime);
//curl_mime_data(part, reinterpret_cast<const char*>(n2_msg_hex), context_res_msg.get_n2_sm_information().length()/2); //TODO: ISSUE need to be solved
curl_mime_data(part, reinterpret_cast<const char*>(n2_msg_hex), 80); //TODO: ISSUE need to be solved
......@@ -188,6 +189,7 @@ void smf_n11::send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_create
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);
// Response information.
......@@ -239,11 +241,96 @@ void smf_n11::send_n1n2_message_transfer_request(std::shared_ptr<itti_n11_create
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("Send PDUSessionUpdateContextResponse to AMF ");
switch(sm_context_res->session_procedure_type){
case session_management_procedures_type_e::PDU_SESSION_ESTABLISHMENT_UE_REQUESTED: {
//Send reply to AMF
nlohmann::json sm_context_updated_data;
sm_context_updated_data["cause"] = sm_context_res->res.get_cause();
//sm_context_res->http_response.send(Pistache::Http::Code::Ok,sm_context_updated_data.dump());
sm_context_res->http_response.send(Pistache::Http::Code::No_Content);
}
break;
case session_management_procedures_type_e::PDU_SESSION_MODIFICATION_UE_INITIATED: {
//TODO:
//send Pistache response with multipart/related message
smf_n1_n2 smf_n1_n2_inst;
std::string boundary = "----Boundary";
pdu_session_update_sm_context_response context_res_msg = sm_context_res->res;
std::string json_part = context_res_msg.sm_context_updated_data.dump();
std::string n1_message = context_res_msg.get_n1_sm_message();
//format string as hex
unsigned char *n1_msg_hex = smf_app_inst->format_string_as_hex(n1_message);
std::string n2_message = context_res_msg.get_n2_sm_information();
unsigned char *n2_msg_hex = smf_app_inst->format_string_as_hex(n2_message);
sm_context_res->http_response.headers().add<Pistache::Http::Header::ContentType>(Pistache::Http::Mime::MediaType("multipart/related; boundary=" + boundary));
string body;
string CRLF = "\r\n";
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/json" + CRLF);
body.append(CRLF);
body.append(json_part + CRLF);
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/vnd.3gpp.5gnas"+ CRLF + "Content-Id: n1SmMsg" + CRLF);
body.append(CRLF);
body.append(std::string((char *)n1_msg_hex, n1_message.length()/2) + CRLF);
//body.append(n1_message + CRLF);
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/vnd.3gpp.ngap" + CRLF + "Content-Id: n2SmMsg" + CRLF);
body.append(CRLF);
body.append(std::string((char *)n2_msg_hex, n2_message.length()/2) + CRLF);
body.append("--" + boundary + "--" + CRLF);
sm_context_res->http_response.send(Pistache::Http::Code::Ok, body);
}
break;
case session_management_procedures_type_e::SERVICE_REQUEST_UE_TRIGGERED: {
//TODO:
//send Pistache response with multipart/related message
smf_n1_n2 smf_n1_n2_inst;
std::string boundary = "----Boundary";
pdu_session_update_sm_context_response context_res_msg = sm_context_res->res;
std::string json_part = context_res_msg.sm_context_updated_data.dump();
//format string as hex
std::string n2_message = context_res_msg.get_n2_sm_information();
unsigned char *n2_msg_hex = smf_app_inst->format_string_as_hex(n2_message);
sm_context_res->http_response.headers().add<Pistache::Http::Header::ContentType>(Pistache::Http::Mime::MediaType("multipart/related; boundary=" + boundary));
string body;
string CRLF = "\r\n";
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/json" + CRLF);
body.append(CRLF);
body.append(json_part + CRLF);
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/vnd.3gpp.ngap" + CRLF + "Content-Id: n2SmMsg" + CRLF);
body.append(CRLF);
body.append(std::string((char *)n2_msg_hex, n2_message.length()/2) + CRLF);
body.append("--" + boundary + "--" + CRLF);
sm_context_res->http_response.send(Pistache::Http::Code::Ok, body);
}
break;
default:{
}
}
}
......@@ -292,7 +379,9 @@ void smf_n11::send_pdu_session_create_sm_context_response(Pistache::Http::Respon
Pistache::Http::Mime::MediaType m3("application/vnd.3gpp.5gnas", Pistache::Http::Mime::MediaType::DontParse);
//httpResponse.headers().add<Pistache::Http::Header::Location>(url);
httpResponse.send(code, resBody, m3);
//httpResponse.send(code, resBody, m3);
// std::string header = "POST %s HTTP 1.1\r\n" + "Host: %s\r\n" + "Content-Length: %d\r\n" + "Connection: Keep-Alive\r\n"
// + "Content-Type: multipart/related; boundary=%s\r\n"+ "Accept-Charset: utf-8\r\n\r\n";
......
......@@ -208,6 +208,7 @@ int session_create_sm_context_procedure::run(std::shared_ptr<itti_n11_create_sm_
std::shared_ptr<session_management_subscription> ss = {};
pc.get()->get_default_qos(sm_context_req->req.get_snssai(), sm_context_req->req.get_dnn(), default_qos);
qfi.qfi = default_qos._5qi;
Logger::smf_app().info( "session_create_sm_context_procedure default qfi %d", qfi.qfi);
//packet detection information
pdi.set(source_interface); //source interface
......@@ -251,7 +252,18 @@ int session_create_sm_context_procedure::run(std::shared_ptr<itti_n11_create_sm_
q.far_id_ul.second = far_id;
q.pdr_id_ul = pdr_id;
q.pdu_session_id = sm_context_req->req.get_pdu_session_id();
//default QoS profile
q.qfi = default_qos._5qi;
q.qos_profile._5qi = default_qos._5qi;
q.qos_profile.arp = default_qos.arp;
//assign default QoS rule for this
QOSRulesIE qos_rule = {};
pc.get()->get_default_qos_rule(qos_rule, sm_context_req->req.get_pdu_session_type());
q.qos_rules.push_back(qos_rule);
ppc->generate_qos_rule_id(q.qos_rules[0].qosruleidentifer);
q.qos_rules[0].qosflowidentifer = q.qfi.qfi;
smf_qos_flow q2 = q;
ppc->add_qos_flow(q2);
......@@ -278,6 +290,7 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
resp.pfcp_ies.get(cause);
if (cause.cause_value == pfcp::CAUSE_VALUE_REQUEST_ACCEPTED) {
resp.pfcp_ies.get(ppc->up_fseid);
n11_triggered_pending->res.set_cause(REQUEST_ACCEPTED);
}
for (auto it : resp.pfcp_ies.created_pdrs) {
......@@ -293,14 +306,10 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
xgpp_conv::pfcp_to_core_fteid(local_up_fteid, q.ul_fteid);
//TODO: should be updated to 5G N3/N9 interface
q.ul_fteid.interface_type = S1_U_SGW_GTP_U; //UPF's N3 interface
// comment if SPGW-C allocate up fteid
//Update Qos Flow
smf_qos_flow q2 = q;
ppc->add_qos_flow(q2);
}
// uncomment if SPGW-C allocate up fteid
// ppc->add_eps_bearer(b);
// ppc->add_qos_flow(b);
} else {
Logger::smf_app().error( "Could not get EPS bearer for created_pdr %d", pdr_id.rule_id);
}
......@@ -317,7 +326,7 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
//TODO: how about pdu_session_id??
smf_qos_flow q = {};
qos_flow_context_created qos_flow = {}; //default flow, so Non-GBR
qos_flow_context_created qos_flow = {}; //default flow, so Non-GBR, TODO: //we can use smf_qos_flow instead!
qos_flow.set_cause(REQUEST_ACCEPTED);
if (not ppc->get_qos_flow(qfi, q)) {
qos_flow.set_cause(SYSTEM_FAILURE);
......@@ -327,6 +336,7 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
} else {
qos_flow.set_ul_fteid(q.ul_fteid); //tunnel info
}
qos_flow.set_qos_rule(q.qos_rules[0]); //set default QoS rule
}
qos_flow.set_qfi(qfi);
qos_flow.set_arp(default_qos.arp);
......@@ -352,7 +362,7 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
n11_triggered_pending->res.set_n1_sm_message(n1_sm_msg_hex);
} else { //PDU Session Establishment Accept
Logger::smf_app().debug("\nPrepare a PDU Session Establishment Accept message and send to UE\n");
Logger::smf_app().debug("Prepare a PDU Session Establishment Accept message and send to UE\n");
smf_n1_n2_inst.create_n1_sm_container(n11_triggered_pending->res, PDU_SESSION_ESTABLISHMENT_ACCEPT, n1_sm_msg, cause_value_5gsm_e::CAUSE_0_UNKNOWN); //TODO: need cause?
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
n11_triggered_pending->res.set_n1_sm_message(n1_sm_msg_hex);
......@@ -381,14 +391,13 @@ void session_create_sm_context_procedure::handle_itti_msg (itti_n4_session_estab
if (n11_triggered_pending->res.get_cause() == REQUEST_ACCEPTED){
//TODO: fill the content of N1N2MessageTransferReqData
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["n2InformationClass"] = "SM";
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["PduSessionId"] = 1;
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["PduSessionId"] = n11_triggered_pending->res.get_pdu_session_id();
//N2InfoContent (section 6.1.6.2.27@3GPP TS 29.518)
//n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapMessageType"] = 123; //NGAP message -to be verified: doesn't exist in tester (not required!!)
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"] = "PDU_RES_SETUP_REQ"; //NGAP message
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapData"]["contentId"] = "n2SmMsg"; //part 3
//n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["sNssai"]["sst"] = 222;
//n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["sNssai"]["sd"] = "0000D4";
//n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["nasPDU"] = ;//TODO: Doesn't exist in the spec (maybe N1MessageContainer in Spec!!), but exist in the tester!!
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["sNssai"]["sst"] = n11_triggered_pending->res.get_snssai().sST;
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["smInfo"]["sNssai"]["sd"] = n11_triggered_pending->res.get_snssai().sD;
n11_triggered_pending->res.n1n2_message_transfer_data["n2InfoContainer"]["ranInfo"] = "SM";
}
//Others information
......@@ -704,7 +713,7 @@ void session_update_sm_context_procedure::handle_itti_msg (itti_n4_session_modif
break;
}
/*
/*
for (auto qfi: list_of_qfis_to_be_modified){
pfcp::fteid_t local_up_fteid = {};
if (it_created_pdr.get(local_up_fteid)) {
......@@ -781,8 +790,29 @@ void session_update_sm_context_procedure::handle_itti_msg (itti_n4_session_modif
int ret = itti_inst->send_msg(itti_msg);
*/
// Create N2 SM Information
smf_n1_n2 smf_n1_n2_inst;
std::string n2_sm_info, n2_sm_info_hex;
//TODO: N2 SM Information
smf_n1_n2_inst.create_n2_sm_information(n11_triggered_pending->res, 1, n2_sm_info_type_e::PDU_RES_SETUP_REQ, n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
n11_triggered_pending->res.set_n2_sm_information(n2_sm_info_hex);
//Fill the json part
//N2SM
//TODO: fill the content of N1N2MessageTransferReqData
n11_triggered_pending->res.sm_context_updated_data["n2InfoContainer"]["n2InformationClass"] = "SM";
n11_triggered_pending->res.sm_context_updated_data["n2InfoContainer"]["smInfo"]["PduSessionId"] = n11_triggered_pending->res.get_pdu_session_id();
//N2InfoContent (section 6.1.6.2.27@3GPP TS 29.518)
n11_triggered_pending->res.sm_context_updated_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"] = "PDU_RES_SETUP_REQ"; //NGAP message
n11_triggered_pending->res.sm_context_updated_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapData"]["contentId"] = "n2SmMsg";
//send ITTI message to N11 interface to trigger SessionUpdateSMContextResponse towards AMFs
Logger::smf_app().info( "Sending ITTI message %s to task TASK_SMF_N11", n11_triggered_pending->get_msg_name());
n11_triggered_pending->session_procedure_type = session_procedure_type;//session_management_procedures_type_e::PDU_SESSION_ESTABLISHMENT_UE_REQUESTED;
int ret = itti_inst->send_msg(n11_triggered_pending);
if (RETURNok != ret) {
Logger::smf_app().error( "Could not send ITTI message %s to task TASK_SMF_N11", n11_triggered_pending->get_msg_name());
......@@ -797,8 +827,7 @@ void session_update_sm_context_procedure::handle_itti_msg (itti_n4_session_modif
{
//TODO: Nsmf_PDUSession_SMContextStatusNotify
/* If the PDU Session establishment is not successful, the SMF informs the AMF by invoking Nsmf_PDUSession_SMContextStatusNotify (Release). The SMF also releases any N4
session(s) created, any PDU Session address if allocated (e.g. IP address) and releases the association with PCF,
if any. In this case, step 19 is skipped.
session(s) created, any PDU Session address if allocated (e.g. IP address) and releases the association with PCF, if any.
see step 18, section 4.3.2.2.1@3GPP TS 23.502)
*/
}
......
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