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.

Chapter 12Packet Headers <strong>and</strong> Form<strong>at</strong>s<strong>The</strong> procedures <strong>and</strong> functio<strong>ns</strong> described in this chapter can be found in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-lib.tcl, ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-packet.tcl, <strong>and</strong>~<strong>ns</strong>/packet.{cc, h}.Objects in the class Packet are the fundamental unit of exchange between objects in the simul<strong>at</strong>ion. <strong>The</strong> class Packetprovides enough inform<strong>at</strong>ion to link a packet on to a list (i.e., in a PacketQueue or on a free list of packets), refer to a buffercontaining packet headers th<strong>at</strong> are defined on a per-protocol basis, <strong>and</strong> to refer to a buffer of packet d<strong>at</strong>a. New protocols maydefine their own packet headers or may extend existing headers with additional fields.New packet headers are introduced into the simul<strong>at</strong>or by defining a C++ structure with the needed fields, defining a st<strong>at</strong>icclass to provide OTcl linkage, <strong>and</strong> then modifying some of the simul<strong>at</strong>or initializ<strong>at</strong>ion code to assign a byte offset in eachpacket where the new header is to be loc<strong>at</strong>ed rel<strong>at</strong>ive to others.When the simul<strong>at</strong>or is initialized through OTcl, a user may choose to enable only a subset of the compiled-in packet form<strong>at</strong>s,resulting in a modest savings of memory during the execution of the simul<strong>at</strong>ion. Presently, most configured-in packet form<strong>at</strong>sare enabled. <strong>The</strong> management of which packet form<strong>at</strong>s are currently enabled in a simul<strong>at</strong>ion is h<strong>and</strong>led by a special packetheader manager object described below. This object supports an OTcl method used to specify which packet headers will beused in a simul<strong>at</strong>ion. If an object in the simul<strong>at</strong>or makes use of a field in a header which has not been enabled, a run-timef<strong>at</strong>al program abort occurs.12.1 A Protocol-Specific Packet HeaderProtocol developers will often wish to provide a specific header type to be used in packets. Doing so allows a new protocolimplement<strong>at</strong>ion to avoid overloading already-existing header fields. We co<strong>ns</strong>ider a simplified version of RTP as an example.<strong>The</strong> RTP header will require a sequence number fields <strong>and</strong> a source identifier field. <strong>The</strong> following classes cre<strong>at</strong>e the neededheader (see ~<strong>ns</strong>/rtp.h <strong>and</strong> ~<strong>ns</strong>/rtp.cc):From rtp.h:/* rtp packet. For now, just have srcid + seqno. */struct hdr_rtp {u_int32_t srcid_;int seqno_;/* per-field member functio<strong>ns</strong> */u_int32_t& srcid() { return (srcid_); }116

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

Saved successfully!

Ooh no, something went wrong!