You are on page 1of 67

Exp. No.

1
IMPLEMENTATION OF ERROR DETECTION / ERROR CORRECTION TECHNIQUES

AIM:
Write a program for error detection and error correction techniques by Hamming Method using C
language.

APPARATUS REQUIERD:
1. C -editor
2. Standalone desktop.

PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.

PROGRAM FOR HAMMING METHOD :

#include<stdio.h>
#include<conio.h>
Void main()
{
int data[7],rec[7],i,c1,c2,c3,c;
printf ("this works for message of 4bits 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];
printf("\n the encoded bits are given below: \n");
for (i=0;i<7;i++) {
printf("%d ",data[i]);
}
printf("\n enter the received data bits one by one: "); 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)
{
printf ("\n congratulations there is no error: ");
}
else
{
printf("\n error on the position: %d\n the correct message is \n",c);
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 Error detection and correction methods were executed and verified successfully by using c
– editor.

Exp. No. 2
IMPLEMENTATION OF STOP AND WAIT PROTOCOL

AIM:
To write a program for talk commands using socket programming to send and receive message
from client and server using connection oriented service.

APPARATUS REQUIERD:
JDK TOOLKIT 5.0
Standalone desktop

PROCEDURE:
Server:
1. Start the program.
2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Wait for client to display this message and write a new one to be displayed by the server.
6. Display message given at client using input streams read from socket.
7. If in the message given by server or client, the word “ end” is encountered, exit both the
programs.
8. Stop the program.

Client:
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Using input streams read message given by server and print it.
4. Using input streams, get message from user to be given to the server.
5. Use output streams to write message to the server.
6. Stop the program

SENDER PROGRAM :

import java.io.*;
import java.net.*;
public class Sender
{
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,str, msg;
int n,i=0,sequence=0;
Sender(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Waiting for Connection....");
sender = new Socket("localhost",2004);
sequence=0;
out=new ObjectOutputStream(sender.getOutputStream());
out.flush();
in=new ObjectInputStream(sender.getInputStream());
str=(String)in.readObject();
System.out.println("reciver > "+str);
System.out.println("Enter the data to send....");
packet=br.readLine();
n=packet.length();
do{
try{
if(i<n){
msg=String.valueOf(sequence);
msg=msg.concat(packet.substring(i,i+1));
} else if(i==n){
msg="end";out.writeObject(msg);break;
}
out.writeObject(msg);
sequence=(sequence==0)?1:0;
out.flush();
System.out.println("data sent>"+msg);
ack=(String)in.readObject();
System.out.println("waiting for ack.....\n\n");
if(ack.equals(String.valueOf(sequence))){
i++;
System.out.println("receiver > "+" packet recieved\n\n");
} else{
System.out.println("Time out resending data....\n\n");
sequence=(sequence==0)?1:0;
}}
catch(Exception e){}
}while(i<n+1);
System.out.println("All data sent. exiting.");
}catch(Exception e){}
finally{
try{
in.close();
out.close();
sender.close();
} catch(Exception e){}
}
}
public static void main(String args[]){
Sender s=new Sender ();
s.run();
}}
RECEIVER PROGRAM:

import java.io.*;
import java.net.*;
public class Reciever{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Reciever(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2004,10);
System.out.println("waiting for connection...");
connection=reciever.accept();
sequence=0;
System.out.println("Connection established :");
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected .");
do{
try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){
data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver >"+packet);
} else
{
System.out.println("\n\nreceiver >"+packet +" duplicate data");
} if(i<3){
out.writeObject(String.valueOf(sequence));i++;
} else{
out.writeObject(String.valueOf((sequence+1)%2));
i=0;
}} catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
out.writeObject("connection ended .");
} catch(Exception e){}
finally{
try{
in.close();
out.close();
reciever.close();
} catch(Exception e){}
}
}
public static void main(String args[]){
Reciever s=new Reciever();
while(true){
s.run();
}
}
}
SENDER OUTPUT:
Waiting for Connection....
receiver > connected .
Enter the data to send....
my name
data sent>0m
waiting for ack.....
receiver > packet received
data sent>1y
waiting for ack.....
receiver > packet received
data sent>0n
waiting for ack.....
receiver > packet received
data sent>1a
waiting for ack.....
Time out resending data....
data sent>1a
waiting for ack.....
receiver > packet received
data sent>0m
waiting for ack.....
receiver > packet received
data sent>1e
waiting for ack.....
receiver > packet received
All data sent. exiting.

RECEIVER OUTPUT:
waiting for connection...
Connection established :
receiver >0m
receiver >1y
receiver >0n
receiver >1a
receiver >1a duplicate data
receiver >0m
receiver >1e
Data received=my name
waiting for connection...

RESULT:
Thus the java Socket Program for stop and Wait Protocol executed and output is verified
Successfully.

Exp. No. 3a
IMPLEMENTATION OF SLIDING WINDOW GO BACK N

AIM:
Write a program in Java to implement Go Back N algorithm. The Program sends the frames from the
Client to the Server with checking for missing frames via sending an acknowledgement.

APPARATUS REQUIERD:
1. JDK TOOLKIT 5.0
2. Standalone desktop

PROCEDURE:
Server:
1. Start the program.
2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Wait for client to display this message and write a new one to be displayed by the server.
6. Display message given at client using input streams read from socket.
7. If in the message given by server or client, the word “ end” is encountered, exit both
the programs.
8. Stop the program.
Client:
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Using input streams read message given by server and print it.
4. Using input streams, get message from user to be given to the server.
5. Use output streams to write message to the server.
6. Stop the program.

SENDER PROGRAM :
import java.net.*;
import java.io.*;
import java.util.*;
public class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket server=new ServerSocket(6262);
System.out.println(“ Server established.” );
Socket client=server.accept();
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
System.out.println(“ Client is now connected.” );
int x=(Integer)ois.readObject();
int k=(Integer)ois.readObject();
int j=0;
int i=(Integer)ois.readObject();
boolean flag=true;
Random r=new Random(6);
int mod=r.nextInt(6);
while(mod==1||mod==0)
mod=r.nextInt(6);
while(true)
{
int c=k;
for(int h=0;h<=x;h++)
{
System.out.print(“ |” +c+” |” );
c=(c+1)%x;
}
System.out.println();
System.out.println();
if(k==j)
{
System.out.println(“ Frame “ +k+” recieved” +” \n” +” Data:” +j);
j++;
System.out.println();
}
else
System.out.println(“ Frames recieved not in correct order” +” \n” +” Expected farme:” + j +” \n”
+”
Recieved frame no :” + k);
System.out.println();
if(j%mod==0 && flag)
{
System.out.println(“ Error found. Acknowledgement not sent. “ );
flag=!flag;
j–;
}
else if(k==j-1)
{
oos.writeObject(k);
System.out.println(“ Acknowledgement sent” );
}
System.out.println();
if(j%mod==0)
flag=!flag;
k=(Integer)ois.readObject();
if(k==-1)
break;
i=(Integer)ois.readObject();
}
System.out.println(“ Client finished sending data. Exiting” );
oos.writeObject(-1);
}
}

CLIENT PROGRAM :
import java.util.*;
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print(“ Enter the value of m : “ );
int m=Integer.parseInt(br.readLine());
int x=(int)((Math.pow(2,m))-1);
System.out.print(“ Enter no. of frames to be sent:” );
int count=Integer.parseInt(br.readLine());
int data[]=new int[count];
int h=0;
for(int i=0;i<count;i++)
{
System.out.print(“ Enter data for frame no ” +h+ ” => “ );
data[i]=Integer.parseInt(br.readLine());
h=(h+1)%x;
}
Socket client=new Socket(“ localhost” ,6262);
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
System.out.println(“ Connected with server.” );
boolean flag=false;
GoBackNListener listener=new GoBackNListener(ois,x);
listener=new GoBackNListener(ois,x);
listener.t.start();
int strt=0;
h=0;
oos.writeObject(x);
do
{
int c=h;
for(int i=h;i<count;i++)
{
System.out.print(“ |” +c+” |” );
c=(c+1)%x;
}
System.out.println();
System.out.println();
h=strt;
for(int i=strt;i<x;i++)
{
System.out.println(“ Sending frame:” +h);
h=(h+1)%x;
System.out.println();
oos.writeObject(i);
oos.writeObject(data[i]);
Thread.sleep(100);
}
listener.t.join(3500);
if(listener.reply!=x-1)
{
System.out.println(“ No reply from server in 3.5 seconds. Resending data from frame no ” +
(listener.reply+1));
System.out.println();
strt=listener.reply+1;
flag=false;
}
else
{
System.out.println(“ All elements sent successfully. Exiting” );
flag=true;
}
}while(!flag);
oos.writeObject(-1);
}
}
class GoBackNListener implements Runnable
{
Thread t;
ObjectInputStream ois;
int reply,x;
GoBackNListener(ObjectInputStream o,int i)
{
t=new Thread(this);
ois=o;
reply=-2;
x=i;
}
@Override
public void run() {
try
{
int temp=0;
while(reply!=-1)
{
reply=(Integer)ois.readObject();
if(reply!=-1 && reply!=temp+1)
reply=temp;
if(reply!=-1)
{
temp=reply;
System.out.println(“ Acknowledgement of frame no ” + (reply%x) + ” recieved.” );
System.out.println();
}
}
reply=temp;
}
catch(Exception e)
{
System.out.println(“ Exception => ” + e);
}
}
}
CLIENT OUTPUT:
Enter the value of m : 7
Enter no. of frames to be sent:5
Enter data for frame no 0 => 1
Enter data for frame no 1 => 2
Enter data for frame no 2 => 3
Enter data for frame no 3 => 4
Enter data for frame no 4 => 5
Connected with server.
|0||1||2||3||4|
Sending frame:0
Acknowledgement of frame no 0 recieved.
Sending frame:1
Sending frame:2
Sending frame:3
Sending frame:4
Sending frame:5

SERVER OUTPUT:
Server established.
Client is now connected.
|0||1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||3
5||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||6
4||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||9
3||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||116||117||118||119||120||1
21||122||123||124||125||126||0|
Frame 0 recieved
Data:0
Acknowledgement sent
|1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||
36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||64||
65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||93||
94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||116||117||118||119||120||121|
|122||123||124||125||126||0||1|
Frame 1 recieved
Data:1
Error found. Acknowledgement not sent.
|2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||3
6||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||64||6
5||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||93||9
4||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||116||117||118||119||120||121||1
22||123||124||125||126||0||1||2|
Frames recieved not in correct order
Expected farme:1
Recieved frame no :2
|3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||
37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||64||65||
66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||93||94||
95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||116||117||118||119||120||121||122
||123||124||125||126||0||1||2||3|
Frames recieved not in correct order
Expected farme:1
Recieved frame no :3
|4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||3
7||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||64||65||6
6||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||93||94||9
5||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||116||117||118||119||120||121||122||1
23||124||125||126||0||1||2||3||4|
Frames recieved not in correct order
Expected farme:1
Recieved frame no :4
RESULT:
Thus the Sliding Window Go Back N & LAN port interface was implemented and the parameters
measured by using LAN-T simulation software.

Exp. No. 3b IMPLEMENTATION AND STUDY OF SELECTIVE REPEAT PROTOCOLS

AIM:
To write a program for sliding window selective repeat Protocol programming to send and
receive message from client and server using connection oriented service.

APPARATUS REQUIERD:
1. JDK TOOLKIT 5.0
2. Standalone desktop.

SENDER PROGRAM :
import java.net.*;
import java.io.*;
import java.rmi.*;
public class slidsender
{
public static void main(String a[])throws Exception
{
ServerSocket ser=new ServerSocket(10);
Socket s=ser.accept();
DataInputStream in=new DataInputStream(System.in);
DataInputStream in1=new DataInputStream(s.getInputStream());
String sbuff[]=new String[8];
PrintStream p;
int sptr=0,sws=8,nf,ano,i;
String ch;
do
{
p=new PrintStream(s.getOutputStream());
System.out.print("Enter the no. of frames : ");
nf=Integer.parseInt(in.readLine());
p.println(nf);
if(nf<=sws-1)
{
System.out.println("Enter "+nf+" Messages to be send\n");
for(i=1;i<=nf;i++)
{
sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8;
}
sws-=nf;
System.out.print("Acknowledgment received");
ano=Integer.parseInt(in1.readLine());
System.out.println(" for "+ano+" frames");
sws+=nf;
}
else
{
System.out.println("The no. of frames exceeds window size");
break;
}
System.out.print("\nDo you wants to send some more frames : ");
ch=in.readLine(); p.println(ch);
}
while(ch.equals("yes"));
s.close();
}
}

RECEIVER PROGRAM:
import java.net.*;
import java.io.*;
class slidreceiver
{
public static void main(String a[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10);
DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
int i=0,rptr=-1,nf,rws=8;
String rbuf[]=new String[8];
String ch; System.out.println();
do
{
nf=Integer.parseInt(in.readLine());
if(nf<=rws-1)
{
for(i=1;i<=nf;i++)
{
rptr=++rptr%8;
rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
}
rws-=nf;
System.out.println("\nAcknowledgment sent\n");
p.println(rptr+1); rws+=nf; }
else
break;
ch=in.readLine();
}
while(ch.equals("yes"));
}
SENDER OUTPUT:
Enter the no. of frames: 4
Enter 4 Messages to be send
hiii
how r u
i am fine
how is everyone
Acknowledgment received for 4 frames
Do you wants to send some more frames: no

RECEIVER OUTPUT:
The received Frame 0 is : hiii
The received Frame 1 is : how r u
The received Frame 2 is : i am fine
The received Frame 3 is : how is everyone
Acknowledgment sent
RESULT:
Thus the Java Socket Program for stop and Wait Protocol executed and output is verified
successfully.

Exp. No. 4
IMPLEMENTATION OF HIGH LEVEL DATA LINK CONTROL

AIM:
To write a c program to implement a data link control for bit stuffing method by using C-editor.

APPARATUS REQUIERD:
1. C -editor
2. Standalone desktop.

PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c.
5. Run the program.
6. If any error occurs in the program correct the error and again run the program.
7. Enter the data of message bit.
8. Check the entered data.
9. Stop the program.

PROGRAM :
#include<stdio.h>
#include<conio.h>
void charc(void);
void main()
{
int choice;
while(1)
{
printf("\n\n\n1.character stuffing"); printf("\n\n2.exit");
printf("\n\n\n enter choice"); scanf("%d",& choice);
printf("%d", choice); if(choice>2)
printf("\n\n invalid option....please renter");
switch(choice)
{
case 1:
charc ();
break;
case 2:
exit(0);
}
}
}
void charc(void)
{
char c[50],d[50],t[50];
int i,m,j;
clrscr();
printf("enter the number of characters\n"); scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
scanf("%c",&c[i]);
}
printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{
if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{
d[j]='d';
j++;
d[j]='l';
j++;
d[j]='e';
j++;
m=m+3;
}
d[j]=c[i];
}
m=m+6;
m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n"); for(i=0;i<m; i ++)
{
printf ("%c",d[i]);
}
for(i=6,j=0;i<m-6;i++,j++)
{
if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'
&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}
printf("\n\n received data:");
for(i=0;i<j; i++)
{printf("%c", t[i]);
}
}

OUTPUT:
RESULT:
Thus the program for implementation of a data link control for bit stuffing method is executed
and output is verified successfully.

Exp. No. 5
IMPLEMENTATION OF IP COMMANDS SUCH AS PING, TRACEROUTE, NSLOOKUP

AIM:
To write a java program for ping, traceroute, nslookup commands of socket programming.

APPARATUS REQUIERD:
1. JDK TOOLKIT 5.0
2. Standalone desktop

PROGRAM (for Ping):


import java.io.*;
import java.net.*;
import java.lang.*;
class ping
{
public static void main(String args[]){
BufferedReader in;
try{
Runtime r = Runtime.getRuntime();
Process p = r.exec("ping www.google.com");
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
if(p==null)
System.out.println("could not connect");
while((line=in.readLine())!=null){
System.out.println(line);
//in.close();
}
}catch(IOException e){
System.out.println(e.toString());
}
}
}

OUTPUT:
Pinging to www.google.com [74.125.28.106]
over a maximum of 30 hops:
1 70 ms 55 ms 70 ms 10.228.129.13
2 87 ms 84 ms 10.228.149.14
3 82 ms 85 ms 116.202.226.145
4 95 ms 94 ms 136 ms 10.228.158.82
5 Request timed out.
6 53 ms 55 ms 59 ms 116.202.226.21
7 85 ms 74 ms 82 ms 72.14.205.145
8 76 ms 75 ms 71 ms 72.14.235.69
9 124 ms 114 ms 113 ms 216.239.63.213
10 181 ms 194 ms 159 ms 66.249.95.132
11 285 ms 247 ms 246 ms 209.85.142.51
12 288 ms 282 ms 283 ms 72.14.233.138
13 271 ms 283 ms 274 ms 64.233.174.97
14 Request timed out.
15 269 ms 273 ms 283 ms pc-in-f106.1e100.net [74.125.28.106]
Ping complete.
PROGRAM (for Traceroute):
import java.io.*;
import java.net.*;
import java.lang.*;
class Traceroute
{
public static void main(String args[]){
BufferedReader in;
try{
Runtime r = Runtime.getRuntime();
Process p = r.exec("tracert www.google.com");
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
if(p==null)
System.out.println("could not connect");
while((line=in.readLine())!=null){
System.out.println(line);
//in.close();
}
}catch(IOException e){
System.out.println(e.toString());
}
}
}

OUTPUT:
Tracing route to www.google.com [74.125.28.106]
over a maximum of 30 hops:
1 70 ms 55 ms 70 ms 10.228.129.13
2 87 ms 84 ms 10.228.149.14
3 82 ms 85 ms 116.202.226.145
4 95 ms 94 ms 136 ms 10.228.158.82
5 Request timed out.
6 53 ms 55 ms 59 ms 116.202.226.21
7 85 ms 74 ms 82 ms 72.14.205.145
8 76 ms 75 ms 71 ms 72.14.235.69
9 124 ms 114 ms 113 ms 216.239.63.213
10 181 ms 194 ms 159 ms 66.249.95.132
11 285 ms 247 ms 246 ms 209.85.142.51
12 288 ms 282 ms 283 ms 72.14.233.138
13 271 ms 283 ms 274 ms 64.233.174.97
14 Request timed out.
15 269 ms 273 ms 283 ms pc-in-f106.1e100.net [74.125.28.106]
Trace complete.

RESULT:
Thus the java Socket Program for ping and traceroute commands is executed and output is verified
successfully.

Exp. No. 6
IMPLEMENTATION OF IP ADDRESS CONFIGURATION.

AIM:
To write a program for implementation of IP address configuration.
APPARATUS REQUIERD:
1. JDK TOOLKIT 5.0
2. Standalone desktop

PROGRAM:
import java.net.*;
import java.io.*;
import java.util.*;
import java.net.InetAddress;
public class JavaProgram
{
public static void main(String args[]) throws Exception
{
// Returns the instance of InetAddress containing
// local host name and address
InetAddress localhost = InetAddress.getLocalHost();
System.out.println("System IP Address : " +
(localhost.getHostAddress()).trim());
// Find public IP address
String systemipaddress = "";
try
{
URL url_name = new URL("http://bot.whatismyipaddress.com");
BufferedReader sc =
new BufferedReader(new InputStreamReader(url_name.openStream()));
// reads system IPAddress
systemipaddress = sc.readLine().trim();
}
catch (Exception e)
{
systemipaddress = "Cannot Execute Properly";
}
System.out.println("Public IP Address: " + systemipaddress +"\n");
}
}

OUTPUT:
System IP Address : 10.0.8.204
Public IP Address : 35.166.48.97
RESULT:
Thus the java socket program for IP address configuration executed and output is verified
successfully.

