Part I Equivalent Transformation Techniques
5.2 Bit Merging
cross-free partitioning of the classi¿er by starting at the last rule and working up- ward. We¿nd that the seventh rule introduces a cross pattern with the eighth rule according to Theorem 5.2. This results in splitting the classi¿er into two partitions. Second, we perform bit swapping on each partition, which converts each partition into a list of one-dimensional pre¿x rules.
5.1.3 Partial List Minimization Algorithm
We now describe how to minimize each bit-swapped partition where we view each partition as a list of 1-dimensional pre¿x rules. If a list of 1-dimensional pre¿x rules is complete (i.e.,, any packet has a matching rule in the list), we can use the algo- rithms in [Suri et al(2003)Suri, Sandholm, and Warkhede,Draves et al(1999)Draves, King, Venkatachary, and Zill] to produce an equivalent minimal pre¿x rule list. However, the rule list in a partition is often incomplete; that is, there exist pack- ets that do not match any rule in the partition.
Instead, we adapt the Weighted 1-Dimensional Pre¿x List Minimization Algo- rithm in [Meiners et al(2007)Meiners, Liu, and Torng] to minimize a partial 1- dimensional pre¿x rule list L over¿eldF as follows. Let {d1,d2,⋅⋅⋅,dz} be the
set of all the decisions of the rules inL. Create a default ruler∗ that matches all packets and assign it decisiondz+1. Appendr∗toLto create a new classi¿erL′. As- sign each decision in{d1,d2,⋅⋅⋅,dz}a weight of 1 and the decisiondz+1a weight of∣D(F)∣, the size of the domainF. Finally, run the weighted 1-dimensional pre¿x list minimization algorithm in [Meiners et al(2007)Meiners, Liu, and Torng] onL′. Given our weight assignment for decisions, we know the¿nal rule of the resulting classi¿erL′′will still ber∗and that this rule will be the only one with decisiondz
+1. Remove this¿nal ruler∗fromL′′, and the resulting pre¿x list is the minimal partial pre¿x list that is equivalent toL.
Continuing the example from Figure 5.3, we use the partial pre¿x list minimiza- tion algorithm to minimize each partition to its minimal pre¿x representation. In this example, this step eliminates one rule from the bottom partition.
5.2 Bit Merging
In this section, we present bit merging, the second part of our bit weaving approach. T he fundamental idea behind bit merging is to repeatedly¿nd in a classi¿er two ternary strings that differ only in one bit and replace them with a single ternary string where the differing bit is∗.
48 5 Bit Weaving
5.2.1 De¿nitions
Two ternary stringst1andt2areternary adjacentif they differ only in one bit, i.e.,, their hamming distance [Hamming(1950)] is one. The ternary string produced by replacing the one differing bit by a∗int1(ort2) is called theternary coveroft1 andt2. For example, 0∗∗is the ternary cover of 00∗and 01∗. We call the process of replacing two ternary adjacent strings by their coverbit mergingor just merging. For example, we can merge 00∗and 01∗to form their cover 0∗∗.
We now de¿ne how to bit merge (or just merge) two rules. For any ruler, we use ℙ(r)to denote the predicate ofr. Two rulesri andrj are ternary adjacent if their
predicatesℙ(ri)andℙ(rj)are ternary adjacent. The merger of ternary adjacent rules
riandrjis a rule whose predicate is the ternary cover ofℙ(ri)andℙ(rj)and whose
decision is the decision of ruleri. We give a necessary and suf¿cient condition where
bit merging two rules does not change the semantics of a classi¿er.
Theorem 5.3.Two rules in a classi¿er can be merged into one rule without chang- ing the classi¿er semantics if and only if they satisfy the following three conditions: (1) they can be moved to be positionally adjacent without changing the semantics of the classi¿er; (2) they are ternary adjacent; (3) they have the same decision. □ The basic idea of bit merging is to repeatedly¿nd two rules in the same bit- swapped partition that can be merged based on the three conditions in Theorem 5.3. We do not consider merging rules from different bit-swapped partitions because any two bits from the same column in the two bit-swapped rules may correspond to different columns in the original rules.
5.2.2 Bit Merging Algorithm (BMA)
5.2.2.1 Pre¿x ChunkingTo address the¿rst condition in Theorem 5.3, we need to quickly determine what rules in a bit-swapped partition can be moved together without changing the seman- tics of the partition (or classi¿er). For any 1-dimensional minimum pre¿x classi¿er ℂ, letℂsdenote the pre¿x classi¿er formed by sorting all the rules inℂin decreas-
ing order of pre¿x length. We prove thatℂ≡ℂsifℂis a 1-dimensional minimum
pre¿x classi¿er in Theorem 5.4.
Before we introduce and prove Theorem 5.4, we¿rst present Lemma 5.1. A rule
risupward redundantif and only if there are no packets whose¿rst matching rule isr[Liu and Gouda(2005)]. Clearly, upward redundant rules can be removed from a classi¿er with no change in semantics.
Lemma 5.1.For any two rules riand rj(i<j)in a pre¿x classi¿er⟨r1,⋅⋅⋅,rn⟩that
5.2 Bit Merging 49 Theorem 5.4.For any one-dimensional minimum pre¿x packet classi¿erℂ, we have
ℂ≡ℂs.
Proof. Consider any two rules ri,rj (i< j) in ℂ. If the pre¿xes ofri andrj do
not overlap (i.e.,ℙ(ri)∩ℙ(rj) =/0), changing the relative order betweenri andrj
does not change the semantics ofℂ. If the pre¿xes ofri andrj do overlap (i.e.,,
ℙ(ri)∩ℙ(rj)∕=/0), then according to Lemma 5.1, we haveℙ(ri)⊂ℙ(rj). This means
thatℙ(ri)is strictly longer thanℙ(rj). This implies thatriis also listed beforerjin
ℂs. Thus, the result follows. ⊓⊔
Based on Theorem 5.4, given a minimum sized pre¿x bit-swapped partition, we ¿rst sort the rules in decreasing order of their pre¿x length. Second, we further partition the rules intopre¿x chunksbased on their pre¿x length. By Theorem 5.4, the order of the rules within each pre¿x chunk is irrelevant.
5.2.2.2 Bit-Mask Grouping
To address the second condition in Theorem 5.3, we need to quickly determine what rules are ternary adjacent. Based on Theorem 5.5, we can signi¿cantly reduce our search space by searching for mergeable rules only among the rules which have the same bit mask and decision.
Theorem 5.5.Given a list of rules such that the rules have the same decision and no rule’s predicate is a proper subset of another rule’s predicate, if two rules are mergeable, then the bit masks of their predicates are the same.
Proof. Suppose in such a list there are two rules ri andrj that are mergeable and
have different bit masks. Because they are mergeable,ℙ(ri)andℙ(rj)differ in only
one bit. Because the bit masks are different, one predicate, say ℙ(ri), must have
a∗ and the other predicate, ℙ(rj), must have a 0 or 1 in that bit column. Thus,
ℙ(rj)⊂ℙ(ri), which is a contradiction.
5.2.2.3 Algorithm and Optimality
The bit merging algorithm (BMA) works as follows. BMA takes as input a mini- mum, possibly incomplete pre¿x classi¿erℂthat corresponds to a cross-free parti- tion generated by bit swapping. BMA¿rst creates classi¿erℂsby sorting the rules
ofℂin decreasing order of their pre¿x length and partitionsℂsinto pre¿x chunks.
Second, for each pre¿x chunk, BMA groups all the rules with the same bit mask and decision together, eliminates duplicate rules, and searches within each group for mergeable rules. The second step repeats until no group contains rules that can be merged. Letℂ′denote the output of the algorithm.
Figure 5.4 demonstrates how BMA works. On the leftmost side is the¿rst par- tition from Figure 5.3. On the¿rst pass, eight ternary rules are generated from the
50 5 Bit Weaving
original seven. For example, the top two rules produce the rule 1000*0**→ 1. These eight rules are grouped into four groups with identical bit masks. On the sec- ond pass, two unique rules are produced by merging rules from the four groups. Since each rule is in a separate group, no further merges are possible and the algo- rithm¿nishes. Algorithm 8 shows the general algorithm for BMA.
Fig. 5.4 Example of Bit Merging Algorithm Execution
Input: A listIofnrules⟨r1,...,rn⟩where each rule hasbbits.
Output: A list ofmrules. LetSbe the set of rules inI;
1
LetCbe the partition ofSsuch that each partition contains a maximal set of rules inSwhere
2
each rule has an identical bitmask and decision; LetOSbe an empty set;
3 for eachc={r′ 1,...,rm′} ∈Cdo 4 fori := 1 to m−1do 5 forj := i+1to mdo 6 ifℙ(r′
i)andℙ(r′j)are ternary adjacentthenAdd the ternary cover ofℙ(ri′)and
7 ℙ(r′ j)toOS; end 8 end 9 end 10
LetObeOSsorted in decreasing order of pre¿x length;
11 ifS=Othen 12 returnO; 13 else 14
return the result of BMA withOas input;
15 end 16
Algorithm 8: Bit Merging Algorithm
The correctness of this algorithm,ℂ′≡ℂ, is guaranteed because we only com- bine mergeable rules. We now prove that BMA is locally optimal as stated in Theo- rem 5.6.
Lemma 5.2.During each execution of the second step, BMA never introduces two rules riand rjsuch thatℙ(ri)⊂ℙ(rj)where both riand rjhave the same decision.
5.3 Discussion 51