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.

20.5.2 Tcl APIs for the ping applic<strong>at</strong>ionAn example script for the ping applic<strong>at</strong>ion is under ~<strong>ns</strong>/tcl/ex/diffusion3/simple-diffusion.tcl. <strong>The</strong> example scenario co<strong>ns</strong>istsof 3 nodes of which one is a ping-sender <strong>and</strong> another is a ping-receiver. <strong>The</strong> source <strong>and</strong> sink nodes are far away from oneanother <strong>and</strong> communic<strong>at</strong>e only through a third node. <strong>The</strong> option adhocRouting is defined as Directed_Diffusion. This enablesa core-diffusion agent to be cre<strong>at</strong>ed during the time of node cre<strong>at</strong>ion. Also it cre<strong>at</strong>es a diffusionApplic<strong>at</strong>ion agent if one is notpresent already. <strong>The</strong> option diffusionFilter needs to be provided <strong>at</strong> the time of node configur<strong>at</strong>ion th<strong>at</strong> defines the one or morefilters th<strong>at</strong> would be added to the node. <strong>The</strong>re is also an option for specifying stopTime which is the time the simul<strong>at</strong>ion ends.At this time there is a callback to a function th<strong>at</strong> prints out all st<strong>at</strong>istical d<strong>at</strong>a into /tmp/diffusion-*.out.Node configur<strong>at</strong>ion is done as follows:$<strong>ns</strong>_ node-config -adhocRouting $opt(adhocRouting)-diffusionFilter $opt(filters)-llType $opt(ll)-stopTime $opt(prestop)<strong>The</strong> ping sender applic<strong>at</strong>ion is cre<strong>at</strong>ed in the following way:set src_(0) [new Applic<strong>at</strong>ion/DiffApp/PingSender]$<strong>ns</strong>_ <strong>at</strong>tach-diffapp $node_(0) $src_(0)$<strong>ns</strong>_ <strong>at</strong> 0.123 "$src_(0) publish"<strong>The</strong> first line cre<strong>at</strong>es a ping-sender object. Simul<strong>at</strong>or class method <strong>at</strong>tach-diffapp basically <strong>at</strong>taches the applic<strong>at</strong>ion to the underlyingdiffusionApplic<strong>at</strong>ion agent for th<strong>at</strong> given node. <strong>The</strong> comm<strong>and</strong> publish essentially “starts” the sender applic<strong>at</strong>ion.Similarly the ping sink is cre<strong>at</strong>ed as follows:#Diffusion sink applic<strong>at</strong>io<strong>ns</strong>et snk_(0) [new Applic<strong>at</strong>ion/DiffApp/PingReceiver]$<strong>ns</strong>_ <strong>at</strong>tach-diffapp $node_(2) $snk_(0)$<strong>ns</strong>_ <strong>at</strong> 1.456 "$snk_(0) subscribe"<strong>The</strong> comm<strong>and</strong> subscribe starts the ping-receiver applic<strong>at</strong>ion.Thus in order to cre<strong>at</strong>e your own applic<strong>at</strong>ion, you need to :1. define <strong>at</strong>tribute-factories <strong>and</strong> <strong>at</strong>tributes for applic<strong>at</strong>ion interest/d<strong>at</strong>a.2. cre<strong>at</strong>e the applic<strong>at</strong>ion class (using dr-library APIs)3. add tcl comm<strong>and</strong>s to start the applic<strong>at</strong>ionSee ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-lib.tcl, <strong>ns</strong>-diffusion.tcl for implement<strong>at</strong>io<strong>ns</strong> of OTcl hooks for directed diffusion. Alo see chapter on Mobilityin this manual for details on mobility model <strong>and</strong> wireless simul<strong>at</strong>io<strong>ns</strong> in <strong>ns</strong>.20.6 Changes required to add yr diffusion applic<strong>at</strong>ion to <strong>ns</strong>Let’s say you have an applic<strong>at</strong>ion (it might even be a certain filter, which also is by class hierarchy, a diffusion applic<strong>at</strong>ion <strong>and</strong>it would derive from class DiffApp) th<strong>at</strong> ru<strong>ns</strong> on the test-bed version. Now you want to run diffusion on <strong>ns</strong> <strong>and</strong> so want to use197

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

Saved successfully!

Ooh no, something went wrong!