Subject: [manet] How to dump routing tables for manets in ns2?

From: Leon Martin <[email-masked]>
Date: Mon, 14 Feb 2005 14:19:01 -0800 (PST)

Hi,

I could not figure out how to dump the routing tables
for wireless ad hoc networks. The 
routing protocols I used are DSDV and AODV. I am using
ns2.27.

I serched the ns-nam mailing list and found this
problem had been asked as early as 
1998 but no solution has ever been provided.

Here is one reply in 1998:
(available at
http://mailman.isi.edu/pipermail/ns-users/1998-June/001292.html)
Two things that are not clearly documented are

	1.  dump-routes only works with dynamic routing, and
we 
		only currently have DV in there (if someone wants
		to donate their LS code, we'd shamelessly 
		purloin it...hint, hint :-)
	2.  dump-routes only works after you issue the ``$ns
run''
		command, because it is that command that sets up
		all the rtObject instances.

and another fresh message was posted on but no answer
has been given:
Does anyone know how to dump routing tables in
wireless simulations? Neither of the following works
in DSDV or AODV: 
$ns dump-routelogic-nh 
or 
set dr [$node rtObject?] 
$dr dump-routes 
$fh I'm using ns-2.27. 
(Available at
http://mailman.isi.edu/pipermail/ns-users/2004-July/043791.html)

In my case, I used two procedures to do the job. The
descriptions are as follows.

/////////////////////// procedure 1
//////////////////////////////

proc rtdump {} {
global ns_
    set now [$ns_ now] 
    puts "Routing table at time $now"
    $ns_ dump-routelogic-nh 
    $ns_ dump-routelogic-distance
}

And the dumping is executed by:

$ns_ at 20.0 "rtdump" 

In the OUTPUT, the place that is supposed to be for
the routing tables is empty, as shown below:

num_nodes is set 2
warning: Please use -channel as shown in
tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 550.0
SORTING LISTS ...DONE!
Routing table at time 20
Dumping Routing Table: Next Hop Information

NS EXITING...

/* Note the blank before NS EXITING... */

//////////////////// procedure 2
//////////////////////////////////////////
I then tried this procedure:

proc rtdump2 {node fh} {
global ns_
    set now [$ns_ now]
    puts "Routing table of node $node at time $now"
    set dr [$node rtObject?]
    $dr dump-routes $fh
}

The output gives an error message:

num_nodes is set 2
warning: Please use -channel as shown in
tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 550.0
SORTING LISTS ...DONE!
Routing table of node _o14 at time 30
ns: rtdump2 _o14 file4: invalid command name ""
    while executing
"$dr dump-routes $fh"
    (procedure "rtdump2" line 6)
    invoked from within
"rtdump2 _o14 file4"

//////////////////// procedures done
///////////////////////////////////////
The following is the ns Tcl script, modified from
tcl/ex/simple-wireless.tcl.

#
# 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

# ///////////// uncomment the line below for procedure
2  ///////////////
# set tracert [open tracert.tr w]

# set up topography object
set topo       [new Topography]

$topo load_flatgrid 500 500

#
# Create God
#
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			
			 
	for {set i 0} {$i < $val(nn) } {incr i} {
		set node_($i) [$ns_ node]	
		$node_($i) random-motion 0		;# disable random 
motion
	}

#
# 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

$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" 

# Setup traffic flow between nodes
# TCP connections between node_(0) and node_(1)

set tcp [new Agent/TCP]
$tcp set class_ 2
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" 

#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 150.0 "$node_($i) reset";
}

# /////////// comment the line below for procedure 2
////////////////
$ns_ at 20.0 "rtdump"

# ///////// uncomment the line below for procedure 2
///////////////
# $ns_ at 30.0 "rtdump2 $node_(0) $tracert"

$ns_ at 150.0 "stop"
$ns_ at 150.01 "puts \"NS EXITING...\" ; $ns_ halt"

proc rtdump {} {
global ns_
    set now [$ns_ now]
    puts "Routing table at time $now"
    $ns_ dump-routelogic-nh
    $ns_ dump-routelogic-distance 
}

proc rtdump2 {node fh} {
global ns_
    set now [$ns_ now]
    puts "Routing table of node $node at time $now"
    set dr [$node rtObject?]
    $dr dump-routes $fh
}

proc stop {} {
    global ns_ tracefd
    $ns_ flush-trace
    close $tracefd
}

puts "Starting Simulation..."
$ns_ run

Thanks in advance.

- Leon

__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage
less. 
http://info.mail.yahoo.com/mail_250

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

_______________________________________________
manet mailing list
[email-masked]
https://www1.ietf.org/mailman/listinfo/manet