NS-3 is a discrete-event network simulator used for research and education in networking. It is the successor to NS-2, providing a more modular and efficient framework for simulating networks. NS-3 offers better support for wireless networks, IPv6, and improved performance compared to NS-2.
There are two options to install ns-3:
- Build it manually on a Linux machine of choice
- Use my pre-built docker image to run it with just two commands on any OS (Win / Mac / Linux).
Manual Installation
Pre-requisites
- CMAKE is essential for building from source
- Configure it to path
- Python should be configured to path
- If using a fresh Ubuntu or any Debian-based Linux distro, then the following command will install everything:
It is not essential to install all of these packages, but installing them ensures the smooth working of ns-3
Installation / Setup
Download the latest release from https://www.nsnam.org/releases/latest
Unpack it in a working directory of your choice
tar
is available by default on Linux and macOS systems. Windows users need to find an alternative.
Change into the ns-3.*
directory which is inside the directory just extracted
Configure to enable examples and tests
Use ns3
to build ns-3
Run your first sample program
Python Configuration
3.8. Using Python to Run ns-3 — Manual
cppyy
is required. Install it
Installing cppyy==3.1.2
also runs fine, but I was getting some materialize symbols warnings. Turns out using cppyy==2.4.2
solves this issue.
Configure ns-3 to support python-bindings
To run programs, there are two ways:
- One is to run a ns-3 shell
./ns3 shell
python3 examples/wireless/mixed-wired-wireless.py
- Other is to use the ‘run’ option to ns-3
./ns3 run examples/wireless/mixed-wired-wireless.py
Use the --no-build
option to run the program without invoking a project rebuild. This option may be useful to improve execution time when running the same program repeatedly but with different arguments, such as from scripts
Usage
- Put any Python file which uses ns-3 modules in the
scratch
folder insidens-3.*
folder - Then run the following command:
./ns3 run [scratch/YOUR_FILE_NAME.py]
Install Pip Wheel (Optional)
If you seek intellisense and code completions from VS-Code or your editor of choice, you must install the ns3
package.
Just use pip install ns3==[YOUR NS-3 VERSION]
to install it.
You can find the exact version for your case here: https://pypi.org/project/ns3/#history
Example: pip install ns3==3.43.post9
Docker Container Installation
Pre-requisites
- Docker correctly configured installed and added to path
Docker Image Pulling
Pull my ns-3 docker image from the following resource:
https://hub.docker.com/repository/docker/avcton/ns-3.43-ubuntu
Usage / Container Launching
Open terminal and navigate to your working directory (i.e, where you will keeping your code files)
Next, just run the docker container from my ns-3 docker image
For Linux Users:
For Windows Users:
Command Prompt:
PowerShell / VSCode Terminal:
The above docker command will run the container, attach it to your current terminal session and mount the current directory opened in your terminal to the code directory in the root ns-3 build folder
Now, any file or folder inside your current directory will be mapped to the code
directory in the ns-3 container. Also, you will now see the linux shell attached to your terminal. This is the inside of ns-3 container.
You can run ls
to see the contents of the ns-3 package. Also the code
folder inside it is mapped to the directory from where you ran docker run
To run your program, simply place it in the directory from where you ran the docker run
command and run the following command in docker attached terminal:
PS: If you get any Failed to materialize symbols
error, then its totally fine to ignore it for now.
That’s it. You now have a working ns-3 container mounted to your working directory.
Cheers 🥂
Python Testing Simulation
You can use the following python code to test your ns-3 simulation:
This should print out the following output: