Coverage for aiocoap/numbers/constants.py: 95%
59 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-28 12:34 +0000
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-28 12:34 +0000
1# SPDX-FileCopyrightText: Christian Amsüss and the aiocoap contributors
2#
3# SPDX-License-Identifier: MIT
5"""Constants either defined in the CoAP protocol (often default values for lack
6of ways to determine eg. the estimated round trip time). Some parameters are
7invented here for practical purposes of the implementation (eg.
8DEFAULT_BLOCK_SIZE_EXP, EMPTY_ACK_DELAY)."""
10import warnings
11import string
13COAP_PORT = 5683
14"""The IANA-assigned standard port for COAP services."""
16COAPS_PORT = 5684
18MCAST_IPV4_ALLCOAPNODES = "224.0.1.187"
19MCAST_IPV6_LINKLOCAL_ALLNODES = "ff02::1"
20MCAST_IPV6_LINKLOCAL_ALLCOAPNODES = "ff02::fd"
21MCAST_IPV6_SITELOCAL_ALLNODES = "ff05::1"
22MCAST_IPV6_SITELOCAL_ALLCOAPNODES = "ff05::fd"
23MCAST_ALL = (
24 MCAST_IPV4_ALLCOAPNODES,
25 MCAST_IPV6_LINKLOCAL_ALLNODES,
26 MCAST_IPV6_LINKLOCAL_ALLCOAPNODES,
27 MCAST_IPV6_SITELOCAL_ALLNODES,
28 MCAST_IPV6_SITELOCAL_ALLCOAPNODES,
29)
31MAX_REGULAR_BLOCK_SIZE_EXP = 6
34class TransportTuning:
35 """Base parameters that guide CoAP transport behaviors
37 The values in here are recommended values, often defaults from RFCs. They
38 can be tuned in subclasses (and then passed into a message as
39 ``transport_tuning``), although users should be aware that alteing some of
40 these can cause the library to behave in ways violating the specification,
41 especially with respect to congestion control.
42 """
44 # +-------------------+---------------+
45 # | name | default value |
46 # +-------------------+---------------+
47 # | ACK_TIMEOUT | 2 seconds |
48 # | ACK_RANDOM_FACTOR | 1.5 |
49 # | MAX_RETRANSMIT | 4 |
50 # | NSTART | 1 |
51 # | DEFAULT_LEISURE | 5 seconds |
52 # | PROBING_RATE | 1 Byte/second |
53 # +-------------------+---------------+
55 ACK_TIMEOUT = 2.0
56 """The time, in seconds, to wait for an acknowledgement of a
57 confirmable message. The inter-transmission time doubles
58 for each retransmission."""
60 ACK_RANDOM_FACTOR = 1.5
61 """Timeout multiplier for anti-synchronization."""
63 MAX_RETRANSMIT = 4
64 """The number of retransmissions of confirmable messages to
65 non-multicast endpoints before the infrastructure assumes no
66 acknowledgement will be received."""
68 NSTART = 1
69 """Maximum number of simultaneous outstanding interactions
70 that endpoint maintains to a given server (including proxies)"""
72 # +-------------------+---------------+
73 # | name | default value |
74 # +-------------------+---------------+
75 # | MAX_TRANSMIT_SPAN | 45 s |
76 # | MAX_TRANSMIT_WAIT | 93 s |
77 # | MAX_LATENCY | 100 s |
78 # | PROCESSING_DELAY | 2 s |
79 # | MAX_RTT | 202 s |
80 # | EXCHANGE_LIFETIME | 247 s |
81 # | NON_LIFETIME | 145 s |
82 # +-------------------+---------------+
84 @property
85 def MAX_TRANSMIT_SPAN(self):
86 """Maximum time from the first transmission
87 of a confirmable message to its last retransmission."""
88 return self.ACK_TIMEOUT * (2**self.MAX_RETRANSMIT - 1) * self.ACK_RANDOM_FACTOR
90 @property
91 def MAX_TRANSMIT_WAIT(self):
92 """Maximum time from the first transmission
93 of a confirmable message to the time when the sender gives up on
94 receiving an acknowledgement or reset."""
95 return (
96 self.ACK_TIMEOUT
97 * (2 ** (self.MAX_RETRANSMIT + 1) - 1)
98 * self.ACK_RANDOM_FACTOR
99 )
101 MAX_LATENCY = 100.0
102 """Maximum time a datagram is expected to take from the start
103 of its transmission to the completion of its reception."""
105 @property
106 def PROCESSING_DELAY(self):
107 """ "Time a node takes to turn around a
108 confirmable message into an acknowledgement."""
109 return self.ACK_TIMEOUT
111 @property
112 def MAX_RTT(self):
113 """Maximum round-trip time."""
114 return 2 * self.MAX_LATENCY + self.PROCESSING_DELAY
116 @property
117 def EXCHANGE_LIFETIME(self):
118 """time from starting to send a confirmable message to the time when an
119 acknowledgement is no longer expected, i.e. message layer information about the
120 message exchange can be purged"""
121 return self.MAX_TRANSMIT_SPAN + self.MAX_RTT
123 DEFAULT_BLOCK_SIZE_EXP = MAX_REGULAR_BLOCK_SIZE_EXP
124 """Default size exponent for blockwise transfers."""
126 EMPTY_ACK_DELAY = 0.1
127 """After this time protocol sends empty ACK, and separate response"""
129 REQUEST_TIMEOUT = MAX_TRANSMIT_WAIT
130 """Time after which server assumes it won't receive any answer.
131 It is not defined by IETF documents.
132 For human-operated devices it might be preferable to set some small value
133 (for example 10 seconds)
134 For M2M it's application dependent."""
136 DEFAULT_LEISURE = 5
138 @property
139 def MULTICAST_REQUEST_TIMEOUT(self):
140 return self.REQUEST_TIMEOUT + self.DEFAULT_LEISURE
142 OBSERVATION_RESET_TIME = 128
143 """Time in seconds after which the value of the observe field are ignored.
145 This number is not explicitly named in RFC7641.
146 """
149_default_transport_tuning = TransportTuning()
152def __getattr__(name):
153 if name[0] in string.ascii_uppercase and hasattr(_default_transport_tuning, name):
154 warnings.warn(
155 f"{name} is deprecated, use through the message's transport_tuning instead",
156 DeprecationWarning,
157 stacklevel=2,
158 )
159 return getattr(_default_transport_tuning, name)
160 raise AttributeError(f"module {__name__} has no attribute {name}")
163SHUTDOWN_TIMEOUT = 3
164"""Maximum time, in seconds, for which the process is kept around during shutdown"""
166__all__ = [
167 k for k in dir() if not k.startswith("_") and k not in ("warnings", "string")
168]