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.

}incr hdrlen_ $incrreturn $baseFrom packet.cc:/* manages active packet header types */class PacketHeaderManager : public TclObject {public:PacketHeaderManager() {bind("hdrlen_", &Packet::hdrlen_);}};<strong>The</strong> code in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-packet.tcl is executed when the simul<strong>at</strong>or initializes. Thus, the foreach st<strong>at</strong>ement is executedbefore the simul<strong>at</strong>ion begi<strong>ns</strong>, <strong>and</strong> initializes the OTcl class array tab_ to contain the mapping between class the name <strong>and</strong>the names of the currently active packet header classes. As discussed above (12.1), packet headers should be accessed usinghdr_〈hdrname〉::access().<strong>The</strong> cre<strong>at</strong>e_packetform<strong>at</strong>{} i<strong>ns</strong>tance procedure is part of the basic Simul<strong>at</strong>or class <strong>and</strong> is called one time during simul<strong>at</strong>orconfigur<strong>at</strong>ion. It first cre<strong>at</strong>es a single PacketHeaderManager object. <strong>The</strong> C++ co<strong>ns</strong>tructor links the OTcl i<strong>ns</strong>tancevariable hdrlen_ (of class PacketHeaderManager) to the C++ variable Packet::hdrlen_ (a st<strong>at</strong>ic member of thePacket class). This has the effect of setting Packet::hdrlen_ to zero. Note th<strong>at</strong> binding across class types in thisfashion is unusual.After cre<strong>at</strong>ing the packet manager, the foreach loop enables each of the packet headers of interest. This loop iter<strong>at</strong>esthrough the list of defined packet headers of the form (h i , o i ) where h i is the name of the ith header <strong>and</strong> o i is the name of thevariable containing the loc<strong>at</strong>ion of the h i header in BOB. <strong>The</strong> placement of headers is performed by the allochdr i<strong>ns</strong>tprocof the PacketHeaderManager OTcl class. <strong>The</strong> procedure keeps a running variable hdrlen_ with the current length ofBOB as new packet headers are enabled. It also arranges for 8-byte alignment for any newly-enabled packet header. Thisis needed to e<strong>ns</strong>ure th<strong>at</strong> when double-world length quantities are used in packet headers on machines where double-wordalignment is required, access faults are not produced. 3 .12.3 Comm<strong>and</strong>s <strong>at</strong> a glanceFollowing is a list of packet-header rel<strong>at</strong>ed procedures:Simul<strong>at</strong>or::cre<strong>at</strong>e_packetform<strong>at</strong>This is an internal simul<strong>at</strong>or procedure <strong>and</strong> is called once during the simul<strong>at</strong>or configur<strong>at</strong>ion to setup apacketHeaderManager object.PacketHeaderManager::allochdrThis is another internal procedure of Class PacketHeaderManager th<strong>at</strong> keeps track of a variable called hdrlen_ as newpacket-headers are enabled. It also allows 8-byte allignment for any newly-enabled pkt header.add-packet-header takes a list of arguments, each of which is a packet header name (without PacketHeader/prefix). This global proc will tell simul<strong>at</strong>or to include the specified packet header(s) in your simul<strong>at</strong>ion.3 In some processer architectures, including the Sparc <strong>and</strong> HP-PA, double-word access must be performed on a double-word boundary (i.e. addressesending in 0 mod 8). Attempting to perform unaligned accesses result in an abnormal program termin<strong>at</strong>ion.124

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

Saved successfully!

Ooh no, something went wrong!