All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eddie Kohler <kohler@cs.ucla.edu>
To: dccp@vger.kernel.org
Subject: Re: 48-bit sequence number arithmetic
Date: Thu, 14 Dec 2006 16:52:18 +0000	[thread overview]
Message-ID: <45818142.4090001@cs.ucla.edu> (raw)

Gerrit,

Subtracting two 32-bit numbers which are 2^31 apart will have the same results.

(int32_t) ((uint32_t) 0 - (uint32_t) 0x80000000) = -0x80000000
(int32_t) ((uint32_t) 0x80000000 - (uint32_t) 0) = -0x80000000

The RFC is not in error and your delta_seqno patch should not be accepted.

As RFC 1982 says:

    Note that there are some pairs of values s1 and s2 for which s1 is
    not equal to s2, but for which s1 is neither greater than, nor less
    than, s2.  An attempt to use these ordering operators on such pairs
    of values produces an undefined result.

    The reason for this is that those pairs of values are such that any
    simple definition that were to define s1 to be less than s2 where
    (s1, s2) is such a pair, would also usually cause s2 to be less than
    s1, when the pair is (s2, s1).  This would mean that the particular
    order selected for a test could cause the result to differ, leading
    to unpredictable implementations.

...

    Thus the problem case is left undefined, implementations are free to
    return either result, or to flag an error, and users must take care
    not to depend on any particular outcome.  Usually this will mean
    avoiding allowing those particular pairs of numbers to co-exist.

Eddie



Gerrit Renker wrote:
> I would like to notify you of an error in RFC 4340.
> 
> In [RFC 4340, sec. 3.1] it is suggested that
>  "It may make sense to store DCCP sequence numbers in the most significant 48 bits
>   of 64-bit integers and set the least significant 16 bits to zero, since this 
>   supports a common technique that implements circular comparison A < B by testing
>   whether (A - B) < 0 using conventional two's-complement arithmetic."
> 
> Unfortunately this does not work.
> 
> Signed 64-bit numbers represent the range -2^63 ... 0 ... 2^63-1. 
> When the difference between two left-shifted 48-bit numbers a and b is +/- 2^63, we can not tell
> whether a is `before' b or b is `before' a: the difference will yield the same negative result -2^63,
> due to the constraints of the data type.
> 
> This case occurs for all 48-bit numbers whose difference amounts to 2^47. Since there are 2^47
> such numbers, this test fails to produce correct results in 2^47 = 140.7375e12 cases.
> 
> The sequence number test based on subtraction works for TCP since signed 32 bit numbers are a native type. 
> For 48 bit, arithmetic operations need to be redeveloped from scratch. It is not sufficient to shift and subtract.
> 
> Regards
> Gerrit Renker

             reply	other threads:[~2006-12-14 16:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-14 16:52 Eddie Kohler [this message]
2006-12-14 16:56 ` 48-bit sequence number arithmetic Eddie Kohler
2006-12-15  8:59 ` Gerrit Renker
2006-12-17 22:19 ` Eddie Kohler
2006-12-19 10:33 ` Gerrit Renker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45818142.4090001@cs.ucla.edu \
    --to=kohler@cs.ucla.edu \
    --cc=dccp@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.