ns-allinone-2.35/dei80211mr-1.1.4/src/mac-802_11mr.cc
void
Mac802_11mr::tx_resume()
{
	double rTime;
	assert(mhSend_.busy() == 0);
	assert(mhDefer_.busy() == 0);

	if(pktCTRL_) {
		/*
		 *  Need to send a CTS or ACK.
		 */
		mhDefer_.start(phymib_.getSIFS());
	} else if(pktRTS_) {
		if (mhBackoff_.busy() == 0) {
			/* Modifica Federico 9/12/2004 */
			/*rTime = (Random::random() % cw_) * phymib_.getSlotTime();
			mhDefer_.start( phymib_.getDIFS() + rTime);*/
		       
			mhBackoff_.start(cw_, is_idle(), phymib_.getDIFS());
			/*
			Fine modifica Federico 9/12/2004
			*/
		}
	} else if(pktTx_) {
		if (mhBackoff_.busy() == 0) {
			hdr_cmn *ch = HDR_CMN(pktTx_);
			struct hdr_mac802_11 *mh = HDR_MAC802_11(pktTx_);
			
			if ((u_int32_t) ch->size() < macmib_.getRTSThreshold()
			    || (u_int32_t) ETHER_ADDR(mh->dh_ra) == MAC_BROADCAST) {
				/* Modifica Federico 9/12/2004 */
				/*rTime = (Random::random() % cw_)
					* phymib_.getSlotTime();
				mhDefer_.start(phymib_.getDIFS() + rTime);*/
			       
			       
				mhBackoff_.start(cw_, is_idle(), phymib_.getDIFS());
			       
			       //Fine modifica Federico 9/12/2004
                        } else {
				mhDefer_.start(phymib_.getSIFS());
                        }
		}
	} else if(callback_) {
		Handler *h = callback_;
		callback_ = 0;
		h->handle((Event*) 0);
	}
	setTxState(MAC_IDLE);
}
// void
// Mac802_11mr::collision(Packet *p)
// {
// 	switch(rx_state_) {
// 	case MAC_RECV:
// 		setRxState(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);
// 	}
// }


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.


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 .
void
Mac802_11mr::tx_resume()
{
	double rTime;
	assert(mhSend_.busy() == 0);
	assert(mhDefer_.busy() == 0);
	if(pktCTRL_) {
		mhDefer_.start(phymib_.getSIFS());
	} else if(pktRTS_) {
		if (mhBackoff_.busy() == 0) {
			mhBackoff_.start(cw_, is_idle(), phymib_.getDIFS());
		}
	} else if(pktTx_) {
		if (mhBackoff_.busy() == 0) {
			hdr_cmn *ch = HDR_CMN(pktTx_);
			struct hdr_mac802_11 *mh = HDR_MAC802_11(pktTx_);
			if ((u_int32_t) ch->size() < macmib_.getRTSThreshold()
			    || (u_int32_t) ETHER_ADDR(mh->dh_ra) == MAC_BROADCAST) {
				mhBackoff_.start(cw_, is_idle(), phymib_.getDIFS());
                        } else {
				mhDefer_.start(phymib_.getSIFS());
                        }
		}
	} else if(callback_) {
		Handler *h = callback_;
		callback_ = 0;
		h->handle((Event*) 0);
	}
	setTxState(MAC_IDLE);
}
void Mac802_11mr :: tx_resume ( ) { double rTime ; assert ( mhSend_ . busy ( ) == 0 ) ; assert ( mhDefer_ . busy ( ) == 0 ) ; if ( pktCTRL_ ) { mhDefer_ . start ( phymib_ . getSIFS ( ) ) ; } else if ( pktRTS_ ) { if ( mhBackoff_ . busy ( ) == 0 ) { mhBackoff_ . start ( cw_ , is_idle ( ) , phymib_ . getDIFS ( ) ) ; } } else if ( pktTx_ ) { if ( mhBackoff_ . busy ( ) == 0 ) { hdr_cmn * ch = HDR_CMN ( pktTx_ ) ; struct hdr_mac802_11 * mh = HDR_MAC802_11 ( pktTx_ ) ; if ( ( u_int32_t ) ch -> size ( ) < macmib_ . getRTSThreshold ( ) || ( u_int32_t ) ETHER_ADDR ( mh -> dh_ra ) == MAC_BROADCAST ) { mhBackoff_ . start ( cw_ , is_idle ( ) , phymib_ . getDIFS ( ) ) ; } else { mhDefer_ . start ( phymib_ . getSIFS ( ) ) ; } } } else if ( callback_ ) { Handler * h = callback_ ; callback_ = 0 ; h -> handle ( ( Event * ) 0 ) ; } setTxState ( MAC_IDLE ) ; }
void
Mac802_11mr::collision(Packet *p)
{
switch(rx_state_) {
case MAC_RECV:
setRxState(MAC_COLL);
 fall through
case MAC_COLL:
assert(pktRx_);
assert(mhRecv_.busy());
void Mac802_11mr :: collision ( Packet * p ) { switch ( rx_state_ ) { case MAC_RECV : setRxState ( MAC_COLL ) ; fall through case MAC_COLL : assert ( pktRx_ ) ; assert ( mhRecv_ . busy () ) ;
/*
		 *  Need to send a CTS or ACK.
		 */ /* Modifica Federico 9/12/2004 */ /*rTime = (Random::random() % cw_) * phymib_.getSlotTime();
			mhDefer_.start( phymib_.getDIFS() + rTime);*/ /*
			Fine modifica Federico 9/12/2004
			*/ /* Modifica Federico 9/12/2004 */ /*rTime = (Random::random() % cw_)
					* phymib_.getSlotTime();
				mhDefer_.start(phymib_.getDIFS() + rTime);*/ //Fine modifica Federico 9/12/2004