- Hi, I do not think that there is a "problem" with the variables per se, but with the way that the TCL interpreter handles the command substitutions.
For example, when you invoke the command directly, i.e. with no wrapping procedure, the NS scheduler schedules the event to occur at time 1.0, but the event itself is actually to "puts stdout \"Rx bytes (directly): 0\"". What happens, is that when the interpreter comes across this command it SUBSTITUTES the part "[$tcp1 set bytes_]", with the actual value at that point (which is always 0) and schedules the command above to execute at point 1.0, which includes only the printout and nothing more. On the other hand, when you invoke it using a wrapper proc, the interpreter does not do any substitutions at the point of scheduling (i.e. $ns at 1.0 testproc) but simply schedules the procedure to execute at point 1.0, which in turn will substitute the correct value of bytes_ at time 1.0. Any substitutions in this case are deliberately left to the procedure from the interpreter. This way of behavior, is for any command - scheduling - want - to - substitute - with value processes. :-) I hope that I have helped. -Fk On 6/14/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > ---------- Forwarded message ---------- > From: Georg Piewald <[EMAIL PROTECTED]> > To: ns-users@ISI.EDU > Date: Wed, 13 Jun 2007 11:35:30 +0200 > Subject: [ns] Strange behaviour of TCPSink instvar "bytes_" > Hi everybody, > > I experienced a very odd problem. I want to output the number of bytes > received by a TCPSink agent at a specified time. This can be read by the > instance variable $bytes_. > Now if I call a procedure at the required point of time, which outputs > the nr of bytes, everything works fine. Like this: > > ... > proc testproc {} { > global tcp1 > puts stdout "Rx bytes (within testproc): [$tcp1 set bytes_]" > } > ... > $ns at 1.0 testproc > ... > > But if I want to output this value directly (without a wrapping > procedure, the output is always 0! Like that: > > $ns at 1.0 "puts stdout \"Rx bytes (directly): [$tcp1 set bytes_]\"" > > How can that be? > I use ns-2.31. The complete code of a minimal example to reproduce the > problem is here: > > > ######################### Example ############################# > > set ns [new Simulator] > > proc testproc {} { > global tcp1 > puts stdout "Rx bytes (within testproc): [$tcp1 set bytes_]" > } > > set n0 [$ns node] > set n1 [$ns node] > $ns duplex-link $n0 $n1 1mb 50ms DropTail > > set tcp0 [new Agent/TCP] > set tcp1 [new Agent/TCPSink] > > $ns attach-agent $n0 $tcp0 > $ns attach-agent $n1 $tcp1 > $ns connect $tcp0 $tcp1 > > set ftp0 [new Application/FTP] > $ftp0 attach-agent $tcp0 > > $ns at 0.1 "$ftp0 start" > $ns at 1.0 testproc > $ns at 1.0 "puts stdout \"Rx bytes (directly): [$tcp1 set bytes_]\"" > $ns at 1.5 "$ftp0 stop" > $ns at 1.6 "exit 0" > $ns run > > ######################## /Example ############################# > > > Output: > > % ns min_ex.tcl > Received bytes (within testproc): 66600 > Received bytes (directly): 0 > > > Thanks for any hint! > Georg > > -- Filippos N Kolovos Software Systems Analyst & Engineer M.Sc. (Eng.) in Data Communications Automation & Networking Department University of Macedonia Library Egnatia 156, P.O.Box 1591 540 06 Thessaloniki, Greece E-Mail: [EMAIL PROTECTED], [EMAIL PROTECTED] ----------------------------------------------