Section 6. Feature Negotiation

Four DCCP options, Change L, Confirm L, Change R, and Confirm R, are
   used to negotiate feature values.  Change options initiate a
   negotiation; Confirm options complete that negotiation.  The "L"
   options are sent by the feature location, and the "R" options are
   sent by the feature remote.  Change options are retransmitted to
   ensure reliability.
   All these options have the same format.  The first byte of option
   data is the feature number, and the second and subsequent data bytes
   hold one or more feature values.  The exact format of the feature
   value area depends on the feature type; see Section 6.3.
   +--------+--------+--------+--------+--------
   |  Type  | Length |Feature#| Value(s) ...
   +--------+--------+--------+--------+--------
   Together, the feature number and the option type ("L" or "R")
   uniquely identify the feature to which an option applies.  The exact
   format of the Value(s) area depends on the feature number.
   Feature negotiation options MUST NOT be sent on DCCP-Data packets,
   and any feature negotiation options received on DCCP-Data packets
   MUST be ignored.
6.1.  Change Options
   Change L and Change R options initiate feature negotiation.  The
   option to use depends on the relevant feature's location: To start a
   negotiation for feature F/A, DCCP A will send a Change L option; to
   start a negotiation for F/B, it will send a Change R option.  Change
   options are retransmitted until some response is received.  They
   contain at least one Value, and thus have a length of at least 4.
              +--------+--------+--------+--------+--------
   Change L:  |00100000| Length |Feature#| Value(s) ...
              +--------+--------+--------+--------+--------
               Type=32
              +--------+--------+--------+--------+--------
   Change R:  |00100010| Length |Feature#| Value(s) ...
              +--------+--------+--------+--------+--------
               Type=34
6.2.  Confirm Options
   Confirm L and Confirm R options complete feature negotiation and are
   sent in response to Change R and Change L options, respectively.
   Confirm options MUST NOT be generated except in response to Change
   options.  Confirm options need not be retransmitted, since Change
   options are retransmitted as necessary.  The first byte of the
   Confirm option contains the feature number from the corresponding
   Change.  Following this is the selected Value, and then possibly the
   sender's preference list.
              +--------+--------+--------+--------+--------
   Confirm L: |00100001| Length |Feature#| Value(s) ...
              +--------+--------+--------+--------+--------
               Type=33
              +--------+--------+--------+--------+--------
   Confirm R: |00100011| Length |Feature#| Value(s) ...
              +--------+--------+--------+--------+--------
               Type=35
   If an endpoint receives an invalid Change option -- with an unknown
   feature number, or an invalid value -- it will respond with an empty
   Confirm option containing the problematic feature number, but no
   value.  Such options have length 3.
6.3.  Reconciliation Rules
   Reconciliation rules determine how the two sets of preferences for a
   given feature are resolved into a unique result.  The reconciliation
   rule depends only on the feature number.  Each reconciliation rule
   must have the property that the result is uniquely determined given
   the contents of Change options sent by the two endpoints.
   All current DCCP features use one of two reconciliation rules:
   server-priority ("SP") and non-negotiable ("NN").
6.3.1.  Server-Priority
   The feature value is a fixed-length byte string (length determined by
   the feature number).  Each Change option contains a list of values
   ordered by preference, with the most preferred value coming first.
   Each Confirm option contains the confirmed value, followed by the
   confirmer's preference list.  Thus, the feature's current value will
   generally appear twice in Confirm options' data, once as the current
   value and once in the confirmer's preference list.
   To reconcile the preference lists, select the first entry in the
   server's list that also occurs in the client's list.  If there is no
   shared entry, the feature's value MUST NOT change, and the Confirm
   option will confirm the feature's previous value (unless the Change
   option was Mandatory; see Section 6.6.9).
6.3.2.  Non-Negotiable
   The feature value is a byte string.  Each option contains exactly one
   feature value.  The feature location signals a new value by sending a
   Change L option.  The feature remote MUST accept any valid value,
   responding with a Confirm R option containing the new value, and it
   MUST send empty Confirm R options in response to invalid values
   (unless the Change L option was Mandatory; see Section 6.6.9).
   Change R and Confirm L options MUST NOT be sent for non-negotiable
   features; see Section 6.6.8.  Non-negotiable features use the feature
   negotiation mechanism to achieve reliability.
6.4.  Feature Numbers
   This document defines the following feature numbers.
                                          Rec'n Initial        Section
   Number   Meaning                       Rule   Value  Req'd Reference
   ------   -------                       -----  -----  ----- ---------
      0     Reserved
      1     Congestion Control ID (CCID)   SP      2      Y     10
      2     Allow Short Seqnos             SP      0      Y     7.6.1
      3     Sequence Window                NN     100     Y     7.5.2
      4     ECN Incapable                  SP      0      N     12.1
      5     Ack Ratio                      NN      2      N     11.3
      6     Send Ack Vector                SP      0      N     11.5
      7     Send NDP Count                 SP      0      N     7.7.2
      8     Minimum Checksum Coverage      SP      0      N     9.2.1
      9     Check Data Checksum            SP      0      N     9.3.1
    10-127  Reserved
   128-255  CCID-specific features                              10.3
                      Table 4: DCCP Feature Numbers
   Rec'n Rule     The reconciliation rule used for the feature.  SP
                  means server-priority, NN means non-negotiable.
   Initial Value  The initial value for the feature.  Every feature has
                  a known initial value.
   Req'd          This column is "Y" if and only if every DCCP
                  implementation MUST understand the feature.  If it is
                  "N", then the feature behaves like an extension (see
                  Section 15), and it is safe to respond to Change
                  options for the feature with empty Confirm options.
                  Of course, a CCID might require the feature; a DCCP
                  that implements CCID 2 MUST support Ack Ratio and
                  Send Ack Vector, for example.
6.5.  Feature Negotiation Examples
   Here are three example feature negotiations for features located at
   the server, the first two for the Congestion Control ID feature, the
   last for the Ack Ratio.
                 Client                     Server
                 ------                     ------
      1. Change R(CCID, 2 3 1)  -->
         ("2 3 1" is client's preference list)
      2.                        <--  Confirm L(CCID, 3, 3 2 1)
                               (3 is the negotiated value;
                               "3 2 1" is server's pref list)
                  * agreement that CCID/Server = 3 *
      1.                   XXX  <--  Change L(CCID, 3 2 1)
      2.                             Retransmission:
                                <--  Change L(CCID, 3 2 1)
      3. Confirm R(CCID, 3, 2 3 1)  -->
                  * agreement that CCID/Server = 3 *
      1.                        <--  Change L(Ack Ratio, 3)
      2. Confirm R(Ack Ratio, 3)  -->
               * agreement that Ack Ratio/Server = 3 *
   This example shows a simultaneous negotiation.
                  Client                     Server
                  ------                     ------
      1a. Change R(CCID, 2 3 1)  -->
       b.                        <--  Change L(CCID, 3 2 1)
      2a.                        <--  Confirm L(CCID, 3, 3 2 1)
       b. Confirm R(CCID, 3, 2 3 1)  -->
                   * agreement that CCID/Server = 3 *
   Here are the byte encodings of several Change and Confirm options.
   Each option is sent by DCCP A.
   Change L(CCID, 2 3) = 32,5,1,2,3
      DCCP B should change CCID/A's value (feature number 1, a server-
      priority feature); DCCP A's preferred values are 2 and 3, in that
      preference order.
   Change L(Sequence Window, 1024) = 32,9,3,0,0,0,0,4,0
      DCCP B should change Sequence Window/A's value (feature number 3,
      a non-negotiable feature) to the 6-byte string 0,0,0,0,4,0 (the
      value 1024).
   Confirm L(CCID, 2, 2 3) = 33,6,1,2,2,3
      DCCP A has changed CCID/A's value to 2; its preferred values are 2
      and 3, in that preference order.
   Empty Confirm L(126) = 33,3,126
      DCCP A doesn't implement feature number 126, or DCCP B's proposed
      value for feature 126/A was invalid.
   Change R(CCID, 3 2) = 34,5,1,3,2
      DCCP B should change CCID/B's value; DCCP A's preferred values are
      3 and 2, in that preference order.
   Confirm R(CCID, 2, 3 2) = 35,6,1,2,3,2
      DCCP A has changed CCID/B's value to 2; its preferred values were
      3 and 2, in that preference order.
   Confirm R(Sequence Window, 1024) = 35,9,3,0,0,0,0,4,0
      DCCP A has changed Sequence Window/B's value to the 6-byte string
      0,0,0,0,4,0 (the value 1024).
   Empty Confirm R(126) = 35,3,126
      DCCP A doesn't implement feature number 126, or DCCP B's proposed
      value for feature 126/B was invalid.
6.6.  Option Exchange
   A few basic rules govern feature negotiation option exchange.
   1. Every non-reordered Change option gets a Confirm option in
      response.
   2. Change options are retransmitted until a response for the latest
      Change is received.
   3. Feature negotiation options are processed in strictly-increasing
      order by Sequence Number.
   The rest of this section describes the consequences of these rules in
   more detail.
6.6.1.  Normal Exchange
   Change options are generated when a DCCP endpoint wants to change the
   value of some feature.  Generally, this will happen at the beginning
   of a connection, although it may happen at any time.  We say the
   endpoint "generates" or "sends" a Change L or Change R option, but of
   course the option must be attached to a packet.  The endpoint may
   attach the option to a packet it would have generated anyway (such as
   a DCCP-Request), or it may create a "feature negotiation packet",
   often a DCCP-Ack or DCCP-Sync, just to carry the option.  Feature
   negotiation packets are controlled by the relevant congestion control
   mechanism.  For example, DCCP A may send a DCCP-Ack or DCCP-Sync for
   feature negotiation only if the B-to-A CCID would allow sending a
   DCCP-Ack.  In addition, an endpoint SHOULD generate at most one
   feature negotiation packet per round-trip time.
   On receiving a Change L or Change R option, a DCCP endpoint examines
   the included preference list, reconciles that with its own preference
   list, calculates the new value, and sends back a Confirm R or Confirm
   L option, respectively, informing its peer of the new value or that
   the feature was not understood.  Every non-reordered Change option
   MUST result in a corresponding Confirm option, and any packet
   including a Confirm option MUST carry an Acknowledgement Number.
   (Section 6.6.4 describes how Change reordering is detected and
   handled.)  Generated Confirm options may be attached to packets that
   would have been sent anyway (such as DCCP-Response or DCCP-SyncAck)
   or to new feature negotiation packets, as described above.
   The Change-sending endpoint MUST wait to receive a corresponding
   Confirm option before changing its stored feature value.  The
   Confirm-sending endpoint changes its stored feature value as soon as
   it sends the Confirm.
   A packet MAY contain more than one feature negotiation option,
   possibly including two options that refer to the same feature; as
   usual, the options are processed sequentially.
6.6.2.  Processing Received Options
   DCCP endpoints exist in one of three states relative to each feature.
   STABLE is the normal state, where the endpoint knows the feature's
   value and thinks the other endpoint agrees.  An endpoint enters the
   CHANGING state when it first sends a Change for the feature and
   returns to STABLE once it receives a corresponding Confirm.  The
   final state, UNSTABLE, indicates that an endpoint in CHANGING state
   changed its preference list but has not yet transmitted a Change
   option with the new preference list.
   Feature state transitions at a feature location are implemented
   according to this diagram.  The diagram ignores sequence number and
   option validity issues; these are handled explicitly in the
   pseudocode that follows.
                                                          timeout/
 rcv Confirm R      app/protocol evt : snd Change L       rcv non-ack
 : ignore      +---------------------------------------+  : snd Change L
      +----+   |                                       |  +----+
      |    v   |                   rcv Change R        v  |    v
   +------------+  rcv Confirm R   : calc new value, +------------+
   |            |  : accept value    snd Confirm L   |            |
   |   STABLE   |<-----------------------------------|  CHANGING  |
   |            |        rcv empty Confirm R         |            |
   +------------+        : revert to old value       +------------+
       |    ^                                            |    ^
       +----+                                  pref list |    | snd
 rcv Change R                                  changes   |    | Change L
 : calc new value, snd Confirm L                         v    |
                                                     +------------+
                                                 +---|            |
                            rcv Confirm/Change R |   |  UNSTABLE  |
                            : ignore             +-->|            |
                                                     +------------+
   Feature locations SHOULD use the following pseudocode, which
   corresponds to the state diagram, to react to each feature
   negotiation option on each valid non-Data packet received.  The
   pseudocode refers to "P.seqno" and "P.ackno", which are properties of
   the packet; "O.type" and "O.len", which are properties of the option;
   "FGSR" and "FGSS", which are properties of the connection and handle
   reordering as described in Section 6.6.4; "F.state", which is the
   feature's state (STABLE, CHANGING, or UNSTABLE); and "F.value", which
   is the feature's value.
   First, check for unknown features (Section 6.6.7);
      If F is unknown,
         If the option was Mandatory,   /* Section 6.6.9 */
            Reset connection and return
         Otherwise, if O.type == Change R,
            Send Empty Confirm L on a future packet
         Return
   Second, check for reordering (Section 6.6.4);
      If F.state == UNSTABLE or P.seqno <= FGSR
              or (O.type == Confirm R and P.ackno < FGSS),
         Ignore option and return
   Third, process Change R options;
      If O.type == Change R,
         If the option's value is valid,   /* Section 6.6.8 */
            Calculate new value
            Send Confirm L on a future packet
            Set F.state := STABLE
         Otherwise, if the option was Mandatory,
            Reset connection and return
         Otherwise,
            Send Empty Confirm L on a future packet
            /* Remain in existing state.  If that's CHANGING, this
               endpoint will retransmit its Change L option later. */
   Fourth, process Confirm R options (but only in CHANGING state).
      If F.state == CHANGING and O.type == Confirm R,
         If O.len > 3,   /* nonempty */
            If the option's value is valid,
               Set F.value := new value
            Otherwise,
               Reset connection and return
         Set F.state := STABLE
   Versions of this diagram and pseudocode are also used by feature
   remotes; simply switch the "L"s and "R"s, so that the relevant
   options are Change R and Confirm L.
6.6.3.  Loss and Retransmission
   Packets containing Change and Confirm options might be lost or
   delayed by the network.  Therefore, Change options are repeatedly
   transmitted to achieve reliability.  We refer to this as
   "retransmission", although of course there are no packet-level
   retransmissions in DCCP: a Change option that is sent again will be
   sent on a new packet with a new sequence number.
   A CHANGING endpoint transmits another Change option once it realizes
   that it has not heard back from the other endpoint.  The new Change
   option need not contain the same payload as the original; reordering
   protection will ensure that agreement is reached based on the most
   recently transmitted option.
   A CHANGING endpoint MUST continue retransmitting Change options until
   it gets some response or the connection terminates.
   Endpoints SHOULD use an exponential-backoff timer to decide when to
   retransmit Change options.  (Packets generated specifically for
   feature negotiation MUST use such a timer.)  The timer interval is
   initially set to not less than one round-trip time, and should back
   off to not less than 64 seconds.  The backoff protects against
   delayed agreement due to the reordering protection algorithms
   described in the next section.  Again, endpoints may piggyback Change
   options on packets they would have sent anyway or create new packets
   to carry the options.  Any new packets are controlled by the relevant
   congestion-control mechanism.
   Confirm options are never retransmitted, but the Confirm-sending
   endpoint MUST generate a Confirm option after every non-reordered
   Change.
6.6.4.  Reordering
   Reordering might cause packets containing Change and Confirm options
   to arrive in an unexpected order.  Endpoints MUST ignore feature
   negotiation options that do not arrive in strictly-increasing order
   by Sequence Number.  The rest of this section presents two algorithms
   that fulfill this requirement.
   The first algorithm introduces two sequence number variables that
   each endpoint maintains for the connection.
   FGSR      Feature Greatest Sequence Number Received: The greatest
             sequence number received, considering only valid packets
             that contained one or more feature negotiation options
             (Change and/or Confirm).  This value is initialized to
             ISR - 1.
   FGSS      Feature Greatest Sequence Number Sent: The greatest
             sequence number sent, considering only packets that
             contained one or more new Change options.  A Change option
             is new if and only if it was generated during a transition
             from the STABLE or UNSTABLE state to the CHANGING state;
             Change options generated within the CHANGING state are
             retransmissions and MUST have exactly the same contents as
             previously transmitted options, allowing tolerance for
             reordering.  FGSS is initialized to ISS.
   Each endpoint checks two conditions on sequence numbers to decide
   whether to process received feature negotiation options.
   1. If a packet's Sequence Number is less than or equal to FGSR, then
      its Change options MUST be ignored.
   2. If a packet's Sequence Number is less than or equal to FGSR, if it
      has no Acknowledgement Number, OR if its Acknowledgement Number is
      less than FGSS, then its Confirm options MUST be ignored.
   Alternatively, an endpoint MAY maintain separate FGSR and FGSS values
   for every feature.  FGSR(F/X) would equal the greatest sequence
   number received, considering only packets that contained Change or
   Confirm options applying to feature F/X; FGSS(F/X) would be defined
   similarly.  This algorithm requires more state, but is slightly more
   forgiving to multiple overlapped feature negotiations.  Either
   algorithm MAY be used; the first algorithm, with connection-wide FGSR
   and FGSS variables, is RECOMMENDED.
   One consequence of these rules is that a CHANGING endpoint will
   ignore any Confirm option that does not acknowledge the latest Change
   option sent.  This ensures that agreement, once achieved, used the
   most recent available information about the endpoints' preferences.
6.6.5.  Preference Changes
   Endpoints are allowed to change their preference lists at any time.
   However, an endpoint that changes its preference list while in the
   CHANGING state MUST transition to the UNSTABLE state.  It will
   transition back to CHANGING once it has transmitted a Change option
   with the new preference list.  This ensures that agreement is based
   on active preference lists.  Without the UNSTABLE state, simultaneous
   negotiation -- where the endpoints began independent negotiations for
   the same feature at the same time -- might lead to the negotiation's
   terminating with the endpoints thinking the feature had different
   values.
6.6.6.  Simultaneous Negotiation
   The two endpoints might simultaneously open negotiation for the same
   feature, after which an endpoint in the CHANGING state will receive a
   Change option for the same feature.  Such received Change options can
   act as responses to the original Change options.  The CHANGING
   endpoint MUST examine the received Change's preference list,
   reconcile that with its own preference list (as expressed in its
   generated Change options), and generate the corresponding Confirm
   option.  It can then transition to the STABLE state.
6.6.7.  Unknown Features
   Endpoints may receive Change options referring to feature numbers
   they do not understand -- for instance, when an extended DCCP
   converses with a non-extended DCCP.  Endpoints MUST respond to
   unknown Change options with Empty Confirm options (that is, Confirm
   options containing no data), which inform the CHANGING endpoint that
   the feature was not understood.  However, if the Change option was
   Mandatory, the connection MUST be reset; see Section 6.6.9.
   On receiving an empty Confirm option for some feature, the CHANGING
   endpoint MUST transition back to the STABLE state, leaving the
   feature's value unchanged.  Section 15 suggests that the default
   value for any extension feature correspond to "extension not
   available".
   Some features are required to be understood by all DCCPs (see Section
   6.4).  The CHANGING endpoint SHOULD reset the connection (with Reset
   Code 5, "Option Error") if it receives an empty Confirm option for
   such a feature.
   Since Confirm options are generated only in response to Change
   options, an endpoint should never receive a Confirm option referring
   to a feature number it does not understand.  Nevertheless, endpoints
   MUST ignore any such options they receive.
6.6.8.  Invalid Options
   A DCCP endpoint might receive a Change or Confirm option for a known
   feature that lists one or more values that it does not understand.
   Some, but not all, such options are invalid, depending on the
   relevant reconciliation rule (Section 6.3).  For instance:
   o  All features have length limitations, and options with invalid
      lengths are invalid.  For example, the Ack Ratio feature takes
      16-bit values, so valid "Confirm R(Ack Ratio)" options have option
      length 5.
   o  Some non-negotiable features have value limitations.  The Ack
      Ratio feature takes two-byte, non-zero integer values, so a
      "Change L(Ack Ratio, 0)" option is never valid.  Note that
      server-priority features do not have value limitations, since
      unknown values are handled as a matter of course.
   o  Any Confirm option that selects the wrong value, based on the two
      preference lists and the relevant reconciliation rule, is invalid.
   However, unexpected Confirm options -- that refer to unknown feature
   numbers, or that don't appear to be part of a current negotiation --
   are not invalid, although they are ignored by the receiver.
   An endpoint receiving an invalid Change option MUST respond with the
   corresponding empty Confirm option.  An endpoint receiving an invalid
   Confirm option MUST reset the connection, with Reset Code 5, "Option
   Error".
6.6.9.  Mandatory Feature Negotiation
   Change options may be preceded by Mandatory options (Section 5.8.2).
   Mandatory Change options are processed like normal Change options
   except that the following failure cases will cause the receiver to
   reset the connection with Reset Code 6, "Mandatory Failure", rather
   than send a Confirm option.  The connection MUST be reset if:
   o  the Change option's feature number was not understood;
   o  the Change option's value was invalid, and the receiver would
      normally have sent an empty Confirm option in response; or
   o  for server-priority features, there was no shared entry in the two
      endpoints' preference lists.
   Other failure cases do not cause connection reset; in particular,
   reordering protection may cause a Mandatory Change option to be
   ignored without resetting the connection.
   Confirm options behave identically and have the same reset conditions
   whether or not they are Mandatory.