summaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
Diffstat (limited to 'sources')
-rw-r--r--sources/thibaut/Makefile22
-rw-r--r--sources/thibaut/gentrace.ml3
-rw-r--r--sources/thibaut/globals.ml10
-rw-r--r--sources/thibaut/map2.ml (renamed from sources/thibaut/map.ml)0
-rw-r--r--sources/thibaut/map2.mli (renamed from sources/thibaut/map.mli)0
-rw-r--r--sources/thibaut/pacemaker.ml9
-rw-r--r--sources/thibaut/simulator.ml49
-rw-r--r--sources/thibaut/trace.ml40
8 files changed, 89 insertions, 44 deletions
diff --git a/sources/thibaut/Makefile b/sources/thibaut/Makefile
index 79583d1..187aa22 100644
--- a/sources/thibaut/Makefile
+++ b/sources/thibaut/Makefile
@@ -1,13 +1,21 @@
-OCAMLC=ocamlc
-OCAMLOPT=ocamlopt
-OCAMLDEP=ocamldep
+OCAMLC=ocamlc.opt
+OCAMLOPT=ocamlopt.opt
+OCAMLDEP=ocamldep.opt
INCLUDES=
OCAMLFLAGS=$(INCLUDES)
-SRCS=map.ml simulator.ml trace.ml gentrace.ml pacemaker.ml
+SRCS=map2.ml simulator.ml trace.ml gentrace.ml pacemaker.ml globals.ml
+BUILDDIR=build
+all: gentrace.opt simulator.opt
-simulator.opt : simulator.cmx
- $(OCAMLOPT) -o simulator $(OCAMLFLAGS) map.cmx pacemaker.cmx simulator.cmx
+builddir:
+ mkdir -p $(BUILDDIR)
+
+gentrace.opt: builddir gentrace.cmx
+ $(OCAMLOPT) -o $(BUILDDIR)/gentrace $(OCAMLFLAGS) map2.cmx str.cmxa globals.cmx pacemaker.cmx trace.cmx gentrace.cmx
+
+simulator.opt : builddir simulator.cmx
+ $(OCAMLOPT) -o $(BUILDDIR)/simulator $(OCAMLFLAGS) map2.cmx str.cmxa globals.cmx pacemaker.cmx trace.cmx simulator.cmx
clean:
rm -f *.cm? *.cmx? *.o *~
@@ -24,4 +32,4 @@ depend: $(SRCS)
%.cmx : %.ml
$(OCAMLOPT) -c $(OCAMLFLAGS) $<
--include .depend \ No newline at end of file
+-include .depend
diff --git a/sources/thibaut/gentrace.ml b/sources/thibaut/gentrace.ml
index ea12bf5..ad4734a 100644
--- a/sources/thibaut/gentrace.ml
+++ b/sources/thibaut/gentrace.ml
@@ -1,4 +1,5 @@
open Trace
+open Globals
let ndays = ref 0
let npeers = ref 0
@@ -38,7 +39,7 @@ let _ =
output oc (Days !ndays)
let peers = Array.init !npeers (fun i ->
- let avail = Random.float 1. in
+ 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 session_length = 10 + Random.int 90 in
diff --git a/sources/thibaut/globals.ml b/sources/thibaut/globals.ml
new file mode 100644
index 0000000..90a5a48
--- /dev/null
+++ b/sources/thibaut/globals.ml
@@ -0,0 +1,10 @@
+type state = ON | OFF
+
+let string_of_state state = match state with
+ | ON -> "On"
+ | OFF -> "Off"
+
+let state_of_string s = match s with
+ | "On" -> ON
+ | "Off" -> OFF
+ | _ -> failwith (Printf.sprintf "Wrong state:%s" s)
diff --git a/sources/thibaut/map.ml b/sources/thibaut/map2.ml
index 3d9597a..3d9597a 100644
--- a/sources/thibaut/map.ml
+++ b/sources/thibaut/map2.ml
diff --git a/sources/thibaut/map.mli b/sources/thibaut/map2.mli
index b025b8c..b025b8c 100644
--- a/sources/thibaut/map.mli
+++ b/sources/thibaut/map2.mli
diff --git a/sources/thibaut/pacemaker.ml b/sources/thibaut/pacemaker.ml
index 7a26a47..2b85e79 100644
--- a/sources/thibaut/pacemaker.ml
+++ b/sources/thibaut/pacemaker.ml
@@ -1,5 +1,6 @@
+open Globals
+
type phase = SEEDING | IDLE
-type state = ON | OFF
type peer_id = int
module PeerId = struct
@@ -12,9 +13,9 @@ module Int = struct
let compare a b = - (Pervasives.compare a b)
end
-module HashMap = Map.Make(PeerId)
+module HashMap = Map2.Make(PeerId)
-module RoundMap = Map.Make(Int)
+module RoundMap = Map2.Make(Int)
type message_content =
| Seed of int * int (* seed, duration *)
@@ -177,4 +178,4 @@ let do_server peer =
| _ -> ()
in
Queue.iter aux peer.messages;
- Queue.clear peer.messages \ No newline at end of file
+ Queue.clear peer.messages
diff --git a/sources/thibaut/simulator.ml b/sources/thibaut/simulator.ml
index e097d4d..32855d8 100644
--- a/sources/thibaut/simulator.ml
+++ b/sources/thibaut/simulator.ml
@@ -1,12 +1,12 @@
open Pacemaker
+open Globals
-let npeers = ref 0
-let degree = ref 0
-let days = ref 0
-let tpm = ref 0
-let accuracy = ref 0
-let duration = ref 0
+let degree = ref 10
+let tpm = ref 3
+let accuracy = ref 30
+let duration = ref 9
let seed = ref 0
+let filename = ref ""
let arg_list = [
"--degree", Arg.Set_int degree, " <n> maximum number of neighbours";
@@ -16,13 +16,30 @@ let arg_list = [
"--seed", Arg.Set_int seed, " <n> random seed"
]
+let anon =
+ let args = ref 0 in
+ fun s ->
+ incr args;
+ match !args with
+ | 1 -> filename := s
+ | _ -> raise (Arg.Bad "Too many arguments")
+
let usage = "usage: simul [OPTIONS] <tracefile>"
let _ =
- Arg.parse (Arg.align arg_list) (fun s -> ()) usage;
- Random.init !seed
+ if Array.length Sys.argv < 2 then begin
+ Arg.usage (Arg.align arg_list) usage;
+ exit 1
+ end else begin
+ Arg.parse (Arg.align arg_list) anon usage;
+ Random.init !seed
+ end
+
+let ic = open_in !filename
+
+let npeers, days = Trace.read_info ic
-let peers = Array.init !npeers (fun i -> {
+let peers = Array.init npeers (fun i -> {
id = i;
con_state = OFF;
neighbours = Array.make !degree None;
@@ -31,7 +48,9 @@ let peers = Array.init !npeers (fun i -> {
history = RoundMap.empty
})
-let nticks = (!days)*24*60*(!tpm)
+let read_round = Trace.read ic peers npeers
+
+let nticks = (days)*24*60*(!tpm)
let round = ref 0
let _ =
@@ -39,12 +58,16 @@ let _ =
if i mod !accuracy = 0 then begin
incr round;
server_init_seed peers.(0) !round !duration
- end
- else if i mod !accuracy = !duration then
+ end;
+
+ if i mod !accuracy = !duration then
server_init_pulse peers.(0) !round;
+ if i mod !tpm = 0 then
+ read_round (i/(!tpm));
+
do_server peers.(0);
- for i = 1 to (!npeers-1) do
+ for i = 1 to (npeers-1) do
let peer = peers.(i) in
if peer.con_state = ON then
do_peer peer
diff --git a/sources/thibaut/trace.ml b/sources/thibaut/trace.ml
index 2ee7c2a..aa74285 100644
--- a/sources/thibaut/trace.ml
+++ b/sources/thibaut/trace.ml
@@ -1,11 +1,10 @@
-type peer_state =
- | ON
- | OFF
+open Globals
+open Pacemaker
type event =
| Peers of int
| Days of int
- | Peer of int * float * peer_state
+ | Peer of int * float * state
| Round of int
| On of int
| Off of int
@@ -14,16 +13,12 @@ type event =
type peer = {
id : int;
- mutable state : peer_state;
+ mutable state : state;
avail : float;
lambda : float;
mu : float
}
-
-let string_of_state state = match state with
- | ON -> "On"
- | OFF -> "Off"
-
+
let output oc trace_event =
let print s = Printf.fprintf oc s in
match trace_event with
@@ -42,6 +37,9 @@ let input ic =
let space = Str.regexp " " in
match Str.split space line with
| ["Peers"; npeers] -> Peers (int_of_string npeers)
+ | ["Peer"; id; avail; state] -> Peer (int_of_string id,
+ float_of_string avail,
+ state_of_string state)
| ["Days"; ndays] -> Days (int_of_string ndays)
| ["End"] -> End
| ["Round"; round] -> Round (int_of_string round)
@@ -49,7 +47,7 @@ let input ic =
| ["Off"; i] -> Off (int_of_string i)
| _ -> failwith (Printf.sprintf "Bad line [%s]" (String.escaped line))
-let read ic =
+let read_info ic =
let npeers = match input ic with
| Peers n -> n
| _ -> failwith "Bad trace"
@@ -58,20 +56,24 @@ let read ic =
| Days n -> n
| _ -> failwith "Bad trace"
in
- for i = 0 to npeers do
+ npeers, ndays
+
+let read ic peers npeers =
+ for i = 0 to (npeers-1) do
match input ic with
- | Peer (i, avail, state) -> ()
+ | Peer (i, avail, state) -> peers.(i).con_state <- state
| _ -> failwith "Not enough peers"
done;
+
let event = ref (input ic) in
let get_event () = event := (input ic) in
- let rec read_round round peers =
+ let rec read_round round =
match !event with
- | Round n -> if n = round then next round peers
- | On i -> peers.(i).Pacemaker.state <- ON; next round peers
- | Off i -> peers.(i).Pacemaker.state <- OFF; next round peers
+ | Round n -> if n = round then next round
+ | On i -> peers.(i).con_state <- ON; next round
+ | Off i -> peers.(i).con_state <- OFF; next round
| _ -> ()
- and next round peers = get_event(); read_round round peers in
- npeers, ndays, read_round
+ and next round = get_event(); read_round round in
+ read_round