Experiment-1: Data Communication and Networks Lab

Experiment – 1:

Introduction to Computer Network laboratory: Introduction to Discrete Event Simulation, Discrete Event Simulation Tools – ns2/ns3, Omnet++


  1. To briefly describe the role of network simulator
  2. To provide a list of different simulators and give a brief introduction of NS2/NS3 and OMNET++
  3. to provide resource of the network simulator NS-2
  4. To give all dependency details for installing the NS
  5. To give installation steps of the NS

Outcome: After doing this experiment student will be able to :

  1. understand the various simulators and their installation
  2. to work on the basic commands related to network simulators
  3. Watch the result in various files such as .tr and .nam files
  4. To see the plot on the animator (NAM)

Introduction to Computer Network Laboratory Simulators:

Computer networks is defined as the interconnection of  different computing devices through a communication channels to facilitate communication and resource-sharing among a wide range of users. The devices communicate with each other following a certain protocol.

Need for Network Simulators:

Performance of the network can be measured in many ways, including transmit time and response time. Transmit time is the amount of time required for a message to travel from one device to another. Response time is the time elapsed between and inquiry and a response. The performance of the network depends on a number of factors, including the number of users, and type of transmission medium, the capability of the connected hardware, and the efficiency of the software.

Performance is evaluated by two network metrics: throughput and delay. We often need more throughput and less delay. However, these criteria are often contradictory. If we try to send more data to the network, we may increase the throughput but we increase the delay because of traffic congestion in the network.

Reliability: in addition to the accuracy of the delivery, network re;liability is measured by the frequency of failure, the time it take the link to recover from a failure, and the network’s roboustness in a catastrophe.

Simulators an introduction:

Network simulation is an important tool in developing, testing and evaluating network protocols. Simulation can be used without the target physical hardware, making it  economical and practical for almost any scale of network topology and setup. It is possible  to simulate a link of any bandwidth and delay, even if such a link is currently impossible in  the real world. With simulation, it is possible to set each simulated node to use any desired software. This means that meaning deploying software is not an issue. Results are also easier to obtain and analyze, because extracting information from important points in the simulated network is as done by simply parsing the generated trace files. Different simulators that are available are:

  • NIST
  • NEST
  • REAL
  • NS
  • OMNET++
  • NCTUns
  • eNS

Classification of Simulations :

In classical thinking there are three types of simulation; discrete event, continuous, and MonteCarlo. They were articulated by Nance (1993) as:

  1. Discrete event simulation :

It utilizes a mathematical/logical model of a physicalsystem that portrays state changes at precise points in simulated time. Both the nature of the state change and the time at which the change occurs mandate precise description. Customers waiting for service, the management of parts inventory or military combat are typical domains of discrete event simulation.

2. Continuous simulation:

  1. It uses equational models, often of physical systems, which do not portray precise time and state relationships that result in discontinuities. The objective of studies using such models do not require the explicit representation of state and time relationships. Examples of such systems are found in ecological modeling, ballistic reentry, or large scale economic models.
  2. Monte Carlo simulation : the name given by John van Neumann and Stanislaw M. Ulam to reflect its gambling similarity, utilizes models of uncertainty where representation of time is unnecessary. The term originally attributed to “a situation in which a difficult non-probabilistic problem is solved through the invention of a stochastic process that satisfies the relations of the deterministic problem”. A more recent characterization is that Monte Carlo is “the method of repetitive trials. Typical of Monte Carlo simulation is the approximation of a definite integral by circumscribing the region with a known geometric shape, then generating random points to estimate the area of the region through the proportion of points falling within the region boundaries.

Features of Network Simulator NS2

NS (Network Simulator) consists of group of series of distinct occurrence complex simulators, specifically NS-1, NS-2 and NS-3. All of them are discrete-event network simulator, mainly used in investigating and training.

NS-2 is a very popular discrete event Network Simulator, which is widely used in  the research field of Wired, Wireless and Satellite Networks across both academia and industry as a way of designing, testing and evaluating new and existing protocols and architectures, and has also proven a very useful tool for teaching purposes.

NS-2 comes fully equipped of protocols, models, algorithms and accessory tools. NS-2  is an open source network simulator which is freely available for academic research  purpose. Therefore, in terms of scientific acceptance, a number of tools/modules and cost, NS-2 would be a sort of ideal choice.

NS is a discrete event simulator targeted at networking research. NS provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) networks.

NS-2 started as a variant of the REAL network simulator in 1989 and has since been supported by the Virtual InterNetwork Testbed (VINT) project that is a DARPA-funded research project whose aim is to build a network simulator.


When the system under research is complex to either follow an analytical approach or implement it in real time to study its behavior, simulation is the solution that ultimately makes it feasible by modeling it and closely mimicking the actual process. Network researches wholly depend on the availability of numerous simulation tools like OPNET, NS2, OMNET++ and so on. Without these tools it would be difficult to even imagine the advancements we have reached in networking. Of the numerous tools available, Network Simulator or NS2 (as it is famously called) stands distinct from the rest of the simulators.

What you need to do?

To create an ns-2 simulation, we need to do the following (in addition to a modest amount of standard housekeeping).

  • define the network topology, including all nodes, links and router queuing rules
  • create some TCP (or UDP) connections, called Agents, and attach them to nodes
  • create some Applications – usually FTP for bulk transfer or telnet for intermittent random packet generation – and attach them to the agents
  • start the simulation

