1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
# Pragmatic General Multicast (PGM), Reliable Multicast
#
# Example script to demonstrate the capabilities of the PGM implementation.
#
# This is a binary tree with one sender and several receivers at the leaf
# nodes.
#
# Ryan S. Barnett, 2001
# rbarnett@catarina.usc.edu
set ns [new Simulator -multicast on]
$ns node-config -PGM ON
$ns namtrace-all [open out.nam w]
$ns color 0 red
$ns color 1 black
$ns color 2 white
$ns color 3 blue
$ns color 4 yellow
$ns color 5 LightBlue
$ns color 6 green
$ns color 7 magenta
$ns color 8 orange
set height 3
set nodeNum [expr 1 << $height]
set linkNum [expr $nodeNum - 1]
set rcvrNum [expr 1 << [expr $height - 1]]
puts "Height $height nodes $nodeNum rcvrs $rcvrNum"
set colors { red black white blue yellow LightBlue green magenta orange }
#
# Create multicast group
#
set group [Node allocaddr]
puts "Group addr: $group"
# Create source node.
set n(0) [$ns node]
$n(0) shape "circle"
$n(0) color "red"
#
# Create nodes
#
for {set k 1} {$k < $rcvrNum} {incr k} {
set n($k) [$ns node]
$n($k) shape "circle"
}
for {set k $rcvrNum} {$k < $nodeNum} {incr k} {
set n($k) [$ns node]
$n($k) shape "circle"
$n($k) color "blue"
}
#set n(16) [$ns node]
#$n(16) shape "circle"
#$n(16) color "blue"
#set n(17) [$ns node]
#$n(17) shape "circle"
#$n(17) color "blue"
proc makelinks { bw delay pairs } {
global ns n
foreach p $pairs {
set src $n([lindex $p 0])
set dst $n([lindex $p 1])
$ns duplex-link $src $dst $bw $delay DropTail
}
}
makelinks 1.5Mb 10ms {
{ 0 1 }
{ 1 2 }
{ 1 3 }
{ 2 4 }
{ 2 5 }
{ 3 6 }
{ 3 7 }
}
#
#Set routing protocol
#
set mproto DM
set mrthandle [$ns mrtproto $mproto {}]
#
# Create loss modules - Cycle is 10,
# loss module i drops (i*5)th packet in the cycle
#
for {set i 0} {$i <= $linkNum} {incr i} {
set loss_module($i) [new PGMErrorModel]
# Drop second ODATA packet every 10 packets.
$loss_module($i) drop-packet ODATA 10 2
$loss_module($i) drop-target [$ns set nullAgent_]
}
proc insert-loss pairs {
global ns n loss_module
set i 0
foreach p $pairs {
set src $n([lindex $p 0])
set dst $n([lindex $p 1])
$ns lossmodel $loss_module($i) $src $dst
incr i
}
}
#
# Insert a loss module
#
insert-loss {
{ 2 4 }
{ 2 5 }
}
#
# Create Sender
#
set src [new Agent/PGM/Sender]
$ns attach-agent $n(0) $src
$src set dst_addr_ $group
$src set dst_port_ 0
# Attach data source to sender.
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $src
$cbr set rate_ 448Kb
$cbr set packetSize_ 210
$cbr set random_ 0
#
# Create PGM receivers
#
set i $rcvrNum
for {set k 0} {$k < $rcvrNum} {incr k} {
set rcv($k) [new Agent/PGM/Receiver]
$ns attach-agent $n($i) $rcv($k)
$ns at 0.01 "$n($i) join-group $rcv($k) $group"
incr i
}
#set rcv(8) [new Agent/PGM/Receiver]
#$ns attach-agent $n(16) $rcv(8)
#$ns at 0.01 "$n(16) join-group $rcv(8) $group"
#set rcv(9) [new Agent/PGM/Receiver]
#$ns attach-agent $n(17) $rcv(9)
#$ns at 0.01 "$n(17) join-group $rcv(9) $group"
# Set Node-2 PGM Agent to be disabled, only multicast.
#set agent2 [$n(2) get-pgm]
#$agent2 set pgm_enabled_ 0
#set agent4 [$n(4) get-pgm]
#$agent4 set pgm_enabled_ 0
$ns at 0.3 "$src start-SPM"
$ns at 0.5 "$cbr start"
$ns at 1.5 "$cbr stop"
$ns at 2.0 "$src stop-SPM"
$ns at 2.0 "finish"
proc finish {} {
global ns src rcv rcvrNum nodeNum n
$src print-stats
# Print statistics for each PGM Agent.
for {set k 0} {$k < $nodeNum} {incr k} {
set pgm_agent [$n($k) get-pgm]
$pgm_agent print-stats
}
# Print statistics for each receiver.
for {set k 0} {$k < $rcvrNum} {incr k} {
$rcv($k) print-stats
}
#$rcv(1) print-all-stats
puts "Simulation Finished"
# puts "Starting Nam.."
# exec nam out.nam &
exit 0
}
$ns run
|