#Create a simulator object set ns [new Simulator] #Open a trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } #Create three nodes set n2 [$ns node] set n1 [$ns node] ###################### # Link definition ###################### $ns duplex-link $n1 $n2 10Mb 2ms DropTail # Set up TCP connection # set tcp1 [$ns_ create-connection TCP $n1 TCPSink $n2 0] # $tcp1 set window_ 30 set tcp1 [new Agent/TCP/FullTcp] set tcp2 [new Agent/TCP/FullTcp] $ns attach-agent $n1 $tcp1 $ns attach-agent $n2 $tcp2 $ns connect $tcp1 $tcp2 $tcp2 listen #--------------------------------------------- Application/TcpApp instproc app-recv {size} { global ns puts "[$ns now] app2 receives data $size from app1" } #--------------------------------------------- set app1 [new Application/TcpApp $tcp1] set app2 [new Application/TcpApp $tcp2] $app1 connect $app2 $ns at 1.2 "$app2 send 100 \"$app1 app-recv 100\"" $ns at 1.1 "$app1 send 100 \"$app2 app-recv 100\"" $ns at 6.5 "finish" #Run the simulation $ns run