0% found this document useful (0 votes)
47 views44 pages

Network Simulator (NS-2) : Internet Technologies 60-375

NS-2 is a discrete event network simulator that models protocols at multiple layers. It supports simulation of TCP, MAC, routing and other protocols and has been used for research and education. NS-2 is open source and runs on UNIX and Windows platforms.

Uploaded by

chethansharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views44 pages

Network Simulator (NS-2) : Internet Technologies 60-375

NS-2 is a discrete event network simulator that models protocols at multiple layers. It supports simulation of TCP, MAC, routing and other protocols and has been used for research and education. NS-2 is open source and runs on UNIX and Windows platforms.

Uploaded by

chethansharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 44

Network Simulator (NS-2)

Internet Technologies
60-375
Agenda
 Overview of NS-2
 History
 Current Status
 Platforms Supported
 Discrete Event Simulator
 NS-2 Environment
 NS-2 Hierarchy
 NS-2 Architecture
 Node Architecture
 Multicast Node Architecture
 Packet Structure
 Links
 Traffic Flow
 Example

© Varaprasad Reddy 2
Overview of NS-2
 Discrete Event Simulator
 Packet level
 Modeling Network protocols
 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, gaf)
 Multicast protocols, Satellite protocols, and many others

© Varaprasad Reddy 3
Overview of NS-2
 Maintained through VINT project
 NS2 :collaborative simulation environment
 Freely
distributed and open source
Supports NT research and education
Protocol design , traffic analysis etc.
 Provides common reference

© Varaprasad Reddy 4
History
 1995 : Developed by LBL through support
of DARPA
 1996: NS was extended and distributed
by VINT project
 1997: Satellite models added @ UCB
 1999: Wireless models added @ CMU
 Recent incorporation of emulation

© Varaprasad Reddy 5
Current status
 Releases:
 Periodic releases (currently 2.27, Jan 2004)
 Daily snapshots (probably compiles and
works, but “unstable”)
 Available from: USC/ISI, UC Berkeley, UK
mirror
 More than 10k users from hundreds of univs

© Varaprasad Reddy 6
Platforms supported

 Most UNIX and UNIX-like systems


 FreeBSD
 Linux
 Solaris

 Windows 98/2000/2003/XP
 Cygwinrequired
 Some work , some doesnt

© Varaprasad Reddy 7
NS-2 : Components
 NS – Simulator
 NAM – Network AniMator
 visual demonstration of NS output
 Preprocessing
 Handwritten TCL or
 Topology generator
 Post analysis
 Trace analysis using Perl/TCL/AWK/MATLAB

© Varaprasad Reddy 8
User’s Perspective
 From the user’s perspective, NS−2 is an OTcl
interpreter that takes an OTcl script as input
and produces a trace file as output.

© Varaprasad Reddy 9
Discrete event simulator
 ns-2 is an discrete event driven simulation
 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
Time: 1.5 sec Time: 1.7 sec

1 2

Time: 2.0 sec Time: 1.8 sec

© Varaprasad Reddy 10
Discrete Event Scheduler

time_, uid_, next_, handler_


head_ ->
head_ ->
handler_ -> handle()

insert time_, uid_, next_, handler_


Event Scheduler

© Varaprasad Reddy 11
Event Scheduler
 Non-Real time schedulers
 Implementations : List , Heap , Calender
 Calender is default
 Real time schedulers
 Used for emulation for direct interaction with real NT.
 Basic use of an event scheduler:
 schedule simulation events, such as when to start an
FTP application, when to finish a simulation, or for
simulation scenario generation prior to a simulation
run.

© Varaprasad Reddy 12
NS-2 Environment
Simulation 1 2
Scenario

set ns_ [new Simulator]

Tcl Script set node_(0) [$ns_ node]


set node_(1) [$ns_ node]

class MobileNode : public Node


{
C++ public:
friend class PositionHandler;
Implementation MobileNode();


}

© Varaprasad Reddy 13
tcl Interpreter With Extents
Event ns-2
Scheduler

Component
Network
tclcl
otcl
tcl8.0
 otcl: Object-oriented support
 tclcl: C++ and otcl linkage
 Discrete event scheduler
 Data network (the Internet) components
© Varaprasad Reddy 14
NS-2 Hierarchy
TclObject

NSOject

Classifer Connector

Addr Delay

Replicator Agent

MCast Application

MPath Queue

Hash Trace

© Varaprasad Reddy 15
NS-2 Hierarchy
Agent

UDP TCP DSDV AODV TORA DSR

Queue
Reno
Application Trace
RBP
Droptail
Vegas
Telnet

RBP
Traffic RED Enq
Sack1
FQ
Exponential Deq
NewReno SFQ
Tap Pareto
DRR
Sink CBR Drop
FullTCP CBQ
Trace
SRM
FTP
© Varaprasad Reddy 16
Adaptive
NS-2 Directory Structure

sim

tcl8.0 tk8.0 otcl Tcl ns-2 nam-1

tcl code C++ code


tcl ...
example
ex test lib ...
validation test tcl code core

© Varaprasad Reddy 17
Node Architecture
Node

Agent

Classifier
Local
Agent

Classifier
Node entry point
Agent
Port
Classifiers: packet demultiplexers.
Addr

Link Link Link

Agents are either protocol endpoints or related


© Varaprasad Reddy 18
objects that generate/fill-in packet fields.
Multicast Node architecture

© Varaprasad Reddy 19
PacketsPacket
(events)
Structure
packet
next_
Size
determined accessdata( ) - packet size
at
simulation
bits( )
Size - timestamp
config time determined at cmn header
compile time - type
Size - UID
determined at tcp header
compile time - interface label
Size
determined at ip header
compile time

Size
determined at trace header
compile time

© Varaprasad Reddy 20
Links
Links: keeps track of “from” and “to” node objects.
blocked

Link
entry Enq Trace Queue Deq Trace Delay TTL Rcv Trace
point

Drop head Drp Trace

© Varaprasad Reddy 21
N1 N2

Node Node

Classifier
Classifier

Local Local
Agent Agent

Classifier
Classifier

Application Application
Port Port
Addr Addr

Link

Link
Enq Trace Queue Deq Trace Delay TTL Rcv Trace

Drop head Drp Trace

© Varaprasad Reddy 22
NS-2 : C++ / OTCL
 NS-2 Code contains two sets of
languages, namely C++ and OTcl.
 C++ is used for the creation of objects
because of speed and efficiency.
 OTcl is used as a front-end to setup the
simulator, configure objects and
schedule events because of its ease of
use.

© Varaprasad Reddy 23
Why two languages? (Tcl & C++)
 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

© Varaprasad Reddy 24
Tcl or C++?
 Tcl
 Simple Configuration, Setup, Scenario
 If it’s something that can be done without
modifying existing Tcl module.
 C++
 Anything that requires processing each
packet
 Needs to change behavior of existing
module

© Varaprasad Reddy 25
Shadowing

TclObject OTcl class C++ class TclObject()


hierarchy hierarchy

Agent Agent()

Agent/DSDV DSDVAgent()

Agent/DSDV OTcl Agent/DSDV C++


shadow object object
© Varaprasad Reddy 26
Object Correspondence
Agent/DSDV Agent TclObject
Constructor Constructor Constructor
Invoke parent Invoke parent Create C++

init complete init complete OTcl shadow

TCL
C++
TclObject() Agent() AgentDSDV()
Constructor Constructor Constructor
Do nothing, Invoke parent Invoke parent
bind and bind and
return return return

© Varaprasad Reddy 27
Outline

© Varaprasad Reddy 28
NS-2 Directory Structure

sim

tcl8.0 tk8.0 otcl Tcl ns-2 nam-1

tcl code C++ code


tcl ...
example
ex test lib ...
validation test tcl code core

© Varaprasad Reddy 29
Making Changes in C++ Space
 Existing code
 recompile

 Addition
 change Makefile and recompile

© Varaprasad Reddy 30
Making Changes in otcl Space
 Existing code
 recompile
 source

 Addition
 source
 change Makefile (NS_TCL_LIB), tcl/ns-
lib.tcl (source) and recompile

© Varaprasad Reddy 31
Installation
 Unix variants
 Download NS-allinone-2.27 package
 Contains
 TCL/TK 8.4.5
 oTCL 1.8

 Tclcl 1.15

 Ns2

 Nam -1

© Varaprasad Reddy 32
Installation
 After successful downloading and unzipping
install allinone package , install NS by
 install by calling ~/ns-allinone-2.27/install
 After successful installation , Validate the
scripts by running ./validate in ~/ns-allinone-
2.27/ns-2.27/
 Its now all set to work with NS

© Varaprasad Reddy 33
Code for simple topology
 Creating a Simulator Object
 set ns [new Simulator]
 Setting up files for trace & NAM
 set trace_nam [open out.nam w]
 set trace_all [open all.tr w]

 Tracing files using their commands


 $ns namtrace-all $trace_nam
 $ns trace-all $trace_all

© Varaprasad Reddy 34
Code for simple topology
 Closing trace file and starting NAM
 proc finish { } {
 global ns trace_nam trace_all
 $ns flush-trace

 close $trace_nam

 close $trace_all

 exec nam out.nam &

 exit 0 }

© Varaprasad Reddy 35
Code for simple topology
 Creating LINK & NODE topology
 Creating NODES
 set n1 [$ns node]
 set n2 [$ns node]

 set n3 [$ns node]

 set n4 [$ns node]

 set r1 [$ns node]

 set r2 [$ns node]

© Varaprasad Reddy 36
Code for simple topology
 Creating LINKS
 $ns duplex-link $N1 $R1 2Mb 5ms DropTail
 set DuplexLink0 [$ns link $N1 $R1]
 $ns duplex-link $N2 $R1 2Mb 5ms DropTail
 set DuplexLink1 [$ns link $N2 $R1]
 $ns duplex-link $R1 $R2 1Mb 10ms DropTail
 set DuplexLink2 [$ns link $R1 $R2]
 $ns duplex-link $R2 $N3 2Mb 5ms DropTail
 set DuplexLink3 [$ns link $R2 $N3]
 $ns duplex-link $R2 $N4 2Mb 5ms DropTail
 set DuplexLink4 [$ns link $R2 $N4]

© Varaprasad Reddy 37
Code for simple topology
 Orientation of links
 $ns duplex-link-op $N1 $R1 orient right-
down
 $ns duplex-link-op $N2 $R1 orient right-up
 $ns duplex-link-op $R1 $R2 orient right
 $ns duplex-link-op $R2 $N3 orient right-up
 $ns duplex-link-op $R2 $N4 orient right-down

© Varaprasad Reddy 38
Final topology Generated

© Varaprasad Reddy 39
Traffic topology aimed at

© Varaprasad Reddy 40
Generating Traffic
 Attaching AGENT TCP to NODE 1
 set TCP1 [new Agent/TCP]
 $ns attach-agent $N1 $TCP1
 Attaching AGENT TCP to NODE 2
 set TCP2 [new Agent/TCP]
 $ns attach-agent $N2 $TCP2
 Attaching AGENT TCP to NODE 3
 set TCP3 [new Agent/TCPSink]
 $ns attach-agent $N2 $TCP3
 Attaching AGENT TCP to NODE 4
 set TCP4 [new Agent/TCPSink]
 $ns attach-agent $N2 $TCP4

© Varaprasad Reddy 41
Generating Traffic
 Attaching Application (FTP)
 set FTP0 [new Application/FTP]
 set FTP1 [new Application/FTP]
 $FTP0 attach-agent $TCP0
 $FTP1 attach-agent $TCP1

© Varaprasad Reddy 42
Setting simulation times
 $ns at 0.5 "$FTP0 start"
 $ns at 0.5 "$FTP1 start"
 $ns at 10.0 "$FTP0 stop"
 $ns at 10.0 "$FTP1 stop“
 $ns at 10.0 “finish”
 Making NS run
 $ns run

© Varaprasad Reddy 43
© Varaprasad Reddy 44

You might also like