RFC 7982 PROPOSED STANDARD STUN · MEASUREMENT · NAT TRAVERSAL

STUN RTT & Loss: Measurement of Round-Trip Time and Fractional Loss Using Session Traversal Utilities for NAT (STUN)

A small STUN attribute that counts retransmissions so endpoints can measure round-trip time and see which direction lost packets.

On rfc-editor.org ↗
PUBLISHED
September 2016
AUTHORS
P. Martinsen, T. Reddy, D. Wing, V. Singh
STREAM
IETF
STUN ATTRIBUTE TYPE
0x8025 (comprehension-optional)
ATTRIBUTE VALUE SIZE
32 bits
FIRST REQUEST REQ VALUE
1
TRANSACTION ID SIZE
96 bits
DOI
10.17487/RFC7982

RFC text

Contents
Original text · RFC Editor View on rfc-editor.org ↗
Internet Engineering Task Force (IETF)                      P. Martinsen
Request for Comments: 7982                                      T. Reddy
Category: Standards Track                                          Cisco
ISSN: 2070-1721                                                  D. Wing

                                                                V. Singh
                                                            callstats.io
                                                          September 2016


           Measurement of Round-Trip Time and Fractional Loss
            Using Session Traversal Utilities for NAT (STUN)

Abstract

   A host with multiple interfaces needs to choose the best interface
   for communication.  Oftentimes, this decision is based on a static
   configuration and does not consider the path characteristics, which
   may affect the user experience.

   This document describes a mechanism for an endpoint to measure the
   path characteristics fractional loss and RTT using Session Traversal
   Utilities for NAT (STUN) messages.

Status of This Memo

   This is an Internet Standards Track document.

   This document is a product of the Internet Engineering Task Force
   (IETF).  It represents the consensus of the IETF community.  It has
   received public review and has been approved for publication by the
   Internet Engineering Steering Group (IESG).  Further information on
   Internet Standards is available in Section 2 of RFC 7841.

   Information about the current status of this document, any errata,
   and how to provide feedback on it may be obtained at
   http://www.rfc-editor.org/info/rfc7982.

