芇WSN中LEACH协议源码分析莄分析(一),先对默认地脚本选项进行初始化:肂setopt(chan)Channel/WirelessChannel荿setopt(prop)Propagation/if)Phy/WirelessPhy莁setopt(mac)Mac/802_11蒀setopt(ifq)Queue/DropTail/PriQueue肈setopt(ll)LL薄setopt(ant)Antenna/OmniAntenna螂setopt(x)0 ;#Xdimensionofthetopography膂setopt(y)0 ;#Ydimensionofthetopography袇setopt(cp)""袈setopt(sc)"../mobility/scene/scen-670x670-50-600-20-2";#scenariofile膃蚀setopt(ifqlen) 50;#maxpacketinif袀setopt(nn) 51;#numberofnodes羇setopt(seed)(stop);#simulationtime莂setopt(tr);#tracefile虿setopt(rp)dsdv;#routingprotocolscript肇setopt(lm)"on";#:袀#蒈#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{[pare$opt(rp)"leach"]==0}{螁for{seti0}{$i<$opt(nn)}{incri}{羈leach-create-mobile-node$i蒇}莄如果路由协议是leach协议,-create-mobile-{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"plete..."芃}肁ns在什么时候结束simulation,$(二),(Efriss_amp)[expr[*$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)[*$opt(RXThresh)/\肅[expr$opt(bw)*$opt(Gt)*$opt(Gr)*\芁$opt(ht)*$opt(ht)*$opt(ht)*$opt(ht)]]膀setopt(EXcvr)50e-9;#Energyforradiocircuitry羆setopt(e_bf)5e-9;#Beamformingenergy(J/bit)节setopt(Esense)0;#Sensingenergy(J/bit)羃setopt(thresh_energy) ;#Thresholdforpoweradaptation衿setopt(Pidle)0;#Idlepower(W)肆setopt(Psleep)0;#Sleeppower(W)蚃莀setinitialized0蚇setrng_[newRNG]#用于产生随机数肆首先往opt数
WSN中LEACH协议源码分析 来自淘豆网www.taodocs.com转载请标明出处.