Computer Network Lab VR-23 III B. Tech II Sem DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING VIGNAN’S INSTITUTE OF INFORMATION TECHNOLOGY (A) (Approved by AICTE & Affiliated to JNTU-GV) Estd. – 2002 NAAC, NBA Accredited & ISO9001:2008, ISO 14001:2004, OHSAS18001:2007 Certified Institution Beside VSEZ, Duvvada, Visakhapatnam-530049. A.P. Phone: 0891-2755222/333/444: Fax: 0891-2752333: E-Mail:vignaniit@yahoo.com,www.vignaniit.com LAB MANUAL Syllabus Course Objectives: 1. Understand and apply different network commands 2. Analyze different networking functions and features for implementing optimal solutions Apply different networking concepts for implementing network solution 3. Implement different network protocols Course Outcomes: 1. Apply the basics of Physical layer in real time applications 2. Apply data link layer concepts, design issues, and protocols 3. Apply Network layer routing protocols and IP addressing 4. Implement the functions of Application layer and Presentation layer paradigms and Protocols Experiments: 1) Implement the data link layer farming methods such as character stuffing and bit stuffing. 2) Write a C program to develop a DNS client server to resolve the given hostname. 3) Implement on a data set of characters the three CRC polynomials – CRC-12, CRC-16and CRC-CCIP. 4) Implement Dijkstra’s algorithm to compute the shortest path in a graph. 5) Take an example subnet graph with weights indicating delay between nodes. Now obtain Routing table art each node using distance vector routing algorithm 6) Take an example subnet of hosts. Obtain broadcast tree for it. 7) Write a client-server application for chat using UDP 8) Implement programs using raw sockets (like packet capturing and filtering) 9) Write a C program to perform sliding window protocol. 10) Get the MAC or Physical address of the system using Address Resolution Protocol. 11) Simulate the Implementing Routing Protocols using border gateway protocol (BGP) 12) Simulate the OPEN SHORTEST PATH FIRST routing protocol based on the cost assigned to the path. 13) Install Wireshark Tool on PC and use into: Capture network traffic Determine default gateway address of your network Examine frame format and contents of Ethernet frames Filter and examine only ICMP traffic Run various network services like ping, ssh, dns ..etc and examine the traffic captured by Wire shark 14) Simulate a three nodes point-to-point network with duplex links between them. Set the queue size vary the bandwidth and find the number of packets dropped 15) Simulate a four-node point-to-point network, and connect the links as follows: n0-n2, n1- n2 and n2-n3. Apply TCP agent between n0-n3 and UDP between n1-n3. Apply relevant applications over TCP and UDP agents changing the parameter and determine the number of packets by TCP/UDP. 16) Simulate the transmission of ping messaged over a network topology consisting of 6nodes and find the number of packets dropped due to congestion. 17) Simulate an Ethernet LAN using N-nodes (6-10), change error rate and data rate and compare the throughput. 18) Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion window for different source/destination. * ns2/ns3/CISCO Packet Tracet/OPNET/any other network simulator may be used for simulation experiments INDEX S.No Contents Page No 1 Exercise – 1 Implement the data link layer farming methods such as character stuffing and bit stuffing. 2 Exercise – 2 Write a C program to develop a DNS client server to resolve the given hostname. 3 Exercise – 3 Implement on a data set of characters the three CRC polynomials – CRC - 12, CRC - 16 and CRC - CCIP. 4 Exercise – 4 Implement Dijkstra’s algorithm to compute the shortest path in a graph. 5 Exercise – 5 Take an example subnet graph with weights indicating delay between nodes. Now obtain Routing table art each node using distance vector routing algorithm 6 Exercise – 6 Take an example subnet of hosts. Obtain broadcast tree for it. 7 Exercise – 7 Write a client - server application for chat using UDP 8 Exercise – 8 Implement programs using raw sockets (like packet capturing and filtering) 9 Exercise – 9 Write a C program to perform sliding window protocol. 10 Exercise – 10 Get the MAC or Physical address of the system using Address Resolution Protocol. 11 Exercise – 1 1 Simulate the Implementing Routing Protocols using border gateway protocol (BGP) 12 Exercise – 1 2 Simulate the OPEN SHORTEST PATH FIRST routing protocol based on the cost assigned to the path. 13 Exercise – 1 3 Install Wireshark Tool on PC and use into: Capture network traffic Determine default gateway address of your network Examine frame format and contents of Ethernet frames Filter and examine only ICMP traffic Run various network services like ping, ssh, dns ..etc and examine the traffic captured by Wire shark 14 E xercise – 1 4 Simulate a three nodes point - to - point network with duplex links between them. Set the queue size vary the bandwidth and find the number of packets dropped 15 Exercise – 1 5 Simulate a four - node point - to - point network, and connect the links as follows: n0 - n2, n1 - n2 and n2 - n3. Apply TCP agent between n0 - n3 and UDP between n1 - n3. Apply relevant applications over TCP and UDP agents changing the parameter and determine the number of packets by TCP/UDP. 16 Exercise – 1 6 Simulate the transmission of ping messaged over a network topology consisting of 6nodes and find the number of packets dropped due to congestion. 17 Exercise – 1 7 Simulate an Ethernet LAN using N - nodes (6 - 10), change error rate and data rate and compare the throughput. 18 Exercise – 1 8 Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion window for different source/destination. Programs 1. Implement the data link layer farming methods such as character stuffing and bit stuffing. Description: Character stuffing is used in byte-oriented protocols such as BISYNC. Concept A special set of characters is used to mark the start and end of a frame: FLAG or DELIMITER (e.g., DLE STX for start and DLE ETX for end) If these characters appear in the actual data , the sender inserts an escape character (e.g., DLE ) to indicate that this is not a frame boundary but part of the data. How it works 1. Sender adds start delimiter 2. If the data contains the delimiter or escape characters: → Insert a DLE before them. 3. Add the end delimiter 4. Receiver removes the stuffed DLE and interprets correctly. Example Assume start = DLE STX, end = DLE ETX Data = A B DLE C Stuffed frame sent: DLE STX A B DLE DLE C DLE ETX Receiver removes the extra DLE to recover original data. Character Stuffing: def character_stuffing (data): start_flag = '@' end_flag = '#' escape_char = '/' stuffed_data = '' for char in data: if char in [start_flag, end_flag, escape_char]: stuffed_data += escape_char # Escape special characters stuffed_data += char framed_data = start_flag + stuffed_data + end_flag return framed_data # Example usage data = "Hello/@World#" stuffed = character_stuffing(data) print("Character Stuffed Frame:", stuffed) Bit Stuffing Bit stuffing is used in bit-oriented protocols like HDLC Concept HDLC uses a unique flag sequence : 01111110 To ensure the flag pattern does not appear in the data by accident, whenever the sender sees five consecutive 1s , it automatically inserts a 0 How it works 1. Sender continuously scans the data stream. 2. When it detects:11111 3. → It inserts 0 to avoid forming 01111110 4. Receiver removes any 0 that appears after five consecutive 1s. Example Data bits: 0111110111 After bit stuffing: 0111110 0111 (0 inserted after 11111) Receiver removes the stuffed 0 during decoding. Bit Stuffing: def bit_stuffing(dat a_bits): stuffed = '' count = 0 for bit in data_bits: stuffed += bit if bit == '1': count += 1 if count == 5: stuffed += '0' # Stuff a 0 after five 1s count = 0 else: count = 0 return stuffed # Example usage binary_data = "01111110111110" stuffed = bit_stuffing(binary_data) print("Bit Stuffed Data: ", stuffed) OUTPUT: Character Stuffed Frame: @Hello//@World/## Bit Stuffed Data: 0111110101111100 2. Write a C program to develop a DNS client server to resolve the given host name. Description: The Domain Name System (DNS) is a distributed, hierarchical naming system used to translate human-readable domain names (like www.example.com ) into machine- readable IP addresses (such as 192.168.1.10 ). DNS enables users to access websites using names instead of numeric addresses. The DNS Client , also called the Resolver , is responsible for generating DNS queries and processing responses. Functions of DNS Client Accepts a hostname request from the user or application. Checks the local DNS cache for the resolved IP address. If not available, forwards the query to a DNS server. Receives the DNS response and returns the IP address to the application. A DNS Server stores portions of the DNS database and provides answers to client queries. Program: // dns_client.c #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <string.h> #include <arpa/inet.h> int main() { char hostname[100]; struct hostent *host_entry; char *IPbuffer; // Get hostname input printf("Enter hostname to resolve (e.g., www.google.com): "); scanf("%s", hostname); // Resolve hostname host_entry = gethostbyname(hostname); if (host_entry == NULL) { fprintf(stderr, "Could not resolve hostname.\n"); return 1; } // Convert to IP string IPbuffer = inet_ntoa(*((struct in_addr*)host_entry->h_addr_list[0])); printf("Host name : %s\n", host_entry->h_name); printf("IP Address : %s\n", IPbuffer); return 0; } OUTPUT : Enter hostname to resolve (e.g., www.google.com): www.google.com Host name : www.google.com IP Address : 142.250.184.100 3.Implement on a data set of characters the three CRC polynomials – CRC-12, CRC-16 and CRC-CCITT Description: CRC is an error-detecting code used in data communication. It treats the input data as a polynomial and divides it by a fixed generator polynomial (G(x)) The remainder of this division is the CRC code, which is appended to the data before transmission. At the receiver end, the same division is performed. If the remainder = 0 , data is error-free. Otherwise, an error occurred Generator Polynomials 1. CRC - 12 Polynomial Degree: 12 Polynomial: G(x) = x^{12} + x^{11} + x^3 + x^2 + 1 Binary representation: 1100000001111 CRC - 16 Polynomial Degree: 16 Polynomial: G(x) = x^{16} + x^{15} + x^2 + 1 Binary representation: 11000000000000101 CRC - CCITT Polynomial Degree: 16 Polynomial: G(x) = x^{16} + x^{12} + x^5 + 1 Binary representation: 10001000000100001 Program: #include <stdio.h> #include <string.h> void crc(char data[], char gp[], int gp_len) { int i, j; char temp[100], rem[100]; strcpy(temp, data); for (i = 0; i < gp_len - 1; i++) strcat(temp, "0"); for (i = 0; i < strlen(temp); i++) rem[i] = temp[i]; for (i = 0; i <= strlen(temp) - gp_len; i++) { if (rem[i] == '1') { for (j = 0; j < gp_len; j++) rem[i + j] = ((rem[i + j] == gp[j]) ? '0' : '1'); } } printf("CRC: "); for (i = strlen(temp) - gp_len + 1; i < strlen(temp); i++) printf("%c", rem[i]); printf("\n"); } int main() { char data[50]; printf("Enter data bits: "); scanf("%s", data); printf("\n-- CRC-12 --\n"); crc(data, "1100000001111", 13); printf("\n-- CRC-16 --\n"); crc(data, "11000000000000101", 17); printf("\n-- CRC-CCITT --\n"); crc(data, "10001000000100001", 17); return 0; } Output Enter data bits: 1101011011 -- CRC-12 -- CRC: 011101011111 -- CRC-16 -- CRC: 1010000110010101 -- CRC-CCITT -- CRC: 1100100001110001 def crc12(data: bytes) -> int: """ Compute CRC-12 (3GPP) for given byte data. Polynomial: x^12 + x^11 + x^3 + x^2 + x + 1 (0x80F) """ width = 12 poly = 0x80F mask = (1 << width) - 1 topbit = 1 << (width - 1) crc = 0x000 for byte in data: crc ^= (byte << (width - 8)) for _ in range(8): if crc & topbit: crc = ((crc << 1) ^ poly) & mask else: crc = (crc << 1) & mask return crc # Example dataset dataset = ["HELLO", "WORLD", "CRC", "DATA"] for text in dataset: value = crc12(text.encode('utf-8')) print(f"Input: {text!r}, CRC-12 = 0x{value:03X}") OUTPUT : Input: 'HELLO', CRC-12 = 0xD44 Input: 'WORLD', CRC-12 = 0xC7C Input: 'CRC', CRC-12 = 0x8A6 Input: 'DATA', CRC-12 = 0xD82 4. Implement Dijkstra’s algorithm to compute the shortest path in a graph. Description: Dijkstra’s algorithm is a greedy-based shortest path algorithm used to compute the shortest distance from a source node to all other nodes in a weighted graph with non-negative edge weights It is widely used in routing , network optimization , and graph-based applications Applications OSPF routing protocol Google Maps shortest road routing Network routing optimization Robot path planning Telecommunications network analysis import heapq def dijkstra(graph, start): # Initialize distances with infinity distances = {vertex: float('inf') for vertex in graph} distances[start] = 0 # Priority queue for the next node to visit pq = [(0, start)] while pq: current_distance, current_vertex = heapq.heappop(pq) # If we already found a shorter path before, skip if current_distance > distances[current_vertex]: continue # Explore neighbors for neighbor, weight in graph[current_vertex].items(): distance = current_distance + weight # If a shorter path is found if distance < distances[neighbor]: distances[neighbor] = distance heapq.heappush(pq, (distance, neighbor)) return distances # Example graph (Adjacency List representation) graph = { 'A': {'B': 4, 'C': 2}, 'B': {'A': 4, 'C': 5, 'D': 10}, 'C': {'A': 2, 'B': 5, 'D': 3}, 'D': {'B': 10, 'C': 3} } # Run Dijkstra's Algorithm start_node = 'A' shortest_paths = dijkstra(graph, start_node) # Output shortest distances print(f"Shortest paths from {start_node}:") for node, distance in shortest_paths.items(): print(f" - {node}: {distance}") OUTPUT : Shortest paths from A: - A: 0 - B: 4 - C: 2 - D: 5 5. Take an example subnet graph with weights indicating delay between nodes. Now obtain Routing table art each node using distance vector routing algorithm 6. Take an example subnet of hosts. Obtain a broadcast tree for it. #include<stdio.h> #define MAX 10 int adjacencyMatrix[MAX][MAX]; int numNodes; // Function to display adjacent nodes of a given node void displayAdjacentNodes(int rootNode) { int i; printf("\nAdjacent nodes of node %d:\n", rootNode); for (i = 1; i <= numNodes; i++) { if (adjacencyMatrix[rootNode][i] == 1 || adjacencyMatrix[i][rootNode] == 1) { printf("%d\t", i); } } printf("\n"); } int main() { int i, j, rootNode; // Input number of nodes printf("Enter number of nodes: "); scanf("%d", &numNodes); // Input the adjacency matrix printf("Enter adjacency matrix:\n"); for (i = 1; i <= numNodes; i++) { for (j = 1; j <= numNodes; j++) { printf("Is there a connection from node %d to node %d (1=yes, 0=no): ", i, j); scanf("%d", &adjacencyMatrix[i][j]); } } // Input the root node printf("Enter root node (1 to %d): ", numNodes); scanf("%d", &rootNode); // Display adjacent nodes