标签:优点 1.0 最大值 链路 limit open amt shadow hit
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 0 blue
$ns color 1 red
$ns color 2 white
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#预先定义trace file
f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w] #Open the NAM trace file
$ns namtrace-all $nf
#Create links between the nodes (双向链接)
$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
它有点类似于FIFO(先入先出)的存储方式。Drop Tail最大的优点是原理简单。
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10 #设置n2与n3之间链路上队列缓冲区的最大值为10
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-up # n0在n2的下方45°
$ns duplex-link-op $n1 $n2 orient right-down # n1在n2的上方45°
$ns duplex-link-op $n2 $n3 orient right # n2的右边是n3
#队列位置定义了队列与水平的夹角(水平线以下度数为正)
#right-up 45
#right-down -45
#right 0 右
![](http://i2.51cto.com/images/blog/201801/22/d49f3f3564b1a1d3b82672e494eff435.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5
#duplex-link-op 设置双工链路属性
#### queuePos
1.queuePos 0.5表示包从上到下进入队列
2. queuePos 0表示包从右到左进入队列
3. queuePos 1表示包从左到右进入队列
4. queuePos 1.5表示包从下到上进入队列
5. queuePos 2==queuePos 0
因此queuePos N表示包进入队列时的角度,角度 =(N×π) % 2π
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
set udp1 [new Agent/UDP]
$ns attach-agent $n3 $udp1
$udp1 set class_ 1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
set null1 [new Agent/Null]
$ns attach-agent $n1 $null1
$ns connect $udp0 $null0
$ns connect $udp1 $null1
$ns at 1.0 "$cbr0 start"
$ns at 1.1 "$cbr1 start"
#Setup a TCP connection
set tcp [new Agent/TCP] #创建一个tcp代理
$tcp set class_ 2 #设置tcp流的颜色为白色(n0)
set sink [new Agent/TCPSink] #Sink:接收器(n3)
$ns attach-agent $n0 $tcp
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 1.2 "$ftp start"
$ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
puts [$cbr0 set packetSize_]
puts [$cbr0 set interval_]
$ns at 3.0 "finish"
#Define a ‘finish‘ procedure
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf #Close the NAM trace file
puts "running nam..."
exec nam out.nam & #Execute NAM on the trace file
exit 0
}
标签:优点 1.0 最大值 链路 limit open amt shadow hit
原文地址:http://blog.51cto.com/12059878/2063978