CN Gemini 3
CN Gemini 3
The transport layer is positioned between the application and network layers and plays a
critical role in providing communication services directly to application processes running on
different hosts. 1This chapter examines the principles of transport layer services, particularly
focusing on the Internet's
TCP and UDP protocols. 2It covers how the transport layer extends the network layer's
host-to-host delivery to process-to-process delivery, the fundamental problem of reliable
data transfer, and the mechanisms for network congestion control. 333333333
<hr>
logical communication between application processes on different hosts. 4This means that
from an application's viewpoint, it seems as if the hosts are directly connected, even though
they might be separated by numerous routers and links across the globe. 5Application
processes use this logical communication to send messages without worrying about the
underlying physical infrastructure. 6
● On the
sending side, the transport layer converts application messages into transport-layer
segments. 8It may break large messages into smaller chunks and adds a transport-layer
header to each one. 9These segments are then passed to the network layer, where they
are encapsulated into network-layer packets (datagrams). 10
● On the
receiving side, the network layer extracts the segment from the datagram and passes it
up to the transport layer, which processes it and makes the data available to the
receiving application process. 11
Network routers only act on network-layer fields and do not examine the transport-layer
segment headers. 12
A Household Analogy: Imagine two houses (hosts), one on the East Coast and one on the
West Coast, each with a dozen kids (processes). 15The kids write letters (application
messages) to their cousins in the other house. 16
● The
postal service (network-layer protocol) provides mail delivery from house to house.
171717
It doesn't care which specific person sent or will receive the letter. 18
● In each house, one kid (Ann on the West Coast, Bill on the East Coast) is responsible for
collecting outgoing mail from their siblings and distributing incoming mail to them. 19Ann
and Bill (transport-layer protocol) provide a delivery service between the cousins
(processes). 20202020
Just as Ann and Bill's work is confined to their homes, transport-layer protocols live only in the
end systems. 21212121The services a transport protocol can offer are constrained by the
underlying network layer's services. 22For instance, if the network layer cannot guarantee a
maximum delay, neither can the transport layer. 23However, a transport protocol can offer
services that the network layer doesn't, such as providing
unreliable service. 28
● UDP offers only these two minimal services: process-to-process delivery and error
checking. It is an unreliable service, just like IP. 31
<hr>
This section details how the transport layer extends host-to-host delivery to
process-to-process delivery.
At the receiving host, the transport layer needs to deliver incoming data to the correct
application process. 34343434It does this by directing the data to an intermediary
socket, which acts as a door to the process. 35Each socket has a unique identifier. 36
● Demultiplexing: The job of examining header fields in a received segment to identify the
receiving socket and delivering the segment to it. 37
● Multiplexing: The job at the source host of gathering data from different sockets,
creating segments by adding headers (with source and destination port numbers), and
passing them to the network layer. 38
● A
UDP socket is fully identified by a two-tuple: a (destination IP address, destination
port number). 42
● When a host receives a UDP segment, it examines the destination port number in the
segment and directs it to the socket with that port number. 43
● If multiple UDP segments arrive with different source IPs or source ports but the
same destination IP and port, they will all be directed to the same destination socket. 44
● The source port number serves as a "return address." When the receiver wants to send
a reply, it uses the source port number from the incoming segment as the destination
port number for the outgoing segment. 45
● When a TCP segment arrives, the host uses all four values to direct the segment to the
correct socket. 47This means two arriving TCP segments with different source IP
addresses or source port numbers will be directed to two different sockets. 48
● A TCP server has a "welcoming socket" that listens on a well-known port (e.g., port 80 for
a web server). 49When a client sends a connection request (a SYN segment), the server
creates a
new socket dedicated to that specific client connection. 50This new socket is identified
by the four-tuple containing the client's IP/port and the server's IP/port. 51
● This allows a single server process to handle many simultaneous connections, as each
connection is uniquely identified by the full four-tuple. 52High-performing web servers
often use a single process but create a new
thread with a new connection socket for each client connection. 53
<hr>
UDP (User Datagram Protocol), defined in [RFC 768], is a minimal transport protocol.
54
Beyond multiplexing/demultiplexing and some light error checking, it adds almost nothing to
the underlying IP service. 55It is
Many applications are better suited for UDP than TCP for several reasons: 57
● Finer Control Over Sending: UDP sends a segment as soon as the application passes it
data, unlike TCP, which has congestion control that can throttle the sender. 58Real-time
applications that need a minimum sending rate and can tolerate some loss often prefer
UDP. 59
● No Connection State: TCP maintains connection state (buffers, sequence numbers, etc.)
in the end systems. 62UDP does not, allowing a server to support many more active
clients. 63
● Small Header Overhead: The UDP header is only 8 bytes, compared to TCP's 20 bytes.
64
While UDP itself is unreliable, an application can build reliability (e.g., acknowledgments and
retransmissions) into the application layer itself. 65
The UDP header is simple, with only four fields, each two bytes long: 66
● Source Port # and Destination Port #: Used for multiplexing and demultiplexing. 67
● Length: Specifies the number of bytes in the UDP segment (header plus data). 68
● Checksum: Used by the receiver to check if errors have been introduced into the
segment. 69
● Calculation: The sender takes all the 16-bit words in the segment (including some IP
header fields), sums them, and performs a 1s complement of the sum. 71Any overflow
during the sum is wrapped around. 72This result is placed in the checksum field. 73
● Verification: The receiver adds all the 16-bit words, including the checksum. 74If no
errors occurred, the sum will be all 1s (1111111111111111). 75If any bit is a 0, an error has
been detected. 76
UDP provides its own checksum because there is no guarantee that all links in the path
provide error checking, and bits can also be corrupted while a segment is stored in a router's
memory. 77777777This adheres to the
end-to-end principle, which states that some functions (like error detection) must be
implemented on an end-to-end basis. 78
<hr>
This section explores how to build a protocol for reliable data transfer over an unreliable
channel, where bits can be corrupted or packets can be lost. 79797979The goal is to provide a
service abstraction of a
reliable channel to the upper layer, where no data is lost or corrupted, and all data is
delivered in the order it was sent. 80 This is done by incrementally developing a series of
protocols.
If the underlying channel is perfectly reliable, the protocol is trivial. 81The sender accepts data
from the upper layer, creates a packet, and sends it. 82The receiver gets the packet, extracts
the data, and passes it to the upper layer. 83
A more realistic model is a channel that can corrupt bits but doesn't lose packets. 84848484To
handle this,
Automatic Repeat reQuest (ARQ) protocols are used. 85 They require three new capabilities:
1. Error Detection: Using a checksum to detect when bit errors have occurred. 86
2. Receiver Feedback: The receiver provides explicit feedback to the sender. This can be a
positive acknowledgment (
ACK) for a correctly received packet or a negative acknowledgment (NAK) for a
corrupted one. 87
3. Retransmission: The sender retransmits a packet that was received in error. 88
This protocol is a
stop-and-wait protocol because the sender sends a packet and then waits for an ACK or
NAK before sending the next one. 89
A fatal flaw exists if the ACK/NAK packets can also be corrupted. 90To solve this, the sender
can resend the packet if it receives a garbled ACK/NAK. 91However, this introduces
Now, assume the channel can also lose packets (both data packets and ACKs). 96 The protocol
must now also handle packet loss. The sender can detect loss by setting a
rdt2.2 can handle this. 99This protocol, which uses a 1-bit sequence number, is also known as
the
The solution is
pipelining, which allows the sender to transmit multiple packets without waiting for
acknowledgments. 104 This requires:
● Buffering at both the sender (for unacknowledged packets) and receiver. 106
N unacknowledged packets in the pipeline, where N is the window size. 108The range of
permissible sequence numbers for transmitted but unacknowledged packets is a window that
slides forward as ACKs are received. 109GBN is a type of
● Sender:
○ If a timeout occurs, the sender retransmits
all packets that have been sent but not yet acknowledged, starting from the oldest
one. 111
○ It uses
cumulative acknowledgments, meaning an ACK for sequence number n confirms
that all packets up to and including n have been correctly received. 112
● Receiver:
○ If a packet with sequence number
n is received correctly and in order, the receiver sends an ACK for n and delivers the
data to the upper layer. 113
GBN can be inefficient because a single packet error can cause the retransmission of many
correct packets. 116
Selective Repeat (SR) protocols avoid this by having the sender retransmit only those
packets that were lost or corrupted. 117
● Sender:
○ Retransmits only the specific packets for which it suspects an error.
○ Each packet has its own logical timer. 118
● Receiver:
○ Individually acknowledges each correctly received packet, whether it's in order or
not. 119119119119
○ Buffers out-of-order packets until the missing packets arrive. 120Once a gap is filled,
a batch of in-order packets can be delivered to the upper layer. 121
The window size for SR must be less than or equal to half the size of the sequence number
space to avoid ambiguity between a retransmitted old packet and a new packet with the same
sequence number. 122
<hr>
TCP is the Internet's connection-oriented, reliable transport protocol, and it uses many of the
principles discussed in Section 3.4. 123
TCP is
connection-oriented. 124124Before data can be sent, the client and server must perform a
send buffer and a receive buffer. 129129129129The sender's TCP grabs chunks of data from its
send buffer, forms segments, and passes them to the network layer. 130The maximum amount
of application-layer data that can be placed in a segment is the
The TCP segment consists of a header and a data field. 132The header is typically 20 bytes and
includes: 133
● Sequence Number (32-bit): The byte-stream number of the first byte in the segment's
data. 135135135135TCP views data as an ordered stream of bytes, and sequence numbers
refer to these bytes, not the segments. 136
● Acknowledgment Number (32-bit): The sequence number of the next byte a host is
expecting from the other side. 137137137137TCP uses
cumulative acknowledgments. 138
● Header Length (4-bit): Specifies the length of the TCP header. 139
● Receive Window (16-bit): Used for flow control; indicates the number of bytes a
receiver is willing to accept. 140
● Flag Field (6-bit): Contains bits like ACK (acknowledgment field is valid), SYN (for
connection setup), and FIN (for connection teardown). 141141141141
TCP uses a timeout/retransmit mechanism to recover from lost segments. 142The timeout
interval must be larger than the connection's Round-Trip Time (RTT). 143
● Doubling the Timeout Interval: Each time TCP retransmits due to a timeout, it sets the
next timeout interval to twice the previous value. 152This exponential backoff provides a
limited form of congestion control. 153
● Fast Retransmit: A timeout period can be long. 154To detect packet loss faster, the
sender uses
duplicate ACKs. 155When a receiver gets an out-of-order segment, it detects a gap and
immediately sends a duplicate ACK for the last in-order byte it received. 156156156156If the
sender receives
three duplicate ACKs for the same data, it takes this as a sign that the subsequent
packet was lost and performs a fast retransmit of the missing segment before its timer
expires. 157
TCP's error recovery is best categorized as a hybrid of GBN and SR protocols. 158It uses
cumulative ACKs like GBN, but many implementations buffer out-of-order segments like SR,
and its fast retransmit mechanism avoids the unnecessary retransmissions common in GBN.
159159159159
TCP provides a
flow-control service to prevent the sender from overflowing the receiver's buffer. 160This is a
speed-matching service. 161
● The sender ensures that the amount of unacknowledged data it sends is less than the
value of rwnd:
(LastByteSent - LastByteAcked) ≤ rwnd 165
2. The server, upon receiving the SYN, allocates buffers and variables, and sends back a
SYNACK segment. 167This segment has the SYN bit set, acknowledges the client's
SYN (
ack = client_isn + 1), and contains the server's own random initial sequence number
(server_isn). 168
3. The client receives the SYNACK, allocates its own buffers and variables, and sends a
final
ACK segment to the server, acknowledging the server's SYN (ack = server_isn + 1).
169
This third segment can carry application data. 170
● Closing a Connection:
○ Either side can initiate the teardown by sending a segment with the
FIN bit set to 1. 171171171
○ The other side sends an ACK for the FIN segment. 172
○ It then sends its own FIN segment, which is in turn acknowledged by the initiating
side. 173Resources are then deallocated. 174
TCP states, such as CLOSED, SYN_SENT, ESTABLISHED, FIN_WAIT, and TIME_WAIT. 175
<hr>
Network congestion occurs when too many sources try to send data at too high a rate,
leading to overflowing router buffers and packet loss. 176
Congestion control refers to mechanisms that throttle senders to prevent this. 177
3. Four Senders, Multihop Paths: When a packet is dropped at a downstream router, the
transmission capacity used at all upstream links to get the packet to that point is wasted.
183
In severe cases, as offered load increases, the effective throughput can drop to zero as
nearly all router resources are spent forwarding packets that are ultimately dropped. 184
1. End-to-end Congestion Control: The network layer provides no explicit support. 185End
systems must infer congestion from network behavior like packet loss and delay. 186
TCP uses this approach, treating packet loss (detected via timeout or triple duplicate
ACKs) as a signal of congestion and reducing its sending rate. 187
2. Network-assisted Congestion Control: Routers provide explicit feedback to the sender
about the congestion state. 188This feedback can be a
choke packet sent directly to the sender or a bit marked in a packet flowing from sender
to receiver. 189
<hr>
TCP uses an end-to-end, network-unassisted approach. 190It has each sender limit its send
rate based on perceived network congestion. 191
2. An acknowledged segment indicates the network is working, so the send rate can be
increased. 197
Slow Start
○ cwnd reaches the value of ssthresh. The sender then transitions to the more
conservative congestion avoidance mode. 204
○ Three duplicate ACKs are detected. TCP then performs a fast retransmit and enters
the fast recovery state. 205
Congestion Avoidance
● Instead of doubling
cwnd every RTT, TCP increases cwnd by just 1 MSS per RTT. 206This is a linear increase,
which is much more conservative than slow start's exponential growth. 207
● If a timeout occurs,
cwnd is reset to 1 MSS and ssthresh is set to cwnd/2, and the sender returns to the slow
start phase. 208
Fast Recovery
● When the ACK for the missing segment finally arrives, TCP deflates
cwnd and enters the congestion avoidance state. 211
TCP Tahoe, always reset cwnd to 1 after any loss event. 212A newer version,
TCP Reno, incorporated fast recovery to avoid the drastic rate reduction after a
triple-duplicate-ACK event. 213
+1 MSS per RTT) and then halves it on a loss event, resulting in a characteristic "sawtooth"
pattern of throughput over time. 215
Fairness
fair if K competing TCP connections each get approximately R/K of a bottleneck link's
capacity R. 216
● TCP's AIMD algorithm tends to converge to a fair allocation. 217Connections that are
consuming less than their fair share will increase their rate, while those consuming more
will eventually experience loss and decrease their rate, pushing the system toward the
equal-share point. 218218218218