eNB_scheduler_NB_IoT.c 7.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * 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
 */

/*! \file eNB_scheduler_nb_iot.c
 * \brief top level of the scheduler, it scheduled in pdcch period based.
 * \author  
 * \date 2017
 * \email: 
 * \version 0.5
 * @ingroup _mac
 *
 */

32 33 34
#include "defs_NB_IoT.h"
#include "proto_NB_IoT.h"
#include "extern_NB_IoT.h"
35 36


37 38 39 40
//	scheduler
#define flag_css_type1 0x1
#define flag_css_type2 0x2
#define flag_uss_v	   0x4
41

42 43 44 45 46
//	common
#define flag_mib      0x1
#define flag_sib1     0x2
#define flag_npss     0x4
#define flag_nsss     0x8
47

48 49 50 51 52 53 54 55

#define num_flags 2
int extend_space[num_flags] = {160, 160};
int extend_alpha_offset[num_flags] = {10, 10};

int uss_space = 320;
int uss_alpha_offset = 10;

56
void eNB_scheduler_computing_flag_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, uint32_t abs_subframe, int *scheduler_flags, int *common_flags){
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	uint32_t subframe = abs_subframe % 10;
	uint32_t frame = abs_subframe / 10;
	int i;

	if(subframe == 0){
		*common_flags |= flag_mib;
	}else if(subframe == 5){
		*common_flags |= flag_npss;
	}else if(subframe == 9 && (frame&0x1)==0){
		*common_flags |= flag_nsss;
	}else if(subframe == 4 && mac_inst->sib1_flag[frame%mac_inst->sib1_period]){
		*common_flags |= flag_sib1;
	}
	for(i=0; i<num_flags; ++i){
		if(((abs_subframe+1)%extend_space[i])==(extend_space[i]>>extend_alpha_offset[i])){
			*scheduler_flags |= (0x1<<i);
		}
	}
	//USS trigger flag
	for(i=0;i<mac_inst->num_uss_list;++i)
	{
		//printf("[eNB Computing falg] USS trigger time %d ss start time %d\n", ((abs_subframe+1)%mac_inst->UE_list_spec[i].NPDCCH_config_dedicated.T), mac_inst->UE_list_spec[i].NPDCCH_config_dedicated.ss_start_uss);
		if(((abs_subframe+1)%mac_inst->UE_list_spec[i].NPDCCH_config_dedicated.T)==mac_inst->UE_list_spec[i].NPDCCH_config_dedicated.ss_start_uss)
		{
			//SCHEDULE_LOG("1\n");
			*scheduler_flags |= (flag_uss_v<<i);
		}
	}
	//printf("[eNB Computing falg] scheduler_flags %X\n", *scheduler_flags);
	/*
	//USS trigger flag
	if((abs_subframe%uss_space)==(uss_space>>uss_alpha_offset)){
		*scheduler_flags |= flag_uss_v;
	}
	*/
}
/*function description:
* top level of the scheduler, this will trigger in every subframe,
95 96
* and determined if do the schedule by checking this current subframe is the start of the NPDCCH period or not
*/
97 98 99
void eNB_dlsch_ulsch_scheduler_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, uint32_t abs_subframe){
 // eNB_MAC_INST_NB_IoT *eNB = &eNB_mac_inst_NB_IoT[module_id];
	int i, max_subframe, scheduler_flags, common_flags,MIB_flag,SIB1_flag;
100
	int a = 0;
101 102 103 104 105
	/*Check this subframe should schedule something, set the flag*/
	scheduler_flags = 0;
	common_flags = 0;
	MIB_flag = 0;
	SIB1_flag = 0;
106 107
	uint32_t h,f,sf;
	//int a;
108 109 110 111 112 113 114 115 116 117 118 119
	//DEBUG("--------------[%04d][eNB scheduler NB-IoT] Start Scheduling------------\n", mac_inst->current_subframe);
	eNB_scheduler_computing_flag_NB_IoT(mac_inst, abs_subframe, &scheduler_flags, &common_flags);
	/*Update the available resource list to current state*/
	//NB_IoT_maintain_available_resource(subframe, frame, hypersfn);
	max_subframe = 0;
	for(i=0; i<num_flags; ++i){
		if(1 == (scheduler_flags&(0x1<<i))){
			if(max_subframe < extend_space[i]){
				max_subframe = extend_space[i];
			}
		}
	}
120

121 122 123 124 125
	if(scheduler_flags > 0){
	        extend_available_resource_DL(mac_inst, mac_inst->current_subframe + 1 + max_subframe);
	}
	
	maintain_available_resource(mac_inst);
126

127
    //static int test=2;
128 129 130 131 132 133 134 135 136 137
	if((abs_subframe % rachperiod[4]) == rachstart[0]){

		   add_UL_Resource();
	}

	//Check if type2 searching space scheduling
	if((scheduler_flags&flag_css_type2)>0){
		schedule_RA_NB_IoT(mac_inst);
		scheduler_flags &= ~(flag_css_type2);
	}
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
	//Check if type1 searching space scheduling
	if((scheduler_flags&flag_css_type1)>0){
		scheduler_flags &= ~(flag_css_type1);
 	}
	
	// loop all USS period
	for(i=0;i<mac_inst->num_uss_list;++i)
	{
		if((scheduler_flags&(flag_uss_v<<i))>0){
			printf("--------------[%04d][SchedulerUSS] Schedule USS list %d------------\n", mac_inst->current_subframe, (scheduler_flags&(flag_uss_v<<i))>>3);
			scheduler_flags &= ~(flag_uss_v<<i);
			convert_system_number(abs_subframe, &h, &f, &sf);
			//DEBUG("=====t:%d======\n", mac_inst->current_subframe);
			//print_available_resource_DL();
			schedule_uss_NB_IoT(0, mac_inst,sf, f, h, i);
		}
	}
	/*
	//Check if UE-specific searching space scheduling
	if((scheduler_flags&flag_uss_v)>0){
		scheduler_flags &= ~(flag_uss_v);
		convert_system_number(abs_subframe, &h, &f, &sf);
		//DEBUG("=====t:%d======\n", mac_inst->current_subframe);
		//print_available_resource_DL();
		schedule_uss_NB_IoT(0, mac_inst,sf, f, h, 0);
	}
	*/
	if(common_flags ==  flag_mib)
		MIB_flag = 1;
	if(common_flags == flag_sib1)
		SIB1_flag = 1;
	convert_system_number(abs_subframe, &h, &f, &sf);
	a = output_handler(mac_inst, 0,0,h,f,sf,MIB_flag,SIB1_flag, abs_subframe);
	//DEBUG("--------------[%04d][eNB scheduler NB-IoT] End Scheduling------------\n", mac_inst->current_subframe);
173 174
}

175 176
void schedule_uss_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, uint32_t subframe, uint32_t frame, uint32_t hypersfn, int index_ss)
{
177
	//int32_t i;
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
	//SCHEDULE_NB_IoT_t *scheduler =  &eNB->scheduler;
  	mac_inst->scheduling_flag.flag_uss[0]=1;
  	mac_inst->scheduling_flag.flag_uss[1]=0;
  	mac_inst->scheduling_flag.flag_uss[2]=0;
  	mac_inst->scheduling_flag.num_uss_run = 0;

	//search space index
	//int index_ss=0;
	int UE_ID;
	UE_TEMPLATE_NB_IoT *UE_template_temp;

	if(mac_inst->scheduling_flag.num_uss_run > 1)
	{
		//spectial case
	}
	else
	{
		//general case
	}

  UE_ID = mac_inst->UE_list_spec[index_ss].head;
  //DEBUG("t=%d   UE ID head %d\n", mac_inst->current_subframe,UE_ID);
  while(UE_ID>-1)
  {
    
    UE_template_temp = &(mac_inst->UE_list_spec[index_ss].UE_template_NB_IoT[UE_ID]);
    printf("------Start Scheduling USS UE RNTI %d------\n", UE_template_temp->rnti);
    if(UE_template_temp->RRC_connected!=1)
    {
    	printf("[schedule_uss_NB_IoT] UE ID %d RRC not connected\n", UE_ID);
	  	printf("[%04d][USS scheduler][UE%d] rrc not connected\n", mac_inst->current_subframe, UE_template_temp->rnti);
    }
    else
    {
    	printf("t=%d*******[schedule_uss_NB_IoT] schedule UE_ID %d direction %d*******%d %d %d\n", mac_inst->current_subframe, UE_ID, UE_template_temp->direction, hypersfn, frame, subframe);
		printf("[%04d][USS scheduler][UE%d] ", mac_inst->current_subframe, UE_template_temp->rnti);
      switch(UE_template_temp->direction)
      {
        //Downlink Scheduling
        case 1:
			printf("uss downlink scheduling.. \n");
          schedule_DL_NB_IoT(0, mac_inst, UE_template_temp,  hypersfn, frame, subframe);
          break;
        //Uplink Scheduling
        case 0:
223
			printf("uss uplink scheduling.. \n");
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
          schedule_UL_NB_IoT(mac_inst, UE_template_temp, subframe, frame, hypersfn);
          break;
		case -1:
			printf("current idle.. \n");
		default:
			break;
      }
      //printf("----------------End Scheduling USS UE RNTI %d-------------------\n", UE_template_temp->rnti);
      UE_template_temp->direction = -1;
    }

    UE_ID = UE_template_temp->next;
  }

}
239