Commit 231c2f3c authored by Cedric Roux's avatar Cedric Roux

gnb: remove srb0 shared global variable - use RLC module instead

parent 8773e423
......@@ -41,6 +41,9 @@
#include "UTIL/OPT/opt.h"
#include "SIMULATION/TOOLS/sim.h" // for taus
/* rlc */
#include "openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h"
#include <executables/softmodem-common.h>
extern RAN_CONTEXT_t RC;
extern const uint8_t nr_slots_per_frame[5];
......@@ -1418,9 +1421,19 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
int current_harq_pid = sched_ctrl->retrans_dl_harq.head;
if (ra->msg3_dcch_dtch == false && current_harq_pid < 0) {
mac_sdu_length = mac_rrc_nr_data_req(module_idP, CC_id, frameP, CCCH, ra->rnti, 1, NULL);
if (mac_sdu_length <= 0)
return; // need to wait until RRCSetup is encoded
/* need to wait until RRCSetup is ready */
mac_rlc_status_resp_t srb0_status = mac_rlc_status_ind(module_idP,
ra->rnti,
module_idP,
frameP,
slotP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
0 /* lcid 0 */,
0,
0);
if (srb0_status.bytes_in_buffer == 0) return;
mac_sdu_length = srb0_status.bytes_in_buffer;
}
long BWPStart = 0;
......@@ -1559,7 +1572,17 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
LOG_D(NR_MAC,"Encoded contention resolution mac_pdu_length %d\n",mac_pdu_length);
uint8_t buffer[CCCH_SDU_SIZE];
uint8_t mac_subheader_len = sizeof(NR_MAC_SUBHEADER_SHORT);
uint16_t mac_sdu_length = mac_rrc_nr_data_req(module_idP, CC_id, frameP, CCCH, ra->rnti, 1, buffer);
mac_sdu_length = mac_rlc_data_req(module_idP,
ra->rnti,
module_idP,
frameP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
CCCH,
CCCH_SDU_SIZE,
(char *)buffer,
0,
0);
if (mac_sdu_length < 256) {
((NR_MAC_SUBHEADER_SHORT *) &buf[mac_pdu_length])->R = 0;
((NR_MAC_SUBHEADER_SHORT *) &buf[mac_pdu_length])->F = 0;
......
......@@ -44,6 +44,8 @@
#include "OCG.h"
#include "OCG_extern.h"
#include "openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h"
/* TODO REMOVE_DU_RRC: the RRC in the DU is a hack and should be taken out in the future */
#include "RRC/LTE/rrc_extern.h"
#include "RRC/NR/nr_rrc_extern.h"
......@@ -2700,6 +2702,8 @@ void reset_ul_harq_list(NR_UE_sched_ctrl_t *sched_ctrl) {
void mac_remove_nr_ue(gNB_MAC_INST *nr_mac, rnti_t rnti)
{
nr_rlc_remove_ue(rnti);
NR_UEs_t *UE_info = &nr_mac->UE_info;
pthread_mutex_lock(&UE_info->mutex);
UE_iterator(UE_info->list, UE) {
......@@ -3097,15 +3101,14 @@ void UL_tti_req_ahead_initialization(gNB_MAC_INST * gNB, NR_ServingCellConfigCom
void send_initial_ul_rrc_message(module_id_t module_id,
int CC_id,
const NR_UE_info_t *UE,
rb_id_t srb_id,
int rnti,
int uid,
const uint8_t *sdu,
sdu_size_t sdu_len) {
const gNB_MAC_INST *mac = RC.nrmac[module_id];
const rnti_t rnti = UE->rnti;
LOG_W(MAC,
"[RAPROC] Received SDU for CCCH on SRB %ld length %d for UE %04x\n",
srb_id, sdu_len, rnti);
"[RAPROC] Received SDU for CCCH length %d for UE %04x\n",
sdu_len, rnti);
/* TODO REMOVE_DU_RRC: the RRC in the DU is a hack and should be taken out in the future */
if (NODE_IS_DU(RC.nrrrc[module_id]->node_type)) {
......@@ -3113,14 +3116,13 @@ void send_initial_ul_rrc_message(module_id_t module_id,
ue_context_p->ue_id_rnti = rnti;
ue_context_p->ue_context.rnti = rnti;
ue_context_p->ue_context.random_ue_identity = rnti;
ue_context_p->ue_context.Srb0.Active = 1;
RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[module_id]->rrc_ue_head, ue_context_p);
}
const NR_ServingCellConfigCommon_t *scc = RC.nrrrc[module_id]->carrier.servingcellconfigcommon;
const NR_ServingCellConfig_t *sccd = RC.nrrrc[module_id]->configuration.scd;
NR_CellGroupConfig_t cellGroupConfig = {0};
fill_initial_cellGroupConfig(UE->uid, &cellGroupConfig, scc, sccd, &RC.nrrrc[module_id]->configuration);
fill_initial_cellGroupConfig(uid, &cellGroupConfig, scc, sccd, &RC.nrrrc[module_id]->configuration);
uint8_t du2cu_rrc_container[1024];
asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
......
......@@ -35,6 +35,7 @@
#include "utils.h"
#include <openair2/UTIL/OPT/opt.h>
#include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
#include "LAYER2/nr_rlc/nr_rlc_oai_api.h"
//#define SRS_IND_DEBUG
......@@ -363,12 +364,19 @@ int nr_process_mac_pdu(instance_t module_idP,
mac_len = 6;
}
send_initial_ul_rrc_message(module_idP,
CC_id,
UE,
CCCH,
pduP + mac_subheader_len,
mac_len);
nr_rlc_activate_srb0(UE->rnti, module_idP, CC_id, UE->uid, send_initial_ul_rrc_message);
mac_rlc_data_ind(module_idP,
UE->rnti,
module_idP,
frameP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
0,
(char *) (pduP + mac_subheader_len),
mac_len,
1,
NULL);
break;
case UL_SCH_LCID_DTCH ... (UL_SCH_LCID_DTCH + 28):
......
......@@ -510,8 +510,8 @@ void process_CellGroup(NR_CellGroupConfig_t *CellGroup, NR_UE_sched_ctrl_t *sche
void send_initial_ul_rrc_message(module_id_t module_id,
int CC_id,
const NR_UE_info_t *UE,
rb_id_t srb_id,
int rnti,
int uid,
const uint8_t *sdu,
sdu_size_t sdu_len);
......
......@@ -23,6 +23,7 @@
#include "mac_proto.h"
#include "openair2/RRC/NR/rrc_gNB_UE_context.h"
#include "openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h"
#include "NR_RRCSetup.h"
#include "NR_DL-CCCH-Message.h"
......@@ -111,13 +112,10 @@ int dl_rrc_message_rrcSetup(module_id_t module_id, const f1ap_dl_rrc_message_t *
gNB_RRC_INST *rrc = RC.nrrrc[module_id];
struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(rrc, dl_rrc->rnti);
gNB_RRC_UE_t *ue_p = &ue_context_p->ue_context;
ue_context_p->ue_context.SRB_configList = rrcSetup_ies->radioBearerConfig.srb_ToAddModList;
ue_context_p->ue_context.masterCellGroup = cellGroup;
ue_p->SRB_configList = rrcSetup_ies->radioBearerConfig.srb_ToAddModList;
ue_p->masterCellGroup = cellGroup;
/* TODO: this should pass through RLC and NOT the RRC with a shared buffer */
AssertFatal(ue_p->Srb0.Active == 1,"SRB0 is not active\n");
memcpy(ue_p->Srb0.Tx_buffer.Payload, dl_rrc->rrc_container, dl_rrc->rrc_container_length);
ue_p->Srb0.Tx_buffer.payload_size = dl_rrc->rrc_container_length;
nr_rlc_srb0_recv_sdu(dl_rrc->rnti, dl_rrc->rrc_container, dl_rrc->rrc_container_length);
protocol_ctxt_t ctxt = { .module_id = module_id, .rnti = dl_rrc->rnti };
nr_rrc_rlc_config_asn1_req(&ctxt,
......
......@@ -164,6 +164,7 @@ void mac_rlc_data_ind (
LOG_I(RLC, "RLC instance for the given UE was not found \n");
switch (channel_idP) {
case 0: rb = ue->srb0; break;
case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
case 4 ... 32: rb = ue->drb[channel_idP - 4]; break;
default: rb = NULL; break;
......@@ -205,6 +206,7 @@ tbs_size_t mac_rlc_data_req(
ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);
switch (channel_idP) {
case 0: rb = ue->srb0; break;
case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
case 4 ... 32: rb = ue->drb[channel_idP - 4]; break;
default:
......@@ -253,6 +255,7 @@ mac_rlc_status_resp_t mac_rlc_status_ind(
ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);
switch (channel_idP) {
case 0: rb = ue->srb0; break;
case 1 ... 3: rb = ue->srb[channel_idP - 1]; break;
case 4 ... NGAP_MAX_DRBS_PER_UE: rb = ue->drb[channel_idP - 4]; break;
default: rb = NULL; break;
......@@ -271,7 +274,7 @@ mac_rlc_status_resp_t mac_rlc_status_ind(
+ buf_stat.retx_size
+ buf_stat.tx_size;
} else {
if (!(frameP%128)) //to suppress this warning message
if (!(frameP%128) || channel_idP == 0) //to suppress this warning message
LOG_W(RLC, "[%s] Radio Bearer (channel ID %d) is NULL for UE with rntiP %x\n", __FUNCTION__, channel_idP, rntiP);
ret.bytes_in_buffer = 0;
}
......@@ -1017,6 +1020,66 @@ rlc_op_status_t nr_rrc_rlc_config_asn1_req (const protocol_ctxt_t * const ctxt
return RLC_OP_STATUS_OK;
}
struct srb0_data {
int module_id;
int CC_id;
int rnti;
int uid;
void (*send_initial_ul_rrc_message)(module_id_t module_id,
int CC_id,
int rnti,
int uid,
const uint8_t *sdu,
sdu_size_t sdu_len);
};
void deliver_sdu_srb0(void *deliver_sdu_data, struct nr_rlc_entity_t *entity,
char *buf, int size)
{
struct srb0_data *s0 = (struct srb0_data *)deliver_sdu_data;
s0->send_initial_ul_rrc_message(s0->module_id, s0->CC_id, s0->rnti, s0->uid,
(unsigned char *)buf, size);
}
void nr_rlc_activate_srb0(int rnti, int module_id, int cc_id, int uid,
void (*send_initial_ul_rrc_message)(
module_id_t module_id,
int CC_id,
int rnti,
int uid,
const uint8_t *sdu,
sdu_size_t sdu_len))
{
nr_rlc_entity_t *nr_rlc_tm;
nr_rlc_ue_t *ue;
struct srb0_data *srb0_data;
srb0_data = calloc(1, sizeof(struct srb0_data));
AssertFatal(srb0_data != NULL, "out of memory\n");
srb0_data->module_id = module_id;
srb0_data->CC_id = cc_id;
srb0_data->rnti = rnti;
srb0_data->uid = uid;
srb0_data->send_initial_ul_rrc_message = send_initial_ul_rrc_message;
nr_rlc_manager_lock(nr_rlc_ue_manager);
ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
if (ue->srb0 != NULL) {
LOG_W(RLC, "SRB0 already exists for UE with RNTI 0x%x, do nothing\n", rnti);
free(srb0_data);
nr_rlc_manager_unlock(nr_rlc_ue_manager);
return;
}
nr_rlc_tm = new_nr_rlc_entity_tm(10000,
deliver_sdu_srb0, srb0_data);
nr_rlc_ue_add_srb_rlc_entity(ue, 0, nr_rlc_tm);
LOG_I(RLC, "activated srb0 for UE with RNTI 0x%x\n", rnti);
nr_rlc_manager_unlock(nr_rlc_ue_manager);
}
rlc_op_status_t rrc_rlc_config_req (
const protocol_ctxt_t* const ctxt_pP,
const srb_flag_t srb_flagP,
......@@ -1081,13 +1144,17 @@ void rrc_rlc_register_rrc (rrc_data_ind_cb_t rrc_data_indP, rrc_data_conf_cb_t r
/* nothing to do */
}
rlc_op_status_t rrc_rlc_remove_ue (const protocol_ctxt_t* const x)
void nr_rlc_remove_ue(int rnti)
{
LOG_D(RLC, "%s:%d:%s: remove UE %d\n", __FILE__, __LINE__, __FUNCTION__, x->rnti);
LOG_W(RLC, "remove UE %x\n", rnti);
nr_rlc_manager_lock(nr_rlc_ue_manager);
nr_rlc_manager_remove_ue(nr_rlc_ue_manager, x->rnti);
nr_rlc_manager_remove_ue(nr_rlc_ue_manager, rnti);
nr_rlc_manager_unlock(nr_rlc_ue_manager);
}
rlc_op_status_t rrc_rlc_remove_ue (const protocol_ctxt_t* const x)
{
nr_rlc_remove_ue(x->rnti);
return RLC_OP_STATUS_OK;
}
......@@ -1173,3 +1240,25 @@ const bool nr_rlc_get_statistics(
return ret;
}
void nr_rlc_srb0_recv_sdu(int rnti, unsigned char *buf, int size)
{
nr_rlc_ue_t *ue;
nr_rlc_entity_t *rb;
T(T_ENB_RLC_DL, T_INT(0), T_INT(rnti), T_INT(0), T_INT(size));
nr_rlc_manager_lock(nr_rlc_ue_manager);
ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
rb = ue->srb0;
if (rb != NULL) {
rb->set_time(rb, nr_rlc_current_time);
rb->recv_sdu(rb, (char *)buf, size, -1);
} else {
LOG_E(RLC, "SDU sent to unknown RB rnti %d srb0\n", rnti);
}
nr_rlc_manager_unlock(nr_rlc_ue_manager);
}
......@@ -48,6 +48,8 @@ void nr_drb_config(struct NR_RLC_Config *rlc_Config, NR_RLC_Config_PR rlc_config
void nr_rlc_bearer_init_ul_spec(struct NR_LogicalChannelConfig *mac_LogicalChannelConfig);
void nr_rlc_remove_ue(int rnti);
int nr_rlc_get_available_tx_space(
const rnti_t rntiP,
const logical_chan_id_t channel_idP);
......@@ -56,3 +58,14 @@ void nr_rlc_activate_avg_time_to_tx(
const rnti_t rnti,
const logical_chan_id_t channel_id,
const bool is_on);
void nr_rlc_srb0_recv_sdu(int rnti, unsigned char *buf, int size);
void nr_rlc_activate_srb0(int rnti, int module_id, int cc_id, int uid,
void (*send_initial_ul_rrc_message)(
module_id_t module_id,
int CC_id,
int rnti,
int uid,
const uint8_t *sdu,
sdu_size_t sdu_len));
......@@ -117,7 +117,7 @@ void nr_rlc_manager_remove_ue(nr_rlc_ue_manager_t *_m, int rnti)
break;
if (i == m->ue_count) {
LOG_W(RLC, "%s:%d:%s: warning: ue %d not found\n",
LOG_W(RLC, "%s:%d:%s: warning: ue %x not found\n",
__FILE__, __LINE__, __FUNCTION__,
rnti);
return;
......@@ -125,11 +125,17 @@ void nr_rlc_manager_remove_ue(nr_rlc_ue_manager_t *_m, int rnti)
ue = m->ue_list[i];
for (j = 0; j < 2; j++)
if (ue->srb0 != NULL) {
/* deliver_sdu_data for srb0 is allocated, needs a free() */
free(ue->srb0->deliver_sdu_data);
ue->srb0->delete(ue->srb0);
}
for (j = 0; j < 3; j++)
if (ue->srb[j] != NULL)
ue->srb[j]->delete(ue->srb[j]);
for (j = 0; j < 5; j++)
for (j = 0; j < MAX_DRBS_PER_UE; j++)
if (ue->drb[j] != NULL)
ue->drb[j]->delete(ue->drb[j]);
......@@ -154,11 +160,23 @@ void nr_rlc_manager_remove_ue(nr_rlc_ue_manager_t *_m, int rnti)
/* must be called with lock acquired */
void nr_rlc_ue_add_srb_rlc_entity(nr_rlc_ue_t *ue, int srb_id, nr_rlc_entity_t *entity)
{
if (srb_id < 1 || srb_id > 2) {
if (srb_id < 0 || srb_id > 3) {
LOG_E(RLC, "%s:%d:%s: fatal, bad srb id\n", __FILE__, __LINE__, __FUNCTION__);
exit(1);
}
/* special case: srb0 */
if (srb_id == 0) {
if (ue->srb0 != NULL) {
LOG_E(RLC, "fatal, srb0 already present\n");
exit(1);
}
ue->srb0 = entity;
return;
}
srb_id--;
if (ue->srb[srb_id] != NULL) {
......@@ -173,7 +191,7 @@ void nr_rlc_ue_add_srb_rlc_entity(nr_rlc_ue_t *ue, int srb_id, nr_rlc_entity_t *
/* must be called with lock acquired */
void nr_rlc_ue_add_drb_rlc_entity(nr_rlc_ue_t *ue, int drb_id, nr_rlc_entity_t *entity)
{
if (drb_id < 1 || drb_id > 5) {
if (drb_id < 1 || drb_id > MAX_DRBS_PER_UE) {
LOG_E(RLC, "%s:%d:%s: fatal, bad drb id\n", __FILE__, __LINE__, __FUNCTION__);
exit(1);
}
......
......@@ -28,6 +28,7 @@ typedef void nr_rlc_ue_manager_t;
typedef struct nr_rlc_ue_t {
int rnti;
nr_rlc_entity_t *srb0;
nr_rlc_entity_t *srb[3];
nr_rlc_entity_t *drb[MAX_DRBS_PER_UE];
} nr_rlc_ue_t;
......
......@@ -161,29 +161,7 @@ uint16_t mac_rrc_nr_data_req(const module_id_t Mod_idP,
// CCCH
if ((Srb_id & RAB_OFFSET) == CCCH) {
LOG_D(NR_RRC,"[gNB %d] Frame %d CCCH request (Srb_id %ld)\n", Mod_idP, frameP, Srb_id);
struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[Mod_idP], rnti);
LOG_D(NR_RRC,"[gNB %d] Frame %d CCCH request (Srb_id %ld)\n", Mod_idP, frameP, Srb_id);
if (ue_context_p == NULL) {
if(buffer_pP != NULL)
LOG_E(NR_RRC,"[gNB %d] Frame %d CCCH request but no ue_context\n", Mod_idP, frameP);
return 0;
}
uint16_t payload_size = ue_context_p->ue_context.Srb0.Tx_buffer.payload_size;
if (buffer_pP == NULL)
return payload_size;
// check if data is there for MAC
if (payload_size > 0) {
char *payload_pP = ue_context_p->ue_context.Srb0.Tx_buffer.Payload;
LOG_D(NR_RRC,"[gNB %d] CCCH has %d bytes (dest: %p, src %p)\n", Mod_idP, payload_size, buffer_pP, payload_pP);
// Fill buffer
memcpy((void *)buffer_pP, (void*)payload_pP, payload_size);
ue_context_p->ue_context.Srb0.Tx_buffer.payload_size = 0;
}
return payload_size;
AssertFatal(0, "CCCH is managed by rlc of srb 0, not anymore by mac_rrc_nr_data_req\n");
}
return 0;
......
......@@ -286,7 +286,6 @@ typedef struct gNB_RRC_UE_s {
uint8_t DRB_active[NGAP_MAX_DRBS_PER_UE];
NR_SRB_INFO SI;
NR_SRB_INFO Srb0;
NR_SRB_INFO_TABLE_ENTRY Srb1;
NR_SRB_INFO_TABLE_ENTRY Srb2;
NR_MeasConfig_t *measConfig;
......@@ -452,7 +451,6 @@ typedef struct {
NR_PDCCH_ConfigSIB1_t *pdcch_ConfigSIB1;
NR_CellGroupConfig_t *secondaryCellGroup[MAX_NR_RRC_UE_CONTEXTS];
NR_SRB_INFO SI;
NR_SRB_INFO Srb0;
int p_gNB;
} rrc_gNB_carrier_data_t;
......
This diff is collapsed.
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