A Practical Approach of Network Simulation

A Practical Approach of Network Simulation

Ratish Agarwal (UIT-RGPV, India), Piyush Kumar Shukla (UIT-RGPV, India) and Sachin Goyal (UIT-RGPV, India)
Copyright: © 2017 |Pages: 16
DOI: 10.4018/978-1-5225-2154-9.ch002
OnDemand PDF Download:
No Current Special Offers


Communication is a very important area of research in the present era. Expansion of globalization and reduction in the cost of electronic devices has made communication very effective. A large number of researchers from academics and industries are involved in the research on communication and networks. Any novel idea has to be verified on the simulator. A number of simulators are available for network simulations such as Network Simulator (NS2 and NS3), OPNET, NetSim, OMNeT++, REAL, J-Sim and QualNet. NS is an open-source simulation tool that runs on Linux. It is a discreet event simulator for networking research and provides substantial support for simulation of routing, multicast and IP protocols. This chapter provides an overview of NS in a much simpler way. At the completion of this chapter readers will be able to write tcl script to simulate a scenario of network. Every simulation on NS generates a huge trace file; the study of this can be done with the help of AWK script.
Chapter Preview


NS-2 is an open-source discrete event network simulator (Information Sciences Institute, The Network Simulator ns-2, 2004) which is widely used by both the research community as well as by the people involved in the standardization protocols of IETF. This chapter is intended to help students, engineers or researchers who need not have much background in programming or who want to learn through simple examples how to analyze some simulated objects using NS-2. NS is an object oriented simulator, written in C++, with OTcl interpreter as a front end.

Importance of Two Languages

NS meets two needs with two languages, C++ and OTcl. C++ is fast to run but slower to change (Asmussen, Soren, Glynn, Peter W., 2007 Jump up Banks, Carson, Nelson Nicol), making it suitable for detailed protocol implementation. OTcl runs much slower but can be changed very quickly (and interactively), making it ideal for simulation configuration. ns (via tclcl) provides glue to make objects and variables appear on both languages.

Tcl (Tool Command Language)

It is used by millions of people in the world. It is a language with a very simple syntax and it allows a very easy integration with other languages. Tcl was created by John Ousterhout. The characteristics of this language are the following:

  • 1.

    It allows a fast development.

  • 2.

    It provide a graphic interface.

  • 3.

    It is compatible with many platforms.

  • 4.

    It is flexible for integration.

  • 5.

    It is easy to use.

  • 6.

    It is free.

NS-2 Simulator Preliminaries

The steps we should follow while writing first simulation script are

  • 1.

    Definition of network nodes, links, queues and topology,

  • 2.

    Definition of agents and applications,

  • 3.

    The nam (Network Animator) visualization tool,

  • 4.

    Tracing, and random Variables.


Initialization And Termination

A Tcl script in NS-2 simulation starts with the command (A Boukerche 2001):

set ns [new Simulator]

This line declares new variable ns using the set Tcl command. You can call this variable whatever you wish, but, in general, people declare it as ns because it is an instance of the Simulator class, so an object. So, using these new variable ns we can use all the methods of the class Simulator that we will see below.

In order to have output files with data on the simulation (trace files) or files used for visualisation (nam files), we need to create the files using the “open” command:

#open trace file (# is used to write comments on the script)
set file1 [open first.tr w]
$ns trace-all $file1
#open namtrace(network animator) file
set file2 [open first.nam w]
$ns namtrace-all $file2

The first and fourth lines in the example are only comments; they are not simulation commands. Note that these lines begin with a # symbol. The termination of the program is made using a “finish” procedure.

# Define a ’ finish ’ procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
puts “running nam...”
exec nam first.nam &
exit 0

Complete Chapter List

Search this Book: