Buffering and Flow Control

Exercise 168 What is a good value for the timeout interval?

13.2.2 Buffering and Flow Control

We saw that the sender of a message must buffer it until it is acknowledged, because a resend may be needed. But the recipient and the routers along the way may also need to buffer it. Flow control is needed to manage limited buffer space The recipient of a message must have a buffer large enough to hold at least a single packet — otherwise when a packet comes in, there will be nowhere to store it. In fact, the need to bound the size of this buffer is the reason for specifying the maximal transfer unit allowed by a network. Even when the available buffer space is more than a single packet, it is still bounded. If more packets arrive than there is space in the buffer, the buffer will overflow . The extra packets have nowhere to go, so they are dropped, meaning that for all intents and purposes they are lost. The situation in which the network is overloaded and drops packets is called congestion. In order to avoid congestion, flow control is needed. Each sender has to know how much free space is available in the recipient’s buffers. It will only send data that can fit into this buffer space. Then it will stop transmitting, until the recipient indicates that some buffer space has been freed. Only resends due to transmission errors are not subject to this restriction, because they replace a previous transmission that was already taken into account. Exercise 169 Is it realistic to know exactly how much buffer space is available? Hint: think of situations in which several different machines send data to the same destina- tion. Piggybacking reduces overhead We saw that the recipient needs to inform the sender of two unrelated conditions: • That data has arrived correctly or not ack or nack, so that the sender will know if it can discard old data or has to retransmit it. • That buffer space is available for additional transmissions. Instead of sending such control data in independent messages, it is possible to com- bine them into one message. Moreover, if the communication is bidirectional, the control data can piggyback on the data going in the other direction. Thus the headers of datagrams going from A to B contain routing and error correction for the data going from A to B, and control for data going from B to A. The opposite is true for headers of datagrams flowing from B to A. 223 A data header B data header control for other direction Large buffers improve utilization of network resources If the buffer can only contain a single packet, the flow control implies that packets be sent one by one. When each packet is extracted by the application to which it is destined, the recipient computer will notify the sender, and another packet will be sent. Even if the application extracts the packets as soon as they arrive, this will lead to large gaps between packets, due to the time needed for the notification known as the round-trip time RTT. With larger buffers, a number of packets can be sent in sequence. This overlaps the transmissions with the waiting time for the notifications. In the extreme case when the propagation delay is the dominant part of the time needed for communication, the effective bandwidth is increased by a factor equal to the number of packets sent. data extracted host A host B packets sent notification of free space request to send time to traverse the net by application Exercise 170 Denote the network bandwidth by B, and the latency to traverse the net- work by t ℓ . Assuming data is extracted as soon as it arrives, what size buffer is needed to keep the network 100 utilized? Adaptivity can be used to handle changing conditions Real implementations don’t depend on a hardcoded buffer size. Instead, the flow control depends on a sliding window whose size can be adjusted. 224 The considerations for setting the window size are varied. On one hand is the desire to achieve the maximal possible bandwidth. As the bandwidth is limited by BW ≤ windowRT T , situations in which the RTT is large imply the use of a large window and long timeouts. For example, this is the case when satellite links are employed. Such links have a propagation delay of more than 0.2 seconds, so the round-trip time is nearly half a second. The delay on terrestrial links, by contrast, is measured in milliseconds. Exercise 171 Does this mean that high-bandwidth satellite links are useless? On the other hand, a high RTT can be the result of congestion. In this case it is better to reduce the window size, in order to reduce the overall load on the network. Such a scheme is used in the flow control of TCP, and is described below. An efficient implementation employs linked lists and IO vectors The management of buffer space for packets is difficult for two reasons: • Packets may come in different sizes, although there is an upper limit imposed by the network. • Headers are added and removed by different protocol layers, so the size of the message and where it starts may change as it is being processed. It is desirable to handle this without copying it to a new memory location each time. The solution is to store the data in a linked list of small units, sometimes called mbufs, rather than in one contiguous sequence. Adding a header is then done by writing it in a separate mbuf, and prepending it to the list. The problem with a linked list structure is that now it is impossible to define the message by its starting address and size, because it is not contiguous in memory. Instead, it is defined by an IO vector: a list of contiguous chunks, each of which is defined by its starting point and size.

13.2.3 TCP Congestion Control