Section SerializedMsgCorrect.
Context {orig_base_params : BaseParams}.
Context {orig_multi_params : MultiParams orig_base_params}.
Context {orig_failure_params : FailureParams orig_multi_params}.
Context {orig_name_overlay_params : NameOverlayParams orig_multi_params}.
Context {orig_fail_msg_params : FailMsgParams orig_multi_params}.
Context {orig_new_msg_params : NewMsgParams orig_multi_params}.
Context {orig_msg_serializer : Serializer msg}.
Definition serialize_packet p :=
@mkPacket _ serialized_multi_params
(@pSrc _ orig_multi_params p)
(pDst p)
(serialize_top (serialize (pBody p))).
Definition serialize_net (net : @network _ orig_multi_params) : (@network _ serialized_multi_params) :=
@mkNetwork _ serialized_multi_params (map serialize_packet (nwPackets net)) net.(nwState).
Definition serialize_onet (net : @ordered_network _ orig_multi_params) : (@ordered_network _ serialized_multi_params) :=
@mkONetwork _ serialized_multi_params (fun src dst => map (fun v => serialize_top (serialize v)) (net.(onwPackets) src dst)) net.(onwState).
Definition serialize_odnet (net : @ordered_dynamic_network _ orig_multi_params) : (@ordered_dynamic_network _ serialized_multi_params) :=
@mkODNetwork _ serialized_multi_params net.(odnwNodes) (fun src dst => map (fun v => serialize_top (serialize v)) (net.(odnwPackets) src dst)) net.(odnwState).
Instance orig_multi_params_name_tot_map :
MultiParamsNameTotalMap orig_multi_params serialized_multi_params :=
{
tot_map_name := id ;
tot_map_name_inv := id
}.
Instance orig_multi_params_name_tot_map_bijective :
MultiParamsNameTotalMapBijective orig_multi_params_name_tot_map :=
{
tot_map_name_inv_inverse := fun _ => eq_refl ;
tot_map_name_inverse_inv := fun _ => eq_refl
}.
Instance orig_base_params_tot_map :
BaseParamsTotalMap orig_base_params serialized_base_params :=
{
tot_map_data := id;
tot_map_input := id;
tot_map_output := id
}.
Instance orig_multi_params_tot_msg_map :
MultiParamsMsgTotalMap orig_multi_params serialized_multi_params :=
{
tot_map_msg := fun v => serialize_top (serialize v)
}.
Instance orig_failure_params_tot_map_congruency : FailureParamsTotalMapCongruency orig_failure_params serialized_failure_params orig_base_params_tot_map :=
{
tot_reboot_eq := fun _ => eq_refl
}.
Instance orig_multi_name_overlay_params_tot_map_congruency : NameOverlayParamsTotalMapCongruency orig_name_overlay_params serialized_name_overlay_params orig_multi_params_name_tot_map :=
{
tot_adjacent_to_fst_snd := fun _ _ => conj (fun H => H) (fun H => H)
}.
Instance orig_multi_fail_msg_params_tot_map_congruency : FailMsgParamsTotalMapCongruency orig_fail_msg_params serialized_fail_msg_params orig_multi_params_tot_msg_map :=
{
tot_fail_msg_fst_snd := eq_refl
}.
Instance orig_multi_new_msg_params_tot_map_congruency : NewMsgParamsTotalMapCongruency orig_new_msg_params serialized_new_msg_params orig_multi_params_tot_msg_map :=
{
tot_new_msg_fst_snd := eq_refl
}.
Program Instance orig_multi_params_map_congruency :
MultiParamsTotalMapCongruency orig_base_params_tot_map
orig_multi_params_name_tot_map orig_multi_params_tot_msg_map :=
{
tot_init_handlers_eq := fun _ => eq_refl ;
tot_net_handlers_eq := _ ;
tot_input_handlers_eq := _
}.
Next Obligation.
rewrite /tot_mapped_net_handlers /= /tot_map_name_msgs /= /id /=.
repeat break_let.
rewrite /serialized_net_handlers.
rewrite serialize_deserialize_top_id.
rewrite /serialize_handler_result.
repeat break_let.
find_injection.
rewrite map_id.
set l1 := map _ l.
set l2 := map _ l.
suff H_suff: l1 = l2 by rewrite H_suff.
rewrite /l1 /l2.
clear.
elim: l => //=.
move => p l IH.
rewrite IH /= /serialize_name_msg_tuple /=.
by break_let.
Qed.
Next Obligation.
rewrite /tot_mapped_input_handlers /=.
repeat break_let.
unfold serialized_input_handlers in *.
rewrite /serialize_handler_result /id /tot_map_name_msgs /tot_map_name /= /id /=.
repeat break_let.
find_injection.
rewrite map_id.
set l1 := map _ l.
set l2 := map _ l.
suff H_suff: l1 = l2 by rewrite H_suff.
rewrite /l1 /l2.
clear.
elim: l => //=.
move => p l IH.
rewrite IH /= /serialize_name_msg_tuple /=.
by break_let.
Qed.
Proof using.
move => net.
rewrite /tot_map_odnet.
rewrite /tot_map_name /= /id /= map_id.
rewrite /serialize_odnet.
set f := fun _ => match _ with _ => _ end.
by have ->: odnwState net = f by rewrite /f; apply functional_extensionality => n; case: odnwState.
Qed.
Proof using.
move => net net' out H_step.
apply step_async_tot_mapped_simulation_1 in H_step.
rewrite /tot_map_name /tot_map_net /= /id /= in H_step.
rewrite /tot_map_trace_occ /= /id /= in H_step.
rewrite /tot_map_packet /= /id /= in H_step.
rewrite /serialize_net.
move: H_step.
set fp := fun p => _.
have H_eq: fp = serialize_packet by rewrite /fp ; apply functional_extensionality; case => /= src dst m.
rewrite H_eq {H_eq fp}.
set mp := fun e : name * _ => _.
suff H_eq': map mp out = out by rewrite H_eq'.
elim: out => //=.
case => a.
case => /= [i|o] l IH; rewrite IH //.
by rewrite map_id.
Qed.
Proof using.
move => net tr H_step.
apply step_async_tot_mapped_simulation_star_1 in H_step.
rewrite /tot_map_name /tot_map_net /= /id /= in H_step.
rewrite /tot_map_trace_occ /= /id /= in H_step.
rewrite /tot_map_packet /= /id /= in H_step.
rewrite /serialize_net.
move: H_step.
set fp := fun p : packet => _.
have H_eq: fp = serialize_packet by rewrite /fp ; apply functional_extensionality; case => /= src dst m.
rewrite H_eq {H_eq fp}.
set mp := fun e : name * _ => _.
suff H_eq': map mp tr = tr by rewrite H_eq'.
elim: tr => //=.
case => a.
case => /= [i|o] l IH; rewrite IH //.
by rewrite map_id.
Qed.
Proof using.
move => net net' failed failed' tr H_step.
apply step_failure_tot_mapped_simulation_1 in H_step.
rewrite /tot_map_name /tot_map_net /= /id /= in H_step.
rewrite /tot_map_trace_occ /= /id /= in H_step.
rewrite /tot_map_packet /= /id /= in H_step.
rewrite /serialize_net.
move: H_step.
rewrite 2!map_id.
set fp := fun p : packet => _.
have H_eq: fp = serialize_packet by rewrite /fp ; apply functional_extensionality; case => /= src dst m.
rewrite H_eq {H_eq fp}.
set mp := fun e : name * _ => _.
suff H_eq': map mp tr = tr by rewrite H_eq'.
elim: tr => //=.
case => a.
case => /= [i|o] l IH; rewrite IH //.
by rewrite map_id.
Qed.
Proof using.
move => net failed tr H_step.
apply step_failure_tot_mapped_simulation_star_1 in H_step.
rewrite /tot_map_name /tot_map_net /= /id /= in H_step.
rewrite /tot_map_packet /= /id /= in H_step.
rewrite /serialize_net.
move: H_step.
rewrite map_id.
set fp := fun p : packet => _.
have H_eq: fp = serialize_packet by rewrite /fp ; apply functional_extensionality; case => /= src dst m.
rewrite H_eq {H_eq fp}.
rewrite /tot_map_trace_occ /=.
set fp := fun e : name * _ => _.
suff H_eq': map fp tr = tr by rewrite H_eq'.
elim: tr => //=.
case => a.
case => /= [i|o] l IH; rewrite IH //.
by rewrite map_id.
Qed.

Lemma step_ordered_failure_serialize_simulation :
forall net net' failed failed' tr,
@step_ordered_failure _ _ orig_name_overlay_params orig_fail_msg_params (failed, net) (failed', net') tr ->
@step_ordered_failure _ _ serialized_name_overlay_params serialized_fail_msg_params (failed, serialize_onet net) (failed', serialize_onet net') tr.