22 for (i = 0; i <
ARRAY_LEN (key->match.as_u64); i++)
24 if (key->match.as_u64[i] != r->match.as_u64[i])
27 for (i = 0; i <
ARRAY_LEN (key->mask.as_u64); i++)
29 if (key->mask.as_u64[i] != r->mask.as_u64[i])
38 RTT (mma_mask_or_match) _tmp_key, *tkp = &_tmp_key;
42 for (i = 0; i <
ARRAY_LEN (tkp->as_u64); i++)
43 tkp->as_u64[i] &= r->mask.as_u64[i];
46 if (tkp->as_u64[i] != r->match.as_u64[i])
52 RTT (mma_rule) *
RT (mma_rules_table_rule_alloc) (
RTT (mma_rules_table) * srt)
54 RTT (mma_rule) * rule;
61 RT (mma_rule_free) (
RTT (mma_rules_table) * srt,
RTT (mma_rule) * rule)
81 return (sr - srt->rules);
91 RTT (mma_mask_or_match) * key,
u32 rule_index)
98 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
103 for (i = 0; i <
vec_len (rp->next_indices); i++)
109 return (rp->action_index);
114 RTT (mma_mask_or_match) * key,
122 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
127 for (i = 0; i <
vec_len (rp->next_indices); i++)
140 int RT (mma_sort_indices) (
void *e1,
void *e2)
142 u32 *ri1 = e1, *ri2 = e2;
143 RTT (mma_rule) * rule1, *rule2;
144 rule1 =
RT (mma_rules_table_get_rule) (
RTT (sort_srt), *ri1);
145 rule2 =
RT (mma_rules_table_get_rule) (
RTT (sort_srt), *ri2);
146 return RTT (sort_srt)->rule_cmp_fn (rule1, rule2);
151 RTT (sort_srt) = srt;
157 RTT (mma_rule) * rule)
159 u32 parent_index,
i, *next_indices = 0, added = 0, rule_index;
160 RTT (mma_rule) * parent, *child;
165 parent =
RT (mma_rules_table_get_rule) (srt, parent_index);
168 parent->action_index = rule->action_index;
169 RT (mma_rule_free) (srt, rule);
173 if (
vec_len (parent->next_indices) == 0)
175 vec_add1 (parent->next_indices, rule_index);
180 for (i = 0; i <
vec_len (parent->next_indices); i++)
182 child =
RT (mma_rules_table_get_rule) (srt, parent->next_indices[
i]);
185 vec_add1 (rule->next_indices, parent->next_indices[i]);
188 vec_add1 (next_indices, rule_index);
194 if (!added && srt->rule_cmp_fn (rule, child) < 0)
196 vec_add1 (next_indices, rule_index);
199 vec_add1 (next_indices, parent->next_indices[i]);
203 vec_add1 (next_indices, rule_index);
205 parent->next_indices = next_indices;
211 RTT (mma_rule) * rule,
u32 rule_index)
218 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
224 if (rule_index == srt->root_index)
228 for (i = 0; i <
vec_len (rp->next_indices); i++)
233 RTT (mma_rule) * child;
234 u32 *next_indices = 0, *new_elts, left_to_add;
235 child =
RT (mma_rules_table_get_rule) (srt, rp->next_indices[
i]);
240 vec_add2 (next_indices, new_elts, i);
243 if (vec_len (child->next_indices))
244 vec_append (next_indices, child->next_indices);
245 left_to_add =
vec_len (rp->next_indices) - i - 1;
248 vec_add2 (next_indices, new_elts, left_to_add);
250 left_to_add * sizeof (
u32));
252 RT (mma_rule_free) (srt, child);
254 rp->next_indices = next_indices;
u32 RT() mma_rules_table_lookup(RTT(mma_rules_table)*srt, RTT(mma_mask_or_match)*key, u32 rule_index)
Lookup key in table.
void RT() mma_sort(RTT(mma_rules_table)*srt, u32 *next_indices)
u8 RT() rule_is_exact_match(RTT(mma_rule)*key, RTT(mma_rule)*r)
#define clib_memcpy_fast(a, b, c)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
for(i=1;i<=collision_buckets;i++)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
u32 RT() mma_rules_table_rule_index(RTT(mma_rules_table)*srt, RTT(mma_rule)*sr)
u32 RT() mma_rules_table_lookup_rule(RTT(mma_rules_table)*srt, RTT(mma_mask_or_match)*key, u32 rule_index)
#define pool_put(P, E)
Free an object E in pool P.
#define vec_free(V)
Free vector's memory (no header).
u8 RT() rule_is_match_for_key(RTT(mma_mask_or_match)*key, RTT(mma_rule)*r)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
int RT() mma_rules_table_add_rule(RTT(mma_rules_table)*srt, RTT(mma_rule)*rule)
#define vec_append(v1, v2)
Append v2 after v1.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
int RT() mma_rules_table_del_rule(RTT(mma_rules_table)*srt, RTT(mma_rule)*rule, u32 rule_index)
#define MMA_TABLE_INVALID_INDEX