Hi, You should inspect the source file and clean it up for line breaks where it should not be. It is easy, jusr 2-3 places. Split into separate wsn1.scn file where that information is given. When done, the code works perfectly.
- Arne ----- Original Message ----- From: "Habeshawit2God" <bez2...@hotmail.co.uk> To: <ns-users@ISI.EDU> Sent: Tuesday, March 17, 2009 6:27 PM Subject: Re: [ns] sample code for wsn > > > Dear naveen prabu, > > As per your advise i tried it however it doesn't work and here is the > error > message it came up with i went to the line it is referring to and realize > that there is actually something wrong with it. Here is the error > message: > > siu06...@sie59a:~/Documents$ ns wsn1.tcl > bad option "file": must be add, info, remove, variable, vdelete, or vinfo > while executing > "trace file for wpan (special handling needed)" > (file "wsn1.tcl" line 47) > > > Dear nabeen, hoping to hear from you soon, i would like to thank you very > much in advance. > > Best regards, > > Habeshawit2God > > P.S please do not hesitate to drop me an e-mail using my personal e-mail > and > I would also appreciate it if you can give me reply between today and > tomorrow as i have to hand in my project on Thursday 19thMarch 2009!! > > > naveen prabu wrote: >> >> >> I have pasted sample tcl file and scenario file here... >> save scn file as wsn1.scn and tcl file as (say)wsn1.tcl and run tcl >> file... >> >> try runnin this....if any bugs then let me know... >> >> wsn1.tcl >> >> >> # ====================================================================== >> # Define options >> # ====================================================================== >> set val(chan) Channel/WirelessChannel ;# Channel Type >> set val(prop) Propagation/TwoRayGround ;# radio-propagation >> model >> set val(netif) Phy/WirelessPhy/802_15_4 >> set val(mac) Mac/802_15_4 >> 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) 25 ;# number of >> mobilenodes >> set val(rp) AODV ;# routing protocol >> set val(x) 50 >> set val(y) 50 >> >> set val(nam) wsn1.nam >> set val(traffic) ftp ;# cbr/poisson/ftp >> >> #read command line arguments >> proc getCmdArgu {argc argv} { >> global val >> 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]] >> } >> } >> getCmdArgu $argc $argv >> >> set appTime1 0.0 ;# in seconds >> set appTime2 0.3 ;# in seconds >> set appTime3 0.7 ;# in seconds >> set stopTime 100 ;# in seconds >> >> # Initialize Global Variables >> set ns_ [new Simulator] >> set tracefd [open ./wsn1.tr w] >> $ns_ trace-all $tracefd >> if { "$val(nam)" == "wsn1.nam" } { >> set namtrace [open ./$val(nam) w] >> $ns_ namtrace-all-wireless $namtrace $val(x) $val(y) >> } >> >> $ns_ puts-nam-traceall {# nam4wpan #} ;# inform nam that this is a >> trace file for wpan (special handling needed) >> >> Mac/802_15_4 wpanNam namStatus on ;# default = off (should be turned >> on before other 'wpanNam' commands can work) >> #Mac/802_15_4 wpanNam ColFlashClr gold ;# default = gold >> #Mac/802_15_4 wpanNam NodeFailClr grey ;# default = grey >> >> >> # For model 'TwoRayGround' >> set dist(5m) 7.69113e-06 >> set dist(9m) 2.37381e-06 >> set dist(10m) 1.92278e-06 >> set dist(11m) 1.58908e-06 >> set dist(12m) 1.33527e-06 >> set dist(13m) 1.13774e-06 >> set dist(14m) 9.81011e-07 >> set dist(15m) 8.54570e-07 >> set dist(16m) 7.51087e-07 >> set dist(20m) 4.80696e-07 >> set dist(25m) 3.07645e-07 >> set dist(30m) 2.13643e-07 >> set dist(35m) 1.56962e-07 >> set dist(40m) 1.20174e-07 >> Phy/WirelessPhy set CSThresh_ $dist(15m) >> Phy/WirelessPhy set RXThresh_ $dist(15m) >> >> # set up topography object >> set topo [new Topography] >> $topo load_flatgrid $val(x) $val(y) >> >> # Create God >> set god_ [create-god $val(nn)] >> >> set chan_1_ [new $val(chan)] >> >> # configure node >> >> $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) \ >> -topoInstance $topo \ >> -agentTrace OFF \ >> -routerTrace OFF \ >> -macTrace ON \ >> -movementTrace OFF \ >> #-energyModel "EnergyModel" \ >> #-initialEnergy 1 \ >> #-rxPower 0.3 \ >> #-txPower 0.3 \ >> -channel $chan_1_ >> >> for {set i 0} {$i < $val(nn) } {incr i} { >> set node_($i) [$ns_ node] >> $node_($i) random-motion 0 ;# disable random motion >> } >> >> source ./wsn1.scn >> >> # Setup traffic flow between nodes >> >> proc cbrtraffic { src dst interval starttime } { >> global ns_ node_ >> set udp($src) [new Agent/UDP] >> eval $ns_ attach-agent \$node_($src) \$udp($src) >> set null($dst) [new Agent/Null] >> eval $ns_ attach-agent \$node_($dst) \$null($dst) >> set cbr($src) [new Application/Traffic/CBR] >> eval \$cbr($src) set packetSize_ 70 >> eval \$cbr($src) set interval_ $interval >> eval \$cbr($src) set random_ 0 >> #eval \$cbr($src) set maxpkts_ 10000 >> eval \$cbr($src) attach-agent \$udp($src) >> eval $ns_ connect \$udp($src) \$null($dst) >> $ns_ at $starttime "$cbr($src) start" >> } >> >> proc poissontraffic { src dst interval starttime } { >> global ns_ node_ >> set udp($src) [new Agent/UDP] >> eval $ns_ attach-agent \$node_($src) \$udp($src) >> set null($dst) [new Agent/Null] >> eval $ns_ attach-agent \$node_($dst) \$null($dst) >> set expl($src) [new Application/Traffic/Exponential] >> eval \$expl($src) set packetSize_ 70 >> eval \$expl($src) set burst_time_ 0 >> eval \$expl($src) set idle_time_ [expr >> $interval*1000.0-70.0*8/250]ms ;# idle_time + pkt_tx_time = interval >> eval \$expl($src) set rate_ 250k >> eval \$expl($src) attach-agent \$udp($src) >> eval $ns_ connect \$udp($src) \$null($dst) >> $ns_ at $starttime "$expl($src) start" >> } >> >> if { ("$val(traffic)" == "cbr") || ("$val(traffic)" == "poisson") } { >> puts "\nTraffic: $val(traffic)" >> #Mac/802_15_4 wpanCmd ack4data on >> puts [format "Acknowledgement for data: %s" [Mac/802_15_4 wpanCmd >> ack4data]] >> set lowSpeed 0.5ms >> set highSpeed 1.5ms >> Mac/802_15_4 wpanNam PlaybackRate $lowSpeed >> $ns_ at [expr $appTime1+0.1] "Mac/802_15_4 wpanNam PlaybackRate >> $highSpeed" >> $ns_ at $appTime2 "Mac/802_15_4 wpanNam PlaybackRate $lowSpeed" >> $ns_ at [expr $appTime2+0.1] "Mac/802_15_4 wpanNam PlaybackRate >> $highSpeed" >> $ns_ at $appTime3 "Mac/802_15_4 wpanNam PlaybackRate $lowSpeed" >> $ns_ at [expr $appTime3+0.1] "Mac/802_15_4 wpanNam PlaybackRate >> $highSpeed" >> eval $val(traffic)traffic 19 6 0.2 $appTime1 >> eval $val(traffic)traffic 10 4 0.2 $appTime2 >> eval $val(traffic)traffic 3 2 0.2 $appTime3 >> Mac/802_15_4 wpanNam FlowClr -p AODV -c tomato >> Mac/802_15_4 wpanNam FlowClr -p ARP -c green >> if { "$val(traffic)" == "cbr" } { >> set pktType cbr >> } else { >> set pktType exp >> } >> Mac/802_15_4 wpanNam FlowClr -p $pktType -s 19 -d 6 -c blue >> Mac/802_15_4 wpanNam FlowClr -p $pktType -s 10 -d 4 -c green4 >> Mac/802_15_4 wpanNam FlowClr -p $pktType -s 3 -d 2 -c cyan4 >> $ns_ at $appTime1 "$node_(19) NodeClr blue" >> $ns_ at $appTime1 "$node_(6) NodeClr blue" >> $ns_ at $appTime1 "$ns_ trace-annotate \"(at $appTime1) >> $val(traffic) traffic from node 19 to node 6\"" >> $ns_ at $appTime2 "$node_(10) NodeClr green4" >> $ns_ at $appTime2 "$node_(4) NodeClr green4" >> $ns_ at $appTime2 "$ns_ trace-annotate \"(at $appTime2) >> $val(traffic) traffic from node 10 to node 4\"" >> $ns_ at $appTime3 "$node_(3) NodeClr cyan3" >> $ns_ at $appTime3 "$node_(2) NodeClr cyan3" >> $ns_ at $appTime3 "$ns_ trace-annotate \"(at $appTime3) >> $val(traffic) traffic from node 3 to node 2\"" >> } >> >> proc ftptraffic { src dst starttime } { >> global ns_ node_ >> set tcp($src) [new Agent/TCP] >> eval \$tcp($src) set packetSize_ 60 >> set sink($dst) [new Agent/TCPSink] >> eval $ns_ attach-agent \$node_($src) \$tcp($src) >> eval $ns_ attach-agent \$node_($dst) \$sink($dst) >> eval $ns_ connect \$tcp($src) \$sink($dst) >> set ftp($src) [new Application/FTP] >> eval \$ftp($src) attach-agent \$tcp($src) >> $ns_ at $starttime "$ftp($src) start" >> } >> >> if { "$val(traffic)" == "ftp" } { >> puts "\nTraffic: ftp" >> #Mac/802_15_4 wpanCmd ack4data off >> puts [format "Acknowledgement for data: %s" [Mac/802_15_4 wpanCmd >> ack4data]] >> set lowSpeed 0.20ms >> set highSpeed 1.5ms >> Mac/802_15_4 wpanNam PlaybackRate $lowSpeed >> $ns_ at [expr $appTime1+0.2] "Mac/802_15_4 wpanNam PlaybackRate >> $highSpeed" >> $ns_ at $appTime2 "Mac/802_15_4 wpanNam PlaybackRate $lowSpeed" >> $ns_ at [expr $appTime2+0.2] "Mac/802_15_4 wpanNam PlaybackRate >> $highSpeed" >> $ns_ at $appTime3 "Mac/802_15_4 wpanNam PlaybackRate $lowSpeed" >> $ns_ at [expr $appTime3+0.2] "Mac/802_15_4 wpanNam PlaybackRate 1ms" >> ftptraffic 19 6 $appTime1 >> ftptraffic 10 4 $appTime2 >> ftptraffic 3 2 $appTime3 >> Mac/802_15_4 wpanNam FlowClr -p AODV -c tomato >> Mac/802_15_4 wpanNam FlowClr -p ARP -c green >> Mac/802_15_4 wpanNam FlowClr -p tcp -s 19 -d 6 -c blue >> Mac/802_15_4 wpanNam FlowClr -p ack -s 6 -d 19 -c blue >> Mac/802_15_4 wpanNam FlowClr -p tcp -s 10 -d 4 -c green4 >> Mac/802_15_4 wpanNam FlowClr -p ack -s 4 -d 10 -c green4 >> Mac/802_15_4 wpanNam FlowClr -p tcp -s 3 -d 2 -c cyan4 >> Mac/802_15_4 wpanNam FlowClr -p ack -s 2 -d 3 -c cyan4 >> $ns_ at $appTime1 "$node_(19) NodeClr blue" >> $ns_ at $appTime1 "$node_(6) NodeClr blue" >> $ns_ at $appTime1 "$ns_ trace-annotate \"(at $appTime1) ftp traffic >> from node 19 to node 6\"" >> $ns_ at $appTime2 "$node_(10) NodeClr green4" >> $ns_ at $appTime2 "$node_(4) NodeClr green4" >> $ns_ at $appTime2 "$ns_ trace-annotate \"(at $appTime2) ftp traffic >> from node 10 to node 4\"" >> $ns_ at $appTime3 "$node_(3) NodeClr cyan3" >> $ns_ at $appTime3 "$node_(2) NodeClr cyan3" >> $ns_ at $appTime3 "$ns_ trace-annotate \"(at $appTime3) ftp traffic >> from node 3 to node 2\"" >> } >> >> # defines the node size in nam >> for {set i 0} {$i < $val(nn)} {incr i} { >> $ns_ initial_node_pos $node_($i) 2 >> } >> >> # Tell nodes when the simulation ends >> for {set i 0} {$i < $val(nn) } {incr i} { >> $ns_ at $stopTime "$node_($i) reset"; >> } >> >> $ns_ at $stopTime "stop" >> $ns_ at $stopTime "puts \"\nNS EXITING...\"" >> $ns_ at $stopTime "$ns_ halt" >> >> proc stop {} { >> global ns_ tracefd val env >> $ns_ flush-trace >> close $tracefd >> set hasDISPLAY 0 >> foreach index [array names env] { >> #puts "$index: $env($index)" >> if { ("$index" == "DISPLAY") && ("$env($index)" != "") } { >> set hasDISPLAY 1 >> } >> } >> if { ("$val(nam)" == "wsn1.nam") && ("$hasDISPLAY" == "1") } { >> exec ./nam wsn1.nam & >> } >> } >> >> puts "\nStarting Simulation..." >> $ns_ run >> >> >> -------------------------------- >> wsn1.scn >> >> # >> # nodes: 25, pause: 2.00, max speed: 2.00 max x = 50.00, max y: 50.00 >> # >> $node_(0) set X_ 26.608377307314 >> $node_(0) set Y_ 49.446991827566 >> $node_(0) set Z_ 0.000000000000 >> $node_(1) set X_ 49.337311778721 >> $node_(1) set Y_ 48.582820874924 >> $node_(1) set Z_ 0.000000000000 >> $node_(2) set X_ 27.437938215931 >> $node_(2) set Y_ 30.091658830425 >> $node_(2) set Z_ 0.000000000000 >> $node_(3) set X_ 10.568766842667 >> $node_(3) set Y_ 47.453389414657 >> $node_(3) set Z_ 0.000000000000 >> $node_(4) set X_ 32.496269526711 >> $node_(4) set Y_ 2.257450139045 >> $node_(4) set Z_ 0.000000000000 >> $node_(5) set X_ 26.476535726599 >> $node_(5) set Y_ 38.646396828920 >> $node_(5) set Z_ 0.000000000000 >> $node_(6) set X_ 49.430596917301 >> $node_(6) set Y_ 31.320042376073 >> $node_(6) set Z_ 0.000000000000 >> $node_(7) set X_ 20.045665842364 >> $node_(7) set Y_ 32.537008965783 >> $node_(7) set Z_ 0.000000000000 >> $node_(8) set X_ 13.641089465783 >> $node_(8) set Y_ 28.871428688349 >> $node_(8) set Z_ 0.000000000000 >> $node_(9) set X_ 2.125856848941 >> $node_(9) set Y_ 9.049644538277 >> $node_(9) set Z_ 0.000000000000 >> $node_(10) set X_ 0.596871605178 >> $node_(10) set Y_ 0.816174228621 >> $node_(10) set Z_ 0.000000000000 >> $node_(11) set X_ 8.828197591068 >> $node_(11) set Y_ 34.402175912553 >> $node_(11) set Z_ 0.000000000000 >> $node_(12) set X_ 18.759762507870 >> $node_(12) set Y_ 25.069997591097 >> $node_(12) set Z_ 0.000000000000 >> $node_(13) set X_ 13.277017351151 >> $node_(13) set Y_ 5.522149009306 >> $node_(13) set Z_ 0.000000000000 >> $node_(14) set X_ 28.935083056450 >> $node_(14) set Y_ 37.156742480258 >> $node_(14) set Z_ 0.000000000000 >> $node_(15) set X_ 23.507724673396 >> $node_(15) set Y_ 3.566772846479 >> $node_(15) set Z_ 0.000000000000 >> $node_(16) set X_ 20.236128396148 >> $node_(16) set Y_ 45.484419961171 >> $node_(16) set Z_ 0.000000000000 >> $node_(17) set X_ 45.709636471608 >> $node_(17) set Y_ 48.353113573382 >> $node_(17) set Z_ 0.000000000000 >> $node_(18) set X_ 45.610349971557 >> $node_(18) set Y_ 49.787732692400 >> $node_(18) set Z_ 0.000000000000 >> $node_(19) set X_ 24.345058881159 >> $node_(19) set Y_ 19.614188426582 >> $node_(19) set Z_ 0.000000000000 >> $node_(20) set X_ 35.972132273531 >> $node_(20) set Y_ 10.620805728046 >> $node_(20) set Z_ 0.000000000000 >> $node_(21) set X_ 49.626765649851 >> $node_(21) set Y_ 14.028905860151 >> $node_(21) set Z_ 0.000000000000 >> $node_(22) set X_ 14.914806804685 >> $node_(22) set Y_ 24.094071765795 >> $node_(22) set Z_ 0.000000000000 >> $node_(23) set X_ 28.443020411336 >> $node_(23) set Y_ 24.367299319338 >> $node_(23) set Z_ 0.000000000000 >> $node_(24) set X_ 48.102836431793 >> $node_(24) set Y_ 22.394995544608 >> $node_(24) set Z_ 0.000000000000 >> >> ------------- >> >> >> > > -- > View this message in context: > http://www.nabble.com/sample-code-for-wsn-tp21750960p22563029.html > Sent from the ns-users mailing list archive at Nabble.com. > >