Creating the Agent

set ns [new Simulator]                  # preamble initialization;
set node1 [$ns node]                     # agent to reside on this node;
set node2 [$ns node]                     # agent to reside on this node;

{\bfseries{}set tcp1 [$ns create-connection TCP $node1 TCPSink $node2 42]}
$tcp  set window_ 50                   # configure the TCP agent;

{\bfseries{}set ftp1 [new Application/FTP]}
{\bfseries{}$ftp1 attach-agent $tcp1}

$ns at 0.0 "$ftp start"
This example illustrates the use of the simulator built-in function create-connection. The arguments to this function are: the source agent to create, the source node, the target agent to create, the target node, and the flow ID to be used on the connection. The function operates by creating the two agents, setting the flow ID fields in the agents, attaching the source and target agents to their respective nodes, and finally connecting the agents (i.e. setting appropriate source and destination addresses and ports). The return value of the function is the name of the source agent created.

Tom Henderson 2011-11-05