eNB_scheduler.c 40.4 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
//efine ENABLE_ENB_AGENT_DL_SCHEDULER
69
//#define DISABLE_SF_TRIGGER
70
//#define DISABLE_CONT_STATS
71

72 73
//#define DEBUG_HEADER_PARSING 1
//#define DEBUG_PACKET_TRACE 1
gauthier's avatar
gauthier committed
74

75 76 77 78 79
/*
  #ifndef USER_MODE
  #define msg debug_msg
  #endif
 */
gauthier's avatar
gauthier committed
80 81 82



83

84 85 86



87 88
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
{
89

knopp's avatar
 
knopp committed
90
  int mbsfn_status[MAX_NUM_CCs];
91
  protocol_ctxt_t   ctxt;
92
#ifdef EXMIMO
Cedric Roux's avatar
Cedric Roux committed
93
  //int ret;
94
#endif
95
#if defined(ENABLE_ITTI)
96
  MessageDef   *msg_p;
97
  const char         *msg_name;
98 99
  instance_t    instance;
  int           result;
100
#endif
knopp's avatar
 
knopp committed
101
  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
102
  int CC_id,i; //,next_i;
knopp's avatar
 
knopp committed
103
  UE_list_t *UE_list=&eNB_mac_inst[module_idP].UE_list;
104
  rnti_t rnti;
105
  void         *DLSCH_dci=NULL;
106
  int size_bits=0,size_bytes=0;
107 108
  
  LTE_eNB_UE_stats  *eNB_UE_stats   = NULL;
109

110
#if defined(FLEXRAN_AGENT_SB_IF)
111
  Protocol__FlexranMessage *msg;
112
#endif
113

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

116
  start_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
gauthier's avatar
gauthier committed
117
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
118

119
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
120 121
    DCI_pdu[CC_id] = &eNB_mac_inst[module_idP].common_channels[CC_id].DCI_pdu;
    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

126 127
  // clear DCI and BCCH contents before scheduling
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
128
    DCI_pdu[CC_id]->Num_dci  = 0;
Cedric Roux's avatar
Cedric Roux committed
129
#if defined(Rel10) || defined(Rel14)
130 131 132 133 134 135
    eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0;
#endif
    eNB_mac_inst[module_idP].frame    = frameP;
    eNB_mac_inst[module_idP].subframe = subframeP;
  }

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

140 141
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
142 143 144 145 146 147 148 149
    if ((frameP==0)&&(subframeP==0)) {
      LTE_eNB_UE_stats *eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti);
      int cqi = eNB_UE_stats == NULL ? -1 : eNB_UE_stats->DL_cqi[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,
            cqi);
    }
150

151 152 153
    PHY_vars_eNB_g[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]=-63;
    if (i==UE_list->head)
      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,PHY_vars_eNB_g[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]); 
154 155
    // increment this, it is cleared when we receive an sdu
    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
156 157

    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].cqi_req_timer++;
158
    eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
159

160
    if (eNB_UE_stats==NULL) {
161
	//mac_remove_ue(module_idP, i, frameP, subframeP);
162
      //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
163
#if defined(FLEXRAN_AGENT_SB_IF)
shahab's avatar
shahab committed
164 165
      if (rrc_agent_registered[module_idP]) {
	agent_rrc_xface[module_idP]->flexran_agent_notify_ue_state_change(module_idP,
166 167
									  rnti,
									  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
168
      }
169
#endif
170
    }
171 172
    else {
      // check uplink failure
Florian Kaltenberger's avatar
Florian Kaltenberger committed
173
      if ((UE_list->UE_sched_ctrl[i].ul_failure_timer>0)&&
174 175 176 177 178
	  (UE_list->UE_sched_ctrl[i].ul_out_of_sync==0) &&
          /* do nothing if CCE allocation is impossible */
          !CCE_allocation_infeasible(module_idP, CC_id, 0, subframeP,
                                     get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format1A),
                                     rnti)) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
179 180 181 182 183
	LOG_D(MAC,"UE %d rnti %x: UL Failure timer %d \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);
	if (UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent==0) {
	  UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=1;
	  
	  // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
184
	  LOG_D(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    
Florian Kaltenberger's avatar
Florian Kaltenberger committed
185 186
	  DLSCH_dci = (void *)UE_list->UE_template[CC_id][i].DLSCH_DCI[0];
	  *(uint32_t*)DLSCH_dci = 0;
187 188
	  if (PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.frame_type == TDD) {
	    switch (PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.N_RB_DL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	    case 6:
	      ((DCI1A_1_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_1_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 31;
	      size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
	      break;
	    case 25:
	      ((DCI1A_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 511;
	      size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_5MHz_TDD_1_6_t;
	      break;
	    case 50:
	      ((DCI1A_10MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_10MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 2047;
	      size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_10MHz_TDD_1_6_t;
	      break;
	    case 100:
	      ((DCI1A_20MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_20MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 8191;
	      size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_20MHz_TDD_1_6_t;
	      break;
213
	    }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
214 215
	  }
	  else { // FDD
216
	    switch (PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.N_RB_DL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
217 218 219 220 221 222
	    case 6:
	      ((DCI1A_1_5MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_1_5MHz_FDD_t*)DLSCH_dci)->rballoc = 31;
	      size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;
	      break;
223 224 225 226 227 228
	    case 15:/*
	      ((DCI1A_2_5MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_2_5MHz_FDD_t*)DLSCH_dci)->rballoc = 31;
	      size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;*/
	      break;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
229 230 231 232 233 234 235 236 237 238 239
	    case 25:
	      ((DCI1A_5MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_5MHz_FDD_t*)DLSCH_dci)->rballoc = 511;
	      size_bytes = sizeof(DCI1A_5MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_5MHz_FDD_t;
	      break;
	    case 50:
	      ((DCI1A_10MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_10MHz_FDD_t*)DLSCH_dci)->rballoc = 2047;
	      size_bytes = sizeof(DCI1A_10MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_10MHz_FDD_t;
240
		break;
241 242 243 244 245 246
	    case 75:
	      /*	      ((DCI1A_15MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_15MHz_FDD_t*)DLSCH_dci)->rballoc = 2047;
	      size_bytes = sizeof(DCI1A_10MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_10MHz_FDD_t;*/
		break;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
247 248 249 250 251 252
	    case 100:
	      ((DCI1A_20MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_20MHz_FDD_t*)DLSCH_dci)->rballoc = 8191;
	      size_bytes = sizeof(DCI1A_20MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_20MHz_FDD_t;
	      break;
253 254
	    }
	  }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
255 256 257 258
	  
	  add_ue_spec_dci(DCI_pdu[CC_id],
			  DLSCH_dci,
			  rnti,
259 260
			  size_bytes,
			  get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format1A),
Florian Kaltenberger's avatar
Florian Kaltenberger committed
261 262 263
			  size_bits,
			  format1A,
			  0);
264
	}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
265
	else { // ra_pdcch_sent==1
266
	  LOG_D(MAC,"UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    	    
Florian Kaltenberger's avatar
Florian Kaltenberger committed
267 268
	  if ((UE_list->UE_sched_ctrl[i].ul_failure_timer % 40) == 0)
	    UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=0; // resend every 4 frames	      
269
	}
270 271 272 273 274
      
	UE_list->UE_sched_ctrl[i].ul_failure_timer++;
	// check threshold
	if (UE_list->UE_sched_ctrl[i].ul_failure_timer > 200) {
	  // inform RRC of failure and clear timer
Cedric Roux's avatar
Cedric Roux committed
275
	  LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",i,rnti);
276 277 278 279
	  mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti);
	  UE_list->UE_sched_ctrl[i].ul_failure_timer=0;
	  UE_list->UE_sched_ctrl[i].ul_out_of_sync=1;
	}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
280 281
      }
    } // ul_failure_timer>0
knopp's avatar
 
knopp committed
282
  }
283

284
#if defined(ENABLE_ITTI)
285

286
  do {
287 288
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
289

290 291 292
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
293

294 295 296 297
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
298

299 300 301 302
      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);
303

304 305
        // TODO process BCCH data req.
        break;
306

307 308 309 310
      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);
311

312 313
        // TODO process CCCH data req.
        break;
314

Cedric Roux's avatar
Cedric Roux committed
315
#if defined(Rel10) || defined(Rel14)
316

317 318 319 320
      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);
321

322 323 324
        // TODO process MCCH data req.
        break;
#endif
325

326 327 328 329 330
      case TERMINATE_MESSAGE:
        LOG_W(MAC, "+++ Exiting MAC thread\n");
        itti_exit_task ();
        break;

331 332 333
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
334
      }
335 336 337 338

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

341 342
#endif

343 344 345
/* #ifndef DISABLE_SF_TRIGGER */
/*   //Send subframe trigger to the controller */
/*   if (mac_agent_registered[module_idP]) { */
346
/*     agent_mac_xface[module_idP]->flexran_agent_send_sf_trigger(module_idP); */
347 348
/*   } */
/* #endif */
349
  
gauthier's avatar
gauthier committed
350
  //if (subframeP%5 == 0)
knopp's avatar
 
knopp committed
351
  //#ifdef EXMIMO
352
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP,module_idP);
353
  pdcp_run(&ctxt);
knopp's avatar
 
knopp committed
354
  //#endif
355

356
  // check HO
357 358
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
359
            CC_id);
360

Cedric Roux's avatar
Cedric Roux committed
361
#if defined(Rel10) || defined(Rel14)
362 363

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
364 365 366 367
    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
368
    }
369
  }
370

371
#endif
knopp's avatar
 
knopp committed
372
  // refresh UE list based on UEs dropped by PHY in previous subframe
373
  /*
knopp's avatar
 
knopp committed
374 375 376
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
377
    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
378
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
 
knopp committed
379
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
 
knopp committed
380 381 382
    }
    i=next_i;
  }
383
  */
384

gauthier's avatar
gauthier committed
385
  switch (subframeP) {
386
  case 0:
387

388
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
389
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
390
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
391

knopp's avatar
knopp committed
392

393 394
    schedule_RA(module_idP,frameP,subframeP,2);

395

396
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
shahab's avatar
shahab committed
397
#ifndef FLEXRAN_AGENT_SB_IF
398
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
shahab's avatar
shahab committed
399 400
#else
      if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
401
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,0,4, &msg);   
shahab's avatar
shahab committed
402
      }
shahab's avatar
shahab committed
403 404

      flexran_agent_mac_destroy_ul_config(msg);
shahab's avatar
shahab committed
405 406 407
     
#endif

408
    } else if  ((mac_xface->frame_parms->tdd_config == 0) || //TDD
409 410
                (mac_xface->frame_parms->tdd_config == 3) ||
                (mac_xface->frame_parms->tdd_config == 6)) {
shahab's avatar
shahab committed
411
#ifndef FLEXRAN_AGENT_SB_IF      
412
      schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
shahab's avatar
shahab committed
413 414
#else
      if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
415
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,subframeP,4, &msg);   
shahab's avatar
shahab committed
416
      }
shahab's avatar
shahab committed
417 418

      flexran_agent_mac_destroy_ul_config(msg);
shahab's avatar
shahab committed
419 420
     
#endif      
Florian Kaltenberger's avatar
Florian Kaltenberger committed
421
    }
422
#ifndef FLEXRAN_AGENT_SB_IF
423 424
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
425 426
#else
    if (mac_agent_registered[module_idP]) {                                  
427 428 429 430 431 432
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
433
	  
shahab's avatar
shahab committed
434
	  flexran_apply_scheduling_decisions(module_idP,
435 436 437 438 439
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
440 441
	}
#endif
442 443 444
    break;

  case 1:
445

gauthier's avatar
gauthier committed
446
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
447
    // FDD, schedule normal UL/DLSCH
448 449
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
450 451
      case 0:
      case 1:
shahab's avatar
shahab committed
452 453 454 455 456
#ifndef FLEXRAN_AGENT_SB_IF
      schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);//,calibration_flag);
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
457
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,subframeP,7, &msg);   
shahab's avatar
shahab committed
458 459
      }

shahab's avatar
shahab committed
460 461 462

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
463
#endif
464
#ifndef FLEXRAN_AGENT_SB_IF
465
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
466
#endif
467 468 469
        break;

      case 6:
shahab's avatar
shahab committed
470
#ifndef FLEXRAN_AGENT_SB_IF      
471
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
shahab's avatar
shahab committed
472 473 474
#else

  if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
