3
set ns [new Simulator]
#open nam file
set nf [open out.nam w]
$ns namtrace-all $nf
#set variables of topology
set lanNodes 5
set link("bandwidth") 5mb
set link("delay") 2ms
set link("queue") DropTail
#define two routers
set router0 [$ns node]
set router1 [$ns node]
#link two routers
$ns duplex-link $router0 $router1 2mb 2ms DropTail
#create and connect nodes with routers
for {set i 0}{$i < $lanNodes}{incr i} {
set n($i) [$ns node]
set n([expr $i+5]) [$ns node]
$ns duplex-link $n($i) $router0 $link("bandwidth") $link("delay") $link("queue")
$ns duplex-link $n([expr $i+5]) $router1 $link("bandwidth") $link("delay") $link("queue")
}
proc finish { } {
global ns nf
close $nf

what is error for this code when i want to implemented this code in ns2 write this sentences " extra characters after close-brace while executing for " what is meaning and who can solve this

user3146469
  • 41
  • 1
  • 2
  • 6

1 Answers1

9

Please try editing (line 16)

for {set i 0}{$i < $lanNodes}{incr i} {

To :

for {set i 0} {$i < $lanNodes} {incr i} {

i.e. add a space after each close-brace ( } )

-

Raein Hashemi
  • 3,346
  • 4
  • 22
  • 33
Knud Larsen
  • 5,753
  • 2
  • 14
  • 19
  • Check [this](https://wiki.tcl-lang.org/page/Common+Tcl+Error+Messages+and+Possible+Explanations) for common tcl messages, should ad brace between { and }. – Yong Yang Mar 11 '21 at 06:54