How to Implement Multicast Routing in NS2

To implement the Multicast routing in NS2 that permits the nodes to forward data to several ends such as a group of nodes effectively. The simulator NS2 supports numerous multicast routing protocols like Distance Vector Multicast Routing Protocol (DVMRP), Protocol Independent Multicast (PIM), and Multicast Extensions to OSPF (MOSPF). In this routing, a source node sends the data to several receivers using a multicast group. Nodes that are portion of the group, receive the data.

We provide simplest steps to executing multicast routing in NS2 using DVMRP, one of the most general multicast routing protocols supported by NS2.

Steps to Implement Multicast Routing in NS2

  1. Set Up NS2 Environment
    • Make sure that NS2 is installed and set up properly on the system.
  2. Understand Multicast Routing
    • Multicast routing allows the transmission of the data using a multicast group address from one source to various destinations. Routers send multicast traffic only to interested receivers, decreasing the network traffic compared to broadcasting.
  3. Use Multicast Routing in NS2
    • The simulation tool NS2 that delivers built-in support for multicast routing protocols. In this sample, we will use the protocol DVMRP (Distance Vector Multicast Routing Protocol) to execute the multicast routing.

Example OTcl Script for Multicast Routing in NS2 (DVMRP)

The following is an instance OTcl script that mimics multicast routing using the DVMRP protocol.

  1. Set Up the Network Topology

# Create a simulator object

set ns [new Simulator -multicast on]

# Open the trace file for recording data

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define the finish procedure

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exec nam out.nam &

exit 0

}

# Create network nodes

set node1 [$ns node]   ;# Source node

set node2 [$ns node]   ;# Receiver node

set node3 [$ns node]

set node4 [$ns node]   ;# Receiver node

set node5 [$ns node]   ;# Receiver node

# Create links between nodes

$ns duplex-link $node1 $node2 10Mb 10ms DropTail

$ns duplex-link $node2 $node3 10Mb 10ms DropTail

$ns duplex-link $node3 $node4 10Mb 10ms DropTail

$ns duplex-link $node4 $node5 10Mb 10ms DropTail

$ns duplex-link $node1 $node5 5Mb 50ms DropTail

# Enable multicast routing protocol (DVMRP)

$ns mrtproto DVMRP

# Create a multicast group address (e.g., 224.1.1.1)

set group “224.1.1.1”

# Join multicast group at receiver nodes

$ns at 0.5 “$node2 join-group $node1 $group”

$ns at 0.5 “$node4 join-group $node1 $group”

$ns at 0.5 “$node5 join-group $node1 $group”

# Attach UDP agents to the source and receivers

set udp [new Agent/UDP]

$ns attach-agent $node1 $udp

set null2 [new Agent/Null]

$ns attach-agent $node2 $null2

set null4 [new Agent/Null]

$ns attach-agent $node4 $null4

set null5 [new Agent/Null]

$ns attach-agent $node5 $null5

# Connect the source to multicast receivers

$ns connect $udp $null2

$ns connect $udp $null4

$ns connect $udp $null5

# Create a CBR (Constant Bit Rate) application for the source

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set rate_ 1Mb

$cbr attach-agent $udp

# Start the CBR traffic at 1.0 seconds

$ns at 1.0 “$cbr start”

# Stop the CBR traffic at 9.0 seconds

$ns at 9.0 “$cbr stop”

# Finish the simulation at 10 seconds

$ns at 10.0 “finish”

# Run the simulation

$ns run

Explanation of the Script

  1. Multicast Support: The emulator is initialized including multicast support allowed by passing the -multicast on argument to the Simulator object.
  2. Network Topology: Five nodes are made, with links among them of changing the bandwidths and latency. Here, node1 is the source node, and node2, node4, and node5 are the multicast receiver nodes.
  3. Multicast Routing Protocol (DVMRP): The line $ns mrtproto DVMRP that permits the DVMRP multicast routing protocol. It is builds a multicast tree among the source and receivers.
  4. Multicast Group: The multicast group address is 224.1.1.1, and the receivers such as node2, node4, and node5 are join the multicast group at time 0.5 seconds.
  5. Traffic Generation: A UDP agent is joined to the source (node1), and Null agents are attached to the receivers (node2, node4, node5). From the source node to the multicast group, a Constant Bit Rate (CBR) application generates traffic.
  6. Simulation Duration: The CBR traffic starts at 1.0 seconds and ends at 9.0 seconds. The whole simulation runs for 10 seconds.

Running the Simulation

  1. We can save the script as multicast_routing.tcl.
  2. Run the script using NS2:

ns multicast_routing.tcl

  1. The simulation will generate a Network Animator (NAM) file (out.nam), and a trace file (out.tr). We can use NAM to visualize the multicast tree and the packet flows among the source and receivers.

Analyse the Results

  • Trace File: The trace file encompasses in depth information regarding the packet transmissions. We can evaluate the trace file to verify if packets are attaining all multicast group members appropriately.
  • NAM Visualization: We can use the NAM to visualize the network and monitor how multicast packets are forwarded using the multicast tree from the source to the receivers.

Enhancements

  1. Multiple Multicast Groups: We can make extra multicast groups with various addresses and analyse how several multicast groups are managed concurrently.
  2. Dynamic Group Membership: Mimic dynamic joining and exit of multicast groups by having nodes are join or leave the group at various times during the simulation.
  3. Compare with Unicast: Compare the performance of multicast routing including unicast routing by making a same network using unicast and assessing the network load and bandwidth usage.
  4. Other Multicast Protocols: Test with other multicast protocols such as PIM (Protocol Independent Multicast) or MOSPF (Multicast OSPF) to compare their behaviour and performance in various network conditions.

We demonstrated the structured approach that supports to execute and evaluate the Multicast routing in the simulation ns2 across this manual. More detailed insights will be presented depending on your needs.

Get professional assistance on Multicast Routing in NS2 from our leading developers. We offer a plethora of project ideas and are dedicated to guiding you effectively with prompt delivery. Our team has expertise in Distance Vector Multicast Routing Protocol (DVMRP), Protocol Independent Multicast (PIM), and Multicast Extensions to OSPF (MOSPF), all tailored to fit your project needs.