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.

Agent set dst_ 0Agent set flags_ 0Generally these initializ<strong>at</strong>io<strong>ns</strong> are placed in the OTcl namespace before any objects of these types are cre<strong>at</strong>ed. Thus, when anAgent object is cre<strong>at</strong>ed, the calls to bind in the objects’ co<strong>ns</strong>tructors will causes the corresponding member variables to beset to these specified defaults.10.4.3 OTcl Methods<strong>The</strong> i<strong>ns</strong>tance procedures defined for the OTcl Agent class are currently found in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-agent.tcl. <strong>The</strong>y are as follows:port the agent’s port identifierdst-port the destin<strong>at</strong>ion’s port identifier<strong>at</strong>tach-source 〈stype〉 cre<strong>at</strong>e <strong>and</strong> <strong>at</strong>tach a Source object to an agent10.5 Examples: Tcp, TCP Sink Agents<strong>The</strong> class TCP represents a simplified TCP sender. It sends d<strong>at</strong>a to a TCPSink agent <strong>and</strong> processes its acknowledgments.It has a separ<strong>at</strong>e object associ<strong>at</strong>ed with it which represents an applic<strong>at</strong>ion’s dem<strong>and</strong>. By looking <strong>at</strong> the class TCPAgent<strong>and</strong> class TCPSinkAgent, we may see how rel<strong>at</strong>ively complex agents are co<strong>ns</strong>tructed. An example from the Tahoe TCPagent TCPAgent is also given to illustr<strong>at</strong>e the use of timers.10.5.1 Cre<strong>at</strong>ing the Agent<strong>The</strong> following OTcl code fragment cre<strong>at</strong>es a TCP agent <strong>and</strong> sets it up:set tcp [new Agent/TCP];# cre<strong>at</strong>e sender agent$tcp set fid_ 2;# set IP-layer flow IDset sink [new Agent/TCPSink];# cre<strong>at</strong>e receiver agent$<strong>ns</strong> <strong>at</strong>tach-agent $n0 $tcp ;# put sender on node $n0$<strong>ns</strong> <strong>at</strong>tach-agent $n3 $sink ;# put receiver on node $n3$<strong>ns</strong> connect $tcp $sink;# establish TCP connectio<strong>ns</strong>et ftp [new Applic<strong>at</strong>ion/FTP];# cre<strong>at</strong>e an FTP source "applic<strong>at</strong>ion"$ftp <strong>at</strong>tach-agent $tcp;# associ<strong>at</strong>e FTP with the TCP sender$<strong>ns</strong> <strong>at</strong> 1.2 "$ftp start";#arrange for FTP to start <strong>at</strong> time 1.2 sec<strong>The</strong> OTcl i<strong>ns</strong>truction new Agent/TCP results in the cre<strong>at</strong>ion of a C++ TcpAgent class object. Its co<strong>ns</strong>tructor first invokesthe co<strong>ns</strong>tructor of the Agent base class <strong>and</strong> then performs its own bindings. <strong>The</strong>se two co<strong>ns</strong>tructors appear as follows:<strong>The</strong> TcpSimpleAgent co<strong>ns</strong>tructor (~<strong>ns</strong>/tcp.cc):TcpAgent::TcpAgent() : Agent(PT_TCP), rtt_active_(0), rtt_seq_(-1),rtx_timer_(this), delsnd_timer_(this){bind("window_", &wnd_);bind("windowInit_", &wnd_init_);99

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

Saved successfully!

Ooh no, something went wrong!