Skip to content

Installing ns3-ai Model under “chroot Jail”

Using AI/ML algorithms with ns-3. 

If we want to implement  AI algorithms in your custom network protocol/application under ns-3, then the direct way is to incorporate an existing  AI/ML/DL framework with it. If it will be an AI/ML C++ based framework, then it can be incorporated with the C++ code of ns-3. But the existing AI/ML frameworks are huge and getting rapidly improving over time.  Further, there are popular frameworks that are based on python and make it hard to merge with ns-3 natively.

So instead of directly incorporating such huge AI/ML frameworks with ns-3, ‘ns3-ai Model’ provides a way to communicate with independently running AI/ML frameworks from an ns-3 simulation.

Features of ns3-ai

ns3-ai does not include any AI algorithms in it. Further, it will not rely on one particular framework. This framework provides the ways to communicate and use the AI framework, which is installed separately in the system. 

The following are the features outlined by its developers[1]

  • High-performance data interaction module (using shared memory).
  • Provide a high-level interface for different AI algorithms.
  • Easy to integrate with other AI frameworks.

Installation of ns-3 under chroot Jail

No specific version was mentioned by the developers of ns3-ai. In this article, I am doing the installation with my previous installation of ns3-33 which was installed under “chroot jail”. Specifically, I am going to use the ns3.33 version in which I installed ms-van3t extension; because in future, I may try to use some ns3-ai nodes in a VANET simulation. 

Hopefully, this installation procedure will also work with higher versions of ns3 also.

So one may follow any procedure from [1] to install any version of ns-3 before proceeding the installation of ns3-ai module or simply follow any chroot jail-based installation procedure.

Installation of ns3-ai Module

Change to “contrib” folder of your ns-3 installation.

$cd /home/your_home/ns-allinone-3.33/ns3.33/contrib

Clone the ns3-ai repository under the  “contrib” folder of your ns-3 installation.

$ git clone
The following output shows the successful cloning of the repository.
Now configure the build from ns3 root directory
$cd /home/your_home/ns-allinone-3.33/ns3.33/
$ ./waf configure 
Now compile using waf
$ ./waf build 

The following screenshot shows the successful install of ns3-ai under chroot jail.

Configure Python interface for ns3-ai

Now configure the build

$sudo apt install python3-pip

cd /home/your_home/ns-allinone-3.33/ns3.33/contrib/ns3-ai/py_interface

pip3 install . –user

The following screen shows the successful configuration of Python Interface


Testing the Installation with simple a_plus_b code

a_plus_b is a very simple but useful example for the ns3-ai model to illustrate the data exchange between Python-based AI frameworks and ns-3. 

We may use this example to test the ns3-ai installation.

In this example, the python code will create a common memory pool and start an ns-3 simulation called a_plus_b which shares some variables from the common memory pool. In this case, the value of ‘a’ and ‘b’ are randomly chosen from the python part of the code and put into the common memory pool.

The ns-3 simulation will have access to these ‘a’ and ‘b’ values and calculate the value ‘c=a+b’ and put and display the result from the ns-3 simulation itself. In the following output, we are having 10 outputs. The reason is, the python code will initiate the ns-3 code 10 times within a loop.

Original Procedure

As per the ns3-ai documentation, the following set of commands should run the a_plus_b iexample.

$ cp -r contrib/ns3-ai/example/a_plus_b scratch/
$ cd scratch/a_plus_b/
$ python3

But, under our ‘chroot jail’ based installation, this command doesn’t able to run the ns-3 part of the code. (just indefinitely waiting after displaying “build”)

Modified Procedure

We tried to run the python script in the background (&) and then manually started the ns-3 part of the simulation.  

So, the following  are the commands that we used under chroot jail.

$ cp -r contrib/ns3-ai/example/a_plus_b scratch/
$ cd scratch/a_plus_b/
$ python3
$ ../../waf –run a_plus_b
Now the simulation produced expected outputs.  The following screenshot shows the outputs.


This example simulation is not using any AI/ML features. So, this will run without having any AI/ML framework installed on the system. But, if we will try to run an example that uses AI/ML features, then before that, we have to install the necessary AI/ML framework and other python dependency modules.

Further, under chroot jail, the programs are not getting started as expected. The reason for these buggy behaviours should be found and addressed.



For Assistance in Protocol Implementation, Simulations & Analysis of Industrial as well as Scholarly Research Works, you may Contact Us.

WhatsApp chatDiscuss Through WhatsApp

Call 91 9843779735

Send an e-Mail Message.

This site is protected by reCAPTCHA and the Google
Privacy Policy and
Terms of Service apply.

WhatsApp chat