A simple animator is presented here, called NetAnim. Written by George Riley, and based on the multi-platform QT4 GUI toolkit, it is capable of animating simulations in ns-3. NetAnim requires a custom trace file for animation. This trace file is generated by an animation interface and is included in the current version of ns-3.
- 1 Prerequisites
- 2 Downloading NetAnim
- 3 Building NetAnim
- 4 The Animation Interface for ns-3
- 5 Running an Example File
- 6 Creating Custom Scripts for Animation
QT4 development packages
xerces-c++ development packages
Debian or Ubuntu Linux distribution:
qt4-dev-tools. Typically "apt-get install qt4-dev-tools" should be sufficient
Red Hat /Fedora based distribution:
Typically "yum install qt" and "yum install qt-devel" should be sufficient
Mac users should install the binaries:
http://www.qtsoftware.com/downloads/mac-os-cpp Make sure to download the binary package; look for a link to something without the word "src" or "debug" in the download filename. These will be the library binaries you need.
Or you can also try libraries from http://qt.nokia.com/downloads/qt-for-open-source-cpp-development-on-mac-os-x for example: http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.2-debug-libs.dmg
Also, you will require mercurial. See your distribution's packages or the mercurial website for more info.
The tarball of the source code is available here. Download it, then untar it:
tar -xzvf NetAnim.tar.gz
NetAnim uses a QT4 build tool called qmake; this is similar to the configure script from autotools in that it generates the Makefile, which make then uses to build the project. qmake is different on different versions of Qt, so we'll provide some additional information that is system dependent. You can check your default version of qmake:
qmake --version Qmake version: 1.07a (Qt 3.3.8b) Qmake is free software from Trolltech ASA.
If you see something like the above, where it says Qt 3.x.x, find the qt4 version of qmake on your system and explicitly call it instead.
cd NetAnim qmake make
On Mac OS X
cd NetAnim /usr/local/Trolltech/Qt-4.x.y/bin/qmake make
Note that above, the x.y is the specific version of Qt4 you are running. As of April 1st 2009, the latest version is 4.5.0, although you might have an older version already installed.
If the above steps do not work , please see the suggestion below from a user
1. Download Qt libraries for Mac from the page [http://qt.nokia.com/downloads/qt-for-open-source-cpp-development-on-mac-os-x] for example: [http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.2-debug-libs.dmg] 2. Download NetAnim from [http://www.nsnam.org/~jpelkey3/NetAnim.tar.gz] 3. $tar -xzvf NetAnim.tar.gz 4. $cd NetAnim 5. $/usr/bin/qmake-4.7 NetAnim.pro This will create xcode project NetAnim.xcodeproj 6. Open NetAnim.xcodeproj with xcode and build.You will get NetAnim executable.
Special note to Mac OS X Lion users as of July 30, 2011: In the latest build of Qt libraries, namely, http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.3.dmg, qmake generates Xcode .pbproj file instead of Makefile by default. The Xcode file, however, is incompatible to the Xcode tools (version 4.1) for Lion. To get the Makefile output from qmake, one can try the following after installed qt-mac-opensource-4.7.3.dmg:
$ cd /usr/local/Qt4.7/mkspecs/ $ sudo rm default $ sudo ln -s macx-g++ default
Then, qmake will use the GCC template instead of Xcode template for building Qt projects. You can then build NetAnim as usual, namely,
$ tar -zxvf NetAnim.tar.gz $ cd NetAnim $ qmake $ make
On Ubuntu/Debian with Qt3 AND Qt4
cd NetAnim qmake-qt4 make
The Animation Interface for ns-3
The NetAnim GUI requires a custom trace file for animation. This trace file is created by an animation interface in ns-3. The animation interface has been merged with the main tree as of ns-3.6. The source code for the animation interface is located in src/helper.
Running an Example File
Two example scripts exist in ns-3 for NetAnim, dumbbell-animation and grid-animation. They are located under examples/animation. The examples can be executed with the following commmands:
./waf --run 'examples/animation/dumbbell-animation --nLeftLeaf=5 --nRightLeaf=5 --animFile=dumbbell.tr' ./waf --run 'examples/animation/grid-animation --xSize=5 --ySize=5 --animFile=grid.tr'
This command generates the custom trace output for the NetAnim GUI. Take the output file we generated, and feed it into NetAnim. Copy the dumbbell.tr file from ns-3 directory to the NetAnim directory. From the NetAnim directory:
This should produce an animation of the packets in the simulation. The sliders control the behavior of the speed of animation.
Creating Custom Scripts for Animation
If you would like to create custom scripts for animation because you need more than a simple dumbbell or grid topology, please keep in mind that nodes must be assigned locations for your animation to show up. Some example code for assigning node locations exists in point-to-point-grid-helper and point-to-point-dumbbell helper, specifically in the BoundingBox functions.