如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
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;#Xdimensionofthetopographysetopt(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(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{[stringcompare$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"puts\"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)[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)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)setin