CN-Unit-3 Study notes (1)
CN-Unit-3 Study notes (1)
SYLLABUS
Introduction and Transport-Layer Services, Multiplexing and Demultiplexing,
Connectionless Transport: UDP, Principles of Reliable Data Transfer, Connection-
oriented Transport: TCP, Principles of Congestion Control: TCP Congestion Control
Course Outcomes:
After the successful completion of the Unit the student will be able to:
1. Analyze various types of services provided by each layer in the network architecture
Reference Book:
James F. Kurose and Keith W. Ross, Computer Networking: A Top-Down Approach, 6/e,
Pearson, 2012 (Text Book, PPT)
Introduction
The transport layer is a central piece of the layered network architecture that resides between the
application and network layers. It has the critical role of providing communication services directly
to the application processes running on different hosts.
1
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
2
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
3
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
4
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
5
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
➢ The TCP server application has a “welcoming socket,” that waits for connection
establishment requests from TCP clients.
➢ The TCP client creates a socket and sends a connection establishment request
segment with the lines:
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,12000))
➢ A connection-establishment request is nothing more than a TCP segment with destination
port number and a special connection-establishment bit set in the TCP header.
➢ The segment also includes a source port number that was chosen by the client.
➢ When the host operating system of the computer running the server process
receives the incoming connection-request segment it locates the server process that is
waiting to accept a connection.
➢ The server process then creates a new socket:
connectionSocket, addr = serverSocket.accept()
➢ The newly created connection socket is identified by four tuples; all subsequently
arriving segments whose source port, source IP address, destination port, and destination
IP address match the four values will be demultiplexed to this socket.
➢ With the TCP connection now in place, the client and server can now send data to each
other.
Fig: Two clients, using the same destination port number (80) to
communicate with the same Web server application
6
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
7
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
8
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
UDP Checksum
-The UDP checksum provides for error detection.
-The checksum is used to determine whether bits within the UDP segment have been altered
(by noise in the links or while stored in a router) as it moved from source to destination.
-UDP at the sender side performs the 1s complement of the sum of all the 16-bit words in
the segment, with any overflow encountered during the sum being wrapped around.
-This result is put in the checksum field of the UDP segment.
-A simple example of the checksum calculation:
➢ Three 16-bit words:
0110011001100000
0101010101010101
1000111100001100
➢ The sum of first two of these 16-bit words is
9
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The 1s complement is obtained by converting all the 0s to 1s and converting all the 1s to
0s.
-Thus, the 1s complement of the sum 0100101011000010 is 1011010100111101, which
becomes the checksum.
-At the receiver, all four 16-bit words are added, including the checksum.
-If no errors are introduced into the packet, then clearly the sum at the receiver will be
1111111111111111.
-If one of the bits is a 0, then it is known that errors have been introduced into the packet.
10
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The sending side of the data transfer protocol will be invoked from above by a call to rdt_send().
-It will pass the data to be delivered to the upper layer at the receiving side.
➢ Here rdt stands for reliable data transfer protocol and _send indicates that the sending
side of rdt is being called.
-On the receiving side, rdt_rcv() will be called when a packet arrives from the receiving side of the
channel.
-When the rdt protocol wants to deliver data to the upper layer, it will do so by calling
deliver_data().
-Here the terminology “packet” is been used rather than transport-layer “segment.”
-The case of unidirectional data transfer is been considered.
11
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
12
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-In a computer network setting, reliable data transfer protocols based on such retransmission are
known as ARQ (Automatic Repeat reQuest) protocols.
-Three additional protocol capabilities are required in ARQ protocols to handle the presence of bit
errors:
➢ Error detection:
• First, a mechanism is needed to allow the receiver to detect when bit errors have
occurred.
• UDP uses the Internet checksum field for exactly this purpose.
• Bits will be gathered into the packet checksum field of the rdt2.0 data packet.
➢ Receiver feedback:
• Since the sender and receiver are typically executing on different
end systems, possibly separated by thousands of miles, the only way for the sender
to know the receiver’s view of the world is for the receiver to provide explicit
feedback to the sender.
• The positive (ACK) and negative (NAK) acknowledgment replies in the
message-dictation scenario are examples of such feedback.
• rdt2.0 protocol will similarly send ACK and NAK packets back from the receiver to
the sender.
➢ Retransmission:
• A packet that is received in error at the receiver will be retransmitted by the sender.
The FSM representation of rdt2.0, a data transfer protocol employing error detection,
positive acknowledgments, and negative acknowledgments.
13
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
14
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
16
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The rdt2.1 sender and receiver FSMs each now have twice as many states as before.
➢ This is because the protocol state must now reflect whether the packet currently being sent
(by the sender) or expected (at the receiver) should have a sequence number of 0 or 1.
One subtle change between rtdt2.1 and rdt2.2 is that the receiver must now include the
sequence number of the packet being acknowledged by an ACK message. This is done by
including the ACK,0 or ACK,1 argument in make_pkt()in the receiver FSM, and the sender must
now check the sequence number of the packet being acknowledged by a received ACK
message.
17
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
18
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
From the below figure the protocol operates with no lost or delayed packets and how it
handles lost data packets. Here time moves forward from the top of the diagram toward the bottom
of the diagram; note that a receive time for a packet is necessarily later than the send time for a
packet as a result of transmission and propagation delays. The send-side brackets indicate the
times at which a timer is set and later times out. Because packet sequence numbers alternate
between 0 and 1, protocol rdt3.0 is sometimes known as the alternating-bit protocol.
19
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
20
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The sender was busy only 2.7 hundredths of one percent of the time.
-Network protocol limits use of physical resources
-Also, neglected lower-layer protocol-processing times at the sender and receiver, as well as
the processing and queuing delays that would occur at any intermediate routers between the
sender and receiver.
-Including these effects would serve only to further increase the delay and further accentuate
the poor performance.
➢ The solution to this particular performance problem is simple: Rather than operate in a stop-
and-wait manner, the sender is allowed to send multiple packets without waiting for
acknowledgments, the many in-transit sender-to-receiver packets can be visualized as filling
a pipeline, this technique is known as pipelining.
21
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-Pipelining has the following consequences for reliable data transfer protocols:
➢ The range of sequence numbers must be increased, since each in-transit packet
(not counting retransmissions) must have a unique sequence number and there may be multiple,
in-transit, unacknowledged packets.
➢ The sender and receiver sides of the protocols may have to buffer more than one packet.
-Two basic approaches toward pipelined error recovery can be identified: Go-Back-N and
selective repeat.
Go-Back-N (GBN)
-In a Go-Back-N (GBN) protocol, the sender is allowed to transmit multiple packets (when
available) without waiting for an acknowledgment, but is constrained to have no more than
some maximum allowable number, N, of unacknowledged packets in the pipeline.
-An extended FSM description of the sender and receiver sides of an ACK-based, NAK-free, GBN
protocol.
-We refer to this FSM description as an extended FSM because we have added variables for base
and nextseqnum, and added operations on these variables and conditional actions involving these
variables.
22
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
23
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
24
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-From the above figure the operation of the GBN protocol for the case of a window size of four
packets.
➢ Because of this window size limitation, the sender sends packets 0 through 3 but then must
wait for one or more of these packets to be acknowledged before proceeding.
➢ As each successive ACK (for example, ACK0 and ACK1) is received, the window slides
forward and the sender can transmit one new packet (pkt4 and pkt5, respectively).
➢ On the receiver side, packet 2 is lost and thus packets 3, 4, and 5 are found to be out of
order and are discarded.
➢ Now the sender has to resend the packets 2,3,4,5 again as the receiver has discarded
packets 3,4,5.
25
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The SR receiver will acknowledge a correctly received packet whether or not it is in order.
-Out-of-order packets are buffered until any missing packets (that is, packets with lower sequence
numbers) are received, at which point a batch of packets can be delivered in order to the upper
layer.
-The SR sender will only send the packet if it is an error or when it is timeout.
26
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
Fig: SR operation
27
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
➢ If there is a TCP connection between Process A on one host and Process B on another
host, then application layer data can flow from Process A to Process B at the same time
as application layer data flows from Process B to Process A.
➢ A TCP connection is also always point-to-point, that is, between a single sender and a
single receiver.
-In TCP they are two processes, the first is client process, while the other process is called the server
process.
➢ The client application process first informs the client transport layer that it wants to establish
a connection to a process in the server.
➢ This connection- establishment procedure is often referred to as a three-way handshake.
-The maximum amount of data that can be grabbed and placed in a segment is limited by the
maximum segment size (MSS).
➢ The MSS is typically set by first determining the length of the largest link-layer frame that
can be sent by the local sending host (the so-called maximum transmission unit, MTU),
and then setting the MSS to ensure that a TCP segment (when encapsulated in an IP
datagram) plus the TCP/IP header length (typically 40 bytes) will fit into a single link-layer
frame.
28
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
30
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The new value of EstimatedRTT is a weighted combination of the previous value of EstimatedRTT
and the new value for SampleRTT.
➢ The recommended value of alpha is 0.125.
-In addition to having an estimate of the RTT, it is also valuable to have a measure of the variability
of the RTT.
➢ The RTT variation, DevRTT, as an estimate of how much SampleRTT typically deviates from
EstimatedRTT:
31
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-We first present a highly simplified description of a TCP sender that uses only timeouts to recover
from lost segments; we then present a more complete description that uses duplicate
acknowledgments in addition to timeouts.
➢ TCP responds to the timeout event by retransmitting the segment that caused the timeout.
➢ TCP then restarts the timer.
-The major event that must be handled by the TCP sender is the arrival of an acknowledgment
segment (ACK) from the receiver.
Fast Retransmit
-One of the problems with timeout-triggered retransmissions is that the timeout period can be
relatively long.
-When a segment is lost, this long timeout period forces the sender to delay resending the lost
packet, thereby increasing the end-to-end delay.
-The sender can often detect packet loss well before the timeout event occurs by noting so-called
duplicate ACKs.
-A duplicate ACK is an ACK that reacknowledges a segment for which the sender has already
received an earlier acknowledgment.
-When a TCP receiver receives a segment with a sequence number that is larger than the next,
expected, in-order sequence number, it detects a gap in the data stream that is, a missing segment.
-This gap could be the result of lost or reordered segments within the network.
-Since TCP does not use negative acknowledgments, the receiver cannot send an explicit negative
acknowledgment back to the sender.
-Instead, it simply reacknowledges the last in-order byte of data it has received.
32
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-Because a sender often sends a large number of segments back-to-back, if one segment is lost,
there will likely be many back-to-back duplicate ACKs.
-If the TCP sender receives three duplicate ACKs for the same data, it takes this as an indication
that the segment following the segment that has been ACKed three times has been lost.
-In the case that three duplicate ACKs are received, the TCP sender performs a fast retransmit,
retransmitting the missing segment before that segment’s timer expires.
Flow Control
-When the TCP connection receives bytes that are correct and in sequence, it places the data in the
receive buffer.
-The associated application process will read data from this buffer, but not necessarily at the instant
the data arrives.
-Indeed, the receiving application may be busy with some other tasks and may not even attempt to
read the data until long after it has arrived.
-If the application is relatively slow at reading the data, the sender can very easily overflow the
connection’s receive buffer by sending too much data too quickly.
-TCP provides a flow-control service to its applications to eliminate the possibility of the sender
overflowing the receiver’s buffer.
-Flow control is thus a speed-matching service: Matching the rate at which the sender is sending
against the rate at which the receiving application is reading.
-A TCP sender can also be throttled due to congestion within the IP network; this form of sender
control is referred to as congestion control.
-TCP provides flow control by having the sender maintain a variable called the receive window.
-The receive window is used to give the sender an idea of how much free buffer space is available
at the receiver.
33
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-Because TCP is full-duplex, the sender at each side of the connection maintains a distinct receive
window.
➢ Suppose that Host Ais sending a large file to Host B over a TCP connection.
➢ Host B allocates a receive buffer to this connection; denote its size by RcvBuffer.
➢ From time to time, the application process in Host B reads from the buffer.
• LastByteRead: the number of the last byte in the data stream read from the
buffer by the application process in B
• LastByteRcvd: the number of the last byte in the data stream that has arrived
from the network and has been placed in the receive buffer at B
-Because TCP is not permitted to overflow the allocated buffer, we must have
LastByteRcvd – LastByteRead <=RcvBuffer
-The receive window, denoted rwnd is set to the amount of spare room in the buffer:
rwnd = RcvBuffer – [LastByteRcvd – LastByteRead]
-Because the spare room changes with time, rwnd is dynamic.
-Host B tells Host A how much spare room it has in the connection buffer by placing its current value
of rwnd in the receive window field of every segment it sends to A.
-Initially, Host B sets rwnd = RcvBuffer.
-Host A makes sure throughout the connection’s life that
LastByteSent – LastByteAcked <=rwnd
34
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
35
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
Suppose that the client application decides it wants to close the connection.
➢ This causes the client TCP to send a TCP segment with the FIN bit set to 1 and to
enter the FIN_WAIT_1 state.
➢ While in the FIN_WAIT_1 state, the client TCP waits for a TCP segment from the
server with an acknowledgment.
➢ When it receives this segment, the client TCP enters the FIN_WAIT_2 state.
➢ While in the FIN_WAIT_2 state, the client waits for another segment from the server
with the FIN bit set to 1; after receiving this segment, the client TCP acknowledges
the server’s segment and enters the TIME_WAIT state.
➢ The TIME_WAIT state lets the TCP client resend the final acknowledgment in case
the ACK is lost.
36
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
37
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
-The life of a TCP connection, the TCP protocol running in each host makes transitions through various
TCP states.
-The client TCP begins in the CLOSED state.
-The application on the client side initiates a new TCP connection.
-This causes TCP in the client to send a SYN segment to TCP in the server.
-After having sent the SYN segment, the client TCP enters the SYN_SENT state.
-While in the SYN_SENT state, the client TCP waits for a segment from the server TCP that includes
an acknowledgment for the client’s previous segment and has the SYN bit set to 1.
-Having received such a segment, the client TCP enters the ESTABLISHED state.
-While in the ESTABLISHED state, the TCP client can send and receive TCP segments containing
payload (that is, application-generated) data.
• What is congestion?
o too much demand for the available supply of a resource
o if there are too many senders trying to send a packet through the network
o Problems:
38
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
▪ delay
▪ loss
o Costs of congestion:
1. the sender must send retranstmissions in order to compansater for
packets being dropped due to buffer overflow.
2. unneeded retranstmissions by the sender in the face of large delays may
cause a router to waste its link bandwidth forwarding unneeded copies of
a packet.
3. when a packet is dropped along a path, the transmission capacity that was
used at each of the stream links to forward that packet to the point it was
dropped have been wasted.
o Approaches to Congestion Control
▪ End-to-end:
▪ No explicit feedback
▪ Congestion Inferred:
▪ From End-System
▪ Observed Loss
▪ Delay
▪ TCP
▪ Network Assisted:
▪ Network feedback:
▪ from router
▪ single bit
▪ explicit Rate
▪ ATM
• In an end-to-end approach to congestion control, the network layer offers no explicit support
to the transport layer for congestion control.
• TCP segment loss (as indicated by a timeout or the receipt of three duplicate
acknowledgments) is taken as an indication of network congestion, and TCP decreases its
window size accordingly. Increasing round trip segment delay as an indicator of increased
network congestion
• In network assisted congestion control, routers provide explicit feedback to the sender
and/or receiver regarding the network's congestion state. Feedback may range from a
simple bit indicating congestion at a link to more sophisticated feedback, such as informing
the sender of the maximum host sending rate a router can support.
• Direct Feedback: A network router directly sends feedback to the sender, often in the form
of a choke packet indicating congestion.
39
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
• TCP limits the rate at which it sends traffic into its connection as a function of perceived network
congestion. The TCP congestion-control mechanism operating at the sender keeps track of an
additional variable: the congestion window, noted cwnd which imposes a constraint on the
rate at which a TCP sender can send traffic into the network.
• Specifically: LastByteSent - LastByteAcked <= min{cwnd, rwnd}. Limiting the amount of
unacknowledged data at the sender we can limit the sender's send rate. At the beginning of
each RTT the sender sends cwnd bytes of data and at the end of the RTT he acknowledges. Thus
the sender's send rate is roughly cwnd/RTT bytes/sec.
• Adjusting the value of cwnd the sender can adjust the rate at which it sends data into the
connection. Let now consider a loss event (timeout OR three duplicate ACKs).
• When there is excessive congestion some router buffers along the path overflows, causing a loss
event at the sender which is taken by the sender to be an indication of congestion on the sender-
to-receiver path.
• If there is no congestion then all the acknowledgements will be received at the sender, which
will take these arrivals as an indication that segments have been received and that he can
increase the congestion window size and hence its transmission rate.
• If acknowledgements arrive at a slow rate then the congestion window will be increased at a
relatively slow rate and, vice versa, it will be increased more quickly if ACKs arrive at a high
40
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
rate. Because TCP uses acknowledgements to trigger (or clock) its increase in congestion window
size, TCP is said to be self-clocking. TCP uses the principles:
1. A lost segment implies congestion therefore the sender rate should be decreased.
2. An acknowledged segment means the network's working, therefore the sender's rate can be
increased (if ACK of unacknowledged segment)
3. Bandwidth probing: the transmission rates increases with ACKs and decreases with loss
events: TCP is continuously checking (probing) the congestion state of the network
Three components :
1 - Slow Start
When a TCP connection begins, cwnd is usually initialized to a small value of 1 MSS and only one
segment is sent. Each acknowledged packet will cause the cwnd to be increased by 1 MSS and the
sender will send now two segments (because the window is increased by one for each ack).
Therefore, the number of segments doubles at each RTT, therefore the sending rate also doubles
every RTT. Thus, the TCP send rate starts slow but grows exponentially during the slow start
phase. When does the growth end?
• Timeout: cwnd is set to 1 MSS and the slow start is started anew. Also the variable slow start
threshold is initialized: ssthresh = cwnd / 2 - (half of value of cwnd when congestion is
detected)
• When cwnd >= ssthresh slow starts is stopped -> congestion avoidance state
• Three duplicate ACKs: fast retransmit and fast recovery state
41
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
2 - Congestion Avoidance
TCP suppose congestion is present, how to adapt? Instead of doubling cwnd every RTT, cwnd is
increased by just a single MSS every RTT. When should this linear increase stop?
• Timeout: cwnd is set to 1 MSS, and ssthresh = cwnd (when loss happened) / 2
• Three duplicate ACKs: cwnd = (cwnd / 2) + 3 MSS and ssthresh = cwnd (when 3 ACKs
received) / 2 -> fast recovery state
3 - Fast Recovery
cwnd is increased by 1 MSS for every duplicate ACK received for the missing state that caused
TCP to enter this state. When the ACK arrives for the missing segment, TCP goes into Congestion
Avoidance after reducing cwnd. If a timeout occurs cwnd is set to 1 MSS and ssthresh is set to half
the value of cwnd when the loss event occurred. Fast recovery is recommended but not required in
TCP, in fact only the newer version of TCP, TCP Reno incorporated fast recovery.
42
COMPUTER SCIENCE AND ENGINEERING
GITAM SCHOOL OF TECHNOLOGY
What is the average throughput (average rate) of a long-lived TCP connection? Ignoring the slow
start phase (usually very short as the rate grows exponentially). When the window size is w the
transmission rate is roughly w/RTT. w is increased by 1 MSS each RTT until a loss event. Denote by
W the value of w when a loss event occurs. Then we have
Today's high speed links allow to have huge windows. What happens if one of the segments in the
window gets lost? What fraction of the transmitted segments could be lost that would allow the TCP
congestion control to achieve the desired rate?
TCP's congestion control exhibits saw tooth behavior, referred to as additive increase,
multiplicative decrease (AIMD). AIMD aims to simultaneously optimize user and network
performance, probing for available bandwidth in an asynchronous manner.
43