开发者

how to make the mobile nodes static in tcl?

开发者 https://www.devze.com 2023-04-10 14:11 出处:网络
code: set val(chan)Channel/WirelessChannel set val(prop)Propagation/TwoRayGround set val(ant)Antenna/OmniAntenna

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号