WSN中LEACH协议源码分析分析(一),先对默认的脚本选项进行初始化:setopt(chan)Channel/WirelessChannelsetopt(prop)Propagation/if)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)(stop);#simulationtimesetopt(tr);#tracefilesetopt(rp)dsdv;#routingprotocolscriptsetopt(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-node方法创建leach节点。将在第二小节讲如何创建leach节点。for{seti0}{$i<$opt(nn)}{incri}{$ns_at$opt(stop)."$node_($i)reset";//完成后,重置节点的应用}$ns_at$opt(stop)."puts\"NSEXITING...\";$ns_halt"if{$opt(sc)==""}{puts"***NOTE:noscenariofilespecified."setopt(sc)"none"}else{puts"Loadingscenariofile..."source$opt(sc)puts"plete..."}ns在什么时候结束simulation,并告诉ns加载sc场景文件。最后$ns_run则ns就开始运行了。分析(二),。setopt(Efriss_amp)[
WSN中LEACH协议源码分析 来自淘豆网www.taodocs.com转载请标明出处.