[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] Linking C++ and OTcl



it's all about tcl's substitution rule. compare this:

set ns [new Simulator]
$ns at 3.0 "puts [$ns now]"
set a 1.0
$ns at 3.0 "set a [$ns now]; puts $a"
set b 123
$ns at 4.0 "set b [$ns now]"
$ns at 5.0 "puts $b"
$ns run

with

set ns [new Simulator]
$ns at 3.0 {puts [$ns now]}
set a 1.0
$ns at 3.0 {set a [$ns now]; puts $a}
set b 123
$ns at 4.0 {set b [$ns now]}
$ns at 5.0 {puts $b}
$ns run

you see the difference. you can find more details in any of the two tcl
books.

you'll learn this if you use tk's bind for a while.

- Haobo

> I have a little problem implementing a new routing agent in ns.
> I don't understand how the "at" command of Simulator objects work.
>
>
> Here are the strange behaviours I noticed :
> (suppose 'findRoute' is a command of my Routing Agent that takes two
> parameters and
> returns an int )
>
> In a TCL script, I have :
> 	$ns_ at 3.0 "[$node_(0) set ragent_] findRoute 4 1500"
> In this case, everything is OK, except I don't get the return value
> (obviously).
>
> Now, if I type
> 	$ns_ at 3.0 "puts [[$node_(0) set ragent_] findRoute 4 1500]"
> I get the correct result except that findRoute is executed a time 0.0
>
> And when I type
> 	$ns_ at 3.0 "set route [[$node_(0) set ragent_] findRoute 4 1500]"
> there is an error because the interpreter doens'nt know about 'route' variable.
>
> Finally, if I have :
> 	set route 234
> 	$ns_ at 3.0 "set route [[$node_(0) set ragent_] findRoute 4 1500]"
> the value of  route is still 234 after the execution of the command
> AND findroute
> is executed at time 0.0
>
> ---
>
> All I vant to do is find a route at a certain time and return a value
> which makes me
> able to identify the route later. Is there a way to do this ?
> I've been trying to solve this by many ways, but I didn't manage to
> do it. I've searched
> the whole Tcl and C++ sources without any success. Please help.
>
> Thanks a lot
>
> Claude.
>
>