eNB_scheduler.c 40.3 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
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
329
      }
330 331 332 333

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

336 337
#endif

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

351
  // check HO
352 353
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
354
            CC_id);
355

Cedric Roux's avatar
Cedric Roux committed
356
#if defined(Rel10) || defined(Rel14)
357 358

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
359 360 361 362
    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
363
    }
364
  }
365

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

gauthier's avatar
gauthier committed
380
  switch (subframeP) {
381
  case 0:
382

383
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
384
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
385
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
386

knopp's avatar
knopp committed
387

388 389
    schedule_RA(module_idP,frameP,subframeP,2);

390

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

      flexran_agent_mac_destroy_ul_config(msg);
shahab's avatar
shahab committed
400 401 402
     
#endif

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

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

  case 1:
440

gauthier's avatar
gauthier committed
441
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
442
    // FDD, schedule normal UL/DLSCH
443 444
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
445 446
      case 0:
      case 1:
shahab's avatar
shahab committed
447 448 449 450 451
#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
452
       agent_mac_xface[module_idP]->flexran_agent_schedule_ul_spec(module_idP,frameP,cooperation_flag,subframeP,7, &msg);   
shahab's avatar
shahab committed
453 454
      }

shahab's avatar
shahab committed
455 456 457

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
458
#endif
459
#ifndef FLEXRAN_AGENT_SB_IF
460
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
461
#endif
462 463 464
        break;

      case 6:
shahab's avatar
shahab committed
465
#ifndef FLEXRAN_AGENT_SB_IF      
466
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
shahab's avatar
shahab committed
467 468 469
#else

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

shahab's avatar
shahab committed
473 474
      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
475 476
#endif  

477
#ifndef FLEXRAN_AGENT_SB_IF
478
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
479
#endif
480 481 482 483 484 485
        break;

      default:
        break;
      }
    } else { //FDD
shahab's avatar
shahab committed
486
#ifndef FLEXRAN_AGENT_SB_IF            
487
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
shahab's avatar
shahab committed
488 489 490
#else

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

shahab's avatar
shahab committed
494 495 496

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
497 498
#endif        

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

521
    break;
522 523

  case 2:
524

gauthier's avatar
gauthier committed
525
    // TDD, nothing
526
    // FDD, normal UL/DLSCH
527
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
shahab's avatar
shahab committed
528
#ifndef FLEXRAN_AGENT_SB_IF            
529
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
shahab's avatar
shahab committed
530 531 532
#else

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

shahab's avatar
shahab committed
536 537 538 539


      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
540 541
#endif        

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

564 565 566
    break;

  case 3:
567

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

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

shahab's avatar
shahab committed
582 583 584

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
585
#endif        
586 587 588

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

      default:
        break;
      }
    } else { //FDD
shahab's avatar
shahab committed
615
#ifndef FLEXRAN_AGENT_SB_IF                  
616
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
shahab's avatar
shahab committed
617 618 619
#else

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

shahab's avatar
shahab committed
623 624 625 626


      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
627 628
#endif        

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

651
    break;
652 653

  case 4:
654

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

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

shahab's avatar
shahab committed
670 671 672

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
673
#endif        
674 675 676 677 678 679 680 681 682

        // no break here!
      case 2:

        // no break here!
      case 4:

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

      default:
        break;
      }
    } else {
709
      if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
shahab's avatar
shahab committed
710
#ifndef FLEXRAN_AGENT_SB_IF                        
711
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
shahab's avatar
shahab committed
712 713 714
#else

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

shahab's avatar
shahab committed
718 719 720

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
721 722
#endif        

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

746 747 748 749 750 751 752
    break;

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

755
    //schedule_RA(module_idP,frameP,subframeP,5);
756
    if (mac_xface->frame_parms->frame_type == FDD) {
757
      schedule_RA(module_idP,frameP,subframeP,1);
shahab's avatar
shahab committed
758
#ifndef FLEXRAN_AGENT_SB_IF                              
759
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
shahab's avatar
shahab committed
760 761 762
#else

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

shahab's avatar
shahab committed
766 767 768

      flexran_agent_mac_destroy_ul_config(msg);

shahab's avatar
shahab committed
769 770
#endif        

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

820 821 822
    break;

  case 6:
823