0% found this document useful (0 votes)
38 views26 pages

CN Lab

Uploaded by

A0554
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)
38 views26 pages

CN Lab

Uploaded by

A0554
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
You are on page 1/ 26

J.N.T.U.H.

UNIVERSITY COLLEGE OF ENGINEERING, SCIENCE &TECHNOLOGY


HYDERABAD

KUKATPALLY, HYDERABAD – 500 085

Certificate
Certified that this is the bonafide record of the practical work done

duringthe academic year by

Name

Roll Number Class

in the Laboratory of _

of the Department of

Signature of the Staff Member Signature of the Head of the

Department Date of Examination_

Signature of the Examiner/s

Internal Examiner External Examiner


J.N.T.U.H. UNIVERSITY COLLEGE OF ENGINEERING, SCIENCE &TECHNOLOGY HYDERABAD

KUKATPALLY, HYDERABAD – 500 085

Name Roll Number

Class Year _ Laboratory

List of Experiments
S.No. Name of the Experiment Date of Page Marks Remarks
Experiment Number
1. Implement the data link layer framing methods such as character, character-stuffing
and bit stuffing.
Bit Stuffing:
#include<stdio.h>
#include<string.h>

int main(){
char s[100];
int c,i,k;
char r[100];
char p[100];
printf("Enter the bitstring :");
scanf("%s",s);
k=0;
c=0;
for(i=strlen(s) -1 ;i>=0;i--){
r[k++] = s[i];
if(s[i] == '1')
c++;
else
c=0;
if(c==5){
r[k++] = '0';
c = 0;
}
}
r[k] = '\0';
printf("The stuffed string is \n");
printf("%s",strrev(r));
c = 0;
k = 0;
for(i=strlen(r)-1;i>=0;i--){
p[k++] = r[i];
if(r[i]=='1')
c++;
else
c = 0;
if(c==5)
{
c=0;
i--;
}
}
p[k] = '\0';
strrev(p);
printf("The destuffed string is %s",p);
}
OUTPUT:

Byte Stuffing:
#include<stdio.h>
#include<string.h>
int main()
{
char inp[50];
int i,k;
char stuff[50] ="";
char res[50] ="";
char stuff1[50] ="";
printf("Enter the input string ");
scanf("%s",inp);
k = 0;
for(i=strlen(inp)-1;i>=0;i--)
{
stuff[k] = inp[i];
k++;
if(inp[i] == 'E'|| inp[i] == 'e'||inp[i] == 'F'||inp[i] == 'f'){
stuff[k] = 'E';
k++;
}
}
printf("%s\n",strrev(stuff));
k = 0;
for(i=strlen(stuff)-1;i>=0;i--)
{
stuff1[k] = stuff[i];
k++;
if(stuff[i] == 'E' || stuff[i] == 'e' || stuff[i] == 'F' || stuff[i] == 'f'){
i--;
}
}
printf("%s",strrev(stuff1));
}
OUTPUT:
2.Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP
CODE:
#include<stdio.h>
#include<string.h>
char data[20],div[20],total[100];
int i,j,datalen,divlen,len,flag=1;
void check();
int main()
{
printf("\nEnter the data:");
scanf("%s",&data);
printf("\nEnter the divisor");
scanf("%s",div);
divlen=strlen(div);
datalen=strlen(data);
len=datalen+divlen-1;
for(i=0;i<datalen;i++)
{ total[i]=data[i];
}
for(i=datalen;i<len;i++)
total[i]='0';
check();
for(i=0;i<divlen;i++)
total[i+datalen]=data[i];
printf("\ntransmitted Code Word:%s",total);
printf("\n\nEnter the received code word:");
scanf("%s",total);
check();
for(i=0;i<divlen-1;i++)
if(data[i]=='1')
{
flag=0;
break;
}
if(flag==1)
printf("\nsuccessful!!");
else
printf("\nreceived code word contains errors...\n");
}
void check()
{
for(j=0;j<divlen;j++)
data[j]=total[j];
while(j<=len)
{
if(data[0]=='1')
for(i = 1;i <divlen ; i++)
data[i] = (( data[i] == div[i])?'0':'1');
for(i=0;i<divlen-1;i++)
data[i]=data[i+1];
data[i]=total[j++];
}
}
OUTPUT:
CRC-12

CRC-16
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.
Sliding window protocol:
#include<stdio.h>
#include<stdlib.h>
int count;
void sender(int i){
printf("The sender has transmitted the frame %d :",i);
}
void receiver(int i){
int ack;
printf("Did you receive the frame %d ?(1Y,0Y) ",i);
scanf("%d",&ack);
if(ack == 1)
return;
else{
if(count<4){
count++;
sender(i);
receiver(i);
}
else{
printf("The limit exceeded :");
exit(0);
}
}
}
int main(){
int n,i;
printf("enter the number of frames to be transmitted :");
scanf("%d",&n);
for(i=1;i<=n;i++){
count = 0;
sender(i);
receiver(i);
}}
OUTPUT:

Go-back-N:
#include<stdio.h>
int main(){
int z , i , k, n , t, ws ,ack ;
printf("Enter the number of frames :");
scanf("%d",&n);
printf("Enter the window size :");
scanf("%d",&ws);
i = 1;
t = 0;

while(i<=n){
z = 0;
for(k = i;k<i+ws && k<=n;k++){
printf("The frame %d has been tarnsmitted ",k);
t++;
}
for(k=i;k<i+ws && k<=n;k++){
printf("\nDid you receive acknowledgement for the frame %d ",k);
scanf("%d",&ack);
if(ack==1){
z++;
}
else{
printf("Error in transmitting the frame %d \n",k);
printf("Retransmitting the window ");
break;
}
}
i = i+ z;
}
printf("the total no of transmissions by the sender is %d ", t);

}
OUTPUT:

Selective Repeat:
#include<stdio.h>
int getAck(int w[],int nr[], int j){
int ack[20];
int k = 0;
int i;
for(i=0;i<j;i++){
printf("Enter the acknowledgement for the frame %d ",w[i]);
scanf("%d",&ack[i]);
if(ack[i] == -1){
nr[k++] = w[i];

}
}
return k;
}
int main(){
int n , ws ,k,j,i=1,z;
int w[10],nr[10];
printf("Enter the no of frames :");
scanf("%d",&n);
printf("Enter the window size :");
scanf("%d",&ws);
k = 0;
while(1){
for(j=k;j<ws&&i<=n;j++){
w[j] = i ;
printf("The frame %d is transmitted ",i);
i++;
}
k = getAck(w,nr,j);
if(k == 0 &&i==n)
break;
for(z=0;z<k;z++){

printf("The frame %d is re -transmitted ",nr[z]);


w[z] = nr[z];
printf("%d %d",z,w[z]);
}
}
}
OUTPUT:
4. Implement Dijsktra’s algorithm to compute the shortest path through a network.
CODE:
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>

int V;

int minDistance(int dist[], bool sptSet[])


{
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v], min_index = v;

return min_index;
}

void printSolution(int dist[])


{
printf("Vertex \t\t Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t\t\t %d\n", i, dist[i]);
}

void dijkstra(int graph[][10], int src,int V)


{
int dist[V];

bool sptSet[V];
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;

dist[src] = 0;

for (int count = 0; count < V - 1; count++) {


int u = minDistance(dist, sptSet);
sptSet[u] = true;
for (int v = 0; v < V; v++)
if (!sptSet[v] && graph[u][v]
&& dist[u] != INT_MAX
&& dist[u] + graph[u][v] < dist[v])
dist[v] = dist[u] + graph[u][v];
}
printSolution(dist);
}
int main()
{
printf("Enter V:");
scanf("%d",&V);
int graph[V][10];

for(int i=0;i<V;i++){
for(int j=0;j<V;j++){
scanf("%d",&graph[i][j]);
}
}

dijkstra(graph, 0,V);

return 0;
}
OUTPUT:
5. Implement distance vector routing algorithm for obtaining routing tables at each node.
CODE:
#include<stdio.h>
struct node {
unsigned dist[20];
unsigned from[20];
}rt[10];
int main() {
int dmat[20][20],n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter 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("\n\nState value for router %d is \n",i+1);
printf("node\tDistance\tnextHop\n");
for(j=0;j<n;j++) {
printf("%d\t%d\t%d\n",j+1,rt[i].dist[j],rt[i].from[j]+1);
}

printf("\n\n"); }
}
OUTPUT:
6. Write a program for congestion control using Leaky bucket algorithm.
CODE:
#include<stdio.h>
int main(){
int N , R ,B,flag;
int fill=0;

printf("Enter the Rate at which bucket is leaking : ");


scanf("%d",&R);
printf("Enter the Bucket Size :");
scanf("%d",&B);
flag = 1;
while(flag){
printf("\nIteration----------------\n");
printf("Enter the rate at which host is transmitting :");
scanf("%d",&N);
if(N-R<0){
if(fill + N <= R ){
printf("\nThe number of packets transmitted are %d " , fill + N);
printf("\nNo packets lost ");
printf("\nBucket empty ");
fill = 0;
}
else{
printf("\nNo of packets transmitted are %d ",R);
fill = fill - R + N;
printf("\nNo packets lost ");
printf("\nBucket has %d packets ",fill);
if(fill== B)
printf("\n The bucket is full ");

}
}
else{
fill += N-R;
printf("\nThe no of packets transmitted are %d ",R);
if(fill>B){
printf("\nOverflow , %d packets are lost ",fill - B );
fill = B ;
if(fill== B)
printf("\n The bucket is full ");
}
else{
printf("\nNo of packets in the bucket are %d " ,fill );
printf("\nNo packets lost ");
if(fill== B)
printf("\n The bucket is full ");
}
}
printf("\nDo you want to proceed ?(1y,0N)");
scanf("%d",&flag);
}}
OUTPUT:
7. Wireshark
Wireshark is a free opensource network protocol analyzer. It is used for network troubleshooting and communication
protocol analysis. Wireshark captures network packets in real time and display them in human-readable format. It
provides many advanced features including live capture and offline analysis, three-pane packet browser, coloring
rules for analysis.

Some intended purposes


Here are some reasons people use Wireshark:

 Network administrators use it to troubleshoot network problems


 Network security engineers use it to examine security problems
 QA engineers use it to verify network applications
 Developers use it to debug protocol implementations
 People use it to learn network protocol internals

Getting Wireshark
The Kai Linux has Wireshark installed. You can just launch the Kali Linux VM and open Wireshark there.
Wireshark can also be downloaded from here:
https://www.wireshark.org/download.html
Starting Wireshark
When you run the Wireshark program, the Wireshark graphic user interface will be shown.

Then, you need to choose an interface. If you are running the Wireshark on your
laptop, you need to select WiFi interface. If you are at a desktop, you need to
select the Ethernet interface being used. Note that there could be multiple
interfaces. In general, you can select any interface but that does not mean that
traffic will flow through that interface. The network interfaces (i.e., the physical
connections) that your computer has to the network are shown.

After you select the interface, you can click start to capture the packets as
shown.
The Wireshark interface has five major components:
Capturing Packets
After downloading and installing Wireshark, you can launch it and click the name of an
interface under Interface List to start capturing packets on that interface. For example, if
you want to capture traffic on the wireless network, click your wireless interface.
Do the following steps:
1. Start up the Wireshark program (select an interface and press start to capture
packets).
2. Start up your favorite browser (ceweasel in Kali Linux).
3. In your browser, go to Wayne State homepage by typing www.wayne.edu.
4. After your browser has displayed the http://www.wayne.edu page, stop
Wireshark packet capture by selecting stop in the Wireshark capture window.
This will cause the Wireshark capture window to disappear and the main
Wireshark window to display all packets captured since you began packet
capture see image below:

Color Coding

You’ll probably see packets highlighted in a variety of different colors. Wireshark


uses colors to help you identify the types of traffic at a glance. By default, light
purple is TCP traffic, light blue is UDP traffic, and black identifies packets with
errors---for example, they could have been delivered out of order.
To view exactly what the color codes mean, click View > Coloring Rules. You can
also customize and modify the coloring rules from here, if you like.

Filtering Packets

The most basic way to apply a filter is by typing it into the filter box at the top of
the window and clicking Apply (or pressing Enter). For example, type “dns” and
you’ll see only DNS packets. When you start typing, Wireshark will help you
autocomplete your filter.
You can also click Analyze > Display Filters to choose a filter from among the default filters
included in Wireshark. From here, you can add your own custom filters and save them to easily
access them in the future.

Another interesting thing you can do is right-click a packet and select Follow >
TCP Stream.

You’ll see the full TCP conversation between the client and the server. You can
also click other protocols in the Follow menu to see the full conversations for
other protocols, if applicable.
Close the window and you’ll find a filter has been applied automatically. Wireshark is showing you
the packets that make up the conversation.

Inspecting Packets
Click a packet to select it and you can dig down to view
its details.
Steps to capture relevant data :
1) Set the filter as ip.addr == <client ip address>

You might also like