NS3 - Information Page

last update: 9/11/2021   (NOTE:   I plan on updating this so all information we present on NS3 can be found here )

--------------------------------------------------------------------------------------------


NS3 Simulator  -  refer to this page for information on NS3


The goal of this section is to provide a path for someone not familiar with ns3 to get started. In overview,  you should assume the following algorithm:

//Goal is to develop sufficient background and experience with ns3 such that when complete, you are comfortable using ns3 to model/solve appropriate problems

developPreliminaryModelProblemStatement();
initProgressMeasure();
while (true)
{
    Read/learn something about ns3;
    Try something based on what you just read;
    rc = refineModelStatement();     
    upDateProgressMeasure();

    if (rc == complete)
   {
       rc = validateModel();
       if (rc == complete)
          break ;
      else
         resetProgressMeasure();
   }
   else
   {
      adjustProgressMeasure();
      if (getCurrentProgressMeasure() > getCurrent_PAIN_THRESHOLD()) {
        getHelp();
        reduce_PAIN_THRESHOLD();
      }
     if (getCurrentProgressMeasure() > getCurrent_PROGRESS_THRESHOLD()) {
        increase_PROGRESS_THRESHOLD();
     }

  }
}

The algorithm should make it clear that an iterative process is required to get through the learning curve associated with ns3.  The secret to success is to work in increments that reflect forward progress. Initially, you should be asking questions daily.  As you make progress, you will learn how to answer more and more of your own questions.     

 

Example scripts (this will be updated shortly):


---------------------------------------------------------------------------------------------

FAQ

---------------------------------------------------------------------------------------------

Question

How can ns3 operate in a more 'real' manner?   

https://www.nsnam.org/wiki/HOWTO_make_ns-3_interact_with_the_real_world

It's possible to tell the ns3 scheduler to use real time rather than simulation time. 
It's possible to setup ns3 for use as an emulator.   The Linux programs and the network stack can make use of ns3 to emulate complex wired/wireless networks.
Aspects of this is captured by NS3's Direct Code Execution (DCE) mode (see https://www.nsnam.org/docs/dce/manual/html/getting-started.html )

--------------------------------------------------------------------------------------------- 

Question
How to use the network emulation platform CORE/EMANE with NS3?

Going one step beyond ns3's native support for emulation,   a set of tools (CORE and EMANE) were
created to address a R&D environment that supports a blend of simulation, emulation, and measurement-based methods.
This paper is a bit old but it gives a good description of CORE/EMANE.


Refer to this page that talks of how ns3 fits into the picture.  CORE/EMANE is a much cleaner way of doing emulation
compared to NS3's DCE mode:

https://www.nsnam.org/wiki/HOWTO_Use_CORE_to_test_ns-3_protocols


---------------------------------------------------------------------------------------------

Question:
How do you install ns3 on a new Linux machine?

Clone, build and test an ns-3 release or the ns development tree to use as a clean starting point. One way to do this is:

   a.  hg clone http://code.nsnam.org/ns-3-allinone
   b.  cd ns-3-allinone
   c.  ./download.py
   d.  ./build.py
   e.  cd ns-3-dev
   f.  ./test.py

-------------------------------------------------------------------------------

Question:  How do I check the version of VBox ?
On a Ubuntu VM:   sudo VBoxService --version


-------------------------------------------------------------------------------

Question:  How do I check if Guest Additions are installed?
On a Ubuntu VM:   "lsmod | grep vboxguest"

Also try   sudo modprobe vboxadd



-------------------------------------------------------------------------------

Question:  how to reinstall Guest Additions from the Linux VM?

Issue  df -k   to find /media ....
cd to this location and run  sudo ./VBoxLinuuxAdditions.run

and then reboot the VM


----------------------------------------------------------------------------

Question:  How to create a new application?

Refer to https://www.nsnam.org/wiki/HOWTO_make_and_use_a_new_application

This page clones the udp-echo-client and server in src/applications/model.
Summary
-best to clone an existing app - just change names
-modify ./wscript file
-modify helper - add a helper function
-modify wscript 
Run ./waf

