CN Lab Manual
CN Lab Manual
AIM:
To simulate error detection and correction using NETSIM and LAN trainer kit
APPARATUS REQUIRED:
1. PC
2. NETSIM software
3. LAN trainer kit
ALGORITHM:
ERROR DETECTION
Go to NETSIM
Select error detection option using longitudinal redundancy check
Input data is entered (8 alphabets)
Link the input data and the corresponding error is displayed
ERROR CORRECTION
PROCEDURE:
RESULT:
Thus the hamming technique has been simulated and verified using
NETSIM.
1 (B). IMPLEMENTATION OF ERROR DETECTION AND
ERROR CORRECTION TECHNIQUES
AIM:
ALGORITHM:
1. Open Turbo C++ software and type the program for error detection
PROCEDURE:
#include<conio.h>
#include<math.h>
#include <stdio.h>
int main()
int data[7],rec[7],i,c1,c2,c3,c;
printf("this works for message of 4 bits in size \n enter message bit one by
one:");
scanf("%d%d%d%d", &data[0],&data[1],&data[2],&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];
for (i=0;i<7;i++)
printf("%d ",data[i]);
for (i=0;i<7;i++)
scanf("%d",&rec[i]);
c1=rec[6]^rec{4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1;
if(c==0)
else
if(rec[7-c]==0) '
rec[7-c]=1;
else
rec[7-c]=0;
for (i=0;i<7;i++)
printf("%d ",rec[i]);
getch() ;
}
OUTPUT:
RESULT:
Thus the program error detection & correction has been executed and verified
successfully.
2 (A). SIMULATION OF STOP AND WAIT PROTOCOL AND
SLIDING WINDOW
AIM:
To Simulate and to study stop and Wait protocol using NETSIM and
LAN trainer kit.
APPARATUS REQUIREMENTS:
1.PC
2.NS-2 Simulator
ALGORITHM:
Step I: Start with the window size from the transmitting node
Step 3: If the transmitted frame reaches the receiver without error, the
receiver transmits a Positive Acknowledgement.
Step 4: If the transmitted frame reaches the receiver with error, the
receiver do not transmit acknowledgement.
Step 7: If the transmitted frame reaches the Transmitter with error, the
Transmitter transmits the same frame.
PROCEDURE (NETSIM) :
1. Open NETSIM.
2. Click on Programming -->Transmission flow.
3. Click on sample option and select wait protocol.
4. Select file to transmitted and error rate.
5. Click on link and then animate.
STOP AND WAIT :
RESULT:
Thus the performance of stop and wait protocol using LAN Trainer and
NETSIM was done.
2(B). IMPLEMENTATION OF STOP AND WAIT PROTOCOL
AND SLIDING WINDOW
AIM:
To implement the hamming technique for detecting and correcting single bit
error in received data.
ALGORITHM:
No of frames is 4
Sending frame 1
Waiting for 1 seconds
Sending frame 1
Ack for frame 1
Sending frame 2
Waiting for 1 seconds
Sending frame 2
Ack for frame 2
Sending frame 3
Ack for frame 3
Sending frame 4
Ack for frame 4
RESULT:
Thus the program for implement of stop and wait protocol has been
executed successfully
3. SIMULATION AND STUDY OF GOBACK-N AND SELECTIVE
REPEAT PROTOCOLS
AIM:
APPARATUS REQUIREMENTS:
1. PC
2. NS-2 Simulator
2. Each frame in the buffer has a sequence number starting from 1 and
increasing up to the window size.
3. The source node has a window i.e. a buffer to store the frames. This
buffer size is the number of frames to be transmitted continuously
2. Each frame in the buffer has a sequence number starting from I and
increasing up to the window size.
3. The source node has a window i.e. a buffer to store the frames. This
buffer size is the number of frames to be transmitted continuously.
4. The receiver has a buffer to store the received fTames. The size of the
buffer depends upon the window size defined by the protocol designer.
6. The source node transmits frames continuously till the window size is
exhausted. If any of the frames are received with error only those frames
are requested for retransmission
10. If all the frames transmitted are errorless the next transmission is
carried out for the new window.
11. This concept of repeating the transmission for the error frames only
is called Selective Repeat transmission flow control protocol.
SELECTIVE REPEAT :
RESULT:
AIM:
ALGORITHM:
0->1:4
1->0:5
1->1:6
1==>0:path taken:0
RESULT:
Thus the shortest path using High level data link was executed.
5. IMPLEMENTATION OF IP COMMANDS SUCH AS PING
and TRACE ROUTE
AIM:
ALGORITHM:
//PING
import java.io.*;
import java.net.*;
class pingserver
Try
String str;
String ip=buf1.readLine();
Runtime H=Runtime.getRuntime();
InputStream in=p.getInputStream();
}}
catch(Exception e)
System.out.println(e.getMessage());
}}
OUTPUT:
Minimum = 1ms,maximum=4ms,average=2ms
TRACE ROUTE
Client:
//pingclient.java
import java.io.*;
import java.net.*;
import java.util.Calendar;
class pingclient
String str;
int c=0;
long t1,t2;
while(c<4)
0t1=System.currentTimeMillis();
out.println(str);
System.out.println(dis.readLine());
t2=System.currentTimeMillis();
System.out.println(";TTL="+(t2-t1)+"ms");
c++;
s.close();}}
//pingserver.java
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
class pingserver
Socket s=ss.accept();
int c=0;
while(c<4)
String str=dis.readLine();
out.println("Reply from"+InetAddress.getLocalHost()+";Length"+str.length());
c++;
s.close();
}
OUTPUT:
//Client:
;TTL=228ms
;TTL=3ms
;TTL=2ms
;TTL=2ms
RESULT:
Thus the ping and trace route configuration has been executed successfully.
6. IMPLEMENTATION OF IP ADDRESS CONFIGURATION
AIM:
ALGORITHM:
1. Start
3. Using the function get Host by name() to find the address of the system.
4. Get the name of the system by using the get Host Name() function.
5. By specifying the system name find out the IP address of the system using the
function
import socket
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
OUTPUT:
RESULT:
Thus the IP address configuration was executed successfully.
7. TO CREATE SCENARIO AND STUDY THE PERFORMANCE OF
NETWORK WITH CSMA/CA PROTOCOL AND COMPARE WITH
CSMA/CA PROTOCOLS
AIM:
To study and implement the Carrier Sense Multiple Access with collision
avoidance.
APPARATUS REQUIRED:
1. Pentium PC
2. Eclipse
3. Java
ALGORITHM:
1. Start
2. Initialize k+0
4. If the channel is busy, wait for IFS (Inter Frame Space) time
13. Stop
CSMA/CA PROGRAM
CLIENT 1
try
int R = 0;
System.out.println("attempt : "+k);
int i = 0;
while(true)
System.out.print(i=i+1); if(cli.isidle())
if(cli.isidle())
System.out.println("Still idle");
// Timer runs and wait for time out System.out.println("Wait for time
out :"+10000);
System.out.println("Ackreceived");
bln = true;
break;
else
}
}
if(bln == true)
break;
catch (InterruptedException e)
System.out.println(e);
Boolean isidle()
try
return true;
catch (Exception e)
return false;
}
}
CLIENT 2
try
ss.close(); System.out.println("Connected");
catch(Exception e)
System.out.println(e);
}
OUTPUT:
attempt : 1
Case 2: stop client2 on is still idle (Channel busy after IFS time)
attempt : 1
is Channel idle?
Channel idle
attempt : 1
is Channel idle?
Channel idle
Selected Random number :2 waiting for R slot time: 12000 Message sent
attempt : 2
is Channel idle?
attempt : 1
is Channel idle?
Channel idle
Still idle
Selected Random number :2 waiting for R slot time: 12000 Message sent
RESULT:
AIM:
To study the performance of token bus, token ring and star protocol through
simulation and using LAN trainer kit.
APPARATUS REQUIRED:
1. PC.
2. NETSIM software.
PROCEDURE :
2. At the system 1, enter the neighbor input address of system 2 and click
insert ring.
3. At the system 2, enter the neighbor input address of system 3 and click
insert ring.
4. After the transfer of five between the systems if you want to receive another
file from another system click receive again.
TOKEN BUS:
TOKEN RING:
STAR TOPOLOGY:
RESULT:
Thus the simulation and implementation of token ring and token bus protocol
using and LAN trainer kit was implemented successfully
9 (A). SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM
AIM:
APPARATUS REQUIRED:
1. PC.
2. NETSIM software.
ALGORITHM:
Step 1. To start with router, the router of the assign an cost a router, the router
that was the text permanent.
Step 2. Examine the each neighbor router of the router that was the last
permanent router.
Step 3. Assign smallest cost of each router sent the router with smallest
cumulative cost and make it permanent.
Step 4. Repeat the following steps with there is no change in routing until for
all router.
Step 5. Take the router entry that is not in your own routing table but exist in
anyone.
Step 6. Repeat the steps for all routing to check whether changes are made in
anyone of the router if yes then repeat the step.
PROCEDURE:
Thus the distance vector routing algorithm was implemented using NETSIM
software.
9(B). IMPLEMENTATION OF DISTANCE VECTOR ROUTING
ALGORITHM
AIM:
ALGORITHM
#include<stdio.h>
#include<conio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
void main()
{
int costmat[20][30];
int nodes,i,j,k,count=0;
printf("\n enter the number of nodes");
scanf("%d",&nodes);
printf("\n enter the cost matrix");
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];
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[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<nodes;i++)
{
printf("\nfor router%d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\n node %d via %d distance %d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
Output:
Enter the number of nodes3
for router1
Result:
Thus the implementation of distance vector routing protocol has been executed
successfully.
10(A). SIMULATION OF LINK STATE ROUTING ALGORITHM
AIM:
APPARATUS REQUIRED:
1. PC
2. NETSIM software
ALGORITHM:
Step 1. To start with router, the router of the assign a cost of their router.
Step 2. Examine the each neighbor router of the router that was the permanent router.
Step 3. Assign the cumulative cost of the each router find the router with smallest
cumulative cost and make it permanent.
PROCEDURE:
Thus the shortest path using link state algorithm was executed using NETSIM
software.
10(B). IMPLEMENTATION OF LINK STATE ROUTING ALGORITHM
AIM:
Algorithm
#include<stdio.h>
#include<string.h>
int main()
int count,src_router,i,j,k,w,v,min;
int cost_matrix[100][100],dist[100],last[100];
int flag[100];
scanf("%d",&count);
for(i=0;i<count;i++)
for(j=0;j<count;j++)
printf("\n%d->%d:",i,j);
scanf("%d",&cost_matrix[i][j]);
if(cost_matrix[i][j]<0)
cost_matrix[i][j]=1000;
scanf("%d",&src_router);
for(v=0;v<count;v++)
flag[v]=0;
last[v]=src_router;
dist[v]=cost_matrix[src_router][v];
flag[src_router]=1;
for(i=0;i<count;i++)
min=1000;
for(w=0;w<count;w++)
if(flag[w])
if(dist[w]<min)
v=w;
min=dist[w];
flag[v]=1;
for(w=0;w<count;w++)
if(flag[w])
if(min+cost_matrix[v][w]<dist[w])
dist[w]=min+cost_matrix[v][w];
last[w]=v;
for(i=0;i<count;i++)
printf("\n%d==>%d:path taken:%d",src_router,i,i);
w=i;
while(w!=src_router)
printf("\n<--%d",last[w]);
w=last[w];
return 0;
}
Output:
Enter the no of routers=3
0->0:
[exam47@cselinux~]$./a.out
0 ->0:3
0 ->1:4
1 ->0:5
1 ->1:6
<- -1
Result:
Thus the program to implementation of link state routing has been executed.
11. STUDY OF NETWORK SIMULATOR (NS).AND SIMULATION OF
CONGESTION CONTROL ALGORITHMS USING NS.
Aim:
INTRODUCTION:
The goal of the ns-3 project is to create an open simulation environment for
networking research that will be preferred inside the research community
It should be aligned with the simulation needs of modern networking research.
Since the process of creation of a network simulator that contains a sufficient number
of high quality validated, tested and actively maintained models requires a lot of
work, ns-3 project spreads this workload over a large community of users and
developers
ns-1:
The first version of ns, known as ns-1, was developed at VJ,GEEKLIME, Madurai
(LBNL) in the 1995-97 timeframe by Steve McCanne, Sally Floyd, Kevin Fall, and
other contributors. This was known as the LBNL Network Simulator, and derived
from an earlier simulator known as REAL by S. Keshav. The core of the simulator
was written in C++, with Tcl-based scripting of simulation scenarios.[5] Long-
running contributions have also come from Sun Microsystems, the UC Berkeley
Daedelus, and Carnegie Mellon Monarch projects.
ns-2 :
ns-3 :
A team led by Tom Henderson, George Riley, Sally Floyd, and Sumit Roy, applied
for and received funding from the U.S. National Science Foundation (NSF) to build
a replacement for ns-2, called ns-3. This team collaborated with the Planete project
of INRIA at Sophia Antipolis, with Mathieu Lacage as the software lead, and formed
a new open source project.
The first release, ns-3.1 was made in June 2008, and afterwards the project
continued making quarterly software releases, and more recently has moved to three
releases per year. ns-3 made its eighteenth release (ns-3.18) in the third quarter of
2013.
Current status of the three versions is:
x ns-1 is no longer developed nor maintained, x
ns-2 build of 2009 is not actively maintained (and is not being accepted for
journal publications)
ns-3 is actively developed (but not compatible for work done on ns-2).
Design:
ns-3 is built using C++ and Python with scripting capability. The ns-3 library is
wrapped to python thanks to the pybindgen library which delegates the parsing of
the ns-3 C++ headers to gccxml and pygccxml to generate automatically the
corresponding C++ binding glue. These automatically-generated C++ files are
finally compiled into the ns-3 python module to allow users to interact with the C++
ns-3 models and core through python scripts. The ns-3 simulator features an
integrated attribute-based system to manage default and per-instance values for
simulation parameters. All of the configurable default values for parameters are
managed by this system, integrated with command-line argument processing,
Doxygen documentation, and an XML-based and optional GTK-based configuration
subsystem.
The large majority of its users focuses on wireless simulations which involve
models for Wi-Fi, WiMAX, or LTE for layers 1 and 2 and routing protocols
such as OLSR and AODV.
Components:
ns-3 is split over couple dozen modules containing one or more models for
real-world network devices and protocols.
ns-3 has more recently integrated with related projects: the Direct Code
Execution extensions allowing the use of C or C++-based applications and Linux
kernel code in the simulations.
Simulation workflow:
The general process of creating a simulation can be divided into several steps:
1. Topology definition: to ease the creation of basic facilities and define their
interrelationships, ns-3 has a system of containers and helpers that facilitates
this process.
2. Model development: models are added to simulation (for example, UDP,
IPv4, point to-point devices and links, applications); most of the time this is
done using helpers.
3. Node and link configuration: models set their default values (for example, the
size of packets sent by an application or MTU of a point-to-point link); most
of the time this is done using the attribute system.
4. Execution: simulation facilities generate events, data requested by the user is
logged.
5. Performance analysis: after the simulation is finished and data is available as
a time stamped event trace. This data can then be statistically analysed with
tools like R to draw conclusions.
6. Graphical Visualization: raw or processed data collected in a simulation can
be graphed using tools like Gnuplot, matplotlib or XGRAPH.
Examples of network simulators:
There are many both free/open-source and proprietary network simulators.
Examples of notable network simulation software are, ordered after how often they
are mentioned in research papers:
1. ns (open source)
2. OPNET (proprietary software)
3. NetSim (proprietary software)
Uses of network simulators:
Network simulators serve a variety of needs. Compared to the cost and time
involved in setting up an entire test bed containing multiple networked computers,
routers and data links, network simulators are relatively fast and inexpensive. They
allow engineers, researchers to test scenarios that might be particularly difficult or
expensive to emulate using real hardware - for instance, simulating a scenario with
several nodes or experimenting with a new protocol in the network. Network
simulators are particularly useful in allowing researchers to test new networking
protocols or changes to existing protocols in a controlled and reproducible
environment. A typical network simulator encompasses a wide range of networking
technologies and can help the users to build complex networks from basic building
blocks such as a variety of nodes and links. With the help of simulators, one can
design hierarchical networks using various types of nodes like computers, hubs,
bridges, routers, switches, links, mobile units etc.
Various types of Wide Area Network (WAN) technologies like TCP, ATM,
IP etc. and Local Area Network (LAN) technologies like Ethernet, token rings etc.,
can all be simulated with a typical simulator and the user can test, analyze various
standard results apart from devising some novel protocol or strategy for routing etc.
Network simulators are also widely used to simulate battlefield networks in
Network-centric warfare.
Packet loss:
When one or more packets of data travelling across a computer network fail
to reach their destination. Packet loss is distinguished as one of the three main error
types encountered in digital communications; the other two being bit error and
spurious packets caused due to noise. Packets can be lost in a network because they
may be dropped when a queue in the network node overflows. The amount of packet
loss during the steady state is another important property of a congestion control
scheme. The larger the value of packet loss, the more difficult it is for transport layer
protocols to maintain high bandwidths, the sensitivity to loss of individual packets,
as well as to frequency and patterns of loss among longer packet sequences is
strongly dependent on the application itself.
Throughput
This is the main performance measure characteristic, and most widely used.
In communication networks, such as Ethernet or packet radio, throughput or network
throughput is the average rate of successful message delivery over a communication
channel. The throughput is usually measured in bits per second (bit/s or bps), and
sometimes in data packets per second or data packets per time slot This measure how
soon the receiver is able to get a certain amount of data send by the sender. It is
determined as the ratio of the total data received to the end to end delay. Throughput
is an important factor which directly impacts the network performance.
Delay:
Delay is the time elapsed while a packet travels from one point e.g., source
premise or network ingress to destination premise or network degrees. The larger
the value of delay, the more difficult it is for transport layer protocols to maintain
high bandwidths. We will calculate end to end delay.
Queue Length:
A queuing system in networks can be described as packets arriving for service,
waiting for service if it is not immediate, and if having waited for service, leaving
the system after being served. Thus queue length is very important characteristic to
determine that how well the active queue management of the congestion control
algorithm has been working.
RESULT:
Thus the study of Network simulator (NS2) was studied.
12. ENCRYPTION AND DECRYPTION USING PROGRAMMING
LANGUAGE
AIM:
ALGORITHM
ENCRYPTION
The resulting value will be the encrypted format (cipher text) of the plain text.
ALGORITHM
DECRYPTION
Get the text to be decrypted (cipher text) and key text. Find the length of the cipher
text. For i=1 to length of cipher text
The resulting value will be the decrypted format (original plain text) of the cipher
plain text.
PROGRAM:
# include<stdio.h>
#include<conio.h>
void main ( )
{
static int s, i, k,n,c[100];
printf(“\n program 1: encryption and 2. decryption”);
scanf (“%d”, &s);
switch (s)
{ case 1: printf(“enter the key value:”);
scanf(“%d”, &k);
printf(“enter the length of text:”);
scanf(“%d”, &n);
printf(“enter the data to be encrypted:”);
for (i=0;i<=n;i++)
scanf(“%c”, &c[i]);
for (i=0;i<=n;i++)
{c[i]=c[i]+k;
if (c[i]>90)
c[i]=c[i]-26;}
printf(“encrypted data”);
for (i=1;i<=n;i++)
printf(“%c”, c[i]);
break;
case 2: printf(“enter the key value:”);
scanf(“%d”, &k);
printf(“enter the length of text:”);
scanf(“%d”, &n);
printf(“enter the data to be decrypted:”);
for (i=0;i<=n;i++)
scanf(“%c”, &c[i]);
for (i=0;i<=n;i++)
{c[i]=c[i]-k;
if (c[i]<65)
c[i]=c[i]+26;}
printf(“decrypted data”);
for (i=1;i<=n;i++)
printf(“%c”, c[i]);
break;
case 3: break;
getch ();
}
}
OUTPUT:
2. DECRYPTION
Enter the key value: 1
Enter the length of text: 5
Enter the data to be decrypted: IFMMP
Decrypted data: HELLO
RESULT:
Thus the Data Encryption and Decryption was studied using Turbo C software.