12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>and</strong> the frame type. It then passes the packet to its send() method, which carries out the medium access protocol. For thebasic Mac object, the send method calls txtime() to compute the tra<strong>ns</strong>mission time, then invokes Channel::send totra<strong>ns</strong>mit the packet. Finally, it schedules itself to resume after the tra<strong>ns</strong>mission time has elapsed.For an incoming packet, the MAC object does its protocol processing <strong>and</strong> passes the packet to the link-layer.14.5.4 CSMA-based MAC<strong>The</strong> class CsmaMac extends the Mac class with new methods th<strong>at</strong> implements carrier se<strong>ns</strong>e <strong>and</strong> backoff mechanisms.<strong>The</strong> CsmaMac::send() method detects when the channel becomes idle using Channel::txtime(). If the channelis busy, the MAC schedules the next carrier se<strong>ns</strong>e <strong>at</strong> the moment the channel tur<strong>ns</strong> idle. Once the channel is idle,the CsmaMac object initi<strong>at</strong>es the contention period with Channel::contention(). At the end of the contention period,the endofContention() method is invoked. At this time, the basic CsmaMac just tra<strong>ns</strong>mits the packet usingChannel::send.class CsmaMac : public Mac {public:CsmaMac();void send(Packet* p);void resume(Packet* p = 0);virtual void endofContention(Packet* p);virtual void backoff(H<strong>and</strong>ler* h, Packet* p, double delay=0);. . .};class CsmaCdMac : public CsmaMac {public:CsmaCdMac();void endofContention(Packet*);};class CsmaCaMac : public CsmaMac {public:CsmaCaMac();virtual void send(Packet*);};<strong>The</strong> CsmaCdMac extends CsmaMac to carry out collision detection procedure of the CSMA/CD (Ethernet) protocol. Whenthe channel signals the end of contention period, the endofContention method checks for collision using the Channel::collision(method. If there is a collision, the MAC invokes its backoff method to schedule the next carrier se<strong>ns</strong>e to retra<strong>ns</strong>mit thepacket.<strong>The</strong> CsmaCaMac extends the send method of CsmaMac to carry out the collision avoidance (CSMA/CA) procedure. I<strong>ns</strong>teadof tra<strong>ns</strong>mitting immedi<strong>at</strong>ely when the channel is idle, the CsmaCaMac object backs off a r<strong>and</strong>om number of slots, thentra<strong>ns</strong>mits if the channel remai<strong>ns</strong> idle until the end of the backoff period.136

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!