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 * Number of network types supported by ATS
36 #define GNUNET_ATS_NetworkTypeCount 5
39 * ATS network types as array initializer
41 #define GNUNET_ATS_NetworkType {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
44 * ATS network types as string array initializer
46 #define GNUNET_ATS_NetworkTypeString {"UNSPECIFIED", "LOOPBACK", "LAN", "WAN", "WLAN"}
48 enum GNUNET_ATS_Network_Type
50 GNUNET_ATS_NET_UNSPECIFIED = 0,
51 GNUNET_ATS_NET_LOOPBACK = 1,
52 GNUNET_ATS_NET_LAN = 2,
53 GNUNET_ATS_NET_WAN = 3,
54 GNUNET_ATS_NET_WLAN = 4,
58 * Default bandwidth assigned to a network : 64 KB/s
60 #define GNUNET_ATS_DefaultBandwidth 65536
63 * Maximum bandwidth assigned to a network : 4095 MB/s
65 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
68 * Number of property types supported by ATS
70 #define GNUNET_ATS_PropertyCount 9
73 * ATS properties types as string array initializer
75 #define GNUNET_ATS_PropertyStrings {"Terminator", "Utilization up", "Utilization down", "Network type", "Delay", "Distance", "Cost WAN", "Cost LAN", "Cost WLAN"}
78 * Enum defining all known property types for ATS Enum values are used
79 * in the GNUNET_ATS_Information struct as
82 * Cost are always stored in uint32_t, so all units used to define costs
83 * have to be normalized to fit in uint32_t [0 .. 4.294.967.295]
85 enum GNUNET_ATS_Property
92 GNUNET_ATS_ARRAY_TERMINATOR = 0,
95 * Actual traffic on this connection from the other peer to this peer.
97 * Unit: [bytes/second]
99 GNUNET_ATS_UTILIZATION_UP,
102 * Actual traffic on this connection from this peer to the other peer.
104 * Unit: [bytes/second]
106 GNUNET_ATS_UTILIZATION_DOWN,
109 * Is this address located in WAN, LAN or a loopback address
110 * Value is element of GNUNET_ATS_Network_Type
112 GNUNET_ATS_NETWORK_TYPE,
116 * Time between when the time packet is sent and the packet arrives
126 GNUNET_ATS_QUALITY_NET_DELAY,
129 * Distance on network layer (required for distance-vector routing).
133 GNUNET_ATS_QUALITY_NET_DISTANCE,
136 * Network overhead on WAN (Wide-Area Network)
138 * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
139 * of application data is transmitted?
140 * A factor used with connect cost, bandwidth cost and energy cost
141 * to describe the overhead produced by the transport protocol
145 * Interpretation: less is better
149 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
150 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
151 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
152 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
157 * Network overhead on LAN (Local-Area Network)
159 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
160 * of application data is transmitted?
161 * A factor used with connect cost, bandwidth cost and energy cost
162 * to describe the overhead produced by the transport protocol
166 * Interpretation: less is better
170 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
171 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
172 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
173 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
178 * Network overhead on WLAN (Wireless Local Area Network)
180 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
181 * of application data is transmitted?
182 * A factor used with connect cost, bandwidth cost and energy cost
183 * to describe the overhead produced by the transport protocol
187 * Interpretation: less is better
191 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
192 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
193 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
194 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
197 /* Cost related values */
198 /* =================== */
200 * Volume based cost in financial units to transmit data
202 * Note: This value is not bound to a specific currency or unit and only
204 * "cent" just refers the smallest amount of money in the respective
209 * Interpretation: less is better
215 // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
217 * Time based cost in financial units to transmit data
219 * Note: This value is not bound to a specific currency or unit and only
221 * "cent" just refers the smallest amount of money in the respective
226 * Interpretation: less is better
230 * Dialup: 10 [cent/h]
232 // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
234 * Computational costs
236 * Effort of preparing data to be sent with this transport
237 * Includes encoding, encryption and conversion of data
238 * Partial values can be summed up: c_sum = c_enc + c_enc + c_conv
239 * Resulting values depend on local system properties, e.g. CPU
243 * Interpretation: less is better
247 * HTTPS with AES CBC-256: 7,382
248 * HTTPS with AES CBC-128: 5,279
249 * HTTPS with RC4-1024: 2,652
251 // GNUNET_ATS_COST_COMPUTATIONAL = 3,
255 * Energy consumption using this transport when sending with a certain
256 * power at a certain bitrate. This is only an approximation based on:
257 * Energy consumption E = P / D
260 * Power P in Watt (J/s)
261 * Datarate D in MBit/s
263 * Conversion between power P and dBm used by WLAN in radiotap's dBm TX power:
265 * Lp(dbm) = 10 log10 (P/ 1mW)
267 * => P = 1 mW * 10^(Lp(dbm)/10)
271 * Interpretation: less is better
276 * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s)
277 * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
279 // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
282 * How many bytes are transmitted to initiate a new connection using
287 * Interpretation: less is better
291 * UDP (No connection) :
293 * TCP (TCP 3-Way handshake):
294 * 220 bytes Ethernet, 172 bytes TCP/IP, 122 bytes TCP
295 * HTTP (TCP + Header) :
296 * 477 bytes Ethernet, 429 bytes TCP/IP, 374 bytes TCP, 278 bytes HTTP
297 * HTTPS HTTP+TLS Handshake:
298 * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
301 // GNUNET_ATS_COST_CONNECT = 5,
305 * How many bandwidth is available to consume?
306 * Used to calculate which impact sending data with this transport has
310 * Interpretation: more is better
313 * LAN: 12,800 (100 MBit/s)
314 * WLAN: 6,912 (54 MBit/s)
315 * Dial-up: 8 (64 Kbit/s)
318 // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
322 * How many bytes are sent over the wire when 1 kilobyte (1024 bytes)
323 * of application data is transmitted?
324 * A factor used with connect cost, bandwidth cost and energy cost
325 * to describe the overhead produced by the transport protocol
329 * Interpretation: less is better
333 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
334 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
335 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
336 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
338 // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
339 /* Quality related values */
340 /* ====================== */
341 /* Physical layer quality properties */
343 * Signal strength on physical layer
347 // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
349 * Collision rate on physical layer
353 // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
355 * Error rate on physical layer
359 // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
362 * Time variations of the delay
363 * 1st derivative of a delay function
367 // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
369 * Error rate on network layer
378 * Note: This numbers are just assumptions as an example, not
379 * measured or somehow determined
381 // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
383 * Drop rate on network layer
384 * Bytes actively dismissed by a network component during transmission
385 * Reasons for dropped data can be full queues, congestion, quota violations...
394 * Note: This numbers are just assumptions as an example, not
395 * measured or somehow determined
397 // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
399 * Loss rate on network layer
400 * Bytes lost during transmission
401 * Reasons can be collisions, ...
410 * Note: This numbers are just assumptions as an example, not measured
411 * or somehow determined
413 // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
415 * Throughput on network layer
426 // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
427 /* Availability related values */
428 /* =========================== */
430 * Is a peer reachable?
432 // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
434 * Is there a connection established to a peer using this transport
436 // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
440 * Number of ATS quality properties
442 #define GNUNET_ATS_QualityPropertiesCount 2
445 * ATS quality properties as array initializer
447 #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE}
450 * ATS quality properties as string array initializer
452 #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"}
455 GNUNET_NETWORK_STRUCT_BEGIN
458 * struct used to communicate the transport's properties like cost and
459 * quality of service as well as high-level constraints on resource
463 * +-----------+ Constraints | | Plugin properties +---------+
464 * | Highlevel |------------> |ATS| <------------------|Transport|
465 * | Component | ATS struct | | ATS struct | Plugin |
466 * +-----------+ | | +---------+
469 * This structure will be used by transport plugins to communicate
470 * costs to ATS or by higher level components to tell ATS their
471 * constraints. Always a pair of (GNUNET_ATS_Property,
472 * uint32_t value). Value is always uint32_t, so all units used to
473 * define costs have to be normalized to fit uint32_t.
475 struct GNUNET_ATS_Information
478 * ATS property type, in network byte order.
480 uint32_t type GNUNET_PACKED;
483 * ATS property value, in network byte order.
485 uint32_t value GNUNET_PACKED;
487 GNUNET_NETWORK_STRUCT_END
490 /* ******************************** Scheduling API ***************************** */
493 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
495 struct GNUNET_ATS_SchedulingHandle;
498 * Handle for address suggestion requests
501 struct GNUNET_ATS_SuggestHandle;
506 * Opaque session handle, defined by plugins. Contents not known to ATS.
513 * Signature of a function called by ATS with the current bandwidth
514 * and address preferences as determined by ATS.
517 * @param address suggested address (including peer identity of the peer)
518 * @param session session to use
519 * @param bandwidth_out assigned outbound bandwidth for the connection
520 * @param bandwidth_in assigned inbound bandwidth for the connection
521 * @param ats performance data for the address (as far as known)
522 * @param ats_count number of performance records in 'ats'
524 typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
526 GNUNET_HELLO_Address *
528 struct Session * session,
530 GNUNET_BANDWIDTH_Value32NBO
533 GNUNET_BANDWIDTH_Value32NBO
536 GNUNET_ATS_Information *
537 ats, uint32_t ats_count);
541 * Initialize the ATS subsystem.
543 * @param cfg configuration to use
544 * @param suggest_cb notification to call whenever the suggestation changed
545 * @param suggest_cb_cls closure for 'suggest_cb'
546 * @return ats context
548 struct GNUNET_ATS_SchedulingHandle *
549 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
550 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
551 void *suggest_cb_cls);
555 * Client is done with ATS scheduling, release resources.
557 * @param sh handle to release
560 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
564 * We would like to reset the address suggestion block time for this
568 * @param peer identity of the peer we want to reset
571 GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
572 const struct GNUNET_PeerIdentity *peer);
575 * We would like to establish a new connection with a peer. ATS
576 * should suggest a good address to begin with.
579 * @param peer identity of the peer we need an address for
580 * @return suggestion handle
582 struct GNUNET_ATS_SuggestHandle *
583 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
584 const struct GNUNET_PeerIdentity *peer);
588 * We want to cancel ATS suggesting addresses for a peer.
591 * @param peer identity of the peer
594 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
595 const struct GNUNET_PeerIdentity *peer);
599 * Convert a GNUNET_ATS_NetworkType to a string
601 * @param net the network type
602 * @return a string or NULL if invalid
605 GNUNET_ATS_print_network_type (uint32_t net);
608 * Returns where the address is located: LAN or WAN or ...
609 * @param sh the GNUNET_ATS_SchedulingHandle handle
610 * @param addr address
611 * @param addrlen address length
612 * @return location as GNUNET_ATS_Information
614 struct GNUNET_ATS_Information
615 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
616 const struct sockaddr * addr,
620 * We have a new address ATS should know. Addresses have to be added with this
621 * function before they can be: updated, set in use and destroyed
624 * @param address the address
625 * @param session session handle (if available)
626 * @param ats performance data for the address
627 * @param ats_count number of performance records in 'ats'
630 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
631 const struct GNUNET_HELLO_Address *address,
632 struct Session *session,
633 const struct GNUNET_ATS_Information *ats,
638 * We have updated performance statistics for a given address. Note
639 * that this function can be called for addresses that are currently
640 * in use as well as addresses that are valid but not actively in use.
641 * Furthermore, the peer may not even be connected to us right now (in
642 * which case the call may be ignored or the information may be stored
643 * for later use). Update bandwidth assignments.
646 * @param address updated address
647 * @param session session handle (if available)
648 * @param ats performance data for the address
649 * @param ats_count number of performance records in 'ats'
652 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
653 const struct GNUNET_HELLO_Address *address,
654 struct Session *session,
655 const struct GNUNET_ATS_Information *ats,
660 * An address is now in use or not used any more.
663 * @param address the address
664 * @param session session handle
665 * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
666 * if address is not used any more
669 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
670 const struct GNUNET_HELLO_Address *address,
671 struct Session *session, int in_use);
675 * A session got destroyed, stop including it as a valid address.
678 * @param address the address
679 * @param session session handle that is no longer valid (if available)
682 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
683 const struct GNUNET_HELLO_Address *address,
684 struct Session *session);
687 /* ******************************** Performance API ***************************** */
690 * ATS Handle to obtain and/or modify performance information.
692 struct GNUNET_ATS_PerformanceHandle;
696 * Signature of a function that is called with QoS information about a peer.
699 * @param address the address
700 * @param bandwidth_out assigned outbound bandwidth for the connection
701 * @param bandwidth_in assigned inbound bandwidth for the connection
702 * @param ats performance data for the address (as far as known)
703 * @param ats_count number of performance records in 'ats'
705 typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
707 GNUNET_HELLO_Address *
710 GNUNET_BANDWIDTH_Value32NBO
713 GNUNET_BANDWIDTH_Value32NBO
716 GNUNET_ATS_Information *
717 ats, uint32_t ats_count);
720 * Handle for an address listing operation
722 struct GNUNET_ATS_AddressListHandle;
726 * Get handle to access performance API of the ATS subsystem.
728 * @param cfg configuration to use
729 * @param infocb function to call on performance changes, can be NULL
730 * @param infocb_cls closure for infocb
731 * @return ats performance context
733 struct GNUNET_ATS_PerformanceHandle *
734 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
735 GNUNET_ATS_PeerInformationCallback infocb,
740 * Get information about addresses known to the ATS subsystem.
742 * @param handle the performance handle to use
743 * @param peer peer idm can be NULL for all peers
744 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
745 * get only address currently used
746 * @param infocb callback to call with the addresses,
747 * will callback with address == NULL when done
748 * @param infocb_cls closure for infocb
749 * @return ats performance context
751 struct GNUNET_ATS_AddressListHandle *
752 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
753 const struct GNUNET_PeerIdentity *peer,
755 GNUNET_ATS_PeerInformationCallback infocb,
760 * Cancel a pending address listing operation
762 * @param handle the GNUNET_ATS_AddressListHandle handle to cancel
765 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
769 * Client is done using the ATS performance subsystem, release resources.
774 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
778 * Function called with reservation result.
781 * @param peer identifies the peer
782 * @param amount set to the amount that was actually reserved or unreserved;
783 * either the full requested amount or zero (no partial reservations)
784 * @param res_delay if the reservation could not be satisfied (amount was 0), how
785 * long should the client wait until re-trying?
787 typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
788 const struct GNUNET_PeerIdentity
789 * peer, int32_t amount,
790 struct GNUNET_TIME_Relative
796 * Context that can be used to cancel a peer information request.
798 struct GNUNET_ATS_ReservationContext;
802 * Reserve inbound bandwidth from the given peer. ATS will look at
803 * the current amount of traffic we receive from the peer and ensure
804 * that the peer could add 'amount' of data to its stream.
806 * @param ph performance handle
807 * @param peer identifies the peer
808 * @param amount reserve N bytes for receiving, negative
809 * amounts can be used to undo a (recent) reservation;
810 * @param rcb function to call with the resulting reservation information
811 * @param rcb_cls closure for info
812 * @return NULL on error
813 * @deprecated will be replaced soon
815 struct GNUNET_ATS_ReservationContext *
816 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
817 const struct GNUNET_PeerIdentity *peer,
819 GNUNET_ATS_ReservationCallback rcb,
824 * Cancel request for reserving bandwidth.
826 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
829 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
833 * Number of preference types supported by ATS
835 #define GNUNET_ATS_PreferenceCount 3
838 * ATS preference types as array initializer
840 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY}
843 * ATS preference types as string array initializer
845 #define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"}
849 * Enum defining all known preference categories.
851 enum GNUNET_ATS_PreferenceKind
855 * End of preference list.
857 GNUNET_ATS_PREFERENCE_END = 0,
860 * Change the peer's bandwidth value (value per byte of bandwidth in
861 * the goal function) to the given amount. The argument is followed
862 * by a double value giving the desired value (can be negative).
863 * Preference changes are forgotten if peers disconnect.
865 GNUNET_ATS_PREFERENCE_BANDWIDTH,
868 * Change the peer's latency value to the given amount. The
869 * argument is followed by a double value giving the desired value
870 * (can be negative). The absolute score in the goal function is
871 * the inverse of the latency in ms (minimum: 1 ms) multiplied by
872 * the latency preferences.
874 GNUNET_ATS_PREFERENCE_LATENCY
878 * Convert a GNUNET_ATS_PreferenceType to a string
880 * @param type the preference type
881 * @return a string or NULL if invalid
884 GNUNET_ATS_print_preference_type (uint32_t type);
887 * Change preferences for the given peer. Preference changes are forgotten if peers
890 * @param ph performance handle
891 * @param peer identifies the peer
892 * @param ... 0-terminated specification of the desired changes
895 GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
896 const struct GNUNET_PeerIdentity *peer, ...);
901 /* end of file gnunet-service-transport_ats.h */