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

Static and Dynamic Routing Lab Guide

The document outlines a lab assignment on computer networks, focusing on static and dynamic routing using Cisco Packet Tracer, as well as flow control techniques like Stop and Wait ARQ, Go Back N, and Selective Repeat. It includes step-by-step instructions for setting up network topologies, configuring IP addresses, and implementing routing protocols. Additionally, it provides Python code examples for sender and receiver implementations for each flow control method.

Uploaded by

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

Static and Dynamic Routing Lab Guide

The document outlines a lab assignment on computer networks, focusing on static and dynamic routing using Cisco Packet Tracer, as well as flow control techniques like Stop and Wait ARQ, Go Back N, and Selective Repeat. It includes step-by-step instructions for setting up network topologies, configuring IP addresses, and implementing routing protocols. Additionally, it provides Python code examples for sender and receiver implementations for each flow control method.

Uploaded by

satyamtk75
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

COMPUTER NETWORKS LAB

Assignment 3
SATYAM KUMAR
22BCE3070

Static Routing using Cisco packet tracer


1. Setting Up the Network Topology
 Step 1: Open Cisco Packet Tracer
o Launch Cisco Packet Tracer.
o You will see a workspace where you can add routers, switches, PCs, and other
network devices.
 Step 2: Add Devices to the Workspace
o Routers: Drag and drop routers from the device menu to the workspace.
You’ll need at least 2 routers.
o End Devices: Add PCs or servers from the "End Devices" section.
o Switches: Add switches to connect PCs to routers (if needed).
 Step 3: Connect Devices Using Cables
o Copper Straight-through cable to connect PCs to switches, and switches to
routers.
o Copper Cross-over cable to connect the two routers.
 2. Configure IP Addresses for Each Interface
o Step 4: Assign IP Addresses to PCs
o Step 5: Configure IP Addresses on Routers
 3. Configure Static Routes Using Interface Method
o Step 6: Add Static Routes on Routers
 4. Verifying the Configuration
o Step 8: Ping Test
Dyanamic Routing using Cisco packet tracer
Steps to Implement Dynamic Routing with RIP (Interface Method)
 Setting Up the Network Topology
o Step 1: Open Cisco Packet Tracer

 Launch Cisco Packet Tracer.


 You’ll see a blank workspace to create your network
topology.
o Step 2: Add Devices to the Workspace
 Routers: Drag and drop at least two routers into the
workspace.
 PCs: Add PCs to represent the end devices connected to the
routers.
 Switches: Optionally, use switches to connect PCs to the
routers.
 Cables: Use appropriate cabling (e.g., Copper Straight-
through for PCs to switches, Cross-over cables for router-to-
router connections).
o Step 3: Connect the Routers and PCs
 Connect PCs to routers via switches or directly to router
interfaces.
 Connect the routers together using cross-over cables on
their interfaces.
 Configure IP Addresses for Each Interface
o Step 4: Assign IP Addresses to the PCs
o Step 5: Configure IP Addresses on Routers
 Configure Dynamic Routing Using RIP
Now that the routers are configured with IP addresses, we will set up RIP
for dynamic routing.
o Step 6: Configure RIP on Routers
o Step 7: Ping Test
 Now, test the connectivity between the two PCs.
Flow control (Stop and Wait ARQ)

Code:

[Link]

import socket

import random

import time

# Constants

PACKET_LOSS_PROB = 0.2 # Simulate packet loss with 20% probability

TIMEOUT = 2 # Timeout in seconds

def sender():

server_address = ('localhost', 8080)

sock = [Link](socket.AF_INET, socket.SOCK_DGRAM)

sequence_number = 0

for i in range(5): # Sending 5 packets

data = f"Packet {i}".encode('utf-8')

while True:

# Create the packet with the current sequence number and data

packet = f"{sequence_number}:{[Link]('utf-8')}".encode('utf-8')

# Simulate packet loss

if [Link]() > PACKET_LOSS_PROB:

print(f"Sending: {[Link]('utf-8')}")

[Link](packet, server_address)

# Start timer and wait for ACK

[Link](TIMEOUT)

try:

ack, _ = [Link](1024)
ack = [Link]('utf-8')

if ack == str(sequence_number):

print(f"ACK received: {ack}")

sequence_number ^= 1 # Toggle sequence number

break

else:

print("Incorrect ACK received, resending packet...")

except [Link]:

print("Timeout! Resending packet...")

[Link]()

if __name__ == "__main__":

sender()

[Link]

import socket

import random

# Constants

PACKET_LOSS_PROB = 0.2 # Simulate packet loss with 20% probability

def receiver():

sock = [Link](socket.AF_INET, socket.SOCK_DGRAM)

[Link](('localhost', 8080))

expected_sequence_number = 0

while True:

packet, address = [Link](1024)

packet = [Link]('utf-8')

sequence_number, data = [Link](':', 1)


sequence_number = int(sequence_number)

# Simulate ACK loss

if [Link]() > PACKET_LOSS_PROB:

if sequence_number == expected_sequence_number:

print(f"Received: {data}")

expected_sequence_number ^= 1 # Toggle sequence number

ack = f"{sequence_number}".encode('utf-8')

[Link](ack, address)

else:

print(f"Duplicate packet received: {data}")

else:

print("Simulated ACK loss, no ACK sent.")

[Link]()

if __name__ == "__main__":

receiver()

Output:
Flow control (Go Back N)
Code:

gbn_sender.py

import socket

import time

import random

# Constants

PACKET_LOSS_PROB = 0.2 # Simulate packet loss with 20% probability

WINDOW_SIZE = 4 # Go-Back-N window size

TIMEOUT = 2 # Timeout in seconds

TOTAL_PACKETS = 10 # Total number of packets to send

def sender():

server_address = ('localhost', 8080)

sock = [Link](socket.AF_INET, socket.SOCK_DGRAM)

[Link](TIMEOUT)

base = 0 # Base of the window

next_seq_num = 0 # Next sequence number to be sent

window = []

# Function to send a packet

def send_packet(seq_num):

packet = f"{seq_num}".encode('utf-8')

if [Link]() > PACKET_LOSS_PROB:

print(f"Sending packet {seq_num}")

[Link](packet, server_address)

else:

print(f"Packet {seq_num} lost in transmission")


while base < TOTAL_PACKETS:

# Send packets within the window size

while next_seq_num < base + WINDOW_SIZE and next_seq_num < TOTAL_PACKETS:

send_packet(next_seq_num)

[Link](next_seq_num)

next_seq_num += 1

# Try to receive ACK

try:

ack, _ = [Link](1024)

ack = int([Link]('utf-8'))

print(f"ACK received for packet {ack}")

# Slide the window

if ack >= base:

base = ack + 1

window = window[ack - base + 1:]

except [Link]:

print("Timeout! Resending window...")

# Resend all packets in the current window

for seq_num in window:

send_packet(seq_num)

print("All packets sent and acknowledged.")

[Link]()

if __name__ == "__main__":

sender()
gbn_receiver.py

import socket

import random

# Constants

PACKET_LOSS_PROB = 0.2 # Simulate packet loss with 20% probability

TOTAL_PACKETS = 10 # Total number of packets to expect

def receiver():

sock = [Link](socket.AF_INET, socket.SOCK_DGRAM)

[Link](('localhost', 8080))

expected_seq_num = 0 # Next expected sequence number

while expected_seq_num < TOTAL_PACKETS:

packet, address = [Link](1024)

seq_num = int([Link]('utf-8'))

if [Link]() > PACKET_LOSS_PROB:

if seq_num == expected_seq_num:

print(f"Received packet {seq_num}, sending ACK.")

ack = f"{seq_num}".encode('utf-8')

[Link](ack, address)

expected_seq_num += 1 # Move to the next expected sequence number

else:

print(f"Out-of-order packet {seq_num} received, discarding.")

else:

print(f"Packet {seq_num} received, but ACK lost.")

[Link]()

if __name__ == "__main__":

receiver()
Output:
Flow control (Selective Repeat)
Code:
Sr_sender.py
import socket

import random

import time

# Constants

PACKET_LOSS_PROB = 0.2 # Simulate packet loss with 20% probability

WINDOW_SIZE = 4 # Sender's window size

TIMEOUT = 2 # Timeout for resending in seconds

TOTAL_PACKETS = 10 # Total number of packets to send

def sender():

server_address = ('localhost', 8081)

sock = [Link](socket.AF_INET, socket.SOCK_DGRAM)

[Link](TIMEOUT)

base = 0 # Base of the window

next_seq_num = 0 # Next sequence number to be sent

window = {}

def send_packet(seq_num):

packet = f"{seq_num}".encode('utf-8')

if [Link]() > PACKET_LOSS_PROB:

print(f"Sending packet {seq_num}")

[Link](packet, server_address)

else:

print(f"Packet {seq_num} lost in transmission")

window[seq_num] = packet # Store packet for potential retransmission

while base < TOTAL_PACKETS:

# Send packets within the window

while next_seq_num < base + WINDOW_SIZE and next_seq_num < TOTAL_PACKETS:


send_packet(next_seq_num)

next_seq_num += 1

# Try to receive ACKs

try:

ack, _ = [Link](1024)

ack = int([Link]('utf-8'))

print(f"ACK received for packet {ack}")

if ack >= base:

base = ack + 1 # Move the base forward

except [Link]:

print("Timeout! Resending unacknowledged packets...")

# Resend all packets that have not been acknowledged

for seq_num in range(base, next_seq_num):

send_packet(seq_num)

print("All packets sent and acknowledged.")

[Link]()

if __name__ == "__main__":

sender()

sr_reciever.py
import socket

import random

# Constants

PACKET_LOSS_PROB = 0.2 # Simulate ACK loss with 20% probability

WINDOW_SIZE = 4 # Receiver's window size

TOTAL_PACKETS = 10 # Total number of packets to expect

def receiver():

sock = [Link](socket.AF_INET, socket.SOCK_DGRAM)


[Link](('localhost', 8081))

expected_seq_num = 0 # Next expected sequence number

received_packets = {} # Buffer for out-of-order packets

while expected_seq_num < TOTAL_PACKETS:

packet, address = [Link](1024)

seq_num = int([Link]('utf-8'))

if seq_num not in received_packets: # Avoid processing duplicate packets

if [Link]() > PACKET_LOSS_PROB:

print(f"Received packet {seq_num}")

# Buffer out-of-order packets

if seq_num >= expected_seq_num and seq_num < expected_seq_num + WINDOW_SIZE:

received_packets[seq_num] = packet

# Send ACK for the received packet

ack = f"{seq_num}".encode('utf-8')

print(f"Sending ACK for packet {seq_num}")

[Link](ack, address)

else:

print(f"Packet {seq_num} received, but ACK lost.")

# Deliver in-order packets to the application

while expected_seq_num in received_packets:

print(f"Delivering packet {expected_seq_num} to application.")

del received_packets[expected_seq_num]

expected_seq_num += 1

[Link]()

if __name__ == "__main__":

receiver()
Output:

You might also like