Dear all,

I would appreciate if somebody could help me with this issue. I figured out
how to employ manual routing in ns2.
However I noticed if I change/add route manually during the simulation to a
specific node it makes its node to stop forwarding packets.

In simple words: it seems that ns2 does not accept on-the-fly changes on the
routing table when manually inserted. Is this true?

For example, in my simulation I start a FTP transfer that should end at
10s.  However, at 5s I add a new route to a node, and then it simply
"crashes" this node -- and the simulation stops at 4.99904 instead of 10s.

For simplicity, I will put here part of the code that  I'm having problem
(and in the end of the message the full code) -- it may be useful for those
who also need to do manual routing.

#...continuation of script

#procedure invoked to add a new route -- that is, extra routes
proc addroute {} {
    global ns n4 n5 n3 n2 n1 n0
    #syntax:
    # origin node -- add-route -- dst node -- head of the link to be used
    [$n1 get-module "Manual"] add-route [$n3 set address_] [[$ns link $n1
$n4] head]
    [$n1 get-module "Manual"] add-route [$n5 set address_] [[$ns link $n1
$n4] head]
    exit 0
}

#data starts - assume that there is a ftp transfer
$ns at 0.5 "$ftp start"

#addroute invoked -- the simulation than stops at 4.99904 instead of going
until 10s.
$ns at 5.0 "addroute"

#simmulation should stop at 10s.
$ns at 10 "$ftp stop"
$ns at 10.0 "finish"

$ns run
#end of script

Does anybody knows why it crashes? or how can I make a on-the-fly change on
the routing table? Is there any workaround to allows to add new routes on
the fly on ns2?

Thank you so much,

Giovane

ps: full script goes below

#beginning of the full script
#Create a simulator object
set ns [new Simulator]

# enable manual routing
$ns rtproto Manual

#Open the nam trace file
set nf [open clean.tr w]
$ns trace-all $nf
set f [open clean.nam w]
$ns namtrace-all $f

proc finish {} {
        global ns nf  f
        $ns flush-trace
        close $nf
    #close trace file
    close $f
        exit 0
}

#Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

# Topology:
#
#
#            /------N2-------\
# N0---N1                N3---N5
#            \-----N4-------/
#
# where N0 is the source of ftp data, N5 should receive
# In the first moment, the upper path(N0-N1-N2-N3-N5) will be choosen (that
is, added to the route table of nodes)
# After, I will change N1 table to reach N3 and N5 via N4, ignoring N2, then
using the lower path.

#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n5 1Mb 10ms DropTail
$ns duplex-link $n1 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n3 1Mb 10ms DropTail

#tcp agent linux -- supports only ns2.33
#n0 - source
#n5 - sink
set tcp [new Agent/TCP/Linux]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
$tcp set fid_ 1

#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP

#routes setup

#node 0 route table
[$n0 get-module "Manual"] add-route-to-adj-node -default $n1

#node 1 route table
#syntax:
#origin node -- add-route -- dst node -- head of the link to be used
[$n1 get-module "Manual"] add-route [$n2 set address_] [[$ns link $n1 $n2]
head]
[$n1 get-module "Manual"] add-route [$n0 set address_] [[$ns link $n1 $n0]
head]
[$n1 get-module "Manual"] add-route [$n4 set address_] [[$ns link $n1 $n4]
head]
[$n1 get-module "Manual"] add-route [$n3 set address_] [[$ns link $n1 $n2]
head]
[$n1 get-module "Manual"] add-route [$n5 set address_] [[$ns link $n1 $n2]
head]

#node 2 route table
[$n2 get-module "Manual"] add-route [$n1 set address_] [[$ns link $n2 $n1]
head]
[$n2 get-module "Manual"] add-route [$n3 set address_] [[$ns link $n2 $n3]
head]
[$n2 get-module "Manual"] add-route [$n5 set address_] [[$ns link $n2 $n3]
head]
[$n2 get-module "Manual"] add-route [$n0 set address_] [[$ns link $n2 $n1]
head]

#node 3 route table
[$n3 get-module "Manual"] add-route [$n2 set address_] [[$ns link $n3 $n2]
head]
[$n3 get-module "Manual"] add-route [$n5 set address_] [[$ns link $n3 $n5]
head]
[$n3 get-module "Manual"] add-route [$n1 set address_] [[$ns link $n3 $n2]
head]
[$n3 get-module "Manual"] add-route [$n4 set address_] [[$ns link $n3 $n4]
head]
[$n3 get-module "Manual"] add-route [$n0 set address_] [[$ns link $n3 $n2]
head]

#node 4 route table
[$n4 get-module "Manual"] add-route [$n3 set address_] [[$ns link $n4 $n3]
head]
[$n4 get-module "Manual"] add-route [$n5 set address_] [[$ns link $n4 $n3]
head]
[$n4 get-module "Manual"] add-route [$n1 set address_] [[$ns link $n4 $n1]
head]
[$n4 get-module "Manual"] add-route [$n1 set address_] [[$ns link $n4 $n1]
head]

#node 5 route table
[$n5 get-module "Manual"] add-route-to-adj-node -default $n3


proc addroute {} {
    global ns n4 n5 n3 n2 n1 n0
    [$n1 get-module "Manual"] add-route [$n3 set address_] [[$ns link $n1
$n4] head]
    [$n1 get-module "Manual"] add-route [$n5 set address_] [[$ns link $n1
$n4] head]
    exit 0
}
$ns at 0.5 "$ftp start"
$ns at 5.0 "addroute"
$ns at 10.0 "$ftp stop"
$ns at 10.0 "finish"
$ns run

Reply via email to