eNB_scheduler.c 33.7 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

nikaeinn's avatar
nikaeinn committed
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


nikaeinn's avatar
nikaeinn committed
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

nikaeinn's avatar
nikaeinn committed
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
nikaeinn's avatar
nikaeinn committed
22 23
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
nikaeinn's avatar
nikaeinn committed
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

nikaeinn's avatar
nikaeinn committed
28
*******************************************************************************/
29
/*! \file eNB_scheduler.c
nikaeinn's avatar
nikaeinn committed
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"
gauthier's avatar
gauthier committed
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"
gauthier's avatar
gauthier committed
55

56 57
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
gauthier's avatar
gauthier committed
58

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

62
//Agent-related headers
nikaeinn's avatar
nikaeinn committed
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
gauthier's avatar
gauthier committed
78

79 80 81 82 83
/*
  #ifndef USER_MODE
  #define msg debug_msg
  #endif
 */
gauthier's avatar
gauthier committed
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

knopp's avatar
 
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
knopp's avatar
 
knopp committed
105
  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
knopp's avatar
 
knopp committed
106
  int CC_id,i,next_i;
knopp's avatar
 
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);
gauthier's avatar
gauthier committed
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++) {
knopp's avatar
 
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;
knopp's avatar
 
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);
knopp's avatar
 
knopp committed
124
  }
125

knopp's avatar
 
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 140 141 142 143
      //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
      if (mac_agent_registered[module_idP]) {
	agent_mac_xface[module_idP]->enb_agent_notify_ue_state_change(module_idP,
								      rnti,
								      PROTOCOL__PRP_UE_STATE_CHANGE_TYPE__PRUESC_DEACTIVATED);
      }
144 145
    }
    i = next_i;
knopp's avatar
 
knopp committed
146
  }
147

148
#if defined(ENABLE_ITTI)
149

150
  do {
151 152
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
153

154 155 156
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
157

158 159 160 161
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
162

163 164 165 166
      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);
167

168 169
        // TODO process BCCH data req.
        break;
170

171 172 173 174
      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);
175

176 177
        // TODO process CCCH data req.
        break;
178 179 180

#ifdef Rel10

181 182 183 184
      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);
185

186 187 188
        // TODO process MCCH data req.
        break;
#endif
189

190 191 192
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
193
      }
194 195 196 197

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

200 201
#endif

gauthier's avatar
gauthier committed
202
  // clear DCI and BCCH contents before scheduling
203
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
204 205
    DCI_pdu[CC_id]->Num_common_dci  = 0;
    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
206

207

208
#ifdef Rel10
209
    eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0;
210
#endif
211

knopp's avatar
 
knopp committed
212 213
    eNB_mac_inst[module_idP].frame    = frameP;
    eNB_mac_inst[module_idP].subframe = subframeP;
214 215


knopp's avatar
 
knopp committed
216
  }
217 218 219 220 221
  
#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);
222
    agent_mac_xface[module_idP]->enb_agent_send_update_mac_stats(module_idP);
223 224 225
  }
#endif
  
gauthier's avatar
gauthier committed
226
  //if (subframeP%5 == 0)
knopp's avatar
 
knopp committed
227
  //#ifdef EXMIMO
228
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,module_idP);
229
  pdcp_run(&ctxt);
knopp's avatar
 
knopp committed
230
  //#endif
231

232
  // check HO
233 234
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
235
            CC_id);
236 237

#ifdef Rel10
238 239

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
240 241 242 243
    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);
knopp's avatar
 
knopp committed
244
    }
245
  }
246

247
#endif
knopp's avatar
 
knopp committed
248
  // refresh UE list based on UEs dropped by PHY in previous subframe
249
  /*
knopp's avatar
 
knopp committed
250 251 252
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
253
    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)));
knopp's avatar
 
knopp committed
254
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
 
knopp committed
255
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
 
knopp committed
256 257 258
    }
    i=next_i;
  }
259
  */
260

gauthier's avatar
gauthier committed
261
  switch (subframeP) {
262
  case 0:
263

264
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
265
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
266
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
267

knopp's avatar
knopp committed
268

269 270
    schedule_RA(module_idP,frameP,subframeP,2);

271 272

    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
273
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
274 275 276
    } 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)) {
277
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
278
    }
279
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
280 281
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
282 283 284 285 286 287 288
#else
    if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
289
                                                                &msg);
290
	  
291
	  apply_dl_scheduling_decisions(module_idP,
292 293 294 295 296 297 298
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
299 300 301
    break;

  case 1:
302

gauthier's avatar
gauthier committed
303
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
304 305
    // FDD, schedule normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
306 307 308
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 0:
      case 1:
309
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
310
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
311
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
312
#endif
313 314 315
        break;

      case 6:
316
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
317
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
318
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
319
#endif
320 321 322 323 324 325
        break;

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

349
    break;
350 351

  case 2:
352

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

379 380 381
    break;

  case 3:
382

gauthier's avatar
gauthier committed
383
    // TDD Config 2, ULSCH for subframeP 7
384 385 386
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
387 388
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 2:
389
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
390 391 392

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

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

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

443
    break;
444 445

  case 4:
446

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

        // no break here!
      case 2:

        // no break here!
      case 4:

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

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

492 493
	//        schedule_RA(module_idP,frameP, subframeP, 0);
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
494
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
495
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
496
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
497 498 499 500 501 502 503
#else
	if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
504
                                                                &msg);
505
	  
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
#else
      if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
540
                                                                &msg);
541
	  
542
	  apply_dl_scheduling_decisions(module_idP,
543 544 545 546 547 548 549
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
550 551
    } else if ((mac_xface->lte_frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->lte_frame_parms->tdd_config == 6)) { // TDD Config 6
552
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
553
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
554
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
555
#endif
556
    } else {
557
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
558 559
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
560 561 562 563 564 565 566
#else
      if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
567
                                                                &msg);
568
	  
569
	  apply_dl_scheduling_decisions(module_idP,
570 571 572 573 574 575 576
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
577
    }
578

579 580 581
    break;

  case 6:
582

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

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

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

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

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

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

682
    break;
gauthier's avatar
gauthier committed
683

684
  case 7:
685

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

      case 5:
716
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
717 718
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
719 720 721 722 723 724 725
#else
	if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
726
                                                                &msg);
727
	  
728
	  apply_dl_scheduling_decisions(module_idP,
729 730 731 732 733 734 735
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
736 737 738 739 740 741
        break;

      default:
        break;
      }
    } else { //FDD
742
      //schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
743
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
744
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
745
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
746 747 748 749 750 751 752
#else
      if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
753
                                                                &msg);
754
	  
755
	  apply_dl_scheduling_decisions(module_idP,
756 757 758 759 760 761 762
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
763
    }
764

765 766 767
    break;

  case 8:
768

gauthier's avatar
gauthier committed
769
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
770 771 772
    //
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
773 774 775 776 777 778
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 2:
      case 3:
      case 4:
      case 5:

779
        //  schedule_RA(module_idP,subframeP);
780
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
781
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
782 783
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
784 785 786 787 788 789 790
#else
	if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
791
                                                                &msg);
792
	  
793
	  apply_dl_scheduling_decisions(module_idP,
794 795 796 797 798 799 800
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
801 802 803 804 805 806
        break;

      default:
        break;
      }
    } else { //FDD
807
      //schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
808
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
809
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
810
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
811 812 813 814 815 816 817
#else
      if (mac_agent_registered[module_idP]) {                                  
	  agent_mac_xface[module_idP]->enb_agent_schedule_ue_spec(
                                                                module_idP,
                                                                frameP,                  
                                                                subframeP,
                                                                mbsfn_status,
818
                                                                &msg);
819
	  
820
	  apply_dl_scheduling_decisions(module_idP,
821 822 823 824 825 826 827
				     frameP,
				     subframeP,
				     mbsfn_status,
				     msg);
	  enb_agent_mac_destroy_dl_config(msg);
	}
#endif
828
    }
829

830 831 832
    break;

  case 9:
833

834 835
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
836 837
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 1:
838
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
839
        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
840
#ifndef ENABLE_ENB_AGENT_DL_SCHEDULER
841 842
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
843 844 845