2017-03-24 13 views
1

我想使用nam運行下面的代碼。ns2無法連接到現有的nam實例

set ns [new Simulator] 

set nf [open lab1.nam w] 
$ns namtrace-all $nf 

set f [open lab1.tr w] 

proc record {} { 

global sink f 
set ns [Simulator instance] 

set time 0.12 

set bw [$sink set bytes_] 

set now [$ns now] 

puts $f "$now [expr (($bw/$time)*8/1000000)]" 

$sink set bytes_ 0 

$ns at [expr $now+$time] "record" 
} 


proc finish {} { 
    global ns nf f 
    $ns flush-trace 
    close $nf 
    close $f 
    exit 0 
} 


set n0 [$ns node] 
set n1 [$ns node] 

$ns duplex-link $n0 $n1 4Mb 10ms DropTail 


set udp0 [new Agent/UDP] 
$udp0 set packetSize_ 1500 
$ns attach-agent $n0 $udp0 

set traffic0 [new Application/Traffic/CBR] 

$traffic0 set packetsize_ 1500 
$traffic0 set interval_ 0.01 
$traffic0 attach-agent $udp0 

set sink [new Agent/LossMonitor] 
$ns attach-agent $n1 $sink 

$ns connect $udp0 $sink 


$ns at 0.0 "record" 
$ns at 2.0 "$traffic0 start" 
$ns at 10.0 "$traffic0 stop" 

$ns at 12.0 "finish" 
$ns run 

我想在虛擬機上使用VirtualBox與Windows 7 32位運行它。

在cmd首先我執行命令ns lab1.tcl 在這個im試圖打開nam之後,使用命令nam lab1.nam。 當我這樣做,我得到的消息

enter image description here

南實際上然後運行,但不正確,這意味着它總是創建的210個字節的數據包和我的代碼不會影響該無論PACKETSIZE我給。

+0

看起來像一個未終止的字符串,可能是在命令行解析中。這確實很奇怪,因爲這是Windows上大多數運行時間的一個經過充分測試的部分。我猜測代碼是用一個運行時構建的,並且正在執行另一個!在其他平臺上,運行時相當簡單很多 –

回答

0

無法連接到現有的南例如

不是一個錯誤。當沒有南窗時,Nam會隨時顯示該消息。

我的測試:$ ns235-64-orig user7375077.tcl ...結果:lab1.nam 288.5kB,lab1.tr 3.3kB。

$ nam lab1.nam:OK ...

enter image description here

A股NS-2.35中使用。沒有修補。 ....可能是你添加了一些可以使nam工作不佳的改變? (或者可能是Cygwin創建的nam正在被破壞?)

建議:使用真正的Linux操作系統使您的「ns2工作」。安裝簡單:1)安裝'VirtualBox'。 2)將Linux OS('s)安裝到VirtualBox中。安全的操作系統選擇:Redhat CentOS 6.8 http://ftp.funet.fi/pub/mirrors/centos.org/6.8/isos/x86_64/CentOS-6.8-x86_64-LiveCD.iso