Hey been trying to get a piece of code working for network animator
------------------------------------------------------Code:#Create a simulator object set ns [new Simulator] $ns rtproto DV Node set multiPath_ 1 #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 } #Create six nodes for {set i 0} {$i < 8} {in exit 0 } #Create six nodes for {set i 0} {$i < 8} {incr i} { set n($i) [$ns node] } #set up a link between then for {set i 0} {$i < 8} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%8]) 1Mb 10ms DropTail } #Setting up a flow needs these four steps --------------- #1. Create a UDP agent and attach it to node n(i) for {set i 0} {$i < 4} {incr i} { set udp(i) [new Agent/UDP] $ns attach-agent $n(i) $udp(i) } #2. Create a CBR traffic source and attach it to udp(i) for {set i 0} {$i < 4} {incr i} { set cbr(i) [new Application/Traffic/CBR] $cbr(i) set packetSize_ 1000 $cbr(i) set interval_ 0.05 $cbr(i) attach-agent $udp(i) #3. Create a Null agent (a traffic sink) and attach it to node(i) for {set x i+4} {$x < 8} {incr x} { set null(i) [new Agent/Null] $ns attach-agent $n(i) $null(x) set null(i) [new Agent/Null] $ns attach-agent $n(x) $null(i) #4. Connect the traffic source with the traffic sink $ns connect $udp(i) $null(i) } } #----------------------------------------------------------- #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 5.0 "$cbr0 stop" #Call the finish procedure after 1 second of simulation time $ns at 1.0 "finish" #Run the simulation $ns run cr i} { set n($i) [$ns node] } #set up a link between then for {set i 0} {$i < 8} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%8]) 1Mb 10ms DropTail } #Setting up a flow needs these four steps --------------- #1. Create a UDP agent and attach it to node n(i) for {set i 0} {$i < 4} {incr i} { set udp(i) [new Agent/UDP] $ns attach-agent $n(i) $udp(i) } #2. Create a CBR traffic source and attach it to udp(i) for {set i 0} {$i < 4} {incr i} { set cbr(i) [new Application/Traffic/CBR] $cbr(i) set packetSize_ 1000 $cbr(i) set interval_ 0.05 $cbr(i) attach-agent $udp(i) #3. Create a Null agent (a traffic sink) and attach it to node(i) for {set x i+4} {$x < 8} {incr x} { set null(i) [new Agent/Null] $ns attach-agent $n(i) $null(x) set null(i) [new Agent/Null] $ns attach-agent $n(x) $null(i) #4. Connect the traffic source with the traffic sink $ns connect $udp(i) $null(i) } } #----------------------------------------------------------- #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 5.0 "$cbr0 stop" #Call the finish procedure after 1 second of simulation time $ns at 1.0 "finish" #Run the simulation $ns run
error
can't read "n(i)": no such element in array
while executing
"$ns attach-agent $n(i) $udp(i)"
("for" body line 3)
invoked from within
"for {set i 0} {$i < 4} {incr i} {
set udp(i) [new Agent/UDP]
$ns attach-agent $n(i) $udp(i)
}"
(file "part2q7" line 35)
dont quite understand what is going on, any help is greatly appreciated!!!!
Cheers