|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright 2021-2023 Software Radio Systems Limited |
| 4 | + * |
| 5 | + * By using this file, you agree to the terms and conditions set |
| 6 | + * forth in the LICENSE file which can be found at the top level of |
| 7 | + * the distribution. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +#include "ue_creation_procedure.h" |
| 12 | +#include "../../ran/gnb_format.h" |
| 13 | + |
| 14 | +using namespace srsran; |
| 15 | + |
| 16 | +void mac_ue_create_request_procedure::operator()(coro_context<async_task<mac_ue_create_response>>& ctx) |
| 17 | +{ |
| 18 | + CORO_BEGIN(ctx); |
| 19 | + log_proc_started(logger, req.ue_index, req.crnti, name()); |
| 20 | + |
| 21 | + // > Create UE in MAC CTRL. |
| 22 | + crnti_assigned = ctrl_unit.add_ue(req.ue_index, req.cell_index, req.crnti); |
| 23 | + if (crnti_assigned == INVALID_RNTI) { |
| 24 | + CORO_EARLY_RETURN(handle_mac_ue_create_result(false)); |
| 25 | + } |
| 26 | + |
| 27 | + // > Update C-RNTI of the UE if it changed. |
| 28 | + req.crnti = crnti_assigned; |
| 29 | + |
| 30 | + // > Create UE UL context and channels. |
| 31 | + CORO_AWAIT_VALUE(add_ue_result, ul_unit.add_ue(req)); |
| 32 | + if (not add_ue_result) { |
| 33 | + CORO_EARLY_RETURN(handle_mac_ue_create_result(false)); |
| 34 | + } |
| 35 | + |
| 36 | + // > Create UE DL context and channels. |
| 37 | + CORO_AWAIT_VALUE(add_ue_result, dl_unit.add_ue(req)); |
| 38 | + if (not add_ue_result) { |
| 39 | + // >> Revert creation of UE in MAC UL. |
| 40 | + CORO_AWAIT(ul_unit.remove_ue(mac_ue_delete_request{req.cell_index, req.ue_index, req.crnti})); |
| 41 | + |
| 42 | + // >> Terminate procedure. |
| 43 | + CORO_EARLY_RETURN(handle_mac_ue_create_result(false)); |
| 44 | + } |
| 45 | + |
| 46 | + // > Create UE context in Scheduler. |
| 47 | + CORO_AWAIT_VALUE(add_ue_result, sched_configurator.handle_ue_creation_request(req)); |
| 48 | + if (not add_ue_result) { |
| 49 | + // >> Revert creation of UE in MAC UL and MAC DL. |
| 50 | + CORO_AWAIT(ul_unit.remove_ue(mac_ue_delete_request{req.cell_index, req.ue_index, req.crnti})); |
| 51 | + CORO_AWAIT(dl_unit.remove_ue(mac_ue_delete_request{req.cell_index, req.ue_index, req.crnti})); |
| 52 | + |
| 53 | + // >> Terminate procedure. |
| 54 | + CORO_EARLY_RETURN(handle_mac_ue_create_result(false)); |
| 55 | + } |
| 56 | + |
| 57 | + // > After UE insertion in scheduler, send response to DU manager. |
| 58 | + CORO_RETURN(handle_mac_ue_create_result(add_ue_result)); |
| 59 | +} |
| 60 | + |
| 61 | +mac_ue_create_response mac_ue_create_request_procedure::handle_mac_ue_create_result(bool result) |
| 62 | +{ |
| 63 | + if (result) { |
| 64 | + log_proc_completed(logger, req.ue_index, req.crnti, name()); |
| 65 | + } else { |
| 66 | + log_proc_failure(logger, req.ue_index, req.crnti, name()); |
| 67 | + } |
| 68 | + |
| 69 | + if (not result and crnti_assigned != INVALID_RNTI) { |
| 70 | + // Remove created UE object |
| 71 | + ctrl_unit.remove_ue(req.ue_index); |
| 72 | + } |
| 73 | + |
| 74 | + // Respond back to DU manager with result |
| 75 | + mac_ue_create_response resp{}; |
| 76 | + resp.ue_index = req.ue_index; |
| 77 | + resp.cell_index = req.cell_index; |
| 78 | + resp.allocated_crnti = result ? crnti_assigned : INVALID_RNTI; |
| 79 | + return resp; |
| 80 | +} |
0 commit comments