Skip to content

Commit 354bec7

Browse files
FabianEckermanncodebot
authored andcommitted
cu_cp: Add unittest for amf initiated ue context release
1 parent 24e4ed4 commit 354bec7

File tree

3 files changed

+80
-40
lines changed

3 files changed

+80
-40
lines changed

tests/unittests/cu_cp/cu_cp_test.cpp

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#include "../rrc/rrc_ue_test_messages.h"
1212
#include "cu_cp_test_helpers.h"
13+
#include "srsran/asn1/f1ap/f1ap.h"
14+
#include "srsran/f1ap/common/f1ap_common.h"
15+
#include "srsran/ran/cu_types.h"
1316
#include <gtest/gtest.h>
1417

1518
using namespace srsran;
@@ -420,13 +423,15 @@ TEST_F(cu_cp_test, when_invalid_paging_message_received_then_paging_is_not_sent_
420423
TEST_F(cu_cp_test, when_ue_level_inactivity_message_received_then_ue_context_release_request_is_sent)
421424
{
422425
// Test preamble
423-
du_index_t du_index = uint_to_du_index(0);
424-
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
425-
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
426-
pci_t pci = 0;
427-
rnti_t crnti = to_rnti(0x4601);
428-
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti);
429-
receive_ngap_dl_info_transfer();
426+
du_index_t du_index = uint_to_du_index(0);
427+
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
428+
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
429+
pci_t pci = 0;
430+
rnti_t crnti = to_rnti(0x4601);
431+
amf_ue_id_t amf_ue_id = uint_to_amf_ue_id(
432+
test_rgen::uniform_int<uint64_t>(amf_ue_id_to_uint(amf_ue_id_t::min), amf_ue_id_to_uint(amf_ue_id_t::max)));
433+
ran_ue_id_t ran_ue_id = uint_to_ran_ue_id(0);
434+
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti, amf_ue_id, ran_ue_id);
430435

431436
cu_cp_inactivity_notification inactivity_notification;
432437
inactivity_notification.ue_index = uint_to_ue_index(0);
@@ -446,12 +451,15 @@ TEST_F(cu_cp_test, when_ue_level_inactivity_message_received_then_ue_context_rel
446451
TEST_F(cu_cp_test, when_unsupported_inactivity_message_received_then_ue_context_release_request_is_not_sent)
447452
{
448453
// Test preamble
449-
du_index_t du_index = uint_to_du_index(0);
450-
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
451-
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
452-
rnti_t crnti = to_rnti(0x4601);
453-
pci_t pci = 0;
454-
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti);
454+
du_index_t du_index = uint_to_du_index(0);
455+
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
456+
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
457+
rnti_t crnti = to_rnti(0x4601);
458+
pci_t pci = 0;
459+
amf_ue_id_t amf_ue_id = uint_to_amf_ue_id(
460+
test_rgen::uniform_int<uint64_t>(amf_ue_id_to_uint(amf_ue_id_t::min), amf_ue_id_to_uint(amf_ue_id_t::max)));
461+
ran_ue_id_t ran_ue_id = uint_to_ran_ue_id(0);
462+
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti, amf_ue_id, ran_ue_id);
455463

456464
cu_cp_inactivity_notification inactivity_notification;
457465
inactivity_notification.ue_index = uint_to_ue_index(0);
@@ -464,6 +472,34 @@ TEST_F(cu_cp_test, when_unsupported_inactivity_message_received_then_ue_context_
464472
asn1::ngap::ngap_elem_procs_o::init_msg_c::types_opts::ue_context_release_request);
465473
}
466474

475+
//////////////////////////////////////////////////////////////////////////////////////
476+
/* AMF initiated UE Context Release */
477+
//////////////////////////////////////////////////////////////////////////////////////
478+
479+
TEST_F(cu_cp_test, when_release_command_received_then_release_command_is_sent_to_du)
480+
{
481+
// Test preamble
482+
du_index_t du_index = uint_to_du_index(0);
483+
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
484+
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
485+
rnti_t crnti = to_rnti(0x4601);
486+
pci_t pci = 0;
487+
amf_ue_id_t amf_ue_id = uint_to_amf_ue_id(
488+
test_rgen::uniform_int<uint64_t>(amf_ue_id_to_uint(amf_ue_id_t::min), amf_ue_id_to_uint(amf_ue_id_t::max)));
489+
ran_ue_id_t ran_ue_id = uint_to_ran_ue_id(0);
490+
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti, amf_ue_id, ran_ue_id);
491+
492+
// Inject UE Context Release Command
493+
cu_cp_obj->get_ngap_message_handler().handle_message(
494+
generate_valid_ue_context_release_command_with_amf_ue_ngap_id(amf_ue_id));
495+
496+
// check that the UE Context Release Command with RRC Container was sent to the DU
497+
ASSERT_EQ(f1ap_pdu_notifier.last_f1ap_msg.pdu.type(), asn1::f1ap::f1ap_pdu_c::types_opts::options::init_msg);
498+
ASSERT_EQ(f1ap_pdu_notifier.last_f1ap_msg.pdu.init_msg().value.type().value,
499+
asn1::f1ap::f1ap_elem_procs_o::init_msg_c::types_opts::ue_context_release_cmd);
500+
ASSERT_TRUE(f1ap_pdu_notifier.last_f1ap_msg.pdu.init_msg().value.ue_context_release_cmd()->rrc_container_present);
501+
}
502+
467503
//////////////////////////////////////////////////////////////////////////////////////
468504
/* DU Initiated UE Context Release */
469505
//////////////////////////////////////////////////////////////////////////////////////
@@ -472,13 +508,15 @@ TEST_F(cu_cp_test, when_unsupported_inactivity_message_received_then_ue_context_
472508
TEST_F(cu_cp_test, when_du_initiated_ue_context_release_received_then_ue_context_release_request_is_sent)
473509
{
474510
// Test preamble
475-
du_index_t du_index = uint_to_du_index(0);
476-
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
477-
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
478-
rnti_t crnti = to_rnti(0x4601);
479-
pci_t pci = 0;
480-
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti);
481-
receive_ngap_dl_info_transfer();
511+
du_index_t du_index = uint_to_du_index(0);
512+
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
513+
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
514+
rnti_t crnti = to_rnti(0x4601);
515+
pci_t pci = 0;
516+
amf_ue_id_t amf_ue_id = uint_to_amf_ue_id(
517+
test_rgen::uniform_int<uint64_t>(amf_ue_id_to_uint(amf_ue_id_t::min), amf_ue_id_to_uint(amf_ue_id_t::max)));
518+
ran_ue_id_t ran_ue_id = uint_to_ran_ue_id(0);
519+
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti, amf_ue_id, ran_ue_id);
482520

