Professional Documents
Culture Documents
Chapter - 7 Network Simulator
Chapter - 7 Network Simulator
1
Documentation
Introductory: Marc Greis’s tutorial
reference: Ns Manual (formerly called "ns Notes
and Documentation")
ns by Example
Practical Programming in Tcl and Tk
(http: //www.beedub.com/book/)
http://hpds.ee.ncku.edu.tw/~smallko/
ns2/ns2.htm
2
Useful links
ns-2 manual
http://www.isi.edu/nsnam/ns/ns-documentation.html
3
Introduction
Methods for network research
Analytical
•Mathematical model
Emulation
•Real code
•Duplicates the functions of one system with a different system
Simulation
•Abstract model
•Behavior of system
4
Introduction…
Simulation frameworks
Commercial
•OPNET
•QualNet
•OMNEST (commercial version of OMNetT++)
Free
•NS-2 (network simulator version 2)
•OMNetT++
5
Installation
Platform
Unix
Windows (cygwin)
Packages
Tcl/tk
Otcl tclcl
Ns-2
Nam
Xgraph
C++ compiler
Ns AllInOne package
6
Installation…
Cygwin, AllInOne installation (windows)
http://140.116.72.80/~smallko/ns2/setup_en.htm
Installation problems
http://www.isis.edu/nsnam/ns/ns-problems.html#general
Cygwin setup
Gcc and g++
Ns-2 setup
Path setting
Cygwin/home/user-name/.bashrc
Testing (startxwin.bat) - ~/ns-allinone-x.x/ns-x.x/ns-tutorial/examples
7
Platforms supported
Most UNIX and UNIX-like systems
FreeBSD
Linux
Solaris
Windows 98/2000/2003/XP/7/10
Cygwin required
8
NS-goals
Support networking research and education
Protocols design and comparison
Provide collaborative environment
Free distributed, open source
ns-users@isi.edu
9
Preliminary for NS-2
Ability to write correct programs
Familiarity with object-oriented programming
Patience to debug NS source code when needed
Simple usage will not need NS source code debugging
More complex simulations may need modification to
NS source code
Debugging skills
NS uses C++ and Otcl
User scripts are in Otcl
10
Network simulator (ns-2)
Ns-2 is a discrete event simulator
Change of state happens only in discrete point of time
Advance of time depends on the timing of events
Events
Basic component that changes a system state
Packet arrival/departure, time-out events
Event handlers
Process events
Agents, Nodes, Links in NS-2 are event handlers.
Object-oriented simulator
C++ : fast to run, slower to change – protocol implementation
Otcl : slower to run, fast to change – simulation configuration
11
Basic Mechanisms of Event Handlers
If there exists an event to process
Call process (event)
During the processing, the event is held for a certain
duration.
Agents in NS-2 does this.
12
Discrete event simulator
Ns-2 is a discrete event driven simulator
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
13
Simulation Network using ns-2
Wired Network
Point-to-point link, LAN
Routing: Distance Vector (Bellman-ford), Link State (Dijikistra)
Transportation: TCP and UDP
Queuing disciplines: drop-tail, RED, FQ, SFQ, DRR, RR
Traffic characterizations - Poisson, Exponential, Pareto etc.
QoS: IntServ and DiffServ
Different mobility model
Wireless Network
Ad-hoc routing and mobile IP: AODV, DSR,…
Sensor-MAC, WiMAX , Wi-Fi…
Satellite network
Power control in wireless networks
Tracing, Visualization, Analysis, Other utilities
14
Simulation Network using ns-2…
17
NS-2 : Components…
Pre-processing
•Traffic and topology model
Post-processing
•Trace analysis, often in awk, perl, or tcl
Simulation procedure
Define Simulation
problem model
Extend
simulator
Post-process Execute
results simulation
18
User’s view of NS-2
19
Architectural View of NS-2
Event ns-2
Scheduler
Component
tclcl
Network
otcl
tcl8.0
otcl: Object-oriented support
tclcl: C++ and otcl linkage
Discrete event scheduler
Data network components
20
NS-2 : C++ / OTCL
NS-2 Code contains two sets of languages,
namely C++ and OTcl.
21
Why two languages? (Tcl & C++)
C++: Detailed protocol simulations require
systems programming language
byte manipulation, packet processing, algorithm
implementation
Fast to run, detailed, slow to modify
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
Simulation scenario configurations
Manipulating existing C++ objects
fast to write and change
iteration time (change the model and re-run) is more
important 22
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
+ running vs. writing speed
– Learning and debugging (two languages)
23
OTcl-C++ linkage
C++
C++/OTcl
split
objects
otcl
Agent Agent()
Agent/DSDV DSDVAgent()
sim
27
NS Models
Traffic models and applications:
Web, FTP, telnet, constant-bit rate (CBR), real audio
Transport protocols:
unicast: TCP (Reno, Vegas, etc.), UDP
Multicast:
Routing and queuing:
Wired routing, ad hoc rtg and directed diffusion
queueing protocols: RED, drop-tail, etc
Physical media:
Wired (point-to-point, LANs), wireless (multiple
propagation models), satellite
28
Design your simulation
Goal and expected results
Network topology
Node
Link
Specify Agents
Protocol
Traffic
Simulation Scenario
29
Network Topology - Node
n0 n1
multiclassifier_
30
Network Topology - Link
n0 n1
n1
head_ entry_
enqT_ queue_ deqT_ link_ ttl_
drophead_ drpT_
31
Network Topology - Routing
n0 n1
Port
Classifier
Addr
Classifier
Node entry n1
0 dmux_ head_ entry
enqT_ queue_ deqT_ link_ ttl_ _
entry_ 1
classifier_ drophead_ drpT_
32
Network Topology – Routing…
n0 n1
Port Port
Classifier Classifier
Addr Addr
Classifier Classifier
0 dmux_ 1 dmux_
Link n0-n1
entry_ 1 entry_ 0
classifier_ classifier_
Link n1-n0
33
Network Topology - Transport
n0 n1
Port Port
Classifier dst_=1.0 Classifier dst_=0.0
Addr Agent/TCP Addr Agent/TCPSink
Classifier
0 Classifier
0
agents_ agents_
0 dmux_ 1 dmux_
Link n0-n1
entry_ 1 entry_ 0
classifier_ classifier_
Link n1-n0
34
Network Topology - Application
n0 n1
Link n1-n0
35
Packet Flow
n0 n1
Link n1-n0
36
NS programming
Create the event scheduler
Turn on tracing
Create network
Setup routing
Insert errors
Create transport connection
Create traffic
Transmit application-level data
37
TCL script
TCL script for scenario setup
Scenario script format
Simulator object
Trace file
Finish procedure
Network setup (node, link, agent, parameter…)
Other procedure, if any
Event scheduling (run simulation, stop simulation …)
38
A TCL script example
n0 n1
40
TCL Script Step 1
41
TCL Script Step 2
42
TCL Script Step 3
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
44
TCL Script Step 5
45
TCL Script Step 6
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
#Run the simulation
$ns run
46
Run simulation program
Usage: ns file.tcl
If the C++ source codes are modified, re-
compilation is required
47
Analyze trace file
Use some scripts like awk or Perl, to filter
the trace file
48
Trace file
49
Plot results in MATLAB, Excel
50
8
Matlab scalar 2D plots
7
50
5
40
4
30
3
20
10 2
8
6 8
4 6 1
4 1 2 3 4 5 6 7
2 2
0 0
1
50
2
40
3
30
4
20
5
10
8 6
6 8
4 6
4 7
2 2
0 0
8
51
1 2 3 4 5 6 7
Simple Simulation using NAM
52
Ns-2 for Wireless and Mobile
networks
53
Wireless and mobile network
simulation in ns-2
Contributed from CMU’s Monarch project
(Wireless extension to ns-2)
Various modules were added to ns-2 to simulate
node mobility and wireless networking
Mobile Node
Ad-hoc Routing(DSR, DSDV, TORA, AODV)
MAC 802.11
Radio Propagation Model
Channel
54
Wireless and Mobile networks
Internals
Mobile node
Basic node that has address and port de-muxes,
routing agent etc
Stack of network components consisting of LL,
MAC, NetIF, radio-model etc
Wireless channel
55
Representation of A Mobile Node
port
Node classifier
protocol
agent Classifier:
Forwarding
255
Agent: Protocol
routing
addr
classifier defaulttarge agent
Entity
t_ Node Entry
LL ARP
LL LL: Link layer object
IFQ
IFQ IFQ: Interface queue
MAC
Propagation
MAC MAC: Mac object
PHY and antenna
models
MobileNode
PHY PHY: Net interface
CHANNEL
Prop/ant Radio propagation/
56
antenna models
Mobile Node Components
Agent
Responsible for packet generations and receptions
Can think of it as an application and transport layers
CBR(Constant Bit Rate), TCP, Sink, UDP, FTP, etc.
Rtagent (DSDV, AODV …)
Ad-hoc network routing protocols
Configure multi-hop routes for packets
LL (Link Layer)
Runs data link protocols
Fragmentation and reassembly of packet
Runs Address Resolution Protocol(ARP) to resolve IP
address to MAC address conversions
57
Mobile Node Components…
Classifiers
• defaulttarget_ points to routing agent object
• 255 is the port id assigned for rtagent_
ARP
• Resolves IP address to hardware (MAC) address
• Broadcasts ARP query
IFq (Interface Queue)
PriQueue is implemented to give priority to routing protocol
packets
Supports filter to remove packets destined to specific address
58
Mobile Node: Components
MAC Layer
802.11
•IEEE RTS/CTS/DATA/ACK for unicast
•Sends DATA directly for broadcast
NetIF (Network Interfaces)
Hardware interface used by mobile node to access the channel
Simulates signal integrity, collision, tx error
Mark each transmitted packet with transmission power,
wavelength etc.
Radio Propagation Model
Friss-space model – attenuation at near distance
Two-ray ground reflection model for far distance
Shadowing model -probabilistic
Antenna
Implements Omni Directional Antenna module which has
unity gain for all direction
59
Wireless Simulation in ns-2 (Mobile Node
Diagram - DSDV)
Agent
(Src/Sink)
Demux
Port
Demux
Addr
RTagent
(DSDV)
LL ARP
IFq
MAC
Radio
Propagation NetIF
Model
Channel
60
Running a simulation-Scenario
500m
61
Setting Up Variables
62
Setting Up Variables…
#Instantiate simulator object
63
GOD
(General Operations Director)
Stores smallest number of hops from one node
to another
Optimal case to compare routing protocol
performance
Automatically generated by scenario file
set god [create-god <no of mnodes>]
$god set-dist <from> <to> <#hops>
64
Configuring Mobile nodes
# Configure nodes
$ns_ node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-channelType $val(chan) \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node ]
65
$node_($i) random-motion 0 ;# disable random motion }
Configuring nodes’ movement
#Configure Initial location of mobile nodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0
FTP
TCP Sink
node_(0) node_(1) 67
Set Stop Time and Start Simulation
#Set Simulation Stop Time
69