NS应用实例3
来源:互联网 发布:淘宝测款 编辑:程序博客网 时间:2024/04/29 23:13
# 场景描述:
# 主要用于观察数据包在节点 Agent 上的排队和丢包情况
# 有线场景,四个节点,FTT+TCP 用蓝色表示, CBR+UDP 用红色表示
set ns [new Simulator]
#设置颜色
$ns color 1 Blue
$ns color 2 Red
set tracefd [open out.tr w]
$ns trace-all $tracefd
set namtracefd [open out.nam w]
$ns namtrace-all $namtracefd
proc finish {} {
global ns tracefd namtracefd
$ns flush-trace
close $tracefd
close $namtracefd
exec nam out.nam &
exit 0
}
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 10ms DropTail
$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
$ns duplex-link-op $n2 $n3 queuePos 0.5
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
$ns at 0.5 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#一下这一行可有可无!
$ns at 4.5 "$ns detach-agent $n0 $tcp ;
$ns detach-agent $n3 $sink"
$ns at 5.0 "finish"
#会在命令窗口中输出, 因为默认的 stdout 是命令窗口啊!
puts "CBR packet size=[$cbr set packet_size_]"
puts "CBR interval=[$cbr set interval_]"
$ns run
程序运行效果图
# 主要用于观察数据包在节点 Agent 上的排队和丢包情况
# 有线场景,四个节点,FTT+TCP 用蓝色表示, CBR+UDP 用红色表示
set ns [new Simulator]
#设置颜色
$ns color 1 Blue
$ns color 2 Red
set tracefd [open out.tr w]
$ns trace-all $tracefd
set namtracefd [open out.nam w]
$ns namtrace-all $namtracefd
proc finish {} {
global ns tracefd namtracefd
$ns flush-trace
close $tracefd
close $namtracefd
exec nam out.nam &
exit 0
}
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 10ms DropTail
$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
$ns duplex-link-op $n2 $n3 queuePos 0.5
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
$ns at 0.5 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#一下这一行可有可无!
$ns at 4.5 "$ns detach-agent $n0 $tcp ;
$ns detach-agent $n3 $sink"
$ns at 5.0 "finish"
#会在命令窗口中输出, 因为默认的 stdout 是命令窗口啊!
puts "CBR packet size=[$cbr set packet_size_]"
puts "CBR interval=[$cbr set interval_]"
$ns run
程序运行效果图
- NS应用实例3
- NS应用实例1
- NS应用实例2
- NS应用实例4
- NS应用实例5
- SYSLOG-NS 应用
- ns-3
- ns-3 Tracer 原理以及应用/ndnSIM Tracer原理以及应用
- NS-3概念引入
- NS-3概念引入
- ns-3 安装
- NS-3 简介
- 下载ns-3-dev
- NS-3 Developers Overview
- NS-3 Module overview
- NS-3安装说明
- WHAT IS NS-3
- NS-3 Develop Tools
- 网络常识
- 市盈率
- wiki文本处理引擎
- 从C转入C++
- vsftpd 匿名用户能下载,不能上传文件
- NS应用实例3
- js获取当前日期时间及其它操作
- javascript使用方括号([])和“.”引用对象的属性和方法
- 平仓
- 一个IT程序员的奋斗史----总有一种力量让我们泪流满面
- 基于windows平台的Android原生(Native)C开发环境搭建
- C/C++ %d等简单格式类型总结
- PPP协议
- Struts2学习笔记之类型转换。