eNB_scheduler.c 34.6 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
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, 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
#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"
55

56 57
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
58

59 60
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"
61

62
//Agent-related headers
63 64 65
#include "enb_agent_extern.h"
#include "enb_agent_mac.h"
#include "enb_agent_mac_proto.h"
66

67 68
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
69 70
#endif

71 72
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1
73
#define ENABLE_ENB_AGENT_DL_SCHEDULER
74
//#define DISABLE_SF_TRIGGER
75

76 77
//#define DEBUG_HEADER_PARSING 1
//#define DEBUG_PACKET_TRACE 1
78

79 80 81 82 83
/*
  #ifndef USER_MODE
  #define msg debug_msg
  #endif
 */
84 85 86



87

88 89 90



91 92
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
{
93

Raymond Knopp's avatar
 
Raymond Knopp committed
94
  int mbsfn_status[MAX_NUM_CCs];
95
  protocol_ctxt_t   ctxt;
96
#ifdef EXMIMO
97
  int ret;
98
#endif
99
#if defined(ENABLE_ITTI)
100 101 102 103
  MessageDef   *msg_p;
  const char   *msg_name;
  instance_t    instance;
  int           result;
104
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
105
  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
Raymond Knopp's avatar
 
Raymond Knopp committed
106
  int CC_id,i,next_i;
Raymond Knopp's avatar
 
Raymond Knopp committed
107
  UE_list_t *UE_list=&eNB_mac_inst[module_idP].UE_list;
108
  rnti_t rnti;
109

110 111
  Protocol__ProgranMessage *msg;

112
  LOG_D(MAC,"[eNB %d] Frame %d, Subframe %d, entering MAC scheduler (UE_list->head %d)\n",module_idP, frameP, subframeP,UE_list->head);
113

114
  start_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
115
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
116

117
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
118
    DCI_pdu[CC_id] = &eNB_mac_inst[module_idP].common_channels[CC_id].DCI_pdu;
119 120
    DCI_pdu[CC_id]->nCCE=0;
    DCI_pdu[CC_id]->num_pdcch_symbols=1;
Raymond Knopp's avatar
 
Raymond Knopp committed
121
    mbsfn_status[CC_id]=0;
122 123
    // clear vrb_map
    memset(eNB_mac_inst[module_idP].common_channels[CC_id].vrb_map,0,100);
Raymond Knopp's avatar
 
Raymond Knopp committed
124
  }
125

Raymond Knopp's avatar
 
Raymond Knopp committed
126
  // refresh UE list based on UEs dropped by PHY in previous subframe
127 128 129
  i = UE_list->head;

  while (i>=0) {
130 131 132 133
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
    LOG_D(MAC,"UE %d: rnti %x (%p)\n", i, rnti,
          mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti));
134
    next_i= UE_list->next[i];
135

136 137
    if (mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti)==NULL) {
      mac_remove_ue(module_idP, i, frameP, subframeP);
138 139
    }
    i = next_i;
Raymond Knopp's avatar
 
Raymond Knopp committed
140
  }
141

142
#if defined(ENABLE_ITTI)
143

144
  do {
145 146
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
147

148 149 150
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
151

152 153 154 155
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
156

157 158 159 160
      case RRC_MAC_BCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_BCCH_DATA_REQ (msg_p).frame, RRC_MAC_BCCH_DATA_REQ (msg_p).enb_index);
161

162 163
        // TODO process BCCH data req.
        break;
164

165 166 167 168
      case RRC_MAC_CCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_CCCH_DATA_REQ (msg_p).frame, RRC_MAC_CCCH_DATA_REQ (msg_p).enb_index);
169

170 171
        // TODO process CCCH data req.
        break;
172 173 174

#ifdef Rel10

175 176 177 178
      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",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              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);
179

180 181 182
        // TODO process MCCH data req.
        break;
#endif
183

184 185 186
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
187
      }
188 189 190 191

      result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
      AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    }
192
  } while(msg_p != NULL);
193

194 195
#endif

196
  // clear DCI and BCCH contents before scheduling
197
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
198 199
    DCI_pdu[CC_id]->Num_common_dci  = 0;
    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
200

201

202
#ifdef Rel10
203
    eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0;
204
#endif
205

Raymond Knopp's avatar
 
Raymond Knopp committed
206 207
    eNB_mac_inst[module_idP].frame    = frameP;
    eNB_mac_inst[module_idP].subframe = subframeP;
208 209


Raymond Knopp's avatar
 
Raymond Knopp committed
210
  }
211 212 213 214 215 216 217 218
  
#ifndef DISABLE_SF_TRIGGER
  //Send subframe trigger to the controller
  if (mac_agent_registered[module_idP]) {
    agent_mac_xface[module_idP]->enb_agent_send_sf_trigger(module_idP);
  }
#endif
  
219
  //if (subframeP%5 == 0)
Raymond Knopp's avatar
 
Raymond Knopp committed
220
  //#ifdef EXMIMO
221
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,module_idP);
222
  pdcp_run(&ctxt);
Raymond Knopp's avatar
 
Raymond Knopp committed
223
  //#endif
224

225
  // check HO
226 227
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
228
            CC_id);
229 230

#ifdef Rel10
231 232

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
233 234 235 236
    if (eNB_mac_inst[module_idP].common_channels[CC_id].MBMS_flag >0) {
      start_meas(&eNB_mac_inst[module_idP].schedule_mch);
      mbsfn_status[CC_id] = schedule_MBMS(module_idP,CC_id,frameP,subframeP);
      stop_meas(&eNB_mac_inst[module_idP].schedule_mch);
Raymond Knopp's avatar
 
Raymond Knopp committed
237
    }
238
  }
239

240
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
241
  // refresh UE list based on UEs dropped by PHY in previous subframe
242
  /*
Raymond Knopp's avatar
 
Raymond Knopp committed
243 244 245
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
246
    LOG_T(MAC,"UE %d : rnti %x, stats %p\n",i,UE_RNTI(module_idP,i),mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i)));
Raymond Knopp's avatar
 
Raymond Knopp committed
247
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
Raymond Knopp's avatar
 
Raymond Knopp committed
248
      mac_remove_ue(module_idP,i,frameP);
Raymond Knopp's avatar
 
Raymond Knopp committed
249 250 251
    }
    i=next_i;
  }
252
  */
253

254
  switch (subframeP) {
255
  case 0:
256

257
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
258
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
259
    // Schedule Normal DLSCH
260

Raymond Knopp's avatar
Raymond Knopp committed
261

262 263
    schedule_RA(module_idP,frameP,subframeP,2);

264 265

    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
266
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
267 268 269
    } else if  ((mac_xface->lte_frame_parms->tdd_config == TDD) || //TDD
                (mac_xface->lte_frame_parms->tdd_config == 3) ||
                (mac_xface->lte_frame_parms->tdd_config == 6)) {
270
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
271
    }
272
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
273 274
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
275 276 277 278 279 280 281 282 283 284
#else
    if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
