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,
60 * Number of property types supported by ATS
62 #define GNUNET_ATS_PropertyCount 9
65 * ATS properties types as string array initializer
67 #define GNUNET_ATS_PropertyStrings {"Terminator", "Utilization up", "Utilization down", "Network type", "Delay", "Distance", "Cost WAN", "Cost LAN", "Cost WLAN"}
70 * Enum defining all known property types for ATS Enum values are used
71 * in the GNUNET_ATS_Information struct as
74 * Cost are always stored in uint32_t, so all units used to define costs
75 * have to be normalized to fit in uint32_t [0 .. 4.294.967.295]
77 enum GNUNET_ATS_Property
84 GNUNET_ATS_ARRAY_TERMINATOR = 0,
87 * Actual traffic on this connection from the other peer to this peer.
89 * Unit: [bytes/second]
91 GNUNET_ATS_UTILIZATION_UP,
94 * Actual traffic on this connection from this peer to the other peer.
96 * Unit: [bytes/second]
98 GNUNET_ATS_UTILIZATION_DOWN,
101 * Is this address located in WAN, LAN or a loopback address
102 * Value is element of GNUNET_ATS_Network_Type
104 GNUNET_ATS_NETWORK_TYPE,
108 * Time between when the time packet is sent and the packet arrives
118 GNUNET_ATS_QUALITY_NET_DELAY,
121 * Distance on network layer (required for distance-vector routing).
125 GNUNET_ATS_QUALITY_NET_DISTANCE,
128 * Network overhead on WAN (Wide-Area Network)
130 * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
131 * of application data is transmitted?
132 * A factor used with connect cost, bandwidth cost and energy cost
133 * to describe the overhead produced by the transport protocol
137 * Interpretation: less is better
141 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
142 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
143 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
144 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
149 * Network overhead on LAN (Local-Area Network)
151 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
152 * of application data is transmitted?
153 * A factor used with connect cost, bandwidth cost and energy cost
154 * to describe the overhead produced by the transport protocol
158 * Interpretation: less is better
162 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
163 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
164 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
165 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
170 * Network overhead on WLAN (Wireless Local Area Network)
172 * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
173 * of application data is transmitted?
174 * A factor used with connect cost, bandwidth cost and energy cost
175 * to describe the overhead produced by the transport protocol
179 * Interpretation: less is better
183 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
184 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
185 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
186 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
189 /* Cost related values */
190 /* =================== */
192 * Volume based cost in financial units to transmit data
194 * Note: This value is not bound to a specific currency or unit and only
196 * "cent" just refers the smallest amount of money in the respective
201 * Interpretation: less is better
207 // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
209 * Time based cost in financial units to transmit data
211 * Note: This value is not bound to a specific currency or unit and only
213 * "cent" just refers the smallest amount of money in the respective
218 * Interpretation: less is better
222 * Dialup: 10 [cent/h]
224 // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
226 * Computational costs
228 * Effort of preparing data to be sent with this transport
229 * Includes encoding, encryption and conversion of data
230 * Partial values can be summed up: c_sum = c_enc + c_enc + c_conv
231 * Resulting values depend on local system properties, e.g. CPU
235 * Interpretation: less is better
239 * HTTPS with AES CBC-256: 7,382
240 * HTTPS with AES CBC-128: 5,279
241 * HTTPS with RC4-1024: 2,652
243 // GNUNET_ATS_COST_COMPUTATIONAL = 3,
247 * Energy consumption using this transport when sending with a certain
248 * power at a certain bitrate. This is only an approximation based on:
249 * Energy consumption E = P / D
252 * Power P in Watt (J/s)
253 * Datarate D in MBit/s
255 * Conversion between power P and dBm used by WLAN in radiotap's dBm TX power:
257 * Lp(dbm) = 10 log10 (P/ 1mW)
259 * => P = 1 mW * 10^(Lp(dbm)/10)
263 * Interpretation: less is better
268 * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s)
269 * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
271 // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
274 * How many bytes are transmitted to initiate a new connection using
279 * Interpretation: less is better
283 * UDP (No connection) :
285 * TCP (TCP 3-Way handshake):
286 * 220 bytes Ethernet, 172 bytes TCP/IP, 122 bytes TCP
287 * HTTP (TCP + Header) :
288 * 477 bytes Ethernet, 429 bytes TCP/IP, 374 bytes TCP, 278 bytes HTTP
289 * HTTPS HTTP+TLS Handshake:
290 * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
293 // GNUNET_ATS_COST_CONNECT = 5,
297 * How many bandwidth is available to consume?
298 * Used to calculate which impact sending data with this transport has
302 * Interpretation: more is better
305 * LAN: 12,800 (100 MBit/s)
306 * WLAN: 6,912 (54 MBit/s)
307 * Dial-up: 8 (64 Kbit/s)
310 // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
314 * How many bytes are sent over the wire when 1 kilobyte (1024 bytes)
315 * of application data is transmitted?
316 * A factor used with connect cost, bandwidth cost and energy cost
317 * to describe the overhead produced by the transport protocol
321 * Interpretation: less is better
325 * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
326 * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
327 * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb]
328 * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb]
330 // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
331 /* Quality related values */
332 /* ====================== */
333 /* Physical layer quality properties */
335 * Signal strength on physical layer
339 // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
341 * Collision rate on physical layer
345 // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
347 * Error rate on physical layer
351 // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
354 * Time variations of the delay
355 * 1st derivative of a delay function
359 // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
361 * Error rate on network layer
370 * Note: This numbers are just assumptions as an example, not
371 * measured or somehow determined
373 // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
375 * Drop rate on network layer
376 * Bytes actively dismissed by a network component during transmission
377 * Reasons for dropped data can be full queues, congestion, quota violations...
386 * Note: This numbers are just assumptions as an example, not
387 * measured or somehow determined
389 // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
391 * Loss rate on network layer
392 * Bytes lost during transmission
393 * Reasons can be collisions, ...
402 * Note: This numbers are just assumptions as an example, not measured
403 * or somehow determined
405 // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
407 * Throughput on network layer
418 // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
419 /* Availability related values */
420 /* =========================== */
422 * Is a peer reachable?
424 // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
426 * Is there a connection established to a peer using this transport
428 // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
432 * Number of ATS quality properties
434 #define GNUNET_ATS_QualityPropertiesCount 2
437 * ATS quality properties as array initializer
439 #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE}
442 * ATS quality properties as string array initializer
444 #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"}
447 GNUNET_NETWORK_STRUCT_BEGIN
450 * struct used to communicate the transport's properties like cost and
451 * quality of service as well as high-level constraints on resource
455 * +-----------+ Constraints | | Plugin properties +---------+
456 * | Highlevel |------------> |ATS| <------------------|Transport|
457 * | Component | ATS struct | | ATS struct | Plugin |
458 * +-----------+ | | +---------+
461 * This structure will be used by transport plugins to communicate
462 * costs to ATS or by higher level components to tell ATS their
463 * constraints. Always a pair of (GNUNET_ATS_Property,
464 * uint32_t value). Value is always uint32_t, so all units used to
465 * define costs have to be normalized to fit uint32_t.
467 struct GNUNET_ATS_Information
470 * ATS property type, in network byte order.
472 uint32_t type GNUNET_PACKED;
475 * ATS property value, in network byte order.
477 uint32_t value GNUNET_PACKED;
479 GNUNET_NETWORK_STRUCT_END
482 /* ******************************** Scheduling API ***************************** */
485 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
487 struct GNUNET_ATS_SchedulingHandle;
491 * Opaque session handle, defined by plugins. Contents not known to ATS.
497 * Signature of a function called by ATS with the current bandwidth
498 * and address preferences as determined by ATS.
501 * @param address suggested address (including peer identity of the peer)
502 * @param session session to use
503 * @param bandwidth_out assigned outbound bandwidth for the connection
504 * @param bandwidth_in assigned inbound bandwidth for the connection
505 * @param ats performance data for the address (as far as known)
506 * @param ats_count number of performance records in 'ats'
508 typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
510 GNUNET_HELLO_Address *
512 struct Session * session,
514 GNUNET_BANDWIDTH_Value32NBO
517 GNUNET_BANDWIDTH_Value32NBO
520 GNUNET_ATS_Information *
521 ats, uint32_t ats_count);
525 * Initialize the ATS subsystem.
527 * @param cfg configuration to use
528 * @param suggest_cb notification to call whenever the suggestation changed
529 * @param suggest_cb_cls closure for 'suggest_cb'
530 * @return ats context
532 struct GNUNET_ATS_SchedulingHandle *
533 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
534 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
535 void *suggest_cb_cls);
539 * Client is done with ATS scheduling, release resources.
541 * @param sh handle to release
544 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
548 * We would like to reset the address suggestion block time for this
552 * @param peer identity of the peer we want to reset
555 GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
556 const struct GNUNET_PeerIdentity *peer);
559 * We would like to establish a new connection with a peer. ATS
560 * should suggest a good address to begin with.
563 * @param peer identity of the peer we need an address for
566 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
567 const struct GNUNET_PeerIdentity *peer);
571 * We want to cancel ATS suggesting addresses for a peer.
574 * @param peer identity of the peer
577 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
578 const struct GNUNET_PeerIdentity *peer);
582 * Returns where the address is located: LAN or WAN or ...
583 * @param sh the GNUNET_ATS_SchedulingHandle handle
584 * @param addr address
585 * @param addrlen address length
586 * @return location as GNUNET_ATS_Information
588 struct GNUNET_ATS_Information
589 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
590 const struct sockaddr * addr,
594 * We have a new address ATS should know. Addresses have to be added with this
595 * function before they can be: updated, set in use and destroyed
598 * @param address the address
599 * @param session session handle (if available)
600 * @param ats performance data for the address
601 * @param ats_count number of performance records in 'ats'
604 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
605 const struct GNUNET_HELLO_Address *address,
606 struct Session *session,
607 const struct GNUNET_ATS_Information *ats,
612 * We have updated performance statistics for a given address. Note
613 * that this function can be called for addresses that are currently
614 * in use as well as addresses that are valid but not actively in use.
615 * Furthermore, the peer may not even be connected to us right now (in
616 * which case the call may be ignored or the information may be stored
617 * for later use). Update bandwidth assignments.
620 * @param address updated address
621 * @param session session handle (if available)
622 * @param ats performance data for the address
623 * @param ats_count number of performance records in 'ats'
626 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
627 const struct GNUNET_HELLO_Address *address,
628 struct Session *session,
629 const struct GNUNET_ATS_Information *ats,
634 * An address is now in use or not used any more.
637 * @param address the address
638 * @param session session handle
639 * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
640 * if address is not used any more
643 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
644 const struct GNUNET_HELLO_Address *address,
645 struct Session *session, int in_use);
649 * A session got destroyed, stop including it as a valid address.
652 * @param address the address
653 * @param session session handle that is no longer valid (if available)
656 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
657 const struct GNUNET_HELLO_Address *address,
658 struct Session *session);
661 /* ******************************** Performance API ***************************** */
664 * ATS Handle to obtain and/or modify performance information.
666 struct GNUNET_ATS_PerformanceHandle;
670 * Signature of a function that is called with QoS information about a peer.
673 * @param address the address
674 * @param bandwidth_out assigned outbound bandwidth for the connection
675 * @param bandwidth_in assigned inbound bandwidth for the connection
676 * @param ats performance data for the address (as far as known)
677 * @param ats_count number of performance records in 'ats'
679 typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
681 GNUNET_HELLO_Address *
684 GNUNET_BANDWIDTH_Value32NBO
687 GNUNET_BANDWIDTH_Value32NBO
690 GNUNET_ATS_Information *
691 ats, uint32_t ats_count);
694 * Handle for an address listing operation
696 struct GNUNET_ATS_AddressListHandle;
700 * Get handle to access performance API of the ATS subsystem.
702 * @param cfg configuration to use
703 * @param infocb function to call on performance changes, can be NULL
704 * @param infocb_cls closure for infocb
705 * @return ats performance context
707 struct GNUNET_ATS_PerformanceHandle *
708 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
709 GNUNET_ATS_PeerInformationCallback infocb,
714 * Get information about addresses known to the ATS subsystem.
716 * @param handle the performance handle to use
717 * @param peer peer idm can be NULL for all peers
718 * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
719 * get only address currently used
720 * @param infocb callback to call with the addresses,
721 * will callback with address == NULL when done
722 * @param infocb_cls closure for infocb
723 * @return ats performance context
725 struct GNUNET_ATS_AddressListHandle *
726 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
727 const struct GNUNET_PeerIdentity *peer,
729 GNUNET_ATS_PeerInformationCallback infocb,
734 * Cancel a pending address listing operation
736 * @param handle the GNUNET_ATS_AddressListHandle handle to cancel
739 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
743 * Client is done using the ATS performance subsystem, release resources.
748 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
752 * Function called with reservation result.
755 * @param peer identifies the peer
756 * @param amount set to the amount that was actually reserved or unreserved;
757 * either the full requested amount or zero (no partial reservations)
758 * @param res_delay if the reservation could not be satisfied (amount was 0), how
759 * long should the client wait until re-trying?
761 typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
762 const struct GNUNET_PeerIdentity
763 * peer, int32_t amount,
764 struct GNUNET_TIME_Relative
770 * Context that can be used to cancel a peer information request.
772 struct GNUNET_ATS_ReservationContext;
776 * Reserve inbound bandwidth from the given peer. ATS will look at
777 * the current amount of traffic we receive from the peer and ensure
778 * that the peer could add 'amount' of data to its stream.
780 * @param ph performance handle
781 * @param peer identifies the peer
782 * @param amount reserve N bytes for receiving, negative
783 * amounts can be used to undo a (recent) reservation;
784 * @param rcb function to call with the resulting reservation information
785 * @param rcb_cls closure for info
786 * @return NULL on error
787 * @deprecated will be replaced soon
789 struct GNUNET_ATS_ReservationContext *
790 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
791 const struct GNUNET_PeerIdentity *peer,
793 GNUNET_ATS_ReservationCallback rcb,
798 * Cancel request for reserving bandwidth.
800 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
803 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
808 * Enum defining all known preference categories.
810 enum GNUNET_ATS_PreferenceKind
814 * End of preference list.
816 GNUNET_ATS_PREFERENCE_END = 0,
819 * Change the peer's bandwidth value (value per byte of bandwidth in
820 * the goal function) to the given amount. The argument is followed
821 * by a double value giving the desired value (can be negative).
822 * Preference changes are forgotten if peers disconnect.
824 GNUNET_ATS_PREFERENCE_BANDWIDTH,
827 * Change the peer's latency value to the given amount. The
828 * argument is followed by a double value giving the desired value
829 * (can be negative). The absolute score in the goal function is
830 * the inverse of the latency in ms (minimum: 1 ms) multiplied by
831 * the latency preferences.
833 GNUNET_ATS_PREFERENCE_LATENCY
838 * Change preferences for the given peer. Preference changes are forgotten if peers
841 * @param ph performance handle
842 * @param peer identifies the peer
843 * @param ... 0-terminated specification of the desired changes
846 GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
847 const struct GNUNET_PeerIdentity *peer, ...);
852 /* end of file gnunet-service-transport_ats.h */