Permalink
Browse files

changes in android client for sigcomm demo

  • Loading branch information...
1 parent df2f79e commit 636487722daf9a59df14c8f65786a0f9f57218d0 @narseo narseo committed Oct 17, 2012
@@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter your (DNS) name:"
- android:height="46dp"
+ android:height="76dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:paddingTop="15px"
@@ -4,47 +4,7 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
- <TableLayout
- android:id="@+id/tableLayoutTop"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:stretchColumns="*"
- android:paddingTop="4px">
-
- <TableRow
- android:id="@+id/tableRow0"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
-
- <Button
- android:id="@+id/rtt"
- android:layout_height="wrap_content"
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_column="0"
- android:gravity="center_horizontal"
- android:text="RTT" />
-
- <Button
- android:id="@+id/jitter"
- android:layout_height="wrap_content"
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_column="1"
- android:gravity="center_horizontal"
- android:text="Jitter" />
-
- <Button
- android:id="@+id/goodput"
- android:layout_height="wrap_content"
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_column="2"
- android:gravity="center_horizontal"
- android:text="Goodput" />
- </TableRow>
-
- </TableLayout>
+
<TextView
android:id="@+id/title"
@@ -36,14 +36,11 @@
public class SigcommDemoAndroidActivity extends Activity implements OnClickListener{
- private static final String TAG = "SIGPST";
+ private static final String TAG = "SIGN";
public PowerManager pm = null;
private PowerManager.WakeLock mWakeLock;
private static Button startButton = null;
private static Button stopButton = null;
- private static Button rttButton = null;
- private static Button jitterButton = null;
- private static Button goodputButton = null;
private static TextView errorView = null;
//Title for the plot (looks better than adding a label for Y Axis which
//is likely to overlap with the tick labels
@@ -55,7 +52,7 @@
//Used to inform which one is the current active plot
- private static int currentPlot = 0;
+ private static int currentPlot = 2;
private static final int PLOT_RTT = 0;
private static final int PLOT_JITTER = 1;
private static final int PLOT_GOODPUT = 2;
@@ -144,12 +141,6 @@ public void onCreate(Bundle savedInstanceState) {
startButton.setOnClickListener(this);
stopButton =(Button) findViewById(R.id.stopTest);
stopButton.setOnClickListener(this);
- rttButton =(Button) findViewById(R.id.rtt);
- rttButton.setOnClickListener(this);
- jitterButton =(Button) findViewById(R.id.jitter);
- jitterButton.setOnClickListener(this);
- goodputButton =(Button) findViewById(R.id.goodput);
- goodputButton.setOnClickListener(this);
@@ -163,7 +154,7 @@ public void onCreate(Bundle savedInstanceState) {
timestampRtt [i] = 0.0f;
timestampJitter [i] = 0.0f;
}
- title.setText("RTT (ms)");
+ title.setText("Goodput (Mbps)");
graph = (GraphView) findViewById(R.id.graph);
@@ -277,21 +268,6 @@ public void onClick(View v) {
}
this.finish();
break;
- //Show RTT plot
- case R.id.rtt:
- currentPlot=PLOT_RTT;
- Log.i(TAG, "CURRENT PLOT: "+currentPlot);
- break;
- //Show JITTER plot
- case R.id.jitter:
- currentPlot=PLOT_JITTER;
- Log.i(TAG, "CURRENT PLOT: "+currentPlot);
- break;
- //Show Goodput (uplink/downlink) plot
- case R.id.goodput:
- currentPlot=PLOT_GOODPUT;
- Log.i(TAG, "CURRENT PLOT: "+currentPlot);
- break;
default:
Log.i(TAG, "ERROR");
}
@@ -414,7 +390,7 @@ public void onReceive(Context context, Intent intent) {
graph.setYLabelPositions(yTicksPosition);
graph.setXLabels(xTicksLabelsTime);
graph.setXLabelPositions(xTicksPosGoodput);
- plot(timestampDownstreamBandwidth, smoothSignal(arrayDownstreamBandwidth, 4), timestampUpstreamBandwidth, smoothSignal(arrayUpstreamBandwidth,4), minXAxisGoodput, maxXAxisGoodput);
+ plotGoodput(timestampDownstreamBandwidth, smoothSignal(arrayDownstreamBandwidth, 4), minXAxisGoodput, maxXAxisGoodput);
break;
}
}
@@ -499,7 +475,7 @@ public float getMax (float [] array){
}
public float[] smoothSignal(float [] array, int windowSize){
- Log.i(TAG, "Smoothing signal");
+ //Log.i(TAG, "Smoothing signal");
float [] smoothSignal = new float[array.length];
for (int i=0; i<array.length; i++){
if (i<windowSize){
@@ -516,13 +492,13 @@ public float getMax (float [] array){
}
smoothSignal[i] = aggregateVal/(float)windowSize;
}
- Log.i(TAG, "Smoothing signal: "+i+" Original "+array[i]+" Smoothed "+smoothSignal[i]);
+ //Log.i(TAG, "Smoothing signal: "+i+" Original "+array[i]+" Smoothed "+smoothSignal[i]);
}
return smoothSignal;
}
public float[] smoothSignal(float [] array){
- Log.i(TAG, "Smoothing signal");
+ //Log.i(TAG, "Smoothing signal");
float [] smoothSignal = new float[array.length];
for (int i=0; i<array.length; i++){
if (i<SMOOTH_WINDOW){
@@ -539,7 +515,7 @@ public float getMax (float [] array){
}
smoothSignal[i] = aggregateVal/(float)SMOOTH_WINDOW;
}
- Log.i(TAG, "Smoothing signal: "+i+" Original "+array[i]+" Smoothed "+smoothSignal[i]);
+ //Log.i(TAG, "Smoothing signal: "+i+" Original "+array[i]+" Smoothed "+smoothSignal[i]);
}
return smoothSignal;
}
@@ -650,6 +626,58 @@ public void plotLatency (float [] timestamps, float [] values, float minX, float
/*
* Plots goodput (bi-dimensional)
*/
+ public void plotGoodput (float [] timestamps, float [] values, float minX, float maxX){
+ float[][] data1 = {timestamps, values};
+
+ //Set x-axis values
+ //Needs to get the minimum for the timestamp as the measurements are not sync-ed
+ float midTime = (maxX-minX)/2.0f+minX;
+ float mid = (float)Math.round(midTime*10)/10;
+ float firstquarterTime = (float)Math.round(((midTime-minX)/2.0f+minX)*10)/10;
+ float secondquarterTime = (float)Math.round(((maxX-midTime)/2.0f+midTime)*10)/10;
+ float max = (float)Math.round(maxX*10)/10;
+ float min = (float)Math.round(minX*10)/10;
+
+
+ //Get maximum from arrays
+ float maxArray = getMax(values);
+ maxValGoodputYAxis = Math.max(maxArray, maxValGoodputYAxis);
+
+ float maxYVal = (float)Math.round(maxValGoodputYAxis*1.2f*10)/10;
+ float midYVal = (float)Math.round(maxYVal*0.5f*10)/10;
+ float firstquarterYVal = (float)Math.round(maxYVal*0.25f*10)/10;
+ float secondquarterYVal = (float)Math.round(maxYVal*0.75f*10)/10;
+
+ String [] xTicksLabelsLatency = new String []{String.valueOf(min), String.valueOf(firstquarterTime), String.valueOf(mid), String.valueOf(secondquarterTime), String.valueOf(max)};
+ float [] xTicksPosLatency = new float []{0.0f, 0.25f, 0.5f, 0.75f, 1.0f};
+
+ String [] yTicksLabelsLatency = new String []{String.valueOf(0.0f), String.valueOf(firstquarterYVal), String.valueOf(midYVal), String.valueOf(secondquarterYVal), String.valueOf(maxYVal)};
+ float [] yTicksPosLatency = new float []{0.0f, 0.25f, 0.5f, 0.75f, 1.0f};
+
+ /*
+ * THIS IS WHERE SMOOTHING CAN BE DONE. SUBSTITUTE ORIGINAL ARRAY
+ * BY AN SMOOTHED ONE
+ */
+ graph.setXLabels(xTicksLabelsLatency);
+ graph.setXLabelPositions(xTicksPosLatency);
+ graph.setYLabels(yTicksLabelsLatency);
+ graph.setYLabelPositions(yTicksPosLatency);
+
+ graph.redraw();
+
+ graph.setData(new float[][][]{data1}, minX, timestamps[timestamps.length-1], 0.0f, maxYVal);
+
+
+ //graph.setData(new float[][][]{data1}, minX, Math.min(timestamps[timestamps.length-1],timestamps2[timestamps2.length-1]), 0.0f, maxYVal);
+ //graph.addData(data2, minX, Math.min(timestamps[timestamps.length-1], timestamps2[timestamps2.length-1]), 0.0f,maxYVal);
+
+ }
+
+
+
+ /*
+ * Plots goodput (bi-dimensional)
+ */
public void plot (float [] timestamps, float [] values, float[] timestamps2, float[] values2, float minX, float maxX){
float[][] data1 = {timestamps, values};
float[][] data2={timestamps2, values2};
@@ -25,7 +25,7 @@
public class SigcommDemoAndroidService extends Service implements Runnable{
- public static final String TAG = "SIGNPOSTSERV";
+ public static final String TAG = "SIGN";
private static SigcommDemoAndroidActivity MAIN_ACTIVITY;
private static PowerManager.WakeLock wl = null;
private static PowerManager pm =null;
@@ -66,8 +66,7 @@
public static InetAddress address = null;
//Default values 192.168.142.229
- public static int [] SERVER = {192, 168, 142, 229};
-
+ public static int [] SERVER = {10, 7, 0, 41};
public static int TCP_PORT = 7777;
public static int UDP_LOCAL_PORT = 5522;
@@ -198,9 +197,11 @@ public void run (){
long startTest = System.currentTimeMillis();
int UDP_SERVER_PORT = -1;
Socket clientSocket = new Socket();
- byte[] ipAddr = new byte[]{(byte) SERVER[0], (byte) SERVER[1], (byte) SERVER[2], (byte) SERVER[3]};
+ //byte[] ipAddr = new byte[]{(byte) SERVER[0], (byte) SERVER[1], (byte) SERVER[2], (byte) SERVER[3]};
+
//InetAddress address = InetAddress.getByAddress(ipAddr);
//InetSocketAddress isockAddress = new InetSocketAddress(address, TCP_PORT);
+
Log.i(TAG, "Dev name: "+devName);
String serverUrl = "";
try{
@@ -232,8 +233,8 @@ public void run (){
//Starting UDP receiver and sender thread (non-blocking)
- SenderThread sender = new SenderThread(address, UDP_SERVER_PORT);
- sender.start();
+ //SenderThread sender = new SenderThread(address, UDP_SERVER_PORT);
+ //sender.start();
/*
* TCP Latency measurement is deprecated but still done.
@@ -248,11 +249,13 @@ public void run (){
//Listen for num bytes from server and estimate latency.
in = inFromServer.readLine();
- int numBytes = Integer.parseInt(in);
- long latency = (System.nanoTime()-startTime)/1000000/2; // time delta (rtt) in nanoseconds -> miliseconds / 2
+ long numBytes = Long.parseLong(in);
+ Log.i(TAG, "NUM Bytes - (server specified): "+numBytes);
+ long latency = (System.nanoTime()-startTime)/(long)1000000; // time delta (rtt) in nanoseconds -> miliseconds / 2
//notifyActivity(latency, LATENCY_UPSTREAM_ID);
Log.i(TAG, "Packet Length (string): "+in+" - Packet Length (int): "+numBytes);
+
long startDownloadTime = System.nanoTime();
//Timer starts now but this value is
//substracted later latency/2
@@ -268,19 +271,22 @@ public void run (){
{
overall += inFromServer.read(data, 0, 1024);
}
- long downloadTime = (System.nanoTime() - startDownloadTime)/1000000-latency*2;
+ long deltaTime = System.nanoTime() - startDownloadTime;
+ long downloadTime = deltaTime/(long)1000000;
+ //long downloadTime = deltaTime/(long)1000000-latency/(long)2;
Log.i(TAG, "Download time: "+downloadTime);
- long goodputDownstream = 8*(long)numBytes/downloadTime; //in Kbps (bits per milisecond = kbits per second)
+ long goodputDownstream = (long)8*(long)numBytes/downloadTime; //in Kbps (bits per milisecond = kbits per second)
Log.e(TAG, "Estimated DOWNSTREAM Goodput (kbps): "+goodputDownstream);
if (goodputDownstream<0){
+ Log.e(TAG, "DELTA: "+deltaTime+" Latency: "+latency);
Log.e(TAG, "ERROR!!! DOWNSTREAM GOODPUT<0. Bits: "+8*numBytes+" - Download Time (long) "+downloadTime);
}
//Passes data as kbps to the notification activity.
//Server is expecting bps
notifyActivity(goodputDownstream, GOODPUT_DOWNSTREAM_ID);
- outToServer.writeBytes(goodputDownstream*1000+ "\r\n"); //Sent to server as bps
+ outToServer.writeBytes(goodputDownstream*(long)1000+ "\r\n"); //Sent to server as bps
//Wait for server latency
int serverLatencyInt = Integer.parseInt(inFromServer.readLine());
@@ -296,7 +302,7 @@ public void run (){
notifyActivity((long)upstreamGoodputInt, GOODPUT_UPSTREAM_ID);
if (DEBUG) Log.i(TAG, "Upstream test finished. " + overallUpstream+" bytes sent");
- if ((System.currentTimeMillis()-startTest) > 120*1000){
+ if ((System.currentTimeMillis()-startTest) > (long)10*(long)1000){
testAlive = false;
}
}
@@ -305,6 +311,7 @@ public void run (){
}
catch(Exception e){
Log.i(TAG, "EXCEPTION OPENING CONNECTION: "+e.getMessage());
+ e.printStackTrace();
notifyErrorActivity("SERVER NOT AVAILABLE");
}
stopThread();

0 comments on commit 6364877

Please sign in to comment.