Hi everybody
Please excuse the newbie question but this has now been annoying me for hours.
I'm cleaning up a (working) script that has a lot of repetition in it (creating
nodes and agents, etc.). I'm trying to replace some of that repetition with
loops but it doesn't want to work.
I'm trying to replace multiple instances of this code:
set udp14 [new Agent/UDP]
$udp15 set class_ 3
$ns attach-agent $n14 $udp14
set cbr14 [new Application/Traffic/CBR]
$cbr14 set packetSize_ $myPacketSize
$cbr14 set interval_ $myInterval
$cbr14 attach-agent $udp14
With something like (apologies for the variable names):
for {set i 14} {$i <= 14} {incr i} {
set age \$udp
set com $age$i
set tra \$cbr
set traf $tra$i
set nod n$i
set udp$i [new Agent/UDP]
$com set class_ 2
$ns attach-agent $nod $com
set cbr14 [new Application/Traffic/CBR]
$traf set packetSize_ $myPacketSize
$traf set interval_ $myInterval
$traf attach-agent $com
}
However, when I run the script I get the following error:
invalid command name "$udp14"
while executing
"$com set class_ 2"
("for" body line 9)
invoked from within
"for {set i 14} {$i <= 14} {incr i} {
set udp$i [new Agent/UDP]
set age \$udp
set com $age$i
set tra \$cbr
set traf $tra$i
set nod n$i
$c..."
(file "hg-0.8.3.tcl" line 228)
So it looks like it not interpreting $com correctly to set up the agent.
Any ideas? I suspect I've missed something simple...
(NS-2.34 on Mandriva)
Thanks in advance,
Geoff
_________________________________________________________________
http://clk.atdmt.com/UKM/go/195013117/direct/01/