eNB_scheduler.c 33.6 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];
knopp's avatar
   
knopp committed
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

knopp's avatar
   
knopp committed
126
  // refresh UE list based on UEs dropped by PHY in previous subframe
127
128
129
  i = UE_list->head;

  while (i>=0) {
130
131
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
132
133
134
135
    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");

136
    next_i= UE_list->next[i];
137

138
139
140
    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]); 
141
142
    // increment this, it is cleared when we receive an sdu
    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
143
144

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

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

269
#if defined(ENABLE_ITTI)
270

271
  do {
272
273
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
274

275
276
277
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
278

279
280
281
282
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
283

284
285
286
287
      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);
288

289
290
        // TODO process BCCH data req.
        break;
291

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

297
298
        // TODO process CCCH data req.
        break;
299
300
301

#ifdef Rel10

302
303
304
305
      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);
306

307
308
309
        // TODO process MCCH data req.
        break;
#endif
310

311
312
313
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
314
      }
315
316
317
318

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

321
322
#endif

gauthier's avatar
gauthier committed
323
  // clear DCI and BCCH contents before scheduling
324
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
   
knopp committed
325
326
    DCI_pdu[CC_id]->Num_common_dci  = 0;
    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
327

328

329
#ifdef Rel10
330
    eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0;
331
#endif
332

knopp's avatar
   
knopp committed
333
334
    eNB_mac_inst[module_idP].frame    = frameP;
    eNB_mac_inst[module_idP].subframe = subframeP;
335
336


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

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

#ifdef Rel10
358
359

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

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

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

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

knopp's avatar
knopp committed
388

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

391

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

  case 1:
422

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

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

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

469
    break;
470
471

  case 2:
472

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

499
500
501
    break;

  case 3:
502

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

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

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

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

563
    break;
564
565

  case 4:
566

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

        // no break here!
      case 2:

        // no break here!
      case 4:

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

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

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

636
637
638
639
640
641
642
    break;

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

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

698
699
700
    break;

  case 6:
701

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

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

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

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

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

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

801
    break;
gauthier's avatar
gauthier committed
802

803
  case 7:
804

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

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

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

884
885
886
    break;

  case 8:
887

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

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

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