Преглед на файлове

added online bandwidth measurement

Boyoung- преди 8 години
родител
ревизия
0f3b24de4f

+ 19 - 0
src/communication/Communication.java

@@ -16,6 +16,8 @@ import java.util.concurrent.LinkedBlockingQueue;
 
 import org.apache.commons.lang3.SerializationUtils;
 
+import util.Bandwidth;
+import util.P;
 import util.Util;
 
 /**
@@ -65,8 +67,15 @@ public class Communication {
 	protected int mState;
 	protected InetSocketAddress mAddress;
 
+	public Bandwidth[] bandwidth;
+	public boolean bandSwitch = true;
+
 	public Communication() {
 		mState = STATE_NONE;
+
+		bandwidth = new Bandwidth[P.size];
+		for (int i = 0; i < P.size; i++)
+			bandwidth[i] = new Bandwidth(P.names[i]);
 	}
 
 	public void setTcpNoDelay(boolean on) {
@@ -319,6 +328,12 @@ public class Communication {
 		r.write(out);
 	}
 
+	public void write(int pid, byte[] out) {
+		write(out);
+		if (bandSwitch)
+			bandwidth[pid].add(out.length);
+	}
+
 	/**
 	 * Write a length encoded byte array.
 	 * 
@@ -333,6 +348,10 @@ public class Communication {
 		write(SerializationUtils.serialize((Serializable) out));
 	}
 
+	public <T> void write(int pid, T out) {
+		write(pid, SerializationUtils.serialize((Serializable) out));
+	}
+
 	public static final Charset defaultCharset = Charset.forName("ASCII");
 
 	// TODO: Rather than having millions of write/read methods can we take

+ 16 - 0
src/exceptions/BandwidthException.java

@@ -0,0 +1,16 @@
+package exceptions;
+
+public class BandwidthException extends RuntimeException {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public BandwidthException() {
+		super();
+	}
+
+	public BandwidthException(String message) {
+		super(message);
+	}
+}

+ 2 - 2
src/protocols/Access.java

@@ -116,8 +116,8 @@ public class Access extends Protocol {
 
 		// step 2
 		timer.start(pid, M.online_write);
-		con2.write(pathTuples);
-		con2.write(Ni);
+		con2.write(pid, pathTuples);
+		con2.write(pid, Ni);
 		timer.stop(pid, M.online_write);
 
 		// step 3

+ 8 - 8
src/protocols/Eviction.java

@@ -74,10 +74,10 @@ public class Eviction extends Protocol {
 		}
 
 		timer.start(pid, M.online_write);
-		con1.write(LiInputKeys);
-		con1.write(E_feInputKeys);
-		con1.write(E_labelInputKeys);
-		con1.write(deltaInputKeys);
+		con1.write(pid, LiInputKeys);
+		con1.write(pid, E_feInputKeys);
+		con1.write(pid, E_labelInputKeys);
+		con1.write(pid, deltaInputKeys);
 		timer.stop(pid, M.online_write);
 
 		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
@@ -178,7 +178,7 @@ public class Eviction extends Protocol {
 	public void runC(PreData predata, boolean firstTree, Tuple[] originalPath, int d, int sw, int w, Timer timer) {
 		if (firstTree) {
 			timer.start(pid, M.online_write);
-			con2.write(originalPath);
+			con2.write(pid, originalPath);
 			timer.stop(pid, M.online_write);
 			return;
 		}
@@ -199,8 +199,8 @@ public class Eviction extends Protocol {
 		}
 
 		timer.start(pid, M.online_write);
-		con2.write(C_feInputKeys);
-		con2.write(C_labelInputKeys);
+		con2.write(pid, C_feInputKeys);
+		con2.write(pid, C_labelInputKeys);
 		timer.stop(pid, M.online_write);
 
 		PermuteTarget permutetarget = new PermuteTarget(con1, con2);
@@ -240,7 +240,7 @@ public class Eviction extends Protocol {
 		pathBuckets[0].expand(Arrays.copyOfRange(originalPath, w, sw));
 
 		timer.start(pid, M.online_write);
-		con2.write(pathBuckets);
+		con2.write(pid, pathBuckets);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 2 - 2
src/protocols/PermuteIndex.java

@@ -39,7 +39,7 @@ public class PermuteIndex extends Protocol {
 		BigInteger[] z = Util.xor(ti_p, predata.pi_p);
 
 		timer.start(pid, M.online_write);
-		con2.write(z);
+		con2.write(pid, z);
 		timer.stop(pid, M.online_write);
 
 		timer.start(pid, M.online_read);
@@ -71,7 +71,7 @@ public class PermuteIndex extends Protocol {
 		BigInteger[] g = Util.xor(predata.evict_rho, z);
 
 		timer.start(pid, M.online_write);
-		con2.write(g);
+		con2.write(pid, g);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 3 - 3
src/protocols/PermuteTarget.java

@@ -55,8 +55,8 @@ public class PermuteTarget extends Protocol {
 		BigInteger[] z = Util.xor(target, predata.pt_p);
 
 		timer.start(pid, M.online_write);
-		con2.write(z);
-		con2.write(I);
+		con2.write(pid, z);
+		con2.write(pid, I);
 		timer.stop(pid, M.online_write);
 
 		timer.start(pid, M.online_read);
@@ -93,7 +93,7 @@ public class PermuteTarget extends Protocol {
 		BigInteger[] g = Util.permute(mk, predata.evict_pi);
 
 		timer.start(pid, M.online_write);
-		con2.write(g);
+		con2.write(pid, g);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 1 - 1
src/protocols/PostProcessT.java

@@ -80,7 +80,7 @@ public class PostProcessT extends Protocol {
 		int delta = (predata.ppt_alpha - j2 + twoTauPow) % twoTauPow;
 
 		timer.start(pid, M.online_write);
-		con1.write(delta);
+		con1.write(pid, delta);
 		timer.stop(pid, M.online_write);
 
 		// step 2

+ 1 - 1
src/protocols/Reshuffle.java

@@ -64,7 +64,7 @@ public class Reshuffle extends Protocol {
 			z[i] = path[i].xor(predata.reshuffle_p[i]);
 
 		timer.start(pid, M.online_write);
-		con1.write(z);
+		con1.write(pid, z);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 15 - 1
src/protocols/Retrieve.java

@@ -15,6 +15,8 @@ import protocols.precomputation.PreRetrieve;
 import protocols.struct.OutAccess;
 import protocols.struct.Party;
 import protocols.struct.PreData;
+import util.Bandwidth;
+import util.P;
 import util.StopWatch;
 import util.Timer;
 import util.Util;
@@ -104,8 +106,13 @@ public class Retrieve extends Protocol {
 			long N = Util.nextLong(numInsert, Crypto.sr);
 
 			for (int j = 0; j < repeat; j++) {
-				if (i * records + j == abandCycles)
+				int cycleIndex = i * records + j;
+				if (cycleIndex == abandCycles)
 					timer.reset();
+				if (cycleIndex == 1) {
+					con1.bandSwitch = false;
+					con2.bandSwitch = false;
+				}
 
 				System.out.println("Test: " + i + " " + j);
 				System.out.println("N=" + BigInteger.valueOf(N).toString(2));
@@ -199,6 +206,13 @@ public class Retrieve extends Protocol {
 		System.out.println();
 		timer.divideBy(cycles - abandCycles).print();
 
+		System.out.println();
+		Bandwidth[] bandwidth = new Bandwidth[P.size];
+		for (int i = 0; i < P.size; i++) {
+			bandwidth[i] = con1.bandwidth[i].add(con2.bandwidth[i]);
+			System.out.println(bandwidth[i]);
+		}
+
 		// System.out.println();
 		// System.out.println(sw.toMS());
 	}

+ 4 - 4
src/protocols/SSCOT.java

@@ -44,8 +44,8 @@ public class SSCOT extends Protocol {
 		}
 
 		timer.start(pid, M.online_write);
-		con2.write(e);
-		con2.write(v);
+		con2.write(pid, e);
+		con2.write(pid, v);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);
@@ -69,8 +69,8 @@ public class SSCOT extends Protocol {
 		}
 
 		timer.start(pid, M.online_write);
-		con2.write(p);
-		con2.write(w);
+		con2.write(pid, p);
+		con2.write(pid, w);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 4 - 4
src/protocols/SSIOT.java

@@ -46,8 +46,8 @@ public class SSIOT extends Protocol {
 		}
 
 		timer.start(pid, M.online_write);
-		con2.write(e);
-		con2.write(v);
+		con2.write(pid, e);
+		con2.write(pid, v);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);
@@ -64,8 +64,8 @@ public class SSIOT extends Protocol {
 		byte[] w = predata.ssiot_F_kprime.compute(y);
 
 		timer.start(pid, M.online_write);
-		con2.write(p);
-		con2.write(w);
+		con2.write(pid, p);
+		con2.write(pid, w);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);

+ 6 - 6
src/protocols/SSXOT.java

@@ -41,7 +41,7 @@ public class SSXOT extends Protocol {
 			a[i] = m[predata.ssxot_E_pi[id][i]].xor(predata.ssxot_E_r[id][i]);
 
 		timer.start(pid, M.online_write);
-		con2.write(a);
+		con2.write(pid, a);
 		timer.stop(pid, M.online_write);
 
 		timer.start(pid, M.online_read);
@@ -78,10 +78,10 @@ public class SSXOT extends Protocol {
 		}
 
 		timer.start(pid, M.online_write);
-		con2.write(E_j);
-		con2.write(E_p);
-		con1.write(C_j);
-		con1.write(C_p);
+		con2.write(pid, E_j);
+		con2.write(pid, E_p);
+		con1.write(pid, C_j);
+		con1.write(pid, C_p);
 		timer.stop(pid, M.online_write);
 
 		timer.stop(pid, M.online_comp);
@@ -96,7 +96,7 @@ public class SSXOT extends Protocol {
 			a[i] = m[predata.ssxot_C_pi[id][i]].xor(predata.ssxot_C_r[id][i]);
 
 		timer.start(pid, M.online_write);
-		con1.write(a);
+		con1.write(pid, a);
 		timer.stop(pid, M.online_write);
 
 		timer.start(pid, M.online_read);

+ 6 - 6
src/protocols/UpdateRoot.java

@@ -43,10 +43,10 @@ public class UpdateRoot extends Protocol {
 		GCSignal[][] E_labelInputKeys = GCUtil.selectLabelKeys(predata.ur_E_labelKeyPairs, R);
 
 		timer.start(pid, M.online_write);
-		con1.write(j1InputKeys);
-		con1.write(LiInputKeys);
-		con1.write(E_feInputKeys);
-		con1.write(E_labelInputKeys);
+		con1.write(pid, j1InputKeys);
+		con1.write(pid, LiInputKeys);
+		con1.write(pid, E_feInputKeys);
+		con1.write(pid, E_labelInputKeys);
 		timer.stop(pid, M.online_write);
 
 		// step 4
@@ -108,8 +108,8 @@ public class UpdateRoot extends Protocol {
 		GCSignal[][] C_labelInputKeys = GCUtil.selectLabelKeys(predata.ur_C_labelKeyPairs, R);
 
 		timer.start(pid, M.online_write);
-		con2.write(C_feInputKeys);
-		con2.write(C_labelInputKeys);
+		con2.write(pid, C_feInputKeys);
+		con2.write(pid, C_labelInputKeys);
 		timer.stop(pid, M.online_write);
 
 		// step 4

+ 40 - 0
src/util/Bandwidth.java

@@ -0,0 +1,40 @@
+package util;
+
+import exceptions.BandwidthException;
+
+public class Bandwidth {
+
+	public String task;
+	public int bandwidth;
+
+	public Bandwidth(String t) {
+		task = t;
+		bandwidth = 0;
+	}
+
+	public Bandwidth(Bandwidth b) {
+		task = b.task;
+		bandwidth = b.bandwidth;
+	}
+
+	public void reset() {
+		bandwidth = 0;
+	}
+
+	public void add(int n) {
+		bandwidth += n;
+	}
+
+	public Bandwidth add(Bandwidth b) {
+		if (!task.equals(b.task))
+			throw new BandwidthException("Task: " + task + " != " + b.task);
+		Bandwidth total = new Bandwidth(task);
+		total.bandwidth = bandwidth + b.bandwidth;
+		return total;
+	}
+
+	@Override
+	public String toString() {
+		return task + "(bytes): " + bandwidth;
+	}
+}