[go: up one dir, main page]

0% found this document useful (0 votes)
17 views13 pages

Advanced Computer Networks Lab Manual

This document is a lab manual for the Advanced Computer Networks Lab for the Master of Technology in Computer Science and Engineering at Vaageswari College of Engineering. It includes implementations of various networking concepts such as IP fragmentation and reassembly, IP forwarding table lookup, and the sliding window protocol, along with practical exercises involving network configuration and packet analysis using Wireshark. The manual provides detailed coding examples and instructions for setting up network connections and analyzing packet headers.

Uploaded by

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

Advanced Computer Networks Lab Manual

This document is a lab manual for the Advanced Computer Networks Lab for the Master of Technology in Computer Science and Engineering at Vaageswari College of Engineering. It includes implementations of various networking concepts such as IP fragmentation and reassembly, IP forwarding table lookup, and the sliding window protocol, along with practical exercises involving network configuration and packet analysis using Wireshark. The manual provides detailed coding examples and instructions for setting up network connections and analyzing packet headers.

Uploaded by

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

Master of Technology

COMPUTER SCIENCE AND ENGINEERING

REGULATION : R22

MTech I – II Sem CSE

LAB MANUAL
for
ADVANCED COMPUTER NETWORKS LAB

VAAGESWARI COLLEGE OF ENGINEERING

BESIDE LMD POLICE STATION, RAMAKRISHNA COLONY


KARIMNAGAR - 505481

ACN LAB MANUAL


1. Implement the IP fragmentation and reassembly algorithm.// A structure
that represents an IP header
struct ip_header {
unsigned char version_ihl; // Version and Internet Header Length
unsigned char tos; // Type of Service
unsigned short total_length; // Total Length
unsigned short identification; // Identification
unsigned short flags_offset; // Flags and Fragment Offset
unsigned char ttl; // Time to Live
unsigned char protocol; // Protocol
unsigned short checksum; // Header Checksum
unsigned int source_address; // Source Address
unsigned int destination_address; // Destination Address
};
// A structure that represents an IP datagram
struct ip_datagram {
struct ip_header header; // IP header
unsigned char *data; // Data payload
};

// A structure that represents a fragment list entry


struct fragment_list_entry {
struct ip_datagram *fragment; // Fragment datagram
struct fragment_list_entry *next; // Next entry in the list
};

// A structure that represents a reassembly buffer entry


struct reassembly_buffer_entry {
unsigned short identification; // Identification of the original datagram
unsigned int source_address; // Source Address of the original datagram
unsigned int destination_address; // Destination Address of the original datagram
unsigned char protocol; // Protocol of the original datagram
struct fragment_list_entry *fragment_list_head; // Head of the fragment list
struct fragment_list_entry *fragment_list_tail; // Tail of the fragment list
struct reassembly_buffer_entry *next; // Next entry in the buffer
};

// A global variable that holds the head of the reassembly buffer


struct reassembly_buffer_entry *reassembly_buffer_head = NULL;

// A function that creates a new IP datagram with a given header and data payload
struct ip_datagram *create_ip_datagram(struct ip_header header, unsigned char *data) {
struct ip_datagram *datagram = (struct ip_datagram *)malloc(sizeof(struct ip_datagram));
// Allocate memory for the datagram
if (datagram == NULL) {
return NULL; // Memory allocation failed
}
datagram->header = header; // Copy the header
datagram->data = data; // Set the data pointer
return datagram; // Return the datagram
}

// A function that frees an IP datagram and its data payload


void free_ip_datagram(struct ip_datagram *datagram) {
if (datagram != NULL) {
if (datagram->data != NULL) {
free(datagram->data); // Free the data payload
}
free(datagram); // Free the datagram structure
}
}

// A function that creates a new fragment list entry with a given fragment datagram
struct fragment_list_entry *create_fragment_list_entry(struct ip_datagram *fragment) {
struct fragment_list_entry *entry = (struct fragment_list_entry *)malloc(sizeof(struct
fragment_list_entry)); // Allocate memory for the entry
if (entry == NULL) {
return NULL; // Memory allocation failed
}
entry->fragment = fragment; // Set the fragment pointer
entry->next = NULL; // Set the next pointer to NULL
return entry; // Return the entry
}

