0% found this document useful (0 votes)
36 views78 pages

CN Master Manual

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

CN Master Manual

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

EXPERIMENT NO: 1

AIM: Implement the data link layer framing methods such as character and bit
stuffing.
Theory:

Purpose of Bit Stuffing

In Data Link layer, the stream of bits from the physical layer is divided into data frames. The
data frames can be of fixed length or variable length. In variable - length framing, the size of
each frame to be transmitted may be different. So, a pattern of bits is used as a delimiter to mark
the end of one frame and the beginning of the next frame. However, if the pattern occurs in the
message, then mechanisms needs to be incorporated so that this situation is avoided.

The two common approaches are −

● Byte - Stuffing − A byte or character is stuffed in the message to differentiate from the
delimiter for synchronization. This is also called character-oriented framing.
● Bit - Stuffing − Bit stuffing is the mechanism of inserting one or more non-information bits
into a message to be transmitted, to break up the message sequence, for synchronization
purpose.

In bit-oriented protocols, the message is coded as a sequence of bits, which are interpreted in the
upper layers as text, graphics, audio, video etc. A frame has the following parts −

● Frame Header − It contains the source and the destination addresses of the frame.
● Payload field − It contains the message to be delivered.
● Trailer − It contains the error detection and error correction bits.
● Flags − A bit pattern that defines the beginning and end bits in a frame. It is generally of 8-
bits. Most protocols use the 8-bit pattern 01111110 as flag.

COMPUTER NETWORKS MASTER MANUAL Page 1


Bit Stuffing Mechanism

In a data link frame, the delimiting flag sequence generally contains six or more consecutive 1s.
In order to differentiate the message from the flag in case of the same sequence, a single bit is
stuffed in the message. Whenever a 0 bit is followed by five consecutive 1bits in the message, an
extra 0 bit is stuffed at the end of the five 1s.

When the receiver receives the message, it removes the stuffed 0s after each sequence of five 1s.
The un-stuffed message is then sent to the upper layers.

COMPUTER NETWORKS MASTER MANUAL Page 2


Purpose of Byte Stuffing

In Data Link layer, the stream of bits from physical layer is divided into data frames. The data
frames can be of fixed length or variable length. In variable – length framing, the size of each
frame to be transmitted may be different. So, a pattern of bits is used as a delimiter to mark the
end of one frame and the beginning of the next frame. However, if the pattern occurs in the
message, then mechanisms needs to be incorporated so that this situation is avoided.

Frame in a Character – Oriented Framing

In character – oriented protocols, the message is coded as 8-bit characters, using codes like
ASCII codes.
COMPUTER NETWORKS MASTER MANUAL Page 3
A frame has the following parts −

● Frame Header − It contains the source and the destination addresses of the frame.
● Payload field − It contains the message to be delivered.
● Trailer − It contains the error detection and error correction bits.
● Flags − 1- byte (8-bits) flag at the beginning and at end of the frame. It is a protocol –
dependent special character, signalling the start and end of the frame.

Byte Stuffing Mechanism

If the pattern of the flag byte is present in the message byte, there should be a strategy so that the
receiver does not consider the pattern as the end of the frame. In character – oriented protocol,
the mechanism adopted is byte stuffing.

In byte stuffing, a special byte called the escape character (ESC) is stuffed before every byte in
the message with the same pattern as the flag byte. If the ESC sequence is found in the message
byte, then another ESC byte is stuffed before it.

COMPUTER NETWORKS MASTER MANUAL Page 4


Implement the data link layer farming methods such as character, character stuffing, and bit
stuffing.

Program:(bit-stuffing)

#include<stdio.h>
main()
{
int i,k,a,count=0;
char c[50];
printf("\nEnter the data to be send:");
fflush(stdin);
gets(c);
a=strlen(c);

COMPUTER NETWORKS MASTER MANUAL Page 5


for(i=0;i<a;i++)
{
if(c[i]=='1')
{
count++;
if(count==6)
{
for(k=a;k>i+1;k--)
c[k]=c[k-1];
a=a+1;
count=0;
c[i+1]='0';
}
}
else
count=0;
}
printf("\nData after stuffing:");
puts(c);
count=0;
for(i=0;i<a;i++)
{
if(c[i]=='1')
{
count++;
if(count==5)
{
for(k=i+1;k<a;k++)
c[k]=c[k+1];
count=0;
}
}
}
}

Output:

Enter the data to be send:11111111


Data after stuffing:111110111

COMPUTER NETWORKS MASTER MANUAL Page 6


Program:(character-stuffing)

#include<stdio.h>
main()
{
char a[50],b[50],c[50];
int i,j,k,m=0,count,l1,l2;
printf("\nEnter the data to send:");
fflush(stdin);
gets(a);
printf("\nEnter the delimeter:");
fflush(stdin);
gets(b);
l1=strlen(a);
l2=strlen(b);
c[0]='S';
for(i=0;i<l2;i++)
c[i+1]=b[i];
for(j=0;j<l1;j++)
{
count=0;
for(k=0,m=j;k<l2;k++,m++)
{
if(a[m]!=b[k])
count=1;
}
if(count==0)
{
for(k=l1+l2-1;k>m;k--)
a[k]=a[k-l2];
for(k=0;k<l2;k++)
a[m++]=b[k];
j=j+l2;
l1=l1+l2;
}
}
for(k=0;k<l1;k++)
c[++i]=a[k];
for(k=0;k<l2;k++)
c[++i]=b[k];
c[++i]='E';
printf("\nData after stuffing:");
for(k=0;k<=i;k++)
printf("%c",c[k]);
for(j=0;j<l1-l2;j++)
{
count=0;
m=j;
for(k=0;k<l2;k++)
{
if(a[m++]!=b[k])
count=1;
}
if(count==0)
{
for(k=m;k<l1-l2;k++)
a[k]=a[k+l2];
l1=l1-l2;
}
}
printf("\nData after destuffing:");
for(i=0;i<l1;i++)
printf("%c",a[i]);
}

Output:

Enter the data to send : hi hello hai


Enter the delimeter: l
Data after stuffing: slhi hellllo hai le
Data after destuffing: hi hello hai
EXPERIMENT NO: 2

AIM: Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC
CCIP

THEORY:

Cyclic redundancy check (CRC):


Error:
A condition when the receiver’s information does not matches with the sender’s
information. During transmission, digital signals suffer from noise that can introduce errors
in the binary bits travelling from sender to receiver. That means a 0 bit may change to 1 or a
1 bit may change to 0.
Error Detecting Codes (Implemented either at Data link layer or Transport Layer of
OSI Model):
Whenever a message is transmitted, it may get scrambled by noise or data may get
corrupted. To avoid this, we use error-detecting codes which are additional data added to a
given digital message to help us detect if any error has occurred during transmission of the
message.
Basic approach used for error detection is the use of redundancy bits, where additional bits are
added to facilitate detection of errors.

Cyclic redundancy check (CRC)


● Unlike checksum scheme, which is based on addition, CRC is based on binary
division.
● In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are
appended to the end of data unit so that the resulting data unit becomes exactly divisible
by a second, predetermined binary number.
● At the destination, the incoming data unit is divided by the same number. If at this step
there is no remainder, the data unit is assumed to be correct and is therefore accepted.
● A remainder indicates that the data unit has been damaged in transit and therefore must be
rejected.
EXAMPLE
ALGORITHM FOR CRC

BEGIN
step 1: declare i,j,keylen,mesglen and char arrays
input[100],temp[30],quot[100],rem[30],key[30],key1[30];
step 2: enter the data and scan the data into input[]
step 3: enter the key and scan the data into key[]
step 4: save the length of input in msglen and length of key in keylen
step 5: copy key[] to key1[]
step 6: initialize i=0 and repeat step 7 until i<keylen-1
step 7: input[msglen+i]=0 and inc i
step 8: initialize i=0 and repeat step 9 until i<keylen
step 9: temp[i]=input[i] and inc i
step 10: initialize i=0 and repeat step 11-22 until i<msglen
step 11: quot[i]=temp[0] and inc i
step 12: if quot[i] equal to 0 then goto step 13 else step 15
step 13: initialize j=0 and repeat step 14 until j<keylen and goto step 17
step 14: key[j]=0 and inc j
step 15: initialize j=0 and repeat step 16 until j<keylen
step 16: key[j]=key1[j] and inc j
step 17: initialize j=keylen-1 and repeat step 18-20 until j>0
step 18: if temp[j] equal to key[j] goto step 19 else step 20
step 19: rem[j-1]='0' and dec j and goto step 21
step 20: rem[j-1]='1' and dec j
step 21: rem[keylen-1]=input[i+keylen]
step 22: copy rem to temp[]
step 23: copy temp[] to rem[]
step 24: print the final data from input[] and rem[]
step 25: enter the frame and save in input
step 26: initialize j=0 and repeat step 27 until j<=msglen and then k=0
step 27: rem[j]=input[j] and inc j
step 28: initialize i=msglen and repeat step 29 until i<=keylen
step 29: if i>msglen then initialize j=0 and repeat step 30 until j<msglen
step 30: rem[j]=rem[j+1] and rem[j]=input[j] and inc j
step 31: if rem[0] then quot[k++]=1 else quot[k++]=0
step 32: initialize j=0 and repeat step 32 until j<=msglen
step 33: rem[j]=rem[j]^input[j]
step 34: print quotient and reminder
step 35: initialize i=1 repeat step 36 until i<=msglen
step 36: if rem[i] then flag=0
step 37: if flag is positive print "no error" else print "error"
END
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k=0;
int flag=1,a[16],g[16],r[20],div[16],n,m;
system(“clear”);
printf(“Enter degree of generator:”);
scanf(“%d”,&n);
printf(“\n Enter the generator:\n”);
for(i=0;i<=n;i++)
scanf(“%d”,&g[i]);
printf(“\nEnter the degree of the frame:”);
scanf(“%d”,&m);
printf(“Enter the frame:\n”);
for(i=0;i<=m;i++)
scanf(“%d”,&a[i]);
if(m<n || g[0]==0)
{
printf(“Not a proper generator:\n”);
exit(0);
}
for(i=m+1;i<=m+n;i++)
a[i]=0;
for(j=0;j<=n;j++)
r[j]=a[j];
for(i=n;i<=m+n;i++)
{
if(i>n)
{
for(j=0;j<n;j++)
r[j]=r[j+1];
r[j]=a[i];
}
if(r[0])
div[k++]=1;
else
{
div[k++]=0;
continue;
}
for(j=0;j<=n;j++)
r[j]=r[j]^g[j];
}
printf(“\n Quotient is:”);
for(j=0;j<k;j++)
printf(“%d”,div[j]);
printf(“\n Remainder is:”);
for(i=1;i<=n;i++)
printf(“%d”,r[i]);
printf(“\n Transmitted frame is:”);
for(i=m+1,j=1;i<=m+n;i++)
printf(“%d”,a[i]);
printf(“\n”);
printf(“\n Enter the degree of frame:”);
scanf(“%d”,&m);
printf(“Enter the frame:\n”);
for(i=0;i<=m;i++)
scanf(“%d”,&a[i]);
for(j=0;j<=n;j++)
r[j]=a[j];
k=0;
for(i=n;i<=m;i++)
{
if(i>n)
{
for(j=0;j<n;j++)
r[j]=r[j+1];
r[j]=a[i];
}
if(r[0])
div[k++]=1;
else
{
div[k++]=0;
continue;
}
for(j=0;j<=n;j++)
r[j]=r[j]^g[j];
}
printf(“\n Quotient is:”);
for(j=0;j<k;j++)
printf(“%d”,div[j]);
printf(“\n Remainder is:”);
for(i=1;i<=n;i++)
printf(“%d”,r[i]);
for(i=1;i<=n;i++)
{
if(r[i])
flag=0;
}
if(flag)
printf(“\n No Error \n”);
else
printf(“\n Error”);
return 0;
}

OUTPUT:
Enter the degree of the generator:3
Enter the generator:
1001
Enter the degree of the frame:7
Enter the frame :
1
1
1
1
1
1
1
1
Quotient is :11100011
Remainder is:011
Transmitted frame is:11111111011

Enter the degree of the frame:10


Enter the frame:
1
1
1
1
1
1
1
1
0
1
1
Quotient is:11100011
Remainder is:000
No Error

EXPERIMENT NO: 3
AIM: 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.
THEORY:

Sliding Window Protocol :

In computer networks sliding window protocol is a method to transmit data on a network. Sliding
window protocol is applied on the Data Link Layer of OSI model. 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.

Both sender and receiver agrees on some window size. 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. If receiver sends a collective or cumulative acknowledgement to sender then it
understands that more than one frames are properly received, for eg:- if ack of frame 3 is received it
understands that frame 1 and frame 2 are received properly.

Image Source

In sliding window protocol the receiver has to have some memory to compensate any loss in transmission
or if the frames are received unordered.

Efficiency of Sliding Window Protocol


η = (W*tx)/(tx+2tp)
W = Window Size

tx = Transmission time
tp = Propagation delay

Sliding window works in full duplex mode

It is of two types:-

1. Selective Repeat: Sender transmits only that frame which is erroneous or is lost.
2. Go back n: Sender transmits all frames present in the window that occurs after the error bit including
error bit also.

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;
}

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

EXPERIMENT NO: 4

AIM: Implement Dijsktra’s algorithm to compute the shortest path through a network

THEORY:

Dijkstra’s Algorithm (Theory):


Dijkstra's Algorithm allows you to calculate the shortest path between one node (you pick
which one) and every other node in the graph. You'll find a description of the algorithm at the
end of this page, but, let's study the algorithm with an explained example! Let's calculate the
shortest path between node C and the other nodes in our graph:

During the algorithm execution, we'll mark every node with its minimum distance to node C
(our selected node). For node C, this distance is 0. For the
rest of nodes, as we still don't know that minimum distance, it starts being infinity (∞):

We'll also have a current node. Initially, we set it to C (our selected node). In the image, we mark
the current node with a red dot.

Now, we check the neighbours of our current node (A, B and D) in no specific order. Let's begin
with B. We add the minimum distance of the current node (in this case, 0) with the weight of the
edge that connects our current node with B (in this case, 7), and we obtain 0 + 7 = 7. We compare
that value with the minimum distance of B (infinity); the lowest value is the one that remains as
the minimum distance of B (in this case, 7 is less than infinity):
So far, so good. Now, let's check neighbour A. We add 0 (the minimum distance of C, our
current node) with 1 (the weight of the edge connecting our current node with A) to obtain 1.
We compare that 1 with the minimum distance of A (infinity), and leave the smallest value:

OK. Repeat the same procedure for D:


Great. We have checked all the neighbours of C. Because of that, we mark it as visited.
Let's represent visited nodes with a green check mark:

We now need to pick a new current node. That node must be the unvisited node with the
smallest minimum distance (so, the node with the smallest number and no check mark). That's
A. Let's mark it with the red dot:
And now we repeat the algorithm. We check the neighbours of our current node, ignoring the
visited nodes. This means we only check B.

For B, we add 1 (the minimum distance of A, our current node) with 3 (the weight of the edge
connecting A and B) to obtain 4. We compare that 4 with the minimum distance of B (7) and
leave the smallest value: 4.

Afterwards, we mark A as visited and pick a new current node: D, which is the non-visited
node with the smallest current distance.
We repeat the algorithm again. This time, we check B and E.

For B, we obtain 2 + 5 = 7. We compare that value with B's minimum distance (4) and leave the
smallest value (4). For E, we obtain 2 + 7 = 9, compare it with the minimum distance of E
(infinity) and leave the smallest one (9).

We mark D as visited and set our current node to B.

Almost there. We only need to check E. 4 + 1 = 5, which is less than E's minimum distance (9),
so we leave the 5. Then, we mark B as visited and set E as the current node.
E doesn't have any non-visited neighbours, so we don't need to check anything. We mark it as
visited.

As there are not univisited nodes, we're done! The minimum distance of each node now
actually represents the minimum distance from that node to node C (the node we picked as
our initial node)!

Here's a description of the algorithm:

1. Mark your selected initial node with a current distance of 0 and the rest with infinity.
2. Set the non-visited node with the smallest current distance as the current node C.
3. For each neighbour N of your current node C: add the current distance of C with the weight of
the edge connecting C-N. If it's smaller than the current distance of N, set it as the new current
distance of N.
4. Mark the current node C as visited.
5. If there are non-visited nodes, go to step 2.

Program:
#include<stdio.h>
#include<stdlib.h>
//#include<string.h>
#define M_NODES 10
#define INFINITY 1000
int n,dis[M_NODES][M_NODES];
void main()
{
void spath(int,int);
int i,j,g[100][100],s,t,c; printf("\
nEnter number of nodes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
printf("\nEnter weight between %d-->%d\t",i,j);
scanf("%d",&c);
if(c>=0)
dis[i][j]=c;
else
exit(0);
}
}
printf("\nEnter source and destination nodes:");
scanf("%d%d",&t,&s);
spath(s,t);
//getch();
}
void spath(int s,int t)
{
struct state
{
int pre,len;
enum{permanet,tentative} label;
}state[M_NODES];
int i,k,min,path[20],c=0;

struct state *p;


for(p=&state[0];p<&state[n];p++)
{
p->pre=-1;
p->len=INFINITY;
p->label=tentative;
}
state[t].len=0;
state[t].label=permanet;
k=t;
do
{
for(i=0;i<n;i++)
if(dis[k][i]!=0&&state[i].label==tentative)
{
if(state[k].len+dis[k][i]<state[i].len)
{
state[i].pre=k;
state[i].len=state[k].len+dis[k][i];
}
}
k=0;
min=INFINITY;
for(i=0;i<n;i++)
{
if(state[i].label==tentative&&state[i].len<min )
{
min=state[i].len;
k=i;
}
}
state[k].label=permanet;
}while(k!=s);
i=0;
k=s;
do
{
path[i++]=k;
k=state[k].pre;
c++;
}while(k>=0);
printf("\nMinimum Cost is=%d",min);
printf("\nShortest path is=");
for(k=c-1;k>=0;k--)
printf("%d-->",path[k]);
}
Output:
EXPERIMENT NO: 5

AIM: Take an example subnet of hosts and obtain a broadcast tree for the subnet.

THEORY:

Given a connected and undirected graph, a spanning tree of that graph is a sub graph that is a tree
and connects all the vertices together. A single graph can have many different spanning
trees. A minimum spanning tree (MST) or minimum weight spanning tree for a weighted,
connected and undirected graph is a spanning tree with weight less than or equal to the weight of
every other spanning tree. The weight of a spanning tree is the sum of weights given to each
edge of the spanning tree.
A minimum spanning tree has (V – 1) edges where V is the number of vertices in the given
graph.

the steps for finding MST using Kruskal’s algorithm

1. Sort all the edges in non-decreasing order of their weight.


2. Pick the smallest edge. Check if it forms a cycle with the spanning tree formed
so far. If cycle is not formed, include this edge. Else, discard it.
3. Repeat step#2 until there are (V-1) edges in the spanning tree.
the steps for finding MST using Kruskal’s algorithm
1. Sort all the edges in non-decreasing order of their weight.
2. Pick the smallest edge. Check if it forms a cycle with the spanning tree formed
so far. If cycle is not formed, include this edge. Else, discard it.
3. Repeat step#2 until there are (V-1) edges in the spanning tree.
Now pick all edges one by one from sorted list of edges
1. Pick edge 7-6: No cycle is formed, include it.

2. Pick edge 8-2: No cycle is formed, include it.

3. Pick edge 6-5: No cycle is formed, include it.

4. Pick edge 0-1: No cycle is formed, include it.

5. Pick edge 2-5: No cycle is formed, include it.

6. Pick edge 8-6: Since including this edge results in cycle, discard it.
7. Pick edge 2-3: No cycle is formed, include it.

8. Pick edge 7-8: Since including this edge results in cycle, discard it.

9. Pick edge 0-7: No cycle is formed, include it.

10. Pick edge 1-2: Since including this edge results in cycle, discard it.
11. Pick edge 3-4: No cycle is formed, include it.

ALGORITHM

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

PROGRAM:

#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;
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)
{
if(parent[l]>0)
l=parent[l]; return
l;
}
OUTPUT
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 B A 6
CA2
DA1
EXPERIMENT NO: 6

AIM: Implement distance vector routing algorithm for obtaining routing tables at each node.

THEORY:

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("\nEnter the cost matrix :\

n"); for(i=0;i<n;i++)

for(j=0;j<n;j++)

{
scanf("%d",&dmat[i][j]);

dmat[i][i]=0;

rt[i].dist[j]=dmat[i][j];

rt[i].from[j]=j;

do

count=0;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

for(k=0;k<n;k++)

if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])

{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];

rt[i].from[j]=k;

count++;

}while(count!=0);

for(i=0;i<n;i++)

printf("\n\nState value for router %d is \n",i+1);

for(j=0;j<n;j++)
{

printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);

printf("\n\n");

OUTPUT CONSOLE:
Output (2):

Enter the number of nodes: 3


EXPERIMENT NO: 7

AIM: Implement data encryption and data decryption

THEORY:
The Data Encryption Standard (DES) is a symmetric-key block cipher published by the National
Institute of Standards and Technology (NIST).

DES is an implementation of a Feistel Cipher. It uses 16 round Feistel structure. The block size
is 64-bit. Though, key length is 64-bit, DES has an effective key length of 56 bits, since 8 of the
64 bits of the key are not used by the encryption algorithm (function as check bits only). General
Structure of DES is depicted in the following illustration −
Since DES is based on the Feistel Cipher, all that is required to specify DES is −
· Round function
· Key schedule
· Any additional processing − Initial and final permutation

Initial and Final Permutation

The initial and final permutations are straight Permutation boxes (P-boxes) that are inverses of
each other. They have no cryptography significance in DES. The initial and final permutations
are shown as follows −

Round Function

The heart of this cipher is the DES function, f. The DES function applies a 48-bit key to the
rightmost 32 bits to produce a 32-bit output.
Expansion Permutation Box − Since right input is 32-bit and round key is a 48-bit,· we first
need to expand right input to 48 bits. Permutation logic is graphically depicted in the
following illustration −

The graphically depicted permutation logic is generally described as table in DES· specification
illustrated as shown −
XOR (Whitener). − After the expansion permutation, DES does XOR operation on the
expanded right section and the round key. The round key is used only in this operation.
Substitution Boxes. − The S-boxes carry out the real mixing (confusion). DES uses· 8 S-
boxes, each with a 6-bit input and a 4-bit output. Refer the following illustration −

The S-box rule is illustrated below −


· There are a total of eight S-box tables. The output of all eight s-boxes is then· combined in
to 32 bit section.

· Straight Permutation − The 32 bit output of S-boxes is then subjected to the


straight· permutation with rule shown in the following illustration:

Key Generation
The round-key generator creates sixteen 48-bit keys out of a 56-bit cipher key. The process of
key generation is depicted in the following illustration −

The logic for Parity drop, shifting, and Compression P-box is given in the DES description.
DES Analysis

The DES satisfies both the desired properties of block cipher. These two properties make cipher
very strong.
· Avalanche effect − A small change in plaintext results in the very great change in
the ciphertext.
· Completeness − Each bit of ciphertext depends on many bits of plaintext.

ALGORITHM(DES):
Begin
Step 1: Declare integer i,ch,lp
Step 2: Declare character array’s cipher[50],plain[50] and character key
Step 3: while(TRUE) do step(4-31)
Step 4: write(“\n- - -MENU- - -\n”)
Step 5: write(“\n1:Data encryption\t\n2:Data Decryption\t\n\n:Exit”)
Step 6: write(“\n\nEnter your choice:”)
Step 7: scanf(“%d”,&ch);
Step 8: switch(ch) do
Step 9: case 1:
Step 10:write(“\nData Encryption”)
Step 11:write(“\nEnter plain text”)
Step 12:fflush(stdin);
Step 13:Input the string into plain to encrypt
Step 14:write(“\nEnter theencryption key:”)
Step 15:input the value into key
Step 16:load the length of the key into lp
Step 17:fori=0 to strlen(plain)-1 step do
Step 18:cipher[i]=plain[i]^lp;
Step 19:cipher[i]=’\0’;
Step 20:write(“\nEncrypted text is:”)
Step 21:puts(cipher)
Step 22:break;
Step 23:case 2:
Step 24:write(“\nDataDecryption”)
Step 25:fori=0 to strlen(plain)-1 step do
Step 26:plain[i]=cipher[i]^lp;
Step 27:write(“\nDecrypted text is:”)
Step 28:puts(cipher);
Step 29:break;
Step 30:case 3:
Step 31:exit(0);

Program:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
int i, ch, lp;
char cipher[50],plain[50];
char key[50];
while(1)
{
printf("\n-----MENU- - - -\n");
printf("\n1:Data Encryption\t\n\n2:Data Decryption\t\n\n3:Exit");
printf("\n\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nData Encryption");
printf("\nEnter the plain text:");
fflush(stdin);
scanf("%s",&plain);
printf("\nEnter the encryption key:");
scanf("%s",&key);
lp=strlen(key);
for(i=0;plain[i]!='\0';i++)
cipher[i]=plain[i]^lp

break;
cipher[i]='\0';
printf("\nThe encrypted text is:"); puts(cipher);
case 2: printf("\nData decryption");
for(i=0;cipher[i]!='\0';i++)
plain[i]=cipher[i]^lp;
printf("\nDecrypted text is:");
puts(plain);
break;
case 3: exit(0);
}
}
}
OUTPUT:
EXPERIMENT NO: 8

AIM: Write a program for congestion control using Leaky bucket algorithm.

THEORY:
The congesting control algorithms are basically divided into two groups: open loop and closed
loop. Open loop solutions attempt to solve the problem by good design, in essence, to make sure it does
not occur in the first place. Once the system is up and running, midcourse corrections are not made. Open
loop algorithms are further divided into ones that act at source versus ones that act at the destination.

In contrast, closed loop solutions are based on the concept of a feedback loop if there is any
congestion. Closed loop algorithms are also divided into two sub categories: explicit feedback and
implicit feedback. In explicit feedback algorithms, packets are sent back from the point of congestion to
warn the source. In implicit algorithm, the source deduces the existence of congestion by making local
observation, such as the time needed for acknowledgment to come back.

The presence of congestion means that the load is (temporarily) greater than the resources (in part
of the system) can handle. For subnets that use virtual circuits internally, these methods can be used at
the network layer.

Another open loop method to help manage congestion is forcing the packet to be transmitted at a
more predictable rate. This approach to congestion management is widely used in ATM networks and is
called traffic shaping.

The other method is the leaky bucket algorithm. Each host is connected to the network by an
interface containing a leaky bucket, that is, a finite internal queue. If a packet arrives at the queue when it
is full, the packet is discarded. In other words, if one or more process are already queued, the new packet
is unceremoniously discarded. This arrangement can be built into the hardware interface or simulate d by
the host operating system. In fact it is nothing other than a single server queuing system with constant
service time.

The host is allowed to put one packet per clock tick onto the network. This mechanism turns an
uneven flow of packet from the user process inside the host into an even flow of packet onto the network,
smoothing out bursts and greatly reducing the chances of congestion.
ALGORITHM/FLOWCHART:

Step 1: Start

Step 2: Set the bucket size or the buffer size.

Step 3: Set the output rate.

Step 4: Transmit the packets such that there is no overflow.

Step 5: Repeat the process of transmission until all packets are transmitted. (Reject packets where its size
is greater than the bucket size)

Step 6: Stop

SOURCE CODE:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

#define NOF_PACKETS 10

intrand(int a)
{
intrn = (random() % 10) % a;
returnrn == 0 ? 1 :rn;
}

intmain()
{
intpacket_sz[NOF_PACKETS], i, clk, b_size, o_rate, p_sz_rm=0, p_sz, p_time, op;
for(i = 0; i<NOF_PACKETS; ++i)
packet_sz[i] = rand(6) * 10;
for(i = 0; i<NOF_PACKETS; ++i)
printf("\npacket[%d]:%d bytes\t", i, packet_sz[i]);
printf("\nEnter the Output rate:");
scanf("%d", &o_rate);
printf("Enter the Bucket Size:");
scanf("%d", &b_size);
for(i = 0; i<NOF_PACKETS; ++i)
{
if( (packet_sz[i] + p_sz_rm) >b_size)
if(packet_sz[i] >b_size)/*compare the packet siz with bucket size*/
printf("\n\nIncoming packet size (%dbytes) is Greater than bucket capacity (%dbytes)-PACKET
REJECTED", packet_sz[i], b_size);
else
printf("\n\nBucket capacity exceeded-PACKETS REJECTED!!");
else
{
p_sz_rm += packet_sz[i];
printf("\n\nIncoming Packet size: %d", packet_sz[i]);
printf("\nBytes remaining to Transmit: %d", p_sz_rm);
p_time = rand(4) * 10;
printf("\nTime left for transmission: %d units", p_time);
for(clk = 10; clk<= p_time; clk += 10)
{
sleep(1);
if(p_sz_rm)
{
if(p_sz_rm<= o_rate)/*packet size remaining comparing with output rate*/
op = p_sz_rm, p_sz_rm = 0;
else
op = o_rate, p_sz_rm -= o_rate;
printf("\nPacket of size %d Transmitted", op);
printf("----Bytes Remaining to Transmit: %d", p_sz_rm);
}
else
{
printf("\nTime left for transmission: %d units", p_time-clk);
printf("\nNo packets to transmit!!");
}
}
}
}
}
Output
EXPERIMENT NO: 9

AIM: Write a program for frame sorting technique used in buffers.

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.

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.

ALGORITHM/FLOWCHART:

Step 1: Start
Step 2: Enter the Message to be transmitted(read in msg)
Step3:Caluculate no of packets
Step4: Goto Step 5,6,7,8
Step5:void shuffle(intNoOfPacket)
Step 5.1: Calculate status,transdata
Step 5.2:for i = 0; i <NoOfPacket;
Step 5.2.1: calculate trans
trans = rand()%NoOfPacket;
Step 5.2.2: if Status[trans]!=1
Copy read data in transmitted data and goto step 6
Step 6: void receive(intNoOfPacket)
Step 6.1:Print the packets received
Step 6.2: Print the frame in sorted order go to Step 7
Step 7: void sortframes(intNoOfPacket)
Step 7.1 : if transdata[j].SeqNum>transdata[j + 1].SeqNumgoto 7.1.1
Step 7.1.1: Sort the packets
Step 8: Stop
Source Code

#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define FSize 3
typedefstruct packet
{
intSeqNum;
char Data[FSize+1];
}packet;

struct packet *readdata, *transdata;


int divide(char *msg)
{
intmsglen, NoOfPacket, i, j;
msglen = strlen(msg);
NoOfPacket = msglen/FSize;
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);
returnNoOfPacket;
}

void shuffle(intNoOfPacket)
{
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);
}
voidsortframes(intNoOfPacket)
{
packet temp;
int i, j;
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(intNoOfPacket)
{
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;
intNoOfPacket;
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 ns
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

EXPERIMENT NO: 10

AIM: Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.

i. Packet Capture Using Wire shark


1. Click View > Wireless Toolbar. The Wireless Toolbar will appear just below the Main toolbar.

2. Use the Wireless Toolbar to configure the desired channel and channel width.

3. Under Capture, click on AirPcap USB wireless capture adapter to select the capture interface.

Note: If the AirPcap isn't listed, press F5 to refresh the list of available packet capture interfaces.

Note: The AirPcap has been discontinued by RiverBed and is 802.11n only.

4. Click the Start Capture button to begin the capture.


5. When you are finished capturing, click the Stop button.

ii. Starting Wire shark

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 and the help information shown in Help information available from Wireshark (or
something similar) should be printed.

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.

You can then expand any part of the tree to view detailed information about each protocol in each packet.
Clicking on an item in the tree will highlight the corresponding bytes in the byte view. An example with a
TCP packet selected is shown in Figure, “Wireshark with a TCP packet selected for viewing”. It also has
the Acknowledgment number in the TCP header selected, which shows up in the byte view as the selected
bytes.
Figure 1. Wireshark with a TCP packet selected for viewing

You can also select and view packets the same way while Wireshark is capturing if you selected “Update
list of packets in real time” in the “Capture Preferences” dialog box.

In addition you can view individual packets in a separate window as shown in Figure , “Viewing a packet
in a separate window”. You can do this by double-clicking on an item in the packet list or by selecting the
packet in which you are interested in the packet list pane and selecting View → Show Packet in New
Window. This allows you to easily compare two or more packets, even across multiple files.
Figure2. Viewing a packet in a separate window

iv. Analysis and Statistics & Filters.


One of Wireshark’s strengths is its statistical tools. When using Wireshark, we have various types
of tools, starting from the simple tools for listing end-nodes and conversations, to the more sophisticated
tools such as flow and I/O graphs.

To start statistics tools, start Wireshark, and choose Statistics from the main menu.

Using the statistics for

capture file properties menu

1. From the Statistics menu, choose Capture File Properties:

What you will get is the Capture File Properties window (displayed in the following screenshot).

As you can see in the following screenshot, we have the following:

 File: Provides file data, such as filename and path, length, and so on
 Time: Start time, end time, and duration of capture
 Capture: Hardware information for the PC that Wireshark is installed on
 Interfaces: Interface information—the interface registry identifier on the left, if capture filter is
turned on, interface type and packet size limit
 Statistics: General capture statistics, including captured and displayed packets:

EXPERIMENT NO:11

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.
EXPERIMENT NO: 12

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)
EXPERIMENT NO: 13

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 designed specifically 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 before he/she
starts the GUI program:
1. Set up environment variables:
Before the user can run up the dispatcher, coordinator, or NCTUns GUI program he/she must
set up the NCTUNSHOME environment variable.
2. Start up the dispatcher on terminal 1.
3. Start up the coordinator on terminal 2.
4. Start up the nctunsclient on terminal 3.
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 to HOST2
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.
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.
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 HOST window.
5. Select Add button on the HOST window to invoke the command window and provide 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 the modal window
that pops up.
8. Select LOG STATISTICS and select checkboxes for Number of Drop Packet and Number
of Collisions in the MAC window
9. Click OK button on the MAC window to exit and once again click on the OK button on 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 HOST window.
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)
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 HOST window.
2. Change simulation time from 0 to 20 for HOST1
3. Select Add button on the HOST1 window to invoke the command window and provide 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
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 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 HOST2 to open the HOST window.
9. Change simulation time from 21 to 40 for HOST2
10. Select Add button on the HOST2 window to invoke the command window and provide 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 MAC window
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 HOST window.
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.
Step1: Drawing topology

1. Select/click the SUBNET icon on the toolbar and click the left mouse button on the editor, 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 port
number
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
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 mouse button
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 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 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.
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 TERMINAL window.
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 mouse button 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 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
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
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 select PLOT
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 transmission of 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
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 on the 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.
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 on the 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.

You might also like