【发布时间】:2015-04-27 14:15:01
【问题描述】:
我编写了一个 ns2 脚本来运行来自 80 个节点中的 40 个节点的并发 HTTP 请求。
但是,模拟显示一个节点而不是 40 个节点向 HTTP 服务器发出请求。
有人可以澄清一下代码可能有什么问题吗?
代码如下
感谢大家的宝贵时间。
set ns [new Simulator]
set clswitch [$ns node] # the access layer switch
set distrswitch [$ns node] # the distribution switch
set cch [$ns node] # the cache
set websrv [$ns node] # the web server
set traceFile [open Asim.tr w]
set namTraceFile [open Asim.nam w]
$ns namtrace-all $namTraceFile
$ns trace-all $traceFile
proc finish {} {
global ns traceFile namTraceFile
$ns flush-trace-all
puts "Simulation completed."
flush $traceFile
flush $namTraceFile
close $traceFile
close $namTraceFile
exit 0
}
for {set i 0} {$i < 80} {incr i} {
if {$i % 2 == 0} {
set cl ($i) [$ns node]
$ns duplex-link $cl($i) $clswitch 100Mb 10ms DropTail
set tcpAgent [new Agent/TCP]
$ns attach-agent $cl($i) $tcpAgent
set tcpSink [new Agent/TCPSink]
$ns attach-agent $clswitch $tcpSink
$ns connect $tcpAgent $tcpSink
set client [new Http/Client $ns $cl($i)]
proc start-connection {} {
global ns client cache server
$client connect $cache
$cache connect $server
$client start-session $cache $server
}
$ns at 0.5 "start-connection"
}
}
$ns duplex-link $clswitch $distrswitch 100Mb 10ms DropTail
set tcpAgent [new Agent/TCP]
$ns attach-agent $clswitch $tcpAgent
set tcpSink [new Agent/TCPSink]
$ns attach-agent $distrswitch $tcpSink
$ns connect $tcpAgent $tcpSink
$ns duplex-link $distrswitch $cch 100Mb 10ms DropTail
set tcpAgent [new Agent/TCP]
$ns attach-agent $distrswitch $tcpAgent
set tcpSink [new Agent/TCPSink]
$ns attach-agent $cch $tcpSink
$ns connect $tcpAgent $tcpSink
$ns duplex-link $cch $websrv 100Mb 10ms DropTail
set tcpAgent [new Agent/TCP]
$ns attach-agent $cch $tcpAgent
set tcpSink [new Agent/TCPSink]
$ns attach-agent $websrv $tcpSink
$ns connect $tcpAgent $tcpSink
set server [new Http/Server $ns $websrv]
set cache [new Http/Cache $ns $cch]
set pgp [new PagePool/Math]
set tmp [new RandomVariable/Constant]
$tmp set val_ 4096
$pgp ranvar-size $tmp
set tmp [new RandomVariable/Exponential]
$tmp set avg_ 6
$pgp ranvar-age $tmp
$server set-page-generator $pgp
set tmp [new RandomVariable/Exponential]
$tmp set avg_ 0.5
$client set-interval-generator $tmp
$client set-page-generator $pgp
$ns at 6.0 "finish"
【问题讨论】:
标签: if-statement for-loop tcl ns2