Professional Documents
Culture Documents
Presented by
Sowmya.G & Sakila.K
Sr.Lecturers,ECE Department
The Oxford College Of Engineering,
Bangalore.
Outline
Introduction to Simulation
Advantages of simulation
Network Simulators
NS – 2 evolution and goals
Discrete event simulation
NS-2 Architecture
C++ and OTCL
Hierarchy
Duality
Naming conventions
NS-2 components, Capabilities and Features
Useful links
Installation
Generic script structure
Simple topology
Summary
Introduction to Simulation
How to study a system?
• Measurements on an existing system
- What to do, if system does not exist really?
- What to do, if changes are very expensive or time consuming?
• Mathematical analysis
- Good solutions, but only feasible for simple systems.
- Real world systems are too complex, e.g., factory, computer,
network, etc.
• Modeling and Evaluation of Communication Systems
• Simulation
- Build the behavior of a system within a program
• Emulation, Emulator
- Not only the behavior is imitated, but the system itself is somehow
reproduced (prototype design)
Advantages of simulation
• Simulation enables the study of experiments with internal
interactions.
• To check the system’s behavior, the simulation can be used to see
Informational, organizational, and environmental changes.
• Observing results from simulation can give insight to which variables
are the most important ones.
• Simulation can be used to devise reinforcement learning mechanism.
• Simulations can be used to verify analytical results, e.g. queueing
systems.
• Animation of a simulation can show the system in action, so that
the plan can be visualized.
Advantages of simulation
• Policies, procedures, decision rules, information flows can be
explored without disrupting the real system.
• New hardware designs, physical layouts, transportation systems can
be tested without committing resources.
• Time can be compressed or expanded.
- Slow-down or Speed-up.
• Bottleneck analysis can be performed to detect excessive delays.
Network simulators
OPNET (http://www.opnet.com)
• Leading Commercial Software
• Support Windows and Unix
• Graphical Interface
• GloMoSim (http://pcl.cs.ucla.edu/projects/glomosim)
• Simulation environment for wireless network
• Scalable to support thousands of nodes
• Free for educational users
• More Resources
http://www.icir.org/models/simulators.html
NS-2 Simulator evolution
Each event
Two nodes
on an Ethernet: simple t=1, A enqueues pkt on LAN
queuing t=1.01, LAN dequeues pkt
model: and triggers B
Agent/TCP TCPAgent()
14
14
OTcl and C++: The Duality
NS-2 Naming conventions
NS-2 implementation
Users Perspective
ns-allinone
Downloading
NS2 is available from http://www.isi.edu/nsnam/ns/ns-
build.html
Download the ns-allinone package, ns-allinone-
2.33.tar.gz
Installing NS2
Go to directory of downloaded ns-allinone.tar.gz
Unpack the file using:
tar -xzvf ns-allinone-2.33.tar.gz
Go to the ns-allinone-2.33 directory:
cd ns-allinone-2.33
Install it with the command
./install
How to Install?
2) Turn on tracing
3) Create topology
7) Start simulation
Step1: Create Simulator Object
n0
n1
Step 3: Create Network
n0
• Nodes
set n0 [$ns node]
set n1 [$ns node]
• Link failures
• Hooks in routing module to reflect routing changes
$ns rtmodel-at <time> up|down $n0 $n1
• For example:
$ns rtmodel-at 1.0 down $n0 $n1
$ns rtmodel-at 2.0 up $n0 $n1
Step 5: Creating UDP connection
n1
null
Step 6: Creating Traffic
(On Top of UDP) cbr
• CBR udp
set cbr [new Application/Traffic/CBR]
n1
null
Creating TCP connection tcp
sink
Step 6: Creating Traffic
(On Top of TCP)
ftp
FTP
set ftp [new Application/FTP] tcp
$ftp attach-agent $tcp
Telnet
set telnet [new Application/Telnet] n0
$telnet attach-agent $tcp
n1
sink
Post-Processing Procedures
• Add a 'finish' procedure that closes the trace file and starts nam.
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
Run Simulation
• Schedule Events
$ns at <time> <event>
• Call ‘finish’
$ns at 5.0 "finish"
Color
$ns duplex-link-op $n0 $n1 color "green“
Label
$ns duplex-link-op $n0 $n1 label “backbone"
Application
FTP
set ftp [new Application/FTP]
CBR
set cbr [new Application/Traffic/CBR]
packet type
timestamp, uid, …
#Monitor the queue for the link between node 2 and node 3
$ns duplex-link-op $n2 $n3 queuePos 0.5
Tracing
set tracefd [open mytrace.tr w]
$ns_ trace-all $tracefd
set nf [open out.nam w]
$ns_ namtrace-all-wireless $nf $val(x) $val(y)