- Home Page of ProjectGuideline.com ›
- Forums ›
- Get Help to do your B.E., and M.E., M.Tech., & M.S., Project in Ns2 ›
- How to get signal strength
Hi,
my problem is:
I’ve got a simple senario: One acces point and one mobile node. The mobile node first is going into the radius of the acess point and then out of the radius. Now I want to know, the signal strength of the mobile node, when the link is going down.
In tcl I haven’t found a solution. I thougth there is something easy like “set strength [$node set signalstrength]” but it seems there isn’t such a think… 🙁
Because of that I go to the C++-Source-Code. After a little bit of searching I found the file “wireless-phy.cc” and there the function “sendUp”. I think there the variable “Pr” is the signal strength (because later in the function “Pr” is compared with “CSTresh_” and “RXTresh_” wich a used to simulated if a paket is recieved correct or not).
But now I had the problem that “Pr” alway had got the same value and I don’t know why. I went back to my tcl file and play a little bit with my settings. As I changed “set opt(prop) Propagation/TwoRayGround” to “set opt(prop) Propagation/FreeSpace” and start a simulation, I’ve got an output on my console like “time: 0.008566: d: 31.622777, Pr: 2.949347e-09” (and there the Pr is chaniging!). First I was wondered about that, but then I looked into the file “propagation.cc” and there I found in the function Pr() “printf(“%lf: d: %lf, Pr: %en”, Scheduler::instance().clock(), d, Pr);”. So I copy that and put it into the file “tworayground.cc” at the same position (the function Pr) and now it seems to work.
But I always have a question: Why is Pr in “tworayground” changing and in wireless-phy”
not? And is it the correct position to read out the signal strength?
I’ve alway looked into the file “mac-802_11.cc” and the function “send” but there “Pr” also seems not to work correct (there it is alwas “1.600278e-02” or “-1″…) What do I have to change?
And a last thing: I want to have the signal strength in dBm. Because of that I made “10*log10(Pr)” but I’m not sure if I have to use “10*log10(Pr/0.001)” instead (because 1mW is the referece value for dBm and I don’t know if it is include in Pr or not…)
I hope anybody can help me with my problem(s). Thanks!
Greets Daniel Rother
PS: Here is my tcl-Code. Maybe there is just a simple error…:
# ======================================================================
# Define options
# ======================================================================
set opt(chan) Channel/WirelessChannel ;# channel type
#set opt(prop) Propagation/FreeSpace ;# radio-propagation model
set opt(prop) Propagation/TwoRayGround ;
set opt(netif) Phy/WirelessPhy ;# network interface type
set opt(mac) Mac/802_11 ;# MAC type
set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type
set opt(ll) LL ;# link layer type
set opt(ant) Antenna/OmniAntenna ;# antenna model
set opt(ifqlen) 50 ;# max packet in ifq
set opt(nn) 3 ;# number of mobilenodes
set opt(adhocRouting) DSDV ;# routing protocol
set opt(x) 300 ;# x coordinate of topology
set opt(y) 150 ;# y coordinate of topology
set opt(apX) 50 ;# x coordinate of the AP
set opt(apY) 50 ;# y coordinate of the AP
set opt(nodeX) 20 ;# start x coordinate of the wireless node
set opt(nodeY) 40 ;# start y coordinate of the wireless node
set opt(nTarX) 250 ;# target x coordinate of the node
set opt(nTarY) 40 ;# target y coordinate of the node
set opt(nSpeed) 5 ;# speed of the node
set opt(seed) 0.0 ;# seed for random number gen.
set opt(ftpstart) 5
set opt(dist) 200
set opt(stop) [expr $opt(dist) / $opt(nSpeed) + 10] ;# time to stop simulation
# time from start to target of the node
set num_wired_nodes 0
set num_bs_nodes 1
Antenna/OmniAntenna set Gt_ 1
Antenna/OmniAntenna set Gr_ 1
Mac/802_11 set basicRate_ 1Mb
Mac/802_11 set dataRate_ 11Mb
Phy/WirelessPhy set L_ 1.0
Phy/WirelessPhy set freq_ 2.472e9
Phy/WirelessPhy set bandwidth_ 11Mb ;
Phy/WirelessPhy set Pt_ 0.031622777
Phy/WirelessPhy set CPTresh_ 10.0
Phy/WirelessPhy set CSTresh_ 5.011872e-12
Phy/WirelessPhy set RXTresh_ 5.82587e-09
# ============================================================================
# create simulator instance
set ns_ [new Simulator]
# Open tracefiles
$ns_ use-newtrace
set tracefd [open out.tr w]
set namtrace [open out.nam w]
set nodetr [open nodetrace.tr w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
proc record {} {
global node nodetr sink
#Get an instance of the simulator
set ns_ [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.5
#How many bytes have been received by the traffic sinks?
set bw [$sink set bytes_]
#Get the current time
set now [$ns_ now]
#Get the signal strength
# is there anythong I can put here?
# just for test…
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $nodetr “$now [expr $bw/$time*8/1000000]”
#Reset the bytes_ values on the traffic sinks
$sink set bytes_ 0
#Re-schedule the procedure
$ns_ at [expr $now+$time] “record”
}
# ============================================================================
# check for boundary parameters and random seed
if { $opt(x) == 0 || $opt(y) == 0 } {
puts “No X-Y boundary values given for wireless topologyn”
}
if {$opt(seed) > 0} {
puts “Seeding Random number generator with $opt(seed)n”
ns-random $opt(seed)
}
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 1 ;# number of domains
lappend cluster_num 1 ;# number of clusters in each domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 2 ;# number of nodes in each cluster
AddrParams set nodes_num_ $eilastlevel ;# of each domain
# Create topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $opt(x) $opt(y)
# create God
create-god [expr $opt(nn) + $num_bs_nodes]
# Create channel
set chan_1_ [new $opt(chan)]
# configure for base-station node
$ns_ node-config -mobileIP ON
-adhocRouting $opt(adhocRouting)
-llType $opt(ll)
-macType $opt(mac)
-ifqType $opt(ifq)
-ifqLen $opt(ifqlen)
-antType $opt(ant)
-propType $opt(prop)
-phyType $opt(netif)
-channel $chan_1_
-topoInstance $topo
-wiredRouting ON
-agentTrace ON
-routerTrace OFF
-macTrace OFF
#create base-station node
set BS [$ns_ node 0.0.0]
$BS random-motion 0 ;# disable random motion
#provide some co-ord (fixed) to base station node
$BS set X_ $opt(apX)
$BS set Y_ $opt(apY)
$BS set Z_ 0.0
# create mobilenodes in the same domain as BS
#configure for mobilenodes
$ns_ node-config -wiredRouting OFF
# configure for mobilehost
set node [ $ns_ node 0.0.1 ]
set node_(0) $node
$node base-station [AddrParams addr2id
[$BS node-addr]]
$node set X_ $opt(nodeX)
$node set Y_ $opt(nodeY)
$node set Z_ 0
# setup TCP connections
set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns_ attach-agent $BS $tcp
$ns_ attach-agent $node $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at $opt(ftpstart) “$ftp start”
# Define initial node position in nam
#$ns_ initial_node_pos $node 20
# Start movement
$ns_ at 10.0 “$node setdest $opt(nTarX) $opt(nTarY) $opt(nSpeed)”
# Tell all nodes when the simulation ends
$ns_ at 0.0 “record”
$ns_ at $opt(stop).0 “$node reset”
$ns_ at $opt(stop).0 “$BS reset”
$ns_ at $opt(stop).0001 “stop”
$ns_ at $opt(stop).0002 “puts “NS EXITING…” ; $ns_ halt”
proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
}
# informative headers for Node-Tracefile
puts $nodetr “time Datarate”
puts “Starting Simulation…”
$ns_ run
In two ray model, the power decreases faster than Free Space model when distance increases. Hence it is always best to use Free Space for shorter distance and Two Ray for longer distances.
Post reply if it makes sense or not.