Running Wireless Simulations in NS
Creating a Mobile Node in NS
o A mobile node consists of a number of network components...
# Configure mobile nodes
$ns_ node-config -macType
-ifqLen

o

Mac/802_11
50



Node configuration API may consist of:
 d...
-ifqType

Queueing
method at the
interface

-ifqLen



Queue/DropTail/PriQueue

Queue size at
the interface



integer (...
All default values for these options are NULL except: addressingType: flat

Common values used in Wireless Simulation
o A ...
-macType $val(mac) 
-adhocRouting $val(rp) 
-agentTrace ON 
-routerTrace ON 
-macTrace OFF 
-movementTrace OFF 
-topoInsta...
o
o

o
o

o

Unlike wired (immobile) network simulation, the location of mobile
hosts are not known when the simulation is...
o
o

Simulated Scenario:
Simulation program:
# simple-wireless.tcl
# A simple example for wireless simulation
#
==========...
# ---------------------------------------------------------------# Create topography object to hold wireless scenario
set ...
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0
#
# Now produce some simple node movements
# Node_(1) s...
$ns_ run

o

Example Program: (Demo above code)
 Prog file: click here

Trace Information from Wireless Simulation
o Agen...
Upcoming SlideShare
Loading in …5
×

Running wireless simulations in ns

2,214 views

Published on

Ns2 simulation for wireless routing

Published in: Education, Technology, Business
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
2,214
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
224
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Running wireless simulations in ns

  1. 1. Running Wireless Simulations in NS Creating a Mobile Node in NS o A mobile node consists of a number of network components:  Link Layer (LL) - tell node how to check packet integrity  Interface Queue (IfQ) - buffer size  MAC layer - tell node how to share broadcast medium o NS supports different kinds of mobile network simulations; You MUST configure the mobile nodes before you can create them. o o Mobile nodes are configured using the command $ns node-config) followed by one or more (name, value) pairs The configuration API of mobile nodes looks as follows: set ns_ [new Simulator] # Configure mobile nodes $ns_ node-config OPTION1 VALUE1 [OPTION2 VALUE2]... o Example: create mobile nodes that uses IEEE 802.11 MAC protocol set ns_ [new Simulator] # Configure mobile nodes $ns_ node-config -macType o Mac/802_11 Example: create mobile nodes that uses IEEE 802.11 MAC protocol and with a buffer of 50 packets set ns_ [new Simulator]
  2. 2. # Configure mobile nodes $ns_ node-config -macType -ifqLen o Mac/802_11 50 Node configuration API may consist of:  defining the type of addressing (flat/hierarchical etc)  the type of adhoc routing protocol  Link Layer  MAC layer  IfQ  etc. Configuring Mobile Nodes o The following table contains the parameters and the most commonly used options (802.11 network) Option Name Usage How node addressingType addresses are organized Routing protocol used by nodes in an -adhocRouting Ad Hoc network (noninfrastructure) Option values    flat hierarchical expanded    DSDV DSR (Source Routing) TORA -llType Link Layer protocol  LL -macType MAC Layer protocol  Mac/802_11 -propType How radio wave propagate  Propagation/TwoRayGround
  3. 3. -ifqType Queueing method at the interface -ifqLen  Queue/DropTail/PriQueue Queue size at the interface  integer (e.g., 50) -phyType Type of physical layer  Phy/WirelessPhy -antType Type of antenna  Antenna/OmniAntenna -channelType Type of channel  Channel/WirelessChannel  Create a topology object: set topo [new Topography] Define the grid size: $topo load_flatgrid 500 500 Use the variable $topo as parameter for this option Description of the wireless -topoInstance network topology -agentTrace Flag to enable writing of trace data for agent module -routerTrace Flag to enable writing of trace data for wireless router module -macTrace Flag to enable writing of trace data for wireless MAC module Flag to enable writing of trace data for -movementTrace the movement of wireless nodes o NOTE:     ON OFF   ON OFF   ON OFF   ON OFF
  4. 4. All default values for these options are NULL except: addressingType: flat Common values used in Wireless Simulation o A very common way to keep option values in a single place is to used an associative array (the indices of the array are names instead of numbers) o Here are some commonly used values for wireless simulations: # =========================================================== =========== # Define options # =========================================================== =========== set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radiopropagation 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 o After storing the values in the associative array $val, we can set the options of wireless nodes as follows: # ================================================== # Configure nodes # ================================================== $ns_ node-config -channelType $val(chan) -propType $val(prop) -antType $val(ant) -llType $val(ll) -ifqType $val(ifq) -ifqLen $val(ifqlen) -phyType $val(netif)
  5. 5. -macType $val(mac) -adhocRouting $val(rp) -agentTrace ON -routerTrace ON -macTrace OFF -movementTrace OFF -topoInstance $topo  Don't worry about the variable $topo, we will cover that later. Topology o The wireless simulation needs to know the area in which the wireless nodes can travel... o For this purpose, NS has defined a Topology class to store information about the mobile hosts that move in a grid... o The create a Topology object, use: set VARNAME [new Topography] EXAMPLE: set topo [new Topography] o To provide the topography object with x and y co-ordinates of the boundary, use: $TOPO_VARNAME load_flatgrid X-SIZE EXAMPLE: $topo  load_flatgrid 500 500 Default granularity is 1 The General Operations Director (GOD) Object Y-SIZE [Granularity]
  6. 6. o o o o o Unlike wired (immobile) network simulation, the location of mobile hosts are not known when the simulation is in progress. In order to determine whether 2 mobile nodes can communicate with each other (i.e., whether they are within each others' range), NS needs to find out their locations. So NS must maintain some necessary information on ALL mobile hosts NS has defined a class to do so, and it is called "GOD" (General Operations Director) - the acronym "GOD" seems appropriate since this object knows information about every mobile hosts :-) Before you can create a mobile host, you MUST first create a "GOD" object, using the following command: create-god NUMBER-Of-Mobile-Nodes The parameter NUMBER-Of-Mobile-Nodes is the number of mobile hosts in the wireless simulation (you need to tell NS the amount of space to reserve) Some more information of the GOD class object:  o The GOD (General Operations Director) object is used to store global information about the state of the environment, network or nodes that an omniscent observer would have, but that should not be made known to any participant in the simulation. A GOD object stores the total number of mobile nodes and a table of shortest number of hops required to reach from one node to another. The next hop information is loaded into GOD object from movement pattern files, before simulation begins, since calculating this on the fly during simulation runs can be quite time consuming. o NOTE: Only ONE single global instance of the GOD object is to be created during an NS simulation !!! How to write a Wireless Simulation in NS o OK, we know enough to write a simple wireless simulation in NS
  7. 7. o o Simulated Scenario: Simulation program: # simple-wireless.tcl # A simple example for wireless simulation # =========================================================== =========== # Define options # =========================================================== =========== set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(ifq) Queue/DropTail/PriQueue ;# interface queue type set val(ll) LL ;# link layer type set val(ant) Antenna/OmniAntenna ;# antenna model set val(ifqlen) 50 ;# max packet in ifq set val(nn) 2 ;# number of mobilenodes set val(rp) DSDV ;# routing protocol # =========================================================== =========== # Main Program # =========================================================== =========== # # Initialize Global Variables # set ns_ [new Simulator] set tracefd [open simple.tr w] $ns_ trace-all $tracefd # ---------------------------------------------------------------# Set up wireless network simulation
  8. 8. # ---------------------------------------------------------------# Create topography object to hold wireless scenario set topo [new Topography] $topo load_flatgrid 500 500 500x500 ;# Grid size is # # Create god object # create-god $val(nn) # # Create the specified number of mobilenodes [$val(nn)] and "attach" them # to the channel. # Here two nodes are created : node(0) and node(1) # configure node $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) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace OFF -movementTrace OFF # -------------------------------------------------------# Direct mobile node's movements # -------------------------------------------------------for {set i 0} {$i< $val(nn) } {incri} { set node_($i) [$ns_ node] $node_($i) random-motion 0 random motion } ;# disable # # Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes # $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $node_(0) set Z_ 0.0
  9. 9. $node_(1) set X_ 390.0 $node_(1) set Y_ 385.0 $node_(1) set Z_ 0.0 # # Now produce some simple node movements # 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" # -------------------------------------------------------------# The rest is "ordinary" network connection setup # -------------------------------------------------------------# Setup TCP connections between node_(0) and node_(1) set tcp [new Agent/TCP] $ns_ attach-agent $node_(0) $tcp $tcp set class_ 2 set sink [new Agent/TCPSink] $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink # Setup FTP flow for TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ns_ at 10.0 "$ftp start" # # Tell nodes when the simulation ends # for {set i 0} {$i< $val(nn) } {incri} { $ns_ at 150.0 "$node_($i) reset"; } $ns_ at 150.0 "stop" $ns_ at 150.01 "puts "NS EXITING..." ; $ns_ halt" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..."
  10. 10. $ns_ run o Example Program: (Demo above code)  Prog file: click here Trace Information from Wireless Simulation o AgentTraces are marked with AGT in the 5th field o RouterTrace are marked with RTR in the 5th field o MacTrace are marked with MAC in the 5th fields. o MovementTrace (shows the movement of the mobile nodes) are marked with M in the 2nd field. References o Marc Greis' NS Tutorial Chapter IX. Running Wireless Simulations in ns - click here

×