eNB_scheduler.c 16.1 KB
Newer Older
1
/*******************************************************************************
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
22 23 24 25 26
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.
27

28
*******************************************************************************/
29
/*! \file eNB_scheduler.c
30
 * \brief eNB scheduler top level function operates on per subframe basis
31 32
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
33
 * \email: navid.nikaein@eurecom.fr
34 35
 * \version 0.5
 * @ingroup _mac
36

37
 */
38

39
#include "assertions.h"
40 41 42 43 44 45 46 47
#include "PHY/defs.h"
#include "PHY/extern.h"

#include "SCHED/defs.h"
#include "SCHED/extern.h"

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/extern.h"
48

49 50 51 52 53 54 55 56 57
#include "LAYER2/MAC/proto.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"
#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h"
#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h"
#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h"
58

59 60
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
61

62 63
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"
64

65 66
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
67 68
#endif

69 70 71 72
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1
//#define DEBUG_HEADER_PARSING 1
//#define DEBUG_PACKET_TRACE 1
73

74 75 76 77 78
/*
  #ifndef USER_MODE
  #define msg debug_msg
  #endif
 */
79 80 81



82

83
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP) {//, int calibration_flag) {
84

85
  start_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
86 87 88
  unsigned char nprb=0;
  unsigned int nCCE=0;
  int mbsfn_status=0;
89
  uint32_t RBalloc=0;
90
#ifdef EXMIMO
91
  int ret;
92
#endif
93
#if defined(ENABLE_ITTI)
94 95 96 97
  MessageDef   *msg_p;
  const char   *msg_name;
  instance_t    instance;
  int           result;
98
#endif
99

100
  DCI_PDU *DCI_pdu= &eNB_mac_inst[module_idP].DCI_pdu;
101
  LOG_D(MAC,"[eNB %d] Frame %d, Subframe %d, entering MAC scheduler\n",module_idP, frameP, subframeP);
102 103 104

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,1);

105 106
#if defined(ENABLE_ITTI)
  do {
107 108
      // Checks if a message has been sent to MAC sub-task
      itti_poll_msg (TASK_MAC_ENB, &msg_p);
109

110 111 112
      if (msg_p != NULL) {
          msg_name = ITTI_MSG_NAME (msg_p);
          instance = ITTI_MSG_INSTANCE (msg_p);
113

114 115 116 117
          switch (ITTI_MSG_ID(msg_p)) {
          case MESSAGE_TEST:
            LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
            break;
118

119 120
          case RRC_MAC_BCCH_DATA_REQ:
            LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
121
                msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
122
                RRC_MAC_BCCH_DATA_REQ (msg_p).frame, RRC_MAC_BCCH_DATA_REQ (msg_p).enb_index);
123

124 125
            // TODO process BCCH data req.
            break;
126

127 128
          case RRC_MAC_CCCH_DATA_REQ:
            LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
129
                msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
130
                RRC_MAC_CCCH_DATA_REQ (msg_p).frame, RRC_MAC_CCCH_DATA_REQ (msg_p).enb_index);
131

132 133
            // TODO process CCCH data req.
            break;
134 135

#ifdef Rel10
136 137
          case RRC_MAC_MCCH_DATA_REQ:
            LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d, mbsfn_sync_area %d\n",
138
                msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
139
                RRC_MAC_MCCH_DATA_REQ (msg_p).frame, RRC_MAC_MCCH_DATA_REQ (msg_p).enb_index, RRC_MAC_MCCH_DATA_REQ (msg_p).mbsfn_sync_area);
140

141 142
            // TODO process MCCH data req.
            break;
143 144
#endif

145 146 147 148
          default:
            LOG_E(MAC, "Received unexpected message %s\n", msg_name);
            break;
          }
149

150 151 152
          result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
          AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
      }
153 154 155
  } while(msg_p != NULL);
#endif

156
  // clear DCI and BCCH contents before scheduling
157 158
  DCI_pdu->Num_common_dci  = 0;
  DCI_pdu->Num_ue_spec_dci = 0;
159
  eNB_mac_inst[module_idP].bcch_active = 0;
160 161

#ifdef Rel10
162
  eNB_mac_inst[module_idP].mcch_active =0;
163 164
#endif

165 166
  eNB_mac_inst[module_idP].frame    = frameP;
  eNB_mac_inst[module_idP].subframe = subframeP;
167

168
  //if (subframeP%5 == 0)
169
#ifdef EXMIMO
170
  pdcp_run(frameP, 1, 0, module_idP);
171 172
#endif
#ifdef CELLULAR
173
  rrc_rx_tx(module_idP, frameP, 0, 0);
174 175
#else
  // check HO
176 177 178 179
  rrc_rx_tx(module_idP,
      frameP,
      1,
      module_idP);
180 181 182
#endif

#ifdef Rel10
183
  if (eNB_mac_inst[module_idP].MBMS_flag >0) {
184
    start_meas(&eNB_mac_inst[module_idP].schedule_mch);
185
      mbsfn_status = schedule_MBMS(module_idP,frameP,subframeP);
186
    stop_meas(&eNB_mac_inst[module_idP].schedule_mch);
187 188 189
  }
#endif

190
  switch (subframeP) {
191 192
  case 0:
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
193
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
194
    // Schedule Normal DLSCH
195 196

    schedule_RA(module_idP,frameP,subframeP,2,&nprb,&nCCE);
197 198

    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
199
        schedule_ulsch(module_idP,frameP,cooperation_flag,0,4,&nCCE);//,calibration_flag);
200 201
    }
    else if  ((mac_xface->lte_frame_parms->tdd_config == TDD) || //TDD
202 203 204 205
        (mac_xface->lte_frame_parms->tdd_config == 3) ||
        (mac_xface->lte_frame_parms->tdd_config == 6))
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4,&nCCE);//,calibration_flag);

206

207
      // schedule_ue_spec(module_idP,subframeP,nprb,&nCCE,mbsfn_status);
208

209
      fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,1,mbsfn_status);
210 211 212
    break;

  case 1:
213
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
214 215
    // FDD, schedule normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
216 217 218 219 220 221 222 223 224 225 226 227 228
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 0:
        case 1:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7,&nCCE);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        case 6:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8,&nCCE);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        default:
          break;
        }
229 230
    }
    else {  //FDD
231 232 233
        schedule_ulsch(module_idP,frameP,cooperation_flag,1,5,&nCCE);
        // schedule_ue_spec(module_idP,subframeP,nprb,&nCCE,mbsfn_status);
        // fill_DLSCH_dci(module_idP,subframeP,RBalloc,0,mbsfn_status);
234 235
    }
    break;
236 237

  case 2:
238
    // TDD, nothing
239 240
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
241 242 243
        schedule_ulsch(module_idP,frameP,cooperation_flag,2,6,&nCCE);
        // schedule_ue_spec(module_idP,subframeP,nprb,&nCCE,mbsfn_status);
        // fill_DLSCH_dci(module_idP,subframeP,RBalloc,0,mbsfn_status);
244 245 246 247
    }
    break;

  case 3:
248
    // TDD Config 2, ULSCH for subframeP 7
249 250 251
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
252 253 254 255 256 257 258 259 260 261
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 2:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7,&nCCE);
        case 5:
          schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        default:
          break;
        }
262 263
    }
    else { //FDD
264 265 266
        //      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7,&nCCE);
        // schedule_ue_spec(module_idP,subframeP,0,0,mbsfn_status);
        // fill_DLSCH_dci(module_idP,subframeP,RBalloc,0,mbsfn_status);
267 268
    }
    break;
269 270

  case 4:
271
    // TDD Config 1, ULSCH for subframeP 8
272 273 274
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == 1) { // TDD
275 276 277 278 279 280 281 282 283 284 285 286 287
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 1:
          //        schedule_RA(module_idP,frameP,subframeP,&nprb,&nCCE);
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8,&nCCE);
        case 2:
        case 4:
        case 5:
          schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,1,mbsfn_status);
          break;
        default:
          break;
        }
288 289
    }
    else {
290 291 292 293 294
        if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
            schedule_RA(module_idP, frameP, subframeP, 0, &nprb, &nCCE);
            //	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8, &nCCE);
            //schedule_ue_spec(module_idP, frameP, subframeP, nprb, &nCCE, mbsfn_status);
            fill_DLSCH_dci(module_idP, frameP, subframeP, RBalloc, 1, mbsfn_status);
Raymond Knopp's avatar
Raymond Knopp committed
295

296
        }
297 298 299 300 301 302 303 304
    }
    break;

  case 5:
    // TDD/FDD Schedule SI
    // TDD Config 0,6 ULSCH for subframes 9,3 resp.
    // TDD normal DLSCH
    // FDD normal UL/DLSCH
305 306
    schedule_SI(module_idP,frameP,&nprb,&nCCE);
    //schedule_RA(module_idP,frameP,subframeP,5,&nprb,&nCCE);
307
    if ((mac_xface->lte_frame_parms->frame_type == FDD) ) {
308 309 310
        //      schedule_RA(module_idP,frameP,subframeP,1,&nprb,&nCCE);
        //      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9,&nCCE);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
311 312 313

    }
    else if ((mac_xface->lte_frame_parms->tdd_config == 0) || // TDD Config 0
314 315 316
        (mac_xface->lte_frame_parms->tdd_config == 6)) { // TDD Config 6
        //schedule_ulsch(module_idP,cooperation_flag,subframeP,&nCCE);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
317 318
    }
    else {
319 320
        //schedule_ue_spec(module_idP,subframeP,nprb,&nCCE,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
321 322 323 324 325 326 327 328
    }
    break;

  case 6:
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 0:
          break;
        case 1:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2,&nCCE);
          //	schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        case 6:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3,&nCCE);
          //	schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        case 5:
          schedule_RA(module_idP,frameP,subframeP,2,&nprb,&nCCE);
          schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,1,mbsfn_status);
          break;
        case 3:
        case 4:
          schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;

        default:
          break;
        }
356 357
    }
    else {  //FDD
358 359 360
        //      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0,&nCCE);
        schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
361 362
    }
    break;
363

364 365 366 367
  case 7:
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
368 369 370 371 372 373 374 375 376 377 378 379 380 381
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 3:
        case 4:
          //	  schedule_RA(module_idP,frameP,subframeP,3,&nprb,&nCCE);  // 3 = Msg3 subframeP, not
          schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status); //1,mbsfn_status);
          break;
        case 5:
          schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        default:
          break;
        }
382
    }
383
    else {  //FDD
384 385 386
        //      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1,&nCCE);
        schedule_ue_spec(module_idP,frameP,subframeP,nprb,&nCCE,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
387 388 389 390
    }
    break;

  case 8:
391
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
392 393 394
    //
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
395 396 397 398 399 400 401 402 403 404 405 406 407 408
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 2:
        case 3:
        case 4:
        case 5:

          //	schedule_RA(module_idP,subframeP,&nprb,&nCCE);
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2,&nCCE);
          schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        default:
          break;
        }
409 410
    }
    else {  //FDD
411 412 413
        //      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2,&nCCE);
        schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
414 415 416 417 418 419
    }
    break;

  case 9:
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
        switch (mac_xface->lte_frame_parms->tdd_config) {
        case 1:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3,&nCCE);
          schedule_RA(module_idP,frameP,subframeP,7,&nprb,&nCCE);  // 7 = Msg3 subframeP, not
          schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,1,mbsfn_status);
          break;
        case 3:
        case 4:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3,&nCCE);
          schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        case 6:
          schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4,&nCCE);
          //schedule_RA(module_idP,frameP,subframeP,&nprb,&nCCE);
          schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        case 2:
        case 5:
          //schedule_RA(module_idP,frameP,subframeP,&nprb,&nCCE);
          schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
          fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
          break;
        default:
          break;
        }
448 449
    }
    else {  //FDD
450 451 452
        //      schedule_ulsch(module_idP,frameP,cooperation_flag,9,3,&nCCE);
        schedule_ue_spec(module_idP,frameP,subframeP,0,&nCCE,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,RBalloc,0,mbsfn_status);
453 454
    }
    break;
455

456
  }
457 458

  DCI_pdu->nCCE = nCCE;
459
  LOG_D(MAC,"frameP %d, subframeP %d nCCE %d\n",frameP,subframeP,nCCE);
460 461

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,0);
462
  stop_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
463

464
}
465 466 467