Hi im new to C, I was wondering what alterations I would need to the code to specify the upper limits of my for loops with a variable e.g instead of
{$i < 8}....something like {$i < flowno}.
Also for the for loop that specifies 4 as its upper limit, instead could I simply write flowno/2, as this loop will always be half the size of the first loop.
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 the required number of nodes 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 n0
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 udp0
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 n1
set x [expr ($i+4)]
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 "$cbr($i) start"
$ns at 5.0 "$cbr($i) stop"
}
#-----------------------------------------------------------
#Call the finish procedure after 1 second of simulation time
$ns at 1.0 "finish"
#Run the simulation
$ns run
any help is greatly appreciated!!!!!