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 ...
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
- Page 83 and 84: mean_pkt_size_ Used to set the expe
- Page 85 and 86: Demarker objects$q trace-file This
- Page 87 and 88: The recv() method overrides the bas
- Page 89 and 90: 9.2 ImplementationThe procedures an
- Page 91 and 92: Average sending rateTSW window leng
- Page 93 and 94: The following command adds an entry
- Page 95 and 96: $qCE configQ 0 1 10 20 0.10Note tha
- Page 97 and 98: Chapter 10AgentsAgents represent en
- Page 99 and 100: CtrMcast/EncapCtrMcast/DecapMessage
- Page 101 and 102: }bind("windowOption_", &wnd_option_
- Page 103 and 104: hdr_flags* nf = (hdr_flags*)npkt->a
- Page 105 and 106: public:ECHO_Timer(ECHO_Agent *a) :
- Page 107 and 108: 10.6.4 Using the agent through OTcl
- Page 109 and 110: State Variables are:dupacks_ Number
- Page 111 and 112: $agent attach-tbf Attaches a token
- Page 113 and 114: (void)Scheduler::instance().schedul
- Page 115 and 116: * outstanding, cancel it.*/void Tcp
- Page 117 and 118: Chapter 12Packet Headers and Format
- Page 119 and 120: method is now obsolete; its usage i
- Page 121 and 122: Packethdrsize_next_bits()points to
- Page 123 and 124: the system’s memory allocator. In
- Page 125 and 126: }incr hdrlen_ $incrreturn $baseFrom
- Page 127 and 128: Chapter 13Error ModelThis chapter d
- Page 129 and 130: SimpleLink::errormodule argsSimulat
- Page 131 and 132: This is a simple example of how to
- Page 133: Higher LayersNode 1Node 2. . .Node
- Page 137 and 138: and the frame type. It then passes
- Page 139 and 140: $ll_ set delay_ $delay$ll_ set band
- Page 141 and 142: 14.10 Commands at a glanceThe follo
- Page 143 and 144: 15.2.1 Default Hierarchical Setting
- Page 145 and 146: Chapter 16Mobile Networking in nsTh
- Page 147 and 148: entry_addrdemuxIP addressdefaulttar
- Page 149 and 150: 16.1.2 Creating Node movementsThe m
- Page 151 and 152: set netif $netif_($t)set mac $mac_(
- Page 153 and 154: the hardware address of a packet’
- Page 155 and 156: destined to itself to the port dmux
- Page 157 and 158: switch(ch->ptype()) {case PT_MAC:br
- Page 159 and 160: 16.1.7 Revised format for wireless
- Page 161 and 162: Packet info at "Application level"
- Page 163 and 164: The main problem facing the wired-c
- Page 165 and 166: target_target_encapsulatorreg_agent
- Page 167 and 168: why: This avoids header clashes bet
- Page 169 and 170: This command is used to create a Go
- Page 171 and 172: Chapter 17Satellite Networking in n
- Page 173 and 174: in counter-rotating planes (where t
- Page 175 and 176: • Position/Sat/Geo A geostationar
- Page 177 and 178: $ns add-isl $ltype $node1 $node2 $b
- Page 179 and 180: $satrouteobject_ compute_routeswher
- Page 181 and 182: This will add an error model to the
- Page 183 and 184: lh_firstnameobj‘‘name’’ is
};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