Fix for Installing NS-3 on Ubuntu 22.04

Installation instructions for NS-3 can be found on the nsnam webpage: Installation - Nsnam. But follow along because newer versions of NS3 and python (3.10) have issues with binding.

After installing the dependencies, both required and optional, there are 3 major ways of installing NS-3 using: (1) bake, (2) waf, and (3) source.

You may very likely encounter error(s) during the build process ending with:

util.commanderror: command ['/usr/bin/python3', 'waf', 'build'] exited with code 1

You may notice that the build script is unable to find the packages ‘cxxfilt’, ‘qt5-default’, python3-gi, python3-gi-cairo, python3-cairo. These packages are optional so ns3 build process should not have issues installing ns3.

The error stated above (in blue) is not related to the optional packages. It is likely related to the g++ versions expected by ns3 and the version installed in Ubuntu 22.04.

Having spent hours debugging and trying to find hacks to fix the installation error, I found that downloading “ns-3-dev” instead of the standard ns3 release(for example: http://www.nsnam.org/release/ns-allinone-3.30.tar.bz2).

For each of the fixes below, you have to restart the ns3 build from the start. Things can break when working with a previous semi-finished ns3 build. You will save yourself a lot of headache by starting the ns3 installation from scratch.

Fix 1: Install ns-3-dev instead of ns-allinone-*

Download the ns3 source as usual:

git clone https://gitlab.com/nsnam/ns-3-allinone.git

Change into the untarred (you have to run ‘tar’ command on the downloaded tar file.)

cd ns-3-allinone

Run the download.py script

./download.py -n ns-3-dev

This will download the required files/folders.

Build using build.py:

./build.py

Your ns3 should be installed at the end of the build process. It takes some time to finish, so you can go make yourself a sandwich and get back to your computer to a freshly installed ns3.

Change into ‘ns-3-dev’ directory.

cd ns-3-dev

Configure.

./ns3 configure --enable-python-bindings --enable-examples --enable-tests

Build your ns3

./ns3 build

Unit test.

./test.py

Fix 2: Modify pybindgen/cppclass.py

It is very likely that you have Python 3.10 (the latest version). NS-3.30> versions were released before the python 3.9>3.10 upgrade. So many bindings now are not supported. That is why even after installing python3-gi-cairo, python3-gi, and python3-pygraphviz etc., the build cannot find them.

Now lets move on to the fix. You need to change into the ns-allinone-3.3*.tar.gz

cd pybindgen-*/pybindgen

gedit cppclass.py

In ‘cppclass.py’, add the following line right below ‘import collections’

try:

collectionsCallable = collections.Callable

except AttributeError:

collectionsCallable = collections

import collections.abc

collectionsCallable = collections.abc.Callable
try:

set

Save the file. Run ./build.py

./build.py

Run waf to configure and build the ns3.

./waf configure —-enable-examples

./waf

Fix 3: Same as Fix 1 but disable python bindings

Follow the same steps from Fix 1 until the ./waf configure step. Do

./waf configure —enable-examples —disable-python-bindings

Then build using waf

./waf

Note: I only tested this with NS3-3.30. You can find more information about the bug here: Ns-3.35 errata - Nsnam. The workarounds posted in the errata link are for ns-3.35 but they also worked for ns-3.30. If they do not, then let me know :)

Fix 4: Disable g++ warnings from breaking your build

Circling back to what I said earlier about the version incompatibilities between older ns3 versions and newer python versions, incompatibilties can also occur due to ns3 older versions (inclujding ns-3.30) using older g++ versions. Ubuntu 22.04> use the latest g++ versions that may break the ns3 build because the ns3 builds from ‘bake’, ‘waf’, and ‘build.py’ treat g++ related warnings as errors.

nsnam provided these instructions to disable warnings from breaking your build here: HOWTO build old versions of ns-3 on newer compilers - Nsnam

In summary, run your build.py as is.

./build.py

Configure your waf by prepending the configure command with ‘CXXFLAGS=”-Wall”’ like

CXXFLAGS="-Wall" ./waf --build-profile=debug --enable-examples --enable-tests configure -d optimized

Then run ./waf script as is.

./waf

Previous
Previous

Latex Template for Academics

Next
Next

Free Computing Resources for your Research