UNIT IV Udp TCP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

UNIT-IV

Transport Layer Protocol:


TCP & UDP

1
PROCESS-TO-PROCESS DELIVERY
• The data link layer is responsible for delivery of frames
between two neighboring nodes over a link. This is called
node-to-node delivery.
• The network layer is responsible for delivery of datagrams
between two hosts. This is called host-to-host delivery.
• Real communication takes place between two processes
(application programs).
• The transport layer is responsible for process-to-process
delivery—the delivery of a packet, part of a message, from one
process to another. Two processes communicate in a
client/server relationship.
Figure: Types of data deliveries
PORT NUMBERS
• Whenever we need to deliver something to one specific
destination among many, we need an address.
• At the data link layer, we need a MAC address to choose one
node among several nodes if the connection is not point-to-
point. A frame in the data link layer needs a destination MAC
address for delivery and a source address for the next node's
reply.
• At the network layer, we need an IP address to choose one host
among millions. A datagram in the network layer needs a
destination IP address for delivery and a source IP address for
the destination's reply.
• At the transport layer, we need a transport layer address, called
a port number, to choose among multiple processes running on
the destination host. The destination port number is needed for
delivery; the source port number is needed for the reply.
Figure: Port numbers
Figure: IP addresses versus port numbers
PORT NUMBERS
• The port numbers are 16-bit integers between 0 and 65,535.
• The client program defines itself with a port number, chosen randomly
by the transport layer software running on the client host.
• The server process must also define itself with a port number. This
port number, however, cannot be chosen randomly.
• The Internet has decided to use universal port numbers for servers;
these are called well-known port numbers.
• Well-known ports:- the ports ranging from 0 to 1,023 are assigned and
controlled by Internet Assigned Number Authority( IANA).
• Registered ports:- the ports ranging from 1,024 to 49,151 are not
assigned or controlled by IANA. They can only be registered with
IANA to prevent duplication.
• Dynamic ports:- the ports ranging from 49,152 to 65,535 are neither
controlled nor registered. They can be used by any process.
• The combination of an IP address and a port number is called a socket
address.

Figure Socket address


MULTIPLEXING & DEMULTIPLEXING
• The addressing mechanism allows
multiplexing and demultiplexing by the
transport layer.
• Multiplexing:- At the sender site, the
transport layer protocol accepts
messages from different processes,
differentiated by their assigned port
numbers. After adding the header, the
transport layer passes the packet to the
network layer.
• Demultiplexing:- At the receiver site, the transport layer
receives datagrams from the network layer. After error checking
and dropping of the header, the transport layer delivers each
message to the appropriate process based on the port number.
USER DATAGRAM PROTOCOL (UDP)
• The User Datagram Protocol (UDP) is called a
connectionless, unreliable transport protocol. It does not add
anything to the services of IP except to provide process-to-
process communication instead of host-to-host
communication.
• UDP is described in RFC 768.
Table Well-known ports used with UDP
UDP HEADER
• UDP transmits segments consisting of an 8-byte header
followed by the payload.
• The two ports serve to identify the endpoints within the
source and destination machines.
• When a UDP packet arrives, its payload is handed to the
process attached to the destination port.
UDP HEADER
• Source port number:- The source port is primarily needed
when a reply must be sent back to the source. If the source
host is the client , the port number is an ephemeral port
number. If the source host is the server, the port number is a
well-known port number.
• Destination port number.:- This is the port number used by
the process running on the destination host. If the destination
host is the server, the port number is a well-known port
number. If the destination host is the client, the port number,
is an ephemeral port number.
• Length:- This is a 16-bit field that defines the total length of
the user datagram, header plus data.
UDP length = IP length - IP header's length
• Checksum:- This field is used to detect errors over the entire
user datagram.
CHECKSUM
• The checksum includes three sections: a pseudoheader, the
UDP header, and the data coming from the application layer.
• The pseudoheader is the part of the header of the IP packet in
which the user datagram is to be encapsulated with some
fields filled with 0s.

Figure: Pseudoheader for checksum calculation


TCP

• TCP is a connection-oriented protocol; it creates a virtual


connection between two TCPs to send data. In addition, TCP
uses flow and error control mechanisms at the transport level.
• Like UDP, TCP provides process-to-process communication
using port numbers.
• TCP, unlike UDP, is a stream-oriented protocol. TCP allows
the sending process to deliver data as a stream of bytes and
allows the receiving process to obtain data as a stream of
bytes.
• TCP creates an environment in which the two processes seem
to be connected by an imaginary "tube“ that carries their data
across the Internet.
Figure: Stream delivery
Sending and Receiving Buffers

• Because the sending and the receiving processes may not


write or read data at the same speed, TCP needs buffers for
storage. There are two buffers, the sending buffer and the
receiving buffer, one for each direction.

Figure: Sending and receiving buffers


TCP Segments
• Although buffering handles the disparity between the speed of the
producing and consuming processes, we need one more step before
we can send data. The IP layer, as a service provider for TCP, needs
to send data in packets, not as a stream of bytes.
• At the transport layer, TCP groups a number of bytes together into
a packet called a segment. TCP adds a header to each segment (for
control purposes) and delivers the segment to the IP layer for
transmission.

Figure: TCP segments


TCP Features
• Numbering System:
• Byte Number: The bytes of data being transferred in each
connection are numbered by TCP. The numbering starts
with a randomly generated number.
• Sequence Number: After the bytes have been numbered,
TCP assigns a sequence number to each segment that is
being sent.
• Acknowledgment Number: The communication in TCP is
full duplex. An acknowledgment number is used to
confirm the bytes has received. the acknowledgment
number is cumulative.

• Flow Control: The receiver of the data controls the amount of


data that are to be sent by the sender. This is done to prevent
the receiver from being overwhelmed with data.
TCP Features
• Error Control: To provide reliable service, TCP implements
an error control mechanism.
• Congestion Control: TCP, unlike UDP, takes into account
congestion in the network.
TCP segment format
• The segment consists of a 20- to 60-byte header, followed by
data from the application program. The header is 20 bytes if
there are no options and up to 60 bytes if it.
• contains options.

Figure: TCP segment format


Figure Control field
TCP Connection

• A SYN segment cannot carry


data, but it consumes one
sequence number.
• A SYN + ACK segment
cannot carry data, but does
consume one sequence
number.
• An ACK segment, if
carrying no data, consumes
no sequence number.

Figure: Connection establishment using three-way handshaking


TCP Data Transfer
• After connection is established
the client sends 2000 bytes of
data in two segments.
• The server then sends 2000
bytes in one segment.
• The client sends one more
segment.
• The first three segments carry
both data and acknowledgment,
but the last segment carries only
an acknowledgment because
there are no more data to be
sent.
Figure: Data transfer
TCP Connection Termination

• The FIN segment consumes one


sequence number if it does
not carry data.
• The FIN + ACK segment
consumes one sequence
number if it does not carry
data.

Figure: Connection termination using three-way handshaking


TCP Half Close

Figure: Half Close

You might also like