CN Lab Manual
CN Lab Manual
CN Lab Manual
EXPERIMENT-2
AIM:- A Program to implement the data link layer framing methods
i) Character stuffing
ii) bit stuffing.
DESCRIPTION:-
Introduction to character stuffing for Data Link Layer: 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.
PROGRAM:-
#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)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);}
printf("Enter the character\n");
ch=getche();
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;
}
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);
}
Program Output:
Enter string
MIRACLE
Enter position
2
Enter the character
frame after stuffing:
dlestxMdldleIRACLEdleetx
------------------
(program exited with code: 0) Press return to continue
int count = 1;
while (i < N) {
if (arr[i] == 1) {
brr[j] = arr[i];
for (k = i + 1;
arr[k] == 1
&& k < N
&& count < 5;
k++) {
j++;
brr[j] = arr[k];
count++;
if (count == 5) {
j++;
brr[j] = 0;
}
i = k;
}
}
else {
brr[j] = arr[i];
}
i++;
j++;
}
int main()
{
int N = 6;
int arr[] = { 1, 1, 1, 1, 1, 1 };
bitStuffing(N, arr);
return 0;
}
Output:-
1111101
EXPERIMENT-3
AIM:- A Program to implement data link layer framing method checksum.
DESCRIPTION:-
Checksum is an error detection mechanism that detects the error in
the data/message in a data communication from sender to receiver. It is only an error
detection mechanism and hence cannot correct the errors in the message bits. It
uses Checksum generator on the sender side and Checksum checker on the receiver side to
check the errors.
PROGRAM:-
#include<stdio.h>
#include<math.h>
int sender(int arr[10],int n)
{
int checksum,sum=0,i;
printf("\n****SENDER SIDE****\n");
for(i=0;i<n;i++)
sum+=arr[i];
printf("SUM IS: %d",sum);
checksum=~sum; //1's complement of sum
printf("\nCHECKSUM IS:%d",checksum);
return checksum;
}
void main()
{
int n,sch,rch;
printf("\nENTER SIZE OF THE STRING:");
scanf("%d",&n);
int arr[n];
printf("ENTER THE ELEMENTS OF THE ARRAY TO CALCULATE
CHECKSUM:\n");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
sch=sender(arr,n);
receiver(arr,n,sch);
}
OUTPUT:-
ENTER SIZE OF THE STRING:4
ENTER THE ELEMENTS OF THE ARRAY TO CALCULATE CHECKSUM:3 6 8 9
****SENDER SIDE****
SUM IS: 26
CHECKSUM IS:-27
****RECEIVER SIDE****
SUM IS:26
CHECKSUM IS:0
EXPERIMENT-4
AIM:- A program for Hamming Code generation for error detection and
correction.
DESCRIPTION:-
Hamming code is a popular error detection and error correction
method in data Communication. Hamming code can only detect 2 bit error and correct
a single bit error which means it is unable to correct burst errors if may occur while
transmission of data.
Hamming code uses redundant bits (extra bits) which are calculated according to the
below formula:-
R is calculated by putting r = 1, 2, 3 … until the above equation becomes true.
R3 bit is appended at position 22 and so on.These redundant bits are then added to the
original data for the calculation of error at receiver’s end.
At receiver’s end with the help of even parity (generally) the erroneous bit position is
identified and since data is in binary we take complement of the erroneous bit position to
correct received data.
Respective index parity is calculated for r1, r2, r3, r4 and so on.
PROGRAM:-
#include<stdio.h>
void main()
{
int data[10];
int dataatrec[10],c,c1,c2,c3,i;
scanf("%d",&data[2]);
scanf("%d",&data[4]);
c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
printf("\nNo error while transmission of data\n");
}
else {
printf("\nError on position %d",c);
else
dataatrec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);
}
}
}
OUTPUT:-
Enter 4 bits of data one by one
3457
Encoded data is
3452701
Enter received data bits one by one
67846785
6Error on position 50
Data sent : 3452701
Data received : 6846785
Correct message is 6846785
EXPERIMENT-5
AIM:- Write a Program to implement on a data set of characters the three CRC
polynomials – CRC 12, CRC 16 and CRC CCIP.
DESCRIPTION:- This Cyclic Redundancy Check is the most powerful and easy to implement
technique. Unlike checksum scheme, which is based on adition, 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.
When this method is used, the sender and the receiver should agree upon a generator
polynomial, G(x) in advance.Both the high and low order bits of G(x) must be ‘1’To compute
checksum for some frame with ‘m’ bits ( polynomial = M(x), append ‘r’ zero bits to the lower
end of the frame (r = degree of the generator polynomial) so that this check summed frame is
divisible by G(x).Divide M(x) by G(x) using modulo-2 division and subtract the remainder
from M(x) using modulo-2subtraction. let the resultant be called as T(x)T(x) is passed to the
receiver and the receiver divides it by G(x). If there is a remainder, there has been a
transmission error.
PROGRAM:-
#include<stdio.h>
#define N strlen(g) char
t[28],cs[28],g[28]; int a,e,c,b;
void xor()
{
for(c=1;c<N;c++) cs[c]=((cs[c]==g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++) cs[e]=t[e];
do
{ if(cs[0]=='1')
xor();
for(c=0;c<N-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
}
int main()
{
int flag=0; do{
printf("\n1.crc12\n2.crc16\ncrc ccit\n4.exit\n\nEnter your option.");
scanf("%d",&b);
switch(b)
{
case 1:strcpy(g,"1100000001111"); break;
case 2:strcpy(g,"11000000000000101"); break;
case 3:strcpy(g,"10001000000100001"); break;
case 4:return 0;
}
printf("\n enter data:");
scanf("%s",t);
printf("\n --------------- \n");
printf("\n generating polynomial:%s",g);
a=strlen(t);
for(e=a;e<a+N-1;e++) t[e]='0';
printf("\n ----------------- \n");
printf("mod-ified data is:%s",t); printf("\n
-------------------------- \n")
crc();
printf("checksum is:%s",cs);
for(e=a;e<a+N-1;e++) t[e]=cs[e-a];
printf("\n --------------- \n");
printf("\n final codeword is : %s",t); printf("\n
---------------------------\n");
printf("\ntest error detection 0(yes) 1(no)?:");
scanf("%d",&e);
if(e==0)
{
do{
printf("\n\tenter the position where error is to be inserted:");
scanf("%d",&e);
}
while(e==0||e>a+N-1);
printf("\n\terroneous data:%s\n",t);
}
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++); if(e<N-1)
printf("error detected\n\n"); else
printf("\n no error detected \n\n"); printf("\n
-------------------------- ");
}while(flag!=1);
}
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++); if(e<N-1)
printf("error detected\n\n"); else
printf("\n no error detected \n\n"); printf("\n
-------------------------- ");
}while(flag!=1);
OUTPUT:-
1.crc12
2.crc16
3.ccip
4.exit
Enter your option.1
enter data:1100110011100011
generating polynomial:1100000001111
checksum is:1101110110001
generating polynomial:11000000000000101
EXPERIMENT-6
AIM:-A Program to implement Sliding window protocol for Goback N.
DESCRIPTION:-The Go Back-N ARQ or Go Back Automatic Repeat Request is a way to
implement sliding window protocol. This protocol is used for flow control in networking and
is a part of the data-link layer. The sender’s window is of size N and the receiver’s window
size is always one. The window sizes for Go Back-N are
1. SENDER WINDOW SIZE (WS)
The WS is equal to N. If we say the protocol is GB-4, then WS = 4. In order to implement
pipelining, the window size should always be greater than one. If window size is one, the
protocol reduces to stop-and -wait protocol.
plenty of sequence numbers, for the sake of explanation. Now the sender has dispatched the
packets zero, one, two and three. After acknowledging the packets zero and one, the receiver
is now awaiting packet two and the sender window has additionally slided to similarly
transmit the packets four and five.
3. ACKNOWLEDGEMENTS
There are 2 kinds of acknowledgments, namely:
Cumulative ACK
Independent ACK
GBN makes use of cumulative acknowledgement. On the receiver side, it starts an
acknowledgment timer when any packet is received, which is constant, and when it expires,
it’s going to send a cumulative ACK for the range of packets received in the interval of the
timer. If the receiver has obtained N packets, then the acknowledgement range might be
N+1. A crucial factor is that the ACK timer will now not begin after the expiration of the
primary timer, but after the receiver has received a packet. The timer at the sender side must
be greater than the ACK timer.
PROGRAM:-
#include<bits/stdc++.h>
#include<ctime>
int main() {
ll tf, N, tt = 0;
srand(time(NULL));
cout << "Enter the Total number of frames : ";
cin >> tf;
cout << "Enter the Window Size : ";
cin >> N;
ll i = 1;
transmission(i, N, tf, tt);
cout << "Total number of frames which were sent and resent are : " << tt <<
endl;
return 0;
}
OUTPUT:-
Enter the Total number of frames: 12
Enter the Window Size : 4
Sending Frame 1…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Timeout!! Frame Number : 1 Not Received
Retransmitting Window…
Sending Frame 1…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Acknowledgment for Frame 1…
Timeout!! Frame Number : 2 Not Received
Retransmitting Window…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Sending Frame 5…
Sending Frame 2…
Sending Frame 3…
Sending Frame 4…
Sending Frame 5…
Acknowledgment for Frame 2…
Acknowledgment for Frame 3…
Acknowledgment for Frame 4…
Timeout!! Frame Number : 5 Not Received
Retransmitting Window…
Sending Frame 5…
Sending Frame 6…
Sending Frame 7…
Sending Frame 8…
Timeout!! Frame Number : 5 Not Received
Retransmitting Window…Sending Frame 5…
Sending Frame 6…
Sending Frame 7…
Sending Frame 8…
Acknowledgment for Frame 5…
Sending Frame 7…
Sending Frame 8…
Sending Frame 9…
Sending Frame 10…
Acknowledgment for Frame 7…
Acknowledgment for Frame 8…
Acknowledgment for Frame 9…
Acknowledgment for Frame 10…Sending Frame 11…
Sending Frame 12
Retransmitting Window…
EXPERIMENT-7
AIM:- A Program to implement Sliding window protocol for Selective repeat.
DESCRIPTION:- 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. In sliding window protocol the receiver has to have some memory to compensate
any loss in transmission or if the frames are received unordered.
η = (W*tx)/(tx+2tp)
W = Window Size
tx = Transmission time
tp = Propagation delay
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 corruption of
mes)\n\n");
printf("After sending %d frames at waits for acknowledgement sent by the
ceiver\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 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-8
AIM:- A Program to implement Stop and Wait Protocol
DESCRIPTION:-Before understanding the stop and Wait protocol, we first know about
the error control mechanism. The error control mechanism is used so that the received data
should be exactly same whatever sender has sent the data. The error control mechanism is
divided into two categories, i.e., Stop and Wait ARQ and sliding window. The sliding window
is further divided into two categories, i.e., Go Back N, and Selective Repeat. Based on the
usage, the people select the error control mechanism whether it is stop and wait or sliding
window.
Here stop and wait means, whatever the data that sender wants to send, he sends the data to
the receiver. After sending the data, he stops and waits until he receives the acknowledgment
from the receiver. The stop and wait protocol is a flow control protocol where flow control is
one of the services of the data link layer.
It is a data-link layer protocol which is used for transmitting the data over the noiseless
channels. It provides unidirectional data transmission which means that either sending or
receiving of data will take place at a time. It provides flow-control mechanism but does not
provide any error control mechanism.
The idea behind the usage of this frame is that when the sender sends the frame then he waits
for the acknowledgment before sending the next frame.
Sender side
Rule 2: Sender sends the next packet only when it receives the acknowledgment of the
previous packet.
Therefore, the idea of stop and wait protocol in the sender's side is very simple, i.e., send one
packet at a time, and do not send another packet before receiving the acknowledgment.
Receiver side
Rule 2: When the data packet is consumed, receiver sends the acknowledgment to the
sender.
Therefore, the idea of stop and wait protocol in the receiver's side is also very simple, i.e.,
consume the packet, and once the packet is consumed, the acknowledgment is sent. This is
known as a flow control mechanism.
P
R
O
G
R
A
M
:
-
#
i
n
c
l
u
d
e
<
s
t
d
i
o
.
h
>
int sender();
int recv();
int timer=0,wait_for_ack=-
1,frameQ=0,cansend=1,t=0;
main()
{
int i,j;
int frame[5];
printf("enter the time when data frame will be
ready\n");
for(j=0;j<3;j++)
{
sender( i,frame[]);
recv(i);
}
sender(int i,int frame[])
{
wait_for_ack++;
if(wait_for_ack==3)
{
if(i==frame[t])
{
frameQ++;
t++;
}
if(frameQ==0)
printf("NO FRAME TO SEND at time=%d \n",i);
if(frameQ>0 && cansend==1)
{
printf("FRAME SEND AT TIME=%d\n",i);
cansend=-1;
frameQ--;
timer++;
printf("timer in sender=%d\n",timer);
}
if(frameQ>0 && cansend==-1)
printf("FRAME IN Q FOR TRANSMISSION AT
TIME=%d\n",i);
if(frameQ>0)
t++;
}
printf("frameQ=%d\n",frameQ);
printf("i=%d t=%d\n",i,t);
printf("value in frame=%d\n",frame[t]);
return 0;
}
int recv(int i )
{ printf("timer in recvr=%d\n",timer);
if(timer>0)
{
timer++;
}
if(timer==3)
{
printf("FRAME ARRIVED AT TIME= %d\n",i);
wait_for_ack=0;
timer=0;
}
else
printf("WAITING FOR FRAME AT TIME
%d\n",i);
return 0;
}
}
OUTPUT:-
Sender Receiver
Sending Frame : 1 Received Frame : 1
Acknowledgement : 1
Sending Frame : 2 ---
Timeout
Sending Frame : 2 Received Frame : 2
Acknowledgement : 2
EXPERIMENT-9
AIM:- A program for congestion control using leaky bucket algorithm.
DESCRIPTION:- 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.
This approach to congestion management is widely used in ATM networks and is called
traffic shaping .he 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.
PROGRAM:-
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#define NOF_PACKETS 10
int rand(int a)
{
int rn = (random() % 10) % a;
return rn == 0 ? 1 : rn;
}
int main()
{
int packet_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-10
AIM:- A Program to implement Dijkstra‘s algorithm to compute the Shortest path
through a graph.
DESCRIPTION:-
The Dijkstra’s algorithm finds the shortest path from a particular node,
called the source node to every other node in a connected graph. It produces a shortest path
tree with the source node as the root. It is profoundly used in computer networks to generate
optimal routes with the aim of minimizing routing costs.
PROGRAM:-
#include <limits.h>
#include <stdio.h>
#define V 9
int graph[V][V] = { { 0, 6, 0, 0, 0, 0, 0, 8, 0 },
{ 6, 0, 8, 0, 0, 0, 0, 13, 0 },
{ 0, 8, 0, 7, 0, 6, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 6, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
};
dijkstra(graph, 0);
return 0;
}
OUTPUT:-
Vertex Distance from Source
00
16
2 14
3 21
4 21
5 11
69
78
8 15
EXPERIMENT-11
AIM:- A Program to implement Distance vector routing algorithm by obtaining routing
table at each node (Take an example subnet graph with weights indicating delay
between nodes).
DESCRIPTION:-
Distance vector routing is an asynchronous algorithm in which node x sends the copy of its
distance vector to all its neighbors. When node x receives the new distance vector from one
of its neighboring vector, v, it saves the distance vector of v and uses the Bellman-Ford
equation to update its own distance vector.
PROGRAM :-
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct
distance from the node i to k using the cost matrix
//and add the distance from k to node j
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{//We calculate the minimum distance
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
OUTPUT:-
EXPERIMENT-12
AIM:- A Program to implement Broadcast tree by taking subnet of hosts.
DESCRIPTION:-Kruskal's algorithm is used to obtain the broadcast tree from the given
subnet.This algorithm constructs a minimal spanning tree for a connected weighted graph G.
Select any edge of minimal value that is not a loop. This is the first edge
of T.Select any remaining edge of G having minimal value that does not from a circuit with
the edges already included in T.Continue step2 until T contains n-1 edges where n is the
number of vertices of G.
PROGRAM:-
#include<stdio.h>
int a[10][10],n;
main()
{
int i,j,root;
clrscr();
printf(“Enter no.of nodes:”);
scanf(“%d”,&n);
printf(“Enter adjacent matrix\n”);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf(“Enter connecting of %d–>%d::”,i,j);
scanf(“%d”,&a[i][j]);
}
printf(“Enter root node:”);
scanf(“%d”,&root);
adj(root);
}
adj(int k)
{
int i,j;
printf(“Adjacent node of root node::\n”);
printf(“%d\n\n”,k);
for(j=1;j<=n;j++)
{
if(a[k][j]==1 || a[j][k]==1)
printf(“%d\t”,j);
}
printf(“\n”);
for(i=1;i<=n;i++)
{
if((a[k][j]==0) && (a[i][k]==0) && (i!=k))
Advertisements
printf(“%d”,i);
}
}
OUTPUT:-
Enter no.of nodes:5
Enter adjacent matrix
Enter connecting of 1–>1::0
Enter connecting of 1–>2::1
Enter connecting of 1–>3::1
Enter connecting of 1–>4::0
Enter connecting of 1–>5::0
Enter connecting of 2–>1::1
Enter connecting of 2–>2::0
Enter connecting of 2–>3::1
Enter connecting of 2–>4::1
Enter connecting of 2–>5::0
Enter connecting of 3–>1::1
Enter connecting of 3–>2::1
Enter connecting of 3–>3::0
Enter connecting of 3–>4::0
Enter connecting of 3–>5::0
Enter connecting of 4–>1::0
Enter connecting of 4–>2::1
Enter connecting of 4–>3::0
Enter connecting of 4–>4::0
Enter connecting of 4–>5::1
EXPERIMENT-13
AIM:-
To study & observe about Wireshark Tool.
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
f. Close Wireshark.
EXPERIMENT-14
Run the “Nmap – Zenmap” GUI program. If you left your settings at
default during installation, you should be able to see an icon for it on your
desktop. If not, look in your Start menu. Opening Zenmap will start the
program.
Enter in the target for your scan. The Zenmap program makes scanning
a fairly simple process. The first step to running a scan is choosing your
target. You can enter a domain (example.com), an IP address (127.0.0.1), a
network (192.168.1.0/24), or a combination of those.
Depending on the intensity and target of your scan, running an Nmap
scan may be against the terms of your internet service provider, and
may land you in hot water. Always check your local laws and your
ISP contract before performing Nmap scans on targets other than
your own network.
Click Scan to start scanning. The active results of the scan will be
displayed in the Nmap Output tab. The time the scan takes will depend on
the scan profile you chose, the physical distance to the target, and the
target’s network configuration.
Read your results. Once the scan is finished, you’ll see the message
“Nmap done” at the bottom of the Nmap Output tab. You can now check
your results, depending on the type of scan you performed. All of the
results will be listed in the main Nmap Output tab, but you can use the
other tabs to get a better look at specific data.[2]
Ports/Hosts - This tab will show the results of your port scan,
including the services for those ports.
Topology - This shows the traceroute for the scan you performed.
You can see how many hops your data goes through to reach the
target.
Host Details - This shows a summary of your target learned through
scans, such as the number of ports, IP addresses, hostnames,
operating systems, and more.
Scans - This tab stores the commands of your previously-run scans.
This allows you to quickly re-scan with a specific set of parameters.
EXPERIMENT-15
16.
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.
How to
2. Features of NS2
1. It is a discrete event simulator for networking research.
2. It provides substantial support to simulate bunch of protocols like TCP, FTP, UDP,
https and DSR.
3. Basic Architecture
NS2 consists of two key languages: C++ and Object-oriented Tool Command
Language (OTcl). While the C++ defines the internal mechanism (i.e., a backend) of
the simulation objects, the OTcl sets up simulation by assembling and configuring the
objects as well as scheduling discrete events. The C++ and the OTcl are linked
together using TclCL
III. NAM trace files which are used by NAM for visualization of ns simulations. The NAM
trace file should contain topology information like nodes, links, queues, node
connectivity etc as well as packet trace information. A NAM trace file has a basic
format to it. Each line is a NAM event. The first character on the line defines the type
of event and is followed by several flags to set options on that event. There are 2
sections in that file, static initial configuration events and animation events. All events
with -t * in them are configuration events and should be at the beginning of the file.
6. Example on NS2
NS workbench is used in following examples to create scenarios and generate TCL
scripts, which are then run in NS2 to generate trace file and NAM file
To use NS workbench you will need Java Sdk installed on your system then download
ns-bench jar file and execute it to start ns workbench
Example 1:
The network consists of five nodes n0 to n4. In this scenario, node n0 sends constant
bit-rate (CBR) traffic to node n3, and node n1 transfers data to node n4 using a file
transfer protocol (FTP). These two carried traffic sources are carried by transport layer
protocols User Datagram Protocol (UDP) and Transmission Control Protocol (TCP),
respectively. In NS2, the transmitting object of these two protocols are a UDP agent
and a TCP agent, while the receivers are a Null agent and a TCP sink agent,
respectively.
4. Supported protocols
5. Supported platforms
6. Modularity
7. Popular
Disadvantages
EXPERIMENT-16
AIM:- To study about NS2 Simulator
i. NS2 Simulator-Introduction
i. NS2 Simulator-Introduction
environment variable.
To draw a new network topology, a user can perform the following steps:
is launched. It is only in this mode that a user can draw a new network
topology or change an existing simulation topology. When a user switches the
mode to the next mode “Edit Property”, the simulation network topology can no
longer be changed.
3. Left-Click anywhere in the blank working area to add a router to the current
network topology. In the same way we can add switch, hub,WLAN access
point,WLAN mobile node , wall (wireless signal obstacle) etc.
4. Left-Click the host icon on the toolbar. Like in step 4, add the required
number of hosts to the current topology.
5. To add links between the hosts and the router, left-click the link icon on the
toolbar to select it.
6. Left-Click a host and hold the mouse button. Drag this link to the router
and then release the mouse left button on top of the router. Now a link between
the selected host and the router has been created.
7. Add the other, required number of links in the same way. This completes the
creation of a simple network topology.
1. A network node (device) may have many parameters to set. For example, we
may have to set the maximum bandwidth, maximum queue size etc to be used
in a network interface. For another example, we may want to specify that
some application programs (traffic generators) should be run on some
hosts or routers to generate network traffic.
2. Before a user can start editing the properties of a node, he/she should switch
the mode from the “Draw Topology” to “Edit Property” mode. In this mode,
topology changes can no longer be made. That is, a user cannot add or delete
nodes or links at this time.
4. A user should be aware that if he/she switches the mode back to the “Draw
Topology” mode when he/she again switches the mode back to the “Edit
Topology” mode, node's IP and MAC addresses will be regenerated and
assigned to layer 3 interfaces.
When a user finishes editing the properties of network nodes and specifying
application programs to be executed during a simulation, he/she can start
runningthe simulation.
1. In order to do so, the user must switch mode explicitly from “Edit Property”
to “Run Simulation”. Entering this mode indicates that no more changes can
2. Whenever the mode is switched to the “ Run Simulation” mode, the many
simulation files that collectively describe the simulation case will be
exported. These simulation files will be transferred to the (either remote or
local) simulation server for it to execute the simulation. These files are stored
in the “ main File Name.sim” directory, where main Filename is the name of
the simulation case chosen in the “Draw Topology” mode.
Playing Back the Packet Animation Trace
After the simulation is finished, the simulation server will send back the
simulation result files to the GUI program after receiving these files, the GUI
program will store these files in the “results directory” .It will then
automatically switch to “play back mode”.
1. These files include a packet animation trace file and all performance log files
that the user specifies to generate. Outputting these performance log files can
be specified by checking some output options in some protocol modules in the
node editor. In addition to this, application programs can generate their own
data files.
2. The packet animation trace file can be replayed later by the packet
animation player. The performance curve of these log files can be plotted
by the performance monitor.
Post Analysis
1. When the user wants to review the simulation results of a simulation case that
has been finished before, he /she can run up the GUI program again and
then open the case's topology file.
2. The user can switch the mode directly to the “Play Back” mode. The GUI
program will then automatically reload the results (including the packet
animation trace file and performance log file.
3. After the loading process is finished, the user can use the control buttons
located at the bottom of the screen to view the animation.
Simulation Commands
Sender:-
stcp –p 2000 –l 1024 1.0.1.2
Receiver:-
rtcp –p 2000 –l 1024
Parameters:-
Drop Packets and Collision Packets.
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
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.
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.
7. Click NODE EDITOR Button on the HOST window and select the MAC
tab from the modal window that pops up.
9. Click OK button on the MAC window to exit and once again click on
the OK button on the HOST window to exit.
2. Click NODE EDITOR Button on the HOST window and select the FIFO
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
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 Repeat Step3(Simulate)
Topology:-
Sender:-
stcp –p 3000 –l 1024 1.0.1.3
stg –u 1024 1.0.1.3
Receiver:-
rtcp –p 3000 –l 1024
rtg –u 3000
Parameters:-
Throughput of incoming and outgoing Packets
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.
4. Click NODE EDITOR Button on the HOST window and select the MAC
tab from the modal window that pops up.
6. Click OK button on the MAC window to exit and once again click on
the OK button on the HOST window to exit.
7. Double click the left mouse button while cursor is on HOST2 to open
the HOST window.
10. Click NODE EDITOR Button on the HOST window and select the MAC
tab from the modal 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 HOST window to exit.
13. Double click the left mouse button while cursor is on HOST3 to
open the HOST window.
14. Select Add button on the HOST window to invoke the command
window and provide the following command in the command
textbox.
rtcp –p 21 –l 1024
17. Click NODE EDITOR Button on the HOST window and select the MAC
tab from the modal window that pops up.
19. 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
Topology:-
Sender:-
stcp –p 2000 –l 1024 1.0.1.4
Receiver:-
rtcp –p 2000 –l 1024
Command Console:-
Goto tools-> simulation time and change Simulation time to 100.
During run mode, double click host 2 and then click command console.
And execute the following command.
ping
1.0.1.4
Parameters:-
Drop Packets and Collision Packets.
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.
3. Click on the “E” icon on the toolbar to save the current topology
Step2: Configuration
4. Double click the left mouse button while cursor is on a HOST to
open the HOST window.
9. Also click NODE EDITOR Button on the HOST window and select
the MAC tab from the modal window that pops up.
10. Select LOG STATISTICS and select checkbox for drop and collision
log statistics in the MAC window
11. Click OK button on the MAC window to exit and once again click on
the OK button on the HOST window to exit.
13. Select G_Setting from the menu bar and select Simulation from the
drop down list Set simulation time>600sec
Step3: Simulate
iv. Type ping IP address of a 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.
Caution: file4 is the hypothetical name given to this simulation.
v. Simulate to Compare Data Rate& Throughput
Simulate an Ethernet LAN using N nodes (6-10), change error rate and data rate
and compare throughput.
Topology:-
Sender:-
stcp –p 2000 –l 1024 1.0.1.4
Receiver:-
rtcp –p 2000 –l 1024
Double click on receiver link and change BER to 0.000001,
Run Again. Parameters:-
Throughput of outgoing Packets
1. Select/click the HOST icon on the toolbar and click the left mouse button
on the editor, to place HOST1 on the editor.
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.
stcp –p 21 –l 1024 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, but use different commands
stcp –p 21 –l 1024 1.0.1.5 at HOST2
stcp –p 21 –l 1024 1.0.1.6 at HOST3
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.
rtcp –p 21 –l 1024
8. Click NODE EDITOR Button on the HOST window and select the MAC
10. Click OK button on the MAC window to exit and once again click on the
OK button on the HOST window to exit.
11. Repeat this step at HOST 5 and HOST6, but use different commands
rtcp –p 21 –l 1024 at
HOST5 rtcp –p 21 –l 1024
at HOST6
12. Double click the left mouse button while cursor is on HOST5 to open
the HOST window.
15. Click OK button on the PHYSICAL window to exit and once again click
on the OK button to return to the HOST window
16. Click NODE EDITOR Button on the HOST window and select the MAC
tab from the modal window that pops up.
17. Select LOG STATISTICS and select checkbox for output throughput
in the MAC window
18. Click OK button on the MAC window to exit and once again click on the
OK button on the HOST window to exit.
19. Repeat this step HOST6, Change Bandwidth this time while undoing
the change in Bit Error Rate, also select the output throughput at
HOST6.
Step3: Simulate
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
iv. To view results, Open up new TERMINAL window, move to file5.results
folder and open output throughput log files in separate TERMINAL
window.
ADDITIONAL PROGRAMS
AIM :-Configuration of TELNET protocols on router for remote access.
Telnet protocol:
Telnet is an application protocol that allows a user to communicate with a
remote device. A user on a client machine can use a software (known as a
Telnet client) to access a command-line interface of another, remote
machine that is running a Telnet server program.Telnet is often used by
network administrators to access and manage remote devices. A network
administrator can access the device by telnetting to the IP address or
hostname of a remote device. The network administrator will then be
presented with a virtual terminal that can interact with the remote host. To
use telnet, you must have a software (Telnet client) installed. On a remote
device, a Telnet server must be installed and running.
and manage the router (R1). The administrator will start a Telnet client
program on Host A and enter the IP address of the router R1 (telnet
10.0.0.1):
The administrator can now manage the remote device (R1) from his own computer.
Although Telnet is simple and easy to use, it is not widely used anymore,
especially in production environments. This is because Telnet sends all data
in clear-text, including usernames and passwords! SSH is commonly used
today instead of Telnet. Telnet is only used if SSH is not available on the
device, for example on some older Cisco equipment.
NetSim allows users to interact with the simulation at runtime via a socket or
through a file. User Interactions make simulation more realistic by allowing
command execution to view/modify certain device parameters during runtime.
Ping Command
The ping command is one of the most often used networking utilities for
troubleshooting network problems.
You can use the ping command to test the availability of a networking
device (usually a computer) on a network
When you ping a device, you send that device a short message, which it then
sends back (the echo)
If you receive a reply then the device is in the Network, if you do not, then the
device is faulty, disconnected, switched off, or incorrectly configured.
Route Commands
You can use the route commands to view, add and delete routes in IP routing tables.
route print: In order to view the entire contents of the IP routing table.
route delete: In order to delete all routes in the IP routing table.
route add: In order to add a static TCP/IP route to the IP routing table.
Network setup
Open NetSim and click Examples > Experiments > Basic-networking-
set as TRUE. Similarly, ICMP Status is set as TRUE for all the devices as
Step 4: Right click on the Application Flow App1 CBR and select Properties or
click on the Application icon present in the top ribbon/toolbar.
A CBR Application is generated from Wired Node 1 i.e. Source to Wired Node 2
i.e. Destination with Packet Size remaining 1460Bytes and Inter Arrival Time
remaining 233.6µs. Transport Protocol is set to UDP.
Additionally, the “Start Time(s)” parameter is set to 30, while configuring the
application. This time is usually set to be greater than the time taken for OSPF
Convergence (i.e., Exchange of OSPF information between all the routers), and it
increases as the size of the network increases.
Step 5: Packet Trace is enabled in NetSim GUI. At the end of the simulation, a
very large .csv file is containing all the packet information is available for the users
to perform packet level analysis. Plots are enabled in NetSim GUI.
Step 6: Click on Run Simulation. Simulation Time is set to 300 Seconds and in the
Runtime Interaction tab Figure 26-4, Interactive Simulation is set to True.
address of all the devices. Now, Right click on Router 3 or any other Router
and select “NetSim Console” option as shown Figure 26-6.
After this the command line interface can be used to execute all the supported
commands.
Network Commands
Ping Command
You can use the ping command with an IP address or Device name.
ICMP_Status should be set as True in all nodes for ping to work.
Route Commands
In order to view the entire contents of the IP routing table, use following command
route print
route print
You’ll see the routing table entries with network destinations and the
gateways to which packets are forwarded, when they are headed to that
destination. Unless you’ve already added static routes to the table, everything
you see here is dynamically generated.
In order to delete a route in the IP routing table you’ll type a command using
the following syntax
So, to delete the route with destination network 11.5.1.2, all we’d have to
To check whether route has been deleted or not check again using route print
command.
To add a static route to the table, you will type a command using the following
syntax.
So, for example, if you wanted to add a route specifying that all traffic
bound for the
11.5.1.2 subnet went to a gateway at 11.5.1.1
If you were to use the route print command to look at the table now, you’d
see your new static route.
How to
Change a Computer's Mac Address in Windows
How to
Access Shared Folders on a Network
How to
Configure Your PC to a Local Area Network