Skip to content

Commit

Permalink
Congestion Control: add in RFC7252 configuration flexibility
Browse files Browse the repository at this point in the history
Create where appropriate default values for the Congestion control base
values and update the derived CC values accordingly.

Move derived value #define to coap_session_internal.h.

Update coap_session_t to hold the new CC values.

Update documentation for the new CC functions that update / get the
appropriate values.

NOTE: PROBING_WAIT is not currently checked in the code.
  • Loading branch information
mrdeep1 authored and obgm committed Jun 17, 2022
1 parent 41afb92 commit 5a10ce4
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 152 deletions.
2 changes: 1 addition & 1 deletion examples/coap-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ main(int argc, char **argv) {

if (is_mcast && wait_seconds == DEFAULT_WAIT_TIME)
/* Allow for other servers to respond within DEFAULT_LEISURE RFC7252 8.2 */
wait_seconds = COAP_DEFAULT_LEISURE;
wait_seconds = coap_session_get_default_leisure(session).integer_part;

wait_ms = wait_seconds * 1000;
coap_log(LOG_DEBUG, "timeout is set to %u seconds\n", wait_seconds);
Expand Down
196 changes: 105 additions & 91 deletions include/coap3/coap_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,130 +424,77 @@ coap_session_t *coap_session_get_by_peer(const coap_context_t *ctx,
#define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})

/**
* Number of message retransmissions before message sending is stopped
* Number of message retransmissions before message sending is stopped.
* RFC 7252, Section 4.8 Default value of MAX_RETRANSMIT is 4
*
* Configurable using coap_session_set_max_retransmit()
*/
#define COAP_DEFAULT_MAX_RETRANSMIT 4
#define COAP_DEFAULT_MAX_RETRANSMIT (4U)

/**
* The number of simultaneous outstanding interactions that a client
* maintains to a given server.
* RFC 7252, Section 4.8 Default value of NSTART is 1
*
* Configurable using coap_session_set_nstart()
*/
#define COAP_DEFAULT_NSTART 1

/**
* The maximum number of seconds before sending back a response to a
* multicast request.
* RFC 7252, Section 4.8 DEFAULT_LEISURE is 5.
*/
#ifndef COAP_DEFAULT_LEISURE
#define COAP_DEFAULT_LEISURE (5U)
#endif /* COAP_DEFAULT_LEISURE */
#define COAP_DEFAULT_NSTART (1U)

/**
* The MAX_TRANSMIT_SPAN definition for the session (s).
* The number of seconds to use as bounds for multicast traffic
* RFC 7252, Section 4.8 Default value of DEFAULT_LEISURE is 5.0
*
* RFC 7252, Section 4.8.2 Calculation of MAX_TRAMSMIT_SPAN
* ACK_TIMEOUT * ((2 ** (MAX_RETRANSMIT)) - 1) * ACK_RANDOM_FACTOR
* Configurable using coap_session_set_default_leisure()
*/
#define COAP_MAX_TRANSMIT_SPAN(s) \
((s->ack_timeout.integer_part * 1000 + s->ack_timeout.fractional_part) * \
((1 << (s->max_retransmit)) -1) * \
(s->ack_random_factor.integer_part * 1000 + \
s->ack_random_factor.fractional_part) \
/ 1000000)
#define COAP_DEFAULT_DEFAULT_LEISURE ((coap_fixed_point_t){5,0})

/**
* The MAX_TRANSMIT_WAIT definition for the session (s).
* The number of bytes/second allowed when there is no response
* RFC 7252, Section 4.8 Default value of PROBING_RATE is 1
*
* RFC 7252, Section 4.8.2 Calculation of MAX_TRAMSMIT_WAIT
* ACK_TIMEOUT * ((2 ** (MAX_RETRANSMIT + 1)) - 1) * ACK_RANDOM_FACTOR
* Configurable using coap_session_set_probing_rate()
*/
#define COAP_MAX_TRANSMIT_WAIT(s) \
((s->ack_timeout.integer_part * 1000 + s->ack_timeout.fractional_part) * \
((1 << (s->max_retransmit + 1)) -1) * \
(s->ack_random_factor.integer_part * 1000 + \
s->ack_random_factor.fractional_part) \
/ 1000000)
#define COAP_DEFAULT_PROBING_RATE (1U)

/**
* The MAX_LATENCY definition.
* RFC 7252, Section 4.8.2 MAX_LATENCY is 100.
*/
#define COAP_MAX_LATENCY 100

/**
* The PROCESSING_DELAY definition for the session (s).
*
* RFC 7252, Section 4.8.2 Calculation of PROCESSING_DELAY
* PROCESSING_DELAY set to ACK_TIMEOUT
*/
#define COAP_PROCESSING_DELAY(s) \
((s->ack_timeout.integer_part * 1000 + s->ack_timeout.fractional_part + 500) \
/ 1000)

/**
* The MAX_RTT definition for the session (s).
*
* RFC 7252, Section 4.8.2 Calculation of MAX_RTT
* (2 * MAX_LATENCY) + PROCESSING_DELAY
*/
#define COAP_MAX_RTT(s) \
((2 * COAP_MAX_LATENCY) + COAP_PROCESSING_DELAY(s))

/**
* The EXCHANGE_LIFETIME definition for the session (s).
*
* RFC 7252, Section 4.8.2 Calculation of EXCHANGE_LIFETIME
* MAX_TRANSMIT_SPAN + (2 * MAX_LATENCY) + PROCESSING_DELAY
*/
#define COAP_EXCHANGE_LIFETIME(s) \
(COAP_MAX_TRANSMIT_SPAN(s) + (2 * COAP_MAX_LATENCY) + COAP_PROCESSING_DELAY(s))

/**
* The NON_LIFETIME definition for the session (s).
*
* RFC 7252, Section 4.8.2 Calculation of NON_LIFETIME
* MAX_TRANSMIT_SPAN + MAX_LATENCY
*/
#define COAP_NON_LIFETIME(s) \
(COAP_MAX_TRANSMIT_SPAN(s) + COAP_MAX_LATENCY)

/** @} */
#define COAP_DEFAULT_MAX_LATENCY (100U)

/**
* Set the CoAP maximum retransmit count before failure
* Set the CoAP initial ack response timeout before the next re-transmit
*
* Number of message retransmissions before message sending is stopped
* Number of seconds when to expect an ACK or a response to an
* outstanding CON message.
* RFC7252 ACK_TIMEOUT
*
* @param session The CoAP session.
* @param value The value to set to. The default is 4 and should not normally
* @param value The value to set to. The default is 2.0 and should not normally
* get changed.
*/
void coap_session_set_max_retransmit(coap_session_t *session,
unsigned int value);
void coap_session_set_ack_timeout(coap_session_t *session,
coap_fixed_point_t value);

/**
* Set the CoAP initial ack response timeout before the next re-transmit
* Get the CoAP initial ack response timeout before the next re-transmit
*
* Number of seconds when to expect an ACK or a response to an
* outstanding CON message.
* RFC7252 ACK_TIMEOUT
*
* @param session The CoAP session.
* @param value The value to set to. The default is 2 and should not normally
* get changed.
*
* @return Current ack response timeout value
*/
void coap_session_set_ack_timeout(coap_session_t *session,
coap_fixed_point_t value);
coap_fixed_point_t coap_session_get_ack_timeout(const coap_session_t *session);

/**
* Set the CoAP ack randomize factor
*
* A factor that is used to randomize the wait time before a message
* is retransmitted to prevent synchronization effects.
* RFC7252 ACK_RANDOM_FACTOR
*
* @param session The CoAP session.
* @param value The value to set to. The default is 1.5 and should not normally
Expand All @@ -556,42 +503,109 @@ void coap_session_set_ack_timeout(coap_session_t *session,
void coap_session_set_ack_random_factor(coap_session_t *session,
coap_fixed_point_t value);

/**
* Get the CoAP ack randomize factor
*
* A factor that is used to randomize the wait time before a message
* is retransmitted to prevent synchronization effects.
* RFC7252 ACK_RANDOM_FACTOR
*
* @param session The CoAP session.
*
* @return Current ack randomize value
*/
coap_fixed_point_t coap_session_get_ack_random_factor(
const coap_session_t *session);

/**
* Set the CoAP maximum retransmit count before failure
*
* Number of message retransmissions before message sending is stopped
* RFC7252 MAX_RETRANSMIT
*
* @param session The CoAP session.
* @param value The value to set to. The default is 4 and should not normally
* get changed.
*/
void coap_session_set_max_retransmit(coap_session_t *session,
uint16_t value);

/**
* Get the CoAP maximum retransmit before failure
*
* Number of message retransmissions before message sending is stopped
* RFC7252 MAX_RETRANSMIT
*
* @param session The CoAP session.
*
* @return Current maximum retransmit value
*/
unsigned int coap_session_get_max_retransmit(const coap_session_t *session);
uint16_t coap_session_get_max_retransmit(const coap_session_t *session);

/**
* Get the CoAP initial ack response timeout before the next re-transmit
* Set the CoAP maximum concurrent transmission count of Confirmable messages
* RFC7252 NSTART
*
* Number of seconds when to expect an ACK or a response to an
* outstanding CON message.
* @param session The CoAP session.
* @param value The value to set to. The default is 1 and should not normally
* get changed.
*/
void coap_session_set_nstart(coap_session_t *session,
uint16_t value);

/**
* Get the CoAP maximum concurrent transmission count of Confirmable messages
* RFC7252 NSTART
*
* @param session The CoAP session.
*
* @return Current ack response timeout value
* @return Current nstart value
*/
coap_fixed_point_t coap_session_get_ack_timeout(const coap_session_t *session);
uint16_t coap_session_get_nstart(const coap_session_t *session);

/**
* Get the CoAP ack randomize factor
* Set the CoAP default leisure time (for multicast)
* RFC7252 DEFAULT_LEISURE
*
* A factor that is used to randomize the wait time before a message
* is retransmitted to prevent synchronization effects.
* @param session The CoAP session.
* @param value The value to set to. The default is 5.0 and should not normally
* get changed.
*/
void coap_session_set_default_leisure(coap_session_t *session,
coap_fixed_point_t value);

/**
* Get the CoAP default leisure time
* RFC7252 DEFAULT_LEISURE
*
* @param session The CoAP session.
*
* @return Current ack randomize value
* @return Current default_leisure value
*/
coap_fixed_point_t coap_session_get_ack_random_factor(
coap_fixed_point_t coap_session_get_default_leisure(
const coap_session_t *session);

/**
* Set the CoAP probing rate when there is no response
* RFC7252 PROBING_RATE
*
* @param session The CoAP session.
* @param value The value to set to. The default is 1 and should not normally
* get changed.
*/
void coap_session_set_probing_rate(coap_session_t *session, uint32_t value);

/**
* Get the CoAP probing rate when there is no response
* RFC7252 PROBING_RATE
*
* @param session The CoAP session.
*
* @return Current probing_rate value
*/
uint32_t coap_session_get_probing_rate(const coap_session_t *session);

/** @} */
/**
* Send a ping message for the session.
* @param session The CoAP session.
Expand Down
Loading

0 comments on commit 5a10ce4

Please sign in to comment.