0% found this document useful (0 votes)
16 views21 pages

CN File

The document is a practical record file for a Computer Networks course, detailing various experiments and topics covered in the curriculum for the academic year 2023-24. Key topics include the OSI and TCP/IP models, network devices, error detection, and network protocols. Each section outlines specific aims, theories, and functionalities related to networking concepts and devices.

Uploaded by

Amit
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)
16 views21 pages

CN File

The document is a practical record file for a Computer Networks course, detailing various experiments and topics covered in the curriculum for the academic year 2023-24. Key topics include the OSI and TCP/IP models, network devices, error detection, and network protocols. Each section outlines specific aims, theories, and functionalities related to networking concepts and devices.

Uploaded by

Amit
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/ 21

Computer Networks

(EAEPC19)
PRACTICAL RECORD FILE
2023-24
Submitted by-

Name: Kumar Samarendra Dev Behera

Roll No.: 2021UEA6521

Branch: ECAM

Section: 1

Semester: 6

Netaji Subhas University of Technology


East Campus, Geeta Colony, New Delhi
INDEX
S.
No. Title Date Sign.
1. To understand OSI Model and TCP/IP Model of Networking. 09.01.2024

To understand about Network Devices used within computer


2. 16.01.2024
networks.

Configure and analyze bus, ring, star, mesh, and hybrid network
3. 16.01.2024
topology with wired v/s wireless networks.

To understand Error Detection and Correction using Hamming


4. 30.01.2024
Code.

5. To study different networking commands. 06.02.2024

To simulate the Go Back N sliding window protocol for flow


6. 13.02.2024
control.

To simulate Selective Repeat ARQ sliding window protocol in


7. 27.02.2024
python.

To analyze Distance Vector Routing Protocol using Routing


8. 12.03.2024
Information Protocol to configure a computer network.
EXPERIMENT 1
AIM: To understand OSI Model and TCP/IP Model of Networking.

THEORY:
Firstly, The OSI (Open Systems Interconnection) model is a conceptual framework that standardizes the
functions of a telecommunication or computing system. These layers enable different networking
technologies and protocols to work together seamlessly. It is divided into seven layers that work together
to carry out specialised network functions, allowing for a more systematic approach to networking. All
these 7 layers work collaboratively to transmit the data from one person to another across the globe.
The model was developed by the International Organization for Standardization (ISO), in the year 1984 to
provide a common understanding and reference for designing and implementing network architectures.

The OSI model consists of seven abstraction


layers arranged in a bottom-up order:
 Physical Layer
 Data Link Layer
 Network Layer
 Transport Layer
 Session Layer
 Presentation Layer
 Application Layer

Here's an overview of the above seven layers of the


OSI model:

1. Physical Layer
Position: Bottom layer. (Layer 1)
Functionality: Deals with the physical connection between devices. It defines the hardware elements, such as
cables, connectors, and transmission media, as well as the electrical and optical signalling used to transmit raw
binary data.
Operation: It transforms binary data into electrical signals for transmission and vice versa. It deals with aspects
such as voltage levels, cable types, and modulation techniques.

2. Data Link Layer:


Position: Above the Physical Layer. (Layer 2)
Functionality: Responsible for creating a reliable link between two directly connected nodes. It involves framing,
addressing, and error detection to ensure the accurate and efficient delivery of data frames over the physical
layer.
Operation: It frames the raw bits into frames, adding necessary header and trailer information. Error detection
and correction mechanisms are employed at this layer to ensure data integrity. The Data Link Layer also
manages access to the physical medium, often using protocols like Ethernet for local area networks.

3. Network Layer:
Position: Above the Data Link Layer. (Layer 7)
Functionality: Focuses on logical addressing, routing, and forwarding of data packets between devices on
different networks. It allows data to traverse multiple networks, making it a critical layer for internetwork
communication.
Operation: The Network Layer encapsulates data into packets, adding headers that include source and
destination IP addresses. Routers operate at this layer, using logical addressing to forward packets between
networks.
4. Transport Layer:
Position: Above the Network Layer. (Layer 7)
Functionality: Ensures endtoend communication, providing error detection, correction, and flow control. It is
responsible for breaking down large messages into smaller segments, managing their reliable delivery, and
reassembling them at the destination.
Operation: It adds a transport layer header to each segment, including information like source and destination
port numbers. Protocols like TCP provide reliable, connection-oriented communication, while UDP offers a
connectionless, lightweight option.

