http://blog.chinaunix.net/u3/103613/showart_2037838.html
下面的文檔描述如何移植 iperf 到 android 平台中
1. download iperf source code
latest iperf version from the below link:
http://sourceforge.net/projects/iperf/
and then unzip it.
tar zxvf iperf_2.0.4.orig.tar.gz
2. copy iperf-2.0.4
copy iperf-2.0.4 folder to external/ in cupcake or other Android version, and rename it as iperf.
3. add header files
add two header files in iperf folder
iperf/include/iperf-int.h
iperf/config.h
you can get it if you build iperf source code in iperf formal package.
4. add Makefile
add a new Android.mk in iperf folder for Android environment.
and the context is as belows:
#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir)
OBJS += compat/error.c
OBJS += compat/snprintf.c
OBJS += compat/inet_ntop.c
OBJS += compat/inet_pton.c
OBJS += compat/signal.c
OBJS += compat/Thread.c
OBJS += compat/string.c
OBJS += compat/gettimeofday.c
OBJS += src/gnu_getopt.c
OBJS += src/gnu_getopt_long.c
OBJS += src/tcp_window_size.c
OBJS += src/service.c
OBJS += src/sockets.c
OBJS += src/stdio.c
OBJS += src/ReportCSV.c
OBJS += src/Locale.c
OBJS += src/ReportDefault.c
OBJS += src/Reporter.c
OBJS += src/Extractor.c
OBJS += src/SocketAddr.c
OBJS += compat/delay.cpp
OBJS += src/Server.cpp
OBJS += src/Client.cpp
OBJS += src/List.cpp
OBJS += src/Launch.cpp
OBJS += src/PerfSocket.cpp
OBJS += src/Settings.cpp
OBJS += src/Listener.cpp
OBJS += src/main.cpp
INCLUDES = $(LOCAL_PATH)/include
L_CFLAGS = -DHAVE_CONFIG_H
########################
include $(CLEAR_VARS)
LOCAL_MODULE := iperf
#LOCAL_SHARED_LIBRARIES := libc libcutils libutils libnetutils libstdc++
LOCAL_CFLAGS := $(L_CFLAGS)
LOCAL_SRC_FILES := $(OBJS)
LOCAL_C_INCLUDES := $(INCLUDES)
include $(BUILD_EXECUTABLE)
########################
4. do modification
do some modification which blocks the build.
4.1 util.h
because Android environment has also one util.h, and Make system will select it instead of util.h in iperf folder,
so we need let Make system select local util.h. one easy method is to use below sentence.
#include "include/util.h"
instead of
#include "util.h"
4.2 headers.h
for iperf/include/headers.h
#ifndef NDEBUG
#define NDEBUG
#endif
instead of
#define NDEBUG
4.3 Listener.cpp
for iperf/src/Listener.cpp
delete the below since we don't care about ipv6 currently.
mreq.ipv6mr_interface = 0;
執行個體
1)TCP測試
伺服器執行:./iperf -s -i 1 -w 1M
用戶端執行:./iperf -c host -i 1 -w 1M 其中-w表示TCP window size,host需替換成伺服器位址。
2)UDP測試
伺服器執行:./iperf -u -s
用戶端執行:./iperf -u -c 10.255.255.251 -b 900M -i 1 -w 1M -t 60
其中-b表示使用多少頻寬,1G的線路你可以使用900M進行測試。
功能介紹
l TCP
n 測量網路頻寬
n 報告MSS/MTU值的大小和觀測值
n 支援TCP視窗值通過通訊端緩衝
n 當P線程或Win32線程可用時,支援多線程。用戶端與服務端支援同時多重串連
l UDP n 用戶端可以建立指定頻寬的UDP流
n 測量丟包
n 測量延遲
n 支援多播
n 當P線程可用時,支援多線程。用戶端與服務端支援同時多重串連(不支援Windows)
l 在適當的地方,選項中可以使用K(kilo-)和M(mega-)。例如131072位元組可以用128K代替。
l 可以指定啟動並執行總時間,甚至可以設定傳輸的資料總量。
l 在報告中,為資料選用最合適的單位。
l 伺服器支援多重串連,而不是等待一個單線程測試。
l 在指定時間間隔重複顯示網路頻寬,波動和丟包情況。
l 伺服器端可作為背景程式運行。
l 伺服器端可作為Windows 服務運行。
l 使用典型資料流來測試連結層壓縮對於可用頻寬的影響。