Upload
udhay-prakash
View
250
Download
2
Embed Size (px)
Citation preview
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 1/48
Ns2
Network Simulator
Tutorial for Beginners’
Udhay Prakash
Udhayprakash.blogspot.in
Uday3prakash @gmail.com
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 2/48
Presentation Agenda
• Introduction to Linux
• Importance of Open Source software
• Network Simulators
•
• Ns2 Installation
• TCL scripting language
• Introduction to NAM and Xgraph
• Discussion about trace file format
04-Jul-14 2udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 3/48
Outcomes
• To get ease with Linux platform
• Open Source vs Free ware vs proprietary
• To insight about a Network Simulator
•
• Scripting language vs programming language
• Ability to install ns2, nam and xgraph
• Ease in working with TCL scripting
• Insight to NAM and Trace files
04-Jul-14 3udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 4/48
SESSIO -1
Introducing to Linux and s2ntroducing to Linux and s2
04-Jul-14 4udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 5/48
Linux
• Developed under GNU project.
• Open Source software, except RedHat
• Major Linux Families» Debian, Ubuntu, Mint, ….
» Fedora
» OpenSUSE
» ArchLinux
» CentOS & RedHat
04-Jul-14 5udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 6/48
Working in Linux
• Are you new to Linux Operating System?
• Are you more habituated to Windows or
Macintosh Operating Systems ?
• en, care u y o ow me… (switch on your PCs)
– Creating a file
– Reading/writing/editing a file
– Operating System specific file types
04-Jul-14 6udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 7/48
Why Simulators?
• Advantages☺Complex scenarios can be easily tested
☺Cheap-does not require costly equipment
☺Results can be quickly obtained-more ideas can be tested in asmaller timeframe
☺Controlled experimental conditions
☺Repeatability helps aid debugging
• Disadvantages☻Not real
☻Real systems too complex to model
☻Consideration of practical conditions
04-Jul-14 7udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 8/48
NS2 Network Simulator
• Open-source event-driven simulator
• Designed specifically for research in computer
communication networks.
• onta ns mo u es or numerous networ
components such as routing, transport layer
protocol, and application.
04-Jul-14 8udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 9/48
Ns2 sources
• http://www.isi.edu/nsnam/ns/
– The source code and documentation is currently maintained
by VINT project at ISI
• http://nsnam.isi.edu/nsnam/index.php/Main_Page – ep , : ns- . re ease .
– Mar 10, 2007: ns-2.31 released.
– July 2, 2006: ns-3 project announced.
• NS2 is a discrete event simulator targeted at networking research
• NS2 is an object oriented simulator, written in C++, with an OTcl
interpreter as a frontend
04-Jul-14 9udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 10/48
NS2 related Documentation
• introductory: Marc Greis's tutorial
• reference: Ns Manual (formerly called "ns Notes
and Documentation")
• ns y xamp e
• Practical Programming in Tcl and Tk
(http://www.beedub.com/book/)• http://hpds.ee.ncku.edu.tw/~smallko/ns2/ns2.htm
04-Jul-14 10udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 11/48
NS2- Features
• Collection of various protocols at multiple layers – 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 TCP(reno, many others• Traffic Models: CBR, VBR, Web, …
• Error Models: Uniform, Busty, …
• Misc: Radio Propagation, Mobility models, Energy Models, …
• Topology Generation tools (nsg2.1, ..)
• Visualization tools (NAM), Tracing
• Codes are contributed from multiple research communities
– Good: Large set of simulation modules
– Bad: Level of support and documentation varies
04-Jul-14 11udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 12/48
NS2 Chronicle
• 1989: REAL by Keshav
• 1995: ns by Floyd, McCanne at LBL
• 1997: ns-2 by the VINT project (Virtual
InterNetwork Testbed at LBL, Xerox PARC, UCB,
12
USC/ISI
• Now: ns-2.35 maintained at USC/ISI• Also there is NS-3, but it has no backwardcompatibility with NS-2.
04-Jul-14 udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 13/48
NS2 Chronicle
• REAL Simulator →NS (or NS1)→NS2→NS3.
• NS-1
–
– Developed by the network research group at theLawrence
– Berkeley National Laboratory (1989) – Derived from REAL Simulator
– Simulation description language: TCL
04-Jul-14 13udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 14/48
NS2 Chronicle
• NS-2 – Object Oriented (OTcl instead of TCL)
– Built in C++ and provides a simulation interface throughOTcl
– Developed by UC Berkeley
– Difficult for the first time users• Very few user friendly manuals. Ex: ns manual
• Needs scripting language, queuing theory and modelling techniques
knowledge• Complaint about inconsistent results
• And BUGS!!!!
• But, large community support
04-Jul-14 14udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 15/48
NS3
• No backward compatibility with NS2
• YANS (Yet Another Network Simulator)→NS-3 base
• NS-3.1 (2008), NS-3.11(2011), …
• Built in C++ and python • Good support for LTE and Wimax
• Simple to work with…..and suitable for dumping into andgetting data from real-time devices.
• No support for some protocols which were supported inns-2.
• But, lesser community support
04-Jul-14 15udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 16/48
NS-2 Directory Structure
TK8.0 OTcl tclclTcl8.0 ns-2 nam-1
ns-allinone
tcl
ex test lib
...
...
examples validation tests
C++ code
OTcl code
mcast
simple.tcl
04-Jul-14 16udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 17/48
NS-2 Environment
SimulationScenario
1 2
set ns_ [new Simulator]
c cr p
C++Implementation
_ _
set node_(1) [$ns_ node]
class MobileNode : public Node
{ friend class PositionHandler; public:
MobileNode();••
}
04-Jul-14 17udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 18/48
NS2 Architecture
04-Jul-14 18udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 19/48
Why two languages? (Tcl & C++)
• C++: Detailed protocol simulations require systems programming
language
– byte manipulation, packet processing, algorithm implementation
– Run time s eed is im ortant
– 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
04-Jul-14 19udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 20/48
What is Tcl/Tk ?•It is a Scripting language to describe a high-level programming language withrelatively transparent syntax
•Tools Command Lanuage (TCL) –simple string based scripting language for controlling and extending applications.
– provides generic programming facilities such as variables, loops, and
rocedures. –Tcl syntax is very much similar to UNIX shell programming.
•Tool k it (TK) – based on X-window system.
– provides facilities (widgets) for building user interfaces.
•Tcl/Tk –Excellent tools for Rapid prototyping.
–Tcl/Tk is interpreted rather than compiled. ( The interpreter is in !/opt/bin/wish )
–weakly typed language (strings and integer variables are interchangeable).
04-Jul-14 20udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 21/48
Basic Tcl
variables:
set x 10
puts “x is $x”
functions and expressions:
procedures:
proc pow {x n} {
if {$n == 1} { return $x }
set part [pow x [expr $n-1]] set y [pow x 2]
set y [expr x*x]
control flow:
if {$x > 0} { return $x } else {return [expr -$x] }
while { $x > 0 } {
puts $x
incr x –1
}
re urn expr x par
}
Also lists, associative arrays, etc.
=> can use a real programminglanguage to build networktopologies, traffic models, etc.
04-Jul-14 21udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 22/48
Basic oTclClass Person
# constructor:
Person instproc init {age} {
$self instvar age_
set age_ $age
# subclass:
Class Kid -superclass Person
Kid instproc greet {} {
$self instvar age_
puts “$age_ years old kid: What’s}
# method:
Person instproc greet {} {
$self instvar age_
puts “$age_ years old: How areyou doing?”
}
up, u e
}
set a [new Person 45]
set b [new Kid 15]$a greet
$b greet
# “new” in ns2 only
=> can easily make variations of existing things (TCP, TCP/Reno)
Person a 45
Kid b 15
a greet
b greet04-Jul-14 22udhayprakash.blogspot.in
S li Obj M d l
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 23/48
Split Object Model• Split Object Model with shared class hierarchy
– Control (OTcl) vs. Data (C++)
• TclCL provides ‘glue library’ to “easily” share functions, variables, etc
– OTcl into C++: command(), tcl.result()
– C++ into OTcl: tcl.eval()
• Not all classes are mirrored exactly
OTcl C++
23
OTcl script
describing
simulation T c l C L
udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 24/48
C++ and OTcl Linkage
• Class Tcl: instance of OTcl interpreter
Tcl& tcl = Tcl::instance();
tcl.evalc(“puts stdout hello world”);
tcl.result() and tcl.error()• Class TclObject and TclClass
– Variable bindings
bind(“rtt_”, &t_rtt_)
– Invoking command method in shadow class
$tcp advanceby 10
04-Jul-14 24udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 25/48
Calling Otcl functions from C++
• OTcl
Agent/TCP instproc advance {num} {
set window_ [expr $window_ + $num]
return $window_
}
• C++Tcl& tcl = Tcl::instance();
char *result;
tcl.evalf(“%s advance %d”, name_, size);
result = tcl.result();
wnd_ = atoi(result);
04-Jul-14 25udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 26/48
EmbeddedTcl
• How it works
– tcl2c++: provided by TclCL, converts tcl scripts
into a C++ static character array
– .tclsh8.0 bin/tcl-expand.tcl tcl/lib/ns-lib.tcl |
tcl2c++ et_ns_lib > gen/ns_tcl.cc
04-Jul-14 26udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 27/48
C++ and OTcl Separation
• “data” / control separation – C++ for “data”:
• per packet processing, core of ns
• fast to run, detailed, complete control
– OTcl for control:• Simulation scenario configurations
• Periodic or triggered action
• Manipulating existing C++ objects
• fast to write and change
+ running vs. writing speed
– Learning and debugging (two languages)
04-Jul-14 27udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 28/48
Object Granularity Tips
• Functionality
– Per-packet processing C++
– Hooks, frequently changing code OTcl
• a a managemen
– Complex/large data structure C++
– One-time configuration variables OTcl
04-Jul-14 28udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 29/48
Ns2 Installation Procedure
• Linux Installation (preferred):
– Go to udhayprakash.blogspot.in
– Search for ns2 installation procedure
– …..
• Windows Installation
– Go to
http://nsnam.isi.edu/nsnam/index.php/Running_Ns _and_Nam_Under_Windows_9x/2000/XP_Using_
Cygwin
04-Jul-14 29udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 30/48
Where to find…/ns-2/tcl/lib
• ns-lib.tcl: – The simulator class and most of its member functiondefinitions
• ns-default.tcl: –
• ns-packet.tcl:
– The packet header format initialization implementation
• other OTcl files: – implementation of compound network objects or the front end(control part) of network objects
04-Jul-14 30udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 31/48
SESSIO -2
Working with s2orking with s2
04-Jul-14 31udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 32/48
A Simple Topology
n0 n1
Application
AgentAgent
0 1
0 0
head_ enqT_ queue_ deqT_ link_ ttl_
drophead_
rcvT_
drpT_
Link
n1 – n0
04-Jul-14 32udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 33/48
N1 N2
C l a s s i f i e r
C l a s s i
Agent
Node
Local
C l a s s i f i e
r
C l a s
s i
Agent
Node
Local
Link
Link
i e r
Addr
Porti e r
Addr
Port
Enq Trace Deq Trace Rcv Trace
Drp Trace
Delay TTL
Drop head
Queue
04-Jul-14 33udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 34/48
Using ns
Problem
Simulationmodel
Setup/runsimulationwith ns
Resultanalysis
Modifyns
04-Jul-14 34udhayprakash.blogspot.in
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 35/48
NS-2 Generic Script Structure
set ns [new Simulator]set ns [new Simulator]# [Turn on tracing]# [Turn on tracing]
# [Turn on# [Turn on visualizervisualizer]]
# Create topology# Create topology
# Setup packet loss, link dynamics# Setup packet loss, link dynamics
# Create:# Create:
## -- multicast groupsmulticast groups
## -- protocol agentsprotocol agents
## -- application and/or setup traffic sourcesapplication and/or setup traffic sources
# Post# Post--processingprocessing procsprocs
# Start simulation# Start simulation
04-Jul-14 35udhayprakash.blogspot.in
h d l i
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 36/48
Event Scheduler Creation
• Event is a packet ID that is unique for a packet, which constitutes:
– Scheduled time
– The pointer to an object that handles the event
• An event scheduler
– Keeps track of simulation time – Fires all the events in the event queue
• Create event scheduler: set ns [new simulator]
• Schedule an event: $ns at <time> <event>
– Event is any legitimate ns/tcl function
– $ns at 5.0 “finish”
• Start scheduler
– $ns run
04-Jul-14 36udhayprakash.blogspot.in
T i
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 37/48
Tracing
04-Jul-14 37udhayprakash.blogspot.in
T i
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 38/48
Tracing
• Packet tracing and event tracing – Objects that are inserted between nodes
– Insert from OTcl using trace{} method
• $ns trace-all $file, or
38
• [$ns link $n0 $n1] trace $file
• Monitoring
– Record counters of interest for all packets or on a
per-flow basis
• …or roll your own
04-Jul-14 udhayprakash.blogspot.in
T i
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 39/48
Tracing• ns and nam trace file formats
– ns also supports show_tcphdr_ variable controlling display of TCPflags
• ns format
opop tsts prevhopprevhop nexthopnexthop typetype sizesize flagsflags flowidflowid srcsrc dstdst seqnoseqno pktidpktid
39
• Enque [+], dequeue [-], receive [r], drop [d]
• Types are
• Flags are – ECN-CE [E], -ECT [N], -CE [C], -CWR [A]; plus
– priority [P] and TCP fast start [F]
++ .. cpcp –––––––––––– .. ..
04-Jul-14 udhayprakash.blogspot.in
Vi li ti ( )
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 40/48
Visualization (nam)
set nf [open out.nam w]$ns namtrace-all $nf
Proc finish {} {
global ns nfclose $nf
exec nam out.nam &
exit 0
}
04-Jul-14 40udhayprakash.blogspot.in
T l C ti
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 41/48
Topology Creation
04-Jul-14 41udhayprakash.blogspot.in
S di D t
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 42/48
Sending Data
04-Jul-14 42udhayprakash.blogspot.in
Sending Data
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 43/48
Sending Data
04-Jul-14 43udhayprakash.blogspot.in
Creating TCP Connections
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 44/48
Creating TCP Connections
• Create TCP agent and attach it to the node set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
• Set null0 [new Agent/TCPSink]
$ns attach-agent $n1 $null0
• Connect the agents $ns connect $tcp0 $null0
04-Jul-14 44udhayprakash.blogspot.in
Traffic on top of TCP
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 45/48
Traffic on top of TCP
• FTP
– set ftp [new Application/FTP]
– $ftp attach-agent $tcp0
• Telnet
– Set telnet [new Application/Telnet]
– $telnet attach-agent $tcp0
04-Jul-14 45udhayprakash.blogspot.in
NS2 pre and post processing
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 46/48
NS2 pre- and post processing
• pre-processing: – traffic and topology generators
– NSG 2.1 (for more details, go to udhayprakash.blogspot.in )
– tclTutor
• post-processing:
– simple trace analysis, often in Awk, Perl, or Tcl.
– Awk scripting is preferred.
04-Jul-14 46udhayprakash.blogspot.in
Summary
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 47/48
Summary
• Simulators help in easy verification of protocols inless time, money.
• NS2 offers support for simulating a variety of
protocols suites and scenarios• Front end is oTCL, back end is C++
• NS2 is on-going effort of research and development.
04-Jul-14 47udhayprakash.blogspot.in
Reference
7/21/2019 Ns2 Network Simulator- Tutorial for Begineers
http://slidepdf.com/reader/full/ns2-network-simulator-tutorial-for-begineers 48/48
Reference
1) ns2 website: http://www.isi.edu/nsnam/ns2) Marc Greis' tutorial
3) Jae Chung tutorial
4) Ns manual
– . .6) Nsnam web pages – http://www.isi.edu/nsnam/
7) NS by example – http://nile.wpi.edu/NS/
8) Tutorial – Marc Greis's tutorial
9) Discrete-event simulation software – http://www.topology.org/soft/sim.html
10) Introduction to NS2(PPT), Prepared by Changyong Jung
04-Jul-14 48udhayprakash.blogspot.in