NS2程序错误:未显示类变量

问题描述 投票:1回答:1

我的程序显示此错误:

warning: no class variable LanRouter::debug_

        see tcl-object.tcl in tclcl for info about this warning.

--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---
        _o12: no target for slot -1
        _o12 type: Classifier/Hash/Dest
content dump:
classifier _o12
        0 offset
        0 shift
        1073741823 mask
        1 slots
                slot 0: _o139 (Classifier/Port)
        -1 default

我已经花了2个小时来编写此程序,请帮助我获得解决方案,我的程序如下:

set ns [new Simulator]

$ns color 1 Blue
$ns color 2 Red

set tracefile1 [open out.tr w]
set winfile [open winfile w]
$ns trace-all $tracefile1

set namfile [open out.nam w]
$ns namtrace-all $namfile

proc finish {} {
    global ns tracefile1 namfile
    $ns flush-trace
    close $tracefile1
    close $namfile
    exec nam out.nam &
    exit 0
    }

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 color Red
$n1 shape box

$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]

$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left

$ns queue-limit $n2 $n3 20

set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$tcp set fid_ 1
$tcp set packet_size_ 552

set ftp [new Application/FTP]
$ftp attach-agent $tcp

set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr  set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01Mb
$cbr set random_ false

$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 125.0 "$cbr stop"
proc plotWindow {tcpSource file} {
    global ns
    set time 0.1
    set now [$ns now]
    set cwnd [$tcpSource set cwnd_]
    puts $file "$now $cwnd"
     $ns at [expr $now + $time] "plotWindow $tcpSource $file"
    }

$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 125.0 "finish"
$ns run

我已经尝试了所有可以解决问题的方法,所以最后我必须来到这里获得解决方案,因此,如果有人有解决方案,请!帮我。谢谢!

ns2
1个回答
0
投票

--- Classfier :: no-slot {}默认处理程序

您的文件接近是https://github.com/dnlove/ammac-ns2/blob/master/duy/tcl/csma.tcl的副本:此原始的“ ammac Csma.Cd文件”运​​行正常。

您的文件:“ TCP连接”部分中缺少一行:$ns connect $tcp $sink

set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink      ;# added .........
$tcp set fid_ 1
$tcp set packet_size_ 552

....然后您的文件运行正常。

如果要避免警告:no class variable LanRouter::debug_,请将其添加到空行2:LanRouter set debug_ 0(警告不是错误,只是文本消息。]

© www.soinside.com 2019 - 2024. All rights reserved.