// A function that frees a fragment list entry and its fragment datagram
void free_fragment_list_entry(struct fragment_list_entry *entry) {
if (entry != NULL) {
free_ip_datagram(entry->fragment); // Free the fragment datagram
free(entry); // Free the entry structure
}
}
// A function that creates a new reassembly buffer entry with a given identification, source
address, destination address, and protocol
struct reassembly_buffer_entry *create_reassembly_buffer_entry(unsigned short
identification, unsigned int source_address, unsigned int destination_address, unsigned char
protocol) {
struct reassembly_buffer_entry *entry = (struct reassembly_buffer_entry
*)malloc(sizeof(struct reassembly_buffer_entry)); // Allocate memory for the entry
if (entry == NULL) {
return NULL; // Memory allocation failed
}
entry->identification = identification; // Set the identification
entry->source_address = source_address; // Set the source address
entry->destination_address = destination_address; // Set the destination address
entry->protocol = protocol; // Set the protocol
entry->fragment_list_head = NULL; // Set the fragment list head to NULL
entry->fragment_list_tail = NULL; // Set the fragment list tail to NULL
entry->next = NULL; // Set the next pointer to NULL
return entry; // Return the entry
}

2. implement IP forwarding table lookup


#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 15
#define N 150
// Declaration of structure of linked list
// to store ip address in each node
struct node {
char* data;
struct node* next;
} * head[15];
// This function fetch data from file
// and store them into different arrays
void storeData(FILE* fp,
char buf[M][N],
char net[M][N],
char mask[M][N],
char gateway[M][N],
char port[M][N])
{

char line[200];
int c, i = 0, j, k = 0, m = 0;
// Read data from the file line by line
// and each line is stored in array separately.
while (fgets(line, sizeof(line), fp)) {
j = 0;
for (int l = 0; l < strlen(line); l++) {
buf[i][j] = line[l];
j++;
}
i++;
}
// From each lines stored in buf,
// network id, subnet mask, gateway
// and port are extracted
// and stored into individual arrays.
for (i = 0; i < 15; i++) {
k = 0;
for (j = 0; buf[i][j] != ','; j++) {
net[i][k] = buf[i][j];
k++;
}
m = j + 2;
k = 0;
for (j = m; buf[i][j] != ','; j++) {
mask[i][k] = buf[i][j];
k++;
}
m = j + 2;
k = 0;
for (j = m; buf[i][j] != ','; j++) {
gateway[i][k] = buf[i][j];
k++;
}
m = j + 2;
k = 0;
for (j = m; buf[i][j] != '\0'; j++) {
port[i][k] = buf[i][j];
k++;
}
}
}
// Function to create routing table
// using arrays created by storeData() function
// using linked list data structure
void insert(char net[M][N], char mask[M][N],
char gateway[M][N], char port[M][N],
char buf[M][N])
{
char *temp1, *temp2, *temp3, *temp4;
struct node* new;

for (int i = 0; i < M; i++) {

// Initialize head of each


// linked list with NULL.
head[i] = NULL;
}
for (int i = 0; i < M; i++) {
for (int j = 0; j < 4; j++) {

// If head is null
// then first create new node
// and store network id into it.
if (head[i] == NULL) {

new = (struct node*)malloc(


sizeof(struct node));
new->data = net[i];
new->next = NULL;
head[i] = new;
}
// If head is not null
// and value of j is 1 then create new node
// which is pointed by head and it
// will contain subnet mask
else if (j == 1) {
new->next = (struct node*)malloc(
sizeof(struct node));
new = new->next;
new->data = mask[i];
new->next = NULL;
}

// If head is not null and value of j is 2


// then create new node
// which is pointed by subnet mask
// and it will contain gateway
else if (j == 2) {

new->next = (struct node*)malloc(


sizeof(struct node));
new = new->next;
new->data = gateway[i];
}

// If head is not null and value of j is 3


// then create new node
// which is pointed by gateway and
// it will contain port
else if (j == 3) {
new->next = (struct node*)malloc(
sizeof(struct node));
new = new->next;
new->data = port[i];
}
}
}
// Perform sorting on the basis
// of longest prefix of subnet mask
for (int i = 0; i < M; i++) {
for (int j = i; j < M; j++) {

// Longest prefix has been compared


// by using inet_addr() system call
// which gives decimal value of an ip address.
if (inet_addr(head[i]->next->data)
< inet_addr(head[j]->next->data)) {

struct node* temp = head[i];


head[i] = head[j];
head[j] = temp;
}
}
}
}

// This function will search for gateway ip


// and port number in routing table
// through which packet has been sent
// to next node/destination
void search(FILE* fp1, FILE* fp2)
{

char str[100];
struct in_addr addr;
unsigned int val;
fprintf(fp2, "%c", ' ');

// Read file '[Link]' line by line


// and perform bitwise AND between subnet mask
// and input(destination) ip coming from file.
while (fgets(str, sizeof(str), fp1)) {
for (int i = 0; i < M; i++) {

// Perform bitwise AND operation on result


// (i.e. Decimal value of an ip address)
// coming from inet_addr() system call
val = inet_addr(str) & inet_addr(head[i]->next->data);
addr.s_addr = val;
char* str1 = inet_ntoa(addr);
char* str2 = head[i]->data;
int count = 0;

// Compare the network id string with result


// coming after performing AND operation
// and if they are same then increment count.
for (int i = 0; str1[i] != '\0'; i++) {

if (str1[i] == str2[i]) {
count++;
}
}

// If count is same as the string length


// of network id then find gateway ip
// and port number of that respective network id
// and write it into '[Link]' file.
if (count == strlen(str1)) {

struct node* ptr = head[i]->next;


struct node* temp = ptr->next;
while (temp != NULL) {

fprintf(fp2, "%s ", temp->data);


temp = temp->next;
}
break;
}
}
}
}

// Driver code
int main(int argc, char* argv[])
{

FILE *fin, *fout, *fp;


char buf[M][N] = { { 0 } };
char net[M][N] = { { 0 } };
char mask[M][N] = { { 0 } };
char gateway[M][N] = { { 0 } };
char port[M][N] = { { 0 } };

// if command line argument is less than 3


// then it will show standard error.
if (argc < 3) {

fprintf(stderr, "File name:%s\n", argv[0]);


return 1;
}

// If 3 arguments are given then input


// and [Link] files will be opened in read mode
// while [Link] file is opened in write mode.
else {

fin = fopen(argv[1], "r");


fout = fopen(argv[2], "w");
fp = fopen(argv[3], "r");
}

// If any of the file is not present


// then it will give an error.
if (fp == NULL || fin == NULL || fout == NULL) {

printf("Error");
return 0;
}

// This function will read the data


// of a file '[Link]' line by line
// and store them into one array named 'buf',
// after that the coma separated values in buf
// are stored into their respective array.
storeData(fp, buf, net, mask, gateway, port);
// It will create routing table using linked list
insert(net, mask, gateway, port, buf);
// It will take input from [Link] files
// which contains only destination ip address
// and search about the route through which
// packet has been sent in network
// and output is stored in to an [Link] file
search(fin, fout);
printf("Forwarding table has been implemented successfully");
printf("See the output in %s file\n", argv[2]);

/*Closes all the files*/


fclose(fin);
fclose(fp);
fclose(fout);
return 0;
}
3. Sliding window protocol
#include<stdio.h>

int main()
{
int w,i,f,frames[50];

printf("Enter window size: ");


scanf("%d",&w);

printf("\nEnter number of frames to transmit: ");


scanf("%d",&f);

printf("\nEnter %d frames: ",f);

for(i=1;i<=f;i++)
scanf("%d",&frames[i]);

printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by
the receiver\n\n",w);

for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}

if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");

return 0;
}
4. Connect two systems using a switch and configure private IP addresses to
the systems and ping them from each other. Using Wireshark, capture
packets and analyze all the header information in the packets captured.
Here are the steps you need to follow:
1. Connect the two systems to the switch using Ethernet cables. Make sure the switch is
powered on and the cables are properly plugged in.
2. On each system, open the network settings and assign a static IP address in the same
subnet. For example, you can use [Link] for one system and [Link] for
the other system. Use [Link] as the subnet mask and leave the default gateway
and DNS server fields blank.
3. To test the connectivity, open a command prompt on one system and ping the other
system’s IP address. For example, type ping [Link] and press Enter. You should
see replies from the other system if the connection is successful.
4. Launch Wireshark and select the network interface that is connected to the switch.
Click the shark fin icon or press Ctrl+E to start capturing packets.
5. To filter packets, you can use the filter bar at the top of the Wireshark window. You can
enter expressions to match specific protocols, addresses, ports, or fields. For example,
you can enter [Link] == [Link] to show only packets that have [Link] as
either the source or destination IP address.
6. To inspect packets, you can click on any packet in the packet list pane (the top section)
and see its details in the packet details pane (the middle section). You can expand or
collapse different layers of the packet by clicking on the plus or minus signs next to
them. You can also see the raw data of the packet in hexadecimal and ASCII formats
in the packet bytes pane (the bottom section).
7. To analyze packet headers, you can look at the fields in the packet details pane and see
their values and meanings. For example, you can see the source and destination IP
addresses, protocol types, flags, checksums, sequence numbers, etc. You can also
right-click on any field and select various options such as applying filters, copying
values, or showing graphs.

5. Install Telnet on one of the systems connected by a switch and telnet to it


from the other system. Using Wireshark, capture the packets and analyze
the TCP 3-way Handshake for connection establishment and tear down.
Here are the steps you need to follow:
To install Telnet on Windows 10, you can use either the Control Panel or the Command
Prompt. If you use the Control Panel, go to Programs and Features, then click Turn Windows
features on or off. Find Telnet Client in the list and check it, then click OK. If you use the
Command Prompt, run it as an administrator and type the following command: dism /online
/Enable-Feature /FeatureName:TelnetClient. You can find more details on how to install
Telnet on Windows 10 in this article1.
To install Telnet on macOS, you need to install the Homebrew package manager first. You
can do this by opening the Terminal and typing the following command: /bin/bash -c "$(curl -
fsSL [Link] Then, you can
install Telnet by typing: brew install telnet. You can find more details on how to install Telnet
on macOS in this article.
To use Telnet to connect to another system, you need to know the IP address or hostname of
the target system. You can find this by using the ipconfig command on Windows or the
ifconfig command on macOS. Then, you can open a Telnet session by typing: telnet <IP
address or hostname>. For example, if the target system has an IP address of [Link],
you can type: telnet [Link]. You can find more details on how to use Telnet in this
article.
To capture TCP packets with Wireshark, you need to download and install Wireshark from its
official website. Then, you need to launch Wireshark and select the network interface that
you want to capture packets from. For example, if you want to capture packets from your
wireless network, select your wireless interface. Then, click the Start button or press Ctrl+E
to begin capturing packets. You can stop capturing packets by clicking the Stop button or
pressing Ctrl+E again. You can find more details on how to capture packets with Wireshark
in this article1.
To analyze the TCP 3-way handshake for connection establishment and tear down, you need
to filter the captured packets by using the expression: [Link] == 1 || [Link] == 1.
This will show only the packets that have either the SYN or FIN flag set, which are used for
opening and closing TCP connections. Then, you can select a packet and inspect its details in
the middle pane of Wireshark. You can see the source and destination IP addresses and ports,
as well as the sequence and acknowledgment numbers of each packet. The TCP 3-way
handshake consists of three steps: SYN, SYN-ACK, and ACK. The first packet is sent by the
client with the SYN flag set and a random sequence number (for example, 1000). The second
packet is sent by the server with both the SYN and ACK flags set and a random sequence
number (for example, 2000) and an acknowledgment number equal to the client’s sequence
number plus one (for example, 1001). The third packet is sent by the client with only the
ACK flag set and an acknowledgment number equal to the server’s sequence number plus
one (for example, 2001). The TCP connection is then established and data can be exchanged
between the client and server. The TCP connection is closed by using a similar process with
the FIN flag instead of the SYN flag.
To analyze TCP packets with Wireshark, you need to follow these steps:

