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

Assignment-05:-Simulation of Network With Specific Routing Protocols

The document details an assignment focused on simulating network routing protocols, specifically Link State Routing and Distance Vector Routing. It explains the theoretical foundations, advantages, and disadvantages of each protocol, along with sample code for simulation using NS2. The document emphasizes the dynamic nature of routing algorithms and their adaptability to network changes.

Uploaded by

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

Assignment-05:-Simulation of Network With Specific Routing Protocols

The document details an assignment focused on simulating network routing protocols, specifically Link State Routing and Distance Vector Routing. It explains the theoretical foundations, advantages, and disadvantages of each protocol, along with sample code for simulation using NS2. The document emphasizes the dynamic nature of routing algorithms and their adaptability to network changes.

Uploaded by

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

Name: Mihir Patil Branch: IT

Batch: S21 Roll no: 94

Assignment-05 :- Simulation of Network with specific routing


protocols

5.1 Link State Routing Protocol


Aim :
To simulate and study the link state routing algorithm using simulation using
NS2.
Theory:

Link State Routing Algorithm

Link State Routing (LSR) is a dynamic routing method where routers share link status information rather than
entire routing tables. Unlike Distance Vector Routing, LSR enables routers to independently compute the
shortest paths using algorithms like Dijkstra’s Shortest Path First (SPF).
Key Concepts:

● Link State Advertisements (LSAs): Routers periodically broadcast LSAs containing link costs and
neighbor details.
● Flooding: LSAs are flooded across the network to ensure all routers have a synchronized view.
● Link State Database (LSDB): Each router maintains an LSDB to store received LSAs and build a
complete network topology.
● Routers use the SPF algorithm to determine optimal routes.
Shortest Path Calculation:
● Network Adaptability: Changes in topology trigger LSAs, prompting routers to update paths
dynamically.

Advantages:

● Fast Convergence: Updates propagate quickly, leading to rapid path recalculations.


● Scalability: Efficient for large networks as only state information is exchanged.
● Loop Prevention: The global network view prevents routing loops.
● Accurate Routing: Adapts dynamically to network changes, optimizing path selection.
N

Code:
set ns [new Simulator] set
nf [open out.nam w] $ns
namtrace-all $nf set tr
[open out.tr w] $ns trace-
all $tr

proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 10Mb 10ms DropTail


$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail

$ns duplex-link-op $n0 $n1 orient right-down


$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n1 orient right-up

set tcp [new Agent/TCP]


$ns attach-agent $n0 $tcp
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
set udp [new Agent/UDP]
$ns attach-agent $n2 $udp
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null

$ns connect $tcp $sink


$ns connect $udp $null
$ns rtmodel-at 1.0 down $n1 $n3
$ns rtmodel-at 2.0 up $n1 $n3
$ns rtproto DV

$ns at 0.0 "$ftp start"


$ns at 0.0 "$cbr start"
$ns at 5.0 "finish"

$ns run

Output:
5.2 Distance Vector Routing Protocol

Aim:
To study simulation of networks with specific routing protocols distance vectors.

Theory:
Distance Vector Routing Protocol is based on the Bellman-Ford Algorithm, also known as the
Ford-Fulkerson Algorithm. It determines the shortest path from one node to another by sharing
distance information between neighboring routers.
Working Principle

1. Each router maintains a routing table containing the distance to all known destinations.
2. Routers exchange periodic updates with their directly connected neighbors.
3. Distance is measured in hops (i.e., the number of routers a packet must pass through).
4. The Bellman-Ford algorithm updates routing tables dynamically based on received
information.
5. Loop prevention mechanisms such as split horizon, hold-down timers, and route poisoning
are used to avoid routing loops.

Advantages:

● Simple and easy to configure.


● Works well in smaller networks.

Disadvantages:

● Slow convergence time, meaning updates take time to propagate.


● Prone to routing loops in larger networks.

Code:
set ns [new Simulator]
$ns rtproto LS

set node1 [$ns node]


set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
set node5 [$ns node]
set node6 [$ns node]
set node7 [$ns node]
set tf [open out.tr w] $ns
trace-all $tf set nf [open
out.nam w] $ns namtrace-
all $nf

$node1 label "node 1"


$node2 label "node 2"
$node3 label "node 3"
$node4 label "node 4"
$node5 label "node 5"
$node6 label "node 6"
$node7 label "node 7"

$node1 label-color blue


$node2 label-color red
$node3 label-color red
$node4 label-color blue
$node5 label-color blue
$node6 label-color blue
$node7 label-color blue

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


$ns duplex-link $node2 $node3 1.5Mb 10ms DropTail
$ns duplex-link $node3 $node4 1.5Mb 10ms DropTail
$ns duplex-link $node4 $node5 1.5Mb 10ms DropTail
$ns duplex-link $node5 $node6 1.5Mb 10ms DropTail
$ns duplex-link $node6 $node7 1.5Mb 10ms DropTail
$ns duplex-link $node7 $node1 1.5Mb 10ms DropTail

$ns duplex-link-op $node1 $node2 orient left-down


$ns duplex-link-op $node2 $node3 orient left-down
$ns duplex-link-op $node3 $node4 orient right-down
$ns duplex-link-op $node4 $node5 orient right
$ns duplex-link-op $node5 $node6 orient right-up
$ns duplex-link-op $node6 $node7 orient left-up
$ns duplex-link-op $node7 $node1 orient left-up

set tcp2 [new Agent/TCP]


$ns attach-agent $node1 $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $node4 $sink2
$ns connect $tcp2 $sink2
set traffic_ftp2 [new Application/FTP]
$traffic_ftp2 attach-agent $tcp2

proc finish {} {
global ns nf tf
$ns flush-trace
close $tf close $nf
exec nam out.nam &
exit 0

}
$ns at 0.5 "$traffic_ftp2 start"
$ns rtmodel-at 1.0 down $node1 $node2
$ns rtmodel-at 2.0 up $node1 $node2
$ns at 3.0 "$traffic_ftp2 start"
$ns at 4.0 "$traffic_ftp2 stop"
$ns at 5.0 "finish"

$ns run

Output:

You might also like