22mcal17 CN Lab Manual
22mcal17 CN Lab Manual
LAB MANUAL
SCHEME: 2022
CODE: 22MCAL17
SEMESTER : 01
PREPARED BY:
Ms. Veena S & Dr. Gomathy Prathima E
AIT-MCA Mission
AIT-MCA-PEOs
AIT-MCA-PSOs
COMPUTER NETWORK LABORATORY (Effective from the academic year 2021 -2022)
SEMESTER – I
Subject Code 22MCAL17 CIE Marks 50
Number of Contact Hours/Week 0:3:0 SEE Marks 50
Credits 1.5 Exam Hours 3 Hrs
Course objectives:
To understand the working principle of various communication protocols.
To understand the network simulator environment and visualize a network topology and
observe its performance
Experiments
1 Implement three nodes point — to — point network with duplex links between them. Set the
queue size and vary the bandwidth and find the number of packets dropped .
2. Implement the data link layer framing methods such as character, character-stuffing and bit
stuffing.
3.Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP
4. Develop a simple data link layer that performs the flow control using the sliding window
protocol, and loss recovery using the Go-Back-N mechanism.
5. Implement Dijsktra's algorithm to compute the shortest path through a network
6. Implement data encryption and data decryption
7. Simulate the network with five nodes nO, nl, n2, n3, n4, forming a star topology. The node
n4 is at the centre. Node nO is a TCP source, which transmits packets to node n3 (a TCP
sink) through the node n4. Node nl is another traffic source, and sends UDP packets to node
n2 through n4. The duration of the simulation time is 10 seconds.
8. Simulate to study transmission of packets over Ethernet LAN and determine the number
of packets drop destination.
2. Implement the data link layer framing methods such as character, character-stuffing and bit
stuffing.
3.Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP
4. Develop a simple data link layer that performs the flow control using the sliding window
protocol, and loss recovery using the Go-Back-N mechanism.
5. Implement Dijsktra's algorithm to compute the shortest path through a network
6. Implement data encryption and data decryption
7. Simulate the network with five nodes nO, nl, n2, n3, n4, forming a star topology. The node
n4 is at the centre. Node nO is a TCP source, which transmits packets to node n3 (a TCP
sink) through the node n4. Node nl is another traffic source, and sends UDP packets to node
n2 through n4. The duration of the simulation time is 10 seconds.
8. Simulate to study transmission of packets over Ethernet LAN and determine the number
of packets drop destination.
Demonstration Experiments ( For CIE) if any
9. Simulate the different types of internet traffic such as FTP and TELNET over a wired network
and analyze the packet drop and packet delivery ratio in the network
2. Implement the data link layer framing methods such as character, character-stuffing
and bit stuffing.
#include <stdio.h>
int main() {
int i, j, count = 0;
int data[20], stuffed_data[30];
// Read the input data
printf("Enter the data: ");
for(i = 0; i < 20; i++) {
scanf("%d", &data[i]);
}
// Perform bit stuffing
j = 0;
for(i = 0; i < 20; i++) {
stuffed_data[j] = data[i];
if(data[i] == 1) {
count++;
}
else {
count = 0;
}
j++;
if(count == 5) {
stuffed_data[j] = 0;
j++;
count = 0;
}
}
return 0;
}
------
This program takes an input string from the user and performs character stuffing using start and
end delimiters and an escape character. The start and end delimiters are defined as !, and the
escape character is defined as \. The input string is scanned using scanf and then the stuffed string
is created using a for loop. Each character in the input string is checked to see if it matches the
start or end delimiter or the escape character. If it does, an escape character is added to the stuffed
string before the character. Finally, the start and end delimiters are added to the beginning and
end of the stuffed string, respectively, and the stuffed string is printed to the console.
#include <stdio.h>
#include <string.h>
int main() {
char start_delimiter = '!';
char end_delimiter = '!';
char escape_character = '\\';
char input_string[100], stuffed_string[100];
int i, j = 0;
printf("Enter the input string: ");
scanf("%s", input_string);
stuffed_string[j++] = start_delimiter;
for (i = 0; i < strlen(input_string); i++) {
if (input_string[i] == start_delimiter || input_string[i] == end_delimiter || input_string[i] ==
escape_character) {
stuffed_string[j++] = escape_character;
}
stuffed_string[j++] = input_string[i];
}
stuffed_string[j++] = end_delimiter;
stuffed_string[j] = '\0';
printf("The stuffed string is: %s", stuffed_string);
return 0;
}
Output:
Enter the input string: hello!world!
The stuffed string is: !hello\!world\!!
3.Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC
CCIP
4. Develop a simple data link layer that performs the flow control using the sliding
window protocol, and loss recovery using the Go-Back-N mechanism.
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent == windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);
if(ack == windowsize)
break;
else
sent = ack;
}
return 0;
}
output:-
enter window size
8
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
dist[i]=999;
}
dist[s]=0;
while(count<=n)
{
min=99;
for(v=1;v<=n;v++)
if(dist[v]<min && !flag[v])
min=dist[v],u=v;
flag[u]=1;
count++;
for(v=1;v<=n;v++)
if((dist[u]+cost[u][v]< dist[v])&& !flag[v])
dist[v]=dist[u]+cost[u][v];
}
}
int main()
{
int i,j,n;
printf("Enter the vertices:");
scanf("%d",&n);
printf("\n enter the cost matrix:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0) cost[i][j]=999;
}
printf("\n enter the source vertex:");
scanf("%d",&s);
dijkstra(n);
printf("\n the shortest path \n");
for(i=1;i<=n;i++)
{
if(i!=s)
printf(" %d -> %d , cost =%d\n",s,i,dist[i]);
}
return 0;
}
Output:
Program
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <math.h>
int mult(unsigned int x, unsigned int y, unsigned int n) {
unsigned long int k=1;
int j;
for (j=1; j<=y; j++) k = (k * x) % n;
return (unsigned int) k;
}
void main () {
char msg[100];
unsigned int pt[100], ct[100], n, d, e, p, q, i;
printf("Enter message : "); gets(msg);
//strcpy(pt, msg);
for(i=0;i<strlen(msg);i++)
pt[i]=msg[i];
n = 253; d = 17; e = 13;
printf("\nCT = ");
for(i=0; i<strlen(msg); i++) ct[i] = mult(pt[i], e,n);
for(i=0; i<strlen(msg); i++) printf("%d ", ct[i]);
printf("\nPT = ");
for(i=0; i<strlen(msg); i++) printf("%c", pt[i]);
for(i=0; i<strlen(msg); i++) pt[i] = mult(ct[i], d,n) ;
}
Output
Enter message : alpha
CT = 113 3 129 213 113
PT = alpha
7. Simulate the network with five nodes nO, nl, n2, n3, n4, forming a star topology. The
node n4 is at the centre. Node nO is a TCP source, which transmits packets to node n3
(a TCP sink) through the node n4. Node nl is another traffic source, and sends UDP
packets to node n2 through n4. The duration of the simulation time is 10 seconds.
set ns [new Simulator]
set namfile [open ex_01.nam w]
$ns namtrace-all $namfile
set tracefile [open ex_01.tr w]
$ns trace-all $tracefile
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
$ns duplex-link $n0 $n4 1Mb 10ms DropTail
$ns duplex-link $n1 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n3 1Mb 10ms DropTail
$ns duplex-link $n4 $n2 1Mb 10ms DropTail
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n2 $null
$ns connect $udp $null
$udp set class_ 1
$ns color 1 Blue
$tcp set class_ 2
$ns color 2 Red
set cbr [new Application/Traffic/CBR]
$cbr set packetsize_ 500
$cbr set interval_ 0.005
$cbr attach-agent $udp
$ns at 0.0 "$cbr start"
$ns at 0.0 "$ftp start"
$ns at 9.0 "$cbr stop"
$ns at 9.0 "$ftp stop"
proc finish {} {
global ns namfile tracefile
$ns flush-trace
close $namfile
close $tracefile
exec nam ex_01.nam &
exit 0
}
$ns at 10.0 "finish"
$ns run
Output:
8. Simulate to study transmission of packets over Ethernet LAN and determine the
number of packets drop destination.
9. Simulate the different types of internet traffic such as FTP and TELNET over a wired
network and analyze the packet drop and packet delivery ratio in the network
set ns [new Simulator]
set ntrace [open prog.tr w]
$ns trace-all $ntrace
set namfile [open prog5.nam w]
$ns namtrace-all $namfile
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 1Mb 10ms DropTail
$ns simplex-link $n3 $n2 1Mb 10ms DropTail
$ns queue-limit $n0 $n2 10
$ns simplex-link-op $n0 $n2 queuePos 0.5
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
$ns connect $tcp0 $sink0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set type_ FTP
set udp0 [new Agent/UDP]
$ns attach-agent $n1 $udp0
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
$ns connect $udp0 $null0
set telnet [new Application/Telnet]
$telnet attach-agent $udp0
$telnet set type_ Telnet
proc Finish {} {
global ns ntrace namfile
$ns flush-trace
close $ntrace
close $namfile
exec nam prog5.nam &
set numTcp [exec grep "^r" prog5.tr | grep "tcp" | tail -n 1 | cut
-d " " -f 6]
set TcpSize [exec grep "^r" prog5.tr | grep -c "tcp"]
set tcpTime 24.0
set numUdp [exec grep "^r" prog5.tr | grep "udp" | tail -n 1 | cut
-d " " -f 6]
set UdpSize [exec grep "^r" prog5.tr | grep -c "udp"]
set UdpTime 23.9
puts "The throughput of FTP is"
puts "[expr ($numTcp*$TcpSize)/$tcpTime] bytes per second"
puts "The throughput of Telnet is"
puts "[expr ($numUdp*$UdpSize)/$UdpTime] bytes per second"
exit 0
}
$ns at 0.1 "$telnet start"
$ns at 0.5 "$ftp0 start"
$ns at 23.9 "$telnet stop"
$ns at 24.0 "$ftp0 stop"
$ns at 25.0 "Finish"
$ns run
OUTPUT