0% found this document useful (0 votes)
29 views

4.1 TCP & UDP

Uploaded by

katyaini1511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

4.1 TCP & UDP

Uploaded by

katyaini1511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

TCP & UDP

INTRODUCTION TO UDP
 Position of UDP in TCP/IP Protocol suite
UDP
 UDP is a transport layer protocol responsible for
process-to-process communication.

 It is an unreliable, connectionless transport


protocol.

 No flow control. No ack of received packets.


Only error control is if a checksum error is
detected, it quietly drops the packet.

 Advantages? Minimal overhead; faster.


PROCESS-TO-PROCESS
COMMUNICATION

 Process - a running application program.

 Host-to-host responsible for message delivery at


computer level.

 Hosts are identified using IP address and for


identifying processes, port numbers are used.

 Port numbers are 16 bit nos. So they are


integers between 0 and 65,535.
 IP Vs UDP
PORT NUMBERS

 Most common ways to achieve process-to-process


communication is through client-server paradigm.
 A process on the local host, called a client needs
services from a process on the remote host,
called server.
 Needs 4 pieces of info: local host (IP addr),
local process (port #), remote host (IP
addr), remote process (port #).
 Local process port # can be just about any
number (between 0 and 65,535), but remote
process port # has to be fixed.
Port Numbers
 Port nos. with which the client program defines
itself is called as the ephemeral port
(meaning short-lived).

 Port nos. with which the server process defines


itself is called as the well known port
numbers, which cannot be chosen randomly.

 Eg: Port 53- DNS


 Port 80- HTTP
 Port 443- HTTPS
 Port 25- SMTP etc
User datagram & Header
 Source port number. It is 16 bits
long, which means that the port
number can range from 0 to 65,535.
 Destination port numberIt is also

16 bits long.
 Length. This is a 16-bit field that defines
the total length of the user datagram,
header plus data. Checksum. This field is
used to detect errors over the entire user
datagram (header plus data).
UDP OPERATION
1. Process-to-process communication
2. Connectionless service
3. Flow and error control
4. Congestion control
5. Encapsulation & decapsulation
6. Multiplexing & demultiplexing
7. Queuing
CONNECTIONLESS SERVICE

 Each user datagram sent by UDP is an


independent datagram.

 The user datagrams are not numbered.

 Also, there is no connection establishment


and no connection termination.
Connectionless service
FLOW AND ERROR
CONTROL
 There is no flow control, and hence no
window mechanism.
 The receiver may overflow with incoming
messages.
 There is no error control mechanism in UDP
except for the checksum.
 This means that the sender does not know
if a message has been lost or duplicated.
 When the receiver detects an error through
the checksum, the user datagram is silently
discarded.
CONGESTION CONTROL

 Since UDP is a connectionless protocol, it


does not provide congestion control.

 UDP assumes that the packets sent are


small and sporadic, and cannot create
congestion in the network.
ENCAPSULATION &
DECAPSULATION
MULTIPLEXING &
DEMULTIPLEXING
QUEUING
USE OF UDP

 Simple request-response communication


with little concern for flow and error control.
 UDP is a suitable transport protocol for

multicasting.
 Used for real-time applications that cannot

tolerate uneven delay between sections of a


received message.
TCP SERVICES

 Process-to-process communication
 Stream delivery service
 Full duplex communication
 Multiplexing & demultiplexing
 Connection-oriented service
STREAM DELIVERY
SERVICE
 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.
Segments

 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.
 The segments are encapsulated in an IP datagram
and transmitted.
 So segmentation is done before data is sent.
FULL DUPLEX COMMUNICATION

 TCP offers full-duplex service, where data


can flow in both directions at the same
time.

 Each TCP endpoint then has its own


sending and receiving buffer, and
segments move in both directions.
MULTIPLEXING &
DEMULTIPLEXING

 TCP performs multiplexing at the


sender and demultiplexing at the
receiver.

 Since TCP is a connection-oriented


protocol, a connection needs to be
established for each pair of processes.
CONNECTION-ORIENTED
SERVICE

 TCP is a connection-oriented protocol.


 When a process at site A wants to send to and

receive data from another process at site B, the


following three phases occur:
1. The two TCPs establish a virtual connection
between them.
2. Data is exchanged in both directions.
3. The connection is terminated.
TCP Numbering system

Byte number

Sequence number

Acknowledgement number
Numbering system

 There are two fields called the


sequence number and the
acknowledgment number.
 These two fields refer to a

byte number and not a


segment number.
 Byte number

 The bytes of data being transferred


in each connection are numbered by
TCP.
 The numbering starts with an
arbitrarily generated number
between 0 and 232-1
 Sequence number

 TCP assigns a sequence number to each segment


that is being sent.
 The sequence number is the number of the first
byte of data carried in that segment.
Acknowledgement number

 The value of the acknowledgment field


defines the number of the next byte a
party expects to receive.
TCP SEGMENT HEADER

 A packet in TCP is called a


segment.

 The segment consists of a header of


20 to 60 bytes, followed by data.
 Source port address. This is a 16-bit field that defines the
port number of the application program in the host that is
sending the segment.
 Destination port address. This is a 16-bit field that defines
the port number of the application program in the host that is
receiving the segment.
 Sequence number. This 32-bit field defines the number
assigned to the first byte of data contained in this segment.
 Acknowledgment number. This 32-bit field defines the byte
number that the receiver of the segment is expecting to
receive from the other party.
 Header length. This 4-bit field indicates the number of 4-
byte words in the TCP header.
 Reserved. This is a 6-bit field reserved for future use.
 Control. This field defines 6 different control bits or flags.
Control Field and Flags
 Window size. This 16 bit field defines the
window size of the sending TCP in bytes. This
value is normally referred to as the receiving
window (rwnd) and is determined by the receiver.
 Checksum. This 16-bit field contains the
checksum for error control.
 Urgent pointer. This 16-bit field, which is valid
only if the urgent flag is set, is used when the
segment contains urgent data.
 Options. There can be up to 40 bytes of optional
information in the TCP header.
TCP CONNECTION MANAGEMENT

 Connection-oriented transmission requires three


phases:

 Connection establishment
 Data transfer and
 Connection termination.
Connection Establishment

 TCP transmits data in full-duplex


mode. When two TCPs in two
machines are connected, they are
able to send segments to each other
simultaneously.
 Three-way handshaking
 The connection establishment in TCP
is called three-way handshaking.
Three-way handshaking

 The process starts with the server. The server program


tells its TCP that it is ready to accept a connection. This
request is called a passive open.
 The client program issues a request for an active open.
 A client that wishes to connect to an open server tells its
TCP to connect to a particular server. TCP can now start
the three-way handshaking process.
First step

i)Client sends the first segment called


SYN which is a control segment used
for synchronization of sequence nos.
ii) SYN segment is a control segment
and carries no data.
Second step
i) The server sends the second segment, a
SYN + ACK segment(control segment & no
data) with two flag bits set: SYN and ACK.
ii) SYN segment is for communication in the other
direction.
iii) The server also acknowledges the receipt of the
SYN segment from the client by setting the ACK
flag
Third step

i) The client sends the third segment. This is


just an
ACK segment.
ii) It acknowledges the receipt of the second
segment with the ACK flag
DATA TRANSFER

 After connection is established, bidirectional


data transfer takes place.
 The client and server can send data and

acknowledgments in both directions.


CONNECTION
TERMINATION

 Client or server can close the


connection, usually initiated by the
client.
 Two options for connection

termination:
 Three-way handshaking and

 Four-way handshaking with a half-

close option.
Three way handshaking
i) Client TCP sends FIN segment with FIN flag set to
server.
 Can be a control or control+data segment. Data

is the last chunk sent by client.


ii) Server TCP sends FIN+ACK segment to client.
 Can be a control or control+data segment. Data

is the last chunk sent by server.


iii) Client TCP sends ACK segment to server.
 This segment cannot carry data and consumes
no
sequence numbers.
Half close connection termination

 In TCP, one end can stop sending data while still


receiving data. This is called a half close.

 Either the server or the client can issue a half-


close request.
Steps

 Client/server sends FIN segment


to other.
 Client/server accepts half close

request by sending ACK


segment.
 After sending all processed

packets, client/server sends FIN


segment to other.
 ACK is sent to confirm the

receipt of FIN by client/server.


TCP ERROR CONTROL

 Error control in TCP is


achieved through the use of
three simple tools:

 Checksum,
acknowledgment, and
time-out.
Checksum

 Each segment includes a checksum


field which is used to check for a
corrupted segment.

 If the segment is corrupted, it is


discarded by the destination TCP and
is considered as lost.
CHECKSUM CALCULATION
 Transmitter:
 m bit checksum is used, then divide data into
segments of m bits size.
 Add all the frames and obtain sum. (discard
carry)
 Complement the sum which is the checksum.
 Data is sent along with checksum.
 Receiver:
 Again divide data into segments of size m bits.
 Add the frames along with received checksum.
 Complement the result.
 If all zeros, then NO ERROR, else error!
Acknowledgment

 TCP uses acknowledgments to confirm the receipt


of data segments.

 ACK segments are never acknowledged.


Time out- Retransmission

 When a segment is
corrupted, lost, or delayed,
it is retransmitted.
 There is no retransmission for

an ACK segment.
Out of Order Segments

 When a segment is delayed,


lost, or discarded, the segments
following that segment arrive
out of order.
 Out-of-order segments are not

delivered to the process.


 TCP guarantees that data are

delivered to the process in


order.
Lost Segment

The receiver TCP delivers only ordered data to the process.


Fast Retransmission- Retransmission after 3
ACKs

You might also like