1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * Copyright (c) 2022 Nordic Semiconductor ASA 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 /** 9 * @file zperf.h 10 * 11 * @brief Zperf API 12 * @defgroup zperf Zperf API 13 * @ingroup networking 14 * @{ 15 */ 16 17 #ifndef ZEPHYR_INCLUDE_NET_ZPERF_H_ 18 #define ZEPHYR_INCLUDE_NET_ZPERF_H_ 19 20 #include <zephyr/net/net_ip.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 enum zperf_status { 27 ZPERF_SESSION_STARTED, 28 ZPERF_SESSION_FINISHED, 29 ZPERF_SESSION_ERROR 30 } __packed; 31 32 struct zperf_upload_params { 33 struct sockaddr peer_addr; 34 uint32_t duration_ms; 35 uint32_t rate_kbps; 36 uint16_t packet_size; 37 struct { 38 uint8_t tos; 39 int tcp_nodelay; 40 int priority; 41 } options; 42 }; 43 44 struct zperf_download_params { 45 uint16_t port; 46 struct sockaddr addr; 47 }; 48 49 struct zperf_results { 50 uint32_t nb_packets_sent; 51 uint32_t nb_packets_rcvd; 52 uint32_t nb_packets_lost; 53 uint32_t nb_packets_outorder; 54 uint32_t total_len; 55 uint32_t time_in_us; 56 uint32_t jitter_in_us; 57 uint32_t client_time_in_us; 58 uint32_t packet_size; 59 uint32_t nb_packets_errors; 60 }; 61 62 /** 63 * @brief Zperf callback function used for asynchronous operations. 64 * 65 * @param status Session status. 66 * @param result Session results. May be NULL for certain events. 67 * @param user_data A pointer to the user provided data. 68 */ 69 typedef void (*zperf_callback)(enum zperf_status status, 70 struct zperf_results *result, 71 void *user_data); 72 73 /** 74 * @brief Synchronous UDP upload operation. The function blocks until the upload 75 * is complete. 76 * 77 * @param param Upload parameters. 78 * @param result Session results. 79 * 80 * @return 0 if session completed successfully, a negative error code otherwise. 81 */ 82 int zperf_udp_upload(const struct zperf_upload_params *param, 83 struct zperf_results *result); 84 85 /** 86 * @brief Synchronous TCP upload operation. The function blocks until the upload 87 * is complete. 88 * 89 * @param param Upload parameters. 90 * @param result Session results. 91 * 92 * @return 0 if session completed successfully, a negative error code otherwise. 93 */ 94 int zperf_tcp_upload(const struct zperf_upload_params *param, 95 struct zperf_results *result); 96 97 /** 98 * @brief Asynchronous UDP upload operation. 99 * 100 * @note Only one asynchronous upload can be performed at a time. 101 * 102 * @param param Upload parameters. 103 * @param callback Session results callback. 104 * @param user_data A pointer to the user data to be provided with the callback. 105 * 106 * @return 0 if session was scheduled successfully, a negative error code 107 * otherwise. 108 */ 109 int zperf_udp_upload_async(const struct zperf_upload_params *param, 110 zperf_callback callback, void *user_data); 111 112 /** 113 * @brief Asynchronous TCP upload operation. 114 * 115 * @note Only one asynchronous upload can be performed at a time. 116 * 117 * @param param Upload parameters. 118 * @param callback Session results callback. 119 * @param user_data A pointer to the user data to be provided with the callback. 120 * 121 * @return 0 if session was scheduled successfully, a negative error code 122 * otherwise. 123 */ 124 int zperf_tcp_upload_async(const struct zperf_upload_params *param, 125 zperf_callback callback, void *user_data); 126 127 /** 128 * @brief Start UDP server. 129 * 130 * @note Only one UDP server instance can run at a time. 131 * 132 * @param param Download parameters. 133 * @param callback Session results callback. 134 * @param user_data A pointer to the user data to be provided with the callback. 135 * 136 * @return 0 if server was started, a negative error code otherwise. 137 */ 138 int zperf_udp_download(const struct zperf_download_params *param, 139 zperf_callback callback, void *user_data); 140 141 /** 142 * @brief Start TCP server. 143 * 144 * @note Only one TCP server instance can run at a time. 145 * 146 * @param param Download parameters. 147 * @param callback Session results callback. 148 * @param user_data A pointer to the user data to be provided with the callback. 149 * 150 * @return 0 if server was started, a negative error code otherwise. 151 */ 152 int zperf_tcp_download(const struct zperf_download_params *param, 153 zperf_callback callback, void *user_data); 154 155 /** 156 * @brief Stop UDP server. 157 * 158 * @return 0 if server was stopped successfully, a negative error code otherwise. 159 */ 160 int zperf_udp_download_stop(void); 161 162 /** 163 * @brief Stop TCP server. 164 * 165 * @return 0 if server was stopped successfully, a negative error code otherwise. 166 */ 167 int zperf_tcp_download_stop(void); 168 169 #ifdef __cplusplus 170 } 171 #endif 172 173 /** 174 * @} 175 */ 176 177 #endif /* ZEPHYR_INCLUDE_NET_ZPERF_H_ */ 178