How to use DSR routing protocol in ns2


The reactive on demand routing protocols establish the route to a particular destination only if it is needed. Dynamic Source Routing (DSR) is one of the commonly used reactive on demand routing protocols in mobile ad hoc network (MANET). DSR is a loop-free, source based, on-demand routing protocol in which each node maintains a route cache consisting of source routes known by the node. A source node initiates a fresh route discovery process only if it does not already have a valid route to the destination in its route cache. The entries in the route cache are regularly updated as new routes are known. The sample16.tcl shows a node configuration for a wireless mobile node that runs DSR as its adhoc routing protocol. Prior to the establishment of communication between the source and receiver node, the routing protocol should be mentioned to find the route between them. Data Transmission is established between nodes using UDP agent and CBR traffic.

#Filename: sample16.tcl #***************DSR ROUTING PROTOCOL***************************# # Simulator Instance Creation set ns [new Simulator] #Fixing the co-ordinate of simutaion area set val(x) 500 set val(y) 500 # 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) CMUPriQueue ;# 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) 10 ;# number of mobilenodes set val(rp) DSR ;# routing protocol set val(x) 500 ;# X dimension of topography set val(y) 500 ;# Y dimension of topography set val(stop) 10.0 ;# time of simulation end # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # general operational descriptor- storing the hop details in the network create-god $val(nn) # configure the 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) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON # Node Creation for {set i 0} {$i < 3} {incr i} { set node_($i) [$ns node] $node_($i) color black } for {set i 0} {$i < 3} {incr i} { $node_($i) set X_ [expr rand()*$val(x)] $node_($i) set Y_ [expr rand()*$val(y)] $node_($i) set Z_ 0 } Defining Communication between node0 and all nodes **************************** for {set i 1} {$i < 3} {incr i} { # Defining a transport agent for sending set udp [new Agent/UDP] # Attaching transport agent to sender node $ns attach-agent $node_($i) $udp # Defining a transport agent for receiving set null [new Agent/Null] # Attaching transport agent to receiver node $ns attach-agent $node_(0) $null #Connecting sending and receiving transport agents $ns connect $udp $null #Defining Application instance set cbr [new Application/Traffic/CBR] # Attaching transport agent to application agent $cbr attach-agent $udp #Packet size in bytes and interval in seconds definition $cbr set packetSize_ 512 $cbr set interval_ 0.1 # data packet generation starting time $ns at 1.0 "$cbr start" # data packet generation ending time #$ns at 6.0 "$cbr stop" }