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

/*! \file eNB_scheduler.c
nikaeinn's avatar
nikaeinn committed
23
 * \brief eNB scheduler top level function operates on per subframe basis
24 25
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
26
 * \email: navid.nikaein@eurecom.fr
27 28
 * \version 0.5
 * @ingroup _mac
29

30
 */
31

32
#include "assertions.h"
33 34 35 36 37 38 39 40
#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
41

42 43 44 45 46 47
#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
48

49 50
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
gauthier's avatar
gauthier committed
51

52 53
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"
54

55
#if defined(FLEXRAN_AGENT_SB_IF)
56
//Agent-related headers
57 58 59
#include "flexran_agent_extern.h"
#include "flexran_agent_mac.h"
#include "flexran_agent_mac_proto.h"
60
#endif
61

62 63
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
64 65
#endif

66 67
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1
68

69
extern RAN_CONTEXT_t RC;
70

71 72 73 74 75 76
uint16_t pdcch_order_table[6] = {31,31,511,2047,2047,8191};

void check_ul_failure(module_id_t module_idP,int CC_id,int UE_id,
		      frame_t frameP, sub_frame_t subframeP) {

  UE_list_t                           *UE_list      = &RC.mac[module_idP]->UE_list;
77
  nfapi_dl_config_request_t           *DL_req       = &RC.mac[module_idP]->DL_req[0];
78 79 80 81 82 83 84 85 86 87 88 89 90
  uint16_t                            rnti          = UE_RNTI(module_idP,UE_id);
  eNB_UE_STATS                        *eNB_UE_stats = &RC.mac[module_idP]->UE_list.eNB_UE_stats[CC_id][UE_id];
  COMMON_channels_t                   *cc           = RC.mac[module_idP]->common_channels;

  // check uplink failure
  if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer>0)&&
      (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync==0)) {
    LOG_D(MAC,"UE %d rnti %x: UL Failure timer %d \n",UE_id,rnti,UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
    if (UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent==0) {
      UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent=1;
      
      // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
      LOG_D(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",UE_id,rnti,UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);	    
91
      nfapi_dl_config_request_pdu_t* dl_config_pdu                    = &DL_req[CC_id].dl_config_request_body.dl_config_pdu_list[DL_req[CC_id].dl_config_request_body.number_pdu]; 
92 93
      memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
      dl_config_pdu->pdu_type                                         = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
94
      dl_config_pdu->pdu_size                                         = (uint8_t)(2+sizeof(nfapi_dl_config_dci_dl_pdu));
95 96 97 98 99 100 101 102 103
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format            = NFAPI_DL_DCI_FORMAT_1A;
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level     = get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->dl_cqi,format1A);
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                  = rnti;
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type             = 1;    // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power    = 6000; // equal to RS power
      
      AssertFatal((cc[CC_id].mib->message.dl_Bandwidth >=0) && (cc[CC_id].mib->message.dl_Bandwidth<6),
		  "illegal dl_Bandwidth %d\n",(int)cc[CC_id].mib->message.dl_Bandwidth);
      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = pdcch_order_table[cc[CC_id].mib->message.dl_Bandwidth];
104 105 106
      DL_req[CC_id].dl_config_request_body.number_dci++;
      DL_req[CC_id].dl_config_request_body.number_pdu++;
     
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
      /* 
	 add_ue_spec_dci(&DL_req[CC_id],
	 rnti,
	 get_aggregation(get_tw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format1A),
	 format1A,
	 NO_DLSCH);*/
    }
    else { // ra_pdcch_sent==1
      LOG_D(MAC,"UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",UE_id,rnti,UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);	    	    
      if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer % 40) == 0)
	UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent=0; // resend every 4 frames	      
    }
    
    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer++;
    // check threshold
    if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer > 200) {
      // inform RRC of failure and clear timer
      LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",UE_id,rnti);
      mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti);
      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer=0;
      UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync=1;
    }
  } // ul_failure_timer>0
  
}

