- Home Page of ProjectGuideline.com ›
- Forums ›
- Questions Asked by Students and Scholars ›
- can't read “ns_”: no such variable – what causes this ns-2 error?
Tagged: no such variable error in ns2, ns-2 error
This is my tcl code and I created my scenario file with this code:
The following is the code :
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 250 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(cp) T250
set val(sc) S250
# ==================================================== =================
# Main Program
# ======================================================================
set ns [new Simulator]
set tracefd [open out.tr w]
set winfile [open winFile w]
global $ns_
$ns trace-all $tracefd
set namtrace [open out.nam w]
$ns namtrace-all-wireless $namtrace 1500 1500
set topo [new Topography]
$topo load_flatgrid 1500 1500
create-god $val(nn)
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-mvementTrace ON \
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
}
puts “Loading scenario file…”
source $val(sc)
puts “Loading connection pattern…”
source $val(cp)
# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 10.0 “$node_($i) reset”;
}
$ns_ at 10.0 “stop”
$ns_ at 10.01 “puts \”NS EXITING…\” ; $ns_ halt”
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
exec nam out.nam &
exit 0
}
puts “Starting Simulation…”
$ns_ run
./setdest -n 250 -p 0.0 -M 10.0 -t 10 -x 1500 -y 1500 > S250
and also
ns cbrgen.tcl -type tcp -nn 250 -seed 1.0 -mc 100 > T250
but when i tried run simulation i shown this error.
can’t read “ns_”: no such variable
while executing
“global $ns_”
(file “wireless.tcl” line 24)
Can you help me about this topic? It would be much appreciated.
In fact, the Answer is simple, you didn’t declare the variable “ns_” in the global memory space.
you only declared a variable named “ns”.
# ==================================================== =================
# Main Program
# ======================================================================
set ns [new Simulator]
So, if you are referring an undeclared variable “ns_” from the global memory space, then you should receive the error
can’t read “ns_”: no such variable
while executing
“global $ns_”
(file “wireless.tcl” line 24)
Since there is no such variable declared in global scope.