ns: _o108malicious: invalid command name "_o108malicious" while executing "_o108malicious" - tcl

I am simulating Wireless Sensor Network Using NS2.35 and I get an error
ns: _o108malicious: invalid command name "_o108malicious"
while executing "o108malicious"
when i add $ns at 3.2 "[$node($id) set ragent_]malicious"this line i get
this error.
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(ifqlen) 150
set val(nn) 25
set val(rp) AODV
set val(x) 800
set val(y) 500
set val(stop) 150
#-------Event scheduler object creation--------#
set ns [new Simulator]
#used to schedule the events that are running at the same time
$ns use-scheduler Heap
#Creating trace file and nam file
set tracefd [open aodv.tr w]
set namtrace [open aodv.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
# configure the nodes
$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 \
-movementTrace ON
# node creation
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
$node_($i) color "black"
$node_($i) label Node$i
}
#initial location of nodes
for {set i 0} {$i < $val(nn)} {incr i} {
$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0
$node_($i) color "green"
}
for {set i 0} {$i < $val(nn)} {incr i} {
$ns at 0.1 "$node_($i) color darkviolet"
$ns at 0.1 "$node_($i) label Node$i"
}
#generation of movements
$ns at 2.0 "$node_(0) setdest 20.0 10.0 0.0"
$ns at 5.0 "$node_(24) setdest 60.0 50.0 50.0"
$ns at 7.0 "$node_(2) setdest 120.0 100.0 50.0"
$ns at 0.0 "$node_(17) setdest 140.0 150.0 50.0"
$ns at 0.0 "$node_(20) setdest 160.0 180.0 50.0"
$ns at 12.0 "$node_(19) setdest 130.0 230.0 6.0"
$ns at 23.0 "$node_(5) setdest 40.0 165.0 9.0"
$ns at 20.0 "$node_(7) setdest 50.0 180.0 13.0"
$ns at 3.0 "$node_(4) setdest 80.0 156.0 5.0"
$ns at 6.0 "$node_(10) setdest 56.0 200.0 10.0"
$ns at 13.0 "$node_(15) setdest 88.0 20.0 45.0"
$ns at 6.0 "$node_(3) setdest 177.0 120.0 45.0"
$ns at 23.0 "$node_(1) setdest 140.0 70.0 20.0"
set fp2 [open "/opt/ns-allinone-2.35/ns-2.35/input.txt" r]
set filed [read $fp2]
puts $filed
set data [split $filed "\n"]
puts $data
foreach line2 $data {
set length2 [string length $line2]
if {$length2 != 0} {
lassign $line2 src dest
puts $src
set tcp1 [new Agent/TCP/Newreno]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns attach-agent $node_($src) $tcp1
$ns attach-agent $node_($dest) $sink1
$ns connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 3.0 "$node_($src) color brown"
$ns at 3.0 "$node_($dest) color brown"
$ns at 3.0 "$ftp1 start"
}
}
close $fp2
set fp1 [open "/opt/ns-allinone-2.35/ns-2.35/mali.txt" r]
set file_data [read $fp1]
set data1 [split $file_data "\n"]
foreach line $data1 {
set length1 [string length $line]
if {$length1 !=0} {
set id $line
$ns at 3.2 "[$node_($id) set ragent_]malicious"
$ns at 3.2 "$node_($id) color red"
$ns at 3.2 "$node_($id) label malicious"
}
}
close $fp1
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 20 defines the node size for nam
$ns initial_node_pos $node_($i) 20
}
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";
}
# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
#$ns at 149.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam aodv.nam &
exit 0
}
#$ns at 150.01 "puts \"end simulation\" ; $ns halt"
$ns run
enter code here
input.txt
5 4
3 9
6 10
1 0
mali.txt
5
3

When the "set malicious" line $ns at 3.2 "[$node_($id) set ragent_]malicious" ... is edited to $ns at 3.2 "[$node_($id) set ragent_] hacker" ... then your files are working fairly OK :
$ ns235-malicious mal-wsn.tcl
num_nodes is set 25
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
5 4
3 9
6 10
1 0
{5 4} {3 9} {6 10} {1 0 } {}
5
3
6
1
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
ns: scheduler going backwards in time from 6.000000 to 0.000000.
The files aodv.nam 200.0kB, aodv.tr 184.0kB are created. $ nam aodv.nam & : OK animation and communication. $ awk -f tess-Packets.awk aodv.tr : OK, the output file "Packets-arrival-time.txt" has 338 lines.
Not quite stable. Can also end the simulation with
SORTING LISTS ...DONE !
Direction for pkt-flow not specified; Sending pkt up the stack on default.
... And NAM opens OK. The files are now: aodv.nam 328.0kB, aodv.tr 308.0kB .
Perfect. Ends with SORTING LISTS ...DONE!. Animation: Perfect. Files are aodv.nam 7.0 MB, aodv.tr 5.7 MB .
Direction for pkt-flow not specified; Sending pkt up the stack on default.
check_pktRTS:Invalid MAC Control subtype
... Conclusion : You will have to run the file several times to get a perfect result. Can be 10 times if Ubuntu. 3 - 4 times if an rpm based OS.
Malicious build example https://groups.google.com/forum/?fromgroups#!searchin/ns-users/malicious%7Csort:date/ns-users/-3JfDWhN2fY/BiOwZuWSBwAJ → 11/10/17.

Related

How to fix ‘can't read "node_(0)": no such variable’ error in tcl?

I'm setting up a net environment that there are n nodes surrounded by a circle with DSR protocol. However, when I fixed most of the errors, the most confused error that I couldn't solve like the title. How to fix 'can't read "node_(0)": no such variable' error? Didn't I already define it in the for loop at line 86?
I can't find a solution to this problem and when I changed
set node_($i) [$ns node]
to
set node_($i) [$ns_ node]
Here's the full code.
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) CMUPriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(ifqlan) 50
set val(nn) 0
set val(rp) DSR
set val(x) 1000
set val(y) 1000
set val(r) 400
proc usage {} \
{
global argv0
puts "\nusage: $argv0 \[-nn node\] \[-r r\] \[-x x\] \[-y y\]\n"
puts "note: \[-nn nodes\] is essential, and the others are optional.\n"
}
proc getval {argc argv} \
{
global val
lappend vallist nn r x y z
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string range $arg 0 0] != "-"} continue
set name [string range $arg 1 end]
set val($name) [lindex $argv[expr $i+1]]
}
}
getval $argc $argv
if {$val(nn) == 0} {
usage
exit
}
set ns [new Simulator]
set tracefd [open circle.tr w]
$ns trace-all $tracefd
set namtracefd [open circle.nam w]
$ns namtrace-all-wireless $namtracefd $val(x) $val(y)
proc finish {} \
{
global ns tracefd namtracefd
$ns flush-trace
#close the trace file
close $tracefd
close $namtracefd
#execute nam on the trace file
exec nam circle.nam &
exit 0
}
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
$ns node-config -addressType def\
-adhocRouting $val(rp)\
-llType $val(ll)\
-macType $val(mac)\
-ifqType $val(ifq)\
-ifqLan $val(ifqlan)\
-antType $val(ant)\
-propType $val(prop)\
-phyType $val(netif)\
-channelType $val(chan)\
-topoInstance $topo\
-agenttrace ON\
-routertrace ON\
-mactrace OFF\
-movementtrace OFF
##################################
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
$node_($i) set X_ [expr $val(r) * cos($i * 2 * 3.14159 / $val(nn))]
$node_($i) set Y_ [expr $val(r) * sin($i * 2 * 3.14159 / $val(nn))]
$node_($i) set Z_ 0
$ns initial_node_pos $node_($i) [expr $val(x) / 10]
}
##################################
set tcp [new Agent/UDP]
$ns attach-agent $node_(0) $tcp
set null [new Agent/Null]
$ns attach-agent $node_([expr $val(nn) / 2]) $null
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 5000
$cbr set interval_ 0.05
$cbr attach-agent $tcp
$ns connect $tcp $null
$ns at 0.1 "$cbr start"
$ns at 3.0 "$cbr stop"
$ns at 5.0 "finish"
$ns run
When i type ns circle.tcl -nn 12, I expect the output:
num_node is set 12
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_and distCST_
SORTING LISTS ...DONE!
Please help me, I've been stuck for a long time.
That error will be produced whenever val(nn) is not greater than zero, as then the loop that creates the nodes:
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
$node_($i) set X_ [expr $val(r) * cos($i * 2 * 3.14159 / $val(nn))]
$node_($i) set Y_ [expr $val(r) * sin($i * 2 * 3.14159 / $val(nn))]
$node_($i) set Z_ 0
$ns initial_node_pos $node_($i) [expr $val(x) / 10]
}
will simply decide that it has nothing to do and not execute the body of the loop even once. What might cause that? Well, if we look at the argument parsing procedure:
proc getval {argc argv} \
{
global val
lappend vallist nn r x y z
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string range $arg 0 0] != "-"} continue
set name [string range $arg 1 end]
set val($name) [lindex $argv[expr $i+1]]
}
}
we can see a number of problems, of which the biggest is this (on the line with set val($name):
lindex $argv[expr $i+1]
The problem here is the lack of a space between $argv and the expression evaluation; that concatenates the two strings before feeding the result into lindex as a single argument! (lindex with a single argument just returns that argument, using the principle of “do nothing, gracefully”.) That's not even syntactically correct in all cases, but probably was in the cases you tried and resulted in val(nn) being set to something like the string -nn 101. Now, the < operator (in the node generation loop) will use ASCII ordering whenever either side looks non-numeric and that string has extra garbage in it so it is definitely non-numeric. Oh dear. (- is ASCII character code 45 and 0 is ASCII character code 48, so - comes before 0.) This isn't what you wanted!
Here's a fixed version of the argument parser:
proc getval {argc argv} {
global val
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string index $arg 0] eq "-"} {
set val([string range $arg 1 end]) [lindex $argv [incr i]]
}
}
}
Remember, in Tcl the spaces are important!
Add four lines, and the simulation can be run.
set val(ifqlen) 50 ;# added (Line 7)
set val(nn) 10 ;# added (Line 10)
.
-movementtrace OFF \
-ifqLen $val(ifqlen) ;# added (Line 85)
.
for {set i 0} {$i < [expr $val(nn)]} {incr i} {
set node_($i) [$ns node] ;# added (Line 89)
Reason for set val(nn) 10 : I didn't get the [$argv]'s to work. ( $ ns file.tcl -nn 10 or $ ns file.tcl nn 10 )
Link to the edited file : https://www.dropbox.com/s/m7zsnga6wf29r95/2Ezio-Auditore-DSR.tcl?dl=0
All ~3500 ns2 simulations ex https://drive.google.com/drive/folders/0B7S255p3kFXNSmRYb2lGcDRUdWs?usp=sharing
EDIT : The 'argument parser' by #Donal Fellows was added, can now run with $ ns file.tcl -nn 12. New example https://www.dropbox.com/s/br6qaeg5kj73k14/4-circle-Ezio-Auditore.tar.gz?dl=0
ns2 analyzing scripts https://drive.google.com/drive/folders/1rU_MFAEl1GCLMTJPLR3zbxPxkQQHkQ7T?usp=sharing

VBFP doesnt work probably in aqua-sim

I used VBF routing, in aqua-sim. However, i noticed that the source packet never reaches the sink! and consumed energy exceed the initial energy!
what is the causes for that?
Here is the tcl file
set opt(chan) Channel/UnderwaterChannel
set opt(prop) Propagation/UnderwaterPropagation
set opt(netif) Phy/UnderwaterPhy
set opt(mac) Mac/UnderwaterMac/BroadcastMac
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(energy) EnergyModel
set opt(txpower) 2.0
set opt(rxpower) 0.75
set opt(initialenergy) 10000
set opt(idlepower) 0.008
set opt(ant) Antenna/OmniAntenna
set opt(filters) GradientFilter ;# options can be one or more of
;# TPP/OPP/Gear/Rmst/SourceRoute/Log/TagFilter
set opt(minspeed) 0.2 ;#minimum speed of node
set opt(maxspeed) 3 ;#maximum speed of node
set opt(speed) 0.5 ;#speed of node
set opt(position_update_interval) 0.3 ;# the length of period to update node's position
set opt(packet_size) 50 ;#50 bytes
set opt(routing_control_packet_size) 20 ;#bytes
set opt(ifqlen) 500 ;# max queue length in if
set opt(nn) 401 ;# number of nodes
set opt(x) 3000 ;# X dimension of the topography
set opt(y) 3000 ;# Y dimension of the topography
set opt(z) 1000
set opt(seed) 11
set opt(stop) 5000 ;# simulation time
set opt(prestop) 4990 ;# time to prepare to stop
set opt(tr) "test.tr" ;# trace file
set opt(datafile) "test.data"
set opt(nam) "test.nam" ;# nam file
set opt(adhocRouting) Vectorbasedforward
set opt(width) 100
set opt(interval) 10.0
set opt(range) 500 ;#range of each node in meters
if { $argc > 0 } {
set opt(seed) [lindex $argv 0]
set opt(nn) [lindex $argv 1]
set opt(datafile) [lindex $argv 2]
}
puts "the file name is $opt(datafile)"
puts "the sending interval is $opt(interval)"
# ==================================================================
LL set mindelay_ 50us
LL set delay_ 25us
LL set bandwidth_ 0 ;# not used
Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
#Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Z_ 0.05
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
Agent/Vectorbasedforward set hop_by_hop_ 0
Mac/UnderwaterMac set bit_rate_ 1.0e4 ;#10kbps
Mac/UnderwaterMac set encoding_efficiency_ 1
Mac/UnderwaterMac/BroadcastMac set packetheader_size_ 0 ;# #of bytes
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/UnderwaterPhy set CPThresh_ 10 ;#10.0
Phy/UnderwaterPhy set CSThresh_ 0 ;#1.559e-11
Phy/UnderwaterPhy set RXThresh_ 0 ;#3.652e-10
#Phy/WirelessPhy set Rb_ 2*1e6
Phy/UnderwaterPhy set Pt_ 0.2818
Phy/UnderwaterPhy set freq_ 25 ;# 25khz
Phy/UnderwaterPhy set K_ 2.0 ;# spherical spreading
# Initialize Global Variables
#
#set sink_ 1
set ns_ [new Simulator]
set topo [new Topography]
$topo load_cubicgrid $opt(x) $opt(y) $opt(z)
#$ns_ use-newtrace
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd
set nf [open $opt(nam) w]
$ns_ namtrace-all-wireless $nf $opt(x) $opt(y)
set data [open $opt(datafile) a]
set total_number [expr $opt(nn)-1]
set god_ [create-god $opt(nn)]
$ns_ at 0.0 "$god_ set_filename $opt(datafile)"
set chan_1_ [new $opt(chan)]
global defaultRNG
$defaultRNG seed $opt(seed)
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
#-channelType $opt(chan) \
-agentTrace OFF \
-routerTrace OFF \
-macTrace ON\
-topoInstance $topo\
-energyModel $opt(energy)\
-txPower $opt(txpower)\
-rxPower $opt(rxpower)\
-initialEnergy $opt(initialenergy)\
-idlePower $opt(idlepower)\
-channel $chan_1_
puts "Width=$opt(width)"
#Set the Sink node
set node_(0) [ $ns_ node 0]
$node_(0) set sinkStatus_ 1
$god_ new_node $node_(0)
$node_(0) set X_ 2000
$node_(0) set Y_ 2000
$node_(0) set Z_ 1
$node_(0) set -cx 2000
$node_(0) set -cy 2000
$node_(0) set -cz 1
$node_(0) set passive 1
set rt [$node_(0) set ragent_]
$rt set control_packet_size $opt(routing_control_packet_size)
set a_(0) [new Agent/UWSink]
$ns_ attach-agent $node_(0) $a_(0)
$a_(0) attach-vectorbasedforward $opt(width)
$a_(0) cmd set-range $opt(range)
$a_(0) cmd set-target-x 2000
$a_(0) cmd set-target-y 2000
$a_(0) cmd set-target-z 1
$a_(0) cmd set-filename $opt(datafile)
$a_(0) cmd set-packetsize $opt(packet_size) ;# # of bytes
for { set i 1 } { $i<$opt(nn)-1 } {incr i } {
set node_($i) [$ns_ node $i]
$node_($i) set sinkStatus_ 1
$god_ new_node $node_($i)
$node_($i) set passive 1
set rt [$node_($i) set ragent_]
$rt set control_packet_size $opt(routing_control_packet_size)
$node_($i) set max_speed $opt(maxspeed)
$node_($i) set min_speed $opt(minspeed)
#$node_($i) set position_update_interval_ $opt(position_update_interval)
set a_($i) [new Agent/UWSink]
$ns_ attach-agent $node_($i) $a_($i)
$a_($i) attach-vectorbasedforward $opt(width)
$a_($i) cmd set-range $opt(range)
$a_($i) cmd set-target-x -20
$a_($i) cmd set-target-y -10
$a_($i) cmd set-target-z -20
$a_($i) cmd set-filename $opt(datafile)
$a_($i) cmd set-packetsize $opt(packet_size) ;
}
Then i give the position of all my nodes from 1-399, as the following
$node_(1) set X_ 2136.167656
$node_(1) set Y_ 295.493365
$node_(1) set Z_ 584.859352
$node_(2) set X_ 38.448393
$node_(2) set Y_ 1111.699107
$node_(2) set Z_ 375.380589
$node_(3) set X_ 1937.160663
$node_(3) set Y_ 1171.175274
$node_(3) set Z_ 532.478177
..
$node_(399) set X_ 234.898387
$node_(399) set Y_ 1004.866538
$node_(399) set Z_ 985.310608
the source node and the rest of tcl file is:
#Set the source node
set node_($total_number) [$ns_ node $total_number]
$god_ new_node $node_($total_number)
$node_($total_number) set sinkStatus_ 1
$node_($total_number) set X_ 1650.370304
$node_($total_number) set Y_ 1166.115416
$node_($total_number) set Z_ 274.908599
$node_($total_number) set-cx 1650.370304
$node_($total_number) set-cy 1166.115416
$node_($total_number) set-cz 274.908599
set rt [$node_($total_number) set ragent_]
$rt set control_packet_size $opt(routing_control_packet_size)
set a_($total_number) [new Agent/UWSink]
$ns_ attach-agent $node_($total_number) $a_($total_number)
$a_($total_number) attach-vectorbasedforward $opt(width)
$a_($total_number) cmd set-range $opt(range)
$a_($total_number) cmd set-target-x 2000
$a_($total_number) cmd set-target-y 2000
$a_($total_number) cmd set-target-z 1
$a_($total_number) cmd set-filename $opt(datafile)
$a_($total_number) cmd set-packetsize $opt(packet_size) ;# # of bytes
set start_time 1.33
for { set j 1 } { $i<$opt(nn)-1 } {incr j } {
$a_($j) set data_rate_ [expr 1.0/$opt(interval)]
$ns_ at $start_time "$a_($j) cbr-start"
set start_time [expr $start_time+0.5 ]
$ns_ at $opt(stop).001 "$a_($j) terminate"
}
# make nam workable
set node_size 10
for {set k 0} { $k<$opt(nn)} {incr k} {
$ns_ initial_node_pos $node_($k) $node_size
}
set opt(stop2) [expr $opt(stop)+200]
puts "Node $total_number is sending first!!"
#$ns_ at 1.33 "$a_($total_number) cbr-start"
#$ns_ at $opt(stop).001 "$a_($total_number) terminate"
$ns_ at $opt(stop2).002 "$a_(0) terminate"
$ns_ at $opt(stop2).003 "$god_ compute_energy"
$ns_ at $opt(stop2).004 "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop2).005 "puts \"NS EXISTING...\"; $ns_ halt"
puts $data "New simulation...."
puts $data "nodes = $opt(nn), maxspeed = $opt(maxspeed), minspeed = $opt(minspeed), random_seed = $opt(seed), sending_interval_=$opt(interval), width=$opt(width)"
puts $data "x= $opt(x) y= $opt(y) z= $opt(z)"
close $data
puts "starting Simulation..."
$ns_ run

Couldn't run tcl script in ns2

When I try to run my own tcl script (10.tcl) in ns2.34, it gives me this error.
couldn't read file "/home/bony/ns-2.34/ns-allinone-2.34/ns-2.34.aodv":
no such file or directory
while executing
"source.orig /home/bony/ns-2.34/ns-allinone-2.34/ns-2.34.aodv"
("uplevel" body line 1)
invoked from within
"uplevel source.orig [list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
..."
(procedure "source" line 8)
invoked from within
"$ns_ $path.$valrp"
(file "10.tcl" line 20)
This is the 10.tcl code I'm using. when I try to run this 10.tcl file in ns2 in Fedora, it gives me above error.
#===================================
# Simulation parameters setup
#===================================
set ns_ source
set path /home/bony/ns-2.34/ns-allinone-2.34/ns-2.34
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) 10 ;# number of mobilenodes
set valrp aodv ;# routing protocol
set val(x) 943 ;# X dimension of topography
set val(y) 567 ;# Y dimension of topography
set val(stop) 20.0 ;# time of simulation end
set speed 10
$ns_ $path.$valrp
set packet_size 512;#packetsize
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Setup topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $valrp \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 10 nodes
set n(0) [$ns node]
$n(0) set X_ 284
$n(0) set Y_ 380
$n(0) set Z_ 0.0
$ns initial_node_pos $n(0) 20
set n(1) [$ns node]
$n(1) set X_ 343
$n(1) set Y_ 195
$n(1) set Z_ 0.0
$ns initial_node_pos $n(1) 20
set n(2) [$ns node]
$n(2) set X_ 411
$n(2) set Y_ 308
$n(2) set Z_ 0.0
$ns initial_node_pos $n(2) 20
set n(3) [$ns node]
$n(3) set X_ 468
$n(3) set Y_ 460
$n(3) set Z_ 0.0
$ns initial_node_pos $n(3) 20
set n(4) [$ns node]
$n(4) set X_ 567
$n(4) set Y_ 363
$n(4) set Z_ 0.0
$ns initial_node_pos $n(4) 20
set n(5) [$ns node]
$n(5) set X_ 586
$n(5) set Y_ 194
$n(5) set Z_ 0.0
$ns initial_node_pos $n(5) 20
set n(6) [$ns node]
$n(6) set X_ 698
$n(6) set Y_ 343
$n(6) set Z_ 0.0
$ns initial_node_pos $n(6) 20
set n(7) [$ns node]
$n(7) set X_ 698
$n(7) set Y_ 467
$n(7) set Z_ 0.0
$ns initial_node_pos $n(7) 20
set n(8) [$ns node]
$n(8) set X_ 783
$n(8) set Y_ 186
$n(8) set Z_ 0.0
$ns initial_node_pos $n(8) 20
set n(9) [$ns node]
$n(9) set X_ 843
$n(9) set Y_ 361
$n(9) set Z_ 0.0
$ns initial_node_pos $n(9) 20
for {set i 0} { $i < $val(nn)} {incr i} {
set tcp($i) [new Agent/TCP]
$ns attach-agent $n($i) $tcp($i)
set sink($i) [new Agent/LossMonitor]
$ns attach-agent $n($i) $sink($i)
}
#===================================
# Agents Definition
#===================================
#===================================
# Applications Definition
#===================================
proc attach-CBR-traffic { node sink size interval } {
#Get an instance of the 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_ .05
#Attach CBR source to sink;
$ns connect $cbr $sink
return $cbr
}
set cbr00 [attach-CBR-traffic $n(0) $sink(9) 512 $interval]
$ns at 1.21 "$cbr00 start"
$ns at 0.86 "$n(0) add-mark MARK darkgreen square"
$ns at 0.86 "$n(0) label Sender"
$ns at 0.86 "$n(9) add-mark MARK magenta circle"
$ns at 0.86 "$n(9) label Receiver"
for {set i 0} {$i < $val(nn) } {incr i} {
set timemin 1
set timemax 10
set timemaxFactor [expr [expr $timemax + 1] - $timemin]
set timevalue [expr int([expr rand() * 100])]
set timevalue [expr [expr $timevalue % $timemaxFactor] + $timemin]
set xmin 500
set xmax 1200
set xmaxFactor [expr [expr $xmax + 1] - $xmin]
set xvalue [expr int([expr rand() * 100])]
set xvalue [expr [expr $xvalue % $xmaxFactor] + $xmin]
set ymin 50
set ymax 800
set ymaxFactor [expr [expr $ymax + 1] - $ymin]
set yvalue [expr int([expr rand() * 100])]
set yvalue [expr [expr $yvalue % $ymaxFactor] + $ymin]
$ns at $timevalue "$n($i) setdest $xvalue $yvalue $speed"
}
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec sed -i "/d -t /d" out.nam
exec nam out.nam &
exec awk -f pdf.awk out.tr > Results
exec awk -f e2edelay.awk out.tr >> Results
exec awk -f throughput.awk out.tr >> Results
exec awk -f control_overhead.awk out.tr >> Results
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n($i) reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

How to implement DSR and DSDV Code in NS-2

How to implement the tcl script for DSR protocol for 50 node in Ns-2?
Also i need the code for DSDV protocol i am doing a performance evaluation for them.
The DSDV c++ code : ns-2.3x/dsdv/{ dsdv.cc, dsdv.h, rtable.cc, rtable.h }.
Tcl scripts with DSR : All scripts with a line like ...
set opt(adhocRouting) DSR
or
set opt(rp) DSR
or
set val(rp) DSR
DSR examples : dsr-examples-04.2015.tar.gz
https://drive.google.com/file/d/0B7S255p3kFXNNFJzNGxRd25Zd3c/view?usp=sharing
DSDV examples : dsdv-examples.tar.gz
https://drive.google.com/file/d/0B7S255p3kFXNTHdTcnpHVFRRZzQ/view?usp=sharing
You don't "implement the tcl script".
Tcl scripts are just to be run, with the executable 'ns' : ns file.tcl
And most files.tcl can be run from a random folder, any location ( outside ns2.) Some files.tcl will require to be run from a particular folder, e.g.
ns-2.3x/tcl/ex/
ns2
#----------------------------------------------------------------
# Definition of the physical layer
#----------------------------------------------------------------
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
#-----------------------------------------------------------------
# Scenario parameters
#------------------------------------------------------------------
set val(x) 2000 ;# X dimension of the topography
set val(y) 2000 ;# Y dimension of the topography
set val(ifqlen) 100 ;# max packet in queue
set val(seed) 0.0 ;#random seed
set val(adhocRouting) DSR ;
set val(nn) 50 ;# how many nodes are simulated
set val(cp) < cbr file >
set val(sc) < scen file >
set val(stop) 200 ;# simulation time
#---------------------------------------------------------------------
# Set up simulator objects
#---------------------------------------------------------------------
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# create trace object for ns and nam
set tracefd [open out.tr w]
$ns_ use-newtrace ;# use the new wireless trace file format
set namtrace [open out.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# define topology
$topo load_flatgrid $val(x) $val(y)
# Create God
set god_ [create-god $val(nn)]
$ns_ node-config -adhocRouting $val(adhocRouting) \
-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 ON
# Create the specified number of nodes [$val(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
#$ns at 0.0 "$node_(0) color blue"
$node_($i) random-motion 0 ;# disable random motion
}
for {set i 0} {$i < $val(nn) } {incr i} {
$node_($i) color blue
$ns_ at 0.0 "$node_($i) color cyan"
}
# Define node movement model
puts "Loading connection pattern..."
source $val(cp)
# Define traffic model
puts "Loading scenario file..."
source $val(sc)
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
# 50 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
# puts "Processing node $i"
$ns_ initial_node_pos $node_($i) 50
}
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
}
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
# dump the initial simulation info to the trace file
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
puts "Starting Simulation..."
$ns_ run
To generate node traffic and scenario file use this link
change "set val(adhocRouting) DSR ;" to "set val(adhocRouting) DSDV ;" to perform DSDV protocol

