Professional Documents
Culture Documents
Part A:
Implementation of experiments using C Language
Theory:
Framing involves identifying the beginning and end of a block of information within
a digital stream. In asynchronous data transmission, since transmissions do not occur at
regular intervals, the receiver resynchronizes at the start of each eight bit character by the use
of a start bit that precedes and a stop bit that ends each character .In synchronous data
transmission bits are transmitted at regular intervals and the receiver has the circuitry that
recovers and tracks the frequency and bit transitions of the received data Framing may
involve delineating the boundaries between frames that are of fixed length or it may involve
delineating between frames that are of variable length. Variable length frames need more
information to delineate. The methods available include:
Special bit patterns-“flags” to identify the beginning and end of frames and character
counts
Bit Stuffing:
HDLC Frame
The high level data link control protocol is a bit oriented protocol which uses bit
stuffing for data transparency. HDLC frame is as shown.
Bits 8 8 8 >0 16 8
Frame 0111 1110 Address Control Data Checksum 0111 1110
The Control field is used for sequence numbers and acknowledgements and other purposes.
The Data field may contain arbitrary information. The Checksum field is a minor variation of
the CRC code using CRC-CCITT as the generator. Frames are delimited by 0111 1110 and
this sequence is not allowed in the data field.
Algorithm:
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int si=0,di=0,count=0;
char flag[]="01111110";
char src[100],des[100];
clrscr();
printf("Enter the frame data in binary");
scanf("%s",src);
strcpy(des,flag);
di=strlen(flag);
while(src[si] != '\0')
{
if(src[si] == '1')
count++;
else
count=0;
des[di++] = src[si++];
if(count == 5 )
{
des[di++] = '0';
count=0;
}
}
des[di] = '\0';
strcat(des,flag);
printf("\nBit stuffed frame is : \n%s",des);
di=strlen(flag); si=0;count=0;
while(des[di] != '\0')
{
if(des[di] == '1')
count++;
else
count=0;
src[si++] = des[di++];
if(count == 5 )
{
di++;
count=0;
}
}
src[si-7] = '\0';
printf("\nBit destuffed frame is : \n%s",src);
getch();
}
Output:
For example:
Algorithm:
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int si=0,di=0,count=0;
char flag[]="DLE";
char src[100],dest[100];
clrscr();
printf("Enter the frame data in ASCII\n");
gets(src);
VII Semester Dept. of TCE, Dr. AIT Page 5
CCN Laboratory (TEL76) 2018-19
strcpy(dest,flag);
di=strlen(flag);
while(src[si] != '\0')
{
if(src[si] == 'D' && src[si+1]=='L' && src[si+2] == 'E' )
{
dest[di+0] = 'E';dest[di+1] = 'S';dest[di+2] = 'C';
dest[di+3] = 'D';dest[di+4] = 'L';dest[di+5] = 'E';
di+=6; si+=3;
}
else
if(src[si] == 'E' && src[si+1]=='S' && src[si+2] == 'C' )
{
dest[di+0] = 'E';dest[di+1] = 'S';dest[di+2] = 'C';
dest[di+3] = 'E';dest[di+4] = 'S';dest[di+5] = 'C';
di+=6; si+=3;
}
else
dest[di++] = src[si++];
}
dest[di] = '\0';
strcat(dest,flag);
printf("\nCharecter stuffed frame is : \n %s",dest);
si=0;
for(di=strlen(flag);di<(strlen(dest)-strlen(flag));di++)
{
if(dest[di] == 'E'&&dest[di+1]=='S'&&dest[di+2]=='C')
{
src[si] = dest[di+3]; src[si+1] = dest[di+4];src[si+2] = dest[di+5];
di=di+5;
si+=3;
}
else
src[si++] = dest[di];
}
src[si]='\0';
printf("\nAfter destuffing : \n%s",src);
getch();
}
Output:
For example:
Enter frame data in ASCII :
AN IDLE MIND ALWAYS ESCAPES FROM WORK
Character stuffed frame is :
DLEAN IESCDLE MIND ALWAYS ESCESCAPES FROM WORKDLE
After destuffing :
AN IDLE MIND ALWAYS ESCAPES FROM WORK
Note: Check the output for 2 different sets of input.
In a substitution cipher, each letter or group of letters is replaced by another letter by adding
key to disguise it.
Plaintext: a b c d e f g h i j k l m n o p q r s t u v w x y z
Key=2
Ciphertext: c d e f g h i j k l m n o ......
Example : attack
Key=3
Encrypted data: dwwdfo
Algorithm:
(a) Encryption:
Read data to be encoded.
Get the key, ie the number of shifts to be performed.
For every character of data, remove all the special characters and change to capitals.
(b) Decryption:
Get the data for decryption.
For every character of cipher subtract the key for decryption from the cipher
Print the decryption data.
Program:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
int shift,pi,ci;
char plain[100],cipher[100];
clrscr();
printf("\n\n\t\tEncrypt n decrypt using sub cipher\n");
printf("Enter the plaintext\n");
gets(plain);
while(1)
{
printf("\n Key for encryption : ");
scanf("%d",&shift);
if(shift<1 || shift >25 )
printf("\nEnter within range");
else
break;
}
for( ci=0,pi=0;cipher[ci]!='\0';ci++)
plain[pi++]= ((cipher[ci])-'A'+(26-shift))%26 + 'A';
plain[pi]='\0';
printf("\n\nAfter decryption :\n %s",plain);
getch();
}
Output:
For example:
After decryption :
TELECOMMUNICATION
Algorithm:
(a) Encryption:
Get sequence of characters in cipher i.e. DRAIT.
Get data to be encoded.
Arrange data horizontally under DRAIT.
Add „.‟To make last row complete.
For every column of DRAIT.
Find next column to send using sequence.
Send data under this letter i.e print the data under this letter.
Jump back to 5 until all the columns are done.
(b) Decryption:
Get sequence of characters in word i.e. DRAIT.
Get data to be decoded.
See if input has a multiple of length of word characters. If it is not multiple.
Print it is an error and quit.
Find position of first character ie A
Put size of data or word characters underneath it.
Repeat steps 4 and 5 of DRAIT in alphabetical order.
Print all characters row wise starting from D to T.
Now, plain text is written horizontally as a series of rows. This is shown below.
D R A I T Keyword
T E L E C
O M M U N
I C A T I
Program:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{
charpln[100],out[100],key[20],ch;
int i,j,ilen,keylen,k;
clrscr();
printf("\n Enter the Plain text to be encrypted: ");
gets(pln);
printf("\n Enter the key: ");
gets(key);
ilen = strlen(pln);
keylen = strlen(key);
for(ch='A',k=0;ch<='z';ch++)
{
for(j=0;j<keylen;j++)
{
if(toupper(key[j]==ch))
{
for(i=j;i<ilen;i+=keylen)
{
out[k++]=pln[i];
}
}
}
}
out[k]='\0';
printf("\n Encrypted data is : %s",out);
for(ch='A',k=0;ch<='z';ch++)
{
for(j=0;j<keylen;j++)
{
if(toupper(key[j]==ch))
{
for(i=j;i<ilen;i+=keylen)
{
pln[i]=out[k++];
}
}
}
}
pln[++i]='\0';
printf("\n The Decrypted data is : %s",pln);
getch();
}
Output:
For example:
LMATTOIOEUTCEMCN
Algorithm:
(a) Encryption:
Get message polynomial
Get generator polynomial = (x16 +x12 + x5)
Multiply M(x) by (x16) to get v(x)
Divide v(x) by G(x) to get the remainder polynomial R(x) of the degree<15
Add R(x) to V(x) to get the encoded polynomial.
Display the encoded polynomial.
(b) Decryption:
Obtain received message in M(x) and store the CRC generate polynomial in G(x)
Divide M(x) by G(x) to get a remainder polynomial
Check for r(x)
If r(x)=0,then no errors have occurred in the transmission.
Otherwise some errors were induced during transmission.
Output y the value of R(x).
Program:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
if (mode)
strcat(o,"0000");
for(j=0;j<strlen(i);j++)
if(*(o+j)=='1')
for(k=0;k<strlen(g);k++)
{
if(((*(o+j+k)=='0')&&(g[k]=='0'))||((*(o+j+k)=='1')&&(g[k]=='1')))
*(o+j+k)='0';
else
*(o+j+k)='1';
}
for(j=0;j<strlen(o);j++)
if(o[j]=='1')
return(1);
return(0);
}
void main()
{
char i[100]={{'\0'}}, o[100]={{'\0'}}, r[100]={{'\0'}};
clrscr();
printf("Enter the Binary data frame:");
scanf("%s", i);
xor2_div(i,o,1);
printf("\n CRC-CCITT Code is:%s %s", i,o+strlen(i));
printf("\n Enter the received code:");
scanf("%s",r);
if(!xor2_div(r,o,0))
printf("\n Received Code is Error Free");
else
VII Semester Dept. of TCE, Dr. AIT Page 16
CCN Laboratory (TEL76) 2018-19
printf("\n /Erroneous");
getch();
}
Output:
For example:
Erroneous.
In order to transfer packets from a source host to the destination host, the network
layer must determine the path or route that the packets are to follow. This is the job of the
network layer routing protocol. At the heart of any routing protocol is the routing algorithm
that determines the path for a packet from source router to destination router. Given a set of
routers, with links connecting the routers, a routing algorithm finds a good path from source
router to destination router, according to some cost criterion. These can be,
1. Hop count: The cost is inversely proportional to the link capacity. One assigns higher
costs to lower capacity links. The objective is to send a packet through a path with the
highest capacity. If each link has equal capacity, then the shortest path is the path
with the minimum number of hops.
2. Transmission speed: The speed at which the various links operate is an important part
of a route‟s efficiency. Faster links obviously take precedence over slow ones.
3. Congestion: Network congestion caused by the current traffic pattern is considered
when evaluating a route and links that are overly congested are bypassed.
4. Route cost: The route cost is a metric assigned by the network administrator used to
rate the relative usability of various routes . The cost can refer to the literal financial
expense incurred by the link or any other pertinent factor.
5. Packet delay: The cost is proportional to an average packet delay which includes
queuing delay in the switch buffer ad propagation delay in the link. The shortest
path represents the fastest path to reach the destination.
Dijkstra's method of computing the shortest path or shortest path routing is a static
routing algorithm. It involves building a graph of the subnet, with each node of the graph
representing a router and each arc representing a communication line or a link. To find a
route between a pair of routers, the algorithm just finds the shortest path between them on the
graph.
In Dijkstra's algorithm the metric used for calculation is distance. Each node is
labeled with its distance from the source node along with the previous node in the path.
Initially no paths are known so all nodes are labeled with infinity. As the algorithm proceeds
and paths are found, the labels may change, reflecting better paths. A label may either be
tentative or permanent. Initially all nodes are tentative and once it is discovered that the
shortest possible path to a node is got it is made permanent and never changed after that.
Algorithm:
Program:
#include<stdio.h>
#include<conio.h>
# define infinty 999
void dijkstra (int cost[20][20],int n,int source,int distance[20])
{
int visited[20],min,u,i,j;
for(i=1;i<=n;i++)
{
distance[i]=cost[source][i];
visited[i]=0;
}
visited[source] =1;
for(i=1;i<=n;i++)
{
min=infinty;
for(j=1;j<=n;j++)
if (visited[j]==0 && distance[j]<min)
{
min =distance[j];
u=j;
}
visited[u]=1;
for(j=1;j<=n;j++)
if(visited[j]==0 &&(distance[u]+cost[u][j]<distance[j]))
distance[j]=distance[u]+cost[u][j];
VII Semester Dept. of TCE, Dr. AIT Page 19
CCN Laboratory (TEL76) 2018-19
}
}
void main()
{
int cost[20][20],distance[20],i,j,src,dst,sum;
unsigned int n;
clrscr();
printf("\n Enter the number of nodes:\t");
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]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if (cost[i][i]!=0)
{
printf("\n invalid entry");
getch();
exit(0);
}
}
printf("\n enter the src node:\t");
scanf("%d",&src);
printf("\n enter the dst node\t");
scanf("%d%",&dst);
dijkstra(cost,n,src,distance);
printf("\n\n shortest dist from %d to %d is %d",src,dst,distance[dst]);
getch();
}
Sample run:
Example: Find the shortest path from 1 to 4 for the arrangement shown below:
2 1
1 2 5
1 3 4 1
3 4
3
Output:
For example:
1 2 3 4 5
1 0 2 1 999 999
2 2 0 3 4 1
3 1 3 0 3 999
4 999 4 3 0 1
5 999 1 999 1 0
Prim’s Algorithm:
Program:
#include<stdio.h>
#include<conio.h>
#define infinity 999
int prime(int cost[10][10],int source,int n)
{
int i,j,sum=0,visited[10],cmp[10],vertex[10];
int min,u,v;
for(i=1;i<=n;i++)
{
vertex[i]=source;
visited[i]=0;
cmp[i]=cost[source][i];
}
visited[source]=1;
for(i=1;i<=n-1;i++)
{
min=Infinity;
for(j=1;j<=n;j++)
if(!visited[j] && cmp[j]<min)
{
min=cmp[j];
u=j;
}
visited[u]=1;
sum=sum+cmp[u];
printf("\n %d-> %d sum=%d",vertex[u],u,cmp[u]);
for(v=1;v<=n;v++)
if(!visited[v] && cost[u][v] < cmp[v])
{
cmp[v]=cost[u][v];
vertex[v]=u;
}
}
return sum;
}
void main()
{
int a[10][10],n,i,j,m,source;
clrscr();
printf("\n Enter the number of vertices");
scanf("%d",&n);
printf("\n Enter the cost matrix:0 self loop& 999 no edge\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]!=a[j][i]||(a[i][i]!=0))
{
printf("\n Invalid entry \n cost matrix should be symmetrical &
the diagonal elements are zero");
getch();
exit(0);
}
printf("\n Entert the source:");
scanf("%d",&source);
m=prime(a,source,n);
printf("\n\n total cost=%d",m);
getch();
}
Sample Run:
2 1
2 5
1
1 3 4 1
3 4
3
1 2 3 4 5
1 0 2 1 999 999
2 2 0 3 4 1
3 1 3 0 3 999
4 999 4 3 0 1
5 999 1 999 1 0
1 3 Sum =1
1 2 Sum =2
2 5 Sum =1
5 4 Sum =1
Total Cost = 5
Policing
1. Network monitors traffic flows continuously to ensure they
meet their traffic contract.
2. The process of monitoring and enforcing the traffic flow is called policing.
3. When a packet violates the contract, network can discard or tag the
packet giving it lower priority
4. If congestion occurs, tagged packets are discarded first
5. Leaky Bucket Algorithm is the most commonly used policing mechanism
(i) Bucket has specified leak rate for average contracted rate
(ii) Bucket has specified depth to accommodate variations in arrival rate
(iii) Arriving packet is conforming if it does not result in overflow
Leaky Bucket algorithm can be used to police arrival rate of a packet stream
Algorithm:
1. The above figure shows the leaky bucket algorithm that can be used to police the
traffic flow.
2. At the arrival of the first packet, the content of the bucket is set to zero and the last
conforming time (LCT) is set to the arrival time of the first packet.
3. The depth of the bucket is L+I, where l depends on the traffic burstiness.
4. At the arrival of the kth packet, the auxiliary variable X‟ records the difference
between the bucket content at the arrival of the last conforming packet and the
inter-arrival time between the last conforming packet and the kth packet.
5. If the auxiliary variable is greater than L, the packet is considered as
nonconforming, otherwise the packet is conforming. The bucket content and the
arrival time of the packet are then updated.
The operation of the leaky bucket algorithm is illustrated in the below figure.
1. Here the value I is four packet times, and the value of L is 6 packet times.
2. The arrival of the first packet increases the bucket content by four (packet
times).
3. At the second arrival the content has decreased to three, but four more are
added to the bucket resulting in total of seven.
4. The fifth packet is declared as nonconforming since it would increase the
content to 11, which would exceed L+I (10).
5. Packets 7, 8, 9 and 10 arrive back to back after the bucket becomes empty.
Packets 7, 8 and 9 are conforming, and the last one is nonconforming.
6. Non-conforming packets not allowed into bucket & hence not included in
calculations.
Program:
//leacky bucket program
#include<stdio.h>
#define bucketsize 1000
#define n 5 // user defined function to output the contents of bucket at a constant rate
void bucketoutput(int *bucket, int op)
{
if(*bucket > 0 && *bucket > op) // if the no. of bytes in the bucket >output rate
{
newpack=rand()%500; //new packet with random size is generated printf("\n\n new packet
size = %d",newpack); newpack=oldpack+newpack;
wt=rand()%5; // random waiting time is generated if(newpack<bucketsize)
bucket=newpack;
else
{
printf("\n%d = the newpacket and old pack is greater than bucketsize reject",newpack);
bucket=oldpack;
}
printf("\nthe data in bucket = %d",bucket);
printf("\n the next packet will arrive after = %d sec",wt);
// calling output rate function with wait time for(j=0;j<wt;j++)
{
bucketoutput(&bucket,op); sleep(1);
}
oldpack=bucket;
VII Semester Dept. of TCE, Dr. AIT Page 28
CCN Laboratory (TEL76) 2018-19
while(bucket>0)
bucketoutput(&bucket,op); return 0;
}
Output
enter output rate 500
new packet size = 383
the data in bucket = 383
the next packet will arrive after = 1 sec
remaining data output = 383
new packet size = 277
the data in bucket = 277
the next packet will arrive after = 0
sec new packet size = 293
the data in bucket = 570
the next packet will arrive after = 0 sec
new packet size = 386
the data in bucket = 956
the next packet will arrive after = 2 sec
500-outputed remaining is 456
remaining data output = 456
new packet size = 149
the data in bucket = 149
the next packet will arrive after = 1 sec
remaining data output = 149
Part B:
CCN Experiments using Hardware
The unit consists of a set of modules, each including one or more functional blocks
typical of communication systems.
The system is highly innovative from a technological as well as an educational point
of view. The modules are used as “Basic Blocks” to build up in a flexible way the different
communication systems, and to examine all the peculiar operating characteristics.
Data communication is a term referred when the sender and receiver are digital
devices, which communicates each other by means of binary information. The objective of
the experiment is to clear the various aspects of the data communications which comprise of
Connect the RS232 of the kit to the usb port of the PC(com1) on both the sides
Connect the power supply.
Load the software and open it (data communication trainer).
Update the OS.
Select the com1 in the window.
Select the bit rate (Should be the same both sides).
Select flow control as X on/ X off.
Now it is ready for transmission.
For echo (To display the type message).
Go to Properties Settings ASCII setup highlight echo…. Ok
For transferring
Go to Transfer Send file Browse Send.
VII Semester Dept. of TCE, Dr. AIT Page 31
CCN Laboratory (TEL76) 2018-19
1. RS 232
INTRODUCTION: RS-232 standard is defined for a point-to-point communication. The data
transfer is defined between DTE ( Data Transfer Equipment ) and the DCE ( Data
communication Equipment ).
DTE- Data Terminating Equipment such as computer port or computer terminal in a network.
The RS-232 line, when idle is in the mark state( logic 1). A transmission starts with a
start bit, which is ( logic 0 ). Then each bit is sent down the line, one at a time. The LSB is
sent first. A stop bit ( logic 1 ) is then appended to the signal to make up the transmission.
EQUIPMENT: DCT-03
9 pin D-connector cable.
Computers-PC-2.
Power Supply.
Procedure:
2. MODEM COMMUNICATION
FSK modulation:
In this form of modulation, the sine wave carrier assumes two values of frequency,
determined by the binary data signal. Logic high or mark and logic low or space are assigned
two different carrier frequencies. The carrier frequency shifts between two frequencies
corresponding to the mark or space level at the input level of the modulator.
FSK demodulation:
The most common circuit for demodulating FSK signals is the PLL. The FSK signal
at the PLL input has two values of frequency shifts, thus providing a two-level signal
corresponding to the original binary data stream. The PLL demodulator is followed by a low
pass filter, which removes the residual carrier components, and by a pulse forming circuit
which restores the correct shape of the data signal.
Procedure:
Connect power supply with proper polarity to kit DCT-03.
Refer to the Block diagram to make connections
Connect TD1 port to input port of FSK modulator and out port of FSK demodulator
to RD2.
Connect telephone link between RJ11 as provided.
Connect RD1 to TD2 port.
Keep switch setting of S4 as shown.
Switch on power supply run a file transfer protocol using hyperlink on both the PC‟s.
Transmitter:
Fiber optic transmitter are typically composed of a buffer, driver and optical source.
The buffer provides both an electrical connection and isolation between the transmitter and
the electrical system supplying the data. The driver electronics provides electrical power to
the optical source in the fashion that duplicates the pattern of data being fed to the
transmitter.
Receiver:
The function of the receiver is to convert the optical energy into electrical form which
is then conditioned to reproduce the transmitted electrical signal in its original form.
Procedure:
Connect power supply with proper polarity to kit DCT-03.
Connect TD1 port to TX port of FO-transmission and TTL port of FO Rx to RD2.
Connect RD1 port to TD2 port.
Keep the switch setting S4 as shown in block diagram.
Switch on power supply run a file transfer protocol using hyperlink on both the PC‟s.
******************