Simulate a wired network and demonstrate Distance Vector Routing algorithm
TCL Script:
set ns [new Simulator]
set namfile [open ex_08.nam w]
$ns namtrace-all $namfile
set tracefile [open ex_08.tr w]
$ns trace-all $tracefile
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 1ms DropTail
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link $n1 $n3 10Mb 1ms DropTail
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link $n1 $n2 10Mb 1ms DropTail
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link $n2 $n3 10Mb 1ms DropTail
$ns duplex-link-op $n2 $n3 orient right-down
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr set packetsize_ 500
$cbr set interval_ 0.005
$cbr attach-agent $udp
$udp set class_ 1
$ns color 1 Red
$ns rtmodel-at 1.0 down $n1 $n3
$ns rtmodel-at 2.0 up $n1 $n3
$ns rtproto DV
$ns at 0.0 "$cbr start"
$ns at 5.0 "$cbr stop"
proc finish {}
{
global ns namfile tracefile
$ns flush-trace close
$namfile close
$tracefile exec nam ex_08.nam &
exit 0
}
$ns at 5.0 "finish"
$ns run
TCL Script:
set ns [new Simulator]
set namfile [open ex_08.nam w]
$ns namtrace-all $namfile
set tracefile [open ex_08.tr w]
$ns trace-all $tracefile
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 10Mb 1ms DropTail
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link $n1 $n3 10Mb 1ms DropTail
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link $n1 $n2 10Mb 1ms DropTail
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link $n2 $n3 10Mb 1ms DropTail
$ns duplex-link-op $n2 $n3 orient right-down
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr set packetsize_ 500
$cbr set interval_ 0.005
$cbr attach-agent $udp
$udp set class_ 1
$ns color 1 Red
$ns rtmodel-at 1.0 down $n1 $n3
$ns rtmodel-at 2.0 up $n1 $n3
$ns rtproto DV
$ns at 0.0 "$cbr start"
$ns at 5.0 "$cbr stop"
proc finish {}
{
global ns namfile tracefile
$ns flush-trace close
$namfile close
$tracefile exec nam ex_08.nam &
exit 0
}
$ns at 5.0 "finish"
$ns run
No comments:
Post a Comment