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

fix issues for encoding/decoding QoS Rules (PDU Session Modification)

parent 878e3e11
This diff is collapsed.
This diff is collapsed.
......@@ -1123,13 +1123,13 @@ void session_update_sm_context_procedure::handle_itti_msg(
//N1 SM
smf_n1_n2_inst.create_n1_sm_container(
n11_triggered_pending->res, PDU_SESSION_MODIFICATION_COMMAND,
n11_triggered_pending->res, PDU_SESSION_MODIFICATION_REQUEST,
n1_sm_msg, cause_value_5gsm_e::CAUSE_0_UNKNOWN);
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);
//N2 SM Information
smf_n1_n2_inst.create_n2_sm_information(
n11_triggered_pending->res, 1, n2_sm_info_type_e::PDU_RES_REL_RSP,
n11_triggered_pending->res, 1, n2_sm_info_type_e::PDU_RES_MOD_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);
......@@ -1138,7 +1138,7 @@ void session_update_sm_context_procedure::handle_itti_msg(
n11_triggered_pending->res.sm_context_updated_data =
sm_context_updated_data;
n11_triggered_pending->res.sm_context_updated_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"] =
"PDU_RES_REL_RSP"; //NGAP message
"PDU_RES_MOD_REQ"; //NGAP message
}
break;
......
......@@ -383,6 +383,142 @@ void send_pdu_session_update_sm_context_establishment(
free(buffer);
}
//------------------------------------------------------------------------------
void send_pdu_session_modification_request_step1(std::string smf_ip_address) {
std::cout << "[AMF N11] PDU Session Modification Request (SM Context Update, Step 1)"
<< std::endl;
nlohmann::json pdu_session_modification_request;
//encode PDU Session Modification Request
/*
0000 2e 01 01 d1 00 00 00 00 00 00 00 00 00 00 00 00
*/
size_t buffer_size = 128;
char *buffer = (char*) calloc(1, buffer_size);
int size = 0;
ENCODE_U8(buffer, 0x2e, size); //ExtendedProtocolDiscriminator
ENCODE_U8(buffer + size, 0x01, size); //PDUSessionIdentity
ENCODE_U8(buffer + size, 0x01, size); //ProcedureTransactionIdentity
ENCODE_U8(buffer + size, 0xc9, size); //MessageType - PDU Session Modification Request
ENCODE_U8(buffer + size, 0x28, size); //_5GSMCapability
ENCODE_U8(buffer + size, 0x01, size); //_5GSMCapability
ENCODE_U8(buffer + size, 0x00, size); //_5GSMCapability
ENCODE_U8(buffer + size, 0x59, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x00, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x7a, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x00, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x09, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x01, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x00, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x06, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x31, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x31, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x01, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x01, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x01, size); //_5GSMCause
ENCODE_U8(buffer + size, 0x3c, size); //_5GSMCause
// ENCODE_U8(buffer + size, 0x00, size); //MaximumNumberOfSupportedPacketFilters
// ENCODE_U8(buffer + size, 0x01, size); //MaximumNumberOfSupportedPacketFilters
/*
ExtendedProtocolDiscriminator extendedprotocoldiscriminator;
PDUSessionIdentity pdusessionidentity;
ProcedureTransactionIdentity proceduretransactionidentity;
MessageType messagetype;
uint16_t presence;
_5GSMCapability _5gsmcapability;
_5GSMCause _5gsmcause;
MaximumNumberOfSupportedPacketFilters maximumnumberofsupportedpacketfilters;
AlwaysonPDUSessionRequested alwaysonpdusessionrequested;
IntergrityProtectionMaximumDataRate intergrityprotectionmaximumdatarate;
QOSRules qosrules;
QOSFlowDescriptions qosflowdescriptions;
MappedEPSBearerContexts mappedepsbearercontexts;
ExtendedProtocolConfigurationOptions extendedprotocolconfigurationoptions;
*/
std::cout << "Buffer: " << std::endl;
for (int i = 0; i < size; i++) {
printf("%02x ", buffer[i]);
}
std::cout << "Buffer: " << std::endl;
std::string url = std::string("http://");
url.append(smf_ip_address);
url.append(std::string("/nsmf-pdusession/v2/sm-contexts/1/modify"));
//Fill the json part
pdu_session_modification_request["pduSessionId"] = 1;
pdu_session_modification_request["n1SmMsg"]["contentId"] = "n1SmMsg"; // NAS
std::string body;
std::string boundary = "----Boundary";
std::string json_part = pdu_session_modification_request.dump();
std::string n1_msg(reinterpret_cast<const char*>(buffer), size);
create_multipart_related_content(body, json_part, boundary, n1_msg,
multipart_related_content_part_e::NAS);
unsigned char *data = (unsigned char*) malloc(body.length() + 1);
memset(data, 0, body.length() + 1);
memcpy((void*) data, (void*) body.c_str(), body.length());
curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl = curl_easy_init();
if (curl) {
CURLcode res = { };
struct curl_slist *headers = nullptr;
//headers = curl_slist_append(headers, "charsets: utf-8");
headers = curl_slist_append(
headers, "content-type: multipart/related; boundary=----Boundary");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 100L);
//curl_easy_setopt(curl, CURLOPT_INTERFACE, "eno1:amf"); //hardcoded
// Response information.
long httpCode = { 0 };
std::unique_ptr<std::string> httpData(new std::string());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
//get cause from the response
nlohmann::json response_data;
try {
response_data = nlohmann::json::parse(*httpData.get());
} catch (nlohmann::json::exception &e) {
std::cout << "Could not get json data from the response" << std::endl;
}
std::cout
<< "[AMF N11] PDU Session Modification Request, response from SMF, Http Code "
<< httpCode << std::endl;
curl_easy_cleanup(curl);
}
curl_global_cleanup();
free(buffer);
}
//------------------------------------------------------------------------------
void send_pdu_session_release_request(std::string smf_ip_address) {
......@@ -879,16 +1015,22 @@ int main(int argc, char *argv[]) {
usleep(100000);
send_pdu_session_update_sm_context_establishment(smf_ip_address);
usleep(200000);
//UE-initiated Service Request
/* //UE-initiated Service Request
send_pdu_session_update_sm_context_ue_service_request(smf_ip_address);
usleep(200000);
send_pdu_session_update_sm_context_ue_service_request_step2(smf_ip_address);
usleep(200000);
*/
//PDU Session Modification
send_pdu_session_modification_request_step1(smf_ip_address);
//PDU Session Release procedure
send_pdu_session_release_request(smf_ip_address);
/* send_pdu_session_release_request(smf_ip_address);
usleep(200000);
send_pdu_session_release_resource_release_ack(smf_ip_address);
usleep(200000);
send_pdu_session_release_complete(smf_ip_address);
usleep(200000);
*/
return 0;
}
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