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

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

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

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

Saved successfully!

Ooh no, something went wrong!