⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simple.tcl

📁 ns2 中 有线模拟
💻 TCL
字号:
#创建一个模拟器类对象
set ns [new Simulator]
#给不同的数据流定义颜色
$ns color 1 blue
$ns color 2 red
#打开一个Nam Trace文件
set nf [open simple.nam w]
$ns namtrace-all $nf
#打开一个Trace文件,用来记录分组传送的过程
set nd [open simple.tr w]
#ns use-newtrace   新格式
$ns trace-all $nd
#定义一个结束的过程
proc finish {} {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam simple.nam
exit 0
}
#创建4个网络节点
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#创建双向链路
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
#设定n2和n3间的队列大小
$ns queue-limit $n2 $n3 10
#设定节点在NAM中的位置
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#设置节点n2和n3间链路中的队列在NAM中的位置
$ns duplex-link-op $n2 $n3 queuePos 0.5
#建立一条TCP的连接
set tcp [new Agent/TCP]
$tcp set fid_ 1
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$ns connect $tcp $sink
#在TCP连接上建立FTP应用程序
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#建立一条UDP连接
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
$udp set fid_ 2
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
#在UDP连接上建立CBR流量产生器
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packetSize_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
#设定FTP和CBR数据传送开始和结束时间
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
$ns at 5.0 "finish"
$ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -