mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Filter: Allow integers in operations on clists
The clists are internally implemented as integer lists. We currently allow pair values (communities in community list) and quad values (cluster ids in cluster lists) for add/del/member/filter operations on clists. Allow also generic integers, so it can be used as a generic integer list.
This commit is contained in:
parent
2f080b5432
commit
21003b8faa
@ -315,6 +315,10 @@ clist_set_type(const struct f_tree *set, struct f_val *v)
|
|||||||
|
|
||||||
switch (set->from.type)
|
switch (set->from.type)
|
||||||
{
|
{
|
||||||
|
case T_INT:
|
||||||
|
v->type = T_INT;
|
||||||
|
return 1;
|
||||||
|
|
||||||
case T_PAIR:
|
case T_PAIR:
|
||||||
v->type = T_PAIR;
|
v->type = T_PAIR;
|
||||||
return 1;
|
return 1;
|
||||||
@ -522,7 +526,7 @@ val_in_range(const struct f_val *v1, const struct f_val *v2)
|
|||||||
if ((v1->type == T_INT) && (v2->type == T_PATH))
|
if ((v1->type == T_INT) && (v2->type == T_PATH))
|
||||||
return as_path_contains(v2->val.ad, v1->val.i, 1);
|
return as_path_contains(v2->val.ad, v1->val.i, 1);
|
||||||
|
|
||||||
if (((v1->type == T_PAIR) || (v1->type == T_QUAD)) && (v2->type == T_CLIST))
|
if (((v1->type == T_INT) || (v1->type == T_PAIR) || (v1->type == T_QUAD)) && (v2->type == T_CLIST))
|
||||||
return int_set_contains(v2->val.ad, v1->val.i);
|
return int_set_contains(v2->val.ad, v1->val.i);
|
||||||
/* IP->Quad implicit conversion */
|
/* IP->Quad implicit conversion */
|
||||||
if (val_is_ip4(v1) && (v2->type == T_CLIST))
|
if (val_is_ip4(v1) && (v2->type == T_CLIST))
|
||||||
|
@ -1359,7 +1359,7 @@
|
|||||||
/* Community (or cluster) list */
|
/* Community (or cluster) list */
|
||||||
struct f_val dummy;
|
struct f_val dummy;
|
||||||
|
|
||||||
if ((v2.type == T_PAIR) || (v2.type == T_QUAD))
|
if ((v2.type == T_INT) || (v2.type == T_PAIR) || (v2.type == T_QUAD))
|
||||||
RESULT_(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, v2.val.i) ]]);
|
RESULT_(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, v2.val.i) ]]);
|
||||||
/* IP->Quad implicit conversion */
|
/* IP->Quad implicit conversion */
|
||||||
else if (val_is_ip4(&v2))
|
else if (val_is_ip4(&v2))
|
||||||
@ -1421,7 +1421,7 @@
|
|||||||
/* Community (or cluster) list */
|
/* Community (or cluster) list */
|
||||||
struct f_val dummy;
|
struct f_val dummy;
|
||||||
|
|
||||||
if ((v2.type == T_PAIR) || (v2.type == T_QUAD))
|
if ((v2.type == T_INT) || (v2.type == T_PAIR) || (v2.type == T_QUAD))
|
||||||
RESULT_(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, v2.val.i) ]]);
|
RESULT_(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, v2.val.i) ]]);
|
||||||
/* IP->Quad implicit conversion */
|
/* IP->Quad implicit conversion */
|
||||||
else if (val_is_ip4(&v2))
|
else if (val_is_ip4(&v2))
|
||||||
|
@ -867,6 +867,25 @@ clist r;
|
|||||||
l = delete(l, [(*,(onef(5)))]);
|
l = delete(l, [(*,(onef(5)))]);
|
||||||
bt_assert(l = -empty-);
|
bt_assert(l = -empty-);
|
||||||
|
|
||||||
|
# clist with integer values instead of community pairs
|
||||||
|
clist li = add(add(add(add(add(-empty-, 100), 200), 300), 400), 500);
|
||||||
|
bt_assert(format(li) = "(clist (0,100) (0,200) (0,300) (0,400) (0,500))");
|
||||||
|
|
||||||
|
# clist add/delete/test for integer values
|
||||||
|
li = delete(li, 500);
|
||||||
|
li = add(li, 12345678); # Same as (188,24910)
|
||||||
|
bt_assert(200 ~ li);
|
||||||
|
bt_assert(500 !~ li);
|
||||||
|
bt_assert(12345678 ~ li);
|
||||||
|
bt_assert(12345679 !~ li);
|
||||||
|
bt_assert(format(li) = "(clist (0,100) (0,200) (0,300) (0,400) (188,24910))");
|
||||||
|
|
||||||
|
# clist filtered through integer set
|
||||||
|
li = delete(li, [101..1000]);
|
||||||
|
bt_assert(100 ~ li);
|
||||||
|
bt_assert(200 !~ li);
|
||||||
|
bt_assert(format(li) = "(clist (0,100) (188,24910))");
|
||||||
|
|
||||||
l2 = add(l2, (3,6));
|
l2 = add(l2, (3,6));
|
||||||
l = filter(l2, [(3,1..4)]);
|
l = filter(l2, [(3,1..4)]);
|
||||||
l2 = filter(l2, [(3,3..6)]);
|
l2 = filter(l2, [(3,3..6)]);
|
||||||
|
Loading…
Reference in New Issue
Block a user