5. Session Layer:
Position: Above the Transport Layer. (Layer 7)
Functionality: Manages the establishment, maintenance, and termination of communication sessions between
applications. It handles session synchronization, dialog control, and token management to facilitate organized
and efficient communication.
Operation: It sets up, coordinates, and terminates sessions, providing synchronization points during data
exchange. Checkpointing and recovery mechanisms help manage ongoing sessions, ensuring data consistency.

6. Presentation Layer:
Position: Above the Session Layer. (Layer 7)
Functionality: Deals with data translation, encryption, and compression to ensure that information sent from
one system can be properly understood by the receiving system. It is responsible for data format conversion and
manages the syntax and semantics of the exchanged information.
Operation: Data is translated into a standard format for transmission. Compression reduces the amount of data,
and encryption secures sensitive information. This layer ensures that data from the application layer can be
properly interpreted by the receiving device.

7. Application Layer:
Position: Top layer. (Layer 7)
Functionality: Provides network services directly to endusers or applications. It includes protocols for tasks such
as email, file transfer, and remote login. This layer represents the interface between the network and the user's
software applications.
Operation: This layer interacts directly with end-user applications, facilitating network services such as file
transfers (FTP), email (SMTP), and remote login (SSH). It encapsulates application-specific data for transmission.
ENCAPSULATION AND DE-CAPSULATION PROCESS
Encapsulation and de-encapsulation are fundamental processes that occur at different layers of the OSI
(Open Systems Interconnection) model during the transmission of data over a network. These processes
play a crucial role in organizing and delivering information between devices.

 Encapsulation Process:
It involves adding protocol-specific headers
and trailers to data as it moves down the
OSI model layers before transmission.

 De-Encapsulation Process:
It involves stripping off the headers and
trailers added during encapsulation as data
moves up the OSI model layers upon
reception.

Steps in Encapsulation: 7. Physical Layer (Layer 1):


1. Application Layer (Layer 7): The data link layer frame is converted into electrical
Data generated by the application is prepared for or optical signals suitable for transmission over the
transmission. physical medium (cables, fibers, etc.).

2. Presentation Layer (Layer 6): Steps in De-Encapsulation:


The data may undergo translation, encryption, or 1. Physical Layer (Layer 1):
compression to ensure that it can be properly The received electrical or optical signals are converted
understood by the receiving system. into a data link layer frame.

3. Session Layer (Layer 5): 2. Data Link Layer (Layer 2):


The session layer manages the establishment, The data link layer header and trailer are removed,
maintenance, and termination of communication leaving the encapsulated network layer packet.
sessions, if necessary.
3. Network Layer (Layer 3):
4. Transport Layer (Layer 4): The network layer header is removed, revealing the
The data is segmented into smaller units or packets, encapsulated transport layer packet.
and a transport layer header is added. This header
includes information such as source and destination 4. Transport Layer (Layer 4):
port numbers, sequence numbers, and error-checking The transport layer header is removed, exposing the
data. original data segments.

5. Network Layer (Layer 3): 5. Session Layer (Layer 5):


The transport layer packet is further encapsulated If any session layer functions were applied during
into a network layer packet by adding a network layer encapsulation, they are reversed.
header. This header includes source and destination
IP addresses and routing information. 6. Presentation Layer (Layer 6):
If any presentation layer functions were applied
6. Data Link Layer (Layer 2): during encapsulation, they are reversed.
The network layer packet is encapsulated into a data
link layer frame by adding a data link layer header and 7. Application Layer (Layer 7):
trailer. This header includes MAC addresses for the The final, original data is presented to the receiving
source and destination devices. application.
TCP/IP Model
The TCP/IP (Transmission Control Protocol/Internet Protocol) model is a
networking framework that defines the rules and standards for communication
between devices on a network. It serves as the basis for the Internet and many other
networks. The TCP/IP model is not as strictly defined as the OSI model but provides a
more practical and widely implemented approach to networking.
It consists of four layers (Application, Transport, Internet, and Link layers) that
collectively govern how data is transmitted, routed, and received across networks,
with each being responsible for specific functions in the transmission and reception
of data:

