Module 4
Module 4
Transport-Layer Protocols
Introduction
• The transport layer acts as a liaison between a client program
and a server program, a process-to-process connection
Transport Layer
Services:
3
Transport Layer
• only the two end systems use the services of the transport layer; all intermediate
routers use only the first three layers.
Services
Each protocol provides a different type of service and should be used
appropriately
UDP
• UDP is an unreliable connectionless transport-layer protocol used for its
simplicity and efficiency in applications where error control can be
provided by the application-layer process.
TCP
• TCP is a reliable connection-oriented protocol that can be used in any
application where reliability is important.
SCTP
• SCTP is a new transport-layer protocol that combines the features of UDP
and TCP
Port Numbers
Web service(port:80)
[Link] 80://[Link]
Process
Applications of UDP
• Domain Name System (DNS)
• Streaming media applications IPTV, i.e. watching TV on a
computer system.
• SNMP
• DHCP
• VOIP
User Datagram
• UDP packets, called user datagrams
• The first two fields define the source and destination port numbers
• The third field defines the total length of the user datagram, header plus
data (16 bits-0 to 65,535 bytes)
• The last field can carry the optional checksum
Example
• 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. TCP creates an environment in which the two processes
seem to be connected by an imaginary “tube” that carries their bytes
across the Internet.
The sending process produces (writes to) the stream and the receiving process
consumes (reads from) it.
TCP Services
Sending and Receiving Buffers: TCP needs buffers for storage. There are two
buffers, the sending buffer and the receiving buffer, one for each direction
• Buffers are also necessary for flow- and error-control mechanisms used by TCP.
• One way to implement a buffer is to use a circular array of 1-byte locations
Numbering System
• TCP software keeps track of the segments being transmitted or received
• 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
• When TCP receives bytes of data from a process, TCP stores them in the
sending buffer and numbers them.
• The numbering does not necessarily start from 0. Instead, TCP chooses an
arbitrary number between 0 and 2^32 − 1 for the number of the first byte
• Ex: if the number happens to be 1057 and the total data to be sent is 6000
bytes, the bytes are numbered from 1057 to 7056.
TCP Features
Sequence Number: After the bytes have been numbered, TCP assigns a
sequence number to each segment that is being sent. The sequence number,
in each direction, is defined as follows:
1. The sequence number of the first segment is the ISN (initial sequence
number), which is a random number.
2. The sequence number of any other segment is the sequence number of
the previous segment plus the number of bytes (real or imaginary)
carried by the previous segment.
10001+1000=11001 11001+1000=12001 12001+1000=13001 13001+1000=14001
TCP Features
Acknowledgment Number
• Each party also uses an acknowledgment number to confirm the bytes it
has received
• The acknowledgment number defines the number of the next byte that
the party expects to receive.
• In addition, the acknowledgment number is cumulative, which means that
the party takes the number of the last byte that it has received, safe and
sound, adds 1 to it, and announces this sum as the acknowledgment
number.
• The term cumulative here means that if a party uses 5643 as an
acknowledgment number, it has received all bytes from the beginning up
to 5642. Note that this does not mean that the party has received 5642
bytes, because the first byte number does not have to be 0.
Segment
• A packet in TCP is called a segment.
The TCP Segment Header
1. Source Port-
2. Destination Port-
NOTE
3. Sequence Number-
4. Acknowledgement Number-
5. Header Length-
• Header length is a 4 bit field. So, the range of decimal values that can be represented is [0, 15].
• The length of TCP header always lies in the range- [20 bytes , 60 bytes]
• So, to represent the header length, we use a scaling factor of 4.
• Header length = Header length field value x 4 bytes
If header length field contains decimal value 5 (represented as 0101), then-
Header length = 5 x 4 = 20 bytes
If header length field contains decimal value 10 (represented as 1010), then-
Header length = 10 x 4 = 40 bytes
If header length field contains decimal value 15 (represented as 1111), then-
Header length = 15 x 4 = 60 bytes
The TCP Segment Header
6. Reserved Bits-
7. Window Size-
NOTE
It is important to note-
•The window size changes dynamically during data transmission.
•It usually increases during TCP transmission up to a point where congestion is
detected.
•After congestion is detected, the window size is reduced to avoid having to drop
packets.
8. Control:These bits enable flow control, connection establishment and termination,
connection abortion, and the mode of data transfer in TCP.
Flags - Note
7. URG Bit- URG bit is used to treat certain data on an urgent basis.
• When URG bit is set to 1, It indicates the receiver that certain amount of data within the
current segment is urgent.
• Urgent data is pointed out by evaluating the urgent pointer field.
• The urgent data has be prioritized.
• Receiver forwards urgent data to the receiving application on a separate channel.
8. ACK Bit- ACK bit indicates whether acknowledgement number field is valid or not.
• When ACK bit is set to 1, it indicates that acknowledgement number contained in the TCP
header is valid.
• For all TCP segments except request segment, ACK bit is set to 1.
• Request segment is sent for connection establishment during Three Way Handshake.
9. PSH Bit- PSH bit is used to push the entire buffer immediately to the receiving application.
NOTE
• Unlike URG bit, PSH bit does not prioritize the data.
• It just causes all the segments in the buffer to be pushed immediately to the
receiving application.
• The same order is maintained in which the segments arrived.
• It is not a good practice to set PSH bit = 1.
• This is because it disrupts the working of receiver’s CPU and forces it to take an
action immediately.
• When FIN bit is set to 1, It indicates the receiver that the sender wants to terminate
the connection.
• FIN segment sent for TCP Connection Termination contains FIN bit set to 1.
The TCP Segment Header
9. Checksum-
• Urgent pointer is a 16 bit field. This field is considered valid and evaluated only
if the URG bit is set to 1.
• The sender side marks some portion of the byte stream as needing special
treatment by the application program at the receiver side
• This pointer indicates how much of the data in the segment, counting from
the first byte, is urgent. (Example if the data size is 100 bytes and only first 50
bytes is urgent, the urgent pointer will have a value of 50)
• The purpose of the PSH bit is to tell TCP that do not wait for the buffer to
become full and send the data immediately. Similarly when the receiver
receives the segment with PSH flag set, should send the data immediately
to the upper layer (receiving application) without waiting for the receive
buffer to become full.
• The PSH flag is also used to facilitate real-time communication via TCP
TCP Connection Establishment
In TCP, connection-oriented transmission requires three phases:
• connection establishment,
• data transfer, and
• connection termination
1. 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.
2. 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
Three-way handshaking
This SYN flooding attack belongs to a group of security attacks known as a denial of service
attack. In which an attacker monopolizes a system with so many service requests that the
system overloads and denies service to valid requests.
SYN Flooding Attack
• The connection establishment procedure in TCP is susceptible to a serious security
problem called SYN flooding attack
How?
• when one or more malicious attackers send a large number of SYN segments to a server
pretending that each of them is coming from a different client by faking the source IP
addresses in the datagrams
• The server, assuming that the clients are issuing an active open, allocates the necessary
resources, such as creating transfer control block (TCB) tables and setting timers
• TCP server then sends the SYN + ACK segments to the fake clients, which are lost
Consequences:
• however, resources are allocated without being used. The server eventually runs out of
resources and may be unable to accept connection requests from valid clients
• This SYN flooding attack belongs to a group of security attacks known as a denial of
service attack. In which an attacker monopolizes a system with so many service
requests that the system overloads and denies service to valid requests.
Data Transfer
After connection is established, bidirectional data transfer can take place.
Seq: 8001+1000=9001
Seq: 15000+1=15001
Ack:10000+1=10001
Seq: 9001+1000=10001
Data Transfer
• After a connection is established, the client sends 2,000 bytes of data in two
segments.
• The server then sends 2,000 bytes in one segment.
• The first three segments carry both data and acknowledgment, but the last
segment carries only an acknowledgment because there is no more data to be
sent.
• The data segments sent by the client have the PSH (push) flag set so that the
server TCP knows to deliver data to the server process as soon as they are
received.
• The segment from the server, on the other hand, does not set the push flag. Most
TCP implementations have the option to set or not to set this flag.
Pushing Data
Normal Scenario:
• Sender application-uses a buffer to store the stream of data. sending TCP can
select the segment size
• The receiving TCP- also buffers the data when they arrive and delivers when
the application program is ready or when it is convenient for the receivingTCP.
Special Occasion:
• The purpose of the PSH bit is to tell TCP that do not wait for the buffer to
become full and send the data immediately. Similarly when the receiver
receives the segment with PSH flag set, should send the data immediately to
the upper layer (receiving application) without waiting for the receive buffer
to become full.
• The PSH flag is also used to facilitate real-time communication via TCP
Urgent Data
occasions: in which an application program needs to send urgent bytes,
some bytes that need to be treated in a special way by the application at the
other end.
• Server: The server TCP sends FIN + ACK segment to confirm the receipt of
the FIN segment from the client and at the same time to announce the
closing of the connection in the other direction
• The client TCP sends an ACK segment, to confirm the receipt of the FIN
segment from the TCP server
Half-Close
(four-way handshaking)
In TCP, one end can stop sending data while still receiving data. This is called a halfclose.
Example:sorting
State Transition Diagram
Connection
Establishment
(Established)
(Established)
FIN-WAIT1
CLOSE-WAIT
Connection
FIN-WAIT2
Termination LAST-ACK
TIME_WAIT
Timeout
Closed
Connection
Termination
Active close
FIN_WAIT1 passive close
TIME_WAIT
CLOSE CLOSE
State transition diagram
State transition diagram
Windows in TCP
• Because of overflow of data - some packet may lost (Faster sender and
slower receiver –buffer) – but TCP is relaibe
• TCP uses two windows (send window and receive window) for each
direction of data transfer
• Sender and receiver agree on the amount of data that is going to be
transferred. How many packets we are allowed to send to the receiver
• Sending window is decided by receiver during connection establishment
5000 is the
10000 is the window size
window size
Windows in TCP
Send Window window size is 100 bytes (201 to 300)
Windows in TCP
Receiver is capable to
Receive Window accommodate for 40 more bytes
Flow Control
Flow control feedback: The receiving TCP controls the sending TCP; the sending TCP
controls the sending process
Opening and Closing Windows
• To achieve flow control, TCP forces the sender and the receiver to adjust their
window sizes, although the size of the buffer for both parties is fixed when the
connection is established.
• The receive window closes (moves its left wall to the right) when more bytes
arrive from the sender; it opens (moves its right wall to the right) when more
bytes are pulled by the process. We assume that it does not shrink (the right
wall does not move to the left).
• The opening, closing, and shrinking of the send window is controlled by the
receiver.
• The send window closes (moves its left wall to the right) when a new
acknowledgment allows it to do so.
• The send window opens (its right wall moves to the right) when the receive
window size (rwnd) advertised by the receiver allows it to do so
200 received
bytes are still
occupied.
Not consumed
by the
101 to 300 receiving
(200 bytes) process
Seq no:
Shrinking of Windows
• The receive window cannot shrink
• The send window, on the other hand, can shrink if the receiver defines a
value for rwnd that results in shrinking the window.
• some implementations do not allow shrinking of the send window. The
limitation does not allow the right wall of the send window to move to the
left.
new ackNo + new rwnd ≥ last ackNo + last rwnd
Shrinking of Windows
Receiver
Window
sender has sent bytes 206 to 214. Bytes 206 to209 are acknowledged and purged. The new
advertisement, however, defines the new value of rwnd as 4, in which 210 + 4 < 206 + 12.
When the send window shrinks, it creates a problem: byte 214, which has already been
sent, is outside the window. It forces the relation, because the receiver does not know which of the
bytes 210 to 217 has already been sent.
One way to prevent this situation is to let the receiver postpone its feedback until enough buffer
locations are available in its window the receiver should wait until more bytes are consumed by its
process to meet the relationship
Window Shutdown
• shrinking the send window by moving its right wall to the left is strongly
discouraged
• There is one exception: the receiver can temporarily shut down the
window by sending a rwnd of 0.
• Reason - the receiver does not want to receive any data from the sender
for a while.
• In this case, the sender does not actually shrink the size of the window,
but stops sending data until a new advertisement has arrived.
• even when the window is shut down by an order from the receiver, the
sender can always send a segment with 1 byte of data. This is called
probing and is used to prevent a deadlock
Silly Window Syndrome
• In the sliding window operation when either the sending application
program creates data slowly or the receiving application program
consumes data slowly, or both
• Results in the sending of data in very small segments, which reduces the
efficiency of the operation
• Eg: if TCP sends segments containing only 1 byte of data, it means that a
41-byte datagram (20 bytes of TCP header and 20 bytes of IP header)
transfers only 1 byte of user data. + the data-link layer and physical-layer
overhead - inefficiency
Syndrome Created by the Sender
• The sending TCP may create a silly window syndrome if it is serving an
application program that creates data slowly for example, 1 byte at a time
• The application program writes 1 byte at a time into the buffer of the
sending TCP. If the sending TCP does not have any specific instructions, it
may create segments containing 1 byte of data
• The solution is to prevent the sending TCP from sending the data byte by
byte. The sending TCP must be forced to wait and collect data to send in a
larger block. How long should the sending TCP wait? If it waits too long, it
may delay the process. If it does not wait long enough, it may end up
sending small segments.
Syndrome Created by the Sender
Syndrome Created by the Sender
Solution: Nagle’s algorithm
1. The sending TCP sends the first piece of data it receives from the sending
application program even if it is only 1 byte.
2. After sending the first segment, the sending TCP accumulates data in the
output buffer and waits until either the receiving TCP sends an acknowledgment
or until enough data have accumulated to fill a maximum-size segment. At this
time, the sending TCP can send the segment.
Features:
• Simplicity
• If the application program is faster than the network, the segments are larger
(maximum-size segments). If the application program is slower than the
network, the segments are smaller (less than the maximum segment size).
waits until either the receiving TCP sends
an acknowledgment or
enough data have accumulated to fill a
maximum-size segment
Syndrome Created by the Receiver
• The receiving TCP may create a silly window syndrome if it is serving an application
program that consumes data slowly, for example, 1 byte at a time.
• Eg: input buffer of the receiving TCP is 4 kilobytes. The sender sends the first 4
kilobytes of data. The receiver stores it in its buffer and buffer is full receiving
application reads the first byte of data and advertise and advertise a window size
of 1 byte
Solution: Syndrome Created by the Receiver
Syndrome Created by the Receiver
• Delayed acknowledgment also has another advantage: it reduces traffic.
• The receiver does not have to acknowledge each segment. However,
there also is a disadvantage in that the delayed acknowledgment may
result in the sender unnecessarily retransmitting the unacknowledged
segments.
Question
• With an example, explain flow control in TCP.
• Error control in TCP is achieved through the use of three simple tools:
checksum, acknowledgment, and time-out.
Error Control
Checksum
• TCP uses a 16-bit checksum that is mandatory in every segment.
• checksum field - used to check for a corrupted segment
Acknowledgment
TCP uses acknowledgments to confirm the receipt of data segments
Dealy
500 ms
ack
Next datagram
received. Ack is sent
The most common rules here:
4. When a segment arrives with an out-of-order sequence number that is higher than
expected, the receiver immediately sends an ACK segment announcing the sequence
number of the next expected segment. This leads to the fast retransmission of missing
segments 1
2
3 x
2 not received
5. When a missing segment arrives, the receiver sends an ACK segment to announce
the next sequence number expected. This informs the receiver that segments
reported missing have been received.
6. If a duplicate segment arrives, the receiver discards the segment, but immediately
sends an acknowledgment indicating the next in-order segment expected. This
solves some problems when an ACK segment itself is lost.
Retransmission
• When sender discovers that the segment sent by it is lost, it retransmits
the same segment to the receiver.
• Sender discovers that the TCP segment is lost when-
– Either Time Out Timer expires
– Or it receives three duplicate acknowledgements
• Fast retransmission
• If three duplicate acknowledgments (i.e., an original ACK plus three exactly
identical copies) arrive for a segment, the next segment is retransmitted
without waiting for the time-out.
Some Scenarios (error control issues)
Some Scenarios (Lost segment)
Some Scenarios (Fast Retransmission)
Some Scenarios (Lost acknowledgment)
Receiver
Sender Window
Window buffer
• The send window is controlled by the receiver using the value of rwnd. This strategy
guarantees that the receive window is never overflowed with the received bytes (no
end congestion)
• TCP is an end-to-end protocol that uses the service of IP. The congestion in the
router is in the IP territory and should be taken care of by IP. IP is a simple protocol
with no congestion control. TCP, itself, needs to be responsible for this problem.
Congestion Window
• To control the number of segments to transmit, TCP uses another variable
called a congestion window, cwnd, whose size is controlled by the
congestion situation in the network.
• The cwnd variable and the rwnd variable together define the size of the
send window in TCP
Exponential
Growth
Congestion Avoidance: Additive Increase
congestion window
reaches the slow-start
threshold
window increases
only 1/cwnd portion
Three versions of TCP: Taho TCP, Reno TCP, and New Reno TCP
Taho TCP
• It used only two different algorithms in their congestion policy: slow start
and congestion avoidance
• Taho TCP treats the two signs used for congestion detection, time-out and
three duplicate ACKs
Example 24.9
• This version treated the two signals of congestion detection time-out and
the arrival of three duplicate ACKs
• If three duplicate ACKs arrive, TCP moves to the fast-recovery state and
remains there as long as more duplicate ACKs arrive
ssthresh+3=6+3=9
1. When TCP sends the segment in front of the sending queue, it starts the
timer.
2. When the timer expires, TCP resends the first segment in front of the
queue, and restarts the timer.
4. If the queue is empty, TCP stops the timer; otherwise, TCP restarts the
timer.
RTO- Round-Trip Time (RTT): RTTM , RTTS, RTTD,
• To calculate the retransmission time-out (RTO), we first need to calculate
the roundtrip time (RTT). Calculating RTT in TCP is an involved process
that we explain step by step with some examples
• Do not update the value of RTTs until you send a segment and receive an
acknowledgment without the need for retransmission.
Keepalive Timer
• A keepalive timer is used in some implementations to prevent a long idle
connection between two TCPs.
• Suppose that a client opens a TCP connection to a server, transfers some
data, and becomes silent. Perhaps the client has crashed.
• To avoid this, most implementations equip a server with a keepalive timer.
If the server does not hear from the client after 2 hours, it sends a probe
segment. If there is no response after 10 probes, each of which is 75
seconds apart, it assumes that the client is down and terminates the
connection.
TIME-WAIT Timer
• The 2MSL timer is used when TCP performs an active close and sends the final ACK.
The connection must stay open for 2 MSL amount of time to allow TCP to resend the
final ACK in case the ACK is lost.
Sample questions
• Define silly window syndrome? What are the solutions to avoid it
(Nagles and Clarkes solution)?