eNB_scheduler.c 33.5 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
#if defined(FLEXRAN_AGENT_SB_IF)
109
  Protocol__FlexranMessage *msg;
110
#endif
111

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

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

117
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
   
knopp committed
118
119
    DCI_pdu[CC_id] = &eNB_mac_inst[module_idP].common_channels[CC_id].DCI_pdu;
    mbsfn_status[CC_id]=0;
120
121
    // clear vrb_map
    memset(eNB_mac_inst[module_idP].common_channels[CC_id].vrb_map,0,100);
knopp's avatar
   
knopp committed
122
  }
123

124
125
126
127
128
129
130
131
132
133
134
  // 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
    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
135
  // refresh UE list based on UEs dropped by PHY in previous subframe
136
137
  for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
    if (UE_list->active[i] != TRUE) continue;
138

139
140
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
141
142
143
144
    if ((frameP==0)&&(subframeP==0))
      LOG_I(MAC,"UE  rnti %x : %s\n", rnti, 
	    UE_list->UE_sched_ctrl[i].ul_out_of_sync==0 ? "in synch" : "out of sync");

145
146
147
    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]); 
148
149
    // increment this, it is cleared when we receive an sdu
    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
150
151

    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].cqi_req_timer++;
152
    
153

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

274
#if defined(ENABLE_ITTI)
275

276
  do {
277
278
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
279

280
281
282
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
283

284
285
286
287
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
288

289
290
291
292
      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);
293

294
295
        // TODO process BCCH data req.
        break;
296

297
298
299
300
      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);
301

302
303
        // TODO process CCCH data req.
        break;
304
305
306

#ifdef Rel10

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

312
313
314
        // TODO process MCCH data req.
        break;
#endif
315

316
317
318
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
319
      }
320
321
322
323

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

326
327
#endif

328
329
330
/* #ifndef DISABLE_SF_TRIGGER */
/*   //Send subframe trigger to the controller */
/*   if (mac_agent_registered[module_idP]) { */
331
/*     agent_mac_xface[module_idP]->flexran_agent_send_sf_trigger(module_idP); */
332
333
/*   } */
/* #endif */
334
  
gauthier's avatar
gauthier committed
335
  //if (subframeP%5 == 0)
knopp's avatar
   
knopp committed
336
  //#ifdef EXMIMO
337
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP,module_idP);
338
  pdcp_run(&ctxt);
knopp's avatar
   
knopp committed
339
  //#endif
340

341
  // check HO
342
343
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
344
            CC_id);
345
346

#ifdef Rel10
347
348

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
349
350
351
352
    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
353
    }
354
  }
355

356
#endif
knopp's avatar
   
knopp committed
357
  // refresh UE list based on UEs dropped by PHY in previous subframe
358
  /*
knopp's avatar
   
knopp committed
359
360
361
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
362
    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
363
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
   
knopp committed
364
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
   
knopp committed
365
366
367
    }
    i=next_i;
  }
368
  */
369

gauthier's avatar
gauthier committed
370
  switch (subframeP) {
371
  case 0:
372

373
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
374
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
375
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
376

knopp's avatar
knopp committed
377

378
379
    schedule_RA(module_idP,frameP,subframeP,2);

380

381
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
382
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
383
384
385
    } else if  ((mac_xface->frame_parms->tdd_config == TDD) || //TDD
                (mac_xface->frame_parms->tdd_config == 3) ||
                (mac_xface->frame_parms->tdd_config == 6)) {
386
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
387
    }
388
#ifndef FLEXRAN_AGENT_SB_IF
389
390
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
391
392
#else
    if (mac_agent_registered[module_idP]) {                                  
393
394
395
396
397
398
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
399
	  
400
401
402
403
404
405
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
406
407
	}
#endif
408
409
410
    break;

  case 1:
411

gauthier's avatar
gauthier committed
412
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
413
    // FDD, schedule normal UL/DLSCH
414
415
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
416
417
      case 0:
      case 1:
418
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
419
#ifndef FLEXRAN_AGENT_SB_IF
420
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
421
#endif
422
423
424
        break;

      case 6:
425
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
426
#ifndef FLEXRAN_AGENT_SB_IF
427
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
428
#endif
429
430
431
432
433
434
        break;

      default:
        break;
      }
    } else { //FDD
435
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
436
#ifndef FLEXRAN_AGENT_SB_IF
437
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
438
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
439
440
#else
      if (mac_agent_registered[module_idP]) {                                  
441
442
443
444
445
446
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
447
	  
448
449
450
451
452
453
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
454
455
	}
#endif
456
    }
457

458
    break;
459
460

  case 2:
461

gauthier's avatar
gauthier committed
462
    // TDD, nothing
463
    // FDD, normal UL/DLSCH
464
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
465
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
466
#ifndef FLEXRAN_AGENT_SB_IF
467
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
468
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
469
470
#else
      if (mac_agent_registered[module_idP]) {                                  
471
472
473
474
475
476
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
477
	  
478
479
480
481
482
483
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
484
485
	}
#endif
486
    }
487

488
489
490
    break;

  case 3:
491

gauthier's avatar
gauthier committed
492
    // TDD Config 2, ULSCH for subframeP 7
493
494
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
495
496
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
497
      case 2:
498
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
499
500
501

        // no break here!
      case 5:
502
#ifndef FLEXRAN_AGENT_SB_IF
503
504
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
505
506
#else
	if (mac_agent_registered[module_idP]) {                                  
507
508
509
510
511
512
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
513
	  
514
515
516
517
518
519
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
520
521
	}
#endif
522
523
524
525
526
527
        break;

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

529
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
530
#ifndef FLEXRAN_AGENT_SB_IF
531
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
532
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
533
534
#else
      if (mac_agent_registered[module_idP]) {                                  
535
536
537
538
539
540
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
541
	  
542
543
544
545
546
547
548
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
      }
549
#endif
550
    }
551

552
    break;
553
554

  case 4:
555

gauthier's avatar
gauthier committed
556
    // TDD Config 1, ULSCH for subframeP 8
557
558
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
559
560
    if (mac_xface->frame_parms->frame_type == 1) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
561
      case 1:
562
        //        schedule_RA(module_idP,frameP,subframeP);
563
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
564
565
566
567
568
569
570
571
572

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
573
#ifndef FLEXRAN_AGENT_SB_IF
574
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
575
576
577
	fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
#else
	if (mac_agent_registered[module_idP]) {                                  
578
579
580
581
582
583
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
584
	  
585
586
587
588
589
590
	  flexran_apply_dl_scheduling_decisions(module_idP,
					       frameP,
					       subframeP,
					       mbsfn_status,
					       msg);
	  flexran_agent_mac_destroy_dl_config(msg);
591
592
	}
#endif	
593
594
595
596
597
598
        break;

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

601
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
602
#ifndef FLEXRAN_AGENT_SB_IF
603
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
604
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
605
606
#else
	if (mac_agent_registered[module_idP]) {                                  
607
608
609
610
611
612
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
613
	  
614
615
616
617
618
619
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
620
621
	}     
#endif
622
      }
623
    }
624

625
626
627
628
629
630
631
    break;

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

634
    //schedule_RA(module_idP,frameP,subframeP,5);
635
    if (mac_xface->frame_parms->frame_type == FDD) {
636
637
      schedule_RA(module_idP,frameP,subframeP,1);
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
638
#ifndef FLEXRAN_AGENT_SB_IF
639
640
      schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
641
642
#else
      if (mac_agent_registered[module_idP]) {                                  
643
644
645
646
647
648
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
649
	  
650
651
652
653
654
655
	  flexran_apply_dl_scheduling_decisions(module_idP,
					  frameP,
					  subframeP,
					  mbsfn_status,
					  msg);
	  flexran_agent_mac_destroy_dl_config(msg);
656
657
	}
#endif
658
659
    } else if ((mac_xface->frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->frame_parms->tdd_config == 6)) { // TDD Config 6
660
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
661
#ifndef FLEXRAN_AGENT_SB_IF
662
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
663
#endif
664
    } else {
665
#ifndef FLEXRAN_AGENT_SB_IF
666
667
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
668
669
#else
      if (mac_agent_registered[module_idP]) {                                  
670
671
672
673
674
675
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
676
	  
677
678
679
680
681
682
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
683
684
	}
#endif
685
    }
686

687
688
689
    break;

  case 6:
690

691
692
693
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
694
695
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
696
697
698
699
      case 0:
        break;

      case 1:
700
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
701
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
702
#ifndef FLEXRAN_AGENT_SB_IF
703
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
704
#endif
705
706
707
        break;

      case 6:
708
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
709
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
710
#ifndef FLEXRAN_AGENT_SB_IF
711
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
712
#endif
713
714
715
        break;

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

      case 3:
      case 4:
741
#ifndef FLEXRAN_AGENT_SB_IF
742
743
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
744
745
#else
	if (mac_agent_registered[module_idP]) {                                  
746
747
748
749
750
751
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
752
	  
753
754
755
756
757
758
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
759
760
	}
#endif
761
762
763
764
765
766
        break;

      default:
        break;
      }
    } else { //FDD
767
      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0);
768
#ifndef FLEXRAN_AGENT_SB_IF
769
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
770
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
771
772
#else
      if (mac_agent_registered[module_idP]) {                                  
773
774
775
776
777
778
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
779
	  
780
781
782
783
784
785
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
786
787
	}
#endif
788
    }
789

790
    break;
gauthier's avatar
gauthier committed
791

792
  case 7:
793

794
795
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
796
797
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
798
799
      case 3:
      case 4:
800
        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
801
#ifndef FLEXRAN_AGENT_SB_IF
802
803
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
804
805
#else
	if (mac_agent_registered[module_idP]) {                                  
806
807
808
809
810
811
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
812
	  
813
814
815
816
817
818
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
819
820
	}
#endif
821
822
823
        break;

      case 5:
824
#ifndef FLEXRAN_AGENT_SB_IF
825
826
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
827
828
#else
	if (mac_agent_registered[module_idP]) {                                  
829
830
831
832
833
834
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
835
	  
836
837
838
839
840
841
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
842
843
	}
#endif
844
845
846
847
848
849
        break;

      default:
        break;
      }
    } else { //FDD
850
      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
851
#ifndef FLEXRAN_AGENT_SB_IF
852
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
853
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
854
855
#else
      if (mac_agent_registered[module_idP]) {                                  
856
857
858
859
860
861
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
862
	  
863
864
865
866
867
868
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
869
870
	}
#endif
871
    }
872

873
874
875
    break;

  case 8:
876

gauthier's avatar
gauthier committed
877
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
878
879
    //
    // FDD Normal UL/DLSCH
880
881
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
882
883
884
885
886
      case 2:
      case 3:
      case 4:
      case 5:

887
        //  schedule_RA(module_idP,subframeP);
888
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
889
#ifndef FLEXRAN_AGENT_SB_IF
890
891
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
892
893
#else
	if (mac_agent_registered[module_idP]) {                                  
894
895
896
897
898
899
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
900
	  
901
902
903
904
905
906
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
907
908
	}
#endif
909
910
911
912
913
914
        break;

      default:
        break;
      }
    } else { //FDD
915
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
916
#ifndef FLEXRAN_AGENT_SB_IF
917
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
918
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
919
920
#else
      if (mac_agent_registered[module_idP]) {                                  
921
922
923
924
925
926
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
927
	  
928
929
930
931
932
933
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
934
935
	}
#endif
936
    }
937

938
939
940
    break;

  case 9:
941

942
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
943
944
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
945
      case 1:
946
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
947
        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
948
#ifndef FLEXRAN_AGENT_SB_IF
949
950
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
951
952
#else
	if (mac_agent_registered[module_idP]) {                                  
953
954
955
956
957
958
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,