Exp. No. 7 PERFORMANCE ANALYSIS OF CSMA/CA AND CSMA/CD PROTOCOLS

AIM:
To create scenario and study the performance of CSMA / CD protocol through simulation.

SOFTWARE REQUIREMENTS:
Ns-2

PROCEDURE:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on tracefile.
4. Create six nodes that forms a network numbered from 0 to 5
5. Create duplex links between the nodes and add Orientation to the nodes for setting a LAN
topology.
6. Setup TCP Connection between n(0) and n(4)
7. Apply FTP Traffic over TCP
8. Setup UDP Connection between n(1) and n(5)
9. Apply CBR Traffic over UDP.
10. Apply CSMA/CA and CSMA/CD mechanisms and study their performance
11. Schedule events and run the program.

PROGRAM:
CSMA/CA:
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 color red
$n1 shape box
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Ca Channel]
Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
# next procedure gets two arguments: the name of the
# tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""
# PPP
$ns at 125.0 "finish"
$ns run
OUTPUT:
CSMA/CD:
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 color red
$n1 shape box
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
# next procedure gets two arguments: the name of the
# tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""
# PPP
$ns at 125.0 "finish"
$ns run

OUTPUT:
RESULT:
Thus, the performance of CSMA / CD protocol was studied through simulation.

Exp. No. 8 NETWORK TOPOLOGY - STAR, BUS, RING

AIM:
To implement the Network Topology using Cisco Packet Tracer.

SOFTWARE USED:
Cisco Packet Tracer 7.2

PROCEDURE:

Step 1: Open Cisco Packet Tracer Student

Step 2: Create a new file using File -> New

Step 3: At the left bottom panel selec Switches(1) and then choose first switch 2950-24(2).
Step 4: Select the Switch 2950-24, then place it on the screen, repeat this step four times.
Step 5: Again go to the left bottom panel, select End Devices(3), then choose Generic PC(4)

Step 6: Click Generic PC and place it on the screen, Repeat this step four times.
Step 7: Now select Connections(5) and choose Automatic Type(6)
Step 8: Connect the switches and PC's and rename all the PC's with the IP address as shown below
for Bus Topology.

Step 9: Connect the switches and PC's and rename all the PC's with the IP address as shown below
for Star Topology.
Step 10: Connect the switches and PC's and rename all the PC's with the IP address as shown below
for Ring Topology.

Step 11: Click on each PC, click Desktop, then IP Configuration.


Step 12: Set an IP Address (Ex. 192.168.1.1) and then click subnet mask, here address will be
automatically assigned.

Step 13: Repeat Step11 for all pC's (Ex. 192.168.1.2, 192.168.1.3, 192.168.1.4, ...)
[Note: IP address labelled and the IP address you set in each PC must be same]

Step 14: After all the topologies are formed, now select Add Simple PDU(7), then click on any of the
two PC's and see whether the connections are successful(8).
Step 15: Repeat Step 14 for all the topologies to check whether connections are successful.

RESULT:
The Network Topoloies using Cisco Packet Tracer are implemented successfully.

Exp. No. 9 IMPLEMENTATION OF DISTANCE VECTOR ROUTING ALGORITHM

AIM:
To simulate and study the Distance Vector routing algorithm using simulation.

SOFTWARE REQUIRED:
NS-2

THEORY:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network for computing
shortest path between source and destination. The Router is one main devices used in a wide area
network. The main task of the router is Routing. It forms the routing table and delivers the packets
depending upon the routes in the tableeither directly or via an intermediate devices.
Each router initially has information about its all neighbors. Then this information will be shared among
nodes.

ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute
name on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.

PROGRAM:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

OUTPUT:
RESULT:
Thus the Distance vector Routing Algorithm was Simulated and studied.
Exp. No. 10 IMPLEMENTATION OF LINK STATE ROUTING ALGORITHM

AIM:
To simulate and study the link state routing algorithm using simulation.

SOFTWARE REQUIRED:
NS-2

PROCEDURE:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose Link state routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.

PROGRAM:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto LS
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

OUTPUT:
RESULT:
Thus the Link State Routing Algorithm was Simulated and studied.
Exp. No. 11 STUDY OF NETWORK SIMULATOR (NS) AND SIMULATION OF CONGESTION
CONTROL ALGORITHMS USING NS

AIM:
To Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS Tool.

NETWORK SIMULATOR (NS2):


Ns overview
Ns programming: A Quick start.
Case study I: A simple Wireless network.
Case study II: Create a new agent in Ns.

Ns overview
Ns Status
Periodical release (ns-2.26, Feb 2003)
Platform support
FreeBSD, Linux, Solaris, Windows and Mac

Ns functionalities
Routing, Transportation, Traffic sources, queuing
disciplines, QoS
Wireless
Ad hoc routing, mobile IP, sensor-MAC
Tracing, visualization and various utilities
NS (Network Simulators)

Most of the commercial simulators are GUI driven, while some network simulators are CLI driven.
The network model / configuration describe the state of the network (nodes, routers, switches, and
links) and the events (data transmissions, packet error etc.). An important output of simulations is the
trace files. Trace files log every packet, every event that occurred in the simulation and are used for
analysis. Network simulators can also provide other tools to facilitate visual analysis of trends and
potential trouble spots.

Most network simulators use discrete event simulation, in which a list of pending "events" is stored, and
those events are processed in order, with some events triggering future events such as the event of
the arrival of a packet at one node triggering the event of the arrival of that packet at a
downstream node.

Simulation of networks is a very complex task. For example, if congestion is high, then estimation of
the average occupancy is challenging because of high variance. To estimate the likelihood of a buffer
overflow in a network, the time required for an accurate answer can be extremely large.
Specialized techniques such as "control varieties" and "importance sampling" have been developed to
speed simulation.

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

There are a wide variety of network simulators, ranging from the very simple to the very complex.
Minimally, a network simulator must enable a user to represent a network topology, specifying the
nodes on the network, the links between those nodes and the traffic between the nodes. More
complicated systems may allow the user to specify everything about the protocols used to handle
traffic in a network. Graphical applications allow users to easily visualize the workings of their
simulated environment. Text-based applications may provide a less intuitive interface, but may permit
more advanced forms of customization.

Packet loss:
Occurs 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 mbps), 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 band widths. 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) has discussed and studied.

Exp. No. 12 IMPLEMENTATION OF ENCRYPTION AND DECRYPTION ALGORITHMS USING ANY


PROGRAMMING LANGUAGE

AIM:
To implement the Encryption and Decryption of a file using RC4 algorithm.

APPARATUS REQUIERD:
Java JDK 5.0.
Personal COMMUNICATION.

PROCEDURE:
Initial Setup:
Install Java JDK 5.0.
Browse C:\Lantrain\DataSecurity.
Copy the RC4 folder and three class files (Connect, RC4Client, and Server) and paste it into
the Java\jdk1.5\bin folder in both the server and client PC’s.
Setting up the Server:
Open the command prompt window (Start _Run _ type cmd).
Browse the java bin folder.
Type java Server to run the server.

Encrypting a file:
1. Open command prompt in the client side.
2. Browse the java bin folder.
3. Type java RC4Client.
4. Enter the IP address of the server.
5. Enter the mode of operation.
6. Enter the Encryption key not more than 5 characters.
7. Enter the path name of the file to be encrypted. (For e.g.: c:\\abc.txt)
8. Type YES if you like to close the session or type NO if you like to continue decrypting the
Cipher text
9. The encrypted text is available in c:\output.tx .Try to re-arrange the cipher text using any
crypt-analysis tool

Decrypting the Cipher text file:


1. Enter the mode of operation as DEC for decrypting the cipher text.
2. Enter the Decryption keys same as used for Encryption.
3. Enter the full path name of the file to be decrypted. (i.e., c:\\output.txt)
4. Find out the decrypted file in c:\\output.txt.

SETTING UP THE SERVER:


MODEL OUT PUTS OF ENCRYPTION:

MODEL OUTPUT OF DECRYPTION:


RESULT:
Thus the data encryption and decryption file using RC4 algorithm was studied and verified.

You might also like