Python bindings

From Nsnam
Revision as of 19:48, 27 April 2008 by Tomh (Talk | contribs) (a few more details on python binding installation, from Craig)

Jump to: navigation, search

Overview

Python bindings for NS-3 will primarily allow the programmer to write complete simulation scripts in Python. In addition, writing new models (e.g. routing protocols) in Python will also be possible, although this second goal may take a bit longer to achieve.

Python bindings for NS-3 are being developed using a new tool called PyBindGen. This tool uses gccxml to scan header files and extract API definitions in a semi-automatic way.

Build instructions

  1. Get CMake (can either build from source or download binaries for windows, linux i386);
  2. Get GCC-XML (must download from CVS). Instructions are to be found here;
  3. Download and install pygccxml, version 0.9.5 or greater; (To install: python setup.py install);
  4. Get the PyBindGen bzr branch; instructions here.
    • Note: the bzr branch does not come with a waf script, but the one from NS-3 (1.3.2) works fine (waf trunk may or not work);
    • Download specific version of waf into PyBindGen trunk;
    • ./waf configure; ./waf; ./waf check; ./waf install;
  5. Finally, get the ns-3-pybindgen-notracing branch: http://code.nsnam.org/gjc/ns-3-pybindgen-notracing/
    • ./waf configure; ./waf

The bindings are generated in a one-liner; e.g.

 [186/469] * command-output : bindings/python/ns3modulegen.py build/debug/ns3/everything.h -> build/debug/bindings/python/ns3module.cc

This runs the python program ns3modulegen.py in the repository (that eventually calls pybindgen code generation), includes a file that pulls in every public include file in ns-3, and then writes the bindings out in a file called ns3module.cc that is 100,000 lines of c++ bindings code.

Testing

./waf --shell
python examples/udp-echo.py

Note: some of the python scripts ported over from C++ may not work due to lack of NS-3 API stability.