133 134
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
{
135

knopp's avatar
 
knopp committed
136
  int mbsfn_status[MAX_NUM_CCs];
137
  protocol_ctxt_t   ctxt;
138

139
#if defined(ENABLE_ITTI)
140
  MessageDef   *msg_p;
141
  const char         *msg_name;
142 143
  instance_t    instance;
  int           result;
144
#endif
145
  int CC_id,i; //,next_i;
146
  UE_list_t *UE_list=&RC.mac[module_idP]->UE_list;
147
  rnti_t rnti;
148
  
149 150 151 152 153 154
  COMMON_channels_t         *cc             = RC.mac[module_idP]->common_channels;
  nfapi_dl_config_request_t *DL_req         = &RC.mac[module_idP]->DL_req[0];
  nfapi_ul_config_request_t *UL_req         = &RC.mac[module_idP]->UL_req[0];
  nfapi_hi_dci0_request_t   *HI_DCI0_req    = &RC.mac[module_idP]->HI_DCI0_req[0];
  nfapi_tx_request_t        *TX_req         = &RC.mac[module_idP]->TX_req[0];
  eNB_UE_STATS              *eNB_UE_stats;
155
#if defined(FLEXRAN_AGENT_SB_IF)
156
  Protocol__FlexranMessage *msg;
157
#endif
158

knopp's avatar
knopp committed
159
  
160
  //  LOG_I(MAC,"[eNB %d] Frame %d, Subframe %d, entering MAC scheduler (UE_list->head %d)\n",module_idP, frameP, subframeP,UE_list->head);
161

162
  start_meas(&RC.mac[module_idP]->eNB_scheduler);
gauthier's avatar
gauthier committed
163
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
164

165
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
166
    mbsfn_status[CC_id]=0;
167
    // clear vrb_map
knopp's avatar
knopp committed
168
    memset(cc[CC_id].vrb_map,0,100);
169

170 171
    // clear DL/UL info for new scheduling round

172 173 174 175 176 177
    RC.mac[module_idP]->pdu_index[CC_id]                                     = 0;
    DL_req[CC_id].dl_config_request_body.number_pdcch_ofdm_symbols           = 1;
    DL_req[CC_id].dl_config_request_body.number_dci                          = 0;
    DL_req[CC_id].dl_config_request_body.number_pdu                          = 0;
    DL_req[CC_id].dl_config_request_body.number_pdsch_rnti                   = 0;
    DL_req[CC_id].dl_config_request_body.transmission_power_pcfich           = 6000;
178

179 180
    HI_DCI0_req[CC_id].hi_dci0_request_body.sfnsf                            = subframeP + (frameP<<3);
    HI_DCI0_req[CC_id].hi_dci0_request_body.number_of_dci                    = 0;
181

182 183 184 185
    UL_req[CC_id].ul_config_request_body.number_of_pdus                      = 0;
    UL_req[CC_id].ul_config_request_body.rach_prach_frequency_resources      = 0; // ignored, handled by PHY for now
    UL_req[CC_id].ul_config_request_body.srs_present                         = 0; // ignored, handled by PHY for now
    TX_req[CC_id].tx_request_body.number_of_pdus                 = 0;
Cedric Roux's avatar
Cedric Roux committed
186
#if defined(Rel10) || defined(Rel14)
knopp's avatar
knopp committed
187
    cc[CC_id].mcch_active =0;
188
#endif
189 190
    RC.mac[module_idP]->frame    = frameP;
    RC.mac[module_idP]->subframe = subframeP;
191 192
  }

knopp's avatar
 
knopp committed
193
  // refresh UE list based on UEs dropped by PHY in previous subframe
194 195
  for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
    if (UE_list->active[i] != TRUE) continue;
196

197 198 199 200
    rnti         = UE_RNTI(module_idP, i);
    CC_id        = UE_PCCID(module_idP, i);
    eNB_UE_stats = &RC.mac[module_idP]->UE_list.eNB_UE_stats[CC_id][i];

201 202 203 204
    if ((frameP==0)&&(subframeP==0)) {
      LOG_I(MAC,"UE  rnti %x : %s, PHR %d dB CQI %d\n", rnti,
            UE_list->UE_sched_ctrl[i].ul_out_of_sync==0 ? "in synch" : "out of sync",
            UE_list->UE_template[CC_id][i].phr_info,
205
            eNB_UE_stats->dl_cqi);
206
    }
207

208
    RC.eNB[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]=-63;
209
    if (i==UE_list->head)
210
      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,RC.eNB[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]); 
211
    // increment this, it is cleared when we receive an sdu
212
    RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
213

214
    RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].cqi_req_timer++;
215

216 217 218 219 220 221 222
    // was this before: 
    //    eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);

    
    // eNB_UE_stats is never NULL now

    /*    if (eNB_UE_stats==NULL) {
223
	//mac_remove_ue(module_idP, i, frameP, subframeP);
224
      //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
225
#if defined(FLEXRAN_AGENT_S_IF)
226
      if (mac_agent_registered[module_idP]) {
227 228 229
	agent_mac_xface[module_idP]->flexran_agent_notify_ue_state_change(module_idP,
									  rnti,
									  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
230
      }
231
#endif
232 233 234
}*/
    check_ul_failure(module_idP,CC_id,i,frameP,subframeP);

knopp's avatar
 
knopp committed
235
  }
236

237
#if defined(ENABLE_ITTI)
238

239
  do {
240 241
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
242

243 244 245
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
246

247 248 249 250
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
251

252 253 254 255
      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);
256

257 258
        // TODO process BCCH data req.
        break;
259

260 261 262 263
      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);
264

265 266
        // TODO process CCCH data req.
        break;
267

Cedric Roux's avatar
Cedric Roux committed
268
#if defined(Rel10) || defined(Rel14)
269

270 271 272 273
      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);
274

275 276 277
        // TODO process MCCH data req.
        break;
#endif
278

279 280 281
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
282
      }
283 284 285 286

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

289 290
#endif

291 292 293
/* #ifndef DISABLE_SF_TRIGGER */
/*   //Send subframe trigger to the controller */
/*   if (mac_agent_registered[module_idP]) { */
294
/*     agent_mac_xface[module_idP]->flexran_agent_send_sf_trigger(module_idP); */
295 296
/*   } */
/* #endif */
297
  
298
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP,module_idP);
299
  pdcp_run(&ctxt);
300

301 302
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
303
            CC_id);
304

Cedric Roux's avatar
Cedric Roux committed
305
#if defined(Rel10) || defined(Rel14)
306 307

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
knopp committed
308
    if (cc[CC_id].MBMS_flag >0) {
309
      start_meas(&RC.mac[module_idP]->schedule_mch);
310
      mbsfn_status[CC_id] = schedule_MBMS(module_idP,CC_id,frameP,subframeP);
311
      stop_meas(&RC.mac[module_idP]->schedule_mch);
knopp's avatar
 
knopp committed
312
    }
313
  }
314

315
#endif
316

