AODV NS2中的数据包大小,用于IEEE 802.15.4仿真

时间:2017-05-18 12:11:00

标签: ns2

我正在尝试使用AODV协议在NS2中进行IEEE 802.15.4模拟。我正在从节点0向节点1发送一个30字节的数据包。从发送方,数据包随添加的标头一起传输。然而,在接收器侧,在MAC层中丢弃路由层报头,但是在AGT层中不丢弃MAC层报头。我发送30字节的数据包,但接收50字节的数据包。我在剧本中做错了吗?我试图使用带有AODV的IEEE 802.11模拟代码,它运行良好。

我已为数据包0附加了完整的TCL脚本和跟踪文件行。

TCL脚本

#===================================
#     Simulation parameters setup
#===================================
set val(chan)   Channel/WirelessChannel     ;# channel type
set val(prop)   Propagation/Shadowing       ;# radio-propagation model
set val(netif)  Phy/WirelessPhy/802_15_4    ;# network interface type
set val(mac)    Mac/802_15_4                ;# 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) 50                          ;# max packet in ifq
set val(nn)     2                           ;# 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(stop)   2                       ;# time of simulation end

##################################################################

#===================================
Antenna/OmniAntenna set Gt_ 1                   ;#Transmit antenna gain
Antenna/OmniAntenna set Gr_ 1                   ;#Receive antenna gain
Phy/WirelessPhy     set L_ 1.0                  ;#System Loss Factor
Phy/WirelessPhy     set freq_ 2.4e9             ;#channel
Phy/WirelessPhy     set bandwidth_ 0.25Mb       ;#Data Rate


###############Simulation experiment # 3 ################################################
Phy/WirelessPhy set Pt_ 0.00050118723363            ;#in W for Transmit Power -3dBm IEEE 802.15.4 standard
Phy/WirelessPhy set RXThresh_ 3.1622776602e-12      ;#Receive Power Threshold  -85dBm   IEEE 802.15.4
Phy/WirelessPhy set CSThresh_ 1.5848931925e-12     ;#Carrier Sense Power   -88dBm

#===================================
#        Initialization        
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file
set tracefile [open outAODV.tr w]
$ns trace-all $tracefile

#Open the NAM trace file
set namfile [open outAODV.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel


#===================================
#     Mobile node parameter setup
#===================================
$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   ON \
                -macTrace      ON \
                -movementTrace ON


# first set values of shadowing model
Propagation/Shadowing set pathlossExp 2.9  ;# path loss exponent
Propagation/Shadowing set std_db 8.0       ;# shadowing deviation (dB)
Propagation/Shadowing set dist0 1.0        ;# reference distance (m)
Propagation/Shadowing set seed 10           ;# seed for RNG


#===================================
#        Nodes Definition        
#===================================
set n0 [$ns node]                       ;#considered as a sink
$n0 set X_ 60
$n0 set Y_ 60
$n0 set Z_ 0.0
$ns initial_node_pos $n0 15

set n1 [$ns node]                       ;# Source 1 measured PDR /throughput / Delay varying diatance
$n1 set X_ 90
$n1 set Y_ 60
$n1 set Z_ 0.0
$ns initial_node_pos $n1 15

# Start Coordinate/Normal Nodes
$ns at 0.0  "$n0 NodeLabel \"PAN Coor\""
$ns at 0.0  "$n0 sscs startCTPANCoord"  

#===================================
#        Agents Definition        
#===================================
#Setup a UDP connection 
set null0 [new Agent/Null]      
$ns attach-agent $n0 $null0

#===================================
#        Applications Definition     CBR1      
#===================================
#Setup a CBR Application over UDP connection

set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
$ns connect $udp1 $null0

set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 30
$cbr1 set interval_ .1

$ns at 1.0 "$cbr1 start"
$ns at 1.5 "$cbr1 stop"

#===================================
#        Termination        
#===================================
#Define a 'finish' procedure
proc finish {} {
    global ns tracefile namfile
    $ns flush-trace
    close $tracefile
    close $namfile
    exec nam out.nam &
    exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

输出跟踪文件(仅适用于数据包0)

s 1.000000000 _1_ AGT  --- 0 cbr 30 [0 0 0 0] ------- [1:0 0:0 32 0] [0] 0 0
r 1.000000000 _1_ RTR  --- 0 cbr 30 [0 0 0 0] ------- [1:0 0:0 32 0] [0] 0 0
s 1.000000000 _1_ RTR  --- 0 AODV 48 [0 0 0 0] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
s 1.000665000 _1_ MAC  --- 0 AODV 55 [0 ffffffff 1 800] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
r 1.003257100 _0_ MAC  --- 0 AODV 48 [0 ffffffff 1 800] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
r 1.003282100 _0_ RTR  --- 0 AODV 48 [0 ffffffff 1 800] ------- [1:255 -1:255 30 0] [0x2 1 1 [0 0] [1 4]] (REQUEST)
s 1.003282100 _0_ RTR  --- 0 AODV 44 [0 0 0 0] ------- [0:255 1:255 30 1] [0x4 1 [0 4] 10.000000] (REPLY)
s 1.004352000 _0_ MAC  --- 0 ARP 35 [0 ffffffff 0 806] ------- [REQUEST 0/0 0/1]
r 1.006304100 _1_ MAC  --- 0 ARP 28 [0 ffffffff 0 806] ------- [REQUEST 0/0 0/1]
s 1.006629100 _1_ MAC  --- 0 ARP 35 [0 0 1 806] ------- [REPLY 1/1 0/0]
s 1.008192000 _0_ MAC  --- 0 ACK 5 [0 1 0 0] 
r 1.008544100 _1_ MAC  --- 0 ACK 5 [0 1 0 0] 
r 1.009184000 _0_ MAC  --- 0 ARP 28 [0 0 1 806] ------- [REPLY 1/1 0/0]
s 1.012032000 _0_ MAC  --- 0 AODV 51 [0 1 0 800] ------- [0:255 1:255 30 1] [0x4 1 [0 4] 10.000000] (REPLY)
s 1.014048100 _1_ MAC  --- 0 ACK 5 [0 0 1 0] 
r 1.014400200 _0_ MAC  --- 0 ACK 5 [0 0 1 0] 
r 1.015040100 _1_ MAC  --- 0 AODV 44 [0 1 0 800] ------- [0:255 1:255 30 1] [0x4 1 [0 4] 10.000000] (REPLY)
r 1.015065100 _1_ RTR  --- 0 AODV 44 [0 1 0 800] ------- [0:255 1:255 30 1] [0x4 1 [0 4] 10.000000] (REPLY)
s 1.015065100 _1_ RTR  --- 0 cbr 50 [0 0 0 0] ------- [1:0 0:0 30 0] [0] 0 0
s 1.017650100 _1_ MAC  --- 0 cbr 57 [0 0 1 800] ------- [1:0 0:0 30 0] [0] 0 0
s 1.020032000 _0_ MAC  --- 0 ACK 5 [0 1 0 0] 
r 1.020384100 _1_ MAC  --- 0 ACK 5 [0 1 0 0] 
r 1.021024000 _0_ MAC  --- 0 cbr 50 [0 0 1 800] ------- [1:0 0:0 30 0] [0] 1 0
r 1.021049000 _0_ AGT  --- 0 cbr 50 [0 0 1 800] ------- [1:0 0:0 30 0] [0] 1 0

1 个答案:

答案 0 :(得分:1)

当使用lr-wpan而不是wifi时,需要修改许多deffernt参数。 如果你想建立基于IEE802.15.4的无线传感器网络 你可以在这条路径中找到有用的例子

.\ns-allinone-2.35\ns-2.35\tcl\ex\wpan

将它们用作模板,或者让它们受益于修改代码。

这本书也解释了这些例子

.....\ns-allinone-2.35\ns-2.35\wpan\WPAN_ZBR_pub.pdf

问候