欢迎来到天天文库
浏览记录
ID:49408608
大小:101.50 KB
页数:11页
时间:2020-03-01
《WSN中LEACH协议源码分析.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、WSN中LEACH协议源码分析分析(一)首先对wireless.tcl进行分析,先对默认的脚木选项进行初始化:setopt(chan)Channel/WirelessChannelsetopt(prop)Propagation/TvvoRayGroundsetopt(netif)Phy/WirelessPhyQueue/DropTail/PriQueueLLAnterrna/OmniAntenna0;#Xdimensionofthetopography0;#Ydimensionofthetopographysetopt(mac)Mac/802_l1setopt(ifq)setopt(H)set
2、opt(ant)setopt(x)setopt(y)setopt(cp)setopt(sc)M../mobility/scene/scen-670x670-50-600-20-2n;#scenariofilesetopt(ifqlen)50;#maxpacketinifsetopt(nn)51;#numberofnodessetopt(seed)0.0setopt(stop)10.0;#simulationtimesetopt(tr)out.tr;#tracefilesetopt(rp)dsdv;#routingprotocolscriptsetopt(lm)"on”;#logmovement
3、在这个wireless.tcl屮设置了一些全局变量:##InitializeGlobalVariables#setns_[newSimulator]setchan[new$opt(chan)Jsetprop[new$opt(prop)]settopo[newTopography]settracefd[open$opt(tr)w]$topoload_flatgrid$opt(x)$opt(y)$proptopography$topo这些初始化将在后面的使用屮用到,该文件最重要的是创建leach节点:创建方法如下:}elseif{[stringcompare$opt(rp)nleachM]==0)
4、{for{seti0}{$i<$opt(nn))fineri){leach-create-mobile-node$i}如果路由协议是leach协议,则在Uarnps.tcl屮调用leach-create-mobile-node方法创建leach节点。将在第二小节讲如何创建leach节点。for{seti0}{$i<$opt(nn)}{incri){$ns_at$opt(stop).000000001n$node_($i)reset";//完成后,重置节点的应用)$ns_at$opt(stop).00000001nputsVNSEXITING...'”;$ns_half*讦{$opt(sc)==
5、””}{putsM***NOTE:noscenariofilespecified."setopt(sc)"none'1)else{puts"Loadingscenariofile..."source$opt(sc)puts"Loadcomplete...'1}ns在什么时候结束simulation,并告诉ns加载sc场景;文件。®Jn$ns_run则ns就开始运行了。分析(二)上节对wireless.tcl进行了简要的分析,接下来对Uamps.tcl脚木进行分析。setopt(Efriss.amp)fexprfexpr1.1*$opt(RXThresh)*16*$PI*$PI]/[expr$
6、opt(bw)*$opt(Gt)*$opt(Gr)*$1*$1]]#Etwo_ray_amp=RXThresh/(RbGtGrhtA2hrA2)setopt(Etwo_ray_amp)[expr1.1*Sopt(RXThresh)/[expr$opt(bw)*$opt(Gt)*$opt(Gr)*$opt(ht)*$opt(ht)*$opt(ht)*$opt(ht)]]setopt(EXcvr)50e-9;#Energyforradiocircuitrysetopt(e_bf)5e-9;#Beamformingenergy(J/bit)setopt(Esense)0;#Sensingener
7、gy(J/bit)setopt(thresh_energy)0.00;#Thresholdforpoweradaptationsetopt(Pidle)0;#Idlepower(W)setopt(Psleep)0;#Sleeppower(W)setinitialized0setrng_[newRNG]#用于产生随机数首先往opt数组里面添加一些变量,并对这些变量进行初化。opt(PsIeep),o
此文档下载收益归作者所有