Getting started with installing ns-3
There are many network simulation tools available as open source and proprietary solutions. In comparison to ns-2 and other simulation tools, ns-3 offers the following features:
- The primary changes ns-2 users observe with ns-3 is the scripting language. Also, ns-2 support is limited to simple wired and Wi-Fi network simulation only.
- ns-2 programs are written in Object-oriented Tool Command Language (OTcl), whereas ns-3 programs are written in C++ or Python.
- ns-3 is open source software and has excellent support from the ns-3 team.
- ns-3 is designed as a set of modules (internet, Wi-Fi, LTE, etc.) and users can extend existing modules and add new modules.
- ns-3 is designed to be used in the command line as well as visualization mode.
- ns-3 can be easily extended with data analysis and visualization tools.
- ns-3 can be used on Linux, macOS, or Microsoft Windows operating systems.
In this section, you will start with the first hands-on task, which is installing ns-3 successfully. Let’s start by installing all necessary dependencies for ns-3:
- Install the core dependencies for ns-3 build essentials and compilation packages:
sudo apt-get update sudo apt install build-essential libsqlite3-dev libboost-all-dev libssl-dev git python3-setuptools castxml
- Install the Python dependencies for ns-3 Python bindings:
sudo apt install gir1.2-goocanvas-2.0 gir1.2-gtk-3.0 libgirepository1.0-dev python3-dev python3-gi python3-gi-cairo python3-pip python3-pygraphviz python3-pygccxml
- Install the dependencies for ns-3 features support, such as
NetAnimator
,gdb
, andvalgrind
:sudo apt install g++ pkg-config sqlite3 qt5-default mercurial ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gdb valgrind uncrustify doxygen graphviz imagemagick python3-sphinx dia tcpdump libxml2 libxml2-dev cmake libc6-dev libc6-dev-i386 libclang-6.0-dev llvm-6.0-dev automake
Next, download the latest ns-3 version and follow the steps for installing it:
$ wget -c https://www.nsnam.org/releases/ns-allinone-3.36.tar.bz2
- Unzip or extract the downloaded file:
$ tar -xvjf ns-allinone-3.36.tar.bz2
- Move to the following directory:
$ cd ns-allinone-3.36/ns-3.36
- Next, configure the ns-3 modules using the build system. The
ns3
command (available in thens-allinone-3.36/ns-3.36
folder) makes use of a Python wrapper aroundCMake
. It is similar toWaf
in earlier ns-3 versions. The following command configures ns-3 modules with all example and test simulation programs:$ ./ns3 configure --enable-examples --enable-tests
After running this command, you can verify the list of modules configured in Figure 1.1:
Figure 1.1 – The list of ns-3 modules configured
- Next, build all the configured ns-3 modules using the following command. This command takes a while to complete:
$ ./ns3 build
After executing the command, we can observe the list of modules linking successfully, as shown in Figure 1.2:
Figure 1.2 – ns-3 build process
- Finally, you can check your installation by running all unit test cases provided in ns-3 modules:
$ ./test.py
After executing this command, all test cases should either pass or be skipped. Then, a successfully installed NS-3.36 simulator is available (refer to Figure 1.3):
Figure 1.3 – ns-3 test cases execution
- After the successful build of ns-3, you have many example simulation programs ready to execute. Try running a first example simulation with the following command and observe the output:
$ ./ns3 run first
Now, we are executing an example ns-3 simulation, first.cc
. Refer to the execution results in Figure 1.4:
Figure 1.4 – The first.cc simulation execution results
Congratulations! We have installed ns-3 successfully and tested a sample simulation. In the next section, we are going to learn how to write an ns-3 simulation program easily using Code::Blocks
editor features. Thanks to the entire ns-3 team for providing detailed documentation on their website (https://www.nsnam.org) related to installing ns-3 with all features, tutorials, examples, and designs of various modules. We recommend you to go through the website for more details.