CN FILE

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

COMPUTER NETWORKS LAB

ETCS365A

Submitted to: Submitted by:


Ms. Mansi Kajal Mohit Sharma
2201010132
B.Tech(CSE)
5th semester

TEACHER SIGN. STUDENT SIGN.


INDEX

S.NO. Topic Date Sign


1. Study of following 03-09-24
Network Devices in Detail
And Installation of Cisco
Packet Tracer
2. Connecting Computers in 10-09-24
a Local Area Network
(LAN) using Cisco Packet
Tracer
3. Creation of Different 17-09-24
Network Topologies using
Cisco Packet Tracer

4. Implementation of Data 24-09-24


Link Framing Method -
Character Count

5. Implementation of Data 01-10-24


Link Framing Method – Bit
Stuffing and Destuffing

6. Implementation of Error 15-10-24


Detection Methods Using
Even and Odd Parity
7. Simulation of Flow 22-10-24
Control and Error Control
Protocols
8. Simulate multiple access 05-11-24
protocols such as Pure
ALOHA, Slotted ALOHA,
CSMA/CD, and CSMA/CA
using Cisco Packet Tracer.

9. Sliding Window Protocol 12-11-24


with Piggybacking
10. Logical Addressing using 19-11-24
IPv4 and IPv6

11. Comparison of UDP, TCP, 19-11-24


and SCTP
Experiment – 1

Aim: Study of following Network Devices in Detail And Installation of Cisco Packet
Tracer Cisco Packet Tracer
• Repeater
• Hub
• Switch
• Bridge
• Router
• Gateway
Apparatus: No software or hardware needed.
1. Repeater: Functioning at Physical Layer. Repeater is an electronic device that receives a
signal and retransmits it at a higher level and/or higher power, or onto the other side of an
obstruction, so that the signal can cover longer distances. Repeater have two ports ,so cannot
be use to connect for more than two devices

2. Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator is a
device for connecting multiple twisted pair or fiber optic Ethernet devices together and
making them act as a single network segment. Hubs work at the physical layer (layer 1) of the
OSI model. The device is a form of multiport repeater. Repeater hubs also participate in
collision detection, forwarding a jam signal to all ports if it detects a collision.

3. Switch: Network switch or switching hub is a computer networking device that connects
network segments. The term commonly refers to a network bridge that processes and routes
data at the data link layer (layer 2) of the OSI model. Switches that additionally process data
at the network layer (layer 3 and above) are often referred to as Layer 3 switches or
multilayer switches.

1
4. Bridge: A network bridge connects multiple network segments at the data link layer
(Layer 2) of the OSI model. In Ethernet networks, the term bridge formally means a device
that behaves according to the IEEE 802.1D standard. A bridge and switch are very much
alike; a switch being a bridge with numerous ports. Switch or Layer 2 switch is often used
interchangeably with bridge .Bridges can analyse incoming data packets to determine if the
bridge is able to send the given packet to another segment of the network.

5. Router: A router is an electronic device that interconnects two or more computer


networks, and selectively interchanges packets of data between them. Each data packet
contains address information that a router can use to determine if the source and destination
are on the same network, or if the data packet must be transferred from one network to
another. Where multiple routers are used in a large collection of interconnected networks, the
routers exchange information about target system addresses, so that each router can build up
a table showing the preferred paths between any two systems on the interconnected networks.

6. Gateway: In a communications network, a network node equipped for interfacing with


another network that uses different protocols.
● A gateway may contain devices such as protocol translators, impedance matching
devices, rate converters, fault isolators, or signal translators as necessary to provide
system interoperability. It also requires the establishment of mutually acceptable
administrative procedures between both networks.
● A protocol mapping gateway interconnects networks with different network protocol
technologies by performing the required protocol conversions.

2
Install Cisco Packet Tracer

1. Download Cisco Packet Tracer


● Visit Cisco Networking Academy: Go to the Cisco Networking Academy website
(netacad.com). You’ll need to sign in with your Cisco account. If you don't have one,
you’ll need to create it.
● Access Packet Tracer: Once logged in, navigate to the "Resources" or "Downloads"
section.
● Download the Installer: Find Cisco Packet Tracer in the list of available software and
download the version compatible with Windows.

3
2. Install Cisco Packet Tracer
● Run the Installer: Once the download is complete, locate the installer file (usually
ends with `.exe`) and double-click it to start the installation process.
● Complete Installation**: After the installation is complete, click “Finish.” You might
need to restart your computer, but it’s usually not necessary.

3. Set Up the Lab Manual


● 1. Obtain the Lab Manual: If you have a specific lab manual, it may be available
through your course or institution. Download it from your course resources or obtain
it directly from your instructor.
● 2. Accessing the Manual: The manual may be a PDF or a document file. Save it to a
convenient location on your computer.
● 3. Follow the Instructions: Open the lab manual and follow the instructions provided.
The manual will guide you on how to set up labs, configure devices, and complete
exercises using Packet Tracer

4. Launch Packet Tracer and Start Working


● Open Packet Tracer: Find Cisco Packet Tracer in your Start Menu or desktop shortcut
and open it.
● Start a New Project: Use the “File” menu to start a new project or open existing
Packet Tracer files.
● Follow Lab Exercises: Use the lab manual to guide you through setting up network
topologies and configurations.

4
EXPERIMENT-2

Aim: Connecting Computers in a Local Area Network (LAN) using Cisco Packet Tracer
Apparatus: Cisco Packet Tracer Software Required
Below is a step-by-step guide to creating a basic LAN with two or more computers connected
to a switch in Cisco Packet Tracer:

1. Launch Cisco Packet Tracer


● Open Cisco Packet Tracer from your desktop or applications menu.
● You will be prompted to log in with your Cisco Networking Academy credentials, or
you can use the Guest Login with limited functionality.

2. Add Network Devices (PCs and Switch)


Steps:

1. Choose End Devices:


○ In the Devices Types section on the left, click the End Devices icon
(represented by a monitor).
○ From the device list that appears, select a PC (Personal Computer).
○ Click on the workspace to place two or more PCs.
2. Choose Networking Device (Switch):
○ In the Devices Types section, click on the Switches icon (represented by a
square with arrows).
○ Choose a simple switch (e.g., 2960-24TT switch).
○ Place the switch on the workspace by clicking on the canvas.

3. Connect Devices Using Copper Straight-Through Cables


To connect computers to the switch, use Copper Straight-Through cables.

Steps:

1. Click on the Connections icon (represented by a lightning bolt) in the toolbar.

5
2. Select the Copper Straight-Through cable (second option under the Connections
icon).
3. Click on the first PC and select the FastEthernet0 interface.
4. Click on the switch and select one of the available FastEthernet ports (e.g.,
FastEthernet0/1).
5. Repeat the above steps to connect the second PC to another port on the switch (e.g.,
FastEthernet0/2).

4. Configure IP Addresses for the PCs

In a LAN, each device must have a unique IP address within the same subnet to communicate
with each other.

Steps:

1. Click on the first PC to open its configuration window.


2. In the Config tab, navigate to FastEthernet0 under the INTERFACE section.
3. Assign the following details:
○ IP Address: 192.168.1.2
○ Subnet Mask: 255.255.255.0
4. Repeat the process for the second PC, but assign a different IP address, such as:
○ IP Address: 192.168.1.3
○ Subnet Mask: 255.255.255.0

Make sure both PCs are in the same subnet (i.e., the first three octets 192.168.1.x should
be the same).

5. Test Connectivity with Ping Command


After setting up the network, you can test connectivity between the computers by using the
ping command.

Steps:

1. Click on the first PC.


2. Go to the Desktop tab and open the Command Prompt.

Type the following command to ping the second PC:


bash
Copy code
ping 192.168.1.3

3.
4. If the network is set up correctly, you should see successful replies from the second

6. Save the Project

Once your LAN is set up and verified, it is important to save your work.

Steps:

6
1. Go to File in the top menu.
2. Click Save As, and name the project (e.g., "LAN_Simulation").
3. Choose a location to save the file.

7
Experiment -3

Aim : Creation of Different Network Topologies using Cisco Packet Tracer


Objective: To implement and understand the working of different types of network
topologies using Cisco Packet Tracer and configure them with appropriate IP addressing and
default gateway settings.
1. Star Topology
Overview: In a Star Topology, all devices are connected to a central switch. This topology
is commonly used in Local Area Networks (LANs).
Steps to Create a Star Topology in Cisco Packet Tracer:
Add Devices:
Drag and drop one Switch and 3-6 PCs onto the workspace.
Connect Devices:
Use the Copper Straight-Through Cable to connect each PC to the switch. The connections should be:
PC1 → Switch
PC2 → Switch
PC3 → Switch (and so on for additional devices).
Assign IP Addresses:
Click on each PC, go to the Desktop tab, and assign unique IP addresses in the same subnet. For
example:
PC1: 192.168.1.2
PC2: 192.168.1.3
PC3: 192.168.1.4
Set the Same Default Gateway:
Set the default gateway
for all PCs to the router's IP. For example:
Default Gateway: 192.168.1.1
Test Connectivity:
Open the Command Prompt in any PC and use the ping command to test connectivity between the
devices:
ping 192.168.1.3

