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

};double& timestamp() { return (ts_); }This structure primarily defines fields used for tracing the flow of packets or measuring other quantities. The time stamp fieldis used to measure queuing delay at switch nodes. The ptype_ field is used to identify the type of packets, which makesreading traces simpler. The uid_ field is used by the scheduler in scheduling packet arrivals. The size_ field is of generaluse and gives the simulated packet’s size in bytes. Note that the actual number of bytes consumed in the simulation may notrelate to the value of this field (i.e., size_ has no relationship to sizeof(struct hdr_cmn) or other ns structures).Rather, it is used most often in computing the time required for a packet to be delivered along a network link. As such itshould be set to the sum of the application data size and IP-, transport-, and application-level headers for the simulated packet.The iface_ field is used by the simulator when performing multicast distribution tree computations. It is a label indicating(typically) on which link a packet was received.12.2.4 The PacketHeaderManager ClassAn object of the class PacketHeaderManager is used to manage the set of currently-active packet header types andassign each of them unique offsets in the BOB. It is defined in both the C++ and OTcl code:From tcl/lib/ns-packet.tcl:PacketHeaderManager set hdrlen_ 0......foreach prot {AODVARPaSRMCommonCtrMcastDiffusion......TORAUMP} {add-packet-header $prot}Simulator instproc create_packetformat {} {PacketHeaderManager instvar tab_set pm [new PacketHeaderManager]foreach cl [PacketHeader info subclass] {if [info exists tab_($cl)] {set off [$pm allochdr $cl]$cl offset $off}}$self set packetManager_ $pm}PacketHeaderManager instproc allochdr cl {set size [$cl set hdrlen_]$self instvar hdrlen_set NS_ALIGN 8 ;# round up to nearest NS_ALIGN bytes, (needed on sparc/solaris)set incr [expr ($size + ($NS_ALIGN-1)) & ~($NS_ALIGN-1)]set base $hdrlen_123

}incr hdrlen_ $incrreturn $baseFrom packet.cc:/* manages active packet header types */class PacketHeaderManager : public TclObject {public:PacketHeaderManager() {bind("hdrlen_", &Packet::hdrlen_);}};The code in ~ns/tcl/lib/ns-packet.tcl is executed when the simulator initializes. Thus, the foreach statement is executedbefore the simulation begins, and initializes the OTcl class array tab_ to contain the mapping between class the name andthe names of the currently active packet header classes. As discussed above (12.1), packet headers should be accessed usinghdr_〈hdrname〉::access().The create_packetformat{} instance procedure is part of the basic Simulator class and is called one time during simulatorconfiguration. It first creates a single PacketHeaderManager object. The C++ constructor links the OTcl instancevariable hdrlen_ (of class PacketHeaderManager) to the C++ variable Packet::hdrlen_ (a static member of thePacket class). This has the effect of setting Packet::hdrlen_ to zero. Note that binding across class types in thisfashion is unusual.After creating the packet manager, the foreach loop enables each of the packet headers of interest. This loop iteratesthrough the list of defined packet headers of the form (h i , o i ) where h i is the name of the ith header and o i is the name of thevariable containing the location of the h i header in BOB. The placement of headers is performed by the allochdr instprocof the PacketHeaderManager OTcl class. The 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 ensure that 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 Commands at a glanceFollowing is a list of packet-header related procedures:Simulator::create_packetformatThis is an internal simulator procedure and is called once during the simulator configuration to setup apacketHeaderManager object.PacketHeaderManager::allochdrThis is another internal procedure of Class PacketHeaderManager that 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 simulator to include the specified packet header(s) in your simulation.3 In some processer architectures, including the Sparc and 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 termination.124

};double& timestamp() { return (ts_); }This structure primarily defines fields used for tracing the flow of packets or measuring other quantities. <strong>The</strong> time stamp fieldis used to measure queuing delay <strong>at</strong> switch nodes. <strong>The</strong> ptype_ field is used to identify the type of packets, which makesreading traces simpler. <strong>The</strong> uid_ field is used by the scheduler in scheduling packet arrivals. <strong>The</strong> size_ field is of generaluse <strong>and</strong> gives the simul<strong>at</strong>ed packet’s size in bytes. Note th<strong>at</strong> the actual number of bytes co<strong>ns</strong>umed in the simul<strong>at</strong>ion may notrel<strong>at</strong>e to the value of this field (i.e., size_ has no rel<strong>at</strong>io<strong>ns</strong>hip to sizeof(struct hdr_cmn) or other <strong>ns</strong> structures).R<strong>at</strong>her, it is used most often in computing the time required for a packet to be delivered along a network link. As such itshould be set to the sum of the applic<strong>at</strong>ion d<strong>at</strong>a size <strong>and</strong> IP-, tra<strong>ns</strong>port-, <strong>and</strong> applic<strong>at</strong>ion-level headers for the simul<strong>at</strong>ed packet.<strong>The</strong> iface_ field is used by the simul<strong>at</strong>or when performing multicast distribution tree comput<strong>at</strong>io<strong>ns</strong>. It is a label indic<strong>at</strong>ing(typically) on which link a packet was received.12.2.4 <strong>The</strong> PacketHeaderManager ClassAn object of the class PacketHeaderManager is used to manage the set of currently-active packet header types <strong>and</strong>assign each of them unique offsets in the BOB. It is defined in both the C++ <strong>and</strong> OTcl code:From tcl/lib/<strong>ns</strong>-packet.tcl:PacketHeaderManager set hdrlen_ 0......foreach prot {AODVARPaSRMCommonCtrMcastDiffusion......TORAUMP} {add-packet-header $prot}Simul<strong>at</strong>or i<strong>ns</strong>tproc cre<strong>at</strong>e_packetform<strong>at</strong> {} {PacketHeaderManager i<strong>ns</strong>tvar tab_set pm [new PacketHeaderManager]foreach cl [PacketHeader info subclass] {if [info exists tab_($cl)] {set off [$pm allochdr $cl]$cl offset $off}}$self set packetManager_ $pm}PacketHeaderManager i<strong>ns</strong>tproc allochdr cl {set size [$cl set hdrlen_]$self i<strong>ns</strong>tvar hdrlen_set NS_ALIGN 8 ;# round up to nearest NS_ALIGN bytes, (needed on sparc/solaris)set incr [expr ($size + ($NS_ALIGN-1)) & ~($NS_ALIGN-1)]set base $hdrlen_123

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

Saved successfully!

Ooh no, something went wrong!