20.5.2 Tcl APIs for the ping application

An example script for the ping application is under ~ns/tcl/ex/diffusion3/simple-diffusion.tcl. The example scenario consists of 3 nodes of which one is a ping-sender and another is a ping-receiver. The source and sink nodes are far away from one another and communicate only through a third node. The option adhocRouting is defined as Directed_Diffusion. This enables a core-diffusion agent to be created during the time of node creation. Also it creates a diffusionApplication agent if one is not present already. The option diffusionFilter needs to be provided at the time of node configuration that defines the one or more filters that would be added to the node. There is also an option for specifying stopTime which is the time the simulation ends. At this time there is a callback to a function that prints out all statistical data into /tmp/diffusion-*.out.

Node configuration is done as follows:

$ns_ node-config -adhocRouting $opt(adhocRouting) \
                 -llType $opt(ll) \
                 -macType $opt(mac) \
                 -diffusionFilter $opt(filters) \
                 -stopTime $opt(prestop) \
                 -agentTrace ON \

The ping sender application is created in the following way:

set src_(0) [new Application/DiffApp/PingSender]
$ns_ attach-diffapp $node_(0) $src_(0)
$ns_ at 0.123 "$src_(0) publish"

The first line creates a ping-sender object. Simulator class method attach-diffapp basically attaches the application to the underlying diffusionApplication agent for that given node. The command publish essentially ``starts'' the sender application.

Similarly the ping sink is created as follows:

#Diffusion sink application
set snk_(0) [new Application/DiffApp/PingReceiver]
$ns_ attach-diffapp $node_(2) $snk_(0)
$ns_ at 1.456 "$snk_(0) subscribe"

The command subscribe starts the ping-receiver application.

Thus in order to create your own application, you need to :

define attribute-factories and attributes for application interest/data.
create the application class (using dr-library APIs)
add tcl commands to start the application

See ~ns/tcl/lib/ns-lib.tcl, ns-diffusion.tcl for implementations of OTcl hooks for directed diffusion. Alo see chapter on Mobility in this manual for details on mobility model and wireless simulations in ns.

Tom Henderson 2011-11-05