Tuesday, December 20, 2011

NS2 simulation for PIM-SM multicasting

I am going to show you how to perform traditional PIM-SM simulation in NS2. For those who doesn't know PIM-SM (Protocol Independent Multicast - Sparse Mode) check the RFC 4601.

Definition extracted from RFCs:
PIM-DM (RFC3973) is a multicast routing protocol that uses the underlying unicast routing information base to flood multicast datagrams to all multicast routers. Prune messages are used to prevent future messages from propagating to routers without group membership information.

PIM-SM (RFC4601) is a multicast routing protocol that can use the underlying unicast routing information base or a separate multicast-capable routing information base. It builds unidirectional shared trees rooted at a Rendezvous Point (RP) per group, and optionally creates shortest-path trees per source.

In simple language, -->PIM-DM uses a push model to flood multicast traffic to every corner of the network. This process is considered to be very “heavy”, since it floods its message to all sub-networks. In PIM-SM environments only sub-networks that have active receivers that have explicitly requested the data will be forwarded the multicast traffic. PIM-SM introduces the concept of Rendezvous Point (RP). The RP it is a appointed router where all the multicast messages flow and from witch it forward through the multipoint tree.

-->The Network Simulator2 (NS-2) is the most popular simulator in the scientific field and in the great telecommunications companies, allowing the creation of any network topology and analyze any kind of protocol.

SIMULATION SCENARIO:
-->
This simulation simulates PIM-SM environment based IP infrastructure with one multicast source, one group address and two nodes joining the group. Node0 thru Node7 are all routers. Source1 is attached to Router0. Receiver1 and Receiver2 are attached to Router6 and Router7 respectively. Router1 is defined as Rendezvous Point (RP).

Source1 starts at 0.5 sec
Receiver1 joins the group at 1.0 sec
Receiver2 joins the group at 1.5 sec
Receiver1 leaves the group at 6.0 sec
Receiver2 leaves the group at 6.5 sec
Source1 stops at 9.5 sec



Network Topology for multicast simulation


File: mulicast.tcl
-->
#//////////////////CODE STARTS HERE/////////////////////////////////
#Create an event scheduler wit multicast turned on
set ns [new Simulator -multicast on]
#$ns multicast
#Turn on Tracing

set tf [open output.tr w]
$ns trace-all $tf

# Turn on nam Tracing
set fd [open mcast.nam w]
$ns namtrace-all $fd

# 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]
set n6 [$ns node]
set n7 [$ns node]

# Create links
$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail
$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail
$ns duplex-link $n1 $n4 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n5 1.5Mb 10ms DropTail
$ns duplex-link $n5 $n6 1.5Mb 10ms DropTail
$ns duplex-link $n5 $n7 1.5Mb 10ms DropTail


# Allocate group addresses
set group1 [Node allocaddr]
set group2 [Node allocaddr]


# Routing protocol: PIM-SM
$ns mrtproto BST
BST set RP_($group1) $n1


# UDP Transport agent for the traffic source
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
$udp0 set dst_addr_ $group1
$udp0 set dst_port_ 0
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 210
$cbr1 set rate_ 1000k
$cbr1 attach-agent $udp0

# Create receiver
set rcvr1 [new Agent/Null]
$ns attach-agent $n6 $rcvr1
set rcvr2 [new Agent/Null]

$ns attach-agent $n7 $rcvr2


$ns at 1.0 "$n6 join-group $rcvr1 $group1"
$ns at 1.5 "$n7 join-group $rcvr2 $group1"

$ns at 6.0 "$n6 leave-group $rcvr1 $group1"
$ns at 6.5 "$n7 leave-group $rcvr2 $group1"

# Schedule events
$ns at 0.5 "$cbr1 start"
$ns at 9.5 "$cbr1 stop"

#post-processing
$ns at 10.0 "finish"
proc finish {} {
global ns tf
$ns flush-trace
close $tf
exec nam mcast.nam &
exit 0
}

# For nam
#Colors for packets from mcast packets
$ns color 10 red

#udp0 traffic has flow ID 10
# Group 0 source

$udp0 set fid_ 10
$n0 color red
$n0 label "Source 1"

$n6 label "Receiver 1"
$n6 color blue
$n7 label "Receiver 2"
$n7 color blue

# Animation rate
$ns set-animation-rate 3.0ms
$ns run
#//////////////////CODE ENDS HERE/////////////////////////////////

Make sure that you make your .tcl file executable
#chmod 700 multicast.tcl

Execute the .tcl file as
#ns multicast.tcl

If you run into any issues, refer to NS2 documentation. It's really nice documentation.

No comments: