Skip to content

Installing and running ns-3 using free Colab Cloud Platform

This article presents a step-by-step procedure for installing and running ns-3 network simulations using the free resources provided by Colab Cloud Platform.

 

Note: The Complete Notebook file of this procedure can be downloaded from [3] and can be imported into your Google Colab for easy installation of ns-3 on Colab.

The following are the major steps :

  1. Setting up Google Colab environment
  2. Setting up a Persistent Storage
  3. Downloading ns-3 on the Persistent Storage
  4. Installing ns-3 on the Persistent Storage
  5. Running an example ns-3 simulation.

Step 1: Setting up Google Colab environment

  • Go to the Google Colab website: https://colab.research.google.com/.
  • Sign in to your Google account.
  • Click on the “New Notebook” button (and you may rename the Notebook as according to the version that you are installing (for example you may rename it as ‘ns-3.37’)
  • Select the “Python 3” runtime.
  • You can now start writing code in your notebook.

Step 2: Setting up a Persistent Storage

Since Google Colab will not provide persistent storage, you may use your Google Drive as a persistent storage by running the following commands from the Jupyter Notebook.
from google.colab import drive
drive.mount(‘/content/gdrive’)

Now you have to Change to the folder content/gdrive/MyDrive where you will have read, write (and execute) access. For that, you have to run the following command from the Jupyter Notebook.

%cd /content/gdrive/MyDrive

Step 3: Downloading ns-3 on the Persistent Storage

Now you may download ns-3 from [2] and keep it under the Google Drive folder. For that, you have to run the following command from the Notebook.

!wget https://www.nsnam.org/releases/ns-allinone-3.37.tar.bz2

The following output shows that the compressed file has been downloaded within 5 seconds. (the download was very fast because, it is using the very fast internet download speed provided by Google)

It will store the compressed file inside the folder ‘/content/gdrive/MyDrive’. Now we may extract the compressed file by running the following command from the Jupyter Notebook.

!tar -xvf ./ns-allinone-3.37.tar.bz2
The following output shows that the compressed file has been extracted within 41 seconds.

Step 4: Installing ns-3 on the Persistent Storage

Now you may install ns-3 by running the following commands from the Jupyter Notebook.
Change to the ns-allinone-3.37/ns-3.37/ with in the Google Drive
%cd ns-allinone-3.37/ns-3.37/

Configure ns-3 by running the following commands from the Jupyter Notebook.

!./ns3 configure –enable-examples
The following output shows that the configure operation has been completed within 47 seconds.

The following screenshot shows the successful configuration operation and the list of configured modules.


Build ns-3 by running the following commands from the Jupyter Notebook.

!./ns3 build

The following output shows that the build operation has been completed within 1 hour.

The following screenshot confirms the successful build operation.

Step 5: Running an example ns-3 simulation.

Run the Example simulation ‘first.cc’ provided with ns-3 by running the following commands from the Jupyter Notebook.

!./ns3 run first

The following output shows that the first time the compile operation took 1 minute.

The following is the output of while running the compiled simulation of fist.cc

Conclusion

This article shows the way to use free computing and storage resources of Google Colab for doing ns-3 simulations. Even though the overall compile time was not good, it is possible to use it for running a large simulation (that may take, for example, 10 hours of CPU time).  It is possible to run a batch of simulations remotely using the free cloud resources.

In fact, there is no simple way to run Network Animations such as NetAnim through this facility and visualize the simulation output. However, it is possible to do quality analysis and produce graphs using the available tools of Jupyter Notebooks.

References

  1. https://colab.research.google.com/
  2. https://www.nsnam.org/releases/ns-allinone-3.37.tar.bz2
  3. https://github.com/igs3000/ns-3-Turotials/blob/main/installing-ns-3-on-google-colab.ipynb
WhatsApp Discuss Through WhatsApp