DD协议代码分析_第1页
DD协议代码分析_第2页
DD协议代码分析_第3页
DD协议代码分析_第4页
DD协议代码分析_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、# =# Define options# =set opt(chan)Channel/WirelessChannel /物理信道类型是无线信道set opt(prop)Propagation/TwoRayGround/无线传输模型是woRayGroundset opt(netif)Phy/WirelessPh/网络借口类型是无线物理层 set opt(mac)Mac/802_11/MAC层协议采用802.11协议set opt(ifq)Queue/DropTail/PriQueue/接口队列类型是IFQ列队set opt(ll)LL/逻辑链路层类型LL层set opt(ant) Antenna

2、/OmniAntenna/无线模型是全向天线set opt(filters) GradientFilter ;# old name for twophasepull filter/ twophasepull过滤器set opt(x)670 ;# X dimension of the topography设定拓扑范围长度,670Mset opt(y)670 ;# Y dimension of the topographyset opt(ifqlen)50 ;# max packet in ifq/网络接口队列的大小50set opt(nn)10 ;# number of nodes/节点数set

3、 opt(sndr) 1 ;# no of senders/没有发送方set opt(rcvr) 4 ;# no of recvrs/没有recvrsset opt(seed)0.0/设置随机数种子set opt(stop)100 ;# simulation time/仿真时间set opt(tr)"DD.tr" ;# trace file/跟踪文件set opt(nam) "DD.nam" ;# nam file/文件名set opt(adhocRouting) Directed_Diffusion/路由协议 # =LL set mindelay_50

4、us/设置mindelay时间LL set delay_25us/设置延迟时间LL set bandwidth_0 ;# not used/没有使用的带宽为0Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1# unity gain, omni-directional antennas/单位增益,全向天线# set up the antennas to be centered in the node and 1.5 meters above it/天线设立在节点中心1.5米以上Antenna/OmniAntenna set X_ 0An

5、tenna/OmniAntenna set Y_ 0Antenna/OmniAntenna set Z_ 1.5Antenna/OmniAntenna set Gt_ 1.0Antenna/OmniAntenna set Gr_ 1.0# Initialize the SharedMedia interface with parameters to make/界面参数初始化# it work like the 914MHz Lucent WaveLAN DSSS radio interface/工作如在914MHz扩频朗讯WaveLAN无线接口Phy/WirelessPhy set CPThr

6、esh_ 10.0Phy/WirelessPhy set CSThresh_ 1.559e-11Phy/WirelessPhy set RXThresh_ 3.652e-10Phy/WirelessPhy set Rb_ 2*1e6Phy/WirelessPhy set Pt_ 0.2818/传输功率Phy/WirelessPhy set freq_ 914e+6 Phy/WirelessPhy set L_ 1.0其中,RXThresh_指的是receiving threshold (RTX),它是由节点传输范围250m计算出来的,CSThresh_指的是carrier-sense

7、 threshold (CTX),它是由载波侦听范围550m计算出来的。CSThresh_与RXThresh_这两个值是功率的threshold值。通过在tcl脚本中设置它们的大小,就可以相应设置节点传输范围和载波侦听范围。=# Main Program/主程序# =# Initialize Global Variables/初始化全局变量#set ns_new Simulator 建立一个模拟实例建立一个拓扑图对象,记录节点的移动情况set toponew Topographyset tracefdopen $opt(tr) w#$ns_ use-newtrace$ns_ trac

8、e-all $tracefdset nf open $opt(nam) w$ns_ namtrace-all-wireless $nf $opt(x) $opt(y)#$ns_ use-newtrace$topo load_flatgrid $opt(x) $opt(y)set god_ create-god $opt(nn)#global node setting/全局节点设置传感器节点属性的配置参数的部分程序代码如下所示:$ns_ node-config -adhocRouting $opt(adhocRouting) -llType $opt(ll) -macType $opt(mac)

9、 -ifqType $opt(ifq) -ifqLen $opt(ifqlen) -antType $opt(ant) -propType $opt(prop) -phyType $opt(netif) -channelType $opt(chan) -topoInstance $topo -diffusionFilter $opt(filters) -agentTrace ON -routerTrace ON -macTrace ON #在本文所有的模拟实验中,MAC层使用的是16Mbs速率的80211协议,也就是说MAC层实现了IEEE 80211 MAC协议。在本文模拟中所使用的MAC协

10、议不是一个最满意的选择,基于对无线传感器网络能量方面的考虑,在MAC层最好选择时分复用(TimeDivision Multiple Access,简称TDIlA)方式,而不是使用RTscTS通道请求的方式。简面言之,这些原因与节点空闲时无线通信所消耗的能量有关,对于TDMA方式的MAC协议,节点空闲期问无线电设各处于休眠状态,但是IEEE 802II MAC协议在节点空闲期间和在传送数据包期间所消耗的能量却都是一样多的。为了使模拟实验和实际的无线传感器网络的能量消耗更加接近随删。设置节点空闲期间所消耗的能量大约是接收数据包所消耗能量的10,即大约是发送数据包所消耗能量的5# Create th

11、e specified number of nodes $opt(nn) and "attach" them# to the channel. 创建指定编号的节点并连接到信道for set i 0 $i < $opt(nn) incr i set node_($i) $ns_ node $i $node_($i) color black $node_($i) random-motion 0;# disable random motion $god_ new_node $node_($i)puts "Loading connection pattern.&qu

12、ot;/ 加载连接模式设定节点初始位置$node_(0) set X_ 18$node_(0) set Y_ 331$node_(0) set Z_ 0$node_(1) set X_ 11$node_(1) set Y_ 36$node_(1) set Z_ 0$node_(2) set X_ 224$node_(2) set Y_ 20$node_(2) set Z_ 0$node_(3) set X_ 158$node_(3) set Y_ 139$node_(3) set Z_ 0$node_(4) set X_ 101$node_(4) set Y_ 147$node_(4) set

13、 Z_ 0$node_(5) set X_ 321$node_(5) set Y_ 382$node_(5) set Z_ 0$node_(6) set X_ 149$node_(6) set Y_ 314$node_(6) set Z_ 0$node_(7) set X_ 381$node_(7) set Y_ 78$node_(7) set Z_ 0$node_(8) set X_ 113$node_(8) set Y_ 400$node_(8) set Z_ 0$node_(9) set X_ 258$node_(9) set Y_ 113$node_(9) set Z_ 0# 1 pi

14、ng sender/ping 发送方for set i 0 $i < $opt(sndr) incr i set src_($i) new Application/DiffApp/PingSender/TPP $ns_ attach-diffapp $node_(expr $i + 2) $src_($i) $ns_ at expr 0.12 * expr 1+$i "$src_($i) publish"# 4 ping receivers/ping 接收方for set i 0 $i < $opt(rcvr) incr i set snk_($i) new A

15、pplication/DiffApp/PingReceiver/TPP $ns_ attach-diffapp $node_(expr $opt(nn)-1 -$i) $snk_($i) $ns_ at expr 1.15*expr 1+$i "$snk_($i) subscribe"#Define node initial position in nam/定义节点初始位置在namfor set i 0 $i < $opt(nn) incr i $ns_ initial_node_pos $node_($i) 20# Tell nodes when the simulation ends/仿真结束的时候告诉节点#for set i 0 $i < $opt(nn) incr i $ns_ at $opt(stop).1 "$node_($i) reset"proc finish global ns_ tracefd nf$ns_ flush-traceclose $tracefdclose $nfexec nam DD.nam &exit 0# tell nam the si

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论