8
2. Ring Topology
Overview: In a Ring Topology, each device is connected to exactly two other devices,
forming a circular network. Data travels in one direction around the ring.
Steps to Create a Ring Topology in Cisco Packet Tracer:
Add Devices:
Drag and drop 4-6 PCs onto the workspace.
Connect Devices:
Use Copper Crossover Cables to connect the PCs in a circular fashion:
PC1 → PC2
PC2 → PC3
PC3 → PC4 (and so on, depending on the number of PCs).
Finally, connect the last PC back to the first PC to complete the ring:
PC4 → PC1.
Assign IP Addresses:
Assign unique IP addresses to each PC. For example:
PC1: 192.168.2.1
PC2: 192.168.2.2
PC3: 192.168.2.3
Set the Same Default Gateway:
Set the default gateway for all PCs to the same value. For example:
Default Gateway: 192.168.2.1
Test Connectivity:

9
Use the ping command from one PC to another to verify connectivity:
ping 192.168.2.2

3. Bus Topology
Overview: In a Bus Topology, all devices are connected to a single backbone cable
(represented as a hub in Packet Tracer). Data travels along this single cable.
Steps to Create a Bus Topology in Cisco Packet Tracer:
Add Devices:
Drag and drop 3-6 PCs onto the workspace.
Use a Hub:
Drag and drop a Hub (which represents the bus) onto the workspace.
Connect Devices:
Use Copper Straight-Through Cables to connect each PC to the Hub.
Assign IP Addresses:
Assign unique IP addresses to each PC in the same subnet. For example:
PC1: 192.168.3.1
PC2: 192.168.3.2
PC3: 192.168.3.3
Set the Same Default Gateway:
Set the same default gateway for all PCs. For example:
Default Gateway: 192.168.3.1

10
Test Connectivity:
Use the ping command to verify connectivity between the PCs:
ping 192.168.3.2

4. Mesh Topology
Overview: In a Mesh Topology, every device is connected to every other device. This
topology is highly reliable because multiple paths exist for data to travel.
Steps to Create a Mesh Topology in Cisco Packet Tracer:
Add Devices:
Drag and drop 3-4 PCs onto the workspace.
Connect Devices:
Use Copper Crossover Cables to connect each PC to every other PC:
PC1 → PC2
PC1 → PC3
PC2 → PC3 (and so on for additional PCs).
Assign IP Addresses:
Assign unique IP addresses to each PC in the same subnet. For example:
PC1: 192.168.4.1
PC2: 192.168.4.2
PC3: 192.168.4.3
Set the Same Default Gateway:
Set the same default gateway for all PCs. For example:
Default Gateway: 192.168.4.1
Test Connectivity:
Use the ping command to verify that all devices can communicate:

11
ping 192.168.4.2

5. Hybrid Topology
Overview:
A Hybrid Topology is a combination of two or more topologies. For example, you could
combine a Star and Bus topology for greater flexibility.
Steps to Create a Hybrid Topology in Cisco Packet Tracer:
Add Devices:
Drag and drop 1-2 switches, a hub, and several PCs onto the workspace.
Create the Star Part:
Connect the PCs to the switches using Copper Straight-Through Cables.
Create the Bus Part:
Connect several other PCs to the Hub using Copper Straight-Through Cables.
Interconnect the Switches and Hub:
Use Copper Crossover Cables to connect the switches and the hub.
Assign IP Addresses:
Assign unique IP addresses to each PC in the same subnet. For example:
PC1: 192.168.5.1
PC2: 192.168.5.2
PC3: 192.168.5.3
Assign IP Addresses:
Assign unique IP addresses to each PC in the same subnet. For example:
PC1: 192.168.5.1

12
PC2: 192.168.5.2
PC3: 192.168.5.3
Set the Same Default Gateway:
Set the same default gateway for all PCs. For example:
Default Gateway: 192.168.5.1
Test Connectivity:
Use the ping command to verify that devices can communicate across both the star and bus
sections of the hybrid network.

6. Tree Topology
Overview: A Tree Topology is a hierarchical arrangement of devices, where multiple star
topologies are interconnected.
Steps to Create a Tree Topology in Cisco Packet Tracer:
Add Devices:
Drag and drop 2-3 switches and 6-9 PCs onto the workspace.
Connect Devices:
Use Copper Straight-Through Cables to connect each switch to a root switch.
Connect each PC to its corresponding switch.
Assign IP Addresses:
Assign unique IP addresses to each PC in the same subnet. For example:
PC1: 192.168.6.1
PC2: 192.168.6.2
PC3: 192.168.6.3
Set the Same Default Gateway:
Set the same default gateway for all PCs. For example:
Default Gateway: 192.168.6.1
Test Connectivity:
Use the ping command to ensure that all PCs can communicate across the different switches:
ping 192.168.6.2

13
14
EXPERIMENT-4

Implementation of Data Link Framing Method - Character Count


Aim: Simulate a simple Data Link layer framing technique using the Character Count
method.

Step-by-Step Guide:
Step 1: Understanding Character Count Framing
Character Count Framing method is a data link layer protocol where the first byte of a frame
specifies the number of characters in the frame.
For example:
Frame 1: [5 H E L L O]
Here, the first byte (5) indicates that the frame contains 5 characters.
Step 2: Create a Network with Two PCs
You can use the same setup as Practical 1 where two PCs are connected in a LAN via a
switch.
Step 3: Simulate Character Count Framing in Packet Tracer
Unfortunately, Cisco Packet Tracer does not directly support simulation of data link layer
framing methods like Character Count. However, you can simulate the logical steps involved
in a simplified manner using messaging between PCs.
For this, you could send data between two computers manually using the Simple PDU or
Message option, and then manually count the characters of the message.
Go to PC1:
Click on PC1, go to the Desktop tab, and open the Command Prompt.
Send a Ping Message to PC2:
Use the ping command to simulate message sending from PC1 to PC2:
Copy code
ping 192.168.1.20
Interpret the Sent Data:
In a real-world scenario, data link layer protocols like Character Count would frame the data.
Let’s simulate by assuming the message being sent is "HELLO", which is 5 characters.
According to Character Count Framing:
The frame would look like: [5 H E L L O].

15
The first byte of the frame would specify that the frame contains 5 characters.
Step 4: Analyse the Transmission
Check for Successful Transmission:
If the ping command is successful, it indicates that the message has been transmitted over the
network, and we can assume that a frame (using the Character Count method) has been used.
Observe the OSI Layers (Optional):
Click on the simulation mode in Packet Tracer (switch from Real-Time to Simulation mode).
You can see how data travels across the OSI layers from the application layer down to the
data link layer.
Though you won’t see the exact character count framing, this gives insight into how data is
processed in each layer.
Code to see this
# Function to frame data using the Character Count method
def frame_data(data_list):
frames = []
for data in data_list:
# Calculate the length of the data
frame_length = len(data)
# Add the character count at the beginning of the frame
frame = str(frame_length) + data
frames.append(frame)
return frames
# Function to extract data by interpreting the Character Count method
def extract_frames(frames):
extracted_data = []
for frame in frames:
# The first character of the frame is the character count
char_count = int(frame[0]) # First character represents the count
# The rest of the frame is the actual data
data = frame[1:char_count + 1] # Extract the number of characters as per the count
extracted_data.append(data)
return extracted_data
# Example data to send (data without framing)

16
data_to_send = ["HELLO", "iphone"]
# Frame the data before sending (sender side)
framed_data = frame_data(data_to_send)
print("Framed Data (Sent):")
print(framed_data)
# Extract the original data after receiving (receiver side)
received_data = extract_frames(framed_data)
print("\nExtracted Data (Received):")
print(received_data)
OUTPUT:

17
EXPERIMENT-5

Aim: Bit stuffing is a technique used in the Data Link Layer to ensure that specific patterns,
such as a frame delimiter, are not accidentally interpreted as data. This method inserts non-
information bits into data when certain patterns appear, and these bits are removed by the
receiver.

In this experiment, we will simulate and understand the process of Bit Stuffing and De-
stuffing.
Step-by-Step Guide:
Step 1: Understanding Bit Stuffing and De-stuffing
In Bit Stuffing, a special sequence of bits, like 01111110, is often used to mark the beginning
and end of a frame (called a flag).
If the data contains the same bit pattern within it (e.g., 011111), the sender inserts an extra '0'
after five consecutive '1's to prevent the pattern from being interpreted as a flag.
De-stuffing is the process by which the receiver removes the extra '0' after receiving five
consecutive '1's.
For example:
Original data: 0111110111110
After bit stuffing: 0111110*0*111110
The receiver detects and removes the extra bit during de-stuffing.

Step 2: Setup Network in Cisco Packet Tracer


Create a basic LAN setup with two computers (PC1 and PC2) and a switch, as we did in the
previous experiments.
Add two PCs and a switch to the workspace.
Connect the PCs to the switch using Copper Straight-Through Cables.
Assign IP addresses to the PCs (e.g., PC1: 192.168.1.10, PC2: 192.168.1.20).

Step 3: Manual Simulation of Bit Stuffing


Cisco Packet Tracer does not provide a direct simulation for bit-level framing methods like
bit stuffing. However, you can simulate this manually.
Bit Stuffing Process:
Prepare the Data:

18
Suppose the original data to be sent from PC1 to PC2 is 0111110111110.
Apply Bit Stuffing:
If you encounter five consecutive 1s, insert an extra 0 after them.
For the example above: 0111110*0*111110.
After bit stuffing, the data becomes 01111100111110.

Step 4: Sending the Stuffed Data


Go to PC1:
Open PC1 and go to the Command Prompt.
Simulate Sending Data:
We can't input binary data directly, but you can simulate sending data using the ping
command, which represents data transmission.
You can assume that the stuffed bit sequence is being transmitted when you ping PC2:
Copy code
ping 192.168.1.20

Monitor the Transmission:


Use Simulation Mode in Packet Tracer to observe the frames being sent across the OSI
layers.

Step 5: Manual De-stuffing Process


When PC2 receives the data, it will perform de-stuffing to reconstruct the original data.
Remove the Stuffed Bits:
The receiver (PC2) checks for five consecutive 1s and removes the extra 0 inserted during
transmission.
For example, if PC2 receives 01111100111110, it will remove the stuffed 0 after the first five
consecutive 1s, resulting in the original data: 0111110111110.

Step 6: Theoretical Discussion


Bit Stuffing is necessary to avoid confusion between the frame delimiter (flag) and the actual
data.
In real data link layer protocols, bit stuffing ensures that special bit patterns (such as frame
delimiters) are not misinterpreted as part of the data.

19
Summary of Steps:
Understand the concept of bit stuffing and de-stuffing.
Create a network with two PCs connected through a switch.
Simulate bit stuffing by adding a '0' after five consecutive 1s in your data.
Send data using the ping command to simulate transmission between two PCs.
Perform de-stuffing at the receiving PC by removing the stuffed bits.
Observe the process using simulation mode in Cisco Packet Tracer to understand the
transmission flow.
Code for bit stuffing
# Function to perform bit stuffing
def bit_stuff(data):
stuffed_data = ""
consecutive_ones = 0
for bit in data:
if bit == '1':
consecutive_ones += 1
stuffed_data += bit
# If 5 consecutive 1s, insert a 0
if consecutive_ones == 5:
stuffed_data += '0'
consecutive_ones = 0
else:
stuffed_data += bit
consecutive_ones = 0
return stuffed_data

# Function to perform bit de-stuffing


def bit_de_stuff(stuffed_data):
de_stuffed_data = ""
consecutive_ones = 0
for bit in stuffed_data:

20
if bit == '1':
consecutive_ones += 1
de_stuffed_data += bit
else:
# If 5 consecutive 1s, ignore the next 0 (the stuffed bit)
if consecutive_ones == 5:
consecutive_ones = 0
continue
else:
de_stuffed_data += bit
consecutive_ones = 0
return de_stuffed_data
# Example Data to be sent (binary string)
data_to_send = "011111101111110011111"
# Perform Bit Stuffing (Sender Side)
stuffed_data = bit_stuff(data_to_send)
print("Data after Bit Stuffing (Sent):")
print(stuffed_data)

# Perform Bit De-stuffing (Receiver Side)


received_data = bit_de_stuff(stuffed_data)
print("\nData after Bit De-stuffing (Received):")
print(received_data)
# Verify if original data is correctly received
if data_to_send == received_data:
print("\nSuccess: Data received matches original data!")
else:
print("\nError: Data received does not match original data!")

21
22
EXPERIMENT-6

Aim: Implementation of Error Detection Methods Using Even and Odd Parity
Objective: In this practical, we will simulate error detection using even and odd parity.
Parity checking is a simple error-detection method used in data communication. It adds an
extra bit (parity bit) to a set of binary data to make the total number of 1s either even (even
parity) or odd (odd parity).
Parity Basics:
Even Parity: The total number of 1s, including the parity bit, should be even.
Odd Parity: The total number of 1s, including the parity bit, should be odd.
Step-by-Step Guide:
Step 1: Understanding Parity Bits
Let's say we have a data byte, 1011010 (7 bits).
For even parity:
Count the number of 1s: There are 4 1s, which is already even. So, the parity bit will be 0.
Transmitted data with even parity: 10110100 (original data + parity bit).
For odd parity:
Count the number of 1s: There are 4 1s, which is even. So, the parity bit will be 1 to make it
odd.
Transmitted data with odd parity: 10110101 (original data + parity bit).

Step 2: Setup a Network in Cisco Packet Tracer


Create a basic LAN setup with two computers (PC1 and PC2) connected via a switch.
Add two PCs and a switch to the workspace.
Connect the PCs using Copper Straight-Through Cables.
Assign IP addresses to the PCs (e.g., PC1: 192.168.1.10, PC2: 192.168.1.20).
Step 3: Manually Simulate Even and Odd Parity
Cisco Packet Tracer does not directly simulate parity bits, but you can manually simulate
how even and odd parity work.
For Even Parity:Prepare the Data:
Suppose we want to send the data 1011010 from PC1 to PC2.
Calculate Even Parity:
Count the 1s in the data. There are 4 1s, which is already even.

23
So, the parity bit is 0.
The transmitted data will be: 10110100.

For Odd Parity:


Prepare the Data:
Suppose we want to send the same data 1011010.
Calculate Odd Parity:
Count the 1s. There are 4 1s, which is even.
To make the total number of 1s odd, we add a parity bit of 1.
The transmitted data will be: 10110101.
Step 4: Simulate Data Transmission Using Ping
Though we can't input binary data directly in Cisco Packet Tracer, we can simulate the
process by sending data via ping and understanding that it would include a parity bit.
Go to PC1:
Open PC1, go to the Desktop tab, and open the Command Prompt.
Send a Ping Request to PC2:
Use the ping command to simulate sending data:
Copy code
ping 192.168.1.20
Simulate Even Parity Transmission:
Suppose the data sent is 10110100 (even parity).
Simulate Odd Parity Transmission:
Suppose the data sent is 10110101 (odd parity).
Step 5: Error Detection (Theoretical)
At the receiving end (PC2), we assume that the receiver will check the parity bit to detect any
errors.
For Even Parity:
If the total number of 1s in the received data is odd, it indicates an error.
For Odd Parity:
If the total number of 1s in the received data is even, it indicates an error.
Step 6: Theoretical Discussion

24
Even and Odd Parity are used for simple error detection. However, parity checking cannot
detect all errors, especially if two bits are flipped (double-bit errors). It is best suited for
detecting single-bit errors.
Parity is a common technique in low-level communication protocols such as serial data
transmission and memory error detection (e.g., ECC memory).
Summary of Steps:
Understand parity: How even and odd parity works for error detection.
Set up a LAN with two PCs connected via a switch in Cisco Packet Tracer.
Manually calculate parity bits for both even and odd parity.
Simulate data transmission using the ping command.
Understand how errors are detected by verifying the number of 1s in the received data
(theoretical)
Code for odd even
# Function to add even parity bit
def add_even_parity(data):
ones_count = data.count('1')
# If the number of 1s is odd, add a parity bit of 1 to make it even
if ones_count % 2 == 1:
return data + '1' # Add parity bit 1
else:
return data + '0' # Add parity bit 0
# Function to add odd parity bit
def add_odd_parity(data):
ones_count = data.count('1')
# If the number of 1s is even, add a parity bit of 1 to make it odd
if ones_count % 2 == 0:
return data + '1' # Add parity bit 1
else:
return data + '0' # Add parity bit 0
# Function to check even parity at the receiver side
def check_even_parity(received_data):
ones_count = received_data.count('1')
# For even parity, the total number of 1s (including the parity bit) should be even

25
return ones_count % 2 == 0
# Function to check odd parity at the receiver side
def check_odd_parity(received_data):
ones_count = received_data.count('1')
# For odd parity, the total number of 1s (including the parity bit) should be odd
return ones_count % 2 == 1
# Example data (binary string)
data_to_send = "1101011" # 7-bit data
# Adding Even Parity
even_parity_data = add_even_parity(data_to_send)
print("Data with Even Parity (Sent):", even_parity_data)
# Adding Odd Parity
odd_parity_data = add_odd_parity(data_to_send)
print("Data with Odd Parity (Sent):", odd_parity_data)
# Simulate transmission (introduce no errors)
received_data_even = even_parity_data
received_data_odd = odd_parity_data
# Checking Even Parity at receiver side
if check_even_parity(received_data_even):
print("Even Parity Check Passed (No error detected).")
else:
print("Even Parity Check Failed (Error detected).")

# Checking Odd Parity at receiver side


if check_odd_parity(received_data_odd):
print("Odd Parity Check Passed (No error detected).")
else:
print("Odd Parity Check Failed (Error detected).")
# Simulate transmission with error (flip one bit)
received_data_even_with_error = "11010110" # Introduce an error by flipping the last bit
# Checking Even Parity with error at receiver side
if check_even_parity(received_data_even_with_error):

26
print("Even Parity Check Passed (No error detected).")
else:
print("Even Parity Check Failed (Error detected).")

OUTPUT:

27
EXPERIMENT- 7
Aim: Simulation of Flow Control and Error Control Protocols
Objective: Simulate and compare flow control and error control protocols such as Stop-
and-Wait ARQ, Go-Back-N ARQ, and Selective Repeat ARQ using Cisco Packet Tracer.
Steps:
Create the Network:
Open Cisco Packet Tracer.
Add two PCs to the workspace.
Connect the two PCs using a crossover cable.
Configure IP Addresses:
Click on PC0, then go to the Desktop tab and open IP Configuration.
Assign IP Address 192.168.1.1 and Subnet Mask 255.255.255.0.
Repeat for PC1, but assign IP Address 192.168.1.2 and the same Subnet Mask 255.255.255.0.
Enable Flow Control:
Use the Simulation Mode in Packet Tracer.
Send data from PC0 to PC1 by using the Simple PDU tool and observe the flow control
behaviour.
Implement Stop-and-Wait ARQ by allowing PC0 to wait for an acknowledgment (ACK)
from PC1 after each packet sent.
Implement Go-Back-N:
Send multiple packets from PC0 to PC1.
Observe how, if a packet is lost, PC0 retransmits all subsequent packets until the error is
corrected.
Simulate Selective Repeat:
Introduce an error by delaying a packet in Simulation Mode.
Watch as only the lost packet is retransmitted while the correct packets are acknowledged and
continue to be processed.
Compare the Protocols:
Observe the behaviour of each protocol in handling errors and retransmissions.
Note the differences in performance (how long it takes to resend packets).
Stop-and-Wait ARQ (Python Implementation):
import time
import random

28
def stop_and_wait(sender_frames):
for i, frame in enumerate(sender_frames):
print(f"Sending frame {i+1}: {frame}")
time.sleep(1)
ack = random.choice([True, False]) # Random acknowledgment
if ack:
print(f"ACK received for frame {i+1}\n")
else:
print(f"Timeout! Resending frame {i+1}")
time.sleep(1)
print(f"Resending frame {i+1}: {frame}\n")

# Example simulation
frames = ["Frame 1", "Frame 2", "Frame 3"]
stop_and_wait(frames)
OUTPUT:

Go-Back-N ARQ (Python Implementation):


def go_back_n(sender_frames, window_size):
n = len(sender_frames)
i=0
while i < n:
print(f"Sending window of frames: {sender_frames[i:i+window_size]}")
for j in range(i, min(i + window_size, n)):
time.sleep(1)

29
ack = random.choice([True, False]) # Random ACK/NACK
if ack:
print(f"ACK received for frame {j+1}")
else:
print(f"Error in frame {j+1}, retransmitting from frame {i+1}")
break
i += window_size

# Example simulation
frames = ["Frame 1", "Frame 2", "Frame 3", "Frame 4", "Frame 5"]
go_back_n(frames, 3)
OUTPUT:

Selective Repeat ARQ (Python Implementation):


def selective_repeat(sender_frames, window_size):
n = len(sender_frames)
acks = [False] * n
i=0
while i < n:
print(f"Sending window of frames: {sender_frames[i:i+window_size]}")
for j in range(i, min(i + window_size, n)):
time.sleep(1)
ack = random.choice([True, False]) # Random ACK/NACK
if ack:
print(f"ACK received for frame {j+1}")

30
acks[j] = True
else:
print(f"Error in frame {j+1}, retransmitting frame {j+1}")
time.sleep(1)
print(f"Resending frame {j+1}: {sender_frames[j]}")
i += window_size

# Example simulation
frames = ["Frame 1", "Frame 2", "Frame 3", "Frame 4", "Frame 5"]
selective_repeat(frames, 3)
OUTPUT:

31
EXPERIMENT-8
Aim: Simulate multiple access protocols such as Pure ALOHA, Slotted ALOHA,
CSMA/CD, and CSMA/CA using Cisco Packet Tracer.
Steps:
Create the Network:
Add five PCs and connect them to a hub (for wired connections) or a wireless router (for
wireless connections).
Configure IP Addresses:
Assign static IP addresses to each PC in the same subnet (e.g., 192.168.1.1, 192.168.1.2, etc.,
with the same subnet mask 255.255.255.0).
Simulate Pure ALOHA:
Switch to Simulation Mode.
Send data from all PCs at random intervals and observe collisions in the event list (under
Collision Detection).
Pure ALOHA will show high collisions due to no coordination between devices.
Simulate Slotted ALOHA:
Send data at defined time intervals by spacing out packet generation in Simulation Mode.
Observe fewer collisions, as data is transmitted at set slots.
Simulate CSMA/CD:
Use the Switch instead of a hub and enable CSMA/CD (in Ethernet settings).
Observe how the devices listen to the medium before transmitting data.
If a collision is detected, the devices stop and wait a random time before retransmitting.
Simulate CSMA/CA:
For wireless networks, simulate CSMA/CA using a wireless router.
Watch how devices request permission to transmit, reducing collisions compared to wired
networks.
Pure ALOHA Protocol (Python Implementation):
import random
import time
def pure_aloha(transmissions):
for i, transmission in enumerate(transmissions):
time.sleep(1)
if random.random() < 0.5: # 50% chance of collision

32
print(f"Collision detected! Resending transmission {i+1}: {transmission}")
else:
print(f"Transmission {i+1} successful: {transmission}")
# Example simulation
transmissions = ["Frame 1", "Frame 2", "Frame 3"]
pure_aloha(transmissions)
CSMA/CD Protocol (Python Implementation):
def csma_cd(transmissions):
for i, transmission in enumerate(transmissions):
print(f"Attempting to send transmission {i+1}: {transmission}")
if random.random() < 0.3: # 30% chance of collision
print(f"Collision detected! Waiting to resend transmission {i+1}")
time.sleep(random.uniform(1, 3)) # Random backoff time
print(f"Resending transmission {i+1}: {transmission}")
else:
print(f"Transmission {i+1} successful: {transmission}")

# Example simulation
transmissions = ["Frame 1", "Frame 2", "Frame 3"]
csma_cd(transmissions)

OUTPUT

33
EXPERIMENT-9

Aim: Sliding Window Protocol with Piggybacking


Objective: Simulate the Sliding Window Protocol with Piggybacking for efficient
data transmission.
Steps:
Create the Network:
Add two PCs connected by a switch or directly by a crossover cable.
Configure IP Addresses:
Assign static IP addresses: 192.168.1.1 for PC0 and 192.168.1.2 for PC1.
Enable Sliding Window Protocol:
In Simulation Mode, send data from PC0 to PC1 with multiple packets in a window.
Enable Piggybacking in the protocol settings (in PDU).
Simulate Data Transmission:
Watch as data frames are sent from PC0 to PC1 and PC1 sends acknowledgments
back while sending its own data frames.
Introduce errors by delaying frames and observe retransmissions.
Analyse Results:
Observe the efficiency gained by sending acknowledgments along with data instead of
separate ACK frames.
def sliding_window_with_piggybacking(sender_frames, window_size):
n = len(sender_frames)
i=0
acks = [False] * n
while i < n:
print(f"Sending window: {sender_frames[i:i+window_size]}")
for j in range(i, min(i + window_size, n)):
print(f"Sending frame {j+1}: {sender_frames[j]}")
ack = random.choice([True, False]) # Random ACK
if ack:
print(f"ACK piggybacked for frame {j+1}")

34
acks[j] = True
else:
print(f"Error, frame {j+1} needs to be retransmitted")
i += window_size

# Example simulation
frames = ["Frame 1", "Frame 2", "Frame 3", "Frame 4", "Frame 5"]
sliding_window_with_piggybacking(frames, 3)

35
EXPERIMENT-10

Aim: Logical Addressing using IPv4 and IPv6


Objective: Simulate logical addressing using IPv4 and IPv6 and demonstrate how devices acquire
IP addresses using ARP, RARP, BOOTP, and DHCP.

Steps:
Create the Network:
Add multiple PCs, a router, and a switch to the workspace.
Connect all devices to the switch and connect the switch to the router.
IPv4 Setup:
Assign static IPv4 addresses to the PCs manually (e.g., 192.168.1.1 to PC0, 192.168.1.2 to PC1, etc.).
Ping each PC to test IPv4 connectivity.
IPv6 Setup:
Enable IPv6 on the router.
Assign IPv6 addresses to the PCs (e.g., 2001:db8::1 for PC0, 2001:db8::2 for PC1).
Simulate ARP and DHCP:
Use ARP by pinging between PCs to resolve MAC addresses from IPv4 addresses.
Set up a DHCP server on the router to dynamically assign IPv4 addresses to PCs.
Monitor Address Resolution:
Switch to Simulation Mode and observe the ARP requests and responses as they occur.

36
EXPERIMENT-11
Aim: Comparison of UDP, TCP, and SCTP
Objective: Simulate and compare transport layer protocols UDP, TCP, and SCTP in
terms of connection setup, reliability, and congestion control.
Steps:
Create the Network:
Add two PCs connected via a router.
Configure IP Addresses:
Assign static IPs (e.g., 192.168.1.1 and 192.168.1.2) to the PCs.
UDP Simulation:
Use Simulation Mode to send UDP packets from PC0 to PC1.
Observe that there are no connection setups or acknowledgment packets (fire-and-
forget protocol).
TCP Simulation:
Send TCP packets from PC0 to PC1.
Observe the three-way handshake for connection establishment and the ACK for
reliable data transmission.
SCTP Simulation:
Send SCTP packets and observe the multi-stream connection, where multiple data
streams are transmitted at once.
Compare the Protocols:
Compare UDP, TCP, and SCTP based on connection setup, reliability, and efficiency
in handling data.
TCP Simulation (Connection Establishment and Data Transfer):
python
import socket
def tcp_server():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('localhost', 8080))
server_socket.listen(1)
print("TCP Server waiting for connection...")
conn, addr = server_socket.accept()

37
print(f"Connection established with {addr}")
data = conn.recv(1024)
print(f"Received: {data.decode()}")
conn.sendall(b"ACK: Message received")
conn.close()
def tcp_client():
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 8080))
client_socket.sendall(b"Hello, TCP Server")
response = client_socket.recv(1024)
print(f"Server Response: {response.decode()}")
client_socket.close()
# Example usage
# Run tcp_server() in one script instance and tcp_client() in another

UDP Simulation:
python
def udp_server():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('localhost', 8080))
print("UDP Server waiting for messages...")
data, addr = server_socket.recvfrom(1024)
print(f"Received from {addr}: {data.decode()}")
server_socket.sendto(b"ACK: Message received", addr)
def udp_client():
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.sendto(b"Hello, UDP Server", ('localhost', 8080))
data, addr = client_socket.recvfrom(1024)
print(f"Server Response: {data.decode()}")
client_socket.close()

38
# Example usage
# Run udp_server() in one script instance and udp_client() in another

39

You might also like