483521
// Inject UE Context Release Request
484522
cu_cp_obj->get_f1ap_message_handler(uint_to_du_index(0))
@@ -499,13 +537,15 @@ TEST_F(cu_cp_test, when_du_initiated_ue_context_release_received_then_ue_context
499537
TEST_F(cu_cp_test, when_reestablishment_fails_then_ue_released)
500538
{
501539
// Test preamble
502-
du_index_t du_index = uint_to_du_index(0);
503-
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
504-
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
505-
rnti_t crnti = to_rnti(0x4601);
506-
pci_t pci = 0;
507-
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti);
508-
receive_ngap_dl_info_transfer();
540+
du_index_t du_index = uint_to_du_index(0);
541+
gnb_cu_ue_f1ap_id_t cu_ue_id = int_to_gnb_cu_ue_f1ap_id(0);
542+
gnb_du_ue_f1ap_id_t du_ue_id = int_to_gnb_du_ue_f1ap_id(0);
543+
rnti_t crnti = to_rnti(0x4601);
544+
pci_t pci = 0;
545+
amf_ue_id_t amf_ue_id = uint_to_amf_ue_id(
546+
test_rgen::uniform_int<uint64_t>(amf_ue_id_to_uint(amf_ue_id_t::min), amf_ue_id_to_uint(amf_ue_id_t::max)));
547+
ran_ue_id_t ran_ue_id = uint_to_ran_ue_id(0);
548+
test_preamble_ue_creation(du_index, du_ue_id, cu_ue_id, pci, crnti, amf_ue_id, ran_ue_id);
509549

510550
// Attach second UE with RRC Reestablishment Request
511551
{

tests/unittests/cu_cp/cu_cp_test_helpers.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
*/
1010

1111
#include "cu_cp_test_helpers.h"
12+
#include "srsran/e1ap/common/e1ap_common.h"
13+
#include "srsran/ran/cu_types.h"
1214
#include "srsran/support/async/async_test_utils.h"
15+
#include <utility>
1316

1417
using namespace srsran;
1518
using namespace srs_cu_cp;
@@ -67,7 +70,9 @@ void cu_cp_test::test_preamble_ue_creation(du_index_t du_index,
6770
gnb_du_ue_f1ap_id_t du_ue_id,
6871
gnb_cu_ue_f1ap_id_t cu_ue_id,
6972
pci_t pci,
70-
rnti_t crnti)
73+
rnti_t crnti,
74+
amf_ue_id_t amf_ue_id,
75+
ran_ue_id_t ran_ue_id)
7176
{
7277
// Connect AMF by injecting a ng_setup_response
7378
ngap_message ngap_msg = generate_ng_setup_response();
@@ -77,8 +82,11 @@ void cu_cp_test::test_preamble_ue_creation(du_index_t du_index,
7782

7883
// Connect DU (note that this creates a DU processor, but the DU is only connected after the F1Setup procedure)
7984
cu_cp_obj->handle_new_du_connection();
85+
ASSERT_EQ(cu_cp_obj->get_nof_dus(), 1U);
86+
8087
// Connect CU-UP
8188
cu_cp_obj->handle_new_cu_up_connection();
89+
ASSERT_EQ(cu_cp_obj->get_nof_cu_ups(), 1U);
8290

8391
// Generate F1SetupRequest
8492
f1ap_message f1setup_msg = generate_f1_setup_request(pci);
@@ -88,17 +96,9 @@ void cu_cp_test::test_preamble_ue_creation(du_index_t du_index,
8896

8997
// Attach UE
9098
attach_ue(du_ue_id, cu_ue_id, crnti, du_index);
91-
92-
// check that UE has been added
9399
ASSERT_EQ(cu_cp_obj->get_nof_ues(), 1U);
94-
}
95100

96-
void cu_cp_test::receive_ngap_dl_info_transfer()
97-
{
98-
// Inject NGAP DL message using random AMF UE ID
99-
amf_ue_id_t amf_ue_id = uint_to_amf_ue_id(
100-
test_rgen::uniform_int<uint64_t>(amf_ue_id_to_uint(amf_ue_id_t::min), amf_ue_id_to_uint(amf_ue_id_t::max)));
101-
ran_ue_id_t ran_ue_id = uint_to_ran_ue_id(0);
101+
// Inject NGAP DL message
102102
ngap_message dl_nas_transport = generate_downlink_nas_transport_message(amf_ue_id, ran_ue_id);
103103
cu_cp_obj->get_ngap_message_handler().handle_message(dl_nas_transport);
104104
}

tests/unittests/cu_cp/cu_cp_test_helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "lib/cu_cp/cu_cp_impl.h"
1414
#include "test_helpers.h"
15-
#include "tests/unittests/e1ap/common/e1ap_cu_cp_test_messages.h"
1615
#include "tests/unittests/e1ap/common/test_helpers.h"
1716
#include "tests/unittests/f1ap/common/test_helpers.h"
1817
#include "tests/unittests/f1ap/cu_cp/f1ap_cu_test_helpers.h"
@@ -37,8 +36,9 @@ class cu_cp_test : public ::testing::Test
3736
gnb_du_ue_f1ap_id_t du_ue_id,
3837
gnb_cu_ue_f1ap_id_t cu_ue_id,
3938
pci_t pci,
40-
rnti_t crnti);
41-
void receive_ngap_dl_info_transfer();
39+
rnti_t crnti,
40+
amf_ue_id_t amf_ue_id,
41+
ran_ue_id_t ran_ue_id);
4242
bool check_minimal_paging_result();
4343
bool check_paging_result();
4444

0 commit comments

Comments
 (0)