The NULL test clearly needs to be before any dereferences.
[oweals/gnunet.git] / src / transport / transport_selection.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport/transport_selection.h
23  * @brief structure definition for automatic transport selection (ATS)
24  * @author Matthias Wachs
25  */
26
27 /**
28  *  The structs defined here are used by the transport plugin to tell ATS about the transport's properties like cost and quality
29  *  and on the other side the structs are used by highlevel components to communicate the constraints they have for a transport to ATS
30  *
31  *                             +---+
32  *  +-----------+ Constraints  |   |  Plugin properties +---------+
33  *  | Highlevel |------------> |ATS| <------------------|Transport|
34  *  | Component | ATS struct   |   |    ATS struct      | Plugin  |
35  *  +-----------+              |   |                    +---------+
36  *                             +---+
37  *
38  */
39
40 #define GNUNET_ATS_ARRAY_TERMINATOR 0
41
42 /**
43  * Enum defining all known property types for ATS
44  * Enum values are used in the GNUNET_ATS_Information struct as (key,value)-pair
45  * Cost are always stored in uint32_t, so all units used to define costs have to be normalized to fit in uint32_t [0 .. 4.294.967.295]
46  * To keep the elements ordered
47  *    1..1024 : Values with a relation to cost
48  * 1025..2048 : Values with a relation to quality
49  *
50  */
51 enum GNUNET_ATS_Property
52 {
53
54         /* Cost related values */
55         /* =================== */
56
57         /**
58          * Volume based cost in financial units to transmit data
59          *
60          * Note: This value is not bound to a specific currency or unit and only used locally
61          * "cent" just refers the smallest amount of money in the respective currency
62          *
63          * Unit: [cent/MB]
64          *
65          * Interpretation: less is better
66          *
67          * Examples:
68          * LAN:  0 [cent/MB]
69          * 2G : 10 [cent/MB]
70          */
71         GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
72
73         /**
74          * Time based cost in financial units to transmit data
75          *
76          * Note: This value is not bound to a specific currency or unit and only used locally
77          * "cent" just refers the smallest amount of money in the respective currency
78          *
79          * Unit: [cent/h]
80          *
81          * Interpretation: less is better
82          *
83          * Examples:
84          * LAN   :  0 [cent/h]
85          * Dialup: 10 [cent/h]
86          */
87         GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
88
89         /**
90          * Computational costs
91          *
92          * Effort of preparing data to be sent with this transport
93          * Includes encoding, encryption and conversion of data
94          * Partial values can be summed up: c_sum = c_enc + c_enc + c_conv
95          * Resulting values depend on local system properties, e.g. CPU
96          *
97          * Unit: [ms/GB]
98          *
99          * Interpretation: less is better
100          *
101          * Examples:
102          *
103          * HTTPS with AES CBC-256:      7,382
104          * HTTPS with AES CBC-128:      5,279
105          * HTTPS with RC4-1024:         2,652
106          */
107         GNUNET_ATS_COST_COMPUTATIONAL = 3,
108
109         /**
110          * Energy consumption
111          *
112          * Energy consumption using this transport when sending with a certain power at a certain bitrate
113          * This is only an approximation based on:
114          * Energy consumption E = P / D
115          *
116          * with:
117          * Power P in Watt (J/s)
118          * Datarate D in MBit/s
119          *
120          * Conversion between power P and dBm used by WLAN in radiotap's dBm TX power:
121          *
122          * Lp(dbm) = 10 log10 (P/ 1mW)
123          *
124          * => P = 1 mW  * 10^(Lp(dbm)/10)
125          *
126          * Unit: [mJ/MB]
127          *
128          * Interpretation: less is better
129          *
130          * Examples:
131          *
132          * LAN:       0
133          * WLAN:      89 (600 mW @ 802.11g /w 54 MBit/s)
134          * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
135          */
136         GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
137
138         /**
139          * Connect cost
140          * How many bytes are transmitted to initiate a new connection using this transport?
141          *
142          * Unit: [bytes]
143          *
144          * Interpretation: less is better
145          *
146          * Examples:
147          *
148          * UDP (No connection)      :    0 bytes
149          * TCP (TCP 3-Way handshake):  220 bytes Ethernet,  172 bytes TCP/IP,  122 bytes TCP
150          * HTTP (TCP + Header)      :  477 bytes Ethernet,  429 bytes TCP/IP,  374 bytes TCP,  278 bytes HTTP
151          * HTTPS  HTTP+TLS Handshake: 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
152          *
153          * */
154         GNUNET_ATS_COST_CONNECT = 5,
155
156         /**
157          * Bandwidth cost
158          *
159          * How many bandwidth is available to consume?
160          * Used to calculate which impact sending data with this transport has
161          *
162          * Unit: [kB/s]
163          *
164          * Interpretation: more is better
165          *
166          * Examples:
167          * LAN:     12,800  (100 MBit/s)
168          * WLAN:    6,912   (54 MBit/s)
169          * Dial-up: 8       (64 Kbit/s)
170          *
171          */
172         GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
173
174         /**
175          *  Network overhead
176          *
177          * How many bytes are sent over the wire when 1 kilobyte (1024 bytes) of application data is transmitted?
178          * A factor used with connect cost, bandwidth cost and energy cost to describe the overhead produced by the transport protocol
179          *
180          * Unit: [bytes/kb]
181          *
182          * Interpretation: less is better
183          *
184          * Examples:
185          *
186          * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
187          * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
188          * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
189          * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
190          */
191         GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
192
193
194         /* Quality related values */
195         /* ====================== */
196
197     /* Physical layer quality properties */
198
199         /**
200          * Signal strength on physical layer
201          *
202          * Unit: [dBm]
203          */
204         GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
205
206         /**
207          * Collision rate on physical layer
208          *
209          * Unit: [B/s]
210          */
211         GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
212
213         /**
214          * Error rate on physical layer
215          *
216          * Unit: [B/s]
217          */
218         GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
219
220     /* Network layer quality properties */
221
222         /**
223          * Delay
224          * Time between when the time packet is sent and the packet arrives
225          *
226          * Unit: [μs]
227          *
228          * Examples:
229          *
230          * LAN   :  180
231          * Dialup: 4000
232          * WLAN  : 7000
233          */
234         GNUNET_ATS_QUALITY_NET_DELAY = 1028,
235
236         /**
237          * Jitter
238          * Time variations of the delay
239          * 1st derivative of a delay function
240          *
241          * Unit: [μs]
242          */
243         GNUNET_ATS_QUALITY_NET_JITTER = 1029,
244
245         /**
246          * Error rate on network layer
247          *
248          * Unit: [B/s]
249          *
250          * Examples:
251          *
252          * LAN       :    0
253          * WLAN      :  400
254          * Bluetooth :  100
255          * Note: This numbers are just assumptions as an example, not measured or somehow determined
256          */
257         GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
258
259         /**
260          * Drop rate on network layer
261      * Bytes actively dismissed by a network component during transmission
262      * Reasons for dropped data can be full queues, congestion, quota violations...
263          *
264          * Unit: [B/s]
265          *
266          * Examples:
267          *
268          * LAN       :    0
269          * WLAN      :  400
270          * Bluetooth :  100
271          * Note: This numbers are just assumptions as an example, not measured or somehow determined
272          */
273         GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
274
275         /**
276          * Loss rate on network layer
277          * Bytes lost during transmission
278          * Reasons can be collisions, ...
279          *
280          * Unit: [B/s]
281          *
282          * Examples:
283          *
284          * LAN       :    0
285          * WLAN      :   40
286          * Bluetooth :   10
287          * Note: This numbers are just assumptions as an example, not measured or somehow determined
288          */
289         GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
290
291         /**
292          * Throughput on network layer
293          *
294          * Unit: [kB/s]
295          *
296          * Examples:
297          *
298          * LAN   : 3400
299          * WLAN  : 1200
300          * Dialup:        4
301          *
302          */
303         GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033
304 };
305
306 /**
307  * This structure will be used by plugins to communicate costs to ATS or by higher level components to tell ATS their constraints
308  * Always a pair of (GNUNET_ATS_Property, uint32_t value)
309  * Value is always uint32_t, so all units used to define costs have to be normalized to fit uint32_t
310  */
311 struct GNUNET_ATS_Information
312 {
313         /**
314          * ATS property type
315          */
316         uint32_t type;
317
318         /**
319          * ATS property value
320          */
321         uint32_t value;
322 };
323
324