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

69
extern RAN_CONTEXT_t RC;
70

71
72
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
{
73

knopp's avatar
   
knopp committed
74
  int mbsfn_status[MAX_NUM_CCs];
75
  protocol_ctxt_t   ctxt;
76

77
#if defined(ENABLE_ITTI)
78
  MessageDef   *msg_p;
79
  const char         *msg_name;
80
81
  instance_t    instance;
  int           result;
82
#endif
knopp's avatar
   
knopp committed
83
  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
84
  int CC_id,i; //,next_i;
85
  UE_list_t *UE_list=&RC.mac[module_idP]->UE_list;
86
  rnti_t rnti;
87
  void         *DLSCH_dci=NULL;
88
  int size_bits=0,size_bytes=0;
89
90
  
  LTE_eNB_UE_stats  *eNB_UE_stats   = NULL;
91

92
#if defined(FLEXRAN_AGENT_SB_IF)
93
  Protocol__FlexranMessage *msg;
94
#endif
95

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

98
  start_meas(&RC.mac[module_idP]->eNB_scheduler);
gauthier's avatar
gauthier committed
99
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
100

101
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
102
    DCI_pdu[CC_id] = &RC.mac[module_idP]->common_channels[CC_id].DCI_pdu;
knopp's avatar
   
knopp committed
103
    mbsfn_status[CC_id]=0;
104
    // clear vrb_map
105
    memset(RC.mac[module_idP]->common_channels[CC_id].vrb_map,0,100);
knopp's avatar
   
knopp committed
106
  }
107

108
109
110
111
112
  // clear DCI and BCCH contents before scheduling
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
    DCI_pdu[CC_id]->Num_common_dci  = 0;
    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
#ifdef Rel10
113
    RC.mac[module_idP]->common_channels[CC_id].mcch_active =0;
114
#endif
115
116
    RC.mac[module_idP]->frame    = frameP;
    RC.mac[module_idP]->subframe = subframeP;
117
118
  }

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

123
124
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
125
    if ((frameP==0)&&(subframeP==0))
126
127
128
      LOG_I(MAC,"UE  rnti %x : %s, PHR %d dB\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);
129

130
    RC.eNB[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]=-63;
131
    if (i==UE_list->head)
132
      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]); 
133
    // increment this, it is cleared when we receive an sdu
134
    RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
135

136
    RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].cqi_req_timer++;
137
    eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
138

139
    if (eNB_UE_stats==NULL) {
140
	//mac_remove_ue(module_idP, i, frameP, subframeP);
141
      //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
142
#if defined(FLEXRAN_AGENT_SB_IF)
143
      if (mac_agent_registered[module_idP]) {
144
145
146
	agent_mac_xface[module_idP]->flexran_agent_notify_ue_state_change(module_idP,
									  rnti,
									  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
147
      }
148
#endif
149
    }
150
151
    else {
      // check uplink failure
Florian Kaltenberger's avatar
Florian Kaltenberger committed
152
153
154
155
156
157
158
      if ((UE_list->UE_sched_ctrl[i].ul_failure_timer>0)&&
	  (UE_list->UE_sched_ctrl[i].ul_out_of_sync==0)) {
	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)
159
	  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
160
161
	  DLSCH_dci = (void *)UE_list->UE_template[CC_id][i].DLSCH_DCI[0];
	  *(uint32_t*)DLSCH_dci = 0;
162
163
	  if (RC.eNB[module_idP][CC_id]->frame_parms.frame_type == TDD) {
	    switch (RC.eNB[module_idP][CC_id]->frame_parms.N_RB_DL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	    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;
188
	    }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
189
190
	  }
	  else { // FDD
191
	    switch (RC.eNB[module_idP][CC_id]->frame_parms.N_RB_DL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
192
193
194
195
196
197
	    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;
198
199
200
201
202
203
	    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
204
205
206
207
208
209
210
211
212
213
214
	    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;
215
		break;
216
217
218
219
220
221
	    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
222
223
224
225
226
227
	    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;
228
229
	    }
	  }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
230
231
232
233
	  
	  add_ue_spec_dci(DCI_pdu[CC_id],
			  DLSCH_dci,
			  rnti,
234
235
			  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
236
237
238
			  size_bits,
			  format1A,
			  0);
239
	}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
240
	else { // ra_pdcch_sent==1
241
	  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
242
243
	  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	      
244
	}
245
246
247
248
249
      
	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
250
	  LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",i,rnti);
251
252
253
254
	  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
255
256
      }
    } // ul_failure_timer>0
knopp's avatar
   
knopp committed
257
  }
258

259
#if defined(ENABLE_ITTI)
260

261
  do {
262
263
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
264

265
266
267
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
268

269
270
271
272
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
273

274
275
276
277
      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);
278

279
280
        // TODO process BCCH data req.
        break;
281

282
283
284
285
      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);
286

287
288
        // TODO process CCCH data req.
        break;
289
290
291

#ifdef Rel10

292
293
294
295
      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);
296

297
298
299
        // TODO process MCCH data req.
        break;
#endif
300

301
302
303
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
304
      }
305
306
307
308

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

311
312
#endif

313
314
315
/* #ifndef DISABLE_SF_TRIGGER */
/*   //Send subframe trigger to the controller */
/*   if (mac_agent_registered[module_idP]) { */
316
/*     agent_mac_xface[module_idP]->flexran_agent_send_sf_trigger(module_idP); */
317
318
/*   } */
/* #endif */
319
  
gauthier's avatar
gauthier committed
320
  //if (subframeP%5 == 0)
knopp's avatar
   
knopp committed
321
  //#ifdef EXMIMO
322
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP,module_idP);
323
  pdcp_run(&ctxt);
knopp's avatar
   
knopp committed
324
  //#endif
325

326
  // check HO
327
328
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
329
            CC_id);
330
331

#ifdef Rel10
332
333

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
334
335
    if (RC.mac[module_idP]->common_channels[CC_id].MBMS_flag >0) {
      start_meas(&RC.mac[module_idP]->schedule_mch);
336
      mbsfn_status[CC_id] = schedule_MBMS(module_idP,CC_id,frameP,subframeP);
337
      stop_meas(&RC.mac[module_idP]->schedule_mch);
knopp's avatar
   
knopp committed
338
    }
339
  }
340

341
#endif
knopp's avatar
   
knopp committed
342
  // refresh UE list based on UEs dropped by PHY in previous subframe
343
  /*
knopp's avatar
   
knopp committed
344
345
346
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
347
    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
348
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
   
knopp committed
349
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
   
knopp committed
350
351
352
    }
    i=next_i;
  }
353
  */
354

gauthier's avatar
gauthier committed
355
  switch (subframeP) {
356
  case 0:
357

358
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
359
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
360
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
361

knopp's avatar
knopp committed
362

363
364
    schedule_RA(module_idP,frameP,subframeP,2);

365

366
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
367
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
368
369
370
    } else if  ((mac_xface->frame_parms->tdd_config == TDD) || //TDD
                (mac_xface->frame_parms->tdd_config == 3) ||
                (mac_xface->frame_parms->tdd_config == 6)) {
371
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
372
    }
373
#ifndef FLEXRAN_AGENT_SB_IF
374
375
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
376
377
#else
    if (mac_agent_registered[module_idP]) {                                  
378
379
380
381
382
383
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
384
	  
385
386
387
388
389
390
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
391
392
	}
#endif
393
394
395
    break;

  case 1:
396

gauthier's avatar
gauthier committed
397
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
398
    // FDD, schedule normal UL/DLSCH
399
400
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
401
402
      case 0:
      case 1:
403
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
404
#ifndef FLEXRAN_AGENT_SB_IF
405
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
406
#endif
407
408
409
        break;

      case 6:
410
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
411
#ifndef FLEXRAN_AGENT_SB_IF
412
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
413
#endif
414
415
416
417
418
419
        break;

      default:
        break;
      }
    } else { //FDD
420
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
421
#ifndef FLEXRAN_AGENT_SB_IF
422
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
423
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
424
425
#else
      if (mac_agent_registered[module_idP]) {                                  
426
427
428
429
430
431
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
432
	  
433
434
435
436
437
438
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
439
440
	}
#endif
441
    }
442

443
    break;
444
445

  case 2:
446

gauthier's avatar
gauthier committed
447
    // TDD, nothing
448
    // FDD, normal UL/DLSCH
449
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
450
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
451
#ifndef FLEXRAN_AGENT_SB_IF
452
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
453
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
454
455
#else
      if (mac_agent_registered[module_idP]) {                                  
456
457
458
459
460
461
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
462
	  
463
464
465
466
467
468
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
469
470
	}
#endif
471
    }
472

473
474
475
    break;

  case 3:
476

gauthier's avatar
gauthier committed
477
    // TDD Config 2, ULSCH for subframeP 7
478
479
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
480
481
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
482
      case 2:
483
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
484
485
486

        // no break here!
      case 5:
487
#ifndef FLEXRAN_AGENT_SB_IF
488
489
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
490
491
#else
	if (mac_agent_registered[module_idP]) {                                  
492
493
494
495
496
497
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
498
	  
499
500
501
502
503
504
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
505
506
	}
#endif
507
508
509
510
511
512
        break;

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

514
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
515
#ifndef FLEXRAN_AGENT_SB_IF
516
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
517
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
518
519
#else
      if (mac_agent_registered[module_idP]) {                                  
520
521
522
523
524
525
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
526
	  
527
528
529
530
531
532
533
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
      }
534
#endif
535
    }
536

537
    break;
538
539

  case 4:
540

gauthier's avatar
gauthier committed
541
    // TDD Config 1, ULSCH for subframeP 8
542
543
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
544
545
    if (mac_xface->frame_parms->frame_type == 1) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
546
      case 1:
547
        //        schedule_RA(module_idP,frameP,subframeP);
548
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
549
550
551
552
553
554
555
556
557

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
558
#ifndef FLEXRAN_AGENT_SB_IF
559
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
560
561
562
	fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
#else
	if (mac_agent_registered[module_idP]) {                                  
563
564
565
566
567
568
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
569
	  
570
571
572
573
574
575
	  flexran_apply_dl_scheduling_decisions(module_idP,
					       frameP,
					       subframeP,
					       mbsfn_status,
					       msg);
	  flexran_agent_mac_destroy_dl_config(msg);
576
577
	}
#endif	
578
579
580
581
582
583
        break;

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

586
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
587
#ifndef FLEXRAN_AGENT_SB_IF
588
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
589
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
590
591
#else
	if (mac_agent_registered[module_idP]) {                                  
592
593
594
595
596
597
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
598
	  
599
600
601
602
603
604
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
605
606
	}     
#endif
607
      }
608
    }
609

610
611
612
613
614
615
616
    break;

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

619
    //schedule_RA(module_idP,frameP,subframeP,5);
620
    if (mac_xface->frame_parms->frame_type == FDD) {
621
622
      schedule_RA(module_idP,frameP,subframeP,1);
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
623
#ifndef FLEXRAN_AGENT_SB_IF
624
625
      schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
626
627
#else
      if (mac_agent_registered[module_idP]) {                                  
628
629
630
631
632
633
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
634
	  
635
636
637
638
639
640
	  flexran_apply_dl_scheduling_decisions(module_idP,
					  frameP,
					  subframeP,
					  mbsfn_status,
					  msg);
	  flexran_agent_mac_destroy_dl_config(msg);
641
642
	}
#endif
643
644
    } else if ((mac_xface->frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->frame_parms->tdd_config == 6)) { // TDD Config 6
645
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
646
#ifndef FLEXRAN_AGENT_SB_IF
647
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
648
#endif
649
    } else {
650
#ifndef FLEXRAN_AGENT_SB_IF
651
652
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
653
654
#else
      if (mac_agent_registered[module_idP]) {                                  
655
656
657
658
659
660
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
661
	  
662
663
664
665
666
667
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
668
669
	}
#endif
670
    }
671

672
673
674
    break;

  case 6:
675

676
677
678
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
679
680
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
681
682
683
684
      case 0:
        break;

      case 1:
685
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
686
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
687
#ifndef FLEXRAN_AGENT_SB_IF
688
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
689
#endif
690
691
692
        break;

      case 6:
693
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
694
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
695
#ifndef FLEXRAN_AGENT_SB_IF
696
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
697
#endif
698
699
700
        break;

      case 5:
701
        schedule_RA(module_idP,frameP,subframeP,2);
702
#ifndef FLEXRAN_AGENT_SB_IF
703
704
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
705
706
#else
	if (mac_agent_registered[module_idP]) {                                  
707
708
709
710
711
712
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
713
	  
714
715
716
717
718
719
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
720
721
	}
#endif
722
723
724
725
        break;

      case 3:
      case 4:
726
#ifndef FLEXRAN_AGENT_SB_IF
727
728
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
729
730
#else
	if (mac_agent_registered[module_idP]) {                                  
731
732
733
734
735
736
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
737
	  
738
739
740
741
742
743
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
744
745
	}
#endif
746
747
748
749
750
751
        break;

      default:
        break;
      }
    } else { //FDD
752
      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0);
753
#ifndef FLEXRAN_AGENT_SB_IF
754
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
755
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
756
757
#else
      if (mac_agent_registered[module_idP]) {                                  
758
759
760
761
762
763
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
764
	  
765
766
767
768
769
770
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
771
772
	}
#endif
773
    }
774

775
    break;
gauthier's avatar
gauthier committed
776

777
  case 7:
778

779
780
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
781
782
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
783
784
      case 3:
      case 4:
785
        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
786
#ifndef FLEXRAN_AGENT_SB_IF
787
788
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
789
790
#else
	if (mac_agent_registered[module_idP]) {                                  
791
792
793
794
795
796
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
797
	  
798
799
800
801
802
803
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
804
805
	}
#endif
806
807
808
        break;

      case 5:
809
#ifndef FLEXRAN_AGENT_SB_IF
810
811
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
812
813
#else
	if (mac_agent_registered[module_idP]) {                                  
814
815
816
817
818
819
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
820
	  
821
822
823
824
825
826
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
827
828
	}
#endif
829
830
831
832
833
834
        break;

      default:
        break;
      }
    } else { //FDD
835
      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
836
#ifndef FLEXRAN_AGENT_SB_IF
837
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
838
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
839
840
#else
      if (mac_agent_registered[module_idP]) {                                  
841
842
843
844
845
846
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
847
	  
848
849
850
851
852
853
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
854
855
	}
#endif
856
    }
857

858
859
860
    break;

  case 8:
861

gauthier's avatar
gauthier committed
862
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
863
864
    //
    // FDD Normal UL/DLSCH
865
866
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
867
868
869
870
871
      case 2:
      case 3:
      case 4:
      case 5:

872
        //  schedule_RA(module_idP,subframeP);
873
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
874
#ifndef FLEXRAN_AGENT_SB_IF
875
876
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
877
878
#else
	if (mac_agent_registered[module_idP]) {                                  
879
880
881
882
883
884
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
885
	  
886
887
888
889
890
891
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
892
893
	}
#endif
894
895
896
897
898
899
        break;

      default:
        break;
      }
    } else { //FDD
900
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
901
#ifndef FLEXRAN_AGENT_SB_IF
902
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
903
      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
925
    break;

  case 9:
926

927
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
928
929
<