DCCN Lab Manual
DCCN Lab Manual
BIT STUFFING:
DESCRIPTION:
The new technique allows data frames to contain an arbitrary number if bits and allows character codes
with an arbitrary no of bits per character. Each frame begins and ends with special bit pattern, 01111110,
called a flag byte. Whenever the senders data link layer encounters five consecutive one’s in the data, it
automatically stuffers a 0 bit into the outgoing bit stream. This bit stuffing is analogous to character
stuffing, in which a DLE is stuffed into the outgoing character stream before DLE in the data.
ALGORITHM:
1. Start
2. Initialize the array for transmitted stream with the special bit pattern 0111 1110
which indicates the beginning of the frame.
3. Get the bit stream to be transmitted into the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after appending 01111110
at the end
6. For de−stuffing, copy the transmitted data to another array after detecting the
stuffed bits 7. Display the received bit stream
8. Stop
SOURCE CODE:
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size :");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1 :");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1; a[k]==1 && k<n && count<5; k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
count=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After Bit Stuffing Frame is :");
for(i=0; i<j; i++)
printf("%d",b[i]);
}
OUTPUT:
1 B)Implement the data link layer farming methods such as CHARACTER
stuffing.
DESCRIPTION:
Each frame starts with the ASCII character sequence DLE STX and ends with the sequence
DLE ETX.(where DLE is Data Link Escape, STX is Start of TeXt and ETX is End of TeXt.) This
method overcomes the drawbacks of the character count method. If the destination ever
loses synchronization, it only has to look for DLE STX and DLE ETX characters. If however,
binary data is being transmitted then there exists a possibility of the characters DLE STX
and DLE ETX occurring in the data. Since this can interfere with the framing, a technique
called character stuffing is used. The sender's data link layer inserts an ASCII DLE
character just before the DLE character in the data. The receiver's data link layer removes
this DLE before this data is given to the network layer. However character stuffing is
closely associated with 8-bit characters and this is a major hurdle in transmitting arbitrary
sized characters.
Algorithm:
Step 1: Initially give the user 2 choices, whether to character stuff or to directly exit, if wrong choice
is entered then prompt an invalid choice message.
Step 2: Intake from the user the number of characters which are to be character stuffed.
Step 3: Then the characters which are to be stuffed are to be taken inside the for loop.
Step 4: Original data is displayed and the characters to be stuffed at the start and end of the frame
are uploaded in the program.
Step 5: If DLE character is present then stuff DLE character before it.
Step 6: The characters DLESTX are inserted at the start and end of the data.
Step 7: The data along with the stuffed characters are displayed
Step 8: The original data is recovered and displayed on the receiving side
Step 9: Stop
#include<stdio.h>
#include<string.h>
int main()
{
int j,l,m,c,k;
char a[50],b[50];
printf("enter string");
scanf("%s",a);
strcpy(b,"DLESTX");
m=strlen(a);
for(j=0;j<m;)
{
if(a[j]=='d')
{
if(a[j+1]=='l')
{
if(a[j+2]=='e')
{
c=j+2;
for(l=0;l<3;l++)
{
for(k=m;k>c;k--)
{
a[k]=a[k-1];
}
m++;
a[m]='\0';
c+=1;
}
a[j+3]='d';
a[j+4]='l';
a[j+5]='e';
a[m]='\0';
j+=5;
}
}
}
j++;
}
strcat(b,a);
strcat(b,"DLEETX");
printf("\n %s",b);
return 0;
}
OUTPUT:
CHARACTER COUNT:
DESCRIPTION:
This method uses a field in the header to specify the number of characters in the frame.
When the data link layer at the destination sees the character count,it knows how many
characters follow, and hence where the end of the frame is. The disadvantage is that if the
count is garbled by a transmission error, the destination will lose synchronization and will
be unable to locate the start of the next frame. So, this method is rarely used.
1. Start
2. Append DLE STX at the beginning of the string
3. Check the data if character is present; if character DLE is present in the string
(example
DOODLE) insert another DLE in the string (ex: DOODLEDLE)
4. Transmit DLE ETXat the end of the string
5. Display the string
6. Stop
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
int cc=0,wc=1,i=0;
char a[100];
printf("Enter a string :");
scanf("%[^\n]",a);
//gets(a);
for(i=0;i<strlen(a);i++)
{
if((a[i]==' ')||(a[i]=='\n')||(a[i]=='\0')||(a[i]=='\t'))
wc++;
}
printf("%s",a);
printf("\nNo. char = %d\n No. of words = %d\n",strlen(a),wc );
}
OUTPUT:
DESCRIPTION:
CRC method can detect a single burst of length n, since only one bit per column will be
changed, a burst of length n+1 will pass undetected, if the first bit is inverted, the last bit
is inverted and all other bits are correct. If the block is badly garbled by a long burst or by
multiple shorter burst, the probability that any of the n columns will have the correct
parity that is 0. so the probability of a bad block being expected when it should not be 2
power(-n). This scheme sometimes known as Cyclic Redundancy Code
Algorithm
PROGRAM:
#include<stdio.h>
#include<math.h>
int main()
{
int i,a,d,f[20],n[50],div[50],j,temp,q[20],z[10];
printf("enter the size of actual data");
scanf("%d",&a);
printf("enter the number\n");
for(i=0;i<a;i++)
{
scanf("%d",&n[i]);
}
printf("enter the lenght of the divisor");
scanf("%d",&d);
printf("enter the divisor\n");
for(i=0;i<d;i++)
{
scanf("%d",&div[i]);
}
for(i=a;i<a+4;i++)
{
n[i]=0;
}
for(i=0;i<a;i++)
{
temp=i;
if(n[i]==1)
{
for(j=0;j<d;j++)
{
if (n[temp]==div[j])
{
n[temp]=0;
f[j]=0;
}
else
{
n[temp]=1;
f[j]=1;
}
temp=temp+1;
}
q[i]=1;
}
else
q[i]=0;
}
printf("%d",f[j]);
printf("\n");
return 0;
}
OUTPUT:
3. 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.
DESCRIPTION:
Go-Back-N ARQ protocol is also known as Go-Back-N Automatic Repeat Request. It is a data link
layer protocol that uses a sliding window method. In this, if any frame is corrupted or lost, all
subsequent frames have to be sent again.
The size of the sender window is N in this protocol. For example, Go-Back-8, the size of the sender
window, will be 8. The receiver window size is always 1.
If the receiver receives a corrupted frame, it cancels it. The receiver does not accept a corrupted
frame. When the timer expires, the sender sends the correct frame again. The design of the Go-
Back-N ARQ protocol is shown below.
SOURCE CODE:
#include<stdio.h>
int main() {
int windowsize, sent=1, ack=0, f, frames[50], i;
return 0;
}
OUTPUT:
DESCRIPTION:
Dijkstra's algorithm (or Dijkstra's Shortest Path First algorithm, SPF algorithm) is an algorithm for
finding the shortest paths between nodes in a graph, which may represent, for example, road
networks.
1. To find the shortest path between points, the weight or length of a path is calculated as the sum
of the weights of the edges in the path.
3. Dijkstra's algorithm finds the shortest path from x to y in order of increasing distance from x.
That is, it chooses the first minimum edge, stores this value and adds the next minimum value from
the next edge it selects.
4. It starts out at one vertex and branches out by selecting certain edges that lead to new vertices.
5. It is similar to the minimum spanning tree algorithm, in that it is "greedy", always choosing the
closest edge in hopes of an optimal solution.
Algorithm:
1. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity
for all other nodes.
2. Mark all nodes unvisited. Set the initial node as current. Create a set of the unvisited nodes
called the unvisited set consisting of all the nodes.
3. For the current node, consider all of its unvisited neighbors and calculate their tentative
distances. For example, if the current node A is marked with a distance of 6, and the edge
connecting it with a neighbor B has length 2, then the distance to B (through A) will be 6 + 2 = 8.
If this distance is less than the previously recorded tentative distance of B, then overwrite that
distance. Even though a neighbor has been examined, it is not marked as "visited" at this time,
and it remains in the unvisited set.
4. When we are done considering all of the neighbors of the current node, mark the current
node as visited and remove it from the unvisited set. A visited node will never be checked again.
5. If the destination node has been marked visited (when planning a route between two specific
nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when
planning a complete traversal; occurs when there is no connection between the initial node and
remaining unvisited nodes), then stop. The algorithm has finished.
6. Select the unvisited node that is marked with the smallest tentative distance, and set it as the
new "current node" then go back to step 3.
#include<stdio.h>
void main()
{
int cost[10][10],distance[10],path[10][10],n,v,p,row,column,min,index=1,i,j;
printf("enter no of nodes");
scanf("%d",&n);
printf("enter cost matrix");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
}
}
printf("enter node to visit");
scanf("%d",&v);
printf("enter paths for selected node");
scanf("%d",&p);
printf("enter path matrix");
for(i=1;i<=p;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&path[i][j]);
}
}
for(i=1;i<=p;i++)
{
distance[i]=0;
row=1;
for(j=1;j<n;j++)
{
if(row!=v)
{
column=path[i][j+1];
distance[i]=distance[i]+cost[row][column];
}
row=column;
}
}
min=distance[1];
for(i=1;i<=p;i++)
{
if(distance[i]<=min)
{
min=distance[i];
index=i;
}
}
printf("min distance is%d \n",min);
printf("min distance path is \n");
for(i=1;i<=n;i++)
printf("---->%d",path[index][i]);
}
OUTPUT:
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
DESCRIPTION:
This technique is widely used because it is simple and easy to understand. The idea o f
this algorithm is to build a graph of the subnet with each node of the
g r a p h representing a router and each arc of the graph representing a communication
line. T o c h o o s e a r o u t e b e t w e e n a g i v e n p a i r o f r o u t e r s t h e a l g o r i t h m j u s t
f i n d s t h e broadcast between them on the graph.
Algorithm:
A router creates a data packet and then sends it to each host one by one. In this case, the
router creates multiple copies of single data packet with different destination addresses. All
packets are sent as unicast but because they are sent to all, it simulates as if router is
broadcasting.
This method consumes lots of bandwidth and router must destination address of each node.
Secondly, when router receives a packet that is to be broadcasted, it simply floods those
packets out of all interfaces. All routers are configured in the same way.
SOURCE CODE:
#include<stdio.h>
int adj(int);
int a[10][10],n;
void main()
{
int i,j,root;
OUTPUT:
1 4
3 5
6. Implement distance vector routing algorithm for obtaining routing tables at each node.
DESCRIPTION:
Algorithm:
1) This step initializes distances from source to all vertices as infinite and distance to
source
itself as 0. Create an array dist[] of size |V| with all values as infinite except
dist[src] where src is source vertex.
2) This step calculates shortest distances. Do following |V|-1 times where |V| is the
number of vertices in given graph.
…..a) Do following for each edge v-u
………………If dist[v] > dist[u] + weight of edge uv, then update dist[v]
………………….dist[v] = dist[u] + weight of edge uv
3) This step reports if there is a negative weight cycle in graph. Do following for each edge
u-v
……If dist[v] > dist[u] + weight of edge uv, then “Graph contains negative weight cycle”
The idea of step 3 is, step 2 guarantees shortest distances if graph doesn’t contain
negative
weight cycle. If we iterate through all edges one more time and get a shorter path for any
vertex, then there is a negative weight cycle.
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}
rt[10];
int main()
{
int dmat[20][20];
int n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("Enter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}
while(count!=0);
for(i=0;i<n;i++)
{
printf("\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
{
printf("\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n");
}
OUTPUT:
a. Take a 64 bit playing text and encrypt the same using DES algorithm
DESCRIPTION:
Data encryption standard was widely adopted by the industry in security products. Plain
text is encrypted in blocks of 64 bits yielding 64 bits of cipher text. The algorithm which is
parameterized by a 56 bit key has 19 distinct stages. The first stage is a key independent
transposition and the last stage is exactly inverse of that transposition.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
int i,ch,lp;
char cipher[50],plain[50];
char key[50];
while(1)
{
printf("\n-----MENU-----\n");
printf("\n1:Data Encryption\t\n\n2:Data Decryption\t\n\n3:Exit");
printf("\n\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nData Encryption");
printf("\nEnter the plain text:");
fflush(stdin);
gets(plain);
printf("\nEnter the encryption key:");
gets(key);
lp=strlen(key);
for(i=0;plain[i]!='\0';i++)
cipher[i]=plain[i]^lp;
cipher[i]='\0';
printf("\nThe encrypted text is:");
puts(cipher);break;
case 2: printf("\nData decryption");
for(i=0;cipher[i]!='\0';i++)
plain[i]=cipher[i]^lp;
printf("\nDecrypted text is:");
puts(plain);
break;
case 3: exit(0);
}
}
}
OUTPUT:
-----menu------
1. Data Encryption
2. Data Decryption
3. Exit
Data Encryption
Enter the plain text:hellow
Enter the encryption key:123ec
The encryption text data:iijr
-----menu------
1. Data Encryption
2. Data Decryption
3. Exit
Enter your choice:2
Data Decryption
Decryption text is:hellow
-----menu------
1. Data Encryption
2. Data Decryption
3.Exit
9. Using RSA algorithm Encrypt a text data and Decrypt the same.
DESCRIPTION:
RSA method is based on some principles from number theory. In encryption process
divide the plain text into blocks, so that each plain text message p falls in the
interval 0<p<n this can be done by grouping the plain text into blocks of k bits.
Where k is the largest integer for which 2 power k <n is true. The security of this
method is based on the difficulty of factoring large numbers. The encryption and
decryption functions are inverses.
#include<stdio.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
void main()
{
int a,b,i,j,t,x,n,k=0,flag=0,
prime[100];
char m[20],pp[20];
float p[20],c[20];
double e,d;
for(i=0;i<50;i++)
{
flag=0;
for(j=2;j<i/2;j++)
if(i%j==0)
{
flag=1;
break;
}
if(flag==0)
prime[k++]=i;
}
a=prime[k-1];
b=prime[k-2];
n=a*b;t=(a-1)*(b-1);
e=(double)prime[2];
d=1/(float)e;
printf("\nKey of encryption is:%lf\n",d);
printf("\nEnter plain the text:");scanf("%s",&m);x=strlen(m);printf("\nDecryption status
From Source to Destination:\n");
printf("\nSource\t->----------------------------------<-destination\n");
printf("\nChar\tnumeric\tcipher\t\tnumeric\t\tchar \n");
printf("\n***********************************************************\n");
printf("\n");for(i=0;i<x;i++)
{
printf("%c",m[i]);
printf("\t%d",m[i]-97);
c[i]=pow(m[i]-97,(float)e);
c[i]=fmod(c[i],(float)n);
printf("\t%f",c[i]);
p[i]=pow(c[i],(float)d);
p[i]=fmod(p[i],(float)n);printf("\t%f",p[i]);
pp[i]=p[i]+97;printf("\t%c\n",pp[i]);
printf("\n***********************************************************\n");
printf("\n");
}
}
OUTPUT:
ADDITIONAL PROGRAMS.
1. Take an example subnet graph with weights indicating delay between
nodes. Now obtain routing table at each node using Link state routing
Algorithm.
The following sequence of steps can be executed in the Link State Routing.
The basis of this advertising is a short packed called a Link State Packet (LSP).
OSPF (Open shortest path first) and IS-IS are examples of Link state routing.
Link State Packet(LSP) contains the following information:The ID of the node that
created the LSP;A list of directly connected neighbors of that node, with the cost
of the link to each one;A sequence number;A time to live(TTL) for this packet.
When a router floods the network with information about its neighbourhood, it is
said to be advertising.Discover your neighborsMeasure delay to your
neighborsBundle all the information about your neighbors togetherSend this
information to all other routers in the subnetCompute the shortest path to every
router with the information you receiveEach router finds out its own shortest
paths to the other routers by using Dijkstra's algorithm.
In link state routing, each router shares its knowledge of its neighbourhood with
all routers in the network.
Link-state protocols implement an algorithm called the shortest path first (SPF,
also known as Dijkstra's Algorithm) to determine the path to a remote destination.
There is no hop count limit. (For an IP datagram, the maximum time to live
ensures that loops are avoided.)
Only when changes occur, It sends all summary information every 30 minutes by
default. Only devices running routing algorithms listen to these updates. Updates
are sent to a multicast address.
Updates are faster and convergence times are reduced. Higher CPU and memory
requirements to maintain link-state databases.
Link-state protocols maintain three separate tables:Neighbor table: It contains a
list of all neighbors, and the interface each neighbor is connected off of.
Neighbors are formed by sending Hello packets.Topology table (Link- State
table) : It contains a map of all links within an area, including each link’s
status.Routing table : It contains the best routes to each particular destination
2. Interact with an Email server using SMTP and pop3 protocals commands.
You will interact with the SMTP server on 196.15.60.220 to send a message
to your mailbox and to other mailboxes already created on the Email server.
U: stands for User input command line
S: stands for Server output message
U:Telnet server 2000.nwlab.edu.25
S:
U:hello server 2000
S:
U:mail from:[email protected]
S:
U:rcpt to:[email protected]
S:
U:data
S:
U:message1
U:
S:
U:Quit
You will interact with the POP3 server to download and read Emails available
in your mailbox.
U:telnet server 2000.nwlab.edu 110
S:
U:user netpcx
S:
U:pass netpcx
S:
U:stat
S:
U: retr 1
S:
U: Quit