2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file include/gnunet_ats_service.h
22 * @brief automatic transport selection and outbound bandwidth determination
23 * @author Christian Grothoff
24 * @author Matthias Wachs
26 #ifndef GNUNET_ATS_SERVICE_H
27 #define GNUNET_ATS_SERVICE_H
29 #include "gnunet_constants.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_hello_lib.h"
34 enum GNUNET_ATS_Network_Type
36 GNUNET_ATS_NET_UNSPECIFIED = 0,
37 GNUNET_ATS_NET_LOOPBACK = 1,
38 GNUNET_ATS_NET_LAN = 2,
39 GNUNET_ATS_NET_WAN = 3,
40 GNUNET_ATS_NET_WLAN = 4,
44 * Enum defining all known property types for ATS Enum values are used
45 * in the GNUNET_ATS_Information struct as
48 * Cost are always stored in uint32_t, so all units used to define costs
49 * have to be normalized to fit in uint32_t [0 .. 4.294.967.295]
51 enum GNUNET_ATS_Property
58 GNUNET_ATS_ARRAY_TERMINATOR = 0,
61 * Actual traffic on this connection from the other peer to this peer.
63 * Unit: [bytes/second]
65 GNUNET_ATS_UTILIZATION_UP,
68 * Actual traffic on this connection from this peer to the other peer.
70 * Unit: [bytes/second]
72 GNUNET_ATS_UTILIZATION_DOWN,
75 * Is this address located in WAN, LAN or a loopback address
76 * Value is element of GNUNET_ATS_Network_Type
78 GNUNET_ATS_NETWORK_TYPE,
82 * Time between when the time packet is sent and the packet arrives
92 GNUNET_ATS_QUALITY_NET_DELAY,
95 * Distance on network layer (required for distance-vector routing).
99 GNUNET_ATS_QUALITY_NET_DISTANCE,
102 * Network overhead on WAN (Wide-Area Network)
104 * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
105 * of application data is transmitted?
106 * A factor used with connect cost, bandwidth cost and energy cost
107 * to describe the overhead produced by the transport protocol
111 * Interpretation: less is better
115 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
116 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
117 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
118 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
123 * Network overhead on LAN (Local-Area Network)
125 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
126 * of application data is transmitted?
127 * A factor used with connect cost, bandwidth cost and energy cost
128 * to describe the overhead produced by the transport protocol
132 * Interpretation: less is better
136 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
137 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
138 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
139 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
144 * Network overhead on WLAN (Wireless Local Area Network)
146 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
147 * of application data is transmitted?
148 * A factor used with connect cost, bandwidth cost and energy cost
149 * to describe the overhead produced by the transport protocol
153 * Interpretation: less is better
157 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
158 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
159 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
160 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
163 /* Cost related values */
164 /* =================== */
166 * Volume based cost in financial units to transmit data
168 * Note: This value is not bound to a specific currency or unit and only
170 * "cent" just refers the smallest amount of money in the respective
175 * Interpretation: less is better
181 // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
183 * Time based cost in financial units to transmit data
185 * Note: This value is not bound to a specific currency or unit and only
187 * "cent" just refers the smallest amount of money in the respective
192 * Interpretation: less is better
196 * Dialup: 10 [cent/h]
198 // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
200 * Computational costs
202 * Effort of preparing data to be sent with this transport
203 * Includes encoding, encryption and conversion of data
204 * Partial values can be summed up: c_sum = c_enc + c_enc + c_conv
205 * Resulting values depend on local system properties, e.g. CPU
209 * Interpretation: less is better
213 * HTTPS with AES CBC-256: 7,382
214 * HTTPS with AES CBC-128: 5,279
215 * HTTPS with RC4-1024: 2,652
217 // GNUNET_ATS_COST_COMPUTATIONAL = 3,
221 * Energy consumption using this transport when sending with a certain
222 * power at a certain bitrate. This is only an approximation based on:
223 * Energy consumption E = P / D
226 * Power P in Watt (J/s)
227 * Datarate D in MBit/s
229 * Conversion between power P and dBm used by WLAN in radiotap's dBm TX power:
231 * Lp(dbm) = 10 log10 (P/ 1mW)
233 * => P = 1 mW * 10^(Lp(dbm)/10)
237 * Interpretation: less is better
242 * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s)
243 * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
245 // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
248 * How many bytes are transmitted to initiate a new connection using
253 * Interpretation: less is better
257 * UDP (No connection) :
259 * TCP (TCP 3-Way handshake):
260 * 220 bytes Ethernet, 172 bytes TCP/IP, 122 bytes TCP
261 * HTTP (TCP + Header) :
262 * 477 bytes Ethernet, 429 bytes TCP/IP, 374 bytes TCP, 278 bytes HTTP
263 * HTTPS HTTP+TLS Handshake:
264 * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
267 // GNUNET_ATS_COST_CONNECT = 5,
271 * How many bandwidth is available to consume?
272 * Used to calculate which impact sending data with this transport has
276 * Interpretation: more is better
279 * LAN: 12,800 (100 MBit/s)
280 * WLAN: 6,912 (54 MBit/s)
281 * Dial-up: 8 (64 Kbit/s)
284 // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
288 * How many bytes are sent over the wire when 1 kilobyte (1024 bytes)
289 * of application data is transmitted?
290 * A factor used with connect cost, bandwidth cost and energy cost
291 * to describe the overhead produced by the transport protocol
295 * Interpretation: less is better
299 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
300 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
301 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
302 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
304 // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
305 /* Quality related values */
306 /* ====================== */
307 /* Physical layer quality properties */
309 * Signal strength on physical layer
313 // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
315 * Collision rate on physical layer
319 // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
321 * Error rate on physical layer
325 // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
328 * Time variations of the delay
329 * 1st derivative of a delay function
333 // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
335 * Error rate on network layer
344 * Note: This numbers are just assumptions as an example, not
345 * measured or somehow determined
347 // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
349 * Drop rate on network layer
350 * Bytes actively dismissed by a network component during transmission
351 * Reasons for dropped data can be full queues, congestion, quota violations...
360 * Note: This numbers are just assumptions as an example, not
361 * measured or somehow determined
363 // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
365 * Loss rate on network layer
366 * Bytes lost during transmission
367 * Reasons can be collisions, ...
376 * Note: This numbers are just assumptions as an example, not measured
377 * or somehow determined
379 // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
381 * Throughput on network layer
392 // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
393 /* Availability related values */
394 /* =========================== */
396 * Is a peer reachable?
398 // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
400 * Is there a connection established to a peer using this transport
402 // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
406 * Number of ATS quality properties
408 #define GNUNET_ATS_QualityPropertiesCount 2
411 * ATS quality properties as array initializer
413 #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE}
416 GNUNET_NETWORK_STRUCT_BEGIN
419 * struct used to communicate the transport's properties like cost and
420 * quality of service as well as high-level constraints on resource
424 * +-----------+ Constraints | | Plugin properties +---------+
425 * | Highlevel |------------> |ATS| <------------------|Transport|
426 * | Component | ATS struct | | ATS struct | Plugin |
427 * +-----------+ | | +---------+
430 * This structure will be used by transport plugins to communicate
431 * costs to ATS or by higher level components to tell ATS their
432 * constraints. Always a pair of (GNUNET_ATS_Property,
433 * uint32_t value). Value is always uint32_t, so all units used to
434 * define costs have to be normalized to fit uint32_t.
436 struct GNUNET_ATS_Information
439 * ATS property type, in network byte order.
441 uint32_t type GNUNET_PACKED;
444 * ATS property value, in network byte order.
446 uint32_t value GNUNET_PACKED;
448 GNUNET_NETWORK_STRUCT_END
451 /* ******************************** Scheduling API ***************************** */
454 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
456 struct GNUNET_ATS_SchedulingHandle;
460 * Opaque session handle, defined by plugins. Contents not known to ATS.
466 * Signature of a function called by ATS with the current bandwidth
467 * and address preferences as determined by ATS.
470 * @param address suggested address (including peer identity of the peer)
471 * @param session session to use
472 * @param bandwidth_out assigned outbound bandwidth for the connection
473 * @param bandwidth_in assigned inbound bandwidth for the connection
474 * @param ats performance data for the address (as far as known)
475 * @param ats_count number of performance records in 'ats'
477 typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
479 GNUNET_HELLO_Address *
481 struct Session * session,
483 GNUNET_BANDWIDTH_Value32NBO
486 GNUNET_BANDWIDTH_Value32NBO
489 GNUNET_ATS_Information *
490 ats, uint32_t ats_count);
494 * Initialize the ATS subsystem.
496 * @param cfg configuration to use
497 * @param suggest_cb notification to call whenever the suggestation changed
498 * @param suggest_cb_cls closure for 'suggest_cb'
499 * @return ats context
501 struct GNUNET_ATS_SchedulingHandle *
502 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
503 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
504 void *suggest_cb_cls);
508 * Client is done with ATS scheduling, release resources.
510 * @param sh handle to release
513 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
517 * We would like to establish a new connection with a peer. ATS
518 * should suggest a good address to begin with.
521 * @param peer identity of the peer we need an address for
524 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
525 const struct GNUNET_PeerIdentity *peer);
529 * We want to cancel ATS suggesting addresses for a peer.
532 * @param peer identity of the peer
535 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
536 const struct GNUNET_PeerIdentity *peer);
540 * Returns where the address is located: LAN or WAN or ...
541 * @param addr address
542 * @param addrlen address length
543 * @return location as GNUNET_ATS_Information
545 struct GNUNET_ATS_Information
546 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
547 const struct sockaddr * addr,
552 * We have updated performance statistics for a given address. Note
553 * that this function can be called for addresses that are currently
554 * in use as well as addresses that are valid but not actively in use.
555 * Furthermore, the peer may not even be connected to us right now (in
556 * which case the call may be ignored or the information may be stored
557 * for later use). Update bandwidth assignments.
560 * @param address updated address
561 * @param session session handle (if available)
562 * @param ats performance data for the address
563 * @param ats_count number of performance records in 'ats'
566 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
567 const struct GNUNET_HELLO_Address *address,
568 struct Session *session,
569 const struct GNUNET_ATS_Information *ats,
574 * An address is now in use or not used any more.
577 * @param address the address
578 * @param session session handle
579 * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
580 * if address is not used any more
583 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
584 const struct GNUNET_HELLO_Address *address,
585 struct Session *session, int in_use);
588 * A session got destroyed, stop including it as a valid address.
591 * @param address the address
592 * @param session session handle that is no longer valid (if available)
595 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
596 const struct GNUNET_HELLO_Address *address,
597 struct Session *session);
600 /* ******************************** Performance API ***************************** */
603 * ATS Handle to obtain and/or modify performance information.
605 struct GNUNET_ATS_PerformanceHandle;
609 * Signature of a function that is called with QoS information about a peer.
612 * @param address the address
613 * @param bandwidth_out assigned outbound bandwidth for the connection
614 * @param bandwidth_in assigned inbound bandwidth for the connection
615 * @param ats performance data for the address (as far as known)
616 * @param ats_count number of performance records in 'ats'
618 typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
620 GNUNET_HELLO_Address *
623 GNUNET_BANDWIDTH_Value32NBO
626 GNUNET_BANDWIDTH_Value32NBO
629 GNUNET_ATS_Information *
630 ats, uint32_t ats_count);
634 * Get handle to access performance API of the ATS subsystem.
636 * @param cfg configuration to use
637 * @param infocb function to call on performance changes, can be NULL
638 * @param infocb_cls closure for infocb
639 * @return ats performance context
641 struct GNUNET_ATS_PerformanceHandle *
642 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
643 GNUNET_ATS_PeerInformationCallback infocb,
648 * Client is done using the ATS performance subsystem, release resources.
653 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
657 * Function called with reservation result.
660 * @param peer identifies the peer
661 * @param amount set to the amount that was actually reserved or unreserved;
662 * either the full requested amount or zero (no partial reservations)
663 * @param res_delay if the reservation could not be satisfied (amount was 0), how
664 * long should the client wait until re-trying?
666 typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
667 const struct GNUNET_PeerIdentity
668 * peer, int32_t amount,
669 struct GNUNET_TIME_Relative
675 * Context that can be used to cancel a peer information request.
677 struct GNUNET_ATS_ReservationContext;
681 * Reserve inbound bandwidth from the given peer. ATS will look at
682 * the current amount of traffic we receive from the peer and ensure
683 * that the peer could add 'amount' of data to its stream.
685 * @param ph performance handle
686 * @param peer identifies the peer
687 * @param amount reserve N bytes for receiving, negative
688 * amounts can be used to undo a (recent) reservation;
689 * @param rcb function to call with the resulting reservation information
690 * @param rcb_cls closure for info
691 * @return NULL on error
692 * @deprecated will be replaced soon
694 struct GNUNET_ATS_ReservationContext *
695 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
696 const struct GNUNET_PeerIdentity *peer,
698 GNUNET_ATS_ReservationCallback rcb,
703 * Cancel request for reserving bandwidth.
705 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
708 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
713 * Enum defining all known preference categories.
715 enum GNUNET_ATS_PreferenceKind
719 * End of preference list.
721 GNUNET_ATS_PREFERENCE_END = 0,
724 * Change the peer's bandwidth value (value per byte of bandwidth in
725 * the goal function) to the given amount. The argument is followed
726 * by a double value giving the desired value (can be negative).
727 * Preference changes are forgotten if peers disconnect.
729 GNUNET_ATS_PREFERENCE_BANDWIDTH,
732 * Change the peer's latency value to the given amount. The
733 * argument is followed by a double value giving the desired value
734 * (can be negative). The absolute score in the goal function is
735 * the inverse of the latency in ms (minimum: 1 ms) multiplied by
736 * the latency preferences.
738 GNUNET_ATS_PREFERENCE_LATENCY
743 * Change preferences for the given peer. Preference changes are forgotten if peers
746 * @param ph performance handle
747 * @param peer identifies the peer
748 * @param ... 0-terminated specification of the desired changes
751 GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
752 const struct GNUNET_PeerIdentity *peer, ...);
757 /* end of file gnunet-service-transport_ats.h */