Professional Documents
Culture Documents
CCN Lab Manual-New - 18tel66
CCN Lab Manual-New - 18tel66
COMPUTER COMMUNICATION
NETWORKS Lab
(18TEL66)
LAB INCHARGE
2. Simulate Ethernet LAN using n(6-10) Nodes and Assign Multiple traffic to
the Nodes to obtain
i. Congestion Window for different Sources/ Destinations.
ii. Compare the Throughput by changing the Error Rate and Data Rate.
5. Build a Four-node Point to Point Network with links n0-n2, n1-n2 and n2-
n3. Connect a TCP link between n0-n3 and UDP link between n1-n3.
(i) Define BERs for Links. Compare TCP and UDP Protocols when errors
occur. (Or)
6. Simulate a Network with a Star Topology (One Router and several Hosts).
Declare Applications (TCP or UDP) to send Packets from Hosts and to Receive
(on one Host). Test the Bandwidth and the Delay, when Buffers are of infinite
Capacities and Buffers are of Limited Capacities.
3. Write a Program to obtain CRC Code for the given Data, using CRC-CCITT
(CRC 16) Polynomial. Verify the Program for the Cases.
a. Without Error
b. With Error
4. Write Programs for Simulation of Stop and Wait Protocol and Sliding Win-
dow Protocol.
6. Write a Program for RSA Algorithm for Encryption and Decryption of Data.
EXPERIMENTS USING
NETWORK SIMULATOR 2
1. Simulate a Point-to-Point Network with Four Nodes and Duplex Links be-
tween them. Analyze the Network Performance by Setting the Queue Size and
Varying the Bandwidth.
Topology:
Program:
#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open lab1.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open lab1.nam w]
$ns namtrace-all $namfile
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#Createlinks between nodes
$ns duplex-link $n0 $n2 300.0Mb 20ms DropTail
$ns queue-limit $n0 $n2 10
$ns duplex-link $n1 $n2 400.0Mb 20ms DropTail
$ns queue-limit $n1 $n2 20
$ns duplex-link $n2 $n3 100.0Mb 20ms DropTail
$ns queue-limit $n2 $n3 3
#Above Highlighted Bandwidth and Queue Size will be changed
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500
#Setup a TCP connection
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp1 $sink3
$tcp1 set packetSize_ 1500
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 8.0 "$ftp0 stop"
#Setup a FTP Application over TCP connection
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 1.0 "$ftp1 start"
$ns at 8.0 "$ftp1 stop"
$ns at 10.0 “finish”
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam lab1.nam &
exit 0
}
$ns run
Awk Script:
BEGIN{
tcppack=0
tcppack1=0
}
{
if($1=="r"&&$4=="3"&&$5=="tcp"&&$6=="1540")
{
tcppack++;
}
if($1=="d"&&$3=="2"&&$5=="tcp"&&$6=="1540")
{
tcppack1++;
}
}
END{
printf("\n total number of data packets received at Node 3: %d\n", tcppack++);
printf("\n total number of packets dropped at Node 2: %d\n", tcppack1++);
}
Save the TCL script. Go to the Terminal window and type the command
ns lab1.tcl and then press Enter key. Two windows will popup.
1. Nam Console 2. Animation window
In the Animation window, press play forward button and wait till it
completes its execution. After that close the window, in the terminal window
create an awk file using gedit with the same name as of tcl file but with. awk
extension. (Ex: lab1.awk)
##write the awk file, save it and in the terminal, window execute it with
awk -f lab1.awk lab1.tr command. Then it displays the required
parameters.
##OUTPUT##
Change the bandwidth & Queue size between the nodes as shown in the table for
3 different cases, run the code and console: List the Number of packets received
at node 3 and number of packets dropped at node 2.
2. Simulate Ethernet LAN using n (6-10) Nodes and Assign Multiple traf -
fic to the Nodes to obtain
i. Congestion Window for different Sources/ Destinations.
proc finish { } {
global ns nf tf
$ns flush-trace
close $tf
close $nf
exec nam lab2.nam &
exit
}
$ns make-lan "$n0 $n1 $n2 $n3 $n4" 100Mb 100ms LL Queue/DropTail
Mac/802_3
BEGIN {
}
{
if($6=="cwnd_")
printf(" Time= %f\t congestion window=%f\t\n",$1,$7);
}
END {
}
Network Animation:
.
ii. Compare the Throughput by changing the Error Rate and Data Rate.
proc finish { } {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam lab3.nam &
exit
}
$ns make-lan "$n0 $n1 $n2 $n3" 100Mb 300ms LL Queue/DropTail Mac/802_3
$ns make-lan "$n4 $n5 $n6 $n7" 100Mb 300ms LL Queue/DropTail Mac/802_3
$ns duplex-link $n3 $n4 100Mb 300ms DropTail
$ns duplex-link-op $n3 $n4 color "green"
$ns duplex-link-op $n3 $n4 orient right
Awk file
BEGIN{
pkt=0;
time=0;
}
{
if($1=="r" && $3=="9" && $4=="7"){
pkt = pkt + $6;
time =$2;
}
}
END {
printf("throughput:%f Mbps",(( pkt / time) * (8 / 1000000)));
}
##Ouput##
For Error rate of 0.1
Throughput 33.59256 Mbps
For Error rate of 0.5
Throughput 1.7549Mbps
Network Animation:
3. Simulate the Transmission of Ping Messages over a Network Topology
Consisting of Six Nodes and Find the Number of Packets dropped due to
Congestion.
proc finish {} {
global ns tf nf
$ns flush-trace
close $tf
close $nf
exec nam lab3.nam &
exit 0
}
$ns run
##awk.file
BEGIN{
a=0
b=0
}
{
if($1=="r")
{
a++;
}
if($1=="d")
{
b++;
}
}
END{
printf("\n total number of received packets:%d\n", a++);
printf("\n total number of Dropped packets:%d\n", b++);
}
Nam Output:
4.Simulate a Simple BSS with Transmitting Nodes in Wireless LAN and
Determine the Performance with respect to Transmission of Packets.
#Create a ns simulator
set ns [new Simulator]
#Setup topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
#Open the NS trace file
set tracefile [open lab4.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open lab4.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#Create 4 nodes
set n0 [$ns node]
$n0 set X_ 618
$n0 set Y_ 734
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 374
$n1 set Y_ 711
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 633
$n2 set Y_ 506
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 859
$n3 set Y_ 683
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n1 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 8.0 "$ftp0 stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam lab4.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
Awk Script
BEGIN{
cbrpack=0
cbrpack1=0
cbrpack2=0
}
{
if($1=="r"&&$3=="_3_"&&$4=="AGT"&&$7=="tcp"&&$8=="1540")
{
cbrpack++;
}
if($1=="s"&&$3=="_1_"&&$4=="AGT"&&$7=="tcp"&&$8=="1540")
{
cbrpack1++;
}
if($1=="D"&&$3=="_0_"&&$4=="AGT"&&$7=="tcp"&&$8=="1540")
{
cbrpack2++;
}
}
END{
printf("\n total number of packets drop: %d\n", cbrpack2++);
printf("\n total number of packets sent: %d\n", cbrpack1++);
printf("\n total number of packets received: %d\n", cbrpack++);
}
Network Animation:
5. Build a Four-node Point to Point Network with links n0-n2, n1-n2 and
n2-n3. Connect a TCP link between n0-n3 and UDP link between n1-n3.
Apply relevant applications over TCP &UDP agents changing the parame-
ter and determine the number of packets by TCP/UDP.
#Create a ns simulator
set ns [new Simulator]
#$ns at 10.0 "$ns detach-agent $n0 $tcp0 ; $ns detach-agent $n3 $sink2"
#$ns at 30.0 "$ns detach-agent $n0 $udp1 ; $ns detach-agent $n3 $null3"
##Awk Script##
BEGIN{
a=0
b=0
}
{
if($1=="r"&&$4=="3"&&$5=="tcp"&&$6=="1540")
{
a++;
}
if($1=="r"&&$4=="3"&&$5=="cbr"&&$6=="1000")
{
b++;
}
}
END{
printf("\n total number of packets received at tcp: %d\n", a++);
printf("\n total number of packets received at udp: %d\n", b++);
}
Network Animation:
##Output##
Total number of packets received at TCP=676
Total number of packets received at UDP =210
6. Simulate a Network with a Star Topology (One Router and several
Hosts). Declare Applications (TCP or UDP) to send Packets from Hosts
and to receive (on one Host). Test the Bandwidth and the Delay, when
Buffers are of infinite Capacities and Buffers are of Limited Capacities.
#Create a ns simulator
set ns [new Simulator]
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
##Awk Script##
BEGIN{
a=0
b=0
}
{
if($1=="r"&&$4=="4"&&$5=="tcp"&&$6=="1540")
{
a++;
}
}
END{
printf("\n total number of packets received at tcp: %d\n", a++);
}
Network Animation:
##OUTPUT##
total number of packets received at tcp: 1300
7. Simulate Link State Routing Algorithm.
AWK SCRIPT
BEGIN{
a=0
b=0
}
{
if($1=="r"&&$4=="4"&&$5=="cbr"&&$6=="1000")
{
a++;
}
}
END{
printf("\n total number of packets received at destination node 4: %d\n", a++);
}
Network Animation:
EXPERIMENTS USING C
In Ubuntu,
Go To the Terminal Use this Command to Create a File
$gedit file1.C
Type The Code
Save The File Using save Option
To Compile the Code
Go The Terminal Window
And Use This Command
$gcc -o file1 file1.C
To See the Output
$./file1
1. a BIT STUFFING
#include <stdio.h>
#include <string.h>
int main()
{
int len, i, j,ext=8;
char data[' '],flag[ ]="01111110",temp[' '];
printf("Enter the data to be stuffed \n");
scanf("%s",&data);
strcpy (temp,flag);
len=strlen(data);
for (i=0,j=0;i<len;i++)
{
if (data[i]=='0')
j=0;
else
j++;
temp[i+ext]=data[i];
if (j==5)
{
temp[i+ ++ext]='0';
j=0;
}
}
temp[len+ext]='\0';
strcat (temp,flag);
printf("The bit stuffed data is %s\n",temp);
}
OUTPUT
Enter the data to be stuffed
1111111010101010111111010
The bit stuffed data is
0111111011111011010101010111110101001111110
b. CHARACTER STUFFING
#include <stdio.h>
#include <string.h>
int main( )
{
int len,i,ext=6;
char data[' '],beg[ ]={"DLESTX"},end[ ]={"DLEETX"},temp[' '];
printf("Enter the data frame \n");
scanf("%s", &data);
strcpy (temp,beg);
len=strlen(data);
for (i=0;i<len;i++)
{
if (data[i]=='D' && data[i+1]=='L' && data[i+2]=='E')
{
temp[i+ ext++]='D';
temp[i+ ext++]='L';
temp[i+ ext++]='E';
}
temp[i+ext]=data[i];
}
temp[len+ext]='\0';
strcat(temp,end);
printf("The Character stuffed data is %s\n",temp);
}
OUTPUT
Enter the data frame
SIRMVITCARDLEABC
The Character stuffed data is
DLESTXSIRMVITCARDLEDLEABCDLEETX
2. Write a Program to obtain CRC code for the given data, using CRC-
CCITT polynomial
#include <stdio.h>
#include <string.h>
void main()
{
int i,j,k,keylen,msglen,value;
char
data[100],ddata[100],out[100],recv[100],key[30],temp[30],quot[100],rem[30],
key1[30];
printf("Enter Data: ");
scanf("%s", &data);
printf("Enter Key: ");
scanf("%s", &key);
keylen=strlen(key);
msglen=strlen(data);
strcpy(ddata,data);
strcpy(key1,key);
for (i=0;i<keylen-1;i++)
{
data[msglen+i]='0';
}
for (i=0;i<keylen;i++)
temp[i]=data[i];
for (i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0';
else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--)
{
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=data[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
strcat(ddata,rem);
printf("\nData to be transmitted is:%s\n", ddata);
printf("\n Enter the Received data:");
scanf("%s", &recv);
value=strcmp(ddata,recv);
if(value==0)
printf("Data is ERROR FREE\n");
else
printf("Error in received data\n");
return 0;
}
Output:
1. Enter Data: 110111011100
Enter Key: 1101
Quotient is 100010001001
Remainder is 101
Data to be transmitted is:110111011100101
Quotient is 100011011
Remainder is 111
Data to be transmitted is:110110101111
OUTPUT:
number of frames is 6
Sending frame 1
ack for frame 1
Sending frame 2
ack for frame 2
Sending frame 3
Waiting for 1 seconds
sending frame 3
ack for frame 3
Sending frame 4
ack for frame 4
Sending frame 5
ack for frame 5
Sending frame 6
Waiting for 1 seconds
sending frame 6
ack for frame 6
end of stop and wait protocol
OUTPUT:
Enter window size: 3
Enter number of frames to transmit: 5
Enter 5 frames: 12 5 19 8 6
With sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by
the receiver
12 5 19
Acknowledgement of above frames sent is received by sender
86
Acknowledgement of above frames sent is received by sender
5. WRITE A PROGRAM FOR DIJKSTRA'S ALGORITHM TO
COMPUTE THE SHORTEST ROUTING PATH.
#include<stdio.h>
#define INFINITY 2000
#define MAXNODES 4
#define MEMBER 1
#define NONMEMBER 0
void shortpath(int weight[][MAXNODES], int , int ,int * ,int precede[]);
int main(void)
{
int i,j,s,t;
int weight[MAXNODES][MAXNODES],precede[MAXNODES],pd;
printf("\n Enter weight matrix ");
for(i=0;i<MAXNODES;i++)
for(j=0;j<MAXNODES;j++)
scanf(" %d",&weight[i][j]);
for(i=0;i<MAXNODES;i++)
{
printf("\n");
for(j=0;j<MAXNODES;j++)
printf(" %d",weight[i][j]);
}
printf("\n Enter the starting node and the ending node: ");
scanf(" %d %d",&s,&t);
shortpath(weight,s,t,&pd,precede);
printf("\n The shortest path from node %d to %d is : %d",s,t,pd);
return(0);
}
void shortpath(int weight[][MAXNODES],int s, int t, int *pd, int precede[])
{
int distance[MAXNODES],perm[MAXNODES];
int current,i,j,k,dc;
int smalldist,newdist;
/* initialization of perm and distance array */
for(i=0;i<MAXNODES;i++)
{
perm[i]=NONMEMBER;
distance[i]=INFINITY;
}
perm[s] = MEMBER;
distance[s] = 0;
current = s;
while(current != t)
{
smalldist=INFINITY;
dc=distance[current];
for(i=0;i<MAXNODES;i++)
if(perm[i]==NONMEMBER)
{
newdist = dc + weight[current][i];
if(newdist < distance[i])
{
distance[i]=newdist;
precede[i]=current;
}
if(distance[i] < smalldist)
{
smalldist = distance[i];
k=i;
}
} /* end of for if */
current = k;
perm[current]=MEMBER;
} /* END WHILE */
*pd=distance[t];
}
OUTPUT:
Enter weight matrix
0 2 2000 1
2 0 1 2000
2000 1 0 5
1 2000 5 0
0 2 2000 1
2 0 1 2000
2000 1 0 5
1 2000 5 0
Enter the starting node and the ending node:
1
3
The shortest path from node 1 to 3 is : 3
value of d is 5
Encrypted message
8 h 10 j 17 q 17 q 15 o
Decrypted message
hello
#include<stdio.h>
#include<strings.h>
#include<stdio.h>
int min(int x,int y)
{
if(x<y)
return x;
else
return y;
}
int main()
{
int drop=0,mini,nsec,cap,count=0,i,inp[25],process;
system("clear");
printf("Enter The Bucket Size\n");
scanf("%d",&cap);
printf("Enter The Operation Rate\n");
scanf("%d",&process);
printf("Enter The No. Of Seconds You Want To Stimulate\n");
scanf("%d",&nsec);
for(i=0;i<nsec;i++)
{
printf("Enter The Size Of The Packet Entering At %dsec\n",i+1);
scanf("%d",&inp[i]);
}
printf("\nSecond|Packet Recieved|Packet Sent|PacketLeft|Packet Dropped|\n");
printf("--------------------------------------------------------------\n");
for(i=0;i<nsec;i++)
{
count+=inp[i];
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t%d",inp[i]);
mini=min(count,process);
printf("\t\t%d",mini);
count=count-mini;
printf("\t\t%d",count);
printf("\t\t%d\n",drop);
drop=0;
}
for(;count!=0;i++)
{
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t0");
mini=min(count,process);
printf("\t\t%d",mini);
count=count-mini;
printf("\t\t%d",count);
printf("\t\t%d\n",drop);
}
}
OUTPUT:
Enter The Bucket Size
5
Enter The Operation Rate
2
Enter The No. Of Seconds You Want To Stimulate
3
Enter The Size Of The Packet Entering At 1sec
5
Enter The Size Of The Packet Entering At 2sec
4
Enter The Size Of The Packet Entering At 3sec
3
Second|Packet Recieved|Packet Sent|PacketLeft|Packet Dropped|
--------------------------------------------------------------
1 5 2 3 0
2 4 2 3 2
3 3 2 3 1
4 0 2 1 0
5 0 1 0 0