1. Download and install Wireshark from [its official website] if you haven't already.
2. Launch Wireshark and select the network interface that you want to capture packets from.
For example, if you want to capture packets from your wireless network, select your wireless
interface.
3. Click the Start button or press Ctrl+E to begin capturing packets. You can stop capturing
packets by clicking the Stop button or pressing Ctrl+E again.
4. Filter the captured packets by using the expression: `[Link] == 1 || [Link] ==
1`. This will show only the packets that have either the SYN or FIN flag set, which are used
for opening and closing TCP connections.
5. Select a packet and inspect its details in the middle pane of Wireshark. You can see the
source and destination IP addresses and ports, as well as the sequence and acknowledgment
numbers of each packet.
6. The TCP 3-way handshake consists of three steps: SYN, SYN-ACK, and ACK. The first
packet is sent by the client with the SYN flag set and a random sequence number (for
example, 1000). The second packet is sent by the server with both the SYN and ACK flags
set and a random sequence number (for example, 2000) and an acknowledgment number
equal to the client's sequence number plus one (for example, 1001). The third packet is sent
by the client with only the ACK flag set and an acknowledgment number equal to the server's
sequence number plus one (for example, 2001). The TCP connection is then established and
data can be exchanged between the client and server.
7. The TCP connection is closed by using a similar process with the FIN flag instead of the
SYN flag. The client sends a packet with the FIN flag set and a sequence number (for
example, 3000). The server responds with a packet with both the FIN and ACK flags set and
a sequence number (for example, 4000) and an acknowledgment number equal to the client's
sequence number plus one (for example, 3001). The client sends a final packet with only the
ACK flag set and an acknowledgment number equal to the server's sequence number plus one
(for example, 4001). The TCP connection is then terminated.

6. Start packet capture in wireshark application and then open your web
browser and type in an URL of the website of your choice. How long did it
take from when the HTTP GET message was sent until the HTTP OK reply
was received for the web page you visited in your web browser.
we need to use Wireshark to analyze the response time of the web server that hosts the
website you visited. Response time is the time it takes for a web server to process a request
and send back a response. It is an important metric for measuring the performance and
latency of web applications.

There are different ways to measure response time using Wireshark, but one common method
is to use the [Link] field, which shows the elapsed time between the HTTP GET request
and the HTTP OK response. To use this method, you need to follow these steps:
- Start packet capture in Wireshark on the interface that connects to the Internet.
- Open your web browser and type in the URL of the website of your choice. For example,
[Link]
- Go back to Wireshark and stop the capture.
- Apply a display filter to show only HTTP traffic. You can use the filter `http` or `[Link] =
80` or `[Link] == 443` depending on whether the website uses HTTP or HTTPS protocol.
- Find the packet that contains the HTTP GET request for the website. You can look for the
packet that has `GET / HTTP/1.1` in the Info column, or use the filter `[Link] =
GET`.
- Right-click on the packet and select Follow > TCP Stream. This will show you all the
packets that belong to the same TCP connection between your browser and the web server.
- In the TCP Stream window, look for the packet that contains the HTTP OK response for the
website. You can look for the packet that has `HTTP/1.1 200 OK` in the Info column, or use
the filter `[Link] == 200`.
- Note down the timestamps of both packets. You can see them in the Time column, or by
expanding the Frame section in the Packet Details pane.
- Subtract the timestamp of the HTTP GET request from the timestamp of the HTTP OK
response. This will give you the response time in seconds.

You might also like