core-wg / coap-sig

Signaling messages draft (now merged with coap-tcp-tls -- please use that repo)
0 stars 0 forks source link

Ping/Pong #3

Open brianraymor opened 8 years ago

brianraymor commented 8 years ago

Captured from Ticket 394:

Do we need ping/pong messages to keep an idle connection alive through NATs?

brianraymor commented 8 years ago

https://trac.tools.ietf.org/wg/core/trac/ticket/394#comment:1 Here is the story for adding keep-alive functionality to the CoAP over TCP document.

After reaching out to folks measuring TCP usage I was told that the use of TCP keepalive messages is often unreliable since network operators deploy middleboxes, which suppress these messages.

For this reason we are suggesting to add a ping/pong message to the CoAP over TCP document. Here is how this could look like.

First, we define a new CoAP Method Codes (for the request) and CoAP Response Codes (for the responses). Let us give them new numbers, such as 7.01 (for PING) and 7.02 (for PONG).

Here is an example message exchange:

                        Client              Server
                           |                  |
                           | <--- TCP --->    |
                           | Connection Setup |
                           |                  |
                           |   NON            |
                           | GET /temperature |
                           |   (Token 0x74)   |
                           +----------------->|
                           |                  |
                           |   NON [0x23bc]   |
                           |   2.05 Content   |
                           |   (Token 0x74)   |
                           |     "22.5 C"     |
                           |<-----------------+
                           |                  |
                           |      ......      |
                           |   time passes    |
                           |      ......      |
                           |                  |
                           |7.03 Ping         |
                           |(Token 0x7f)      |
                           +----------------->|
                           |                  |
                           |7.02 Pong         |
                           |(Token 0x7f)      |
                           |<-----------------+
                           |                  |
                           |  <--- TCP --->   |
                           |  Conn. Teadown   |

The PING packet would look as follows:

    0                   1                   2
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |      0x01     |      0xe1     |      0x7f     |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    Len   =    0 ------>  0x01
    TKL   =    1 ___/
    Code  =  7.01     --> 0xe1
    Token =               0x7f

           Figure: PING Encoding Example.

The PONG packet has the following structure:

    0                   1                   2
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |      0x01     |      0xe2     |      0x7f     |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    Len   =    0 ------>  0x01
    TKL   =    1 ___/
    Code  =  7.02     --> 0xe2
    Token =               0x7f

           Figure: PONG Encoding Example.
brianraymor commented 8 years ago

https://trac.tools.ietf.org/wg/core/trac/ticket/394#comment:2

Keep alive is better done through empty messages.

Ping/pong is mainly requested by people who want to know whether their previous messages have been processed by the application layer on the other side. It does not really have that semantics, but at least can find out whether the TCP data went through. Because of difficulties with flow control implementations (see question number 3 in #393), this may be a fundamentally not quite right but still rather expedient solution.

(Ping/pong could be invested with application layer custody semantics, either through an additional option or always.)

brianraymor commented 8 years ago

https://trac.tools.ietf.org/wg/core/trac/ticket/394#comment:3

+1 for empty messages for keep-alives.

+1 to also support a lightweight checkpointing, since we need a way to indicate when resources can be freed safely.

brianraymor commented 8 years ago

Other references: