#fulltcp02.tcl

set ns [new Simulator]

set nf [open fulltcp02.nam w]
$ns namtrace-all $nf

set tr [open fulltcp02.tr w]
$ns trace-all $tr

proc finish {} {
        global ns nf tr 
        $ns flush-trace
        close $nf
        close $tr
        exec nam fulltcp02.nam &
        exit 0 }

#Creazione della topologia
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

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

#Il livello di trasporto
set ftcp0 [new Agent/TCP/FullTcp]
set ftcp2 [new Agent/TCP/FullTcp]
$ns attach-agent $n0 $ftcp0
$ns attach-agent $n2 $ftcp2
$ftcp0 set fid_ 0
$ftcp2 set fid_ 2

$ns color 0 red
$ns color 2 blue

$ns connect $ftcp0 $ftcp2

$ftcp2 listen
$ftcp2 set window_ 16
$ftcp0 set window_ 8

#Il livello di applicazione
set ftp02 [new Application/FTP]
$ftp02 attach-agent $ftcp0

set ftp20 [new Application/FTP]
$ftp20 attach-agent $ftcp2

puts "\n\n#### COMMENTI ####\n"
puts "0.1 : ftp02 starts"
puts "0.5 : ftp20 starts"
puts "1   : ftp20 stops"
puts "1.5 : ftp02 stops"
puts "La finestra di controllo di flusso vista da ftcp0 e' 8"
puts "Quella vista da ftcp2 e' 16\n"
 
#Temporizzazione della simulazione
$ns at 0.1 "$ftp02 start"
$ns at 0.5 "$ftp20 start"
$ns at 1   "$ftp20 stop"
$ns at 1.5 "$ftp02 stop"
$ns at 3 "finish"

$ns run