Ns2下Aodv协议仿真及各项性能指标分析的源程序

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

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

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

资源描述

1.AODV协议仿真程序#wuchunmingprogramsit#setthenormalvarsetval(chan)Channel/WirelessChannel;#ChannelTypesetval(prop)Propagation/TwoRayGround;#radio-propagationmodelsetval(netif)Phy/WirelessPhy;#networkinterfacetypesetval(mac)Mac/802_11;#MACtypesetval(ifq)Queue/DropTail/PriQueue;#interfacequeuetypesetval(ll)LL;#linklayertypesetval(ant)Antenna/OmniAntenna;#antennamodelsetval(ifqlen)50;#maxpacketinifqsetval(nn)50;#numberofmobilenodessetval(rp)AODV;#routingprotocolsetval(x)1000setval(y)1000setopt(sc)scen1setopt(cbr)cbr1#initializetheglobalsetns_[newSimulator]settracefd[openaodv.trw]$ns_trace-all$tracefdsetnamtrace[openaodv.namw]$ns_namtrace-all-wireless$namtrace$val(x)$val(y)settopo[newTopography]$topoload_flatgrid$val(x)$val(y)setgod_[newGod]create-god$val(nn)setchan_[new$val(chan)]#configuration$ns_node-config-adhocRouting$val(rp)\-llType$val(ll)\-macType$val(mac)\-ifqType$val(ifq)\-ifqLen$val(ifqlen)\-antType$val(ant)\-propType$val(prop)\-phyType$val(netif)\-topoInstance$topo\-agentTraceON\-routerTraceON\-macTraceON\-movementTraceOFF\-channel$chan_#initilizethenodefor{seti0}{$i$val(nn)}{incri}{setnode_($i)[$ns_node]$node_($i)random-motion0}#importscenfilesource$opt(sc)#importcbrfilesource$opt(cbr)#gettoendtheprogramsource$opt(sc)for{seti0}{$i$val(nn)}{incri}{$ns_at180.1$node_($i)reset;}$ns_at180.2stop$ns_at180.3puts\NSexiting…\;$ns_haltprocstop{}{globalns_tracefdnamtrace$ns_flush-traceclose$tracefdclose$namtraceexecnamaodv.nam&exit0}$ns_run2.包延迟BEGIN{highest_packet_id=0;}{event=$1;time=$2;node=$3;node=substr(node,2,1);trace_type=$4;flag=$5;uid=$6;pkt_type=$7;pkt_size=$8;if(uidhighest_packet_id)highest_packet_id=uid;if(start_time[uid]==0)start_time[uid]=time;if(pkt_type==tcp&&event!=d){if(event==r){end_time[uid]=time;}}else{end_time[uid]=-1;}}END{for(uid=0;uid=highest_packet_id;uid++){start=start_time[uid];end=end_time[uid];packet_duration=end-start;if(startend)printf(%f%f\n,start,packet_duration);}}3.丢包率BEGIN{sends=0;recvs=0;}$0~/^s.*AGT/{sends++;}$0~/^r.*AGT/{recvs++;}END{printf(r/sratio:%.4f\n,(1-(recvs/sends)));}4包的吞吐率BEGIN{init=0;i=0;}{event=$1;time=$2;node=$3;node=substr(node,2,1);trace_type=$4;flag=$5;uid=$6;pkt_type=$7;pkt_size=$8;if(event==r&&pkt_type==tcp){pkt_byte_sum[i+1]=pkt_byte_sum[i]+pkt_size;if(init==0){start_time=time;init=1;}end_time[i]=time;i=i+1;}}END{#第一笔记录的Throughput设置为零,以表示传输开始,为了绘图的美观printf(%.2f\t%.2f\n,end_time[0],0);for(j=1;ji;j++){#单位为kbpsth=pkt_byte_sum[j]/(end_time[j]-start_time)*8/1000;printf(%.2f\t%.2f\n,end_time[j],th);}#最后一笔记录的Throughput设置为零,以表示传输结束,为了绘图的美观printf(%.2f\t%.2f\n,end_time[i-1],0);}5.包的投递率BEGIN{sends=0;recvs=0;}$0~/^s.*AGT/{sends++;}$0~/^r.*AGT/{recvs++;}END{printf(r/sratio:%.4f\n,(recvs/sends));}5路由负载率BEGIN{requests=0;frequency=0;}{id=$5;source_ip=$57;if(($1==s)&&($61==REQUEST)&&(id==source_ip)){requests++;}}END{frequency=requests;printf(%.4f\n,frequency);}

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

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

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

×
保存成功