⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bt-drr.cc

📁 NS2网络仿真软件是目前最为流行的网络仿真模拟软件
💻 CC
📖 第 1 页 / 共 2 页
字号:
		else 			type = BT_DM1;	}	else {		// select appropriate packet type based on MTU		if ((mtu > Payload[15]) || ((mtu <= Payload[15]) && (mtu > Payload[11])))			type = BT_DH5;		else if (mtu <= Payload[11] && mtu > Payload[4])			type = BT_DH3;		else 			type = BT_DH1;	}		int pi = (int)(Payload[type]*8/(rate*SlotTime));	uchar result = updateQuanta(ch, qos->token_rate, type);	if (result) {		qoslm_->packet_type = type;		qoslm_->polling_interval = pi;  	// To be used when QoS is reserved		                                        // in the reverse direcetion as well	}	return result;}/* Does admission control based on slot availability within cycle time. Admissioncontrol can be improved upon*/ucharBT_DRRScheduler::updateQuanta (uchar ch, int token_rate, bt_packet_type type){	double slots;	int quanta; 	if (token_rate == -1) {		slots = 0.5*(cycleTime_/SlotTime - slotsPerCycle_);		quanta_[ch] = (int)(slots*Payload[type]*8)/(1+SlotSize[type]);		slotsPerCycle_ += slots;		numFlows_ ++; 		active_[ch] = 1;		return 1;	}	if (token_rate == 0) 		quanta = (int)(cycleTime_*DefaultRate);	else {		quanta = (int)(cycleTime_*token_rate*1000);	}	slots = (1+SlotSize[type])*(quanta/(Payload[type]*8));	if ((slots+slotsPerCycle_)*SlotTime < cycleTime_) {		slotsPerCycle_ += slots;		numFlows_ ++; 		active_[ch] = 1;		quanta_[ch] = quanta;		return 1;	}	else 		return 0;}	/* Return the next packet to be scheduled */Packet* BT_DRRScheduler::schedule_next(){	Scheduler& s = Scheduler::instance();	Packet* p_sched = 0;	int queue_no = -1;	/* start from the current queue */	for (int i = currQueue_; i < currQueue_ + MaxQueues; i++) {		int j = i%MaxQueues;		/* if a round is over indicate that DC can be increased now*/		if ((j == 0)&& nextround_) {			nextround_ = 0;			for (int i=0; i< MaxQueues; i++) 				incr_[i] = 0;		}		LinkController* lc = (LinkController*)lc_[j];		/* see if the the current register at the link controller 		corresponding the the current queue has any data to send */				int size = lc->pktSize();		/* mark the queue backlogged in the forward direction if 		the queue it has a non-zero packet size */		backlog_fwd_[j] = size ? 1 : 0;		size <<= 3;		/* Find if the flow (forward + reverse) is backlogged */		uchar	backlogged = (backlog_fwd_[j] || backlog_rev_[j]);		if (backlogged) {			/* If the DC hasn't already been incremented this			round, increment it */			if (incr_[j] == 0) {				dc_[j] = MIN(MaxQuanta,dc_[j]+quanta_[j]);				incr_[j] = 1;			}			/* If the packetsize to be transmitted in less than 			DC get the packet from the current register of the 			link controller */			if (size < dc_[j]) {				currQueue_ = queue_no = j;				p_sched = lc->send();				break;			}		} else 			dc_[j] = 0;		nextround_ = 1;	}	if (p_sched) {		hdr_bt* bt = HDR_BT(p_sched);		dc_[queue_no] -= (Payload[bt->type])<<3;				}	else {		if (queue_no < 0) {			/* if the round resulted in no packet being scheduled			find the next active queue */			if (numFlows_) queue_no = nextActive();			else return 0;		}		/* create a poll packet for the next queue with am_addr_ = queue_no+1 */		p_sched = createPOLLpacket(queue_no+1);	}	return p_sched;}// Find the next active queueucharBT_DRRScheduler::nextActive(){	for (int i=0; i<MaxQueues; i++) {		currQueue_ = (currQueue_+1)%MaxQueues;		if (active_[currQueue_])			break;	}	return currQueue_;}// handle a packet going up the stackvoid BT_DRRScheduler::sendUp (Packet* p, Handler* h){	hdr_cmn* ch = HDR_CMN(p);	hdr_bt* bt = HDR_BT(p);	int size = Payload[bt->type];	int index = bt->am_addr -1;	/* if packetsize is non-zero, mark flow as non	backlogged in the reverse direction */	backlog_rev_[index] = (size) ? 1 : 0;	lc_[index]->recv(p,this);}		/* This function not used now, will be required when    'traffic' is sent in the reverse direction as well*/voidBT_DRRScheduler::schedulePoll(int index){	Scheduler& s = Scheduler::instance(); 	s.cancel(pollEvent_[index]);	pollEvent_[index]->num_ = index;	s.schedule (&ph_, pollEvent_[index], maxPollInterval_[index]);}/* create a poll packet */Packet* BT_DRRScheduler::createPOLLpacket (uchar am_addr){	Packet* p = Packet::alloc();	hdr_cmn* ch = HDR_CMN(p);	hdr_bt* bt = HDR_BT(p);	bt->type = BT_POLL;	bt->am_addr = am_addr;	ch->size() = PollSize;	return p;}/* not used in this version */voidBluePollHandler::handle (Event* e){	BluePollEvent* pe = (BluePollEvent*)e;		uchar am_addr = pe->num_ + 1;	Packet* pkt = sched_->createPOLLpacket(am_addr);	sched_->pollQ_->enque(pkt);	delete pe;}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -