Write a tcl script that forms a network consisting of 5 nodes, numbered from 0 to 4, which form a ring. The links have a 128K bandwidht with 10ms delay. Set the routing protocol to DV (Distance vector). Send UDP packets from node 0 to node 2 with the rate of 0.02 seconds per packet. Start transmission at 0.05. Bring down the link between node 1 and node 2 at 0.25. Finish the transmission at 1.000. Then run nam to view the results. What do you see? Will packets be re-routed after the link goes down? Is this what you expect?
set ns [new Simulator] set nam_file lab-ex.nam set nf [open $nam_file w] $ns namtrace-all $nf # Create the topology # Frist, the nodes ...... # Create the connection ...... # Set the routing protocol ...... # Now create agents and attach them to the appropriate nodes ...... # Start transmitting packets from 0 to 2 ...... # Bring down the link between 1 and 2 using this command $ns rtmodel-at 0.25 down $n(1) $n(2) # Final wrapup proc finish {} { global ns nf nam_file $ns flush-trace close $nf exec nam $nam_file & exit 0 } $ns at 1.00 "finish" $ns run
4 | | 0-------------1----------2---------5 | | 3Choose CtrMcast as the multicast routing protocol for the experiment. Node 0 is a UDP source for this group. The source will start transmission at time 0.05. Nodes 3 and 4 will join the multicast group at times 0.10 and 0.12, respectively. Node 3 will leave the multicast group at 0.5, and the execution will terminate at 0.6
Stay in the ns-test directory, create lab1d.tcl:
# Create event scheduler set ns [new Simulator] set nam_file lab-ex-2.nam set nf [open $nam_file w] $ns namtrace-all $nf # Create the topology # First the nodes ...... # Make the links ...... # Use the following to make the orientation right. $ns duplex-link-op $n(0) $n(1) orient right $ns duplex-link-op $n(1) $n(2) orient right $ns duplex-link-op $n(2) $n(3) orient right $ns duplex-link-op $n(1) $n(3) orient down $ns duplex-link-op $n(1) $n(4) orient up # Create the multicast group. Use the following line ...... # Choose the routing protocol ...... # Create the UDP agent and tie it to the multicast group ...... # Set the timing and run the script. ...... # Final wrapup proc finish {} { global ns nf nam_file $ns flush-trace close $nf exec nam $nam_file & exit 0 } $ns at 5.0 "finish" # Start the simulator $ns run
References: