Skip to content

Commit

Permalink
cu_cp,rrc: improve unittests and check for nas pdu in rrc reconfigura…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
FabianEckermann authored and codebot committed Jul 12, 2024
1 parent 5665faf commit 99d1742
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
36 changes: 36 additions & 0 deletions tests/test_doubles/rrc/rrc_test_message_validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,39 @@ bool srsran::test_helpers::is_valid_rrc_security_mode_command(const byte_buffer&
TRUE_OR_RETURN(dcch.unpack(bref) == asn1::SRSASN_SUCCESS);
return is_valid_rrc_security_mode_command(dcch);
}

bool srsran::test_helpers::is_valid_rrc_ue_capability_enquiry(const asn1::rrc_nr::dl_dcch_msg_s& msg)
{
TRUE_OR_RETURN(msg.msg.type().value == asn1::rrc_nr::dl_dcch_msg_type_c::types_opts::c1);
TRUE_OR_RETURN(msg.msg.c1().type().value == asn1::rrc_nr::dl_dcch_msg_type_c::c1_c_::types_opts::ue_cap_enquiry);
TRUE_OR_RETURN(msg.msg.c1().ue_cap_enquiry().crit_exts.type().value ==
asn1::rrc_nr::ue_cap_enquiry_s::crit_exts_c_::types_opts::ue_cap_enquiry);
return true;
}

bool srsran::test_helpers::is_valid_rrc_ue_capability_enquiry(const byte_buffer& dl_dcch_msg)
{
asn1::cbit_ref bref{dl_dcch_msg};
asn1::rrc_nr::dl_dcch_msg_s dcch;
TRUE_OR_RETURN(dcch.unpack(bref) == asn1::SRSASN_SUCCESS);
return is_valid_rrc_ue_capability_enquiry(dcch);
}

bool srsran::test_helpers::is_valid_rrc_reconfiguration(const asn1::rrc_nr::dl_dcch_msg_s& msg)
{
TRUE_OR_RETURN(msg.msg.type().value == asn1::rrc_nr::dl_dcch_msg_type_c::types_opts::c1);
TRUE_OR_RETURN(msg.msg.c1().type().value == asn1::rrc_nr::dl_dcch_msg_type_c::c1_c_::types_opts::rrc_recfg);
TRUE_OR_RETURN(msg.msg.c1().rrc_recfg().crit_exts.type().value ==
asn1::rrc_nr::rrc_recfg_s::crit_exts_c_::types_opts::rrc_recfg);
TRUE_OR_RETURN(msg.msg.c1().rrc_recfg().crit_exts.rrc_recfg().non_crit_ext_present);
TRUE_OR_RETURN(msg.msg.c1().rrc_recfg().crit_exts.rrc_recfg().non_crit_ext.ded_nas_msg_list.size() != 0);
return true;
}

bool srsran::test_helpers::is_valid_rrc_reconfiguration(const byte_buffer& dl_dcch_msg)
{
asn1::cbit_ref bref{dl_dcch_msg};
asn1::rrc_nr::dl_dcch_msg_s dcch;
TRUE_OR_RETURN(dcch.unpack(bref) == asn1::SRSASN_SUCCESS);
return is_valid_rrc_reconfiguration(dcch);
}
8 changes: 8 additions & 0 deletions tests/test_doubles/rrc/rrc_test_message_validators.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ bool is_valid_rrc_reestablishment(const byte_buffer& dl_dcch_msg);
bool is_valid_rrc_security_mode_command(const asn1::rrc_nr::dl_dcch_msg_s& msg);
bool is_valid_rrc_security_mode_command(const byte_buffer& dl_dcch_msg);

/// \brief Check if DL-DCCH message is a valid RRC UE Capability Enquiry message.
bool is_valid_rrc_ue_capability_enquiry(const asn1::rrc_nr::dl_dcch_msg_s& msg);
bool is_valid_rrc_ue_capability_enquiry(const byte_buffer& dl_dcch_msg);

/// \brief Check if DL-DCCH message is a valid RRC Reconfiguration message.
bool is_valid_rrc_reconfiguration(const asn1::rrc_nr::dl_dcch_msg_s& msg);
bool is_valid_rrc_reconfiguration(const byte_buffer& dl_dcch_msg);

} // namespace test_helpers
} // namespace srsran
15 changes: 12 additions & 3 deletions tests/unittests/cu_cp/cu_cp_initial_context_setup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "tests/test_doubles/f1ap/f1ap_test_messages.h"
#include "tests/test_doubles/ngap/ngap_test_message_validators.h"
#include "tests/test_doubles/rrc/rrc_test_message_validators.h"
#include "tests/test_doubles/rrc/rrc_test_messages.h"
#include "tests/unittests/e1ap/common/e1ap_cu_cp_test_messages.h"
#include "tests/unittests/f1ap/common/f1ap_cu_test_messages.h"
#include "tests/unittests/ngap/ngap_test_messages.h"
Expand Down Expand Up @@ -82,7 +81,7 @@ class cu_cp_initial_context_setup_test : public cu_cp_test_environment, public :
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_security_mode_command(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid Security Mode command");
"Invalid Security Mode Command");

// Inject UE Context Setup Response
f1ap_message ue_ctxt_setup_response = generate_ue_context_setup_response(ue_ctx->cu_ue_id.value(), du_ue_id);
Expand All @@ -98,9 +97,13 @@ class cu_cp_initial_context_setup_test : public cu_cp_test_environment, public :

// Wait for UE Capability Enquiry
bool result = this->wait_for_f1ap_tx_pdu(du_idx, f1ap_pdu);
report_fatal_error_if_not(result, "Failed to receive DL RRC Message, containing RRC UE Capability Enquiry");
report_fatal_error_if_not(result, "Failed to receive UE Capability Enquiry");
report_fatal_error_if_not(test_helpers::is_valid_dl_rrc_message_transfer(f1ap_pdu),
"Invalid DL RRC Message Transfer");
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_ue_capability_enquiry(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid UE Capability Enquiry");
}

void send_ue_capability_info_and_await_registration_accept_and_initial_context_setup_response()
Expand Down Expand Up @@ -169,6 +172,12 @@ class cu_cp_initial_context_setup_test : public cu_cp_test_environment, public :
report_fatal_error_if_not(result, "Failed to receive F1AP DL RRC Message (containing RRC Reconfiguration)");
report_fatal_error_if_not(test_helpers::is_valid_dl_rrc_message_transfer(f1ap_pdu),
"Invalid DL RRC Message Transfer");

// Make sure RRC Reconfiguration contains NAS PDU
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_reconfiguration(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid RRC Reconfiguration");
}

void send_rrc_reconfiguration_complete_and_await_initial_context_setup_response()
Expand Down
22 changes: 18 additions & 4 deletions tests/unittests/cu_cp/cu_cp_test_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,12 @@ bool cu_cp_test_environment::setup_ue_security(unsigned du_idx, gnb_du_ue_f1ap_i
report_fatal_error_if_not(result, "Failed to receive Security Mode Command");
report_fatal_error_if_not(test_helpers::is_valid_ue_context_setup_request(f1ap_pdu),
"Invalid UE Context Setup Request");
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_security_mode_command(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid Security Mode command");
{
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_security_mode_command(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid Security Mode command");
}

// Inject UE Context Setup Response
f1ap_message ue_ctxt_setup_response = generate_ue_context_setup_response(ue_ctx.cu_ue_id.value(), du_ue_id);
Expand All @@ -405,6 +407,12 @@ bool cu_cp_test_environment::setup_ue_security(unsigned du_idx, gnb_du_ue_f1ap_i
report_fatal_error_if_not(result, "Failed to receive DL RRC Message, containing RRC UE Capability Enquiry");
report_fatal_error_if_not(test_helpers::is_valid_dl_rrc_message_transfer(f1ap_pdu),
"Invalid DL RRC Message Transfer");
{
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_ue_capability_enquiry(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid UE Capability Enquiry");
}

// Inject UL RRC Message Transfer (containing UE Capability Info)
get_du(du_idx).push_ul_pdu(test_helpers::create_ul_rrc_message_transfer(
Expand Down Expand Up @@ -520,6 +528,12 @@ bool cu_cp_test_environment::attach_ue(unsigned du_idx,
report_fatal_error_if_not(result, "Failed to receive F1AP DL RRC Message (containing RRC Reconfiguration)");
report_fatal_error_if_not(test_helpers::is_valid_dl_rrc_message_transfer(f1ap_pdu),
"Invalid DL RRC Message Transfer");
{
const byte_buffer& rrc_container = test_helpers::get_rrc_container(f1ap_pdu);
report_fatal_error_if_not(
test_helpers::is_valid_rrc_reconfiguration(test_helpers::extract_dl_dcch_msg(rrc_container)),
"Invalid RRC Reconfiguration");
}

// Inject RRC Reconfiguration Complete and wait for PDU Session Resource Setup Response to be sent to AMF.
get_du(du_idx).push_ul_pdu(test_helpers::create_ul_rrc_message_transfer(
Expand Down

0 comments on commit 99d1742

Please sign in to comment.