[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] Problems using ns object in OTcl
Hi all,
I am having troubles using ns object (eg agents and nodes) in my own custom
OTcl class Entity.
I want to be able to create a new entity which then consists of a node a TCP
agent and a TCPSink. If I can write this wrapper class I maybe able to catch
the done of the TCP agent and use this to implement client server behaviour.
However when I try to use the agents in this class I get an error message
from ns:
trace: can't attach _o10 for writing.
My guess is that the class doesn't contain pointers to the objects but
copies of them. Any ideas of whats wrong and how I could accomplish what I
am trying to do are very much appreciated.
Below my tcl-script and the error message
Regards,
Mark Janssen
----- test.tcl -----
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows
$ns color 1 Blue
Class Entity
Entity instproc init {sender receiver node} {
$self set sender_ $sender
$self set receiver_ $receiver
$self set node_ $node
}
Entity instproc start {} {
global ns
$self instvar sender_
$self instvar receiver_
$self instvar node_
$ns attach-agent $sender_ $node_
$ns attach-agent $receiver_ $node_
}
Entity instproc done {} {
global ns
$ns trace-annotate "Done"
puts "Done"
}
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Open the trace file
set f [open out.tr w]
$ns trace-all $f
#Define a 'finish' procedure
proc finish {} {
global ns nf f
$ns flush-trace
close $f
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$ns duplex-link $n0 $n1 1Mb 80ms DropTail
$ns duplex-link $n1 $n2 1Mb 80ms DropTail
set tcp1 [new Agent/TCP]
set sink1 [new Agent/TCPSink]
set server1 [new Entity $tcp1 $sink1 $n0]
set tcp2 [new Agent/TCP]
set sink2 [new Agent/TCPSink]
set server2 [new Entity $tcp2 $sink2 $n2]
$server1 start
$server2 start
$ns connect [$server1 set sender_] [$server2 set receiver_]
#Call the finish procedure after 5 seconds of simulation time
$ns at 0.1 "[$server1 set sender_] send 1000"
$ns at 5.0 "finish"
#Run the simulation
$ns run
----- test.tcl -----
----- err.log -----
[mjanssen@laptop myscripts]$ ns test.tcl
trace: can't attach _o10 for writing
(_o59 cmd line 1)
invoked from within
"_o59 cmd attach _o10"
invoked from within
"catch "$self cmd $args" ret"
(procedure "_o59" line 2)
(SplitObject unknown line 2)
invoked from within
"$node attach $agent"
(procedure "_o3" line 2)
(Simulator attach-agent line 2)
invoked from within
"$ns attach-agent $sender_ $node_"
(procedure "_o61" line 6)
(Entity start line 6)
invoked from within
"$server1 start "
(file "mark.tcl" line 69)
[mjanssen@laptop myscripts]$
----- err.log -----
------------
Mark Janssen
Institute of Computational Physics
Room MG307
Telephone 030-2537724