我是NS2的新手并试图建立一个基本的哑铃形网络模拟;我有一个节点,其中 n TCP代理(网关或“gw”)通过链接传输到远程节点(远程网关,“rgw”),该节点连接到 n TCP接收器(每个代理与一个接收器连接)。
这是一张n = 5的图片。节点0有五个带有Pareto流量生成器的TCP代理;每个都连接到连接到右侧节点之一的TCPSink代理。
我有以下TCL脚本来设置和测试网络;它运行成功,但是当我在NAM中查看跟踪时,我看不到数据包在移动。我用NAM运行了一个类似的教程,它看起来很好,所以我自己的代码中一定有一个bug。任何人都可以帮我找到我的错误吗?
感谢。
set ns [new Simulator]
# Set up trace
set trc [open out.trc w]
set namtrc [open out.nam w]
$ns trace-all $trc
$ns namtrace-all $namtrc
proc finish {} {
global ns trc
global ns namtrc
$ns flush-trace
close $trc
close $namtrc
exec nam out.nam &
exit 0
}
# Simulation parameters
set n 5
set bw 150000000 # 150 Mb/s
# Set up bottleneck link
set gw [$ns node]
set rgw [$ns node]
$ns duplex-link $gw $rgw $bw .30 DropTail
set snd {} # TCP senders sitting on the gateway node
set trf {} # Traffic generators for the senders
set dst {} # Destination nodes hosting the receivers
set rcv {} # TCP receivers sitting on the destination
for {set i 0} {$i<$n} {incr i} {
# Create the objects needed for a new connection
lappend snd [new Agent/TCP]
lappend rcv [new Agent/TCPSink]
lappend trf [new Application/Traffic/Pareto]
lappend srv [$ns node]
# set up source and destination nodes
$ns attach-agent $gw [lindex $snd $i]
$ns attach-agent [lindex $srv $i] [lindex $rcv $i]
[lindex $trf $i] attach-agent [lindex $snd $i]
# Connect nodes
$ns duplex-link $rgw [lindex $srv $i] 1000000000000 .100 DropTail
# Connect agents
$ns connect [lindex $snd $i] [lindex $rcv $i]
}
foreach traffic $trf {
$ns at 0.0 "$traffic start"
}
$ns at 10.0 "finish"
$ns run
以下是使用此代码生成的跟踪的摘录:
+ 0.214008 0 1 pareto 40 ------- 0 0.0 2.0 0 0
- 0.214008 0 1 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.321715 0 1 pareto 40 ------- 0 0.3 5.0 0 1
- 0.321715 0 1 pareto 40 ------- 0 0.3 5.0 0 1
r 0.51401 0 1 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.51401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
- 0.51401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
r 0.61401 1 2 pareto 40 ------- 0 0.0 2.0 0 0
+ 0.61401 2 1 ack 40 ------- 0 2.0 0.0 0 2
- 0.61401 2 1 ack 40 ------- 0 2.0 0.0 0 2
r 0.621717 0 1 pareto 40 ------- 0 0.3 5.0 0 1
+ 0.621717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
- 0.621717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
r 0.71401 2 1 ack 40 ------- 0 2.0 0.0 0 2
+ 0.71401 1 0 ack 40 ------- 0 2.0 0.0 0 2
- 0.71401 1 0 ack 40 ------- 0 2.0 0.0 0 2
r 0.721717 1 5 pareto 40 ------- 0 0.3 5.0 0 1
+ 0.721717 5 1 ack 40 ------- 0 5.0 0.3 0 3
- 0.721717 5 1 ack 40 ------- 0 5.0 0.3 0 3
+ 0.735936 0 1 pareto 40 ------- 0 0.2 4.0 0 4
- 0.735936 0 1 pareto 40 ------- 0 0.2 4.0 0 4
r 0.821717 5 1 ack 40 ------- 0 5.0 0.3 0 3
+ 0.821717 1 0 ack 40 ------- 0 5.0 0.3 0 3
- 0.821717 1 0 ack 40 ------- 0 5.0 0.3 0 3
+ 0.831634 0 1 pareto 40 ------- 0 0.4 6.0 0 5
- 0.831634 0 1 pareto 40 ------- 0 0.4 6.0 0 5
r 1.014013 1 0 ack 40 ------- 0 2.0 0.0 0 2
+ 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 6
- 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 6
+ 1.014013 0 1 pareto 1040 ------- 0 0.0 2.0 0 7
- 1.014068 0 1 pareto 1040 ------- 0 0.0 2.0 0 7
r 1.035938 0 1 pareto 40 ------- 0 0.2 4.0 0 4
+ 1.035938 1 4 pareto 40 ------- 0 0.2 4.0 0 4
- 1.035938 1 4 pareto 40 ------- 0 0.2 4.0 0 4
r 1.121719 1 0 ack 40 ------- 0 5.0 0.3 0 3
+ 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 8
- 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 8
+ 1.121719 0 1 pareto 1040 ------- 0 0.3 5.0 0 9
- 1.121775 0 1 pareto 1040 ------- 0 0.3 5.0 0 9
r 1.131636 0 1 pareto 40 ------- 0 0.4 6.0 0 5
看起来工作正常。
答案 0 :(得分:1)
尝试下面的代码,它可以正常工作
set ns [new Simulator]
# Set up trace
set trc [open out.trc w]
set namtrc [open out.nam w]
$ns trace-all $trc
$ns namtrace-all $namtrc
proc finish {} {
global ns trc
global ns namtrc
$ns flush-trace
close $trc
close $namtrc
exec nam out.nam &
exit 0
}
# Simulation parameters
set n 5
set bw 150000000; # 150 Mb/s
# Set up bottleneck link
set gw [$ns node]
set rgw [$ns node]
$ns duplex-link $gw $rgw $bw .3000 DropTail
set snd {}
# TCP senders sitting on the gateway node
set trf {}
# Traffic generators for the senders
set dst {}
# Destination nodes hosting the receivers
set rcv {}
# TCP receivers sitting on the destination
for {set i 0} {$i<$n} {incr i} {
# Create the objects needed for a new connection
lappend snd [new Agent/TCP]
lappend rcv [new Agent/TCPSink]
lappend trf [new Application/Traffic/Pareto]
lappend srv [$ns node]
# set up source and destination nodes
$ns attach-agent $gw [lindex $snd $i]
$ns attach-agent [lindex $srv $i] [lindex $rcv $i]
[lindex $trf $i] attach-agent [lindex $snd $i]
# Connect nodes
$ns duplex-link $rgw [lindex $srv $i] 10000 .10000 DropTail
# Connect agents
$ns connect [lindex $snd $i] [lindex $rcv $i]
}
foreach traffic $trf {
$ns at 0.0 "$traffic start"
}
$ns at 10.0 "finish"
$ns run