NS2网络仿真基础教程——TCP和UDP协议仿真

2024-10-12 07:28:44

1、第一步:验证NS2仿真环境本教程的环境为centOS6.0+NS2 2.35。关于Linux以及NS2的安装已经有大量的优秀教程,希望小伙伴可以查找相关资料配置好基本的运行环境。验证方法如下:找到NS2的安装路径,并找到~/ns-2.35/tcl/ex文件夹下的simple.tcl文件,使用命令行命令:ns simple.tcl,在正常环境下会出现nam程序界面以及一个网络仿真拓扑图。

NS2网络仿真基础教程——TCP和UDP协议仿真NS2网络仿真基础教程——TCP和UDP协议仿真

3、第三步:创建仿真脚本文件ex1.tcltcl脚本文件可以通过gedit进行编辑。

NS2网络仿真基础教程——TCP和UDP协议仿真

5、第五步:创建udp协议代理,cbr数据发生器,将二者绑定,并在1.1 和1.2秒启动两个数倌栗受绽据发生器set udp0 [new 帆歌达缒Agent/UDP]$ns attach-agent $n0 $udp0set cbr0 [new Application/Traffic/CBR]$cbr0 attach-agent $udp0set udp1 [new Agent/UDP]$ns attach-agent $n3 $udp1$udp1 set class_ 1set cbr1 [new Application/Traffic/CBR]$cbr1 attach-agent $udp1set null0 [new Agent/Null]$ns attach-agent $n3 $null0set 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"set tcp [new Agent/TCP]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $n0 $tcp$ns attach-agent $n3 $sink$ns connect $tcp $sinkset 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_]

NS2网络仿真基础教程——TCP和UDP协议仿真

6、第六步:定义仿真结束过程,在该过程中关闭两个记录文件。最后,使用run命令启动仿真。proc finish {} { global ns f nf $ns flush-trace close $f close $nf puts "running nam..." exec nam out.nam & exit 0}$ns run

NS2网络仿真基础教程——TCP和UDP协议仿真NS2网络仿真基础教程——TCP和UDP协议仿真
猜你喜欢