当前位置:   article > 正文

Android 移植iperf3.13 测试网络_iperf安卓下载

iperf安卓下载

iperf,测试网络性能的,不同于 webrtc里面的gcc 算法预估网络带宽,iperf是实际占用网络来传输数据测量实际的网络性能。

官网:https://iperf.fr/
官方就有 android 的下载 https://iperf.fr/iperf-download.php#android, 但是看起来要访问 play.google. 墙。急用,怎么自己拿源码来ndk 编译一下。
1. 最适配的方式,应该是用 configure + make, configure来配置ndk编译器。 (ubuntu环境下) 没有环境,不想太折腾
2. 在AndroidStudio 上用cmake 编译
3. 还是用比较熟悉的 Android.mk , 在AS中编译
 

目录

一:下载源码

 二:AS 创建一个空的demo,src/main 目录下建一个jni, 把源码解压到这里, 然后编写 Android.mk 来编译。(如果直接使用ndk-build 命令,就不需要AS了。)

  在app 的build.gradle中手动指定Android.mk 文件位置,使用的ndk版本,以及要编译的平台

Android.mk

对源码需要做一点头文件的修改

1. 在src 中加上 iperf_config.h

2. src 目录下 version.h    同上,来源为version.h.in

3.修改源码里面一个 字符串,临时文件的路径

最后,build

1. 测试带宽

 2. 测试udp 丢包


一:下载源码

发布的只有3.1.3 iPerf - Download iPerf3 and original iPerf pre-compiled binaries

 二:AS 创建一个空的demo,src/main 目录下建一个jni, 把源码解压到这里, 然后编写 Android.mk 来编译。(如果直接使用ndk-build 命令,就不需要AS了。)


  在app 的build.gradle中手动指定Android.mk 文件位置,使用的ndk版本,以及要编译的平台

  1. android {
  2. compileSdk 32
  3. defaultConfig {
  4. applicationId "com.example.iperf3"
  5. minSdk 23
  6. targetSdk 32
  7. versionCode 1
  8. versionName "1.0"
  9. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  10. // 平台指定
  11. ndk{
  12. abiFilters "arm64-v8a"
  13. }
  14. }
  15. // ndk 版本指定(可不选,AS会根据gradle版本指定默认)
  16. // ndkVersion "22.0.7026061"
  17. ndkVersion '24.0.8215888'
  18. // ndkVersion "21.1.6352462"
  19. buildTypes {
  20. release {
  21. minifyEnabled false
  22. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  23. }
  24. }
  25. compileOptions {
  26. sourceCompatibility JavaVersion.VERSION_1_8
  27. targetCompatibility JavaVersion.VERSION_1_8
  28. }
  29. // Android.mk 文件指定
  30. externalNativeBuild{
  31. ndkBuild{
  32. path file("src/main/jni/Android.mk")
  33. }
  34. }
  35. }

Android.mk

  1. LOCAL_PATH := $(call my-dir)
  2. #-------------------iperf3-----
  3. include $(CLEAR_VARS)
  4. LOCAL_MODULE := iperf3
  5. MY_SRC_PATH = iperf-3.1.3/src
  6. LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(MY_SRC_PATH)
  7. #LOCAL_SRC_FILES := $(call all-c-files-under, iperf-3.1.3/src) 没效果??
  8. LOCAL_SRC_FILES += $(MY_SRC_PATH)/cjson.c
  9. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_api.c
  10. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_client_api.c
  11. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_error.c
  12. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_locale.c
  13. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_sctp.c
  14. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_server_api.c
  15. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_tcp.c
  16. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_udp.c
  17. LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_util.c
  18. LOCAL_SRC_FILES += $(MY_SRC_PATH)/main.c
  19. LOCAL_SRC_FILES += $(MY_SRC_PATH)/net.c
  20. #LOCAL_SRC_FILES += $(MY_SRC_PATH)/t_timer.c
  21. #LOCAL_SRC_FILES += $(MY_SRC_PATH)/t_units.c
  22. #LOCAL_SRC_FILES += $(MY_SRC_PATH)/t_uuid.c
  23. LOCAL_SRC_FILES += $(MY_SRC_PATH)/tcp_info.c
  24. LOCAL_SRC_FILES += $(MY_SRC_PATH)/tcp_window_size.c
  25. LOCAL_SRC_FILES += $(MY_SRC_PATH)/timer.c
  26. LOCAL_SRC_FILES += $(MY_SRC_PATH)/units.c
  27. LOCAL_LDFLAGS += -pie -fPIE
  28. include $(BUILD_EXECUTABLE)
  29. #include $(BUILD_STATIC_LIBRARY)

对源码需要做一点头文件的修改

本来这些头文件是 configure 命令自动添加上去的,我们没有configure,需要自己动手补上。

1. 在src 中加上 iperf_config.h

(来源是源码中的 iperf_config.h.in,  configure命令以这个为输入,定义了一些宏, 不确定的话,直接把这个iperf3搞到ubuntu上,运行一下./configure  可以得到一版,然参考修改) 可直接参考:
iperf_config.h

  1. /* src/iperf_config.h.in. Generated from configure.ac by autoheader. */
  2. /* Define to 1 if you have the `cpuset_setaffinity' function. */
  3. #undef HAVE_CPUSET_SETAFFINITY
  4. /* Have CPU affinity support. */
  5. #undef HAVE_CPU_AFFINITY
  6. /* Define to 1 if you have the <dlfcn.h> header file. */
  7. #undef HAVE_DLFCN_H
  8. /* Have IPv6 flowlabel support. */
  9. #undef HAVE_FLOWLABEL
  10. /* Define to 1 if you have the <inttypes.h> header file. */
  11. #undef HAVE_INTTYPES_H
  12. /* Define to 1 if you have the <memory.h> header file. */
  13. #undef HAVE_MEMORY_H
  14. /* Define to 1 if you have the <netinet/sctp.h> header file. */
  15. #undef HAVE_NETINET_SCTP_H
  16. /* Define to 1 if you have the `sched_setaffinity' function. */
  17. #undef HAVE_SCHED_SETAFFINITY
  18. /* Have SCTP support. */
  19. #undef HAVE_SCTP
  20. /* Define to 1 if you have the `sendfile' function. */
  21. #undef HAVE_SENDFILE
  22. /* Have SO_MAX_PACING_RATE sockopt. */
  23. #undef HAVE_SO_MAX_PACING_RATE
  24. /* Define to 1 if you have the <stdint.h> header file. */
  25. #undef HAVE_STDINT_H
  26. /* Define to 1 if you have the <stdlib.h> header file. */
  27. #undef HAVE_STDLIB_H
  28. /* Define to 1 if you have the <strings.h> header file. */
  29. #undef HAVE_STRINGS_H
  30. /* Define to 1 if you have the <string.h> header file. */
  31. #undef HAVE_STRING_H
  32. /* Define to 1 if the system has the type `struct sctp_assoc_value'. */
  33. #undef HAVE_STRUCT_SCTP_ASSOC_VALUE
  34. /* Define to 1 if you have the <sys/socket.h> header file. */
  35. #undef HAVE_SYS_SOCKET_H
  36. /* Define to 1 if you have the <sys/stat.h> header file. */
  37. #undef HAVE_SYS_STAT_H
  38. /* Define to 1 if you have the <sys/types.h> header file. */
  39. #undef HAVE_SYS_TYPES_H
  40. /* Have TCP_CONGESTION sockopt. */
  41. #undef HAVE_TCP_CONGESTION
  42. /* Define to 1 if you have the <unistd.h> header file. */
  43. #undef HAVE_UNISTD_H
  44. /* Define to the sub-directory where libtool stores uninstalled libraries. */
  45. #undef LT_OBJDIR
  46. /* Name of package */
  47. #define PACKAGE "iperf"
  48. /* Define to the address where bug reports for this package should be sent. */
  49. #define PACKAGE_BUGREPORT "https://github.com/esnet/iperf"
  50. /* Define to the full name of this package. */
  51. #define PACKAGE_NAME "iperf"
  52. /* Define to the full name and version of this package. */
  53. #define PACKAGE_STRING "iperf 3.1.3"
  54. /* Define to the one symbol short name of this package. */
  55. #define PACKAGE_TARNAME "iperf"
  56. /* Define to the home page for this package. */
  57. #define PACKAGE_URL "http://software.es.net/iperf/"
  58. /* Define to the version of this package. */
  59. #define PACKAGE_VERSION "3.1.3"
  60. /* Define to 1 if you have the ANSI C header files. */
  61. #define STDC_HEADERS 1
  62. /* Version number of package */
  63. #define VERSION "3.1.3"

2. src 目录下 version.h    同上,来源为version.h.in
 

  1. /*
  2. * iperf, Copyright (c) 2014, The Regents of the University of
  3. * California, through Lawrence Berkeley National Laboratory (subject
  4. * to receipt of any required approvals from the U.S. Dept. of
  5. * Energy). All rights reserved.
  6. *
  7. * If you have questions about your rights to use or distribute this
  8. * software, please contact Berkeley Lab's Technology Transfer
  9. * Department at TTD@lbl.gov.
  10. *
  11. * NOTICE. This software is owned by the U.S. Department of Energy.
  12. * As such, the U.S. Government has been granted for itself and others
  13. * acting on its behalf a paid-up, nonexclusive, irrevocable,
  14. * worldwide license in the Software to reproduce, prepare derivative
  15. * works, and perform publicly and display publicly. Beginning five
  16. * (5) years after the date permission to assert copyright is obtained
  17. * from the U.S. Department of Energy, and subject to any subsequent
  18. * five (5) year renewals, the U.S. Government is granted for itself
  19. * and others acting on its behalf a paid-up, nonexclusive,
  20. * irrevocable, worldwide license in the Software to reproduce,
  21. * prepare derivative works, distribute copies to the public, perform
  22. * publicly and display publicly, and to permit others to do so.
  23. *
  24. * This code is distributed under a BSD style license, see the LICENSE
  25. * file for complete information.
  26. */
  27. #define IPERF_VERSION "3.1.3"

3.修改源码里面一个 字符串,临时文件的路径

iperf_aip.c::

 /tmp/ 这个是linux路径,android 上没有,直接改为 /data/ 或者就是当前运行目录。

最后,build

在app\build\intermediates\ndkBuild\debug\obj\local\arm64-v8a  得到可执行文件, push 到/data/xx上去运行。

附上测试命令:

1. 测试带宽

服务端:#iperf3 -s -p 5001
                -s 表示作为服务端, -p 指定端口号

        
客户端:#iperf3 -c 127.0.0.1(服务器IP) -P 4 -t 30 -i 2 -p 5001
                -c 表示作为客户端, 后面跟服务端ip,  -P (大写) 表示process, 同时并发任务数,这里是4,  -t 表示测试持续时间,单位秒。   -i 表示每隔2秒报一次结果。  -p 端口号

 2. 测试udp 丢包

(udp无连接,发快网络带宽不够导致丢包,所以测udp在限制带宽的情况下丢包率)
服务端:#iperf3 -s -p 5001
客户端:
 #iperf3 -u -c 192.168.43.129 -p 8989 -b 100M -t 30
                -u 指定使用udp, -c 表示作为客户端   -b 限制在100Mbit 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/856482
推荐阅读
相关标签
  

闽ICP备14008679号