You are on page 1of 69

Department of Computer Science and Engineering(AI & ML)

LAB MANUAL (MASTER)

Name of the Lab : Computer Networks

Year : III Year II semester

Regulation : R20

A.Y. : 2022-23

CMREC, III –I,CSE Page 1


LAB CODE

➢ Students should report to the concerned lab as per the time table.

➢ Students who turn up late to the labs will in no case be permitted to do the program schedule
for the day.

➢ After completion of the program, certification of the concerned staff in-charge in the
observation book is necessary.

➢ Student should bring a notebook of 100 pages and should enter the readings /observations into
the notebook while performing the experiment.

➢ The record of observations along with the detailed experimental procedure of the experiment
in the immediate last session should be submitted and certified staff member in-charge.
➢ The group-wise division made in the beginning should be adhered to and no mix up of students
among different groups will be permitted.

➢ When the experiment is completed, should disconnect the setup made by them, and should
return all the components/instruments taken for the purpose.

➢ Any damage of the equipment or burn-out components will be viewed seriously either by
putting penalty or by dismissing the total group of students from the lab for the semester/year.

➢ Students should be present in the labs for total scheduled duration.

➢ Students are required to prepare thoroughly to perform the experiment before coming to
laboratory.
CMREC, III –I,CSE Page 2
AI604PC: COMPUTER NETWORKS LAB
III Year B.Tech. CSE II-Sem L T P C
0 0 3 1.5
Course Objectives
1. To understand the working principle of various communication protocols.
2. To understand the network simulator environment and visualize a network topology
and observe its performance
3. To analyze the traffic flow and the contents of protocol frames

Course Outcomes
1. Implement data link layer farming methods
2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools

List of Experiments
1. Implement the data link layer framing methods such as character, character-stuffing and bit
stuffing.
2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRCCCIP
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.
4. Implement Dijsktra’s algorithm to compute the shortest path through a network
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
6. Implement distance vector routing algorithm for obtaining routing tables at each node.
7. Implement data encryption and data decryption
8. Write a program for congestion control using Leaky bucket algorithm.
9. Write a program for frame sorting technique used in buffers.
10. Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
11. How to run Nmap scan
12. Operating System Detection using Nmap
13. Do the following using NS2 Simulator
i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate& Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to Transmission of Packets

CMREC, III –I,CSE Page 3


INDEX
Experiment Page
Name of the Experiment
No. No.

1. Implement the data link layer framing methods such as character,


character-stuffing and bit stuffing. 5-12

2. Write a program to compute CRC code for the polynomials CRC-12,


CRC-16 and CRC CCIP 13-18
Develop a simple data link layer that performs the flow control using
3. the sliding window protocol, and loss recovery using the Go-Back-N
mechanism. 19-21

4. Implement Dijsktra’s algorithm to compute the shortest path through a


network 22-26
5. Take an example subnet of hosts and obtain a broadcast tree for the
subnet. 27-32
6. Implement distance vector routing algorithm for obtaining routingtables at
each node. 33-38
7. Implement data encryption and data decryption
39-43
8. Write a program for congestion control using Leaky bucket algorithm. 44-45
9. Write a program for frame sorting technique used in buffers. 46-48
Wire shark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
10. iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters Viewing Captured 49-54
Traffic
v. Analysis and Statistics & Filters.
11. How to run Nmap scan 55
12. Operating System Detection using Nmap 56
Do the following using NS2 Simulator
i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets
Dropped
13. by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped 57-69
due to Congestion
v. Simulate to Compare Data Rate& Throughput.
vi. Simulate to Plot Congestion for Different
Source/Destination
vii. Simulate to Determine the Performance with
respect to Transmission of Packets

CMREC, III –I,CSE Page 4


EXPERIMENT NO: 1

NAME OF THE EXPERIMENT: Character Stuffing.


AIM: Implement the data link layer farming methods such as character, character stuffing.
HARDWARE REQUIREMENTS: Intel based Desktop PC:-
RAM of 512 MB
SOFTWARE REQUIREMENTS: Turbo C / Borland C.
THEORY:
The framing method gets around the problem of resynchronization after an error by having each frame
start with the ASCII character sequence DLE STX and the sequence DLE ETX. If the destination
ever losses the track of the frame boundaries all it has to do is look for DLE STX or DLE ETX
characters to figure out. The data link layer on the receiving end removes the DLE before the data are
given to the network layer. This technique is called character stuffing
ALGORITHM:
Begin
Step 1: Initialize I and j as 0
Step 2: Declare n and pos as integer and a[20],b[50],ch as character
Step 3: read the string a
Step 4: find the length of the string n, i.e n-strlen(a)
Step 5: read the position, pos
Step 6: if pos > n then
Step 7: print invalid position and read again the position, pos
Step 8: end if
Step 9: read the character, ch
Step 10: Initialize the array b , b[0…5] as ’d’, ’l’, ’e’, ’s’ ,’t’ ,’x’
respectively
Step 11: j=6;
Step 12: Repeat step[(13to22) until i<n
Step 13: if i==pos-1 then
Step 14: initialize b array,b[j],b[j+1]…b[j+6] as‘d’, ‘l’, ‘e’ ,’ch, ’d’, ‘l’,‘e’
respectively

CMREC, III –I,CSE Page 5


Step 15: increment j by 7, i.e j=j+7
Step 16: end if
Step 17: if a[i]==’d’ and a[i+1]==’l’ and a[i+2]==’e’ then
Step 18: initialize array b, b[13…15]=’d’, ‘l’, ‘e’ respectively
Step 19: increment j by 3, i.e j=j+3
Step 20: end if
Step 21: b[j]=a[i]
Step 22: increment I and j;
Step 23: initialize b array,b[j],b[j+1]…b[j+6] as‘d’, ‘l’,‘e’ ,’e’,‘t’, ‘x’,‘\0’
respectively
Step 24: print frame after stiuffing
Step 25: print b
End
CREATE THE PROGRAM NAME

[m0033@agni cnlabprograms]$ vi exp1a.c

SOURCE CODE:
//PROGRAM FOR CHARACTER STUFFING
#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
{

CMREC, III –I,CSE Page 6


printf("invalid position, Enter again :");
scanf("%d",&pos);
}
printf("enter the character\n");
scanf("%s",&ch);
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}

CMREC, III –I,CSE Page 7


b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
}
COMPILE THE PROGRAM:
[m0033@agni cnlabprograms]$ cc exp1a.c

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

Enter the string: archana

Enter position 3

Enter the character h

Frame after stuffing:

dlestxardlehdlechanadleetx

CMREC, III –I,CSE Page 8


NAME OF THE EXPERIMENT: Bit Stuffing.
AIM: Implement the data link layer farming methods such as and bit stuffing.
HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB
SOFTWARE REQUIREMENTS: Turbo C / Borland C.
THEORY:
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 stuffs 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:
Begin
Step 1: Read frame length n
Step 2: Repeat step (3 to 4) until i<n(: Read values in to the input frame (0’s and 1’s) i.e.
Step 3: initialize I i=0;
Step 4: read a[i] and increment i
Step 5: Initialize i=0, j=0,count =0
Step 6: repeat step (7 to 22) until i<n
Step 7: If a[i] == 1 then
Step 8: b[j] = a[i]
Step 9: Repeat step (10 to 18) until (a[k] =1 and k<n and count <5)
Step 10: Initialize k=i+1;
Step 11: Increment j and b[j]= a[k];
Step 12: Increment count;
Step 13: if count =5 then
Step 14: increment j,
Step 15: b[j] =0
Step 16: end if
Step 17: i=k;

CMREC, III –I,CSE Page 9


Step 18: increment k
Step 19: else
Step 20: b[j] = a[i]
Step 21: end if
Step 22: increment I and j
Step 23: print the frame after bit stuffing
Step 24: repeat step (25 to 26) until i< j
Step 25: print b[i]
Step 26: increment i
End
CREATE THE NAME OF THE PROGRAM

[m0033@agni cnlabprograms]$ vi exp1a.c

SOURCE CODE:
// BIT Stuffing program
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
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++)
{

CMREC, III –I,CSE Page 10


j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
}

COMPILE THE PROGRAM:


[m0033@agni cnlabprograms]$ cc exp1b.c

OUTPUT

[m0033@agni cnlabprograms]$ ./a.out

Enter frame length:12

Enter input frame (0's & 1's only):

CMREC, III –I,CSE Page 11


1

1
After stuffing the frame is: 1111101111111

CMREC, III –I,CSE Page 12


EXPERIMENT NO: 2

NAME OF THE EXPERIMENT: Cyclic Redundancy Check.


AIM: Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC
CCIP.
HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB
SOFTWARE REQUIREMENTS: Turbo C / Borland C.
THEORY:
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.5. 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/FLOWCHART:
Begin
Step 1: Declare I,j,fr[8],dupfr[11],recfr[11],tlen,flag,gen[4],genl,frl,
rem[4] as integer
Step 2: initialize frl=8 and genl=4
Step 3: initialize i=0
Step 4: Repeat step(5to7) until i<frl
Step 5: read fr[i]
Step 6: dupfr[i]=fr[i]
Step 7: increment i
Step 8: initialize i=0
Step 9: repeat step(10to11) until i<genl
Step 10: read gen[i]
Step 11: increment i
Step 12: tlen=frl+genl-1
Step 13: initialize i=frl

CMREC, III –I,CSE Page 13


Step 14: Repeat step(15to16) until i<tlen
Step 15: dupfr[i]=0
Step 16: increment i
Step 17: call the function remainder(dupfr)
Step 18: initialize i=0
Step 19: repeat step(20 to 21) until j<genl
Step 20: recfr[i]=rem[j]
Step 21: increment I and j
Step 22: call the function remainder(dupfr)
Step 23: initialize flag=0 and i=0
Step 24: Repeat step(25to28) until i<4
Step 25: if rem[i]!=0 then
Step 26: increment flag
Step 27: end if
Step 28: increment i
Step 29: if flag=0 then
Step 25: print frame received correctly
Step 25: else
Step 25: print the received frame is wrong
End
Function: Remainder(int fr[])
Begin
Step 1: Declare k,k1,I,j as integer
Step 2: initialize k=0;
Step 3: repeat step(4 to 14) until k< frl
Step 4: if ((fr[k] == 1) then
Step 5: k1=k
Step 6: initialize i=0, j=k
Step 7: repeat step(8 to 9) until i< genl
Step 8: rem[i] =fr[j] exponential gen[i]
Step 9: increment I and j
Step 10: initialize I = 0

CMREC, III –I,CSE Page 14


Step 11: repeat step(12to13) until I <genl
Step 12: fr[k1] = rem[i]
Step 13: increment k1 and i
Step 14: end if
End
CREATE THE PROGRAM NAME
[m0033@agni cnlabprograms]$ vi exp2.c

SOURCE CODE:
//PROGRAM FOR CYCLIC REDUNDENCY CHECK
#include<stdio.h>
int gen[4],genl,frl,rem[4];
void main()
{
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
frl=8; genl=4;
printf("enter frame:");
for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
}
printf("enter generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);
tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
{
dupfr[i]=0;
}
remainder(dupfr);
for(i=0;i<frl;i++)
{

CMREC, III –I,CSE Page 15


recfr[i]=fr[i];
}
for(i=frl,j=1;j<genl;i++,j++)
{
recfr[i]=rem[j];
}

remainder(recfr);
flag=0;
for(i=0;i<4;i++)
{
if(rem[i]!=0)
flag++;
}
if(flag==0)
{
printf("frame r eceived correctly");
}
else
{
printf("the received frame is wrong");
}

}
remainder(int fr[])
{
int k,k1,i,j;
for(k=0;k<frl;k++)
{
if(fr[k]==1)
{
k1=k;

CMREC, III –I,CSE Page 16


for(i=0,j=k;i<genl;i++,j++)
{
rem[i]=fr[j]^gen[i];
}

for(i=0;i<genl;i++)
{
fr[k1]=rem[i];
k1++;
}
}
}
}
COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp2.c

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

Enter frame: 1

0
1

1
Enter generator: 1

CMREC, III –I,CSE Page 17


frame received correctly

[m0033@agni cnlabprograms]$ ./a.out

enter frame:1

enter generator:1

1
the received frame is wrong

CMREC, III –I,CSE Page 18


EXPERIMENT NO: 3
NAME OF THE EXPERIMENT: 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.

AIM: Implement of a slidining window algorithm to loss recovery using the Go-Back-N mechanism.
a) Sliding window protocol

Sliding window protocol: this protocol is applied on the Data Link Layer of OSI model to
provide flow control. At data link layer data is in the form of frames. In Networking, Window
simply means a buffer which has data frames that needs to be transmitted.

In this sliding window mechanism both sender and receiver agrees on some window size and
transfer the frames based on the size the window. If window size=w then after sending w frames
sender waits for the acknowledgement (ack) of the first frame.

As soon as sender receives the acknowledgement of a frame it is replaced by the next frames to
be transmitted by the sender.

#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");
}

CMREC, III –I,CSE Page 19


else
printf("%d ",frames[i]);
}

if(f%w!=0)
printf("\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

b) Go back-N Protocol
Go-Back-N protocol, also called Go-Back-N Automatic Repeat reQuest, is a data link layer protocol
that uses a sliding window method for reliable and sequential delivery of data frames. It is a case of
sliding window protocol having to send window size of N and receiving window size of 1.
Go – Back – N ARQ provides for sending multiple frames before receiving the acknowledgment for
the first frame. The frames are sequentially numbered and a finite number of frames. The maximum
number of frames that can be sent depends upon the size of the sending window. If the
acknowledgment of a frame is not received within an agreed upon time period, all frames starting
from that frame are retransmitted

#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);

CMREC, III –I,CSE Page 20


sent++;
if(sent == windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received before timer
epires\n");
scanf("%d",&ack);

if(ack == windowsize)
break;
else
sent = ack;
}
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.
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

CMREC, III –I,CSE Page 21


EXPERIMENT NO: 4

NAME OF THE EXPERIMENT: Shortest Path.


AIM: Implement Dijkstra‘s algorithm to compute the Shortest path through a given graph.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.


THEORY:
ALGORITHM/FLOWCHART:
Begin
Step1: Declare array path [5] [5], min, a [5][5], index, t[5];
Step2: Declare and initialize st=1,ed=5
Step 3: Declare variables i, j, stp, p, edp
Step 4: print “enter the cost “
Step 5: i=1
Step 6: Repeat step (7 to 11) until (i<=5)
Step 7: j=1
Step 8: repeat step (9 to 10) until (j<=5)
Step 9: Read a[i] [j]
Step 10: increment j
Step 11: increment i

CMREC, III –I,CSE Page 22


Step 12: print “Enter the path”
Step 13: read p
Step 14: print “Enter possible paths”
Step 15: i=1
Step 16: repeat step(17 to 21) until (i<=p)
Step 17: j=1
Step 18: repeat step(19 to 20) until (i<=5)
Step 19: read path[i][j]
Step 20: increment j
Step 21: increment i
Step 22: j=1
Step 23: repeat step(24 to 34) until(i<=p)
Step 24: t[i]=0
Step 25: stp=st
Step 26: j=1
Step 27: repeat step(26 to 34) until(j<=5)
Step 28: edp=path[i][j+1]
Step 29: t[i]= [ti]+a[stp][edp]
Step 30: if (edp==ed) then
Step 31: break;
Step 32: else
Step 33: stp=edp
Step 34: end if
Step 35: min=t[st]
Step 36: index=st
Step 37: repeat step( 38 to 41) until (i<=p)
Step 38: min>t[i]
Step 39: min=t[i]
Step 40: index=i
Step 41: end if
Step 42: print” minimum cost” min

CMREC, III –I,CSE Page 23


Step 43: print” minimum cost pth”
Step 44: repeat step(45 to 48) until (i<=5)
Step 45: print path[index][i]
Step 46: if(path[idex][i]==ed) then
Step 47: break
Step 48: end if
End
CREATE THE PROGRAM NAME
[m0033@agni cnlabprograms]$ vi exp3.c

SOURCE CODE:
//*********************************
//PROGRAM FOR FINDING SHORTEST //PATH FOR A GIVEN GRAPH
//*********************************
#include<stdio.h>
void main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
printf("enter the cost matrix\n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&a[i][j]);
printf("enter the paths\n");
scanf("%d",&p);
printf("enter possible paths\n");
for(i=1;i<=p;i++)
for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
{
t[i]=0;
stp=st;

CMREC, III –I,CSE Page 24


for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
}
min=t[st];index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}
}
COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp3.c

CMREC, III –I,CSE Page 25


OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

enter the cost matrix

01420

10370

43050

27506

00060

Enter the paths: 4

Enter possible paths

12345

12450

13450

14500

Minimum cost 8

Minimum cost path --> 1--> 4--> 5

CMREC, III –I,CSE Page 26


EXPERIMENT NO: 5

NAME OF THE EXPERIMENT: Broadcast Tree.

AIM: Implement broadcast tree for a given subnet of hosts

Fig: Broadcast Tree

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
This technique is widely used because it is simple and easy to understand. The idea of this algorithm
is to build a graph of the subnet with each node of the graph representing a router and

each arc of the graph representing a communication line. To choose a route between a given pair of
routers the algorithm just finds the broadcast between them on the graph.

CMREC, III –I,CSE Page 27


ALGORITHM/FLOWCHART:
step 1: declare variable as int p,q,u,v,n;
step 2: Initialize min=99,mincost=0;
step 3: declare variable as int t[50][2],i,j;
step 4: declare variable as int parent[50],edge[50][50];
step 5: Begin
step 6: write "Enter the number of nodes"
step 7: read "n"
step 8: Initialize i=0
step 9: repeat step(10-12) until i<n
step10: increment i
step11: write"65+i"
step12: Initialize parent[i]=-1
step13:wite "\n"
step14: Initialize i=0
step15: repeat step(15-21) until i<n
step16: increment i
step17: write"65+i"
step18: Initialize j=0
step19: repeat until j<n
step20: increment j
step21: read edge[i][j]
step22: Initialize i=0
step23: repeat step(23-43) until i<n
step24: increment i
step25: Initialize j=0
step26: repeat until j<n
step27: increment j
step28: if'edge[i]j]!=99
step29: if'min>edge[i][j] repeat step (29-32)
step30: intialize min=edge[i][j]

CMREC, III –I,CSE Page 28


step31: intialize u=i
step32: intialize v=j
step33: calling function p=find(u);
step34: calling function q=find(v);
step35: if'P!=q repeat steps(35-39)
step36: intialize t[i][0]=u
step37: intialize t[i][1]=v
step38: initialize mincost=mincost+edge[u][v]
step39: call function sunion(p,q)
step40: else repeat steps(40-42)
step41: Intialize t[i][0]=-1;
step42: Intialize t[i][1]=-1;
step43: intialize min=99;
step44; write"Minimum cost is %d\n Minimum spanning tree is",mincost
step45: Initialize i=0
step46: repeat until i<n
step47: increment i
step48: if't[i][0]!=-1 && t[i][1]!=-1'repeat step(48-50)
step49: write "%c %c %d", 65+t[i][0], 65+t[i][1], edge[t[i][0]][t[i][1]]
step50: write"\n"
step51: end
step52: called function sunion(int l,int m) repeat step(51-52)
step53: intialize parent[l]=m
step54: called function find(int l) repeat step(53-56)
step55: if parent([l]>0)
step56: initialize l=parent
step57: return l

COMPILE THE PROGRAM NAME


[m0033@agni cnlabprograms]$ vi exp5.c

CMREC, III –I,CSE Page 29


SOURCE CODE:
// Write a ‘c’ program for Broadcast tree from subnet of host
#include<stdio.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()
{
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;

CMREC, III –I,CSE Page 30


v=j;
}
p=find(u);
q=find(v);
if(p!=q)
{
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");
}
}
sunion(int l,int m)
{
parent[l]=m;
}
find(int l)

CMREC, III –I,CSE Page 31


{
if(parent[l]>0)
l=parent[l];
return l;
}
COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp5.c
OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

Enter the number of nodes 4

A B C D

A 1 3 5 6

B 6 7 8 9

C 2 3 5 6

D 1 2 3 7

Minimum cost is 9

Minimum spanning tree is

BA6

CA2

DA1

CMREC, III –I,CSE Page 32


EXPERIMENT NO: 6

NAME OF THE EXPERIMENT: Distance Vector routing.

AIM: Obtain Routing table at each node using distance vector routing algorithm for a given subnet.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
Distance Vector Routing Algorithms calculate a best route to reach a destination based solely on
distance. E.g. RIP. RIP calculates the reach ability based on hop count. It’s different from link state
algorithms which consider some other factors like bandwidth and other metrics to reach a destination.
Distance vector routing algorithms are not preferable for complex networks and take longer to
converge.

CMREC, III –I,CSE Page 33


ALGORITHM/FLOWCHART:
Begin
Step1: Create struct node unsigned dist[20],unsigned from[20],rt[10]
Step2: initialize int dmat[20][20], n,i,j,k,count=0,
Step3: write "the number of nodes "
Step4: read the number of nodes "n"
Step5: write" the cost matrix :"
Step6: intialize i=0
Step7: repeat until i<n
Step8: increment i
Step9: initialize j=0
Step10: repeat Step(10-16)until j<n
Step11: increment j
Step12:read dmat[i][j]
Step13:intialize dmat[i][j]=0
Step14:intialize rt[i].dist[j]=dmat[i][j]
Step15:intialize rt[i].from[j]=j
Step16:end
Step17:start do loop Step (17-33)until
Step18:intilialize count =0
Step19:initialize i=0
Step20:repeat until i<n
Step21:increment i
Step22:initialize j=0
Step23:repeat until j<n
Step24:increment j
Step25:initialize k=0
Step26:repeat until k<n
Step27:increment k
Step28:if repeat Step(28-32) until rt[i].dist[j]>dmat[i][k]+rt[k].dist[j]
Step29:intialize rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]

CMREC, III –I,CSE Page 34


Step30:intialize rt[i].from[j]=k;
Step31:increment count
Step32:end if
Step33:end do stmt
Step34:while (count!=0)
Step35:initialize i=0
Step36:repeat Steps(36-44)until i<n
Step37:increment i
Step38:write ' state values for router',i+1
Step39:initialize j=0
Step40:repeat Steps ( 40-43)until j<n
Step41:increment j
Step42:write 'node %d via %d distance % ',j+1,rt[i].from[j]+1,rt[i].dist[j]
Step43:end
Step44:end
End

CREATE THE PROGRAM NAME


[m0033@agni cnlabprograms]$ vi exp4.c

CMREC, III –I,CSE Page 35


SOURCE CODE:
#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];

CMREC, III –I,CSE Page 36


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");
}
COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp4.c

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

Enter the number of nodes : 3

Enter the cost matrix :

024

204

450

State value for router 1 is

node 1 via 1 Distance0

node 2 via 2 Distance2

node 3 via 3 Distance4

State value for router 2 is

CMREC, III –I,CSE Page 37


node 1 via 1 Distance2

node 2 via 2 Distance0

node 3 via 3 Distance4

State value for router 3 is

node 1 via 1 Distance4

node 2 via 2 Distance5

node 3 via 3 Distance0

CMREC, III –I,CSE Page 38


EXPERIMENT NO: 7

NAME OF THE EXPERIMENT: RSA.


AIM: Using RSA algorithm encrypt a text data and Decrypt the same.
HARDWARE REQUIREMENTS: Intel based Desktop PC:-RAM of 512 MB
SOFTWARE REQUIREMENTS: Turbo C / Borland C.
THEORY:
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
ALGORITHM/FLOWCHART:
Step1: Start
Step2: Initialize variables as int a,b,i,j,t,x,n,k=0,flag=0,prime[100]
Step3: Initialize variables as char m[20],pp[20]
Step4: Initialize variables as float p[20],c[20]
Step5: Initialize variables as double e,d;
Step6: Initialize i=0
Step7: Repeat step(7-16) until i<50
Step8: Increment i
Step9: Initialize flag=0
Step10: Initialize j=2
Step11: Repeat until j<i/2
Step12: if ‘ i%j == 0 ’ repeat until(12-14)
Step13: Initialize flag=1
Step14: break
Step15: if ’ (flag==0) ‘
Step16: Initialize prime[k++]=i
Step17: Initialize a=prime[k-1]
Step18: Initialize b=prime[k-2]
Step19: Initialize n=a*b

CMREC, III –I,CSE Page 39


Step20: Initialize t=(a-1)*(b-1)
Step21: Initialize e=(double)prime[2]
Step22: Initialize d=1/(float)e
Step23: write "\nKey of encryption is:%lf\n",d
Step24: write"\nEnter plain the text:"
Step25: read m
Step26: Intialize x=strlen(m)
Step27: write"\nDecryption status From Source to Destination:\n"
Step28: write"\nSource\t->---------------------------------- <-destination\n"
Step29: write"\nChar\tnumeric\tcipher\t\tnumeric\t\tchar \n"
Step30: write"\n***********************************************************\n"
Step31: write"\n"
Step32: Intialize i=0
Step33: repeat steps(33-46) until i<x
Step34: Increment i
Step35: write "%c",m[i]
Step36: write"\t%d",m[i]-97
Step37; Intialize c[i]=pow(m[i]-97,(float)e)
Step38: Initialize c[i]=fmod(c[i],(float)n)
Step39: write "\t%f",c[i]
Step40: Intialize p[i]=pow(c[i],(float)d);
Step41: Intialize p[i]=fmod(p[i],(float)n);
Step42: write "\t%f",p[i]
Step43: Intialize pp[i]=p[i]+97
Step44: write "\t%c\n",pp[i]
Step45: write "\n***********************************************************\n"
Step46: write "\n"
Step 47 end
CREATE THE NAME OF THE PROGRAM
[m0033@agni cnlabprograms]$ vi exp8.c

CMREC, III –I,CSE Page 40


SOURCE CODE:
#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];

CMREC, III –I,CSE Page 41


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]);

CMREC, III –I,CSE Page 42


pp[i]=p[i]+97;

printf("\t%c\n",pp[i]);

printf("\n***********************************************************\n");

printf("\n");

}
}

COMPILE THE PROGRAM


[m0033@agni cnlabprograms]$ cc exp8.c -lm

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

Key of encryption is:0.500000

Enter plain the text:CSEB

Decryption status From Source to Destination:

Source-> --------------------------------------------------- <-destination

Char numeric cipher numeric char

***********************************************************
C -30 900.000000 30.000000 C
***********************************************************
S -14 196.000000 14.000000 S
***********************************************************
E -28 784.000000 28.000000 E
***********************************************************
B -31 961.000000 31.000000 B
**********************************************************

CMREC, III –I,CSE Page 43


EXPERIMENT NO: 8
NAME OF THE EXPERIMENT: Congestion Control.
AIM: Using Leaky Bucket algorithm.
HARDWARE REQUIREMENTS: Intel based Desktop PC:-RAM of 512 MB
SOFTWARE REQUIREMENTS: Turbo C / Borland C.
THEORY:
The leaky bucket algorithm controls the rate at which the packets are introduced in the network, but
it is very conservative in nature. Some flexibility is introduced in the token bucket algorithm. In the
token bucket, algorithm tokens are generated at each tick (up to a certain limit). For an incoming
packet to be transmitted, it must capture a token and the transmission takes place at the same rate.
Hence some of the busty packets are transmitted at the same rate if tokens are available and thus
introduces some amount of flexibility in the system.
PROGRAM:
//#include<iostream.h>
//#include<dos.h>
#include<stdio.h>
#include<stdlib.h>
#define bucketSize 512
//void randomize();
//int random(int);
//delay(int);
void bktInput(int a,int b);
void bktInput(int a,int b) {
if(a>bucketSize)
printf("\n\t\tBucket overflow");
else {
delay(500);
while(a>b){
printf("\n\t\t %d bytes outputted.", b );
a-=b;
delay(500);

CMREC, III –I,CSE Page 44


}
if (a>0) printf("\n\t\tLast %d bytes sent" ,a);
printf("\n\t\tBucket output successful");
}
}
void main() {
int i, op, pktSize;
//randomize();
printf("Enter output rate : "); scanf("%d",&op);
for( i=1;i<=5;i++){
delay(random(1000));
pktSize=random(1000);
printf("\nPacket no %d", i);
printf("tPacket size = %d",pktSize);
bktInput(pktSize,op);
}
}
OUTPUT:
Enter output rate : 100
Packet no 0 Packet size = 3
Bucket output successful
Last 3 bytes sent
Packet no 1 Packet size = 33
Bucket output successful
Last 33 bytes sent
Packet no 2 Packet size = 117
Bucket output successful
100 bytes outputted.
Last 17 bytes sent
Packet no 3 Packet size = 95
Bucket output successful
Last 95 bytes sent
Packet no 4 Packet size = 949
Bucket overflow

CMREC, III –I,CSE Page 45


EXPERIMENT NO: 9
NAME OF THE EXPERIMENT: Frame sorting techniques
AIM: Using buffers.
HARDWARE REQUIREMENTS: Intel based Desktop PC:-RAM of 512 MB
SOFTWARE REQUIREMENTS: Turbo C / Borland C.
THEORY:
The data link layer divides the stream of bits received from the network layer into manageable data units called
frames. If frames are to be distributed to different systems on the network, the Data link layer adds a header to
the frame to define the sender and/or receiver of the frame. Each Data link layer has its own frame format. One
of the fields defined in the format is the maximum size of the data field. In other words, when datagram is
encapsulated in a frame, the total size of the datagram must be less than this maximum size, which is defined
by restriction imposed by the hardware and software used in the network.

IP Datagram

Header MTU Trailer

The value of MTU differs from one physical network to another in order to make IP protocol
portable/independent of the physical network, the packagers decided to make the maximum length of the IP
datagram equal to the largest Maximum Transfer Unit (MTU) defined so far. However for other physical
networks we must divide the datagrams to make it possible to pass through these networks. This is called
fragmentation. When a datagram is fragmented, each fragmented has its own header. A fragmented datagram
may itself be fragmented if it encounters a network with an even smaller MTU. In another words, a datagram
may be fragmented several times before it reached the final destination and also, the datagrams referred to as
(frames in Data link layer) may arrives out of order at destination. Hence sorting of frames need to be done at
the destination to recover the original data.
PROGRAM:
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define FSize 3
typedef struct packet{int SeqNum; char Data[FSize+1];}packet;
struct packet *readdata, *transdata;
int divide(char *msg) {
int msglen, NoOfPacket, i, j;
msglen = strlen(msg);
NoOfPacket = msglen/FSize;

CMREC, III –I,CSE Page 46


if ((msglen%FSize)!=0) NoOfPacket++;
readdata = (struct packet *)malloc(sizeof(packet) * NoOfPacket);
for(i = 0; i < NoOfPacket; i++) {
readdata[i].SeqNum = i + 1;
for (j = 0; (j < FSize) && (*msg != '\0'); j++, msg++)
readdata[i].Data[j] = *msg;
readdata[i].Data[j] = '\0';
}
printf("\nThe Message has been divided as follows\n");
printf("\nPacket No. Data\n\n");
for (i = 0; i < NoOfPacket; i++)
printf(" %2d %s\n", readdata[i].SeqNum,
readdata[i].Data);
return NoOfPacket;
}
void shuffle(int NoOfPacket) {
int *Status;
int i, j, trans;
randomize();
Status=(int * )calloc(NoOfPacket, sizeof(int));
transdata = (struct packet *)malloc(sizeof(packet) * NoOfPacket);
for (i = 0; i < NoOfPacket;) {
trans = rand()%NoOfPacket;
if (Status[trans]!=1) {
transdata[i].SeqNum = readdata[trans].SeqNum;
strcpy(transdata[i].Data, readdata[trans].Data);
i++; Status[trans] = 1;
}
}
free(Status);
}
void sortframes(int NoOfPacket) {
packet temp;
int i, j;
for (i = 0; i < NoOfPacket; i++)
for (i = 0; i < NoOfPacket; i++)
for (j = 0; j < NoOfPacket – i-1; j++)

if (transdata[j].SeqNum > transdata[j + 1].SeqNum) {


temp.SeqNum = transdata[j].SeqNum;
strcpy(temp.Data, transdata[j].Data);
transdata[j].SeqNum = transdata[j + 1].SeqNum;
strcpy(transdata[j].Data, transdata[j + 1].Data);
transdata[j + 1].SeqNum = temp.SeqNum;
strcpy(transdata[j + 1].Data, temp.Data);
}
}
void receive(int NoOfPacket) {
CMREC, III –I,CSE Page 47
int i;
printf("\nPackets received in the following order\n");
for (i = 0; i < NoOfPacket; i++) printf("%4d", transdata[i].SeqNum);
sortframes(NoOfPacket);
printf("\n\nPackets in order after sorting..\n");
for (i = 0; i < NoOfPacket; i++) printf("%4d", transdata[i].SeqNum);
printf("\n\nMessage received is :\n");
for (i = 0; i < NoOfPacket; i++) printf("%s", transdata[i].Data);
}
void main() {
char *msg;
int NoOfPacket;
clrscr();
printf("\nEnter The message to be Transmitted :\n");
scanf("%[^\n]", msg);
NoOfPacket = divide(msg);
shuffle(NoOfPacket);
receive(NoOfPacket);
free(readdata);
free(transdata);
getch();
}
OUTPUT:
Enter The messgae to be Transmitted :
hi, it was nice meeting u on sunday
The Message has been divided as follows
Packet No. Data
1 hi,
2 it
3 wa
4 sn
5 ice
6 me
7 eti
8 ng
9 uo
10 n s
11 und
12 ay
Packets received in the following order
4 2 6 3 5 1 8 9 11 7 12 10
Packets in order after sorting..
1 2 3 4 5 6 7 8 9 10 11 12
Message received is :
hi, it was nice meeting u on Sunday

CMREC, III –I,CSE Page 48


EXPERIMENT NO: 10

NAME OF THE EXPERIMENT: Wireshark


AIM: Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters Viewing CapturedTraffic
v. Analysis and Statistics & Filters.
THEORY:
(Wireshark-win64-3.4.3)

Wireshark is a network packet analyzer. A network packet analyzer presents captured packet data in as
much detail as possible.

You could think of a network packet analyzer as a measuring device for examining what’s happening
inside a network cable, just like an electrician uses a voltmeter for examining what’s happening inside an
electric cable (but at a higher level, of course).

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

i) packet capture using wireshark. click capture:

CMREC, III –I,CSE Page 49


Click the red “Stop” button near the top left corner of the window when you want to stop capturing traffic

ii) starting wire shark


After downloading and installing Wireshark, you can launch it and double-click the name of a network interface
under Capture to start capturing packets on that interface(wifi or Ethernet or LAN)

CMREC, III –I,CSE Page 50


iii)Viewing captired Traffic

View > Coloring Rules.

CMREC, III –I,CSE Page 51


You can also save your own captures in Wireshark and open them later. Click File > Save to save your captured
packets.

iv. Analysis and Statistics and Filters

Apply a filter 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.

To analyze traffic,
click Analyze > Display Filters to choose a filter from among the default filters included inWireshark.

CMREC, III –I,CSE Page 52


CMREC, III –I,CSE Page 53
v) To find Statistics:

Goto to statistics and select Protocol(DHCP, UDP Multicast)

CMREC, III –I,CSE Page 54


EXPERIMENT NO: 11

NAME OF THE EXPERIMENT: Nmap Scan


AIM: How to run Nmap Scan

THEORY:

Nmap, short for Network Mapper, is a free, open-source tool for vulnerability scanning and
network discovery. Network administrators use Nmap to identify what devices are running on
their systems, discovering hosts that are available and the services they offer, finding open ports
and detecting security risks
i) how to run nmap scan
To get started, download and install Nmap from the nmap.org website and then launch a command
prompt. Typing nmap [hostname] or nmap [ip_address] will initiate a default scan.

CMREC, III –I,CSE Page 55


EXPERIMENT NO: 12

NAME OF THE EXPERIMENT: Operating system detection using NMAP

AIM: Operating system detection using NMAP

THEORY:

To detect OS use the command: Goto Command Prompt, type namp,


type: Nmap -sV -O -v IP address(172.16.27.26)

CMREC, III –I,CSE Page 56


EXPERIMENT NO: 13
NAME OF THE EXPERIMENT: NS2 Simulator

AIM: Do the following using NS2 Simulator


i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate& Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to Transmission of Packets

Description:

NS2 Simulator-Introduction
1. NS2 stands for Network Simulator Version
2. It is an open-source event-driven simulator designedspecifically for research in computer
communication networks.

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. Uses TCL as its scripting language.

Network simulation is an important tool in developing, testing and evaluating network protocols.
Simulation can be used without the target physical hardware, making it economical and practical for almost
any scale of network topology and setup.

GETTING STARTED

Setting up the environment


A user using the NCTUns in single machine mode, needs to do the following steps beforehe/she
starts the GUI program:
1. Set up environment variables:
Before the user can run up the dispatcher, coordinator, or NCTUns GUI programhe/she must
set up the NCTUNSHOME environment variable.
2. Start up the dispatcher on terminal 1.

CMREC, III –I,CSE Page 57


3. Start up the coordinator on terminal 2.
4. Start up the nctunsclient on terminal 3.

CMREC, III –I,CSE Page 58


After the above steps are followed, the starting screen of NCTUns disappears and the user is presented
with the working window as shown below:

ii) Simulate a three node point to point network with a duplex link between them. Set the queue
size and vary the bandwidth and find the number of packets dropped.

Step1: Drawing topology


1. Select/click the HOST icon on the toolbar and click the left mouse button on the editor,to place a
HOST1 on the editor.
Repeat the above procedure and place another host “HOST2” on the editor.
2. Select/click the HUB icon on the toolbar and click the left mouse button on the editor,to place
HUB1 on the editor.
3. Click on the LINK icon on the toolbar and connect HOST1 to HUB1 and HUB1 toHOST2
4. Click on the “E” icon on the toolbar to save the current topology
e.g: file1.tpl
(Look for the ******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting the “E” icon.
CMREC, III –I,CSE Page 59
Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOSTwindow.
2. Select Add button on the HOST window to invoke the command window andprovide
the following command in the command textbox.
stg –u 1024 100 1.0.1.2
3. Click OK button on the command window to exit and once again click on the OK button
on the HOST window to exit.
4. Double click the left mouse button while cursor is on HOST2 to open the HOSTwindow.
5. Select Add button on the HOST window to invoke the command window andprovide
the following command in the command textbox.
rtg –u –w log1
6. Click OK button on the command window to exit.
7. Click NODE EDITOR Button on the HOST window and select the MAC tab from themodal
window that pops up.
8. Select LOG STATISTICS and select checkboxes for Number of Drop Packetand
Number of Collisions in the MAC window
9. Click OK button on the MAC window to exit and once again click on the OK buttonon the
HOST window to exit.
Note: To set QUEUE size
1. Double click the left mouse button while cursor is on HOST2 to open the HOSTwindow.
2. Click NODE EDITOR Button on the HOST window and select the FIFO tab from the modal
window that pops up.
3. Change Queue size (Default 50).
4. Click OK button on the FIFO window to exit and once again click on the OK button on the
HOST window to exit.
Step3: Simulate
i. Click “R” icon on the tool bar
ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to
execute the simulation.
iii. venTo start playback select “►” icon located at the bottom right corner of the
editor.
iv. To view results, Open up new TERMINAL window, move to file1.results folder
and open collision and drop log files in separate TERMINAL window.
Changing configurations
Change 1
1. Open the above file,
2. Do not change the topology or any other configuration,
3. Select E icon on the toolbar
4. Reduce the bandwidth at link2 by double clicking the left mouse button while cursor is on
link2 .(Change bandwidth on both tabs Uplink/Downlink)
5. Repeat Step3 (Simulate)

CMREC, III –I,CSE Page 60


Change 2
1. Open the above file,
2. Remove HUB and replace it with SWITCH.
3. Do not change anything in the configuration
4. Repeat Step3(Simulate)

iii) Simulate a four node point to point network and connect the link as follows Apply a TCP agent
between n0 to n3 and apply a UDP agent between n1 and n3.Apply relevant applications over TCP and
UDP agents changing the parameters and determine the number of packets sent by two agents.

Step1: Drawing topology

1. Select/click the HOST icon on the toolbar and click the left mouse button on the editor,to place a
host on the editor.
Repeat the above procedure and place two other hosts “HOST2” and “HOST3” on the
editor.
2. Select/click the HUB (or SWITCH) icon on the toolbar and click the left mouse button
on the editor, to place a HUB (or SWITCH) on the editor.
3. Click on the LINK icon on the toolbar and connect HOST1 to HUB, HOST2 to HUB and
HUB to HOST3
4. Click on the “E” icon on the toolbar to save the current topology e.g: file2.tpl (Look
for the ******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting the “E” icon.

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOSTwindow.
2. Change simulation time from 0 to 20 for HOST1
3. Select Add button on the HOST1 window to invoke the command window andprovide
the following command in the command textbox.
ttcp –t –u –s –p 8000 1.0.1.3
4. Click OK button on the command window to exit

CMREC, III –I,CSE Page 61


5. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.
6. Select LOG STATISTICS and select checkbox for output throughput in the MACwindow
7. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.
8. Double click the left mouse button while cursor is on HOST2 to open the HOSTwindow.
9. Change simulation time from 21 to 40 for HOST2
10. Select Add button on the HOST2 window to invoke the command window andprovide
the following command in the command textbox.

stg –u 1024 100 1.0.1.3


11. Click OK button on the command window to exit
12. Click NODE EDITOR Button on the HOST window and select the MAC tab from the
modal window that pops up.
13. Select LOG STATISTICS and select checkbox for output throughput in the MACwindow
14. Click OK button on the MAC window to exit and once again click on the OK button
on the HOST window to exit.
15. Double click the left mouse button while cursor is on HOST3 to open the HOSTwindow.
16. Change simulation time from 0 to 20 for HOST3
17. Select Add button on the HOST window to invoke the command window and provide
the following command in the command textbox.
ttcp –r –u –s –p 8000
18. Click OK button on the command window to exit.
19. Change simulation time from 21 to 40 for HOST3
20. Also add the following command on HOST3 rtg –u –
w log1
21. Click NODE EDITOR Button on the HOST window and select the MAC tab from the
modal window that pops up.
22. Select LOG STATISTICS and select checkbox for input and output
throughput in the MAC window
23. Click OK button on the MAC window to exit and once again click on the OK button
on the HOST window to exit.

Step3: Simulate
i. Click “R” icon on the tool bar
ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to
execute the simulation.
iii. To start playback select “►” icon located at the bottom right corner of the editor.
iv. To view results, Open up new TERMINAL window, move to file2.results folder
and open input and output throughput log files in separate TERMINAL window.

iv)Simulate the transmission of ping messages over a network topology consisting of 6 nodes
and find the number of packets dropped due to congestion.

CMREC, III –I,CSE Page 62


Step1: Drawing topology

1. Select/click the SUBNET icon on the toolbar and click the left mouse button on theeditor, to
place a SUBNET on the editor.
2. A pop up window appears requesting the number of nodes and radius for the subnet
Set number of nodes=6;
Set radius of subnet >150

3. Click on the “E” icon on the toolbar to save the current topology e.g: file4.tpl (Look
for the ******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting the “E” icon.

Step2: Configuration
1. Make 5 HOST as sender and make 1 HOST as receiver and give the commands with
particular portnumber
2. Sender Commands
Sender 1 : stcp –p 21 –l 1024 1.0.1.1
Sender 2 : stcp –p 22 –l 1024 1.0.1.1
Sender 3 : stcp –p 23 –l 1024 1.0.1.1
Sender 4 : stcp –p 24 –l 1024 1.0.1.1
Sender 5 : stcp –p 25 –l 1024 1.0.1.1
Receiver Commands
rtcp –p 21 –l 1024
rtcp –p 22 –l 1024
rtcp –p 23 –l 1024
rtcp –p 24 –l 1024

CMREC, III –I,CSE Page 63


rtcp –p 25 –l 1024
3. For each sender HOST select the Outthroughput, Collision and Drop packets.
4. For receiver HOST select the Inthroughtput, Collision and Drop packets.

Step3: Simulate
i. Click “R” icon on the tool bar
ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to
execute the simulation.
iii. During simulation, double click the mouse button on any sender HOST, the HOST
window pops up, select / click on command console button located at the bottom.
iv. A terminal window appears, type ping IP address of a receiver HOST in the subnet at the
command prompt.
v. To view results, Open up new TERMINAL window, move to file4.results folder and open
drop and collision log files in separate TERMINAL window.

v) Simulate an ETHERNET LAN using n nodes (6-10), change error rate and data
rate and compare throughput.

Step1: Drawing topology

1. Select/click the HOST icon on the toolbar and click the left mousebutton
on the editor, to place HOST1 on the editor.
i. Repeat the above procedure and place 5 other hosts
“HOST2”, “HOST3”, “HOST4”, “HOST5”, and
“HOST6”on the editor.
2. Select/click the HUB icon on the toolbar and click the left mouse
button on the editor, to place HUB1 on the editor.
Repeat the above procedure and place another host “HUB2” on theeditor
3. Click on the LINK icon on the toolbar and connect HOST1,
HOST2 and HOST3 to HUB1, HOST4, HOST5 and HOST6 to
HUB2.
4. Select/click the SWITCH icon on the toolbar and click the left mouse
button on the editor, to place SWITCH1 on the editor.
5. Click on the LINK icon on the toolbar and connect HUB1 to
SWITCH1 and HUB2 to SWITCH1.
CMREC, III –I,CSE Page 64
6. Click on the “E” icon on the toolbar to save the current
topology e.g: file5.tpl
(Look for the ******.tpl extension.)

NOTE: Changes cannot / (should not) be done after


selecting the “E” icon.

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to
open the HOST window.
2. Select Add button on the HOST window to invoke the command
window and provide the following command in the command
textbox.
ttcp –t –u –s –p 8001 1.0.1.4 (Split time from 0 to 10)
3. Change error rate and data rate in the physical layer and select
Outthroughput in MAC layer
4. Click OK button on the command window to exit and once
again click on the OK button on the HOST window to exit.
5. Repeat this step at HOST 2 and HOST3 by changing port number & IP
address of receiver. Change error rate and data rate.
ttcp –t –u –s –p 8002 1.0.1.5 (Split time from 11 to 20)
ttcp –t –u –s –p 8003 1.0.1.6 (Split time from 21 to 30)
5. Double click the left mouse button while cursor is on HOST4 to
open the HOST window.
6. Select Add button on the HOST window to invoke the command
window and provide the following command in the command
textbox.
ttcp –r –u –s –p 8001(Split time from 0 to 10)
7. Change error rate and data rate in the physical layer and select
INthroughput in MAC layer
8. Repeat this step at HOST 5 and HOST6, but use different
commands. Change error rate and data rate.
ttcp –r –u –s –p 8002(Split time from 11 to 20) ttcp –r
–u –s –p 8003(Split time from 21 to 30)

Step3: Simulate
i. Click “R” icon on the tool bar
ii. Select Simulation in the menu bar and click/ select
RUN in the dropdown list to execute the simulation.
iii. To start playback select “►” icon located at the bottom right
corner of the editor. To view results, Open up new TERMINAL
window, move to file5.results folder and open output throughput
log files in separate TERMINALwindow.

CMREC, III –I,CSE Page 65


vi) Simulate an ETHERNET LAN using n nodes and set multiple traffic nodes
and plot congestion window for different source/destination.

Step1: Drawing topology

1. Select/click the HOST icon on the toolbar and click the left mouse button
on the editor, to place HOST1 on the editor.
i. Repeat the above procedure and place 3 other hosts
“HOST2”, “HOST3”, “HOST4”, “HOST5”, and
“HOST6”on the editor.
2. Select/click the HUB icon on the toolbar and click the left mouse button
on the editor, to place HUB1 on the editor.
Repeat the above procedure and place another host “HUB2” on the editor
3. Click on the LINK icon on the toolbar and connect HOST1, HOST2
and HOST3 to HUB1, HOST4, HOST5 and HOST6 to HUB2.
4. Select/click the SWITCH icon on the toolbar and click the left mousebutton
on the editor, to place SWITCH1 the editor.
5. Click on the LINK icon on the toolbar and connect HUB1 to SWITCH1
and HUB2 to SWITCH1.
6. Click on the “E” icon on the toolbar to save the current
topology e.g: file7.tpl (Look for the ******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selectingthe “E” icon.

Step2: Configuration

1. Double click the left mouse button while cursor is on HOST1 to open
the HOST window.
2. Select Add button on the HOST window to invoke the command
window and provide the following command in the command textbox.
ttcp –t –u –s –p 8001 1.0.1.4
3. Click OK button on the command window to exit and once again click
on the OK button on the HOST window to exit.
4. Repeat this step at HOST 2 and HOST3 by changing port number & IP
address of receiver. Change error rate and data rate.
ttcp –t –u –s –p 8002 1.0.1.5
ttcp –t –u –s –p 8003 1.0.1.6
CMREC, III –I,CSE Page 66
5. Select Outthroughput, Collision & Drop in MAC layer for all senders
6. Double click the left mouse button while cursor is on HOST4 to open
the HOST window.
7. Select Add button on the HOST window to invoke the command
window and provide the following command in the command textbox.
ttcp –r –u –s –p 8001
8. Repeat this step at HOST 5 and HOST6, but use different
commands. Change error rate and data rate.
ttcp –r –u –s –p 8002
ttcp –r –u –s –p 8003
9. select Inthroughput, Collision & Drop in MAC layer for all receivers

Step3: Simulate
i. Click “R” icon on the tool bar
ii. Select Simulation in the menu bar and click/ select RUN in the
dropdown list to execute the simulation.
iii. To start playback select “►” icon located at the bottom right corner of the
editor.
iv. To plot congestion window select Tools in the menu bar and selectPLOT
GRAPH in the drop down list.
v. In the Graph window, select File->OPEN, move to file7.results folder and
the drop and collision log file.
vi. To open another Graph window, Select File->New tab on the drop down
list to open up to a maximum of 6 windows
vii. To view results, Open up new TERMINAL window, move to file7.results
folder and open input and output throughput log files in separate
TERMINAL window.

vii) Simulate simple BSS and with transmitting nodes in wireless LAN by simulation
and determine the performance with respect to transmissionof packets.

Step1: Drawing topology

1. Select/click the HOST icon on the toolbar and click the left mouse button on the
editor, to place HOST1 on the editor.
2. Select/click the ROUTER icon on the toolbar and click the left mouse button on the
CMREC, III –I,CSE Page 67
editor, to place ROUTER1 on the editor.
3. Select/click the WIRELESS ACCESS POINT(802.11b) icon on the toolbar and
click the left mouse button on the editor, to place ACCESS POINT 1 onthe editor.
Repeat this procedure and place ACCESS POINT 2 on the editor.
4. Select/click the MOBILE NODE (infrastructure mode) icon on the toolbar and
click the left mouse button on the editor, to place MOBILE NODE 1 on the editor.
Repeat this procedure and place MOBILE NODE 2, MOBILE NODE3 and
MOBILE NODE 4 on the editor.
5. Click on the LINK icon on the toolbar and connect ACCESS POINT1 to
ROUTER1 and ACCESS POINT2 to ROUTER1
6. Click on the “Create a moving path” icon on the toolbar and draw moving path
across MOBILE NODE 1 and 2, Repeat for MOBILE NODE 3and 4 (Accept the
default speed value 10 and close the window, Click the right mouse button to
terminate the path).

To create Subnet
7. Select wireless subnet icon in the toolbar now select MOBILE NODE1, MOBILE
NODE2 and ACCESS POINT1 by clicking on left mouse button,and clicking right
mouse button will create a subnet.
8. Repeat the above step for MOBILE NODE3, MOBILE NODE4 and
ACCESS POINT2.
9. Click on the “E” icon on the toolbar to save the current topology e.g:
file8.tpl
(Look for the ******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting the “E” icon.

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOST
window.
2. Select Add button on the HOST window to invoke the command window and
provide the following command in the command textbox.
ttcp –r –u –s –p 8001
3. Click OK button on the command window to exit
4. Repeat this step and add the following commands at HOST1 ttcp
–r –u –s –p 8002
ttcp –r –u –s –p 8003 ttcp
–r –u –s –p 8004 ttcp –r
–u –s –p 8005
5. Click NODE EDITOR Button on the HOST1 window and select the MAC tab
from the modal window that pops up.
6. Select LOG STATISTICS and select checkbox for Input throughput in the MAC
window
7. Click OK button on the MAC window to exit and once again click on the OK
button on the HOST window to exit.
8. Double click the left mouse button while cursor is on MOBILE NODE 1 to open
the MOBILE NODE window.
CMREC, III –I,CSE Page 68
9. Select Application tab and select Add button to invoke the command
window and provide the following command in the command textbox.
ttcp –t –u –s –p 8001 1.0.2.2 (host’s ip address)
10. Click NODE EDITOR Button on the MOBILE NODE1 window and select
the MAC tab from the nodal window that pops up.
11. Select LOG STATISTICS and select checkbox for Output throughput in the
MAC window
12. Click OK button on the MAC window to exit and once again click onthe OK
button on the MOBILE NODE1 window to exit.
13. Repeat the above steps (step 8 to step12) for the MOBILE NODE2,3 and 4 and
add the following commands at
MOBILE NODE2:- ttcp –t –u –s –p 8002 1.0.2.2 MOBILE
NODE 3:- ttcp –t–u –s –p 8003 1.0.2.2 MOBILE NODE4:-
ttcp –t –u –s –p 8004 1.0.2.2
14. Double click the left mouse button while cursor is on ROTER1 to open the
ROUTER window.
15. Click NODE EDITOR Button on the ROUTER1 window and you can see three
stacks. two stacks for two ACCESS POINTS and another stack for HOST1
which is connected to the ROUTER1.
16. Select the MAC tab of ACCESS POINT1 and Select LOG STATISTICS and
select checkbox for Input throughput in the MAC window. Click OK button on
the MAC window to exit.
17. Select the MAC tab of ACCESS POINT2 and Select LOG STATISTICS and
select checkbox for Input throughput in the MAC window. Click OK button on
the MAC window to exit.
18. Select the MAC tab of HOST1 and Select LOG STATISTICS and select
checkbox for Output throughput in the MAC window. Click OK button on the
MAC window to exit.
19. Add the following command for router
ttcp –t –u –s –p 8005 1.0.2.2 (host’s ip address)

Step3: Simulate
I. Click “R” icon on the tool bar
II. Select Simulation in the menu bar and click/ select RUN in the
dropdown list to execute the simulation.
III. To start playback select “►” icon located at the bottom right corner of the
editor.
IV. MOBILE NODE’s start moving across the paths already drawn.

CMREC, III –I,CSE Page 69

You might also like