DD协议代码分析

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#==================================================================#Defineoptions#===================================================================setopt(chan)Channel/WirelessChannel/物理信道类型是无线信道setopt(prop)Propagation/TwoRayGround/无线传输模型是woRayGroundsetopt(netif)Phy/WirelessPh/网络借口类型是无线物理层setopt(mac)Mac/802_11/MAC层协议采用802.11协议setopt(ifq)Queue/DropTail/PriQueue/接口队列类型是IFQ列队setopt(ll)LL/逻辑链路层类型LL层setopt(ant)Antenna/OmniAntenna/无线模型是全向天线setopt(filters)GradientFilter;#oldnamefortwophasepullfilter/twophasepull过滤器setopt(x)670;#Xdimensionofthetopography设定拓扑范围——长度,670Msetopt(y)670;#Ydimensionofthetopographysetopt(ifqlen)50;#maxpacketinifq/网络接口队列的大小50setopt(nn)10;#numberofnodes/节点数setopt(sndr)1;#noofsenders/没有发送方setopt(rcvr)4;#noofrecvrs/没有recvrssetopt(seed)0.0/设置随机数种子setopt(stop)100;#simulationtime/仿真时间setopt(tr)DD.tr;#tracefile/跟踪文件setopt(nam)DD.nam;#namfile/文件名setopt(adhocRouting)Directed_Diffusion/路由协议#==================================================================LLsetmindelay_50us/设置mindelay时间LLsetdelay_25us/设置延迟时间LLsetbandwidth_0;#notused/没有使用的带宽为0Queue/DropTail/PriQueuesetPrefer_Routing_Protocols1#unitygain,omni-directionalantennas/单位增益,全向天线#setuptheantennastobecenteredinthenodeand1.5metersaboveit/天线设立在节点中心1.5米以上Antenna/OmniAntennasetX_0Antenna/OmniAntennasetY_0Antenna/OmniAntennasetZ_1.5Antenna/OmniAntennasetGt_1.0Antenna/OmniAntennasetGr_1.0#InitializetheSharedMediainterfacewithparameterstomake/界面参数初始化#itworklikethe914MHzLucentWaveLANDSSSradiointerface/工作如在914MHz扩频朗讯WaveLAN无线接口Phy/WirelessPhysetCPThresh_10.0Phy/WirelessPhysetCSThresh_1.559e-11Phy/WirelessPhysetRXThresh_3.652e-10Phy/WirelessPhysetRb_2*1e6Phy/WirelessPhysetPt_0.2818/传输功率Phy/WirelessPhysetfreq_914e+6Phy/WirelessPhysetL_1.0其中,RXThresh_指的是receivingthreshold(RTX),它是由节点传输范围250m计算出来的,CSThresh_指的是carrier-sensethreshold(CTX),它是由载波侦听范围550m计算出来的。CSThresh_与RXThresh_这两个值是功率的threshold值。通过在tcl脚本中设置它们的大小,就可以相应设置节点传输范围和载波侦听范围。=======================#MainProgram/主程序#=================================================================##InitializeGlobalVariables/初始化全局变量#setns_[newSimulator]建立一个模拟实例建立一个拓扑图对象,记录节点的移动情况settopo[newTopography]settracefd[open$opt(tr)w]#$ns_use-newtrace$ns_trace-all$tracefdsetnf[open$opt(nam)w]$ns_namtrace-all-wireless$nf$opt(x)$opt(y)#$ns_use-newtrace$topoload_flatgrid$opt(x)$opt(y)setgod_[create-god$opt(nn)]#globalnodesetting/全局节点设置传感器节点属性的配置参数的部分程序代码如下所示:$ns_node-config-adhocRouting$opt(adhocRouting)\-llType$opt(ll)\-macType$opt(mac)\-ifqType$opt(ifq)\-ifqLen$opt(ifqlen)\-antType$opt(ant)\-propType$opt(prop)\-phyType$opt(netif)\-channelType$opt(chan)\-topoInstance$topo\-diffusionFilter$opt(filters)\-agentTraceON\-routerTraceON\-macTraceON#在本文所有的模拟实验中,MAC层使用的是1.6Mb/s速率的802.11协议,也就是说MAC层实现了IEEE802.11MAC协议。在本文模拟中所使用的MAC协议不是一个最满意的选择,基于对无线传感器网络能量方面的考虑,在MAC层最好选择时分复用(TimeDivisionMultipleAccess,简称TDIlA)方式,而不是使用RTs/cTS通道请求的方式。简面言之,这些原因与节点空闲时无线通信所消耗的能量有关,对于TDMA方式的MAC协议,节点空闲期问无线电设各处于休眠状态,但是IEEE802.IIMAC协议在节点空闲期间和在传送数据包期间所消耗的能量却都是一样多的。为了使模拟实验和实际的无线传感器网络的能量消耗更加接近随删。设置节点空闲期间所消耗的能量大约是接收数据包所消耗能量的10%,即大约是发送数据包所消耗能量的5%#Createthespecifiednumberofnodes[$opt(nn)]andattachthem#tothechannel.创建指定编号的节点并连接到信道for{seti0}{$i$opt(nn)}{incri}{setnode_($i)[$ns_node$i]$node_($i)colorblack$node_($i)random-motion0;#disablerandommotion$god_new_node$node_($i)}putsLoadingconnectionpattern.../加载连接模式设定节点初始位置$node_(0)setX_18$node_(0)setY_331$node_(0)setZ_0$node_(1)setX_11$node_(1)setY_36$node_(1)setZ_0$node_(2)setX_224$node_(2)setY_20$node_(2)setZ_0$node_(3)setX_158$node_(3)setY_139$node_(3)setZ_0$node_(4)setX_101$node_(4)setY_147$node_(4)setZ_0$node_(5)setX_321$node_(5)setY_382$node_(5)setZ_0$node_(6)setX_149$node_(6)setY_314$node_(6)setZ_0$node_(7)setX_381$node_(7)setY_78$node_(7)setZ_0$node_(8)setX_113$node_(8)setY_400$node_(8)setZ_0$node_(9)setX_258$node_(9)setY_113$node_(9)setZ_0#1pingsender/ping发送方for{seti0}{$i$opt(sndr)}{incri}{setsrc_($i)[newApplication/DiffApp/PingSender/TPP]$ns_attach-diffapp$node_([expr$i+2])$src_($i)$ns_at[expr0.12*[expr1+$i]]$src_($i)publish}#4pingreceivers/ping接收方for{seti0}{$i$opt(rcvr)}{incri}{setsnk_($i)[newApplication/DiffApp/PingReceiver/TPP]$ns_attach-diffapp$node_([expr$opt(nn)-1-$i])$snk_($i)$ns_at[expr1.15*[expr1+$i]]$snk_($i)subscribe}#Definenodeinitialpositioninnam/定义节点初始位置在namfor{seti0}{$i$opt(nn)}{incri}{$ns_initial_node_pos$node_($i)20}##Tellnodeswhenthesimulationends/仿真结束的时候告诉节点#for{seti0}{$i$opt(nn)}{incri}{$ns_at$opt(stop).1$node_($i)reset;}procfinish{}{globalns_tracefdnf$ns_flush-traceclose$tracefdclose$nfexecnamDD.nam&exit0}#tellnamthesimulationstoptime/告诉nam仿真停止时间$ns_at$opt(stop)finish$ns_at$opt(stop)$ns_nam-end-wireless$opt(stop)$ns_at$opt(stop).01puts\NSEXITING...\;$ns_haltputsStartingSimulation...$ns_run

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功