Ns2 程序中的分段错误
Segmentation fault in Ns2 program
我提到了 ns2 的一个程序,当我更改此程序时,该程序给了我分段错误(核心已转储)-> $ns at 0.5 “$cbr0 start” 为 this->$ns at 0.5 "$cbr0开始”。 ""有什么问题吗。如果我把""改成""下面是错误
错误
(_o5 命令第 1 行)
从内部调用
“_o5 cmd 在 0.5 “_o84 开始””
从内部调用
"catch "$self 命令 $args"ret"
从内部调用
"if [catch "$self 命令 $args" ret] {
设置 cls [$self 信息 class]
全局错误信息
设置 savedInfo $errorInfo
错误 "error when calling class $cls: $args" $..."
(程序“_o5”第 2 行)
(SplitObject 未知第 2 行)
从内部调用
“_o5 在 0.5 “o84 开始””
("eval" 正文第 1 行)
从内部调用
"eval $scheduler at $args"
(程序“_o3”第 3 行)
(第 3 行的模拟器)
从内部调用
“$ns 在 0.5 “$cbr0 开始””
(文件"b.tcl"第71行)
代码:
set ns [new Simulator]
#Define different colors for data flow
$ns color 1 Blue
$ns color 2 Red
#open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#define a finish procedure
proc finish {} {
global ns nf
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam&
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#create links between nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms SFQ
#orientation
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitors the queue for the link betweeen node 2 & 3
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Create udp agent and attatch it to node 0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0
#Create CBR traffic source & attatch it to upd0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create udp agent and attatch it to node 1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
#Create CBR traffic source & attatch it to upd1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr0 attach-agent $udp1
#Create a CBR traffic source & attatch it to udp 1
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
#connect the traffic source with the traffic sink
$ns connect $udp0 $null0
$ns connect $udp1 $null0
#Schedule events for the CBR agent
$ns at 0.5 “$cbr0 start”
$ns at 1.0 “$cbr1 start”
$ns at 4.0 “$cbr1 stop”
$ns at 4.5 “$cbr0 stop”
#call finish after 5 seconds of simulation time
$ns at 5.0 “finish”
#Run the simulator
$ns run
“ ”在 Unix / Linux 程序中不是合法字符。必须是“ ”。
与您的文件相似的文件是 "second.tcl" → udp-examples-2.tar.gz →
https://drive.google.com/file/d/0B7S255p3kFXNcDJOTWNUaFJrSkE/view?usp=sharing
'second.tcl' :
set ns [new Simulator]
#Define different colors for data flow
$ns color 1 Blue
$ns color 2 Red
#open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#define a finish procedure
proc finish {} {
global ns nf
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam&
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#create links between nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms SFQ
#orientation
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitors the queue for the link betweeen node 2 & 3
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Create udp agent and attatch it to node 0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0
#Create CBR traffic source & attatch it to upd0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create udp agent and attatch it to node 1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
#Create CBR traffic source & attatch it to upd1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr0 attach-agent $udp1
#Create a CBR traffic source & attatch it to udp 1
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
#connect the traffic source with the traffic sink
$ns connect $udp0 $null0
$ns connect $udp1 $null0
#Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
#call finish after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulator
$ns run
工作正常,文件 first.nam 898kB 已创建,'nam' window 打开。
Link,所有 ~2500 个示例 https://drive.google.com/drive/folders/0B7S255p3kFXNSmRYb2lGcDRUdWs?usp=sharing
我提到了 ns2 的一个程序,当我更改此程序时,该程序给了我分段错误(核心已转储)-> $ns at 0.5 “$cbr0 start” 为 this->$ns at 0.5 "$cbr0开始”。 ""有什么问题吗。如果我把""改成""下面是错误
错误
(_o5 命令第 1 行) 从内部调用 “_o5 cmd 在 0.5 “_o84 开始”” 从内部调用 "catch "$self 命令 $args"ret" 从内部调用 "if [catch "$self 命令 $args" ret] { 设置 cls [$self 信息 class] 全局错误信息 设置 savedInfo $errorInfo 错误 "error when calling class $cls: $args" $..." (程序“_o5”第 2 行) (SplitObject 未知第 2 行) 从内部调用 “_o5 在 0.5 “o84 开始”” ("eval" 正文第 1 行) 从内部调用 "eval $scheduler at $args" (程序“_o3”第 3 行) (第 3 行的模拟器) 从内部调用 “$ns 在 0.5 “$cbr0 开始”” (文件"b.tcl"第71行)
代码:
set ns [new Simulator]
#Define different colors for data flow
$ns color 1 Blue
$ns color 2 Red
#open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#define a finish procedure
proc finish {} {
global ns nf
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam&
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#create links between nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms SFQ
#orientation
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitors the queue for the link betweeen node 2 & 3
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Create udp agent and attatch it to node 0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0
#Create CBR traffic source & attatch it to upd0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create udp agent and attatch it to node 1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
#Create CBR traffic source & attatch it to upd1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr0 attach-agent $udp1
#Create a CBR traffic source & attatch it to udp 1
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
#connect the traffic source with the traffic sink
$ns connect $udp0 $null0
$ns connect $udp1 $null0
#Schedule events for the CBR agent
$ns at 0.5 “$cbr0 start”
$ns at 1.0 “$cbr1 start”
$ns at 4.0 “$cbr1 stop”
$ns at 4.5 “$cbr0 stop”
#call finish after 5 seconds of simulation time
$ns at 5.0 “finish”
#Run the simulator
$ns run
“ ”在 Unix / Linux 程序中不是合法字符。必须是“ ”。
与您的文件相似的文件是 "second.tcl" → udp-examples-2.tar.gz →
https://drive.google.com/file/d/0B7S255p3kFXNcDJOTWNUaFJrSkE/view?usp=sharing
'second.tcl' :
set ns [new Simulator]
#Define different colors for data flow
$ns color 1 Blue
$ns color 2 Red
#open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#define a finish procedure
proc finish {} {
global ns nf
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam&
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#create links between nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms SFQ
#orientation
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitors the queue for the link betweeen node 2 & 3
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Create udp agent and attatch it to node 0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0
#Create CBR traffic source & attatch it to upd0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create udp agent and attatch it to node 1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
#Create CBR traffic source & attatch it to upd1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr0 attach-agent $udp1
#Create a CBR traffic source & attatch it to udp 1
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
#connect the traffic source with the traffic sink
$ns connect $udp0 $null0
$ns connect $udp1 $null0
#Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
#call finish after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulator
$ns run
工作正常,文件 first.nam 898kB 已创建,'nam' window 打开。
Link,所有 ~2500 个示例 https://drive.google.com/drive/folders/0B7S255p3kFXNSmRYb2lGcDRUdWs?usp=sharing