Sunday, January 15, 2017

ns-3 Shorts: PyViz!!

How do you turn "Viz" on?

Firstly, sorry for sneaking in the Age of Empires reference in a post about an open source software but then moving on. I have been working on ns-3 for quite sometime now, and if you work on a software for sometime, you, at times, start feeling like.... well, *insert your favourite Hackerman Meme here*.  I have observed that a lot of new users completely overlook the functionality of PyViz which ns-3 provides. PyViz allows you to visualise your simulation without adding a single line of code, but it needs proper python configuration.

First, to run any simulation with PyViz, you just need to add --vis during execution.

./waf --run second --vis

If your python configuration is correct, you can see visualisation on screen.

To see if your PyViz is enabled, try

./waf configure

And see the output for "PyViz visualizer", it should show either "enabled", or "not enabled (Python Bindings are needed but not enabled)"

Now ns-3 documentation provides a long and detailed explanation of how to download and run ns-3 on any system, but they recommend the installation of the allinone package or installation through bake. Both these methods along side the base ns-3 directory, contains a few other directories including a version of pybindgen. This is the "by the book" method to do it, but if you want to keep several copies of ns-3, installing every time with these processes will have both time and space overheads. 

So, here goes the alternative method. The most important dependency of ns-3 which comes in all these installations is pybindgen and, even though it is an optional dependency, it is a necessary requirement to unlock all the python based functionality of ns-3, say, PyViz. So, what should we do to a important dependency? Install it globally. Installing pybindgen globally makes the installation of a new copy of ns-3 very easy. 

To install pybindgen globally you can just clone this, and do a python install and you can get your ns-3 work with python without having a pybindgen in the directory one level above it.

*A PG rated hack* 
Every version of ns-3 comes with a specific commit hash of the above repository, so your latest globally installed pybindgen might not work for older versions, but you can try to overcome by editing the pybindgen version (you can see your pybindgen version in the output of ./waf configure) in bindings/python/wscript, but this might work for only a few versions.


Now there is a chance that even after the configuration is proper, the PyViz might not show up. That might be because the command line parser has not been added to code.

  CommandLine cmd;
  cmd.Parse (argc,argv);

No comments:

Post a Comment