Once started, the simulation runs for the designated amount of time, driven by the packets generated by the Application objects. As the simulated applications generate packets for transmission, the ns-2 system calculates when these packets arrive and depart from each node, and generates simulated acknowledgment packets as appropriate. Unless delays are explicitly introduced, node responses – such as forwarding a packet or sending an ACK – are instantaneous. That is, if a node begins sending a simulated packet from node N1 to N2 at time T=1.000 over a link with bandwidth 60 ms per packet and with propagation delay 200 ms, then at time T=1.260 N2 will have received the packet. N2 will then respond at that same instant, if a response is indicated, eg by enqueuing the packet or by forwarding it if the queue is empty.

Introduction to OMNeT++

OMNeT++ is a modular, component-based C++ simulation library and framework, primarily for building network simulators. It could be used to simulate different routing protocols, whether MANET or WSN, OMNeT++ has a lot of examples to illustrate how these protocols work in details. OMNET provide the following:

  • C++ class library

– Simulation kernel

–Utility classes (for random number generation, statistics collection, topology discovery etc.)

-> use to create simulation components (simple modules and channels)

  • Infrastructure to assemble simulations

– Network Description Language (NED)

–.ini files

  • Runtime user interfaces

– Tkenv


  • Tools to facilitate creating simulations and evaluating results




  • Tools to document large simulation models


  • Extension interfaces for real-time simulation, emulation, MRIP, parallel distributed simulation, database connectivity and so on

Installation of NS2

Step 1: Setting up the Prerequisites

1. First of all, download Network Simulator (NS-2.35) from here.I assume you have downloaded it into your ‘/home/ECE/Local’ directory.
2 [Optional]. Now we have to update the Ubuntu with its latest components. Open up a terminal and run these commands:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get update

Make sure that your Ubuntu is fully updated ( i.e. there should be no pending updates in your Ubuntu Software Center and in Software Updater).
3. Before installing the NS we have to install some essential packages required by the NS. So run the following commands:

sudo apt-get install build-essential autoconf automake
sudo apt-get install tcl8.5-dev tk8.5-dev
sudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev
sudo apt-get install gcc-4.4

Step 2: Extract and Install NS
1. Extract the downloaded NS package either using the right click context menu “Extract here” or using the following commands from a terminal:

cd /home/ ECE/Local
tar -xvzf ns-allinone-2.35.tar.gz
  1. After extracting the “ns-allinone-2.35” folder, open up the file “/ns-allinone-2.35/ns-2.35/linkstate/ls.h” in an editor. You can do it either from the terminal or from the file explorer (Nautilus). We have to make some changes in the ls.h file else it will show an error while installing the NS. Once you have opened the file move to the line 137 and replace the erase (image 1) with this—>erase (image 2) and save the file.
  2. Now its time to finally install the NS. Open up a terminal and move to the directory where you have extracted the package, in our case its ‘/home/ECE/Local’ and install NS using the following commands (image 4):
cd /home/ECE/Local/ns-allinone-2.35
sudo ./install

It will take some time here so have patience.

Step 3: Set the Environment Variables

  1. Assuming everything went well in the previous step and you have successfully installed your NS. Now that NS is installed, there are some environment variables that need to be added to your profile. This can be done by editing the .bashrc file. Open a new terminal and open the file using:
1 sudo gedit .bashrc

NOTE: You may want to create a backup of the .bashrc before editing, the easiest way is to copy the file to a different location. Later you can replace the edited .bashrc with the copied one in case something goes sideways or if you want to remove the NS.
2. Add the following lines AT THE END of the file. Be sure to change “/path_to” to the path of where you have extracted the NS (e.g. ‘/home/ECE/Local’).

export PATH=$PATH:/home/ece/Public/ns-allinone-2.35/bin:/home/ece/Public/ns-allinone-2.35/tcl8.5.10/unix:/home/ece/Public/ns-allinone-2.35/tk8.5.10/unix

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ece/Public/ns-allinone-2.35/otcl-1.14:/home/ece/Public/ns-allinone-2.35/lib

export TCL_LIBRARY=$TCL_LIBRARY:/home/ece/Public/ns-allinone-2.35/tcl8.5.10/library

Now save and close the file-descriptor

Step 4: Validate the Installation

You need to validate NS to check if everything is OK but keep in mind that it will take a lot of time (about 1:30 hrs). Open up a terminal and move to the directory ‘/home/ece/Local/ns-allinone-2.35/ns-2.35/’ and run:

1 ./validate

And That is it ! You can now run ns from a terminal window by executing: ns
If you received the “%” sign, it means that NS is running (image 5). Congratulations !!

Introduction to TCL Scripts:

Now that the NS2 is installed on your system. You need to know a bit about the scripting. The scripting interface for ns-2 uses the language Tcl, pronounced “tickle”; more precisely it is object-Tcl, or OTcl. For simple use, learning the general Tcl syntax is not necessary; one can proceed quite successfully by modifying standard examples.

However, Tcl is a powerful scripting language that runs under Unix, Linux, VMS, DOS/Windows, OS/2, and MacOS (at least). It provides all the usual high-level programming features that we’ve come to expect from languages like the Unix shell, Awk, Perl, or Rexx, such as:

  • Variable-length strings
  • Associative arrays
  • Lists
  • Keyed lists (aka structs, structures or records)
  • Pattern matching with regular expressions
  • Ability to define or redefine procedures at run-time
  • Full file access
  • Error handling


Use of set, puts, incr, and set n [expr $n + 1] commands in tcl


Arrays in TcL








error: Content is protected !!