2 This file is part of GNUnet.
3 (C) 2010-2015 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 6
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, GNUNET_ATS_NET_BT }
45 * Types of networks (with separate quotas) we support.
47 enum GNUNET_ATS_Network_Type
50 * Category of last resort.
52 GNUNET_ATS_NET_UNSPECIFIED = 0,
55 * Loopback (same host).
57 GNUNET_ATS_NET_LOOPBACK = 1,
62 GNUNET_ATS_NET_LAN = 2,
65 * Wide area network (i.e. Internet)
67 GNUNET_ATS_NET_WAN = 3,
70 * Wireless LAN (i.e. 802.11abgn)
72 GNUNET_ATS_NET_WLAN = 4,
82 * Default bandwidth assigned to a network : 64 KB/s
84 #define GNUNET_ATS_DefaultBandwidth 65536
87 * Undefined value for an `enum GNUNET_ATS_Property`
89 #define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
92 * String representation for GNUNET_ATS_VALUE_UNDEFINED
94 #define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
97 * Maximum bandwidth assigned to a network : 4095 MB/s
99 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
102 * Textual equivalent for GNUNET_ATS_MaxBandwidth
104 #define GNUNET_ATS_MaxBandwidthString "unlimited"
107 * Number of property types supported by ATS
109 #define GNUNET_ATS_PropertyCount 11
113 * Enum defining all known property types for ATS Enum values are used
114 * in the GNUNET_ATS_Information struct as
117 * Cost are always stored in uint32_t, so all units used to define costs
118 * have to be normalized to fit in uint32_t [0 .. UINT32_MAX-1]
120 * UINT32_MAX is reserved for uninitialized values #GNUNET_ATS_VALUE_UNDEFINED
122 enum GNUNET_ATS_Property
129 GNUNET_ATS_ARRAY_TERMINATOR = 0,
132 * Actual traffic on this connection from this peer to the other peer.
133 * Includes transport overhead
135 * Unit: [bytes/second]
137 GNUNET_ATS_UTILIZATION_OUT,
140 * Actual traffic on this connection from the other peer to this peer.
141 * Includes transport overhead
143 * Unit: [bytes/second]
145 GNUNET_ATS_UTILIZATION_IN,
148 * Actual traffic on this connection from this peer to the other peer.
149 * Only payload from layers > transport
151 * Unit: [bytes/second]
153 GNUNET_ATS_UTILIZATION_PAYLOAD_OUT,
156 * Actual traffic on this connection from the other peer to this peer.
157 * Only payload from layers > transport
159 * Unit: [bytes/second]
161 GNUNET_ATS_UTILIZATION_PAYLOAD_IN,
164 * Is this address located in WAN, LAN or a loopback address
165 * Value is element of GNUNET_ATS_Network_Type
167 GNUNET_ATS_NETWORK_TYPE,
171 * Time between when the time packet is sent and the packet arrives
173 * Unit: [microseconds]
181 GNUNET_ATS_QUALITY_NET_DELAY,
184 * Distance on network layer (required for distance-vector routing).
188 GNUNET_ATS_QUALITY_NET_DISTANCE,
191 * Network overhead on WAN (Wide-Area Network)
193 * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
194 * of application data is transmitted?
195 * A factor used with connect cost, bandwidth cost and energy cost
196 * to describe the overhead produced by the transport protocol
200 * Interpretation: less is better
204 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
205 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
206 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
207 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
212 * Network overhead on LAN (Local-Area Network)
214 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
215 * of application data is transmitted?
216 * A factor used with connect cost, bandwidth cost and energy cost
217 * to describe the overhead produced by the transport protocol
221 * Interpretation: less is better
225 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
226 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
227 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
228 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
233 * Network overhead on WLAN (Wireless Local Area Network)
235 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
236 * of application data is transmitted?
237 * A factor used with connect cost, bandwidth cost and energy cost
238 * to describe the overhead produced by the transport protocol
242 * Interpretation: less is better
246 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
247 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
248 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
249 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
257 * Number of ATS quality properties
259 #define GNUNET_ATS_QualityPropertiesCount 2
262 * ATS quality properties as array initializer
264 #define GNUNET_ATS_QualityProperties { GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE }
267 * ATS quality properties as string array initializer
269 #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"}
271 GNUNET_NETWORK_STRUCT_BEGIN
274 * struct used to communicate the transport's properties like cost and
275 * quality of service as well as high-level constraints on resource
279 * +-----------+ Constraints | | Plugin properties +---------+
280 * | Highlevel |------------> |ATS| <------------------|Transport|
281 * | Component | ATS struct | | ATS struct | Plugin |
282 * +-----------+ | | +---------+
285 * This structure will be used by transport plugins to communicate
286 * costs to ATS or by higher level components to tell ATS their
287 * constraints. Always a pair of (GNUNET_ATS_Property,
288 * uint32_t value). Value is always uint32_t, so all units used to
289 * define costs have to be normalized to fit uint32_t.
291 struct GNUNET_ATS_Information
294 * ATS property type, in network byte order.
296 uint32_t type GNUNET_PACKED;
299 * ATS property value, in network byte order.
301 uint32_t value GNUNET_PACKED;
303 GNUNET_NETWORK_STRUCT_END
305 /* ******************************** Scheduling API ***************************** */
308 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
310 struct GNUNET_ATS_SchedulingHandle;
313 * Handle for address suggestion requests
315 struct GNUNET_ATS_SuggestHandle;
318 * Opaque session handle, defined by plugins. Contents not known to ATS.
323 * Signature of a function called by ATS with the current bandwidth
324 * and address preferences as determined by ATS.
326 * If an address is available immediately the address will be included. If no
327 * address can be suggested, address, session, bandwidth and ATS information will
328 * be NULL/0. ATS will suggest an address as soon as it can provide such an
332 * @param address suggested address (including peer identity of the peer)
333 * @param session session to use
334 * @param bandwidth_out assigned outbound bandwidth for the connection
335 * @param bandwidth_in assigned inbound bandwidth for the connection
336 * @param ats performance data for the address (as far as known)
337 * @param ats_count number of performance records in @a ats
340 (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
341 const struct GNUNET_PeerIdentity *peer,
342 const struct GNUNET_HELLO_Address *address,
343 struct Session *session,
344 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
345 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
346 const struct GNUNET_ATS_Information *ats, uint32_t ats_count);
350 * Initialize the ATS subsystem.
352 * @param cfg configuration to use
353 * @param suggest_cb notification to call whenever the suggestation changed
354 * @param suggest_cb_cls closure for @a suggest_cb
355 * @return ats context
357 struct GNUNET_ATS_SchedulingHandle *
358 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
359 GNUNET_ATS_AddressSuggestionCallback suggest_cb, void *suggest_cb_cls);
363 * Client is done with ATS scheduling, release resources.
365 * @param sh handle to release
368 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
372 * We would like to reset the address suggestion block time for this
376 * @param peer identity of the peer we want to reset
379 GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
380 const struct GNUNET_PeerIdentity *peer);
384 * We would like to establish a new connection with a peer. ATS
385 * should suggest a good address to begin with.
388 * @param peer identity of the peer we need an address for
389 * @return suggestion handle
391 struct GNUNET_ATS_SuggestHandle *
392 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
393 const struct GNUNET_PeerIdentity *peer);
397 * We want to cancel ATS suggesting addresses for a peer.
400 * @param peer identity of the peer
403 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
404 const struct GNUNET_PeerIdentity *peer);
408 * Convert a ATS property to a string
410 * @param type the property type
411 * @return a string or NULL if invalid
414 GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type);
418 * Convert a `enum GNUNET_ATS_Network_Type` to a string
420 * @param net the network type
421 * @return a string or NULL if invalid
424 GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
428 * Returns where the address is located: LAN or WAN or ...
430 * @param sh the `struct GNUNET_ATS_SchedulingHandle` handle
431 * @param addr address
432 * @param addrlen address length
433 * @return location as `struct GNUNET_ATS_Information`
435 struct GNUNET_ATS_Information
436 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
437 const struct sockaddr *addr,
442 * Test if a address and a session is known to ATS.
444 * @param sh the scheduling handle
445 * @param address the address
446 * @param session the session
447 * @return #GNUNET_YES or #GNUNET_NO
450 GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh,
451 const struct GNUNET_HELLO_Address *address,
452 struct Session *session);
456 * We have a new address ATS should know. Addresses have to be added with this
457 * function before they can be: updated, set in use and destroyed
460 * @param address the address
461 * @param session session handle (if available)
462 * @param ats performance data for the address
463 * @param ats_count number of performance records in @a ats
466 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
467 const struct GNUNET_HELLO_Address *address,
468 struct Session *session,
469 const struct GNUNET_ATS_Information *ats,
474 * We have updated performance statistics for a given address. Note
475 * that this function can be called for addresses that are currently
476 * in use as well as addresses that are valid but not actively in use.
477 * Furthermore, the peer may not even be connected to us right now (in
478 * which case the call may be ignored or the information may be stored
479 * for later use). Update bandwidth assignments.
482 * @param address updated address
483 * @param session session handle (if available)
484 * @param ats performance data for the address
485 * @param ats_count number of performance records in @a ats
486 * @return #GNUNET_OK or #GNUNET_SYSERR
489 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
490 const struct GNUNET_HELLO_Address *address,
491 struct Session *session,
492 const struct GNUNET_ATS_Information *ats,
497 * An address is now in use or not used any more.
500 * @param address the address
501 * @param session session handle
502 * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO
503 * if address is not used any more
506 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
507 const struct GNUNET_HELLO_Address *address,
508 struct Session *session,
513 * An address got destroyed, stop including it as a valid address.
515 * If a session is given, only the session will be removed, if no session is
516 * given the full address will be deleted.
519 * @param address the address
520 * @param session session handle that is no longer valid (if available)
523 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
524 const struct GNUNET_HELLO_Address *address,
525 struct Session *session);
528 /* ******************************** Performance API ***************************** */
531 * ATS Handle to obtain and/or modify performance information.
533 struct GNUNET_ATS_PerformanceHandle;
536 * Signature of a function that is called with QoS information about an address.
539 * @param address the address, NULL if ATS service was disconnected
540 * @param address_active #GNUNET_YES if this address is actively used
541 * to maintain a connection to a peer;
542 * #GNUNET_NO if the address is not actively used;
543 * #GNUNET_SYSERR if this address is no longer available for ATS
544 * @param bandwidth_out assigned outbound bandwidth for the connection
545 * @param bandwidth_in assigned inbound bandwidth for the connection
546 * @param ats performance data for the address (as far as known)
547 * @param ats_count number of performance records in @a ats
550 (*GNUNET_ATS_AddressInformationCallback) (void *cls,
551 const struct GNUNET_HELLO_Address *address,
553 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
554 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
555 const struct GNUNET_ATS_Information *ats,
560 * Handle for an address listing operation
562 struct GNUNET_ATS_AddressListHandle;
566 * Get handle to access performance API of the ATS subsystem.
568 * @param cfg configuration to use
569 * @param addr_info_cb callback called when performance characteristics for
571 * @param addr_info_cb_cls closure for @a addr_info_cb
572 * @return ats performance context
574 struct GNUNET_ATS_PerformanceHandle *
575 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
576 GNUNET_ATS_AddressInformationCallback addr_info_cb,
577 void *addr_info_cb_cls);
582 * Get information about addresses known to the ATS subsystem.
584 * @param handle the performance handle to use
585 * @param peer peer idm can be NULL for all peers
586 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
587 * get only address currently used
588 * @param infocb callback to call with the addresses,
589 * will callback with address == NULL when done
590 * @param infocb_cls closure for @a infocb
591 * @return ats performance context
593 struct GNUNET_ATS_AddressListHandle *
594 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
595 const struct GNUNET_PeerIdentity *peer,
597 GNUNET_ATS_AddressInformationCallback infocb,
602 * Cancel a pending address listing operation
604 * @param handle the `struct GNUNET_ATS_AddressListHandle` handle to cancel
607 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
611 * Client is done using the ATS performance subsystem, release resources.
616 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
620 * Function called with reservation result.
623 * @param peer identifies the peer
624 * @param amount set to the amount that was actually reserved or unreserved;
625 * either the full requested amount or zero (no partial reservations)
626 * @param res_delay if the reservation could not be satisfied (amount was 0), how
627 * long should the client wait until re-trying?
630 (*GNUNET_ATS_ReservationCallback) (void *cls,
631 const struct GNUNET_PeerIdentity * peer,
633 struct GNUNET_TIME_Relative res_delay);
637 * Context that can be used to cancel a peer information request.
639 struct GNUNET_ATS_ReservationContext;
643 * Reserve inbound bandwidth from the given peer. ATS will look at
644 * the current amount of traffic we receive from the peer and ensure
645 * that the peer could add 'amount' of data to its stream.
647 * @param ph performance handle
648 * @param peer identifies the peer
649 * @param amount reserve N bytes for receiving, negative
650 * amounts can be used to undo a (recent) reservation;
651 * @param rcb function to call with the resulting reservation information
652 * @param rcb_cls closure for info
653 * @return NULL on error
654 * @deprecated will be replaced soon
656 struct GNUNET_ATS_ReservationContext *
657 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
658 const struct GNUNET_PeerIdentity *peer, int32_t amount,
659 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls);
663 * Cancel request for reserving bandwidth.
665 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
668 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
671 * Number of preference types supported by ATS
673 #define GNUNET_ATS_PreferenceCount 3
676 * ATS preference types as array initializer
678 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY}
681 * ATS preference types as string array initializer
683 #define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"}
686 * Enum defining all known preference categories.
688 enum GNUNET_ATS_PreferenceKind
692 * End of preference list.
694 GNUNET_ATS_PREFERENCE_END = 0,
697 * Change the peer's bandwidth value (value per byte of bandwidth in
698 * the goal function) to the given amount. The argument is followed
699 * by a double value giving the desired value (can be negative).
700 * Preference changes are forgotten if peers disconnect.
702 GNUNET_ATS_PREFERENCE_BANDWIDTH,
705 * Change the peer's latency value to the given amount. The
706 * argument is followed by a double value giving the desired value
707 * (can be negative). The absolute score in the goal function is
708 * the inverse of the latency in microseconds (minimum: 1
709 * microsecond) multiplied by the latency preferences.
711 GNUNET_ATS_PREFERENCE_LATENCY
715 * Convert a GNUNET_ATS_PreferenceType to a string
717 * @param type the preference type
718 * @return a string or NULL if invalid
721 GNUNET_ATS_print_preference_type (uint32_t type);
725 * Change preferences for the given peer. Preference changes are forgotten if peers
728 * @param ph performance handle
729 * @param peer identifies the peer
730 * @param ... 0-terminated specification of the desired changes
733 GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
734 const struct GNUNET_PeerIdentity *peer, ...);
738 * Application feedback on how good preference requirements are fulfilled
739 * for the preferences included in the given time scope [now - scope .. now]
741 * An application notifies ATS if (and only if) it has feedback information
742 * for specific properties. This values are valid until the feedback scores are
743 * updated by the application.
745 * If the application has no feedback for this preference kind the application
746 * will not explicitly call for this property and will not include it in this
749 * @param ph performance handle
750 * @param scope the time interval this valid for: [now - scope .. now]
751 * @param peer identifies the peer
752 * @param ... 0-terminated specification of the desired changes
755 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
756 const struct GNUNET_PeerIdentity *peer,
757 const struct GNUNET_TIME_Relative scope, ...);
760 /* end of file gnunet-service-transport_ats.h */