Professional Documents
Culture Documents
EC8563 Comm Networks Lab
EC8563 Comm Networks Lab
NAMAKKAL .
LABORATORY MANUAL
COURSECREDITS : UG Credits: 2
PREREQUISITES :
SOFTWARE
HARDWARE
15 Implementation of CSMA/CD. 81
16 Implementation of CSMA/CA. 88
18 Study of network (NS) and simulation of congestion control algorithm using NS. 105
19 RPC 107
4
IMPLEMENTATIN AND STUDY OF ENCRYPTION AND DECRYPTION
AIM
APPARATUS REQUIRED:
1. PENTIUM – PC
2. C COMPLIER
3. TURBO C
PRINCIPLE:
CRYPTOGRAPHY (secret writing) is the process which uses the encryption and decryption
algorithm. An encryption algorithm transforms the plain-text into ciphertext (unknown format) and
decryption algorithm transforms the ciphertext back into plain-text. The sender uses an encryption
algorithm to send the information in the unknown format and the receiver uses a decryption algorithm
to retrieve the original information.
ALGORITHM:
CLIENT:
• Stop
SERVER:
5
• Display waiting for connection
• Transform the hexcode into the string format using the string builder
• Stop
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
unsigned long modexp(unsigned long msg,unsigned long exp,unsigned long n)
{
unsigned long i,k=1;
for(i=0;i<exp;i++)
k=(k*msg)%n;
return k;
}
int main()
{
unsigned long p,q,e,d,n,z,i,C,M;
int len;
char data[100];
system("clear");
printf("\nEnter the value of P and Q(such that p*q>255 and p not equal to q)\n");
scanf("%lu%lu",&p,&q);
n=p*q;
z=(p-1)*(q-1);
for(i=1;i<z;i++)
{
if((z%i)==0)
continue;
else
break;
}
e=i;
printf("\nEncryption key is:%lu",e);
6
for(i=1;i<z;i++)
if(((e*i-1)%z)==0)
break;
d=i;
printf("\nDecryption key is:%lu",d);
printf("\nPls enter the message:");
scanf("%s",data);
len=strlen(data);
for(i=0;i<len;i++)
{
M=(unsigned long)data[i];
C=modexp(M,e,n);
printf("\nEncrypted value its char representation:%lu\t%c\t\n",C,C);
M=modexp(C,d,n);
printf("\nDecrypted value and its char representation:%lu\t%c\t\n",M,M);
}
return 0;
getch();
}
OUTPUT:
RESULT:
Thus the encryption and decryption concept using java is implemented successfully.
7
VIVA QUESTIONS:
Congestion in a network occurs if user sends data into the network at a rate greater than that allowed
by network resources.
Congestion occurs because the switches in a network have a limited buffer size to store arrived
packets before processing.
Data encryption refers to mathematical calculations and algorithmic schemes that transform plaintext
into cyphertext, a form that is non-readable to unauthorized parties. The recipient of an encrypted
message uses a key which triggers the algorithm mechanism to decrypt the data, transforming it to the
original plaintext version.
An public-key encryption technology developed by RSA Data Security, Inc. The acronym stands for
Rivest, Shamir, and Adelman, the inventors of the technique. The RSA algorithm is based on the fact
that there is no efficient way to factor very large numbers. Deducing an RSA key, therefore, requires
an extraordinary amount of computer processing power and time.The RSA algorithm has become the
de facto standard for industrial-strengthencryption, especially for data sent over the Internet.
The FECN bit is used to warn the receiver of congestion in the network. The sender andreceiver are
communication with each other and are using some type of flow control at a higher level.
8
ERROR DETECTION USING HAMMING CODE
#include<stdlib.h>
#include<stdio.h>
char data[5];
int encoded[8], edata[7], syndrome[3];
int hmatrix[3][7]={1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,0,1};
char gmatrix[4][8]={"0111000","1010100","1100010","1110001"};
int main()
{
int i,j;
system("clear");
printf("Hamming Code --- Encoding\n");
printf("Enter 4 bit data:");
scanf("%s",data);
printf("Generator MAtrix\n");
for(i=0;i<4;i++)
printf("\t%s\n",gmatrix[i]);
printf("Encoded Data:");
for(i=0;i<7;i++)
{
for(j=0;j<4;j++)
encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0'));
encoded[i]=encoded[i]%2;
printf("%d",encoded[i]);
}
printf("\nHamming Code --- Decoding\n");
printf("Enter Encoded bits as received:");
for(i=0;i<7;i++)
scanf("%d",&edata[i]);
for(i=0;i<3;i++)
{
for(j=0;j<7;j++)
syndrome[i]=syndrome[i]+(edata[i]*hmatrix[i][j]);
syndrome[i]=syndrome[i]%2;
}
for(j=0;j<7;j++)
if((syndrome[0]==hmatrix[0][j])&&(syndrome[1]==hmatrix[1][j])&&(syndrome[2]==hmatrix[2][j]))
break;
if(j==7)
printf("Data is error free\n");
else
{
9
printf("Errorn received at bit number %d of the data\n",j+1);
edata[j]=!edata[j];
printf("The correct data should be:");
for(i=0;i<7;i++)
printf("%d",edata[i]);
}
}#include<stdlib.h>
#include<stdio.h>
char data[5];
int encoded[8], edata[7], syndrome[3];
int hmatrix[3][7]={1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,0,1};
char gmatrix[4][8]={"0111000","1010100","1100010","1110001"};
int main()
{
int i,j;
system("clear");
printf("Hamming Code --- Encoding\n");
printf("Enter 4 bit data:");
scanf("%s",data);
printf("Generator MAtrix\n");
for(i=0;i<4;i++)
printf("\t%s\n",gmatrix[i]);
printf("Encoded Data:");
for(i=0;i<7;i++)
{
for(j=0;j<4;j++)
encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0'));
encoded[i]=encoded[i]%2;
printf("%d",encoded[i]);
}
printf("\nHamming Code --- Decoding\n");
printf("Enter Encoded bits as received:");
for(i=0;i<7;i++)
scanf("%d",&edata[i]);
for(i=0;i<3;i++)
{
for(j=0;j<7;j++)
syndrome[i]=syndrome[i]+(edata[i]*hmatrix[i][j]);
syndrome[i]=syndrome[i]%2;
}
for(j=0;j<7;j++)
if((syndrome[0]==hmatrix[0][j])&&(syndrome[1]==hmatrix[1][j])&&(syndrome[2]==hmatrix[2][j]))
break;
if(j==7)
printf("Data is error free\n");
10
else
{
printf("Errorn received at bit number %d of the data\n",j+1);
edata[j]=!edata[j];
printf("The correct data should be:");
for(i=0;i<7;i++)
printf("%d",edata[i]);
}
}
OUTPUT:
11
RESULT:
Thus the implementation of error correction and detection using hamming code was successfully
executed.
12
LINK STATE ROUTING
AIM:
APPARATUS REQUIRED:
1. PENTIUM – PC
2. C COMPLIER
3. TURBO C
PRINCIPLE:
PROCEDURE:
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<math.h>
13
#define IN 99
#define N 6
int dijkstra(int cost[][N],int source,int target);
char
interface[6][6][20]={{"0","0","0","0","0","0"},{"0","0","192.1.1.1","0","200.1.1.1"},{"0","0","0","0",
"198.1.1.2","0"},{"0","192.1.1.3","0","198.1.1.3","0","200.1.1.2"},{"0","0","200.1.1.3","0","200.1.1.4
","0"}};
int main()
{
int cost[N][N],i,j,w,ch,co;
char ip[10];
int source,target,x,y;
printf("\t the shortest path algorithm(DIJKSRTRA'S ALGORITHM in c\n\n");
for(i=1;i<N;i++)
for(j=1;j<N;j++)
cost[i][j]=IN;
for(x=1;x<N;x++)
{
for(y=x+1;y<N;y++)
{
printf("enter the weight of the path between node%d and %d:",x,y);
scanf("%d",&w);
cost[x][y]=cost[y][x]=w;
}
printf("\n");
}
for(x=1;x<N;x++)
{
for(y=1;y<N;y++)
{
printf("%s:\t",interface[x][y]);
//scanf("%s",&ip);
//interface[x][y][20]=ip;
}
printf("\n");
}
printf("\nEnter the source:");
scanf("%d",&source);
printf("\nEnter the target");
scanf("%d",&target);
co=dijsktra(cost,source,target);
printf("\nThe Shortest Path:%d",co);
return 0;
}
14
{
int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j,x,y;
char path[N];int path1[N];
for(i=0;i<N;i++)
{
dist[i]=IN;
prev[i]=-1;
}
start=source;
selected[start]=1;
dist[start]=0;
while(selected[target]==0)
{
min=IN;
m=0;
for(i=1;i<N;i++)
{
d=dist[start]+cost[start][i];
if(d<dist[i]&&selected[i]==0)
{
dist[i]=d;
prev[i]=start;
}
if(min>dist[i]&&selected[i]==0)
{
min=dist[i];
m=i;
}
}
start=m;
selected[start]=1;
}
start=target;
j=0;
while(start!=-1)
{
path[j++]=start+64;
path1[j++]=start;
start=prev[start];
}
path[j]='\0';
strrev(path);
printf("%s",path);
printf("\n");
for(j=j-1;j>=0;j--)
{
15
printf("%d\t",path1[j]);
if(j>0)
{
x=path1[j];
y=path1[j-1];
printf("%s\t%s\n",interface[x][y],interface[y][x]);
}
}
return dist[target];
}
OUTPUT:
RESULT:
Thus the link state algorithm was implemented and the output was verified.
16
VIVA QUESTIONS:
The basic concept of link-state routing is that every node constructs a map of the connectivity to the
network, in the form of a graph, showing which nodes are connected to which other nodes. Each node
then independently calculates the next best logical path from it to every possible destination in the
network. The collection of best paths will then form the node's routing table.
The network layer is responsible for the source-to-destination delivery of a packet possibly across
multiple networks specific responsibility of a network layer includes the following.
A logical circuit made between the sending and receiving computer. The connection is made after both
computers do handshaking. after the connection; all packets follow the same route and arrive in
sequence.
In datagram approach, each packet is treated independently from all others. Even when one packet
represents just a place of a multipacket transmission, the networks treat if as though it existed alone.
Packets in this technology are referred to as datagrams.
17
DISTANCE VECTOR ROUTING
AIM:
APPARATUS REQUIRED:
1. PENTIUM – PC
2. C COMPLIER
3. TURBO C
PRINCIPLE:
It is under dynamic routing algorithm. This algorithm operates by having each route maintains a table
giving the least known distance to reach destination and include line in used to get these. These are
updated by changing information with neighbour. This is called “Bell mann ford algorithm” and “fod
fick” algorithm.
PROCEDURE:
#include<stdlib.h>
#define nul 1000
#define nodes 10
int no;
struct node
{
int a[nodes][4];
}router[nodes];
void init(int r)
{
18
int i;
19
for(i=1;i<=no;i++)
{
router[r].a[i][1]=i;
router[r].a[i][2]=999;
router[r].a[i][3]=nul;
}
router[r].a[r][2]=0;
router[r].a[r][3]=r;
}
void inp(int r)
{
int i;
printf("\nEnter distance from the node %d to other nodes",r);
printf("\nPls Enter 999 of there is no direct route\n",r);
for(i=1;i<=no;i++)
{
if(i!=r)
{
printf("\nEnter dist to node %d:",i);
scanf("%d",&router[r].a[i][2]);
router[r].a[i][3]=i;
}
}
}
void display(int r)
{
int i,j;
printf("\n\nThe routing table for node %d is as follows:",r);
for(i=1;i<=no;i++)
{
if(router[r].a[i][2]>=99)
printf("\n\t\t\t%d\tno link\tno hop",router[r].a[i][1]);
else
printf("\n\t\t\t%d\t\t%d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
}
}
void dv_algo(int r)
{
int i,j,z;
for(i=0;i<=no;i++)
{
if(router[r].a[i][2]!=999&&router[r].a[i][2]!=0)
{
for(j=1;j<=no;j++)
{
z=router[r].a[i][2]+router[i].a[j][2];
20
if(router[r].a[j][2]>z)
{
router[r].a[j][2]=z;
router[r].a[j][3]=i;
}
}
}
}
}
int main()
{
int i,j,x,y;
char choice;
printf("Enter the no.of nodes required(less than 10 pls):");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
init(i);
inp(i);
}
printf("\nTne configuration of the nodes after initialization is as follows:");
for(i=1;i<=no;i++)
display(i);
for(i=1;i<=no;i++)
dv_algo(i);
printf("\nThe configuration of the nodes after computation of paths is as follows:");
for(i=1;i<=no;i++)
display(i);
while(1)
{
printf("\n\nWanna continue (y/n):");
scanf("%c",&choice);
if(choice=='n')
break;
printf("\nEnter the nodes btn which the shortest path is to be found:\n");
scanf("%d%d",&x,&y);
printf("\nThe length of the shortest path is %d",router[x].a[y][2]);
}
}
21
OUTPUT:
RESULT:
Thus the distance vector routing algorithm was implemented and the output was verified.
22
VIVA QUESTIONS:
Routing is the process of selecting paths in a network along which to send network traffic. Routing
isperformed for many kinds of networks, including the telephone network (Circuit
switching),electronicdata networks (such as the Internet), and transportation networks.
A distance-vector routing protocol is one of the two major classes of routing protocols, the other
majorclass being the link-state protocol. A distance-vector routing protocol requires that a router
informs itsneighbors of topology changes periodically. Compared to link-state protocols, which
require a router toinform all the nodes in a network of topology changes, distance-vector routing
protocols have lesscomputational complexity and message overhead.
The simplest form of error detection is to append a single bit called a parity bit to a string of data.
The number of bits positions in which two codeword differ is called the hamming distance.
Codeword is the encoded block of ‘n’ bits. It contains message bits and redundant bits.
Block length: the number of bits ‘n’ after coding is called the block length of the code
23
PROGRAM FOR PING
AIM:
To write a socket program for PING in Java.
APPARATUS REQUIRED:
1. PENTIUM – PC
2. Jdk 1.7
3. Java software
ALGORITHM:
PING program
import java.util.*;
public class PingDemo
{
public void Ping(String host)
{
try
{
Process p=Runtime.getRuntime().exec("Ping "+host);
Scanner scan=new Scanner(p.getInputStream());
while(scan.hasNextLine())
{
System.out.println(scan.nextLine());
}
}
catch(Exception ex)
{
System.out.println("error"+ex);
}
}
public static void main(String args[])
{
PingDemo P1=new PingDemo();
P1.Ping(args[0]);
24
}
}
OUTPUT:
RESULT:
Thus the socket programming for Ping using Java was written and executed successfully.
25
VIVA QUESTIONS:
1. What is PING?
2. What is the use of PING?
3. What is a message queue?
4. What are RAW sockets?
5. What are public and private ports?
6. What is a Java bean?
26
27
PROGRAM FOR TRACE ROUTE
AIM:
To write a socket program for TRACE ROUTE in Java.
TRACEROUTE Command
1. The trace route command is used to discover the routes that packets actually take when
traveling to their destination. The device (for example, a router or a PC) sends out a
sequence of User Datagram Protocol (UDP) data grams to an invalid port address at the
remote host.
2. Three data grams are sent, each with a Time-To-Live (TTL) field value set to one. The
TTL value of 1 causes the datagram to "timeout" as soon as it hits the first router in the
path; this router then responds with an ICMP Time Exceeded Message (TEM) indicating
that the datagram has expired.
3. Another three UDP messages are now sent, each with the TTL value set to 2, which
causes the second router to return ICMP TEMs. This process continues until the packets
actually reach the other destination.
4. Since these data grams are trying to access an invalid port at the destination host, ICMP
Port Unreachable Messages are returned, indicating an unreachable port; this event
signals the Trace route program that it is finished.
ALGORITHM
Ping Server
1. Start the program.
2. Import necessary packages.
3. Initialize the ping server with both sockets as null value.
4. Start the server socket.
5. At the client give the IP address of the server.
6. The client program is then started by starting socket.
7. At the receiver end, the client is pinged.
8. Stop the program.
Ping Client
1. Start the program.
2. Import necessary packages.
3. Initialize the ping client with both sockets as null value.
4. Start the socket.
5. Get the IP address of the server.
28
6. Ping the server.
7. At the receiver end, the server is pinged.
8. Stop the program.
SOURCE CODE
//pingclient.java
import java.io.*;
import java.net.*;
import java.util.Calendar;
class pingclient
{
public static void main(String args[])throws Exception
{
String str;
int c=0;
long t1,t2;
Socket s=new Socket("127.0.0.1",5555);
DataInputStream dis=new DataInputStream(s.getInputStream());
PrintStream out=new PrintStream(s.getOutputStream());
while(c<4)
{
t1=System.currentTimeMillis();
str="Welcome to network programming world";
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
{
public static void main(String args[])throws Exception
{
ServerSocket ss=new ServerSocket(5555); Socket
s=ss.accept();
int c=0;
29
while(c<4)
{
DataInputStream dis=new DataInputStream(s.getInputStream());
PrintStream out=new PrintStream(s.getOutputStream());
String str=dis.readLine();
out.println("Reply from"+InetAddress.getLocalHost()+";Length"+str.length()); c++;
}
s.c lose();}}
OUTPUT
C:\>javac pingserver.java
Note: pingserver.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\>java pingserver
C:\>javac pingclient.java
Note: pingclient.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\>java pingclient
Reply from welcome-PC/192.168.1.100;Length36; TTL=50ms
Reply from welcome-PC/192.168.1.100;Length36; TTL=0ms
Reply from welcome-PC/192.168.1.100;Length36; TTL=0ms
Reply from welcome-PC/192.168.1.100;Length36; TTL=0ms
RESULT
Thus the socket programming for Trace route using Java was written and executed successfully
30
VIVA QUESTIONS:
1. What is traceroute?
2. How does the race condition occur?
3. What does a socket consists of?
4. What is the difference between a NULL pointer and a void pointer?
5. What is encapsulation techniques?
31
NSLOOKUP COMMAND
AIM:
To write a program in java to demonstrate the usage of nslookup command.
ALGORITHM:
SOURCE CODE:
import java.io.*;
import java.net.*;
class Server
{
public static void main(String args[])
{
try
{
String str;
BufferedReader buf1=new BufferedReader(new
InputStreamReader(System.in));
String ip=buf1.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("nslookup" + ip);
InputStream in=p.getInputStream();
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
while((str=buf2.readLine())!=null)
{
System.out.println(" " + str);
}
}
catch(Exception e)
32
System.out.println(e.getMessage());
OUTPUT
> www.google.com
Server: UnKnown
Address: 172.15.150.99
RESULT
Thus the socket programming for Nslookup using Java was written and executed successfully
33
VIVA QUESTIONS:
1. What is nslookup?
2. What is the use of nslookup?
3. How sockets can be used to write client-server application using a connection-oriented client-
server technique?
4. What this function nslookup does?
5. What this function DNS does?
34
IMPLEMENTATION OF IP ADDRESS CONFIGURATION
AIM:
To write a program in java to implement IP address configuration..
ALGORITHM:
SOURCE CODE:
import java.io.*;
import java.net.*;
class Server
{
public static void main(String args[])
{
try
{
String str;
BufferedReader buf1=new BufferedReader(new
InputStreamReader(System.in));
String ip=buf1.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("ipconfig " + ip);
InputStream in=p.getInputStream();
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
while((str=buf2.readLine())!=null)
{
System.out.println(" " + str);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
35
OUTPUT:
C:\Program Files\Java\jdk1.6.0\bin>ipconfig
Windows IP Configuration
RESULT
Thus the program for IP Address Configurationusing Java was written and executed successfully.
36
VIVA QUESTIONS:
1. What is IP CONFIG?
2. How to get a valid ipconfig?
3. What is TCP/IP configuration?
4. What are the parameters ipconfig displays?
5. What is the use of DNS and DHCP in ipconfig?
37
IMPLEMENTATION AND STUDY OF STOP & WAIT PROTOCOL
AIM
APPARATUS REQUIRED:
1. Pentium – PC
2. Eclipse
3. Java
PRINCIPLE:
• Protocols in which the sender sends a frame and then waits for an acknowledgement before
proceeding are called “STOP & WAIT” protocol.
• The sender in this protocol simply receives a packet from the network layer copies it into a frame,
and then transmit it.
• After transmission, the sender will go to busy waits state until an acknowledgement is received
from the receiver.
• Once a frame is received it passes the data packet to the network layer and sends an
acknowledgement for the frame it just received.
• It then loops back to busy waiting and the process continues until the End of File is reached.
• In this protocol, there can be only one outgoing frame at a time so no sequence numbers are
required.
• The acknowledgement sent by the receiver to the sender is nothing more than an empty frame.
SERVER SIDE
11. Stop
CLIENT SIDE
6. Write message
11. Stop
39
STOP AND WAIT PROGRAM
SERVER
import java.io.*;
import java.net.*;
try
int ackno = 0;
for(int i=0;i<Integer.parseInt(framelength);i++)
frame = (String)in.readObject();
if(ackno == 0)
ackno = 1;
else
ackno = 0;
out.writeObject(ack);
in.close();
out.close();
ss.close();
catch(Exception e)
41
{
System.out.println("Error:" + e);
CLIENT
import java.io.*;
import java.net.*;
try
42
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
frame = "program";
//3. send the frame length to server to control loop operation in server
out.writeObject(Integer.toString(frame.length()));
int frameno = 0;
subframe = frame.substring(i,i+1);
if(frameno == 0)
frameno = 1;
else
frameno = 0;
ack = (String)in.readObject();
in.close();
out.close();
43
con.close();
catch(Exception e)
System.out.println("socket error:"+e);
OUTPUT:
CLIENT:
44
Ack received from Server : ack0
SERVER:
RESULT
Thus the “STOP AND WAIT” protocol programmed using java was implemented successfully
45
VIVA QUESTIONS:
Data can be corrupted during transmission. Transmission errors detected at physical layer of OSI
model. Transmission errors corrected at the data link layer.
Data link layer is the second layer in OSI model. The DLL lies between the network layer & physical
layer. It receives services from physical layer and provides services to the network layer. The DLL
isresponsible for carrying a packet from one hop to next hop.
Duties of DLL are Packet zing,Addressing,Error control, Flow control, Medium access control
46
IMPLEMENTATION AND STUDY OF GO-BACK-N PROTOCOL
AIM
APPARATUS REQUIRED:
1. Pentium – PC
2. Eclipse
3. Java
PRINCIPLE:
ALGORITHM
SERVER SIDE
CLIENT SIDE:
GO BACK N PROGRAM
SERVER:
import java.io.*;
import java.net.*;
try
// Initilize socket
48
ServerSocket ss = new ServerSocket(123);
//Get Error on
for(int i=0;i<msgln;i++)
System.out.println((String)in.readObject());
System.out.println((String)in.readObject());
// close objects
49
ss.close();
con.close();
in.close();
catch (Exception e)
System.out.println(“Error: ”+e);
GO BACK N PROGRAM
CLIENT:
import java.io.*;
import java.net.*;
try
// Initilize socket
50
Socket con = new Socket("localhost",123);
int erroron = 2;
out.writeObject(Integer.toString(message.length()));
out.writeObject(Integer.toString(erroron));
// Starting transmission
for(int i=0;i<message.length();i++)
out.writeObject(message.substring(i,i+1));
System.out.println(message.substring(i,i+1));
out.writeObject(message.substring(i,i+1));
System.out.println(message.subSequence(i, i+1));
51
// Close objects
con.close();
out.close();
catch (Exception e)
System.out.println(e);
OUTPUT
============================== client ==========================
Connected with server - IP: 127.0.0.1
t
w
52
o
RESULT
54
IMPLEMENTATION AND STUDY OF SELECTIVE REPEAT PROTOCOL
AIM
APPARATUS REQUIRED:
1. Pentium – PC
2. Eclipse
3. Java
PRINCIPLE:
ALGORITHM:
SERVER SIDE:
55
CLIENT SIDE:
SERVER:
import java.io.*;
import java.net.*;
try
// Initilize socket
56
Socket con = ss.accept();
//Get Error on
for(int i=0;i<msgln;i++)
System.out.println((String)in.readObject());
System.out.println((String)in.readObject());
// close objects
ss.close();
con.close();
in.close();
catch (Exception e)
57
{
System.out.println(“Error : ”+e);
CLIENT
import java.io.*;
import java.net.*;
try
// Initilize socket
int erroron = 3;
out.writeObject(Integer.toString(erroron));
for(int i=0;i<message.length();i++)
out.writeObject(message.substring(i,i+1));
System.out.println(message.substring(i,i+1));
out.writeObject(message.substring(erroron,erroron+1));
System.out.println(message.subSequence(erroron, erroron+1));
// Close objects
con.close();
out.close();
catch (Exception e)
System.out.println(e);
59
OUTPUT
============================== client ==========================
Connected with server - IP: 127.0.0.1
60
N
RESULT:
Thus the “SELECTIVE REPEAT” protocol programmed using java is implemented
successfully.
61
VIVA QUESTIONS:
Block length: the number of bits ‘n’ after coding is called the block length of the code.
62
IMPLEMENTATION OF SLIDING WINDOW PROTOCOL
AIM:
ALGORITHM:
1. Start theprogram.
2. Get the frame size from theuser
3. To create the frame based on the user request. 4.To
send frames to server from the clientside.
5. If your frames reach the server it will send ACK signal to client otherwise itwill
send NACK signal toclient.
6. Stop theprogram
Sender:
import java.net.*;
import java.io.*;
import java.rmi.*;
Socket s=ser.accept();
PrintStream p;
63
int sptr=0,sws=8,nf,ano,i;
64
String ch;
do
p=new PrintStream(s.getOutputStream());
nf=Integer.parseInt(in.readLine());
p.println(nf);
if(nf<=sws-1)
for(i=1;i<=nf;i++)
sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8;
sws-=nf;
else
break;
65
System.out.print("\nDo you wants to send some more frames : ");
ch=in.readLine(); p.println(ch);
while(ch.equals("yes"));
s.close();
Receiver:
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;
{
nf=Integer.parseInt(in.readLine());
if(nf<=rws-1)
{
66
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"));
}
}
67
Output:
RESULT:
Thus the “Sliding window” protocol programmed using java is implemented successfully.
68
TOKEN RING PROTOCOL
AIM:
APPARATUS REQUIRED:
• Pentium pc
PRINCIPLE:
• In the token passing method, the stations in a network are organized In a logical ring.
• In a physical ring topology, when a station sends the token to its successor, the token
• In this, each device has a dedicated point-to-point connection with only the two devices
• In this method, a special packet called token circulates throughout the ring.
• When a station has some data to send, it waits until it receives the token from its
• When the station has no more data to send, it releases the token, passing it to the next
ALGORITHM:
Client 1:
Client 2:
• Start
• Stop
Client 3:
• Start
CLIENT 1
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
{
70
public static void main (String args [])
try
con.close();
catch (SocketException e)
catch(IOException e)
System.out.println("io error:"+e);
CLIENT 2
import java.io.IOException;
71
import java.net.ServerSocket;
import java.net.Socket;
try
providersocket.close();
Thread.sleep(4000);
try
con2.close();
catch(IOException e)
72
{
catch (IOException e)
catch (InterruptedException e)
CLIENT 3
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
73
{
try
providersocket.close();
catch (IOException e)
Client 2:
74
========== Passing Token to next client =========
Client 3 :
Client 1:
Client 2:
(Don’t run program in client2, it is assumed like client 2 disconnected from LAN)
Client 3:
Client 1:
Client 2:
75
Client 3 is disconnected from LAN
Client 3:
(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)
Client 1:
Client 2:
(Don’t run program in client 2 it is assumed like client 2 disconnected from LAN)
Client 3:
(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)
PROCEDURE:
1. Type the Client 1, Client 2 and Client 3 program in three different computers.
2. To verify Case 1: first execute Client 3 then Client 2 then Client 1, so Client 3waiting for token
from Client 2, Client 2 waiting for Token from Client 1, Client 1 starts the token sending, it sends
token to Client 2, now client 2 holds token for 40 seconds then it sends token to Client 3.
3. To verify Case 2: first execute Client 3 then Client 1, don’t execute program in Client 2 (It is
assumed like Client 2 is disconnected from the LAN), Client 1 starts the token sending, it sends token
to Client 2, but Client 2 is disconnected from the LAN, so that, the token ring breaks.
4. To verify Case 3: Don’t execute Client 3 (It is assumed like Client 3 is disconnected from LAN),
execute program in Client 2 then Client 1, Client 1 sends token to Client 2, now Client 2 trying to send
token to Client 3, but Client 3 is disconnected from the LAN, so that, token ring breaks.
5. To verify Case 4 : Don’t execute Client 3 and Client 2 (It is assumed like Client 3 and Client 2 are
disconnected from the LAN). So the token ring process is not initiated at all.
RESULT: Thus, the token ring protocol was programmed using java and implemented successfully in
the laboratory.
76
TOKEN BUS PROTOCOL
AIM:
APPARATUS REQUIRED:
• Pentium pc
PRINCIPLE:
• In this, one long cable acts as a backbone to link all the devices in a network. If the backbone is
broken, the entire segment fails.
• When a station has finished sending its data, it releases the token and inserts the address of its
successor in the token.
• Only the station with address matching the destination address of the token gets thetoken to access
the shared media.
• In the intermediate system fails, the token directly passes to the next available system.But it’s not
applicable in token ring protocol.
ALGORITHM:
CLIENT1:
77
CLIENT 2:
1. Start
CLIENT 3:
1. Start
7. stop
CLIENT 1
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
78
public class cl1
try
con.close();
catch (SocketException e)
try
con2.close();
catch(IOException e2)
79
}
catch(IOException e)
System.out.println("io error:"+e);
CLIENT 2
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
try
80
Socket con = providersocket.accept();
providersocket.close();
Thread.sleep(4000);
try
con2.close();
catch(IOException e)
catch (IOException e)
catch (InterruptedException e)
81
}
CLIENT 3
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
try
providersocket.close();
catch (IOException e)
{
82
System.out.println("socket error:" +e);
}
Case 1 : When all the clients connected in LAN
Client 1:
Client 2:
Client 3 :
Client 1:
Client 2:
(Don’t run program in client2, it is assumed like client 2 disconnected from LAN)
83
Client 3:
Client 1:
Client 2:
Client 3:
(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)
Client 1:
Client 2:
(Don’t run program in client 2 it is assumed like client 2 disconnected from LAN)
Client 3:
(Don’t run program in client 3 it is assumed like client 3 disconnected from LAN)
84
PROCEDURE:
1. Type the Client 1, Client 2 and Client 3 program in three different computers.
2. To verify Case 1: first execute Client 3 then Client 2 then Client 1, so Client 3 waiting for token
from Client 2, Client 2 waiting for Token from Client 1, Client 1 starts the token sending, it sends
token to Client 2, now client 2 holds token for 40 seconds then it sends token to Client 3.
3. To verify Case 2: first execute Client 3 then Client 1, don’t execute program in Client 2 (It is
assumed like Client 2 is disconnected from the LAN), Client 1 starts the token sending, it sends token
to Client 2, but Client 2 is disconnected from the LAN, so the token sent to Client 3.
4. To verify Case 3: Don’t execute Client 3 (It is assumed like Client 3 is disconnected from LAN),
execute program in Client 2 then Client 1, Client 1 sends token to Client 2, now Client 2 trying to send
token to Client 3, but Client 3 is disconnected from the LAN, so token not sent to Client 3.
5. To verify Case 4 : Don’t execute Client 3 and Client 2 (It is assumed like Client 3 and Client 2 are
disconnected from the LAN)
RESULT:
Thus, the token bus protocol was programmed using java and implemented successfully.
85
VIVA QUESTIONS:
Token ring local area network (LAN) technology is a local area network protocol which resides at the
data link layer (DLL) of the OSI model. It uses a special three-byte frame called a token that travels
around the ring. Token-possession grants the possessor permission to transmit on the medium. Token
ring frames travel completely around the loop.
Token bus is a network implementing the token ring protocol over a "virtual ring" on a coaxial cable.
A token is passed around the network nodes and only the node possessing the token may transmit. If a
node doesn't have anything to send, the token is passed on to the next node on the virtual ring. Each
node must know the address of its neighbour in the ring, so a special protocol is needed to notify the
other nodes of connections to, and disconnections from, the ring.
3.Define networks.
The links connecting the devices are often called communication channel.
Networks use distributed processing in which a task is divided among multiple computers.
86
IMPLEMENTATION AND STUDY OF CSMA/CD
AIM
To study and implement the Carrier Sense Multiple Access with Collision Detection
APPARATUS REQUIRED:
1. Pentium – PC
2. Eclipse
3. Java
PRINCIPLE:
The Carrier Sense Multiple Access is based on the principle of “SENSE BEFORETRANSMIT”. This
CSMA/CD is generally used in wired networks. It is mainly focused to detect the collision if it has
occurred.
ALGORITHM:
SERVER:
6. Read message
9. Stop
CLIENT:
87
1. Open socket with input address ,port
4. If message not sent, collision occurred (To occur collision don’t run not server)
5. Calculate back of time using random number selection and wait for that time
7. If message not sent, collision occurred, Again calculate back off time by selecting random number,
this trail can be done for 15 times.
CSMA/CD PROGRAM
SERVER:
import java.io.*;
import java.net.*;
try
System.out.println("Connected");
88
ObjectInputStream in = new ObjectInputStream(con.getInputStream());
System.out.println((String)in.readObject());
in.close();
ss.close();
catch(Exception e)
System.out.println(e);
CSMA/CD PROGRAM
CLEINT:
import java.io.*;
import java.net.*;
try
int R = 0;
int Tb = 0;
System.out.println("attempt : "+i);
if(cli.send() == "sent")
{
break;
else
R = 2^i-1;
Tb = R*Tp;
System.out.println("waiting for next attempt with back time (in seconds): "+Tb);
Thread.sleep(Tb);
catch (InterruptedException e)
System.out.println(e);
90
}
String send()
String str=null;
try
out.writeObject(msg);
str = "sent";
catch(Exception e)
return str;
OUTPUT
collision occured
waiting for next attempt with back time (in seconds): 4000
attempt : 2
collision occured
waiting for next attempt with back time (in seconds): 6000
attempt : 3
collision occured
attempt : 4
collision occured
waiting for next attempt with back time (in seconds): 2000
attempt : 5
Connected
CNLAB
PROCEDURE:
92
1. Run the Client program, don’t run server program (consider as to raise collision)
2. Client will try to send the message to server, but server is not running, so the attempt is
failed, so consider as collision occurred.
3. Client will select random number and calculate Back off time and wait for the back off time
and again will try to send the message. This loop continues till the 15 trails.
4. Run the server in between consider as no collision, so message will be sent from client to
server.
RESULT:
93
IMPLEMENTATION AND STUDY OF CSMA/CA
AIM
To study and implement the Carrier Sense Multiple Access with collision avoidance.
APPARATUS REQUIRED:
1. Pentium – PC
2. Eclipse
3. Java
PRINCIPLE:
Carrier sense multiple access with collision avoidance (CSMA/CA) is a method in which carrier
sensing is used, nodes attempt to avoid collisions by transmitting only when the channel is sensed to
be "idle"
ALGORITHM
1. Start
2. Initialize k+0
94
13. Stop
CSMA/CA PROGRAM
CLIENT 1
import java.io.*;
import java.net.*;
try
int R = 0;
System.out.println("attempt : "+k);
// is idle channel?
while(true)
{
System.out.print(i=i+1);
if(cli.isidle())
Thread.sleep(8000);
if(cli.isidle())
System.out.println("Still idle");
R = 2^k-1;
// wait R slot
96
Thread.sleep(R*6000);
// send frame
System.out.println("Message sent");
Thread.sleep(10000);
// ack check
if(cli.isidle())
System.out.println("Ack received");
bln = true;
break;
else
break;
else
97
System.out.println("Busy, goes to channel idle check");
if(bln == true)
break;
catch (InterruptedException e)
System.out.println(e);
Boolean isidle()
try
98
soc.close();
return true;
catch (Exception e)
return false;
CLIENT 2
import java.io.*;
import java.net.*;
try
while(true)
99
{
ss.accept();
ss.close();
System.out.println("Connected");
catch(Exception e)
{
System.out.println(e);
OUTPUT:
attempt : 1
is Channel idle?
123456789101112131415161718192021222324
Case 2: stop client2 on “is still idle” (Channel busy after IFS time)
is Channel idle?
Channel idle
is still idle?
2345678910
attempt : 1
is Channel idle?
Channel idle
is still idle?
Still idle
Message sent
attempt : 2
is Channel idle?
101
============ Client 1 ===============
attempt : 1
is Channel idle?
Channel idle
is still idle?
Still idle
Message sent
Ack received
RESULT:
102
STUDY OF HIGH LEVEL DATA LINK PROTOCOL
Aim:
Introduction:
HDLC - Short for High-level Data Link Control, a transmission protocol used at the data link
layer (layer 2) of the OSI seven layer model for data communications. The HDLC protocol embeds
information in a data frame that allows devices to control data flow and correct errors. HDLC is an ISO
standard developed from the Synchronous Data Link Control (SDLC) standard proposed by IBM in the
1970's. HDLC NRM (also known as SDLC) .HDLC is a bit oriented protocol that supports both half-
duplex and full-duplex communication over point to point & multipoint link.
For any HDLC communications session, one station is designated primary and the other secondary. A
session can use one of the following connection modes, which determine how the primary and secondary
stations interact
• Normal unbalanced: The secondary station responds only to the primary station.
• Asynchronous balanced: Both stations send and receive over its part of a duplex line.
The Link Access Procedure-Balanced (LAP-B) and Link Access Procedure D-channel (LAP-
D) protocols are subsets of HDLC.
LAPB is a bit-oriented synchronous protocol that provides complete data transparency in a full-duplex
point-to-point operation. It supports a peer-to-peer link in that neither end of the link plays the role of
the permanent master station. HDLC NRM, on the other hand, has a permanent primary station with
one or more secondary stations.
The concept of a frame window is used to send multiple frames before receiving confirmation
that the first frame has been correctly been received. This means that data can continue to flow in
situations where there may be long "turn-around" time lagswithout stopping to wait for an
acknowledgement. This kind of situation occurs, for instance in satellite communication.
1. Information frames
• I-frames carry user's data and control information about user's data.
C:\images\Information-frames.jpg• The first bit of control field is always zero, i.e. the presence of
zero at this place indicates that it is I-frame.
• Bit number 2, 3 & 4 in control field is called N(S) that specifies the sequence number of the frame.
Thus it specifies the number of the frame that is currently being sent. Since it is a 3.bit field, only eight
sequence numbers are possible 0, 1,2,3,4,5,6, 7 (000 to 111).
• Bit number 5 in control field is P/F i.e. Poll/Final and is used for these two purposes. It has, meaning
only when it is set i.e. when P/F=1.
(i) It means poll when frame is sent by a primary station to secondary (when address field contains the
address of receiver).
(ii) It means final when frame is sent by secondary to a primary (when the address field contains the
address of the sender).
• Bit number 6, 7, and 8 in control field specifies N(R) i.e. the sequence number of the frame expected
in return in two-way communication.
2. Supervisory frame
• S-frame carries control information, primarily data link layer flow and error controls.
C:\images\Supervisory-frame.jpg•The first two bits in the control field of S-frame are always 10.
2. REJ Reject-used by the receiver to send a NAK when error has occurred.
4. SREJ Selective Reject-indicates to the transmitter that it should retransmit the frame
indicated in the N(R) subfield.
• There is no N(S) field in control field of S-frame as S-frames do not transmit data.
104
• Last three bits in control field indicates N(R) i.e. they correspond to the ACK or NAK value.
3. Unnumbered frame
• U-frames are reserved for system management and information carried by them is used for managing
the link
• U-frames are used to exchange session management and control information between the two
connected devices.
• Information field in U-frame does not carry user information rather, it carries system management
information.
• U-frame is identified by the presence of 11 in the first and second bit position in control field.
C:\images\Unnumbered-frame.jpg• U-frame contains two code fields, one two hit and other three bit.
Address field - Defines the address of the secondary station which is sending the frame or the
destination of the frame sent by the primary station. It contains Service Access Point (6bits), a
Command/Response bit to indicate whether the frame relates to information frames (I-frames) being
sent from the node or received by the node, and an address extension bit which is usually set to true to
indicate that the address is of length one byte. When set to false it indicates an additional byte follows.
Extended address - HDLC provides another type of extension to the basic format. The address field
may be extended to more than one byte by agreement between the involved parties.
Control field - Serves to identify the type of the frame. In addition, it includes sequence numbers,
control features and error tracking according to the frame type.
FCS - The Frame Check Sequence (FCS) enables a high level of physical error control by allowing
the integrity of the transmitted frame data to be checked.
RESULT:
Thus the High level data link control protocol was studied
105
STUDY OFNETWORK SIMULATOR AND SIMULATION OF CONGESTION CONTROL
ALGORITHMS USING NS
Introduction: ns (from network simulator) is a name for series of discrete event network
simulators, specifically ns-1, ns-2 and ns-3. All of them are discrete-event network simulator, primarily
used in research[4] and teaching. ns-3 is free software, publicly available under the GNU GPLv2 license
for research, development, and use.
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
Since the process of creation of a network simulator that contains a sufficient number of highquality
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.it used.
ns-2
In 1996-97, ns version 2 (ns-2) was initiated based on a refactoring by Steve McCanne. Use of
Tcl was replaced by MIT's Object Tcl (OTcl), an object-oriented dialect Tcl. The core of ns-2 is also
written in C++, but the C++ simulation objects are linked to shadow objects in OTcl and variables can
be linked between both language realms. Simulation scripts are written in the OTcl language, an
extension of the Tcl scripting language. Presently, ns-2 consists of over 300,000 lines of source code,
and there is probably a comparable amount of contributed code that is not integrated directly into the
main distribution (many forks of ns-2 exist, both maintained and unmaintained). It runs on GNU/Linux,
FreeBSD, Solaris, Mac OS X and Windows versions that support Cygwin. It is licensed for use under
version 2 of the GNU General Public License
106
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.In the process of developing ns-3, it
was decided to completely abandon backwardcompatibility with ns-2. The new simulator would be
written from scratch, using the C++ programming language. Development of ns-3 began in July 2006.
A framework for generating Python bindings (pybindgen) and use of the Waf build system were
contributed by Gustavo Carneiro. 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.
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. x 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:
107
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, pointto-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
timestamped 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 notable network simulation software are, ordered after how often they are mentioned in
research papers:
1. ns (open source)
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:
108
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 valueof 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 thesystem 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:
109
CONTENT BEYOND THE SYLLABUS EXPERIMENTS
IMPLEMENTATION OF REMOTE PROCEDURE CALL
AIM:
ALGORITHM:
CLIENT SIDE:
1. Establish a connection between the Client and Server.
Socket client=new Socket("127.0.0.1",6555);
2. Create instances for input and output streams.
Print Stream ps=new Print Stream(client.getOutputStream());
3. BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
4. Enter the command in Client Window.
Send themessage to its output str=br.readLine();
ps.println(str);
SERVER SIDE:
1. Accept the connection request by the client.
ServerSocket server=new ServerSocket(6555);
Sockets=server.accept();
2. Getthe IPaddressfromitsinputstream.
BufferedReaderbr1=newBufferedReader(newInputStreamReader(s.getInputStream()));
ip=br1.readLine();
3. During runtime execute the process
Runtime r=Runtime.getRuntime();
Process p=r.exec(str);
Clientrpc:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrpc
110
try
System.out.println("Enter String");
String str=in.readLine();
dout.writeBytes(str+'\n');
clsct.close();
catch (Exception e)
{ System.out.println(e);
Serverrpc:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrpc
111
public static void main(String args[])
try
while(true)
Socket obj1=obj.accept();
Process p=Runtime.getRuntime().exec(str);
catch(Exception e)
System.out.println(e);
112
Output:
RESULT:
113
FILE TRANSFER IN CLIENT & SERVER
AIM:
To Perform File Transfer in Client & Server Using TCP/IP.
CLIENT SIDE:
1. Start.
2. Establish a connection between the Client and Server.
3. Socketss=new Socket(InetAddress.getLocalHost(),1100);
4. Implement a client that can send two requests.
a. To get a file from the server.
b. To put or send a file to the server.
5. After getting approval from the server ,the client either get file from the server or send file to the
server.
SERVER SIDE:
1. Start.
2. Implement a server socket that listens to a particular port number.
3. Server reads the filename and sends the data stored in the file for the‘get’ request.
4. It reads the data from the input stream and writes it to a file in theserver for the ‘put’ instruction.
5. Exit upon client’s request.
6. Stop.
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientfile
try
114
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String str=in.readLine();
dout.writeBytes(str+'\n');
String str2=in.readLine();
String str1,ss;
char buffer[];
while(true)
str1=din.readLine();
if(str1.equals("-1"))
break;
System.out.println(str1);
buffer=new char[str1.length()];
str1.getChars(0,str1.length(),buffer,0);
f.write(buffer);
f.close();
clsct.close();
115
catch (Exception e)
System.out.println(e);
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverfile
try
while(true)
Socket obj1=obj.accept();
String str=din.readLine();
116
String s;
while((s=b.readLine())!=null)
System.out.println(s);
dout.writeBytes(s+'\n');
f.close();
dout.writeBytes("-1\n");
catch(Exception e)
System.out.println(e);
117
Output:
RESULT:
118