1. Application Layer:
Functionality: The topmost layer of the TCP/IP model is the Application Layer, which deals with communication
between applications and the network. It includes protocols such as HTTP (Hypertext Transfer Protocol), FTP
(File Transfer Protocol), SMTP (Simple Mail Transfer Protocol), and DNS (Domain Name System). This layer
handles user interfaces and data exchange between applications.

2. Transport Layer:
Functionality: The Transport Layer ensures end-to-end communication between devices. It is responsible for
segmenting and reassembling data into packets for transmission. The two main protocols at this layer are TCP
(Transmission Control Protocol) and UDP (User Datagram Protocol). TCP provides reliable, connection-oriented
communication with features like error detection, flow control, and retransmission of lost packets, while UDP
offers faster, connectionless communication without reliability mechanisms.

3. Internet Layer:
Functionality: The Internet Layer, also known as the Network Layer in the OSI model, is responsible for routing
packets across different networks to their destinations. It uses IP (Internet Protocol) to address and route
packets based on their IP addresses. The Internet Layer enables internetworking by connecting disparate
networks and facilitating the exchange of data between them.

4. Link Layer:
Functionality: The Link Layer, also referred to as the Network Interface Layer or Data Link Layer in the OSI
model, deals with the physical connection between devices on the same network segment. It includes protocols
such as Ethernet, Wi-Fi, and PPP (Point-to-Point Protocol), which define how data is formatted for transmission
over specific types of physical media. The Link Layer is responsible for addressing devices on the local network
and managing access to the physical medium.

Key Features of the TCP/IP Model:


 Simplified Structure: The TCP/IP model consists of four layers, compared to the seven layers of the OSI model,
making it simpler to understand and implement.
 Flexibility: TCP/IP is highly adaptable and can be used in various network environments, including the Internet,
intranets, and local area networks (LANs).
 Scalability: TCP/IP supports scalable network architectures, allowing networks to grow and accommodate
increasing traffic and devices.
 Wide Adoption: TCP/IP is the foundation of the Internet and is widely adopted in networking technologies,
making it a de facto standard for network communication.
DIFFERENCE BETWEEN OSI MODEL AND TCP/IP MODEL
The OSI (Open Systems Interconnection) model and the TCP/IP (Transmission Control Protocol/Internet Protocol)
model are both conceptual frameworks used to understand and implement network communications, but they
differ in structure and scope. The OSI model consists of seven layers, offering a comprehensive and theoretical
approach to networking, while the TCP/IP model is more pragmatic, comprising four layers that closely reflect the
actual implementation of networking protocols, particularly on the Internet. The OSI model provides a standardized
reference for understanding network protocols and interactions, while the TCP/IP model, being more widely
implemented, serves as the de facto standard for networking, especially in Internet-based environments. Despite
their differences, both models offer valuable insights into network architecture and communication protocols.
EXPERIMENT 2
AIM: To understand about Network Devices used within computer networks.

THEORY:
Network devices are essential components of computer networks, facilitating communication and data exchange
between devices within a network and beyond. Routers intelligently direct data packets between different networks,
switches efficiently forward data within a local network, and hubs, though less common now, simply repeat signals
to connected devices. While modems enable digital communication over analog infrastructure, bridges connect
multiple LAN segments, and repeaters amplify signals to extend network reach. Additionally, network interface cards
(NICs) serve as interfaces between devices and the network, allowing computers to connect to and communicate
over the network by translating digital data from the computer into signals that can be transmitted over network
cables or wirelessly. Together, these devices form the infrastructure that powers modern communication and
connectivity.

Some network devices are:


1. Router:
A router is a critical networking device responsible for directing data packets between
different computer networks. It serves as a traffic cop, determining the best path for data to
travel based on network conditions and routing tables. A router is often referred to as an
"intelligent switch" due to its advanced capabilities in directing data packets between
different networks based on various factors such as network congestion, quality of service
requirements, and security policies. Unlike switches, which primarily operate at the data link
layer (Layer 2) and make forwarding decisions based on MAC addresses, routers operate at
the network layer (Layer 3) of the OSI model and use routing tables and algorithms to
determine the best path for data transmission based on IP addresses. This intelligence allows routers to efficiently
manage traffic between networks, optimize network performance, and provide additional functionalities such as
network address translation (NAT) and firewall services.

2. Switch:
Switches are fundamental to local area networks (LANs) as they facilitate
communication among devices within the same network. Operating at the data link
layer (Layer 2) of the OSI model, switches use MAC addresses to efficiently forward data
packets to their intended destinations. Unlike hubs, which broadcast data to all
connected devices, switches intelligently learn the MAC addresses of connected devices
and build a MAC address table to make forwarding decisions. This results in improved
network performance by reducing unnecessary network traffic and collisions.

3. Hub:
Hubs, while less commonly used in modern networks, are basic networking devices that operate
at the physical layer (Layer 1) of the OSI model. They serve as simple signal repeaters,
broadcasting data received from one connected device to all other connected devices. Unlike
switches, hubs lack intelligence and do not differentiate between devices, leading to increased
network congestion and reduced efficiency. Due to their limitations, hubs have largely been
replaced by switches in most network deployments.
4. Modem:
Modems, short for modulator-demodulators, are devices that modulate analog signals from a
computer or network into digital signals for transmission over analog communication lines,
such as telephone lines or coaxial cables. On the receiving end, modems demodulate incoming
digital signals back into analog signals interpretable by the receiving device. They enable digital
communication over analog infrastructure and are commonly used for internet connectivity
over DSL (Digital Subscriber Line) or cable broadband connections.

5. Network Bridge:
Network bridges are devices that connect multiple network segments or LANs together
and forward traffic between them based on MAC addresses. Operating at the data link
layer (Layer 2) of the OSI model, bridges effectively extend a LAN by interconnecting
multiple LAN segments while maintaining a single logical network. Unlike routers, which
operate at the network layer and make forwarding decisions based on IP addresses,
bridges focus on MAC addresses and are commonly used to segment LANs, reduce
network congestion, and improve network performance.

6. Network Repeater:
Network repeaters are devices used to regenerate or replicate signals in a network, effectively
extending the distance a signal can travel without degradation. Operating at the physical layer
(Layer 1) of the OSI model, repeaters amplify signals before retransmitting them; allowing data
to traverse longer distances over network cables or media. They play a vital role in overcoming
signal attenuation and maintaining signal integrity in large networks or environments with long
cable runs, such as Ethernet LANs or fiber optic networks.

7. Network Interface Card (NIC):


A Network Interface Card (NIC), also known as a network adapter or LAN adapter, is a
hardware component that enables a computer or device to connect to a network. NICs are
installed internally in computers or externally as peripheral devices and facilitate
communication between the device and the network by providing a physical connection,
typically through Ethernet, Wi-Fi, or other network interfaces. NICs handle the
transmission and reception of data packets, converting digital data produced by the device
into signals suitable for transmission over the network medium and vice versa. They play a crucial role in enabling
devices to access and participate in local area networks (LANs) or connect to the internet, serving as the interface
between the device's internal processing capabilities and the external network infrastructure.
EXPERIMENT 3
AIM: Configure and analyze bus, ring, star, mesh, and hybrid network topology with wired v/s wireless networks.

THEORY:
Network topology refers to the layout of devices and connections within a computer network. Wired
networks utilize physical cables like Ethernet or fiber optics to connect devices, commonly employing star,
bus, or ring topologies. These configurations offer reliability and high bandwidth but may lack mobility. In
contrast, wireless networks transmit data through radio waves, using infrastructure, ad-hoc, or mesh
topologies. While wireless networks provide mobility and easy setup, they may face interference and
security concerns. The choice between wired and wireless topologies depends on factors such as cost,
scalability, and specific network requirements.

