NS2中如何设定无线节点的通信半径

来源:互联网 发布:叶问3游戏网络无连接 编辑:程序博客网 时间:2024/05/17 22:40

转载地址:http://140.116.164.80/~smallko/ns2/range_en.htm

To set communication radius, you have to set the receiving threshold value, RXThresh_. This can be obtained by running the program ~ns/indep-utils/propagation/threshold.cc (compile using g++ and the option –lm) and specifying the propagation model and the desired radius. Then in your script, before creating the simulator, use the command “Phy/WirelessPhy set RXThresh_ ”. Ideally, you would also like to set the transmission power, Pt_ and the carrier sensing threshold, CSThresh_. But I still don’t know how to obtain their values. Some standard values for Pt_ are: 7.214e-4 for 100m, 8.5872e-4 for 40m. Also note that the effectiveness of the radius depends on the propagation model. While it works perfectly for FreeSpace, it might not work as well for the other two.

[compile threshold.cc]
$ cd ns/indep-utils/propagation/
$ g++ -lm threshold.cc -o threshold

[example]
$ threshold -m TwoRayGround 250
distance = 250
propagation model: TwoRayGround

Selected parameters:
transmit power: 0.281838
frequency: 9.14e+08
transmit antenna gain: 1
receive antenna gain: 1
system loss: 1
transmit antenna height: 1.5
receive antenna height: 1.5

Receiving threshold RXThresh_ is: 3.65262e-10
$

p.s. (0.28183815×1.52×1.52) / (2504)=3.652e-10

the more information can be found at http://140.116.164.80/~smallko/ns2/11b.htm

[usage]

$ threshold

USAGE: find receiving threshold for certain communication range (distance)
SYNOPSIS: threshold -m <propagation-model> [other-options] distance

<propagation-model>: FreeSpace, TwoRayGround or Shadowing
[other-options]: set parameters other than default values:

Common parameters:
-Pt <transmit-power>
-fr <frequency>
-Gt <transmit-antenna-gain>
-Gr <receive-antenna-gain>
-L <system-loss>

For two-ray ground model:
-ht <transmit-antenna-height>
-hr <receive-antenna-height>

For shadowing model:
-pl <path-loss-exponent>
-std <shadowing-deviation>
-d0 <reference-distance>
-r <receiving-rate>

[Tcl example]     node0 ------- node1

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)         32768                         ;# max packet in ifq

 

set val(rp) DumbAgent

 

set ns [new Simulator]

Antenna/OmniAntenna set X_ 0

Antenna/OmniAntenna set Y_ 0

Antenna/OmniAntenna set Z_ 1.5

Antenna/OmniAntenna set Gt_ 1.0

Antenna/OmniAntenna set Gr_ 1.0

 

Phy/WirelessPhy set CPThresh_ 10.0

Phy/WirelessPhy set CSThresh_ 1.559e-11

Phy/WirelessPhy set RXThresh_ 3.652e-10

Phy/WirelessPhy set bandwidth_ 2e6

Phy/WirelessPhy set Pt_ 0.28183815

Phy/WirelessPhy set freq_ 914e+6

Phy/WirelessPhy set L_ 1.0 

 

 

set f [open test.tr w]

$ns trace-all $f

$ns eventtrace-all

set nf [open test.nam w]

$ns namtrace-all-wireless $nf 500 500

 

# set up topography object

set topo       [new Topography]

 

$topo load_flatgrid 500 500

 

# Create God

create-god 2

 

# create channel

set chan [new $val(chan)]

 

$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) \

                -channel $chan \

                -topoInstance $topo \

                -agentTrace ON \

                -routerTrace OFF \

                -macTrace ON \

                -movementTrace OFF

 

for {set i 0} {$i < 2} {incr i} {

        set node_($i) [$ns node]

        $node_($i) random-motion 0

}

 

$node_(0) set X_ 30.0

$node_(0) set Y_ 30.0

$node_(0) set Z_ 0.0

 

$node_(1) set X_ 280.0

$node_(1) set Y_ 30.0

$node_(1) set Z_ 0.0

 

set udp [new Agent/mUDP]

#set the sender trace file name to sd

$udp set_filename sd

$ns attach-agent $node_(0) $udp

 

set null [new Agent/mUdpSink]

#set the receiver filename to rd

$null set_filename rd

$ns attach-agent $node_(1) $null

$ns connect $udp $null

 

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1Mb

$cbr set random_ false

 

$ns at 0.0 "$cbr start"

$ns at 15.0 "$cbr stop"

 

for {set i 0} {$i < 2} {incr i} {

        $ns initial_node_pos $node_($i) 30

        $ns at 20.0 "$node_($i) reset";

}

 

$ns at 20.0 "finish"

$ns at 20.1 "puts \"NS EXITING...\"; $ns halt"

 

#INSERT ANNOTATIONS HERE

proc finish {} {

        global ns f nf val

        $ns flush-trace

        close $f

        close $nf

 

}

puts "Starting Simulation..."

$ns run

 

[simulation results]

1.      First case: the distance between node0 and node1 is 250 m

After simulation, two files are generated, i.e. sender trace file (sd) and receiver trace file (rd). Check the contents in rd and we can find that node1 has received the data sent from node0.

 

2.      Second case: the distance between node0 and node 1 is 251 m (change the position of node1 : $node_(1) set X_ 281.0)

Check the contents in rd and we can not find any data in it. It means that node1 does not receive any data sent from node0. It is due to out of transmission range.

 

Reference

  1. http://www.cecs.uci.edu/~arijitg/faq.html
  2. http://web.syr.edu/~dchen02/FAQ.txt