You are on page 1of 44

NS2 Workshop

Module-1

Presented by
Sreenu.G

1
Contents
2

 Introduction to Computer Networks


 Basics of Computer Network Simulation
 Introduction to Network Simulator 2 (NS2)
 Basic architecture of NS2
 The Two-Language Concept in NS2
 Linkage Between OTcl and C++ in NS2
 NS2 Installation
 Structure of NS2 Program
 Trace file and Nam File
 Modeling Network Protocols
 Conclusion
 References
Introduction to Computer
Networks
3

What is a computer network?


Applications of Networks
Network Topology
Network Components
 Physical Media
 Interconnecting Devices
 Computers
 Networking Protocol
 Applications
Protocols
Protocols
4

For proper communication, entities in different


systems must speak the same language.
There must be mutually acceptable conventions and
rules about the content, timing and underlying
mechanisms.
Those conventions and associated rules are referred
as “PROTOCOLS”.
Standard Protocol Architectures:
 OSI Reference model
 TCP/IP protocol suite
OSI Reference Model
5

Open Systems Interconnection


Reference model
provides a general framework for standardization
defines a set of layers and services provided by each layer
one or more protocols can be developed for each layer
Developed by the International Organization for
Standardization (ISO)
Published by ITU-T (International Telecommunications
Union)
OSI Reference Model
6

A layered model
Seven layers – seven has been presented as the
optimal number of layer
Delivered too late (published in 1984)!
by that time TCP/IP started to become the de facto
standard
Although no OSI-based protocol survived, the model
is still valid (in the textbooks)
OSI - The Layer Model
7

Each layer performs a subset of the required


communication functions
Each layer relies on the next lower layer to perform
more primitive functions
Each layer provides services to the next higher layer
Changes in one layer should not require changes in
other layers
Summary of layers
8
TCP/IP Reference Model
9

Most widely used interoperable network protocol


architecture
Specified and extensively used before OSI

 OSI was slow to take place in the market

Funded by the US Defense Advanced Research


Project Agency (DARPA) for its packet switched
network (ARPANET)
Used by the Internet and WWW
TCP/IP Reference Model
10
Basics of Computer Network
Simulation
11

Simulation: The Formal Definition

According to Shannon, simulation is “the process of


designing a model of a real system and conducting
experiments with this model for the purpose of
understanding the behaviour of the system and/or
evaluating various strategies for the operation of the
system.”
From Network to Simulation
12
App
Application,
App App
Agent & Node
Agent
Agent Agent

Node Node Node

Link Link Link

Node Link Node Link Node

Link Link Link

Node Link
App App App

Agent Agent Agent

Node Node Node


Why Simulation
13

real-system not available, is complex/costly or


dangerous (eg: space simulations, flight
simulations)

quickly evaluate design alternatives (eg: different


system configurations)

evaluate complex functions for which closed form


formulas or numerical techniques not available
The evaluation spectrum
14

Numerical models

Simulation

Emulation

Prototype

Operational system
Elements of Simulation
15

Entities
Resources
Activities and Events
Scheduler
Global Variables
Random Number Generator
Statistics Gatherer
Introduction to Network Simulator 2
17

Network Simulator (Version 2), widely known as


NS2.

It is often used by researches to help evaluate the


performance of new protocols.
Introduction to Network Simulator 2
18

Simulation of wired as well as wireless network


functions and protocols (e.g., routing algorithms,
TCP, UDP) can be done using NS2.

ns2 allows you to setup a computer network,


consisting of nodes/routers and links. You can then
send data (packets) over the network using a variety
of different protocols at different layers.
Introduction to Network Simulator 2
19

Network simulator 2 (ns2) is a popular open source


discrete event simulator for computer networks.

Event-driven simulation tool.


 Physical activities are translated to events
 Events are queued and processed in the order of their
scheduled occurrences
 Time progresses as the events are processed
Introduction to Network Simulator 2
20

University of California and Cornell University who


developed the REAL network simulator,the
foundation which NS is based on.
Since 1995 the Defense Advanced Research Projects
Agency (DARPA) supported development of NS
through the Virtual InterNetwork Testbed (VINT)
project .
 Currently the National Science Foundation (NSF)
has joined the ride in development.
Platforms supported
21

Most UNIX and UNIX-like systems


 FreeBSD
 Linux

 Solaris

Windows 98 onwards
 Cygwin required
NS Goals
22

Support networking research and education


 Protocol design, traffic studies, etc
 Protocol comparison

Provide a collaborative environment


 Freely distributed, open source
 Share code, protocols, models, etc
 Allow easy comparison of similar protocols
 Increase confidence in results
 More people look at models in more situations
 Experts develop models
NS Components
24

NS, the simulator itself


Nam, the network animator
 Visualize ns (or other) output
 Nam editor: GUI interface to generate ns scripts

Pre-processing:
 Traffic and topology generators
Post-processing:
 Simple trace analysis, often in Awk, Perl, or Tcl
The Two-Language Concept in NS2
29

NS uses two languages.

Because any network simulator, in general, has two


different kinds of things it needs to do.
 detailed simulations of protocols
 slightly varying parameters or configurations, or quickly
