# tcpudp.tcl

#create scheduler
set ns [new Simulator]

#choose colors
$ns color 0 blue
$ns color 1 red
$ns color 2 green

#turn tracing on
set ns_f [open tcpudp.tr w]
$ns trace-all $ns_f
set nam_f [open tcpudp.nam w]
$ns namtrace-all $nam_f

#create topology
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

$ns duplex-link $n0 $n1 1Mb 2ms DropTail
$ns duplex-link $n1 $n2 1Mb 2ms DropTail

#limit queue size (otherwise unlimited)
#$ns queue-limit $n2 $n3 5

#adjust nam orientation
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right

#turn nam visualization for n1-n2 queue
$ns duplex-link-op $n1 $n2 queuePos 0.5

#udp
#create udp agenet and a cbr application
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
$udp set class_ 0

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp

#create and attach null agents
set null [new Agent/Null]
$ns attach-agent $n2 $null

$ns connect $udp $null

#schedule the start of cbr traffic
$ns at 0.1 "$cbr start"
$ns at 5.0 "$cbr stop"

#tcp
#create and attach a TCP agent source/sink
#set tcp [new Agent/TCP]
#$tcp set class_ 2
#set sink [new Agent/TCPSink]
#$ns attach-agent $n0 $tcp
#$ns attach-agent $n2 $sink
#$ns connect $tcp $sink

#attach an ftp application to the TCP agent
#set ftp [new Application/FTP]
#$ftp attach-agent $tcp

#schedule ftp application
#$ns at 0.1 "$ftp start"
#$ns at 5.0 "$ftp stop"

#$ns at 5.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

#print the (default) cbr values
#puts [ $cbr0 set packetSize_ ]
#puts [ $cbr0 set interval_ ]

$ns at 6.0 "finish"

proc finish {} {
	global ns ns_f nam_f
	$ns flush-trace
	close $ns_f
	close $nam_f

	puts "running nam..."
	exec nam tcpudp.nam &
	exit 0
}

$ns run


