参考文献:
NS Simulator for Beginners 第九章 推荐资料百度文库:NS2仿真MM1K队列 https://wenku.baidu.com/view/413f0c73b90d6c85ec3ac674.html
以下是 tcl 代码
set ns [new Simulator] set tf [open out.tr w] $ns trace-all $tf set lambda 30.0 set mu 33.0
set n1 [$ns node] set n2 [$ns node] # Since packet sizes will be rounded to an integer # number of bytes , we should have large packets and # to have small rounding errors , and so we take large bandwidth set link [$ns duplex-link $n1 $n2 100kb 0ms DropTail] $ns queue-limit $n1 $n2 100000
# generate random interarrival times and packet sizes set InterArrivalTime [new RandomVariable/Exponential] $InterArrivalTime set avg_ [expr 1/$lambda] set pktSize [new RandomVariable/Exponential] $pktSize set avg_ [expr 100000.0/(8*$mu)]
set src [new Agent/UDP] $ns attach-agent $n1 $src
# queue monitoring set qmon [$ns monitor-queue $n1 $n2 [open qm.out w] 0.1] [$ns link $n1 $n2] queue-sample-timeout
proc 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 $bytes } set sink [new Agent/Null] $ns attach-agent $n2 $sink $ns connect $src $sink $ns at 0.0001 “sendpacket” $ns at 200.0 “finish”
$ns run