CODE:
import networkx as nx
import matplotlib.pyplot as plt
# Create a bus network
bus_nodes = 6
bus_edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
G_bus = nx.Graph(bus_edges)
plt.subplot(2, 3, 1)
nx.draw(G_bus, with_labels=False, node_color='r', edge_color='b')
plt.title('Bus Topology')

# Create a ring network


ring_nodes = 6
ring_edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1)]
G_ring = nx.Graph(ring_edges)
plt.subplot(2, 3, 2)
nx.draw(G_ring, with_labels=False, node_color='g', edge_color='m')
plt.title('Ring Topology')

# Create a star network


star_nodes = 6
star_edges = [(1, 2), (1, 3), (1, 4), (1, 5), (1, 6)]
G_star = nx.Graph(star_edges)
plt.subplot(2, 3, 3)
nx.draw(G_star, with_labels=False, node_color='b', edge_color='k')
plt.title('Star Topology')

# Create a mesh network


mesh_nodes = 6
mesh_edges = [(1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 3), (2, 4), (2, 5), (2, 6),
(3, 1), (3, 2), (3, 4), (3, 5), (3, 6), (4, 1), (4, 2), (4, 3), (4, 5), (4, 6),
(5, 1), (5, 2), (5, 3), (5, 4), (5, 6)]
G_mesh = nx.Graph(mesh_edges)
plt.subplot(2, 3, 4)
nx.draw(G_mesh, with_labels=False, node_color='m', edge_color='c')
plt.title('Mesh Topology')
# Create a hybrid network (combination of star and mesh)
hybrid_edges = [(1, 2), (1, 3), (1, 4), (1, 5), (2, 6), (3, 6), (4, 6), (5, 6)]
G_hybrid = nx.Graph(hybrid_edges)
plt.subplot(2, 3, 5)
nx.draw(G_hybrid, with_labels=False, node_color='c', edge_color='r')
plt.title('Hybrid Topology')

# Adjust figure properties


plt.subplots_adjust(wspace=0.4, hspace=0.4)
plt.gcf().set_size_inches(12, 6)
plt.suptitle('Network Topologies Visualization')
plt.show()

OUTPUT:
EXPERIMENT 4
AIM: To understand Error Detection and Correction using Hamming Code.

THEORY:
The Hamming code implements a simple error detection and correction scheme known as parity coding. Initially, a 4-
bit data vector is encoded into a 7-bit codeword, where specific bits (P1, P2, and P4) are used as parity bits to detect
errors. Subsequently, a random bit in the encoded data is flipped to simulate an error. Error correction is then
attempted by recalculating the parity bits and identifying the error position based on their values. Once the error
position is determined, the erroneous bit is corrected, and the decoded data is obtained. Parity coding works by
adding extra bits (parity bits) to the data, allowing the detection and correction of single-bit errors.

CODE:
data = [1 0 1 1]
% Initialize the encoded vector with zeros
encoded = zeros(1, 7);

% Position grouping (P1, P2, P4 are parity bits)


encoded(1) = data(1);
encoded(2) = data(2);
encoded(3) = data(3);
encoded(4) = mod(data(1) + data(2) + data(3), 2);
encoded(5) = data(4);
encoded(6) = mod(data(1) + data(2) + data(4), 2);
encoded(7) = mod(data(1) + data(3) + data(4), 2);
disp('The Encoded Data');
disp(encoded);
% Simulate an error by flipping a random bit
errorPosition = randi(7);
encoded(errorPosition) = mod(encoded(errorPosition) + 1, 2);
disp('Received Data with error');
disp(encoded);

% Correct errors using position grouping


decoded = zeros(1, 4);
error = zeros(1, 3);
error(1) = mod(encoded(1) + encoded(2) + encoded(3) + encoded(4),2);
error(2) = mod(encoded(1) + encoded(2) + encoded(5) + encoded(6),2);
error(3) = mod(encoded(1) + encoded(3) + encoded(5) + encoded(7),2);
n = length(error);
Pno = 0;
for i = 1:n
Pno = Pno + error(i)*2^(n-i);
end

disp('The error position is');


disp(Pno);
new = encoded(end:-1:1);
if new(Pno)==0
new(Pno) = 1;
else
new(Pno) = 0;
end
final = new(end:-1:1);
decoded(1) = final(1);
decoded(2) = final(2);
decoded(3) = final(3);
decoded(4) = final(5);

disp('The decoded data is');


disp(decoded);
OUTPUT:
EXPERIMENT 5
AIM: To study different networking commands.

THEORY:
Networking commands are essential tools used in command-line interfaces (CLI) to manage, monitor, and
troubleshoot computer networks. They provide users with the ability to retrieve detailed information about network
configuration, diagnose connectivity issues, and perform administrative tasks.

1. ipconfig (Windows) / ifconfig (Linux/macOS):


- Function: Display network interface configuration information, including IP addresses, subnet masks, default
gateways, and MAC addresses.
- Usage: Used to view and manage network settings on local machines.

2. ping:
- Function: Send ICMP echo request packets to a specified destination to test network connectivity and measure
round-trip time.
- Usage: Used to check if a remote host is reachable and to diagnose network latency issues.

3. tracert (Windows) / traceroute (Linux/macOS):


- Function: Trace the route taken by packets from the local system to a specified destination, showing each hop
along the way.
- Usage: Used to identify network congestion, routing issues, and latency problems.
These networking commands provide users with powerful tools for managing and troubleshooting computer
networks. By understanding their functionalities and how to use them effectively, network administrators and users
can diagnose and resolve a wide range of network issues, ensuring optimal network performance and reliability.

IPCONFIG:
PING:

TRACET:
EXPERIMENT 6
AIM: To simulate the Go Back N sliding window protocol for flow control.

THEORY:
The Go Back N sliding window protocol is a flow control mechanism used in data communication networks.
It operates by allowing the sender to transmit a window of frames consecutively without waiting for
acknowledgment from the receiver. The receiver acknowledges the receipt of frames up to a certain
sequence number, enabling the sender to slide the window forward. However, if an acknowledgment is
not received within a certain timeout period or if a frame is lost or corrupted, the sender retransmits all
frames starting from the one that was not acknowledged. This protocol efficiently utilizes network
resources by ensuring a steady flow of data while handling potential errors or network congestion
effectively.

CODE:
import random
n = int(input('Number of frames: '))
w = int(input('Window size: '))
pt = 1
flag = False
while not flag:
for i in range(pt, min(pt+w, n+1)):
print('Frame', i, 'transmitted')
s = random.randint(1, 10)
if s > 3:
print('PAK of frame', pt, 'received')
pt += w
if pt > n:
flag = True
else:
print('NAK of frame', pt, 'received')
for j in range(pt, min(pt+w, n+1)):
print('Frame', j, 'discarded')
i=n-w+1
while i <= n:
s = random.randint(1, 10)
if s > 4:
print('PAK of frame', i, 'received')
i += 1
else:
print('NAK of frame', i, 'received')
for j in range(1, n+1):
print('Frame', j, 'discarded')
for k in range(1, n+1):
print('Frame', k, 'transmitted')
break
OUTPUT:
EXPERIMENT 7
AIM: To simulate Selective Repeat ARQ sliding window protocol in python.

THEORY:
Selective Repeat Automatic Repeat reQuest (ARQ) is a sliding window protocol used in computer networks
to ensure reliable data transmission over unreliable channels. Unlike other ARQ protocols, such as Go-
Back-N, Selective Repeat ARQ retransmits only the packets that are damaged or lost, rather than
retransmitting the entire window. This reduces unnecessary retransmissions and improves efficiency. In
Selective Repeat ARQ, both sender and receiver maintain a window of sequence numbers to track the sent
and received packets. Upon receipt of packets, the receiver acknowledges them individually, allowing the
sender to retransmit only the missing or damaged packets. This protocol enhances network performance
by minimizing the impact of errors and congestion while maximizing throughput.

CODE:
import random
n = int(input('Enter the number of frames: '))
w = int(input('Window size: '))
pt = w + 1
flag = False
ext = 0
flag1 = False
flag2 = False
a = list(range(1, n+1))
for i in range(1, w+1):
print('Frame', a[i-1], 'transmitted')
while not flag:
s = random.randint(1, 10)
if s > 3:
print('PAK of frame', a[pt - w - 1], 'received')
else:
print('NAK of frame', a[pt - w - 1], 'received')
ext += 1
a.insert(pt - 1, a[pt - w - 1])
print('Frame', a[pt - 1], 'transferred')
if a[pt - 1] == n:
flag = True
pt += 1
k = pt - w
while not flag2:
test = random.randint(1, 17)
if flag1:
print('Frame', a[k - 1], 'transmitted')
flag1 = False
if test > 3:
print('PAK of frame', a[k - 1], 'received')
k += 1
else:
print('NAK of frame', a[k - 1], 'received')
flag1 = True
if k >= n + ext + 1:
flag2 = True
OUTPUT:
EXPERIMENT 8
AIM: To analyze Distance Vector Routing Protocol using Routing Information Protocol to configure a computer
network.

THEORY:
Distance Vector Routing Protocol, utilizing the Routing Information Protocol (RIP), operates on the
principle of exchanging routing information between neighboring routers within a computer network. Each
router maintains a table containing the distance (metric) to reachable network destinations and forwards
this information to its neighboring routers periodically. RIP employs the Bellman-Ford algorithm to
calculate the shortest path to each destination based on hop count. Despite its simplicity, RIP's periodic
updates and reliance on hop count can lead to slow convergence and potential routing loops in larger
networks. Nonetheless, in small-scale environments, where network topology changes infrequently, RIP
remains a straightforward and viable option for configuring routing tables and ensuring efficient data
transmission within the network. Its ease of implementation and minimal configuration overhead make it
particularly suitable for smaller networks or for educational purposes, providing a foundational
understanding of routing protocols. However, its limitations become apparent in larger, more dynamic
networks, where more sophisticated routing protocols such as OSPF or EIGRP are preferred for their faster
convergence and greater flexibility.

CODE:
import numpy as np
# Initialize network parameters
Nodes = 5 # Number of nodes in the network
Itr = 10 # Number of iterations for routing table updates
Maxhop = 15 # Maximum number of hops allowed

# Initialize routing tables for each node [Destination Node, Next Hop, Distance, Sequence Number]
rt = {}
for node in range(1, Nodes + 1):
rt[node] = np.array([[node, node, 0, 0]]) # Initialize with self-entry

# Simulate routing table updates


for iter in range(1, Itr + 1):
print(f"Iteration: {iter}")
# Update routing tables for each node
for node in range(1, Nodes + 1):
# Generate random updates for simplicity
destNode = np.random.randint(1, Nodes + 1) # Random destination node
dist = np.random.randint(1, Maxhop + 1) # Random distance/hops
seqNum = np.random.randint(1, 101) # Random sequence number

# Check if destination node entry exists in routing table


destIndex = np.where(rt[node][:, 0] == destNode)[0]
if destIndex.size == 0: # New entry for destination node
newEntry = np.array([[destNode, destNode, dist, seqNum]])
rt[node] = np.concatenate((rt[node], newEntry), axis=0)
else:

# Update existing entry if necessary (based on sequence number)


if seqNum > rt[node][destIndex, 3]: # Newer sequence number
rt[node][destIndex, 1] = destNode # Update next hop
rt[node][destIndex, 2] = dist # Update distance
rt[node][destIndex, 3] = seqNum # Update sequence number

# Display final routing tables


for node in range(1, Nodes + 1):
print(f"Routing Table for Node {node}")
print("----------------------------------------")
print("[Dest Node | Next Hop | Distance | Seq Num]")
print(rt[node])
print("----------------------------------------")

OUTPUT:

You might also like