eNB_scheduler.c 34.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

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
317
318
319
  LOG_I(MAC,"[eNB %d][before switch] Frame %d, Subframe %d CC_id %d RA 0 is active, Msg3 in (%d,%d), (%d,%d,%d,%d) UL_pdus %d\n",
	module_idP,frameP,subframeP,CC_id,cc[0].RA_template[0].Msg3_frame,cc[0].RA_template[0].Msg3_subframe,
	cc[0].RA_template[0].RA_active,cc[0].RA_template[1].RA_active,cc[0].RA_template[2].RA_active,cc[0].RA_template[3].RA_active,
	RC.mac[module_idP]->UL_req[0].ul_config_request_body.number_of_pdus);
gauthier's avatar
gauthier committed
320
  switch (subframeP) {
321
  case 0:
322

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

knopp's avatar
knopp committed
327

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

  case 1:
364

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

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

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

411
    break;
412
413

  case 2:
414

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

441
442
443
    break;

  case 3:
444

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

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

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

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

505
    break;
506
507

  case 4:
508

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

        // no break here!
      case 2:

        // no break here!
      case 4:

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

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

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

578
579
580
581
582
583
584
    break;

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

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

640
641
642
    break;

  case 6:
643

644
645
646
    // 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
647
648
    if (cc[0].tdd_Config != NULL) { // TDD
      switch (cc[0].tdd_Config->subframeAssignment) {
649
650
651
652
      case 0:
        break;

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

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

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

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

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

743
    break;
gauthier's avatar
gauthier committed
744

745
  case 7:
746

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

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

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

826
827
828
    break;

  case 8:
829

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

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

      default:
        break;
      }
    } else { //FDD
868
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
869
#ifndef FLEXRAN_AGENT_SB_IF
870
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
871
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
872
873
#else
      if (mac_agent_registered[module_idP]) {                                  
874
875
876
877
878
879
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
880
	  
881
882
883
884
885
886
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
887
888
	}
#endif
889
    }
890

891
892
893
    break;

  case 9:
894

895
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
knopp's avatar
knopp committed
896
897
    if (cc[0].tdd_Config != NULL) {
      switch (cc[0].tdd_Config->subframeAssignment) {
898
      case 1:
899
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
900
        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
901
#ifndef FLEXRAN_AGENT_SB_IF
902
903
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
904
905
#else
	if (mac_agent_registered[module_idP]) {                                  
906
907
908
909
910
911
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
912
	  
913
914
915
916
917
918
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
919
920
	}
#endif
921
922
923
924
        break;

      case 3:
      case 4:
925
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
926
#ifndef FLEXRAN_AGENT_SB_IF
927
928
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
929
930
#else
	if (mac_agent_registered[module_idP]) {