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

📄 mac-802_11.cc

📁 TCP westwood code, download
💻 CC
📖 第 1 页 / 共 4 页
字号:
		return 0;						// 0 == FALSE --> NOT IDLE	if(tx_state_ != MAC_IDLE)		return 0;	if(nav_[nav_tc_] > Scheduler::instance().clock())		return 0;	return 1;}voidMac802_11::discard(Packet *p, const char* why){	hdr_mac802_11* mh = HDR_MAC802_11(p);	hdr_cmn *ch = HDR_CMN(p);#if 0	/* old logic 8/8/98 -dam */	/*	 * If received below the RXThreshold, then just free.	 */	if(p->txinfo_.Pr < p->txinfo_.ant.RXThresh) {		Packet::free(p);		//p = 0;		return;	}#endif // 0	/* if the rcvd pkt contains errors, a real MAC layer couldn't	   necessarily read any data from it, so we just toss it now */	if(ch->error() != 0) {		Packet::free(p);		//p = 0;		return;	}	switch(mh->dh_fc.fc_type) {	case MAC_Type_Management:		drop(p, why);		return;	case MAC_Type_Control:		switch(mh->dh_fc.fc_subtype) {		case MAC_Subtype_RTS:			if((u_int32_t)ETHER_ADDR(mh->dh_sa) == \			   (u_int32_t)index_) {				drop(p, why);				return;			}			/* fall through - if necessary */		case MAC_Subtype_CTS:		case MAC_Subtype_ACK:			if((u_int32_t)ETHER_ADDR(mh->dh_da) == \			   (u_int32_t)index_) {				drop(p, why);				return;			}			break;		default:			fprintf(stderr, "invalid MAC Control subtype\n");			exit(1);		}		break;	case MAC_Type_Data:		switch(mh->dh_fc.fc_subtype) {		case MAC_Subtype_QoS_Null:		case MAC_Subtype_QoS_CFPoll:		case MAC_Subtype_Data:			if((u_int32_t)ETHER_ADDR(mh->dh_da) == \			   (u_int32_t)index_ ||			   (u_int32_t)ETHER_ADDR(mh->dh_sa) == \			   (u_int32_t)index_ ||			   (u_int32_t)ETHER_ADDR(mh->dh_da) == MAC_BROADCAST) {				drop(p);				return;			}			break;		default:			fprintf(stderr, "invalid MAC Data subtype\n");			exit(1);		}		break;	default:		fprintf(stderr, "invalid MAC type (%x)\n", mh->dh_fc.fc_type);		trace_pkt(p);		exit(1);	}	Packet::free(p);}voidMac802_11::capture(Packet *p){	/*	 * Update the NAV so that this does not screw	 * up carrier sense.	 */	for(int i=0; i<=7; i++) set_nav(usec(eifs_ + txtime(p)),i);	Packet::free(p);}voidMac802_11::collision(Packet *p){	//printf("Detected collision at node %d...\n",index_);	switch(rx_state_) {	case MAC_RECV:		SET_RX_STATE(MAC_COLL);		/* fall through */	case MAC_COLL:		assert(pktRx_);		assert(mhRecv_.busy());		/*		 *  Since a collision has occurred, figure out		 *  which packet that caused the collision will		 *  "last" the longest.  Make this packet,		 *  pktRx_ and reset the Recv Timer if necessary.		 */		if(txtime(p) > mhRecv_.expire()) {			mhRecv_.stop();			discard(pktRx_, DROP_MAC_COLLISION);			pktRx_ = p;			mhRecv_.start(txtime(pktRx_));		}		else {			discard(p, DROP_MAC_COLLISION);		}		break;	default:		assert(0);	}}voidMac802_11::tx_resume(){	double rTime;	assert(mhSend_.busy() == 0);	//assert(mhDefer_[tc_].busy() == 0);	if(pktCTRL_) {		/*		 *  Need to send a CTS or ACK.		 */		 // My BugFix 		if (mhDefer_[tc_].busy()) {			mhDefer_[tc_].stop();			if (!mhBackoff_[tc_].busy()) mhBackoff_[tc_].start(cw_[tc_],0);		}		mhDefer_[tc_].start(sifs_);	} else if(pktRTS_) {		if(mhBackoff_[tc_].busy() == 0) {			rTime = (Random::random() % cw_[tc_]) * phymib_->SlotTime;			mhDefer_[tc_].start(aifs_[tc_] + rTime);		}	} //@@ FaZ	else if (pktSchElem_) {		//printf("In tx_resume cerco di inviare pktSchElem_ ... \n");		int idle=0;		for(int i=0;i<=7;i++) idle+=(nav_[i]<=Scheduler::instance().clock());		if (idle==8 && rx_state_==MAC_IDLE) {			//printf("Sending Schedule Element at time %2.9f\n",Scheduler::instance().clock()); // polling DELAY DEBUG			if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();			mhDefer_[tc_].start(pifs_);		}		//printf("Fatto!!!\n");	}//@ FaZ	else 	if(pktQoSTx_[tc_]) {		if (btbs_) {					int idle=0;			for(int i=0;i<=7;i++) idle+=(mhBackoff_[i].busy()==0 || (mhBackoff_[i].busy() && mhBackoff_[i].paused()))+(mhDefer_[i].busy()==0);			if (idle==16 && rx_state_==MAC_IDLE) { 				//printf("OK->Defer PIFS tx %2.6f\n",Scheduler::instance().clock()); // BEACON DELAY DEBUG				mhDefer_[tc_].start(pifs_);				btbs_=0;			}		} /*else if (pktQoSPoll_ && (!pktCTRL_)) {			int idle=0;			for(int i=0;i<=7;i++) idle+=(mhBackoff_[i].busy()==0 || (mhBackoff_[i].busy() && mhBackoff_[i].paused()))+(mhDefer_[i].busy()==0);			if (idle==16 && rx_state_==MAC_IDLE) { 				//printf("\tOK->Defer PIFS tx %2.6f\n",Scheduler::instance().clock()); // polling DELAY DEBUG				if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();				mhDefer_[tc_].start(pifs_);				ptbs_=0;			}		}*/		if(mhBackoff_[tc_].busy() == 0) {			hdr_cmn *ch = HDR_CMN(pktQoSTx_[tc_]);			struct hdr_mac802_11 *mh = HDR_MAC802_11(pktQoSTx_[tc_]);			if ((u_int32_t) ch->size() < macmib_->RTSThreshold || (u_int32_t) ETHER_ADDR(mh->dh_da) == MAC_BROADCAST) {				//rTime = (Random::random() % cw_[tc_]) * phymib_->SlotTime;				//mhDefer_[tc_].start(aifs_[tc_] + rTime);				mhBackoff_[tc_].start(cw_[tc_],is_idle(tc_));			} else {				mhDefer_[tc_].start(sifs_);			}		}	} else if(QoScallback_[tc_]) {		Handler *h = QoScallback_[tc_];		QoScallback_[tc_] = 0;		h->handle((Event*) 0);	}		if (btbs_) {				int idle=0;		for(int i=0;i<=7;i++) idle+=(nav_[i]<=Scheduler::instance().clock());		if (idle==8 && rx_state_==MAC_IDLE) {			//printf("OK->Defer PIFS tx %2.6f\n",Scheduler::instance().clock()); // BEACON DELAY DEBUG			if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();			mhDefer_[tc_].start(pifs_);			btbs_=0;		}	} else if (pktQoSPoll_ && (!pktCTRL_)) {				int idle=0;		for(int i=0;i<=7;i++) idle+=(nav_[i]<=Scheduler::instance().clock());		if (idle==8) {			//printf("\tOK->Defer PIFS tx %2.6f\n",Scheduler::instance().clock()); // polling DELAY DEBUG			if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();			mhDefer_[tc_].start(pifs_);			ptbs_=0;		}	} //@@ FaZ/*	else if (pktSchElem_ && (!pktCTRL_)) {				//printf("In tx_resume cerco di inviare pktSchElem_ ... \n");		int idle=0;		for(int i=0;i<=7;i++) idle+=(nav_[i]<=Scheduler::instance().clock());		if (idle==8 && rx_state_==MAC_IDLE) {			//printf("Sending Schedule Element at time %2.9f\n",Scheduler::instance().clock()); // polling DELAY DEBUG			if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();			mhDefer_[tc_].start(pifs_);		}		//printf("Fatto!!!\n");	}//@ FaZ*/	SET_TX_STATE(MAC_IDLE);}voidMac802_11::rx_resume(){	assert(pktRx_ == 0);	assert(mhRecv_.busy() == 0);	if (btbs_) {				int idle=0;		for(int i=0;i<=7;i++) idle+=(nav_[i]<=Scheduler::instance().clock());		if (idle==8 && tx_state_==MAC_IDLE) {			//printf("OK->Defer PIFS rx %2.6f\n",Scheduler::instance().clock()); // BEACON DELAY DEBUG			if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();			mhDefer_[tc_].start(pifs_);			btbs_=0;		}	}	if (pktQoSPoll_ && (!pktCTRL_)) {				int idle=0;		for(int i=0;i<=7;i++) idle+=(nav_[i]<=Scheduler::instance().clock());		if (idle==8 && tx_state_==MAC_IDLE) {			//printf("\tOK->Defer PIFS rx %2.6f\n",Scheduler::instance().clock()); // polling DELAY DEBUG			if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop();			mhDefer_[tc_].start(pifs_);			ptbs_=0;		}	}			SET_RX_STATE(MAC_IDLE);}/* ======================================================================   Timer Handler Routines   ====================================================================== */voidMac802_11::backoffHandler(u_int32_t winner_tc_){//@@ FaZ	EnergyModel *em = netif_->node()->energy_model();		if (em && em->sleep()) {		printf("Node %d is sleeping at %2.9f, exiting backoff...\n",index_,Scheduler::instance().clock());		return;	}//@ FaZ	int highest=8;	for(int i=0; i<=7; i++) { // TC=0 highest priority, .... TC=7 lower priority		// check for virtual collisions		if (mhBackoff_[i].busy() && mhBackoff_[i].expire()==0.0) {			// virtual collision found			//printf(" Node %d: VIRTUAL COLLISION occurred\n",index_);			if (i<=highest && i<winner_tc_) { 				highest=i; 				//printf(" Node %d, TC %d: VIRTUAL COLLISION WINNER\n",index_,i);			}			else { mhBackoff_[i].stop(); inc_cw(i); mhBackoff_[i].start(cw_[i],0); }		}	}	if (highest<winner_tc_) {		inc_cw(winner_tc_);		mhBackoff_[winner_tc_].start(cw_[winner_tc_],0);		return;	}/*//@@ FaZ	int highest=0; //non dovrebbe essere 0 ma -1 (se lo metto si blocca) ... tanto l'AC=0 non viene usata :P	for(int i=7; i>=0; i--) { // TC=7 highest priority, .... TC=0 lower priority		// check for virtual collisions		if (mhBackoff_[i].busy() && mhBackoff_[i].expire()==0.0) {			// virtual collision found			//printf(" Node %d: VIRTUAL COLLISION occurred\n",index_);			if (i>=highest && i>winner_tc_) { 				highest=i; 				//printf(" Node %d, TC %d: VIRTUAL COLLISION WINNER\n",index_,i);			}			else { mhBackoff_[i].stop(); inc_cw(i); mhBackoff_[i].start(cw_[i],0); }		}	}	if (highest>winner_tc_) {		inc_cw(winner_tc_);		mhBackoff_[winner_tc_].start(cw_[winner_tc_],0);		return;	}//@ FaZ*/		//tc_=winner_tc_;	//if (index_==0) printf(" BackoffHandler winner TC: %d\n",tc_);	if(pktCTRL_) {		assert(mhSend_.busy() || mhDefer_[winner_tc_].busy());		return;	}	tc_=winner_tc_;	if(check_pktRTS() == 0)		return;	if(check_pktTx() == 0)		return;}voidMac802_11::deferHandler(u_int32_t winner_tc_){//@@ FaZ	EnergyModel *em = netif_->node()->energy_model();		if (em && em->sleep()) {		//printf("Node %d is sleeping at %2.9f, exiting defer...",index_,Scheduler::instance().clock());		return;	}//@ FaZ	if (check_pktQoSNull() == 0) return;

⌨️ 快捷键说明

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