From Script | Spoken-Tutorial
Jump to: navigation, search

ns-3 (http://www.nsnam.org) is a discrete-event network simulator for Internet systems, targeted primarily for research and educational use. ns-3 is free software, licensed under the GNU GPLv2 license, and is publicly available for research, development, and use. ns-3 is intended as an eventual replacement for the popular ns-2 simulator. The project has an active developer base and a vibrant community of networking researchers involved with it.

Please note that ns-3 is _not_ an evolution of ns-2, and is a completely new simulator written from scratch. ns-3's source code is written in C++, whereas end users can develop their simulation scripts using C++ or Python. ns-3 works on Linux and Unix variants, OSX and Windows (via Cygwin).

In the following tutorials, we will cover some of the important concepts that underly ns-3, and the basics of writing simulation scripts. Note that there are also a tonne of tutorials at http://www.nsnam.org/tutorials.html.

Version and OS

For the tutorials, we will be using ns-3-dev. We recommend using a GNU/Linux variant or OSX for these tutorials.

(Please see the associated text box of individual spoken tutorials on the website to decide the versions of software and OS to which it is applicable.)


ns-3 allows one to perform network simulations, and thus aid in the testing and validation of network models. Simulations are important because they provide a platform to verify the working of a protocol before a real world implementation of the same can be experimented with.


To run a simulation, a user writes a simulation script in either C++ or Python. The simulation script uses the models that are available and generates PCAP and/or ASCII traces. Users may use their own formats for extraction of data out of a simulation.


Users are expected to be familiar with C++ and be familiar with Computer Networks.


  • Prof. M. S. Gaur, Department of Computer Engineering, Malaviya National Institute of Technology, Jaipur, India.
  • Lalith Suresh P., Department of Computer Science and Engineering, Instituto Superior Técnico, Lisbon, Portugal.

NS-3 Basic Tutorials

NS-3 Concepts and Installation

This tutorial covers some important concepts of ns-3, and then proceeds to demonstrate an installation of the same.

  1. Packets: Packet objects are units of information sent and received by applications.
  2. Nodes: A Node class represents a network element in ns-3. Just like in a real network node, it may _optionally_ have an Ipv4 stack, one or more routing protocols, a mobility model or applications running on top of it.
  3. Applications: Applications are traffic generators, which generate streams of data as per user defined intervals/bursts. They are highly configurable. A well known kind of application that ns-3 offers is 'ping'.
  4. NetDevices: NetDevice objects represent real world network interfaces in ns-3. Presently, ns-3 allows users to use Csma, Wifi, Point-to-point, Wimax, Mesh and many more with their simulation nodes.
  5. Helpers: Helpers, as the name suggests, add an extra layer of abstraction to make it easier for users to write simulation scripts with fewer lines of code.
  6. Logging: Allows a user to perform classical 'printf' style debugging with ease.
  7. Tracing: This is ns-3's mechanism to probe and collect information from particular points of the simulation system. This can be from different part's of a node's stack such as the NetDevice, the PHY, or the transport.
  8. Use Mercurial to clone ns-3-dev.
  9. Build ns-3.

Basic Simulation Tutorial

This tutorial covers the writing of basic simulation scripts. The following sequence of steps will be involved:

  1. Creating nodes.
  2. Adding Csma network devices to the nodes and connecting the devices.
  3. Setting up an Ipv4 stack on the nodes.
  4. Setting up applications on the nodes.
  5. Running the simulation.
  6. Viewing Trace Files using Wireshark.

NS-3 Advanced Tutorials

These tutorials cover Wifi simulations, routing protocols, mobility models, the PyViz visualiser, the tracing subsystem and the flow monitor.

Wifi Simulations

  1. Create nodes.
  2. Add Wifi NetDevices to the nodes. Setup the MAC/PHY properties.
  3. Setting up an Ipv4 stack on the nodes.
  4. Setup a routing protocol (we'll use OLSR) on the nodes to perform routing.
  5. Setup a mobility model for the nodes.
  6. Setup applications on the nodes.

PyViz Visualiser

  1. Use PyViz to visualise the Wifi simulation.
  2. Demonstrate the varying of simulation speed.
  3. Observe a node's routing table and other properties attached to it.

Tracing Subsystem

  1. Make use of the tracing subsystem with the Wifi simulation.
  2. Use the tracing mechanism to observe a particular node's NetDevice.

ns-3 Flow Monitor

  1. Setup the flow monitor to monitor flow statistics in the Wifi simulation.

Contributors and Content Editors