微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

不同能量的节点

如何解决不同能量的节点

我正在处理我的项目。它是关于根据节点的能量检测自私节点。在这里我有 20 个能量相同的节点,然后我又添加了 5 个但能量不同的节点。该程序显示输出(如代码末尾所列)。 同样,当我运行 nam 文件时,它只显示了 20 个节点。

我的代码

# Define options
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             ;# interface queue type
set val(ll)             LL                         ;# link layer type
set val(ant)            Antenna/OmniAntenna        ;# antenna model
set val(ifqlen)         100000                         ;# max packet in ifq
set val(nn)             20                         ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x)              1000               ;# X dimension of topography
set val(y)              1000               ;# Y dimension of topography 
set val(seed)           0.0
set val(cp)             "cbr-20"
set val(sc)             "setdest-20"
set val(stop)       200.0              ;# time of simulation end
set ns_       [new Simulator]
set tracefile       [open aodvnode50.tr w]
#set windowVsTime2 [open win.tr w] 
$ns_ trace-all $tracefile
$ns_ use-newtrace 
#$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
#Open the NAM trace file
set namfile [open manet.nam w]
$ns_ namtrace-all $namfile
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
set god_ [create-god $val(nn)]
set chan_1_ [new $val(chan)]
#
#  Create nn mobilenodes [$val(nn)] and attach them to the channel. 
#
# configure the nodes
        $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_1_ \
             -topoInstance $topo \
             -agentTrace ON \
             -routerTrace ON \
             -macTrace ON \
-energyModel "EnergyModel" \
        -initialEnergy 100.0 \
        -txPower 2.0522 \
        -rxPower 0.0591 \
        -idlePower 0.00006 \
        -sleepPower 0.000003 \       
    for {set i 0} {$i < $val(nn) } { incr i } {
        set node_($i) [$ns_ node]
                $node_($i) random-motion 0  ;# disable random motion
    }
$ns_ node-config -initialEnergy 500
set node_(20) [$ns_ node]
$ns_ node-config -initialEnergy 20
set node_(21) [$ns_ node]
$ns_ node-config -initialEnergy 30
set node_(22) [$ns_ node]
$ns_ node-config -initialEnergy 100
set node_(23) [$ns_ node]
$ns_ node-config -initialEnergy 100
set node_(24) [$ns_ node]
# 21 connecting to 24 at time 20.48548468411224
#
set udp_(8) [new Agent/UDP]
$ns_ attach-agent $node_(21) $udp_(8)
set null_(8) [new Agent/Null]
$ns_ attach-agent $node_(24) $null_(8)
set cbr_(8) [new Application/Traffic/CBR]
$cbr_(8) set packetSize_ 512
$cbr_(8) set interval_ 1.0
$cbr_(8) set random_ 1
$cbr_(8) set maxpkts_ 10000
$cbr_(8) attach-agent $udp_(8)
$ns_ connect $udp_(8) $null_(8)
$ns_ at 20.48548468411224 "$cbr_(8) start"
#
# 22 connecting to 9 at time 76.258212521792487
#
set udp_(9) [new Agent/UDP]
$ns_ attach-agent $node_(22) $udp_(9)
set null_(9) [new Agent/Null]
$ns_ attach-agent $node_(9) $null_(9)
set cbr_(9) [new Application/Traffic/CBR]
$cbr_(9) set packetSize_ 512
$cbr_(9) set interval_ 1.0
$cbr_(9) set random_ 1
$cbr_(9) set maxpkts_ 10000
$cbr_(9) attach-agent $udp_(9)
$ns_ connect $udp_(9) $null_(9)
$ns_ at 76.258212521792487 "$cbr_(9) start"
puts "Loading connection pattern..."
source $val(cp)
puts "Loading scenario file..."
source $val(sc)
proc finish {} {
    global ns_ tracefile namfile
    $ns_ flush-trace
    close $tracefile
    close $namfile
    exec nam manet.nam &
    exit 0
}

 for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ initial_node_pos $node_($i) 20
}
 
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at $val(stop).000000001 "$node_($i) reset";
}
$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop).000000001 "puts \"NS EXITING...\"; $ns_ halt"
puts "Start Simulation..."
$ns_ run

cbr-20、setdest-20 文件https://drive.google.com/file/d/1w72g92luudD08qYvhwQdsJR2u1UjlhI6/view?usp=sharing https://drive.google.com/file/d/1r5j_5iYtH-oo4AIFpLM6T5b6lxxyC15q/view?usp=sharing

输出

    num_nodes is set 20
INITIALIZE THE LIST xListHead
Loading connection pattern...
Loading scenario file...
Start Simulation...
SORTING LISTS ...DONE!
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,distCST_ = 550.0
MAC_802_11: accessing MAC cache_ array out of range (src 21,dst 24,size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 24,dst 21,size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21,size 20)!
[suppressing additional MAC cache_ warnings]
NS EXITING...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。