Add network tester client [android] to be able to test mobile networks in terms of packet size and sending rates.

BUG=webrtc:7426

Review-Url: https://codereview.webrtc.org/2787863002
Cr-Commit-Position: refs/heads/master@{#17789}
This commit is contained in:
michaelt
2017-04-20 06:56:27 -07:00
committed by Commit bot
parent fcea39d7ce
commit 2fe9ac3763
17 changed files with 303 additions and 1 deletions

View File

@ -112,3 +112,57 @@ if (rtc_enable_protobuf) {
}
}
}
if (is_android) {
android_apk("NetworkTesterMobile") {
testonly = true
apk_name = "NetworkTesterMobile"
android_manifest = "androidapp/AndroidManifest.xml"
deps = [
":NetworkTesterMobile_javalib",
":NetworkTesterMobile_resources",
"//base:base_java",
"//webrtc/base:base_java",
]
shared_libraries = [ "//webrtc/tools/network_tester:network_tester_so" ]
}
android_library("NetworkTesterMobile_javalib") {
testonly = true
android_manifest = "androidapp/AndroidManifest.xml"
java_files = [
"androidapp/src/com/google/media/networktester/MainActivity.java",
"androidapp/src/com/google/media/networktester/NetworkTester.java",
]
deps = [
":NetworkTesterMobile_resources",
"//webrtc/base:base_java",
]
}
android_resources("NetworkTesterMobile_resources") {
testonly = true
resource_dirs = [ "androidapp/res" ]
custom_package = "com.google.media.networktester"
}
rtc_shared_library("network_tester_so") {
sources = [
"jni.cpp",
]
deps = [
":network_tester",
"../../system_wrappers:field_trial_default",
]
suppressed_configs += [ "//build/config/android:hide_all_but_jni_onload" ]
configs += [ "//build/config/android:hide_all_but_jni" ]
output_extension = "so"
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.media.networktester" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="24"
android:maxSdkVersion="24" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.google.media.networktester.MainActivity">
<Button
android:text="@string/start_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/start_button"/>
<Button
android:text="@string/interrupt_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/start_button"
android:id="@+id/stop_button"/>
</RelativeLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@ -0,0 +1,6 @@
<resources>
<string name="app_name">NetworkTester</string>
<string name="start_test">Start test</string>
<string name="interrupt_test">Interrupt test</string>
<string name="test_status">Status</string>
</resources>

View File

@ -0,0 +1,66 @@
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
package com.google.media.networktester;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends Activity {
Button startButton;
Button stopButton;
NetworkTester networkTester = null;
Handler mainThreadHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton = (Button) findViewById(R.id.start_button);
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startTest();
}
});
stopButton = (Button) findViewById(R.id.stop_button);
stopButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
stopTest();
}
});
mainThreadHandler = new Handler();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
private void startTest() {
if (networkTester == null) {
networkTester = new NetworkTester();
networkTester.start();
}
}
private void stopTest() {
if (networkTester != null) {
networkTester.interrupt();
networkTester = null;
}
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
package com.google.media.networktester;
public class NetworkTester extends Thread {
private native static long CreateTestController();
private native static void TestControllerConnect(long testController);
private native static void TestControllerRun(long testController);
private native static boolean TestControllerIsDone(long testController);
private native static void DestroyTestController(long testController);
static {
System.loadLibrary("network_tester_so");
}
@Override
public void run() {
final long testController = CreateTestController();
TestControllerConnect(testController);
while (!Thread.interrupted() && !TestControllerIsDone(testController)) {
TestControllerRun(testController);
}
DestroyTestController(testController);
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <jni.h>
#undef JNIEXPORT
#define JNIEXPORT __attribute__((visibility("default")))
#include <string>
#include "webrtc/tools/network_tester/test_controller.h"
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_media_networktester_NetworkTester_CreateTestController(
JNIEnv* jni,
jclass) {
return reinterpret_cast<intptr_t>(new webrtc::TestController(
0, 0, "/mnt/sdcard/network_tester_client_config.dat",
"/mnt/sdcard/network_tester_client_packet_log.dat"));
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_media_networktester_NetworkTester_TestControllerConnect(
JNIEnv* jni,
jclass,
jlong native_pointer) {
reinterpret_cast<webrtc::TestController*>(native_pointer)
->SendConnectTo("85.195.237.107", 9090);
}
extern "C" JNIEXPORT bool JNICALL
Java_com_google_media_networktester_NetworkTester_TestControllerIsDone(
JNIEnv* jni,
jclass,
jlong native_pointer) {
return reinterpret_cast<webrtc::TestController*>(native_pointer)
->IsTestDone();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_media_networktester_NetworkTester_TestControllerRun(
JNIEnv* jni,
jclass,
jlong native_pointer) {
reinterpret_cast<webrtc::TestController*>(native_pointer)->Run();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_media_networktester_NetworkTester_DestroyTestController(
JNIEnv* jni,
jclass,
jlong native_pointer) {
webrtc::TestController* test_controller =
reinterpret_cast<webrtc::TestController*>(native_pointer);
if (test_controller) {
delete test_controller;
}
}

View File

@ -16,7 +16,8 @@ TestController::TestController(int min_port,
int max_port,
const std::string& config_file_path,
const std::string& log_file_path)
: config_file_path_(config_file_path),
: socket_factory_(rtc::ThreadManager::Instance()->WrapCurrentThread()),
config_file_path_(config_file_path),
packet_logger_(log_file_path),
local_test_done_(false),
remote_test_done_(false) {
@ -101,6 +102,9 @@ void TestController::OnReadPacket(rtc::AsyncPacketSocket* socket,
case NetworkTesterPacket::TEST_START: {
packet_sender_.reset(new PacketSender(this, config_file_path_));
packet_sender_->StartSending();
rtc::CritScope scoped_lock(&local_test_done_lock_);
local_test_done_ = false;
remote_test_done_ = false;
break;
}
case NetworkTesterPacket::TEST_DATA: {