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 * @param cont the continuation to indicate success to call with the address
390 * @param cont_cls the closure for the @a cont
391 * @return suggestion handle
393 struct GNUNET_ATS_SuggestHandle *
394 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
395 const struct GNUNET_PeerIdentity *peer,
396 GNUNET_ATS_AddressSuggestionCallback cont,
401 * We want to cancel ATS suggesting addresses for a peer.
404 * @param peer identity of the peer
407 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
408 const struct GNUNET_PeerIdentity *peer);
412 * Convert a ATS property to a string
414 * @param type the property type
415 * @return a string or NULL if invalid
418 GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type);
422 * Convert a `enum GNUNET_ATS_Network_Type` to a string
424 * @param net the network type
425 * @return a string or NULL if invalid
428 GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
432 * Returns where the address is located: LAN or WAN or ...
434 * @param sh the `struct GNUNET_ATS_SchedulingHandle` handle
435 * @param addr address
436 * @param addrlen address length
437 * @return location as `struct GNUNET_ATS_Information`
439 struct GNUNET_ATS_Information
440 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
441 const struct sockaddr *addr,
446 * Test if a address and a session is known to ATS.
448 * @param sh the scheduling handle
449 * @param address the address
450 * @param session the session
451 * @return #GNUNET_YES or #GNUNET_NO
454 GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh,
455 const struct GNUNET_HELLO_Address *address,
456 struct Session *session);
460 * We have a new address ATS should know. Addresses have to be added with this
461 * function before they can be: updated, set in use and destroyed
464 * @param address the address
465 * @param session session handle (if available)
466 * @param ats performance data for the address
467 * @param ats_count number of performance records in @a ats
470 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
471 const struct GNUNET_HELLO_Address *address,
472 struct Session *session,
473 const struct GNUNET_ATS_Information *ats,
478 * We have updated performance statistics for a given address. Note
479 * that this function can be called for addresses that are currently
480 * in use as well as addresses that are valid but not actively in use.
481 * Furthermore, the peer may not even be connected to us right now (in
482 * which case the call may be ignored or the information may be stored
483 * for later use). Update bandwidth assignments.
486 * @param address updated address
487 * @param session session handle (if available)
488 * @param ats performance data for the address
489 * @param ats_count number of performance records in @a ats
490 * @return #GNUNET_OK or #GNUNET_SYSERR
493 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
494 const struct GNUNET_HELLO_Address *address,
495 struct Session *session,
496 const struct GNUNET_ATS_Information *ats,
501 * An address is now in use or not used any more.
504 * @param address the address
505 * @param session session handle
506 * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO
507 * if address is not used any more
510 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
511 const struct GNUNET_HELLO_Address *address,
512 struct Session *session,
517 * An address got destroyed, stop including it as a valid address.
519 * If a session is given, only the session will be removed, if no session is
520 * given the full address will be deleted.
523 * @param address the address
524 * @param session session handle that is no longer valid (if available)
527 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
528 const struct GNUNET_HELLO_Address *address,
529 struct Session *session);
532 /* ******************************** Performance API ***************************** */
535 * ATS Handle to obtain and/or modify performance information.
537 struct GNUNET_ATS_PerformanceHandle;
540 * Signature of a function that is called with QoS information about an address.
543 * @param address the address, NULL if ATS service was disconnected
544 * @param address_active #GNUNET_YES if this address is actively used
545 * to maintain a connection to a peer;
546 * #GNUNET_NO if the address is not actively used;
547 * #GNUNET_SYSERR if this address is no longer available for ATS
548 * @param bandwidth_out assigned outbound bandwidth for the connection
549 * @param bandwidth_in assigned inbound bandwidth for the connection
550 * @param ats performance data for the address (as far as known)
551 * @param ats_count number of performance records in @a ats
554 (*GNUNET_ATS_AddressInformationCallback) (void *cls,
555 const struct GNUNET_HELLO_Address *address,
557 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
558 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
559 const struct GNUNET_ATS_Information *ats,
564 * Handle for an address listing operation
566 struct GNUNET_ATS_AddressListHandle;
570 * Get handle to access performance API of the ATS subsystem.
572 * @param cfg configuration to use
573 * @param addr_info_cb callback called when performance characteristics for
575 * @param addr_info_cb_cls closure for @a addr_info_cb
576 * @return ats performance context
578 struct GNUNET_ATS_PerformanceHandle *
579 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
580 GNUNET_ATS_AddressInformationCallback addr_info_cb,
581 void *addr_info_cb_cls);
586 * Get information about addresses known to the ATS subsystem.
588 * @param handle the performance handle to use
589 * @param peer peer idm can be NULL for all peers
590 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
591 * get only address currently used
592 * @param infocb callback to call with the addresses,
593 * will callback with address == NULL when done
594 * @param infocb_cls closure for @a infocb
595 * @return ats performance context
597 struct GNUNET_ATS_AddressListHandle *
598 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
599 const struct GNUNET_PeerIdentity *peer,
601 GNUNET_ATS_AddressInformationCallback infocb,
606 * Cancel a pending address listing operation
608 * @param handle the `struct GNUNET_ATS_AddressListHandle` handle to cancel
611 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
615 * Client is done using the ATS performance subsystem, release resources.
620 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
624 * Function called with reservation result.
627 * @param peer identifies the peer
628 * @param amount set to the amount that was actually reserved or unreserved;
629 * either the full requested amount or zero (no partial reservations)
630 * @param res_delay if the reservation could not be satisfied (amount was 0), how
631 * long should the client wait until re-trying?
634 (*GNUNET_ATS_ReservationCallback) (void *cls,
635 const struct GNUNET_PeerIdentity * peer,
637 struct GNUNET_TIME_Relative res_delay);
641 * Context that can be used to cancel a peer information request.
643 struct GNUNET_ATS_ReservationContext;
647 * Reserve inbound bandwidth from the given peer. ATS will look at
648 * the current amount of traffic we receive from the peer and ensure
649 * that the peer could add 'amount' of data to its stream.
651 * @param ph performance handle
652 * @param peer identifies the peer
653 * @param amount reserve N bytes for receiving, negative
654 * amounts can be used to undo a (recent) reservation;
655 * @param rcb function to call with the resulting reservation information
656 * @param rcb_cls closure for info
657 * @return NULL on error
658 * @deprecated will be replaced soon
660 struct GNUNET_ATS_ReservationContext *
661 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
662 const struct GNUNET_PeerIdentity *peer, int32_t amount,
663 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls);
667 * Cancel request for reserving bandwidth.
669 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
672 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
675 * Number of preference types supported by ATS
677 #define GNUNET_ATS_PreferenceCount 3
680 * ATS preference types as array initializer
682 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY}
685 * ATS preference types as string array initializer
687 #define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"}
690 * Enum defining all known preference categories.
692 enum GNUNET_ATS_PreferenceKind
696 * End of preference list.
698 GNUNET_ATS_PREFERENCE_END = 0,
701 * Change the peer's bandwidth value (value per byte of bandwidth in
702 * the goal function) to the given amount. The argument is followed
703 * by a double value giving the desired value (can be negative).
704 * Preference changes are forgotten if peers disconnect.
706 GNUNET_ATS_PREFERENCE_BANDWIDTH,
709 * Change the peer's latency value to the given amount. The
710 * argument is followed by a double value giving the desired value
711 * (can be negative). The absolute score in the goal function is
712 * the inverse of the latency in microseconds (minimum: 1
713 * microsecond) multiplied by the latency preferences.
715 GNUNET_ATS_PREFERENCE_LATENCY
719 * Convert a GNUNET_ATS_PreferenceType to a string
721 * @param type the preference type
722 * @return a string or NULL if invalid
725 GNUNET_ATS_print_preference_type (uint32_t type);
729 * Change preferences for the given peer. Preference changes are forgotten if peers
732 * @param ph performance handle
733 * @param peer identifies the peer
734 * @param ... 0-terminated specification of the desired changes
737 GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
738 const struct GNUNET_PeerIdentity *peer, ...);
742 * Application feedback on how good preference requirements are fulfilled
743 * for the preferences included in the given time scope [now - scope .. now]
745 * An application notifies ATS if (and only if) it has feedback information
746 * for specific properties. This values are valid until the feedback scores are
747 * updated by the application.
749 * If the application has no feedback for this preference kind the application
750 * will not explicitly call for this property and will not include it in this
753 * @param ph performance handle
754 * @param scope the time interval this valid for: [now - scope .. now]
755 * @param peer identifies the peer
756 * @param ... 0-terminated specification of the desired changes
759 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
760 const struct GNUNET_PeerIdentity *peer,
761 const struct GNUNET_TIME_Relative scope, ...);
764 /* end of file gnunet-service-transport_ats.h */