| | 24 | The motivation for uTP is for BitTorrent clients to not disrupt |
| | 25 | internet connections, while still utilizing the unused bandwidth |
| | 26 | fully. |
| | 27 | |
| | 28 | The problem is that DSL and cable modems typically have a send |
| | 29 | buffer disproportional to their max send rate, which can hold several |
| | 30 | seconds worth of packets. BitTorrent traffic is typically background |
| | 31 | transfers, and should have lower priority than checking email, |
| | 32 | phone calls and browsing the web, but when using regular TCP |
| | 33 | connections BitTorrent quickly fills up the send buffer, adding |
| | 34 | multiple seconds delay to all interactive traffic. |
| | 35 | |
| | 36 | The fact that BitTorrent uses multiple TCP connections gives it an |
| | 37 | unfair advantage when competing with other services for bandwidth, |
| | 38 | which exaggerates the effect of BitTorrent filling the upload pipe. |
| | 39 | |
| | 40 | The traditional solution to this problem is to cap the upload rate |
| | 41 | of the bittorrent client to 80% of the uplink capacity. 80% leaves |
| | 42 | some head room for interactive traffic. |
| | 43 | |
| | 44 | The main drawbacks with this solution are: |
| | 45 | |
| | 46 | 1. The user needs to configure his/her bittorrent client, it won't |
| | 47 | work out-of-the-box. |
| | 48 | 2. The user needs to know his/her internet connection's upload |
| | 49 | capacity. This capacity may change, especially on laptops that |
| | 50 | may connect to a large number of different networks. |
| | 51 | 3. The headroom of 20% is arbitrary and wastes bandwidth. Whenever |
| | 52 | there is no interactive traffic competing with bittorrent, the |
| | 53 | extra 20% are wasted. Whenever there is competing interactive |
| | 54 | traffic, it cannot use more than 20% of the capacity. |
| | 55 | |
| | 56 | uTP solves this problem by using the modem queue size as a controller |
| | 57 | for its send rate. When the queue grows too large, it throttles back. |
| | 58 | |
| | 59 | This lets it utilize the full upload capacity when there is no |
| | 60 | competition for it, and it lets it throttle back to virtually nothing |
| | 61 | when there is a lot of interactive traffic. |
| | 62 | |
| 24 | | connection setup |
| 25 | | ---------------- |
| | 66 | This document assumes some knowledge of how TCP and window based |
| | 67 | congestion control works. |
| | 68 | |
| | 69 | The main addition compared to TCP is the delay based congestion |
| | 70 | control. See the `congestion control`_ section. |
| | 71 | |
| | 72 | Like TCP, uTP uses window based congestion control. Each socket |
| | 73 | has a ``max_window`` which determines the maximum number of bytes |
| | 74 | the socket may have *in-flight* at any given time. Any packet that |
| | 75 | has been sent, but not yet acked, is considered to be in-flight. |
| | 76 | |
| | 77 | The number of bytes in-flight is ``cur_window``. |
| | 78 | |
| | 79 | A socket may only send a packet if ``cur_window`` + ``packet_size`` |
| | 80 | is less than or equal to min(``max_window``, ``wnd_size``). |
| | 81 | The packet size may vary, see the `packet sizes`_ section. |
| | 82 | |
| | 83 | ``wnd_size`` is the advertised window from the other end. It sets |
| | 84 | an upper limit on the number of packets in-flight. |
| | 85 | |
| | 86 | An implementation MAY violate the above rule if the ``max_window`` |
| | 87 | is smaller than the packet size, and it paces the packets so that |
| | 88 | the average ``cur_window`` is less than or equal to ``max_window``. |
| | 89 | |
| | 90 | Each socket keeps a state for the last delay measurement from the |
| | 91 | other endpoint (``reply_micro``). Whenever a packet is received, |
| | 92 | this state is updated by subtracting ``timestamp_microseconds`` |
| | 93 | from the hosts current time, in microseconds (see `header format`_). |
| | 94 | |
| | 95 | Every time a packet is sent, the sockets ``reply_micro`` value is |
| | 96 | put in the ``timestamp_difference_microseconds`` field of the packet |
| | 97 | header. |
| | 98 | |
| | 99 | Unlike TCP, sequence numbers and ACKs in uTP refers to packets, not |
| | 100 | bytes. This means uTP cannot *repackage* data when resending it. |
| | 101 | |
| | 102 | Each socket keeps a state of the next sequence number to use when |
| | 103 | sending a packet, ``seq_nr``. It also keeps a state of the sequence |
| | 104 | number that was last received, ``ack_nr``. The oldest unacked packet |
| | 105 | is ``seq_nr`` - ``cur_window``. |
| 85 | | acked. This is not the same as the next sequence number minus the last acked |
| 86 | | sequence number. Packets can be acked in the middle of the send window using |
| 87 | | the Selective ACK extension. Any acked packet is deducted from the current |
| 88 | | window size, and allows the sender to send more packets to fill up the window. |
| | 162 | acked. The advertised receive window lets the other end cap the window size |
| | 163 | if it cannot receive any faster, if its receive buffer is filling up. |
| | 164 | |
| | 165 | When sending packets, this should be set to the number of bytes left in the |
| | 166 | socket's receive buffer. |
| | 289 | connection setup |
| | 290 | ---------------- |
| | 291 | |
| | 292 | *describe the initial connection setup sequence* |
| | 293 | |
| | 294 | packet loss |
| | 295 | ----------- |
| | 296 | |
| | 297 | If the packet with sequence number (``seq_nr`` - ``cur_window``) has not been acked |
| | 298 | (this is the oldest packet in the send buffer, and the next one expected to be acked) |
| | 299 | has not been acked, but 3 or more packets have been acked passed it (through Selective |
| | 300 | ACK), the packet is assumed to have been lost. Similarly, when receiving 3 duplicate |
| | 301 | acks, ``ack_nr`` + 1 is assumed to have been lost (if a packet with that sequence number |
| | 302 | has been sent). |
| | 303 | |
| | 304 | When a packet is lost, the ``max_window`` is multiplied by 0.78. |
| | 305 | |
| | 333 | |
| | 334 | Every time a socket sends or receives a packet, it updates its timeout counter. If |
| | 335 | no packet has arrived within ``timeout`` number of milliseconds from the last |
| | 336 | timeout counter reset, the socket triggers a timeout. It will set its ``packet_size`` |
| | 337 | and ``max_window`` to the smallest packet size (150 bytes). This allows it to send |
| | 338 | one more packet, and this is how the socket gets started again if the window size |
| | 339 | goes down to zero. |
| | 340 | |
| | 341 | The initial timeout is set to 1000 milliseconds, and later updated according to |
| | 342 | the formula above. For each packet that times out in a row, the timeout is |
| | 343 | doubled. |
| | 344 | |
| | 345 | packet sizes |
| | 346 | ------------ |
| | 347 | |
| | 348 | In order to have as little impact as possible on slow congested links, uTP adjusts |
| | 349 | its packet size down to as small as 150 bytes per packet. Using packets that small |
| | 350 | has the benefit of not clogging up a slow uplink, with long serialization delay. |
| | 351 | The cost of using packets that small is that the overhead from the packet headers |
| | 352 | become significant. At high rates, large packet sizes are used, at slow rates, |
| | 353 | small packet sizes are used. |