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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

method is now obsolete; its usage is tricky <strong>and</strong> its misuse can be very difficult to detect.<strong>The</strong> st<strong>at</strong>ic object class_rtphdr of class RTPHeaderClass is used to provide linkage to OTcl when the RTP headeris enabled <strong>at</strong> configur<strong>at</strong>ion time. When the simul<strong>at</strong>or executes, this st<strong>at</strong>ic object calls the PacketHeaderClass co<strong>ns</strong>tructorwith arguments "PacketHeader/RTP" <strong>and</strong> sizeof(hdr_rtp). This causes the size of the RTP header to be stored <strong>and</strong>made available to the packet header manager <strong>at</strong> configur<strong>at</strong>ion time (see below, Section 12.2.4). Notice th<strong>at</strong> bind_offset()MUST be called in the co<strong>ns</strong>tructor of this class, so th<strong>at</strong> the packet header manager knows where to store the offset for thisparticular packet header.<strong>The</strong> sample member function sendpkt() method of RTPAgent cre<strong>at</strong>es a new packet to send by calling allocpkt(),which h<strong>and</strong>les assignment of all the network-layer packet header fields (in this case, IP). Headers other than IP are h<strong>and</strong>ledsepar<strong>at</strong>ely. In this case, the agent uses the RTPHeader defined above. <strong>The</strong> Packet::access(void) member functionretur<strong>ns</strong> the address of the first byte in a buffer used to hold header inform<strong>at</strong>ion (see below). Its return value is cast as a pointerto the header of interest, after which member functio<strong>ns</strong> of the RTPHeader object are used to access individual fields.12.1.1 Adding a New Packet Header TypeAssuming we wish to cre<strong>at</strong>e a new header called newhdr the following steps are performed:1. cre<strong>at</strong>e a new structure defining the raw fields (called hdr_newhdr), define offset_ <strong>and</strong> access methods.2. define member functio<strong>ns</strong> for needed fields.3. cre<strong>at</strong>e a st<strong>at</strong>ic class to perform OTcl linkage (defines PacketHeader/Newhdr), do bind_offset() in its co<strong>ns</strong>tructor.4. edit ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-packet.tcl to enable new packet form<strong>at</strong> (see 12.2.2, 12.2.4).This is the recommended way to add your packet headers. If you do not follow this method, your simul<strong>at</strong>ion may still work,but it may behave in a unpredictable way when more protocols are added into your simul<strong>at</strong>ion. <strong>The</strong> reason is th<strong>at</strong> the BOB(Bag of Bits, Section 12.2.1) in <strong>ns</strong>packet is a large sparse space, assigning one wrong packet header offset may not triggerfailure immedi<strong>at</strong>ely.12.1.2 Selectively Including Packet Headers in Your Simul<strong>at</strong>ionBy default, <strong>ns</strong> includes ALL packet headers of ALL protocols in <strong>ns</strong> in EVERY packet in your simul<strong>at</strong>ion. This is a LOT ofoverhead, <strong>and</strong> will increase as more protocols are added into <strong>ns</strong>. For “packet-inte<strong>ns</strong>ive” simul<strong>at</strong>io<strong>ns</strong>, this could be a hugeoverhead. For i<strong>ns</strong>tance, as of now (Aug 30, 2000), the size of packet headers of all protocols in <strong>ns</strong> is about 1.9KB; however,if you turn on only the common header, the IP header <strong>and</strong> the TCP header, they add up to about 100 bytes. If you are doinglarge-scale web traffic simul<strong>at</strong>ion with many big f<strong>at</strong> pipes, reducing unused packet headers can lead to major memory saving.To include only the packet headers th<strong>at</strong> are of interest to you in your specific simul<strong>at</strong>ion, follow this p<strong>at</strong>tern (e.g., you want toremove AODV <strong>and</strong> ARP headers from your simul<strong>at</strong>ion):remove-packet-header AODV ARP......set <strong>ns</strong> [new Simul<strong>at</strong>or]Notice th<strong>at</strong> remove-packet-header MUST go before the simul<strong>at</strong>or is cre<strong>at</strong>ed. All packet header names are in the formsof PacketHeader/[hdr]. You only need to supply the [hdr] part, not the prefix. To find the names of packet headers,you may either look them up in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-packet.tcl, or run the following simple comm<strong>and</strong>s in <strong>ns</strong>:118

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

Saved successfully!

Ooh no, something went wrong!