summaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorthibauth <thibauth@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-06-30 16:02:23 +0000
committerthibauth <thibauth@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-06-30 16:02:23 +0000
commit1bc4b7d7b988976d37a05c1c7a8348fb92985400 (patch)
tree759eca257d2edffe1faa2e9acea3518eaf6be370 /sources
parent9ddda112ef635e8dff6a50a98b2e7814d99ddcea (diff)
downloadpacemaker-1bc4b7d7b988976d37a05c1c7a8348fb92985400.tar.gz
Fix the bug found yesterday
git-svn-id: https://scm.gforge.inria.fr/svn/pacemaker@36 30fcff6e-8de6-41c7-acce-77ff6d1dd07b
Diffstat (limited to 'sources')
-rw-r--r--sources/thibaut/gentrace.ml5
-rw-r--r--sources/thibaut/globals.ml11
-rw-r--r--sources/thibaut/pacemaker.ml20
-rw-r--r--sources/thibaut/plot.py20
-rw-r--r--sources/thibaut/simulator.ml7
-rw-r--r--sources/thibaut/trace.ml14
-rw-r--r--sources/thibaut/tracestats.ml24
7 files changed, 52 insertions, 49 deletions
diff --git a/sources/thibaut/gentrace.ml b/sources/thibaut/gentrace.ml
index b956bce..7d58ed8 100644
--- a/sources/thibaut/gentrace.ml
+++ b/sources/thibaut/gentrace.ml
@@ -41,8 +41,7 @@ let _ =
let peers = Array.init !npeers
(fun i ->
let avail = if i = 0 then 1. else Random.float 1. in
- let init = Random.float 1. in
- let state = if init < avail then ON else OFF in
+ let state = if i = 0 then ON else OFF in
let session_length = 10 + Random.int 90 in
let mu = if i = 0 then 0. else 1./. (float_of_int session_length) in
let lambda = mu*.(1.-.avail)/.avail in
@@ -67,7 +66,7 @@ let _ =
output oc (On p.Trace.id)
end else if p.state = ON && r < p.mu then begin
p.Trace.state <- OFF;
- output oc (Off p.Trace.id)
+ output oc (Off p.Trace.id)
end
in
Array.iter aux peers
diff --git a/sources/thibaut/globals.ml b/sources/thibaut/globals.ml
index 58f2421..9f8f3a0 100644
--- a/sources/thibaut/globals.ml
+++ b/sources/thibaut/globals.ml
@@ -244,18 +244,19 @@ type peer = {
messages : message Queue.t;
mutable history : (int * (int HashMap.t list)) RoundMap.t; (* seed, branch *)
mutable distance : int;
- mutable connection_time : int
+ mutable connection_time : int;
+ mutable nproofs : int
}
and slot = peer SlotArray.slot
let disconnect oc round peer =
SlotArray.clear peer.slots;
+ if (round-peer.connection_time) > 0 then
+ Printf.fprintf oc "%d %d %d\n%!" peer.id (round-peer.connection_time)
+ peer.nproofs;
peer.con_state <- OFF;
peer.distance <- -1;
- if (round-peer.connection_time) > 0 then
- Printf.fprintf oc "%d %d\n%!" peer.id
- (round-peer.connection_time)
-
+ peer.nproofs <- 0
let swap a pos1 pos2 =
let temp = a.(pos1) in
diff --git a/sources/thibaut/pacemaker.ml b/sources/thibaut/pacemaker.ml
index 26c30dc..32f0047 100644
--- a/sources/thibaut/pacemaker.ml
+++ b/sources/thibaut/pacemaker.ml
@@ -59,7 +59,9 @@ let server_init_pulse peer round =
let rec verify_branch branch = match branch with
| [] -> true
| [h] -> true
- | h1::h2::t -> (HashMap.mem (Hashtbl.hash h1) h2 && verify_branch t)
+ | h1::h2::t ->
+ let hash = Hashtbl.hash h1 in
+ (HashMap.exists (fun _ a -> a = hash) h2) && (verify_branch (h2::t))
let process_message oc current_round peer m =
if m.round >= (current_round - 2) then
@@ -75,9 +77,9 @@ let process_message oc current_round peer m =
SlotArray.iter (send_message message) peer.slots
| SeedReply(hash) ->
begin try
- let data = RoundMap.find m.round peer.rounds_data in
+ let data = RoundMap.find m.round peer.rounds_data in
if data.phase = SEEDING then
- data.hmap <- HashMap.add m.sender hash data.hmap;
+ data.hmap <- HashMap.add m.sender hash data.hmap;
with
Not_found -> ()
end
@@ -92,18 +94,20 @@ let process_message oc current_round peer m =
let hash = HashMap.find peer.id h in
let hmap = find_reply hash data.replies in
if verify_branch branch then
- let branch2 = hmap::branch in
+ let branch2 = hmap::branch in
let message = {
sender = peer.id;
round = m.round;
content = Pulse(seed, branch2)
} in
- data.phase <- PULSE;
+ if data.phase = SEEDING then begin
+ data.phase <- PULSE;
+ Printf.fprintf oc "%d %d\n" peer.id current_round;
+ peer.nproofs <- peer.nproofs + 1
+ end;
SlotArray.iter (send_message message) peer.slots;
peer.history <- RoundMap.add m.round
(seed, branch2) peer.history;
- Printf.fprintf oc "%d %d %d\n" peer.id
- peer.distance current_round
with
| Not_found -> ()
with
@@ -121,7 +125,7 @@ let do_peer oc current_round peer =
let message = {
sender = peer.id;
round = round;
- content = SeedReply(Hashtbl.hash data.hmap)
+ content = SeedReply(hash)
} in
SlotArray.iter (send_message message) peer.slots;
end
diff --git a/sources/thibaut/plot.py b/sources/thibaut/plot.py
index f00a0ab..92e5fcd 100644
--- a/sources/thibaut/plot.py
+++ b/sources/thibaut/plot.py
@@ -5,22 +5,24 @@ import os
dirname = sys.argv[1]
-rounds = os.path.join(dirname, "rounds.data")
+"""rounds = os.path.join(dirname, "rounds.data")
a = np.loadtxt(rounds, unpack=True, usecols=(1,))
plt.plot(a)
-plt.savefig(os.path.join(dirname, "rounds.png"))
+plt.savefig(os.path.join(dirname, "rounds.png"))"""
plt.cla()
-sessions = os.path.join(dirname, "trace.data")
+sessions = os.path.join(dirname, "sessions.data")
a = np.loadtxt(sessions)
-plt.plot(a)
-plt.show()
+plt.hist(a, bins=100)
plt.savefig(os.path.join(dirname, "sessions.png"))
plt.cla()
-sessions = os.path.join(dirname, "avail.data")
-a = np.loadtxt(sessions)
-plt.plot(a)
-plt.show()
+avail = os.path.join(dirname, "avail.data")
+a = np.loadtxt(avail)
+plt.hist(a, bins=100,range=(0,1))
plt.savefig(os.path.join(dirname, "avail.png"))
+simul_sessions = os.path.join(dirname, "simul_sessions.data")
+a,b = np.loadtxt(simul_sessions, unpack=True, usecols = (1,2))
+c = np.unique(np.floor(a/10))
+print np.sum(np.floor(a/10))/np.sum(b)
diff --git a/sources/thibaut/simulator.ml b/sources/thibaut/simulator.ml
index 0536a8c..52cc047 100644
--- a/sources/thibaut/simulator.ml
+++ b/sources/thibaut/simulator.ml
@@ -83,12 +83,13 @@ let peers = Array.init npeers
history = RoundMap.empty;
distance = -1;
connection_time = 0;
+ nproofs = 1
} in
p )
(* tracking array keeps track of the position of peer i in the peers array *)
let tracking_array = Array.init npeers (fun i -> i)
-let do_trace_round = Trace.read sessions_oc ic peers
+let do_trace_round = Trace.read sessions_oc ic tracking_array peers
let nticks = (days)*24*60*(!tpm)
let round = ref 0
let connected = ref 0
@@ -96,8 +97,8 @@ let connected = ref 0
let _ =
Printf.fprintf oc "#minute connected messages asks askroots\n%!";
Printf.fprintf mesh_oc "#minute connected old repart\n%!";
- Printf.fprintf sessions_oc "#id duration\n%!";
- Printf.fprintf proofs_oc "#id distance round\n%!";
+ Printf.fprintf sessions_oc "#id duration nproofs\n%!";
+ Printf.fprintf proofs_oc "#id round\n%!";
for i = 0 to (nticks-1) do
for i = 0 to 2 do
diff --git a/sources/thibaut/trace.ml b/sources/thibaut/trace.ml
index 018831f..47fd3c5 100644
--- a/sources/thibaut/trace.ml
+++ b/sources/thibaut/trace.ml
@@ -55,11 +55,11 @@ let read_info ic =
in
npeers, ndays
-let read oc ic peers =
+let read oc ic tracking peers =
let npeers = Array.length peers in
for i = 0 to (npeers-1) do
match input ic with
- | Peer (i, avail, state) -> () (*peers.(i).con_state <- state*)
+ | Peer (i, avail, state) -> peers.(i).con_state <- state
| _ -> failwith "Not enough peers"
done;
@@ -69,12 +69,12 @@ let read oc ic peers =
let rec read_round round =
match !event with
| Round n -> if n = round then next round
- | On i ->
- peers.(i).con_state <- ON;
- peers.(i).connection_time <- round;
+ | On i -> let peer = peers.(tracking.(i)) in
+ peer.con_state <- ON;
+ peer.connection_time <- round;
next round
- | Off i ->
- disconnect oc round peers.(i);
+ | Off i -> let peer = peers.(tracking.(i)) in
+ disconnect oc round peer;
next round
| _ -> ()
diff --git a/sources/thibaut/tracestats.ml b/sources/thibaut/tracestats.ml
index 5f952a6..a769eac 100644
--- a/sources/thibaut/tracestats.ml
+++ b/sources/thibaut/tracestats.ml
@@ -52,7 +52,6 @@ let _ =
let avail_oc = open_out (Filename.concat !outputdir "avail.data") in
let peers, nrounds, iter_round = Compattrace.trace_read !inputfile in
let npeers = Array.length peers in
- let sessions = Array.make 1000 0 in
for i = 0 to (nrounds-1) do
iter_round i;
let nconnected = ref 0 in
@@ -64,19 +63,16 @@ let _ =
incr nconnected
end
else if p.state = OFF then begin
- if p.session > 0 && p.session < 1000 then begin
- sessions.(p.session) <- sessions.(p.session) + 1;
- p.session <- 0;
- end
+ if p.session > 0 then
+ Printf.fprintf sessions_oc "%d\n" p.session;
+ p.session <- 0;
end
done
done;
- Array.iter (Printf.fprintf sessions_oc "%d\n") sessions;
- let avail = Array.make 101 0 in
- Array.iter
- (fun p ->
- let a = p.real_avail*100/nrounds in
- avail.(a) <- avail.(a) + 1
- )
- peers;
- Array.iter (Printf.fprintf avail_oc "%d\n") avail
+ Array.iter
+ (fun p ->
+ Printf.fprintf avail_oc "%f\n"
+ ((float_of_int p.real_avail)/.(float_of_int nrounds))
+ )
+ peers;
+