欢迎来到天天文库
浏览记录
ID:41127373
大小:81.50 KB
页数:10页
时间:2019-08-17
《WSN中LEACH协议源码分析》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、WSN中LEACH协议源码分析分析(一)首先对wireless.tcl进行分析,先对默认的脚本选项进行初始化:setopt(chan)Channel/WirelessChannelsetopt(prop)Propagation/TwoRayGroundsetopt(netif)Phy/WirelessPhysetopt(mac)Mac/802_11setopt(ifq)Queue/DropTail/PriQueuesetopt(ll)LLsetopt(ant)Antenna/OmniAntennasetopt(x)0;#Xdimensionofthetopographyse
2、topt(y)0;#Ydimensionofthetopographysetopt(cp)""setopt(sc)"../mobility/scene/scen-670x670-50-600-20-2";#scenariofilesetopt(ifqlen)50;#maxpacketinifsetopt(nn)51;#numberofnodessetopt(seed)0.0setopt(stop)10.0;#simulationtimesetopt(tr)out.tr;#tracefilesetopt(rp)dsdv;#routingprotocolscriptsetopt
3、(lm)"on";#logmovement在这个wireless.tcl中设置了一些全局变量:##InitializeGlobalVariables#setns_[newSimulator]setchan[new$opt(chan)]setprop[new$opt(prop)]settopo[newTopography]settracefd[open$opt(tr)w]$topoload_flatgrid$opt(x)$opt(y)$proptopography$topo这些初始化将在后面的使用中用到,该文件最重要的是创建leach节点:创建方法如下:}elseif{[st
4、ringcompare$opt(rp)"leach"]==0}{for{seti0}{$i<$opt(nn)}{incri}{leach-create-mobile-node$i}如果路由协议是leach协议,则在Uamps.tcl中调用leach-create-mobile-node方法创建leach节点。将在第二小节讲如何创建leach节点。for{seti0}{$i<$opt(nn)}{incri}{$ns_at$opt(stop).000000001"$node_($i)reset";//完成后,重置节点的应用}$ns_at$opt(stop).00000001"p
5、uts"NSEXITING...";$ns_halt"if{$opt(sc)==""}{puts"***NOTE:noscenariofilespecified."setopt(sc)"none"}else{puts"Loadingscenariofile..."source$opt(sc)puts"Loadcomplete..."}ns在什么时候结束simulation,并告诉ns加载sc场景文件。最后$ns_run则ns就开始运行了。分析(二)上节对wireless.tcl进行了简要的分析,接下来对Uamps.tcl脚本进行分析。setopt(Efriss_amp)
6、[expr[expr1.1*$opt(RXThresh)*16*$PI*$PI]/[expr$opt(bw)*$opt(Gt)*$opt(Gr)*$l*$l]]#Etwo_ray_amp=RXThresh/(RbGtGrht^2hr^2)setopt(Etwo_ray_amp)[expr1.1*$opt(RXThresh)/[expr$opt(bw)*$opt(Gt)*$opt(Gr)*$opt(ht)*$opt(ht)*$opt(ht)*$opt(ht)]]setopt(EXcvr)50e-9;#Energyforradiocircuitrysetopt(e_bf)
7、5e-9;#Beamformingenergy(J/bit)setopt(Esense)0;#Sensingenergy(J/bit)setopt(thresh_energy)0.00;#Thresholdforpoweradaptationsetopt(Pidle)0;#Idlepower(W)setopt(Psleep)0;#Sleeppower(W)setinitialized0setrng_[newRNG]#用于产生随机数首先往opt数组里面添加一些变量,并对这些变量进行初化。opt(Psleep),opt
此文档下载收益归作者所有