Skip to content

Commit 81a9483

Browse files
FabianEckermannFabian Eckermann
authored andcommitted
cu_cp: improve initial ue creation
1 parent a91b8a9 commit 81a9483

File tree

11 files changed

+219
-97
lines changed

11 files changed

+219
-97
lines changed

lib/cu_cp/du_processor/du_processor_impl.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -159,50 +159,47 @@ bool du_processor_impl::create_rrc_ue(cu_cp_ue& ue,
159159
ue_rrc_context_creation_outcome
160160
du_processor_impl::handle_ue_rrc_context_creation_request(const ue_rrc_context_creation_request& req)
161161
{
162-
srsran_assert(req.c_rnti != rnti_t::INVALID_RNTI, "ue={}: Invalid C-RNTI", req.ue_index);
162+
srsran_assert(req.c_rnti != rnti_t::INVALID_RNTI, "ue={} c-rnti={}: Invalid C-RNTI", req.ue_index, req.c_rnti);
163+
164+
// Check that creation message is valid
165+
const du_cell_configuration* pcell = cfg.du_cfg_hdlr->get_context().find_cell(req.cgi);
166+
if (pcell == nullptr) {
167+
logger.warning("ue={} c-rnti={}: Could not find cell with NCI={}", req.ue_index, req.c_rnti, req.cgi.nci);
168+
// Return the RRCReject container
169+
return make_unexpected(rrc_du_adapter.on_rrc_reject_required());
170+
}
171+
const pci_t pci = pcell->pci;
163172

164173
ue_index_t ue_index = req.ue_index;
174+
cu_cp_ue* ue = nullptr;
165175

166176
if (ue_index == ue_index_t::invalid) {
167177
// Add new CU-CP UE
168-
ue_index = ue_mng.add_ue(cfg.du_index);
178+
ue_index = ue_mng.add_ue(cfg.du_index, cfg.du_cfg_hdlr->get_context().id, pci, req.c_rnti, pcell->cell_index);
169179
if (ue_index == ue_index_t::invalid) {
170180
logger.warning("CU-CP UE creation failed");
171181
return make_unexpected(rrc_du_adapter.on_rrc_reject_required());
172182
}
183+
ue = ue_mng.find_ue(ue_index);
173184

174185
/// NOTE: From this point on the UE exists in the UE manager and must be removed if any error occurs.
175-
}
176-
177-
// Lambda, that removes the UE from the UE manager and returns a RRCReject container.
178-
auto return_failure = [this](ue_index_t ue_id) {
179-
// Remove the UE from the UE manager
180-
ue_mng.remove_ue(ue_id);
181-
// Return the RRCReject container
182-
return make_unexpected(rrc_du_adapter.on_rrc_reject_required());
183-
};
184186

185-
// Check that creation message is valid
186-
const du_cell_configuration* pcell = cfg.du_cfg_hdlr->get_context().find_cell(req.cgi);
187-
if (pcell == nullptr) {
188-
logger.warning("ue={}: Could not find cell with NCI={}", ue_index, req.cgi.nci);
189-
return return_failure(ue_index);
190-
}
191-
const pci_t pci = pcell->pci;
192-
193-
// Create new UE RRC context
194-
cu_cp_ue* ue = ue_mng.set_ue_du_context(ue_index, cfg.du_cfg_hdlr->get_context().id, pci, req.c_rnti);
195-
if (ue == nullptr) {
196-
logger.warning("ue={}: Could not create UE context", ue_index);
197-
// A UE with the same PCI and RNTI already exists, so we don't remove it and only reject the new UE.
198-
return make_unexpected(rrc_du_adapter.on_rrc_reject_required());
187+
} else {
188+
ue = ue_mng.set_ue_du_context(ue_index, cfg.du_cfg_hdlr->get_context().id, pci, req.c_rnti, pcell->cell_index);
189+
if (ue == nullptr) {
190+
logger.warning("ue={}: Could not create UE context", ue_index);
191+
// A UE with the same PCI and RNTI already exists, so we don't remove it and only reject the new UE.
192+
return make_unexpected(rrc_du_adapter.on_rrc_reject_required());
193+
}
199194
}
200-
ue->set_pcell_index(pcell->cell_index);
201195

202196
// Create RRC UE. If the DU-to-CU-RRC-Container is empty, the UE will be rejected.
203197
if (not create_rrc_ue(*ue, req.c_rnti, req.cgi, req.du_to_cu_rrc_container.copy(), std::move(req.prev_context))) {
204198
logger.warning("ue={}: Could not create RRC UE object", ue_index);
205-
return return_failure(ue_index);
199+
// Remove the UE from the UE manager
200+
ue_mng.remove_ue(ue_index);
201+
// Return the RRCReject container
202+
return make_unexpected(rrc_du_adapter.on_rrc_reject_required());
206203
}
207204
rrc_ue_interface* rrc_ue = rrc->find_ue(ue_index);
208205
f1ap_rrc_ue_adapters[ue_index] = {};

lib/cu_cp/ue_manager/cu_cp_ue_impl.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,30 @@ cu_cp_ue::cu_cp_ue(ue_index_t ue_index_,
1818
const up_resource_manager_cfg& up_cfg,
1919
const security_manager_config& sec_cfg,
2020
ue_task_scheduler_impl task_sched_,
21-
pci_t pci_,
22-
rnti_t c_rnti_) :
21+
std::optional<gnb_du_id_t> du_id_,
22+
std::optional<pci_t> pci_,
23+
std::optional<rnti_t> c_rnti_,
24+
std::optional<du_cell_index_t> pcell_index_) :
2325
ue_index(ue_index_),
2426
task_sched(std::move(task_sched_)),
2527
up_mng(up_cfg),
2628
sec_mng(sec_cfg),
2729
rrc_ue_cu_cp_ev_notifier(ue_index)
2830
{
29-
if (pci_ != INVALID_PCI) {
30-
pci = pci_;
31+
if (du_id_.has_value() && du_id_.value() != gnb_du_id_t::invalid) {
32+
ue_ctxt.du_id = du_id_.value();
3133
}
3234

33-
if (c_rnti_ != rnti_t::INVALID_RNTI) {
34-
ue_ctxt.crnti = c_rnti_;
35+
if (pci_.has_value() && pci_.value() != INVALID_PCI) {
36+
pci = pci_.value();
37+
}
38+
39+
if (c_rnti_.has_value() && c_rnti_.value() != rnti_t::INVALID_RNTI) {
40+
ue_ctxt.crnti = c_rnti_.value();
41+
}
42+
43+
if (pcell_index_.has_value() && pcell_index_.value() != du_cell_index_t::invalid) {
44+
pcell_index = pcell_index_.value();
3545
}
3646

3747
ue_ctxt.du_idx = du_index_;
@@ -41,7 +51,7 @@ cu_cp_ue::cu_cp_ue(ue_index_t ue_index_,
4151
}
4252

4353
/// \brief Update a UE with PCI and/or C-RNTI.
44-
void cu_cp_ue::update_du_ue(gnb_du_id_t du_id_, pci_t pci_, rnti_t c_rnti_)
54+
void cu_cp_ue::update_du_ue(gnb_du_id_t du_id_, pci_t pci_, rnti_t c_rnti_, du_cell_index_t pcell_index_)
4555
{
4656
if (du_id_ != gnb_du_id_t::invalid) {
4757
ue_ctxt.du_id = du_id_;
@@ -54,6 +64,10 @@ void cu_cp_ue::update_du_ue(gnb_du_id_t du_id_, pci_t pci_, rnti_t c_rnti_)
5464
if (c_rnti_ != rnti_t::INVALID_RNTI) {
5565
ue_ctxt.crnti = c_rnti_;
5666
}
67+
68+
if (pcell_index_ != du_cell_index_t::invalid) {
69+
pcell_index = pcell_index_;
70+
}
5771
}
5872

5973
/// \brief Set/update the measurement context of the UE.

lib/cu_cp/ue_manager/cu_cp_ue_impl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "../up_resource_manager/up_resource_manager_impl.h"
1919
#include "cu_cp_ue_impl_interface.h"
2020
#include "ue_task_scheduler_impl.h"
21+
#include <optional>
2122
#include <unordered_map>
2223

2324
namespace srsran {
@@ -43,8 +44,10 @@ class cu_cp_ue : public cu_cp_ue_impl_interface
4344
const up_resource_manager_cfg& up_cfg,
4445
const security_manager_config& sec_cfg,
4546
ue_task_scheduler_impl task_sched_,
46-
pci_t pci_ = INVALID_PCI,
47-
rnti_t c_rnti_ = rnti_t::INVALID_RNTI);
47+
std::optional<gnb_du_id_t> du_id_ = std::nullopt,
48+
std::optional<pci_t> pci_ = std::nullopt,
49+
std::optional<rnti_t> c_rnti_ = std::nullopt,
50+
std::optional<du_cell_index_t> pcell_index_ = std::nullopt);
4851

4952
/// \brief Cancel all pending UE tasks.
5053
void stop();
@@ -82,9 +85,10 @@ class cu_cp_ue : public cu_cp_ue_impl_interface
8285
cell_meas_manager_ue_context& get_meas_context() { return meas_context; }
8386

8487
/// \brief Update a UE with PCI and/or C-RNTI.
85-
void update_du_ue(gnb_du_id_t du_id_ = gnb_du_id_t::invalid,
86-
pci_t pci_ = INVALID_PCI,
87-
rnti_t c_rnti_ = rnti_t::INVALID_RNTI);
88+
void update_du_ue(gnb_du_id_t du_id_ = gnb_du_id_t::invalid,
89+
pci_t pci_ = INVALID_PCI,
90+
rnti_t c_rnti_ = rnti_t::INVALID_RNTI,
91+
du_cell_index_t pcell_index_ = du_cell_index_t::invalid);
8892

8993
/// \brief Set/update the measurement context of the UE.
9094
void update_meas_context(cell_meas_manager_ue_context meas_ctxt);

lib/cu_cp/ue_manager/ue_manager_impl.cpp

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,37 @@ void ue_manager::stop()
3333
ue_task_scheds.stop();
3434
}
3535

36-
ue_index_t ue_manager::add_ue(du_index_t du_index)
36+
ue_index_t ue_manager::add_ue(du_index_t du_index,
37+
std::optional<gnb_du_id_t> du_id,
38+
std::optional<pci_t> pci,
39+
std::optional<rnti_t> rnti,
40+
std::optional<du_cell_index_t> pcell_index)
3741
{
42+
if (du_index == du_index_t::invalid) {
43+
logger.warning("CU-CP UE creation Failed. Cause: Invalid DU index={}", du_index);
44+
return ue_index_t::invalid;
45+
}
46+
47+
if (du_id.has_value() && du_id.value() == gnb_du_id_t::invalid) {
48+
logger.warning("CU-CP UE creation Failed. Cause: Invalid gNB-DU ID={}", du_id.value());
49+
return ue_index_t::invalid;
50+
}
51+
52+
if (pci.has_value() && pci.value() == INVALID_PCI) {
53+
logger.warning("CU-CP UE creation Failed. Cause: Invalid pci={}", pci.value());
54+
return ue_index_t::invalid;
55+
}
56+
57+
if (rnti.has_value() && rnti.value() == rnti_t::INVALID_RNTI) {
58+
logger.warning("CU-CP UE creation Failed. Cause: Invalid rnti={}", rnti.value());
59+
return ue_index_t::invalid;
60+
}
61+
62+
if (pcell_index.has_value() && pcell_index.value() == du_cell_index_t::invalid) {
63+
logger.warning("CU-CP UE creation Failed. Cause: Invalid pcell_index={}", pcell_index.value());
64+
return ue_index_t::invalid;
65+
}
66+
3867
if (ues.size() == ue_config.max_nof_supported_ues) {
3968
logger.warning("CU-CP UE creation Failed. Cause: Maximum number of UEs {} supported by the CU-CP has been reached",
4069
ue_config.max_nof_supported_ues);
@@ -53,9 +82,20 @@ ue_index_t ue_manager::add_ue(du_index_t du_index)
5382
// Create UE object
5483
ues.emplace(std::piecewise_construct,
5584
std::forward_as_tuple(new_ue_index),
56-
std::forward_as_tuple(new_ue_index, du_index, up_config, sec_config, std::move(ue_sched)));
85+
std::forward_as_tuple(
86+
new_ue_index, du_index, up_config, sec_config, std::move(ue_sched), du_id, pci, rnti, pcell_index));
87+
88+
// Add PCI and RNTI to lookup.
89+
if (pci.has_value() && rnti.has_value()) {
90+
pci_rnti_to_ue_index.emplace(std::make_tuple(pci.value(), rnti.value()), new_ue_index);
91+
}
5792

58-
logger.info("ue={}: Created new CU-CP UE", new_ue_index);
93+
logger.info("ue={}{}{}{}{}: Created new CU-CP UE",
94+
new_ue_index,
95+
du_id.has_value() ? fmt::format(" gnb_du_id={}", du_id.value()) : "",
96+
pci.has_value() ? fmt::format(" pci={}", pci.value()) : "",
97+
rnti.has_value() ? fmt::format(" rnti={}", rnti.value()) : "",
98+
pcell_index.has_value() ? fmt::format(" pcell_index={}", pcell_index.value()) : "");
5999

60100
return new_ue_index;
61101
}
@@ -120,11 +160,16 @@ ue_task_scheduler* ue_manager::find_ue_task_scheduler(ue_index_t ue_index)
120160

121161
// du processor
122162

123-
cu_cp_ue* ue_manager::set_ue_du_context(ue_index_t ue_index, gnb_du_id_t du_id, pci_t pci, rnti_t rnti)
163+
cu_cp_ue* ue_manager::set_ue_du_context(ue_index_t ue_index,
164+
gnb_du_id_t du_id,
165+
pci_t pci,
166+
rnti_t rnti,
167+
du_cell_index_t pcell_index)
124168
{
125169
srsran_assert(ue_index != ue_index_t::invalid, "Invalid ue_index={}", ue_index);
126170
srsran_assert(pci != INVALID_PCI, "Invalid pci={}", pci);
127171
srsran_assert(rnti != rnti_t::INVALID_RNTI, "Invalid rnti={}", rnti);
172+
srsran_assert(pcell_index != du_cell_index_t::invalid, "Invalid pcell_index={}", pcell_index);
128173

129174
// check if ue_index is in db
130175
if (ues.find(ue_index) == ues.end()) {
@@ -139,12 +184,13 @@ cu_cp_ue* ue_manager::set_ue_du_context(ue_index_t ue_index, gnb_du_id_t du_id,
139184
}
140185

141186
auto& ue = ues.at(ue_index);
142-
ue.update_du_ue(du_id, pci, rnti);
187+
ue.update_du_ue(du_id, pci, rnti, pcell_index);
143188

144189
// Add PCI and RNTI to lookup.
145190
pci_rnti_to_ue_index.emplace(std::make_tuple(pci, rnti), ue_index);
146191

147-
logger.debug("ue={}: Updated UE with pci={} and rnti={}", ue_index, pci, rnti);
192+
logger.debug(
193+
"ue={}: Updated UE with gnb_du_id={} pci={} rnti={} pcell_index={}", ue_index, du_id, pci, rnti, pcell_index);
148194

149195
return &ue;
150196
}

lib/cu_cp/ue_manager/ue_manager_impl.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ue_task_scheduler_impl.h"
2020
#include "srsran/cu_cp/security_manager_config.h"
2121
#include "srsran/cu_cp/ue_configuration.h"
22+
#include <optional>
2223
#include <unordered_map>
2324

2425
namespace srsran {
@@ -70,11 +71,26 @@ class ue_manager : public ue_metrics_handler
7071

7172
/// \brief Allocate resources for the UE in the CU-CP.
7273
/// \param[in] du_index Index of the DU the UE is connected to.
74+
/// \param[in] du_id The gNB-DU ID of the DU the UE is connected to.
75+
/// \param[in] pci The PCI of the cell the UE is connected to.
76+
/// \param[in] rnti The RNTI of the UE.
77+
/// \param[in] pcell_index The index of the PCell the UE is connected to.
7378
/// \return ue_index of the created UE or ue_index_t::invalid in case of failure.
74-
ue_index_t add_ue(du_index_t du_index);
79+
ue_index_t add_ue(du_index_t du_index,
80+
std::optional<gnb_du_id_t> du_id = std::nullopt,
81+
std::optional<pci_t> pci = std::nullopt,
82+
std::optional<rnti_t> rnti = std::nullopt,
83+
std::optional<du_cell_index_t> pcell_index = std::nullopt);
7584

7685
/// \brief Set the DU context of the UE.
77-
cu_cp_ue* set_ue_du_context(ue_index_t ue_index, gnb_du_id_t du_id, pci_t pci, rnti_t rnti);
86+
/// \param[in] ue_index Index of the UE.
87+
/// \param[in] du_id The gNB-DU ID of the DU the UE is connected to.
88+
/// \param[in] pci The PCI of the cell the UE is connected to.
89+
/// \param[in] rnti The RNTI of the UE.
90+
/// \param[in] pcell_index The index of the PCell the UE is connected to.
91+
/// \return Pointer to the DU UE if found, nullptr otherwise.
92+
cu_cp_ue*
93+
set_ue_du_context(ue_index_t ue_index, gnb_du_id_t du_id, pci_t pci, rnti_t rnti, du_cell_index_t pcell_index);
7894

7995
/// \brief Find the UE with the given UE index, thats DU context is set up.
8096
/// \param[in] ue_index Index of the UE to be found.

tests/unittests/cu_cp/mobility/handover_reconfiguration_routine_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ class handover_reconfiguration_routine_test : public mobility_test
2525

2626
void create_ues(bool procedure_outcome, unsigned transaction_id_)
2727
{
28-
ue_index_t source_ue_index = get_ue_manager()->add_ue(source_du_index);
29-
source_ue = get_ue_manager()->set_ue_du_context(source_ue_index, int_to_gnb_du_id(0), source_pci, source_rnti);
28+
ue_index_t source_ue_index =
29+
get_ue_manager()->add_ue(source_du_index, int_to_gnb_du_id(0), source_pci, source_rnti, du_cell_index_t::min);
30+
source_ue = get_ue_manager()->find_ue(source_ue_index);
3031
ASSERT_NE(source_ue, nullptr);
3132
source_rrc_ue_notifier.set_transaction_id(transaction_id_);
3233
source_ue->set_rrc_ue_notifier(source_rrc_ue_notifier);
3334

34-
ue_index_t target_ue_index = get_ue_manager()->add_ue(target_du_index);
35-
target_ue = get_ue_manager()->set_ue_du_context(target_ue_index, int_to_gnb_du_id(0), target_pci, target_rnti);
35+
ue_index_t target_ue_index =
36+
get_ue_manager()->add_ue(target_du_index, int_to_gnb_du_id(0), target_pci, target_rnti, du_cell_index_t::min);
37+
target_ue = get_ue_manager()->find_ue(target_ue_index);
3638
ASSERT_NE(target_ue, nullptr);
3739
cu_cp_handler.set_rrc_reconfiguration_outcome(procedure_outcome);
3840
target_ue->set_rrc_ue_notifier(target_rrc_ue_notifier);
@@ -61,15 +63,15 @@ class handover_reconfiguration_routine_test : public mobility_test
6163
private:
6264
// source UE parameters.
6365
du_index_t source_du_index = uint_to_du_index(0);
64-
unsigned source_pci = 1;
66+
pci_t source_pci = 1;
6567
rnti_t source_rnti = to_rnti(0x4601);
6668
dummy_du_processor_rrc_ue_control_message_notifier source_rrc_ue_notifier;
6769
dummy_f1ap_ue_context_manager source_f1ap_ue_ctxt_mng;
6870
cu_cp_ue* source_ue = nullptr;
6971

7072
// target UE parameters.
7173
du_index_t target_du_index = uint_to_du_index(1);
72-
unsigned target_pci = 2;
74+
pci_t target_pci = 2;
7375
rnti_t target_rnti = to_rnti(0x4601);
7476
dummy_du_processor_rrc_ue_control_message_notifier target_rrc_ue_notifier;
7577
cu_cp_ue* target_ue = nullptr;

tests/unittests/cu_cp/routines/ue_context_release_routine_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ class ue_context_release_test : public cu_cp_routine_manager_test
3333

3434
ue_index_t add_ue(pci_t pci, rnti_t c_rnti)
3535
{
36-
ue_index_t ue_index = ue_mng.add_ue(du_index_t::min);
37-
cu_cp_ue* ue = ue_mng.set_ue_du_context(ue_index, int_to_gnb_du_id(0), pci, c_rnti);
36+
ue_index_t ue_index = ue_mng.add_ue(du_index_t::min, int_to_gnb_du_id(0), pci, c_rnti, du_cell_index_t::min);
37+
cu_cp_ue* ue = ue_mng.find_ue(ue_index);
3838
// Set parameters from creation message
39-
ue->set_pcell_index(du_cell_index_t::min);
4039
ue->set_rrc_ue_notifier(rrc_ue_ctrl_notifier);
4140
ue->set_rrc_ue_srb_notifier(rrc_ue_srb_ctrl_notifier);
4241

0 commit comments

Comments
 (0)