[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] black hole simulation



hi ,
I'm a student of Roma3 university. i'm doing a black hole simulation
using ns-2/nam. I succeded to implement a net that use a distance vector
protocol but I have some problem:
1)how cam visualize in nam the routing table of each router? which is
the ns-2 line that i have to write?
2)at a time t1 a router of my net (r12) has to send to the other router
a distance vector (false) that tell them that there is a route that have
cost=0 to reach a destination that not have a link with r(12).Infact, if
there is a tcp connection between two host r(12), sending false dv has
to change routing table to each router taking the packet that are not
directed to it. which are the ns-2 line that i haves to write?
3)at a time t2 a r(12) begin to send the "true" dv to the ather router
(black hole finished). i have to implement a timer that calcoulate the
time passed by the last packet received by the real destination and the
first packet that the real destination receive after the and of black
hole.which are the ns-2 lines that i have to write?
I know that the problem is not simple but i not have succeded to do it.
could you help me please.
you are my last hope.
thank you very much.
p.s.: in the attach there are the lines of my simulation


# Preamble
set ns [new Simulator]

# Tell the simulator to use dynamic routing
$ns rtproto DV 
Agent/rtProto/DV set advertInterval 1.0
Agent/rtProto/DV set INFINITY 100

# Set ns color indices
$ns color 0 blue
$ns color 1 black
$ns color 2 turquoise
$ns color 3 orange
$ns color 4 gold
$ns color 5 red


# Open trace files
set f [open SIM.tr w]
$ns trace-all $f
set nf [open SIM.nam w]
$ns namtrace-all $nf


proc finish {} {
    global ns f nf
    $ns flush-trace
    close $nf
    close $f
    puts "running nam"   
    exit 0
}


# Create 13 routers
for {set i 0} {$i < 13} {incr i} {
        set r($i) [$ns node]
}

# Create 30 pc
for {set i 13} {$i < 43} {incr i} {
        set pc($i) [$ns node]
}

for {set i 0} {$i < 13} {incr i} {
        $r($i) shape hexagon
	  $r($i) color green
}

for {set i 13} {$i < 43} {incr i} {
	  $pc($i) color blue
}





# Create duplex links
$ns duplex-link $r(0) $pc(13)  1Mb 50ms DropTail
$ns duplex-link $r(0) $pc(14)  1Mb 50ms DropTail
$ns duplex-link $r(0) $pc(15)  1Mb 50ms DropTail
$ns duplex-link $r(0) $r(1)    2Mb 50ms DropTail
$ns duplex-link $r(0) $r(5)    2Mb 50ms DropTail
$ns duplex-link $r(1) $pc(16)  1Mb 50ms DropTail
$ns duplex-link $r(1) $pc(17)  1Mb 50ms DropTail
$ns duplex-link $r(1) $pc(18)  1Mb 50ms DropTail
$ns duplex-link $r(1) $r(2)    2Mb 50ms DropTail
$ns duplex-link $r(1) $r(6)   10Mb 50ms DropTail
$ns duplex-link $r(2) $pc(19)  1Mb 50ms DropTail
$ns duplex-link $r(2) $pc(20)  1Mb 50ms DropTail
$ns duplex-link $r(2) $pc(21)  1Mb 50ms DropTail
$ns duplex-link $r(2) $r(3)    2Mb 50ms DropTail
$ns duplex-link $r(2) $r(7)   10Mb 50ms DropTail
$ns duplex-link $r(3) $pc(22)  1Mb 50ms DropTail
$ns duplex-link $r(3) $pc(23)  1Mb 50ms DropTail
$ns duplex-link $r(3) $pc(24)  1Mb 50ms DropTail
$ns duplex-link $r(3) $r(4)    2Mb 50ms DropTail
$ns duplex-link $r(3) $r(8)   10Mb 50ms DropTail
$ns duplex-link $r(4) $pc(25)  1Mb 50ms DropTail
$ns duplex-link $r(4) $pc(26)  1Mb 50ms DropTail
$ns duplex-link $r(4) $pc(27)  1Mb 50ms DropTail
$ns duplex-link $r(4) $r(9)    2Mb 50ms DropTail
$ns duplex-link $r(5) $pc(28)  1Mb 50ms DropTail
$ns duplex-link $r(5) $pc(29)  1Mb 50ms DropTail
$ns duplex-link $r(5) $pc(30)  1Mb 50ms DropTail
$ns duplex-link $r(5) $r(6)   10Mb 50ms DropTail
$ns duplex-link $r(6) $r(7)   10Mb 50ms DropTail
$ns duplex-link $r(6) $r(10)  10Mb 50ms DropTail
$ns duplex-link $r(7) $r(8)   10Mb 50ms DropTail
$ns duplex-link $r(7) $r(11)  10Mb 50ms DropTail
$ns duplex-link $r(8) $r(9)   10Mb 50ms DropTail
$ns duplex-link $r(8) $r(12)  10Mb 50ms DropTail
$ns duplex-link $r(9) $pc(31)  1Mb 50ms DropTail
$ns duplex-link $r(9) $pc(32)  1Mb 50ms DropTail
$ns duplex-link $r(9) $pc(33)  1Mb 50ms DropTail
$ns duplex-link $r(10) $r(11)  2Mb 50ms DropTail
$ns duplex-link $r(10) $pc(34) 1Mb 50ms DropTail
$ns duplex-link $r(10) $pc(35) 1Mb 50ms DropTail
$ns duplex-link $r(10) $pc(36) 1Mb 50ms DropTail
$ns duplex-link $r(11) $r(12)  2Mb 50ms DropTail
$ns duplex-link $r(11) $pc(37) 1Mb 50ms DropTail
$ns duplex-link $r(11) $pc(38) 1Mb 50ms DropTail
$ns duplex-link $r(11) $pc(39) 1Mb 50ms DropTail
$ns duplex-link $r(12) $pc(40) 1Mb 50ms DropTail
$ns duplex-link $r(12) $pc(41) 1Mb 50ms DropTail
$ns duplex-link $r(12) $pc(42) 1Mb 50ms DropTail



# Orient the nodes 
$ns duplex-link-op $r(0)  $pc(13)  orient 165deg
$ns duplex-link-op $r(0)  $pc(14)  orient 180deg
$ns duplex-link-op $r(0)  $pc(15)  orient 195deg
$ns duplex-link-op $r(0)  $r(1)    orient 0deg
$ns duplex-link-op $r(0)  $r(5)    orient 270deg
$ns duplex-link-op $r(1)  $pc(16)  orient 105deg
$ns duplex-link-op $r(1)  $pc(17)  orient 90deg
$ns duplex-link-op $r(1)  $pc(18)  orient 75deg
$ns duplex-link-op $r(1)  $r(2)    orient 0deg
$ns duplex-link-op $r(1)  $r(6)    orient 270deg
$ns duplex-link-op $r(2)  $pc(19)  orient 105deg
$ns duplex-link-op $r(2)  $pc(20)  orient 90deg
$ns duplex-link-op $r(2)  $pc(21)  orient 75deg
$ns duplex-link-op $r(2)  $r(3)    orient 0deg
$ns duplex-link-op $r(2)  $r(7)    orient 270deg
$ns duplex-link-op $r(3)  $pc(22)  orient 105deg
$ns duplex-link-op $r(3)  $pc(23)  orient 90deg
$ns duplex-link-op $r(3)  $pc(24)  orient 75deg
$ns duplex-link-op $r(3)  $r(4)    orient 0deg
$ns duplex-link-op $r(3)  $r(8)    orient 270deg
$ns duplex-link-op $r(4)  $pc(25)  orient 15deg
$ns duplex-link-op $r(4)  $pc(26)  orient 0deg
$ns duplex-link-op $r(4)  $pc(27)  orient 345deg
$ns duplex-link-op $r(4)  $r(9)    orient 270deg
$ns duplex-link-op $r(5)  $pc(28)  orient 165deg
$ns duplex-link-op $r(5)  $pc(29)  orient 180deg
$ns duplex-link-op $r(5)  $pc(30)  orient 195deg
$ns duplex-link-op $r(5)  $r(6)    orient 0deg
$ns duplex-link-op $r(6)  $r(7)    orient 0deg
$ns duplex-link-op $r(6)  $r(10)   orient 270deg
$ns duplex-link-op $r(7)  $r(8)    orient 0deg
$ns duplex-link-op $r(7)  $r(11)   orient 270deg
$ns duplex-link-op $r(8)  $r(9)    orient 0deg
$ns duplex-link-op $r(8)  $r(12)   orient 270deg
$ns duplex-link-op $r(9)  $pc(31)  orient 15deg
$ns duplex-link-op $r(9)  $pc(32)  orient 0deg
$ns duplex-link-op $r(9)  $pc(33)  orient 345deg
$ns duplex-link-op $r(10) $r(11)  orient 0deg
$ns duplex-link-op $r(10) $pc(34) orient 255deg
$ns duplex-link-op $r(10) $pc(35) orient 270deg
$ns duplex-link-op $r(10) $pc(36) orient 285deg
$ns duplex-link-op $r(11) $r(12)  orient 0deg
$ns duplex-link-op $r(11) $pc(37) orient 255deg
$ns duplex-link-op $r(11) $pc(38) orient 270deg
$ns duplex-link-op $r(11) $pc(39) orient 285deg
$ns duplex-link-op $r(12) $pc(40) orient 255deg
$ns duplex-link-op $r(12) $pc(41) orient 270deg
$ns duplex-link-op $r(12) $pc(42) orient 285deg


# Show the queues
$ns queue-limit $r(6) $r(7) 10
$ns queue-limit $r(7) $r(6) 10
$ns queue-limit $r(7) $r(8) 10
$ns queue-limit $r(8) $r(7) 10
$ns duplex-link-op $r(6) $r(7) queuePos 0.25
$ns duplex-link-op $r(7) $r(6) queuePos 0.75
$ns duplex-link-op $r(7) $r(8) queuePos 0.25
$ns duplex-link-op $r(8) $r(7) queuePos 0.75
 

# Link costs
$ns cost $r(0)  $r(1)   20
$ns cost $r(0)  $r(5)   20
$ns cost $r(1)  $r(6)    1
$ns cost $r(5)  $r(6)    1
$ns cost $r(1)  $r(2)   20
$ns cost $r(6)  $r(7)    1
$ns cost $r(7)  $r(8)    1
$ns cost $r(8)  $r(9)    1
$ns cost $r(2)  $r(7)    1
$ns cost $r(2)  $r(3)   20
$ns cost $r(3)  $r(8)    1
$ns cost $r(3)  $r(4)   20
$ns cost $r(4)  $r(9)   20
$ns cost $r(6)  $r(10)   1
$ns cost $r(7)  $r(11)   1
$ns cost $r(8)  $r(12)   1
$ns cost $r(10) $r(11)  20
$ns cost $r(11) $r(12)  20
$ns cost $r(1)  $r(0)   20
$ns cost $r(5)  $r(0)   20
$ns cost $r(6)  $r(1)    1
$ns cost $r(6)  $r(5)    1
$ns cost $r(2)  $r(1)   20
$ns cost $r(7)  $r(6)    1
$ns cost $r(8)  $r(7)    1
$ns cost $r(9)  $r(8)    1
$ns cost $r(7)  $r(2)    1
$ns cost $r(3)  $r(2)   20
$ns cost $r(8)  $r(3)    1
$ns cost $r(4)  $r(3)   20
$ns cost $r(9)  $r(4)   20
$ns cost $r(10) $r(6)    1
$ns cost $r(11) $r(7)    1
$ns cost $r(12) $r(8)    1
$ns cost $r(11) $r(10)  20
$ns cost $r(12) $r(11)  20


# Create sender TCP agents and CBR applications
set tcp0 [new Agent/TCP]
$tcp0 set colored_rtx_ 5
$tcp0 set window_ 64
$tcp0 set class_ 1
$tcp0 set packetSize_ 1460
$ns attach-agent $pc(14) $tcp0

set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $tcp0
$cbr0 set packet_size_ 1460
$cbr0 set rate_ 1Mbps
$cbr0 set maxpkts_ 65536
set tcp1 [new Agent/TCP]
$tcp1 set colored_rtx_ 5
$tcp1 set window_ 64
$tcp1 set class_ 2
$tcp1 set packetSize_ 1460
$ns attach-agent $pc(34) $tcp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $tcp1
$cbr1 set packet_size_ 1460
$cbr1 set rate_ 1Mbps
$cbr1 set maxpkts_ 65536
set tcp2 [new Agent/TCP]
$tcp2 set colored_rtx_ 5
$tcp2 set window_ 64
$tcp2 set class_ 3
$tcp2 set packetSize_ 1460
$ns attach-agent $pc(18) $tcp2
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $tcp2
$cbr2 set packet_size_ 1460
$cbr2 set rate_ 1Mbps
$cbr2 set maxpkts_ 65536
set tcp3 [new Agent/TCP]
$tcp3 set colored_rtx_ 5
$tcp3 set window_ 64
$tcp3 set class_ 4
$tcp3 set packetSize_ 1460
$ns attach-agent $pc(30) $tcp3
set cbr3 [new Application/Traffic/CBR]
$cbr3 attach-agent $tcp3
$cbr3 set packet_size_ 1460
$cbr3 set rate_ 1Mbps
$cbr3 set maxpkts_ 65536


# Create TCP sinks
set sink0 [new Agent/TCPSink]
$ns attach-agent $pc(42) $sink0
set sink1 [new Agent/TCPSink]
$ns attach-agent $pc(25) $sink1
set sink2 [new Agent/TCPSink]
$ns attach-agent $pc(39) $sink2
set sink3 [new Agent/TCPSink]
$ns attach-agent $pc(33) $sink3

 
# Connect the sender-receiver pairs
$ns connect $tcp0 $sink0
$ns connect $tcp1 $sink1
$ns connect $tcp2 $sink2
$ns connect $tcp3 $sink3

 
# Run the simulation
$ns at 1.0 "$cbr0 start"
$ns at 1.3 "$cbr1 start"
$ns at 1.6 "$cbr2 start"
$ns at 1.9 "$cbr3 start"

$ns rtmodel-at 10.0 down $r(6) $r(7)
$ns rtmodel-at 20.0 up $r(6) $r(7)
$ns at 21.0 "finish"
$ns run