2018년 3월 30일 금요일

[Android] porting - iperf3

How to Install iperf3 on Android system

- 본 문서는 Iperf3 utility를 Android 개발환경에 적용하기 위한 내용을 기술한다.

Android : 7.1.0
Build System : Ubuntu 14.04 LTS
--------------------------------------------------------------------
ref : https://github.com/esnet/iperf
version : iperf 3.1.3
--------------------------------------------------------------------

소스코드는 github 또는 download 사이트를 통해 다운로드 가능하다.
  1. Project site (source code repository, issue tracker) hosted on GitHub:
    • https://github.com/esnet/iperf
  2. Source code downloads:
    • http://downloads.es.net/pub/iperf/

Android platform build 시 system.img 에 포함되어 릴리즈 되도록 적용한다.
  1. 소스코드 인출
    • git clone https://github.com/esnet/iperf.git
  2. Build
    • copy source files to android/external/iperf-3.1.3
      • $ copy -Rf ./iperf <Android_SRC_Root_DIR>/external/iperf3
    • $ configure - generate iperf_config.h file
      • $ cd <Android_SRC_Root_DIR>/external/iperf3
      • $ ./configure [enter]
    • generate Android.mk
      • $ vi <Android_SRC_Root_DIR>/external/iperf3/Android.mk
      •   1 LOCAL_PATH:= $(call my-dir)
          2 
          3 include $(CLEAR_VARS)
          4 
          5 LOCAL_MODULE_TAGS := optional
          6 
          7 # set SRC_FILES_LIST to all the .c files in $(LOCAL_PATH)/src/
          8 SRC_FILE_LIST := $(wildcard $(LOCAL_PATH)/src/*.c)
          9 
         10 # exclude test files $(LOCAL_PATH)/src/t_timer.c t_units.c t_uuid.c
         11 EXCLUD_FILE_LIST := $(wildcard $(LOCAL_PATH)/src/t_*.c)
         12 
         13 LOCAL_SRC_FILES := $(filter-out $(EXCLUD_FILE_LIST:$(LOCAL_PATH)/%=%),$(SRC_FILE_LIST:$(LOCAL_PATH)/%=%))
         14 
         15 LOCAL_C_INCLUDES :=  \
         16     $(LOCAL_PATH) \
         17     $(LOCAL_PATH)/src
         18 
         19 LOCAL_CFLAGS := -DHAVE_CONFIG_H -g -O2 -Wall -MT
         20 LDFLAGS="-fPIE -pie -fuse-ld=bfd"
         21 
         22 LOCAL_SHARED_LIBRARIES :=
         23 
         24 LOCAL_MODULE:= iperf3
         25 
         26 include $(BUILD_EXECUTABLE)
        3.2.2 partial build
         $ cd [android source root directory]
         $ source ./build/envsetup.sh
         $ mmm ./external/iperf-3.1.3

    • Partial build
      • $ source ./build/envsetup.sh [enter]
      • $ lunch [enter]
        • Select Lunch menu
      • mmm ./external/iperf3/ [enter]
  3. Run-time error 수정
    • case : iperf3: error - unable to create a new stream: No such file or directory
    • resolve : modify iperf_new_stream() at iperf_api.c ( external/iperf3/src/ )
    • 2657 struct iperf_stream *
      2658 iperf_new_stream(struct iperf_test *test, int s)
      2659 { 
      2660     int i;                 
      2661     struct iperf_stream *sp;
      2662   
      2663     char template[1024];
      2664     if (test->tmp_template) {
      2665         snprintf(template, sizeof(template) / sizeof(char), "%s", test->tmp_template);
      2666     } else {             
      2667         /* Android patch :               
      2668          * iperf3: error - unable to create a new stream: No such file or directory
      2669          */
      2670 #ifdef __ANDROID__
      2671         char buf[] = "/system/bin/iperf3.XXXXXX";
      2672 #else
      2673         char buf[] = "/tmp/iperf3.XXXXXX";
      2674 #endif           
      2675         snprintf(template, sizeof(template) / sizeof(char), "%s", buf);
      2676     }