#Create simulator
set ns [new Simulator]

$ns color 0 Blue
$ns color 1 Red

#trace file
set tf [open S01E01.out.tr w]
$ns trace-all $tf

#nam tracefile
set nf [open S01E01.out.nam w]
$ns namtrace-all $nf

proc finish {} {
	#finalize trace files
	global ns nf tf
	$ns flush-trace
	close $tf
	close $nf
	
	exec nam S01E01.out.nam &
	exit 0
}

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

#and links
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 10Mb 10ms DropTail

#CBR Traffic 0->2
set udp1 [new Agent/UDP]
$ns attach-agent $n0 $udp1
set null1 [new Agent/Null]
$ns attach-agent $n2 $null1
$ns connect $udp1 $null1
$udp1 set fid_ 0
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1500
$cbr1 set rate_ 10Mb
$cbr1 set random_ false

#CBR Traffic 2->0
set udp2 [new Agent/UDP]
$ns attach-agent $n2 $udp2
set null2 [new Agent/Null]
$ns attach-agent $n0 $null2
$ns connect $udp2 $null2
$udp1 set fid_ 1
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$cbr2 set packetSize_ 1500
$cbr2 set rate_ 5Mb
$cbr2 set random_ false

$ns at 0.1 "$cbr1 start"
$ns at 0.1 "$cbr2 start"
$ns at 10.1 "$cbr1 stop"
$ns at 10.1 "$cbr2 stop"
$ns at 10.5 "finish"

$ns run
