(* Title: Seq_Invariants.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke, Inria *) section "Invariant proofs on individual processes" theory Seq_Invariants imports AWN.Invariants Aodv Aodv_Data Aodv_Predicates Fresher begin text \ The proposition numbers are taken from the December 2013 version of the Fehnker et al technical report. \ text \Proposition 7.2\ lemma sequence_number_increases: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). sn \ \ sn \')" by inv_cterms lemma sequence_number_one_or_bigger: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). 1 \ sn \)" by (rule onll_step_to_invariantI [OF sequence_number_increases]) (auto simp: \\<^sub>A\<^sub>O\<^sub>D\<^sub>V_def) text \We can get rid of the onl/onll if desired...\ lemma sequence_number_increases': "paodv i \\<^sub>A (\((\, _), _, (\', _)). sn \ \ sn \')" by (rule step_invariant_weakenE [OF sequence_number_increases]) (auto dest!: onllD) lemma sequence_number_one_or_bigger': "paodv i \ (\(\, _). 1 \ sn \)" by (rule invariant_weakenE [OF sequence_number_one_or_bigger]) auto lemma sip_in_kD: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ ({PAodv-:7} \ {PAodv-:5} \ {PRrep-:0..PRrep-:1} \ {PRreq-:0..PRreq-:3}) \ sip \ \ kD (rt \))" by inv_cterms lemma rrep_1_update_changes: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l = PRrep-:1 \ rt \ \ update (rt \) (dip \) (dsn \, kno, val, hops \ + 1, sip \, {})))" by inv_cterms lemma addpreRT_partly_welldefined: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PRreq-:16..PRreq-:18} \ {PRrep-:2..PRrep-:6} \ dip \ \ kD (rt \)) \ (l \ {PRreq-:3..PRreq-:17} \ oip \ \ kD (rt \)))" by inv_cterms text \Proposition 7.38\ lemma includes_nhip: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). \dip\kD(rt \). the (nhop (rt \) dip)\kD(rt \))" proof - { fix ip and \ \' :: state assume "\dip\kD (rt \). the (nhop (rt \) dip) \ kD (rt \)" and "\' = \\rt := update (rt \) ip (0, unk, val, Suc 0, ip, {})\" hence "\dip\kD (rt \). the (nhop (update (rt \) ip (0, unk, val, Suc 0, ip, {})) dip) = ip \ the (nhop (update (rt \) ip (0, unk, val, Suc 0, ip, {})) dip) \ kD (rt \)" by clarsimp (metis nhop_update_unk_val update_another) } note one_hop = this { fix ip sip sn hops and \ \' :: state assume "\dip\kD (rt \). the (nhop (rt \) dip) \ kD (rt \)" and "\' = \\rt := update (rt \) ip (sn, kno, val, Suc hops, sip, {})\" and "sip \ kD (rt \)" hence "(the (nhop (update (rt \) ip (sn, kno, val, Suc hops, sip, {})) ip) = ip \ the (nhop (update (rt \) ip (sn, kno, val, Suc hops, sip, {})) ip) \ kD (rt \)) \ (\dip\kD (rt \). the (nhop (update (rt \) ip (sn, kno, val, Suc hops, sip, {})) dip) = ip \ the (nhop (update (rt \) ip (sn, kno, val, Suc hops, sip, {})) dip) \ kD (rt \))" by (metis kD_update_unchanged nhop_update_changed update_another) } note nhip_is_sip = this show ?thesis by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf sip_in_kD] onl_invariant_sterms [OF aodv_wf addpreRT_partly_welldefined] solve: one_hop nhip_is_sip) qed text \Proposition 7.22: needed in Proposition 7.4\ lemma addpreRT_welldefined: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PRreq-:16..PRreq-:18} \ dip \ \ kD (rt \)) \ (l = PRreq-:17 \ oip \ \ kD (rt \)) \ (l = PRrep-:5 \ dip \ \ kD (rt \)) \ (l = PRrep-:6 \ (the (nhop (rt \) (dip \))) \ kD (rt \)))" (is "_ \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V ?P") unfolding invariant_def proof fix s assume "s \ reachable (paodv i) TT" then obtain \ p where "s = (\, p)" and "(\, p) \ reachable (paodv i) TT" by (metis prod.exhaust) have "onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V ?P (\, p)" proof (rule onlI) fix l assume "l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p" with \(\, p) \ reachable (paodv i) TT\ have I1: "l \ {PRreq-:16..PRreq-:18} \ dip \ \ kD(rt \)" and I2: "l = PRreq-:17 \ oip \ \ kD(rt \)" and I3: "l \ {PRrep-:2..PRrep-:6} \ dip \ \ kD(rt \)" by (auto dest!: invariantD [OF addpreRT_partly_welldefined]) moreover from \(\, p) \ reachable (paodv i) TT\ \l \ labels \\<^sub>A\<^sub>O\<^sub>D\<^sub>V p\ and I3 have "l = PRrep-:6 \ (the (nhop (rt \) (dip \))) \ kD(rt \)" by (auto dest!: invariantD [OF includes_nhip]) ultimately show "?P (\, l)" by simp qed with \s = (\, p)\ show "onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V ?P s" by simp qed text \Proposition 7.4\ lemma known_destinations_increase: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). kD (rt \) \ kD (rt \'))" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf addpreRT_welldefined] simp add: subset_insertI) text \Proposition 7.5\ lemma rreqs_increase: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). rreqs \ \ rreqs \')" by (inv_cterms simp add: subset_insertI) lemma dests_bigger_than_sqn: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:15..PAodv-:19} \ {PPkt-:7..PPkt-:11} \ {PRreq-:9..PRreq-:13} \ {PRreq-:21..PRreq-:25} \ {PRrep-:10..PRrep-:14} \ {PRerr-:1..PRerr-:5} \ (\ip\dom(dests \). ip\kD(rt \) \ sqn (rt \) ip \ the (dests \ ip)))" proof - have sqninv: "\dests rt rsn ip. \ \ip\dom(dests). ip\kD(rt) \ sqn rt ip \ the (dests ip); dests ip = Some rsn \ \ sqn (invalidate rt dests) ip \ rsn" by (rule sqn_invalidate_in_dests [THEN eq_imp_le], assumption) auto have indests: "\dests rt rsn ip. \ \ip\dom(dests). ip\kD(rt) \ sqn rt ip \ the (dests ip); dests ip = Some rsn \ \ ip\kD(rt) \ sqn rt ip \ rsn" by (metis domI option.sel) show ?thesis by inv_cterms (clarsimp split: if_split_asm option.split_asm elim!: sqninv indests)+ qed text \Proposition 7.6\ lemma sqns_increase: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). \ip. sqn (rt \) ip \ sqn (rt \') ip)" proof - { fix \ :: state assume *: "\ip\dom(dests \). ip \ kD (rt \) \ sqn (rt \) ip \ the (dests \ ip)" have "\ip. sqn (rt \) ip \ sqn (invalidate (rt \) (dests \)) ip" proof fix ip from * have "ip\dom(dests \) \ sqn (rt \) ip \ the (dests \ ip)" by simp thus "sqn (rt \) ip \ sqn (invalidate (rt \) (dests \)) ip" by (metis domI invalidate_sqn option.sel) qed } note solve_invalidate = this show ?thesis by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf addpreRT_welldefined] onl_invariant_sterms [OF aodv_wf dests_bigger_than_sqn] simp add: solve_invalidate) qed text \Proposition 7.7\ lemma ip_constant: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). ip \ = i)" by (inv_cterms simp add: \\<^sub>A\<^sub>O\<^sub>D\<^sub>V_def) text \Proposition 7.8\ lemma sender_ip_valid': "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), a, _). anycast (\m. not_Pkt m \ msg_sender m = ip \) a)" by inv_cterms lemma sender_ip_valid: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), a, _). anycast (\m. not_Pkt m \ msg_sender m = i) a)" by (rule step_invariant_weaken_with_invariantE [OF ip_constant sender_ip_valid']) (auto dest!: onlD onllD) lemma received_msg_inv: "paodv i \ (recvmsg P \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:1} \ P (msg \))" by inv_cterms text \Proposition 7.9\ lemma sip_not_ip': "paodv i \ (recvmsg (\m. not_Pkt m \ msg_sender m \ i) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). sip \ \ ip \)" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf received_msg_inv] onl_invariant_sterms [OF aodv_wf ip_constant [THEN invariant_restrict_inD]] simp add: clear_locals_sip_not_ip') clarsimp+ lemma sip_not_ip: "paodv i \ (recvmsg (\m. not_Pkt m \ msg_sender m \ i) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). sip \ \ i)" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf received_msg_inv] onl_invariant_sterms [OF aodv_wf ip_constant [THEN invariant_restrict_inD]] simp add: clear_locals_sip_not_ip') clarsimp+ text \Neither \sip_not_ip'\ nor \sip_not_ip\ is needed to show loop freedom.\ text \Proposition 7.10\ lemma hop_count_positive: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \ip\kD (rt \). the (dhops (rt \) ip) \ 1)" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf addpreRT_welldefined]) auto lemma rreq_dip_in_vD_dip_eq_ip: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PRreq-:16..PRreq-:18} \ dip \ \ vD(rt \)) \ (l \ {PRreq-:5, PRreq-:6} \ dip \ = ip \) \ (l \ {PRreq-:15..PRreq-:18} \ dip \ \ ip \))" proof (inv_cterms, elim conjE) fix l \ pp p' assume "(\, pp) \ reachable (paodv i) TT" and "{PRreq-:17}\\\. \\rt := the (addpreRT (rt \) (oip \) {the (nhop (rt \) (dip \))})\\ p' \ sterms \\<^sub>A\<^sub>O\<^sub>D\<^sub>V pp" and "l = PRreq-:17" and "dip \ \ vD (rt \)" from this(1-3) have "oip \ \ kD (rt \)" by (auto dest: onl_invariant_sterms [OF aodv_wf addpreRT_welldefined, where l="PRreq-:17"]) with \dip \ \ vD (rt \)\ show "dip \ \ vD (the (addpreRT (rt \) (oip \) {the (nhop (rt \) (dip \))}))" by simp qed text \Proposition 7.11\ lemma anycast_msg_zhops: "\rreqid dip dsn dsk oip osn sip. paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(_, a, _). anycast msg_zhops a)" proof (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf rreq_dip_in_vD_dip_eq_ip [THEN invariant_restrict_inD]] onl_invariant_sterms [OF aodv_wf hop_count_positive [THEN invariant_restrict_inD]], elim conjE) fix l \ a pp p' pp' assume "(\, pp) \ reachable (paodv i) TT" and "{PRreq-:18}unicast(\\. the (nhop (rt \) (oip \)), \\. Rrep (the (dhops (rt \) (dip \))) (dip \) (sqn (rt \) (dip \)) (oip \) (ip \)). p' \ pp' \ sterms \\<^sub>A\<^sub>O\<^sub>D\<^sub>V pp" and "l = PRreq-:18" and "a = unicast (the (nhop (rt \) (oip \))) (Rrep (the (dhops (rt \) (dip \))) (dip \) (sqn (rt \) (dip \)) (oip \) (ip \))" and *: "\ip\kD (rt \). Suc 0 \ the (dhops (rt \) ip)" and "dip \ \ vD (rt \)" from \dip \ \ vD (rt \)\ have "dip \ \ kD (rt \)" by (rule vD_iD_gives_kD(1)) with * have "Suc 0 \ the (dhops (rt \) (dip \))" .. thus "0 < the (dhops (rt \) (dip \))" by simp qed lemma hop_count_zero_oip_dip_sip: "paodv i \ (recvmsg msg_zhops \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l\{PAodv-:4..PAodv-:5} \ {PRreq-:n|n. True} \ (hops \ = 0 \ oip \ = sip \)) \ ((l\{PAodv-:6..PAodv-:7} \ {PRrep-:n|n. True} \ (hops \ = 0 \ dip \ = sip \))))" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf received_msg_inv]) auto lemma osn_rreq: "paodv i \ (recvmsg rreq_rrep_sn \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:4, PAodv-:5} \ {PRreq-:n|n. True} \ 1 \ osn \)" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf received_msg_inv]) clarsimp lemma osn_rreq': "paodv i \ (recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:4, PAodv-:5} \ {PRreq-:n|n. True} \ 1 \ osn \)" proof (rule invariant_weakenE [OF osn_rreq]) fix a assume "recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) a" thus "recvmsg rreq_rrep_sn a" by (cases a) simp_all qed lemma dsn_rrep: "paodv i \ (recvmsg rreq_rrep_sn \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:6, PAodv-:7} \ {PRrep-:n|n. True} \ 1 \ dsn \)" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf received_msg_inv]) clarsimp lemma dsn_rrep': "paodv i \ (recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). l \ {PAodv-:6, PAodv-:7} \ {PRrep-:n|n. True} \ 1 \ dsn \)" proof (rule invariant_weakenE [OF dsn_rrep]) fix a assume "recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) a" thus "recvmsg rreq_rrep_sn a" by (cases a) simp_all qed lemma hop_count_zero_oip_dip_sip': "paodv i \ (recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l\{PAodv-:4..PAodv-:5} \ {PRreq-:n|n. True} \ (hops \ = 0 \ oip \ = sip \)) \ ((l\{PAodv-:6..PAodv-:7} \ {PRrep-:n|n. True} \ (hops \ = 0 \ dip \ = sip \))))" proof (rule invariant_weakenE [OF hop_count_zero_oip_dip_sip]) fix a assume "recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) a" thus "recvmsg msg_zhops a" by (cases a) simp_all qed text \Proposition 7.12\ lemma zero_seq_unk_hops_one': "paodv i \ (recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \dip\kD(rt \). (sqn (rt \) dip = 0 \ sqnf (rt \) dip = unk) \ (sqnf (rt \) dip = unk \ the (dhops (rt \) dip) = 1) \ (the (dhops (rt \) dip) = 1 \ the (nhop (rt \) dip) = dip))" proof - { fix dip and \ :: state and P assume "sqn (invalidate (rt \) (dests \)) dip = 0" and all: "\ip. sqn (rt \) ip \ sqn (invalidate (rt \) (dests \)) ip" and *: "sqn (rt \) dip = 0 \ P \ dip" have "P \ dip" proof - from all have "sqn (rt \) dip \ sqn (invalidate (rt \) (dests \)) dip" .. with \sqn (invalidate (rt \) (dests \)) dip = 0\ have "sqn (rt \) dip = 0" by simp thus "P \ dip" by (rule *) qed } note sqn_invalidate_zero [elim!] = this { fix dsn hops :: nat and sip oip rt and ip dip :: ip assume "\dip\kD(rt). (sqn rt dip = 0 \ \\<^sub>3(the (rt dip)) = unk) \ (\\<^sub>3(the (rt dip)) = unk \ the (dhops rt dip) = Suc 0) \ (the (dhops rt dip) = Suc 0 \ the (nhop rt dip) = dip)" and "hops = 0 \ sip = dip" and "Suc 0 \ dsn" and "ip \ dip \ ip\kD(rt)" hence "the (dhops (update rt dip (dsn, kno, val, Suc hops, sip, {})) ip) = Suc 0 \ the (nhop (update rt dip (dsn, kno, val, Suc hops, sip, {})) ip) = ip" by - (rule update_cases, auto simp add: sqn_def dest!: bspec) } note prreq_ok1 [simp] = this { fix ip dsn hops sip oip rt dip assume "\dip\kD(rt). (sqn rt dip = 0 \ \\<^sub>3(the (rt dip)) = unk) \ (\\<^sub>3(the (rt dip)) = unk \ the (dhops rt dip) = Suc 0) \ (the (dhops rt dip) = Suc 0 \ the (nhop rt dip) = dip)" and "Suc 0 \ dsn" and "ip \ dip \ ip\kD(rt)" hence "\\<^sub>3(the (update rt dip (dsn, kno, val, Suc hops, sip, {}) ip)) = unk \ the (dhops (update rt dip (dsn, kno, val, Suc hops, sip, {})) ip) = Suc 0" by - (rule update_cases, auto simp add: sqn_def sqnf_def dest!: bspec) } note prreq_ok2 [simp] = this { fix ip dsn hops sip oip rt dip assume "\dip\kD(rt). (sqn rt dip = 0 \ \\<^sub>3(the (rt dip)) = unk) \ (\\<^sub>3(the (rt dip)) = unk \ the (dhops rt dip) = Suc 0) \ (the (dhops rt dip) = Suc 0 \ the (nhop rt dip) = dip)" and "Suc 0 \ dsn" and "ip \ dip \ ip\kD(rt)" hence "sqn (update rt dip (dsn, kno, val, Suc hops, sip, {})) ip = 0 \ \\<^sub>3 (the (update rt dip (dsn, kno, val, Suc hops, sip, {}) ip)) = unk" by - (rule update_cases, auto simp add: sqn_def dest!: bspec) } note prreq_ok3 [simp] = this { fix rt sip assume "\dip\kD rt. (sqn rt dip = 0 \ \\<^sub>3(the (rt dip)) = unk) \ (\\<^sub>3(the (rt dip)) = unk \ the (dhops rt dip) = Suc 0) \ (the (dhops rt dip) = Suc 0 \ the (nhop rt dip) = dip)" hence "\dip\kD rt. (sqn (update rt sip (0, unk, val, Suc 0, sip, {})) dip = 0 \ \\<^sub>3(the (update rt sip (0, unk, val, Suc 0, sip, {}) dip)) = unk) \ (\\<^sub>3(the (update rt sip (0, unk, val, Suc 0, sip, {}) dip)) = unk \ the (dhops (update rt sip (0, unk, val, Suc 0, sip, {})) dip) = Suc 0) \ (the (dhops (update rt sip (0, unk, val, Suc 0, sip, {})) dip) = Suc 0 \ the (nhop (update rt sip (0, unk, val, Suc 0, sip, {})) dip) = dip)" by - (rule update_cases, simp_all add: sqnf_def sqn_def) } note prreq_ok4 [simp] = this have prreq_ok5 [simp]: "\sip rt. \\<^sub>3(the (update rt sip (0, unk, val, Suc 0, sip, {}) sip)) = unk \ the (dhops (update rt sip (0, unk, val, Suc 0, sip, {})) sip) = Suc 0" by (rule update_cases) simp_all have prreq_ok6 [simp]: "\sip rt. sqn (update rt sip (0, unk, val, Suc 0, sip, {})) sip = 0 \ \\<^sub>3 (the (update rt sip (0, unk, val, Suc 0, sip, {}) sip)) = unk" by (rule update_cases) simp_all show ?thesis by (inv_cterms inv add: onl_invariant_sterms_TT [OF aodv_wf addpreRT_welldefined] onl_invariant_sterms [OF aodv_wf hop_count_zero_oip_dip_sip'] seq_step_invariant_sterms_TT [OF sqns_increase aodv_wf aodv_trans] onl_invariant_sterms [OF aodv_wf osn_rreq'] onl_invariant_sterms [OF aodv_wf dsn_rrep']) clarsimp+ qed lemma zero_seq_unk_hops_one: "paodv i \ (recvmsg (\m. rreq_rrep_sn m \ msg_zhops m) \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, _). \dip\kD(rt \). (sqn (rt \) dip = 0 \ (sqnf (rt \) dip = unk \ the (dhops (rt \) dip) = 1 \ the (nhop (rt \) dip) = dip)))" by (rule invariant_weakenE [OF zero_seq_unk_hops_one']) auto lemma kD_unk_or_atleast_one: "paodv i \ (recvmsg rreq_rrep_sn \) onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). \dip\kD(rt \). \\<^sub>3(the (rt \ dip)) = unk \ 1 \ \\<^sub>2(the (rt \ dip)))" proof - { fix sip rt dsn1 dsn2 dsk1 dsk2 flag1 flag2 hops1 hops2 nhip1 nhip2 pre1 pre2 assume "dsk1 = unk \ Suc 0 \ dsn2" hence "\\<^sub>3(the (update rt sip (dsn1, dsk1, flag1, hops1, nhip1, pre1) sip)) = unk \ Suc 0 \ sqn (update rt sip (dsn2, dsk2, flag2, hops2, nhip2, pre2)) sip" unfolding update_def by (cases "dsk1 =unk") (clarsimp split: option.split)+ } note fromsip [simp] = this { fix dip sip rt dsn1 dsn2 dsk1 dsk2 flag1 flag2 hops1 hops2 nhip1 nhip2 pre1 pre2 assume allkd: "\dip\kD(rt). \\<^sub>3(the (rt dip)) = unk \ Suc 0 \ sqn rt dip" and **: "dsk1 = unk \ Suc 0 \ dsn2" have "\dip\kD(rt). \\<^sub>3(the (update rt sip (dsn1, dsk1, flag1, hops1, nhip1, pre1) dip)) = unk \ Suc 0 \ sqn (update rt sip (dsn2, dsk2, flag2, hops2, nhip2, pre2)) dip" (is "\dip\kD(rt). ?prop dip") proof fix dip assume "dip\kD(rt)" thus "?prop dip" proof (cases "dip = sip") assume "dip = sip" with ** show ?thesis by simp next assume "dip \ sip" with \dip\kD(rt)\ allkd show ?thesis by simp qed qed } note solve_update [simp] = this { fix dip rt dests assume *: "\ip\dom(dests). ip\kD(rt) \ sqn rt ip \ the (dests ip)" and **: "\ip\kD(rt). \\<^sub>3(the (rt ip)) = unk \ Suc 0 \ sqn rt ip" have "\dip\kD(rt). \\<^sub>3(the (rt dip)) = unk \ Suc 0 \ sqn (invalidate rt dests) dip" proof fix dip assume "dip\kD(rt)" with ** have "\\<^sub>3(the (rt dip)) = unk \ Suc 0 \ sqn rt dip" .. thus "\\<^sub>3 (the (rt dip)) = unk \ Suc 0 \ sqn (invalidate rt dests) dip" proof assume "\\<^sub>3(the (rt dip)) = unk" thus ?thesis .. next assume "Suc 0 \ sqn rt dip" have "Suc 0 \ sqn (invalidate rt dests) dip" proof (cases "dip\dom(dests)") assume "dip\dom(dests)" with * have "sqn rt dip \ the (dests dip)" by simp with \Suc 0 \ sqn rt dip\ have "Suc 0 \ the (dests dip)" by simp with \dip\dom(dests)\ \dip\kD(rt)\ [THEN kD_Some] show ?thesis unfolding invalidate_def sqn_def by auto next assume "dip\dom(dests)" with \Suc 0 \ sqn rt dip\ \dip\kD(rt)\ [THEN kD_Some] show ?thesis unfolding invalidate_def sqn_def by auto qed thus ?thesis by (rule disjI2) qed qed } note solve_invalidate [simp] = this show ?thesis by (inv_cterms inv add: onl_invariant_sterms_TT [OF aodv_wf addpreRT_welldefined] onl_invariant_sterms [OF aodv_wf dests_bigger_than_sqn [THEN invariant_restrict_inD]] onl_invariant_sterms [OF aodv_wf osn_rreq] onl_invariant_sterms [OF aodv_wf dsn_rrep] simp add: proj3_inv proj2_eq_sqn) qed text \Proposition 7.13\ lemma rreq_rrep_sn_any_step_invariant: "paodv i \\<^sub>A (recvmsg rreq_rrep_sn \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(_, a, _). anycast rreq_rrep_sn a)" proof - have sqnf_kno: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PRreq-:16..PRreq-:18} \ sqnf (rt \) (dip \) = kno))" by (inv_cterms inv add: onl_invariant_sterms_TT [OF aodv_wf addpreRT_welldefined]) show ?thesis by (inv_cterms inv add: onl_invariant_sterms_TT [OF aodv_wf addpreRT_welldefined] onl_invariant_sterms [OF aodv_wf sequence_number_one_or_bigger [THEN invariant_restrict_inD]] onl_invariant_sterms [OF aodv_wf kD_unk_or_atleast_one] onl_invariant_sterms_TT [OF aodv_wf sqnf_kno] onl_invariant_sterms [OF aodv_wf osn_rreq] onl_invariant_sterms [OF aodv_wf dsn_rrep]) (auto simp: proj2_eq_sqn) qed text \Proposition 7.14\ lemma rreq_rrep_fresh_any_step_invariant: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), a, _). anycast (rreq_rrep_fresh (rt \)) a)" proof - have rreq_oip: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PRreq-:3, PRreq-:4, PRreq-:15, PRreq-:27} \ oip \ \ kD(rt \) \ (sqn (rt \) (oip \) > (osn \) \ (sqn (rt \) (oip \) = (osn \) \ the (dhops (rt \) (oip \)) \ Suc (hops \) \ the (flag (rt \) (oip \)) = val))))" proof inv_cterms fix l \ l' pp p' assume "(\, pp) \ reachable (paodv i) TT" and "{PRreq-:2}\\\. \\rt := update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})\\ p' \ sterms \\<^sub>A\<^sub>O\<^sub>D\<^sub>V pp" and "l' = PRreq-:3" show "osn \ < sqn (update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})) (oip \) \ (sqn (update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})) (oip \) = osn \ \ the (dhops (update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})) (oip \)) \ Suc (hops \) \ the (flag (update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})) (oip \)) = val)" unfolding update_def by (clarsimp split: option.split) (metis linorder_neqE_nat not_less) qed have rrep_prrep: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PRrep-:2..PRrep-:7} \ (dip \ \ kD(rt \) \ sqn (rt \) (dip \) = dsn \ \ the (dhops (rt \) (dip \)) = Suc (hops \) \ the (flag (rt \) (dip \)) = val \ the (nhop (rt \) (dip \)) \ kD (rt \))))" by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf rrep_1_update_changes] onl_invariant_sterms [OF aodv_wf sip_in_kD]) show ?thesis by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf rreq_oip] onl_invariant_sterms [OF aodv_wf rreq_dip_in_vD_dip_eq_ip] onl_invariant_sterms [OF aodv_wf rrep_prrep]) qed text \Proposition 7.15\ lemma rerr_invalid_any_step_invariant: "paodv i \\<^sub>A onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), a, _). anycast (rerr_invalid (rt \)) a)" proof - have dests_inv: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PAodv-:15, PPkt-:7, PRreq-:9, PRreq-:21, PRrep-:10, PRerr-:1} \ (\ip\dom(dests \). ip\vD(rt \))) \ (l \ {PAodv-:16..PAodv-:19} \ {PPkt-:8..PPkt-:11} \ {PRreq-:10..PRreq-:13} \ {PRreq-:22..PRreq-:25} \ {PRrep-:11..PRrep-:14} \ {PRerr-:2..PRerr-:5} \ (\ip\dom(dests \). ip\iD(rt \) \ the (dests \ ip) = sqn (rt \) ip)) \ (l = PPkt-:14 \ dip \\iD(rt \)))" by inv_cterms (clarsimp split: if_split_asm option.split_asm simp: domIff)+ show ?thesis by (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf dests_inv]) qed text \Proposition 7.16\ text \ Some well-definedness obligations are irrelevant for the Isabelle development: \begin{enumerate} \item In each routing table there is at most one entry for each destination: guaranteed by type. \item In each store of queued data packets there is at most one data queue for each destination: guaranteed by structure. \item Whenever a set of pairs @{term "(rip, rsn)"} is assigned to the variable @{term "dests"} of type @{typ "ip \ sqn"}, or to the first argument of the function @{term "rerr"}, this set is a partial function, i.e., there is at most one entry @{term "(rip, rsn)"} for each destination @{term "rip"}: guaranteed by type. \end{enumerate} \ lemma dests_vD_inc_sqn: "paodv i \ onl \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\(\, l). (l \ {PAodv-:15, PPkt-:7, PRreq-:9, PRreq-:21, PRrep-:10} \ (\ip\dom(dests \). ip\vD(rt \) \ the (dests \ ip) = inc (sqn (rt \) ip))) \ (l = PRerr-:1 \ (\ip\dom(dests \). ip\vD(rt \) \ the (dests \ ip) > sqn (rt \) ip)))" by inv_cterms (clarsimp split: if_split_asm option.split_asm)+ text \Proposition 7.27\ lemma route_tables_fresher: "paodv i \\<^sub>A (recvmsg rreq_rrep_sn \) onll \\<^sub>A\<^sub>O\<^sub>D\<^sub>V (\((\, _), _, (\', _)). \dip\kD(rt \). rt \ \\<^bsub>dip\<^esub> rt \')" proof (inv_cterms inv add: onl_invariant_sterms [OF aodv_wf dests_vD_inc_sqn [THEN invariant_restrict_inD]] onl_invariant_sterms [OF aodv_wf hop_count_positive [THEN invariant_restrict_inD]] onl_invariant_sterms [OF aodv_wf osn_rreq] onl_invariant_sterms [OF aodv_wf dsn_rrep] onl_invariant_sterms [OF aodv_wf addpreRT_welldefined [THEN invariant_restrict_inD]]) fix \ pp p' assume "(\, pp) \ reachable (paodv i) (recvmsg rreq_rrep_sn)" and "{PRreq-:2}\\\. \\rt := update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})\\ p' \ sterms \\<^sub>A\<^sub>O\<^sub>D\<^sub>V pp" and "Suc 0 \ osn \" and *: "\ip\kD (rt \). Suc 0 \ the (dhops (rt \) ip)" show "\ip\kD (rt \). rt \ \\<^bsub>ip\<^esub> update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})" proof fix ip assume "ip\kD (rt \)" moreover with * have "1 \ the (dhops (rt \) ip)" by simp moreover from \Suc 0 \ osn \\ have "update_arg_wf (osn \, kno, val, Suc (hops \), sip \, {})" .. ultimately show "rt \ \\<^bsub>ip\<^esub> update (rt \) (oip \) (osn \, kno, val, Suc (hops \), sip \, {})" by (rule rt_fresher_update) qed next fix \ pp p' assume "(\, pp) \ reachable (paodv i) (recvmsg rreq_rrep_sn)" and "{PRrep-:1}\\\. \\rt := update (rt \) (dip \) (dsn \, kno, val, Suc (hops \), sip \, {})\\ p' \ sterms \\<^sub>A\<^sub>O\<^sub>D\<^sub>V pp" and "Suc 0 \ dsn \" and *: "\ip\kD (rt \). Suc 0 \ the (dhops (rt \) ip)" show "\ip\kD (rt \). rt \ \\<^bsub>ip\<^esub> update (rt \) (dip \) (dsn \, kno, val, Suc (hops \), sip \, {})" proof fix ip assume "ip\kD (rt \)" moreover with * have "1 \ the (dhops (rt \) ip)" by simp moreover from \Suc 0 \ dsn \\ have "update_arg_wf (dsn \, kno, val, Suc (hops \), sip \, {})" .. ultimately show "rt \ \\<^bsub>ip\<^esub> update (rt \) (dip \) (dsn \, kno, val, Suc (hops \), sip \, {})" by (rule rt_fresher_update) qed qed end