Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-10-2016, 02:20 AM
|
#1
|
LQ Newbie
Registered: Nov 2016
Location: jakarta, indonesia
Posts: 3
Rep:
|
ns-allinone-2.35 error : "can't read "chan": no such variable"
hi friends...im a newbie in linux and ns2...im using ns-allinone-2.35 in ubuntu 14.04
currently im working in wireless sensor network...i got an error when i run the codes...i cant figure it out...i was trying to find the answer but i didnt get it...what does this error mean? because i didnt declare "chan"? i already did, such as set val(chan) Channel/WirelessChannel ; set chan_1 [new $val(chan)] ; channel $chan_1.
Or it's talking about "$ns node",
at "for {set i 0} {$i <22} {incr i} {
set n($i) [$ns node]
$n($i) color "blue"
$n($i) shape"circle"
}"
(file "coba2.tcl" line 64)?
this is the error
num_nodes is set 22
can't read "chan": no such variable
while executing
"$node add-interface $chan $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ $inerrProc_ $outerrProc_ $FECProc_"
(procedure "_o3" line 83)
(Simulator create-wireless-node line 83)
invoked from within
"_o3 create-wireless-node"
("eval" body line 1)
invoked from within
"eval $self create-wireless-node $args"
(procedure "_o3" line 23)
(Simulator node line 23)
invoked from within
"$ns node"
("for" body line 2)
invoked from within
"for {set i 0} {$i <22} {incr i} {
set n($i) [$ns node]
$n($i) color "blue"
$n($i) shape"circle"
}"
(file "coba2.tcl" line 64)
#simulation
#define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;#radio-propagation
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ll) LL ;#Link layer type
set val(ifq) CMUPriQueue ;#Interface queue
set val(ifqlen) 50 ;# max packet in ifq
set val(netif) Phy/WirelessPhy ;#network interface
set val(mac) Mac/802_11 ;# MAC type
set val(nn) 22 ;#number of mobilenodes
set val(rp) DSR ;#routing protocol
set val(x) 4400
set val(y) 4400
set val(initialenergy) 1000 ;# Intial energy in Joules
set xdist 100
set ydist 100
set val(energymodel) EnergyModel ;#Energy set up
set ns [new Simulator]
#ns-random 0
#create tracefile
set f [open 1_out.tr w]
$ns trace-all $f
#create nam trace
set namtrace [open 1_out.nam w]
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
set f5 [open node5.tr w]
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y) ; #set topology
create-god $val(nn)
set chan_1 [new $val(chan)]
#configure and create nodes
$ns node-config -adhocRouting $val(rp) \
llType $val(ll) \
macTtype $val(mac) \
ifqType $val(ifq) \
ifqLen $val(ifqlen) \
antType $val(ant) \
propType $val(prop) \
phyType $val(netif) \
topoInstance $topo \
agentTrace ON \
routerTrace ON \
macTrace On \
movementTrace OFF \
channel $chan_1
$ns node-config -energyModel EnergyModel \
energyModel $val(energymodel) \
initialEnergy $val(initialenergy) \
idlePower 0.0 \
rxPower 1.0 \
txPower 2.0 \
sleepPower 0.000 \
transtionPower 0.2 \
transtionTime 0.00000005
for {set i 0} {$i <22} {incr i} {
set n($i) [$ns node]
$n($i) color "blue"
$n($i) shape"circle"
}
#set finish procedure
proc finish {} {
global ns f namtrace
global f5 namtrace
$ns flush-trace
close $namtrace
close $f
exec nam -r 5m 1_out.nam &
exit 0
}
proc record {} {
global sink5 f5
#Get An Instance of the simulator
set ns [Simulator instance]
#Set The Time After Which The Procedure Should Be Called Again
set time 0.05
set bw5 [$sink5 set bytes_]
#Get The current Time
set now [$ns now]
#Save Data to the files
puts $f5 "now [expr $bw5/$time*8/1000000]"
$sink5 set bytes_ 0
$ns at [expr $now + $time] "record"
}
set i 0
set y 100
for {set t 0} {$t < 5} {incr t} {
if {[expr $t % 2] == 0} {
puts "genap"
set x 100
for {ser b 0} {$b<6} {incr b}{
$n($i) set X_ $x
$n($i) set Y_ $y
$n($i) set Z_ 3000.0
set x [expr $x + 300]
set i [expr $i +1]
puts "$i $x $y"
}
} else {
puts "ganjil"
set x 100
for {set b 0} {$b<6} {incr b} {
$n($i) set X_ $x
$n($i) set Y_ $y
$n($i) set Z_ 3000.0
set x [expr $x + 1500]
set i [expr $i +1]
puts "$i $x $y"
}
}
set y [expr $y + 300]
}
for {set i 0} {$i < $val(nn) } {incr i} {
#$ns intial_node_pos $n($i) 30+i*100
$ns intial_node_pos $n($i) 10
}
#shutdown node
#command "node-down" and "node off" in ns2 is not working
$ns at 2.0 "$n(3) color red"
$ns at 2.0 "$n(3) shade triangle"
$ns at 2.0 "$n(3) setdest 4300.0 100.0 3000000000.0"
$ns at 4.0 "$n(11) color red"
$ns at 4.0 "$n(11) shade triangle"
$ns at 4.0 "$n(11) setdest 4300.0 700.0 3000000000.0"
$ns at 6.0 "$n(19) color red"
$ns at 6.0 "$n(19) shade triangle"
$ns at 6.0 "$n(19) setdest 4300.0 1300.0 3000000000.0"
$ns at 10.0 "$n(3) color red"
$ns at 10.0 "$n(3) shade triangle"
$ns at 10.0 "$n(3) setdest 4300.0 1300.0 3000000000.0"
$ns at 14.0 "$n(11) color red"
$ns at 14.0 "$n(11) shade triangle"
$ns at 14.0 "$n(11) setdest 4300.0 1300.0 3000000000.0"
#turn on mode
$ns at 6.0 "$n(3) color green"
$ns at 6.0 "$n(3) shade circle"
$ns at 6.0 "$n(3) setdest 1000.0 100.0 30000.0"
$ns at 10.0 "$n(11) color green"
$ns at 10.0 "$n(11) shade circle"
$ns at 10.0 "$n(11) setdest 1000.0 700.0 30000.0"
$ns at 14.0 "$n(11) color green"
$ns at 14.0 "$n(11) shade circle"
$ns at 14.0 "$n(11) setdest 1000.0 1300.0 30000.0"
#configure and set up a flow
set sink5 [new Agent/LossMonitor]
$ns attach-agent $n(5) $sink5
$ns attach-agent $n(9) $sink9
for {set i 0} {$i < 22} {incr i} {
set udp [expr $i] [new Agent/UDP]
}
$ns attach-agent $n(0) $udp0
$ns attach-agent $n(1) $udp1
$ns attach-agent $n(2) $udp2
$ns attach-agent $n(3) $udp3
$ns attach-agent $n(4) $udp4
$ns attach-agent $n(5) $udp5
$ns attach-agent $n(6) $udp6
$ns attach-agent $n(7) $udp7
$ns attach-agent $n(8) $udp8
$ns attach-agent $n(9) $udp9
$ns attach-agent $n(10) $udp10
$ns attach-agent $n(11) $udp11
$ns attach-agent $n(12) $udp12
$ns attach-agent $n(13) $udp13
$ns attach-agent $n(14) $udp14
$ns attach-agent $n(15) $udp15
$ns attach-agent $n(16) $udp16
$ns attach-agent $n(17) $udp17
$ns attach-agent $n(18) $udp18
$ns attach-agent $n(19) $udp19
$ns attach-agent $n(20) $udp20
$ns attach-agent $n(21) $udp21
proc attach-CBR-traffic { node sink size interval} {
#Get an instance of simulator
set ns [Simulator instance]
#create a cbr agent and attach it to the node
set cbr [new Agent/CBR]
$ns attach-agent $node $cbr
$cbr set packetSize_ $size
$cbr set interval_ $interval
#attach CBR source to sink;
$ns connect $cbr $sink
return $cbr
}
set cbr0 [attach-CBR-traffic $n(0) $sink5 1000 .050]
#simulation start
$ns at 0.0 "record"
$ns at 0.0 " $cbr0 start"
$ns at 20.0 " $cbr0 stop"
$ns at 20.0 "finish"
$ns run
can somebody help me please? i can't figure it out. thank you so much!
regards,
angel
|
|
|
11-10-2016, 02:21 AM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,251
|
Not urgent at all - and don't multi-post.
Reported for closure.
|
|
|
11-10-2016, 03:25 AM
|
#3
|
LQ Newbie
Registered: Nov 2016
Location: jakarta, indonesia
Posts: 3
Original Poster
Rep:
|
hi syg00....im sorry about "the multi-post"
i dont understand what you mean...
btw i really need help to fix it...thank you...
|
|
|
11-10-2016, 07:17 AM
|
#4
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,894
|
Per LQ rules, do not post the same discussion multiple times. Duplicate discussions can be frustrating for other members. Try and pick the most relevant forum for your post. This thread has been closed.
|
|
|
All times are GMT -5. The time now is 10:51 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|