285
	  apply_dl_scheduling_decisions(module_idP,
286 287 288 289 290 291 292
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
293 294 295
    break;

  case 1:
296

297
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
298 299
    // FDD, schedule normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
300 301 302
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 0:
      case 1:
303
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
304
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
305
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
306
#endif
307 308 309
        break;

      case 6:
310
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
311
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
312
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
313
#endif
314 315 316 317 318 319
        break;

      default:
        break;
      }
    } else { //FDD
320
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
321
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
322
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
323
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
324 325 326 327 328 329 330 331 332 333
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
334
	  apply_dl_scheduling_decisions(module_idP,
335 336 337 338 339 340 341
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
342
    }
343

344
    break;
345 346

  case 2:
347

348
    // TDD, nothing
349 350
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
351
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
352
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
353
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
354
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
355 356 357 358 359 360 361 362 363 364
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
365
	  apply_dl_scheduling_decisions(module_idP,
366 367 368 369 370 371 372
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
373
    }
374

375 376 377
    break;

  case 3:
378

379
    // TDD Config 2, ULSCH for subframeP 7
380 381 382
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
383 384
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 2:
385
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
386 387 388

        // no break here!
      case 5:
389
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
390 391
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
392 393 394 395 396 397 398 399 400 401
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
402
	  apply_dl_scheduling_decisions(module_idP,
403 404 405 406 407 408 409
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
410 411 412 413 414 415
        break;

      default:
        break;
      }
    } else { //FDD
416

417
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
418
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
419
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
420
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
421 422 423 424 425 426 427 428 429 430
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
431
	  apply_dl_scheduling_decisions(module_idP,
432 433 434 435 436 437 438
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
439
    }
440

441
    break;
442 443

  case 4:
444

445
    // TDD Config 1, ULSCH for subframeP 8
446 447 448
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == 1) { // TDD
449 450
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 1:
451
        //        schedule_RA(module_idP,frameP,subframeP);
452
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
453 454 455 456 457 458 459 460 461

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
462
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
463
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
464 465 466 467 468 469 470 471 472 473 474
	fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
475
	  apply_dl_scheduling_decisions(module_idP,
476 477 478 479 480 481 482
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif	
483 484 485 486 487 488 489 490
        break;

      default:
        break;
      }
    } else {
      if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD

491 492
	//        schedule_RA(module_idP,frameP, subframeP, 0);
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
493
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
494
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
495
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
496 497 498 499 500 501 502 503 504 505
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
506
	  apply_dl_scheduling_decisions(module_idP,
507 508 509 510 511 512 513
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}     
#endif
514
      }
515
    }
516

517 518 519 520 521 522 523
    break;

  case 5:
    // TDD/FDD Schedule SI
    // TDD Config 0,6 ULSCH for subframes 9,3 resp.
    // TDD normal DLSCH
    // FDD normal UL/DLSCH
524
    schedule_SI(module_idP,frameP,subframeP);
525

526
    //schedule_RA(module_idP,frameP,subframeP,5);
527
    if (mac_xface->lte_frame_parms->frame_type == FDD) {
528 529
      schedule_RA(module_idP,frameP,subframeP,1);
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
530
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
531 532
      schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
533 534 535 536 537 538 539 540 541 542
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
543
	  apply_dl_scheduling_decisions(module_idP,
544 545 546 547 548 549 550
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
551 552
    } else if ((mac_xface->lte_frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->lte_frame_parms->tdd_config == 6)) { // TDD Config 6
553
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
554
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
555
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
556
#endif
557
    } else {
558
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
559 560
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
561 562 563 564 565 566 567 568 569 570
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
571
	  apply_dl_scheduling_decisions(module_idP,
572 573 574 575 576 577 578
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
579
    }
580

581 582 583
    break;

  case 6:
584

585 586 587 588
    // 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
589 590 591 592 593
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 0:
        break;

      case 1:
594
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
595
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
596
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
597
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
598
#endif
599 600 601
        break;

      case 6:
602
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
603
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
604
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
605
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
606
#endif
607 608 609
        break;

      case 5:
610
        schedule_RA(module_idP,frameP,subframeP,2);
611
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
612 613
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
614 615 616 617 618 619 620 621 622 623
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
624
	  apply_dl_scheduling_decisions(module_idP,
625 626 627 628 629 630 631
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
632 633 634 635
        break;

      case 3:
      case 4:
636
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
637 638
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
639 640 641 642 643 644 645 646 647 648
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
649
	  apply_dl_scheduling_decisions(module_idP,
650 651 652 653 654 655 656
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
657 658 659 660 661 662
        break;

      default:
        break;
      }
    } else { //FDD
663
      //      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0);
664
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
665
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
666
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
667 668 669 670 671 672 673 674 675 676
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
677
	  apply_dl_scheduling_decisions(module_idP,
678 679 680 681 682 683 684
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
685
    }
686

687
    break;
688

689
  case 7:
690

691 692 693
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
694 695 696
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 3:
      case 4:
697
        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
698
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
699 700
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
701 702 703 704 705 706 707 708 709 710
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
711
	  apply_dl_scheduling_decisions(module_idP,
712 713 714 715 716 717 718
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
719 720 721
        break;

      case 5:
722
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
723 724
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
725 726 727 728 729 730 731 732 733 734
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
735
	  apply_dl_scheduling_decisions(module_idP,
736 737 738 739 740 741 742
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
743 744 745 746 747 748
        break;

      default:
        break;
      }
    } else { //FDD
749
      //schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
750
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
751
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
752
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
753 754 755 756 757 758 759 760 761 762
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
763
	  apply_dl_scheduling_decisions(module_idP,
764 765 766 767 768 769 770
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
771
    }
772

773 774 775
    break;

  case 8:
776

777
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
778 779 780
    //
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
781 782 783 784 785 786
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 2:
      case 3:
      case 4:
      case 5:

787
        //  schedule_RA(module_idP,subframeP);
788
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
789
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
790 791
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
792 793 794 795 796 797 798 799 800 801
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
802
	  apply_dl_scheduling_decisions(module_idP,
803 804 805 806 807 808 809
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
810 811 812 813 814 815
        break;

      default:
        break;
      }
    } else { //FDD
816
      //schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
817
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
818
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
819
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
820 821 822 823 824 825 826 827 828 829
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
830
	  apply_dl_scheduling_decisions(module_idP,
831 832 833 834 835 836 837
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
838
    }
839

840 841 842
    break;

  case 9:
843

844 845
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
846 847
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 1:
848
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
849
        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
850
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
851 852
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
853 854 855 856 857 858 859 860 861 862
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
863
	  apply_dl_scheduling_decisions(module_idP,
864 865 866 867 868 869 870
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
871 872 873 874
        break;

      case 3:
      case 4:
875
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
876
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
877 878
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
879 880 881 882 883 884 885 886 887 888
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
889
	  apply_dl_scheduling_decisions(module_idP,
890 891 892 893 894 895 896
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
897 898 899
        break;

      case 6:
900
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);
901
        //schedule_RA(module_idP,frameP,subframeP);
902
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
903 904
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
905 906 907 908 909 910 911 912 913 914
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
915
	  apply_dl_scheduling_decisions(module_idP,
916 917 918 919 920 921 922
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
923 924 925 926
        break;

      case 2:
      case 5:
927
        //schedule_RA(module_idP,frameP,subframeP);
928
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
929 930
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
931 932 933 934 935 936 937 938 939 940
#else
	if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
941
	  apply_dl_scheduling_decisions(module_idP,
942 943 944 945 946 947 948
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
949 950 951 952 953 954
        break;

      default:
        break;
      }
    } else { //FDD
955
      //     schedule_ulsch(module_idP,frameP,cooperation_flag,9,3);
956
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
957
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
958
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
959 960 961 962 963 964 965 966 967 968
#else
      if (mac_agent_registered[module_idP]) {                                  
	  enb_agent_mac_create_empty_dl_config(module_idP, &msg);
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
                                                                msg);
	  
969
	  apply_dl_scheduling_decisions(module_idP,
970 971 972 973 974 975 976
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
      }
#endif
977
    }
978

979
    break;
980

981
  }
982

983
  LOG_D(MAC,"FrameP %d, subframeP %d : Scheduling CCEs\n",frameP,subframeP);
984

985
  // Allocate CCEs for good after scheduling is done
986 987
  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++)
    allocate_CCEs(module_idP,CC_id,subframeP,0);
988

989
  LOG_D(MAC,"frameP %d, subframeP %d\n",frameP,subframeP);
990

991
  stop_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
992
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_OUT);
993

994
}
995 996 997