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 ...

nmlab.korea.ac.kr
from nmlab.korea.ac.kr More from this publisher
12.07.2015 Views

implemented in a single Mac object. For sending, the Mac object must follow a certain medium access protocol beforetransmitting the packet on the channel. For receiving, the MAC layer is responsible for delivering the packet to the link layer.Above the MAC layer, the link layer can potentially have many functionalities such as queuing and link-level retransmission.The need of having a wide variety of link-level schemes leads to the division of functionality into two components: Queueand LL (link-layer). The Queue object, simulating the interface queue, belongs to the same Queue class that is describedin Chapter 7. The LL object implements a particular data link protocol, such as ARQ. By combining both the sending andreceiving functionalities into one module, the LL object can also support other mechanisms such as piggybacking.14.3 Channel ClassThe Channel class simulates the actual transmission of the packet at the physical layer. The basic Channel implementsa shared medium with support for contention mechanisms. It allows the MAC to carry out carrier sense, contention, andcollision detection. If more than one transmissions overlaps in time, a channel raises the collision flag. By checking this flag,the MAC object can implement collision detection and handling.Since the transmission time is a function of the number of bits in the packet and the modulation speed of each individualinterface (MAC), the Channel object only sets its busy signal for the duration requested by the MAC object. It alsoschedules the packets to be delivered to the destination MAC objects after the transmission time plus the propagation delay.14.3.1 Channel StateThe C++ class Channel includes enough internal state to schedule packet delivery and detect collisions. It exports thefollowing OTcl configuration parameter:delay_propagation delay on the channel14.3.2 Example: Channel and classifier of the physical layerset channel_ [new Channel]$channel_ set delay_ 4us# propagation delayset mcl_ [new Classifier/Mac]$channel_ target $mcl_$mcl_ install $mac_DA $recv_iface. . .14.3.3 Channel Class in C++In C++, the class Channel extends the Connector object with several new methods to support a variety of MAC protocols.The class is defined as follow in ~ns/channel.h:class Channel : public Connector {public:Channel();133

};void recv(Packet* p, Handler*);virtual int send(Packet* p, double txtime);virtual void contention(Packet*, Handler*);int hold(double txtime);virtual int collision() { return numtx_ > 1; }virtual double txstop() { return txstop_; }. . .The important methods of the class Channel are:• txstop() method returns the time when the channel will become idle, which can be used by the MAC to implementcarrier sense.• contention() method allows the MAC to contend for the channel before sending a packet. The channel then usethis packet to signal the corresponding Mac object at the end of each contention period.• collision() method indicates whether a collision occurs during the contention period. When the Channel signalthe end of the contention period, the MAC can use the collision() method to detect collision.• send() method allows the MAC object to transmit a packet on the channel for a specified duration of time.• hold() method allows the MAC object to hold the channel for a specified duration of time without actually transmittingany packets. This is useful in simulating the jamming mechanism of some MAC protocols.14.4 MacClassifier ClassThe MacClassifier class extends the Classifier class to implement a simple broadcasting mechanism. It modifiesthe recv() method in the following way: since the replication of a packet is expensive, normally a unicast packet willbe classified by the MAC destination address macDA_ and delivered directly to the MAC object with such an address.However, if the destination object cannot be found or if the MAC destination address is explicitly set to the broadcast addressBCAST_ADDR, the packet will be replicated and sent to all MACs on the lan excluding the one that is the source of the packet.Finally, by setting the bound variable MacClassifier::bcast_ to a non–zero value, will cause MacClassifieralways to replicate packets.class MacClassifier : public Classifier {public:void recv(Packet*, Handler*);};void MacClassifier::recv(Packet* p, Handler*){Mac* mac;hdr_mac* mh = hdr_mac::access(p);}if (bcast_ || mh->macDA() == BCAST_ADDR || (mac = (Mac *)find(p)) == 0) {// Replicate packets to all slots (broadcast). . .return;}mac->recv(p);134

};void recv(Packet* p, H<strong>and</strong>ler*);virtual int send(Packet* p, double txtime);virtual void contention(Packet*, H<strong>and</strong>ler*);int hold(double txtime);virtual int collision() { return numtx_ > 1; }virtual double txstop() { return txstop_; }. . .<strong>The</strong> important methods of the class Channel are:• txstop() method retur<strong>ns</strong> the time when the channel will become idle, which can be used by the MAC to implementcarrier se<strong>ns</strong>e.• contention() method allows the MAC to contend for the channel before sending a packet. <strong>The</strong> channel then usethis packet to signal the corresponding Mac object <strong>at</strong> the end of each contention period.• collision() method indic<strong>at</strong>es whether a collision occurs during the contention period. When the Channel signalthe end of the contention period, the MAC can use the collision() method to detect collision.• send() method allows the MAC object to tra<strong>ns</strong>mit a packet on the channel for a specified dur<strong>at</strong>ion of time.• hold() method allows the MAC object to hold the channel for a specified dur<strong>at</strong>ion of time without actually tra<strong>ns</strong>mittingany packets. This is useful in simul<strong>at</strong>ing the jamming mechanism of some MAC protocols.14.4 MacClassifier Class<strong>The</strong> MacClassifier class extends the Classifier class to implement a simple broadcasting mechanism. It modifiesthe recv() method in the following way: since the replic<strong>at</strong>ion of a packet is expe<strong>ns</strong>ive, normally a unicast packet willbe classified by the MAC destin<strong>at</strong>ion address macDA_ <strong>and</strong> delivered directly to the MAC object with such an address.However, if the destin<strong>at</strong>ion object cannot be found or if the MAC destin<strong>at</strong>ion address is explicitly set to the broadcast addressBCAST_ADDR, the packet will be replic<strong>at</strong>ed <strong>and</strong> sent to all MACs on the lan excluding the one th<strong>at</strong> is the source of the packet.Finally, by setting the bound variable MacClassifier::bcast_ to a non–zero value, will cause MacClassifieralways to replic<strong>at</strong>e packets.class MacClassifier : public Classifier {public:void recv(Packet*, H<strong>and</strong>ler*);};void MacClassifier::recv(Packet* p, H<strong>and</strong>ler*){Mac* mac;hdr_mac* mh = hdr_mac::access(p);}if (bcast_ || mh->macDA() == BCAST_ADDR || (mac = (Mac *)find(p)) == 0) {// Replic<strong>at</strong>e packets to all slots (broadcast). . .return;}mac->recv(p);134

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

Saved successfully!

Ooh no, something went wrong!