From 47960a06d6c9f7c474c529a858e00da3165d1d10 Mon Sep 17 00:00:00 2001 From: Chao Kong Date: Tue, 25 Aug 2015 14:01:47 -0400 Subject: [PATCH 1/6] add intermediate results --- .../com/mobilyzer/MeasurementScheduler.java | 18 +++- .../src/com/mobilyzer/MeasurementTask.java | 11 +++ .../com/mobilyzer/ServerMeasurementTask.java | 1 + Mobilyzer/src/com/mobilyzer/UpdateIntent.java | 7 ++ .../com/mobilyzer/UserMeasurementTask.java | 8 ++ .../mobilyzer/measurements/ParallelTask.java | 3 + .../com/mobilyzer/measurements/PingTask.java | 96 ++++++++++++++++++- .../measurements/SequentialTask.java | 1 + .../measurements/TCPThroughputTask.java | 80 ++++++++++++++++ .../measurements/TracerouteTask.java | 77 ++++++++++++++- .../mobilyzer/measurements/UDPBurstTask.java | 2 +- 11 files changed, 296 insertions(+), 8 deletions(-) diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java b/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java index 948c0ab..53b3b56 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java @@ -185,6 +185,9 @@ public void onCreate() { filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION); filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION); filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION); + //added by Clarence + filter.addAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); + broadcastReceiver = new BroadcastReceiver() { @@ -323,7 +326,20 @@ public void onReceive(Context context, Intent intent) { } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals( Config.TASK_RESUMED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); - } + } //added by Clarence + } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION)){ + String IM_taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD); + String IM_taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD); + int IM_priority = + intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, + MeasurementTask.INVALID_PRIORITY); + Parcelable[] IM_Results = intent.getParcelableArrayExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD); + if (IM_Results != null && IM_Results.length!=0) { + sendResultToClient(IM_Results, IM_priority, IM_taskKey, IM_taskid); + Logger.i("Sending Intermediate results to client..."); + System.out.println("receive the intermediate results"); + } + } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION) || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION)) { Logger.d("Checkin intent received"); diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java index eb90244..8bc0318 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java @@ -29,6 +29,8 @@ public abstract class MeasurementTask Parcelable { protected MeasurementDesc measurementDesc; protected String taskId; + + private MeasurementScheduler scheduler; // added by Clarence public static final int USER_PRIORITY = Integer.MIN_VALUE; @@ -114,6 +116,15 @@ public String getKey() { public void setKey(String key) { this.measurementDesc.key = key; } + + // added by Clarence, pass scheduler to every specific task + public void setScheduler(MeasurementScheduler scheduler) { + this.scheduler = scheduler; + } + + public MeasurementScheduler getScheduler() { + return this.scheduler; + } public MeasurementDesc getDescription() { diff --git a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java index ce5a231..250cf79 100644 --- a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java @@ -38,6 +38,7 @@ public class ServerMeasurementTask implements Callable { public ServerMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler, ResourceCapManager manager) { realTask = task; + realTask.setScheduler(null); //added by Clarence this.scheduler = scheduler; this.contextCollector = new ContextCollector(); this.rManager = manager; diff --git a/Mobilyzer/src/com/mobilyzer/UpdateIntent.java b/Mobilyzer/src/com/mobilyzer/UpdateIntent.java index e16b5fa..f6be044 100644 --- a/Mobilyzer/src/com/mobilyzer/UpdateIntent.java +++ b/Mobilyzer/src/com/mobilyzer/UpdateIntent.java @@ -44,6 +44,8 @@ public class UpdateIntent extends Intent { public static final String VIDEO_TASK_PAYLOAD_REBUFFER_TIME = "VIDEO_TASK_PAYLOAD_REBUFFER_TIME"; public static final String VIDEO_TASK_PAYLOAD_BBA_SWITCH_TIME = "VIDEO_TASK_PAYLOAD_BBA_SWITCH_TIME"; public static final String VIDEO_TASK_PAYLOAD_BYTE_USED = "VIDEO_TASK_PAYLOAD_BYTE_USED"; + //added by Clarence + public static final String INTERMEDIATE_RESULT_PAYLOAD = "INTERMEDIATE_RESULT_PAYLOAD"; // Different types of actions that this intent can represent: @@ -81,6 +83,11 @@ public class UpdateIntent extends Intent { PACKAGE_PREFIX + ".DATA_USAGE_ACTION"; public static final String AUTH_ACCOUNT_ACTION = PACKAGE_PREFIX + ".AUTH_ACCOUNT_ACTION"; + + + // added by Clarence + public static final String MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION = + APP_PREFIX + ".MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION"; /** * Creates an intent of the specified action with an optional message diff --git a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java index 59ec096..f371214 100644 --- a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.concurrent.Callable; +import android.content.Context; import android.content.Intent; import com.mobilyzer.MeasurementResult.TaskProgress; @@ -33,6 +34,7 @@ public class UserMeasurementTask implements Callable { public UserMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler) { realTask = task; + realTask.setScheduler(scheduler); //added by Clarence this.scheduler = scheduler; this.contextCollector= new ContextCollector(); } @@ -48,7 +50,10 @@ private void broadcastMeasurementStart() { intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_STARTED); intent.putExtra(UpdateIntent.TASKID_PAYLOAD, realTask.getTaskId()); intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, realTask.getKey()); +// Context context = scheduler.getApplicationContext(); +// context.sendBroadcast(intent); scheduler.sendBroadcast(intent); + } /** @@ -96,9 +101,12 @@ public MeasurementResult[] call() throws MeasurementError { ArrayList> contextResults = contextCollector.stopCollector(); for (MeasurementResult r: results){ + String testIntermediate1 = r.toString(); r.addContextResults(contextResults); r.getDeviceProperty().dnResolvability=contextCollector.dnsConnectivity; r.getDeviceProperty().ipConnectivity=contextCollector.ipConnectivity; + String testIntermediate2 = r.toString(); + } } catch (MeasurementError e) { Logger.e("User measurement " + realTask.getDescriptor() + " has failed"); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java index 9cf9c36..46c888a 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java @@ -165,6 +165,9 @@ public String getDescriptor() { @Override public MeasurementResult[] call() throws MeasurementError { + for (MeasurementTask task: this.tasks){ + task.setScheduler(this.getScheduler()); + } //added by Clarence long timeout=duration; executor=Executors.newFixedThreadPool(this.tasks.size()); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java index 6d26ee3..13868e5 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java @@ -15,6 +15,7 @@ package com.mobilyzer.measurements; +import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; @@ -23,7 +24,9 @@ import com.mobilyzer.Config; import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; +import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; +import com.mobilyzer.UpdateIntent; import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; @@ -71,6 +74,32 @@ public class PingTask extends MeasurementTask{ //Track data consumption for this task to avoid exceeding user's limit private long dataConsumed; + + private MeasurementScheduler scheduler = null; // added by Clarence + + private void broadcastIntermediateMeasurement(MeasurementResult[] results, MeasurementScheduler scheduler) { + this.scheduler = scheduler; + Intent intent = new Intent(); + intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); + //TODO fixed one value priority for all users task? + intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, + MeasurementTask.USER_PRIORITY); + intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); + intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, this.getKey()); + + if (results != null){ + + //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); + intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); + + this.scheduler.sendBroadcast(intent); + }else{ + intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); + + } + + } + /** * Encode ping specific parameters, along with common parameters inherited from MeasurmentDesc * @author wenjiezeng@google.com (Steve Zeng) @@ -356,6 +385,11 @@ private MeasurementResult executePingCmdTask(int ipByteLen) PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult measurementResult = null; + + MeasurementResult IM_measurementResult = null; //added by Clarence + MeasurementResult[] IM_result = null; + IM_result = new MeasurementResult[1]; + // TODO(Wenjie): Add a exhaustive list of ping locations for different // Android phones pingTask.pingExe = Util.pingExecutableBasedOnIPType(ipByteLen); @@ -384,11 +418,13 @@ private MeasurementResult executePingCmdTask(int ipByteLen) ArrayList receivedIcmpSeq = new ArrayList(); double packetLoss = Double.MIN_VALUE; int packetsSent = Config.PING_COUNT_PER_MEASUREMENT; + // Process each line of the ping output and store the rrt in array rrts. while ((line = br.readLine()) != null) { // Ping prints a number of 'param=value' pairs, among which we only need // the 'time=rrt_val' pair String[] extractedValues = Util.extractInfoFromPingOutput(line); + if (extractedValues != null) { int curIcmpSeq = Integer.parseInt(extractedValues[0]); double rrtVal = Double.parseDouble(extractedValues[1]); @@ -409,6 +445,18 @@ private MeasurementResult executePingCmdTask(int ipByteLen) int packetsReceived = packetLossInfo[1]; packetLoss = 1 - ((double) packetsReceived / (double) packetsSent); } + this.scheduler = this.getScheduler(); + if ( this.scheduler != null ){ + if (rrts.size() >= 2 && (rrts.size() < Config.PING_COUNT_PER_MEASUREMENT) && (extractedValues != null) ){ + IM_measurementResult = constructResult(rrts,packetLoss, + rrts.size(),PING_METHOD_CMD); + IM_result[0] = IM_measurementResult; + broadcastIntermediateMeasurement(IM_result,this.scheduler); + + + } + } + //IM_packetsSent++; Logger.i(line); } @@ -452,6 +500,10 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { ArrayList rrts = new ArrayList(); String errorMsg = ""; MeasurementResult result = null; + double packetLoss = Double.MIN_VALUE; //added by Clarence + MeasurementResult IM_measurementResult = null; //added by Clarence + MeasurementResult[] IM_result = null; + IM_result = new MeasurementResult[1]; try { int timeOut = (int) (3000 * (double) pingTask.pingTimeoutSec / @@ -466,11 +518,28 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { if (status) { totalPingDelay += rrtVal; rrts.add((double) rrtVal); + packetLoss = 1 - + ((double) rrts.size() / (i+1)); + dataConsumed += pingTask.packetSizeByte * (i+1) * 2; + this.scheduler = this.getScheduler(); + if ( this.scheduler != null){ + IM_measurementResult = constructResult(rrts,packetLoss, + (i+1),PING_METHOD_JAVA); + IM_result[0] = IM_measurementResult; + broadcastIntermediateMeasurement(IM_result,this.scheduler); + + } + + } } Logger.i("java ping succeeds"); - double packetLoss = 1 - - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); +// double packetLoss = 1 - +// ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); //deleted by Clarence + if (packetLoss == Double.MIN_VALUE) { + packetLoss = 1 - + ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); + } dataConsumed += pingTask.packetSizeByte * Config.PING_COUNT_PER_MEASUREMENT * 2; @@ -505,6 +574,10 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult result = null; + double packetLoss = Double.MIN_VALUE; //added by Clarence + MeasurementResult IM_measurementResult = null; //added by Clarence + MeasurementResult[] IM_result = null; + IM_result = new MeasurementResult[1]; try { long totalPingDelay = 0; @@ -525,12 +598,27 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { pingEndTime = System.currentTimeMillis(); httpClient.disconnect(); rrts.add((double) (pingEndTime - pingStartTime)); + packetLoss = 1 - + ((double) rrts.size() / (i+1)); + dataConsumed += pingTask.packetSizeByte * (i+1) * 2; + this.scheduler = this.getScheduler(); + if ( this.scheduler != null){ + IM_measurementResult = constructResult(rrts,packetLoss, + (i+1),PING_METHOD_HTTP); + IM_result[0] = IM_measurementResult; + broadcastIntermediateMeasurement(IM_result,this.scheduler); + + } } Logger.i("HTTP get ping succeeds"); Logger.i("RTT is " + rrts.toString()); - double packetLoss = 1 - - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); +// double packetLoss = 1 +// - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); + if (packetLoss == Double.MIN_VALUE) { + packetLoss = 1 - + ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); + } dataConsumed += pingTask.packetSizeByte * Config.PING_COUNT_PER_MEASUREMENT * 2; diff --git a/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java b/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java index 7dd1a38..bee358e 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java @@ -169,6 +169,7 @@ public MeasurementResult[] call() throws MeasurementError { try { // futures=executor.invokeAll(this.tasks,timeout,TimeUnit.MILLISECONDS); for(MeasurementTask mt: tasks){ + mt.setScheduler(this.getScheduler()); if(stopFlag){ throw new MeasurementError("Cancelled"); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java index 66a3550..e1faa26 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java @@ -17,7 +17,9 @@ import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; +import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; +import com.mobilyzer.UpdateIntent; import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; @@ -26,6 +28,7 @@ import com.mobilyzer.util.PhoneUtils; import android.content.Context; +import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; @@ -88,6 +91,34 @@ public class TCPThroughputTask extends MeasurementTask { private long duration; private TaskProgress taskProgress; private volatile boolean stopFlag; + + private MeasurementScheduler scheduler = null; // added by Clarence + private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; //added by Clarence + + //added by Clarence, add broadcast to send the intermediate results + + private void broadcastIntermediateMeasurement(MeasurementResult[] results, MeasurementScheduler scheduler) { + this.scheduler = scheduler; + Intent intent = new Intent(); + intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); + //TODO fixed one value priority for all users task? + intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, + MeasurementTask.USER_PRIORITY); + intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); + intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, this.getKey()); + + if (results != null){ + + //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); + intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); + + this.scheduler.sendBroadcast(intent); + }else{ + intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); + + } + + } // class constructor public TCPThroughputTask(MeasurementDesc desc) { @@ -530,13 +561,17 @@ private void uplink() throws MeasurementError, IOException, InterruptedException long startTime = System.currentTimeMillis(); long endTime = startTime; + int data_limit_byte_up = (int)(((TCPThroughputDesc)measurementDesc).data_limit_mb_up *this.KBYTE*this.KBYTE); byte[] uplinkBuffer = new byte[((TCPThroughputDesc)measurementDesc).pkt_size_up_bytes]; this.genRandomByteArray(uplinkBuffer); + + try { + long totalDuration = (long)(this.KSEC* ((TCPThroughputDesc)measurementDesc).duration_period_sec + @@ -550,6 +585,10 @@ private void uplink() throws MeasurementError, IOException, InterruptedException oStream.write(uplinkBuffer, 0, uplinkBuffer.length); oStream.flush(); endTime = System.currentTimeMillis(); + + + + this.totalSendSize += ((TCPThroughputDesc)measurementDesc).pkt_size_up_bytes; if (this.DATA_LIMIT_ON && @@ -576,6 +615,9 @@ private void uplink() throws MeasurementError, IOException, InterruptedException byte [] resultMsg = new byte[this.BUFFER_SIZE]; int resultMsgLen = iStream.read(resultMsg, 0, resultMsg.length); if (resultMsgLen > 0) { + + MeasurementResult IntermediateResult = null; //added by Clarence + String resultMsgStr = new String(resultMsg).substring(0, resultMsgLen); // Sample result string is "1111.11#2222.22#3333.33"; Logger.i("Uplink result from server is " + resultMsgStr); @@ -585,6 +627,23 @@ private void uplink() throws MeasurementError, IOException, InterruptedException sampleResult = Double.valueOf(tps_result_str[i]); this.samplingResults = this.insertWithOrder(this.samplingResults, sampleResult); + + //added by Clarence + this.scheduler = this.getScheduler(); + if (this.scheduler != null){ + PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); + IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, + Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, + System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); + IntermediateResult.addResult("tcp_speed_results", this.samplingResults); + IntermediateResult.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED); + IntermediateResult.addResult("duration", this.taskDuration); + IntermediateResult.addResult("server_version", this.serverVersion); + MeasurementResult[] IM_mrArray = new MeasurementResult[1]; + IM_mrArray[0] = IntermediateResult; + broadcastIntermediateMeasurement(IM_mrArray,this.scheduler); + + } } } Logger.i("Total number of sampling result is " + this.samplingResults.size()); @@ -679,6 +738,9 @@ private void downlink() throws MeasurementError, IOException { * @param time period increment */ private void updateSize(int delta) { + + MeasurementResult IntermediateResult = null; //added by Clarence + double gtime = System.currentTimeMillis() - this.taskStartTime; //ignore slow start if (gtime<((TCPThroughputDesc)measurementDesc).slow_start_period_sec*this.KSEC) @@ -696,6 +758,24 @@ private void updateSize(int delta) { this.samplingResults = this.insertWithOrder(this.samplingResults, throughput); this.accumulativeSize = 0; this.startSampleTime = System.currentTimeMillis(); + + //added by Clarence + this.scheduler = this.getScheduler(); + if (this.scheduler != null){ + PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); + IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, + Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, + System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); + IntermediateResult.addResult("tcp_speed_results", this.samplingResults); + IntermediateResult.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED); + IntermediateResult.addResult("duration", time); + IntermediateResult.addResult("server_version", this.serverVersion); + MeasurementResult[] IM_mrArray = new MeasurementResult[1]; + IM_mrArray[0] = IntermediateResult; + broadcastIntermediateMeasurement(IM_mrArray,this.scheduler); + + } + } } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java index 14fba2f..9803e3f 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java @@ -14,9 +14,11 @@ package com.mobilyzer.measurements; +import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -42,8 +44,10 @@ import com.mobilyzer.Config; import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; +import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; import com.mobilyzer.PreemptibleMeasurementTask; +import com.mobilyzer.UpdateIntent; import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; @@ -83,9 +87,37 @@ public class TracerouteTask extends MeasurementTask implements PreemptibleMeasur private long totalRunningTime; private int ttl; private int maxHopCount; + // Track data consumption for this task to avoid exceeding user's limit private long dataConsumed; + private MeasurementScheduler scheduler = null; // added by Clarence + private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; //added by Clarence + + //added by Clarence, add broadcast to send the intermediate results + + private void broadcastIntermediateMeasurement(MeasurementResult[] results, MeasurementScheduler scheduler) { + this.scheduler = scheduler; + Intent intent = new Intent(); + intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); + //TODO fixed one value priority for all users task? + intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, + MeasurementTask.USER_PRIORITY); + intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); + intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, this.getKey()); + + if (results != null){ + + //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); + intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); + + this.scheduler.sendBroadcast(intent); + }else{ + intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); + + } + + } /** * The description of the Traceroute measurement @@ -110,6 +142,8 @@ public static class TracerouteDesc extends MeasurementDesc { public String preCondition; private int parallelProbeNum; + + public TracerouteDesc(String key, Date startTime, Date endTime, double intervalSec, long count, long priority, int contextIntervalSec, Map params) @@ -323,6 +357,9 @@ public MeasurementResult[] call() throws MeasurementError { throw new MeasurementError("target " + target + " cannot be resolved"); } MeasurementResult result = null; + MeasurementResult IntermediateResult = null; //added by Clarence + + ExecutorService hopExecutorService = Executors.newFixedThreadPool(task.parallelProbeNum); @@ -343,11 +380,11 @@ public MeasurementResult[] call() throws MeasurementError { target); taskCompletionService.submit(new HopExecutor(task.pingsPerHop, command, hostIp, ttl)); ttl++; - } + } for (int tasksHandled = 0; tasksHandled < maxHopCount; tasksHandled++) { - + try { Future hopResult = taskCompletionService.take(); HopInfo hop = hopResult.get(); @@ -376,7 +413,9 @@ public MeasurementResult[] call() throws MeasurementError { new MeasurementResult(phoneUtils.getDeviceInfo().deviceId, phoneUtils.getDeviceProperty(this.getKey()), TracerouteTask.TYPE, System.currentTimeMillis() * 1000, taskProgress, this.measurementDesc); + result.addResult("num_hops", hop.ttl); + for (int i = 0; i < hopHosts.size(); i++) { HopInfo hopInfo = hopHosts.get(i); int hostIdx = 1; @@ -389,6 +428,7 @@ public MeasurementResult[] call() throws MeasurementError { } } Logger.i(MeasurementJsonConvertor.toJsonString(result)); + MeasurementResult[] mrArray = new MeasurementResult[1]; mrArray[0] = result; return mrArray; @@ -397,6 +437,39 @@ public MeasurementResult[] call() throws MeasurementError { } } + //added by Clarence + this.scheduler = this.getScheduler(); + if (this.scheduler != null){ + + PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); + IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, + Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TracerouteTask.TYPE, + System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); + + IntermediateResult.addResult("num_hops", hop.ttl); + + for (int i = 0; i < hopHosts.size(); i++) { + HopInfo IM_hopInfo = hopHosts.get(i); + int IM_hostIdx = 1; //added by Clarence + for (String IM_host : IM_hopInfo.hosts) { + IntermediateResult.addResult("hop_" + IM_hopInfo.ttl + "_addr_" + IM_hostIdx++, IM_host); + } + IntermediateResult.addResult("hop_" + IM_hopInfo.ttl + "_rtt_ms", String.format("%.3f", IM_hopInfo.rtt)); + + } + +// for (String IM_host :hop.hosts){ +// IntermediateResult.addResult("hop_" + hop.ttl + "_addr_" + IM_hostIdx++, IM_host); +// } +// IntermediateResult.addResult("hop_" + hop.ttl + "_rtt_ms", String.format("%.3f", hop.rtt)); + + MeasurementResult[] IM_mrArray = new MeasurementResult[1]; + IM_mrArray[0] = IntermediateResult; + broadcastIntermediateMeasurement(IM_mrArray,this.scheduler); + } + + + } catch (InterruptedException e) { e.printStackTrace(); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java b/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java index ee5ffe4..2b85429 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java @@ -42,7 +42,7 @@ * * UDPBurstTask provides two types of measurements, Burst Up and Burst Down, described next. * - * 1. UDPBurst Up: the device sends sends a burst of UDPBurstCount UDP packets and waits for a + * 1. UDPBurst Up: the device sends a burst of UDPBurstCount UDP packets and waits for a * response from the server that includes the number of packets that the server received * * 2. UDPBurst Down: the device sends a request to a remote server on a UDP port and the server From 531dc8137896342eaf402417fe224f463b183029 Mon Sep 17 00:00:00 2001 From: ChaoKong Date: Wed, 26 Aug 2015 18:28:20 -0400 Subject: [PATCH 2/6] add intermediate results --- .../src/com/mobilyzer/MeasurementTask.java | 18 ++++---- .../com/mobilyzer/ServerMeasurementTask.java | 2 +- .../com/mobilyzer/UserMeasurementTask.java | 2 +- .../mobilyzer/measurements/ParallelTask.java | 2 +- .../com/mobilyzer/measurements/PingTask.java | 27 ++++++------ .../measurements/SequentialTask.java | 2 +- .../measurements/TCPThroughputTask.java | 41 ++++++++++--------- .../measurements/TracerouteTask.java | 27 ++++++------ 8 files changed, 64 insertions(+), 57 deletions(-) diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java index 8bc0318..b756378 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java @@ -7,6 +7,10 @@ import java.util.Set; import java.util.concurrent.Callable; +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; + import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.measurements.DnsLookupTask; import com.mobilyzer.measurements.HttpTask; @@ -19,8 +23,7 @@ import com.mobilyzer.measurements.UDPBurstTask; import com.mobilyzer.measurements.VideoQoETask; -import android.os.Parcel; -import android.os.Parcelable; + public abstract class MeasurementTask implements @@ -30,7 +33,8 @@ public abstract class MeasurementTask protected MeasurementDesc measurementDesc; protected String taskId; - private MeasurementScheduler scheduler; // added by Clarence + //private MeasurementScheduler scheduler; // added by Clarence + private Context context = null; //added by Clarence public static final int USER_PRIORITY = Integer.MIN_VALUE; @@ -118,12 +122,12 @@ public void setKey(String key) { } // added by Clarence, pass scheduler to every specific task - public void setScheduler(MeasurementScheduler scheduler) { - this.scheduler = scheduler; + public void setContext(Context context) { + this.context = context; } - public MeasurementScheduler getScheduler() { - return this.scheduler; + public Context getContext() { + return this.context; } diff --git a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java index 250cf79..4dcbd5c 100644 --- a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java @@ -38,7 +38,7 @@ public class ServerMeasurementTask implements Callable { public ServerMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler, ResourceCapManager manager) { realTask = task; - realTask.setScheduler(null); //added by Clarence + realTask.setContext(null); //added by Clarence this.scheduler = scheduler; this.contextCollector = new ContextCollector(); this.rManager = manager; diff --git a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java index f371214..7940838 100644 --- a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java @@ -34,7 +34,7 @@ public class UserMeasurementTask implements Callable { public UserMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler) { realTask = task; - realTask.setScheduler(scheduler); //added by Clarence + realTask.setContext(scheduler.getApplicationContext()); //added by Clarence this.scheduler = scheduler; this.contextCollector= new ContextCollector(); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java index 46c888a..bef5df7 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java @@ -166,7 +166,7 @@ public String getDescriptor() { @Override public MeasurementResult[] call() throws MeasurementError { for (MeasurementTask task: this.tasks){ - task.setScheduler(this.getScheduler()); + task.setContext(this.getContext()); } //added by Clarence long timeout=duration; executor=Executors.newFixedThreadPool(this.tasks.size()); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java index 13868e5..ed1e65c 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java @@ -15,6 +15,7 @@ package com.mobilyzer.measurements; +import android.content.Context; import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; @@ -75,10 +76,10 @@ public class PingTask extends MeasurementTask{ private long dataConsumed; - private MeasurementScheduler scheduler = null; // added by Clarence + private Context context = null; // added by Clarence - private void broadcastIntermediateMeasurement(MeasurementResult[] results, MeasurementScheduler scheduler) { - this.scheduler = scheduler; + private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { + this.context = context; Intent intent = new Intent(); intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); //TODO fixed one value priority for all users task? @@ -92,7 +93,7 @@ private void broadcastIntermediateMeasurement(MeasurementResult[] results, Measu //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); - this.scheduler.sendBroadcast(intent); + this.context.sendBroadcast(intent); }else{ intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); @@ -445,13 +446,13 @@ private MeasurementResult executePingCmdTask(int ipByteLen) int packetsReceived = packetLossInfo[1]; packetLoss = 1 - ((double) packetsReceived / (double) packetsSent); } - this.scheduler = this.getScheduler(); - if ( this.scheduler != null ){ + this.context = this.getContext(); + if ( this.context != null ){ if (rrts.size() >= 2 && (rrts.size() < Config.PING_COUNT_PER_MEASUREMENT) && (extractedValues != null) ){ IM_measurementResult = constructResult(rrts,packetLoss, rrts.size(),PING_METHOD_CMD); IM_result[0] = IM_measurementResult; - broadcastIntermediateMeasurement(IM_result,this.scheduler); + broadcastIntermediateMeasurement(IM_result,this.context); } @@ -521,12 +522,12 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { packetLoss = 1 - ((double) rrts.size() / (i+1)); dataConsumed += pingTask.packetSizeByte * (i+1) * 2; - this.scheduler = this.getScheduler(); - if ( this.scheduler != null){ + this.context = this.getContext(); + if ( this.context != null){ IM_measurementResult = constructResult(rrts,packetLoss, (i+1),PING_METHOD_JAVA); IM_result[0] = IM_measurementResult; - broadcastIntermediateMeasurement(IM_result,this.scheduler); + broadcastIntermediateMeasurement(IM_result,this.context); } @@ -601,12 +602,12 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { packetLoss = 1 - ((double) rrts.size() / (i+1)); dataConsumed += pingTask.packetSizeByte * (i+1) * 2; - this.scheduler = this.getScheduler(); - if ( this.scheduler != null){ + this.context = this.getContext(); + if ( this.context != null){ IM_measurementResult = constructResult(rrts,packetLoss, (i+1),PING_METHOD_HTTP); IM_result[0] = IM_measurementResult; - broadcastIntermediateMeasurement(IM_result,this.scheduler); + broadcastIntermediateMeasurement(IM_result,this.context); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java b/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java index bee358e..61a4cb8 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java @@ -169,7 +169,7 @@ public MeasurementResult[] call() throws MeasurementError { try { // futures=executor.invokeAll(this.tasks,timeout,TimeUnit.MILLISECONDS); for(MeasurementTask mt: tasks){ - mt.setScheduler(this.getScheduler()); + mt.setContext(this.getContext()); if(stopFlag){ throw new MeasurementError("Cancelled"); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java index e1faa26..8c294a8 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java @@ -3,8 +3,8 @@ package com.mobilyzer.measurements; import java.io.IOException; -import java.io.InvalidClassException; import java.io.InputStream; +import java.io.InvalidClassException; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; @@ -15,22 +15,23 @@ import java.util.Map; import java.util.Random; +import android.content.Context; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; + import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; +import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; import com.mobilyzer.UpdateIntent; -import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; import com.mobilyzer.util.MLabNS; import com.mobilyzer.util.MeasurementJsonConvertor; import com.mobilyzer.util.PhoneUtils; -import android.content.Context; -import android.content.Intent; -import android.os.Parcel; -import android.os.Parcelable; /** * @author Haokun Luo @@ -92,13 +93,13 @@ public class TCPThroughputTask extends MeasurementTask { private TaskProgress taskProgress; private volatile boolean stopFlag; - private MeasurementScheduler scheduler = null; // added by Clarence + private Context IM_context = null; // added by Clarence private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; //added by Clarence //added by Clarence, add broadcast to send the intermediate results - private void broadcastIntermediateMeasurement(MeasurementResult[] results, MeasurementScheduler scheduler) { - this.scheduler = scheduler; + private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { + this.IM_context = context; Intent intent = new Intent(); intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); //TODO fixed one value priority for all users task? @@ -112,7 +113,7 @@ private void broadcastIntermediateMeasurement(MeasurementResult[] results, Measu //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); - this.scheduler.sendBroadcast(intent); + this.IM_context.sendBroadcast(intent); }else{ intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); @@ -544,6 +545,8 @@ private void uplink() throws MeasurementError, IOException, InterruptedException Socket tcpSocket = null; InputStream iStream = null; OutputStream oStream = null; + + try { tcpSocket = new Socket(); @@ -561,6 +564,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException long startTime = System.currentTimeMillis(); long endTime = startTime; + int data_limit_byte_up = (int)(((TCPThroughputDesc)measurementDesc).data_limit_mb_up @@ -585,10 +589,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException oStream.write(uplinkBuffer, 0, uplinkBuffer.length); oStream.flush(); endTime = System.currentTimeMillis(); - - - - + this.totalSendSize += ((TCPThroughputDesc)measurementDesc).pkt_size_up_bytes; if (this.DATA_LIMIT_ON && @@ -629,8 +630,8 @@ private void uplink() throws MeasurementError, IOException, InterruptedException sampleResult); //added by Clarence - this.scheduler = this.getScheduler(); - if (this.scheduler != null){ + this.IM_context = this.getContext(); + if (this.IM_context != null){ PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, @@ -641,7 +642,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException IntermediateResult.addResult("server_version", this.serverVersion); MeasurementResult[] IM_mrArray = new MeasurementResult[1]; IM_mrArray[0] = IntermediateResult; - broadcastIntermediateMeasurement(IM_mrArray,this.scheduler); + broadcastIntermediateMeasurement(IM_mrArray,this.IM_context); } } @@ -760,8 +761,8 @@ private void updateSize(int delta) { this.startSampleTime = System.currentTimeMillis(); //added by Clarence - this.scheduler = this.getScheduler(); - if (this.scheduler != null){ + this.IM_context = this.getContext(); + if (this.IM_context != null){ PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, @@ -772,7 +773,7 @@ private void updateSize(int delta) { IntermediateResult.addResult("server_version", this.serverVersion); MeasurementResult[] IM_mrArray = new MeasurementResult[1]; IM_mrArray[0] = IntermediateResult; - broadcastIntermediateMeasurement(IM_mrArray,this.scheduler); + broadcastIntermediateMeasurement(IM_mrArray,this.IM_context); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java index 9803e3f..10ef4ba 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java @@ -14,11 +14,6 @@ package com.mobilyzer.measurements; -import android.content.Intent; -import android.os.Parcel; -import android.os.Parcelable; - - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -41,14 +36,19 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import android.content.Context; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; + import com.mobilyzer.Config; import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; +import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; import com.mobilyzer.PreemptibleMeasurementTask; import com.mobilyzer.UpdateIntent; -import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; import com.mobilyzer.util.MeasurementJsonConvertor; @@ -56,6 +56,7 @@ import com.mobilyzer.util.Util; + /** * A Callable task that handles Traceroute measurements */ @@ -91,13 +92,13 @@ public class TracerouteTask extends MeasurementTask implements PreemptibleMeasur // Track data consumption for this task to avoid exceeding user's limit private long dataConsumed; - private MeasurementScheduler scheduler = null; // added by Clarence + private Context context = null; // added by Clarence private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; //added by Clarence //added by Clarence, add broadcast to send the intermediate results - private void broadcastIntermediateMeasurement(MeasurementResult[] results, MeasurementScheduler scheduler) { - this.scheduler = scheduler; + private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { + this.context = context; Intent intent = new Intent(); intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); //TODO fixed one value priority for all users task? @@ -111,7 +112,7 @@ private void broadcastIntermediateMeasurement(MeasurementResult[] results, Measu //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); - this.scheduler.sendBroadcast(intent); + this.context.sendBroadcast(intent); }else{ intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); @@ -438,8 +439,8 @@ public MeasurementResult[] call() throws MeasurementError { } } //added by Clarence - this.scheduler = this.getScheduler(); - if (this.scheduler != null){ + this.context = this.getContext(); + if (this.context != null){ PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, @@ -465,7 +466,7 @@ public MeasurementResult[] call() throws MeasurementError { MeasurementResult[] IM_mrArray = new MeasurementResult[1]; IM_mrArray[0] = IntermediateResult; - broadcastIntermediateMeasurement(IM_mrArray,this.scheduler); + broadcastIntermediateMeasurement(IM_mrArray,this.context); } From 1105fca7f264fb391dd343e75a2a29601817ed7f Mon Sep 17 00:00:00 2001 From: ChaoKong Date: Sat, 3 Oct 2015 18:08:51 -0400 Subject: [PATCH 3/6] Make modifications:1,remove added by Clarence, 2, Unify UpperCamelCase and LowerCamelCase, 3, change some variables name --- Mobilyzer/project.properties | 6 +-- .../com/mobilyzer/MeasurementScheduler.java | 4 +- .../src/com/mobilyzer/MeasurementTask.java | 6 +-- .../com/mobilyzer/ServerMeasurementTask.java | 2 +- Mobilyzer/src/com/mobilyzer/UpdateIntent.java | 3 +- .../com/mobilyzer/UserMeasurementTask.java | 6 +-- .../mobilyzer/measurements/ParallelTask.java | 2 +- .../com/mobilyzer/measurements/PingTask.java | 48 +++++++++---------- .../measurements/TCPThroughputTask.java | 17 ++++--- .../measurements/TracerouteTask.java | 36 +++++++------- 10 files changed, 62 insertions(+), 68 deletions(-) diff --git a/Mobilyzer/project.properties b/Mobilyzer/project.properties index 06a801a..bf2469f 100644 --- a/Mobilyzer/project.properties +++ b/Mobilyzer/project.properties @@ -11,7 +11,7 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-18 +target=android-21 android.library=true -android.library.reference.1=../../../android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib -android.library.reference.2=../../ModifiedExoPlayerLibrary/library/src/main +android.library.reference.1=../../ExoPlayerLib +android.library.reference.2=../../google-play-services_lib diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java b/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java index 53b3b56..b9e3cd5 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java @@ -185,7 +185,7 @@ public void onCreate() { filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION); filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION); filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION); - //added by Clarence + filter.addAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); @@ -326,7 +326,7 @@ public void onReceive(Context context, Intent intent) { } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals( Config.TASK_RESUMED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); - } //added by Clarence + } } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION)){ String IM_taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD); String IM_taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD); diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java index b756378..b610b4d 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java @@ -33,8 +33,8 @@ public abstract class MeasurementTask protected MeasurementDesc measurementDesc; protected String taskId; - //private MeasurementScheduler scheduler; // added by Clarence - private Context context = null; //added by Clarence + //private MeasurementScheduler scheduler; + private Context context = null; public static final int USER_PRIORITY = Integer.MIN_VALUE; @@ -121,7 +121,7 @@ public void setKey(String key) { this.measurementDesc.key = key; } - // added by Clarence, pass scheduler to every specific task + // pass scheduler to every specific task public void setContext(Context context) { this.context = context; } diff --git a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java index 4dcbd5c..95844da 100644 --- a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java @@ -38,7 +38,7 @@ public class ServerMeasurementTask implements Callable { public ServerMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler, ResourceCapManager manager) { realTask = task; - realTask.setContext(null); //added by Clarence + realTask.setContext(null); this.scheduler = scheduler; this.contextCollector = new ContextCollector(); this.rManager = manager; diff --git a/Mobilyzer/src/com/mobilyzer/UpdateIntent.java b/Mobilyzer/src/com/mobilyzer/UpdateIntent.java index f6be044..1e7f9e0 100644 --- a/Mobilyzer/src/com/mobilyzer/UpdateIntent.java +++ b/Mobilyzer/src/com/mobilyzer/UpdateIntent.java @@ -44,7 +44,6 @@ public class UpdateIntent extends Intent { public static final String VIDEO_TASK_PAYLOAD_REBUFFER_TIME = "VIDEO_TASK_PAYLOAD_REBUFFER_TIME"; public static final String VIDEO_TASK_PAYLOAD_BBA_SWITCH_TIME = "VIDEO_TASK_PAYLOAD_BBA_SWITCH_TIME"; public static final String VIDEO_TASK_PAYLOAD_BYTE_USED = "VIDEO_TASK_PAYLOAD_BYTE_USED"; - //added by Clarence public static final String INTERMEDIATE_RESULT_PAYLOAD = "INTERMEDIATE_RESULT_PAYLOAD"; @@ -85,7 +84,7 @@ public class UpdateIntent extends Intent { PACKAGE_PREFIX + ".AUTH_ACCOUNT_ACTION"; - // added by Clarence + public static final String MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION = APP_PREFIX + ".MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION"; diff --git a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java index 7940838..2e90d73 100644 --- a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java @@ -34,7 +34,7 @@ public class UserMeasurementTask implements Callable { public UserMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler) { realTask = task; - realTask.setContext(scheduler.getApplicationContext()); //added by Clarence + realTask.setContext(scheduler.getApplicationContext()); this.scheduler = scheduler; this.contextCollector= new ContextCollector(); } @@ -101,11 +101,11 @@ public MeasurementResult[] call() throws MeasurementError { ArrayList> contextResults = contextCollector.stopCollector(); for (MeasurementResult r: results){ - String testIntermediate1 = r.toString(); + String testIntermediateFirst = r.toString(); r.addContextResults(contextResults); r.getDeviceProperty().dnResolvability=contextCollector.dnsConnectivity; r.getDeviceProperty().ipConnectivity=contextCollector.ipConnectivity; - String testIntermediate2 = r.toString(); + String testIntermediateSecond = r.toString(); } } catch (MeasurementError e) { diff --git a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java index bef5df7..f458f1d 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java @@ -167,7 +167,7 @@ public String getDescriptor() { public MeasurementResult[] call() throws MeasurementError { for (MeasurementTask task: this.tasks){ task.setContext(this.getContext()); - } //added by Clarence + } long timeout=duration; executor=Executors.newFixedThreadPool(this.tasks.size()); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java index ed1e65c..5901f0c 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java @@ -76,9 +76,9 @@ public class PingTask extends MeasurementTask{ private long dataConsumed; - private Context context = null; // added by Clarence + private Context context = null; - private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { + private void broadcastIntermediateResults(MeasurementResult[] results, Context context) { this.context = context; Intent intent = new Intent(); intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); @@ -387,9 +387,9 @@ private MeasurementResult executePingCmdTask(int ipByteLen) String errorMsg = ""; MeasurementResult measurementResult = null; - MeasurementResult IM_measurementResult = null; //added by Clarence - MeasurementResult[] IM_result = null; - IM_result = new MeasurementResult[1]; + MeasurementResult intermediateMeasurementResults = null; + MeasurementResult[] intermediateResult = null; + intermediateResult = new MeasurementResult[1]; // TODO(Wenjie): Add a exhaustive list of ping locations for different // Android phones @@ -449,15 +449,15 @@ private MeasurementResult executePingCmdTask(int ipByteLen) this.context = this.getContext(); if ( this.context != null ){ if (rrts.size() >= 2 && (rrts.size() < Config.PING_COUNT_PER_MEASUREMENT) && (extractedValues != null) ){ - IM_measurementResult = constructResult(rrts,packetLoss, + intermediateMeasurementResults = constructResult(rrts,packetLoss, rrts.size(),PING_METHOD_CMD); - IM_result[0] = IM_measurementResult; - broadcastIntermediateMeasurement(IM_result,this.context); + intermediateResult[0] = intermediateMeasurementResults; + broadcastIntermediateResults(intermediateResult,this.context); } } - //IM_packetsSent++; + Logger.i(line); } @@ -501,10 +501,10 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { ArrayList rrts = new ArrayList(); String errorMsg = ""; MeasurementResult result = null; - double packetLoss = Double.MIN_VALUE; //added by Clarence - MeasurementResult IM_measurementResult = null; //added by Clarence - MeasurementResult[] IM_result = null; - IM_result = new MeasurementResult[1]; + double packetLoss = Double.MIN_VALUE; + MeasurementResult intermediateMeasurementResults = null; + MeasurementResult[] intermediateResult = null; + intermediateResult = new MeasurementResult[1]; try { int timeOut = (int) (3000 * (double) pingTask.pingTimeoutSec / @@ -524,10 +524,10 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { dataConsumed += pingTask.packetSizeByte * (i+1) * 2; this.context = this.getContext(); if ( this.context != null){ - IM_measurementResult = constructResult(rrts,packetLoss, + intermediateMeasurementResults = constructResult(rrts,packetLoss, (i+1),PING_METHOD_JAVA); - IM_result[0] = IM_measurementResult; - broadcastIntermediateMeasurement(IM_result,this.context); + intermediateResult[0] = intermediateMeasurementResults; + broadcastIntermediateResults(intermediateResult,this.context); } @@ -536,7 +536,7 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { } Logger.i("java ping succeeds"); // double packetLoss = 1 - -// ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); //deleted by Clarence +// ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); if (packetLoss == Double.MIN_VALUE) { packetLoss = 1 - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); @@ -575,10 +575,10 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult result = null; - double packetLoss = Double.MIN_VALUE; //added by Clarence - MeasurementResult IM_measurementResult = null; //added by Clarence - MeasurementResult[] IM_result = null; - IM_result = new MeasurementResult[1]; + double packetLoss = Double.MIN_VALUE; + MeasurementResult intermediateMeasurementResults = null; + MeasurementResult[] intermediateResult = null; + intermediateResult = new MeasurementResult[1]; try { long totalPingDelay = 0; @@ -604,10 +604,10 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { dataConsumed += pingTask.packetSizeByte * (i+1) * 2; this.context = this.getContext(); if ( this.context != null){ - IM_measurementResult = constructResult(rrts,packetLoss, + intermediateMeasurementResults = constructResult(rrts,packetLoss, (i+1),PING_METHOD_HTTP); - IM_result[0] = IM_measurementResult; - broadcastIntermediateMeasurement(IM_result,this.context); + intermediateResult[0] = intermediateMeasurementResults; + broadcastIntermediateResults(intermediateResult,this.context); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java index 8c294a8..921c3cf 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java @@ -93,16 +93,16 @@ public class TCPThroughputTask extends MeasurementTask { private TaskProgress taskProgress; private volatile boolean stopFlag; - private Context IM_context = null; // added by Clarence - private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; //added by Clarence + private Context IM_context = null; + private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; - //added by Clarence, add broadcast to send the intermediate results + // add broadcast to send the intermediate results private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { this.IM_context = context; Intent intent = new Intent(); intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); - //TODO fixed one value priority for all users task? + intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, MeasurementTask.USER_PRIORITY); intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); @@ -617,7 +617,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException int resultMsgLen = iStream.read(resultMsg, 0, resultMsg.length); if (resultMsgLen > 0) { - MeasurementResult IntermediateResult = null; //added by Clarence + MeasurementResult IntermediateResult = null; String resultMsgStr = new String(resultMsg).substring(0, resultMsgLen); // Sample result string is "1111.11#2222.22#3333.33"; @@ -628,8 +628,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException sampleResult = Double.valueOf(tps_result_str[i]); this.samplingResults = this.insertWithOrder(this.samplingResults, sampleResult); - - //added by Clarence + this.IM_context = this.getContext(); if (this.IM_context != null){ PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); @@ -740,7 +739,7 @@ private void downlink() throws MeasurementError, IOException { */ private void updateSize(int delta) { - MeasurementResult IntermediateResult = null; //added by Clarence + MeasurementResult IntermediateResult = null; double gtime = System.currentTimeMillis() - this.taskStartTime; //ignore slow start @@ -760,7 +759,7 @@ private void updateSize(int delta) { this.accumulativeSize = 0; this.startSampleTime = System.currentTimeMillis(); - //added by Clarence + this.IM_context = this.getContext(); if (this.IM_context != null){ PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java index 10ef4ba..1f95c0f 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java @@ -92,10 +92,10 @@ public class TracerouteTask extends MeasurementTask implements PreemptibleMeasur // Track data consumption for this task to avoid exceeding user's limit private long dataConsumed; - private Context context = null; // added by Clarence - private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; //added by Clarence + private Context context = null; + private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; - //added by Clarence, add broadcast to send the intermediate results + // add broadcast to send the intermediate results private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { this.context = context; @@ -358,7 +358,7 @@ public MeasurementResult[] call() throws MeasurementError { throw new MeasurementError("target " + target + " cannot be resolved"); } MeasurementResult result = null; - MeasurementResult IntermediateResult = null; //added by Clarence + MeasurementResult intermediateResult = null; @@ -438,35 +438,31 @@ public MeasurementResult[] call() throws MeasurementError { } } - //added by Clarence + this.context = this.getContext(); if (this.context != null){ PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); - IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, + intermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TracerouteTask.TYPE, System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); - IntermediateResult.addResult("num_hops", hop.ttl); + intermediateResult.addResult("num_hops", hop.ttl); for (int i = 0; i < hopHosts.size(); i++) { - HopInfo IM_hopInfo = hopHosts.get(i); - int IM_hostIdx = 1; //added by Clarence - for (String IM_host : IM_hopInfo.hosts) { - IntermediateResult.addResult("hop_" + IM_hopInfo.ttl + "_addr_" + IM_hostIdx++, IM_host); + HopInfo intermediateHopInfo = hopHosts.get(i); + int intermediateHostIdx = 1; + for (String intermediateHost : intermediateHopInfo.hosts) { + intermediateResult.addResult("hop_" + intermediateHopInfo.ttl + "_addr_" + intermediateHostIdx++, intermediateHost); } - IntermediateResult.addResult("hop_" + IM_hopInfo.ttl + "_rtt_ms", String.format("%.3f", IM_hopInfo.rtt)); + intermediateResult.addResult("hop_" + intermediateHopInfo.ttl + "_rtt_ms", String.format("%.3f", intermediateHopInfo.rtt)); } -// for (String IM_host :hop.hosts){ -// IntermediateResult.addResult("hop_" + hop.ttl + "_addr_" + IM_hostIdx++, IM_host); -// } -// IntermediateResult.addResult("hop_" + hop.ttl + "_rtt_ms", String.format("%.3f", hop.rtt)); - - MeasurementResult[] IM_mrArray = new MeasurementResult[1]; - IM_mrArray[0] = IntermediateResult; - broadcastIntermediateMeasurement(IM_mrArray,this.context); + + MeasurementResult[] intermediateMrArray = new MeasurementResult[1]; + intermediateMrArray[0] = intermediateResult; + broadcastIntermediateMeasurement(intermediateMrArray,this.context); } From 838942b45122123028a48935739c42262adeddc7 Mon Sep 17 00:00:00 2001 From: ChaoKong Date: Tue, 6 Oct 2015 16:49:23 -0400 Subject: [PATCH 4/6] remove the intermediate results of uplink in throughput, which is useless --- .../measurements/TCPThroughputTask.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java index 921c3cf..dc33acf 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java @@ -617,7 +617,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException int resultMsgLen = iStream.read(resultMsg, 0, resultMsg.length); if (resultMsgLen > 0) { - MeasurementResult IntermediateResult = null; +// MeasurementResult IntermediateResult = null; String resultMsgStr = new String(resultMsg).substring(0, resultMsgLen); // Sample result string is "1111.11#2222.22#3333.33"; @@ -629,21 +629,21 @@ private void uplink() throws MeasurementError, IOException, InterruptedException this.samplingResults = this.insertWithOrder(this.samplingResults, sampleResult); - this.IM_context = this.getContext(); - if (this.IM_context != null){ - PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); - IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, - Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, - System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); - IntermediateResult.addResult("tcp_speed_results", this.samplingResults); - IntermediateResult.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED); - IntermediateResult.addResult("duration", this.taskDuration); - IntermediateResult.addResult("server_version", this.serverVersion); - MeasurementResult[] IM_mrArray = new MeasurementResult[1]; - IM_mrArray[0] = IntermediateResult; - broadcastIntermediateMeasurement(IM_mrArray,this.IM_context); - - } +// this.IM_context = this.getContext(); +// if (this.IM_context != null){ +// PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); +// IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, +// Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, +// System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); +// IntermediateResult.addResult("tcp_speed_results", this.samplingResults); +// IntermediateResult.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED); +// IntermediateResult.addResult("duration", this.taskDuration); +// IntermediateResult.addResult("server_version", this.serverVersion); +// MeasurementResult[] IM_mrArray = new MeasurementResult[1]; +// IM_mrArray[0] = IntermediateResult; +// broadcastIntermediateMeasurement(IM_mrArray,this.IM_context); +// +// } } } Logger.i("Total number of sampling result is " + this.samplingResults.size()); From f1a8dd5d9a9a6091033f915e10fe19572465da73 Mon Sep 17 00:00:00 2001 From: ChaoKong Date: Tue, 6 Oct 2015 19:58:37 -0400 Subject: [PATCH 5/6] remove the unnecessary annotations of intermediate results of uplink in throughput --- .../measurements/TCPThroughputTask.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java index dc33acf..c0a565c 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java @@ -617,7 +617,7 @@ private void uplink() throws MeasurementError, IOException, InterruptedException int resultMsgLen = iStream.read(resultMsg, 0, resultMsg.length); if (resultMsgLen > 0) { -// MeasurementResult IntermediateResult = null; + String resultMsgStr = new String(resultMsg).substring(0, resultMsgLen); // Sample result string is "1111.11#2222.22#3333.33"; @@ -629,21 +629,6 @@ private void uplink() throws MeasurementError, IOException, InterruptedException this.samplingResults = this.insertWithOrder(this.samplingResults, sampleResult); -// this.IM_context = this.getContext(); -// if (this.IM_context != null){ -// PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); -// IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, -// Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, -// System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); -// IntermediateResult.addResult("tcp_speed_results", this.samplingResults); -// IntermediateResult.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED); -// IntermediateResult.addResult("duration", this.taskDuration); -// IntermediateResult.addResult("server_version", this.serverVersion); -// MeasurementResult[] IM_mrArray = new MeasurementResult[1]; -// IM_mrArray[0] = IntermediateResult; -// broadcastIntermediateMeasurement(IM_mrArray,this.IM_context); -// -// } } } Logger.i("Total number of sampling result is " + this.samplingResults.size()); From edef19d65da7284c7da130d04f47af86b3cd6d3a Mon Sep 17 00:00:00 2001 From: ChaoKong Date: Mon, 21 Dec 2015 20:17:01 -0500 Subject: [PATCH 6/6] Comparing with current version --- .../com/mobilyzer/MeasurementScheduler.java | 18 +- .../src/com/mobilyzer/MeasurementTask.java | 19 +- .../com/mobilyzer/ServerMeasurementTask.java | 1 - Mobilyzer/src/com/mobilyzer/UpdateIntent.java | 6 - .../com/mobilyzer/UserMeasurementTask.java | 8 - Mobilyzer/src/com/mobilyzer/api/API.java | 16 +- .../mobilyzer/measurements/DnsLookupTask.java | 644 ++++++++++++------ .../mobilyzer/measurements/ParallelTask.java | 3 - .../com/mobilyzer/measurements/PingTask.java | 97 +-- .../measurements/SequentialTask.java | 1 - .../measurements/TCPThroughputTask.java | 75 +- .../measurements/TracerouteTask.java | 82 +-- .../mobilyzer/measurements/UDPBurstTask.java | 2 +- 13 files changed, 478 insertions(+), 494 deletions(-) diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java b/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java index b9e3cd5..948c0ab 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementScheduler.java @@ -185,9 +185,6 @@ public void onCreate() { filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION); filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION); filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION); - - filter.addAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); - broadcastReceiver = new BroadcastReceiver() { @@ -326,20 +323,7 @@ public void onReceive(Context context, Intent intent) { } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals( Config.TASK_RESUMED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); - } - } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION)){ - String IM_taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD); - String IM_taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD); - int IM_priority = - intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, - MeasurementTask.INVALID_PRIORITY); - Parcelable[] IM_Results = intent.getParcelableArrayExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD); - if (IM_Results != null && IM_Results.length!=0) { - sendResultToClient(IM_Results, IM_priority, IM_taskKey, IM_taskid); - Logger.i("Sending Intermediate results to client..."); - System.out.println("receive the intermediate results"); - } - + } } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION) || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION)) { Logger.d("Checkin intent received"); diff --git a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java index b610b4d..eb90244 100644 --- a/Mobilyzer/src/com/mobilyzer/MeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/MeasurementTask.java @@ -7,10 +7,6 @@ import java.util.Set; import java.util.concurrent.Callable; -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; - import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.measurements.DnsLookupTask; import com.mobilyzer.measurements.HttpTask; @@ -23,7 +19,8 @@ import com.mobilyzer.measurements.UDPBurstTask; import com.mobilyzer.measurements.VideoQoETask; - +import android.os.Parcel; +import android.os.Parcelable; public abstract class MeasurementTask implements @@ -32,9 +29,6 @@ public abstract class MeasurementTask Parcelable { protected MeasurementDesc measurementDesc; protected String taskId; - - //private MeasurementScheduler scheduler; - private Context context = null; public static final int USER_PRIORITY = Integer.MIN_VALUE; @@ -120,15 +114,6 @@ public String getKey() { public void setKey(String key) { this.measurementDesc.key = key; } - - // pass scheduler to every specific task - public void setContext(Context context) { - this.context = context; - } - - public Context getContext() { - return this.context; - } public MeasurementDesc getDescription() { diff --git a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java index 95844da..ce5a231 100644 --- a/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/ServerMeasurementTask.java @@ -38,7 +38,6 @@ public class ServerMeasurementTask implements Callable { public ServerMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler, ResourceCapManager manager) { realTask = task; - realTask.setContext(null); this.scheduler = scheduler; this.contextCollector = new ContextCollector(); this.rManager = manager; diff --git a/Mobilyzer/src/com/mobilyzer/UpdateIntent.java b/Mobilyzer/src/com/mobilyzer/UpdateIntent.java index 1e7f9e0..e16b5fa 100644 --- a/Mobilyzer/src/com/mobilyzer/UpdateIntent.java +++ b/Mobilyzer/src/com/mobilyzer/UpdateIntent.java @@ -44,7 +44,6 @@ public class UpdateIntent extends Intent { public static final String VIDEO_TASK_PAYLOAD_REBUFFER_TIME = "VIDEO_TASK_PAYLOAD_REBUFFER_TIME"; public static final String VIDEO_TASK_PAYLOAD_BBA_SWITCH_TIME = "VIDEO_TASK_PAYLOAD_BBA_SWITCH_TIME"; public static final String VIDEO_TASK_PAYLOAD_BYTE_USED = "VIDEO_TASK_PAYLOAD_BYTE_USED"; - public static final String INTERMEDIATE_RESULT_PAYLOAD = "INTERMEDIATE_RESULT_PAYLOAD"; // Different types of actions that this intent can represent: @@ -82,11 +81,6 @@ public class UpdateIntent extends Intent { PACKAGE_PREFIX + ".DATA_USAGE_ACTION"; public static final String AUTH_ACCOUNT_ACTION = PACKAGE_PREFIX + ".AUTH_ACCOUNT_ACTION"; - - - - public static final String MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION = - APP_PREFIX + ".MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION"; /** * Creates an intent of the specified action with an optional message diff --git a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java index 2e90d73..59ec096 100644 --- a/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java +++ b/Mobilyzer/src/com/mobilyzer/UserMeasurementTask.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.concurrent.Callable; -import android.content.Context; import android.content.Intent; import com.mobilyzer.MeasurementResult.TaskProgress; @@ -34,7 +33,6 @@ public class UserMeasurementTask implements Callable { public UserMeasurementTask(MeasurementTask task, MeasurementScheduler scheduler) { realTask = task; - realTask.setContext(scheduler.getApplicationContext()); this.scheduler = scheduler; this.contextCollector= new ContextCollector(); } @@ -50,10 +48,7 @@ private void broadcastMeasurementStart() { intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_STARTED); intent.putExtra(UpdateIntent.TASKID_PAYLOAD, realTask.getTaskId()); intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, realTask.getKey()); -// Context context = scheduler.getApplicationContext(); -// context.sendBroadcast(intent); scheduler.sendBroadcast(intent); - } /** @@ -101,12 +96,9 @@ public MeasurementResult[] call() throws MeasurementError { ArrayList> contextResults = contextCollector.stopCollector(); for (MeasurementResult r: results){ - String testIntermediateFirst = r.toString(); r.addContextResults(contextResults); r.getDeviceProperty().dnResolvability=contextCollector.dnsConnectivity; r.getDeviceProperty().ipConnectivity=contextCollector.ipConnectivity; - String testIntermediateSecond = r.toString(); - } } catch (MeasurementError e) { Logger.e("User measurement " + realTask.getDescriptor() + " has failed"); diff --git a/Mobilyzer/src/com/mobilyzer/api/API.java b/Mobilyzer/src/com/mobilyzer/api/API.java index 5582737..c68934a 100644 --- a/Mobilyzer/src/com/mobilyzer/api/API.java +++ b/Mobilyzer/src/com/mobilyzer/api/API.java @@ -40,6 +40,8 @@ import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.measurements.DnsLookupTask; import com.mobilyzer.measurements.HttpTask; +import com.mobilyzer.measurements.PageLoadTimeTask; +import com.mobilyzer.measurements.PageLoadTimeTask.PageLoadTimeDesc; import com.mobilyzer.measurements.ParallelTask; import com.mobilyzer.measurements.PingTask; import com.mobilyzer.measurements.SequentialTask; @@ -54,6 +56,8 @@ import com.mobilyzer.measurements.TCPThroughputTask.TCPThroughputDesc; import com.mobilyzer.measurements.TracerouteTask.TracerouteDesc; import com.mobilyzer.measurements.UDPBurstTask.UDPBurstDesc; +import com.mobilyzer.measurements.VideoQoETask; +import com.mobilyzer.measurements.VideoQoETask.VideoQoEDesc; import com.mobilyzer.util.Logger; /** @@ -294,10 +298,14 @@ public MeasurementTask createTask( TaskType taskType, Date startTime task = new UDPBurstTask(new UDPBurstDesc(clientKey, startTime, endTime , intervalSec, count, priority, contextIntervalSec, params)); break; -// case PLT: -// task = new PageLoadTimeTask(new PageLoadTimeDesc(clientKey, startTime, endTime -// , intervalSec, count, priority, contextIntervalSec, params)); -// break; + case PLT: + task = new PageLoadTimeTask(new PageLoadTimeDesc(clientKey, startTime, endTime + , intervalSec, count, priority, contextIntervalSec, params)); + break; + case VIDEOQOE: + task = new VideoQoETask(new VideoQoEDesc(clientKey, startTime, endTime + , intervalSec, count, priority, contextIntervalSec, params)); + break; default: throw new MeasurementError("Undefined measurement type. Candidate: " + "DNSLOOKUP, HTTP, PING, TRACEROUTE, TCPTHROUGHPUT, UDPBURST"); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/DnsLookupTask.java b/Mobilyzer/src/com/mobilyzer/measurements/DnsLookupTask.java index 27ebe31..d582ac2 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/DnsLookupTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/DnsLookupTask.java @@ -17,11 +17,17 @@ import android.os.Parcel; import android.os.Parcelable; +import java.io.IOException; import java.io.InvalidClassException; import java.net.InetAddress; +import java.net.SocketAddress; +import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.security.InvalidParameterException; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.Map; import com.mobilyzer.Config; @@ -34,220 +40,464 @@ import com.mobilyzer.util.MeasurementJsonConvertor; import com.mobilyzer.util.PhoneUtils; +import org.xbill.DNS.*; + /** * Measures the DNS lookup time */ -public class DnsLookupTask extends MeasurementTask{ - // Type name for internal use - public static final String TYPE = "dns_lookup"; - // Human readable name for the task - public static final String DESCRIPTOR = "DNS lookup"; - - //Since it's very hard to calculate the data consumed by this task - // directly, we use a fixed value. This is on the high side. - public static final int AVG_DATA_USAGE_BYTE=2000; - - private long duration; - - /** - * The description of DNS lookup measurement - */ - public static class DnsLookupDesc extends MeasurementDesc { - public String target; - private String server; - - - public DnsLookupDesc(String key, Date startTime, Date endTime, - double intervalSec, long count, long priority, - int contextIntervalSec, Map params) { - super(DnsLookupTask.TYPE, key, startTime, endTime, intervalSec, count, - priority, contextIntervalSec, params); - initializeParams(params); - if (this.target == null || this.target.length() == 0) { - throw new InvalidParameterException("LookupDnsTask cannot be created" + - " due to null target string"); - } - } - - /* - * @see com.google.wireless.speed.speedometer.MeasurementDesc#getType() +public class DnsLookupTask extends MeasurementTask { + // Type name for internal use + public static final String TYPE = "dns_lookup"; + // Human readable name for the task + public static final String DESCRIPTOR = "DNS lookup"; + + //Since it's very hard to calculate the data consumed by this task + // directly, we use a fixed value. This is on the high side. + public static final int AVG_DATA_USAGE_BYTE = 2000; + + private long duration; + private boolean debug = true; + + /** + * The description of DNS lookup measurement */ + public static class DnsLookupDesc extends MeasurementDesc { + public String target; + public String server; + public String qclass; + public String qtype; + + + public DnsLookupDesc(String key, Date startTime, Date endTime, + double intervalSec, long count, long priority, + int contextIntervalSec, Map params) { + super(DnsLookupTask.TYPE, key, startTime, endTime, intervalSec, count, + priority, contextIntervalSec, params); + initializeParams(params); + if (this.target == null || this.target.length() == 0) { + throw new InvalidParameterException("LookupDnsTask cannot " + + "be created due to null " + + "target string"); + } + } + + /* + * @see com.google.wireless.speed.speedometer.MeasurementDesc#getType() + */ + @Override + public String getType() { + return DnsLookupTask.TYPE; + } + + @Override + protected void initializeParams(Map params) { + if (params == null) { + return; + } + + this.server = params.get("server"); + this.target = params.get("target"); + // make the lookup absolute if it isn't already + if (!this.target.endsWith(".")) { + this.target = this.target + "."; + } + + /* we are extending the DNS measurement to allow setting + * arbitrary query classes and types, but we want to maintain + * backwards compatibility. Therefore, we are going to default + * to a standard IPv4 query, qclass IN and qtype A + */ + if (params.containsKey("qclass")) { + this.qclass = params.get("qclass"); + } else { + this.qclass = "IN"; + } + + if (params.containsKey("qtype")) { + this.qtype = params.get("qtype"); + } else { + this.qtype = "A"; + } + + } + + protected DnsLookupDesc(Parcel in) { + super(in); + target = in.readString(); + server = in.readString(); + qclass = in.readString(); + qtype = in.readString(); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public DnsLookupDesc createFromParcel(Parcel in) { + return new DnsLookupDesc(in); + } + + public DnsLookupDesc[] newArray(int size) { + return new DnsLookupDesc[size]; + } + }; + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeString(target); + dest.writeString(server); + dest.writeString(qclass); + dest.writeString(qtype); + } + } + + private class DNSWrapper { + public boolean isValid; + public String rawOutput; + public Message response; + public int qid; + public int id; + public long respTime; + + public DNSWrapper(boolean isValid, byte[] rawOutput, Message response, + int qid, int id, long respTime) { + this.isValid = isValid; + this.rawOutput = rawOutput.toString(); + this.response = response; + this.qid = qid; + this.id = id; + this.respTime = respTime; + } + } + + + public DnsLookupTask(MeasurementDesc desc) { + super(new DnsLookupDesc(desc.key, desc.startTime, desc.endTime, + desc.intervalSec, desc.count, desc.priority, + desc.contextIntervalSec, desc.parameters)); + this.duration = Config.DEFAULT_DNS_TASK_DURATION; + } + + protected DnsLookupTask(Parcel in) { + super(in); + duration = in.readLong(); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public DnsLookupTask createFromParcel(Parcel in) { + return new DnsLookupTask(in); + } + + public DnsLookupTask[] newArray(int size) { + return new DnsLookupTask[size]; + } + }; + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(duration); + } + + /** + * Returns a copy of the DnsLookupTask + */ + @Override + public MeasurementTask clone() { + MeasurementDesc desc = this.measurementDesc; + DnsLookupDesc newDesc = new DnsLookupDesc(desc.key, desc.startTime, desc.endTime, + desc.intervalSec, desc.count, desc.priority, desc.contextIntervalSec, desc.parameters); + return new DnsLookupTask(newDesc); + } + + public ArrayList measureDNS(String domain, String qtype, String qclass) { + Record question = null; + try { + question = Record.newRecord(Name.fromString(domain), + Type.value(qtype), + DClass.value(qclass)); + } catch (TextParseException e) { + Logger.d("dns testing: Error constructing packet"); + } + if (debug) Logger.d("dns testing: constructed question"); + + Message query = Message.newQuery(question); + // wait for at most 5 seconds for a response + //long endTime = System.currentTimeMillis() + 5; + if (debug) Logger.d("dns testing: constructed query"); + ArrayList responses = sendMeasurement(query, false); + return responses; + } + + private ArrayList sendMeasurement(Message query, boolean useTCP) { + // now that we have a message, put it on the wire and wait for + // responses + int qid = query.getHeader().getID(); + byte[] output = query.toWire(); + int udpSize = SimpleResolver.maxUDPSize(query); + DnsLookupDesc desc = (DnsLookupDesc) this.measurementDesc; + long endTime = System.currentTimeMillis() + 60 * 5 * 1000; + + /* the people who wrote the DNS code were not awesome and didn't have abstract methods, + * so the code doesn't let me use their superclass, client. Therefore, I'm doing the hacky + * solution and creating 2 different clients + */ + TCPClient tclient = null; + UDPClient uclient = null; + if (useTCP || (output.length > udpSize)) { + try { + tclient = new TCPClient(endTime); + SocketAddress addr = new InetSocketAddress(desc.server, 53); + tclient.connect(addr); + useTCP = true; + } catch (IOException e) { + Logger.d("dns testing: Error creating client"); + } + + } else { + try { + uclient = new UDPClient(endTime); + uclient.bind(null); + SocketAddress addr = new InetSocketAddress(desc.server, 53); + uclient.connect(addr); + } catch (IOException e) { + Logger.e("dns testing: Error creating client"); + } + } + if (debug) Logger.d("dns testing: initialized client"); + + boolean shouldSend = true; + long startTime = 0; + long respTime; + ArrayList responses = new ArrayList(); + if (debug) Logger.d("dns testing: about to start loop current time " + System.currentTimeMillis() + " end time: " + endTime); + while (System.currentTimeMillis() < endTime) { + byte[] in = {}; + + if (debug) Logger.d("dns testing: in send loop"); + if (shouldSend) { + try { + if (useTCP) tclient.send(output); + else uclient.send(output); + startTime = System.currentTimeMillis(); + shouldSend = false; + } catch (IOException e) { + Logger.e("dns testing: Error sending"); + } + if (debug) Logger.d("dns testing: sent query"); + } + + try { + if (useTCP) { + in = tclient.recv(); + } else { + in = uclient.recv(udpSize); + } + } catch (IOException e) { + Logger.d("dns testing: Problem receiving packet due to " + e.getMessage()); + } + + if (debug) Logger.d("dns testing: received"); + + respTime = System.currentTimeMillis() - startTime; + + // if we didn't get anything back, then continue. this + // means we will break out if we are over time + if (in.length == 0) { + if (debug) Logger.d("dns testing: empty response, breaking out"); + break; + } + + DNSWrapper wrap; + Message response; + // don't parse the message if it's too short + if (in.length < Header.LENGTH) { + wrap = new DNSWrapper(false, in, null, qid, -1, respTime); + responses.add(wrap); + if (debug) Logger.d("dns testing: nothing to parse"); + continue; + } + + + int id = ((in[0] & 0xFF) << 8) + (in[1] & 0xFF); + try { + response = SimpleResolver.parseMessage(in); + wrap = new DNSWrapper(true, in, response, qid, id, respTime); + responses.add(wrap); + if (debug) Logger.d("dns testing: successfully parsed response"); + } catch (WireParseException e) { + Logger.e("dns testing: Problem trying to parse dns packet"); + wrap = new DNSWrapper(false, in, null, qid, -1, respTime); + responses.add(wrap); + continue; + } + + // if the response was truncated, then requery over TCP + if (!useTCP && response.getHeader().getFlag(Flags.TC)) { + try { + uclient.cleanup(); + tclient = new TCPClient(endTime); + SocketAddress addr = new InetSocketAddress(desc.server, 53); + tclient.connect(addr); + useTCP = true; + shouldSend = true; + if (debug) Logger.d("dns testing: requerying over tcp"); + } catch (IOException e) { + Logger.e("dns testing: Problem trying to retry over TCP"); + } + } + + } + + if (debug) Logger.d("dns testing: outside send loop"); + return responses; + } + + + @Override + public MeasurementResult[] call() throws MeasurementError { + ArrayList responses = null; + DnsLookupDesc desc = (DnsLookupDesc) this.measurementDesc; + for (int i = 0; i < Config.DEFAULT_DNS_COUNT_PER_MEASUREMENT; i++) { + DnsLookupDesc taskDesc = (DnsLookupDesc) this.measurementDesc; + Logger.i("Running DNS Lookup for target " + taskDesc.target); + responses = measureDNS(taskDesc.target, taskDesc.qtype, taskDesc.qclass); + } + if ((responses == null) || (responses.size() == 0)) { + throw new MeasurementError("Problems conducting DNS measurement"); + } else { + Logger.i("Successfully resolved target address"); + PhoneUtils phoneUtils = PhoneUtils.getPhoneUtils(); + ArrayList results = new ArrayList(); + MeasurementResult result; +// for (DNSWrapper wrap : responses) { + result = new MeasurementResult( + phoneUtils.getDeviceInfo().deviceId, + phoneUtils.getDeviceProperty(this.getKey()), + DnsLookupTask.TYPE, + System.currentTimeMillis() * 1000, + TaskProgress.COMPLETED, this.measurementDesc); + + // now turn the result into an array of hashmaps with the data we care about + + List> data = extractResults(responses); + result.addResult("results", data); + result.addResult("target", desc.target); + result.addResult("qtype", desc.qtype); + result.addResult("qclass", desc.qclass); + + Logger.i(MeasurementJsonConvertor.toJsonString(result)); + results.add(result); +// } + + // create the result array to return + MeasurementResult resultsFinal [] = new MeasurementResult[results.size()]; + for (int i = 0; i < resultsFinal.length; i++) { + resultsFinal[i] = results.get(i); + } + + return resultsFinal; + } + } + + public List> extractResults(ArrayList responses) { + ArrayList> data = new ArrayList>(); + for (DNSWrapper wrap : responses) { + Message resp = null; + if (wrap.isValid) { + resp = wrap.response; + } + HashMap item = new HashMap(); + item.put("qryId", wrap.qid); + item.put("respId", wrap.id); + item.put("payload", wrap.rawOutput); + item.put("respTime", wrap.respTime); + item.put("isValid", wrap.isValid); + item.put("rcode", Rcode.string(resp.header.getRcode())); + item.put("tc", resp.getHeader().getFlag(Flags.TC)); + + // process the question + Record[] questionRecs = resp.getSectionArray(0); + if (questionRecs.length == 0) { + item.put("domain", null); + item.put("qtype", null); + item.put("qclass", null); + } else { + Record rec = questionRecs[0]; + item.put("domain", rec.name.toString()); + item.put("qtype", Type.string(rec.type)); + item.put("qclass", DClass.string(rec.dclass)); + } + + // now process the answers + List> answers = new ArrayList>(); + questionRecs = resp.getSectionArray(1); + for (Record recd : questionRecs) { + HashMap entry = new HashMap(); + entry.put("name", recd.name.toString()); + entry.put("rtype", Type.string(recd.type)); + entry.put("rdata", recd.rrToString()); + answers.add(entry); + } + item.put("answers", answers.toArray()); + data.add(item); + } + return data; + } + + @SuppressWarnings("rawtypes") + public static Class getDescClass() throws InvalidClassException { + return DnsLookupDesc.class; + } + @Override public String getType() { - return DnsLookupTask.TYPE; + return DnsLookupTask.TYPE; } @Override - protected void initializeParams(Map params) { - if (params == null) { - return; - } + public String getDescriptor() { + return DESCRIPTOR; + } - this.target = params.get("target"); - this.server = params.get("server"); + @Override + public String toString() { + DnsLookupDesc desc = (DnsLookupDesc) measurementDesc; + return "[DNS Lookup]\n Target: " + desc.target + "\n Interval (sec): " + + desc.intervalSec + "\n Next run: " + desc.startTime; } - protected DnsLookupDesc(Parcel in) { - super(in); - target = in.readString(); - server = in.readString(); + @Override + public boolean stop() { + //There is nothing we need to do to stop the DNS measurement + return false; } - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public DnsLookupDesc createFromParcel(Parcel in) { - return new DnsLookupDesc(in); - } + @Override + public long getDuration() { + return this.duration; + } - public DnsLookupDesc[] newArray(int size) { - return new DnsLookupDesc[size]; - } - }; @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeString(target); - dest.writeString(server); - } - } - - public DnsLookupTask(MeasurementDesc desc) { - super(new DnsLookupDesc(desc.key, desc.startTime, desc.endTime, - desc.intervalSec, desc.count, desc.priority, desc.contextIntervalSec, - desc.parameters)); - this.duration=Config.DEFAULT_DNS_TASK_DURATION; - } - - protected DnsLookupTask(Parcel in) { - super(in); - duration = in.readLong(); - } - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - public DnsLookupTask createFromParcel(Parcel in) { - return new DnsLookupTask(in); - } - - public DnsLookupTask[] newArray(int size) { - return new DnsLookupTask[size]; - } - }; - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(duration); - } - /** - * Returns a copy of the DnsLookupTask - */ - @Override - public MeasurementTask clone() { - MeasurementDesc desc = this.measurementDesc; - DnsLookupDesc newDesc = new DnsLookupDesc(desc.key, desc.startTime, desc.endTime, - desc.intervalSec, desc.count, desc.priority, desc.contextIntervalSec, desc.parameters); - return new DnsLookupTask(newDesc); - } - - @Override - public MeasurementResult[] call() throws MeasurementError { - long t1, t2; - long totalTime = 0; - InetAddress resultInet = null; - int successCnt = 0; - for (int i = 0; i < Config.DEFAULT_DNS_COUNT_PER_MEASUREMENT; i++) { - try { - DnsLookupDesc taskDesc = (DnsLookupDesc) this.measurementDesc; - Logger.i("Running DNS Lookup for target " + taskDesc.target); - t1 = System.currentTimeMillis(); - InetAddress inet = InetAddress.getByName(taskDesc.target); - t2 = System.currentTimeMillis(); - if (inet != null) { - totalTime += (t2 - t1); - resultInet = inet; - successCnt++; + public void setDuration(long newDuration) { + if (newDuration < 0) { + this.duration = 0; + } else { + this.duration = newDuration; } - } catch (UnknownHostException e) { - throw new MeasurementError("Cannot resovle domain name"); - } - } - - if (resultInet != null) { - Logger.i("Successfully resolved target address"); - PhoneUtils phoneUtils = PhoneUtils.getPhoneUtils(); - MeasurementResult result = new MeasurementResult( - phoneUtils.getDeviceInfo().deviceId, - phoneUtils.getDeviceProperty(this.getKey()), - DnsLookupTask.TYPE, System.currentTimeMillis() * 1000, - TaskProgress.COMPLETED, this.measurementDesc); - result.addResult("address", resultInet.getHostAddress()); - result.addResult("real_hostname", resultInet.getCanonicalHostName()); - result.addResult("time_ms", totalTime / successCnt); - Logger.i(MeasurementJsonConvertor.toJsonString(result)); - MeasurementResult[] mrArray= new MeasurementResult[1]; - mrArray[0]=result; - return mrArray; - - } else { - throw new MeasurementError("Cannot resovle domain name"); - } - } - - @SuppressWarnings("rawtypes") - public static Class getDescClass() throws InvalidClassException { - return DnsLookupDesc.class; - } - - @Override - public String getType() { - return DnsLookupTask.TYPE; - } - - @Override - public String getDescriptor() { - return DESCRIPTOR; - } - - @Override - public String toString() { - DnsLookupDesc desc = (DnsLookupDesc) measurementDesc; - return "[DNS Lookup]\n Target: " + desc.target + "\n Interval (sec): " - + desc.intervalSec + "\n Next run: " + desc.startTime; - } - - @Override - public boolean stop() { - //There is nothing we need to do to stop the DNS measurement - return false; - } - - @Override - public long getDuration() { - return this.duration; - } - - - @Override - public void setDuration(long newDuration) { - if(newDuration<0){ - this.duration=0; - }else{ - this.duration=newDuration; - } - } - - /** - * Since it is hard to get the amount of data sent directly, - * use a fixed value. The data consumed is usually small, and the fixed - * value is a conservative estimate. - * - * TODO find a better way to get this value - */ - @Override - public long getDataConsumed() { - return AVG_DATA_USAGE_BYTE; - } + } + + /** + * Since it is hard to get the amount of data sent directly, + * use a fixed value. The data consumed is usually small, and the fixed + * value is a conservative estimate. + *

