Commit df8b9363 authored by wangdong's avatar wangdong

Create a new schedule mode - ai-dl-mode

parent 01051752
......@@ -96,6 +96,201 @@ int rr_dl_run(module_id_t Mod_id,
const int RBGlastsize = get_rbg_size_last(Mod_id, CC_id);
UE_info_t *UE_info = &RC.mac[Mod_id]->UE_info;
int rbg = 0;
for (; !rbgalloc_mask[rbg]; rbg++)
; /* fast-forward to first allowed RBG */
/* just start with the UE after the one we had last time. If it does not
* exist, this will start at the head */
int *start_ue = data;
*start_ue = next_ue_list_looped(UE_list, *start_ue);
int UE_id = *start_ue;
UE_list_t UE_sched;
int *cur_UE = &UE_sched.head;
// Allocate retransmissions, and mark UEs with new transmissions,亦是是每帧执行
do {
// check whether there are HARQ retransmissions
const COMMON_channels_t *cc = &RC.mac[Mod_id]->common_channels[CC_id];
const uint8_t harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config, frame, subframe);//fdd固定每8帧
UE_sched_ctrl_t *ue_ctrl = &UE_info->UE_sched_ctrl[UE_id];
const uint8_t round = ue_ctrl->round[CC_id][harq_pid];
if (round != 8) { // retransmission: allocate
const int nb_rb = UE_info->UE_template[CC_id][UE_id].nb_rb[harq_pid];
if (nb_rb == 0)
goto skip_ue;
int nb_rbg = (nb_rb + (nb_rb % RBGsize)) / RBGsize;
// needs more RBGs than we can allocate
if (nb_rbg > n_rbg_sched) {//这一帧的家伙满足不了了
LOG_D(MAC,
"retransmission of UE %d needs more RBGs (%d) than we have (%d)\n",
UE_id, nb_rbg, n_rbg_sched);
goto skip_ue;
}
// ensure that the number of RBs can be contained by the RBGs (!), i.e.
// if we allocate the last RBG this one should have the full RBGsize
if ((nb_rb % RBGsize) == 0 && nb_rbg == n_rbg_sched
&& rbgalloc_mask[N_RBG - 1] && RBGlastsize != RBGsize) {
LOG_D(MAC,
"retransmission of UE %d needs %d RBs, but the last RBG %d is too small (%d, normal %d)\n",
UE_id, nb_rb, N_RBG - 1, RBGlastsize, RBGsize);
goto skip_ue;
}
const uint8_t cqi = ue_ctrl->dl_cqi[CC_id];
const int idx = CCE_try_allocate_dlsch(Mod_id, CC_id, subframe, UE_id, cqi);
if (idx < 0)
goto skip_ue; // cannot allocate CCE
ue_ctrl->pre_dci_dl_pdu_idx = idx;
// retransmissions: directly allocate
n_rbg_sched -= nb_rbg;
ue_ctrl->pre_nb_available_rbs[CC_id] += nb_rb;
for (; nb_rbg > 0; rbg++) {
if (!rbgalloc_mask[rbg])
continue;
ue_ctrl->rballoc_sub_UE[CC_id][rbg] = 1;
rbgalloc_mask[rbg] = 0;
nb_rbg--;
}
LOG_D(MAC,
"%4d.%d n_rbg_sched %d after retransmission reservation for UE %d "
"round %d retx nb_rb %d pre_nb_available_rbs %d\n",
frame, subframe, n_rbg_sched, UE_id, round,
UE_info->UE_template[CC_id][UE_id].nb_rb[harq_pid],
ue_ctrl->pre_nb_available_rbs[CC_id]);
/* if there are no more RBG to give, return */
if (n_rbg_sched <= 0)
return 0;
max_num_ue--;
/* if there are no UEs that can be allocated anymore, return */
if (max_num_ue == 0)
return n_rbg_sched;
for (; !rbgalloc_mask[rbg]; rbg++) /* fast-forward */ ;
} else {
rnti_t rnti = UE_RNTI(Mod_id, UE_id);
if (UE_info->UE_template[CC_id][UE_id].dl_buffer_total > 0) {//获取该dl的buffer,如果没Buffer就后面跳过了!!!
*cur_UE = UE_id;
cur_UE = &UE_sched.next[UE_id];
}
}
skip_ue:
UE_id = next_ue_list_looped(UE_list, UE_id);
} while (UE_id != *start_ue);
*cur_UE = -1; // mark end,巧妙的Hack!
if (UE_sched.head < 0){
return n_rbg_sched;
}// no UE has a transmission
// after allocating retransmissions: pre-allocate CCE, compute number of
// requested RBGs
// 计算每个调度帧内UE所需的RB
max_num_ue = min(max_num_ue, n_rbg_sched);
int rb_required[MAX_MOBILES_PER_ENB]; // how much UEs request
cur_UE = &UE_sched.head;
while (*cur_UE >= 0 && max_num_ue > 0) {
const int UE_id = *cur_UE;
cur_UE = &UE_sched.next[UE_id]; // go to next
const uint8_t cqi = UE_info->UE_sched_ctrl[UE_id].dl_cqi[CC_id];
const int idx = CCE_try_allocate_dlsch(Mod_id, CC_id, subframe, UE_id, cqi);
if (idx < 0) {
LOG_D(MAC, "cannot allocate CCE for UE %d, skipping\n", UE_id);
continue;
}
UE_info->UE_sched_ctrl[UE_id].pre_dci_dl_pdu_idx = idx;
const int mcs = cqi_to_mcs[cqi];
UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = mcs;
const uint32_t B = UE_info->UE_template[CC_id][UE_id].dl_buffer_total;
rb_required[UE_id] = find_nb_rb_DL(mcs, B, n_rbg_sched * RBGsize, RBGsize);
max_num_ue--;
}
// PARTITIONING
// Reduces the available RBs according to slicing configuration
//
*cur_UE = -1; // not all UEs might be allocated, mark end
/* for one UE after the next: allocate resources */
cur_UE = &UE_sched.head;
while (*cur_UE >= 0) {
const int UE_id = *cur_UE;
UE_sched_ctrl_t *ue_ctrl = &UE_info->UE_sched_ctrl[UE_id];
ue_ctrl->rballoc_sub_UE[CC_id][rbg] = 1;//该次轮询给 ***
rbgalloc_mask[rbg] = 0;//该RBG已分配
const int sRBG = rbg == N_RBG - 1 ? RBGlastsize : RBGsize;//是否是最后一个RBG
ue_ctrl->pre_nb_available_rbs[CC_id] += sRBG;//更新该UE的可用的RBs
rb_required[UE_id] -= sRBG;//相应的减少了该UE所需发送的RBs
if (rb_required[UE_id] <= 0) {//该UE的还剩的所需发送为0
*cur_UE = UE_sched.next[*cur_UE];
if (*cur_UE < 0)
cur_UE = &UE_sched.head;
} else {
cur_UE = UE_sched.next[*cur_UE] < 0 ? &UE_sched.head : &UE_sched.next[*cur_UE];
}
n_rbg_sched--;//每次分配一个RBG
if (n_rbg_sched <= 0)
break;//如果该次调度所有的rbg均被分配,则跳出资源分配
for (rbg++; !rbgalloc_mask[rbg]; rbg++) /* fast-forward */ ;
}
return n_rbg_sched;
//* 分配的结果:将结果都存储到了 ue_ctrl->rballoc_sub_UE[CC_id][rbg] 之中!!!,最后所有rbg都分配
}
default_sched_dl_algo_t round_robin_dl = {
.name = "round_robin_dl",
.setup = rr_dl_setup,
.unset = rr_dl_unset,
.run = rr_dl_run,
.data = NULL
};
/*
* /*! \file pre_processor.c->downlink AI Scheduler
* \brief eNB scheduler preprocessing fuction prior to scheduling
* \author wangdong
* \date 2020/11/07
* \email s20200619@xs.ustb.edu.cn
* \version 0.1 Bate
* @ingroup _mac
*/
void *ai_dl_setup(void) {
void *data = malloc(sizeof(int));
*(int *) data = 0;
AssertFatal(data, "could not allocate data in %s()\n", __func__);
return data;
}
void ai_dl_unset(void **data) {
if (*data)
free(*data);
*data = NULL;
}
int ai_dl_run(module_id_t Mod_id,
int CC_id,
int frame,
int subframe,
UE_list_t *UE_list,
int max_num_ue,
int n_rbg_sched,
uint8_t *rbgalloc_mask,
void *data) {
DevAssert(UE_list->head >= 0);
DevAssert(n_rbg_sched > 0);
const int N_RBG = to_rbg(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
const int RBGsize = get_min_rb_unit(Mod_id, CC_id);
const int RBGlastsize = get_rbg_size_last(Mod_id, CC_id);
UE_info_t *UE_info = &RC.mac[Mod_id]->UE_info;
Subframe subframe_t = {
.Mod_id = Mod_id,
.frame = frame,
......@@ -110,6 +305,50 @@ int rr_dl_run(module_id_t Mod_id,
.allocate = {0,0,0,0},
.total_buffer = {0,0,0,0},
};
//建立Socket链接,并存放在RC.sockfd中
//然后就是创建Socket连接,并发送
static int flag =0;
#define MAXLINE 800000
#define SER_PORT 23333
int buffer = 0;
if(flag==0){
LOG_I(MAC,"[SOCKET]Socket \n");
struct sockaddr_in servaddr;
int sockfd = 0;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
RC.sockfd = sockfd;
printf("[SOCKET]Socket ID :&RC.mac[Mod_id]->sockfd= %d\n", RC.sockfd); //buffer = sockfd;
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr);
servaddr.sin_port = htons(SER_PORT);
if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
{
printf("[SOCKET]connet error:%s\n", strerror(errno));
} //链接服务器
else{
flag = flag +1;
int num;
char *json_data = NULL;
json_data = "Begin Connection to Python Server";
int n = strlen(json_data);
char buf[MAXLINE];
write(sockfd, json_data, n);
read(sockfd, buf, MAXLINE);
printf("[SOCKET]Response from server: %s\n", buf);
}
}
int rbg = 0;
for (; !rbgalloc_mask[rbg]; rbg++)
; /* fast-forward to first allowed RBG */
......@@ -300,14 +539,18 @@ skip_ue:
}
default_sched_dl_algo_t round_robin_dl = {
.name = "round_robin_dl",
.setup = rr_dl_setup,
.unset = rr_dl_unset,
.run = rr_dl_run,
.name = "ai_dl",
.setup = ai_dl_setup,
.unset = ai_dl_unset,
.run = ai_dl_run,
.data = NULL
};
void *pf_dl_setup(void) {
void *data = calloc(MAX_MOBILES_PER_ENB, sizeof(float));
for (int i = 0; i < MAX_MOBILES_PER_ENB; i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment