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
40 * Types of networks (with separate quotas) we support.
42 enum GNUNET_ATS_Network_Type
45 * Category of last resort.
47 GNUNET_ATS_NET_UNSPECIFIED = 0,
50 * Loopback (same host).
52 GNUNET_ATS_NET_LOOPBACK = 1,
57 GNUNET_ATS_NET_LAN = 2,
60 * Wide area network (i.e. Internet)
62 GNUNET_ATS_NET_WAN = 3,
65 * Wireless LAN (i.e. 802.11abgn)
67 GNUNET_ATS_NET_WLAN = 4,
77 * ATS network types as array initializer
79 #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 }
84 * Default bandwidth assigned to a network : 64 KB/s
86 #define GNUNET_ATS_DefaultBandwidth 65536
89 * Undefined value for an `enum GNUNET_ATS_Property`
91 #define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
94 * String representation for GNUNET_ATS_VALUE_UNDEFINED
96 #define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
99 * Maximum bandwidth assigned to a network : 4095 MB/s
101 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
104 * Textual equivalent for GNUNET_ATS_MaxBandwidth
106 #define GNUNET_ATS_MaxBandwidthString "unlimited"
109 * Number of property types supported by ATS
111 #define GNUNET_ATS_PropertyCount 11
115 * Enum defining all known property types for ATS Enum values are used
116 * in the GNUNET_ATS_Information struct as
119 * Cost are always stored in uint32_t, so all units used to define costs
120 * have to be normalized to fit in uint32_t [0 .. UINT32_MAX-1]
122 * UINT32_MAX is reserved for uninitialized values #GNUNET_ATS_VALUE_UNDEFINED
124 enum GNUNET_ATS_Property
131 GNUNET_ATS_ARRAY_TERMINATOR = 0,
134 * Actual traffic on this connection from this peer to the other peer.
135 * Includes transport overhead
137 * Unit: [bytes/second]
139 GNUNET_ATS_UTILIZATION_OUT,
142 * Actual traffic on this connection from the other peer to this peer.
143 * Includes transport overhead
145 * Unit: [bytes/second]
147 GNUNET_ATS_UTILIZATION_IN,
150 * Actual traffic on this connection from this peer to the other peer.
151 * Only payload from layers > transport
153 * Unit: [bytes/second]
155 GNUNET_ATS_UTILIZATION_PAYLOAD_OUT,
158 * Actual traffic on this connection from the other peer to this peer.
159 * Only payload from layers > transport
161 * Unit: [bytes/second]
163 GNUNET_ATS_UTILIZATION_PAYLOAD_IN,
166 * Is this address located in WAN, LAN or a loopback address
167 * Value is element of GNUNET_ATS_Network_Type
169 GNUNET_ATS_NETWORK_TYPE,
173 * Time between when the time packet is sent and the packet arrives
175 * Unit: [microseconds]
183 GNUNET_ATS_QUALITY_NET_DELAY,
186 * Distance on network layer (required for distance-vector routing).
190 GNUNET_ATS_QUALITY_NET_DISTANCE,
193 * Network overhead on WAN (Wide-Area Network)
195 * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
196 * of application data is transmitted?
197 * A factor used with connect cost, bandwidth cost and energy cost
198 * to describe the overhead produced by the transport protocol
202 * Interpretation: less is better
206 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
207 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
208 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
209 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
214 * Network overhead on LAN (Local-Area Network)
216 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
217 * of application data is transmitted?
218 * A factor used with connect cost, bandwidth cost and energy cost
219 * to describe the overhead produced by the transport protocol
223 * Interpretation: less is better
227 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
228 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
229 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
230 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
235 * Network overhead on WLAN (Wireless Local Area Network)
237 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
238 * of application data is transmitted?
239 * A factor used with connect cost, bandwidth cost and energy cost
240 * to describe the overhead produced by the transport protocol
244 * Interpretation: less is better
248 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
249 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
250 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
251 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
259 * Number of ATS quality properties
261 #define GNUNET_ATS_QualityPropertiesCount 2
264 * ATS quality properties as array initializer
266 #define GNUNET_ATS_QualityProperties { GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE }
269 * ATS quality properties as string array initializer
271 #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"}
273 GNUNET_NETWORK_STRUCT_BEGIN
276 * struct used to communicate the transport's properties like cost and
277 * quality of service as well as high-level constraints on resource
281 * +-----------+ Constraints | | Plugin properties +---------+
282 * | Highlevel |------------> |ATS| <------------------|Transport|
283 * | Component | ATS struct | | ATS struct | Plugin |
284 * +-----------+ | | +---------+
287 * This structure will be used by transport plugins to communicate
288 * costs to ATS or by higher level components to tell ATS their
289 * constraints. Always a pair of (GNUNET_ATS_Property,
290 * uint32_t value). Value is always uint32_t, so all units used to
291 * define costs have to be normalized to fit uint32_t.
293 struct GNUNET_ATS_Information
296 * ATS property type, in network byte order.
298 uint32_t type GNUNET_PACKED;
301 * ATS property value, in network byte order.
303 uint32_t value GNUNET_PACKED;
305 GNUNET_NETWORK_STRUCT_END
308 /* ********************* LAN Characterization library ************************ */
309 /* Note: these functions do not really communicate with the ATS service */
312 * Convert a ATS property to a string
314 * @param type the property type
315 * @return a string or NULL if invalid
318 GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type);
322 * Convert a `enum GNUNET_ATS_Network_Type` to a string
324 * @param net the network type
325 * @return a string or NULL if invalid
328 GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
332 * Handle for the LAN Characterization library.
334 struct GNUNET_ATS_InterfaceScanner;
338 * Returns where the address is located: loopback, LAN or WAN.
340 * @param is handle from #GNUNET_ATS_interface_scanner_init()
341 * @param addr address
342 * @param addrlen address length
343 * @return type of the network the address belongs to
345 enum GNUNET_ATS_Network_Type
346 GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is,
347 const struct sockaddr *addr,
352 * Initialize the ATS address characterization client handle.
354 * @return scanner handle, NULL on error
356 struct GNUNET_ATS_InterfaceScanner *
357 GNUNET_ATS_scanner_init (void);
361 * Terminate interface scanner.
363 * @param is scanner we are done with
366 GNUNET_ATS_scanner_done (struct GNUNET_ATS_InterfaceScanner *is);
370 /* ********************Connection Suggestion API ***************************** */
373 * Handle to the ATS subsystem for making suggestions about
374 * connections the peer would like to have.
376 struct GNUNET_ATS_ConnectivityHandle;
379 * Handle for address suggestion requests.
381 struct GNUNET_ATS_ConnectivitySuggestHandle;
385 * Initialize the ATS connectivity suggestion client handle.
387 * @param cfg configuration to use
388 * @return ats connectivity handle, NULL on error
390 struct GNUNET_ATS_ConnectivityHandle *
391 GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
395 * Shutdown ATS connectivity suggestion client.
397 * @param ch handle to destroy
400 GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
404 * We would like to establish a new connection with a peer. ATS
405 * should suggest a good address to begin with.
408 * @param peer identity of the peer we need an address for
409 * @return suggestion handle, NULL if request is already pending
411 struct GNUNET_ATS_ConnectivitySuggestHandle *
412 GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
413 const struct GNUNET_PeerIdentity *peer);
417 * We no longer care about being connected to a peer.
422 GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh);
425 /* ******************************** Scheduling API ***************************** */
428 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
430 struct GNUNET_ATS_SchedulingHandle;
433 * Opaque session handle, defined by plugins. Contents not known to ATS.
438 * Signature of a function called by ATS with the current bandwidth
439 * and address preferences as determined by ATS.
442 * @param peer for which we suggest an address, NULL if ATS connection died
443 * @param address suggested address (including peer identity of the peer),
444 * may be NULL to signal disconnect from peer
445 * @param session session to use, NULL to establish a new outgoing session
446 * @param bandwidth_out assigned outbound bandwidth for the connection,
447 * 0 to signal disconnect
448 * @param bandwidth_in assigned inbound bandwidth for the connection,
449 * 0 to signal disconnect
452 (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
453 const struct GNUNET_PeerIdentity *peer,
454 const struct GNUNET_HELLO_Address *address,
455 struct Session *session,
456 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
457 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
461 * Initialize the ATS scheduling subsystem.
463 * @param cfg configuration to use
464 * @param suggest_cb notification to call whenever the suggestation changed
465 * @param suggest_cb_cls closure for @a suggest_cb
466 * @return ats context
468 struct GNUNET_ATS_SchedulingHandle *
469 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
470 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
471 void *suggest_cb_cls);
475 * Client is done with ATS scheduling, release resources.
477 * @param sh handle to release
480 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
484 * Test if a address and a session is known to ATS.
486 * @param sh the scheduling handle
487 * @param address the address
488 * @param session the session
489 * @return #GNUNET_YES or #GNUNET_NO
492 GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh,
493 const struct GNUNET_HELLO_Address *address,
494 struct Session *session);
498 * Handle used within ATS to track an address.
500 struct GNUNET_ATS_AddressRecord;
504 * We have a new address ATS should know. Addresses have to be added with this
505 * function before they can be: updated, set in use and destroyed
508 * @param address the address
509 * @param session session handle (if available, i.e. for incoming connections)
510 * @param ats performance data for the address
511 * @param ats_count number of performance records in @a ats
512 * @return handle to the address representation inside ATS, NULL
513 * on error (i.e. ATS knows this exact address already, or
514 * address is invalid)
516 struct GNUNET_ATS_AddressRecord *
517 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
518 const struct GNUNET_HELLO_Address *address,
519 struct Session *session,
520 const struct GNUNET_ATS_Information *ats,
525 * An address was used to initiate a session.
527 * @param ar address record to update information for
528 * @param session session handle
531 GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
532 struct Session *session);
536 * A session was destroyed, disassociate it from the
537 * given address record. If this was an incoming
538 * addess, destroy the address as well.
540 * @param ar address record to update information for
541 * @param session session handle
542 * @return #GNUNET_YES if the @a ar was destroyed because
543 * it was an incoming address,
544 * #GNUNET_NO if the @ar was kept because we can
545 * use it still to establish a new session
548 GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
549 struct Session *session);
553 * We have updated performance statistics for a given address. Note
554 * that this function can be called for addresses that are currently
555 * in use as well as addresses that are valid but not actively in use.
556 * Furthermore, the peer may not even be connected to us right now (@a
557 * session value of NULL used to signal disconnect, or somehow we
558 * otherwise got updated on @a ats information). Based on the
559 * information provided, ATS may update bandwidth assignments and
560 * suggest to switch addresses.
562 * @param ar address record to update information for
563 * @param ats performance data for the address
564 * @param ats_count number of performance records in @a ats
567 GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
568 const struct GNUNET_ATS_Information *ats,
573 * An address got destroyed, stop using it as a valid address.
575 * @param ar address record to destroy, it's validation has
576 * expired and ATS may no longer use it
579 GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
583 /* ******************************** Performance API ***************************** */
586 * ATS Handle to obtain and/or modify performance information.
588 struct GNUNET_ATS_PerformanceHandle;
591 * Signature of a function that is called with QoS information about an address.
594 * @param address the address, NULL if ATS service was disconnected
595 * @param address_active #GNUNET_YES if this address is actively used
596 * to maintain a connection to a peer;
597 * #GNUNET_NO if the address is not actively used;
598 * #GNUNET_SYSERR if this address is no longer available for ATS
599 * @param bandwidth_out assigned outbound bandwidth for the connection
600 * @param bandwidth_in assigned inbound bandwidth for the connection
601 * @param ats performance data for the address (as far as known)
602 * @param ats_count number of performance records in @a ats
605 (*GNUNET_ATS_AddressInformationCallback) (void *cls,
606 const struct GNUNET_HELLO_Address *address,
608 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
609 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
610 const struct GNUNET_ATS_Information *ats,
615 * Handle for an address listing operation
617 struct GNUNET_ATS_AddressListHandle;
621 * Get handle to access performance API of the ATS subsystem.
623 * @param cfg configuration to use
624 * @param addr_info_cb callback called when performance characteristics for
626 * @param addr_info_cb_cls closure for @a addr_info_cb
627 * @return ats performance context
629 struct GNUNET_ATS_PerformanceHandle *
630 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
631 GNUNET_ATS_AddressInformationCallback addr_info_cb,
632 void *addr_info_cb_cls);
637 * Get information about addresses known to the ATS subsystem.
639 * @param handle the performance handle to use
640 * @param peer peer idm can be NULL for all peers
641 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
642 * get only address currently used
643 * @param infocb callback to call with the addresses,
644 * will callback with address == NULL when done
645 * @param infocb_cls closure for @a infocb
646 * @return ats performance context
648 struct GNUNET_ATS_AddressListHandle *
649 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
650 const struct GNUNET_PeerIdentity *peer,
652 GNUNET_ATS_AddressInformationCallback infocb,
657 * Cancel a pending address listing operation
659 * @param handle the `struct GNUNET_ATS_AddressListHandle` handle to cancel
662 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
666 * Client is done using the ATS performance subsystem, release resources.
671 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
675 * Function called with reservation result.
678 * @param peer identifies the peer
679 * @param amount set to the amount that was actually reserved or unreserved;
680 * either the full requested amount or zero (no partial reservations)
681 * @param res_delay if the reservation could not be satisfied (amount was 0), how
682 * long should the client wait until re-trying?
685 (*GNUNET_ATS_ReservationCallback) (void *cls,
686 const struct GNUNET_PeerIdentity * peer,
688 struct GNUNET_TIME_Relative res_delay);
692 * Context that can be used to cancel a peer information request.
694 struct GNUNET_ATS_ReservationContext;
698 * Reserve inbound bandwidth from the given peer. ATS will look at
699 * the current amount of traffic we receive from the peer and ensure
700 * that the peer could add 'amount' of data to its stream.
702 * @param ph performance handle
703 * @param peer identifies the peer
704 * @param amount reserve N bytes for receiving, negative
705 * amounts can be used to undo a (recent) reservation;
706 * @param rcb function to call with the resulting reservation information
707 * @param rcb_cls closure for @a rcb
708 * @return NULL on error
709 * @deprecated will be replaced soon
711 struct GNUNET_ATS_ReservationContext *
712 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
713 const struct GNUNET_PeerIdentity *peer,
715 GNUNET_ATS_ReservationCallback rcb,
720 * Cancel request for reserving bandwidth.
722 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
725 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
728 * Number of preference types supported by ATS
730 #define GNUNET_ATS_PreferenceCount 3
733 * ATS preference types as array initializer
735 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY}
738 * ATS preference types as string array initializer
740 #define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"}
743 * Enum defining all known preference categories.
745 enum GNUNET_ATS_PreferenceKind
749 * End of preference list.
751 GNUNET_ATS_PREFERENCE_END = 0,
754 * Change the peer's bandwidth value (value per byte of bandwidth in
755 * the goal function) to the given amount. The argument is followed
756 * by a double value giving the desired value (can be negative).
757 * Preference changes are forgotten if peers disconnect.
759 GNUNET_ATS_PREFERENCE_BANDWIDTH,
762 * Change the peer's latency value to the given amount. The
763 * argument is followed by a double value giving the desired value
764 * (can be negative). The absolute score in the goal function is
765 * the inverse of the latency in microseconds (minimum: 1
766 * microsecond) multiplied by the latency preferences.
768 GNUNET_ATS_PREFERENCE_LATENCY
772 * Convert a GNUNET_ATS_PreferenceType to a string
774 * @param type the preference type
775 * @return a string or NULL if invalid
778 GNUNET_ATS_print_preference_type (uint32_t type);
782 * Change preferences for the given peer. Preference changes are forgotten if peers
785 * @param ph performance handle
786 * @param peer identifies the peer
787 * @param ... 0-terminated specification of the desired changes
790 GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
791 const struct GNUNET_PeerIdentity *peer,
796 * Application feedback on how good preference requirements are fulfilled
797 * for the preferences included in the given time scope [now - scope .. now]
799 * An application notifies ATS if (and only if) it has feedback information
800 * for specific properties. This values are valid until the feedback scores are
801 * updated by the application.
803 * If the application has no feedback for this preference kind the application
804 * will not explicitly call for this property and will not include it in this
807 * @param ph performance handle
808 * @param scope the time interval this valid for: [now - scope .. now]
809 * @param peer identifies the peer
810 * @param ... 0-terminated specification of the desired changes
813 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
814 const struct GNUNET_PeerIdentity *peer,
815 const struct GNUNET_TIME_Relative scope,
819 /* end of file gnunet-service-transport_ats.h */