tclファイルが実行できません
ubuntu16.04でns2(ns-2.34)を使っています。
サンプルのtclスクリプト(run550.tcl)を実行しようとした結果
以下のようなエラーが表示されました。
~/ns-allinone-2.34/ns-2.34/myworkspace/tcl$ ns run550.tcl
wrong # args: should be "source fileName"
while executing
"source -encoding utf-8 [file join $TclLibDir clock.tcl]"
(procedure "::tcl::clock::format" line 3)
invoked from within
"clock format [clock seconds] -format {%Y/%m/%d(%a) %p %I:%M:%S}"
invoked from within
"puts $SimT [clock format [clock seconds] -format {%Y/%m/%d(%a) %p %I:%M:%S}]"
(file "run550.tcl" line 49)
実行しているプログラミングはサンプルです。
何がエラーにつながっているのか理解できません
すみませんがご教授お願いします。
追記:
こちらで同様の質問をしています。
https://forums.ubuntulinux.jp/viewtopic.php?id=20199
実験環境の設定等を記述しているrun550.tclのソースのみ貼ります。
これをns-2.34フォルダ内で保存し。実行します
実行コマンド:~/ns-allinone-2.34/ns-2.34$ ns run550.tcl
#Copyright (c) 1997 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the Computer Systems
# Engineering Group at Lawrence Berkeley Laboratory.
# 4. Neither the name of the University nor of the Laboratory may be used
# to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Each agent keeps track of what messages it has seen
# and only forwards those which it hasn't seen before.
# Each message is of the form "ID:DATA" where ID is some arbitrary
# message identifier and DATA is the payload. In order to reduce
# memory usage, the agent stores only the message ID.
# Note that I have not put in any mechanism to expire old message IDs
# from the list of seen messages. There also isn't any standard mechanism
# for assigning message IDs. An actual assignment may wish to have the
# students come up with solutions for these problems.
remove-all-packet-headers
add-packet-header Common IP RTP
set SimT [open "Simtime.txt" w]
puts $SimT [clock format [clock seconds] -format {%Y/%m/%d(%a) %p %I:%M:%S}]
puts "###############################################"
puts "# Simulation Start"
puts "###############################################"
# port number
set MESSAGE_PORT 42
# parameters for topology generator
set peer_num 540 ;#送信先の数
set stubNum 10 ;#このidからスタブノード
set max_id 550 ;#ノード最大数
set Snum [expr $stubNum + $peer_num] ;#送信先 last id
set R_interval 360.0
set ROST_timing 360.0
set finish_time 1800.0
#set group_size 7
#set num_groups 5
#set num_nodes [expr $group_size * $num_groups]
# trial number
set trial_count 30
##################################################
# only existing idea(ROST):0
# existing idea + my idea:1
##################################################
set idea 1
# mkdir name:$dir $dir = ../result/trial_***_$trial_count_$Snum
set dir ../result/trial_
if {$idea == 0} {
append dir ROST_
} elseif {$idea == 1} {
append dir myApproach_
} else {
append dir myIdea_
}
append dir $trial_count
append dir _$Snum
append dir _$finish_time
exec mkdir $dir
# mkdir finish
# make mid flow file
set mid [open "mid-flow" w]
puts $mid [clock format [clock seconds] -format {%Y/%m/%d(%a) %p %I:%M:%S}]
puts $mid "Snum:$Snum idea:$idea trial:$trial_count"
close $mid
set ns [new Simulator]
#set f [open flooding.tr w]
#$ns trace-all $f
##set nf [open flooding.nam w]
#$ns namtrace-all $nf
proc ALMstop {id} {
global a
$a($id) set ALM -1
}
proc disruptALM {cid} {
global app n server
if {[$n($cid) mc-member] == 1 && $cid != $server} {
$app($cid) ALMdisrupt
}
}
proc R_run_stop {} {
global n app stubNum Snum
for {set i $stubNum} {$i < $Snum} {incr i} {
if {[$n($i) mc-member] == 1 } {
$app($i) R_notrun
}
}
}
# log statics
proc fileoutput {} {
global app stubNum Snum dir n server serverdegree
# logfile name $dir = ../result/trial_***_$trial_count_$Snum/treestate
append dir /treestate
set TS [open "$dir" w]
puts $TS "server id:$server\tdegree:$serverdegree"
puts $TS "id root start_t stop_t total_recv SD_recv descenNum degree u_degree f_degree depth leaf parent_id child_id"
close $TS
for {set i $stubNum} {$i < $Snum} {incr i} {
if {[$n($i) mc-member] == 1 } {
$app($i) treestate $dir
}
}
}
# finish proc
proc finish {} {
global ns f nf paraS at_f lt_f bw_f SimT
puts ""
puts "(Otcl)finish!!!!!!!!!!!!!"
puts ""
puts $SimT [clock format [clock seconds] -format {%Y/%m/%d(%a) %p %I:%M:%S}]
$ns flush-trace
#close $f
#close $nf
close $paraS
close $at_f
close $lt_f
close $bw_f
close $SimT
fileoutput
puts "running nam..."
#exec nam flooding.nam &
exit 0
}
# descendant manage
proc descendant {} {
global app stubNum Snum n
for {set i $stubNum} {$i < $Snum} {incr i} {
if {[$n($i) mc-member] == 1 } {
$n($i) descendantnum_reset
}
}
for {set i $stubNum} {$i < $Snum} {incr i} {
if {[$n($i) mc-member] == 1 } {
$app($i) descendant
}
}
}
# rejoin proc
proc ALM_rejoin {Fid} {
global ns a
puts ""
puts "(Otcl)ALM Rejoining\tFid = $Fid"
puts ""
set t [$ns now]
set mid [open "mid_flow" a]
puts $mid "$t $Fid rejoing"
close $mid
$a($Fid) set parent_Element {}
$a($Fid) set messages_seen {}
$a($Fid) set count 0
$a($Fid) set flooding_timeout -1
$a($Fid) set flooding_count -1
$a($Fid) send_message 9 -1 {ALM search} $Fid
$ns at [expr $t+1.0] "$a($Fid) time_manegement $Fid [expr $t+0.10]"
after 1200
#exit 0
}
##############################################
# only existing idea(ROST):0
# existing idea + my idea:1
##############################################
#set idea 0
# myidea proc
proc MYIDEA {} {
global ns app n idea stubNum Snum server
puts ""
puts "(Otcl)MY IDEA start"
puts ""
set MY 0
for {set i $stubNum} {$i <= $Snum} {incr i} {
if {[$n($i) mc-member] == 1 && $i != $server} {
if {[$app($i) L_run] == 1} {
$ns at [expr $now+3.0] "MYIDEA"
set MY 1
break;
}}
}
if {$MY == 0} {
for {set i $stubNum} {$i <= $Snum} {incr i} {
if {[$n($i) mc-member] == 1 && $i != $server} {
$app($i) MYIDEA_start
}
}
}
}
# ROST proc
proc ROST {} {
global ns app n idea stubNum Snum R_interval server
puts ""
puts "(Otcl)ROST start"
puts ""
set t $R_interval
set now [$ns now]
set L 0
for {set i $stubNum} {$i < $Snum} {incr i} {
if {[$n($i) mc-member] == 1 && $i != $server} {
if {[$app($i) L_run] == 1} {
$ns at [expr $now+3.0] "ROST"
set L 1
break;
}}
}
if {$L == 0} {
for {set i $stubNum} {$i < $Snum} {incr i} {
if {[$n($i) mc-member] == 1 && $i != $server} {
$app($i) ROST_start $idea
}
}
$ns at [expr $now+$t] "ROST"
}
}
# class member
source flooding_class.tcl
## Topology Generator
puts "node create start"
for {set i 0} {$i <= $Snum} {incr i} {
#puts -nonewline "$i..."; flush stdout
set n($i) [$ns node]
}
puts "node create finish"
$n($Snum) shape "hexagon"
# parameter
source linkdelay.tcl ;#bounded-random link delay
source ../link/$Snum.tcl ;#physical link
set paraS [open "../para/$Snum/server$Snum-$trial_count.txt" r]
set at_f [open "../para/$Snum/arrival$Snum-$trial_count.txt" r]
set lt_f [open "../para/$Snum/leave$Snum-$trial_count.txt" r]
set bw_f [open "../para/$Snum/degree$Snum-$trial_count.txt" r]
#サーバー決定 - server dicision
gets $paraS serverID
set server $serverID
set serverdegree 100
#puts "server\t$server"
$n($server) shape "box"
# attach a new Agent/MessagePassing/Flooding to each node on port $MESSAGE_PORT, Agent_id, degree, server_id
for {set i 0} {$i < $Snum} {incr i} {
set a($i) [new Agent/MessagePassing/Flooding]
$n($i) attach $a($i) $MESSAGE_PORT
$a($i) set messages_seen {}
$a($i) setid $i
if {$i >= $stubNum && $i != $Snum} {
gets $bw_f degree_num
gets $lt_f stop_time
#puts "$i:degree_num \t $degree_num"
if {$i != $server} {
$a($i) set degree $degree_num
$a($i) set stoptime $stop_time
} elseif {$i == $server} {
$a($i) set degree $serverdegree
}
} elseif {$i == $Snum} {
$a($i) set degree 0
}
#$a($i) puts "id:$i , degree:$degree"
$a($i) set root $server
}
set tree [new ALMtree]
$tree tracefile $dir
# logfile name $dir = ../result/trial_***_$trial_count/descendant
set DL [open "$dir/descendant" w]
puts $DL "server id:$server\tdegree:$serverdegree"
puts $DL "id stop_t descenNum"
close $DL
#$ns duplex-link $n($Snum) $n($server) $linkBW [tt] DropTail
$ns at $ROST_timing "ROST"
$a($server) set ALM_ 1
set app($server) [new ALMApp 1 -1 $serverdegree $n($server) $tree]
$app($server) start
#$ns at 0.0 "$a($Snum) send_message 900 -1 {ALM search} $Snum"
#$ns at 0.1 "$a($Snum) time_manegement $Snum 0.0"
#set app($Snum) [new ALMApp -1 $server 0 $n($Snum) $tree]
#$app($Snum) start
set fID $stubNum
# now set up some events
for {set i $stubNum} {$i < $Snum} {incr i} {
gets $at_f arrival_time
$a($i) set AT $arrival_time
# if {$i == $server || $i < 41}
if {$i != $server} {
puts "$i:arrivaltime \t $arrival_time"
$ns at $arrival_time "$a($i) send_message 9 $fID {ALM search} $i"
$ns at [expr $arrival_time+1.0] "$a($i) time_manegement $i [expr $arrival_time+1.0]"
incr fID
}
}
$ns at $finish_time "finish"
$ns run