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

CSE 3421

Lecture 03 (Contd.) : Chapter 23

UDP and TCP

Sumaya Kazary
Assistant Professor
Department of Computer Science and Engineering
Dhaka University of Engineering & Technology, Gazipur

Acknowledgement
Thanks to the authors of all the books and online tutorials used in this slide.
23-2 USER DATAGRAM PROTOCOL (UDP)

 The User Datagram Protocol (UDP) is called a


connectionless, unreliable transport protocol.
 Connectionless ‘Best effort delivery’:
 It does not add anything to the services of IP except to
provide process-to-process communication instead of host-
to-host communication.
 Unreliable :
 It performs very limited error checking.
 No Order of payload
 UDP is used to send small messages when
reliability is not a matter of concern.

23.2
UDP Operation
UDP characteristics include the following:
•It is a connectionless protocol.
•It is an Unreliable transport protocol. There is no flow control
and error control mechanism.
•It is faster and needs fewer resources.
•The packets don't necessarily arrive in order.
•It allows missing packets - the sender is unable to know whether
a packet has been received.
•It is better suited for applications that need fast, efficient
transmission, such as for VoIP, video streaming, gaming and live
broadcasts.
•UDP is also used for some route updating protocols such as
Routing Information Protocol (RIP)

23.3
Well-known ports used with UDP

4
User Datagram
65,535

Figure 23.9 User datagram format

23.5
Figure 23.10 Pseudoheader for checksum calculation

23.6
Figure 23.11 shows the checksum calculation for a very small user
datagram with only 7 bytes of data. Because the number of bytes of
data is odd, padding is added for checksum calculation. The
pseudoheader as well as the padding will be dropped when the user
datagram is delivered to IP.

Figure 23.11 Checksum calculation of a simple UDP user datagram


23.7
Figure 23.12 Queues in UDP

23.8
23-3 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.

23.9
Functionalities of TCP Protocol:

1. Segmentation
2. Connection Oriented Protocol
3. Full duplex
4. Piggybacking
5. Error Control
6. Flow Control
7. Congestion Control

23.10
TCP Services : Process to Process Communication

23.11 Table 23.2 Well-known ports used by TCP


Stream Delivery Service

Figure 23.13 Stream delivery

23.12
Sending and Receiving Buffers

Figure 23.14 Sending and receiving buffers

23.13
TCP Segments

Figure 23.15 TCP segments

23.14
The bytes of data being transferred in each
connection are numbered by TCP.
The numbering starts with a randomly generated
number.

The value in the sequence number field of a


segment defines the number of the 1st data
byte contained in that segment.

The value of the acknowledgment field in a


segment defines the number of the next byte a
party expects to receive.

The acknowledgment number is cumulative.


23.15
Example 23.3
Suppose a TCP connection is transferring a file of 5000 bytes. The
first byte is numbered 10,001.What are the sequence numbers for
each segment if data are sent in five segments, each carrying
1000 bytes?
The following shows the sequence number for each segment:

23.16
TCP Segment

Figure 23.16 TCP segment format


23.17
Figure 23.17 Control field

There are six control bits or flags:


URG: It represents an urgent pointer. If it is set, then the data is processed
urgently.
ACK: If the ACK is set to 0, then it means that the data segment does not
contain an acknowledgment.
PSH: If this field is set, then it requests the receiving device to push the
data to the receiving application without buffering it.
RST: If it is set, then it requests to restart a connection.
SYN: It is used to establish a connection between the hosts.
FIN: It is used to release a connection, and no further data exchange will
happen.

23.18
TCP Connection Establishment and Termination

 Connection Establishment
 Establishes a virtual path between the source and destination.
A Three-way Handshake is a method used in a TCP/IP network to
create a connection between a local host/client and server.
It is a three-step method that requires both the client and server to
exchange SYN and ACK (acknowledgment) packets before actual
data communication begins.
 A three-way handshake is also known as a TCP Handshake.

23.19
Figure 23.18 Connection establishment using three-way handshaking

23.20
Note

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.

23.21
TCP Data Transfer

23.22 Figure 23.19 TCP Data Transfer


TCP Connection Termination

Figure 23.20 Connection termination using three-way handshaking


23.23
Note

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.

23.24
Figure 23.21 Half-close

23.25
SYN Flooding Attack : Denial-of-Service (DoS)attack
 The connection establishment procedure in TCP is susceptible
to a serious security problem called the SYN flooding attack
 A malicious attacker sends a large number of SYN segments
to a server using fake source IP addresses !!!

23.26
Figure 23.22 Sliding window

23.27
Note

A sliding window is used to make


transmission more efficient as well as
to control the flow of data so that the
destination does not become
overwhelmed with data.
TCP sliding windows are byte-oriented.

23.28
Example 23.4

What is the value of the receiver window (rwnd) for host


A if the receiver, host B, has a buffer size of 5000 bytes
and 1000 bytes of received and unprocessed data?

Solution
The value of rwnd = 5000 − 1000 = 4000. Host B can
receive only 4000 bytes of data before overflowing its
buffer. Host B advertises this value in its next segment to
A.

23.29
Example 23.5

What is the size of the window for host A if the value of


rwnd is 3000 bytes and the value of cwnd is 3500 bytes?

Solution
The size of the window is the smaller of rwnd and cwnd,
which is 3000 bytes.

23.30
Example 23.6
Figure 23.23 shows an unrealistic example of a sliding window.
The sender has sent bytes up to 202. We assume that cwnd is 20 (in
reality this value is thousands of bytes). The receiver has sent an
acknowledgment number of 200 with an rwnd of 9 bytes (in reality
this value is thousands of bytes). The size of the sender window is
the minimum of rwnd and cwnd, or 9 bytes. Bytes 200 to 202 are
sent, but not acknowledged. Bytes 203 to 208 can be sent without
worrying about acknowledgment. Bytes 209 and above cannot be
sent.

23.31
Note

Some points about TCP sliding windows:


❏ The size of the window is the lesser of rwnd and
cwnd.
❏ The source does not have to send a full window’s
worth of data.
❏ The window can be opened or closed by the
receiver, but should not be shrunk.
❏ The destination can send an acknowledgment at
any time as long as it does not result in a shrinking
window.
❏ The receiver can temporarily shut down the
window; the sender, however, can always send a
segment of 1 byte after the window is shut down.

23.32
Error Control in TCP

Error detection and correction in TCP is achieved


through the use of three simple tools:
1. Checksum,
2. Acknowledgment, and
3. Time-out.

23.33
Note

ACK segments do not consume


sequence numbers and are not
acknowledged.
In modern implementations, a
retransmission occurs if the
retransmission timer expires or three
duplicate ACK segments have arrived.
No retransmission timer is set for an
ACK segment.
23.34
Note

Data may arrive out of order and be


temporarily stored by the receiving TCP,
but TCP guarantees that no out-of-order
segment is delivered to the process.

23.35
some scenarios of TCP operation

23.36
Figure 23.24 Normal operation

23.37
Figure 23.25 Lost segment

The receiver TCP delivers only ordered data to the process.

23.38
Figure 23.26 Fast retransmission

23.39
Thanks for Having Patience

23.40

You might also like