475
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,subframeP,8, &msg);   
shahab's avatar
shahab committed
476 477
      }

shahab's avatar
shahab committed
478 479
      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
480 481
#endif  

482
#ifndef FLEXRAN_AGENT_SB_IF
483
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
484
#endif
485 486 487 488 489 490
        break;

      default:
        break;
      }
    } else { //FDD
shahab's avatar
shahab committed
491
#ifndef FLEXRAN_AGENT_SB_IF            
492
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
shahab's avatar
shahab committed
493 494 495
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
496
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,1,5, &msg);   
shahab's avatar
shahab committed
497 498
      }

shahab's avatar
shahab committed
499 500 501

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
502 503
#endif        

504
#ifndef FLEXRAN_AGENT_SB_IF
505
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
506
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
507 508
#else
      if (mac_agent_registered[module_idP]) {                                  
509 510 511 512 513 514
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
515
	  
shahab's avatar
shahab committed
516
	  flexran_apply_scheduling_decisions(module_idP,
517 518 519 520 521
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
522 523
	}
#endif
524
    }
525

526
    break;
527 528

  case 2:
529

gauthier's avatar
gauthier committed
530
    // TDD, nothing
531
    // FDD, normal UL/DLSCH
532
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
shahab's avatar
shahab committed
533
#ifndef FLEXRAN_AGENT_SB_IF            
534
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
shahab's avatar
shahab committed
535 536 537
#else

   if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
538
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,2,6, &msg);   
shahab's avatar
shahab committed
539 540
      }

shahab's avatar
shahab committed
541 542 543 544


      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
545 546
#endif        

547
#ifndef FLEXRAN_AGENT_SB_IF
548
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
549
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
550 551
#else
      if (mac_agent_registered[module_idP]) {                                  
552 553 554 555 556 557
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
558
	  
shahab's avatar
shahab committed
559
	  flexran_apply_scheduling_decisions(module_idP,
560 561 562 563 564
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
565 566
	}
#endif
567
    }
568

569 570 571
    break;

  case 3:
572

gauthier's avatar
gauthier committed
573
    // TDD Config 2, ULSCH for subframeP 7
574 575
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
576 577
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
578
      case 2:
shahab's avatar
shahab committed
579
#ifndef FLEXRAN_AGENT_SB_IF                  
580
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
shahab's avatar
shahab committed
581 582 583
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
584
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,subframeP,7, &msg);   
shahab's avatar
shahab committed
585 586
      }

shahab's avatar
shahab committed
587 588 589

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
590
#endif        
591 592 593

        // no break here!
      case 5:
594
#ifndef FLEXRAN_AGENT_SB_IF
595 596
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
597 598
#else
	if (mac_agent_registered[module_idP]) {                                  
599 600 601 602 603 604
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
605
	  
shahab's avatar
shahab committed
606
	  flexran_apply_scheduling_decisions(module_idP,
607 608 609 610 611
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
612 613
	}
#endif
614 615 616 617 618 619
        break;

      default:
        break;
      }
    } else { //FDD
shahab's avatar
shahab committed
620
#ifndef FLEXRAN_AGENT_SB_IF                  
621
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
shahab's avatar
shahab committed
622 623 624
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
625
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,3,7, &msg);   
shahab's avatar
shahab committed
626 627
      }

shahab's avatar
shahab committed
628 629 630 631


      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
632 633
#endif        

