Title: NS2 Tutorial
1NS-2 Tutorial
- Presented by
- Lap Kong Law
- lklaw_at_cs.ucr.edu
2Problem
- Impossible to carry real experiments
- Difficult to find a location
- Wireless experiments take huge space (in the
order of km). - Difficult to arrange experiments
- Hard to manage a large number of nodes.
- High equipment cost
- Feasibility study is costly
- The cost of implementing a real system to study
the feasibility is very high - Not flexible
- Difficult to change parameters
So, we use NS-2!
3Roadmap
- Introduction to NS-2
- Installation
- NS-2 Architecture
- Mobile Networking in NS-2
- Example simulation script
- Trace file Analysis
- Visualization
- Cautions
- Other Simulators
4Introduction to NS-2
- NS-2 stands for Network Simulator ver. 2
- Discrete event simulator
- Packet Level
- Link layer and up
- Provide substantial support on
- TCP, Routing, Multicast protocols on both wired
and wireless networks - Began in 1989 as a variant of the REAL network
simulator - In 1995, NS development was supported by DARPA in
VINT project - Supported and contributed by
- DARPA, NSF, ACIRI and many researchers
- Latest version 2.26
- Released on Feb 28, 2003
5Installation
- Download NS-2
- http//www.isi.edu/nsnam/ns/ns-build.html
- Recommend the all-in-one package
- Install NS-2
- ./configure make in OTcl TclCL directory
- ./configure make in ns directory
- ./validate
- Get an account with HUGE space available
6NS-2 Architecture
- Object-oriented (C, OTcl)
- Scalability Extensibility
- Data / Control Separation
- Split C / OTcl object
- C for data
- Define packet action
- OTcl for control
- Periodic or triggered action
- Each object defined in TCL script is an instance
of class written by C language
7Mobile Networking in NS-2
- MobileNode inherits from Node object
- MobileNode consists of
- Link Layer (LL)
- ARP module connected to LL
- Interface priority queue (IFq)
- MAC layer (MAC)
- Network Interface (netIF)
8Mobile Networking in NS-2
- Support four Ad-hoc Routing Protocols
- Destination Sequence Distance Vector (DSDV)
- Dynamic Source Routing (DSR)
- Temporally ordered Routing Algorithm (TORA)
- Adhoc On-demand Distance Vector (AODV)
- MAC layer protocols
- 802.11
- Preamble TDMA
- Radio Propagation Model
- Friss-space attenuation at near distance
- Two Ray Ground at far distance
- Antenna
- Omni-directional antenna
9Mobile Networking in NS-2
- Basic steps to do simulation
- Build your simulation script (.tcl)
- Create scenario
- Generating traffic pattern
- Run simulation
- Analyze trace file
- Visualize your simulation
10Example Simulation Script
11Example Scenario
- For large topologies, the node movement are
defined in a separated file for convenience (and
also for flexibility) - You can find some examples of node movement files
in the /tcl/mobility/scene/ directory - There is a generator (called setdest) for
creating node movement. It is located in the
/indep-utils/cmu-scen-gen/setdest/ directory - Usage of the setdest tool
- ./setdest n ltnum_of_nodegt -p ltpause_timegt
- -s ltmax_speedgt -t ltsim_timegt -x ltmax_xgt -y
ltmax_ygt - gt ltscenario_filegt
12Example Traffic pattern
- Similarly, traffic patterns are also defined in a
separated file. - Examples can be found in the /tcl/mobility/scene/
directory - Traffic generator is located in
/indep-utils/cmu-scen-gen/ and are called
cbrgen.tcl - Constant Bit Rate (CBR) or Transport Control
Protocol (TCP) - To create connections, run
- ns cbrgen.tcl -type cbrtcp -nn nodes
- -seed seed -mc connections -rate rate
- gt lttraffic pattern filegt
13Trace file Analysis
- Trace support for wireless simulations currently
use cmu-trace objects - Cmu-trace objects are of three types
- CMUTrace/Drop
- CMUTrace/Recv
- CMUTrace/Send
- Tracing packets sent by agents, routers, mac
layers or interface queues
14Trace file Analysis
- Revised trace format
- ns use-newtrace
- Example
s -t 0.267662078 -Hs 0 -Hd -1 -Ni 0 -Nx 5.00 -Ny
2.00 -Nz 0.00 -Ne -1.000000 -Nl RTR -Nw --- -Ma
0 -Md 0 -Ms 0 -Mt 0 -Is 0.255 -Id -1.255 It
message -Il 32 -If 0 -Ii 0 -Iv 32
Event type s ? send r ? receive d ? drop f ?
forward
Next hop info Hs ? id for this node Hd ? id for
next hop towards the dest.
- Packet info for MAC level
- Packet info for Application level
- Consists of field leading with P
- ARP
- TCP
- CBR
- DSR
Packet info at IP level Is ? source
address.port Id ? dest. Address.port It ? packet
type Il ? packet size If ? flow id Ii ? unique
id Iv ? TTL value
Node property Ni ? node id Nx ? nodes x
coordinate Ny ? nodes y coordinate Nz ? nodes z
coordinate Ne ? nodes energy level
15Visualization
- Nam stands for Network Animator
- It is a Tcl/TK based animation tools for viewing
network simulation traces - Produce the nam trace file
- set namtrace open opt(nam) w
- ns namtrace-all-wireless namtrace ltmax_xgt
ltmax_ygt
16Result Visualization
- Use Python!
- To extract the required information from the
trace file. - To produce output in particular formats that are
easier to plot. - GNUPlot
- Command-line driven program for producing 2D and
3D plots. - Generate beautiful plots.
- Matlab
- More advanced ploting functions.
- Various ploting libraries available for download.
17Cautions
- NS-2 is still under research and development
- Bugs in the software are still being discovered
and corrected - Users are responsible for verifying their
simulation results that may be invalidated by
bugs. - Similarly, users are responsible for verifying
that they are using the correct models in their
simulations.
18Other Simulators
- OPNET (http//www.opnet.com)
- Commercial Software
- Support Windows and Unix
- Graphical Interface
- Not free
- GloMoSim (http//pcl.cs.ucla.edu/projects/glomosim
) - Simulation environment for wireless network
- Scalable to support thousands of nodes
- Using layered approach to build different
simulation layers - Free for educational users