0% found this document useful (0 votes)
11 views4 pages

Assignment 2

Uploaded by

Mainuddin Mondal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Assignment 2

Uploaded by

Mainuddin Mondal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT 2

OBJECľI
VE :
Repeating the Dynamic Source Routing (DSR) experiment with 10 nodes involves establishing
the shortest path from Node 0 to Node 4. Midway through the simulation time, the link between
Node 2 and Node 3 is intentionally disabled. Subsequently, the same link is restored after one-
fourth of the total simulation time has elapsed. Each segment of the code is presented without
detailed explanations.

TCL SCRIPT:

set ns [new Simulator] set


nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf proc
finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for {set i 0} {$i < 10} {incr i} {
set n($i) [$ns node]
}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropĪail
}
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropĪail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropĪail set
udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Īraffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0 set
null0 [new Agent/Null]
$ns attach-agent $n(4) $null0
$ns connect $udp0 $null0
$ns rtproto DV
$ns rtmodel-at 22.0 up $n(2) $n(3)
$ns rtmodel-at 20.0 up $n(2) $n(3)
$udp0 set fid_ 1
$ns color 1 Red
$ns at 1.0 "$cbr0 start"
$ns at 45 "finish"
$ns run
EXPLANATION OF THE CODE:

o 1. **Graph Initialization:** The initial step involves creating a graph to


represent the network topology using the NetworkX library in Python.
o
o This code initializes an empty graph using the NetworkX library.
o
o 2. **Node and Edge Addition:** Nodes and edges are added to the graph, each
assigned an associated weight.
o
o These lines add nodes and edges to the graph, defining initial weights for each
edge.
o
o 3. **Initial Graph Visualization:** The code then presents a visual
representation of the initial state of the graph.
o
o This part of the code generates a visual representation of the initial graph.
o
o 4. **Shortest Path Computation:** Dijkstra's algorithm is used to find the
shortest path from Node 0 to Node 4.
o
o This section computes and prints the shortest path from Node 0 to Node 4
using Dijkstra's algorithm.
o
o 5. **Link Down Simulation:** The code simulates a link failure between
Node 2 and Node 3 after half of the simulation time.
o
o This part of the code increases the weight of the edge between Node 2 and
Node 3, simulating a link down scenario.
o
o 6. **Updated Graph Visualization:** The code then illustrates the graph after
the link-down simulation.
o
o This section generates a visual representation of the graph after the simulated
link-down event.
o
o 7. **Link Up Simulation:** After one-fourth of the simulation time, the code
restores the link between Node 2 and Node 3.
o
o This part of the code sets the weight of the edge back to its original value,
simulating a link restoration.
o
o 8. **Final Graph Visualization:** The code then presents the graph after the
link-up simulation.
o
o This section generates a visual representation of the final graph after the
simulated link-up event.
o
o The entire program provides a step-by-step illustration of the DSR experiment,
from graph creation to simulating link events and visualizing the network state
at different stages.

NEWORK ANIMATION:

CONCLUSION:
The written TCL script on running provides a network animation which satisfies the desired
objective of the specified question.

You might also like