3. 3
Outline
Introduction
NS-2 : Components
Installation of ns2
Implementation of Wireless Sensor Network
Design and develop code for mobility in DTN
Schedule
References
4. 4
NS2 –Network Simulator
ns-2 is a discrete event network simulator for wired and wireless networks alike
It is popular for its extensibility (due to its open source model)
Supports an array of popular network protocols
Popularly used in the simulation of routing and multicast protocols, and is heavily used in ad-hoc research
ns-2 is written in C++ and OTcl
OTcl = Tcl + OO
C++ implements the code that executed frequently
OTcl configures the system
5. 5
NS-2 : Components
NS – Simulator
NAM – Network AniMator
visual demonstration of NS output
Preprocessing
Handwritten TCL or
Traffic and topology generators
Post analysis
Trace analysis using :
Perl/TCL/AWK/MATLAB
ProblemsSimulate the environmentRun with ns-2Analysis the resultFinishModifyNoFinish the simulationYes
6. 6
Basic Requirements: NS-2
A computer which is having access to the Internet
Minimum 512Mb RAM
Operating system: Linux(Ubuntu 12.04)
ns-2.34 package(ns-allinone)
gcc-4.4.3
7. Installation
Download NS-allinone-2.34 package
http://www.isi.edu/nsnam/ns/
for easy installation, download ns-allinone
includes Tcl, Otcl, TclCL, ns, nam, etc.
Works on Unix and cygwin for windows 9x/2000/xp.
After successful downloading and unzipping install allinone package , install NS by
install by calling ~/ns-allinone-2.34/install
After successful installation , Validate the scripts by running ./validate in ~/ns-allinone-2.34/ns-2.34/
Its now all set to work with NS
7
8. 8
Steps to set up the simulation for wireless script
Mobile node at core of mobility model
Mobile nodes can move in a given topology, receive/transmit signals from/to wireless channels
Scenario : Simple 2 Nodes Simulation
Simulate a very simple 2-node wireless scenario
The topology consists of two mobile nodes
The mobile nodes move about within 500mX500m area
A TCP connection is setup between the two
Mobile nodes.
Packets are exchanged between the nodes as they come within hearing range of one another.
9. 9
Setting Up Variables
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ll) LL ;# Link layer type
set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type
set val(ifqlen) 50 ;# max packet in ifq
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(rp) DSDV ;# ad-hoc routing protocol
set val(nn) 2 ;# number of mobilenodes
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
11. 11
God (General Operations Director) Object
.
.
Create God object:
create-god $val(nn) God object stores:
number of mobile nodes
table of shortest number of hops required to reach from one node to another
Stores smallest number of hops from one node to another
Optimal case to compare routing protocol performance
12. 12
Simple Configuration For Wireless 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
13. 13
Configuring Movement
Create two nodes
Provide initial (X,Y, for now Z=0) co-ordinates
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node ]
$node_($i) random-motion 0 ;# disable random motion
}
$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
14. 14
Produce some node movements
Explanation:
#Node_(1) starts to move towards node_(0)
$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0"
$ns_ at 10.0 "$node_(0) setdest 20.0 18.0 1.0”
#Node_(1) then starts to move away from node_(0)
$ns_ at 100.0 "$node_(1) setdest 490.0 480.0 15.0“
$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0" means at time 50.0s, node1 starts to move towards the destination (x=25,y=20) at a speed of 15m/s.
15. 15
Setup traffic flow
TCP connections between node_(0) and node_(1)
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp
$ns_ attach-agent $node_(1) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 10.0 "$ftp start"
16. 16
Set Stop Time and Start Simulation
Tell nodes when the simulation ends
Finally, Start The Simulation
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 150.0 "$node_($i) reset";
}
$ns_ at 150.0001 "stop"
$ns_ at 150.0002 "puts "NS EXITING...“ ; $ns_ halt"
proc stop {} {
global ns_ tracefd
close $tracefd
}
puts "Starting Simulation..."
$ns_ run
17. 17
Running the Script
The file “simple-wireless.tcl” is under <root>/ns- allinone2.34/ns-2.34/simple-wireless.tcl
cd into the directory and type “ns simple-wireless.tcl” to run the simulation
The simulation will generate a trace file named “simple.tr”
18. 18
Schedule
Phase 1
Literature Review and Forming Objective
Phase 2
Implementation
Phase 3
Testing and Analysis
Phase 4
Report Writing
19. 19
References
http://www.isi.edu/nsnam/ns
Tutorials
Marc Greis’s Tutorial (http://www.isi.edu/nsnam/ns/tutorial/index.html)
Ns by example (http://nile.wpi.edu/NS/)
Wireless Tutorial (http://www.isi.edu/nsnam/ns/ns- tutorial/wireless.ppt )
Doc:
ns by Example
http://nile.wpi.edu/NS/
NS Manual:
http://www.isi.edu/nsnam/ns/doc/index.html
Workshop and presentations
http://www.isi.edu/nsnam/ns/ns-tutorial/index.html