Multicast in ns2 1 Multicast 2 Multicast Routing


![Multicast Routing l set ns [new Simulator] $ns multicast Or set ns [new Simulator Multicast Routing l set ns [new Simulator] $ns multicast Or set ns [new Simulator](https://slidetodoc.com/presentation_image_h2/47f2eac3f165b7197973c1c3c7be845e/image-3.jpg)



![Multicast: Step 2 l Topology # Create nodes set n 0 [$ns node] set Multicast: Step 2 l Topology # Create nodes set n 0 [$ns node] set](https://slidetodoc.com/presentation_image_h2/47f2eac3f165b7197973c1c3c7be845e/image-7.jpg)






- Slides: 13
Multicast in ns-2 報告者: 陳沐恩 1
Multicast 簡介 2
Multicast Routing l set ns [new Simulator] $ns multicast Or set ns [new Simulator –multicast on] l set mproto <type>: Ctr. Mcast, DM, ST, BST 3
Multicast Routing l all nodes will contain multicast protocol agents Ø l allocating a multicast address Ø l set mrthandle [$ns mrtproto $mproto] set group [Node allocaddr] define an agent and as a multicast source for the group Ø Ø $udp 1 set dst_addr_ $group $udp 1 set dst_port_ 0 4
Multicast Routing l create a receiver agent Ø l specify which nodes join the group and when they want to join the group Ø l set rcvr [new Agent/Loss. Monitor] $ns at 0. 0 "$n 1 join-group $rcvr $group" make a node leave the group at a time Ø $ns at 1. 6 "$n 2 leave-group $rcvr $group" 5
Multicast: Step 1 l Scheduler , tracing , and topology # Create scheduler set ns [new Simulator] # Turn on multicast $ns multicast # Turn on Tracing set fd [new “mcast. nam” w] $ns namtrace-all $fd 6
Multicast: Step 2 l Topology # Create nodes set n 0 [$ns node] set n 1 [$ns node] set n 2 [$ns node] set n 3 [$ns node] # Create links $ns duplex-link $n 0 $n 1 1. 5 Mb 10 ms Drop. Tail $ns duplex-link $n 0 $n 2 1. 5 Mb 10 ms Drop. Tail $ns duplex-link $n 0 $n 3 1. 5 Mb 10 ms Drop. Tail 7
Multicast: Step 3 l Routing and group setup # Routing protocol: let’s run distance vector set mproto DM # Allocate group addresses set group 1 [Node allocaddr] set group 2 [Node allocaddr] 8
Multicast: Step 4 l Sender 0 # Transport agent for the traffic source set udp 0 [new Agent/UDP] $ns attach-agent $n 1 $udp 0 set dst_addr_ $group 1 $udp 0 set dst_port_ 0 # Constant Bit Rate source #0 set cbr 0 [new Application/Traffic/CBR] $cbr 0 attach-agent $udp 0 # Start at time 1. 0 second $ns at 1. 0 "$cbr 0 start" 9
Multicast: Step 5 l Sender 1 # Transport agent for the traffic source set udp 1 [new Agent/UDP] $ns attach-agent $n 3 $udp 1 set dst_addr_ $group 2 $udp 1 set dst_port_ 0 # Constant Bit Rate source #0 set cbr 1 [new Application/Traffic/CBR] $cbr 1 attach-agent $udp 1 # Start at time 1. 1 second $ns at 1. 1 "$cbr 1 start" 10
Multicast: Step 6 l Receiver with dynamic membership # Can also be Agent/Null set rcvr [new Agent/Loss. Monitor] # Assign it to node $n 2 $ns at 1. 2 "$n 2 join-group $rcvr $group 2" $ns at 1. 25 "$n 2 leave-group $rcvr $group 2" $ns at 1. 3 "$n 2 join-group $rcvr $group 2" $ns at 1. 35 "$n 2 join-group $rcvr $group 1" 11
Multicast: Step 7 l End-of-simulation wrapper (as usual) $ns at 2. 0 "finish" proc finish {} { global ns fd close $fd $ns flush-trace puts "running nam. . . " exec nam out. nam & exit 0 } $ns run 12
抽考題目 l l 使用DM這個multicast protocol,讓所有node 包含multicast protocol agent,並建立一個 multicast的group,定義一個udp的agent給 group當作multicast的來源端。 提供tcl,請依要求補上缺少的code(5行) 13