Tuesday, January 6, 2015

Install and configure Network simulator (ns3) on Ubuntu 14.04

On CSE we have to take thesis on the final year. Those who are on networking sector they have to work with Network simulator. Popular network simulator is NS3. Sometimes we need to install and configure it on ubuntu 14.04. As we have to download the source and compile it so it’s difficult for begginers. I will try to explain it easily. If any command not work please inform me.

Install ubuntu 14.04 on your development mechine. First we will install some packages using these commands.
$ sudo apt-get update
$ sudo apt-get install gcc g++ python python-dev mercurial bzr gdb valgrind gsl-bin libgsl0-dev libgsl0ldbl flex bison tcpdump sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev libgtk2.0-0 libgtk2.0-dev uncrustify doxygen graphviz imagemagick python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev python-pygccxml

This package will take 27mb. In that case i removed the command of texlive. If you need later you can install it.

Download NS3 from this link. extract it and write command =>
$ cd ns-allinone-3.21
$ chmod +x build.py
$ ./build.py –enable-examples –enable-tests

It will take time to run this command. Be patient. If all is ok, you will get this message -
“Build finished successfully”.(clap for yourself)

write command =>
$ cd ns-3.21
$ ./waf -d debug –enable-examples –enable-tests configure
$ ./waf

To check everything is successfully installed or not, please run this command -
$ ./test.py

Installation is finished.
Now say how you can run the programs of these folder – ns-allinone-3.21/ns-3.21/example ?
copy first.cc from the example folder and then put it on ns-allinone-3.21/ns-3.21/scratch folder.

write command =>
$ ./waf –run first

You will see this output -
At time 3s client sent 1024 bytes to port 9
At time 3.00469s server received 1024 bytes from port 49153
At time 3.00469s server sent 1024 bytes to port 49153
At time 3.00837s client received 1024 bytes from port 9

Sometimes we need to show in graphical mood. In that case we will compile and extract a xml file and then we analysis it using NetAnim.
So we will install NetAnim.
$ sudo apt-get install NetAnim

If you face any problem installing NetAnim, then you need to install Qt package. Go to software manager and write qt creator, then install. After this you have to again type the command =>
$ sudo apt-get install NetAnim

Open this file ns-allinone-3.21/ns-3.21/scratch/first.cc and edit it carefully =>
If you face any problem you can check this link -

#include “ns3/netanim-module.h” // Please add these lines
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“FirstScriptExample”);
main (int argc, char *argv[])
Time::SetResolution (Time::NS);
LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);
LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“”, “”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Please add these lines
AnimationInterface anim (“animation.xml”);
anim.SetConstantPosition (nodes.Get(0), 1.0, 2.0);
anim.SetConstantPosition (nodes.Get(1), 2.0, 3.0);
// Please add these lines
Simulator::Run ();
Simulator::Destroy ();
return 0;

write command =>
$ ./waf –run first

You will get output as animation.xml on this folder ns-allinone-3.21/ns-3.21/ . Now open NetAmin. Then from this software open the animation.xml, Then you can see the graphical output.
Hope now you can work with NS3. If you face any problem don’t hasitate to comment here.


  1. Hi
    i need your help please , when i open NetAnim i did not find animation.xml

  2. i have a problem in installation ns3 on ubunto 14.04,
    i need your help please.

  3. i have a problem in installation ns3 on ubunto 14.04,
    i need your help please.

  4. etting error while running ./build.py –enable-examples –enable-tests. please help.
    error is
    QMake version 2.01a
    Using Qt version 4.8.6 in /usr/lib/i386-linux-gnu
    qmake found
    => qmake NetAnim.pro
    => make
    make: Nothing to be done for `first'.
    Leaving directory `netanim-3.105'
    # Build NS-3
    Entering directory `./ns-3.21'
    Traceback (most recent call last):
    File "./build.py", line 170, in
    File "./build.py", line 161, in main
    build_ns3(config, build_examples, build_tests, args, build_options)
    File "./build.py", line 80, in build_ns3
    run_command(cmd) # waf configure ...
    File "/home/ubantu/ns-allinone-3.21/util.py", line 19, in run_command
    print " => ", ' '.join(argv)
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

    1. Try this: ./build.py --enable-examples --enable-tests
      You have used "–" instead of "--"

  5. netanim not working please help

  6. ./build.py –enable-examples –enable-tests. this command has to be edited
    the correct one is;
    ./build.py --enable-examples --enable-tests

  7. Changes to first.cc in folder scratch did not take effect (XML file creation for NetAnim). Renamed scratch/first.cc to scratch/myfirst.cc, ran ./waf --run myfirst, BINGO

  8. assert failed. cond="uid != 0", msg="Assert in TypeId::LookupByName: ns3::WimaxNetDevice not found", file=../src/core/model/type-id.cc, line=540

  9. while i am running my script scratch/myfirst.cc under cygwin windows iam getting this exception. your help will beappriciated

  10. during run command ./build.py error permission denied please reply me

  11. during run command ./build.py error permission denied please reply me

  12. during run command ./build.py error permission denied please reply me

  13. This comment has been removed by the author.

  14. This comment has been removed by the author.

  15. correct ./waf -d debug –enable-examples –enable-tests configure
    ./build.py –enable-examples –enable-tests
    ./waf -d debug --enable-examples --enable-tests configure
    ./build.py --enable-examples --enable-tests
    and if you get again error somewhere else try to see if sing (-) is double(--)

  16. The project was not configured: run "waf configure" first!

  17. how can i configure netanim on mac , i use the following commands but it is not fond :
    cd netanim
    make clean
    qmake -spec macx-g++ NetAnim.pro
    i get these lines when i use make clean:
    make: getcwd: No such file or directory
    make: *** No rule to make target `clean'. Stop.

  18. I am getting "xmL format is not supported. Minimum Version:3.106