1、本实验报告是利用 ns2 仿真 M/M/1/ 队列模型 网络拓扑结构采用最基本的拓扑结构,即有两个网络节点分别代表源发端和目的端,中间连接一条链路(具体实现请见下面附录)。 网络参数链路带宽 100kbps队列容量 100000 /因为必须需要队列容量参数,而本模型考虑的是无穷大因此将此设为 100000 代表无穷大。分组大小 200 性能评价 平均队长 Lq 平均逗留时间 Ws实验采用 = 30 =40 来验证 M/M/1/ 队列模型 = 0.75=平均队长理论值=2.252q(1)L平均逗留时间理论值:=0.1()sW而实际测量值Lq = 2.404304(具体分析请见附录)Ws = 0.
2、100828仿真实验图示如下: 图 1 表示瞬间队长横轴表示时间,单位是 100 毫秒;纵轴表示队列分组长度。图 1,链路中的瞬间队长 图 2 表示,平均逗留时间其中横轴表示数据包开始发送时间,纵轴表示该数据包的延迟图 2,每个数据包的延迟附录:TCL、Gawk 代码如下所示:TCL:(mm1.tcl 生成网络拓扑结构)set ns new Simulatorset tf open out.tr w $ns trace-all $tfset lambda 30.0set mu 40.0set n1 $ns nodeset n2 $ns node# Since packet sizes will
3、 be rounded to an integer# number of bytes, we should have large packets and# to have small rounding errors, and so we take large bandwidthset link $ns duplex-link $n1 $n2 100kb 0ms DropTail$ns queue-limit $n1 $n2 100000# generate random interarrival times and packet sizesset InterArrivalTime new Ra
4、ndomVariable/Exponential$InterArrivalTime set avg_ expr 1/$lambdaset pktSize new RandomVariable/Exponential$pktSize set avg_ expr 100000.0/(8*$mu)set src new Agent/UDP$ns attach-agent $n1 $src# queue monitoringset qm $ns monitor-queue $n1 $n2 open qtr w 0.01$ns link $n1 $n2 queue-sample-timeoutproc
5、finish global ns tf$ns flush-trace close $tf exit 0 proc sendpacket global ns src InterArrivalTime pktSize set time $ns now$ns at expr $time + $InterArrivalTime value “sendpacket“set bytes expr round ($pktSize value)$src send $bytesset sink new Agent/Null$ns attach-agent $n2 $sink$ns connect $src $s
6、ink$ns at 0.0001 “sendpacket“$ns at 500.0 “finish“$ns runGawk 代码:(文件 curlen.awk 得到瞬间队列长度)BEGINhighest_packet_id = 0;num = 0;packet_id = $6;len = $5;if(highest_packet_id=packet_id)curlenhighest_packet_id += len;num+;if(highest_packet_id highest_packet_id )highest_packet_id = packet_id;if ( start_time
7、packet_id = 0 ) start_timepacket_id = time;if ( action = “r“ ) end_timepacket_id = time;else end_timepacket_id = -1; END for ( packet_id = 0; packet_id highest_packet_id )highest_packet_id = packet_id;if ( start_timepacket_id = 0 ) start_timepacket_id = time;if ( action = “r“ ) end_timepacket_id = time;else end_timepacket_id = -1; END for ( packet_id = 0; packet_id = highest_packet_id; packet_id+ ) start = start_timepacket_id;end = end_timepacket_id;packet_duration = end - start;if ( start end ) total_delay+=packet_duration;num +;printf(“avg delay is:%f“,total_delay/num);