?? 一個完整ns腳本程序.txt
字號:
一個完整NS腳本程序
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
set nf [open out1.nam w]
$ns namtrace-all $nf
set tf [open out.tr w]
$ns trace-all $tf
proc finish {} {
global ns tf
$ns flush-trace
close $nf
close $tf
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#band 是網(wǎng)絡帶寬,delay是該連路的延遲
set band 1
set var1 0.2
set var2 0.2
#set var_user 0.1
set delay 10ms
# normal 是正常流量速率,attack1,attack2是攻擊流量速率
set normal [expr $var_user*$band]mb
set attack1 [expr $var1*$band]mb
set attack2 [expr $var2*$band]mb
set bandwith [expr 1*$band]mb
set queuelim 60
$ns duplex-link $n0 $n3 $bandwith $delay DropTail
$ns duplex-link $n1 $n3 $bandwith $delay DropTail
$ns duplex-link $n2 $n3 $bandwith $delay DropTail
$ns duplex-link $n3 $n4 $bandwith $delay DropTail
$ns queue-limit $n3 $n4 $queuelim
$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n1 $n3 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right
$ns duplex-link-op $n1 $n3 color "Red"
$ns duplex-link-op $n2 $n3 color "Red"
$ns duplex-link-op $n3 $n4 color "Green"
$ns duplex-link-op $n3 $n4 queuePos 0.5
set tcp0 [new Agent/TCP/Reno]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n4 $sink0
$ns connect $tcp0 $sink0
$tcp0 set fid_ 0
$tcp0 set packetSize_ 1000
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp1 $null1
$udp1 set fid_ 1
set udp2 [new Agent/UDP]
$ns attach-agent $n2 $udp2
set null2 [new Agent/Null]
$ns attach-agent $n4 $null2
$ns connect $udp2 $null2
$udp2 set fid_ 2
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set type_ FTP
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set type_ CBR
$cbr1 set packet_size_ 500
$cbr1 set rate_ $attack1
$cbr1 set random_ false
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$cbr2 set type_ CBR
$cbr2 set packet_size_ 500
$cbr2 set rate_ $attack2
$cbr2 set random_ false
$ns at 0.1 "$ftp0 start"
$ns at 0.2 "$cbr2 start"
$ns at 0.3 "$cbr1 start"
$ns at 35 "$cbr1 stop"
$ns at 40 "$cbr2 stop"
$ns at 45 "$ftp0 stop"
$ns at 50 "finish"
#Print CBR packet size and interval
puts "tcp packet size = [$tcp0 set packetSize_]"
puts "window = [$tcp0 set window_]"
puts "attack1 =$attack1"
puts "attack2 =$attack2"
puts "bandwith = $bandwith"
#Run the simulation
$ns run
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -