Re: [ns] How to get the Nodes' coordinate from TCL to C++
Hi Samira, I had the same question and i got the following reply from Mr. Keven Sheth that turned out to be useful. What he answered specifically is how to calculate the distances between to nodes, which uses the coordinates of the nodes by accessing them from struct mb_node in file God.cc (in ./mobile). After retrieving the nodes coordinates i think it becomes an easy task to pass them to the MAC layer. I also found the same solution that Keven proposed at this link: http://www.cse.msu.edu/~wangbo1/ns2/nshowto2.html Below i will paste Keven's original reply. I hope it turns out useful. Cheers, Mathiew KEVIN'S REPLY Hi Mathiew I needed to the same in my project. what I did is used god object. you can study and you can do many more things using it . here I am just describing what I did: I added following function in ns-2.33/mobile/god.cc (you will need to add declaration in god.h) double God::getdistance(int i,int k) { double x1=mb_node[i]-X(); double y1=mb_node[i]-Y(); double x2=mb_node[k]-X(); double y2=mb_node[k]-Y(); double distance; distance=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))); return distance; } then I was able to get distance between two nodes by writing following code in c++ God::instance()-getdistance(i,k); // i and k are the id of the nodes you will also need to include following statements in your .tcl file 1 after creating topography set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] 2. when you are dynamically creating nodes for { set i 0 } { $i $val(nn) } { incr i } { set node_($i) [$ns_ node $i] $node_($i) random-motion 0 ;# disable random motion $god_ new_node $node_($i) } following is a function of my agent for your reference: void Manetconf::neighbors(int i) { int nodes=God::instance()-nodes(); coutneighbors of node i:endl; for(int k=0;knodes;k++) { if(k!=i) { if(God::instance()-IsNeighbor(i,k)) coutk:God::instance()-getdistance(i,k) yesendl; else coutk:God::instance()-getdistance(i,k) noendl; } } coutendl; } --- Quoting samyar@gmail.com: hi Mathiew I have exactly same as your problem. I want to send node coordinate or position to MAC layer and amke some desicion base on this information. can i ask you which routing and MAC do you use? anyway i think we have tosend this information through routing layer and not bye TCL. my email: samyar@gmail.com and my name is SAMIRA . thanks a lot
[ns] how to change node color
Dear All I am using following code but its not working $node color Red also tried $node color red both of above not working and there is no error as well. Whats the proper way to change node color,please help. Best Regards
[ns] Sending data to a specific port of a node in ns2
Hi everyone! How can I send data to a specific port on a node in ns-2.33? I recently declare nodes and send data among them, is there any way to send data to a certain port of a node? Please reply back soon. Faraz
[ns] Directional Antenna (smart antenna)
Hi, Is there any Directional Antenna (or smart antenna) implementation publicly available? I read several papers saying that they have implemented their ideas in NS2 but all I could find is a few outdated and broken links. I am trying to implement my ideas on directional antenna (for Mesh or MANET type network). Any information would be highly appreciated. - Greene
[ns] Parsing Trace File
Hi all, I want to parse some of the columns in the trace file i.e. only want some columns from the trace file. Does any body already has a python script written for that? Please share it with me. Thank you very much! Regards, Arslan
[ns] xgraph cannot open display
Eng Rony hi all, I'm having some problems while I'm=A0trying to run the example4(about xgrap= h) in section VIII from Marc Greis' tutorial. when I was trying to=A0run the example by g= iving the command ns=A0example4.tcl it's saying that: xgraph: cannot open display i use cygwin,ns2.29. how can i solve this problem? thanks
[ns] CBR maxpkts and interval
Hi, How can I set a limit of maximum no of packets to be sent from a node in CBR traffic. It is $cbr set maxpkts_ 20 (I think) but it is not working. Even after setting a fixed no of packets for transmission, I see more packets flowing from source to destination. Can some one help me please? Faraz
[ns] sample code for wsn
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 thisif 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 appTime10.0 ;# in seconds set appTime20.3 ;# in seconds set appTime30.7 ;# in seconds set stopTime100 ;# 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_ 1 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
[ns] how to draw xgraph from tae trace file
please tel me how to draw the xgraph from trace file.?