#routeDV_mpath.tcl

#Esempio di multipath routing. Le sorgente e' su n1.

set ns [new Simulator]

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

#Con le seguenti righe di codice viene abilitato il multipath routing
$ns rtproto DV
Node set multiPath_ 1

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

#Creazione topologia
for  {set i 0} {$i < 6} {incr i} {
set n($i) [$ns node]
}

for  {set i 0 } {$i < 6} {incr i} {
    $ns duplex-link $n($i) $n([expr ($i+1)%6]) 1Mb 10ms DropTail
}

$ns duplex-link $n(0) $n(4) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(3) 1Mb 10ms DropTail

#Costi dei link
$ns cost $n(0) $n(1) 2
$ns cost $n(1) $n(0) 2
$ns cost $n(1) $n(2) 1
$ns cost $n(2) $n(1) 1
$ns cost $n(2) $n(3) 5
$ns cost $n(3) $n(2) 5
$ns cost $n(3) $n(4) 10
$ns cost $n(4) $n(3) 10
$ns cost $n(4) $n(5) 10
$ns cost $n(5) $n(4) 10
$ns cost $n(5) $n(0) 10
$ns cost $n(0) $n(5) 10
$ns cost $n(4) $n(0) 10
$ns cost $n(0) $n(4) 10
$ns cost $n(1) $n(3) 2
$ns cost $n(3) $n(1) 2

#Il livello di trasporto
#nodo1 :sorgente 
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
$udp1 set fid_ 1
$ns color 1 red

#nodo4 :destinatario
set null4 [new Agent/Null]
$ns attach-agent $n(4) $null4

$ns connect $udp1 $null4

#Il livello di applicazione
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1

#Commenti
puts "\n\n##### COMMENTI #####"
puts "0.2 :cbr1 starts"
puts "il protcollo di routing distribuisce\nil traffico tra i due\
percorsi identici\n"

#Temporizzaione della simulazione
$ns at 0.2 "$cbr1 start"
$ns at 1 "finish"

$ns run