+ * TODO find a better way to get this value + */ + @Override + public long getDataConsumed() { + return AVG_DATA_USAGE_BYTE; + } } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java index f458f1d..9cf9c36 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/ParallelTask.java @@ -165,9 +165,6 @@ public String getDescriptor() { @Override public MeasurementResult[] call() throws MeasurementError { - for (MeasurementTask task: this.tasks){ - task.setContext(this.getContext()); - } long timeout=duration; executor=Executors.newFixedThreadPool(this.tasks.size()); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java index 5901f0c..6d26ee3 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/PingTask.java @@ -15,8 +15,6 @@ package com.mobilyzer.measurements; -import android.content.Context; -import android.content.Intent; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; @@ -25,9 +23,7 @@ import com.mobilyzer.Config; import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; -import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; -import com.mobilyzer.UpdateIntent; import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; @@ -75,32 +71,6 @@ public class PingTask extends MeasurementTask{ //Track data consumption for this task to avoid exceeding user's limit private long dataConsumed; - - private Context context = null; - - private void broadcastIntermediateResults(MeasurementResult[] results, Context context) { - this.context = context; - Intent intent = new Intent(); - intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); - //TODO fixed one value priority for all users task? - intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, - MeasurementTask.USER_PRIORITY); - intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); - intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, this.getKey()); - - if (results != null){ - - //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); - intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); - - this.context.sendBroadcast(intent); - }else{ - intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); - - } - - } - /** * Encode ping specific parameters, along with common parameters inherited from MeasurmentDesc * @author wenjiezeng@google.com (Steve Zeng) @@ -386,11 +356,6 @@ private MeasurementResult executePingCmdTask(int ipByteLen) PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult measurementResult = null; - - MeasurementResult intermediateMeasurementResults = null; - MeasurementResult[] intermediateResult = null; - intermediateResult = new MeasurementResult[1]; - // TODO(Wenjie): Add a exhaustive list of ping locations for different // Android phones pingTask.pingExe = Util.pingExecutableBasedOnIPType(ipByteLen); @@ -419,13 +384,11 @@ private MeasurementResult executePingCmdTask(int ipByteLen) ArrayList receivedIcmpSeq = new ArrayList(); double packetLoss = Double.MIN_VALUE; int packetsSent = Config.PING_COUNT_PER_MEASUREMENT; - // Process each line of the ping output and store the rrt in array rrts. while ((line = br.readLine()) != null) { // Ping prints a number of 'param=value' pairs, among which we only need // the 'time=rrt_val' pair String[] extractedValues = Util.extractInfoFromPingOutput(line); - if (extractedValues != null) { int curIcmpSeq = Integer.parseInt(extractedValues[0]); double rrtVal = Double.parseDouble(extractedValues[1]); @@ -446,18 +409,6 @@ private MeasurementResult executePingCmdTask(int ipByteLen) int packetsReceived = packetLossInfo[1]; packetLoss = 1 - ((double) packetsReceived / (double) packetsSent); } - this.context = this.getContext(); - if ( this.context != null ){ - if (rrts.size() >= 2 && (rrts.size() < Config.PING_COUNT_PER_MEASUREMENT) && (extractedValues != null) ){ - intermediateMeasurementResults = constructResult(rrts,packetLoss, - rrts.size(),PING_METHOD_CMD); - intermediateResult[0] = intermediateMeasurementResults; - broadcastIntermediateResults(intermediateResult,this.context); - - - } - } - Logger.i(line); } @@ -501,10 +452,6 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { ArrayList rrts = new ArrayList(); String errorMsg = ""; MeasurementResult result = null; - double packetLoss = Double.MIN_VALUE; - MeasurementResult intermediateMeasurementResults = null; - MeasurementResult[] intermediateResult = null; - intermediateResult = new MeasurementResult[1]; try { int timeOut = (int) (3000 * (double) pingTask.pingTimeoutSec / @@ -519,28 +466,11 @@ private MeasurementResult executeJavaPingTask() throws MeasurementError { if (status) { totalPingDelay += rrtVal; rrts.add((double) rrtVal); - packetLoss = 1 - - ((double) rrts.size() / (i+1)); - dataConsumed += pingTask.packetSizeByte * (i+1) * 2; - this.context = this.getContext(); - if ( this.context != null){ - intermediateMeasurementResults = constructResult(rrts,packetLoss, - (i+1),PING_METHOD_JAVA); - intermediateResult[0] = intermediateMeasurementResults; - broadcastIntermediateResults(intermediateResult,this.context); - - } - - } } Logger.i("java ping succeeds"); -// double packetLoss = 1 - -// ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); - if (packetLoss == Double.MIN_VALUE) { - packetLoss = 1 - - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); - } + double packetLoss = 1 - + ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); dataConsumed += pingTask.packetSizeByte * Config.PING_COUNT_PER_MEASUREMENT * 2; @@ -575,10 +505,6 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult result = null; - double packetLoss = Double.MIN_VALUE; - MeasurementResult intermediateMeasurementResults = null; - MeasurementResult[] intermediateResult = null; - intermediateResult = new MeasurementResult[1]; try { long totalPingDelay = 0; @@ -599,27 +525,12 @@ private MeasurementResult executeHttpPingTask() throws MeasurementError { pingEndTime = System.currentTimeMillis(); httpClient.disconnect(); rrts.add((double) (pingEndTime - pingStartTime)); - packetLoss = 1 - - ((double) rrts.size() / (i+1)); - dataConsumed += pingTask.packetSizeByte * (i+1) * 2; - this.context = this.getContext(); - if ( this.context != null){ - intermediateMeasurementResults = constructResult(rrts,packetLoss, - (i+1),PING_METHOD_HTTP); - intermediateResult[0] = intermediateMeasurementResults; - broadcastIntermediateResults(intermediateResult,this.context); - - } } Logger.i("HTTP get ping succeeds"); Logger.i("RTT is " + rrts.toString()); -// double packetLoss = 1 -// - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); - if (packetLoss == Double.MIN_VALUE) { - packetLoss = 1 - - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); - } + double packetLoss = 1 + - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); dataConsumed += pingTask.packetSizeByte * Config.PING_COUNT_PER_MEASUREMENT * 2; diff --git a/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java b/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java index 61a4cb8..7dd1a38 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/SequentialTask.java @@ -169,7 +169,6 @@ public MeasurementResult[] call() throws MeasurementError { try { // futures=executor.invokeAll(this.tasks,timeout,TimeUnit.MILLISECONDS); for(MeasurementTask mt: tasks){ - mt.setContext(this.getContext()); if(stopFlag){ throw new MeasurementError("Cancelled"); } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java index c0a565c..66a3550 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TCPThroughputTask.java @@ -3,8 +3,8 @@ package com.mobilyzer.measurements; import java.io.IOException; -import java.io.InputStream; import java.io.InvalidClassException; +import java.io.InputStream; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; @@ -15,23 +15,19 @@ import java.util.Map; import java.util.Random; -import android.content.Context; -import android.content.Intent; -import android.os.Parcel; -import android.os.Parcelable; - import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; -import com.mobilyzer.MeasurementResult.TaskProgress; -import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; -import com.mobilyzer.UpdateIntent; +import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; import com.mobilyzer.util.MLabNS; import com.mobilyzer.util.MeasurementJsonConvertor; import com.mobilyzer.util.PhoneUtils; +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; /** * @author Haokun Luo @@ -92,34 +88,6 @@ public class TCPThroughputTask extends MeasurementTask { private long duration; private TaskProgress taskProgress; private volatile boolean stopFlag; - - private Context IM_context = null; - private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; - - // add broadcast to send the intermediate results - - private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { - this.IM_context = context; - Intent intent = new Intent(); - intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); - - intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, - MeasurementTask.USER_PRIORITY); - intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); - intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, this.getKey()); - - if (results != null){ - - //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); - intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); - - this.IM_context.sendBroadcast(intent); - }else{ - intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); - - } - - } // class constructor public TCPThroughputTask(MeasurementDesc desc) { @@ -545,8 +513,6 @@ private void uplink() throws MeasurementError, IOException, InterruptedException Socket tcpSocket = null; InputStream iStream = null; OutputStream oStream = null; - - try { tcpSocket = new Socket(); @@ -564,18 +530,13 @@ private void uplink() throws MeasurementError, IOException, InterruptedException long startTime = System.currentTimeMillis(); long endTime = startTime; - - int data_limit_byte_up = (int)(((TCPThroughputDesc)measurementDesc).data_limit_mb_up *this.KBYTE*this.KBYTE); byte[] uplinkBuffer = new byte[((TCPThroughputDesc)measurementDesc).pkt_size_up_bytes]; this.genRandomByteArray(uplinkBuffer); - - try { - long totalDuration = (long)(this.KSEC* ((TCPThroughputDesc)measurementDesc).duration_period_sec + @@ -590,7 +551,6 @@ private void uplink() throws MeasurementError, IOException, InterruptedException oStream.flush(); endTime = System.currentTimeMillis(); - this.totalSendSize += ((TCPThroughputDesc)measurementDesc).pkt_size_up_bytes; if (this.DATA_LIMIT_ON && this.totalSendSize >= data_limit_byte_up) { @@ -616,9 +576,6 @@ private void uplink() throws MeasurementError, IOException, InterruptedException byte [] resultMsg = new byte[this.BUFFER_SIZE]; int resultMsgLen = iStream.read(resultMsg, 0, resultMsg.length); if (resultMsgLen > 0) { - - - String resultMsgStr = new String(resultMsg).substring(0, resultMsgLen); // Sample result string is "1111.11#2222.22#3333.33"; Logger.i("Uplink result from server is " + resultMsgStr); @@ -628,7 +585,6 @@ private void uplink() throws MeasurementError, IOException, InterruptedException sampleResult = Double.valueOf(tps_result_str[i]); this.samplingResults = this.insertWithOrder(this.samplingResults, sampleResult); - } } Logger.i("Total number of sampling result is " + this.samplingResults.size()); @@ -723,9 +679,6 @@ private void downlink() throws MeasurementError, IOException { * @param time period increment */ private void updateSize(int delta) { - - MeasurementResult IntermediateResult = null; - double gtime = System.currentTimeMillis() - this.taskStartTime; //ignore slow start if (gtime<((TCPThroughputDesc)measurementDesc).slow_start_period_sec*this.KSEC) @@ -743,24 +696,6 @@ private void updateSize(int delta) { this.samplingResults = this.insertWithOrder(this.samplingResults, throughput); this.accumulativeSize = 0; this.startSampleTime = System.currentTimeMillis(); - - - this.IM_context = this.getContext(); - if (this.IM_context != null){ - PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); - IntermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, - Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TCPThroughputTask.TYPE, - System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); - IntermediateResult.addResult("tcp_speed_results", this.samplingResults); - IntermediateResult.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED); - IntermediateResult.addResult("duration", time); - IntermediateResult.addResult("server_version", this.serverVersion); - MeasurementResult[] IM_mrArray = new MeasurementResult[1]; - IM_mrArray[0] = IntermediateResult; - broadcastIntermediateMeasurement(IM_mrArray,this.IM_context); - - } - } } diff --git a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java index 1f95c0f..14fba2f 100755 --- a/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/TracerouteTask.java @@ -14,6 +14,9 @@ package com.mobilyzer.measurements; +import android.os.Parcel; +import android.os.Parcelable; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -36,19 +39,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import android.content.Context; -import android.content.Intent; -import android.os.Parcel; -import android.os.Parcelable; - import com.mobilyzer.Config; import com.mobilyzer.MeasurementDesc; import com.mobilyzer.MeasurementResult; -import com.mobilyzer.MeasurementResult.TaskProgress; -import com.mobilyzer.MeasurementScheduler; import com.mobilyzer.MeasurementTask; import com.mobilyzer.PreemptibleMeasurementTask; -import com.mobilyzer.UpdateIntent; +import com.mobilyzer.MeasurementResult.TaskProgress; import com.mobilyzer.exceptions.MeasurementError; import com.mobilyzer.util.Logger; import com.mobilyzer.util.MeasurementJsonConvertor; @@ -56,7 +52,6 @@ import com.mobilyzer.util.Util; - /** * A Callable task that handles Traceroute measurements */ @@ -88,37 +83,9 @@ public class TracerouteTask extends MeasurementTask implements PreemptibleMeasur private long totalRunningTime; private int ttl; private int maxHopCount; - // Track data consumption for this task to avoid exceeding user's limit private long dataConsumed; - private Context context = null; - private TaskProgress Intermediate_TaskProgress = TaskProgress.COMPLETED; - - // add broadcast to send the intermediate results - - private void broadcastIntermediateMeasurement(MeasurementResult[] results, Context context) { - this.context = context; - Intent intent = new Intent(); - intent.setAction(UpdateIntent.MEASUREMENT_INTERMEDIATE_PROGRESS_UPDATE_ACTION); - //TODO fixed one value priority for all users task? - intent.putExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, - MeasurementTask.USER_PRIORITY); - intent.putExtra(UpdateIntent.TASKID_PAYLOAD, this.getTaskId()); - intent.putExtra(UpdateIntent.CLIENTKEY_PAYLOAD, this.getKey()); - - if (results != null){ - - //intent.putExtra(UpdateIntent.TASK_STATUS_PAYLOAD, Config.TASK_FINISHED); - intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, results); - - this.context.sendBroadcast(intent); - }else{ - intent.putExtra(UpdateIntent.INTERMEDIATE_RESULT_PAYLOAD, "No intermediate results are broadcasted"); - - } - - } /** * The description of the Traceroute measurement @@ -143,8 +110,6 @@ public static class TracerouteDesc extends MeasurementDesc { public String preCondition; private int parallelProbeNum; - - public TracerouteDesc(String key, Date startTime, Date endTime, double intervalSec, long count, long priority, int contextIntervalSec, Map params) @@ -358,9 +323,6 @@ public MeasurementResult[] call() throws MeasurementError { throw new MeasurementError("target " + target + " cannot be resolved"); } MeasurementResult result = null; - MeasurementResult intermediateResult = null; - - ExecutorService hopExecutorService = Executors.newFixedThreadPool(task.parallelProbeNum); @@ -381,11 +343,11 @@ public MeasurementResult[] call() throws MeasurementError { target); taskCompletionService.submit(new HopExecutor(task.pingsPerHop, command, hostIp, ttl)); ttl++; - } + } for (int tasksHandled = 0; tasksHandled < maxHopCount; tasksHandled++) { - + try { Future hopResult = taskCompletionService.take(); HopInfo hop = hopResult.get(); @@ -414,9 +376,7 @@ public MeasurementResult[] call() throws MeasurementError { new MeasurementResult(phoneUtils.getDeviceInfo().deviceId, phoneUtils.getDeviceProperty(this.getKey()), TracerouteTask.TYPE, System.currentTimeMillis() * 1000, taskProgress, this.measurementDesc); - result.addResult("num_hops", hop.ttl); - for (int i = 0; i < hopHosts.size(); i++) { HopInfo hopInfo = hopHosts.get(i); int hostIdx = 1; @@ -429,7 +389,6 @@ public MeasurementResult[] call() throws MeasurementError { } } Logger.i(MeasurementJsonConvertor.toJsonString(result)); - MeasurementResult[] mrArray = new MeasurementResult[1]; mrArray[0] = result; return mrArray; @@ -438,35 +397,6 @@ public MeasurementResult[] call() throws MeasurementError { } } - - this.context = this.getContext(); - if (this.context != null){ - - PhoneUtils Intermediate_phoneUtils = PhoneUtils.getPhoneUtils(); - intermediateResult = new MeasurementResult(Intermediate_phoneUtils.getDeviceInfo().deviceId, - Intermediate_phoneUtils.getDeviceProperty(this.getKey()),TracerouteTask.TYPE, - System.currentTimeMillis()*1000,Intermediate_TaskProgress,this.measurementDesc); - - intermediateResult.addResult("num_hops", hop.ttl); - - for (int i = 0; i < hopHosts.size(); i++) { - HopInfo intermediateHopInfo = hopHosts.get(i); - int intermediateHostIdx = 1; - for (String intermediateHost : intermediateHopInfo.hosts) { - intermediateResult.addResult("hop_" + intermediateHopInfo.ttl + "_addr_" + intermediateHostIdx++, intermediateHost); - } - intermediateResult.addResult("hop_" + intermediateHopInfo.ttl + "_rtt_ms", String.format("%.3f", intermediateHopInfo.rtt)); - - } - - - MeasurementResult[] intermediateMrArray = new MeasurementResult[1]; - intermediateMrArray[0] = intermediateResult; - broadcastIntermediateMeasurement(intermediateMrArray,this.context); - } - - - } catch (InterruptedException e) { e.printStackTrace(); diff --git a/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java b/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java index 2b85429..ee5ffe4 100644 --- a/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java +++ b/Mobilyzer/src/com/mobilyzer/measurements/UDPBurstTask.java @@ -42,7 +42,7 @@ * * UDPBurstTask provides two types of measurements, Burst Up and Burst Down, described next. * - * 1. UDPBurst Up: the device sends a burst of UDPBurstCount UDP packets and waits for a + * 1. UDPBurst Up: the device sends sends a burst of UDPBurstCount UDP packets and waits for a * response from the server that includes the number of packets that the server received * * 2. UDPBurst Down: the device sends a request to a remote server on a UDP port and the server