Then build a script that uses the app

   a.  change directory into ns-3-dev/examples/udp/
   b.  cp udp-echo.cc request-response.cc
   c.  Edit the new script (request-response.cc) and make the same substitutions as in step 3 above.
   d.  Edit the wscript in this directory and add the new example to the build
       search for udp-echo
       copy the two lines of build instructions and rename udp-echo to request response in the copied lines.  
         obj = bld.create_ns3_program('request-response',
                                      ['csma', 'internet'])
         obj.source = 'request-response.cc'
   e.  save file
   f.  change into the top level directory (ns-3-dev)
       cd ../..
   g.  build the whole thing
       ./waf

Keys:
-After adding new code (model, helper, our scripts), run ./waf  either at the NS$HOME or in the source code dir.

To run the new script :  

 cd ..
   b.  ./waf --run request-response

4. Observe the pcap traces to see what you've done

   a.  tcpdump -nn -tt -r request-response-0-1.pcap
         reading from file request-response-0-1.pcap, link-type EN10MB (Ethernet)
         2.000000 arp who-has 10.1.1.2 (ff:ff:ff:ff:ff:ff) tell 10.1.1.1
         2.004148 arp reply 10.1.1.2 is-at 00:00:00:00:00:02
         2.004148 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 10
         2.008312 arp who-has 10.1.1.1 (ff:ff:ff:ff:ff:ff) tell 10.1.1.2
         2.008312 arp reply 10.1.1.1 is-at 00:00:00:00:00:01
         2.014100 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024
   b.  Note that a 10 byte request packet goes from 10.1.1.1 (node zero)
   c.  Note that a 1024 byte response packet comes back from 10.1.1.2

-------------------------------------------------------------------------------

Question:  is it easier to write script models using Python rather than C++ ?

When it comes to writing ns-3 scripts in Python, my short advice is "Don't bother".


The only advantage you get from using Python is the ability to use all your installed Python libraries that you installed with PIP, such as numpy or matplotlib. I am not sure with ns-3 developers created Python Bindings, I figure the reason has to do with using the GUI on-line visualizer, PyViz because it's very convenient to import Python libraries into the visualizer. Students do not have to touch the Python code for the visualizer.

Here are my reasons for not using Python to write ns-3 scripts:
  1. Inconvenience: Python binding is created as binaries, not actual Python code. Functions are added to a dictionary at run-time. I think this makes it harder for auto-complete in modern IDEs to work. I personally couldn't get Visual Studio Code to do auto-complete with Python code.
  2. In
  3. Lack of support: There's almost no support for scripts that are written in python. Most users in the ns-3 user group use C++. The ns-3 website about writing python scripts is out-of-date
  4. TraceSources: There's no implementation of connecting a TraceSource to a callback function. In C++ we use Config::Connect to connect to TraceSources, which helps in collecting data. Many solutions to problems you could face would require connecting to these trace sources. Therefore, it really limits the functionality of ns-3

My Recommendation
What I do is write my ns-3 scripts in C++. I write output to text files, and then, post-simulation, I write Python scripts to analyze the data, and create graphics that I export to PDF (for when I put them in a research paper or a report)

However, PyViz is a decent visualization tool
And in order to be able to run PyViz visualization, you need to have PyBindGen Enabled and have some prerequisite libraries installed in Ubuntu. 

To check if PyViz is enabled, run ./waf --configure, which should show the Python Bindings is enabled, and PyViz Visualizer is enabled. Python Bindings is what enables writing ns-3 scripts in Python, and it's needed by PyViz.

The output should look like this:
...
Checking for pybindgen location                                            : ../pybindgen (guessed) 
Checking for python module 'pybindgen'                                     : 0.21.0 
Checking for pybindgen version                                             : 0.21.0 
...
PyViz visualizer              : enabled
...
Python Bindings               : enabled

If Python Binding is not enabled, make sure you have the folder pybindgen a level higher than the root ns-3 directory. I have an instruction video to install the latest ns-3 version on a fresh copy of Ubuntu 20 on my YouTube channel



-------------------------------------------------------------------------------
 Question   How do I setup a script so I can explore TCP competing flows ?

Question 3:  I tried to make a development directory under NS3 and now things don't work.

 - Waf must be run directly from the NS3 install folder (as your CWD)

A related problem is when I issue: 

./waf --run scratch/<subdirectory><X>     NS3 does not compile...it gives a link error.

Place X in the first level directory scratch as NS3 is not aware of how to properly use subdirectories without additional hints


Last update 8/29/2021