how to make the mobile nodes static in tcl?

code:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(ant) Antenna/OmniAntenna
set val(ll) LL
set val(ifq) Queue/DropTail/PriQueue
set val(ifqlen) 50
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(rp) DSDV
set val(nn) 15
set val(x) 700
set val(y) 500
set val(stop) 130
set ns [new Simulator]
set tracefd [open trust.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open trust.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god (1)
#create-god (3)
$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 \
-movementTrace OFF\
-energyModel "EnergyModel" \
-initialEnergy 50
# Energy model
$ns node-config -energyModel EnergyModel \
-initialEnergy 50 \
-txPower 0.75
#-rxPower 0.25 \
#idlePower 0.0 \
#sensePower 0.0
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
}
$ns at 0.0 "$ns trace-annotate \"MOBILE NODE MOVEMENTS\""
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(1) $tcp
$ns attach-agent $node_(3) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
#setting initial position:
for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $node_($i) 30
}
#$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 130.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam trust.nam &
}
$ns run
this code run but the mobile nodes are dynamic each time how to make the dynamic mobile nodes to static?
how to make it static mobile nodes and need to do randomized overhearing in the ns2 tcl code
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
$node_($i) random-motion 0 ;# disable random motion
}
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
}
This code sets the mobility of the nodes. You can comment this code and see. The nodes should then be static.