-1记录分段故障核心转储

时间:2014-12-22 09:33:12

标签: tcl helper ns2

我正在尝试使用NS-2中的应用程序/流量/跟踪从节点1到节点2传输二进制文件(视频帧的帧),它给出了错误,分段故障核心被转储。 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

1 个答案:

答案 0 :(得分:0)

二进制字符串到文本

在尝试打开文件之前,您需要将文件名作为文本或将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