exploring a number of scenarios.

NS meets both of these needs with two languages,


C++ and Otcl.
The Two-Language Concept in NS2
30

NS2 consists of two key languages: C++ and Object-


oriented Tool Command Language (OTcl).
The C++ defines the internal mechanism (i.e.,a
backend) of the simulation objects.
The OTcl sets up simulation by configuring the
objects as well as scheduling discrete events (i.e., a
frontend).
The C++ and the OTcl are linked together using
TclCL.
Why two languages? (Tcl & C++)
34

 C++: Detailed protocol simulations require


systems programming language
 byte manipulation, packet processing, algorithm
implementation
 Run time speed is important
 Turn around time (run simulation, find bug, fix bug,
recompile, re-run) is slower
 Tcl: Simulation of slightly varying parameters or
configurations
 quickly exploring a number of scenarios
 iteration time (change the model and re-run) is more
important
How Ns2 Works
36
How Ns2 Works
37
Running NS2
38

NS2 provides users with an executable command ns


which takes on input argument, the name of a Tcl
simulation scripting file.

Users are feeding the name of a Tcl simulation script


(which sets up a simulation) as an input argument of
an NS2 executable command ns.

In most cases, a simulation trace file is created, and


is used to plot graph and/or to create animation.
Terminology
39

An NS2 simulation script (e.g., myfirst_ns.tcl) is


referred to as a Tcl simulation script .
C++ and OTcl class hierarchies, which have one-to-
one correspondence, are referred to as the compiled
hierarchy and the interpreted hierarchy,
respectively.
An OTcl object is associated with instance variables,
instance procedures, and commands, while a C++
object is associated with variables and functions.
Notations
40
Linkage Between OTcl and C++ in NS2
41
Shadowing

TclObject OTcl class C++ class TclObject()


hierarchy hierarchy

Agent Agent()

Agent/DSDV DSDVAgent()

Agent/DSDV OTcl Agent/DSDV C++


shadow object object
42
From Network to Simulation
46
Application,
App1 App2 App1 App2 Agent & Node App1 App2

Agent1 Agent2 Agent1 Agent2 Agent1 Agent2

Node Node Node

Link Link Link

Node Link Node Link Node

Link Link Link

Node Link
Node Node Node

Agent1 Agent2 Agent1 Agent2 Agent1 Agent2

App1 App2 App1 App2 App1 App2


Installation
47

Install apt-get in machine then give the folloing


line to terminal
 
sudo add-apt-repository ppa:wouterh && sudo apt-
get update && sudo apt-get
install ns nam xgraph
 
You will have to give 2 or 3 times "yes" to proceed
through installation
 
after installing type "ns" in terminal, if you get "%"
as prompt ..done....
Structure of NS2 Program
48

Creating a Simulator Object


 Setting up files for trace & NAM
 Tracing files using their commands
Closing trace file and starting NAM
Creating LINK & NODE topology
Orientation of links
Final topology Generated
49
Trace file and NamTrace File
50

Once the simulation is complete, we can see two


files: “trace.tr”, and “nam.out”.
The trace file (trace.tr) is a standard format used by
ns2.
In ns2, each time a packet moves from one node to
another, or onto a link, or into a buffer, etc., it gets
recorded in this trace file.
Each row represents one of these events and each
column has its own meaning.
NamTrace File
51

Start nam with the command 'nam <nam-file>'


where '<nam-file>' is the name of a nam trace file
that was generated by ns.
 Network Animator
 A visual aid showing how packets flow along the network
52
Modeling Network protocols
53

 Collection of Various protocols at multiple layers

 TCP(reno, tahoe, vegas, sack)


 MAC(802.11, 802.3, TDMA)
 Ad-hoc Routing (DSDV, DSR, AODV, TORA)
 Sensor Network (diffusion)
 Multicast protocols, Satellite protocols, and
many others
Conclusion
54

A computer network is a complex system that


requires a careful treatment in design and
implementation.
Simulation, regarded as one of the most powerful
performance analysis tools, is usually used in
carrying out such a treatment to complement the
analytical tools.
An introduction to Ns2 is presented with the help of
architecture . Also the different languages used in
NS2, result analysing tools in NS2 are also discussed.
References
55

A. S. Tanenbaum, Computer Networks, 3rd ed.


Prentice Hall, 1996.
R. E. Shannon, “Introduction to the art and science
of simulation,” in Proc. of the 30th conference on
Winter simulation (WSC’98), 1989.
The Network Simulator Wiki. [Online]. Available:
http://nsnam.isi.edu/nsnam/index.php/
The Network Simulator – ns-2. [Online]. Available:
http://www.isi.edu/nsnam/ns/
References
56

M. Greis. Tutorial for the Network Simulator NS2.


[Online]. Available:
http://www.isi.edu/nsnam/ns/tutorial/
K. Fall and K. Varadhan. (2007, Aug.) The ns manual
(formerly known as ns notes and documentation).
[Online]. Available:
http://www.isi.edu/nsnam/ns/ns-documentation.ht
ml
57

THANK YOU

You might also like