Skip to content

Commit 99d88db

Browse files
added further definition for the next layers to make the BDD creation super fast
1 parent f4daf3a commit 99d88db

File tree

2 files changed

+112
-71
lines changed

2 files changed

+112
-71
lines changed

hol/policy_to_table/bdd_fwd_pipeline_exampleScript.sml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ open bdd_utilsLib;
4444
val _ = new_theory "bdd_fwd_pipeline_example";
4545

4646
(* a few types abbreviations *)
47-
val _ = type_abbrev("BDD_tbl_type", “:(( (string# num list) var_table_list, (string# num list) action_expr) BDD)”);
47+
48+
(*val _ = type_abbrev("BDD_tbl_type", “:(( (string# num list) var_table_list, (string# num list) action_expr) BDD)”);
4849
4950
val _ = type_abbrev("struc_tbl_type", “:((( atom_var list # num # (string# num list) action_expr) list list # num,
5051
(string# num list) action_expr) decision_structure)”);
5152
5253
val _ = type_abbrev("action_rule_type", “:((string# num list) action_expr) rule”);
5354
val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) policy”);
54-
55+
*)
5556

57+
val _ = type_abbrev("single_rule", “: single_rule ”);
5658

5759
(****************************************************************)
5860
(****************************************************************)
@@ -94,24 +96,24 @@ val policy_order = “["x";"y";"z";"w";"q";"r"]”;
9496
(* Rule 1: High priority small control packets - expedited forwarding *)
9597
val arith_policy_rule1 = “(arith_and (arith_a ^is_high_priority)
9698
(arith_and (arith_a ^is_small_packet) (arith_a ^is_control_type)),
97-
action ("fwd_priority",[1; 255])):((string# num list) action_expr) arith_rule”;
99+
action ("fwd_priority",[1; 255])): single_rule ”;
98100

99101
(* Rule 2: High priority data packets *)
100102
val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_data_type),
101-
action ("fwd",[1])):((string# num list) action_expr) arith_rule”;
103+
action ("fwd",[1])): single_rule ”;
102104

103105
(* Rule 3: Medium priority young packets *)
104106
val arith_policy_rule3 = “(arith_and (arith_a ^is_medium_priority) (arith_a ^is_young_packet),
105-
action ("fwd",[2])):((string# num list) action_expr) arith_rule”;
107+
action ("fwd",[2])): single_rule ”;
106108

107109
(* Rule 7: Default forward rule *)
108110
val arith_policy_rule7 = “(arith_a a_True,
109-
action ("fwd",[5])):((string# num list) action_expr) arith_rule”;
111+
action ("fwd",[5])): single_rule ”;
110112

111113
val arith_policy = “[^arith_policy_rule1;
112114
^arith_policy_rule2;
113115
^arith_policy_rule3;
114-
^arith_policy_rule7]:((string# num list) action_expr) arith_policy”;
116+
^arith_policy_rule7]: single_rule list”;
115117

116118

117119
(********************************)
@@ -144,7 +146,7 @@ val arith_policy_var_policy_thm = REWRITE_RULE[all_distinct_conj, arith_policy_e
144146
(***********************)
145147

146148
(* create BDD of var policy *)
147-
val eval_policy_full_opt = EVAL “mk_BDDPred_opt policy_structure (0,[],[(0, non_termn (NONE, ^var_policy))]) [] ^policy_order 1”;
149+
val eval_policy_full_opt = EVAL “mk_BDDPred_opt_new policy_structure (0,[],[(0, non_termn (NONE, ^var_policy))]) [] ^policy_order 1”;
148150
val eval_policy_full_opt_rhs = optionSyntax.dest_some (rhs (concl eval_policy_full_opt));
149151

150152

@@ -154,7 +156,7 @@ val gen_var_table_auto = bdd_utilsLib.bdd_to_tables_iterative eval_policy_full_
154156

155157

156158
(* now create a BDD for the table*)
157-
val eval_table_full_opt_auto = EVAL “mk_BDDPred_opt table_structure_new (0,[],[(0, non_termn (NONE, ^gen_var_table_auto))]) [] ^policy_order 1”;
159+
val eval_table_full_opt_auto = EVAL “mk_BDDPred_opt_new table_structure_new (0,[],[(0, non_termn (NONE, ^gen_var_table_auto))]) [] ^policy_order 1”;
158160
val eval_table_full_opt_auto_rhs = optionSyntax.dest_some (rhs (concl eval_table_full_opt_auto));
159161

160162

hol/policy_to_table/policy_test_cases/profiling_proofScript.sml

Lines changed: 101 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ val _ = new_theory "profiling_proof";
4747

4848
val _ = type_abbrev("distrub_st", ``:( (string, (num list) option) alist # num list # num list)``);
4949

50-
Definition eliminable_def:
51-
eliminable ((r,edges,labels):('a,'b)BDD) n =
50+
51+
52+
(*
53+
54+
Definition eliminable_new_def:
55+
eliminable_new ((r,edges,labels):('a,'b)BDD) n =
5256
case ALOOKUP edges n of
5357
|SOME (n1, n2) =>
5458
if n1 = n2 ∧
@@ -59,8 +63,28 @@ Definition eliminable_def:
5963
| NONE => NONE
6064
End
6165
62-
63-
val _ = type_abbrev("distrub_st", ``:( (string, (num list) option) alist # num list # num list)``);
66+
67+
68+
Definition eliminable_projection_def:
69+
eliminable_projection edges_proj n =
70+
case ALOOKUP edges_proj n of
71+
|SOME (n1, n2) =>
72+
if n1 = n2 ∧
73+
n1 ≠ n ∧
74+
n ≠ 0n ∧
75+
has_parent edges_proj n1 n
76+
then SOME n1
77+
else NONE
78+
| NONE => NONE
79+
End
80+
81+
82+
Definition mergable_projection_def:
83+
mergable_projection edges_proj labels_proj n n' =
84+
(n≠n' ∧ ALOOKUP edges_proj n = ALOOKUP edges_proj n' ∧
85+
eq_vars_in_labels labels_proj n n' ∧ ALOOKUP labels_proj n' ≠ NONE )
86+
End
87+
6488
6589
6690
Definition update_internals_def:
@@ -107,50 +131,72 @@ End
107131
Definition merge_safe_def:
108132
merge_safe (BDD:('a,'b) BDD) n n' =
109133
if mergable BDD n n' then
110-
merge BDD n' n
134+
(T, merge BDD n n')
111135
else
112-
BDD
136+
(F, BDD)
113137
End
114138
115139
116140
Definition eliminate_safe_def:
117141
eliminate_safe (BDD:('a,'b) BDD) n =
118-
case eliminable BDD n of
119-
| SOME n' => merge BDD n' n
120-
| NONE => BDD
142+
case eliminable_new BDD n of
143+
| SOME n' => (T, merge BDD n' n)
144+
| NONE => (F,BDD)
121145
End
122146
123147
124148
125149
126-
(* can be improved more *)
127-
Definition optimize_node_def:
128-
(optimize_node (BDD:('a,'b) BDD) n [] = eliminate_safe BDD n) ∧
129150
130-
(optimize_node BDD n (n'::nl) =
131-
case eliminable BDD n of
132-
| SOME n' => eliminate_safe (BDD:('a,'b) BDD) n
133-
| NONE => optimize_node (merge_safe BDD n n') n nl)
151+
Definition optimize_node_def:
152+
(optimize_node edges_proj labels_proj (BDD:('a,'b) BDD) n [] = SND (eliminate_safe BDD n)) ∧
153+
154+
(optimize_node edges_proj labels_proj BDD n (n'::nl) =
155+
case eliminable_projection edges_proj n of
156+
| SOME n' => SND (eliminate_safe BDD n)
157+
| NONE => (
158+
case mergable_projection edges_proj labels_proj n' n of
159+
| T => ( case merge_safe BDD n' n of
160+
| (T, BDD') => BDD'
161+
| (F, BDD') => optimize_node edges_proj labels_proj BDD n nl
162+
)
163+
164+
| F => optimize_node edges_proj labels_proj BDD n nl)
165+
)
134166
End
135167
136168
137169
138170
139171
Definition optimize_layer_def:
140-
(optimize_layer (BDD:('a,'b) BDD) [] = BDD) /\
141-
(optimize_layer BDD (n::nl)=
142-
optimize_layer (optimize_node BDD n nl) nl
172+
(optimize_layer edges_proj labels_proj (BDD:('a,'b) BDD) [] = BDD) /\
173+
(optimize_layer edges_proj labels_proj BDD (n::nl)=
174+
optimize_layer edges_proj labels_proj (optimize_node edges_proj labels_proj BDD n nl) nl
143175
)
144176
End
145177
146-
178+
179+
Definition project_edges_to_def:
180+
project_edges_to ((r, edges,labels):('a,'b) BDD) nl =
181+
MAP (\n. (n,THE(ALOOKUP edges n))) nl
182+
End
183+
184+
Definition project_labels_to_def:
185+
project_labels_to ((r, edges,labels):('a,'b) BDD) nl =
186+
MAP (\n. (n,THE(ALOOKUP labels n))) nl
187+
End
188+
189+
190+
147191
Definition optimize_internals_def:
148192
(optimize_internals (BDD:('a,'b) BDD) [] = BDD) /\
149193
(optimize_internals BDD ((var,NONE)::l) = optimize_internals BDD l) /\
150194
151195
(optimize_internals BDD ((var,SOME nl)::l)=
152-
let BDD' = optimize_layer BDD nl in
153-
optimize_internals BDD' l
196+
let edges_proj = project_edges_to BDD nl in
197+
let labels_proj = project_labels_to BDD nl in
198+
let BDD' = optimize_layer edges_proj labels_proj BDD nl in
199+
optimize_internals BDD' l
154200
)
155201
End
156202
@@ -160,9 +206,11 @@ End
160206
Definition optimize_bdd_def:
161207
optimize_bdd (BDD:('a,'b) BDD) order =
162208
let (internals,ntl,tl) = bdd_distribute (BDD:('a,'b) BDD) order in
163-
let BDD1 = optimize_layer BDD tl in
164-
let BDD2 = optimize_layer BDD1 ntl in
165-
optimize_internals BDD2 internals
209+
let labels_proj_tl = project_labels_to BDD tl in (* for terminals *)
210+
let labels_proj_ntl = project_labels_to BDD ntl in (* for terminals *)
211+
let BDD1 = optimize_layer [] labels_proj_tl BDD tl in
212+
let BDD2 = optimize_layer [] labels_proj_ntl BDD1 ntl in
213+
optimize_internals BDD2 internals
166214
End
167215
168216
@@ -178,6 +226,9 @@ Definition mk_BDDPred_opt_new_def:
178226
End
179227
180228
229+
230+
231+
181232
182233
183234
@@ -210,12 +261,6 @@ val eval_table_full_opt_auto_new = EVAL “mk_BDDPred_opt_new table_structure_ne
210261
211262
212263
213-
214-
215-
216-
217-
val _ = type_abbrev("single_rule", “:((string# num list) action_expr) arith_rule”);
218-
219264
val test_pd_type = “[("ip", type_record [("priority", type_length 3);
220265
("size", type_length 16);
221266
("age", type_length 8);
@@ -224,11 +269,8 @@ val test_pd_type = “[("ip", type_record [("priority", type_length 3);
224269
val is_high_priority = “(arithm_le (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 2 3))”;
225270
val is_medium_priority = “(arithm_ge (lv_acc (lv_x "ip") "priority") ^(bdd_utilsLib.make_bv 4 3))”;
226271
227-
val is_size_packet1 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 30000 16))”;
228-
val is_size_packet2 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 27000 16))”;
229-
val is_size_packet3 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 25000 16))”;
230-
val is_size_packet4 = “(arithm_ge (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 23000 16))”;
231-
272+
val is_small_packet1 = “(arithm_le (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 500 16))”;
273+
val is_small_packet2 = “(arithm_le (lv_acc (lv_x "ip") "size") ^(bdd_utilsLib.make_bv 400 16))”;
232274
233275
val is_young_packet = “(arithm_ge (lv_acc (lv_x "ip") "age") ^(bdd_utilsLib.make_bv 200 8))”;
234276
@@ -237,42 +279,38 @@ val is_data_type = “(arithm_ge (lv_acc (lv_x "ip") "type") ^(bdd_utilsLib.make
237279
238280
239281
240-
val policy_me = “[("x1", ^is_high_priority);
241-
("x2", ^is_medium_priority);
282+
val policy_me = “[("x", ^is_high_priority);
283+
("y", ^is_medium_priority);
284+
("z1", ^is_small_packet1);
285+
("z2", ^is_small_packet2);
286+
("w", ^is_young_packet);
287+
("q", ^is_control_type);
288+
("r", ^is_data_type)]”;
242289
243-
("z1", ^is_size_packet1);
244-
("z2", ^is_size_packet2);
245-
("z3", ^is_size_packet3);
246-
("z4", ^is_size_packet4);
290+
val policy_full_order = “[("a",["x";"y"]);
291+
("b",["z1";"z2"]);
292+
("c",["w"]);
293+
("d",["q";"r"])]”;
247294
248-
("q1", ^is_control_type);
249-
("q2", ^is_data_type)]”;
250-
251-
val policy_full_order = “[("a",["x1";"x2"]);
252-
("b",["z1";"z2";"z3";"z4"]);
253-
("d",["q1";"q2"])]”;
254-
255-
val policy_order = “["x1";"x2";"z1";"z2";"z3";"z4";"q1";"q2"]”;
295+
val policy_order = “["x";"y";"z1";"z2";"w";"q";"r"]”;
256296
297+
(* Rule 1: High priority small control packets - expedited forwarding *)
257298
val arith_policy_rule1 = “(arith_and (arith_a ^is_high_priority)
258-
(arith_and (arith_a ^is_size_packet1) (arith_a ^is_control_type)),
299+
(arith_and (arith_a ^is_small_packet1) (arith_a ^is_control_type)),
259300
action ("fwd_priority",[1; 255])):single_rule”;
260301
261-
val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet2),
302+
(* Rule 2: High priority data packets *)
303+
val arith_policy_rule2 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_data_type),
262304
action ("fwd",[1])):single_rule”;
263305
264-
val arith_policy_rule3 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet3),
306+
(* Rule 3: Medium priority young packets *)
307+
val arith_policy_rule3 = “(arith_and (arith_a ^is_medium_priority) (arith_a ^is_young_packet),
265308
action ("fwd",[2])):single_rule”;
266309
267-
val arith_policy_rule4 = “(arith_and (arith_a ^is_high_priority) (arith_a ^is_size_packet4),
310+
(* Rule 3: Medium priority young packets *)
311+
val arith_policy_rule4 = “((arith_a ^is_small_packet2),
268312
action ("fwd",[3])):single_rule”;
269313
270-
val arith_policy_rule5 = “(arith_and (arith_a ^is_medium_priority)
271-
(arith_and (arith_a ^is_size_packet1) (arith_a ^is_data_type)),
272-
action ("fwd_priority",[1; 4])):single_rule”;
273-
274-
275-
276314
277315
(* Default forward rule *)
278316
val arith_policy_rule_default = “(arith_a a_True,
@@ -282,9 +320,10 @@ val arith_policy = “[^arith_policy_rule1;
282320
^arith_policy_rule2;
283321
^arith_policy_rule3;
284322
^arith_policy_rule4;
285-
^arith_policy_rule5;
286323
^arith_policy_rule_default]:single_rule list”;
287324
325+
326+
288327
(**************************************************)
289328
290329
@@ -293,7 +332,7 @@ val arith_policy = “[^arith_policy_rule1;
293332
294333
295334
296-
335+
*)
297336

298337

299338

0 commit comments

Comments
 (0)