Tuesday, December 13, 2011

[ns] On-the-fly ns2 interpreter

Hi everyone,

Firstly, great job to the team on the wiki, forums, and mailing lists. It
really helped me to get to speed with ns2.

I'd like to use ns2 along with external packet data sources in real-time,
e.g. a message received on a socket on my linux PC should be sent over the
network currently being simulated in ns2. My current understanding is that
the events have to be specified in a Tcl script before the simulation is
run (via the Simulator class/command). Once the simulation is running, and
a packet arrives on my socket, I would like to "inject" an event into the
simulator.

The rest of my code is in C++. My approach: I extracted some of the code
from the ns source (~ns/common/tclAppInit.cc) and tried to create an
instance of the interpreter myself, and then plan to use Tcl::eval() and
its variants to interface with the simulator in real-time...similar to what
ns does on an input script file. I'm having trouble with the EmbeddedTcl
codes from "~ns/gen/ns_tcl.cc" and "~ns/gen/ptypes.cc". After calling
et_ns_ptypes.load() and et_ns_lib.load(), I was assuming that the ns2 OTcl
classes would be available, but when I run 'tcl.evalc("set ns [new
Simulator]");', I get the following run-time error:

mytest:
> [code omitted because of length]
> : invalid command name "Simulator"
> while executing
> "Simulator proc address-format {} {
> return [Simulator set AddressFormat_]
> }"
>

What am I missing from the ns2 source that imported the class definitions
into the Tcl interpreter? Is there a scoping difference between
Tcl::evalc() and Tcl_Eval()?

Any help is greatly appreciated. For those interested, the simple code I
have is available here:
http://pastebin.com/LXmsgiya

Thanks,
Nikhil

No comments:

Post a Comment

Counter

blogger analytics