gauthier's avatar
gauthier committed
317
  switch (subframeP) {
318
  case 0:
319

320
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
321
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
322
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
323

knopp's avatar
knopp committed
324

325
    //    schedule_RA(module_idP,frameP,subframeP,2);
326
    LOG_D(MAC,"Scheduling MIB\n");
327
    if ((frameP&3) == 0) schedule_mib(module_idP,frameP,subframeP);
328
    LOG_D(MAC,"NFAPI: number_of_pdus %d, number_of_TX_req %d\n",
329 330
	  DL_req[0].dl_config_request_body.number_pdu,
	  TX_req[0].tx_request_body.number_of_pdus);
knopp's avatar
knopp committed
331
    if (cc[0].tdd_Config == NULL) {  //FDD
332
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
333 334
    } else if  ((cc[0].tdd_Config->subframeAssignment == 0) ||
		(cc[0].tdd_Config->subframeAssignment == 3) ||
knopp's avatar
knopp committed
335
                (cc[0].tdd_Config->subframeAssignment == 6)) {
336
      schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
337
    }
338
#ifndef FLEXRAN_AGENT_SB_IF
339 340
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
341 342
#else
    if (mac_agent_registered[module_idP]) {                                  
343 344 345 346 347 348
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
349
	  
350 351 352 353 354 355
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
356 357
	}
#endif
358 359 360
    break;

  case 1:
361

gauthier's avatar
gauthier committed
362
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
363
    // FDD, schedule normal UL/DLSCH
knopp's avatar
knopp committed
364 365
    if (cc[0].tdd_Config != NULL) { // TDD
      switch (cc[0].tdd_Config->subframeAssignment) {
366 367
      case 0:
      case 1:
368
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
369
#ifndef FLEXRAN_AGENT_SB_IF
370
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
371
#endif
372 373 374
        break;

      case 6:
375
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
376
#ifndef FLEXRAN_AGENT_SB_IF
377
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
378
#endif
379 380 381 382 383 384
        break;

      default:
        break;
      }
    } else { //FDD
385
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
386
#ifndef FLEXRAN_AGENT_SB_IF
387
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
388
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
389 390
#else
      if (mac_agent_registered[module_idP]) {                                  
391 392 393 394 395 396
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
397
	  
398 399 400 401 402 403
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
404 405
	}
#endif
406
    }
407

408
    break;
409 410

  case 2:
411

gauthier's avatar
gauthier committed
412
    // TDD, nothing
413
    // FDD, normal UL/DLSCH
knopp's avatar
knopp committed
414
    if (cc[0].tdd_Config == NULL) {  //FDD
415
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
416
#ifndef FLEXRAN_AGENT_SB_IF
417
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
418
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
419 420
#else
      if (mac_agent_registered[module_idP]) {                                  
421 422 423 424 425 426
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
427
	  
428 429 430 431 432 433
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
434 435
	}
#endif
436
    }
437

438 439 440
    break;

  case 3:
441

gauthier's avatar
gauthier committed
442
    // TDD Config 2, ULSCH for subframeP 7
443 444
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
knopp's avatar
knopp committed
445 446
    if (cc[0].tdd_Config != NULL) {
      switch (cc[0].tdd_Config->subframeAssignment) {
447
      case 2:
448
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
449 450 451

        // no break here!
      case 5:
452
#ifndef FLEXRAN_AGENT_SB_IF
453 454
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
455 456
#else
	if (mac_agent_registered[module_idP]) {                                  
457 458 459 460 461 462
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
463
	  
464 465 466 467 468 469
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
470 471
	}
#endif
472 473 474 475 476 477
        break;

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

479
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
480
#ifndef FLEXRAN_AGENT_SB_IF
481
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
482
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
483 484
#else
      if (mac_agent_registered[module_idP]) {                                  
485 486 487 488 489 490
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
491
	  
492 493 494 495 496 497 498
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
      }
499
#endif
500
    }
501

502
    break;
503 504

  case 4:
505

gauthier's avatar
gauthier committed
506
    // TDD Config 1, ULSCH for subframeP 8
507 508
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
knopp's avatar
knopp committed
509 510
    if (cc[0].tdd_Config != NULL) { // TDD
      switch (cc[0].tdd_Config->subframeAssignment) {
511
      case 1:
512
        //        schedule_RA(module_idP,frameP,subframeP);
513
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
514 515 516 517 518 519 520 521 522

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
523
#ifndef FLEXRAN_AGENT_SB_IF
524
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
525 526 527
	fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
#else
	if (mac_agent_registered[module_idP]) {                                  
528 529 530 531 532 533
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
534
	  
535 536 537 538 539 540
	  flexran_apply_dl_scheduling_decisions(module_idP,
					       frameP,
					       subframeP,
					       mbsfn_status,
					       msg);
	  flexran_agent_mac_destroy_dl_config(msg);
541 542
	}
#endif	
543 544 545 546 547 548
        break;

      default:
        break;
      }
    } else {
knopp's avatar
knopp committed
549
      if (cc[0].tdd_Config == NULL) {  //FDD
550

551
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
552
#ifndef FLEXRAN_AGENT_SB_IF
553
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
554
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
555 556
#else
	if (mac_agent_registered[module_idP]) {                                  
557 558 559 560 561 562
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
563
	  
564 565 566 567 568 569
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
570 571
	}     
#endif
572
      }
573
    }
574

575 576 577 578 579 580 581
    break;

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

584
    //schedule_RA(module_idP,frameP,subframeP,5);
knopp's avatar
knopp committed
585
    if (cc[0].tdd_Config == NULL) {
586 587
      schedule_RA(module_idP,frameP,subframeP,1);
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
588
#ifndef FLEXRAN_AGENT_SB_IF
589 590
      schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
591 592
#else
      if (mac_agent_registered[module_idP]) {                                  
593 594 595 596 597 598
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
599
	  
600 601 602 603 604 605
	  flexran_apply_dl_scheduling_decisions(module_idP,
					  frameP,
					  subframeP,
					  mbsfn_status,
					  msg);
	  flexran_agent_mac_destroy_dl_config(msg);
606 607
	}
#endif
knopp's avatar
knopp committed
608 609
    } else if ((cc[0].tdd_Config->subframeAssignment == 0) || // TDD Config 0
               (cc[0].tdd_Config->subframeAssignment == 6)) { // TDD Config 6
610
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
611
#ifndef FLEXRAN_AGENT_SB_IF
612
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
613
#endif
614
    } else {
615
#ifndef FLEXRAN_AGENT_SB_IF
616 617
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
618 619
#else
      if (mac_agent_registered[module_idP]) {                                  
620 621 622 623 624 625
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
626
	  
627 628 629 630 631 632
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
633 634
	}
#endif
635
    }
636

637 638 639
    break;

  case 6:
640

641 642 643
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
knopp's avatar
knopp committed
644 645
    if (cc[0].tdd_Config != NULL) { // TDD
      switch (cc[0].tdd_Config->subframeAssignment) {
646 647 648 649
      case 0:
        break;

      case 1:
650
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
651
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
652
#ifndef FLEXRAN_AGENT_SB_IF
653
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
654
#endif
655 656 657
        break;

      case 6:
658
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
659
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
660
#ifndef FLEXRAN_AGENT_SB_IF
661
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
662
#endif
663 664 665
        break;

      case 5:
666
        schedule_RA(module_idP,frameP,subframeP,2);
667
#ifndef FLEXRAN_AGENT_SB_IF
668 669
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
670 671
#else
	if (mac_agent_registered[module_idP]) {                                  
672 673 674 675 676 677
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
678
	  
679 680 681 682 683 684
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
685 686
	}
#endif
687 688 689 690
        break;

      case 3:
      case 4:
691
#ifndef FLEXRAN_AGENT_SB_IF
692 693
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
694 695
#else
	if (mac_agent_registered[module_idP]) {                                  
696 697 698 699 700 701
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
702
	  
703 704 705 706 707 708
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
709 710
	}
#endif
711 712 713 714 715 716
        break;

      default:
        break;
      }
    } else { //FDD
717
      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0);
718
#ifndef FLEXRAN_AGENT_SB_IF
719
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
720
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
721 722
#else
      if (mac_agent_registered[module_idP]) {                                  
723 724 725 726 727 728
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
729
	  
730 731 732 733 734 735
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
736 737
	}
#endif
738
    }
739

740
    break;
gauthier's avatar
gauthier committed
741

742
  case 7:
743

744 745
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
knopp's avatar
knopp committed
746 747
    if (cc[0].tdd_Config != NULL) { // TDD
      switch (cc[0].tdd_Config->subframeAssignment) {
748 749
      case 3:
      case 4:
750
        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
751
#ifndef FLEXRAN_AGENT_SB_IF
752 753
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
754 755
#else
	if (mac_agent_registered[module_idP]) {                                  
756 757 758 759 760 761
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
762
	  
763 764 765 766 767 768
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
769 770
	}
#endif
771 772 773
        break;

      case 5:
774
#ifndef FLEXRAN_AGENT_SB_IF
775 776
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
777 778
#else
	if (mac_agent_registered[module_idP]) {                                  
779 780 781 782 783 784
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
785
	  
786 787 788 789 790 791
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
792 793
	}
#endif
794 795 796 797 798 799
        break;

      default:
        break;
      }
    } else { //FDD
800
      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
801
#ifndef FLEXRAN_AGENT_SB_IF
802
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
803
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
804 805
#else
      if (mac_agent_registered[module_idP]) {                                  
806 807 808 809 810 811
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
812
	  
813 814 815 816 817 818
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
819 820
	}
#endif
821
    }
822

823 824 825
    break;

  case 8:
826

gauthier's avatar
gauthier committed
827
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
828 829
    //
    // FDD Normal UL/DLSCH
knopp's avatar
knopp committed
830 831
    if (cc[0].tdd_Config != NULL) { // TDD
      switch (cc[0].tdd_Config->subframeAssignment) {
832 833 834 835 836
      case 2:
      case 3:
      case 4:
      case 5:

837
        //  schedule_RA(module_idP,subframeP);
838
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
839
#ifndef FLEXRAN_AGENT_SB_IF
840 841
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
842 843
#else
	if (mac_agent_registered[module_idP]) {                                  
844 845 846 847 848 849
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
850
	  
851 852 853 854 855 856
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
857 858
	}
#endif
859 860 861 862 863 864
        break;

      default:
        break;
      }
    } else { //FDD
865
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);