634
#ifndef FLEXRAN_AGENT_SB_IF
635
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
636
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
637 638
#else
      if (mac_agent_registered[module_idP]) {                                  
639 640 641 642 643 644
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
645
	  
shahab's avatar
shahab committed
646
	  flexran_apply_scheduling_decisions(module_idP,
647 648 649 650 651 652
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
      }
653
#endif
654
    }
655

656
    break;
657 658

  case 4:
659

gauthier's avatar
gauthier committed
660
    // TDD Config 1, ULSCH for subframeP 8
661 662
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
663 664
    if (mac_xface->frame_parms->frame_type == 1) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
665
      case 1:
666
        //        schedule_RA(module_idP,frameP,subframeP);
shahab's avatar
shahab committed
667
#ifndef FLEXRAN_AGENT_SB_IF                        
668
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
shahab's avatar
shahab committed
669 670 671
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
672
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,subframeP,8, &msg);   
shahab's avatar
shahab committed
673 674
      }

shahab's avatar
shahab committed
675 676 677

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
678
#endif        
679 680 681 682 683 684 685 686 687

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
688
#ifndef FLEXRAN_AGENT_SB_IF
689
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
690 691 692
	fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
#else
	if (mac_agent_registered[module_idP]) {                                  
693 694 695 696 697 698
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
699
	  
shahab's avatar
shahab committed
700
	  flexran_apply_scheduling_decisions(module_idP,
701 702 703 704 705
					       frameP,
					       subframeP,
					       mbsfn_status,
					       msg);
	  flexran_agent_mac_destroy_dl_config(msg);
706 707
	}
#endif	
708 709 710 711 712 713
        break;

      default:
        break;
      }
    } else {
714
      if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
shahab's avatar
shahab committed
715
#ifndef FLEXRAN_AGENT_SB_IF                        
716
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
shahab's avatar
shahab committed
717 718 719
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
720
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,4,8, &msg);   
shahab's avatar
shahab committed
721 722
      }

shahab's avatar
shahab committed
723 724 725

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
726 727
#endif        

728
#ifndef FLEXRAN_AGENT_SB_IF
729
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
730
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
731 732
#else
	if (mac_agent_registered[module_idP]) {                                  
733 734 735 736 737 738
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
739
	  
shahab's avatar
shahab committed
740
	  flexran_apply_scheduling_decisions(module_idP,
741 742 743 744 745
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
746 747
	}     
#endif
748
      }
749
    }
750

751 752 753 754 755 756 757
    break;

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

760
    //schedule_RA(module_idP,frameP,subframeP,5);
761
    if (mac_xface->frame_parms->frame_type == FDD) {
762
      schedule_RA(module_idP,frameP,subframeP,1);
shahab's avatar
shahab committed
763
#ifndef FLEXRAN_AGENT_SB_IF                              
764
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
shahab's avatar
shahab committed
765 766 767
#else

if (mac_agent_registered[module_idP]){
shahab's avatar
shahab committed
768
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,5,9, &msg);   
shahab's avatar
shahab committed
769 770
      }

shahab's avatar
shahab committed
771 772 773

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
774 775
#endif        

776
#ifndef FLEXRAN_AGENT_SB_IF
777 778
      schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
779 780
#else
      if (mac_agent_registered[module_idP]) {                                  
781 782 783 784 785 786
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
787
	  
shahab's avatar
shahab committed
788
	  flexran_apply_scheduling_decisions(module_idP,
789 790 791 792 793
					  frameP,
					  subframeP,
					  mbsfn_status,
					  msg);
	  flexran_agent_mac_destroy_dl_config(msg);
794 795
	}
#endif
796 797
    } else if ((mac_xface->frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->frame_parms->tdd_config == 6)) { // TDD Config 6
798
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
799
#ifndef FLEXRAN_AGENT_SB_IF
800
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
801
#endif
802
    } else {
803
#ifndef FLEXRAN_AGENT_SB_IF
804 805
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
806 807
#else
      if (mac_agent_registered[module_idP]) {                                  
808 809 810 811 812 813
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
814
	  
shahab's avatar
shahab committed
815
	  flexran_apply_scheduling_decisions(module_idP,
816 817 818 819 820
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
821 822
	}
#endif
823
    }
824