next up previous contents index
Next: 31.3 The class TrafficGenerator Up: 31.2 The transport agent Previous: 31.2.4 Agent upcalls to

   
31.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.




2000-08-24