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版本,以及要编译的平台

android {compileSdk 32defaultConfig {applicationId "com.example.iperf3"minSdk 23targetSdk 32versionCode 1versionName "1.0"testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"// 平台指定ndk{abiFilters "arm64-v8a"}}
// ndk 版本指定(可不选,AS会根据gradle版本指定默认)
//    ndkVersion "22.0.7026061"ndkVersion '24.0.8215888'
//    ndkVersion "21.1.6352462"buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}// Android.mk 文件指定externalNativeBuild{ndkBuild{path file("src/main/jni/Android.mk")}}
}

Android.mk

LOCAL_PATH := $(call my-dir)#-------------------iperf3-----
include $(CLEAR_VARS)
LOCAL_MODULE := iperf3
MY_SRC_PATH = iperf-3.1.3/src
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(MY_SRC_PATH)
#LOCAL_SRC_FILES := $(call all-c-files-under, iperf-3.1.3/src) 没效果??
LOCAL_SRC_FILES += $(MY_SRC_PATH)/cjson.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_api.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_client_api.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_error.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_locale.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_sctp.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_server_api.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_tcp.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_udp.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/iperf_util.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/main.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/net.c
#LOCAL_SRC_FILES += $(MY_SRC_PATH)/t_timer.c
#LOCAL_SRC_FILES += $(MY_SRC_PATH)/t_units.c
#LOCAL_SRC_FILES += $(MY_SRC_PATH)/t_uuid.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/tcp_info.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/tcp_window_size.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/timer.c
LOCAL_SRC_FILES += $(MY_SRC_PATH)/units.cLOCAL_LDFLAGS += -pie -fPIE
include $(BUILD_EXECUTABLE)
#include $(BUILD_STATIC_LIBRARY)

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

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

1. 在src 中加上 iperf_config.h

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

/* src/iperf_config.h.in.  Generated from configure.ac by autoheader.  *//* Define to 1 if you have the `cpuset_setaffinity' function. */
#undef HAVE_CPUSET_SETAFFINITY/* Have CPU affinity support. */
#undef HAVE_CPU_AFFINITY/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H/* Have IPv6 flowlabel support. */
#undef HAVE_FLOWLABEL/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H/* Define to 1 if you have the <netinet/sctp.h> header file. */
#undef HAVE_NETINET_SCTP_H/* Define to 1 if you have the `sched_setaffinity' function. */
#undef HAVE_SCHED_SETAFFINITY/* Have SCTP support. */
#undef HAVE_SCTP/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE/* Have SO_MAX_PACING_RATE sockopt. */
#undef HAVE_SO_MAX_PACING_RATE/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H/* Define to 1 if the system has the type `struct sctp_assoc_value'. */
#undef HAVE_STRUCT_SCTP_ASSOC_VALUE/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H/* Have TCP_CONGESTION sockopt. */
#undef HAVE_TCP_CONGESTION/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H/* Define to the sub-directory where libtool stores uninstalled libraries. */
#undef LT_OBJDIR/* Name of package */
#define PACKAGE "iperf"/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "https://github.com/esnet/iperf"/* Define to the full name of this package. */
#define PACKAGE_NAME "iperf"/* Define to the full name and version of this package. */
#define PACKAGE_STRING "iperf 3.1.3"/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "iperf"/* Define to the home page for this package. */
#define PACKAGE_URL "http://software.es.net/iperf/"/* Define to the version of this package. */
#define PACKAGE_VERSION "3.1.3"/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1/* Version number of package */
#define VERSION "3.1.3"

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

/** iperf, Copyright (c) 2014, The Regents of the University of* California, through Lawrence Berkeley National Laboratory (subject* to receipt of any required approvals from the U.S. Dept. of* Energy).  All rights reserved.** If you have questions about your rights to use or distribute this* software, please contact Berkeley Lab's Technology Transfer* Department at TTD@lbl.gov.** NOTICE.  This software is owned by the U.S. Department of Energy.* As such, the U.S. Government has been granted for itself and others* acting on its behalf a paid-up, nonexclusive, irrevocable,* worldwide license in the Software to reproduce, prepare derivative* works, and perform publicly and display publicly.  Beginning five* (5) years after the date permission to assert copyright is obtained* from the U.S. Department of Energy, and subject to any subsequent* five (5) year renewals, the U.S. Government is granted for itself* and others acting on its behalf a paid-up, nonexclusive,* irrevocable, worldwide license in the Software to reproduce,* prepare derivative works, distribute copies to the public, perform* publicly and display publicly, and to permit others to do so.** This code is distributed under a BSD style license, see the LICENSE* file for complete information.*/
#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 

Android 移植iperf3.13 测试网络相关推荐

  1. Android KitKat 4.4 Wifi移植AP模式和网络共享的调试日志

    Tethering技术在移动平台上已经运用的越来越广泛了.它能够把移动设备当做一个接入点,其它的设备能够通过Wi-Fi.USB或是Bluetooth等方式连接到此移动设备.在Android中能够将Wi ...

  2. Android网卡网速测试

    1.可以使用speedtest.apk测试 2.使用iPerf进行网络吞吐量测试 2.1 unbunt环境 1)apt-get install iperf (安装iperf) 2)  iperf -s ...

  3. Android 基础知识+app测试权限问题

    Android 基础知识(权限篇)** 前言 ​ Android是一个开源的,基于Linux的移动设备操作系统,主要用于移动设备,如智能手机和平板电脑.Android是由谷歌及其他公司带领的开放手机联 ...

  4. 《大话移动APP测试:Android与iOS应用测试指南》

    <大话移动app测试:android与ios应用测试指南> 基本信息 作者: 陈晔 出版社:清华大学出版社 ISBN:9787302368793 上架时间:2014-7-7 出版日期:20 ...

  5. iperf3 网络带宽测试工具

    iperf3 网络带宽测试工具 iperf3 是一个 TCP, UDP, 和 SCTP (传输层协议)网络带宽测量工具. 简介 iperf 是一个用于主动测量 IP 网络上最大可用带宽的工具. 它支持 ...

  6. android dropbear 密码,Android移植之dropbear

    Android移植之dropbear 1.需求 Android虽然提供了ADB,但还是没有ssh,scp等用起来顺手,所以想移植一个ssh的Server到开发板上去,因为android默认的代码有ex ...

  7. 【以太坊】ubuntu安装以太坊ethereum的测试网络ropsten-net以及雷电网络raiden-network环境...

    ubuntu安装以太坊ethereum的测试网络ropsten-net以及雷电网络raiden-network环境 前言 为了保证环境稳定,我从头开了一个虚拟机. 环境如下 xiaoyu@xiaoyu ...

  8. Android之ListViewJson加载网络数据

    使用到的主要内容: 1.Json 解析网络数据 2.异步任务加载图片和数据 3.ListView 的内存空间优化(ConvertView)和运行时间优化(ViewHolder) 4.ListView ...

  9. 云炬Android开发笔记 13购物车,订单,支付功能开发(包含支付宝支付和微信支付)

    阅读目录 1.购物车UI编写 1.1 购物车布局  1.2 recycleView中的item的布局 2. 购物车数据结构分析.解析与转化 2.1 解析的数据 2.2 数据的转化 2.3 数据适配器的 ...

最新文章

  1. Protocol Buffer技术详解(语言规范)
  2. 初始springCloud
  3. python如何爬虫eps数据_入门Python爬虫 -- 解析数据篇
  4. JavaScript中用var和不用var的区别
  5. 网易严选搜索推荐实践之:“全能选手”召回表征算法实践
  6. Windows恶搞脚本,太实用了医院WiFi很快
  7. Java set的区别_Java Set集合详解及Set与List的区别
  8. 怎么打钩_如何在excel中打钩
  9. 思科网院计算机应用基础答案,计算机应用基础试题及答案
  10. 八仙过海,四种同步(Java中的四种同步类)
  11. 流程图 FlowChart
  12. Revit开发之内建模型
  13. 5+App使用UniPush发送消息,App在线、离线均能收到消息推送,并在通知栏进行提醒,苹果、华为、小米手机均测试通过
  14. 脑卒中css评分是什么意思,你知道房颤卒中新评分—ABC评分量表吗?
  15. 基于LLVM编译器的IDA自动结构体分析插件
  16. Google Earth Engine(GEE)——可视化动态图
  17. 【Lintcode】1335. Repeated DNA Sequences
  18. Java图片加文字水印
  19. BugkuCTF web11_网站被黑 writeup
  20. 分享一套公众号写作流程,不觉得牛逼算我输!

热门文章

  1. 分类模型训练完之后,测试效果极差可能原因分析
  2. 用ASP.NET建立一个在线RSS新闻聚合器
  3. 微生物群落功能预测工具
  4. 计算机思维使用的方法是,计算机思维
  5. 关于《数据仓库知识体系》的超全指南(建议收藏)
  6. python:talib 计算 OBV
  7. proteus练习(1) 流水灯的实现
  8. 计算机如何删除用不到的打印机驱动程序,打印机驱动不能删除怎么办 打印机驱动无法删除的解决方法...
  9. 四维图新地图坐标_一种融合双目视觉和差分卫星定位的地标地图生成方法与流程...
  10. Linux Ubuntu20.04安装RTL8156网卡驱动开启巨型帧