Skip to content

Commit ad40268

Browse files
added a few test cases for time
1 parent b006f25 commit ad40268

File tree

4 files changed

+300
-63
lines changed

4 files changed

+300
-63
lines changed

hol/policy_to_table/fwd_proofLib.sml

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,38 @@ open table_bs_propertiesTheory;
4141

4242
open bdd_utilsLib;
4343

44+
4445

46+
fun time_stage (stage_name, timer_cpu, timer_real) =
47+
let
48+
val cpu_time = Timer.checkCPUTimer timer_cpu
49+
val real_time = Timer.checkRealTimer timer_real
50+
val _ = HOL_MESG (stage_name ^ " completed in: " ^
51+
Time.toString (#usr cpu_time) ^ " user, " ^
52+
Time.toString (#sys cpu_time) ^ " system, " ^
53+
Time.toString real_time ^ " real\n")
54+
in
55+
(cpu_time, real_time)
56+
end
4557

46-
(* a few types abbreviations *)
47-
(*
48-
val _ = type_abbrev("BDD_tbl_type", “:(( (string# num list) var_table_list, (string# num list) action_expr) BDD)”);
49-
50-
val _ = type_abbrev("struc_tbl_type", “:((( atom_var list # num # (string# num list) action_expr) list list # num,
51-
(string# num list) action_expr) decision_structure)”);
52-
53-
val _ = type_abbrev("action_rule_type", “:((string# num list) action_expr) rule”);
54-
val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) policy”);
55-
*)
56-
5758

5859

5960
fun convert_arith_policy_to_interval_tables (arith_policy, policy_me, test_pd_type, policy_full_order, policy_order) =
6061

6162
let
6263

64+
val start_cpu_total = Timer.startCPUTimer ();
65+
val start_real_total = Timer.startRealTimer ();
66+
67+
6368
(***********************)
6469
(* STAGE 1 *)
6570
(***********************)
6671

72+
val start_cpu_stage1 = Timer.startCPUTimer ();
73+
val start_real_stage1 = Timer.startRealTimer ();
74+
75+
6776
(*convert arith policy to var policy*)
6877
val arith_policy_eval = EVAL “convert_arith_to_var_policy ^arith_policy ^policy_me”;
6978
val var_policy = optionSyntax.dest_some (rhs (concl arith_policy_eval));
@@ -81,25 +90,44 @@ val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) p
8190
(ISPECL[arith_policy, var_policy, policy_me] policy_airth_to_var_sem_conversion_correct);
8291

8392

93+
val _ = time_stage ("Stage 1", start_cpu_stage1, start_real_stage1)
94+
95+
8496
(***********************)
8597
(* STAGE 2 *)
8698
(***********************)
8799

100+
101+
val start_cpu_stage2 = Timer.startCPUTimer ();
102+
val start_real_stage2 = Timer.startRealTimer ();
103+
104+
88105
(* create BDD of var policy *)
89106
val eval_policy_full_opt = EVAL “mk_BDDPred_opt policy_structure (0,[],[(0, non_termn (NONE, ^var_policy))]) [] ^policy_order 1”;
90107
val eval_policy_full_opt_rhs = optionSyntax.dest_some (rhs (concl eval_policy_full_opt));
91108

109+
val _ = time_stage ("Stage 2 from var policy to BDD", start_cpu_stage2, start_real_stage2);
110+
val start_cpu_stage2_vbdd = Timer.startCPUTimer ();
111+
val start_real_stage2_vbdd = Timer.startRealTimer ();
92112

93113
(* automatically generate a var table from the var policy's BDD via sml*)
94114
val test_groupings = rhs(concl(EVAL policy_full_order));
95115
val gen_var_table_auto = bdd_utilsLib.bdd_to_tables_iterative eval_policy_full_opt_rhs test_groupings;
96116

97117

118+
val _ = time_stage ("Stage 2 from var BDD to table", start_cpu_stage2_vbdd, start_real_stage2_vbdd);
119+
val start_cpu_stage2_tbl = Timer.startCPUTimer ();
120+
val start_real_stage2_tbl = Timer.startRealTimer ();
121+
98122
(* now create a BDD for the table*)
99123
val eval_table_full_opt_auto = EVAL “mk_BDDPred_opt table_structure (0,[],[(0, non_termn (NONE, ^gen_var_table_auto))]) [] ^policy_order 1”;
100124
val eval_table_full_opt_auto_rhs = optionSyntax.dest_some (rhs (concl eval_table_full_opt_auto));
101125

102126

127+
val _ = time_stage ("Stage 2 from table to table BDD", start_cpu_stage2_tbl, start_real_stage2_tbl);
128+
val start_cpu_stage2_tbdd = Timer.startCPUTimer ();
129+
val start_real_stage2_tbdd = Timer.startRealTimer ();
130+
103131
(* get I (pairs isomorphic in the graph), and check if isisIsomorph *)
104132
val get_i_policy = bdd_utilsLib.pairBDDs (eval_policy_full_opt_rhs, eval_table_full_opt_auto_rhs);
105133
(*val is_tbl_policy1_iso = EVAL “isIsomorph_exec ^get_i_policy ^eval_policy_full_opt_rhs
@@ -109,16 +137,23 @@ val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) p
109137

110138
(* Theorem of correctness for conversion from var policy to var table *)
111139

112-
(* method 1 *)
113140
val policy_thm_init = computeLib.RESTR_EVAL_CONV [“sem_tables”,“sem_policy”, “mv_dom_vars”] “correct_var_policy_var_tables_exec ^var_policy ^gen_var_table_auto ^policy_order ^get_i_policy ”;
114141
val var_policy_var_table_thm = SIMP_RULE bool_ss [correct_var_policy_var_tables_exec_thm1] policy_thm_init;
115142

143+
val _ = time_stage ("Stage 2 proof", start_cpu_stage2_tbdd, start_real_stage2_tbdd);
144+
145+
val _ = time_stage ("Stage 2 total", start_cpu_stage2, start_real_stage2);
146+
116147

117148

118149
(***********************)
119150
(* STAGE 3 *)
120151
(***********************)
121152

153+
val start_cpu_stage3 = Timer.startCPUTimer ();
154+
val start_real_stage3 = Timer.startRealTimer ();
155+
156+
122157
(* covert var table to interval table *)
123158
val only_var_table = fst (dest_pair gen_var_table_auto);
124159
val convert_to_interval = EVAL “convert_var_to_sinterval_tables ^only_var_table ^policy_me ^test_pd_type”;
@@ -129,8 +164,17 @@ val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) p
129164
val var_table_sinterval_tbl_thm =
130165
REWRITE_RULE [convert_to_interval] (ISPECL[only_var_table, only_interval_table1, “0:num”, policy_me, test_pd_type ] correct_tables_from_var_to_sinterval_thm);
131166

167+
val _ = time_stage ("Stage 3", start_cpu_stage3, start_real_stage3);
168+
169+
170+
171+
172+
(***********************)
173+
(* FINAL PROOF *)
174+
(***********************)
175+
val start_cpu_final = Timer.startCPUTimer ();
176+
val start_real_final = Timer.startRealTimer ();
132177

133-
134178
(* to glue the theorems we need to take care of the conditions/ assumptions *)
135179

136180
(* condition1 *)
@@ -176,6 +220,13 @@ val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) p
176220
fs[cond1_thm, cond2_thm, cond3_thm]
177221
);
178222

223+
224+
val _ = time_stage ("Final glue proof", start_cpu_final, start_real_final);
225+
226+
val _ = time_stage ("Total time of everything", start_cpu_total, start_real_total);
227+
228+
229+
179230
in
180231
final_thm
181232
end;

hol/policy_to_table/policy_test_cases/auto_test2Script.sml

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,72 @@ open fwd_proofLib;
99
val _ = new_theory "auto_test2";
1010

1111
val _ = type_abbrev("single_rule", “:((string# num list) action_expr) arith_rule”);
12-
1312

14-
val test_pd_type1 = “[("ip", type_record [("ttl", type_length 6)])]”;
15-
16-
val is_le_than_10 = “(arithm_le (lv_acc (lv_x "ip") "ttl") ^(bdd_utilsLib.make_bv 10 6))”;
17-
val is_ge_than_10 = “(arithm_ge (lv_acc (lv_x "ip") "ttl") ^(bdd_utilsLib.make_bv 10 6))”;
18-
19-
val is_ge_than_30 = “(arithm_ge (lv_acc (lv_x "ip") "ttl") ^(bdd_utilsLib.make_bv 30 6))”;
20-
val is_le_than_9 = “(arithm_le (lv_acc (lv_x "ip") "ttl") ^(bdd_utilsLib.make_bv 9 6))”;
21-
22-
23-
val policy_me1 = “[("x", ^is_le_than_10)]”;
24-
25-
val policy_full_order1 = “[("a",["x"])]”;
26-
27-
val policy_order1 = “["x"]”;
28-
29-
(* Rule 1: ttl <= 10 : accept *)
30-
val arith_policy_rule1 = “((arith_a ^is_le_than_10),
31-
action ("accept",[])):single_rule”;
32-
33-
(* Default forward rule *)
34-
val arith_policy_default = “(arith_a a_True,
35-
action ("reject",[])):single_rule”;
36-
37-
val arith_policy1 = “[^arith_policy_rule1;
38-
^arith_policy_default]:single_rule list”;
39-
13+
val test_pd_type = “[("ip", type_record [("priority", type_length 3);
14+
("size", type_length 16);
15+
("age", type_length 8);
16+
("type", type_length 4)])]”;
4017

18+
val is_high_priority = “(arithm_le (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 2 3))”;
19+
val is_medium_priority = “(arithm_ge (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 4 3))”;
4120

42-
val final_thm_res1 =
43-
fwd_proofLib.convert_arith_policy_to_interval_tables (arith_policy1, policy_me1, test_pd_type1, policy_full_order1, policy_order1);
21+
val is_small_packet1 = “(arithm_le (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 500 16))”;
22+
val is_small_packet2 = “(arithm_le (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 400 16))”;
4423

45-
(*********************************)
24+
val is_young_packet = “(arithm_ge (lv_acc (lv_x "ip") "age") ^(bdd_utilsLib.make_bv 200 8))”;
4625

47-
val arith_policy_rule2 = “((arith_a ^is_ge_than_30),
48-
action ("accept",[])):single_rule”;
26+
val is_control_type = “(arithm_le (lv_acc (lv_x "ip") "type") ^(bdd_utilsLib.make_bv 3 4))”;
27+
val is_data_type = “(arithm_ge (lv_acc (lv_x "ip") "type") ^(bdd_utilsLib.make_bv 8 4))”;
4928

5029

51-
val arith_policy2 = “[^arith_policy_rule2;
52-
^arith_policy_default]:single_rule list”;
5330

54-
val policy_me2 = “[("x", ^is_ge_than_30)]”;
31+
val policy_me = “[("x", ^is_high_priority);
32+
("y", ^is_medium_priority);
33+
("z1", ^is_small_packet1);
34+
("z2", ^is_small_packet2);
35+
("w", ^is_young_packet);
36+
("q", ^is_control_type);
37+
("r", ^is_data_type)]”;
5538

39+
val policy_full_order = “[("a",["x";"y"]);
40+
("b",["z1";"z2"]);
41+
("c",["w"]);
42+
("d",["q";"r"])]”;
5643

57-
val final_thm_res2 =
58-
fwd_proofLib.convert_arith_policy_to_interval_tables (arith_policy2, policy_me2, test_pd_type1, policy_full_order1, policy_order1);
44+
val policy_order = “["x";"y";"z1";"z2";"w";"q";"r"]”;
5945

60-
(***********************)
46+
(* Rule 1: High priority small control packets - expedited forwarding *)
47+
val arith_policy_rule1 = “(arith_and (arith_a ^is_high_priority)
48+
(arith_and (arith_a ^is_small_packet1) (arith_a ^is_control_type)),
49+
action ("fwd_priority",[1; 255])):single_rule”;
6150

62-
val arith_policy_rule3 = “(arith_or (arith_a ^is_ge_than_10) (arith_a ^is_le_than_9),
63-
action ("reject",[])):single_rule”;
51+
(* Rule 2: High priority data packets *)
52+
val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_data_type),
53+
action ("fwd",[1])):single_rule”;
6454

55+
(* Rule 3: Medium priority young packets *)
56+
val arith_policy_rule3 = “(arith_and (arith_a ^is_medium_priority) (arith_a ^is_young_packet),
57+
action ("fwd",[2])):single_rule”;
6558

59+
(* Rule 3: Medium priority young packets *)
60+
val arith_policy_rule4 = “((arith_a ^is_small_packet2),
61+
action ("fwd",[3])):single_rule”;
6662

67-
val arith_policy3 = “[^arith_policy_default;
68-
^arith_policy_rule3]:single_rule list”;
69-
70-
val policy_me3 = “[("x", ^is_ge_than_10);("y", ^is_le_than_9)]”;
71-
72-
val policy_full_order3 = “[("a",["x";"y"])]”;
73-
74-
val policy_order3 = “["x";"y"]”;
7563

64+
(* Default forward rule *)
65+
val arith_policy_rule_default = “(arith_a a_True,
66+
action ("fwd",[5])):single_rule”;
7667

77-
val final_thm_res3 =
78-
fwd_proofLib.convert_arith_policy_to_interval_tables (arith_policy3, policy_me3, test_pd_type1, policy_full_order3, policy_order3);
68+
val arith_policy = “[^arith_policy_rule1;
69+
^arith_policy_rule2;
70+
^arith_policy_rule3;
71+
^arith_policy_rule4;
72+
^arith_policy_rule_default]:single_rule list”;
7973

8074

8175

76+
val final_thm_res =
77+
fwd_proofLib.convert_arith_policy_to_interval_tables (arith_policy, policy_me, test_pd_type, policy_full_order, policy_order);
8278

8379

8480

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
open HolKernel boolLib liteLib simpLib Parse bossLib;
2+
3+
open policy_arith_to_varTheory;
4+
5+
open bdd_utilsLib;
6+
open fwd_proofLib;
7+
8+
9+
val _ = new_theory "auto_test3";
10+
11+
val _ = type_abbrev("single_rule", “:((string# num list) action_expr) arith_rule”);
12+
13+
val test_pd_type = “[("ip", type_record [("priority", type_length 3);
14+
("size", type_length 16);
15+
("age", type_length 8);
16+
("type", type_length 4)])]”;
17+
18+
val is_high_priority = “(arithm_le (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 2 3))”;
19+
val is_medium_priority = “(arithm_ge (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 4 3))”;
20+
21+
val is_size_packet1 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 30000 16))”;
22+
val is_size_packet2 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 27000 16))”;
23+
val is_size_packet3 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 25000 16))”;
24+
val is_size_packet4 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 23000 16))”;
25+
26+
27+
val is_young_packet = “(arithm_ge (lv_acc (lv_x "ip") "age") ^(bdd_utilsLib.make_bv 200 8))”;
28+
29+
val is_control_type = “(arithm_le (lv_acc (lv_x "ip") "type") ^(bdd_utilsLib.make_bv 3 4))”;
30+
val is_data_type = “(arithm_ge (lv_acc (lv_x "ip") "type") ^(bdd_utilsLib.make_bv 8 4))”;
31+
32+
33+
34+
val policy_me = “[("x1", ^is_high_priority);
35+
("x2", ^is_medium_priority);
36+
37+
("z1", ^is_size_packet1);
38+
("z2", ^is_size_packet2);
39+
("z3", ^is_size_packet3);
40+
("z4", ^is_size_packet4);
41+
42+
("q1", ^is_control_type);
43+
("q2", ^is_data_type)]”;
44+
45+
val policy_full_order = “[("a",["x1";"x2"]);
46+
("b",["z1";"z2";"z3";"z4"]);
47+
("d",["q1";"q2"])]”;
48+
49+
val policy_order = “["x1";"x2";"z1";"z2";"z3";"z4";"q1";"q2"]”;
50+
51+
val arith_policy_rule1 = “(arith_and (arith_a ^is_high_priority)
52+
(arith_and (arith_a ^is_size_packet1) (arith_a ^is_control_type)),
53+
action ("fwd_priority",[1; 255])):single_rule”;
54+
55+
val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet2),
56+
action ("fwd",[1])):single_rule”;
57+
58+
val arith_policy_rule3 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet3),
59+
action ("fwd",[2])):single_rule”;
60+
61+
val arith_policy_rule4 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet4),
62+
action ("fwd",[3])):single_rule”;
63+
64+
val arith_policy_rule5 = “(arith_and (arith_a ^is_medium_priority)
65+
(arith_and (arith_a ^is_size_packet1) (arith_a ^is_data_type)),
66+
action ("fwd_priority",[1; 4])):single_rule”;
67+
68+
69+
70+
71+
(* Default forward rule *)
72+
val arith_policy_rule_default = “(arith_a a_True,
73+
action ("fwd",[5])):single_rule”;
74+
75+
val arith_policy = “[^arith_policy_rule1;
76+
^arith_policy_rule2;
77+
^arith_policy_rule3;
78+
^arith_policy_rule4;
79+
^arith_policy_rule5;
80+
^arith_policy_rule_default]:single_rule list”;
81+
82+
83+
84+
val final_thm_res =
85+
fwd_proofLib.convert_arith_policy_to_interval_tables (arith_policy, policy_me, test_pd_type, policy_full_order, policy_order);
86+
87+
88+
89+
90+
91+
val _ = export_theory ();
92+
93+
94+
95+
96+
97+

0 commit comments

Comments
 (0)