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;
499 * Opaque session handle, defined by plugins. Contents not known to ATS.
505 * Signature of a function called by ATS with the current bandwidth
506 * and address preferences as determined by ATS.
509 * @param address suggested address (including peer identity of the peer)
510 * @param session session to use
511 * @param bandwidth_out assigned outbound bandwidth for the connection
512 * @param bandwidth_in assigned inbound bandwidth for the connection
513 * @param ats performance data for the address (as far as known)
514 * @param ats_count number of performance records in 'ats'
516 typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
518 GNUNET_HELLO_Address *
520 struct Session * session,
522 GNUNET_BANDWIDTH_Value32NBO
525 GNUNET_BANDWIDTH_Value32NBO
528 GNUNET_ATS_Information *
529 ats, uint32_t ats_count);
533 * Initialize the ATS subsystem.
535 * @param cfg configuration to use
536 * @param suggest_cb notification to call whenever the suggestation changed
537 * @param suggest_cb_cls closure for 'suggest_cb'
538 * @return ats context
540 struct GNUNET_ATS_SchedulingHandle *
541 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
542 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
543 void *suggest_cb_cls);
547 * Client is done with ATS scheduling, release resources.
549 * @param sh handle to release
552 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
556 * We would like to reset the address suggestion block time for this
560 * @param peer identity of the peer we want to reset
563 GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
564 const struct GNUNET_PeerIdentity *peer);
567 * We would like to establish a new connection with a peer. ATS
568 * should suggest a good address to begin with.
571 * @param peer identity of the peer we need an address for
574 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
575 const struct GNUNET_PeerIdentity *peer);
579 * We want to cancel ATS suggesting addresses for a peer.
582 * @param peer identity of the peer
585 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
586 const struct GNUNET_PeerIdentity *peer);
590 * Convert a GNUNET_ATS_NetworkType to a string
592 * @param net the network type
593 * @return a string or NULL if invalid
596 GNUNET_ATS_print_network_type (uint32_t net);
599 * Returns where the address is located: LAN or WAN or ...
600 * @param sh the GNUNET_ATS_SchedulingHandle handle
601 * @param addr address
602 * @param addrlen address length
603 * @return location as GNUNET_ATS_Information
605 struct GNUNET_ATS_Information
606 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
607 const struct sockaddr * addr,
611 * We have a new address ATS should know. Addresses have to be added with this
612 * function before they can be: updated, set in use and destroyed
615 * @param address the address
616 * @param session session handle (if available)
617 * @param ats performance data for the address
618 * @param ats_count number of performance records in 'ats'
621 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
622 const struct GNUNET_HELLO_Address *address,
623 struct Session *session,
624 const struct GNUNET_ATS_Information *ats,
629 * We have updated performance statistics for a given address. Note
630 * that this function can be called for addresses that are currently
631 * in use as well as addresses that are valid but not actively in use.
632 * Furthermore, the peer may not even be connected to us right now (in
633 * which case the call may be ignored or the information may be stored
634 * for later use). Update bandwidth assignments.
637 * @param address updated address
638 * @param session session handle (if available)
639 * @param ats performance data for the address
640 * @param ats_count number of performance records in 'ats'
643 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
644 const struct GNUNET_HELLO_Address *address,
645 struct Session *session,
646 const struct GNUNET_ATS_Information *ats,
651 * An address is now in use or not used any more.
654 * @param address the address
655 * @param session session handle
656 * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
657 * if address is not used any more
660 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
661 const struct GNUNET_HELLO_Address *address,
662 struct Session *session, int in_use);
666 * A session got destroyed, stop including it as a valid address.
669 * @param address the address
670 * @param session session handle that is no longer valid (if available)
673 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
674 const struct GNUNET_HELLO_Address *address,
675 struct Session *session);
678 /* ******************************** Performance API ***************************** */
681 * ATS Handle to obtain and/or modify performance information.
683 struct GNUNET_ATS_PerformanceHandle;
687 * Signature of a function that is called with QoS information about a peer.
690 * @param address the address
691 * @param bandwidth_out assigned outbound bandwidth for the connection
692 * @param bandwidth_in assigned inbound bandwidth for the connection
693 * @param ats performance data for the address (as far as known)
694 * @param ats_count number of performance records in 'ats'
696 typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
698 GNUNET_HELLO_Address *
701 GNUNET_BANDWIDTH_Value32NBO
704 GNUNET_BANDWIDTH_Value32NBO
707 GNUNET_ATS_Information *
708 ats, uint32_t ats_count);
711 * Handle for an address listing operation
713 struct GNUNET_ATS_AddressListHandle;
717 * Get handle to access performance API of the ATS subsystem.
719 * @param cfg configuration to use
720 * @param infocb function to call on performance changes, can be NULL
721 * @param infocb_cls closure for infocb
722 * @return ats performance context
724 struct GNUNET_ATS_PerformanceHandle *
725 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
726 GNUNET_ATS_PeerInformationCallback infocb,
731 * Get information about addresses known to the ATS subsystem.
733 * @param handle the performance handle to use
734 * @param peer peer idm can be NULL for all peers
735 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
736 * get only address currently used
737 * @param infocb callback to call with the addresses,
738 * will callback with address == NULL when done
739 * @param infocb_cls closure for infocb
740 * @return ats performance context
742 struct GNUNET_ATS_AddressListHandle *
743 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
744 const struct GNUNET_PeerIdentity *peer,
746 GNUNET_ATS_PeerInformationCallback infocb,
751 * Cancel a pending address listing operation
753 * @param handle the GNUNET_ATS_AddressListHandle handle to cancel
756 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
760 * Client is done using the ATS performance subsystem, release resources.
765 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
769 * Function called with reservation result.
772 * @param peer identifies the peer
773 * @param amount set to the amount that was actually reserved or unreserved;
774 * either the full requested amount or zero (no partial reservations)
775 * @param res_delay if the reservation could not be satisfied (amount was 0), how
776 * long should the client wait until re-trying?
778 typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
779 const struct GNUNET_PeerIdentity
780 * peer, int32_t amount,
781 struct GNUNET_TIME_Relative
787 * Context that can be used to cancel a peer information request.
789 struct GNUNET_ATS_ReservationContext;
793 * Reserve inbound bandwidth from the given peer. ATS will look at
794 * the current amount of traffic we receive from the peer and ensure
795 * that the peer could add 'amount' of data to its stream.
797 * @param ph performance handle
798 * @param peer identifies the peer
799 * @param amount reserve N bytes for receiving, negative
800 * amounts can be used to undo a (recent) reservation;
801 * @param rcb function to call with the resulting reservation information
802 * @param rcb_cls closure for info
803 * @return NULL on error
804 * @deprecated will be replaced soon
806 struct GNUNET_ATS_ReservationContext *
807 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
808 const struct GNUNET_PeerIdentity *peer,
810 GNUNET_ATS_ReservationCallback rcb,
815 * Cancel request for reserving bandwidth.
817 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
820 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
825 * Enum defining all known preference categories.
827 enum GNUNET_ATS_PreferenceKind
831 * End of preference list.
833 GNUNET_ATS_PREFERENCE_END = 0,
836 * Change the peer's bandwidth value (value per byte of bandwidth in
837 * the goal function) to the given amount. The argument is followed
838 * by a double value giving the desired value (can be negative).
839 * Preference changes are forgotten if peers disconnect.
841 GNUNET_ATS_PREFERENCE_BANDWIDTH,
844 * Change the peer's latency value to the given amount. The
845 * argument is followed by a double value giving the desired value
846 * (can be negative). The absolute score in the goal function is
847 * the inverse of the latency in ms (minimum: 1 ms) multiplied by
848 * the latency preferences.
850 GNUNET_ATS_PREFERENCE_LATENCY
855 * Change preferences for the given peer. Preference changes are forgotten if peers
858 * @param ph performance handle
859 * @param peer identifies the peer
860 * @param ... 0-terminated specification of the desired changes
863 GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
864 const struct GNUNET_PeerIdentity *peer, ...);
869 /* end of file gnunet-service-transport_ats.h */