Copyright Notice

   Copyright (c) 2016 IETF Trust and the persons identified as the
   document authors.  All rights reserved.

   This document is subject to BCP 78 and the IETF Trust's Legal
   Provisions Relating to IETF Documents
   (http://trustee.ietf.org/license-info) in effect on the date of
   publication of this document.  Please review these documents
   carefully, as they describe your rights and restrictions with respect
   to this document.  Code Components extracted from this document must
   include Simplified BSD License text as described in Section 4.e of
   the Trust Legal Provisions and are provided without warranty as
   described in the Simplified BSD License.

Table of Contents

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   3
   2.  Notational Conventions  . . . . . . . . . . . . . . . . . . .   4
   3.  Measuring RTT and Fractional Loss . . . . . . . . . . . . . .   4
     3.1.  TRANSACTION_TRANSMIT_COUNTER Attribute  . . . . . . . . .   4
     3.2.  Usage in Requests . . . . . . . . . . . . . . . . . . . .   5
     3.3.  Usage in Responses  . . . . . . . . . . . . . . . . . . .   5
     3.4.  Example Operation . . . . . . . . . . . . . . . . . . . .   6
   4.  IANA Considerations . . . . . . . . . . . . . . . . . . . . .   7
   5.  Security Considerations . . . . . . . . . . . . . . . . . . .   7
   6.  References  . . . . . . . . . . . . . . . . . . . . . . . . .   8
     6.1.  Normative References  . . . . . . . . . . . . . . . . . .   8
     6.2.  Informative References  . . . . . . . . . . . . . . . . .   9
   Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . .   9
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  10

1.  Introduction

   This document extends STUN [RFC5389] to make it possible to correlate
   STUN responses to specific requests when retransmits occur.  This
   assists the client in determining path characteristics like round-
   trip time (RTT) and fractional packet loss.

   The TRANSACTION_TRANSMIT_COUNTER attribute introduced in Section 3.1
   can be used in Interactive Connectivity Establishment (ICE) [RFC5245]
   connectivity checks (STUN Binding request and response).  It can also
   be used with Traversal Using Relays around NAT (TURN) [RFC5766] by
   adding this attribute to Allocate requests and responses to measure
   loss and RTT between the client and the respective TURN server.

   ICE is a mechanism commonly used in Voice over IP (VoIP) applications
   to traverse NATs, and it uses a static prioritization formula to
   order the candidate pairs and perform connectivity checks, in which
   the most preferred address pairs are tested first, and when a
   sufficiently good pair is discovered, that pair is used for
   communications and then further connectivity tests are stopped.

   When multiple paths are available for communication, the endpoint
   sends ICE connectivity checks across each path (candidate pair).
   Choosing the path with the lowest round-trip time is a reasonable
   approach, but retransmits can cause an otherwise good path to appear
   flawed.  However, STUN's retransmission algorithm [RFC5389] cannot
   determine the round-trip time (RTT) if a STUN request packet is
   retransmitted because each request and retransmission packet is
   identical.  Further, several STUN requests may be sent before the
   connectivity between candidate pairs are ascertained (see Section 16
   of [RFC5245]).  To resolve the issue of identical request and
   response packets in a STUN transaction, this document changes the
   retransmission behavior for idempotent packets.  Using the mechanism
   described herein, a client can determine RTT as well as get a hint
   regarding which path direction caused packet loss.  This is achieved
   by defining a new STUN attribute and requires compliant STUN (TURN
   and ICE) endpoints to count request packets.

   The mechanisms described in this document can be used by the
   controlling agent to influence the ICE candidate pair selection.  How
   ICE will actually use this information to improve the active
   candidate pair selection is outside the scope of this document.

2.  Notational Conventions

   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
   "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
   document are to be interpreted as described in [RFC2119].

   This specification uses terminology defined in ICE [RFC5245] and STUN
   [RFC5389].

3.  Measuring RTT and Fractional Loss

   This document defines a new comprehension-optional STUN attribute
   TRANSACTION_TRANSMIT_COUNTER with a STUN Type 0x8025.  This type is
   in the comprehension-optional range, which means that STUN agents can
   safely ignore the attribute.  If ICE is in use, it will fall back to
   normal procedures.

   If a client wishes to measure RTT, it inserts the
   TRANSACTION_TRANSMIT_COUNTER attribute in a STUN request.  In this
   attribute, the client sends the number of times the STUN request is
   transmitted with the same transaction ID.  The server would echo back
   the transmission count in the response so that the client can
   distinguish between STUN responses coming from retransmitted
   requests.  Hence, the endpoint can use the STUN requests and
   responses to determine the round-trip time (RTT).  The server may
   also convey the number of responses it has sent for the STUN request
   to the client.  Further, this information enables the client to get a
   hint regarding in which direction the packet loss occurred.  In some
   cases, it is impossible to distinguish between packet reordering and
   packet loss.  However, if this information is collected as network
   metrics from several clients over a longer time period, it will be
   easier to detect a pattern that can provide useful information.

3.1.  TRANSACTION_TRANSMIT_COUNTER Attribute

   The TRANSACTION_TRANSMIT_COUNTER attribute in a STUN request takes a
   32-bit value.  This document updates one of the STUN message
   structuring rules explained in Section 6 of [RFC5389] wherein
   retransmission of the same request reuses the same transaction ID and
   is bit-wise identical to the previous request.  For idempotent
   packets, the Req and Resp fields in the TRANSACTION_TRANSMIT_COUNTER
   attribute will be incremented by 1 by the client or server for every
   transmission with the same transaction ID.  Any retransmitted STUN
   request MUST be bit-wise identical to the previous request except for
   the values in the TRANSACTION_TRANSMIT_COUNTER attribute.

   The IANA-assigned STUN type for the new attribute is 0x8025.

   The format of the value in the TRANSACTION_TRANSMIT_COUNTER attribute
   in the request is:

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       |        Reserved (Padding)     |    Req        |     Resp      |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

        Figure 1: TRANSACTION_TRANSMIT_COUNTER Attribute in Request

   The fields are described below:

   Req:  Number of times the request is transmitted with the same
      transaction ID to the server.

   Resp:  Number of times a response with the same transaction ID is
      sent from the server.  MUST be set to zero in requests and ignored
      by the receiver.

   The padding is necessary to hit the 32-bit boundary needed for STUN
   attributes.  The padding bits are ignored, but to allow for future
   reuse of these bits, they MUST be set to zero.

3.2.  Usage in Requests

   When sending a STUN request, the TRANSACTION_TRANSMIT_COUNTER
   Attribute allows a client to indicate to the server that it wants to
   measure RTT and get a hint about the direction of any packet loss.

   The client MUST populate the Req value in the
   TRANSACTION_TRANSMIT_COUNTER.  This value MUST reflect the number of
   requests that have been transmitted to the server.  Therefore, the
   initial value for the first request sent is 1.  The first retransmit
   will set the value to 2 and so on.

   The Resp field in the attribute MUST be set to zero in the request.

3.3.  Usage in Responses

   When a server receives a STUN request that includes a
   TRANSACTION_TRANSMIT_COUNTER attribute, it processes the request as
   per the STUN protocol [RFC5389] plus the specific rules mentioned
   here.  The server checks the following:

   o  If the TRANSACTION_TRANSMIT_COUNTER attribute is not recognized,
      ignore the attribute because its type indicates that it is
      comprehension-optional.  This should be the existing behavior as
      explained in Section 7.3 of [RFC5389].

   o  The server that supports the TRANSACTION_TRANSMIT_COUNTER
      attribute MUST echo back the Req field in the response using a
      TRANSACTION_TRANSMIT_COUNTER attribute.

   o  If the server is stateless or does not want to remember the
      transaction ID, then it populates value 0 for the Resp field in
      the TRANSACTION_TRANSMIT_COUNTER attribute sent in the response.
      If the server is stateful, then it populates the Resp field with
      the number of responses it has sent for the STUN request.

   A client that receives a STUN response with a
   TRANSACTION_TRANSMIT_COUNTER can check the values in the Req field to
   accurately calculate the RTT if retransmits are occurring.

   If the server sending the STUN response is stateless, the value of
   the Resp field will always be 0.  If the server keeps state of the
   numbers of STUN requests with that same transaction ID, the value
   will reflect how many packets the server has seen and responded to.
   This gives the client a hint about in which direction loss occurred.
   See Section 3.4 for more details.

3.4.  Example Operation

   An example operation, when a server is stateful, is described in
   Figure 2.  In the first case, all the requests and responses are
   received correctly.

   In the case of upstream loss, the first request is lost, but the
   second one is received correctly.  The client, upon receiving the
   response, notes that while two requests were sent, only one was
   received by the server.  The server also realizes that the value in
   the Req field does not match the number of received requests,
   therefore one request was lost.  This may also occur at startup in
   the presence of firewalls or NATs that block unsolicited incoming
   traffic.

   In the case of downstream loss, the responses get lost, the client
   expecting multiple responses notes that, while the server responded
   to three requests, only one response was received.

   In the case of loss in both directions, requests and responses get
   lost in tandem, the server notes that one request packet was not
   received, while the client expecting three responses received only
   one, and then it notes that one request and response packet were
   lost.

   |     Normal    |  Upstream loss | Downstream loss | Both upstream &|
   |               |                |                 | downstream loss|
   | Client Server |  Client Server |  Client  Server |  Client Server |
   |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+|
   | 1        1,1  |  1        x    |  1         1,1  |  1        x    |
   |   1,1         |                |    x            |                |
   |               |  2        2,1  |  2         2,2  |  2        2,1  |
   |               |    2,1         |    x            |    x           |
   |               |                |  3         3,3  |  3        3,2  |
   |               |                |    3,3          |    3,2         |

         Figure 2: Retransmit Operation between Client and Server

   Another example is when the client sends two requests but the second
   request arrives at the server before the first request because of
   out-of-order delivery.  In this case, the stateful server populates
   value 1 for the Resp field in the TRANSACTION_TRANSMIT_COUNTER
   attribute sent in response to the second request and value 2 for the
   Resp field in the TRANSACTION_TRANSMIT_COUNTER attribute sent in
   response to the first request.

   The intention with this mechanism is not to carry out comprehensive
   and accurate measurements regarding in what direction loss is
   occurring.  In some cases, it might not be able to distinguish the
   difference between downstream loss and packet reordering.

4.  IANA Considerations

   This document defines the TRANSACTION_TRANSMIT_COUNTER STUN
   attribute, described in Section 3.  IANA has allocated the
   comprehension-optional codepoint 0x8025 for this attribute.

5.  Security Considerations

   Security considerations discussed in [RFC5389] are to be taken into
   account.  STUN requires that the 96-bit transaction ID be uniformly
   and randomly chosen from the interval 0 .. 2**96-1, and be
   cryptographically strong.  This is good enough security against an
   off-path attacker.  An on-path attacker can either inject a fake
   response or modify the values in the TRANSACTION_TRANSMIT_COUNTER
   attribute to mislead the client and server.  This attack can be
   mitigated using STUN authentication.  As the
   TRANSACTION_TRANSMIT_COUNTER is expected to be used between peers
   using ICE, and ICE uses a STUN short-term credential mechanism, the
   risk of an on-path attack influencing the messages is minimal.  If
   the TRANSACTION_TRANSMIT_COUNTER is used with an Allocate request,
   one of the following mechanisms can be used to prevent attackers from
   trying to impersonate a TURN server and sending a bogus
   TRANSACTION_TRANSMIT_COUNTER attribute in the Allocate response:
   1) the STUN long-term credential mechanism, 2) the STUN Extension for
   Third-Party Authorization [RFC7635], or 3) a TLS or DTLS connection
   between the TURN client and the TURN server.  However, an attacker
   could corrupt, remove, or delay an ICE request or response, in order
   to discourage that path from being used.

   If not encrypted, the information sent in any STUN packet can
   potentially be observed passively and used for reconnaissance and
   later attacks.

6.  References

6.1.  Normative References

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119,
              DOI 10.17487/RFC2119, March 1997,
              <http://www.rfc-editor.org/info/rfc2119>.

   [RFC5245]  Rosenberg, J., "Interactive Connectivity Establishment
              (ICE): A Protocol for Network Address Translator (NAT)
              Traversal for Offer/Answer Protocols", RFC 5245,
              DOI 10.17487/RFC5245, April 2010,
              <http://www.rfc-editor.org/info/rfc5245>.

   [RFC5389]  Rosenberg, J., Mahy, R., Matthews, P., and D. Wing,
              "Session Traversal Utilities for NAT (STUN)", RFC 5389,
              DOI 10.17487/RFC5389, October 2008,
              <http://www.rfc-editor.org/info/rfc5389>.

   [RFC5766]  Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using
              Relays around NAT (TURN): Relay Extensions to Session
              Traversal Utilities for NAT (STUN)", RFC 5766,
              DOI 10.17487/RFC5766, April 2010,
              <http://www.rfc-editor.org/info/rfc5766>.

6.2.  Informative References

   [RFC7635]  Reddy, T., Patil, P., Ravindranath, R., and J. Uberti,
              "Session Traversal Utilities for NAT (STUN) Extension for
              Third-Party Authorization", RFC 7635,
              DOI 10.17487/RFC7635, August 2015,
              <http://www.rfc-editor.org/info/rfc7635>.

Acknowledgements

   Thanks to Brandon Williams, Simon Perreault, Aijun Wang, Martin
   Thomson, Oleg Moskalenko, Ram Mohan Ravindranath, Spencer Dawkins,
   Suresh Krishnan, Ben Campbell, Mirja Kuehlewind, Lionel Morand,
   Kathleen Moriarty, and Alissa Cooper for their valuable input and
   comments.

Authors' Addresses

   Paal-Erik Martinsen
   Cisco Systems, Inc.
   Philip Pedersens vei 22
   Lysaker, Akershus  1325
   Norway

   Email: palmarti@cisco.com


   Tirumaleswar Reddy
   Cisco Systems, Inc.
   Cessna Business Park, Varthur Hobli
   Sarjapur Marathalli Outer Ring Road
   Bangalore, Karnataka  560103
   India

   Email: tireddy@cisco.com


   Dan Wing

   Email: dwing-ietf@fuggles.com


   Varun Singh
   CALLSTATS I/O Oy
   Runeberginkatu 4c A 4
   Helsinki  00100
   Finland

   Email: varun@callstats.io
   URI:   https://www.callstats.io/about

AI ELI5

On this page
PROBLEMSTUN retransmissions are bit-wise identical, so a client cannot tell which transmission a response answers. That makes round-trip time hard to measure and makes a good path look flawed.
MECHANISMA new TRANSACTION_TRANSMIT_COUNTER attribute carries a Req count set by the client and a Resp count set by the server. The server echoes Req back, so the client can match each response to the transmission that caused it.
WHY IT MATTERSClients can compute RTT even when retransmits occur and get a hint about whether requests or responses were lost. It is meant as a hint, not a precise measurement.

§1Why STUN Needs Transmit Counters

RFC 7982 extends STUN (RFC 5389) so that a client can correlate STUN responses with specific requests when retransmits occur. This helps the client work out path characteristics such as round-trip time (RTT) and fractional packet loss.

The motivation is ICE (RFC 5245), which sends connectivity checks over each candidate pair and uses a static prioritization formula. Choosing the path with the lowest RTT is reasonable, but retransmits can make an otherwise good path look flawed. STUN's retransmission algorithm cannot determine RTT when a request is retransmitted, because each request and retransmission is identical.

The attribute can be used in ICE connectivity checks (STUN Binding request and response) and in TURN Allocate requests and responses (RFC 5766) to measure loss and RTT to a TURN server. How ICE uses the numbers to improve candidate pair selection is outside the scope of the document.

When a message is sent again and again, every copy looks the same, so you cannot tell which copy got the reply. This document puts a counter on each copy so you can.

§2The TRANSACTION_TRANSMIT_COUNTER Attribute

The document defines a new comprehension-optional STUN attribute, TRANSACTION_TRANSMIT_COUNTER, with STUN type 0x8025. Because the type is in the comprehension-optional range, STUN agents that do not know it can safely ignore it, and ICE falls back to normal procedures.

The attribute value is 32 bits. A 16-bit Reserved (Padding) field is followed by two 8-bit counters:

  • Req: the number of times the request has been transmitted with the same transaction ID.
  • Resp: the number of times a response with the same transaction ID has been sent by the server. It MUST be set to zero in requests and is ignored by the receiver.

The padding exists to reach the 32-bit boundary needed for STUN attributes. Receivers ignore the padding bits, but senders MUST set them to zero so the bits can be reused later.

This changes one STUN message structuring rule from RFC 5389, under which a retransmission is bit-wise identical to the previous request. Now a retransmitted request MUST be bit-wise identical except for the values in this attribute.

The attribute is a tiny tag with two numbers on it: how many times the question was asked, and how many times the answer was given. A few spare bits are left empty on purpose.

TRANSACTION_TRANSMIT_COUNTER VALUE IN A REQUEST (RFC 7982)
TRANSACTION_TRANSMIT_COUNTER value
FieldNameSizeValueDescription
RESERVEDReserved (Padding)2 bytesIgnored by receivers; MUST be set to zero.
REQReq1 byteTimes the request has been sent with the same transaction ID.
RESPResp1 byteResponses sent by the server; MUST be zero in requests.

§3Client and Server Rules

A client that wants to measure RTT adds the attribute to its STUN request. It MUST fill in Req with the number of requests transmitted to the server so far, so the first request carries 1, the first retransmit carries 2, and so on. Resp MUST be zero.

A server that supports the attribute processes the request as usual under RFC 5389 and MUST echo the Req field back in a TRANSACTION_TRANSMIT_COUNTER attribute in the response. A server that does not recognize the attribute ignores it, which is the existing comprehension-optional behavior.

The Resp field depends on whether the server keeps state:

  • A stateless server, or one that does not want to remember the transaction ID, sets Resp to 0.
  • A stateful server sets Resp to the number of responses it has sent for that request.

Using the echoed Req, the client can calculate RTT accurately even when retransmits occur. A nonzero Resp also tells the client how many requests the server has seen and answered, which hints at the direction in which loss occurred.

The asker numbers every try. The answerer repeats the number back, so the asker knows exactly which try the answer is for. A careful answerer also says how many answers it has given.

§4Example: Spotting Where Packets Are Lost

The RFC walks through four cases with a stateful server. In the normal case every request and response arrives. In the other cases the two counters disagree in a telling way:

  • Upstream loss: the first request is lost and the second arrives. The client sent two requests but the response shows the server saw only one.
  • Downstream loss: the server responded to three requests, but the client received only one response.
  • Loss in both directions: the server notes that one request never arrived, and the client expecting three responses received only one.

Upstream loss may also occur at startup when firewalls or NATs block unsolicited incoming traffic. In a reordering example, the second request reaches the server first, so the stateful server answers it with Resp 1 and answers the first request with Resp 2.

The RFC says the goal is not comprehensive or accurate loss measurement. In some cases downstream loss cannot be told apart from reordering, but collecting the metrics from several clients over a longer period makes patterns easier to see.

Counting how many tries were sent and how many were heard lets you guess whether your voice did not carry or the reply got lost on the way back.

UPSTREAM LOSS, STATEFUL SERVER (AFTER RFC 7982 FIGURE 2)
ClientServer
  1. Request, Req=1 (lost)The first request never reaches the server.
  2. Request, Req=2The retransmit arrives.
  3. Response, Req=2 Resp=1The server has seen and answered one request, though two were sent.

§5Security and IANA Considerations

IANA has allocated the comprehension-optional codepoint 0x8025 for the attribute. For security, the considerations of RFC 5389 apply. STUN requires the 96-bit transaction ID to be uniformly random and cryptographically strong, which is good enough against an off-path attacker.

An on-path attacker can inject a fake response or modify the counter values to mislead the client and server. STUN authentication mitigates this, and since ICE uses the STUN short-term credential mechanism, the risk is judged minimal for ICE peers.

If the attribute is used with a TURN Allocate request, impersonation of the server can be prevented with the STUN long-term credential mechanism, third-party authorization (RFC 7635), or a TLS or DTLS connection. An attacker could still corrupt, remove or delay an ICE request or response to discourage a path. Unencrypted STUN packets can be observed passively and used for reconnaissance.

Someone sitting in the middle could scribble on the counters to fool both sides, so the messages should be signed or sent privately.

§6References