?? mac-802_16.cc
字號:
Queue_list->lookup(mac_->macDA_)->BE.enque(p->copy());
if(Queue_list->lookup(mac_->macDA_)->BE.Lock==0)
{
int SFID_tmp=Insert_SFID(Search_BCID_macSA(mac_->macDA_)->BCID,PT_BE,DL);
Search_SFID(SFID_tmp)->BW=Queue_list->lookup(mac_->macDA_)->BE.byteLength()*10;
Search_SFID(SFID_tmp)->destIP=mac_->macDA_;
Queue_list->lookup(mac_->macDA_)->BE.Lock=1;
}
break;
default:
break;
}
Scheduler& s = Scheduler::instance();
if(!abstract_) s.schedule(&hRes_, &intr_, 0);
//sendDown(p);
}
else sendDown(p);
}
else
{
if(hdr->ptype()==PT_UGS||hdr->ptype()==PT_rtPS
||hdr->ptype()==PT_nrtPS||hdr->ptype()==PT_ertPS||hdr->ptype()==PT_BE)
{
switch(hdr->ptype())
{
case PT_UGS:
ss_buf->lookup(creatid)->UGS.enque(p->copy());
break;
case PT_rtPS:
ss_buf->lookup(creatid)->rtPS.enque(p->copy());
break;
case PT_nrtPS:
ss_buf->lookup(creatid)->nrtPS.enque(p->copy());
break;
case PT_ertPS:
ss_buf->lookup(creatid)->ertPS.enque(p->copy());
break;
case PT_BE:
ss_buf->lookup(creatid)->BE.enque(p->copy());
break;
default:
break;
}
if(check_list->RSPenable(creatid))
{
if(ss_buf->lookup(creatid)->set_UGS==0)
{
if(ss_buf->lookup(creatid)->UGS.byteLength()!=0)
{
sendBWREQ(ss_buf->lookup(creatid)->UGS.byteLength()
,Search_BCID_macSA(creatid)->BCID,PT_UGS, mac_->macDA_,mac_->macSA_);
ss_buf->lookup(creatid)->set_UGS=1;
}
}
if(ss_buf->lookup(creatid)->set_rtPS==0)
{
if(ss_buf->lookup(creatid)->rtPS.byteLength()!=0)
{
sendBWREQ(ss_buf->lookup(creatid)->rtPS.byteLength()
,Search_BCID_macSA(creatid)->BCID,PT_rtPS, mac_->macDA_,mac_->macSA_);
ss_buf->lookup(creatid)->set_rtPS=1;
}
}
if(ss_buf->lookup(creatid)->set_ertPS==0)
{
if(ss_buf->lookup(creatid)->ertPS.byteLength()!=0)
{
sendBWREQ(ss_buf->lookup(creatid)->ertPS.byteLength()
,Search_BCID_macSA(creatid)->BCID,PT_ertPS, mac_->macDA_,mac_->macSA_);
ss_buf->lookup(creatid)->set_ertPS=1;
}
}
if(ss_buf->lookup(creatid)->set_nrtPS==0)
{
if(ss_buf->lookup(creatid)->nrtPS.byteLength()!=0)
{
sendBWREQ(ss_buf->lookup(creatid)->nrtPS.byteLength()
,Search_BCID_macSA(creatid)->BCID,PT_nrtPS, mac_->macDA_,mac_->macSA_);
ss_buf->lookup(creatid)->set_nrtPS=1;
}
}
if(ss_buf->lookup(creatid)->set_BE==0)
{
if(ss_buf->lookup(creatid)->BE.byteLength()!=0)
{
sendBWREQ(ss_buf->lookup(creatid)->BE.byteLength()
,Search_BCID_macSA(creatid)->BCID,PT_BE, mac_->macDA_,mac_->macSA_);
ss_buf->lookup(creatid)->set_BE=1;
}
}
}
Scheduler& s = Scheduler::instance();
if(!abstract_) s.schedule(&hRes_, &intr_, 0);
}
else sendDown(p);
}
return;
}
}
bool Mac802_16::Call_Admission_Control(int BCID,packet_t ptype,int BR_BW)
{
if(CAC_UL - BR_BW >= 0)
{
CAC_UL -= BR_BW;
printf("BS Remainder Uplink Bandwidth %f\n",CAC_UL);
return true;
}
else
return false;
}
void Mac802_16::Bandwidth_Management()
{
printf("\n");
double DL_BW,UL_BW;
BCID_List *BCID_tmp;
int flag;
/*---------------------------------------- Downlink ----------------------------------------*/
Tmp_DL_BW = BS_DL_BW;
if(DLMAP_SS[DL_burst_profile]!=0)
BCID_tmp=Search_BCID(DLMAP_SS[DL_burst_profile]);
else
BCID_tmp=BCID_head;
DL_burst_profile=0;
flag=0;
Downlink_:
while(BCID_tmp!=NULL)
{
SFID_List *SFID_tmp=BCID_tmp->SF;
BCID_tmp->SS_DL_BW = 0;
while(SFID_tmp!= NULL)
{
if(SFID_tmp->SFID%10==5)
BCID_tmp->SS_DL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==6)
BCID_tmp->SS_DL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==7)
BCID_tmp->SS_DL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==8)
BCID_tmp->SS_DL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==9)
BCID_tmp->SS_DL_BW += SFID_tmp->BW;
SFID_tmp=SFID_tmp->next;
}
if(BCID_tmp->SS_DL_BW > 0 && Tmp_DL_BW - BCID_tmp->SS_DL_BW >= 0)
{
for(int i=0;i<13;i++)
{
if(BCID_tmp->BCID==DLMAP_SS[i] && flag==1)
goto sendDLMAP_;
}
Tmp_DL_BW -= BCID_tmp->SS_DL_BW;
DLMAP_SS[DL_burst_profile]=BCID_tmp->BCID;
printf("DLMAP_SS[DL_burst_profile] %d IP %d\n",DLMAP_SS[DL_burst_profile],BCID_tmp->srcIP);
DL_burst_profile++;
if(DL_burst_profile == 12)
{
BCID_tmp=BCID_tmp->next;
if(BCID_tmp!=NULL)
{
DLMAP_SS[DL_burst_profile]=BCID_tmp->BCID;
printf("next DL SS ===========> BCID %d \n",DLMAP_SS[DL_burst_profile]);
}
else
DLMAP_SS[DL_burst_profile]=0;
goto sendDLMAP_;
}
if(BCID_tmp->next==NULL && DL_burst_profile < 12)
{
flag=1;
BCID_tmp=BCID_head;
goto Downlink_;
}
}
DL_BW += BCID_tmp->SS_DL_BW;
BCID_tmp=BCID_tmp->next;
}
sendDLMAP_:
sendDLMAP(DL_burst_profile);
/*------------------------------------------ Uplink ------------------------------------------*/
Tmp_UL_BW = BS_UL_BW;
if(ULMAP_SS[UL_burst_profile]!=0)
BCID_tmp=Search_BCID(ULMAP_SS[UL_burst_profile]);
else
BCID_tmp=BCID_head;
UL_burst_profile=0;
flag=0;
Uplink_:
while(BCID_tmp!=NULL)
{
SFID_List *SFID_tmp=BCID_tmp->SF;
BCID_tmp->SS_UL_BW = 0;
while(SFID_tmp!=NULL)
{
if(SFID_tmp->SFID%10==0)
BCID_tmp->SS_UL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==1)
BCID_tmp->SS_UL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==2)
BCID_tmp->SS_UL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==3)
BCID_tmp->SS_UL_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==4)
BCID_tmp->SS_UL_BW += SFID_tmp->BW;
SFID_tmp=SFID_tmp->next;
}
if(BCID_tmp->SS_UL_BW > 0 && Tmp_UL_BW - BCID_tmp->SS_UL_BW >= 0)
{
for(int i=0;i<11;i++)
{
if(BCID_tmp->BCID==ULMAP_SS[i] && flag==1)
goto sendULMAP_;
}
Tmp_UL_BW -= BCID_tmp->SS_UL_BW;
CAC_UL=Tmp_UL_BW;
ULMAP_SS[UL_burst_profile]=BCID_tmp->BCID;
printf("ULMAP_SS[UL_burst_profile] %d IP %d\n",ULMAP_SS[UL_burst_profile],BCID_tmp->srcIP);
UL_burst_profile++;
if(UL_burst_profile == 10)
{
BCID_tmp=BCID_tmp->next;
if(BCID_tmp!=NULL)
{
ULMAP_SS[UL_burst_profile]=BCID_tmp->BCID;
printf("next UL SS ===========> BCID %d \n",ULMAP_SS[UL_burst_profile]);
}
else
ULMAP_SS[UL_burst_profile]=0;
goto sendULMAP_;
}
if(BCID_tmp->next==NULL && UL_burst_profile < 10)
{
flag=1;
BCID_tmp=BCID_head;
goto Uplink_;
}
}
UL_BW += BCID_tmp->SS_UL_BW;
BCID_tmp=BCID_tmp->next;
}
sendULMAP_:
sendULMAP(UL_burst_profile);
}
void Mac802_16::BS_Scheduler(int BCID, int Symbol_number)
{
BCID_List* BCID_tmp = Search_BCID(BCID);
int All_UGS_BW=-1,All_ertPS_BW=-1,All_rtPS_BW=-1,All_nrtPS_BW=-1,All_BE_BW=-1;
if(BCID_tmp!= NULL)
{
SFID_List* SFID_tmp=BCID_tmp->SF;
while(SFID_tmp!=NULL)
{
if(SFID_tmp->SFID%10==5)
All_UGS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==6)
All_ertPS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==7)
All_rtPS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==8)
All_nrtPS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==9)
All_BE_BW += SFID_tmp->BW;
SFID_tmp=SFID_tmp->next;
}
}
if(All_UGS_BW!=-1) PDU_Generator(PT_UGS, All_UGS_BW+1, BCID);
if(All_ertPS_BW!=-1)PDU_Generator(PT_ertPS, All_ertPS_BW+1, BCID);
if(All_rtPS_BW!=-1) PDU_Generator(PT_rtPS, All_rtPS_BW+1, BCID);
if(All_nrtPS_BW!=-1)PDU_Generator(PT_nrtPS, All_nrtPS_BW+1, BCID);
if(All_BE_BW!=-1) PDU_Generator(PT_BE, All_BE_BW+1, BCID);
}
void Mac802_16::SS_Scheduler(int BCID, int Symbol_number)
{
BCID_List* BCID_tmp = Search_BCID(BCID);
int All_UGS_BW=-1,All_ertPS_BW=-1,All_rtPS_BW=-1,All_nrtPS_BW=-1,All_BE_BW=-1;
if(BCID_tmp!= NULL)
{
SFID_List* SFID_tmp=BCID_tmp->SF;
while(SFID_tmp!=NULL)
{
if(SFID_tmp->SFID%10==0)
All_UGS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==1)
All_ertPS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==2)
All_rtPS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==3)
All_nrtPS_BW += SFID_tmp->BW;
else if(SFID_tmp->SFID%10==4)
All_BE_BW += SFID_tmp->BW;
SFID_tmp=SFID_tmp->next;
}
}
if(All_UGS_BW!=-1) SS_PDU_Generator(PT_UGS, All_UGS_BW+1, BCID);
if(All_ertPS_BW!=-1)SS_PDU_Generator(PT_ertPS, All_ertPS_BW+1, BCID);
if(All_rtPS_BW!=-1) SS_PDU_Generator(PT_rtPS, All_rtPS_BW+1, BCID);
if(All_nrtPS_BW!=-1)SS_PDU_Generator(PT_nrtPS, All_nrtPS_BW+1, BCID);
if(All_BE_BW!=-1) SS_PDU_Generator(PT_BE, All_BE_BW+1, BCID);
}
void Mac802_16::sendRNGREQ(int SA)
{
printf("SS %d is sending RNGREQ to BS\n",creatid);
Packet* p= Packet::alloc();
struct hdr_cmn *hdr = HDR_CMN(p);
struct hdr_mac* mac_ = HDR_MAC(p);
struct hdr_mac802_16* mac16_ =HDR_MAC802_16(p);
struct rng_req_t* rngreq = HDR_MAC802_16_RNGREQ(p);
mac_->macDA_ = 0;
mac_->macSA_ = SA;
hdr->txtime() = 0.0001;
hdr->uid() = 0;
hdr->ptype() = PT_RNGREQ;
hdr->size() = 10;
hdr->iface() = -2;
hdr->error() = 0;
//generic mac header
mac16_->HT =0;
mac16_->EC =1;
mac16_->type=1;
mac16_->CI=1;
mac16_->EKS=1;
mac16_->LEN=3;
mac16_->CID=0;
mac16_->HCS=0;
mac16_->mmt=4;
rngreq->downlinkchannelid = 1;
rngreq->ReqDownlinkBurPro = 1;
rngreq->ssMACAddr = SA;
rngreq->MACver =16;
pktRNGREQ_=p;
BFt.start(cw_,State_,symbolDuration_);
}
void Mac802_16::sendRNGRSP(int ssmac,int BSCID)
{
printf("BS is sending RNGRSP to SS %d\n",BSCID);
Packet* p= Packet::alloc();
struct hdr_cmn *hdr = HDR_CMN(p);
struct hdr_mac* mac_ = HDR_MAC(p);
struct hdr_mac802_16* mac16_ =HDR_MAC802_16(p);
struct rng_rsp_t* rngrsp = HDR_MAC802_16_RNGRSP(p);
mac_->macDA_=ssmac;
mac_->macSA_=creatid;
hdr->txtime() = 0.0001;
hdr->uid() = 0;
hdr->ptype() = PT_RNGRSP;
hdr->size() = 24;
hdr->iface() = -2;
hdr->error() = 0;
mac16_->HT =0;
mac16_->EC =1;
mac16_->type=1;
mac16_->CI=1;
mac16_->EKS=1;
mac16_->LEN=3;
mac16_->CID=BSCID;
mac16_->HCS=0;
mac16_->mmt=5;
rngrsp->BasicCID = BSCID;
rngrsp->SSMAC = ssmac;
rngrsp->RNGstatus = 0;
rngrsp->uplinkchannelid=0;
rngrsp->RNGstatus=0;
rngrsp->PriManCID=0;
rngrsp->FrameNum=0;
rngrsp->IniRNGOpp=0;
pktRNGRSP_=p;
transmit(pktRNGRSP_,0);
}
void Mac802_16::sendBWREQ(int BR, int CID, packet_t pype, int DA,int SA)
{
Packet* p= Packet::alloc();
//p->destIP=DA;
struct hdr_cmn *hdr = HDR_CMN(p);
struct hdr_mac802_16* mac16_ =HDR_MAC802_16(p);
struct bw_req_t* br =HDR_MAC802_16_BWREQ(p) ;
struct hdr_mac* mac_ = HDR_MAC(p);
mac_->macDA_ = 0;
mac_->macSA_ = SA;
hdr->txtime() = 0.000002;
hdr->uid() = 0;
hdr->ptype() = PT_BWREQ;
hdr->size() = 24;
hdr->iface() = -2;
hdr->error() = 0;
mac16_->HT =1;
mac16_->type=1;
mac16_->CI=1;
mac16_->EKS=1;
br->HT =1;
br->EC =0;
br->BR =BR*10;
br->CID=Search_BCID_macSA(creatid)->BCID;
br->HCS=1;
switch(pype){
case PT_UGS:
br->Type=0x0;
printf("SS %d is send UGS Bandwidth Request to BS\n",this->creatid);
break;
case PT_ertPS:
br->Type=0x1;
printf("SS %d is send ertPS Bandwidth Request BS\n",this->creatid);
break;
case PT_rtPS:
br->Type=0x2;
printf("SS %d is send rtPS Bandwidth Request BS\n",this->creatid);
break;
case PT_nrtPS:
br->Type=0x3;
printf("SS %d is send nrtPS Bandwidth Request BS\n",this->creatid);
break;
case PT_BE:
br->Type=0x4;
printf("SS %d is send BE Bandwidth Request BS\n",this->creatid);
break;
default: break;
}
pktBr_=p;
SendBW.start(cw_bw,State_,symbolDuration_);
}
void Mac802_16::sendULMAP(int UL_burst_profile)
{
printf("There are %d Uplink SSs\n",UL_burst_profile);
Packet *p=Packet::alloc();
struct hdr_cmn *hdr = HDR_CMN(p);
struct hdr_mac *mac_ = HDR_MAC(p);
struct hdr_mac802_16 *mac_16 = HDR_MAC802_16(p);
struct UL_MAP* ulmap=HDR_MAC802_16_UL_MAP(p);
int Symbol_offset=0;
mac_->macDA_ = MAC_BROADCAST;
mac_->macSA_ = creatid;
hdr->txtime() = 0.000001;
hdr->uid() = 0;
hdr->ptype() = PT_ULMAP;
hdr->size() = 10;
hdr->iface() = -2;
hdr->error() = 0;
mac_16->HT =0;
mac_16->EC =1;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -