Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error while running tcl script in Linux, pls help

Status
Not open for further replies.

munnadee

Technical User
Dec 14, 2005
7
FI
Hi Everybody,

I am learning TCL and very new to it. I have been trying to execute some tcl script in a console. It runs the script well in the starting but sometimes it says the following error:

ns: finish:
while executing
"close $namtracefd"
(procedure "finish" line 5)
invoked from within
"finish"

Though there is not mistake and it runs well in the starting it starts saying the above error after a few trials. Any idea how to get rid of this error? Pls let me know if anybody cud help me out. Thanks alot.
 
Hi,

This is the procedure.

proc finish {} {
global ns_ tracefd namtracefd myfile
$ns_ flush-trace
close $tracefd
close $namtracefd
close $myfile

exec nam wired-and-wireless.nam &
}

Though I am closing all the data files in the finish procedure still its showing some error either of namtracefd or of tracefd.

Thanks for your reply.
 
Hi

Hmm... Abit more complicated. I thinked it is only a short test script. I suspect that something could happen in that $ns_ .

Hope that someone older in Tcl see any typical error. If possible post the entire script or make it available on-line.

Feherke.
 
Hi,

You can find the task description here at this link:
My task it to plot a graph of Fairness indices against different TCP packet sizes in a wired and wireless network transmission. I am trying to calculate throughput and fairness index values with the proc 'CalculateThroughput {}' and trying to put it in 'myfile' datafile. It prints the throughput values which it has been asked to but is giving an error at the end when it is about to execute Nam. Please go through the script if you can find anything.

This is the whole script.


# This simulation is a combination of wired and wireless topologies.
# Define options
#==============================================================
global opt
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) 670
set opt(y) 670
set opt(ifqlen) 50
set opt(tr) wired-and-wireless.tr
set opt(namtr) wired-and-wireless.nam
set opt(nn) 3
set opt(adhocRouting) DSDV
set opt(cp) ""
set opt(sc) "../mobility/scene/scen-3-test"
set opt(finish) 60
#===============================================================

#argument setting for the input by the user
if { $argc != 1 } {
puts "Error: ns script.tcl <TCPpacket_size>, <TCPpacket_size> >= 0"
exit 1
}
set PacketSize_ [expr [lindex $argv 0]]

#setting number of wired and base sation node
set num_wired_nodes 2
set num_bs_nodes 2

#simulator instance
set ns_ [new Simulator]

# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 3
lappend cluster_num 2 1 1
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 4 1
AddrParams set nodes_num_ $eilastlevel

#open trace and nam file
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd
set namtracefd [open $opt(namtr) w]
$ns_ namtrace-all $namtracefd

#open trace file for tcpsizes and fairness indices..
set myfile [open fairnfd.tr w]


#setting up topology of the network
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)

# Define a 'finish' procedure
proc finish {} {
global ns_ tracefd namtracefd myfile
$ns_ flush-trace
close $tracefd
close $namtracefd
close $myfile

exec nam wired-and-wireless.nam &
}

#god needs to know the number of all wireless interfaces
create-god [expr $opt(nn) + $num_bs_nodes]

#create wired nodes
set temp {0.0.0 0.1.0}
for {set i 0} {$i < $num_wired_nodes} {incr i} {
set W($i) [$ns_ node [lindex $temp $i]]
}

#Configure nodes
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propInstance [new $opt(prop)] \
-phyType $opt(netif) \
-channel [new $opt(chan)] \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF

#setup base sations
set temp {1.0.0 1.0.1 1.0.2 1.0.3 1.0.4}
set BS(0) [$ns_ node [lindex $temp 0]]
set BS(1) [$ns_ node 2.0.0]
$BS(0) random-motion 0
$BS(1) random-motion 0
$BS(0) set X_ 1.0
$BS(0) set Y_ 2.0
$BS(0) set Z_ 0.0

$BS(1) set X_ 50.0
$BS(1) set Y_ 100.0
$BS(1) set Z_ 0.0

#configure mobilenodes in the base sation domain
$ns_ node-config -wiredRouting OFF

for {set j 0} {$j < $opt(nn)} {incr j} {
set node_($j) [ $ns_ node [lindex $temp \
[expr $j+1]] ]
$node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}

# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes

$node_(0) set X_ 100.0
$node_(0) set Y_ 200.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 10.0
$node_(1) set Y_ 300.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 100.0
$node_(2) set Y_ 400.0
$node_(2) set Z_ 0.0

#create links between wired and BS nodes
$ns_ duplex-link $W(0) $W(1) 1Mb 10ms DropTail
$ns_ duplex-link $W(1) $BS(0) 1Mb 10ms DropTail
$ns_ duplex-link $W(1) $BS(1) 1Mb 10ms DropTail

$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $BS(0) orient left-down
$ns_ duplex-link-op $W(1) $BS(1) orient right-down


# setup TCP connections
set tcp(1) [new Agent/TCP]
$tcp(1) set class_ 2
$tcp(1) set packetSize_ $PacketSize_
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp(1)
$ns_ attach-agent $W(0) $sink1
$ns_ connect $tcp(1) $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp(1)
$ns_ at 5 "$ftp1 start"

set tcp(2) [new Agent/TCP]
$tcp(2) set class_ 2
$tcp(2) set packetSize_ $PacketSize_
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $W(1) $tcp(2)
$ns_ attach-agent $node_(2) $sink2
$ns_ connect $tcp(2) $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp(2)
$ns_ at 5 "$ftp2 start"

#Throughput calculation of the TCP flow
set TCP_Number 2
set STOP 60
set MITTAUS_ALKU 2

proc tallennaAlkutilanne {} {

global TCP_Number tcpBW tcp

for { set i 1 } { $i <= $TCP_Number } { incr i } {
set tcpBW($i) [$tcp($i) set ack_]
}
}

proc CalculateThroughput {} {
global TCP_Number fairness tcp tcpBW myfile PacketSize_
global MITTAUS_ALKU STOP

for { set i 1 } { $i <= $TCP_Number} { incr i } {
set BW($i) [expr [$tcp($i) set ack_] - $tcpBW($i)]
}

set d [expr $STOP - $MITTAUS_ALKU]
for { set i 1 } { $i <= $TCP_Number } { incr i } {
set Throughput($i) [expr 8*$BW($i)/$d * [$tcp($i) set packetSize_ ]]
set Throughput($i) [expr $Throughput($i)+0.00]
}

set x1 [expr ($Throughput(1)+$Throughput(2))*($Throughput(1)+$Throughput(2))]
set x2 [expr ($Throughput(1)*$Throughput(1))+($Throughput(2)*$Throughput(2))]
set x3 [expr 2*$x2]
set fairin_ [expr $x1/$x3]

puts "writing data into tracefile..."
puts $myfile "$PacketSize_ [expr $fairin_+0.00]"

puts "Throughput: $Throughput(1)"
puts "Throughput: $Throughput(2)"
}

#giving initial position to the nodes in the nam
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 20
}

#telling the nodes when to stop
for {set i } {$i < $opt(nn) } {incr i} {
$ns_ at $opt(finish).0000010 "$node_($i) reset";
}

#calling the procedures defined earlier and ending the simulation
$ns_ at [expr $MITTAUS_ALKU] "tallennaAlkutilanne"
$ns_ at [expr $STOP] "CalculateThroughput"
$ns_ at $opt(finish).0000010 "$BS(0) reset";
$ns_ at $opt(finish) "finish"
$ns_ at $opt(finish).1 "puts \"NS EXITING...\" ; $ns_ halt"

puts "Starting Simulation..."

$ns_ run


Thanks.
 
set ns_ [new Simulator]

This doesn't look like a Tcl statement to me. What does it do?

_________________
Bob Rashkin
 
It creates a new Simualtor instance and initializes it to ns_ . It works well in my practice. As I am new to TCL I am not quite professional in using it.
 
So, you're using Incr Tcl?

_________________
Bob Rashkin
 
I am not getting what you r asking for. If you r a bit clearer in ur question I will try to let u know. Thats all the script I have been using so far. And I am not a good user either. Any help pls?
 
As far as just looking at your script, in the body of the script you open to namtracefd so I see no reason why finish should not be able to close it.

That said I don't know where the command new comes from; it's not Tcl. Since I don't know what it does, I'm inclined to suspect that it is the source of your problem.

_________________
Bob Rashkin
 
Actually, everything worked out well with my colleagues. But I am getting the above said errors while trying to execute the file. I guess its not the problem with 'new' command. To say frankly I dont know TCL but working out my assignment by learning it now. Some of my colleagues succeeded in their work. And its all the same script. It might be the problem with runtime environment, I doubt.

Thanks for your help anyway. But still I have to work it out. =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top