【问题标题】:-1 records Segmentation Fault core dumped-1 记录 Segmentation Fault 核心转储
【发布时间】:2015-02-20 09:19:55
【问题描述】:

我正在尝试使用 NS-2 中的 Application/Traffic/Trace 从节点 1 到节点 2 传输二进制文件(视频帧的帧),它给了我错误,Segmentation Fault Core dumped。 TCL脚本如下:

set ns [new Simulator]

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 f [open aj/star.tr w]
$ns trace-all $f
set nf [open aj/star.nam w]
$ns namtrace-all $nf


$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail
$ns duplex-link $n0 $n2 10Mb 5ms DropTail
$ns duplex-link $n0 $n3 10Mb 5ms DropTail
$ns duplex-link $n0 $n4 10Mb 5ms DropTail
$ns duplex-link $n0 $n5 10Mb 5ms DropTail


set tfile [new Tracefile]
$tfile filename starwars

set original_file_name csencoding.binary
set trace_file_name video.dat
set original_file_id [open $original_file_name r]
set trace_file_id [open $trace_file_name wb]
set s4 [new Agent/UDP]
$ns attach-agent $n4 $s4

set null1 [new Agent/Null]
$ns attach-agent $n1 $null1

$ns connect $s4 $null1

set trace [new Application/Traffic/Trace]
$trace attach-tracefile $tfile

$trace attach-agent $s4



$ns at 1.0 "$trace start"

$ns at 110.0 "$trace stop"

$ns at 120.0 "finish"

proc finish {} {

         global ns nf f
         $ns flush-trace
         close $f
         close $nf
  exec nam aj/star.nam &
         exit 0

}

$ns run

二进制文件:

1000110 1101111 1110010 1100101 1101101 1100001 1101110 1010001 1000011 1001001 1000110 0101110 0110000 0110000 0110000 0101110 1110000 1100111 1101101 1011111 1000011 1010011 1000100 1100001 1110100 1100001 0101110 1100100 1100001 1110100

【问题讨论】:

  • 你忘了问问题。出于某种原因,该按钮被标记为
  • 您可能想要更改您的标签; helper 在这里似乎真的不是一个有用的标签。 tcl 或许?
  • 二进制数据是文件名“ForemanQCIF.000.pgm_CSData.dat”。我怀疑“set original_file_id [open $original_file_name r]”应该打开“ForemanQCIF.000.pgm_CSData.dat”。

标签: tcl helper ns2


【解决方案1】:

二进制字符串转文本

在尝试打开文件之前,您需要将文件名作为文本获取或将 csencoding.binary 转换为文本。它无法打开文件名的“1000110 ...”表示。这是一个可以将7位二进制转换为文本的过程。

#!/usr/bin/tclsh

set bin "1000110 1101111 1110010 1100101 1101101 1100001 1101110 1010001 1000011 1001001 1000110 0101110 0110000 0110000 0110000 0101110 1110000 1100111 1101101 1011111 1000011 1010011 1000100 1100001 1110100 1100001 0101110 1100100 1100001 1110100"

proc bin7str {bin} {
        set str ""
        foreach {el} $bin {
                append str [binary format B* "0${el}"]
        }
        return $str
}

puts [bin7str $bin]

输出:

./bin.tcl
ForemanQCIF.000.pgm_CSData.dat

【讨论】:

  • 重新考虑打开文件后我没有看到 $original_file_id 被使​​用。除非有升级或升级来获得它,否则它看起来像未使用过。
猜你喜欢
  • 2017-12-14
  • 1970-01-01
  • 2014-10-11
  • 1970-01-01
  • 2022-11-24
  • 1970-01-01
  • 1970-01-01
  • 2021-01-16
  • 2011-09-29
相关资源
最近更新 更多