Multicast forwarding requires enhancements to the nodes and links in the topology. Therefore, the user must specify multicast requirements to the Simulator class before creating the topology. This is done in one of two ways:
set ns [new Simulator -multicast on] {\rm or} set ns [new Simulator] $ns multicastWhen multicast extensions are thus enabled, nodes will be created with additional classifiers and replicators for multicast forwarding, and links will contain elements to assign incoming interface labels to all packets entering a node.
A multicast routing strategy is the mechanism by which the multicast distribution tree is computed in the simulation. ns supports three multiast route computation strategies: centralised, dense mode(DM) or shared tree mode(ST).
The method []mrtproto in the Class Simulator specifies either the route computation strategy, for centralised multicast routing, or the specific detailed multicast routing protocol that should be used.
The following are examples of valid invocations of multicast routing in ns:
set cmc [$ns mrtproto CtrMcast] # specify centralized multicast for all nodes; # cmc is the handle for multicast protocol object; $ns mrtproto DM # specify dense mode multicast for all nodes; $ns mrtproto ST # specify shared tree mode to run on all nodes;Notice in the above examples that CtrMcast returns a handle that can be used for additional configuration of centralised multicast routing. The other routing protocols will return a null string. All the nodes in the topology will run instances of the same protocol.
Multiple multicast routing protocols can be run at a node, but in this case the user must specify which protocol owns which incoming interface. For this finer control []mrtproto-iifs is used.
New/unused multicast address are allocated using the procedure []allocaddr.
The agents use the instance procedures []join-group and []leave-group, in the class Node to join and leave multicast groups. These procedures take two mandatory arguments. The first argument identifies the corresponding agent and second argument specifies the group address.
An example of a relatively simple multicast configuration is:
set ns [new Simulator {\bfseries{}-multicast on}] # enable multicast routing; set group [{\bfseries{}Node allocaddr}] # allocate a multicast address; set node0 [$ns node] # create multicast capable nodes; set node1 [$ns node] $ns duplex-link $node0 $node1 1.5Mb 10ms DropTail set mproto DM # configure multicast protocol; set mrthandle [{\bfseries{}$ns mrtproto $mproto}] # all nodes will contain multicast protocol agents; set udp [new Agent/UDP] # create a source agent at node 0; $ns attach-agent $node0 $udp set src [new Application/Traffic/CBR] $src attach-agent $udp {\bfseries{}$udp set dst_addr_ $group} {\bfseries{}$udp set dst_port_ 0} set rcvr [new Agent/LossMonitor] # create a receiver agent at node 1; $ns attach-agent $node1 $rcvr $ns at 0.3 "{\bfseries{}$node1 join-group $rcvr $group}" # join the group at simulation time 0.3 (sec);