diff --git a/lib/sasa/sasaRun.ml b/lib/sasa/sasaRun.ml index 1d3cdd0c0ff90ef21186d74f6d8edcf20aa07493..f51feb528b653e90be695d8523e00a18a573a586 100644 --- a/lib/sasa/sasaRun.ml +++ b/lib/sasa/sasaRun.ml @@ -65,11 +65,6 @@ let (compute_legitimate: bool -> 'v SimuState.t -> bool) = in f pidl get_info -(* update the network processes w.r.t. the config *) -let update_network config network = List.map - (fun (p,nl) -> p, Sasacore.SimuState.update_neighbor_env config nl) - network - open SimuState let (make_do: string array -> 'v SimuState.t -> RdbgPlugin.t) = fun argv st -> @@ -98,8 +93,7 @@ let (make_do: string array -> 'v SimuState.t -> RdbgPlugin.t) = (* Do the same job as SasaSimuState.simustep *) let (step_custom: RdbgPlugin.sl -> RdbgPlugin.sl) = fun sl_in -> - let st = { st with SimuState.network = update_network !sasa_config st.network ; - SimuState.config = !sasa_config } in + let st = Sasacore.SimuState.update_config !sasa_config st in match !pre_enable_processes_opt with | None -> ( (* the first step *) (* 1: Get enable processes *) @@ -122,7 +116,7 @@ let (make_do: string array -> 'v SimuState.t -> RdbgPlugin.t) = in (* 3: Do the steps *) let ne = Sasacore.Step.f pnal st.config in - let nst = { st with network = update_network ne st.network ; config = ne } in + let nst = update_config ne st in let sasa_nenv = from_sasa_env nst in (* 1': Get enable processes *) let pnall, enab_ll = Sasacore.SimuState.get_enable_processes nst in @@ -137,8 +131,7 @@ let (make_do: string array -> 'v SimuState.t -> RdbgPlugin.t) = let (step_internal_daemon: RdbgPlugin.sl -> RdbgPlugin.sl) = fun sl_in -> (* in this mode, sasa does not play first *) - let st = { st with SimuState.network = update_network !sasa_config st.network ; - SimuState.config = !sasa_config } in + let st = update_config !sasa_config st in (* 1: Get enable processes *) let pnall, enab_ll = Sasacore.SimuState.get_enable_processes st in let pot_sl = compute_potentiel st in diff --git a/lib/sasacore/simuState.ml b/lib/sasacore/simuState.ml index 1cf4bf255ed343512f5e48c8a45c4bfd00b69567..787df8f16003ce0ff520e99bd925b2af855a5b36 100644 --- a/lib/sasacore/simuState.ml +++ b/lib/sasacore/simuState.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 16/04/2021 (at 13:28) by Erwan Jahier> *) +(* Time-stamp: <modified the 16/04/2021 (at 15:39) by Erwan Jahier> *) open Register @@ -37,17 +37,25 @@ let (dump_process: string -> 'v Process.t * 'v Register.neighbor list -> unit) = open Process open SasArg +type 'v t = { + sasarg: SasArg.t; + network: ('v Process.t * 'v Register.neighbor list) list; + config: 'v Env.t +} let (update_neighbor_env: 'v Env.t -> 'v Register.neighbor list -> 'v Register.neighbor list) = fun e nl -> List.map (fun n -> { n with state = Env.get_copy e n.Register.pid }) nl +let update_network config network = List.map + (fun (p,nl) -> p, update_neighbor_env config nl) + network -type 'v t = { - sasarg: SasArg.t; - network: ('v Process.t * 'v Register.neighbor list) list; - config: 'v Env.t -} +let (update_config: 'v Env.t -> 'v t -> 'v t) = + fun e st -> + let verb = !Register.verbose_level > 0 in + if verb then Printf.eprintf " ===> update_neighbor_env\n%!"; + { st with network = update_network e st.network ; config = e } type 'v enable_processes = ('v Process.t * 'v Register.neighbor list * Register.action) list list * bool list list @@ -297,7 +305,7 @@ let (make : bool -> string array -> 'v t) = pl; Printf.eprintf "Ignoring the first vectors of sasa inputs\n%!"; ); - if !Register.verbose_level > 0 then Printf.eprintf "==> Main.make done !\n%!"; + if !Register.verbose_level > 0 then Printf.eprintf "==> SimuState.make done !\n%!"; { sasarg = args; network = pl_n; diff --git a/lib/sasacore/simuState.mli b/lib/sasacore/simuState.mli index f70db6bfc5f88e2936d7e3a611c185fe601b6bf6..b7db9e311abc9a53200a02af718865ccaeb86084 100644 --- a/lib/sasacore/simuState.mli +++ b/lib/sasacore/simuState.mli @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 16/04/2021 (at 15:07) by Erwan Jahier> *) +(* Time-stamp: <modified the 16/04/2021 (at 15:31) by Erwan Jahier> *) (** The module is used by - the main sasa simulation loop (in ../../src/sasaMain.ml) @@ -21,7 +21,8 @@ type 'v enable_processes = val get_enable_processes: 'v t -> 'v enable_processes -val update_neighbor_env: 'v Env.t -> 'v Register.neighbor list -> 'v Register.neighbor list +(** update the config and network processes *) +val update_config: 'v Env.t -> 'v t -> 'v t (* For SasaRun *) val get_inputs_rif_decl : SasArg.t -> 'v Process.t list -> (string * string) list diff --git a/src/sasaMain.ml b/src/sasaMain.ml index 990ffd7a5edf71afc851365937383860fe6f149d..b6137dad2b01c59a4a8864d8cfff4f677d27ebb5 100644 --- a/src/sasaMain.ml +++ b/src/sasaMain.ml @@ -75,14 +75,6 @@ let legitimate p_nl_l e = open Sasacore.SimuState -(* update the network processes w.r.t. the config *) -let update_network config network = - let verb = !Register.verbose_level > 0 in - if verb then Printf.eprintf " ===> update_neighbor_env\n%!"; - List.map - (fun (p,nl) -> p, Sasacore.SimuState.update_neighbor_env config nl) - network - let inject_fault ff st = let update_nodes e (p,nl) = let pid = p.Process.pid in @@ -91,7 +83,7 @@ let inject_fault ff st = Env.set e pid v in let e = List.fold_left update_nodes st.config st.network in - { st with network = update_network e st.network ; config = e } + update_config e st let plur i = if i>1 then "s" else "" @@ -179,7 +171,7 @@ let (simustep: int -> int -> string -> 'v SimuState.t -> 'v SimuState.t * string if st.sasarg.daemon <> Daemon.Custom then print_step n i pot st.sasarg st.config pl next_activate_val enab_ll; let ne = Sasacore.Step.f pnal st.config in - let st = { st with network = update_network ne st.network ; config = ne } in + let st = update_config ne st in st, next_activate_val let rec (simuloop: int -> int -> string -> 'v SimuState.t -> unit) =