41.2.5 An example

Here is an example of how the API is used to implement a simple application (FTP) on top of a FullTCP connection.

        set src [new Agent/TCP/FullTcp]
        set sink [new Agent/TCP/FullTcp]
        $ns_ attach-agent $node_(s1) $src
        $ns_ attach-agent $node_(k1) $sink
        $ns_ connect $src $sink

        # set up TCP-level connections
        $sink listen; 
        $src set window_ 100

        set ftp1 [new Application/FTP]
        $ftp1 attach-agent $src

        $ns_ at 0.0 "$ftp1 start"

In the configuration script, the first five lines of code allocates two new FullTcp agents, attaches them to the correct nodes, and "connects" them together (assigns the correct destination addresses to each agent). The next two lines configure the TCP agents further, placing one of them in LISTEN mode. Next, ftp1 is defined as a new FTP Application, and the attach-agent method is called in C++ (app.cc).

The ftp1 application is started at time 0:

        Application/FTP instproc start {} {
      	        [$self agent] send -1;   # Send indefinitely
        }
Alternatively, the FTP application could have been implemented in C++ as follows:
        void FTP::start()
        {
                agent_-\>send(-1);    // Send indefinitely
        }
Since the FTP application does not make use of callbacks, these functions are null in C++ and no OTcl callbacks are made.



Tom Henderson 2014-12-17