ns2 cannot connect to existing nam instance

2019-07-27 03:30发布

问题:

I'm trying to run the below code using 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

I'm trying to run it on a Virtual Machine using VirtualBox with windows 7 32bit.

On cmd first i execute the command ns lab1.tcl After this im trying to open nam , using the command nam lab1.nam. When i do this, i get the message

Nam is actually then running but not properly,meaning it always creates packets of 210 bytes and my code doesn't affect this whatever packetsize i give.

回答1:

cannot connect to existing nam instance

Not an error. Nam will show that message any time, when no nam window is present.

My test : $ ns235-64-orig user7375077.tcl ... Result : lab1.nam 288.5kB, lab1.tr 3.3kB .

$ nam lab1.nam : OK ...

A stock ns-2.35 was used. No patching. .... May be you added some changes which can make nam work poorly ? ( Or may be it is the Cygwin created nam being corrupt ? )

Suggestions : Make your "ns2 work" with a genuine Linux OS. Easy install : 1) Install 'VirtualBox'. 2) Install the Linux OS(´s) into VirtualBox. The safe OS choice : Redhat CentOS 6.8 http://ftp.funet.fi/pub/mirrors/centos.org/6.8/isos/x86_64/CentOS-6.8-x86_64-LiveCD.iso



标签: tcl ns2 nam