0% found this document useful (0 votes)
4 views52 pages

CNLab FinalFormatted

The document outlines a series of experiments related to networking and data link layer protocols, including the study of network devices, implementation of various data link layer methods such as character stuffing, bit stuffing, checksum, and Hamming code generation. Each experiment includes objectives, procedures, and example programs to demonstrate the concepts. Additionally, it covers practical aspects of connecting computers in a Local Area Network and using tools like Wireshark and Nmap for network analysis.

Uploaded by

arnav0260
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views52 pages

CNLab FinalFormatted

The document outlines a series of experiments related to networking and data link layer protocols, including the study of network devices, implementation of various data link layer methods such as character stuffing, bit stuffing, checksum, and Hamming code generation. Each experiment includes objectives, procedures, and example programs to demonstrate the concepts. Additionally, it covers practical aspects of connecting computers in a Local Area Network and using tools like Wireshark and Nmap for network analysis.

Uploaded by

arnav0260
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

INDEX

S.No Name of Experiment CO Page No


1 Study of Network devices in detail and connect the CO1
computers in Local Area Network. 1
Write a Program to implement the data link layer
2 farming methods such as CO2 7
i) Character stuffing ii) bit stuffing.
3 Write a Program to implement data link layer farming CO2
method checksum. 9

4 Write a program for Hamming Code generation for


CO2 12
error detection and correction.
5 Write a Program to implement on a data set of characters the CO2
three CRC polynomials – CRC 12, CRC 16 and CRC CCIP. 14
6 Write a Program to implement Sliding window protocol for CO2
Goback N. 17
7 Write a Program to implement Sliding window protocol for CO2
Selective repeat. 19
8 Write a Program to implement Stop and Wait Protocol. CO2 22
9 Write a program for congestion control using leaky bucket CO2
algorithm. 27

10 Write a Program to implement Dijkstra‘s algorithm to


CO2 30
compute the Shortest path through a graph.
Write a Program to implement Distance vector routing
11 algorithm by obtaining routing table at each node (Take
CO2 32
an example subnet graph with weights indicating delay
between nodes).
12 Write a Program to implement Broadcast tree by taking
CO2 34
subnet of hosts.
Study about Wireshark
i. Packet Capture Using Wire shark
13 ii. Starting Wire shark using command line CO3 36
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
14 How to run Nmap scan. CO4 41
15 Operating System Detection using Nmap CO4 43
Do the following using NS2 Simulator
i. NS2 Simulator-Introduction
16 ii. Simulate to find the number of CO5
44
packets Dropped
iii. Simulate to find the number of packets
Content Beyond Syllabus
Implement an Ethernet LAN using n nodes and set
17 multiple traffic nodes and plot conges the window for CO4 45
different source/destination.
EXPERIMENT-1

1. AIM : Study of Network devices in detail and connect the computers in


Local Area Network.
Study of Network Devices in Detail and connect the computers in Local Area
Network
a) Study of Network Devices in Detail
 Repeater
 Hub
 Switch
 Bridge
 Router
 Gate Way

Apparatus(Software): No software or hardware needed.

Procedure: following should be done to understand this practical.

1. Repeater:Functioning a Physical Layer .Arepeaterisanelectronicdevicethatrecei ves


assignaland retransmits it at a higher level and/or higher power, or onto
theothersideofanobstruction,sothatthesignalcancoverlongerdistances.Repeaterh
avetwoports,socannotbeusetoconnectformorethantwodevices

2. Hub:AnEthernet hub,activehub,network hub,repeaterhub,hubor


concentrator

isadeviceforconnectingmultipletwistedpairorfiberopticEthernetdevicestogether and
making them act as a single networksegment.Hubsworkat thephysical layer (layer 1)
of the OSI model. The device is a form of multiport repeater.Repeater
hubsalsoparticipate incollision detection,forwardinga jam signaltoallportsif it detects
acollision.

Page | 1
3. Switch:Anetwork switch or switching hub isacomputer networking devicethat connects
network segments.The term commonly refers to a network bridge thatprocessesandroutesdata at
the data link layer (layer 2) of the OSI
model.Switchesthatadditionallyprocessdataatthenetworklayer(layer3andabove)areoftenre ferred
toas Layer 3switchesormultilayerswitches.

Switch

4. Bridge: A network bridge connects multiple network segments at the data linklayer (Layer 2)
of the OSI model.In Ethernetnetworks,the term bridgeformallymeans a device that behaves
according to the IEEE 802.1D standard. A bridge andswitch are very much alike; a switch being
a bridge with numerous ports. Switch
orLayer2switchisoftenusedinterchangeablywithbridge.Bridgescananalyzeincoming data packets
to determine if the bridge is able to send the given packet toanothersegmentof thenetwork.

5. Router:Arouterisanelectronicdevicethatinterconnectstwoormorecomputer networks, and


selectively interchangespacketsofdata between them.Each data packet contains address
information that a router can use to determine if
thesourceanddestinationareonthesamenetwork,orifthedatapacketmustbetransferred from one
network to another. Where multiple routers are used in a largecollection of

Page | 2
interconnected networks, the routers exchange information about targetsystem addresses, so
that each router can build up a table showing the preferred pathsbetweenany two systems
on the interconnectednetworks.

6. Gate Way: In a communications network, a network node equipped for


interfacingwithanother networkthat uses differentprotocols.
a. Agatewaymaycontaindevicessuchasprotocoltranslators,impedancematc
hingdevices,rateconverters,faultisolators,orsignaltranslatorsasnecessary
toprovidesysteminteroperability.Italsorequirestheestablishmentofmutua
llyacceptableadministrativeprocedures betweenbothnetworks.

b. Aprotocoltranslation/mappinggatewayinterconnectsnetworkswithdifferen
tnetworkprotocoltechnologiesbyperformingtherequiredprotocolconversio ns.

Page | 3
b) AIM: Connect thecomputersin localareanetwork.

Procedure: On the host computer


Onthehostcomputer, followthesestepstosharetheInternetconnection:

1. LogontothehostcomputerasAdministratororasOwner.
2. ClickStart,andthenclickControlPanel.
3. ClickNetworkandInternetConnections.
4. ClickNetworkConnections.
5. Right-click the connection that you use to connect to the Internet. For example, ifyou connect to
the Internet by using a modem, right-click the connection that youwantunderDial-up / other
networkavailable.
6. ClickProperties.
7. ClicktheAdvancedtab.

8. Under Internet Connection Sharing, select the Allow other network users
toconnectthroughthiscomputer'sInternetconnectioncheckbox.

9. If you are sharing a dial-up Internet connection, select the Establish a dial-
upconnectionwheneveracomputeronmynetworkattemptstoaccess theInternet check box if you
want to permit your computer to automatically connecttotheInternet.

10. ClickOK.You receive thefollowingmessage:


When Internet Connection Sharing is enabled, your LAN adapter will be set to use
IPaddress 192.168.0.1. Your computer may lose connectivity with other computers
onyour network. If these other computers have static IP addresses, it is a good idea to
setthem to obtain their IP addresses automatically.Are you sure you want to
enableInternet ConnectionSharing?

11. Click Yes.


The connection to the Internet is shared to other computers on the local area network(LAN).
The network adapter that is connected to the LAN is configured with a static IP
addressof192.168.0.1and a subnet maskof255.255.255.0
Ontheclientcomputer

To connect to the Internet by using the shared connection, you must confirm the
LANadapter IP configuration, and then configure the client computer.To confirm the
LANadapterIPconfiguration,follow thesesteps:

Page | 4
1. LogontotheclientcomputerasAdministratororasOwner.
2. ClickStart,andthenclickControlPanel.
3. ClickNetworkandInternetConnections.
4. ClickNetworkConnections.
5. Right-clickLocalAreaConnectionandthenclickProperties.
6. Click the General tab, click Internet Protocol (TCP/IP) in the
connectionusesthefollowingitemslist, andthenclickProperties.
7. In the Internet Protocol (TCP/IP) Properties dialog box, click Obtain an
IPaddressautomatically(if it isnotalreadyselected),andthenclickOK.

Note: You can also assign a unique static IP address in the range of 192.168.0.2
to192.168.0.254. For example, you can assign the following static IP address,
subnetmask,anddefault gateway:
8.IPAddress192.168.31.202
9.Subnet mask255.255.255.0
10. Default gateway192.168.31.1
11. IntheLocalAreaConnectionPropertiesdialogbox,clickOK.
12. QuitControlPanel.
Ping Output:

Traceroute Output:

Page | 5
Page | 6
EXPERIMENT-2

2. AIM: Write a program to implement the data link layer farming methods such as
i) Character stuffing ii) bit stuffing.

i)Character Stuffing
Program:
#include<stdio.h>
#include<string.h>
main()
{
char a[30], fs[50] = " ", t[3], sd, ed, x[3], s[3], d[3], y[3];
int i, j, p = 0, q = 0;
clrscr();
printf("Enter characters to be stuffed:");
scanf("%s", a);
printf("\nEnter a character that represents starting delimiter:");
scanf(" %c", &sd);
printf("\nEnter a character that represents ending delimiter:");
scanf(" %c", &ed);
x[0] = s[0] = s[1] = sd;
x[1] = s[2] = '\0';
y[0] = d[0] = d[1] = ed;
d[2] = y[1] = '\0';
strcat(fs, x);
for(i = 0; i<strlen(a); i++)
{
t[0] = a[i];
t[1] = '\0';
if(t[0] == sd)
strcat(fs, s);
else if(t[0] == ed)
strcat(fs, d);
else
strcat(fs, t);
}
strcat(fs, y);
printf("\n After stuffing:%s", fs);
}
OUTPUT:

Enter characters to be stuffed: goodday


Enter a character that represents starting delimiter:
d Enter a character that represents ending delimiter:
g After stuffing: dggooddddayg.

Page | 7
ii) Bit stuffing
Program:
#include<stdio.h>
#include<string.h>
int main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size (Example: 8):");
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)
{
j++;
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)
{

}
i=k; b[j]=0;
} }
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After Bit Stuffing :");
for(i=0; i<j; i++)
printf("%d",b[i]);
return 0;
}
OUTPUT for BIT STUFFING:
Enter frame size (Example: 8):12
Enter the frame in the form of 0 and 1 :0 1 0 1 1 1 1 1 1 0 0 1
After Bit Stuffing :0101111101001

Page | 8
EXPERIMENT-3
3. AIM: Write a program to implement data link layer farming method checksum.
program:
#include<stdio.h>
#include<string.h>

int main()
{
char a[20],b[20];
char sum[20],complement[20];
int i,length;

printf("Enter first binary string\n");


scanf("%s",&a);
printf("Enter second binary string\n");
scanf("%s",&b);

if(strlen(a)==strlen(b))
{ length = strlen(a);
char carry='0';

for(i=length-1;i>=0;i--)
{
if(a[i]=='0' && b[i]=='0' && carry=='0')
{
sum[i]='0';
carry='0';
}
else if(a[i]=='0' && b[i]=='0' && carry=='1')
{

sum[i]='1';
carry='0';

}
else if(a[i]=='0' && b[i]=='1' && carry=='0')
{
sum[i]='1';
carry='0';

}
else if(a[i]=='0' && b[i]=='1' && carry=='1')
{
sum[i]='0';

Page | 9
carry='1';

}
else if(a[i]=='1' && b[i]=='0' && carry=='0')
{
sum[i]='1';
carry='0';

}
else if(a[i]=='1' && b[i]=='0' && carry=='1')
{
sum[i]='0';
carry='1';

}
else if(a[i]=='1' && b[i]=='1' && carry=='0')
{
sum[i]='0';
carry='1';

}
else if(a[i]=='1' && b[i]=='1' && carry=='1')
{
sum[i]='1';
carry='1';

}
else
break;
}

printf("\nSum=%c%s",carry,sum);
for(i=0;i<length;i++)
{
if(sum[i]=='0')
complement[i]='1';
else
complement[i]='0';
}

if(carry=='1')
carry='0';
else
carry='1'; printf("\nChecksum=%c

%s",carry,complement);

Page | 10
}
else {
printf("\nWrong input strings");
}
}

OUTPUT:

Page | 11
EXPERIMENT-4
4. AIM: Write a program for hamming code generation for error detection and
correction.
Program:
#include<stdio.h>
void main() {
int data[10];
int dataatrec[10],c,c1,c2,c3,i;

printf("Enter 4 bits of data one by one\n");


scanf("%d",&data[0]);

scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);

//Calculation of even parity


data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\n\nEnter received data bits one by one\n");


for(i=0;i<7;i++)
scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;

if(c==0) {
printf("\nNo error while transmission of data\n");
}
else {
printf("\nError on position %d",c);

printf("\nData sent : ");


for(i=0;i<7;i++)
printf("%d",data[i]); printf("\

nData received : ");

Page | 12
for(i=0;i<7;i++)
printf("%d",dataatrec[i]); printf("\
nCorrect message is\n");

//if errorneous bit is 0 we complement it else vice versa


if(dataatrec[7-c]==0)
dataatrec[7-c]=1;
else
dataatrec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);
}
}
}

OUTPUT:

Enter 4 bits of data one by one


1
0
1
0

Encoded data is
1010010

Enter received data bits one by one


1
0
1
0
0
1
0

No error while transmission of data

Page | 13
EXPERIMENT-5
5. AIM: Write a program to implement on a data set of characters the three crc
polynomials – crc 12, crc 16 and crc ccip.
Program:
#include<stdio.h>
# include<string.h>
#define N strlen(g)
char t[28],cs[28],g[28];
int a,e,c,b;
void xor()
{
for(c=1;c<N;c++)
cs[c]=((cs[c]==g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++)
cs[e]=t[e];
do
{ if(cs[0]=='1')
xor();
for(c=0;c<N-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
} int main()
{ int flag=0;
do{
printf("\n1.crc12\n2.crc16\ncrcccit\n4.exit\n\nEnter your option.");
scanf("%d",&b);
switch(b)
{ case 1:strcpy(g,"1100000001111");
break;
case 2:strcpy(g,"11000000000000101");
break;
case 3:strcpy(g,"10001000000100001");
break;
case 4:return 0;
}
printf("\n enter data:");
scanf("%s",t);
printf("\n \n");
printf("\n generating polynomial:%s",g);
a=strlen(t);

Page | 14
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n \n");
printf("mod-ified data is:%s",t);
printf("\n \n");
crc();
printf("checksum is:%s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("\n \n");
printf("\n final codeword is : %s",t);
printf("\n \n");
printf("\ntest error detection 0(yes) 1(no)?:");
scanf("%d",&e);
if(e==0)
{
do{
printf("\n\tenter the position where error is to be inserted:");
scanf("%d",&e);
}
while(e==0||e>a+N-1);
t[e-1]=(t[e-1]=='0')?'1':'0';
printf("\n \n");
printf("\n\terroneous data:%s\n",t);
} crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e+
+); if(e<N-1)
printf("error detected\n\n");
else
printf("\n no error detected \n\n");
printf("\n ");
}while(flag!=1);
} crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e+
+); if(e<N-1)
printf("error detected\n\n");
else
printf("\n no error detected \n\n");
printf("\n ");
}while(flag!=1);

Page | 15
OUTPUT:
1.crc12
2.crc16
3.crc ccit
4.exit
Enter your option.1
enter data:1100110011100011

generating polynomial:1100000001111

mod-ified data is:11001100111000110000000000001100000001111

checksum is:1101110110001

final codeword is : 11001100111000111101110110001100000001111

test error detection 0(yes) 1(no)?:1


no error detected

1.crc12
2.crc16
3.crc ccit
4.exit
enter data:11001100111000

generating polynomial:11000000000000101

mod-ified data is:110011001110000000000000000000000000000000101

Page | 16
EXPERIMENT-6

6. AIM: Write a program to implement sliding window protocol for goback n.


program:
#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;
}
els sent = ack;
} e
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.

Please enter the last Acknowledgement received.


2
Frame 2 has been transmitted.

Page | 17
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.

Please enter the last Acknowledgement received.


8

Page | 18
EXPERIMENT-7
7. AIM: Write a program to implement sliding window protocol for selective repeat.

Program:
#include<stdio.h>
int main()
{
int w,i,f,frames[50];

printf("Enter window size: ");


scanf("%d",&w);

printf("\nEnter number of frames to transmit: ");


scanf("%d",&f);

printf("\nEnter %d frames: ",f);

for(i=1;i<=f;i++)
scanf("%d",&frames[i]);

printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);

for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}

if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");

return 0;
}

Page | 19
OUTPUT:
Enter window size: 3
Enter number of frames to transmit: 5
Enter 5 frames: 12 5 89 4 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 89
Acknowledgement of above frames sent is received by sender

46
Acknowledgement of above frames sent is received by sender

Sliding Window Protocol Program in C++


Below is the simulation of sliding window protocol in C++.
Program:
#include<iostream>
using namespace std;

int main()
{
int w,i,f,frames[50];

cout<<"Enter window size: ";


cin>>w;

cout<<"\nEnter number of frames to transmit: ";


cin>>f;

cout<<"\nEnter "<<f<<" frames: ";

for(i=1;i<=f;i++)
cin>>frames[i];

cout<<"\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n";
cout<<"After sending "<<w<<" frames at each stage sender waits for acknowledgement sent
by the receiver\n\n";

for(i=1;i<=f;i++)
{
if(i%w==0)
{
cout<<frames[i]<<"\n";

Page | 20
cout<<"Acknowledgement of above frames sent is received by sender\n\n";
}
else
cout<<frames[i]<<" ";
}

if(f%w!=0)
cout<<"\nAcknowledgement of above frames sent is received by sender\n";

return 0;
}

OUTPUT:
Enter window size: 3

Enter number of frames to transmit: 5

Enter 5 frames: 12 5 89 4 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 89
Acknowledgement of above frames sent is received by sender

46
Acknowledgement of above frames sent is received by sender

Page | 21
EXPERIMENT-8

8. AIM: Write a program to implement stop and wait protocol.


program:
#include <stdlib.h>
#define TIMEOUT 5
#define MAX_SEQ 1
#define TOT_PACKETS 8
#define inc(k) if(k<MAX_SEQ) k++; else k=0;
typedef struct
{
int data;
}packet;
typedef struct
{
int kind;
int seq;
int ack;
packet info;
int err;
}frame;
frame DATA;
typedef enum{frame_arrival,err,timeout,no_event} event_type;

void from_network_layer(packet *);


void to_network_layer(packet *);
void to_physical_layer(frame *);
void from_physical_layer(frame *);
void wait_for_event_sender(event_type *);
void wait_for_event_reciever(event_type *);
void reciever();
void sender();

int i=1; //Data to be sent by sender char


turn; //r , s
int DISCONNECT=0;
/*
_*/
void main()
{
clrscr();
randomize();
while(!DISCONNECT)

Page | 22
{
sender();
delay(400);
reciever();
}

}
/*
_*/
void sender()
{
static int frame_to_send=0;
static frame s;
packet buffer;
event_type event;
static int flag=0;

if(flag==0)
{
from_network_layer(&buffer);
s.info = buffer;
s.seq = frame_to_send;
printf("SENDER : Info = %d Seq No = %d ",s.info,s.seq); turn
= 'r';
to_physical_layer(&s);
flag = 1;
}
wait_for_event_sender(&event);
if(turn=='s')
{
if(event==frame_arrival)
{
from_network_layer(&buffer);
inc(frame_to_send);
s.info = buffer;
s.seq = frame_to_send;
printf("SENDER : Info = %d Seq No = %d ",s.info,s.seq); turn
= 'r';
to_physical_layer(&s);
}
if(event==timeout)
{
printf("SENDER : Resending Frame ");

Page | 23
turn = 'r';
to_physical_layer(&s);
}
}
}
/*
_*/
void reciever()
{
static int frame_expected=0;
frame r,s;
event_type event;

wait_for_event_reciever(&event);
if(turn=='r')
{
if(event==frame_arrival)
{
from_physical_layer(&r);
if(r.seq==frame_expected)
{
to_network_layer(&r.info);
inc(frame_expected);
}
else
printf("RECIEVER : Acknowledgement Resent\n");

turn = 's';
to_physical_layer(&s);
}
if(event==err)
{
printf("RECIEVER : Garbled Frame\n");
turn = 's'; //if frame not recieved
} //sender shold send it again
}
}
/*
_*/
void from_network_layer(packet *buffer)
{
(*buffer).data = i; i+
+;

Page | 24
}
/*
*/
void to_physical_layer(frame *s)
{ // 0 means error
s->err = random(4); //non zero means no error
DATA = *s; //probability of error = 1/4
}
/*
*/
void to_network_layer(packet *buffer)
{
printf("RECIEVER :Packet %d recieved , Ack Sent\n",
(*buffer).data); if(i>TOT_PACKETS) //if all packets recieved then
disconnect
{
DISCONNECT = 1;
printf("\nDISCONNECTED");
}
}
/*
*/
void from_physical_layer(frame *buffer)
{
*buffer = DATA;
}
/*
*/
void wait_for_event_sender(event_type * e)
{
static int timer=0;

if(turn=='s')
{
timer++;
if(timer==TIMEOUT)
{
*e = timeout;
printf("SENDER : Ack not recieved=> TIMEOUT\n");
timer = 0;
return;
}
if(DATA.err==0)
*e = err;

Page | 25
else
{
timer = 0;
*e = frame_arrival;
}
}
}
/*
*/
void wait_for_event_reciever(event_type * e)
{
if(turn=='r')
{
if(DATA.err==0)
*e = err;
else
*e = frame_arrival;
}

OUTPUT:

Page | 26
EXPERIMENT-9
9. AIM: Write a program for congestion control using leaky bucket algorithm.
program:
#include <stdio.h>

#include<stdio.h>

#include<stdlib.h>

#define MIN(x,y) (x>y)?y:x

int main()

int orate,drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;

printf("\n enter bucket size : ");

scanf("%d",&cap);

printf("\n enter output rate :");

scanf("%d",&orate);

do{

printf("\n enter number of packets coming at second %d :",i+1);

scanf("%d",&inp[i]);

i++;

printf("\n enter 1 to contiue or 0 to quit ");

scanf("%d",&ch);

}while(ch);

nsec=i;

printf("\n second \t recieved \t sent \t dropped \tremained \n");

for(i=0;count || i<nsec;i++)

printf(" %d",i+1);

printf(" \t%d\t ",inp[i]);

Page | 27
printf(" \t %d\t ",MIN((inp[i]

+count),orate)); if((x=inp[i]+count-

orate)>0)

if(x>cap)

count=cap;

drop=x-cap;

else

count=x;

drop=0;

else

drop=0;

count=0;

printf(" \t %d \t %d \n",drop,count);

return 0;

OUTPUT:
enter bucket size : 5

enter output rate :3

enter number of packets coming at second 1 :1

enter 1 to contiue or 0 to quit 1

enter number of packets coming at second 2 :2


Page | 28
enter 1 to contiue or 0 to quit 0

second recieved sent dropped remained

1 1 1 0 0

2 2 2 0 0

Page | 29
EXPERIMENT-10
10. AIM: Write a program to implement dijkstra‘s algorithm to compute the shortest
path through a graph.
Program:
#include <limits.h>
#include <stdio.h>
#define V 9
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;
}
int printSolution(int dist[], int n)
{ printf("Vertex Distance from Source\
n");
for (int i = 0; i< V; i++)
printf("%d \t %d\n", i, dist[i]);
}
void dijkstra(int graph[V][V], int src)
{ 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, V);
}
int main() {
int graph[V][V] = { { 0, 6, 0, 0, 0, 0, 0, 8, 0 },
{ 6, 0, 8, 0, 0, 0, 0, 13, 0 },
{ 0, 8, 0, 7, 0, 6, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 6, 14, 10, 0, 2, 0, 0 },

Page | 30
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 13, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 }
};
dijkstra(graph, 0);
return 0;
}

OUTPUT:
Vertex Distance from Source
00
16
2 14
3 21
4 21
5 11
69
78
8 15

Page | 31
EXPERIMENT-11
11. AIM: Write a program to implement distance vector routing algorithm by
obtaining routing table at each node (take an example subnet graph with weights
indicating delay between nodes).
Program:
/*
Distance Vector Routing in this program is implemented using Bellman Ford Algorithm:-
*/
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]); costmat[i]
[i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct distance
from the node i to k using the cost matrix
//and add the distance from k to node j
for(j=0;j<nodes;j++) for(k=0;k<nodes;k+
+)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])

Page | 32
{//We calculate the minimum distance
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<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
/*

OUTPUT:
A sample run of the program works as:-
Enter the number of nodes :
3
Enter the cost matrix :
027
201
710
For router 1
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
For router 2
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
For router 3
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0
*/

Page | 33
EXPERIMENT-12
12. AIM: Write a program to implement broadcast tree by taking subnet of hosts.
program:
#include<stdio.h>
#include<conio.h
> int p,q,u,v,n;
int min=99,mincost=0;
int t[50][2],i,j;
int parent[50],edge[50][50];
main()
{
clrscr();
printf("\n Enter the number of nodes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("%c\t",65+i);
parent[i]=-1;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%c",65+i);
for(j=0;j<n;j++)
scanf("%d",&edge[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(edge[i][j]!=99)
if(min>edge[i][j])
{
min=edge[i][j];
u=i;
v=j;
}
p=find(u);
q=find(v);
if(p!=q)
{

Page | 34
t[i][0]=u;
t[i][1]=v;
mincost=mincost+edge[u][v];
sunion(p,q);
}
Else
{
t[i][0]=-1;t[i][1]=-1;
}
min=99;
}
printf("Minimum cost is %d\n Minimum spanning tree is\n" ,mincost);
for(i=0;i<n;i++)
if(t[i][0]!=-1 && t[i][1]!=-1)
{
printf("%c %c %d", 65+t[i][0],65+t[i][1],edge[t[i][0]][t[i][1]]);printf("\n");
}
getch();
}
sunion(int l,int m)
{
parent[l]=m;
}
find(int l)
{
if(parent[l]>0)
i=parent[i];
return i;
}

OUTPUT:

Page | 35
EXPERIMENT-13
13. AIM: Study about wireshark

Wireshark is an open-source packet analyzer, which is used for education, analysis, software
development, communication protocol development, and network troubleshooting.

It is used to track the packets so that each one is filtered to meet our specific needs. It is commonly
called as a sniffer, network protocol analyzer, and network analyzer. It is also used by network
security engineers to examine security problems.

Wireshark is a free to use application which is used to apprehend the data back and forth. It is
often called as a free packet sniffer computer application. It puts the network card into an
unselective mode, i.e., to accept all the packets which it receives.

A packet is a unit of data which is transmitted over a network between the origin and the destination.
Network packets are small, i.e., maximum 1.5 Kilobytes for Ethernet packets and 64 Kilobytes for
IP packets. The data packets in the Wireshark can be viewed online and can be analyzed offline
Installation of Wireshark Software

Below are the steps to install the Wireshark software on the computer:

o Open the web browser.


o Search for 'Download Wireshark.'
o Select the Windows installer according to your system configuration, either 32-bt or 64-bit.
Save the program and close the browser.
o Now, open the software, and follow the install instruction by accepting the license.
o The Wireshark is ready for use.

On the network and Internet settings option, we can check the interface connected to our
computer.

If you are Linux users, then you will find Wireshark in its package repositories.

i. Packet Capture Using Wire shark


Capturing your traffic with Wireshark
After starting Wireshark, do the following:

Page | 36
1. Select Capture | Interfaces
2. Select the interface on which packets need to be captured. This will usually be the
interface where the Packet/s column is constantly changing, which would indicate the
presence of live traffic). If you have multiple network interface cards (i.e. LAN card
and Wi-Fi adapter) you may need to check with your IT administrator to determine the
right interface.
3. Click the Start button to start the capture.
4. Recreate the problem. The capture dialog should show the number of packets
increasing. Try to avoid running any other internet applications while capturing,
closing other browsers, Instant messengers etc.
5. Once the problem which is to be analyzed has been reproduced, click on Stop. It may
take a few seconds for Wireshark to display the packets captured.
6. Save the packet trace in the default format. Click on the File menu option and select
Save As. By default Wireshark will save the packet trace in libpcap format. This is a
filename with a.pcap extension.

ii. Starting Wire shark using command line

You can start Wireshark from the command line, but it can also be started from most
Window managers as well. In this section we will look at starting it from the command line.

Wireshark supports a large number of command line parameters. To see what they are,
simply enter the command wireshark –h

Wireshark 3.7.3 (v3.7.3rc0-25-g72703582d587)


Interactively dump and analyze network traffic.
See https:/ for more information. Usage: wireshark

[options] ... [ <infile> ]

Capture interface:
-i <interface>, --interface <interface>
name or idx of interface (def: first non-loopback)
-f <capture filter> packet filter in libpcap filter syntax

iii. Viewing Captured Traffic


Once you have captured some packets or you have opened a previously saved capture file,
you can view the packets that are displayed in the packet list pane by simply clicking on a
packet in the packet list pane, which will bring up the selected packet in the tree view and
byte view panes. Once you have captured some packets or you have opened a previously

Page | 37
saved capture file, you can view the packets that are displayed in the packet list pane by
simply clicking on a packet in the packet list pane, which will bring up the selected packet in
the tree view and byte view panes.
iv. Analysis and Statistics & Filters.

Analysis menu in wireshark


The “Analyze” Menu The Wireshark Analyze menu contains the fields shown in Analyze
menu items.

The “Statistics” Menu in wireshark

The Wireshark Statistics menu contains the fields shown in .

Page | 38
Filters in wireshark
Wireshark has two filtering languages: capture filters and display filters. Capture filters are
used for filtering when capturing packets, “Filtering while capturing”. Display filters are
used for filtering which packets are displayed.

Page | 39
Page | 40
EXPERIMENT-14
14. AIM: How to run nmap scan.
1
Download the Nmap installer. This can be found for free from the developer’s website. It is
highly recommended that you download directly from the developer to avoid any potential
viruses or fake files. Downloading the Nmap installer includes Zenmap, the graphical
interface for Nmap which makes it easy for newcomers to perform scans without having to
learn command lines.
 The Zenmap program is available for Windows, Linux, and Mac OS X. You
can find the installation files for all operating systems on the Nmap website.
2
 Install Nmap. Run the installer once it is finished downloading. You will be asked
which components you would like to install. In order to get the full benefit of Nmap,
keep all of these checked. Nmap will not install any adware or spyware.
3
 Run the "Nmap – Zenmap" GUI program. If you left your settings at default during
installation, you should be able to see an icon for it on your desktop. If not, look in
your Start menu. Opening Zenmap will start the program.
4
 Enter in the target for your scan. The Zenmap program makes scanning a fairly
simple process. The first step to running a scan is choosing your target. You can
enter a domain (example.com), an IP address (127.0.0.1), a network
(192.168.1.0/24), or a combination of those.
5
Choose your Profile. Profiles are preset groupings of modifiers that change what is scanned.
The profiles allow you to quickly select different types of scans without having to type in the
modifiers on the command line. Choose the profile that best fits your needs:
 Intense scan - A comprehensive scan. Contains Operating System (OS) detection,
version detection, script scanning, traceroute, and has aggressive scan timing.
This is considered an intrusive scan.
 Ping scan - This scan simply detects if the targets are online, it does not scan any
ports.
 Quick scan - This is quicker than a regular scan due to aggressive timing and only
scanning select ports.
 Regular scan - This is the standard Nmap scan without any modifiers. It will
return ping and return open ports on the target.
6
 Click Scan to start scanning. The active results of the scan will be displayed in the Nmap
Output tab. The time the scan takes will depend on the scan profile you chose, the
physical distance to the target, and the target’s network configuration.
7
Read your results. Once the scan is finished, you’ll see the message "Nmap done" at the
bottom of the Nmap Output tab. You can now check your results, depending on the type of

Page | 41
scan you performed. All of the results will be listed in the main Nmap Output tab, but you
can use the other tabs to get a better look at specific data.
 Ports/Hosts - This tab will show the results of your port scan, including the
services for those ports.
 Topology - This shows the traceroute for the scan you performed. You can see
how many hops your data goes through to reach the target.
 Host Details - This shows a summary of your target learned through scans, such
as the number of ports, IP addresses, hostnames, operating systems, and more.
 Scans - This tab stores the commands of your previously-run scans. This
allows you to quickly re-scan with a specific set of parameters.

Page | 42
EXPERIMENT-15
15. AIM: Operating system detection using nmap
program:

nmap -O -sVx.x.x.x
Starting Nmap 7.92 ( https://nmap.org ) at 2021-09-17 11:02 PDT
Nmap scan report for x.x.x.x
Host is up (0.22s latency).
Not shown: 994 closed tcp ports (reset)

PORT STATE SERVICE VERSION


135/tcp open msrpc Microsoft Windows RPC 139/tcp open
netbios-ssn Microsoft Windows netbios-ssn 445/tcp open
microsoft-ds?
2701/tcp open cmrcservice Microsoft Configuration Manager Remote Control service
(CmRcService.exe)
3306/tcp open mysql MySQL 5.1.60-community-log 3389/tcp
open ms-wbt-server Microsoft Terminal Services

Aggressive OS guesses: Microsoft Windows Server 2016 (93%),


Microsoft Windows Server 2008 R2 SP1 (92%), Microsoft Windows Server 2012 R2 (91%),
Microsoft Windows 10 1607 (90%), Microsoft Windows Server 2008 R2 (90%),
Microsoft Windows Server 2012 (89%), Microsoft Windows Server 2012 or
Windows Server 2012 R2 (89%), Microsoft Windows Server 2008 R2 or Windows 8 (87%),
Microsoft Windows Server 2008 R2 SP1 or Windows 8 (87%), Microsoft Windows 7 SP1
(86%)
No exact OS matches for host (test conditions non-ideal). Network
Distance: 18 hops
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

OS and Service detection performed. Please report any incorrect results at


https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 33.77 seconds

Page | 43
EXPERIMENT-16

16. AIM: Do the following using ns2 simulator

i. NS2 Simulator-Introduction

What is NS2
NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator
designed specifically for research in computer communication networks.

2. Features of NS2
1. It is a discrete event simulator for networking research.
2. It provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https and DSR.

3. It simulates wired and wireless network.

4. It is primarily Unix based.

5. Uses TCL as its scripting language.

6. Otcl: Object oriented support

7. Tclcl: C++ and otcl linkage

8. Discrete event scheduler

3. Basic Architecture
NS2 consists of two key languages: C++ and Object-oriented Tool Command Language
(OTcl). While the C++ defines the internal mechanism (i.e., a backend) of the simulation
objects, the OTcl sets up simulation by assembling and configuring the objects as well as
scheduling discrete events. The C++ and the OTcl are linked together using TclCL

Page | 44
Additional program
17 AIM: Implement an Ethernet LAN using n nodes and set multiple traffic nodes and
plot conges the window for different source/destination.

Program:

#Create Simulator

set ns [new Simulator]

#Use colors to differentiate the traffics

$ns color 1 Blue

$ns color 2 Red

#Open trace and NAM trace file set ntrace [open prog5.tr w]

$ns trace-all $ntrace

set namfile [open prog5.nam w]

$ns namtrace-all $namfile

#Use some flat file to create congestion graph windows set winFile0 [open WinFile0 w]

set winFile1 [open WinFile1 w]

#Finish Procedure proc Finish {} {

#Dump all trace data and Close the files global ns ntrace namfile

$ns flush-trace close $ntrace close $namfile

#Execute the NAM animation file exec nam prog5.nam &

Page | 45
#Plot the Congestion Window graph using xgraph exec xgraph WinFile0 WinFile1 &

exit 0

#Plot Window Procedure

proc PlotWindow {tcpSource file} { global ns

set time 0.1

set now [$ns now]

set cwnd [$tcpSource set cwnd_] puts $file "$now $cwnd"

$ns at [expr $now+$time] "PlotWindow $tcpSource $file"

#Create 6 nodes

for {set i 0} {$i<6} {incr i} { set n($i) [$ns node]

#Create duplex links between the nodes

$ns duplex-link $n(0) $n(2) 2Mb 10ms DropTail

$ns duplex-link $n(1) $n(2) 2Mb 10ms DropTail

$ns duplex-link $n(2) $n(3) 0.6Mb 100ms DropTail

Page | 46
#Nodes n(3) , n(4) and n(5) are considered in a LAN

set lan [$ns newLan "$n(3) $n(4) $n(5)" 0.5Mb 40ms LL Queue/DropTail MAC/802_3
Channel]

#Orientation to the nodes

$ns duplex-link-op $n(0) $n(2) orient right-down

$ns duplex-link-op $n(1) $n(2) orient right-up

$ns duplex-link-op $n(2) $n(3) orient right

#Setup queue between n(2) and n(3) and monitor the queue

$ns queue-limit $n(2) $n(3) 20

$ns duplex-link-op $n(2) $n(3) queuePos 0.5

#Set error model on link n(2) to n(3) set loss_module [new ErrorModel]

$loss_module ranvar [new RandomVariable/Uniform]

$loss_module drop-target [new Agent/Null]

$ns lossmodel $loss_module $n(2) $n(3)

#Set up the TCP connection between n(0) and n(4) set tcp0 [new Agent/TCP/Newreno]

$tcp0 set fid_ 1

$tcp0 set window_ 8000

$tcp0 set packetSize_ 552

$ns attach-agent $n(0) $tcp0

Page | 47
set sink0 [new Agent/TCPSink/DelAck]

$ns attach-agent $n(4) $sink0

$ns connect $tcp0 $sink0

#Apply FTP Application over TCP set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 set type_ FTP

#Set up another TCP connection between n(5) and n(1) set tcp1 [new Agent/TCP/Newreno]

$tcp1 set fid_ 2

$tcp1 set window_ 8000

$tcp1 set packetSize_ 552

$ns attach-agent $n(5) $tcp1

set sink1 [new Agent/TCPSink/DelAck]

$ns attach-agent $n(1) $sink1

$ns connect $tcp1 $sink1

#Apply FTP application over TCP set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ftp1 set type_ FTP

Page | 48
#Schedule Events

$ns at 0.1 "$ftp0 start"

$ns at 0.1 "PlotWindow $tcp0 $winFile0"

$ns at 0.5 "$ftp1 start"

$ns at 0.5 "PlotWindow $tcp1 $winFile1"

$ns at 25.0 "$ftp0 stop"

$ns at 25.1 "$ftp1 stop"

$ns at 25.2 "Finish"

#Run the simulation

$ns run

OUTPUT:

Page | 49

You might also like