Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
verimag
synchrone
sasa
Commits
df5741b0
Commit
df5741b0
authored
Apr 16, 2021
by
erwan
Browse files
Chore: code refactoring again
parent
4b316bf3
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/sasa/sasaRun.ml
View file @
df5741b0
...
...
@@ -15,7 +15,7 @@ let (get_action_value : (string * Data.v) list -> string -> string -> bool) =
open
Sasacore
open
Process
let
(
from_sasa_env
:
'
v
Main
.
t
->
RdbgPlugin
.
sl
)
=
let
(
from_sasa_env
:
'
v
SimuState
.
t
->
RdbgPlugin
.
sl
)
=
fun
st
->
List
.
fold_left
(
fun
acc
(
p
,_
)
->
...
...
@@ -37,7 +37,7 @@ let (get_sl_out: bool -> 'v Process.t list -> bool list list -> RdbgPlugin.sl) =
pl
ll
)
let
(
compute_potentiel
:
'
v
Main
.
t
->
RdbgPlugin
.
sl
)
=
let
(
compute_potentiel
:
'
v
SimuState
.
t
->
RdbgPlugin
.
sl
)
=
fun
st
->
match
Register
.
get_potential
()
with
|
None
->
[]
...
...
@@ -51,7 +51,7 @@ let (compute_potentiel: 'v Main.t -> RdbgPlugin.sl) =
let
p
=
(
user_pf
pidl
get_info
)
in
[(
"potential"
,
Data
.
F
p
)]
let
(
compute_legitimate
:
bool
->
'
v
Main
.
t
->
bool
)
=
let
(
compute_legitimate
:
bool
->
'
v
SimuState
.
t
->
bool
)
=
fun
silent
st
->
silent
||
match
Register
.
get_legitimate
()
with
...
...
@@ -67,11 +67,11 @@ let (compute_legitimate: bool -> 'v Main.t -> bool) =
(* update the network processes w.r.t. the config *)
let
update_network
config
network
=
List
.
map
(
fun
(
p
,
nl
)
->
p
,
Sasacore
.
Main
.
update_neighbor_env
config
nl
)
(
fun
(
p
,
nl
)
->
p
,
Sasacore
.
SimuState
.
update_neighbor_env
config
nl
)
network
open
Main
let
(
make_do
:
string
array
->
'
v
Main
.
t
->
RdbgPlugin
.
t
)
=
open
SimuState
let
(
make_do
:
string
array
->
'
v
SimuState
.
t
->
RdbgPlugin
.
t
)
=
fun
argv
st
->
let
pl
=
fst
(
List
.
split
st
.
network
)
in
let
prog_id
=
Printf
.
sprintf
"%s (with sasa Version %s)"
...
...
@@ -79,11 +79,11 @@ let (make_do: string array -> 'v Main.t -> RdbgPlugin.t) =
in
let
vntl_i
=
List
.
map
(
fun
(
vn
,
vt
)
->
vn
,
Data
.
type_of_string
vt
)
(
Sasacore
.
Main
.
get_inputs_rif_decl
st
.
sasarg
pl
)
(
Sasacore
.
SimuState
.
get_inputs_rif_decl
st
.
sasarg
pl
)
in
let
vntl_o
=
List
.
map
(
fun
(
vn
,
vt
)
->
vn
,
Data
.
type_of_string
vt
)
(
Sasacore
.
Main
.
get_outputs_rif_decl
st
.
sasarg
pl
)
(
Sasacore
.
SimuState
.
get_outputs_rif_decl
st
.
sasarg
pl
)
in
let
vntl_o
=
if
Register
.
get_potential
()
=
None
then
vntl_o
else
...
...
@@ -95,15 +95,15 @@ let (make_do: string array -> 'v Main.t -> RdbgPlugin.t) =
pre_enable_processes_opt
:=
None
;
sasa_config
:=
st
.
config
in
(* Do the same job as Sasa
Main
.simustep *)
(* Do the same job as Sasa
SimuState
.simustep *)
let
(
step_custom
:
RdbgPlugin
.
sl
->
RdbgPlugin
.
sl
)
=
fun
sl_in
->
let
st
=
{
st
with
Main
.
network
=
update_network
!
sasa_config
st
.
network
;
Main
.
config
=
!
sasa_config
}
in
let
st
=
{
st
with
SimuState
.
network
=
update_network
!
sasa_config
st
.
network
;
SimuState
.
config
=
!
sasa_config
}
in
match
!
pre_enable_processes_opt
with
|
None
->
(
(* the first step *)
(* 1: Get enable processes *)
let
pnall
,
enab_ll
=
Sasacore
.
Main
.
get_enable_processes
st
in
let
pnall
,
enab_ll
=
Sasacore
.
SimuState
.
get_enable_processes
st
in
let
sasa_nenv
=
from_sasa_env
st
in
let
pot_sl
=
compute_potentiel
st
in
let
silent
=
List
.
for_all
(
fun
b
->
not
b
)
(
List
.
flatten
enab_ll
)
in
...
...
@@ -125,7 +125,7 @@ let (make_do: string array -> 'v Main.t -> RdbgPlugin.t) =
let
nst
=
{
st
with
network
=
update_network
ne
st
.
network
;
config
=
ne
}
in
let
sasa_nenv
=
from_sasa_env
nst
in
(* 1': Get enable processes *)
let
pnall
,
enab_ll
=
Sasacore
.
Main
.
get_enable_processes
nst
in
let
pnall
,
enab_ll
=
Sasacore
.
SimuState
.
get_enable_processes
nst
in
let
pot_sl
=
compute_potentiel
nst
in
let
silent
=
List
.
for_all
(
fun
b
->
not
b
)
(
List
.
flatten
enab_ll
)
in
let
legit
=
compute_legitimate
silent
nst
in
...
...
@@ -137,10 +137,10 @@ let (make_do: string array -> 'v Main.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
Main
.
network
=
update_network
!
sasa_config
st
.
network
;
Main
.
config
=
!
sasa_config
}
in
let
st
=
{
st
with
SimuState
.
network
=
update_network
!
sasa_config
st
.
network
;
SimuState
.
config
=
!
sasa_config
}
in
(* 1: Get enable processes *)
let
pnall
,
enab_ll
=
Sasacore
.
Main
.
get_enable_processes
st
in
let
pnall
,
enab_ll
=
Sasacore
.
SimuState
.
get_enable_processes
st
in
let
pot_sl
=
compute_potentiel
st
in
let
silent
=
List
.
for_all
(
fun
b
->
not
b
)
(
List
.
flatten
enab_ll
)
in
let
legit
=
compute_legitimate
silent
st
in
...
...
@@ -221,7 +221,7 @@ let (make_do: string array -> 'v Main.t -> RdbgPlugin.t) =
let
(
make
:
string
array
->
RdbgPlugin
.
t
)
=
fun
argv
->
try
make_do
argv
(
Sasacore
.
Main
.
make
false
argv
)
make_do
argv
(
Sasacore
.
SimuState
.
make
false
argv
)
with
|
Dynlink
.
Error
e
->
Printf
.
printf
"Error (SasaRun.make): %s
\n
"
(
Dynlink
.
error_message
e
);
...
...
lib/sasacore/
main
.ml
→
lib/sasacore/
simuState
.ml
View file @
df5741b0
File moved
lib/sasacore/
main
.mli
→
lib/sasacore/
simuState
.mli
View file @
df5741b0
File moved
src/sasaMain.ml
View file @
df5741b0
...
...
@@ -73,14 +73,14 @@ let legitimate p_nl_l e =
in
ulf
pidl
(
from_pid
p_nl_l
)
open
Sasacore
.
Main
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
.
Main
.
update_neighbor_env
config
nl
)
(
fun
(
p
,
nl
)
->
p
,
Sasacore
.
SimuState
.
update_neighbor_env
config
nl
)
network
let
inject_fault
ff
st
=
...
...
@@ -95,7 +95,7 @@ let inject_fault ff st =
let
plur
i
=
if
i
>
1
then
"s"
else
""
let
(
compute_potentiel
:
'
v
Main
.
t
->
string
)
=
let
(
compute_potentiel
:
'
v
SimuState
.
t
->
string
)
=
fun
st
->
match
Register
.
get_potential
()
with
|
None
->
""
...
...
@@ -116,12 +116,12 @@ let (compute_potentiel: 'v Main.t -> string) =
string_of_float
p
let
(
simustep
:
int
->
int
->
string
->
'
v
Main
.
t
->
'
v
Main
.
t
*
string
)
=
let
(
simustep
:
int
->
int
->
string
->
'
v
SimuState
.
t
->
'
v
SimuState
.
t
*
string
)
=
fun
n
i
activate_val
st
->
(* 1: Get enable processes *)
let
verb
=
!
Register
.
verbose_level
>
0
in
if
verb
then
Printf
.
eprintf
"==> Sasa
Main
.simustep :1: Get enable processes
\n
%!"
;
let
all
,
enab_ll
=
Sasacore
.
Main
.
get_enable_processes
st
in
if
verb
then
Printf
.
eprintf
"==> Sasa
SimuState
.simustep :1: Get enable processes
\n
%!"
;
let
all
,
enab_ll
=
Sasacore
.
SimuState
.
get_enable_processes
st
in
let
pot
=
compute_potentiel
st
in
let
pl
=
fst
(
List
.
split
st
.
network
)
in
let
st
,
all
,
enab_ll
=
...
...
@@ -141,7 +141,7 @@ let (simustep: int -> int -> string -> 'v Main.t -> 'v Main.t * string) =
str
!
moves
(
plur
!
moves
)
(
n
-
i
)
(
plur
(
n
-
i
))
!
rounds
(
plur
!
rounds
);
Printf
.
eprintf
"%s==> Inject a fault
\n
%!"
str
;
let
st
=
inject_fault
ff
st
in
let
all
,
enab_ll
=
Sasacore
.
Main
.
get_enable_processes
st
in
let
all
,
enab_ll
=
Sasacore
.
SimuState
.
get_enable_processes
st
in
st
,
all
,
enab_ll
)
else
if
legitimate
st
.
network
st
.
config
then
(
...
...
@@ -157,7 +157,7 @@ let (simustep: int -> int -> string -> 'v Main.t -> 'v Main.t * string) =
str
!
moves
(
plur
!
moves
)
(
n
-
i
)
(
plur
(
n
-
i
))
!
rounds
(
plur
!
rounds
);
Printf
.
eprintf
"%s==> Inject a fault
\n
%!"
str
;
let
st
=
inject_fault
ff
st
in
let
all
,
enab_ll
=
Sasacore
.
Main
.
get_enable_processes
st
in
let
all
,
enab_ll
=
Sasacore
.
SimuState
.
get_enable_processes
st
in
st
,
all
,
enab_ll
)
else
...
...
@@ -166,7 +166,7 @@ let (simustep: int -> int -> string -> 'v Main.t -> 'v Main.t * string) =
if
st
.
sasarg
.
daemon
=
Daemon
.
Custom
then
print_step
n
i
pot
st
.
sasarg
st
.
config
pl
activate_val
enab_ll
;
(* 2: read the actions *)
if
verb
then
Printf
.
eprintf
"==> Sasa
Main
.simustep : 2: read the actions
\n
%!"
;
if
verb
then
Printf
.
eprintf
"==> Sasa
SimuState
.simustep : 2: read the actions
\n
%!"
;
let
get_action_value
=
RifRead
.
bool
(
st
.
sasarg
.
verbose
>
1
)
in
let
next_activate_val
,
pnal
=
Daemon
.
f
st
.
sasarg
.
dummy_input
(
st
.
sasarg
.
verbose
>=
1
)
st
.
sasarg
.
daemon
st
.
network
st
.
config
all
enab_ll
get_action_value
...
...
@@ -175,23 +175,23 @@ let (simustep: int -> int -> string -> 'v Main.t -> 'v Main.t * string) =
update_round
next_activate_val
enab_ll
;
let
next_activate_val
=
bool_ll_to_string
next_activate_val
in
(* 3: Do the steps *)
if
verb
then
Printf
.
eprintf
"==> Sasa
Main
.simustep : 3: Do the steps
\n
%!"
;
if
verb
then
Printf
.
eprintf
"==> Sasa
SimuState
.simustep : 3: Do the steps
\n
%!"
;
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
st
,
next_activate_val
let
rec
(
simuloop
:
int
->
int
->
string
->
'
v
Main
.
t
->
unit
)
=
let
rec
(
simuloop
:
int
->
int
->
string
->
'
v
SimuState
.
t
->
unit
)
=
fun
n
i
activate_val
st
->
if
!
Register
.
verbose_level
>
0
then
Printf
.
eprintf
"==> Sasa
Main
.simuloop %d/%d
\n
%!"
i
n
;
if
!
Register
.
verbose_level
>
0
then
Printf
.
eprintf
"==> Sasa
SimuState
.simuloop %d/%d
\n
%!"
i
n
;
let
st
,
next_activate_val
=
simustep
n
i
activate_val
st
in
if
i
>
0
then
simuloop
n
(
i
-
1
)
next_activate_val
st
else
(
print_string
"#q
\n
"
;
flush_all
()
)
let
()
=
let
st
=
Sasacore
.
Main
.
make
true
Sys
.
argv
in
let
st
=
Sasacore
.
SimuState
.
make
true
Sys
.
argv
in
try
let
n
=
st
.
sasarg
.
length
in
simuloop
n
n
""
st
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment