A NetAnim example for ns3

NetAnim is a GUI for ns3 (like visualizer). The last version 3.107 comes with ns3-allinone-3.25. To compile it follow these commands:

#Install required software
sudo apt-get install mercurial qt4-dev-tools

#Download netanim from mercurial
hg clone http://code.nsnam.org/netanim

#or use it from ns3-allinone-3.25
cd netanim-3.107

make clean
qmake NetAnim.pro  (For MAC Users: qmake -spec macx-g++ NetAnim.pro)
make 

./NetAnim

To generate an xml file compatible with netanim, you must add the following lines to your simulation file.

// netanim headers
  #include "ns3/netanim-module.h"

// file's name to run on netanim
  std::string animFile = "example.xml" ; 

  AnimationInterface anim (animFile);

// background image. Starts on 0,0, the image is not resized (scale 1,1) and the image has no transparency (alpha channel is one).
  anim.SetBackgroundImage("potential_google_fiber_cities.png",0,0,1,1,1);

// Set position of node 0 in the layout
  anim.SetConstantPosition(nodes.Get(0),115,63);
// Set description of node 0
  anim.UpdateNodeDescription (0, "Portland");
// Set size of node 0
  anim.UpdateNodeSize (0,10, 10);
// Set color of node 0 (R,G,B). In this case, color is blue.
  anim.UpdateNodeColor (0, 0, 0, 255);

  anim.SetConstantPosition(nodes.Get(1),83,219);
  anim.UpdateNodeDescription (1, "San Jose");
  anim.UpdateNodeSize (1, 10, 10);
// Set color of node 1 (R,G,B). In this case, color is green.
  anim.UpdateNodeColor (1, 0, 255, 0);

  anim.SetConstantPosition(nodes.Get(2),249,178);
  anim.UpdateNodeDescription (4, "Salt Lake City");
  anim.UpdateNodeSize (2, 10, 10);
// Set color of node 2 (R,G,B). In this case, color is red.
  anim.UpdateNodeColor (2, 255, 0, 0);





















Maybe, when you'll execute your simulation you'll get this error:

undefined reference to `ns3::AnimationInterface::AnimationInterface(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
undefined reference to `ns3::AnimationInterface::~AnimationInterface()'
collect2: error: ld returned 1 exit status

Waf: Leaving directory `ns-allinone-3.25/ns-3.25/build'
Build failed
 -> task in 'brite-generic-example' failed (exit status 1): 
{task 139687142658192: cxxprogram brite-generic-example.cc.1.o -> ns3.25-brite-generic-example-debug}
['/usr/bin/g++', '-pthread', '-pthread', '-Wl,--enable-new-dtags', '-Wl,-rpath,/usr/lib/openmpi/lib', '-pthread', 'src/brite/examples/brite-generic-example.cc.1.o', '-o', '/home/dragonx/Downloads/ns-allinone-3.25/ns-3.25/build/src/brite/examples/ns3.25-brite-generic-example-debug', '-Wl,-rpath,/usr/lib/openmpi/lib', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-L/usr/lib/openmpi/lib', '-L/home/dragonx/Downloads/ns-allinone-3.25/BRITE', '-lns3.25-brite-debug', '-lns3.25-nix-vector-routing-debug', '-lns3.25-applications-debug', '-lns3.25-internet-debug', '-lns3.25-bridge-debug', '-lns3.25-point-to-point-debug', '-lns3.25-mpi-debug', '-lns3.25-traffic-control-debug', '-lns3.25-config-store-debug', '-lns3.25-network-debug', '-lns3.25-stats-debug', '-lns3.25-core-debug', '-lrt', '-lgsl', '-lgslcblas', '-lm', '-lsqlite3', '-lmpi_cxx', '-lmpi', '-lbrite', '-ldl', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-lpangocairo-1.0', '-latk-1.0', '-lcairo', '-lgdk_pixbuf-2.0', '-lgio-2.0', '-lpangoft2-1.0', '-lpango-1.0', '-lgobject-2.0', '-lglib-2.0', '-lfontconfig', '-lfreetype', '-lxml2']

To solve it, you must Add 'netanim' to your wscript or move your simulation file to your scratch folder.
An extract of BRITE wscript as example:

obj = bld.create_ns3_program('brite-generic-example', ['netanim','brite', 'internet', 'point-to-point', 'nix-vector-routing', 'applications'])

   obj.source = 'brite-generic-example.cc'

Comments

  1. Hi thank you, your post is very informative. Can you please elaborate on what co-ordinate system you used for positioning the points i.e. nodes.

    ReplyDelete

Post a Comment

Popular posts from this blog

Exception: Could not find a default OpenFlow controller in Mininet

How to fix Android when developer options are not available for this user

Webcam streaming throught VLC with YUY2 compatibility