错误:执行TCL脚本时,sendmsg()to udp不应为-1(使用NS& nam)

发布于 2025-02-06 15:39:41 字数 2971 浏览 4 评论 0原文

我正在使用NS和NAM在TCL中编写脚本。

我要解决的陈述问题是什么?在这里是:

“问题”

以下是我编写的用于解决上述问题的TCL脚本。我在Ubuntu 20.04中使用NS2和NAM软件包。我的任务是创建8个节点,使用(任何能力)的双工链接链接它们,在节点0&上应用TCP代理。 1并在节点2上应用UDP。

然后,我需要将TCP代理与CBR源和UDP代理连接使用FTP源。以下是我的代码:

set val(stop)   10.0;


set ns [new Simulator]

#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile

#===================================
#        Nodes Definition        
#===================================
#Create 8 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]

$ns duplex-link $n0 $n3 20.0Mb 10ms DropTail
$ns duplex-link $n1 $n3 20.0Mb 10ms DropTail
$ns duplex-link $n3 $n2 20.0Mb 10ms DropTail
$ns duplex-link $n3 $n4 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n6 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n5 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n7 20.0Mb 10ms DropTail

$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n3 $n2 orient left-down
$ns duplex-link-op $n3 $n4 orient right
$ns duplex-link-op $n4 $n6 orient right
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n7 orient right-down

#===================================
#        Agents Definition        
#===================================

set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
$ns attach-agent $n1 $tcp

set udp [new Agent/UDP]
$ns attach-agent $n2 $udp

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $tcp
$cbr set packet_size_ 1500

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

# null & sink

set null [new Agent/Null]
$ns attach-agent $n6 $null
$ns connect $udp $null

set sink [new Agent/TCPSink]
$ns attach-agent $n6 $sink
$ns connect $tcp $sink


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

$ns at 0.5 "$ftp start"
$ns at 5.0 "$ftp stop"

$ns at 6.0 "finish"
$ns run

当我使用ns file.tcl运行此代码时 - 我会收到以下错误:

 Error:  sendmsg() for UDP should not be -1
ns: _o180 stop: 
    (_o177 cmd line 1)
    invoked from within
"_o177 cmd advance 0"
    invoked from within
"catch "$self cmd $args" ret"
    invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
    (procedure "_o177" line 2)
    (SplitObject unknown line 2)
    invoked from within
"[$self agent] advance 0"
    (procedure "_o180" line 2)
    (Application/FTP stop line 2)
    invoked from within
"_o180 stop"

I'm writing a script in TCL using NS and NAM.

What is the statement question I'm trying to solve? Here it is:

Question

Following is the TCL script I have written to solve the above problem. I'm using NS2 and NAM packages in Ubuntu 20.04. I'm tasked to create 8 nodes, link them using duplex-link (of any capacity), apply TCP Agent on node 0 & 1 and apply UDP on node 2.

Then, I need to connect the TCP Agent(s) with CBR source and UDP agent with FTP source. Following is my code:

set val(stop)   10.0;


set ns [new Simulator]

#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile

#===================================
#        Nodes Definition        
#===================================
#Create 8 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]

$ns duplex-link $n0 $n3 20.0Mb 10ms DropTail
$ns duplex-link $n1 $n3 20.0Mb 10ms DropTail
$ns duplex-link $n3 $n2 20.0Mb 10ms DropTail
$ns duplex-link $n3 $n4 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n6 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n5 20.0Mb 10ms DropTail
$ns duplex-link $n4 $n7 20.0Mb 10ms DropTail

$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n3 $n2 orient left-down
$ns duplex-link-op $n3 $n4 orient right
$ns duplex-link-op $n4 $n6 orient right
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n7 orient right-down

#===================================
#        Agents Definition        
#===================================

set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
$ns attach-agent $n1 $tcp

set udp [new Agent/UDP]
$ns attach-agent $n2 $udp

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $tcp
$cbr set packet_size_ 1500

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

# null & sink

set null [new Agent/Null]
$ns attach-agent $n6 $null
$ns connect $udp $null

set sink [new Agent/TCPSink]
$ns attach-agent $n6 $sink
$ns connect $tcp $sink


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

$ns at 0.5 "$ftp start"
$ns at 5.0 "$ftp stop"

$ns at 6.0 "finish"
$ns run

When I run this code using ns file.tcl - I get the following error:

 Error:  sendmsg() for UDP should not be -1
ns: _o180 stop: 
    (_o177 cmd line 1)
    invoked from within
"_o177 cmd advance 0"
    invoked from within
"catch "$self cmd $args" ret"
    invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
    (procedure "_o177" line 2)
    (SplitObject unknown line 2)
    invoked from within
"[$self agent] advance 0"
    (procedure "_o180" line 2)
    (Application/FTP stop line 2)
    invoked from within
"_o180 stop"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文