Multicast in ns-2
description
Transcript of Multicast in ns-2
![Page 1: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/1.jpg)
1
Multicast in ns-2
報告者 :陳沐恩
![Page 2: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/2.jpg)
2
Multicast 簡介
![Page 3: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/3.jpg)
3
Multicast Routing
set ns [new Simulator]
$ns multicast
Or
set ns [new Simulator –multicast on]
set mproto <type>
<type>:CtrMcast, DM, ST, BST
![Page 4: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/4.jpg)
4
Multicast Routing
all nodes will contain multicast protocol agents set mrthandle [$ns mrtproto $mproto]
allocating a multicast address set group [Node allocaddr]
define an agent and as a multicast source for the group $udp1 set dst_addr_ $group $udp1 set dst_port_ 0
![Page 5: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/5.jpg)
5
Multicast Routing
create a receiver agent set rcvr [new Agent/LossMonitor]
specify which nodes join the group and when they want to join the group $ns at 0.0 "$n1 join-group $rcvr $group"
make a node leave the group at a time $ns at 1.6 "$n2 leave-group $rcvr $group"
![Page 6: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/6.jpg)
6
Multicast:Step1
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
![Page 7: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/7.jpg)
7
Multicast:Step2
Topology# Create nodesset n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]# Create links$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail$ns duplex-link $n0 $n2 1.5Mb 10ms DropTail$ns duplex-link $n0 $n3 1.5Mb 10ms DropTail
![Page 8: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/8.jpg)
8
Multicast:Step3
Routing and group setup# Routing protocol: let’s run distance vector
set mproto DM
# Allocate group addresses
set group1 [Node allocaddr]
set group2 [Node allocaddr]
![Page 9: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/9.jpg)
9
Multicast:Step4
Sender0# Transport agent for the traffic sourceset udp0 [new Agent/UDP]$ns attach-agent $n1 $udp0$udp0 set dst_addr_ $group1$udp0 set dst_port_ 0# Constant Bit Rate source #0set cbr0 [new Application/Traffic/CBR]$cbr0 attach-agent $udp0# Start at time 1.0 second$ns at 1.0 "$cbr0 start"
![Page 10: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/10.jpg)
10
Multicast:Step5
Sender1# Transport agent for the traffic sourceset udp1 [new Agent/UDP]$ns attach-agent $n3 $udp1$udp1 set dst_addr_ $group2$udp1 set dst_port_ 0# Constant Bit Rate source #0set cbr1 [new Application/Traffic/CBR]$cbr1 attach-agent $udp1# Start at time 1.1 second$ns at 1.1 "$cbr1 start"
![Page 11: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/11.jpg)
11
Multicast:Step6
Receiver with dynamic membership# Can also be Agent/Null
set rcvr [new Agent/LossMonitor]
# Assign it to node $n2
$ns at 1.2 "$n2 join-group $rcvr $group2"
$ns at 1.25 "$n2 leave-group $rcvr $group2"
$ns at 1.3 "$n2 join-group $rcvr $group2"
$ns at 1.35 "$n2 join-group $rcvr $group1"
![Page 12: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/12.jpg)
12
Multicast:Step7
End-of-simulation wrapper (as usual)$ns at 2.0 "finish"proc finish {} {global ns fdclose $fd$ns flush-traceputs "running nam..."exec nam out.nam &exit 0}$ns run
![Page 13: Multicast in ns-2](https://reader036.fdocuments.net/reader036/viewer/2022082517/56813ff5550346895dab16e0/html5/thumbnails/13.jpg)
13
抽考題目使用 DM這個multicast protocol,讓所有
node包含multicast protocol agent,並建立一個multicast 的 group,定義一個 udp 的agent 給 group當作multicast的來源端。
提供 tcl,請依要求補上缺少的 code(5 行 )