微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

多次运行相同的ns2文件

如何解决多次运行相同的ns2文件

如何使用不同的RNG种子多次运行相同的 TCL脚本,目的是 NS2中的统计分析 / strong>?

我正在从 run.tcl 呼叫 check.tcl 。这些文件正在生成跟踪文件,但没有保存每次运行的值。我想多次运行 check.tcl 。最后,我要平均所有输出值。

请帮助

#run.tcl
source check.tcl
set ns [new Simulator]
global $ns
#set topo    [new Topography]
#global $topo

#create trace object for ns and nam
for {set i 0} {$i < 10} {incr i} {
puts $i
#$defaultRNG seed $i
#set seed 100 * $defaultRNG
#puts $defaultRNG
#puts $seed
input_Protocol_pramerters $i $ns
#close $tracefile
#close $namfile
}

puts "Done"

#check.tcl
proc input_Protocol_pramerters {iter ns} {
set val(stop)   22.0                         ;# time of simulation end
    
#$defaultRNG seed $iter
set tracefile "wired"
append tracefile $iter ".tr"
set namfile "wired"
append namfile $iter ".nam"

set trtrace [open $tracefile w]
set namtrace [open $namfile w]
$ns trace-all $trtrace
$ns namtrace-all $namtrace

#Define a 'finish' procedure
proc finish {} {
    global ns trtrace namtrace
    $ns flush-trace
    close $trtrace
    close $namtrace
#    exec nam wired$iter.nam &
    exit 0
}
#set ns [new Simulator]

#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#Createlinks between nodes
$ns duplex-link $n1 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n0 50
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n4 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n0 50 
$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n3 50
#Give node position (for NAM)
$ns duplex-link-op $n1 $n0 orient right-down
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n4 $n0 orient left-up
$ns duplex-link-op $n0 $n3 orient left-down
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n1 $tcp0
set sink4 [new Agent/Tcpsink]
$ns attach-agent $n0 $sink4
$ns connect $tcp0 $sink4
$tcp0 set packetSize_ 1500
set tcp1 [new Agent/TCP]
$ns attach-agent $n2 $tcp1
set sink7 [new Agent/Tcpsink]
$ns attach-agent $n0 $sink7
$ns connect $tcp1 $sink7
$tcp1 set packetSize_ 1500
set tcp2 [new Agent/TCP]
$ns attach-agent $n4 $tcp2
set sink6 [new Agent/Tcpsink]
$ns attach-agent $n0 $sink6
$ns connect $tcp2 $sink6
$tcp2 set packetSize_ 1500
set tcp3 [new Agent/TCP]
$ns attach-agent $n3 $tcp3
set sink5 [new Agent/Tcpsink]
$ns attach-agent $n0 $sink5
$ns connect $tcp3 $sink5
$tcp3 set packetSize_ 1500
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp3
$ns at 1.0 "$ftp1 start"
$ns at 20.0 "$ftp1 stop"
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns at 1.0 "$ftp2 start"
$ns at 20.0 "$ftp2 stop"
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp1
$ns at 1.0 "$ftp3 start"
$ns at 20.0 "$ftp3 stop"
#Define a 'finish' procedure
#proc finish {} {
#global ns tracefile namfile
#$ns flush-trace
#close $tracefile
#close $namfile
#exec nam check.nam &
#exit 0
#}
#for {set i 0} {$i < 5} { incr i } {
#$ns at $val(stop) "\$n$i reset"
#}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
#$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。