From SIMPLE.TCL
Set NS [New Simulator]
$ns Color 0 Blue
$ns Color 1 red
$ns Color 2 White
Set n0 [$ns node]
Set n1 [$ns node]
Set N2 [$ns node]
Set N3 [$ns node]
Set f [Open out.tr W]
$ns Trace-all $f
Set NF [Open Out.nam W]
$ns Namtrace-all $NF
$ns duplex-link $n 0 $n 2 5Mb 2ms droptail
$ns duplex-link $n 1 $n 2 5Mb 2ms droptail
$ns duplex-link $n 2 $n 3 1.5Mb 10ms droptail
$ns duplex-link-op $n 0 $n 2 Orient right-up
$ns duplex-link-op $n 1 $n 2 Orient Right-down
$ns duplex-link-op $n 2 $n 3 Orient Right
$ns duplex-link-op $n 2 $n 3 Queuepos 0.5
Set udp0 [New AGENT/UDP]
$ns attach-agent $n 0 $udp 0
Set cbr0 [New APPLICATION/TRAFFIC/CBR]
$CBR 0 attach-agent $udp 0
Set UDP1 [New AGENT/UDP]
$ns attach-agent $n 3 $udp 1
$UDP 1 Set Class_ 1
Set CBR1 [New APPLICATION/TRAFFIC/CBR]
$CBR 1 attach-agent $udp 1
Set null0 [New Agent/null]
$ns attach-agent $n 3 $null 0
Set NULL1 [New Agent/null]
$ns attach-agent $n 1 $null 1
$ns Connect $UDP 0 $null 0
$ns Connect $udp 1 $null 1
$ns at 1.0 "$CBR 0 start"
$ns at 1.1 "$CBR 1 Start"
Set TCP [New AGENT/TCP]
$tcp Set Class_ 2
Set sink [New Agent/tcpsink]
$ns attach-agent $n 0 $tcp
$ns attach-agent $n 3 $sink
$ns Connect $tcp $sink
Set FTP [New APPLICATION/FTP]
$ftp attach-agent $tcp
$ns at 1.2 "$ftp start"
$ns at 1.35 "$ns detach-agent $n 0 $tcp; $ns detach-agent $n 3 $sink "
puts [$CBR 0 set Packetsize_]
puts [$CBR 0 set Interval_]
$ns at 3.0 "Finish"
Proc Finish {} {
Global NS F NF
$ns Flush-trace
Close $f
Close $NF
Puts "Running nam ..."
exec Nam Out.nam &
Exit 0
}
$ns Run
NS2 simulation under the UDP protocol