Ex.No 1.a) –
IMPLEMENTATION OF TCP SOCKET POGRAMMING
AIM:
To Write a java program to perform TCP socket programming
ALGORITHM:
1.
Start
the Program
2.
Write
the program for both TCP Client and TCP
Server then save it in jdk bin
3.
Establish
socket communication between the client and server
4.
Type
the host name or IP address to establish Connection
5.
Now
we can chat between client and server
6.
Stop
the Program
PROGRAM:
TCP SERVER:
import java.io.*;
import java.net.*;
public class tcpser
{
public static void
main(String a[])throws Exception
{
System.out.println("TCP
SERVER");
System.out.println("server
is ready to connect....");
ServerSocket
Serversoc=new ServerSocket(9);
Socket
clientsoc=Serversoc.accept();
PrintWriter out=new
PrintWriter(clientsoc.getOutputStream(),true);
BufferedReader in=new
BufferedReader(new InputStreamReader(clientsoc.getInputStream()));
String inputline;
BufferedReader
stdin=new BufferedReader(new InputStreamReader(System.in));
try
{
while(true)
{
inputline=stdin.readLine();
out.println(inputline);
System.out.println("client
says:"+in.readLine());
}
}
catch(Exception e)
{
System.exit(0);
}}}
TCP CLIENT:
import java.io.*;
import java.net.*;
public class tcpcli
{
public static void
main(String []args)throws IOException
{
System.out.println("TCPCLIENT");
System.out.println("enter
the host name to connect");
DataInputStream
inp=new DataInputStream(System.in);
String
str=inp.readLine();
Socket clientsoc=new
Socket(str,9);
PrintWriter out=new
PrintWriter(clientsoc.getOutputStream(),true);
BufferedReader in=new
BufferedReader(new InputStreamReader(clientsoc.getInputStream()));
BufferedReader
stdin=new BufferedReader(new InputStreamReader(System.in));
String userinput;
try
{
while(true)
{
userinput=stdin.readLine();
out.println(userinput);
System.out.println("server
says:"+in.readLine());
}
}
catch(Exception e)
{
System.exit(0);}}
}
OUTPUT:
TCP SERVER:
E:\Networklab>javac
tcpser.java
E:\ Networklab >java
tcpser
TCP SERVER
server is ready to connect....
welcome
client says:Hello
TCP CLIENT:
E:\ Networklab >java
tcpcli
TCPCLIENT
enter the host name to connect
lab3-3
Hello
server says:welcome
Ex No:1.b).Program for Client - Server Communication to Display
date using Java
This is a program for
displaying the date from server to client. Client is requesting the server to retrieve the current date.
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Client
{
public static void main(String args[])
{
try
{
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
String str=din.readLine();
dout.writeBytes(str+'\n');
System.out.println(str);
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Server
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
while(true)
{
Socket obj1=obj.accept();
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
Date d=new Date();
String S=d.toString();
dout.writeBytes(S+'\n');
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output
E:\networklab>javac Server.java
E:\networklab>javac Client.java
E:\networklab>java Server
E:\networklab>java Client
Tue Jul 12 22:25:06 PDT 2011
Ex.No 2.a). –
IMPLEMENTATION OF UDP SOCKET POGRAMMING
AIM:
To Write a java program to perform UDP socket programming
ALGORITHM:
1.
Start
the Program
2.
Write
the program for both UDP Client and UDP
Server then save it in jdk bin
3.
Establish
socket communication between the client and server
4.
Type
the host name or IP address to establish Connection
5.
Now
we can chat between client and server
6.
Stop
the Program
PROGRAM:
UDP SERVER:
import java.io.*;
import java.net.*;
class UDPserver1
{
public static void
main(String args[])throws Exception
{
DatagramSocket
serverSocket=new DatagramSocket(9876);
byte[]
receiveData=new byte[1024];
byte[] sendData=new
byte[1024];
while(true)
{
DatagramPacket
receivePacket=new DatagramPacket(receiveData,receiveData.length);
serverSocket.receive(receivePacket);
String sentence=new
String(receivePacket.getData());
System.out.println("RECEIVED"+sentence);
BufferedReader
inFromUser=new BufferedReader(new InputStreamReader(System.in));
String
sentence1=inFromUser.readLine();
InetAddress
IpAddress=receivePacket.getAddress();
int
Port=receivePacket.getPort();
String
capitalizedSentence=sentence1.toUpperCase();
sendData=capitalizedSentence.getBytes();
DatagramPacket
sendPacket=new DatagramPacket(sendData,sendData.length,IpAddress,Port);
serverSocket.send(sendPacket);
}}
}
UDP CLIENT:
import java.io.*;
import java.net.*;
class UDPclient1
{
public static void
main(String args[])throws Exception
{
BufferedReader
inFormUser=new BufferedReader(new InputStreamReader(System.in));
DatagramSocket
clientSocket=new DatagramSocket();
InetAddress
IpAddress=InetAddress.getByName("Localhost");
byte[] sendData=new
byte[1024];
byte[]
receiveData=new byte[1024];
while(true)
{
String
sentence=inFormUser.readLine();
sendData=sentence.getBytes();
DatagramPacket
sendPacket=new DatagramPacket(sendData,sendData.length,IpAddress,9876);
clientSocket.send(sendPacket);
DatagramPacket
receivePacket=new DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
String
modifiedSentence=new String(receivePacket.getData());
System.out.println("FROM
SERVER"+modifiedSentence);
}}
}
OUTPUT:
UDP SERVER:
E:NETWORKLAB>javac UDPserver1.java
E: NETWORKLAB>java UDPserver1
Hai computer networks
Received
system software
UDP CLIENT:
E:\networklab >javac
UDPclient1.java
E:\networklab >java
UDPclient1
Received
Hai computer networks
System software
Ex No:2 b).Program for
Domain Name System (DNS) using UDP
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientdns12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the DOMAIN NAME or IP adress:");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("IP address or DOMAIN NAME:
"+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverdns12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddress
addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String name[]={"www.aptitudeguru.com","www.downloadcyclone.blogspot.com"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(ip[i]))
{
sendbyte=name[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
else if(s.equals(name[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output
E:\networklab >java Serverdns12
E:\networklab >java Clientdns12
Enter the DOMAIN NAME or IP adress:
165.165.80.80
IP address or DOMAIN NAME: www.aptitudeguru.com
E:\networklab >java Clientdns12
Enter the DOMAIN NAME or IP adress:
www.downloadcyclone.blogspot.com
IP address or DOMAIN NAME: 165.165.79.1
Ex.No 3 – RAW SOCKET
PROGRAMMING
AIM:
To Write a java program to perform a raw socket programming
ALGORITHM:
1.
Start
the Program
2.
Write
the program for both Client and Server then save it in jdk bin
3.
Establish
socket communication between the client and server
4.
In
server type a file name which you wants to transfer
5.
That
file is transferred to client
6.
Stop
the Program.
PROGRAM :
RAW
SERVER :
import java.io.*;
import java.net.*;
class Rawserver
{
public static void
main(String args[])throws Exception
{
int i=0;
byte b[]=new
byte[1200];
System.out.println("Enter
the file to be transfered");
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
String
t=br.readLine();
FileInputStream f=new
FileInputStream(t);
DatagramSocket d=new
DatagramSocket(606);
while(f.available()!=0)
{
b[i]=(byte)f.read();
i++;
}
f.close();
DatagramPacket p=new
DatagramPacket(b,i,InetAddress.getLocalHost(),999);
d.send(p);
}}
RAW CLIENT:
import java.io.*;
import java.net.*;
class Rawclient
{
public static void
main(String args[])throws Exception
{
byte b[]=new
byte[1024];
try{
System.out.println("client
started");
DatagramSocket d=new
DatagramSocket(999);
DatagramPacket p=new
DatagramPacket(b,1024);
d.receive(p);
System.out.println(new
String(p.getData(),0,p.getLength()));}
catch(Exception e){
e.printStackTrace();
}}}
OUTPUT:
RAW SERVER:
E:\networklab >java
Rawserver
Enter the file to be
transfered
name.txt
RAW CLIENT
E:\networklab >javac Rawclient.java
E:\networklab >java Rawclient
client started
INDIA
Network
TAMILNADU
Ex.No 4 – SIMULATION OF
SLIDING WINDOW PROTOCOL
AIM:
To Write a java program for implement Sliding Window Protocol
ALGORITHM:
1.
Start
the Program
2.
Read
the window size to be send
3.
Read
the total no of packets
4.
To
check Whether the no of packets is less than window size means read the packet
to kill
5.
Remaining
packets are send to the corresponding destination
6.
Retransmit
the kill packet
7.
Otherwise
all packets are sent to the corresponding destination
8.
Stop
the Program
PROGRAM:
import java.io.*;
class sliding
{
int pak,winsize,pkno;
public sliding() throws Exception
{
DataInputStream ds=new DataInputStream(System.in);
System.out.println("ENTER THE WINDOW SIZE ");
winsize=Integer.parseInt(ds.readLine());
System.out.println("ENTER THE TOTAL NO OF PACKETS ");
pak=Integer.parseInt(ds.readLine());
if(pak<winsize)
{
System.out.println("DO YOU
WANT TO KILL ANY PACKET?? (Y/N)");
String k=ds.readLine();
if(k.equals("Y"))
{
System.out.println("ENTER PACKET NO TO KILL ");
pkno=Integer.parseInt(ds.readLine());
}
}
}
public void selrepeat(int pn) throws Exception
{
System.out.println("Selective repeat of packet" + pn);
System.out.println("Packet " +pn + "send");
System.out.println("Packet" + pn + "Received");
System.out.println("Acknowledge" + pn + "Received");
}
public void trans() throws Exception
{
int dis=0,dis1=0;
for(int i=1; i<=pak;)
{
for(int j=1;j<=winsize
&& i<=pak;j++,i++)
{
if(i==pkno)
{
dis=1;
System.out.println("Packet" + pkno + "Discarded");
System.out.println("Remaining packet to be sent in this seission
is " + (winsize-j));
if(j==winsize)
dis1=1;
Thread.sleep(2000);
}
else
{
System.out.println("Packet" + i + "send");
System.out.println("Packet" + i + "Received");
System.out.println("Acknowledge" + i + "Received");
}
}
if(dis1==1)
{
dis1=0;
continue;
}
if(dis==1)
{
selrepeat(pkno);
dis=0;
}
}
}
public static void main(String args[]) throws Exception
{
sliding s= new sliding(); s.trans(); }
}
OUTPUT:
E:\networklab >java
sliding
ENTER THE WINDOW SIZE
5
ENTER THE TOTAL NO OF
PACKETS
4
DO YOU WANT TO KILL
ANY PACKET?? (Y/N)
Y
ENTER PACKET NO TO
KILL
3
Packet1send
Packet1Received
Acknowledge1Received
Packet2send
Packet2Received
Acknowledge2Received
Packet3Discarded
Remaining packet to
be sent in this seission is 2
Packet4send
Packet4Received
Acknowledge4Received
Selective repeat of
packet3
Packet 3send
Packet3Received
Acknowledge3Received
E:\networklab >java
sliding
ENTER THE WINDOW SIZE
3
ENTER THE TOTAL NO OF
PACKETS
4
Packet1send
Packet1Received
Acknowledge1Received
Packet2send
Packet2Received
Acknowledge2Received
Packet3send
Packet3Received
Acknowledge3Received
Packet4send
Packet4Received
Acknowledge4ReceivedPUT:
Ex.No 5 –
IMPLEMENTATION OF RPC
AIM:
To Write a java program for implementation OF Remote Method Invocation
(RPC) to perform addition of two numbers.
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrpc
{
public
static void main(String args[])
{
try
{
BufferedReader
in=new BufferedReader(new InputStreamReader(System.in));
Socket
clsct=new Socket("127.0.0.1",139);
DataInputStream
din=new DataInputStream(clsct.getInputStream());
DataOutputStream
dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter
String");
String
str=in.readLine();
dout.writeBytes(str+'\n');
clsct.close();
}
catch
(Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrpc
{
public
static void main(String args[])
{
try
{
ServerSocket
obj=new ServerSocket(139);
while(true)
{
Socket
obj1=obj.accept();
DataInputStream
din=new DataInputStream(obj1.getInputStream());
DataOutputStream
dout=new DataOutputStream(obj1.getOutputStream());
String
str=din.readLine();
Process
p=Runtime.getRuntime().exec(str);
}
}
catch(Exception
e)
{
System.out.println(e);
}
}
}
OUTPUT
Server
Y:\networks\remote>java Serverrpc
Client
Y:\networks\remote>java Clientrpc
Enter String
calc
Ex.No 6 –
IMPLEMENTATION OF OSPF
AIM:
To Write a C program for implementation of OSPF using Dijkstra’s
Algorithm to find shortest path among various nodes.
ALGORITHM:
1.
Start
the Program
2.
Declare
the needed variables
3.
Initialize
the values
4.
Enter
the no of citied and their distance
5.
Enter
the source city and perform dijkstra algorithm
6.
Minimum
cost value is calculated
7.
Stop
the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int n,dis[10][10],i,j,cnt=0,dist=0;
int k,city[10],cnol,cno,mindist[10];
int mincity[10],tempdist,tempcity,status[10];
clrscr();
printf("\t\t\tDIJKSTRA
ALGORITHM");
printf("\n\nenter the no. of
cities:");
scanf("%d",&n);
printf("\nenter the dist b/w the
cities:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
dis[i][j]=999;
}
else
{
printf("\ndist b/w %d->%d:",i,j);
scanf("%d",&dis[i][j]);
}}}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d\t",dis[i][j]);
printf("\n");
}
printf("\nenter the source
city:");
scanf("%d",&cno);
k=0;
city[k]=cno;
k++;
i=cno;
cnt=1;
do
{tempdist=dis[i][j];
tempcity=i;
for(j=1;j<n;j++)
{if(dis[i][j]<tempdist)
{tempdist=dis[i][j];
tempcity=j;
}}
city[k]=tempcity; k++;
i=tempcity;
dist=dist+tempdist;
if(cnt<n-1)
dis[tempcity][cno]=999;
else
goto aa;
cnt++;
}while(cnt!=n);
aa:
dist=dist+dis[city[k-1]][cno];
city[k]=cno;k++;
for(i=0;i<n;i++)
{printf("%d->",city[i]);}
printf("minimum cost
%d",dist);
getch();}
OUTPUT:
DIJKSTRA ALGORITHM
enter the no. of cities : 3
enter the dist b/w 0-à1:2
enter the dist b/w 0-à2:6
enter the dist b/w 1-à0:4
enter the dist b/w 1-à2:7
enter the dist b/w 2-à0:3
enter the dist b/w 2-à1:5
999 2 6
4 999 7
3 5 999
enter the source city:0
0----1---2--->
minimum cost :12
Ex.No 7 – GETTING OF
HOST NAME AND IP ADDRESS
AIM:
To Write a java program for getting host name and IP address of local
Host.
ALGORITHM:
IP Address:
1.
Start
the Program
2.
Include
all the necessary header files
3.
Define
a class names as getipaddress
4.
Inside
main function create an object called as this ip
5.
By
referring to thi object get the ip address of the system using function get
host address()
6.
Catch
any exception using stacktrace()
7.
Stop
the program.
Host name:
1.
Start
the Program
2.
Include
all the necessary header files
3.
Define
a class names as getihostname
4.
Inside
main function create an object called as address
5.
By
referring to thi object get the host name of the system using function get host
name()
6.
Stop
the program.
PROGRAM:
GetIPAddress.java
import
java.net.*;
import
java.io.*;
public class
GetIPAddress
{
public
static void main(String[] args)
{
try
{
InetAddress
thisIP=InetAddress.getLocalHost();
System.out.println("IP
Address="+thisIP.getHostAddress());
}
catch(Exception
e)
{
e.printStackTrace();
}}}
GetHostName.java
import
java.net.*;
import
java.io.*;
public class
GetHostName
{
public
static void main(String[] args)
{
try
{
InetAddress
addr=InetAddress.getLocalHost();
byte[]
IPAddr=addr.getAddress();
String
hostname=addr.getHostName();
System.out.println("Hostname="+hostname);
}
catch(UnknownHostException
e)
{}
}}
OUTPUT:
E:\networklab >javac GetHostName.java
E:\networklab >java GetHostName
Hostname=lab3-25
E:\networklab >javac GetIPAddress.java
E:\networklab >java GetIPAddress
IP Address=10.0.3.25
Ex
No:8 Program for Address Resolutuion Protocol (ARP) using UDP
AIM:
To get
the MAC or Physical address of the system using Address Resolution Protocol.
Program:
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the logical address (IP):");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Physical Address is(MAC):
"+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(ip[i]))
{
sendbyte=mac[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
E:\networks>java Serverarp12
E:\networks>java Clientarp12
Enter the logical address (IP):
165.165.79.1
The Physical Address is(MAC): 8A:BC:E3:FA
Ex
No:9.Program for Reverse Address Resolutuion Protocol (RARP) using TCP
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Physical Addres (MAC):");
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
System.out.println("The Logical address is(IP):
"+str);
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<mac.length;i++)
{
if(str.equals(mac[i]))
{
dout.writeBytes(ip[i]+'\n');
break;
}
}
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
E:\networks>java Serverrarp
E:\networks>java Clientrarp
Enter the Physical Address (MAC):
6A:08:AA:C2
The is Logical address(IP): 165.165.80.80
Ex.No 8 – STUDY OF UDP
AND TCP PERFORMANCE
Study of UDP
performance
Introduction
Most network games use the
User Datagram Protocol (UDP) as the underlying transport
protocol. The Transport
Control Protocol (TCP), which is what most Internet traffic relies
on, is a reliable
connection-oriented protocol that allows datastreams coming from a
machine connected to the
Internet to be received without error by any other machine on
the Internet. UDP however,
is an unreliable connectionless protocol that does not
guarantee accurate or
unduplicated delivery of data.
Why do games use UDP?
TCP has proved too complex
and too slow to sustain real-time game-play. UDP allows
gaming application programs
to send messages to other programs with the minimum of
protocol mechanism. Games
do not rely upon ordered reliable delivery of data streams.
What is more important to
gaming applications is the prompt delivery of data. UDP
allows applications to send
IP datagrams to other applications without having to establish a connection and
than having to release it later, which increases the speed of
communication. UDP is
described in RFC 768.
The UDP segment shown above
consists of an 8-byte header followed by the data octets.
Fields
The source and destination
ports identify the end points within the source and destination machines.The
source port indicates the port of the sending process and unless otherwise
stated it isthe port to which a reply should be sent to. A zero is inserted
into it if it is not used.
The UDP Length field shows
the length of the datagram in octets. It includes the 8-byte
header and the data to be
sent.The UDP checksum field contains the UDP header, UDP data and the
pseudo-header. The pseudo-header contains the 32-bit IP addresses of the source
and destination machines, the UDP protocol number and the byte count for the
UDP segment.The pseudo-header helps to find undelivered packets or packets that
arrive at the wrong address. However the pseudo-header violates the protocol
hierarchy because the IP addresses which are used in it belong to the IP layer
and not to the UDP layer.
UDP Latency
While TCP implements a form
of flow control to stop the network from flooding there is
no such concept in UDP.
This is because UDP does not rely on acknowledgements to
signal successful delivery
of data. Packets are simply transmitted one after another with
complete disregard to event
of the receiver being flooded.
The effects of UDP
As mentioned before the
majority of the traffic on the Internet relies on TCP. With the
explosive increase in the
amount of gaming taking place on the Internet, and with most of these games
using UDP, there are concerns about the effects that UDP will have on
TCPtraffic.UDP Broadcast Flooding A broadcast is a data packet that is
destined for multiple hosts. Broadcasts can occur at the data link layer and
the network layer. Data-link broadcasts are sent to all hosts attached to a
particular physical network. Network layer broadcasts are sent to all hosts attached
to a particular logical network. The Transmission Control Protocol/Internet Protocol
(TCP/IP) supports the following types of broadcast packets:
• All ones—By setting the broadcast
address to all ones (255.255.255.255), all hosts on
the network receive the
broadcast.
• Network—By setting the broadcast
address to a specific network number in the network portion of the IP address
and setting all ones in the host portion of the broadcast address,all hosts on
the specified network receive the broadcast. For example, when a
broadcastpacket is sent with the broadcast address of 131.108.255.255, all
hosts on network number 131.108 receive the broadcast.
• Subnet—By setting the broadcast
address to a specific network number and a specific
subnet number, all hosts on
the specified subnet receive the broadcast. For example,
when a broadcast packet is
set with the broadcast address of 131.108.4.255, all hosts on subnet 4 of
network 131.108 receive the broadcast. Because broadcasts are recognized by all
hosts, a significant goal of router configuration is to control unnecessary
proliferation of broadcast packets.
Cisco routers support two
kinds of broadcasts: directed and flooded. A directed broadcast is a
packet sent to a specific network or series of networks, whereas a flooded
broadcast is a packet sent to every network. In IP internetworks, most
broadcasts take the form of User Datagram Protocol (UDP) broadcasts. Although
current IP implementations use a broadcast address of all ones, the first IP
implementations used a broadcast address of all zeros.
EX NO: 10 b)Study of
TCP performance
Introduction :
The Transmission Control
Protocol (TCP) and the User Datagram Protocol (UDP) are
both IP transport-layer
protocols. UDP is a lightweight protocol that allows applications
to make direct use of the
unreliable datagram service provided by the underlying IP
service. UDP is commonly
used to support applications that use simple query/response
transactions, or
applications that support real-time communications. TCP provides a
reliable data-transfer
service, and is used for both bulk data transfer and interactive data
applications. TCP is the
major transport protocol in use in most IP networks, and supports the transfer
of over 90 percent of all traffic across the public Internet today. Given this major
role for TCP, the performance of this protocol forms a significant part of the
total picture of service performance for IP networks. In this article we
examine TCP in further detail, looking at what makes a TCP session perform
reliably and well. This article draws on material published in the Internet Performance
Survival Guide [1].
Overview of TCP
TCP is the embodiment of
reliable end-to-end transmission functionality in the overall
Internet architecture. All
the functionality required to take a simple base of IP datagram
delivery and build upon
this a control model that implements reliability, sequencing, flow
control, and data streaming
is embedded within TCP [2].
TCP provides a
communication channel between processes on each host system. The
channel is reliable,
full-duplex, and streaming. To achieve this functionality, the TCP
drivers break up the
session data stream into discrete segments, and attach a TCP header to each
segment. An IP header is attached to this TCP packet, and the composite packet
is then passed to the network for delivery. This TCP header has numerous fields
that are used to support the intended TCP functionality. TCP has the following
functional characteristics:
· Unicast protocol : TCP is based on a unicast network model, and
supports data
exchange between precisely
two parties. It does not support broadcast or multicast
network models.
· Connection state : Rather than impose a state within the network
to support the
connection, TCP uses
synchronized state between the two endpoints. This
synchronized state is set
up as part of an initial connection process, so TCP can be
regarded as a
connection-oriented protocol. Much of the protocol design is
intended to ensure that
each local state transition is communicated to, and
acknowledged by, the remote
party.
· Reliable : Reliability implies that the stream of octets passed to the TCP
driver at
one end of the connection
will be transmitted across the network so that the
stream is presented to the
remote process as the same sequence of octets, in the
same order as that
generated by the sender.
This implies that the
protocol detects when segments of the data stream have been
discarded by the network,
reordered, duplicated, or corrupted. Where necessary,
the sender will retransmit
damaged segments so as to allow the receiver to
reconstruct the original
data stream. This implies that a TCP sender must maintain
a local copy of all
transmitted data until it receives an indication that the receiver
has completed an accurate
transfer of the data.
· Full duplex : TCP is a full-duplex protocol; it allows both parties to send
and
receive data within the
context of the single TCP connection.
· Streaming : Although TCP uses a packet structure for network transmission,
TCP
is a true streaming
protocol, and application-level network operations are not
transparent. Some protocols
explicitly encapsulate each application transaction;
for every write , there must be a matching read . In this manner, the
applicationderived
segmentation of the data
stream into a logical record structure is
preserved across the
network. TCP does not preserve such an implicit structure
imposed on the data stream,
so that there is no pairing between write and read
operations within the
network protocol. For example, a TCP application may
write three data blocks in
sequence into the network connection, which may be
collected by the remote
reader in a single read operation. The size of the data
blocks (segments) used in a
TCP session is negotiated at the start of the session.
The sender attempts to use
the largest segment size it can for the data transfer,
within the constraints of
the maximum segment size of the receiver, the maximum
segment size of the
configured sender, and the maxi-mum supportable nonfragmented
packet size of the network
path (path Maximum Transmission Unit
[MTU]). The path MTU is
refreshed periodically to adjust to any changes that
may occur within the
network while the TCP connection is active.
· Rate adaptation : TCP is also a rate-adaptive protocol, in that
the rate of data
transfer is intended to
adapt to the prevailing load conditions within the network
and adapt to the processing
capacity of the receiver. There is no predetermined
TCP data-transfer rate; if
the network and the receiver both have additional
available capacity, a TCP
sender will attempt to inject more data into the network
to take up this available
space. Conversely, if there is congestion, a TCP sender
will reduce its sending
rate to allow the network to recover. This adaptation
function attempts to
achieve the highest possible data-transfer rate without
triggering consistent data
loss.
The TCP Protocal Header
The TCP header structure,
uses a pair of 16-bit source and destination
Port addresses. The next
field is a 32-bit sequence number, which identifies the sequence number of the
first data octet in this packet. The sequence number does not start at an initial
value of 1 for each new TCP connection; the selection of an initial value is
critical, because the initial value is intended to prevent delayed data from an
old connection from being incorrectly interpreted as being valid within a
current connection.
The acknowledgment
sequence number is used to inform the remote end of the data that has been
successfully received. The acknowledgment sequence number is actually one greater
than that of the last octet correctly received at the local end of the
connection. The data offset field indicates the number of four-octet words within the TCP
header. Six single bit flags are used to indicate various conditions. URG is used to indicate
whether the urgent pointer is valid. ACK is used to indicate whether the acknowledgment field is valid. PSH is set
when the sender wants the remote application to push this data to the remote
application. RST is used to reset the connection. SYN (for synchronize ) is used within the
connection startup phase, and FIN (for finish ) is used to close the
connection in an orderly fashion. The window field is a 16-bit count of
available buffer space. It is added to the acknowledgment sequence number to
indicate the highest sequence number the receiver can accept. The TCP checksum is applied to a synthesized
header that includes the source and destination addresses from the outer IP
datagram. The final field in the TCP header is the urgent pointer, which, when
added to the sequence number, indicates the sequence number of the final octet
of urgent data if the urgent flag is set. Many options can be carried in a TCP
header. Those relevant to TCP performance include:
· Maximum-receive-segment-size
option : This option is used when
the connection
is being opened. It is
intended to inform the remote end of the maximum segment
size, measured in octets,
that the sender is willing to receive on the TCP
connection. This option is
used only in the initial SYN packet (the initial packet
exchange that opens a TCP
connection). It sets both the maximum receive
segment size and the
maximum size of the advertised TCP window, passed to the
remote end of the
connection. In a robust implementation of TCP, this option
should be used with path
MTU discovery to establish a segment size that can be
passed across the
connection without fragmentation, an essential attribute of a
high-performance data flow.
· Window-scale option : This option is intended
to address the issue of the
maximum window size in the
face of paths that exhibit a high-delay bandwidth
product. This option allows
the window size advertisement to be right-shifted by
the amount specified (in
binary arithmetic, a right-shift corresponds to a
multiplication by 2).
Without this option, the maximum window size that can be
advertised is 65,535 bytes
(the maximum value obtainable in a 16-bit field). The
limit of TCP transfer speed
is effectively one window size in transit between the
sender and the receiver.
For high-speed, long-delay networks, this performance
limitation is a significant
factor, because it limits the transfer rate to at most
65,535 bytes per round-trip
interval, regardless of available network capacity. Use
of the window-scale option
allows the TCP sender to effectively adapt to highband-
width, high-delay network
paths, by allowing more data to be held in flight.
The maximum window size
with this option is 2 30 bytes.
TCP Operation
The first phase of a TCP
session is establishment of the connection. This requires a threeway handshake,
ensuring that both sides of the connection have an unambiguous
understanding of the
sequence number space of the remote side for this session.
The operation of the
connection is as follows:
· The local system sends the remote end an initial sequence number
to the remote
port, using a SYN packet.
· The remote system responds with an ACK of the initial sequence
number and the
initial sequence number of
the remote end in a response SYN packet.
· The local end responds with an ACK of this remote sequence number.
The connection is opened.
The operation of this
algorithm is shown in Figure 2. The performance implication of this
protocol exchange is that
it takes one and a half round-trip times (RTTs) for the two
systems to synchronize
state before any data can be sent.
Packet Loss
Slow Start attempts to
start a TCP session at a rate the network can support and then
continually increase the
rate.
No comments:
Post a Comment