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.

}bind("windowOption_", &wnd_option_);bind("windowCo<strong>ns</strong>tant_", &wnd_co<strong>ns</strong>t_);...bind("off_ip_", &off_ip_);bind("off_tcp_", &off_tcp_);...<strong>The</strong> Agent co<strong>ns</strong>tructor (~<strong>ns</strong>/agent.cc):Agent::Agent(int pkttype) :addr_(-1), dst_(-1), size_(0), type_(pkttype), fid_(-1),prio_(-1), flags_(0){memset(pending_, 0, sizeof(pending_)); /* timers */// this is really an IP agent, so set up// for gener<strong>at</strong>ing the appropri<strong>at</strong>e IP fields. . .bind("addr_", (int*)&addr_);bind("dst_", (int*)&dst_);bind("fid_", (int*)&fid_);bind("prio_", (int*)&prio_);bind("flags_", (int*)&flags_);...}<strong>The</strong>se code fragments illustr<strong>at</strong>e the common case where an agent’s co<strong>ns</strong>tructor passes a packet type identifier to the Agentco<strong>ns</strong>tructor. <strong>The</strong> values for the various packet types are used by the packet tracing facility (Section 26.5) <strong>and</strong> are defined in~<strong>ns</strong>/trace.h. <strong>The</strong> variables which are bound in the TcpAgent co<strong>ns</strong>tructor are ordinary i<strong>ns</strong>tance/member variables for theclass with the exception of the special integer values off_tcp_ <strong>and</strong> off_ip_. <strong>The</strong>se are needed in order to access a TCPheader <strong>and</strong> IP header, respectively. Additional details are in the section on packet headers (Section 12.1).Note th<strong>at</strong> the TcpAgent co<strong>ns</strong>tructor contai<strong>ns</strong> initializ<strong>at</strong>io<strong>ns</strong> for two timers, rtx_timer_ <strong>and</strong> delsnd_timer_.TimerH<strong>and</strong>ler objects are initialized by providing a pointer (the this pointer) to the relevant agent.10.5.2 Starting the Agent<strong>The</strong> TcpAgent agent is started in the example when its FTP source receives the start directive <strong>at</strong> time 1.2. <strong>The</strong> startoper<strong>at</strong>ion is an i<strong>ns</strong>tance procedure defined on the class Applic<strong>at</strong>ion/FTP (Section 38.4). It is defined in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-source.tclas follows:Applic<strong>at</strong>ion/FTP i<strong>ns</strong>tproc start {} {[$self agent] send -1}In this case, agent refers to our simple TCP agent <strong>and</strong> send -1 is analogous to sending an arbitrarily large file.<strong>The</strong> call to send eventually results in the simple TCP sender gener<strong>at</strong>ing packets. <strong>The</strong> following function output performsthis:void TcpAgent::output(int seqno, int reason)100

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

Saved successfully!

Ooh no, something went wrong!