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.

• recv(int nbytes)—Announces th<strong>at</strong> nbytes of d<strong>at</strong>a have been received by the agent. For UDP agents, thissignifies the arrival of a single packet. For TCP agents, this signifies the “delivery” of an amount of in-sequence d<strong>at</strong>a,which may be larger than th<strong>at</strong> contained in a single packet (due to the possibility of network reordering).• resume()—This indic<strong>at</strong>es to the applic<strong>at</strong>ion th<strong>at</strong> the tra<strong>ns</strong>port agent has sent out all of the d<strong>at</strong>a submitted to it up toth<strong>at</strong> point in time. For TCP, it does not indic<strong>at</strong>e whether the d<strong>at</strong>a has been ACKed yet, only th<strong>at</strong> it has been sent out forthe first time.<strong>The</strong> default behavior is as follows: Depending on whether the applic<strong>at</strong>ion has been implemented in C++ or OTcl, these C++functio<strong>ns</strong> call a similarly named (recv, resume) function in the applic<strong>at</strong>ion, if such methods have been defined.Although strictly not a callback to applic<strong>at</strong>io<strong>ns</strong>, certain Agents have implemented a callback from C++ to OTcl-level th<strong>at</strong>has been used by applic<strong>at</strong>io<strong>ns</strong> such as HTTP simul<strong>at</strong>ors. This callback method, done{}, is used in TCP agents. In TCP,done{} is called when a TCP sender has received ACKs for all of its d<strong>at</strong>a <strong>and</strong> is now closed; it therefore can be used tosimul<strong>at</strong>e a blocked TCP connection. <strong>The</strong> done{} method was primarily used before this API was completed, but may stillbe useful for applic<strong>at</strong>io<strong>ns</strong> th<strong>at</strong> do not want to use resume().To use done{} for FullTcp, for example, you can try:set myagent [new Agent/TCP/FullTcp]$myagent proc done... code you want ...If you want all the FullTCP’s to have the same code you could also do:Agent/TCP/FullTcp i<strong>ns</strong>tproc done... code you want ...By default, done{} does nothing.38.2.5 An exampleHere is an example of how the API is used to implement a simple applic<strong>at</strong>ion (FTP) on top of a FullTCP connection.set src [new Agent/TCP/FullTcp]set sink [new Agent/TCP/FullTcp]$<strong>ns</strong>_ <strong>at</strong>tach-agent $node_(s1) $src$<strong>ns</strong>_ <strong>at</strong>tach-agent $node_(k1) $sink$<strong>ns</strong>_ connect $src $sink# set up TCP-level connectio<strong>ns</strong>$sink listen;$src set window_ 100set ftp1 [new Applic<strong>at</strong>ion/FTP]$ftp1 <strong>at</strong>tach-agent $src$<strong>ns</strong>_ <strong>at</strong> 0.0 "$ftp1 start"334

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

Saved successfully!

Ooh no, something went wrong!