Acn Final MP G3 23 ODD

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Government Polytechnic, Pune-16

(An Autonomous Institute of Government of Maharashtra)

A Micro Project Report on


Distance Vector Algorithm Program using C++

Submitted By

Name Enrollment No
Shreyash Dilip Chabilwad 2106034
Ritesh Ganesh Chinchole 2106036
Rushikesh Pundlik Dawale 2106039
Shreyas Sunil Deobhankar 2106040

Under the guidance of

Smt.A.S.Paike Mam

(Academic Year:2023-24)

Government Polytechnic,Pune 16
Department of Computer Engineering

Department Of Computer Engineering


Department of Computer Engineering
Government Polytechnic Pune
YEAR 2022-23

CERTIFICATE

This is to certify that the mini-project work entitled “Distance Vector Algorithm
Program using C++ ” is a bonafide work carried out by

Name Enrollment No
Shreyash Dilip Chabilwad 2106034
Ritesh Ganesh Chinchole 2106036
Rushikesh Pundlik Dawale 2106039
Shreyas Sunil Deobhankar 2106040

of class Third Year in partial fulfilment of the requirement for the completion of
Course of Diploma Advanced Computer Network (CM4108) in Computer Engineering
from Government Polytechnic Pune. The report has been approved as it satisfies the
academic requirements in respect of micro-project work
prescribed for the course.

Micro Project Guide Head Of Department Principal

Smt.A.S.Paike Smt.J.R.Hange Dr.V.S.Bandal

Department Of Computer Engineering


Page |1

Acknowledgement

My Sincere efforts have made me to accomplish the task of completing this project.
However, it would not have been possible without the kind support and help of many
individuals.I would like to express my sincere gratitude to my Principal Dr. Vitthal Bandal
and the college for providing me with facilities required to do my project.
I am highly indebted to my Project Guide Smt.A.S.Paike mam for her valuable guidance
which has promoted my efforts in all the stages of this project work. Assistant is
developing my project and to the people who have willingly helped me out with their
abilities.
This project has been a remarkable learning experience, and I am thankful to each and
every one of you for your contributions and support in bringing our smart home design to
fruition.Finally, words are not sufficient to express gratitude my cherished family
members for supporting me without their encouragement and support I would not reach
this stage.

Department Of Computer Engineering


Page |2

Abstract
Distance Vector Routing is a fundamental algorithm used in computer networking to
determine the best path for data to travel through a network. This project presents
an implementation of the Distance Vector Routing Algorithm using C++, providing a
simplified but illustrative example of its functionality.

The program simulates a network of routers and allows users to specify link costs
between routers. Each router maintains a routing table, which is updated as per the
Distance Vector Algorithm. The routing tables reflect the best path and associated
cost to reach other routers in the network.

The project demonstrates the core principles of Distance Vector Routing, including
the exchange of routing information among routers and the iterative process of
updating routing tables until they converge to optimal values. It also showcases how
routers can handle unreachable or infinity-cost destinations.

This C++ program serves as a valuable learning resource for those looking to
understand the basic concepts of Distance Vector Routing and lays the groundwork
for more complex routing protocols used in real-world networking scenarios. It
illustrates the importance of dynamic routing and adapting to changes in network
topology, making it an essential concept in the field of computer networking.

Through this project, readers and learners can gain insight into the mechanics of
routing in computer networks, furthering their understanding of how data is
efficiently delivered from source to destination in complex network infrastructures.

Department Of Computer Engineering


Page |3

Contents

Sr.NO Name of the Chapter Page No

1 Acknowledgement 1

2 Abstract 2

3 Introduction 4

4 Routing Protocols 6

5 Routing table 7

6 Distance Vector Routing 9

7 Implementation of Distance Vector Routing 11

8 Output 14

9 Conclusion 15

10 Reference 15

Department Of Computer Engineering


Page |4

Introduction

A Router is a networking device that forwards data packets between computer


network. When a data packet comes to a router port, the router reads address
information in packet to determine out which port the packet will be sent.

Functions of routers

Path
Determination Data Forwarding Data Forwarding

Path determination :

A router determines the path data takes when it moves from a source to a
destination.

Data forwarding :

A router forwards data to the next device on the selected path to eventually
reach its destination. The device and router may be on the same network or on
different networks.

