Skip to main content

Introduction to NS2 - NS2 Tutorial 1

Introduction to Network Simulations

In this post, you can learn

  • Introduction to Network Simulator 2 and its architecture
  • Installation of Network Simulator 2 in various Operating Systems
  • How to simulate a given network with available libraries of NS2

A simulator is of extensive use to engineers and researchers as it provides them a simple and inexpensive way to test the real world scenarios without facing the problems of actual implementation, though getting the same results. Similarly, a network simulator is software which models the behavior of the network given to it as an input, under real network characteristics without the actual network being present. To generalize, we can say that a simple network simulator must provide the user the capability to create nodes, the links between them and the traffic between the nodes. Additionally, an advanced network simulator may provide options for specifying every detail about the protocol used in handling network traffic.

Simulation is the modelling of an environment which is exactly similar to the underlying state of the target. The main goal of building a simulator is that, the internal state transitions and responsiveness of the system must exactly match the actual target environment it’s trying to mimic. Simulators are often used in order to give the user an initial experience of the real environment, since it may not be feasible for the user or the corporation to let the trainee use the actual environment due to monetary or safety reasons. The best example of a simulator is the flight simulator. The pilot trainee is never allowed to board the actual cockpit until he is able to get through the flight simulator environment. The flight simulator has the exact controls which is present in the cockpit and creates a virtual environment similar to that of the actual cockpit. It is capable of taking into consideration a number of factors like G-Forces, turbulence etc. It’s mandatory that these effects are very accurate so that the pilot doesn’t make any errors during the actual flight. Like wise, network simulators are useful in analysing, testing and design of various methods of computer networks. The emergence of wireless networks forced network simulations to be more accurate and appropriate due to its dynamic nature while deploying such networks.

1.1  Need for Simulation

Most of the pilot projects are using simulators rather than the real network deployments because of various factors like cost, implementation difficulties, customization, new technology adaptation, etc.

However there are situations where the real networks deployment are at upper hand for accurate results and it is the actual thing happening. Here is a simple comparison between the real model and the simulated model.

Real Network

Simulated Model

The cost of all the network components have to be procured

Most of the simulators are open source and free and cost is zero. (Example, NS2, OMNeT++, etc)

Time to set the things is really a painful task. (For Example, configuring a switch, hub or a router involves a skilled worker)

Learn a programming tool to model the devices once. Once learned, setting a network is a very simple task

Altering a given component may incur additional devices to setup or malfunction the entire network setup.

There is no risk while changing or altering the pre existing network.

This is the actual thing happening and whatever results you get the results are real and accurate.

Here also one may get accurate results until the system is bug free. If there are bugs in the system, the results may be unreliable or inaccurate.

Overall: Cost is high and exact results.

Overall: Cheaper and easier to deploy and development

So once the network project is decided, it is advisable to look for a simulator rather than option for a real network deployment as the initial cost should in any case be minimal.

1.2  List of Network Simulators

There are various simulators available for simulations each with their own purpose. However there are limited simulators that support wide range of protocols, routing metrics, etc. Here is the list of simulators that support huge number of protocols and network entities.

Network Simulator 2 [NS2]

Network simulator 2[3] is one of the oldest simulator available for simulation of wired, wireless, satellite networks, etc. For more than a decade, it satisfies most of the researchers/students across the globe in simulating the networks. It has a strong community that helps developers, researchers across the internet.  NS2 was criticized because of the complex architecture it has (OTcl and C++), but it supports the oldest to latest the protocol that were available for the wired or wireless networks.  NS2 is completely open source and free.

Network Simulator 3 [NS3]

NS3 [14] is another simulator available for less than a decade and it supports network components of recent developments, unlike NS2, the architecture of ns3 is simpler and one can simulate a network using either C++ or python scripts. NS3 is evolving these days to a greater extent and will come with new protocols, new networks, etc in each of their releases. NS3 is completely open source and free.

OMNeT++

OMNeT++[15] another tool that supports many protocols, network entities using the framework INET which is coming as a third party interface. OMNeT++ is built on the eclipse framework and the development and deployment is very easy as it as a richer GUI that supports the developers to form a network very easy.  It is built over C++ and most of the developmental modules are developed in C++ and there is a configuration file (omnetpp.ini) which solves the purpose of forming a network either in a text mode or in a graphical mode.  All these things available at a free cost. OMNEST is the commercial version.

OPNET

This is expensive commercial software available for network simulation and is available with source codes for unrestricted protocols. Trial version is available on request. It contains excellent manual. It has a full-fledged GUI with XML based support for scenario generation. Because of its heavy weight components, this is a slow simulator.

There are various other simulators too in the market that solves the purpose of narrow network research. So, the developers once identified a network, there are choices available for them to select the perfect simulator for their research. The following table will list some of the key comparisons between the simulators

Name

OPNET

NS2

NS3

OMNeT++

Cost

Highly expensive.

Free and Open Source

Free and Open Source

Academic Version is Free

Support

Good manual with source codes

Proper documentation

Proper documentation

Documentation is available

Topology/Scenario

GUI

OTcl

C++ or Python

GUI with omnetpp.ini

Languages/scripts used

C++

OTcl and C++

C++ and Python

C++

Forum /Community Help

Less

Best

Good

Good

Overall Rating

Expensive and highly commercial, simulation is also slow, suited best for the industries

Best for latest and faster simulations

Best for latest and faster simulations

Need for a third party framework for a given network. Also issue with version compatibility

1.3 Time driven and Event Driven Simulations

Usually network simulations carried out either in time driven or event driven. Each of them have their own pros and cons. This topic will show you the difference between these simulations.

Time driven Simulation

Time driven simulation is also called as discrete time simulation. The simulation is carried out on a fixed time interval. The time interval in which a task is running is assumed to be running before the end of the interval though the task would have arrived at the beginning of the interval.

For example:

Assume ∆t is the interval in which the task is running (Assuming a packet arrives in ∆t)

∆t = t2- t1.

Suppose if the packet arrives t1+0.001 and it may be running before the time t2. So sometimes, the packet may have to wait for a shorter duration of time because of this kind of simulation.

A simple pseudo code shows

For t = 1 to time

{

If (packet arrival)

Buffer ++;

Else (packet departure)

Buffer—

Print (Buffer);

}

This shows the time driven simulation has some limitations in networks.

Event driven Simulation

Event driven simulation as the name says, it handles some set of events using a scheduler or a handler.  Here are some of the key features of event driven simulation

  • Discrete set of events can be handled by a scheduler
  • One event upon completes triggers the next events
  • The events are fired as random intervals and are scheduled by the handler
  • The simulation may be stopped once all the events are executed or at a predefined time (where we want to end the simulation). In short, the stopping occurs when the system reaches a particular state or particular time.

Here is the pseudo code for Event driven simulation

Initialize the system

Initialize the events

While (true)

     Collect information from the current event.

     Remove first event from the list and handle it.

     Set time to the event

When compared event driven simulation has upper hand over the time driven simulation as in the latter case, the time is wasted in difference of timing. But selecting a small ∆t does not solve the purpose as the computational complexity of handling the network dynamics may not suite.

This book is demonstrates the Network Simulator 2 (NS2) which is a discrete event simulator that handles the network dynamics using discrete number of events that are handled by a scheduler. Also ns2 supports four different types of scheduler namely calendar (Default), heap, simple linked list and real time scheduler.  

1.4 Modeling for Network Simulation

The most difficult part in simulation of network is the selection of a Model. Selecting a model needs the thorough knowledge of network elements, problem specification and the deep knowledge of the system under study. So, to analyse a given network under study, here are steps that can be used for performance analysis [16]

  • Problem formulation and system model definition
  • Performance Metrics definitions
  • Various levels under study
  • Data collection
  • Selection of simulation environment
  • Verification and validation
  • Experimentation and analysis

1.5 Conclusion

This chapter deals with the elements of network simulation that compared time driven and event driven simulation. Also this chapter tells the list of network simulators that are available for research and development. This chapter compares various simulators based on their usage and features.                                   

Comments

Popular posts from this blog

Installing ns-3.34 in Ubuntu 20.04

This post shows how to install ns 3.34 in Ubuntu 20.04 LTS Prerequisites: Fresh installation of Ubuntu Version 20.04 LTS  ns3.34 can be downloaded from here Follow the video link for complete step by step instructions on the installation.  This version fixes the compilation issues of vanet-routing-compare.cc (bug in ns3.33)  Issue the following commands after opening a terminal  $ sudo apt update $ sudo apt install g++ python3 python3-dev python-dev pkg-config sqlite3 python3-setuptools git qt5-default gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar openmpi-bin openmpi-common openmpi-doc libopenmpi-dev tcpdump wireshark libxml2 libxml2-dev Unzip or untar the ns-allinone-3.34.tar.bz2 in the home folder (in my case its /home/pradeepkumar) $ cd ns-allinone-3.34/ $ ./build.py --enable-examples --enable-tests  Once the installation is completed, you may get an output show

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installation of ns3 in Windows 10 and Windows 11 OS using WSL (Windows Subsystem for Linux)

This post shows how to install ns-3.33 in Windows 10 through WSL (Windows Subsystem for Linux) This posts works for Windows 11 also (I have tested it on a Windows 11 ISO and it works the Same way as mentioned in the following post.) This post will work for ns-3.3x version. Prerequisites : Install Windows Subsystem for Linux with GUI: Please refer the following video  System Information: OS used: Windows 10 and WSL (Ubuntu 20.04) GUI: XServer for Windows NS3 Version: ns-3.33 See the following complete video on how to install ns3 in Windows 10 Step 0 : Open XLaunch Step 1 :  Open WSL using PowerShell and open it as Administrator Command:/  wsl $ xfce4-session The GUI of Ubuntu Opens within Windows 10 OS. Step 2 : Download ns3 from nsnam.org website through Mozilla Firefox browser Step 3: Open a Terminal  $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev python3-pygraphviz cvs mercurial bzr git cmake p7zip-full python3-matplotlib python-tk python3-dev qt5-q