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.

foreach cl [PacketHeader info subclass] {puts $cl}To include only a specific set of headers in your simul<strong>at</strong>ion, e.g., IP <strong>and</strong> TCP, follow this p<strong>at</strong>tern:remove-all-packet-headersadd-packet-header IP TCP......set <strong>ns</strong> [new Simul<strong>at</strong>or]IMPORTANT: You MUST never remove common header from your simul<strong>at</strong>ion. As you can see in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-packet.tcl,this is enforced by these header manipul<strong>at</strong>ion procs.Notice th<strong>at</strong> by default, all packet headers are included.12.2 Packet Classes<strong>The</strong>re are four C++ classes relevant to the h<strong>and</strong>ling of packets <strong>and</strong> packet headers in general: Packet, p_info PacketHeader,<strong>and</strong> PacketHeaderManager. <strong>The</strong> class Packet defines the type for all packets in the simul<strong>at</strong>ion; it is a subclass ofEvent so th<strong>at</strong> packets may be scheduled (e.g. for l<strong>at</strong>er arrival <strong>at</strong> some queue). <strong>The</strong> class packet_info holds all textrepresent<strong>at</strong>io<strong>ns</strong> for packet names. <strong>The</strong> class PacketHeader provides a base class for any packet header configured intothe simul<strong>at</strong>ion. It essentially provides enough internal st<strong>at</strong>e to loc<strong>at</strong>e any particular packet header in the collection of packetheaders present in any given packet. <strong>The</strong> class PacketHeaderManager defines a class used to collect <strong>and</strong> managecurrently-configured headers. It is invoked by a method available to OTcl <strong>at</strong> simul<strong>at</strong>ion configur<strong>at</strong>ion time to enable somesubset of the compiled-in packet headers.12.2.1 <strong>The</strong> Packet Class<strong>The</strong> class Packet defines the structure of a packet <strong>and</strong> provides member functio<strong>ns</strong> to h<strong>and</strong>le a free list for objects of this type.It is illustr<strong>at</strong>ed in Figure 12.1 <strong>and</strong> defined as follows in packet.h:class Packet : public Event {priv<strong>at</strong>e:friend class PacketQueue;u_char* bits_;u_char* d<strong>at</strong>a_; /* variable size buffer for ’d<strong>at</strong>a’ */u_int d<strong>at</strong>alen_; /* length of variable size buffer */protected:st<strong>at</strong>ic Packet* free_;public:Packet* next_; /* for queues <strong>and</strong> the free list */st<strong>at</strong>ic int hdrlen_;Packet() : bits_(0), d<strong>at</strong>alen_(0), next_(0) {}u_char* co<strong>ns</strong>t bits() { return (bits_); }Packet* copy() co<strong>ns</strong>t;st<strong>at</strong>ic Packet* alloc();119

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

Saved successfully!

Ooh no, something went wrong!