📄 mac-802_16-bs.cc
字号:
#ifdef TRACE_BS printf("BS:HandleConcat(%lf): Passing pkt UP \n", Scheduler::instance().clock());#endif#ifdef PACKET_TRACE //------------------------------------------------------------------ //If packet tracing....need to do this to trace all the IP packets //$A10 packetTrace(q,1);#endif //------------------------------------------------------------------ RecvFrame(q,1); } return;}/*****************************************************************************Send packet down to the physical layer...only packets passed by upper layers will be sent by this function..No Management messages..*****************************************************************************//*! Send packet down to the physical layer...only packets passed by upper layers will be sent by this function..No Management messages..*/void Mac802_16BS::sendDown(Packet* p) { int cindex, findex; struct hdr_cmn* ch = HDR_CMN(p); struct hdr_mac802_16* dh = HDR_MAC802_16(p); struct hdr_mac* mh = HDR_MAC(p); #ifdef TRACE_BS //---------------------------------------------------------------- printf("BS:sendDown: Received a packet (size:%d) from upper layer at %lf\n", ch->size(), Scheduler::instance().clock());#endif //--------------------------------------------------------------------------- /* Lets try this */ if(callback_) { Handler *h = callback_; callback_ = 0; h->handle((Event*) 0); } total_num_appbytesDS += ch->size(); /* Make 802_16 & ethernet header */ /* Ethernet header has to be properly updated as BS node is passing the data to the end-host */ mh->set(MF_DATA,index_); /* To set the MAC src-addr and type */ ch->size() += ETHER_HDR_LEN; dh->dshdr_.fc_type = 0; dh->dshdr_.fc_parm = 0; dh->dshdr_.ehdr_on = 0; dh->dshdr_.mac_param = 0; dh->dshdr_.len = ch->size(); cindex = classify(p, DOWNSTREAM,&findex); //$A19 // If it is not a broadcast //if (mh->macDA() != -1){ #ifdef TRACE_BS //--------------------------------------------------------------------- printf("BS:sendDown: Received a packet (size:%d) from upper layer at %lf\n", ch->size(),Scheduler::instance().clock()); dump_pkt(p); printf(" Packet classified on flow-id = %d\n", SSRecord[cindex].d_rec[findex].flow_id);#endif //-------------------------------------------------------------------------------- //printf("2...\n"); ApplyPhs(p,cindex,findex); /* Send the packet */ /* Apply rate-control */ /* SendFrame will be called from rate-control */ SSRecord[cindex].d_rec[findex].util_total_bytes_DS += ch->size(); SSRecord[cindex].d_rec[findex].util_total_pkts_DS ++; //#ifdef RATE_CONTROL//------------------------------------------------- if (SSRecord[cindex].d_rec[findex].ratecontrol) /* Rate-control on*/ { RateControl(p,cindex,findex,DATA_PKT); return; } //#endif//-------------------------------------------------------------- //SendFrame(p,DATA_PKT); HandleOutData(p,cindex,findex); return; //} //if it is a broadcast, it should be a management packet (ex. arp) //SendFrame(p,MGMT_PKT); //insert_pkt(p,cindex,findex); //insert_mgmtpkt(p,cindex,findex); //return; }//#ifdef RATE_CONTROL//------------------------------------------------------//$A20/************************************************************************* Packet enters the BS for respective flow from this function *************************************************************************//*! Packet enters the BS for respective flow from this function */void Mac802_16BS::HandleOutData(Packet* p, int cindex, int findex){ struct hdr_cmn* ch = HDR_CMN(p); struct hdr_mac802_16* dh = HDR_MAC802_16(p); struct hdr_mac* mh = HDR_MAC(p); /* Make 802_16 & ethernet header */ /* Ethernet header has to be properly updated as SS node is also simulating the end-host */ mh->set(MF_DATA,index_); /* To set the MAC src-addr and type */ ch->size() += ETHER_HDR_LEN; dh->dshdr_.fc_type = 0; dh->dshdr_.fc_parm = 0; dh->dshdr_.ehdr_on = 0; dh->dshdr_.mac_param = 0; dh->dshdr_.len = ch->size(); ch->size() += MAC802_16_HDR_LEN; /* Pass the packet to state-machine */ (this->*DOWNswitch[SSRecord[cindex].d_rec[findex].state])(cindex, findex, PKT_ARRIVAL , p); return;}/********************************************************************************The type filed is used to indicate whether packet was picked from IFQ queue or not..If yes, then unlock the IFQ ********************************************************************************//*! The type filed is used to indicate whether packet was picked from IFQ queue or not..If yes, then unlock the IFQ */void Mac802_16BS::RateControl(Packet *p, int cindex, int findex, int type){ struct hdr_cmn *ch = HDR_CMN(p); #ifdef TRACE_BS //------------------------------------------------------- printf("BS: RateControl : cindex = %d findex = %d pkt-length = %d\n", cindex,findex,ch->size());#endif //------------------------------------------------------------------ if (SSRecord[cindex].d_rec[findex].init_) { SSRecord[cindex].d_rec[findex].tokens_ = (double) SSRecord[cindex].d_rec[findex].bucket_; SSRecord[cindex].d_rec[findex].lastupdatetime_ = Scheduler::instance().clock(); SSRecord[cindex].d_rec[findex].init_ = 0;#ifdef TRACE_BS //--------------------------------------------------------------------- printf("Initializing tokens to %lf \n",SSRecord[cindex].d_rec[findex].tokens_);#endif //------------------------------------------------------------------------------- } /* Enque packets if queue already exists, unlock IFQ if type is DATA_PKT */ if (SSRecord[cindex].d_rec[findex].tokenq_->length() > 0) { if (SSRecord[cindex].d_rec[findex].tokenq_->length() < SSRecord[cindex].d_rec[findex].tokenqlen_) { #ifdef TRACE_BS //--------------------------------------------------------- printf("Enqueing pkt, tokens not available\n");#endif //------------------------------------------------------------------- SSRecord[cindex].d_rec[findex].tokenq_->enque(p); } else { drop(p); SSRecord[cindex].d_rec[findex].total_pkts_dropped++; SSRecord[cindex].d_rec[findex].dropped_tokenq++; total_packets_dropped++; dropped_tokenq++; #ifdef TRACE_BS //----------------------------------------------- printf("Packet dropped at Token bucket queue \n");#endif //---------------------------------------------------------- } if (type == DATA_PKT) { if(callback_) { Handler *h = callback_; callback_ = 0; h->handle((Event*) 0); } } return; } //struct hdr_cmn *ch = HDR_CMN(p); double tok; tok = getupdatedtokens(cindex,findex); int pktsize = ch->size()<<3;#ifdef TRACE_BS //------------------------------------------------------ printf("Tokens = %lf Pkt size = %d\n", SSRecord[cindex].d_rec[findex].tokens_,ch->size());#endif //------------------------------------------------------------------ if (SSRecord[cindex].d_rec[findex].tokens_ >=pktsize) { SendFrame(p,type); SSRecord[cindex].d_rec[findex].tokens_-=pktsize; } else { if (SSRecord[cindex].d_rec[findex].tokenqlen_!=0) { #ifdef TRACE_BS //---------------------------------------------------- printf("Enqueing pkts, tokens not available\n");#endif //--------------------------------------------------------------- SSRecord[cindex].d_rec[findex].tokenq_->enque(p); double etime = (pktsize - SSRecord[cindex].d_rec[findex].tokens_)/SSRecord[cindex].d_rec[findex].rate_; if (etime < 0.0) { printf("BS:RateControl: etime is negative,exiting \n"); exit(1); } mhToken_.start((Packet*)&SSRecord[cindex].d_rec[findex].intr, etime); double current_time = Scheduler::instance().clock(); insert_tokenlist(current_time+etime, cindex,findex); } else { drop(p); SSRecord[cindex].d_rec[findex].total_pkts_dropped++; SSRecord[cindex].d_rec[findex].dropped_tokenq++; total_packets_dropped++; dropped_tokenq++; #ifdef TRACE_BS //--------------------------------------------------------------------- printf("Packet dropped at Token bucket queue since Max queue len is Zero \n");#endif //-------------------------------------------------------------------------------- } /* Unlock the IFQ if DATA_PKT */ if (type == DATA_PKT) { if(callback_) { Handler *h = callback_; callback_ = 0; h->handle((Event*) 0); } } } }/**********************************************************************************************************************************************************/double Mac802_16BS::getupdatedtokens(int cindex,int findex){ double now = Scheduler::instance().clock(); SSRecord[cindex].d_rec[findex].tokens_ += (now - SSRecord[cindex].d_rec[findex].lastupdatetime_) * SSRecord[cindex].d_rec[findex].rate_; if (SSRecord[cindex].d_rec[findex].tokens_ > SSRecord[cindex].d_rec[findex].bucket_) SSRecord[cindex].d_rec[findex].tokens_ = SSRecord[cindex].d_rec[findex].bucket_; SSRecord[cindex].d_rec[findex].lastupdatetime_ = Scheduler::instance().clock(); #ifdef TRACE_BS //--------------------------------------------------------- printf("Updating tokens to %lf\n",SSRecord[cindex].d_rec[findex].tokens_);#endif //-------------------------------------------------------------------- return SSRecord[cindex].d_rec[findex].tokens_;}/**********************************************************************************************************************************************************/void Mac802_16BS::BsTokenHandler(Event * e){ tkptr temp; int cindex,findex; temp = TokenList; if (!temp) { printf("BS :Error1 in BsTokenHandler: Exiting\n"); exit(1); } else { TokenList = TokenList->next; } cindex = temp->cindex; findex = temp->findex; free(temp); Packet *p; #ifdef TRACE_BS //------------------------------------------------------ printf("Token timer expired cindex = %d findex = %d \n",cindex,findex);#endif //----------------------------------------------------------------- if (SSRecord[cindex].d_rec[findex].tokenq_->length() == 0) { printf("BS :Error2 in BsTokenHandler: Exiting\n"); exit(1); } p = SSRecord[cindex].d_rec[findex].tokenq_->deque(); struct hdr_cmn *ch = HDR_CMN(p); double tok; tok = getupdatedtokens(cindex,findex); int pktsize = ch->size()<<3; SendFrame(p,MGMT_PKT); SSRecord[cindex].d_rec[findex].tokens_-=pktsize; if (SSRecord[cindex].d_rec[findex].tokenq_->length() > 0) { p = SSRecord[cindex].d_rec[findex].tokenq_->head(); struct hdr_cmn *ch = HDR_CMN(p); int pktsize = ch->size()<<3; double etime = (pktsize - SSRecord[cindex].d_rec[findex].tokens_)/SSRecord[cindex].d_rec[findex].rate_;#ifdef TRACE_BS //-------------------------------------------------------------------- printf("Starting token timer pktsize = %d etime = %lf..\n",ch->size(),etime);#endif //------------------------------------------------------------------------------- if (etime < 0.0) { printf("BS:RateControl: etime is negative,exiting \n"); exit(1); } mhToken_.start((Packet*)&SSRecord[cindex].d_rec[findex].intr, etime); double current_time = Scheduler::instance().clock(); insert_tokenlist(current_time+etime, cindex,findex); } }/**********************************************************************************************************************************************************/void Mac802_16BS::insert_tokenlist(double time, int cindex, int findex){ tkptr temp, prev,node; temp = TokenList; prev =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -