eNB_scheduler.c 34.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21
22

/*! \file eNB_scheduler.c
nikaeinn's avatar
nikaeinn committed
23
 * \brief eNB scheduler top level function operates on per subframe basis
24
25
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
26
 * \email: navid.nikaein@eurecom.fr
27
28
 * \version 0.5
 * @ingroup _mac
29

30
 */
31

32
#include "assertions.h"
33
34
35
36
37
38
39
40
#include "PHY/defs.h"
#include "PHY/extern.h"

#include "SCHED/defs.h"
#include "SCHED/extern.h"

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/extern.h"
gauthier's avatar
gauthier committed
41

42
43
44
45
46
47
#include "LAYER2/MAC/proto.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"
gauthier's avatar
gauthier committed
48

49
50
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
gauthier's avatar
gauthier committed
51

52
53
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"
54

55
#if defined(FLEXRAN_AGENT_SB_IF)
56
//Agent-related headers
57
58
59
#include "flexran_agent_extern.h"
#include "flexran_agent_mac.h"
#include "flexran_agent_mac_proto.h"
60
#endif
61

62
63
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
64
65
#endif

66
67
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1
68
//efine ENABLE_ENB_AGENT_DL_SCHEDULER
69
//#define DISABLE_SF_TRIGGER
70
//#define DISABLE_CONT_STATS
71

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

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



83

84
85
86



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

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

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

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

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

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

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

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

140
141
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
142
143
144
145
146
147
148
149
    if ((frameP==0)&&(subframeP==0)) {
      LTE_eNB_UE_stats *eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti);
      int cqi = eNB_UE_stats == NULL ? -1 : eNB_UE_stats->DL_cqi[0];
      LOG_I(MAC,"UE  rnti %x : %s, PHR %d dB CQI %d\n", rnti,
            UE_list->UE_sched_ctrl[i].ul_out_of_sync==0 ? "in synch" : "out of sync",
            UE_list->UE_template[CC_id][i].phr_info,
            cqi);
    }
150

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

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

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

284
#if defined(ENABLE_ITTI)
285

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

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

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

299
300
301
302
      case RRC_MAC_BCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_BCCH_DATA_REQ (msg_p).frame, RRC_MAC_BCCH_DATA_REQ (msg_p).enb_index);
303

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

307
308
309
310
      case RRC_MAC_CCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_CCCH_DATA_REQ (msg_p).frame, RRC_MAC_CCCH_DATA_REQ (msg_p).enb_index);
311

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

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

317
318
319
320
      case RRC_MAC_MCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d, mbsfn_sync_area %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_MCCH_DATA_REQ (msg_p).frame, RRC_MAC_MCCH_DATA_REQ (msg_p).enb_index, RRC_MAC_MCCH_DATA_REQ (msg_p).mbsfn_sync_area);
321

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

326
327
328
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
329
      }
330
331
332
333

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

336
337
#endif

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

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

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

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
359
360
361
362
    if (eNB_mac_inst[module_idP].common_channels[CC_id].MBMS_flag >0) {
      start_meas(&eNB_mac_inst[module_idP].schedule_mch);
      mbsfn_status[CC_id] = schedule_MBMS(module_idP,CC_id,frameP,subframeP);
      stop_meas(&eNB_mac_inst[module_idP].schedule_mch);
knopp's avatar
   
knopp committed
363
    }
364
  }
365

366
#endif
knopp's avatar
   
knopp committed
367
  // refresh UE list based on UEs dropped by PHY in previous subframe
368
  /*
knopp's avatar
   
knopp committed
369
370
371
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
372
    LOG_T(MAC,"UE %d : rnti %x, stats %p\n",i,UE_RNTI(module_idP,i),mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i)));
knopp's avatar
   
knopp committed
373
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
   
knopp committed
374
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
   
knopp committed
375
376
377
    }
    i=next_i;
  }
378
  */
379

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

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

knopp's avatar
knopp committed
387

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

390

391
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
392
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
393
    } else if  ((mac_xface->frame_parms->tdd_config == 0) || //TDD
394
395
                (mac_xface->frame_parms->tdd_config == 3) ||
                (mac_xface->frame_parms->tdd_config == 6)) {
396
      schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
397
    }
398
#ifndef FLEXRAN_AGENT_SB_IF
399
400
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
401
402
#else
    if (mac_agent_registered[module_idP]) {                                  
403
404
405
406
407
408
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
409
	  
410
411
412
413
414
415
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
416
417
	}
#endif
418
419
420
    break;

  case 1:
421

gauthier's avatar
gauthier committed
422
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
423
    // FDD, schedule normal UL/DLSCH
424
425
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
426
427
      case 0:
      case 1:
428
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
429
#ifndef FLEXRAN_AGENT_SB_IF
430
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
431
#endif
432
433
434
        break;

      case 6:
435
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
436
#ifndef FLEXRAN_AGENT_SB_IF
437
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
438
#endif
439
440
441
442
443
444
        break;

      default:
        break;
      }
    } else { //FDD
445
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
446
#ifndef FLEXRAN_AGENT_SB_IF
447
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
448
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
449
450
#else
      if (mac_agent_registered[module_idP]) {                                  
451
452
453
454
455
456
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
457
	  
458
459
460
461
462
463
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
464
465
	}
#endif
466
    }
467

468
    break;
469
470

  case 2:
471

gauthier's avatar
gauthier committed
472
    // TDD, nothing
473
    // FDD, normal UL/DLSCH
474
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
475
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
476
#ifndef FLEXRAN_AGENT_SB_IF
477
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
478
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
479
480
#else
      if (mac_agent_registered[module_idP]) {                                  
481
482
483
484
485
486
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
487
	  
488
489
490
491
492
493
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
494
495
	}
#endif
496
    }
497

498
499
500
    break;

  case 3:
501

gauthier's avatar
gauthier committed
502
    // TDD Config 2, ULSCH for subframeP 7
503
504
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
505
506
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
507
      case 2:
508
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
509
510
511

        // no break here!
      case 5:
512
#ifndef FLEXRAN_AGENT_SB_IF
513
514
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
515
516
#else
	if (mac_agent_registered[module_idP]) {                                  
517
518
519
520
521
522
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
523
	  
524
525
526
527
528
529
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
530
531
	}
#endif
532
533
534
535
536
537
        break;

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

539
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
540
#ifndef FLEXRAN_AGENT_SB_IF
541
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
542
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
543
544
#else
      if (mac_agent_registered[module_idP]) {                                  
545
546
547
548
549
550
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
551
	  
552
553
554
555
556
557
558
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
      }
559
#endif
560
    }
561

562
    break;
563
564

  case 4:
565

gauthier's avatar
gauthier committed
566
    // TDD Config 1, ULSCH for subframeP 8
567
568
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
569
570
    if (mac_xface->frame_parms->frame_type == 1) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
571
      case 1:
572
        //        schedule_RA(module_idP,frameP,subframeP);
573
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
574
575
576
577
578
579
580
581
582

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
583
#ifndef FLEXRAN_AGENT_SB_IF
584
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
585
586
587
	fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
#else
	if (mac_agent_registered[module_idP]) {                                  
588
589
590
591
592
593
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
594
	  
595
596
597
598
599
600
	  flexran_apply_dl_scheduling_decisions(module_idP,
					       frameP,
					       subframeP,
					       mbsfn_status,
					       msg);
	  flexran_agent_mac_destroy_dl_config(msg);
601
602
	}
#endif	
603
604
605
606
607
608
        break;

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

611
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
612
#ifndef FLEXRAN_AGENT_SB_IF
613
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
614
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
615
616
#else
	if (mac_agent_registered[module_idP]) {                                  
617
618
619
620
621
622
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
623
	  
624
625
626
627
628
629
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
630
631
	}     
#endif
632
      }
633
    }
634

635
636
637
638
639
640
641
    break;

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

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

697
698
699
    break;

  case 6:
700

701
702
703
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
704
705
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
706
707
708
709
      case 0:
        break;

      case 1:
710
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
711
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
712
#ifndef FLEXRAN_AGENT_SB_IF
713
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
714
#endif
715
716
717
        break;

      case 6:
718
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
719
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
720
#ifndef FLEXRAN_AGENT_SB_IF
721
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
722
#endif
723
724
725
        break;

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

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

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

800
    break;
gauthier's avatar
gauthier committed
801

802
  case 7:
803

804
805
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
806
807
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
808
809
      case 3:
      case 4:
810
        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
811
#ifndef FLEXRAN_AGENT_SB_IF
812
813
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
814
815
#else
	if (mac_agent_registered[module_idP]) {                                  
816
817
818
819
820
821
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
822
	  
823
824
825
826
827
828
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
829
830
	}
#endif
831
832
833
        break;

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

      default:
        break;
      }
    } else { //FDD
860
      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
861
#ifndef FLEXRAN_AGENT_SB_IF
862
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
863
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
864
865
#else
      if (mac_agent_registered[module_idP]) {                                  
866
867
868
869
870
871
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
872
	  
873
874
875
876
877
878
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
879
880
	}
#endif
881
    }
882

883
884
885
    break;

  case 8:
886

gauthier's avatar
gauthier committed
887
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
888
889
    //
    // FDD Normal UL/DLSCH
890
891
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
892
893
894
895
896
      case 2:
      case 3:
      case 4:
      case 5:

897
        //  schedule_RA(module_idP,subframeP);
898
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
899
#ifndef FLEXRAN_AGENT_SB_IF
900
901
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
902
903
#else
	if (mac_agent_registered[module_idP]) {                                  
904
905
906
907
908
909
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
910
	  
911
912
913
914
915
916
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
917
918
	}
#endif
919
920
921
922
923
924
        break;

      default:
        break;
      }
    } else { //FDD
925
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
926
#ifndef FLEXRAN_AGENT_SB_IF
927
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
928
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
929
930
#else
      if (mac_agent_registered[module_idP]) {                                  
931
932
933
934
935
936
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
937
	  
938
939
940
941
942
943
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
944
945
	}
#endif
946
    }
947

948
949
950
    break;

  case 9:
951

952
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
953
954
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
955
      case 1:
956
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
957
        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
958
#ifndef FLEXRAN_AGENT_SB_IF
959
960
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
961
962
#else
	if (mac_agent_registered[module_idP]) {                                  
963
964
965
966
967
968
	  agent_mac_xface[module_idP]->flexran_agent_schedule_ue_spec(
								      module_idP,
								      frameP,                  
								      subframeP,
								      mbsfn_status,
								      &msg);
969
	  
970
971
972
973
974
975
	  flexran_apply_dl_scheduling_decisions(module_idP,
						frameP,
						subframeP,
						mbsfn_status,
						msg);
	  flexran_agent_mac_destroy_dl_config(msg);
976
977
	}
#endif
978
979
980