-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LockServ with SeqNum VST applied (#2)
System with applied SeqNum transformer and extraction-related files.
- Loading branch information
Showing
12 changed files
with
281 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ocaml/LockServSeqNum.ml | ||
ocaml/LockServSeqNum.mli | ||
_build | ||
LockServSeqNumMain.native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
OCAMLBUILD = ocamlbuild -use-ocamlfind -tag thread -package verdi-runtime -I ocaml -cflag -g | ||
|
||
MLEXTRACTED = ocaml/LockServSeqNum.ml ocaml/LockServSeqNum.mli | ||
|
||
MLFILES = ocaml/LockServSeqNumArrangement.ml ocaml/LockServSeqNumSerialization.ml \ | ||
ocaml/LockServSeqNumMain.ml ocaml/LockServSeqNumOpts.ml | ||
|
||
default: LockServSeqNumMain.native | ||
|
||
$(MLEXTRACTED): | ||
+$(MAKE) -C ../.. extraction/lockserv-seqnum/$@ | ||
|
||
LockServSeqNumMain.native: $(MLEXTRACTED) $(MLFILES) | ||
$(OCAMLBUILD) LockServSeqNumMain.native | ||
|
||
clean: | ||
$(OCAMLBUILD) -clean | ||
|
||
.PHONY: default clean $(MLEXTRACTED) | ||
|
||
.NOTPARALLEL: $(MLEXTRACTED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Require Import Verdi.Verdi. | ||
|
||
Require Import LockServSeqNum. | ||
|
||
Require Import ExtrOcamlBasic. | ||
Require Import ExtrOcamlNatInt. | ||
|
||
Require Import Verdi.ExtrOcamlBasicExt. | ||
Require Import Verdi.ExtrOcamlList. | ||
Require Import Verdi.ExtrOcamlFin. | ||
|
||
Extraction "extraction/lockserv-seqnum/ocaml/LockServSeqNum.ml" seq transformed_base_params transformed_multi_params. |
68 changes: 68 additions & 0 deletions
68
extraction/lockserv-seqnum/ocaml/LockServSeqNumArrangement.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module type IntValue = sig | ||
val v : int | ||
end | ||
|
||
module type Params = sig | ||
val debug : bool | ||
val num_clients : int | ||
end | ||
|
||
module LockServSeqNumArrangement (P : Params) = struct | ||
type name = LockServSeqNum.name0 | ||
type state = LockServSeqNum.seq_num_data | ||
type input = LockServSeqNum.msg0 | ||
type output = LockServSeqNum.msg0 | ||
type msg = LockServSeqNum.seq_num_msg | ||
type client_id = int | ||
type res = (output list * state) * ((name * msg) list) | ||
type task_handler = name -> state -> res | ||
type timeout_setter = name -> state -> float | ||
|
||
let systemName = "Lock Server with Sequence Numbering" | ||
|
||
let serializeName = LockServSeqNumSerialization.serializeName | ||
|
||
let deserializeName = LockServSeqNumSerialization.deserializeName | ||
|
||
let init = fun n -> | ||
let open LockServSeqNum in | ||
Obj.magic ((transformed_multi_params P.num_clients).init_handlers (Obj.magic n)) | ||
|
||
let handleIO = fun n i s -> | ||
let open LockServSeqNum in | ||
Obj.magic ((transformed_multi_params P.num_clients).input_handlers (Obj.magic n) (Obj.magic i) (Obj.magic s)) | ||
|
||
let handleNet = fun dst src m s -> | ||
let open LockServSeqNum in | ||
Obj.magic ((transformed_multi_params P.num_clients).net_handlers (Obj.magic dst) (Obj.magic src) (Obj.magic m) (Obj.magic s)) | ||
|
||
let deserializeMsg = LockServSeqNumSerialization.deserializeMsg | ||
|
||
let serializeMsg = LockServSeqNumSerialization.serializeMsg | ||
|
||
let deserializeInput = LockServSeqNumSerialization.deserializeInput | ||
|
||
let serializeOutput = LockServSeqNumSerialization.serializeOutput | ||
|
||
let debug = P.debug | ||
|
||
let debugInput = fun _ inp -> | ||
Printf.printf "[%s] got input %s" (Util.timestamp ()) (LockServSeqNumSerialization.debugSerializeInput inp); | ||
print_newline () | ||
|
||
let debugRecv = fun _ (nm, msg) -> | ||
Printf.printf "[%s] receiving message %s from %s" (Util.timestamp ()) (LockServSeqNumSerialization.debugSerializeMsg msg) (serializeName nm); | ||
print_newline () | ||
|
||
let debugSend = fun _ (nm, msg) -> | ||
Printf.printf "[%s] sending message %s to %s" (Util.timestamp ()) (LockServSeqNumSerialization.debugSerializeMsg msg) (serializeName nm); | ||
print_newline () | ||
|
||
let createClientId () = | ||
let upper_bound = 1073741823 in | ||
Random.int upper_bound | ||
|
||
let serializeClientId = string_of_int | ||
|
||
let timeoutTasks = [] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open LockServSeqNumOpts | ||
open LockServSeqNumArrangement | ||
|
||
let () = | ||
let () = | ||
try | ||
parse Sys.argv | ||
with | ||
| Arg.Help msg -> | ||
Printf.printf "%s: %s" Sys.argv.(0) msg; | ||
exit 2 | ||
| Arg.Bad msg -> | ||
Printf.eprintf "%s" msg; | ||
exit 2 | ||
in | ||
let () = | ||
try | ||
validate () | ||
with Arg.Bad msg -> | ||
Printf.eprintf "%s: %s." Sys.argv.(0) msg; | ||
prerr_newline (); | ||
exit 2 | ||
in | ||
let module Pms = struct | ||
let debug = !debug | ||
let num_clients = List.length !cluster - 1 | ||
end in | ||
let module Arrangement = LockServSeqNumArrangement (Pms) in | ||
let module Shim = UnorderedShim.Shim (Arrangement) in | ||
let open Shim in | ||
main { cluster = !cluster | ||
; me = !me | ||
; port = !port | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
open List | ||
open Printf | ||
open Str | ||
|
||
let cluster_default : (LockServSeqNum.name0 * (string * int)) list = [] | ||
let me_default : LockServSeqNum.name0 = LockServSeqNum.Server | ||
let port_default : int = 8351 | ||
let debug_default : bool = true | ||
|
||
let cluster = ref cluster_default | ||
let me = ref me_default | ||
let port = ref port_default | ||
let debug = ref debug_default | ||
|
||
let node_spec arg nodes_ref doc = | ||
let parse opt = | ||
(* name,ip:port *) | ||
if string_match (regexp "\\([^,]+\\),\\(.+\\):\\([0-9]+\\)") opt 0 then | ||
match LockServSeqNumSerialization.deserializeName (matched_group 1 opt) with | ||
| Some nm -> (nm, (matched_group 2 opt, int_of_string (matched_group 3 opt))) | ||
| None -> raise (Arg.Bad (sprintf "wrong argument: '%s'; option '%s' expects a proper name" arg opt)) | ||
else | ||
raise (Arg.Bad (sprintf "wrong argument: '%s'; option '%s' expects an entry in the form 'name,host:port'" arg opt)) | ||
in (arg, Arg.String (fun opt -> nodes_ref := !nodes_ref @ [parse opt]), doc) | ||
|
||
let parse inp = | ||
let opts = | ||
[ node_spec "-node" cluster "{name,host:port} one node in the cluster" | ||
; ("-me", Arg.String (fun opt -> | ||
match LockServSeqNumSerialization.deserializeName opt with | ||
| Some nm -> me := nm | ||
| None -> raise (Arg.Bad (sprintf "wrong argument: '-me' expects a proper name"))), "{name} name for this node") | ||
; ("-port", Arg.Set_int port, "{port} port for client commands") | ||
; ("-debug", Arg.Set debug, "run in debug mode") | ||
] in | ||
Arg.parse_argv ?current:(Some (ref 0)) inp | ||
opts | ||
(fun x -> raise (Arg.Bad (sprintf "%s does not take position arguments" inp.(0)))) | ||
"Try -help for help or one of the following." | ||
|
||
let rec assoc_unique = function | ||
| [] -> true | ||
| (k, _) :: l -> if mem_assoc k l then false else assoc_unique l | ||
|
||
let validate () = | ||
if length !cluster = 0 then | ||
raise (Arg.Bad "Please specify at least one -node"); | ||
if not (mem_assoc !me !cluster) then | ||
raise (Arg.Bad (sprintf "%s is not a member of this cluster" (LockServSeqNumSerialization.serializeName !me))); | ||
if not (assoc_unique !cluster) then | ||
raise (Arg.Bad "Please remove duplicate -node name entries"); | ||
if !port = snd (List.assoc !me !cluster) then | ||
raise (Arg.Bad "Can't use same port for client commands and messages") |
37 changes: 37 additions & 0 deletions
37
extraction/lockserv-seqnum/ocaml/LockServSeqNumSerialization.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
let serializeName : LockServSeqNum.name0 -> string = function | ||
| LockServSeqNum.Server -> "Server" | ||
| LockServSeqNum.Client i -> Printf.sprintf "Client-%d" i | ||
|
||
let deserializeName (s : string) : LockServSeqNum.name0 option = | ||
match s with | ||
| "Server" -> Some LockServSeqNum.Server | ||
| _ -> | ||
try Scanf.sscanf s "Client-%d" (fun x -> Some (LockServSeqNum.Client (Obj.magic x))) | ||
with _ -> None | ||
|
||
let deserializeMsg : string -> LockServSeqNum.seq_num_msg = fun s -> | ||
Marshal.from_string s 0 | ||
|
||
let serializeMsg : LockServSeqNum.seq_num_msg -> string = fun m -> | ||
Marshal.to_string m [] | ||
|
||
let deserializeInput inp c : LockServSeqNum.msg0 option = | ||
match inp with | ||
| "Unlock" -> Some LockServSeqNum.Unlock | ||
| "Lock" -> Some (LockServSeqNum.Lock c) | ||
| "Locked" -> Some (LockServSeqNum.Locked c) | ||
| _ -> None | ||
|
||
let serializeOutput : LockServSeqNum.msg0 -> int * string = function | ||
| LockServSeqNum.Lock _ -> (0, "Lock") (* never happens *) | ||
| LockServSeqNum.Unlock -> (0, "Unlock") (* never happens *) | ||
| LockServSeqNum.Locked c -> (c, "Locked") | ||
|
||
let debugSerializeInput : LockServSeqNum.msg0 -> string = function | ||
| LockServSeqNum.Lock c -> Printf.sprintf "Lock %d" c | ||
| LockServSeqNum.Unlock -> "Unlock" | ||
| LockServSeqNum.Locked c -> Printf.sprintf "Locked %d" c | ||
|
||
let debugSerializeMsg : LockServSeqNum.seq_num_msg -> string = function | ||
| { LockServSeqNum.tmNum = n ; LockServSeqNum.tmMsg = m } -> | ||
Printf.sprintf "%d: %s" n (debugSerializeInput (Obj.magic m)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env bash | ||
./LockServSeqNumMain.native -me $1 -port $2 -node Server,localhost:9000 -node Client-0,localhost:9001 -node Client-1,localhost:9002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Require Import Verdi.Verdi. | ||
|
||
Require Import LockServ. | ||
Require Verdi.SeqNum. | ||
Require Import Verdi.SeqNumCorrect. | ||
|
||
Section LockServSeqNum. | ||
Variable num_Clients : nat. | ||
|
||
Definition transformed_base_params := | ||
@SeqNum.base_params (LockServ_BaseParams num_Clients) (LockServ_MultiParams num_Clients). | ||
|
||
Definition transformed_multi_params := | ||
@SeqNum.multi_params (LockServ_BaseParams num_Clients) (LockServ_MultiParams num_Clients). | ||
|
||
Theorem transformed_correctness : | ||
forall net tr, | ||
step_dup_star (params := transformed_multi_params) step_async_init net tr -> | ||
@mutual_exclusion num_Clients (nwState (revertNetwork net)). | ||
Proof using. | ||
intros. | ||
pose proof @true_in_reachable_transform _ (LockServ_MultiParams num_Clients) | ||
(fun net : network => mutual_exclusion (nwState net)) | ||
(@true_in_reachable_mutual_exclusion num_Clients). | ||
unfold true_in_reachable in *. | ||
apply H0. | ||
unfold reachable. | ||
eauto. | ||
Qed. | ||
End LockServSeqNum. |