Introduction To NS2: T S Pradeep Kumar VIT University-Chennai Campus
Introduction To NS2: T S Pradeep Kumar VIT University-Chennai Campus
T S Pradeep Kumar
VIT University- Chennai campus
http://www.pradeepkumar.org
[email protected]
Overview
•Linux Vs Windows
•Network Simulation
•Introduction to NS2
•About NS2
•NS2 Architecture
•OTCL
Versus
TS PRADEEP KUMAR
Network Simulation
• Approaches
– Experiment
• Put all network Devices and measure the results/performance
• Pros - realistic
• Cons - Expensive/Sometime impossible
– Mathematical model
• Model devices using a graph model
• Insight
• Need to make assumptions
– Simulation
• Use programming to represent devices
• Easy and can be easily verified
• Not much insight, need to make assumptions
TS PRADEEP KUMAR
Network Simulation
• Network Simulation
– Time Driven
• Events occurs within the interval is assumed to be
occur at the end of the interval
• Simulation finishes at a pre-specified time
• a, b,c,d are events
• a is assumed to occur at t=2Δ
TS PRADEEP KUMAR
Network Simulation
• Network Simulation
– Event Driven
• Every event provide a reference to the next event (Example: using
pointer)
A B C
• Simulation finishes
– When there are no more events
– At pre-specified time
TS PRADEEP KUMAR
About NS2
• NS is a discrete event simulator
• It provides support for
– Simulation of TCP
– Routing
– Multicast Protocols over Wired and Wireless
networks
TS PRADEEP KUMAR
About NS2
• NS is not a polished and finished product, but
the result of an on-going effort of research
and development.
• In particular, bugs in the software are still
being discovered and corrected.
• Users of ns are responsible for verifying for
themselves that their simulations are not
invalidated by bugs
TS PRADEEP KUMAR
TS PRADEEP KUMAR
NS2 Architecture
• Network Simulator 2 is an event driven
Simulator
• It consists of
– C++ (Internally)
– OTCL (User Interface)
– TclCL (Interface between C++ and OTCL)
TS PRADEEP KUMAR
NS2 Architecture
TS PRADEEP KUMAR
NS2 Architecture
TS PRADEEP KUMAR
OTCL
• NS is a OTCL interpreter with network
simulation object libraries
• Relation between TCL and OTCL is similar to C
and C++
• A Simple example follows..
• To run these examples
– ns filename.tcl (or) tclsh filename.tcl
TCL Example
# Writing a procedure called "test“
proc test {} {
set a 43
set b 27
set c [expr $a + $b]
set d [expr [expr $a - $b] * $c]
for {set k 0} {$k < 10} {incr k} {
if {$k < 5} {
puts "k < 5, pow = [expr pow($d, $k)]"
} else {
puts "k >= 5, mod = [expr $d % $k]"
}}}
# Calling the "test" procedure created above
test
OTCL Example
# Create a class call "mom" and add a member
function call "greet"
Class mom
mom instproc greet {} {
$self instvar age_
puts "$age_ years old mom say:
How are you doing?"
}
OTCL Example
# Create a child class of "mom" called "kid" and overide
the member function "greet"
Class kid -superclass mom
kid instproc greet {} {
$self instvar age_
puts "$age_ years old kid say:
What's up, dude?"
}
OTCL Example
• # Create a mom and a kid object set each age
• set a [new mom]
• $a set age_ 45
• set b [new kid]
• $b set age_ 15
TS PRADEEP KUMAR