Ai&ds CS3591 CN Lab Manual
Ai&ds CS3591 CN Lab Manual
Name :
Reg no :
Department :
Subject :
AISHWARYA
COLLEGE OF ENGINEERING AND TECHNOLOGY
ANTHIYUR
Department……………………………………………………………………………………………………....
………………………………………………………………………………………………………………..Record
Name:………………………………………. Dept:……………………………………………..
Certified that this is bonafide record of work done by the above student of the
………………………………………………………………………………………………………..laboratory
Held on……………………………………………...
Aim:
To use commands like tcpdump, netstat, ifconfig, nslookup and trace route. Capture ping and
trace route PDUs using a network protocol analyzer and examine.
1. Tcpdump
Tcpdump is a command line utility that allows you to capture and analyze network traffic going
through your system.
Procedure
$ which tcpdump
/usr/sbin/tcpdump
$ su
1
06:03:58.258143 ARP, Request who-has 172.16.51.87 tell 172.16.22.25, length 46
06:03:58.258225 ARP, Request who-has 172.16.51.88 tell 172.16.22.25, length 46
06:03:58.260828 ARP, Request who-has 172.16.51.122 tell 172.16.22.25, length 46
06:03:58.260903 ARP, Request who-has 172.16.51.123 tell 172.16.22.25, length 46
^C
5244 packets captured
59636 packets received by filter
54378 packets dropped by kernel
(Press ctrl+C to stop execution)
Filtering packets
To filter packets based on protocol, specifying the protocol in the command line. For example, capture
ICMP packets only by using this command:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
06:15:07.800786 IP localhost.localdomain > ec2-54-204-39-132.compute-1.amazonaws.com: ICMP
echo request, id 8180, seq 13, length 64
06:15:08.063488 IP ec2-54-204-39-132.compute-1.amazonaws.com > localhost.localdomain: ICMP
echo reply, id 8180, seq 13, length 64
2
5 packets captured
5 packets received by filter
0 packets dropped by kernel
2. netstat
netstat (network statistics) is a command line tool for monitoring network connections both incoming
and outgoing as well as viewing routing tables, interface statistics etc.
3. ifconfig
It displays the details of a network interface card like IP address, MAC Address, and the status of a
network interface card
3
loop txqueuelen 1000 (Local Loopback)
RX packets 4154 bytes 352264 (344.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4154 bytes 352264 (344.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4. nslookup
nslookup (stands for “Name Server Lookup”) is a useful command for getting information from
DNS server. It is a network administration tool for querying the Domain Name System (DNS) to obtain
domain name or IP address mapping or any other specific DNS record.
Non-authoritative answer:
Name: annauniv.edu
Address: 103.70.60.38
Non-authoritative answer:
206.26.217.172.in-addr.arpa name = maa03s23-in-f14.1e100.net.
206.26.217.172.in-addr.arpa name = maa03s23-in-f14.1e100.net.
206.26.217.172.in-addr.arpa name = maa03s23-in-f206.1e100.net.
206.26.217.172.in-addr.arpa name = maa03s23-in-f206.1e100.net.
Non-authoritative answer:
Name: annauniv.edu
Address: 103.70.60.38
annauniv.edu text = "v=spf1 ip4:103.70.60.40 -all"
annauniv.edu mail exchanger = 0 sonic.annauniv.edu.
annauniv.edu
origin = ns.annauniv.edu
mail addr = root.annauniv.edu
serial = 20170907
refresh = 300
4
retry = 900
expire = 604800
minimum = 86400
annauniv.edu nameserver = ns.annauniv.edu.
Non-authoritative answer:
annauniv.edu nameserver = ns.annauniv.edu.
5. traceroute
The traceroute command is used in Linux to map the journey that a packet of information undertakes
from its source to its destination.
Usage:
traceroute [ -46dFITnreAUDV ] [ -f first_ttl ] [ -g gate, ... ] [ -i device ] [ -m max_ttl ] [ -N squeries ] [ -
p port ] [ -t tos ] [ -l flow_label ] [ -w waittime ] [ -q nqueries ] [ -s src_addr ] [ -z sendwait ] [ --
fwmark=num ] host [ packetlen ]
Options:
-4 Use IPv4
-6 Use IPv6
-d --debug Enable socket level debugging
-F --dont-fragment Do not fragment packets
5
1 localhost.localdomain (172.16.20.138) 3004.348 ms !H 3004.215 ms !H 3004.104 ms !H
Capture ping and traceroute PDUs using a network protocol analyzer and examine.
Wireshark is free & Open source network packet analyzer that is used for network analysis,
troubleshooting, etc.
Wireshark is quite similar to tcpdump, the major difference between the two is that Wireshark has a
graphical interface with built-in filtering options, which make it easy to use.
To Open Wireshark
# sudo wireshark
In a konsole execute
# ping www.sudo.com
# traceroute www.google.com
6
Result:
Thus commands like tcpdump, netstat, ifconfig, nslookup and traceroute was used. Ping and
traceroute PDUs using a network protocol analyzer was captured and examined.
7
Ex: 2 WRITE A HTTP WEB CLIENT PROGRAM TO DOWNLOAD A WEB PAGE
USING TCP SOCKETS
AIM
To write a program in Python to create an HTTP web client that downloads a web page using
TCP sockets.
Algorithm
PROGRAM
import socket
# Main function
if __name__ == "__main__":
# Specify the host and resource
host = "example.com" # Replace with the desired host
resource = "/" # Replace with the specific resource path (e.g., "/index.html")
Result
The program successfully downloads a web page using TCP sockets and saves it as an
HTML file in the current working directory.
EX NO :3 A. APPLICATION USING TCP SOCKETS - ECHO CLIENT AND ECHO
SERVER
Aim
To write a program in Python to implement an Echo Client and Echo Server using TCP
sockets where the client sends a message, and the server echoes it back.
Algorithm
Server-Side Algorithm
Client-Side Algorithm
import socket
# Accept a connection
conn, addr = server_socket.accept()
print(f"Connection established with {addr}")
while True:
# Receive data from the client
data = conn.recv(1024)
if not data:
break
print(f"Received: {data.decode()}")
import socket
Aim
To write a program in Python to implement a simple cB hat application using TCP sockets
where a client and server can exchange messages.
Algorithm
Server-Side Algorithm
Client-Side Algorithm
SERVER
import socket
# Accept a connection
conn, addr = server_socket.accept()
print(f"Connection established with {addr}")
# Chat loop
while True:
# Receive a message from the client
client_message = conn.recv(1024).decode()
if client_message.lower() == "exit":
print("Client has exited the chat.")
break
print(f"Client: {client_message}")
CLIENT PROGRAM
import socket
# Chat loop
while True:
# Send a message to the server
client_message = input("You: ")
client_socket.sendall(client_message.encode())
if client_message.lower() == "exit":
print("You exited the chat.")
break
Client Console
Connected to server at localhost:12345
You: Hello, Server!
Server: Hello, Client!
You: How are you?
Server: I'm fine. Type 'exit' to end the chat.
Result
The Chat Client and Chat Server programs successfully exchange messages in real time using
TCP sockets.
Ex.No.4 SIMULATION OF DNS USING UDP SOCKETS
AIM
To write a program in Python to simulate DNS (Domain Name System) resolution using
UDP sockets.
ALGORITHM
SERVER-SIDE ALGORITHM
Client-Side Algorithm
Server Program
import socket
try:
# Create a UDP socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
# Receive query from the client
query, client_address = server_socket.recvfrom(1024)
domain_name = query.decode()
print(f"Received query for: {domain_name}")
Client Program
import socket
while True:
# Input domain name from user
domain_name = input("Enter domain name to resolve (or 'exit' to quit): ")
if domain_name.lower() == "exit":
print("Exiting DNS client.")
break
Result
The DNS simulation using UDP sockets successfully resolved domain names to IP addresses
or returned appropriate error messages.
Ex.No.5 USE A TOOL LIKE WIRESHARK TO CAPTURE PACKETS AND EXAMINE
THE PACKETS
Aim
To capture, filter, and analyze network packets using the Wireshark application.
Requirements
Theory
Wireshark is a widely-used network protocol analyzer that lets you capture and interactively
browse the traffic running on a computer network. It is used for network troubleshooting,
analysis, and communication protocol development.
1. Install Wireshark
2. Launch Wireshark
After completing the activity, click on the Stop button (red square icon) to stop
capturing packets.
1. Apply Filters
Use the Filter bar at the top of the Wireshark window to filter specific types of
packets.
Common filters:
o DNS Traffic: udp.port == 53
o HTTP Traffic: http
o TCP Traffic: tcp
o UDP Traffic: udp
o Filter by IP Address: ip.addr == <your-IP-address>
DNS Analysis:
o Look for DNS queries and responses with domain names and IP addresses.
HTTP Analysis:
o Analyze GET and POST requests and their server responses.
TCP Analysis:
o Observe source and destination ports, flags, and handshake details.
Go to File > Save As to save the captured packets for later analysis.
Sample Observations
DNS Traffic
HTTP Traffic
TCP Traffic
Result
The Wireshark tool was successfully used to capture, filter, and analyze network packets for
DNS, HTTP, TCP, and UDP protocols.
Ex no 6 . Simulation of Address Resolution Protocol (ARP) Using Python and Cisco
Devices
Aim
To simulate the Address Resolution Protocol (ARP) using Python, observe how it works to
map an IP address to a MAC address in a local network, and capture the ARP packets using
Cisco devices.
Requirements
1. Software:
o Python 3.x
o Cisco Packet Tracer (or real Cisco Router/Switch) for networking simulation.
o Scapy Python library (for ARP simulation)
2. Hardware:
o Ethernet-enabled computer with network access
o Cisco Router/Switch (if using a physical network setup)
3. Knowledge:
o Basic understanding of Cisco Networking concepts (routers, switches, IP
addressing)
Theory
The Address Resolution Protocol (ARP) is a protocol used to resolve an IP address to its
corresponding MAC address within the same local area network (LAN). Devices in the LAN
use ARP to discover the MAC address associated with a known IP address.
ARP Request: Sent by a device when it needs to find the MAC address
corresponding to a given IP address.
ARP Reply: Sent by the device that owns the IP address with its MAC address.
1. Install Scapy
Before running the program, install the scapy library using the following command:
bash
Copy code
pip install scapy
# Send the request and capture the response (timeout is set to 1 second)
answered_list, unanswered_list = srp(arp_request_broadcast, timeout=1, verbose=False)
return answered_list
if answered_list:
display_result(answered_list)
else:
print("No response received. Please check the target IP address or your network
connection.")
1. Install Scapy
Open a terminal or command prompt and install the scapy library using the command:
bash
Copy code
pip install scapy
bash
Copy code
python arp_simulation.py
The program will ask for an IP address to query (e.g., 192.168.1.1). Enter the IP
address of a device within your local network.
Set up Cisco Packet Tracer: Create a simple network with a Cisco router or switch
and connect some end devices (PCs or servers). Assign IP addresses to these devices
within the same subnet.
Ping a Device in Cisco Packet Tracer: On a Cisco PC, open the command prompt
and ping another device (e.g., 192.168.1.1).
Observe ARP Behavior in Cisco: After pinging, use the show ip arp command on a
Cisco router or switch to observe the ARP cache. This will display the mapping of IP
addresses to MAC addresses in the local network.
In Cisco Packet Tracer, you can use the following command to view the ARP table on
a router or switch:
bash
Copy code
show ip arp
This will show the IP-to-MAC address mapping for devices that have been pinged
within the same subnet.
The Python program will display the IP and corresponding MAC address for the
given target IP after sending an ARP request. It will show something like:
text
Copy code
IP Address MAC Address
-----------------------------------------
192.168.1.1 00:1a:2b:3c:4d:5e
Sample Output
text
Copy code
Enter the target IP address (e.g., 192.168.1.1): 192.168.1.1
IP Address MAC Address
-----------------------------------------
192.168.1.1 00:1a:2b:3c:4d:5e
1. Set Up Wireshark
Open Wireshark and start capturing packets on the correct network interface
(Ethernet or Wi-Fi).
Apply a filter to only show ARP packets by typing the following in the filter bar:
text
Copy code
arp
You will be able to observe ARP requests and replies being exchanged between
devices.
ARP Request: Sent from a source IP to request the MAC address of the target IP.
ARP Reply: Sent from the device with the target IP, containing its MAC address.
Result
The Address Resolution Protocol (ARP) was successfully simulated in Python, and ARP
packets were analyzed using Wireshark and the Cisco Router/Switch. The IP address and
corresponding MAC address were obtained.
6.B SIMULATION OF REVERSE ADDRESS RESOLUTION PROTOCOL (RARP)
USING PYTHON
Aim
To simulate the Reverse Address Resolution Protocol (RARP) using Python and understand
how a device can obtain its IP address based on its MAC address.
Requirements
1. Software:
o Python 3.x
o Scapy Python library (for RARP simulation)
2. Hardware:
o Ethernet-enabled computer with network access
3. Knowledge:
o Basic understanding of networking protocols (especially ARP and RARP)
Theory
The Reverse Address Resolution Protocol (RARP) is the reverse process of ARP. While
ARP is used by devices to map an IP address to a MAC address, RARP allows a device to
map its MAC address to an IP address. RARP is generally used by diskless workstations to
find their IP address when they boot up, as they don't have the ability to store an IP address
locally.
RARP Request: A device sends a RARP request to a RARP server (typically a router
or dedicated server) to obtain its IP address.
RARP Reply: The server responds with the corresponding IP address for the given
MAC address.
1. Install Scapy
Before running the program, install the scapy library using the following command:
bash
Copy code
pip install scapy
2. RARP Simulation Program
python
# Send the request and capture the response (timeout is set to 1 second)
answered_list, unanswered_list = srp(rarp_request_broadcast, timeout=1, verbose=False)
return answered_list
if answered_list:
display_result(answered_list)
else:
print("No response received. Please check the MAC address or your network
connection.")
Steps to Perform the Experiment
1. Install Scapy
Open a terminal or command prompt and install the scapy library using the command:
bash
Copy code
pip install scapy
2. Run the Python Program
bash
Copy code
python rarp_simulation.py
The program will ask for a MAC address to query (e.g., 00:1a:2b:3c:4d:5e). Enter the
MAC address of a device in your local network.
The program will attempt to send a RARP request for the given MAC address and
print the corresponding IP address if available.
The RARP Request is sent to the network using the device's MAC address.
The RARP Reply from the server (or router) provides the IP address mapped to that
MAC address.
If the MAC address exists in the RARP server's database, the corresponding IP
address is displayed.
Sample Output
text
Copy code
Enter the MAC address (e.g., 00:1a:2b:3c:4d:5e): 00:1a:2b:3c:4d:5e
MAC Address IP Address
-----------------------------------------
00:1a:2b:3c:4d:5e 192.168.1.5
Steps to Capture RARP Packets Using Wireshark
1. Set Up Wireshark
Open Wireshark and start capturing packets on the correct network interface
(Ethernet or Wi-Fi).
Apply a filter to only show ARP and RARP packets by typing the following in the
filter bar:
text
Copy code
arp or rarp
You will be able to observe RARP requests and replies being exchanged between
devices.
RARP Request: Sent from a device with a specific MAC address to request its IP
address.
RARP Reply: Sent from the RARP server, containing the IP address corresponding to
the device's MAC address.
Result
The Reverse Address Resolution Protocol (RARP) was successfully simulated in Python, and
RARP packets were analyzed using Wireshark. The MAC address was mapped to the
corresponding IP address, as observed in the output of the Python program
Ex No. 7b SIMULATION OF CONGESTION CONTROL ALGORITHMS USING CISCO
Aim
To simulate and observe congestion control algorithms (such as TCP Tahoe, TCP Reno, and
TCP Vegas) using Cisco Packet Tracer and analyze how these algorithms manage congestion
in a network.
Requirements
1. Software:
o Cisco Packet Tracer (for network simulation)
o PC with Cisco Packet Tracer installed
2. Hardware:
o Ethernet-enabled computers or routers
3. Knowledge:
o Basic understanding of networking protocols, especially TCP congestion
control algorithms.
Theory
Congestion control algorithms are used in networks to prevent packet loss and ensure
efficient data transmission under varying network conditions. These algorithms adjust the
data transmission rate based on feedback from the network to avoid congestion.
TCP Tahoe: A basic congestion control mechanism that uses slow-start, congestion
avoidance, and fast retransmit.
TCP Reno: An enhanced version of TCP Tahoe that includes fast recovery to handle
packet loss.
TCP Vegas: An improved version of TCP Reno that uses the round-trip time (RTT)
for better congestion control and avoids overloading the network.
In a typical network, packet loss, delay, and network congestion can significantly impact
performance. TCP congestion control mechanisms help in dynamically adjusting the sender's
transmission rate to alleviate congestion, minimize delays, and optimize throughput.
Open Cisco Packet Tracer and create a network topology that includes:
o At least two PCs connected via a router.
o Add some switches if necessary for larger networks.
o Ensure both PCs are on the same network (subnet).
o Configure basic IP addressing for all devices in the network.
2. Configure Devices
PC Configuration:
1. On each PC, configure the IP address and subnet mask.
2. Ensure that the PCs can ping each other to confirm connectivity.
Router Configuration (if needed for routing):
1. Set up routing between subnets using static routes or a dynamic routing
protocol like RIP.
2. Configure the interfaces and IP addresses on the router.
To simulate congestion, generate traffic between the two PCs. This can be done using
ping or by initiating TCP connections (e.g., web traffic or file transfers).
For TCP traffic:
o Open the Command Prompt on one of the PCs.
o Use a command like ping -t 192.168.1.2 (replace with the target PC's IP
address) to generate continuous traffic.
o Alternatively, use a web server or FTP server on one of the PCs and use the
web browser on the other to generate TCP traffic.
5. Analyze Traffic
Once the network is running and traffic is flowing, observe the congestion window
(CWND) and Round-Trip Time (RTT). You can monitor these parameters using the
Simulation Mode in Cisco Packet Tracer.
Use the Command Prompt to view changes in RTT as congestion increases.
If packet loss occurs, observe the TCP behavior (slow start and congestion avoidance)
and how the sender reduces the transmission rate.
Expected Observations
TCP Tahoe: The window size increases exponentially at first (slow start) and then
linearly (congestion avoidance). Upon packet loss, TCP Tahoe resets the window size
to the initial value (slow start).
TCP Reno: TCP Reno performs similarly to TCP Tahoe but with an additional fast
recovery phase. After detecting a packet loss, Reno recovers faster by halving the
congestion window size but not resetting it entirely.
TCP Vegas: Vegas uses the round-trip time (RTT) to detect potential congestion
early and adjusts the sending rate before packet loss occurs. It aims to maintain a low
RTT by proactively reducing the window size.
Sample Topology
text
Copy code
[PC1] -------- [Router] -------- [PC2]
| |
Switch (optional) Switch (optional)
Result
The simulation successfully demonstrated the congestion control algorithms (TCP Tahoe,
TCP Reno, and TCP Vegas) in action. Observations of the TCP window size, RTT, and
packet loss showed how these algorithms adapt to network congestion to ensure efficient data
transfer.
Ex.No:8 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL :
Aim
To study and compare the performance of TCP and UDP protocols in a network using Cisco
Packet Tracer simulation.
Requirements
1. Software:
o Cisco Packet Tracer (Network Simulator)
2. Hardware:
o PCs, switches, and routers (simulated in Cisco Packet Tracer)
3. Knowledge:
o Basics of TCP and UDP protocols
o Configuration of IP addresses and devices in a network.
Theory
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are two primary
transport layer protocols.
Comparison:
TCP ensures reliable data transfer with higher latency, while UDP offers faster but less
reliable data transfer. This simulation demonstrates these differences.
text
Copy code
[PC1] --- [Switch] --- [Router] --- [Switch] --- [PC2]
IP Address Configuration:
o Assign IP addresses to all devices (PCs, routers) in the same subnet.
Example configuration:
o PC1: 192.168.1.2 /24
o Router Interface 1: 192.168.1.1 /24
o Router Interface 2: 192.168.2.1 /24
o PC2: 192.168.2.2 /24
Static Routing (if applicable):
Configure static routes on the router to enable communication between the subnets.
Use Simulation Mode in Cisco Packet Tracer to observe TCP and UDP traffic.
TCP Traffic:
o Configure a web server on PC2 and use a web browser on PC1 to access the
server.
o Alternatively, use a file transfer protocol (FTP) server.
o Observe the 3-way handshake (SYN, SYN-ACK, ACK) and acknowledgment
of packets.
UDP Traffic:
o Configure a TFTP (Trivial File Transfer Protocol) server on PC2 and use
PC1 to transfer files.
o Observe the lack of acknowledgment and retransmission.
Latency:
o Compare the delay experienced in TCP and UDP communication.
Packet Loss:
o Introduce network congestion or simulate packet loss to observe how TCP
retransmits lost packets, while UDP does not.
Throughput:
o Measure the rate of successful data delivery in both protocols.
o Use tools like ping or continuous file transfers to observe throughput.
5. Visualize Packets
Result
The performance of TCP and UDP protocols was successfully studied and analyzed using
Cisco Packet Tracer. The observations highlight the trade-offs between reliability and speed
in TCP and UDP.
EX.NO.9A SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM
Aim
To simulate the Distance Vector Routing (DVR) algorithm using Python and observe the
routing table updates and shortest path determination using Cisco Packet Tracer.
Requirements
1. Software:
o Python (Version 3.x)
o Cisco Packet Tracer
2. Hardware (Simulated in Cisco Packet Tracer):
o PCs, switches, and routers
3. Knowledge:
o Basics of Distance Vector Routing Algorithm
o Configuration of routing tables in Cisco devices.
Theory
A routing protocol where each router shares its routing table with directly connected
neighbors periodically.
It uses the Bellman-Ford algorithm to compute the shortest path.
Key steps include:
1. Initialization: Each node maintains a routing table.
2. Table Exchange: Nodes exchange routing information with neighbors.
3. Update: Nodes update their tables based on received information.
4. Convergence: Routing tables eventually stabilize.
Python Simulation
Algorithm:
1. Initialize the network as a graph with weighted edges representing the cost of links.
2. Assign each router a routing table initialized with direct neighbor costs.
3. Implement the Distance Vector Algorithm to update routing tables iteratively.
4. Print the final routing tables once convergence is achieved.
Python Code
python
Copy code
# Distance Vector Routing Algorithm Simulation in Python
def distance_vector_routing(graph, num_nodes):
# Initialize routing tables
routing_table = {node: {neighbor: float('inf') for neighbor in range(num_nodes)} for node
in range(num_nodes)}
for node in graph:
for neighbor, cost in graph[node]:
routing_table[node][neighbor] = cost
routing_table[node][node] = 0
lua
Copy code
R1 --- R2
| |
R3 --- R4
2. Assign IP Addresses:
o Configure IP addresses on the interfaces of each router.
3. Enable RIP (Routing Information Protocol):
o On each router, configure RIP as follows:
bash
Copy code
Router> enable
Router# configure terminal
Router(config)# router rip
Router(config-router)# version 2
Router(config-router)# network <subnet-ID>
Router(config-router)# exit
Router(config)# exit
o
Replace <subnet-ID> with the appropriate subnets for each router.
4. Observe Routing Table Updates:
o Use the show ip route command on each router to view the routing table
updates.
o Verify that the routers share their routing tables and determine the shortest
path.
Observations
Result
The Distance Vector Routing Algorithm was successfully simulated using Python and Cisco
Packet Tracer. Routing tables were updated dynamically, and shortest paths were determined
under varying network conditions.
9.B Simulation of Link State Routing Algorithm Using Python
Aim
To simulate the Link State Routing (LSR) algorithm using Python and observe how the
shortest paths are calculated and routing tables are updated dynamically.
Requirements
1. Software:
o Python (Version 3.x)
2. Knowledge:
o Basics of Link State Routing Algorithm
o Understanding of Dijkstra's Algorithm for shortest path computation
Theory
A routing protocol where each router knows the entire topology of the network.
Uses Dijkstra's Algorithm to compute the shortest path from the source to all other
nodes.
Steps:
1. Each router discovers its neighbors and measures the cost to reach them.
2. The router constructs a Link State Packet (LSP) containing the costs of its
directly connected links.
3. LSPs are exchanged with all other routers in the network.
4. Each router uses the collected LSPs to construct a complete topology map.
5. The shortest path to all nodes is calculated using Dijkstra’s algorithm.
Python Simulation
Algorithm:
For the above graph, the program will display routing tables with the shortest paths and costs
for each node.
Procedure
Observations
0 1 0→1 2
0 2 0→1→2 3
0 3 0→1→2→36
Result
The Link State Routing Algorithm was successfully simulated using Python, and the shortest
paths and routing tables were displayed for each node.
Ex No 10 .Simulation of Error Correction Code (Like CRC)
Aim
To simulate the Cyclic Redundancy Check (CRC) error correction code using Python and
verify its ability to detect errors in transmitted data.
Requirements
1. Software:
o Python (Version 3.x)
2. Knowledge:
o Basics of Error Detection and Correction
o Understanding of Cyclic Redundancy Check (CRC) Algorithm
Theory
Steps:
1. Append a number of zeros equal to the degree of the polynomial to the input message.
2. Divide the message by the generator polynomial using XOR operations.
3. The remainder is the CRC checksum.
4. Transmit the original message along with the checksum.
5. The receiver performs the division again. If the remainder is 0, the message is error-
free.
Python Simulation
Algorithm
Python Code
python
Copy code
def xor_operation(a, b):
"""Perform XOR operation between two binary strings."""
result = []
for i in range(1, len(b)):
if a[i] == b[i]:
result.append('0')
else:
result.append('1')
return ''.join(result)
if temp[0] == '1':
temp = xor_operation(generator, temp)
else:
temp = xor_operation('0' * pick, temp)
return temp
# Compute CRC
checksum = crc(data, generator)
print(f"CRC Checksum: {checksum}")
# Simulate transmission
transmitted_data = data + checksum
print(f"Transmitted Data: {transmitted_data}")
# Receiver validation
remainder = divide_data(transmitted_data, generator)
print(f"Remainder at Receiver: {remainder}")
if int(remainder) == 0:
print("No error detected in the transmitted data.")
else:
print("Error detected in the transmitted data.")
if __name__ == "__main__":
main()
Input:
Data: 1101011011
Generator Polynomial: 10011
Output:
Procedure
Observations
No error
1101011011 10011 1100 11010110111100 0000
detected
Error detected
1101011011 10011 1100 11010110111101 0001
in data
Result
The simulation of the Cyclic Redundancy Check (CRC) algorithm was successfully
implemented using Python, and it was able to detect errors in the transmitted data.