add udp one copy to app

This commit is contained in:
HappyZ 2017-02-26 16:00:59 -08:00
parent 51a5036f0e
commit ffa270c0b0
6 changed files with 142 additions and 3 deletions

View File

@ -75,6 +75,7 @@ class MainActivity extends Activity {
protected static String binary_TX_Normal;
protected static String binary_TX_NormalUDP;
protected static String binary_TX_Sendfile;
protected static String binary_TX_UDPSendfile;
protected static String binary_TX_Splice;
protected static String binary_TX_RawNormal;
protected static final String binary_TX_RawSplice = "";
@ -87,6 +88,7 @@ class MainActivity extends Activity {
protected static boolean isRunning_TX_Normal = false;
protected static boolean isRunning_TX_NormalUDP = false;
protected static boolean isRunning_TX_Sendfile = false;
protected static boolean isRunning_TX_UDPSendfile = false;
protected static boolean isRunning_TX_Splice = false;
protected static boolean isRunning_TX_RawNormal = false;
protected static boolean isRunning_TX_RawSplice = false;
@ -128,6 +130,7 @@ class MainActivity extends Activity {
Runtime.getRuntime().exec("su -c killall -9 " + binary_TX_Normal).waitFor();
Runtime.getRuntime().exec("su -c killall -9 " + binary_TX_NormalUDP).waitFor();
Runtime.getRuntime().exec("su -c killall -9 " + binary_TX_Sendfile).waitFor();
Runtime.getRuntime().exec("su -c killall -9 " + binary_TX_UDPSendfile).waitFor();
Runtime.getRuntime().exec("su -c killall -9 " + binary_TX_Splice).waitFor();
Runtime.getRuntime().exec("su -c killall -9 " + binary_TX_RawNormal).waitFor();
Runtime.getRuntime().exec("su -c killall -9 " + binary_RX_Normal).waitFor();
@ -149,6 +152,8 @@ class MainActivity extends Activity {
missingFiles += " " + binary_TX_NormalUDP;
if (!Utilities.fileExist(binaryFolderPath + binary_TX_Sendfile))
missingFiles += " " + binary_TX_Sendfile;
if (!Utilities.fileExist(binaryFolderPath + binary_TX_UDPSendfile))
missingFiles += " " + binary_TX_UDPSendfile;
if (!Utilities.fileExist(binaryFolderPath + binary_TX_Splice))
missingFiles += " " + binary_TX_Splice;
if (!Utilities.fileExist(binaryFolderPath + binary_TX_RawNormal))
@ -229,7 +234,7 @@ class MainActivity extends Activity {
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (which == 5 || (flagRecv && which == 2) || (mVersion < 21 && which == 3)) {
if ((flagRecv && which == 2) || (mVersion < 21 && which == 3)) {
Toast.makeText(MainActivity.this, "not working", Toast.LENGTH_SHORT).show();
return;
}
@ -485,7 +490,12 @@ class MainActivity extends Activity {
Thread.sleep(1005);
}
break;
case 5: // rawsocket splice unimplemented
case 5: // udp sendfile
new Thread(new Thread_TX_CUDPSendfile()).start();
Thread.sleep(1005);
while (isRunning_TX_UDPSendfile) {
Thread.sleep(1005);
}
break;
default: // do nothing
break;
@ -609,6 +619,7 @@ class MainActivity extends Activity {
binary_TX_Normal = "client_send_normaltcp";
binary_TX_NormalUDP = "client_send_normaludp";
binary_TX_Sendfile = "client_send_normaltcp_sendfile";
binary_TX_UDPSendfile = "client_send_normaludp_sendfile";
binary_TX_RawNormal = "client_send_bypassl3";
binary_TX_Splice = "client_send_normaltcp_splice";
binary_RX_Normal = "client_recv_normaltcp";

View File

@ -0,0 +1,110 @@
package edu.ucsb.cs.sandlab.offloadingdemo;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by yanzi on 9/19/15.
* Updated on 01/27/17
*/
class Thread_TX_CUDPSendfile implements Runnable {
private double sentBytes = 0.0;
private double duration = 0.0;
private double throughput = 0.0;
@Override
public void run() {
// prevent multiple runs
if (MainActivity.isRunning_TX_UDPSendfile)
return;
MainActivity.isRunning_TX_UDPSendfile = true;
// variables
Process proc;
String stdout;
BufferedReader stdout_buf, error_buf;
String[] commd = new String[3];
// get the right command
commd[0] = "su";
commd[1] = "-c";
// ./client_send_normaludp_sendfile <bytes2send/file2send> <ip> <port>
// <[optional] bandwidth (bps)> <[optional] sendsize (Bytes)>
commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
+ MainActivity.binaryFolderPath + MainActivity.binary_TX_UDPSendfile + " "
+ MainActivity.bytes2send + " "
+ (MainActivity.isLocal ? Utilities.myInetIP : MainActivity.remoteIP) + " "
+ Utilities.UDP_port + " "
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
MainActivity.currentBandwidth));
Log.d("TX_UDPSendfile", "Start TX UDP Sendfile");
try {
// run process
proc = Runtime.getRuntime().exec(commd);
// if config to log per process
while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
MainActivity.perProcPID = Utilities.getMyPID(
MainActivity.binary_TX_UDPSendfile, false);
}
proc.waitFor();
// read error
error_buf = new BufferedReader(new InputStreamReader(
proc.getErrorStream()));
final String error = error_buf.readLine(); // only one line error
// read std out
stdout_buf = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
// get sent bytes
stdout = stdout_buf.readLine();
if (stdout == null) {
// error happens
MainActivity.myHandler.post(new Runnable() {
@Override
public void run() {
MainActivity.txt_results.append("Err in TX_UDP_Sendfile: " + error + "\n");
}
});
} else {
// sent bytes
sentBytes = Utilities.parseBinOutput(stdout);
// duration
stdout = stdout_buf.readLine();
duration = Utilities.parseBinOutput(stdout);
MainActivity.reportedFinishTime = duration;
// throughput
stdout = stdout_buf.readLine();
throughput = Utilities.parseBinOutput(stdout);
if (MainActivity.isVerbose) {
MainActivity.myHandler.post(new Runnable() {
@Override
public void run() {
MainActivity.txt_results.append("Sent " + sentBytes +
"bytes in " + duration +
"s (" +throughput/Utilities.oneMB +"Mbps)\n");
}
});
}
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
Log.d("TX_UDPSendfile", "Stop TX UDP Sendfile");
MainActivity.isRunning_TX_UDPSendfile = false;
MainActivity.perProcPID = -1;
}
}

View File

@ -46,7 +46,8 @@ class Utilities {
// predefined selections
static CharSequence[] existedItems = new CharSequence[] {
"Socket_Normal", "Socket_NormalUDP", "Socket_Sendfile", "Socket_Splice", "RawSocket_Normal"
"Socket_Normal", "Socket_NormalUDP", "Socket_Sendfile",
"Socket_Splice", "RawSocket_Normal", "Socket_UDPSendfile"
};
static CharSequence[] existedItemsThrpt = new CharSequence[]{
"800Mbps", "760Mbps", "720Mbps", "680Mbps", "640Mbps", "600Mbps", "560Mbps",// 0-6

View File

@ -0,0 +1,14 @@
#!/bin/bash
loc=/Users/yanzi/GDrive/UCSB/Projects/Offloading_2017/Data/$1;
if [ ! -d $loc ]; then
mkdir -p $loc;
fi
for file in $(adb shell ls /sdcard/SSLogger/*.tar.gz | tr -d '\r'); do
echo $file;
adb pull $file $loc;
done
adb shell rm /sdcard/SSLogger/*.tar.gz

View File

@ -7,6 +7,8 @@ cd client_send_bypassl3 && make
cd ../
cd client_send_normaludp && make
cd ../
cd client_send_normaludp_sendfile && make
cd ../
cd client_send_normaltcp && make
cd ../
# client read file only

View File

@ -11,6 +11,7 @@ adb push ../offloading_binaries/client_recv_normaltcp/client_recv_normaltcp /dat
adb push ../offloading_binaries/client_recv_normaludp/client_recv_normaludp /data/local/tmp/
adb push ../offloading_binaries/server_recv_normaltcp/server_m_recv_normaltcp /data/local/tmp/
adb push ../offloading_binaries/server_recv_normaludp/server_m_recv_normaludp /data/local/tmp/
adb push ../offloading_binaries/client_send_normaludp_sendfile/client_send_normaludp_sendfile /data/local/tmp/
echo "* Pushing tcpdump 4.8.1"
adb push tcpdump /data/local/tmp/
echo "* Change permission"