Load balancing :

Sometimes the router may send copies of the same data packet by using
multiple different paths. It does this to reduce errors due to data losses, create
redundancy, and manage traffic volume.

Department Of Computer Engineering


Page |5
Path determination also known as routing is the process of path selection in
any network. A computer network is made of many machines, called nodes,
and paths or links that connect those nodes. Communication between two
nodes in an interconnected network can take place through many different
paths. Routing is the process of selecting the best path using some
predetermined rules. It tries to find the best path by analysing network metrics
such as delay, capacity, and speed.

Routing creates efficiency in network communication. Network communication


failures result in long wait times for website pages to load for users. It can also
cause website servers to crash because they can't handle a large number of
users. Routing helps minimize network failure by managing data traffic so that
a network can use as much of its capacity as possible without creating
congestion.

Department Of Computer Engineering


Routing Protocols :
Page |6

A routing protocol is a set of rules that specify how routers identify


and forward packets along a network path. Routing protocols are
grouped into two distinct categories: interior gateway protocols and
exterior gateway protocols.
Interior gateway protocols work best within an autonomous system
—a network administratively controlled by a single organization.
External gateway protocols better manage the transfer of
information between two autonomous systems.

Department Of Computer Engineering


Page |7

Routing table
A routing table is a set of rules, often viewed in table format, that is used to
determine where data packets traveling over an Internet Protocol (IP) network
will be directed. All IP-enabled devices, including routers and switches, use
routing tables.

The routing table contains a list of specific routing destinations. When the
router receives a packet of data, it references the routing table to know where
to send that data. The routing table may also contain information on how far
each destination is from the router. In essence, a routing table is a map for the
router.

A routing table does not contain a list of all possible destinations. Rather, it
contains a list of destinations that are next in line to the router. Each router
contains this list. When a packet is received, it's directed to the next network
link (hop), as listed in the table, until it reaches its final destination. The
routing table contains a list of IP addresses, Gateway addresses, and other
information.

Example of Routing Table :

Network destination Netmask Gateway Interface Metric

0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.100 10

127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1

192.168.0.0 255.255.255.0 192.168.0.100 192.168.0.100 10

192.168.0.100 255.255.255.255 127.0.0.1 127.0.0.1 10

192.168.0.1 255.255.255.255 192.168.0.100 192.168.0.100 10

Department Of Computer Engineering


Page |8

Fields of Routing Tables :

1. Network ID:
The network ID or destination corresponding to the route.

2. Subnet Mask:
The mask that is used to match a destination IP address to the network ID.

3. Next Hop:
The IP address to which the packet is forwarded

4. Outgoing Interface:
Outgoing interface the packet should go out to reach the destination
network.

5. Metric:
A common use of the metric is to indicate the minimum number of
hops (routers crossed) to the network ID.

Department Of Computer Engineering


Page |9

Distance Vector Routing

Routing algorithms are software programs that implement different routing protocols.
They work by assigning a cost number to each link; the cost number is calculated using
various network metrics. Every router tries to forward the data packet to the next best link
with the lowest cost.

The Distance vector algorithm is iterative, asynchronous and distributed.

Distributed:
Each node receives information from one or more of its directly attached neighbours,
performs calculation and then distributes the result back to its neighbours.

Iterative:
Its process continues until no more information is available to be exchanged between
neighbours.

Asynchronous:
It does not require that all of its nodes operate in the lock step with each other.

o The Distance vector algorithm is a dynamic algorithm.


o It is mainly used in ARPANET, and RIP.
o Each router maintains a distance table known as Vector.

Distance Vector Routing Algorithm:

1. A router transmits its distance vector to each of its neighbours in a routing packet.

2. Each router receives and saves the most recently received distance vector
from each of its neighbours.

3. A router recalculates its distance vector when:


 It receives a distance vector from a neighbour containing different
information than before.
 It discovers that a link to a neighbour has gone down.

The DV calculation is based on minimizing the cost to each destination

o Dx(y) = Estimate of least cost from x to y

Department Of Computer Engineering


P a g e | 10

o C(x,v) = Node x knows cost to each neighbor v


o Dx = [Dx(y): y ∈ N ] = Node x maintains distance vector
o Node x also maintains its neighbors' distance vectors
– For each neighbor v, x maintains Dv = [Dv(y): y ∈ N ]

When a node x receives new DV estimate from any neighbor v, it saves v’s distance
vector and it updates its own DV using B-F equation :

Dx(y) = min { C(x,v) + Dv(y), Dx(y) } for each node y ∈ N

Department Of Computer Engineering


P a g e | 11
Implementation of Distance Vector Routing

Program:

#include <iostream>
#include <vector>
#include <map>
#include <climits> // Include the header for INT_MAX
using namespace std;

class Router {
private:
int id;
map<int, int> routingTable;

public:
Router(int id) : id(id) {
routingTable[id] = 0; // Distance to itself is 0
}

void updateRoutingTable(int neighborId, int cost) {


routingTable[neighborId] = cost;
}

int getCostTo(int destinationId) {


if (routingTable.find(destinationId) != routingTable.end()) {
return routingTable[destinationId];
} else {
return INT_MAX; // Infinity (unreachable)
}
}

void printRoutingTable() {
cout << "Router " << id << " Routing Table:" << endl;
for (auto entry : routingTable) {
cout << "To " << entry.first << " via " << entry.first << ": " <<
entry.second << endl;
}
}
};
Department Of Computer Engineering
P a g e | 12

int main() {
vector<Router> routers;
int numRouters;

cout << "Enter the number of routers: ";


cin >> numRouters;

// Create routers and initialize their routing tables


for (int i = 1; i <= numRouters; i++) {
routers.push_back(Router(i));
}

// Simulate link costs and update routing tables


for (int i = 0; i < numRouters; i++) {
for (int j = 0; j < numRouters; j++) {
if (i != j) {
int cost;
cout << "Enter cost from Router " << (i + 1) << " to Router " <<
(j + 1) << ": ";
cin >> cost;
routers[i].updateRoutingTable(j + 1, cost);
}
}
}

// Print an overview of the network


cout << "Network Overview:" << endl;
cout << "------------------" << endl;
for (Router& router : routers) {
cout << "Router " << router.getCostTo(1) << " --> ";
}
cout << "Router " << routers[0].getCostTo(numRouters) << endl;
cout << "------------------" << endl;

Department Of Computer Engineering


P a g e | 13

// Print actual network


cout << "Actual Network:" << endl;
cout << "------------------" << endl;
for (int i = 0; i < numRouters; i++) {
for (int j = 0; j < numRouters; j++) {
cout << routers[i].getCostTo(j + 1) << " ";

cout << endl;


}
cout << "------------------" << endl;

// Print routing tables of all routers using asterisks


cout << "Routing Tables:" << endl;
cout << "------------------" << endl;
for (Router& router : routers) {
router.printRoutingTable();
cout << "------------------" << endl;
}

return 0;
}

Department Of Computer Engineering


P a g e | 14

Output

Department Of Computer Engineering


P a g e | 15

Advantages and Disadvantages of Distance Vector


Routing

Advantages:

1.Distance vector routing protocol is easy to implement in small networks;


2.Debugging is very easy in the distance vector routing protocol.
3.This protocol has a very limited redundancy in a small network.

Disadvantage:

1.A broken link between the routers should be updated to every other router in the network
immediately. The distance vector routing takes a considerable time for the update. This
problem is also known as count-to- infinity.
2.The time required by every router in a network to produce an accurate routing table is called
convergence time. In the large and complex network, this time is excessive.
3.Every change in the routing table is propagated to other neighbouring routers periodically
which create traffic on the network.

Department Of Computer Engineering


P a g e | 16

Conclusion

This report includes all the basic knowledge about Routing, types of routing, routing
protocols and algorithms. Need and importance of routing and routing tables are neatly
defined. We studied about the Distance Vector Routing and implemented it by creating
routing tables for the routers using python language. This report can serve as a guide for
learning distance Vector Routing and its implementation.

Reference

 Distance Vector Routing (DVR) Protocol - GeeksforGeeks


 What is Routing - Beginner's Guide to Network Routing - AWS (amazon.com)
 Distance Vector Routing (DVR) Protocol (tutorialspoint.com)
 Computer Network | Distance Vector Routing Algorithm - javatpoint
 Data Communications and Networking – Behrouz A. Forouzan

Department Of Computer Engineering

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy