gNB_scheduler.c 20.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file gNB_scheduler.c
 * \brief gNB scheduler top level function operates on per subframe basis
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
24 25 26
 * \author  Navid Nikaein and Raymond Knopp, WEI-TAI CHEN
 * \date 2010 - 2014, 2018
 * \email: navid.nikaein@eurecom.fr, kroempa@gmail.com
27
 * \version 0.5
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
28
 * \company Eurecom, NTUST
29 30 31 32 33 34 35 36 37
 * @ingroup _mac

 */

#include "assertions.h"

#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_extern.h"
#include "LAYER2/MAC/mac_proto.h"
38
#include "LAYER2/NR_MAC_gNB/mac_proto.h"
Raymond Knopp's avatar
Raymond Knopp committed
39 40
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
41 42 43 44
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"

45
#include "RRC/NR/nr_rrc_extern.h"
46 47 48 49

//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

50
#include "openair1/PHY/defs_gNB.h"
51
#include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h"
52

53 54 55 56 57 58 59 60 61
//Agent-related headers
#include "flexran_agent_extern.h"
#include "flexran_agent_mac.h"

#if defined(ENABLE_ITTI)
#include "intertask_interface.h"
#endif

#include "assertions.h"
laurent's avatar
laurent committed
62
#include <openair1/PHY/LTE_TRANSPORT/transport_proto.h>
63 64 65 66 67 68

#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1

extern RAN_CONTEXT_t RC;
extern int phy_test;
69 70 71 72
extern uint8_t nfapi_mode;

uint16_t nr_pdcch_order_table[6] = { 31, 31, 511, 2047, 2047, 8191 };

73
void clear_nr_nfapi_information(gNB_MAC_INST * gNB,
74
                                int CC_idP,
75
                                frame_t frameP,
76
                                sub_frame_t slotP){
77

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
78 79 80 81
  nfapi_nr_dl_config_request_t    *DL_req = &gNB->DL_req[0];
  nfapi_ul_config_request_t       *UL_req = &gNB->UL_req[0];
  nfapi_hi_dci0_request_t   *     HI_DCI0_req = &gNB->HI_DCI0_req[0];
  nfapi_tx_request_t              *TX_req = &gNB->TX_req[0];
82 83 84 85 86 87 88 89

  gNB->pdu_index[CC_idP] = 0;

  if (nfapi_mode==0 || nfapi_mode == 1) { // monolithic or PNF

    DL_req[CC_idP].dl_config_request_body.number_dci                          = 0;
    DL_req[CC_idP].dl_config_request_body.number_pdu                          = 0;
    DL_req[CC_idP].dl_config_request_body.number_pdsch_rnti                   = 0;
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
90
    //DL_req[CC_idP].dl_config_request_body.transmission_power_pcfich           = 6000;
91

92
    HI_DCI0_req[CC_idP].hi_dci0_request_body.sfnsf                            = slotP + (frameP<<7);
93 94 95 96 97 98 99 100 101 102 103
    HI_DCI0_req[CC_idP].hi_dci0_request_body.number_of_dci                    = 0;


    UL_req[CC_idP].ul_config_request_body.number_of_pdus                      = 0;
    UL_req[CC_idP].ul_config_request_body.rach_prach_frequency_resources      = 0; // ignored, handled by PHY for now
    UL_req[CC_idP].ul_config_request_body.srs_present                         = 0; // ignored, handled by PHY for now

    TX_req[CC_idP].tx_request_body.number_of_pdus                 = 0;

  }
}
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
104
/*
105 106
void check_nr_ul_failure(module_id_t module_idP,
                         int CC_id,
107
                         int UE_id,
108
                         frame_t frameP,
109
                         sub_frame_t slotP) {
110

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
111 112 113 114
  UE_list_t                     *UE_list  = &RC.nrmac[module_idP]->UE_list;
  nfapi_nr_dl_config_request_t  *DL_req   = &RC.nrmac[module_idP]->DL_req[0];
  uint16_t                      rnti      = UE_RNTI(module_idP, UE_id);
  NR_COMMON_channels_t          *cc       = RC.nrmac[module_idP]->common_channels;
115 116 117 118 119 120 121 122 123 124

  // check uplink failure
  if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer > 0) &&
      (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 0)) {
    LOG_I(MAC, "UE %d rnti %x: UL Failure timer %d \n", UE_id, rnti,
    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
    if (UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent == 0) {
      UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent = 1;

      // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
125
      nfapi_nr_dl_config_request_pdu_t *dl_config_pdu                    = &DL_req[CC_id].dl_config_request_body.dl_config_pdu_list[DL_req[CC_id].dl_config_request_body.number_pdu];
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
      memset((void *) dl_config_pdu, 0,sizeof(nfapi_dl_config_request_pdu_t));
      dl_config_pdu->pdu_type                                         = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
      dl_config_pdu->pdu_size                                         = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu));
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag                = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format            = NFAPI_DL_DCI_FORMAT_1A;
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level     = get_aggregation(get_bw_index(module_idP, CC_id),
                      UE_list->UE_sched_ctrl[UE_id].
                      dl_cqi[CC_id], format1A);
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                  = rnti;
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type             = 1;  // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power    = 6000; // equal to RS power

      AssertFatal((cc[CC_id].mib->message.dl_Bandwidth >= 0) && (cc[CC_id].mib->message.dl_Bandwidth < 6),
      "illegal dl_Bandwidth %d\n",
      (int) cc[CC_id].mib->message.dl_Bandwidth);
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = nr_pdcch_order_table[cc[CC_id].mib->message.dl_Bandwidth];
      DL_req[CC_id].dl_config_request_body.number_dci++;
      DL_req[CC_id].dl_config_request_body.number_pdu++;
      DL_req[CC_id].dl_config_request_body.tl.tag                      = NFAPI_DL_CONFIG_REQUEST_BODY_TAG;
      LOG_I(MAC,
      "UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d), resource_block_coding %d \n",
      UE_id, rnti,
      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer,
      dl_config_pdu->dci_dl_pdu.
      dci_dl_pdu_rel8.resource_block_coding);
    } else {    // ra_pdcch_sent==1
      LOG_I(MAC,
      "UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",
      UE_id, rnti,
      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
      if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer % 40) == 0) UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent = 0;  // resend every 4 frames
    }

    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer++;
    // check threshold
    if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer > 20000) {
      // inform RRC of failure and clear timer
      LOG_I(MAC,
      "UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",
      UE_id, rnti);
      mac_eNB_rrc_ul_failure(module_idP, CC_id, frameP, subframeP,rnti);
      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
      UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync   = 1;

      //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
      if (rrc_agent_registered[module_idP]) {
        LOG_W(MAC, "notify flexran Agent of UE state change\n");
        agent_rrc_xface[module_idP]->flexran_agent_notify_ue_state_change(module_idP,
            rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
      }
    }
  }       // ul_failure_timer>0

}
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
180
*/
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
181
/*
182 183 184 185 186 187
void schedule_nr_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
{
  gNB_MAC_INST *gNB = RC.nrmac[module_idP];
  UE_list_t *UE_list = &gNB->UE_list;
  nfapi_ul_config_request_body_t *ul_req;
  int CC_id, UE_id;
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
188
  NR_COMMON_channels_t *cc = RC.nrmac[module_idP]->common_channels;
189 190 191 192 193
  SoundingRS_UL_ConfigCommon_t *soundingRS_UL_ConfigCommon;
  struct SoundingRS_UL_ConfigDedicated *soundingRS_UL_ConfigDedicated;
  uint8_t TSFC;
  uint16_t deltaTSFC;   // bitmap
  uint8_t srs_SubframeConfig;
194

195 196 197
  // table for TSFC (Period) and deltaSFC (offset)
  const uint16_t deltaTSFCTabType1[15][2] = { {1, 1}, {1, 2}, {2, 2}, {1, 5}, {2, 5}, {4, 5}, {8, 5}, {3, 5}, {12, 5}, {1, 10}, {2, 10}, {4, 10}, {8, 10}, {351, 10}, {383, 10} };  // Table 5.5.3.3-2 3GPP 36.211 FDD
  const uint16_t deltaTSFCTabType2[14][2] = { {2, 5}, {6, 5}, {10, 5}, {18, 5}, {14, 5}, {22, 5}, {26, 5}, {30, 5}, {70, 10}, {74, 10}, {194, 10}, {326, 10}, {586, 10}, {210, 10} }; // Table 5.5.3.3-2 3GPP 36.211 TDD
198

199
  uint16_t srsPeriodicity, srsOffset;
200

201 202 203 204 205 206 207 208 209 210 211 212 213 214
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    soundingRS_UL_ConfigCommon = &cc[CC_id].radioResourceConfigCommon->soundingRS_UL_ConfigCommon;
    // check if SRS is enabled in this frame/subframe
    if (soundingRS_UL_ConfigCommon) {
      srs_SubframeConfig = soundingRS_UL_ConfigCommon->choice.setup.srs_SubframeConfig;
      if (cc[CC_id].tdd_Config == NULL) { // FDD
  deltaTSFC = deltaTSFCTabType1[srs_SubframeConfig][0];
  TSFC = deltaTSFCTabType1[srs_SubframeConfig][1];
      } else {    // TDD
  deltaTSFC = deltaTSFCTabType2[srs_SubframeConfig][0];
  TSFC = deltaTSFCTabType2[srs_SubframeConfig][1];
      }
      // Sounding reference signal subframes are the subframes satisfying ns/2 mod TSFC (- deltaTSFC
      uint16_t tmp = (subframeP % TSFC);
215

216 217 218 219 220 221 222
      if ((1 << tmp) & deltaTSFC) {
  // This is an SRS subframe, loop over UEs
  for (UE_id = 0; UE_id < MAX_MOBILES_PER_GNB; UE_id++) {
    if (!RC.nrmac[module_idP]->UE_list.active[UE_id]) continue;
    ul_req = &RC.nrmac[module_idP]->UL_req[CC_id].ul_config_request_body;
    // drop the allocation if the UE hasn't send RRCConnectionSetupComplete yet
    if (mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED) continue;
223

224 225 226
    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated != NULL,
          "physicalConfigDedicated is null for UE %d\n",
          UE_id);
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    if ((soundingRS_UL_ConfigDedicated = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated) != NULL) {
      if (soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup) {
        get_srs_pos(&cc[CC_id],
        soundingRS_UL_ConfigDedicated->choice.
        setup.srs_ConfigIndex,
        &srsPeriodicity, &srsOffset);
        if (((10 * frameP + subframeP) % srsPeriodicity) == srsOffset) {
    // Program SRS
    ul_req->srs_present = 1;
    nfapi_ul_config_request_pdu_t * ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus];
    memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t));
    ul_config_pdu->pdu_type =  NFAPI_UL_CONFIG_SRS_PDU_TYPE;
    ul_config_pdu->pdu_size =  2 + (uint8_t) (2 + sizeof(nfapi_ul_config_srs_pdu));
    ul_config_pdu->srs_pdu.srs_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL8_TAG;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.size = (uint8_t)sizeof(nfapi_ul_config_srs_pdu);
    ul_config_pdu->srs_pdu.srs_pdu_rel8.rnti = UE_list->UE_template[CC_id][UE_id].rnti;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.srs_bandwidth = soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.frequency_domain_position = soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth = soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth;;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.transmission_comb = soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.i_srs = soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex;
    ul_config_pdu->srs_pdu.srs_pdu_rel8.sounding_reference_cyclic_shift = soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift;    //              ul_config_pdu->srs_pdu.srs_pdu_rel10.antenna_port                   = ;//
    //              ul_config_pdu->srs_pdu.srs_pdu_rel13.number_of_combs                = ;//
    RC.nrmac[module_idP]->UL_req[CC_id].sfn_sf = (frameP << 4) + subframeP;
    RC.nrmac[module_idP]->UL_req[CC_id].header.message_id = NFAPI_UL_CONFIG_REQUEST;
    ul_req->number_of_pdus++;
        } // if (((10*frameP+subframeP) % srsPeriodicity) == srsOffset)
      } // if (soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup)
    }   // if ((soundingRS_UL_ConfigDedicated = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated)!=NULL)
  }   // for (UE_id ...
      }     // if((1<<tmp) & deltaTSFC)
259

260 261 262
    }     // SRS config
  }
}
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
263
*/
264
void copy_nr_ulreq(module_id_t module_idP, frame_t frameP, sub_frame_t slotP)
265 266 267 268 269 270
{
  int CC_id;
  gNB_MAC_INST *mac = RC.nrmac[module_idP];

  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {

271
    nfapi_ul_config_request_t *ul_req_tmp             = &mac->UL_req_tmp[CC_id][slotP];
272 273 274 275 276 277 278
    nfapi_ul_config_request_t *ul_req                 = &mac->UL_req[CC_id];
    nfapi_ul_config_request_pdu_t *ul_req_pdu         = ul_req->ul_config_request_body.ul_config_pdu_list;

    *ul_req = *ul_req_tmp;

    // Restore the pointer
    ul_req->ul_config_request_body.ul_config_pdu_list = ul_req_pdu;
279
    ul_req->sfn_sf                                    = (frameP<<7) + slotP;
280 281 282 283
    ul_req_tmp->ul_config_request_body.number_of_pdus = 0;

    if (ul_req->ul_config_request_body.number_of_pdus>0)
      {
284
        LOG_D(PHY, "%s() active NOW (frameP:%d slotP:%d) pdus:%d\n", __FUNCTION__, frameP, slotP, ul_req->ul_config_request_body.number_of_pdus);
285 286 287 288 289 290 291
      }

    memcpy((void*)ul_req->ul_config_request_body.ul_config_pdu_list,
     (void*)ul_req_tmp->ul_config_request_body.ul_config_pdu_list,
     ul_req->ul_config_request_body.number_of_pdus*sizeof(nfapi_ul_config_request_pdu_t));
  }
}
292

293
void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
294
                               frame_t frameP,
295
                               sub_frame_t slotP){
296 297 298
  protocol_ctxt_t   ctxt;

  int               CC_id, i = -1;
299
  UE_list_t         *UE_list = &RC.nrmac[module_idP]->UE_list;
300 301
  rnti_t            rnti;

302
  NR_COMMON_channels_t *cc      = RC.nrmac[module_idP]->common_channels;
303
  //nfapi_nr_dl_config_dlsch_pdu_rel15_t *dlsch_config = NULL;
304

305 306
  start_meas(&RC.nrmac[module_idP]->eNB_scheduler);
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
307

308
  RC.nrmac[module_idP]->frame    = frameP;
309 310
  RC.nrmac[module_idP]->slot     = slotP;

311 312

  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
313
    //mbsfn_status[CC_id] = 0;
314 315 316 317 318

    // clear vrb_maps
    memset(cc[CC_id].vrb_map, 0, 100);
    memset(cc[CC_id].vrb_map_UL, 0, 100);

319
    clear_nr_nfapi_information(RC.nrmac[module_idP], CC_id, frameP, slotP);
320 321 322
  }

  // refresh UE list based on UEs dropped by PHY in previous subframe
323
  for (i = 0; i < MAX_MOBILES_PER_GNB; i++) {
324 325
    if (UE_list->active[i]) {

326 327
      nfapi_nr_config_request_t *cfg = &RC.nrmac[module_idP]->config[CC_id];

328 329 330 331 332 333 334
      nfapi_nr_coreset_t coreset = RC.nrmac[module_idP]->coreset[CC_id][1];
      nfapi_nr_search_space_t search_space = RC.nrmac[module_idP]->search_space[CC_id][1];

      if (nr_is_dci_opportunity(search_space,
                                    coreset,
                                    frameP,
                                    slotP,
335
                                    *cfg)){
336
          nr_schedule_uss_dlsch_phytest(module_idP, frameP, slotP, NULL);
337
          }
338

339 340
      rnti = UE_RNTI(module_idP, i);
      CC_id = UE_PCCID(module_idP, i);
341
      //int spf = get_spf(cfg);
342

343
      if (((frameP&127) == 0) && (slotP == 0)) {
344
        LOG_I(MAC,
345 346 347 348 349 350 351 352 353
        "UE  rnti %x : %s, PHR %d dB DL CQI %d PUSCH SNR %d PUCCH SNR %d\n",
        rnti,
        UE_list->UE_sched_ctrl[i].ul_out_of_sync ==
        0 ? "in synch" : "out of sync",
        UE_list->UE_template[CC_id][i].phr_info,
        UE_list->UE_sched_ctrl[i].dl_cqi[CC_id],
        (UE_list->UE_sched_ctrl[i].pusch_snr[CC_id] - 128) / 2,
        (UE_list->UE_sched_ctrl[i].pucch1_snr[CC_id] - 128) / 2);
      }
354

355
      RC.gNB[module_idP][CC_id]->pusch_stats_bsr[i][to_absslot(cfg,frameP,slotP)] = -63;
356

357
      if (i == UE_list->head)
358
        VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,RC.gNB[module_idP][CC_id]->
359
                                                pusch_stats_bsr[i][to_absslot(cfg,frameP,slotP)]);
360

361
      // increment this, it is cleared when we receive an sdu
362 363
      RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
      RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].cqi_req_timer++;
364 365 366

      LOG_D(MAC, "UE %d/%x : ul_inactivity %d, cqi_req %d\n",
            i,
367 368 369
            rnti,
            RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ul_inactivity_timer,
            RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].cqi_req_timer);
370

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
371
      //check_nr_ul_failure(module_idP, CC_id, i, frameP, subframeP);
372

373 374
      if (RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ue_reestablishment_reject_timer > 0) {
        RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ue_reestablishment_reject_timer++;
375

376 377 378
        if(RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ue_reestablishment_reject_timer >=
          RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ue_reestablishment_reject_timer_thres) {
          RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ue_reestablishment_reject_timer = 0;
379

380 381 382 383 384 385 386 387
          for (int ue_id_l = 0; ue_id_l < MAX_MOBILES_PER_GNB; ue_id_l++) {
            if (reestablish_rnti_map[ue_id_l][0] == rnti) {
            // clear currentC-RNTI from map
            reestablish_rnti_map[ue_id_l][0] = 0;
            reestablish_rnti_map[ue_id_l][1] = 0;
            break;
            }
          }
388

389 390
          // Note: This should not be done in the MAC!
          for (int ii=0; ii<MAX_MOBILES_PER_GNB; ii++) {
391
            NR_gNB_ULSCH_t *ulsch = RC.gNB[module_idP][CC_id]->ulsch[ii][0];
392
            if((ulsch != NULL) && (ulsch->rnti == rnti)){
393
              LOG_W(MAC, "TODO: clean_eNb_ulsch UE %x \n", rnti);
394
              clean_gNB_ulsch(ulsch);
395 396 397 398
            }
          }

          for (int ii=0; ii<MAX_MOBILES_PER_GNB; ii++) {
laurent's avatar
laurent committed
399
            NR_gNB_DLSCH_t *dlsch = RC.gNB[module_idP][CC_id]->dlsch[ii][0];
400
            if((dlsch != NULL) && (dlsch->rnti == rnti)){
401
              LOG_W(MAC, "TODO: clean_eNb_dlsch UE %x \n", rnti);
402
              clean_gNB_dlsch(dlsch);
403 404
            }
          }
405

406 407
          for(int j = 0; j < 10; j++){
            nfapi_ul_config_request_body_t *ul_req_tmp = NULL;
408
            ul_req_tmp = &RC.nrmac[module_idP]->UL_req_tmp[CC_id][j].ul_config_request_body;
409 410 411 412 413 414 415 416 417 418 419 420 421 422
            if(ul_req_tmp){
              int pdu_number = ul_req_tmp->number_of_pdus;
              for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--){
                if(ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti){
                  LOG_I(MAC, "remove UE %x from ul_config_pdu_list %d/%d\n", rnti, pdu_index, pdu_number);
                 if(pdu_index < pdu_number -1){
                    memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
                  }
                  ul_req_tmp->number_of_pdus--;
                }
              }
            }
          }
          rrc_mac_remove_ue(module_idP,rnti);
423
        }
424 425 426
      } //END if (RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[i].ue_reestablishment_reject_timer > 0)
    } //END if (UE_list->active[i])
  } //END for (i = 0; i < MAX_MOBILES_PER_GNB; i++)
427

428
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES,NOT_A_RNTI, frameP, slotP,module_idP);
429

430 431
  pdcp_run(&ctxt);

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
432
  //rrc_rx_tx(&ctxt, CC_id);
433 434

  // This schedules MIB
435 436
  if((slotP == 0) && (frameP & 7) == 0){
    schedule_nr_mib(module_idP, frameP, slotP);
437
  }
438

Guy De Souza's avatar
Guy De Souza committed
439
  // Phytest scheduling/ option not activated because of pending bug
440

441 442
  /*if (slotP==2)
    nr_schedule_css_dlsch_phytest(module_idP, frameP, slotP);*/
Guy De Souza's avatar
Guy De Souza committed
443

444
  if (slotP==1){
445
  nr_schedule_uss_dlsch_phytest(module_idP, frameP, slotP, NULL);
446
  }
447

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
448
  /*
449 450
  // Allocate CCEs for good after scheduling is done
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++)
451
    allocate_CCEs(module_idP, CC_id, subframeP, 0);
452

453
  stop_meas(&RC.nrmac[module_idP]->eNB_scheduler);
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
454
  */
455

456
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_OUT);
Raymond Knopp's avatar
Raymond Knopp committed
457
}