(* Title: Loop_Freedom.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke, Inria *) section "Routing graphs and loop freedom" theory Loop_Freedom imports Aodv_Predicates Fresher begin text \Define the central theorem that relates an invariant over network states to the absence of loops in the associate routing graph.\ definition rt_graph :: "(ip \ state) \ ip \ ip rel" where "rt_graph \ = (\dip. {(ip, ip') | ip ip' dsn dsk hops pre. ip \ dip \ rt (\ ip) dip = Some (dsn, dsk, val, hops, ip', pre)})" text \Given the state of a network @{term \}, a routing graph for a given destination ip address @{term dip} abstracts the details of routing tables into nodes (ip addresses) and vertices (valid routes between ip addresses).\ lemma rt_graphE [elim]: fixes n dip ip ip' assumes "(ip, ip') \ rt_graph \ dip" shows "ip \ dip \ (\r. rt (\ ip) = r \ (\dsn dsk hops pre. r dip = Some (dsn, dsk, val, hops, ip', pre)))" using assms unfolding rt_graph_def by auto lemma rt_graph_vD [dest]: "\ip ip' \ dip. (ip, ip') \ rt_graph \ dip \ dip \ vD(rt (\ ip))" unfolding rt_graph_def vD_def by auto lemma rt_graph_vD_trans [dest]: "\ip ip' \ dip. (ip, ip') \ (rt_graph \ dip)\<^sup>+ \ dip \ vD(rt (\ ip))" by (erule converse_tranclE) auto lemma rt_graph_not_dip [dest]: "\ip ip' \ dip. (ip, ip') \ rt_graph \ dip \ ip \ dip" unfolding rt_graph_def by auto lemma rt_graph_not_dip_trans [dest]: "\ip ip' \ dip. (ip, ip') \ (rt_graph \ dip)\<^sup>+ \ ip \ dip" by (erule converse_tranclE) auto text "NB: the property below cannot be lifted to the transitive closure" lemma rt_graph_nhip_is_nhop [dest]: "\ip ip' \ dip. (ip, ip') \ rt_graph \ dip \ ip' = the (nhop (rt (\ ip)) dip)" unfolding rt_graph_def by auto theorem inv_to_loop_freedom: assumes "\i dip. let nhip = the (nhop (rt (\ i)) dip) in dip \ vD (rt (\ i)) \ vD (rt (\ nhip)) \ nhip \ dip \ (rt (\ i)) \\<^bsub>dip\<^esub> (rt (\ nhip))" shows "\dip. irrefl ((rt_graph \ dip)\<^sup>+)" using assms proof (intro allI) fix \ :: "ip \ state" and dip assume inv: "\ip dip. let nhip = the (nhop (rt (\ ip)) dip) in dip \ vD(rt (\ ip)) \ vD(rt (\ nhip)) \ nhip \ dip \ rt (\ ip) \\<^bsub>dip\<^esub> rt (\ nhip)" { fix ip ip' assume "(ip, ip') \ (rt_graph \ dip)\<^sup>+" and "dip \ vD(rt (\ ip'))" and "ip' \ dip" hence "rt (\ ip) \\<^bsub>dip\<^esub> rt (\ ip')" proof induction fix nhip assume "(ip, nhip) \ rt_graph \ dip" and "dip \ vD(rt (\ nhip))" and "nhip \ dip" from \(ip, nhip) \ rt_graph \ dip\ have "dip \ vD(rt (\ ip))" and "nhip = the (nhop (rt (\ ip)) dip)" by auto from \dip \ vD(rt (\ ip))\ and \dip \ vD(rt (\ nhip))\ have "dip \ vD(rt (\ ip)) \ vD(rt (\ nhip))" .. with \nhip = the (nhop (rt (\ ip)) dip)\ and \nhip \ dip\ and inv show "rt (\ ip) \\<^bsub>dip\<^esub> rt (\ nhip)" by (clarsimp simp: Let_def) next fix nhip nhip' assume "(ip, nhip) \ (rt_graph \ dip)\<^sup>+" and "(nhip, nhip') \ rt_graph \ dip" and IH: "\ dip \ vD(rt (\ nhip)); nhip \ dip \ \ rt (\ ip) \\<^bsub>dip\<^esub> rt (\ nhip)" and "dip \ vD(rt (\ nhip'))" and "nhip' \ dip" from \(nhip, nhip') \ rt_graph \ dip\ have 1: "dip \ vD(rt (\ nhip))" and 2: "nhip \ dip" and "nhip' = the (nhop (rt (\ nhip)) dip)" by auto from 1 2 have "rt (\ ip) \\<^bsub>dip\<^esub> rt (\ nhip)" by (rule IH) also have "rt (\ nhip) \\<^bsub>dip\<^esub> rt (\ nhip')" proof - from \dip \ vD(rt (\ nhip))\ and \dip \ vD(rt (\ nhip'))\ have "dip \ vD(rt (\ nhip)) \ vD(rt (\ nhip'))" .. with \nhip' \ dip\ and \nhip' = the (nhop (rt (\ nhip)) dip)\ and inv show "rt (\ nhip) \\<^bsub>dip\<^esub> rt (\ nhip')" by (clarsimp simp: Let_def) qed finally show "rt (\ ip) \\<^bsub>dip\<^esub> rt (\ nhip')" . qed } note fresher = this show "irrefl ((rt_graph \ dip)\<^sup>+)" unfolding irrefl_def proof (intro allI notI) fix ip assume "(ip, ip) \ (rt_graph \ dip)\<^sup>+" moreover then have "dip \ vD(rt (\ ip))" and "ip \ dip" by auto ultimately have "rt (\ ip) \\<^bsub>dip\<^esub> rt (\ ip)" by (rule fresher) thus False by simp qed qed end