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 ...
foreach cl [PacketHeader info subclass] {puts $cl}To include only a specific set of headers in your simulation, e.g., IP and TCP, follow this pattern:remove-all-packet-headersadd-packet-header IP TCP......set ns [new Simulator]IMPORTANT: You MUST never remove common header from your simulation. As you can see in ~ns/tcl/lib/ns-packet.tcl,this is enforced by these header manipulation procs.Notice that by default, all packet headers are included.12.2 Packet ClassesThere are four C++ classes relevant to the handling of packets and packet headers in general: Packet, p_info PacketHeader,and PacketHeaderManager. The class Packet defines the type for all packets in the simulation; it is a subclass ofEvent so that packets may be scheduled (e.g. for later arrival at some queue). The class packet_info holds all textrepresentations for packet names. The class PacketHeader provides a base class for any packet header configured intothe simulation. It essentially provides enough internal state to locate any particular packet header in the collection of packetheaders present in any given packet. The class PacketHeaderManager defines a class used to collect and managecurrently-configured headers. It is invoked by a method available to OTcl at simulation configuration time to enable somesubset of the compiled-in packet headers.12.2.1 The Packet ClassThe class Packet defines the structure of a packet and provides member functions to handle a free list for objects of this type.It is illustrated in Figure 12.1 and defined as follows in packet.h:class Packet : public Event {private:friend class PacketQueue;u_char* bits_;u_char* data_; /* variable size buffer for ’data’ */u_int datalen_; /* length of variable size buffer */protected:static Packet* free_;public:Packet* next_; /* for queues and the free list */static int hdrlen_;Packet() : bits_(0), datalen_(0), next_(0) {}u_char* const bits() { return (bits_); }Packet* copy() const;static Packet* alloc();119
Packethdrsize_next_bits()points to next packet in eitherfree list or in a PacketQueueaccessdata()packet datasize determinedat compile timeip header bodySize Determinedat Simulator ConfigTime, stored in hdrsize_size determinedat compile timesize determinedat compile timesize determinedat compile timetcp header bodyrtp header bodytrace header bodyFigure 12.1: A Packet Object};static Packet* alloc(int);inline void allocdata(int);static void free(Packet*);inline u_char* access(int off) {if (off < 0)abort();return (&bits_[off]);}inline u_char* accessdata() { return data_; }This class holds a pointer to a generic array of unsigned characters (commonly called the “bag of bits” or BOB for short) wherepacket header fields are stored. It also holds a pointer to packet “data” (which is often not used in simulations). The bits_variable contains the address of the first byte of the BOB. Effectively BOB is (currently implemented as) a concatenation ofall the structures defined for each packet header (by convention, the structures with names beginning hdr_〈something〉)that have been configured in. BOB generally remains a fixed size throughout a simulation, and the size is recorded in thePacket::hdrlen_ member variable. This size is updated during simulator configuration by OTcl 1 .The other methods of the class Packet are for creating new packets and storing old (unused) ones on a private free list. Suchallocation and deallocation is performed by the following code (in ~ns/packet.h):inline Packet* Packet::alloc(){Packet* p = free_;if (p != 0)free_ = p->next_;1 It is not intended to be updated after configuration time. Doing so should be possible, but is currently untested.120
- Page 69 and 70: $ns_ link-lossmodel This function
- Page 71 and 72: Chapter 7Queue Management and Packe
- Page 73 and 74: }}}void Queue::resume(){Packet* p =
- Page 75 and 76: 7.3 Different types of Queue object
- Page 77 and 78: maxidle_ is the maximum amount of t
- Page 79 and 80: dst_ The destination address of pac
- Page 81 and 82: 7.5.2 ConfigurationRunning a JoBS s
- 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: method is now obsolete; its usage i
- 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 and 134: Higher LayersNode 1Node 2. . .Node
- Page 135 and 136: };void recv(Packet* p, Handler*);vi
- 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
Packethdrsize_next_bits()points to next packet in eitherfree list or in a PacketQueueaccessd<strong>at</strong>a()packet d<strong>at</strong>asize determined<strong>at</strong> compile timeip header bodySize Determined<strong>at</strong> Simul<strong>at</strong>or ConfigTime, stored in hdrsize_size determined<strong>at</strong> compile timesize determined<strong>at</strong> compile timesize determined<strong>at</strong> compile timetcp header bodyrtp header bodytrace header bodyFigure 12.1: A Packet Object};st<strong>at</strong>ic Packet* alloc(int);inline void allocd<strong>at</strong>a(int);st<strong>at</strong>ic void free(Packet*);inline u_char* access(int off) {if (off < 0)abort();return (&bits_[off]);}inline u_char* accessd<strong>at</strong>a() { return d<strong>at</strong>a_; }This class holds a pointer to a generic array of u<strong>ns</strong>igned characters (commonly called the “bag of bits” or BOB for short) wherepacket header fields are stored. It also holds a pointer to packet “d<strong>at</strong>a” (which is often not used in simul<strong>at</strong>io<strong>ns</strong>). <strong>The</strong> bits_variable contai<strong>ns</strong> the address of the first byte of the BOB. Effectively BOB is (currently implemented as) a conc<strong>at</strong>en<strong>at</strong>ion ofall the structures defined for each packet header (by convention, the structures with names beginning hdr_〈something〉)th<strong>at</strong> have been configured in. BOB generally remai<strong>ns</strong> a fixed size throughout a simul<strong>at</strong>ion, <strong>and</strong> the size is recorded in thePacket::hdrlen_ member variable. This size is upd<strong>at</strong>ed during simul<strong>at</strong>or configur<strong>at</strong>ion by OTcl 1 .<strong>The</strong> other methods of the class Packet are for cre<strong>at</strong>ing new packets <strong>and</strong> storing old (unused) ones on a priv<strong>at</strong>e free list. Suchalloc<strong>at</strong>ion <strong>and</strong> dealloc<strong>at</strong>ion is performed by the following code (in ~<strong>ns</strong>/packet.h):inline Packet* Packet::alloc(){Packet* p = free_;if (p != 0)free_ = p->next_;1 It is not intended to be upd<strong>at</strong>ed after configur<strong>at</strong>ion time. Doing so should be possible, but is currently untested.120