Commit 9a00386f authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Merge branch 'padding_issue_ngap_msg' into 'develop'

Fix padding issue for NGAP, NAS messages

See merge request oai/oai-cn5g-smf!13
parents e08a5729 e062b8f8
......@@ -203,7 +203,7 @@ install_nlohmann_from_git() {
install_nghttp2_from_git() {
if [ $1 -eq 0 ]; then
read -p "Do you want to install nghttp2 ? <y/N> " prompt
OPTION="-y"
OPTION=""
else
prompt='y'
OPTION="-y"
......@@ -260,8 +260,7 @@ install_nghttp2_from_git() {
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
popd
fi
return 0
return 0
}
#-------------------------------------------------------------------------------
......@@ -401,8 +400,6 @@ check_install_smf_deps() {
install_nghttp2_from_git $1 $2
ret=$?;[[ $ret -ne 0 ]] && return $ret
$SUDO /sbin/ldconfig -v
ret=$?;[[ $ret -ne 0 ]] && return $ret
return 0
}
......
......@@ -41,8 +41,8 @@ Based on document **3GPP TS 23.501 v16.0.0 §6.2.2**.
| 1 | Session Management (Session Establishment/Modification/Release) | :heavy_check_mark: | |
| 2 | UE IP address allocation & management​ | :heavy_check_mark: | Only support static ipv4 address allocation |
| 3 | DHCPv4 (server and client) and DHCPv6 (server and client) function | :x: | |
| 4 | Respond to ARP requests and/or IPv6 Neighbour Solicitation requests | :x: | Local configuration in SMF |
| 5 | Selection of UPF function​ | :x: | |
| 4 | Respond to ARP requests and/or IPv6 Neighbour Solicitation requests | :x: | |
| 5 | Selection of UPF function​ | :heavy_check_mark: | Local configuration in SMF |
| 6 | Configures traffic steering at UPF | :x: | |
| 7 | Termination of interfaces towards PCFs | :x: | |
| 8 | Lawful intercept | :x: | |
......@@ -55,5 +55,3 @@ Based on document **3GPP TS 23.501 v16.0.0 §6.2.2**.
| 15 | Support of header compression. ​ | :x: | |
| 16 | Act as I-SMF in deployments | :x: | |
| 17 | Provisioning of external parameters | :x: | |
......@@ -19,6 +19,14 @@
* contact@openairinterface.org
*/
/*! \file smf_http2-server.cpp
\brief
\author Tien-Thinh NGUYEN
\company Eurecom
\date 2020
\email: tien-thinh.nguyen@eurecom.fr
*/
#include "smf-http2-server.h"
#include <string>
#include <boost/algorithm/string.hpp>
......
......@@ -19,6 +19,14 @@
* contact@openairinterface.org
*/
/*! \file smf_http2-server.h
\brief
\author Tien-Thinh NGUYEN
\company Eurecom
\date 2020
\email: tien-thinh.nguyen@eurecom.fr
*/
#ifndef FILE_SMF_HTTP2_SERVER_SEEN
#define FILE_SMF_HTTP2_SERVER_SEEN
......
......@@ -64,10 +64,8 @@ void mime_parser::get_mime_parts(std::vector<mime_part> &parts) const {
for (auto it : mime_parts) {
parts.push_back(it);
}
}
//---------------------------------------------------------------------------------------------
unsigned char* mime_parser::format_string_as_hex(const std::string &str) {
unsigned int str_len = str.length();
......@@ -101,6 +99,8 @@ void mime_parser::create_multipart_related_content(std::string &body,
const std::string &n1_message,
const std::string &n2_message) {
//TODO: provide Content-Ids as function parameters
//format string as hex
unsigned char *n1_msg_hex = format_string_as_hex(n1_message);
unsigned char *n2_msg_hex = format_string_as_hex(n2_message);
......@@ -131,6 +131,7 @@ void mime_parser::create_multipart_related_content(
std::string &body, const std::string &json_part, const std::string boundary,
const std::string &message, const multipart_related_content_part_e content_type) {
//TODO: provide Content-Id as function parameters
//format string as hex
unsigned char *msg_hex = format_string_as_hex(message);
......
......@@ -186,10 +186,10 @@ int nas_message_encode(unsigned char *buffer, const nas_message_t *const msg,
if (bytes < 0) {
return bytes;
}
// if (size > 1) {
// return size + bytes;
// }
if (size > 1) {
return size + bytes;
}
return bytes;
}
......
......@@ -24,8 +24,8 @@ typedef struct asn_per_constraint_s {
} flags;
int range_bits; /* Full number of bits in the range */
int effective_bits; /* Effective bits */
long lower_bound; /* "lb" value */
long upper_bound; /* "ub" value */
long long lower_bound; /* "lb" value */
long long upper_bound; /* "ub" value */
} asn_per_constraint_t;
typedef struct asn_per_constraints_s {
asn_per_constraint_t value;
......
......@@ -46,6 +46,7 @@ itti_mw *itti_inst = nullptr;
async_shell_cmd *async_shell_cmd_inst = nullptr;
smf_app *smf_app_inst = nullptr;
smf_config smf_cfg;
SMFApiServer *smf_api_server_1 = nullptr;
void send_heartbeat_to_tasks(const uint32_t sequence);
......@@ -73,7 +74,9 @@ void my_app_signal_handler(int s)
if (itti_inst) delete itti_inst; itti_inst = nullptr;
std::cout << "ITTI memory done." << std::endl;
if (smf_app_inst) delete smf_app_inst; smf_app_inst = nullptr;
std::cout << "PGW APP memory done." << std::endl;
std::cout << "SMF APP memory done." << std::endl;
smf_api_server_1->shutdown();
if (smf_api_server_1) delete smf_api_server_1; smf_api_server_1 = nullptr;
std::cout << "Freeing Allocated memory done" << std::endl;
exit(0);
}
......@@ -124,13 +127,15 @@ int main(int argc, char **argv)
//SMF Pistache API server (HTTP1)
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&smf_cfg.sbi.addr4))) , Pistache::Port(smf_cfg.sbi.port));
SMFApiServer smfApiServer(addr, smf_app_inst);
smfApiServer.init(2);
std::thread smf_api_manager(&SMFApiServer::start, smfApiServer);
SMFApiServer *smf_api_server_1 = new SMFApiServer(addr, smf_app_inst);
smf_api_server_1->init(2);
smf_api_server_1->start();
//std::thread smf_api_manager(&SMFApiServer::start, smf_api_server_1);
//SMF NGHTTP API server (HTTP2)
smf_http2_server *smf_server = new smf_http2_server(conv::toString(smf_cfg.sbi.addr4), smf_cfg.sbi_http2_port, smf_app_inst);
std::thread smf_api(&smf_http2_server::start, smf_server);
smf_http2_server *smf_api_server_2 = new smf_http2_server(conv::toString(smf_cfg.sbi.addr4), smf_cfg.sbi_http2_port, smf_app_inst);
smf_api_server_2->start();
//std::thread smf_api(&smf_http2_server::start, smf_api_server_2);
FILE *fp = NULL;
std::string filename = fmt::format("/tmp/smf_{}.status", getpid());
......
......@@ -77,9 +77,7 @@ void smf_n1_n2::create_n1_sm_container(pdu_session_msg &msg,
n1_msg_type);
int bytes = { 0 };
unsigned char data[BUF_LEN] = { '\0' };
memset(data, 0, sizeof(data));
nas_message_t nas_msg = { };
memset(&nas_msg, 0, sizeof(nas_message_t));
nas_msg.header.extended_protocol_discriminator =
EPD_5GS_SESSION_MANAGEMENT_MESSAGES;
......@@ -187,7 +185,6 @@ void smf_n1_n2::create_n1_sm_container(pdu_session_msg &msg,
//Presence
sm_msg->pdu_session_establishment_accept.presence = 0xffff; //TODO: To be updated
//_5GSMCause
//sm_msg->pdu_session_establishment_accept._5gsmcause = sm_context_res.get_cause();
sm_msg->pdu_session_establishment_accept._5gsmcause =
static_cast<uint8_t>(sm_cause);
Logger::smf_app().debug(
......@@ -581,7 +578,6 @@ void smf_n1_n2::create_n1_sm_container(pdu_session_msg &msg,
std::string n1Message((char*) data, bytes);
nas_msg_str = n1Message;
}
break;
......@@ -623,7 +619,6 @@ void smf_n1_n2::create_n1_sm_container(pdu_session_msg &msg,
std::string n1Message((char*) data, bytes);
nas_msg_str = n1Message;
}
break;
......@@ -631,9 +626,7 @@ void smf_n1_n2::create_n1_sm_container(pdu_session_msg &msg,
Logger::smf_app().debug("Unknown PDU Session Type");
//TODO:
}
} //end Switch
}
//------------------------------------------------------------------------------
......@@ -641,7 +634,6 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
uint8_t ngap_msg_type,
n2_sm_info_type_e ngap_ie_type,
std::string &ngap_msg_str) {
//TODO: To be filled with the correct parameters
Logger::smf_app().info(
"Create N2 SM Information, NGAP message type %d, IE type %d",
ngap_msg_type, ngap_ie_type);
......@@ -725,6 +717,7 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
pduSessionAggregateMaximumBitRate->criticality = Ngap_Criticality_reject;
pduSessionAggregateMaximumBitRate->value.present =
Ngap_PDUSessionResourceSetupRequestTransferIEs__value_PR_PDUSessionAggregateMaximumBitRate;
asn_set_empty(&ngap_IEs->protocolIEs.list);
//SessionAMBR
supi_t supi = msg.get_supi();
......@@ -743,6 +736,7 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
"SMF context with SUPI " SUPI_64_FMT " does not exist!", supi64);
//TODO:
}
ASN_SEQUENCE_ADD(&ngap_IEs->protocolIEs.list,
pduSessionAggregateMaximumBitRate);
......@@ -867,6 +861,8 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
Ngap_Pre_emptionVulnerability_pre_emptable;
}
asn_set_empty(
&qosFlowSetupRequestList->value.choice.QosFlowSetupRequestList.list);
ASN_SEQUENCE_ADD(
&qosFlowSetupRequestList->value.choice.QosFlowSetupRequestList.list,
ngap_QosFlowSetupRequestItem);
......@@ -874,30 +870,32 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
Logger::smf_app().info(
"QoS parameters: QFI %d, ARP priority level %d, qos_flow.qos_profile.arp.preempt_cap %s, qos_flow.qos_profile.arp.preempt_vuln %s",
qos_flow.qfi.qfi, qos_flow.qos_profile.arp.priority_level,qos_flow.qos_profile.arp.preempt_cap.c_str(), qos_flow.qos_profile.arp.preempt_vuln.c_str());
qos_flow.qfi.qfi, qos_flow.qos_profile.arp.priority_level,
qos_flow.qos_profile.arp.preempt_cap.c_str(),
qos_flow.qos_profile.arp.preempt_vuln.c_str());
//encode
size_t buffer_size = BUF_LEN;
char *buffer = (char*) calloc(1, buffer_size);
asn_enc_rval_t er = aper_encode_to_buffer(
ssize_t encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_PDUSessionResourceSetupRequestTransfer, nullptr,
ngap_IEs, (void*) buffer, buffer_size);
if (er.encoded < 0) {
ngap_IEs, (void**) &buffer);
if (encoded_size < 0) {
Logger::smf_app().warn(
"NGAP PDU Session Resource Setup Request Transfer encode failed, er.encoded: %d",
er.encoded);
"NGAP PDU Session Resource Setup Request Transfer encode failed (encode size %d)",
encoded_size);
return;
}
#if DEBUG_IS_ON
Logger::smf_app().debug("N2 SM buffer data: ");
for (int i = 0; i < er.encoded; i++)
for (int i = 0; i < encoded_size; i++)
printf("%02x ", (char) buffer[i]);
printf(" (%d bytes)\n", (int) er.encoded);
printf(" (%d bytes)\n", (int) encoded_size);
#endif
std::string ngap_message((char*) buffer, er.encoded);
std::string ngap_message((char*) buffer, encoded_size);
ngap_msg_str = ngap_message;
//free memory
......@@ -921,7 +919,6 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
free_wrapper((void**) &ngap_QosFlowSetupRequestItem);
free_wrapper((void**) &ngap_IEs);
free_wrapper((void**) &buffer);
}
break;
......@@ -1157,24 +1154,24 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
size_t buffer_size = BUF_LEN;
char *buffer = (char*) calloc(1, buffer_size);
asn_enc_rval_t er = aper_encode_to_buffer(
ssize_t encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_PDUSessionResourceModifyRequestTransfer, nullptr,
ngap_IEs, (void*) buffer, buffer_size);
if (er.encoded < 0) {
ngap_IEs, (void**) &buffer);
if (encoded_size < 0) {
Logger::smf_app().warn(
"[Create N2 SM Information] NGAP PDU Session Resource Modify Request Transfer encode failed, er.encoded: %d",
er.encoded);
"NGAP PDU Session Resource Modify Request Transfer encode failed (encoded size %d)",
encoded_size);
return;
}
#if DEBUG_IS_ON
Logger::smf_app().debug("N2 SM buffer data: ");
for (int i = 0; i < er.encoded; i++)
for (int i = 0; i < encoded_size; i++)
printf("%02x ", (char) buffer[i]);
printf(" (%d bytes)\n", (int) er.encoded);
printf(" (%d bytes)\n", (int) encoded_size);
#endif
std::string ngap_message((char*) buffer, er.encoded);
std::string ngap_message((char*) buffer, encoded_size);
ngap_msg_str = ngap_message;
//free memory
......@@ -1208,8 +1205,7 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
break;
case n2_sm_info_type_e::PDU_RES_SETUP_RSP: {
//PDU Session Resource Setup Response Transfer
//for testing purpose
//PDU Session Resource Setup Response Transfer for testing purpose
Logger::smf_app().debug(
"[Create N2 SM Information] NGAP PDU Session Resource Setup Response Transfer");
......@@ -1282,24 +1278,24 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
size_t buffer_size = BUF_LEN;
char *buffer = (char*) calloc(1, buffer_size);
asn_enc_rval_t er = aper_encode_to_buffer(
ssize_t encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_PDUSessionResourceSetupResponseTransfer, nullptr,
ngap_resource_response_transfer, (void*) buffer, buffer_size);
if (er.encoded < 0) {
ngap_resource_response_transfer, (void**) &buffer);
if (encoded_size < 0) {
Logger::smf_app().warn(
"[Create N2 SM Information] NGAP PDU Session Resource Setup Response Transfer encode failed, er.encoded: %d",
er.encoded);
"NGAP PDU Session Resource Setup Response Transfer encode failed (encoded size %d)",
encoded_size);
return;
}
#if DEBUG_IS_ON
Logger::smf_app().debug("N2 SM buffer data: ");
for (int i = 0; i < er.encoded; i++)
for (int i = 0; i < encoded_size; i++)
printf("%02x ", (char) buffer[i]);
Logger::smf_app().debug(" (%d bytes) \n", er.encoded);
Logger::smf_app().debug(" (%d bytes) \n", encoded_size);
#endif
std::string ngap_message((char*) buffer, er.encoded);
std::string ngap_message((char*) buffer, encoded_size);
ngap_msg_str = ngap_message;
//free memory
......@@ -1320,12 +1316,10 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
break;
case n2_sm_info_type_e::PDU_RES_MOD_RSP: {
//PDU Session Resource Modify Response Transfer IE
//for testing purpose
//PDU Session Resource Modify Response Transfer IE for testing purpose
Logger::smf_app().debug(
"[Create N2 SM Information] NGAP PDU Session Resource Modify Response Transfer");
//struct Ngap_UPTransportLayerInformation *dL_NGU_UP_TNLInformation; /* OPTIONAL */
//struct Ngap_UPTransportLayerInformation *uL_NGU_UP_TNLInformation; /* OPTIONAL */
//struct Ngap_QosFlowAddOrModifyResponseList *qosFlowAddOrModifyResponseList; /* OPTIONAL */
......@@ -1394,24 +1388,24 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
size_t buffer_size = BUF_LEN;
char *buffer = (char*) calloc(1, buffer_size);
asn_enc_rval_t er = aper_encode_to_buffer(
ssize_t encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_PDUSessionResourceModifyResponseTransfer, nullptr,
ngap_resource_response_transfer, (void*) buffer, buffer_size);
if (er.encoded < 0) {
ngap_resource_response_transfer, (void**) &buffer);
if (encoded_size < 0) {
Logger::smf_app().warn(
"[Create N2 SM Information] NGAP PDU Session Resource Modify Response Transfer encode failed, er.encoded: %d",
er.encoded);
" NGAP PDU Session Resource Modify Response Transfer encode failed (encoded size %d)",
encoded_size);
return;
}
#if DEBUG_IS_ON
Logger::smf_app().debug("N2 SM buffer data: ");
for (int i = 0; i < er.encoded; i++)
for (int i = 0; i < encoded_size; i++)
printf("%02x ", (char) buffer[i]);
Logger::smf_app().debug(" (%d bytes) \n", er.encoded);
Logger::smf_app().debug(" (%d bytes) \n", encoded_size);
#endif
std::string ngap_message((char*) buffer, er.encoded);
std::string ngap_message((char*) buffer, encoded_size);
ngap_msg_str = ngap_message;
//free memory
......@@ -1439,7 +1433,6 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
//This IE is included in the following messages:
//1 - PDU Session Update SM Context Response (PDU Session Release UE-Initiated: section 4.3.4@3GPP TS 23.502, step 1)
//2 - N1N2MessageTransfer Request​ (PDU Session Release SMF-Requested, step 1)
//TODO:
Ngap_PDUSessionResourceReleaseCommandTransfer_t *ngap_resource_release_command_transfer =
nullptr;
......@@ -1471,31 +1464,29 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
size_t buffer_size = BUF_LEN;
char *buffer = (char*) calloc(1, buffer_size);
asn_enc_rval_t er = aper_encode_to_buffer(
ssize_t encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_PDUSessionResourceReleaseCommandTransfer, nullptr,
ngap_resource_release_command_transfer, (void*) buffer, buffer_size);
if (er.encoded < 0) {
ngap_resource_release_command_transfer, (void**) &buffer);
if (encoded_size < 0) {
Logger::smf_app().warn(
"[Create N2 SM Information] NGAP PDU Session Release Command encode failed, er.encoded: %d",
er.encoded);
"NGAP PDU Session Release Command encode failed (encoded size %d)",
encoded_size);
return;
}
#if DEBUG_IS_ON
Logger::smf_app().debug("N2 SM buffer data: ");
for (int i = 0; i < er.encoded; i++)
for (int i = 0; i < encoded_size; i++)
printf("%02x ", (char) buffer[i]);
Logger::smf_app().debug(" (%d bytes) \n", er.encoded);
Logger::smf_app().debug(" (%d bytes) \n", encoded_size);
#endif
std::string ngap_message((char*) buffer, er.encoded);
std::string ngap_message((char*) buffer, encoded_size);
ngap_msg_str = ngap_message;
//free memory
free_wrapper((void**) &ngap_resource_release_command_transfer);
free_wrapper((void**) &buffer);
}
break;
......@@ -1517,31 +1508,29 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
size_t buffer_size = BUF_LEN;
char *buffer = (char*) calloc(1, buffer_size);
asn_enc_rval_t er = aper_encode_to_buffer(
ssize_t encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_PDUSessionResourceReleaseResponseTransfer, nullptr,
ngap_resource_release_response_transfer, (void*) buffer, buffer_size);
if (er.encoded < 0) {
ngap_resource_release_response_transfer, (void**) &buffer);
if (encoded_size < 0) {
Logger::smf_app().warn(
"[Create N2 SM Information] NGAP PDU Session Release Command encode failed, er.encoded: %d",
er.encoded);
"NGAP PDU Session Release Command encode failed (encoded size %d)",
encoded_size);
return;
}
#if DEBUG_IS_ON
Logger::smf_app().debug("N2 SM buffer data: ");
for (int i = 0; i < er.encoded; i++)
for (int i = 0; i < encoded_size; i++)
printf("%02x ", (char) buffer[i]);
Logger::smf_app().debug(" (%d bytes) \n", er.encoded);
Logger::smf_app().debug(" (%d bytes) \n", encoded_size);
#endif
std::string ngap_message((char*) buffer, er.encoded);
std::string ngap_message((char*) buffer, encoded_size);
ngap_msg_str = ngap_message;
//free memory
free_wrapper((void**) &ngap_resource_release_response_transfer);
free_wrapper((void**) &buffer);
}
break;
......@@ -1549,7 +1538,6 @@ void smf_n1_n2::create_n2_sm_information(pdu_session_msg &msg,
Logger::smf_app().warn("Unknown NGAP IE type: %s \n",
n2_sm_info_type_e2str[(uint8_t) ngap_ie_type]);
}
}
//------------------------------------------------------------------------------
......@@ -1618,10 +1606,9 @@ int smf_n1_n2::decode_n2_sm_information(
if (rc.code != RC_OK) {
Logger::smf_app().warn("asn_decode failed with code %d", rc.code);
return RETURNerror ;
return RETURNerror;
}
return RETURNok ;
return RETURNok;
}
//---------------------------------------------------------------------------------------------
......@@ -1648,10 +1635,9 @@ int smf_n1_n2::decode_n2_sm_information(
if (rc.code != RC_OK) {
Logger::smf_app().warn("asn_decode failed with code %d", rc.code);
return RETURNerror ;
return RETURNerror;
}
return RETURNok ;
return RETURNok;
}
//---------------------------------------------------------------------------------------------
......@@ -1678,14 +1664,11 @@ int smf_n1_n2::decode_n2_sm_information(
if (rc.code != RC_OK) {
Logger::smf_app().warn("asn_decode failed with code %d", rc.code);
return RETURNerror ;
return RETURNerror;
}
return RETURNok ;
return RETURNok;
}
//---------------------------------------------------------------------------------------------
int smf_n1_n2::decode_n2_sm_information(
std::shared_ptr<Ngap_PDUSessionResourceSetupUnsuccessfulTransfer_t> &ngap_IE,
......@@ -1710,8 +1693,7 @@ int smf_n1_n2::decode_n2_sm_information(
if (rc.code != RC_OK) {
Logger::smf_app().warn("asn_decode failed with code %d", rc.code);
return RETURNerror ;
return RETURNerror;
}
return RETURNok ;
return RETURNok;
}
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