Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
44eb4d8c
Commit
44eb4d8c
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Patches
Plain Diff
added community filter matching, fixed term condition with more than one group of conditions
parent
ec368617
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
routingtable/filter/term_condition.go
+24
-8
24 additions, 8 deletions
routingtable/filter/term_condition.go
routingtable/filter/term_condition_test.go
+38
-19
38 additions, 19 deletions
routingtable/filter/term_condition_test.go
with
62 additions
and
27 deletions
routingtable/filter/term_condition.go
+
24
−
8
View file @
44eb4d8c
...
@@ -20,13 +20,17 @@ func NewTermCondition(prefixLists []*PrefixList, routeFilters []*RouteFilter) *T
...
@@ -20,13 +20,17 @@ func NewTermCondition(prefixLists []*PrefixList, routeFilters []*RouteFilter) *T
}
}
func
(
f
*
TermCondition
)
Matches
(
p
net
.
Prefix
,
pa
*
route
.
Path
)
bool
{
func
(
f
*
TermCondition
)
Matches
(
p
net
.
Prefix
,
pa
*
route
.
Path
)
bool
{
return
f
.
matches
Any
PrefixList
(
p
)
||
return
f
.
matchesPrefixList
Filters
(
p
)
&&
f
.
machtches
Any
RouteFilter
(
p
)
||
f
.
machtchesRouteFilter
s
(
p
)
&&
f
.
machtches
AnyLage
CommunityFilter
(
pa
)
||
f
.
machtchesCommunityFilter
s
(
pa
)
&&
f
.
machtches
Any
CommunityFilter
(
pa
)
f
.
machtches
Lage
CommunityFilter
s
(
pa
)
}
}
func
(
t
*
TermCondition
)
matchesAnyPrefixList
(
p
net
.
Prefix
)
bool
{
func
(
t
*
TermCondition
)
matchesPrefixListFilters
(
p
net
.
Prefix
)
bool
{
if
len
(
t
.
prefixLists
)
==
0
{
return
true
}
for
_
,
l
:=
range
t
.
prefixLists
{
for
_
,
l
:=
range
t
.
prefixLists
{
if
l
.
Matches
(
p
)
{
if
l
.
Matches
(
p
)
{
return
true
return
true
...
@@ -36,7 +40,11 @@ func (t *TermCondition) matchesAnyPrefixList(p net.Prefix) bool {
...
@@ -36,7 +40,11 @@ func (t *TermCondition) matchesAnyPrefixList(p net.Prefix) bool {
return
false
return
false
}
}
func
(
t
*
TermCondition
)
machtchesAnyRouteFilter
(
p
net
.
Prefix
)
bool
{
func
(
t
*
TermCondition
)
machtchesRouteFilters
(
p
net
.
Prefix
)
bool
{
if
len
(
t
.
routeFilters
)
==
0
{
return
true
}
for
_
,
l
:=
range
t
.
routeFilters
{
for
_
,
l
:=
range
t
.
routeFilters
{
if
l
.
Matches
(
p
)
{
if
l
.
Matches
(
p
)
{
return
true
return
true
...
@@ -46,7 +54,11 @@ func (t *TermCondition) machtchesAnyRouteFilter(p net.Prefix) bool {
...
@@ -46,7 +54,11 @@ func (t *TermCondition) machtchesAnyRouteFilter(p net.Prefix) bool {
return
false
return
false
}
}
func
(
t
*
TermCondition
)
machtchesAnyCommunityFilter
(
pa
*
route
.
Path
)
bool
{
func
(
t
*
TermCondition
)
machtchesCommunityFilters
(
pa
*
route
.
Path
)
bool
{
if
len
(
t
.
communityFilters
)
==
0
{
return
true
}
if
pa
.
BGPPath
==
nil
{
if
pa
.
BGPPath
==
nil
{
return
false
return
false
}
}
...
@@ -60,7 +72,11 @@ func (t *TermCondition) machtchesAnyCommunityFilter(pa *route.Path) bool {
...
@@ -60,7 +72,11 @@ func (t *TermCondition) machtchesAnyCommunityFilter(pa *route.Path) bool {
return
false
return
false
}
}
func
(
t
*
TermCondition
)
machtchesAnyLageCommunityFilter
(
pa
*
route
.
Path
)
bool
{
func
(
t
*
TermCondition
)
machtchesLageCommunityFilters
(
pa
*
route
.
Path
)
bool
{
if
len
(
t
.
largeCommunityFilters
)
==
0
{
return
true
}
if
pa
.
BGPPath
==
nil
{
if
pa
.
BGPPath
==
nil
{
return
false
return
false
}
}
...
...
This diff is collapsed.
Click to expand it.
routingtable/filter/term_condition_test.go
+
38
−
19
View file @
44eb4d8c
...
@@ -26,8 +26,7 @@ func TestMatches(t *testing.T) {
...
@@ -26,8 +26,7 @@ func TestMatches(t *testing.T) {
prefixLists
:
[]
*
PrefixList
{
prefixLists
:
[]
*
PrefixList
{
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"127.0.0.1"
),
8
)),
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"127.0.0.1"
),
8
)),
},
},
routeFilters
:
[]
*
RouteFilter
{},
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"one prefix in prefix list and no match, no route filters set"
,
name
:
"one prefix in prefix list and no match, no route filters set"
,
...
@@ -35,8 +34,7 @@ func TestMatches(t *testing.T) {
...
@@ -35,8 +34,7 @@ func TestMatches(t *testing.T) {
prefixLists
:
[]
*
PrefixList
{
prefixLists
:
[]
*
PrefixList
{
NewPrefixList
(
net
.
NewPfx
(
0
,
32
)),
NewPrefixList
(
net
.
NewPfx
(
0
,
32
)),
},
},
routeFilters
:
[]
*
RouteFilter
{},
expected
:
false
,
expected
:
false
,
},
},
{
{
name
:
"one prefix of 2 matches in prefix list, no route filters set"
,
name
:
"one prefix of 2 matches in prefix list, no route filters set"
,
...
@@ -45,22 +43,19 @@ func TestMatches(t *testing.T) {
...
@@ -45,22 +43,19 @@ func TestMatches(t *testing.T) {
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
)),
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
)),
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"127.0.0.1"
),
8
)),
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"127.0.0.1"
),
8
)),
},
},
routeFilters
:
[]
*
RouteFilter
{},
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"no prefixes in prefix list, only route filter matches"
,
name
:
"no prefixes in prefix list, only route filter matches"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefixLists
:
[]
*
PrefixList
{},
routeFilters
:
[]
*
RouteFilter
{
routeFilters
:
[]
*
RouteFilter
{
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
},
},
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"no prefixes in prefix list, one route filter matches"
,
name
:
"no prefixes in prefix list, one route filter matches"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefixLists
:
[]
*
PrefixList
{},
routeFilters
:
[]
*
RouteFilter
{
routeFilters
:
[]
*
RouteFilter
{
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"8.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"8.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
...
@@ -68,9 +63,8 @@ func TestMatches(t *testing.T) {
...
@@ -68,9 +63,8 @@ func TestMatches(t *testing.T) {
expected
:
true
,
expected
:
true
,
},
},
{
{
name
:
"no prefixes in prefix list, one of many route filters matches"
,
name
:
"no prefixes in prefix list, one of many route filters matches"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"127.0.0.1"
),
8
),
prefix
:
net
.
NewPfx
(
strAddr
(
"127.0.0.1"
),
8
),
prefixLists
:
[]
*
PrefixList
{},
routeFilters
:
[]
*
RouteFilter
{
routeFilters
:
[]
*
RouteFilter
{
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
},
},
...
@@ -88,7 +82,7 @@ func TestMatches(t *testing.T) {
...
@@ -88,7 +82,7 @@ func TestMatches(t *testing.T) {
expected
:
false
,
expected
:
false
,
},
},
{
{
name
:
"one prefix in prefixlist, one route fi
t
ler, only prefix list matches"
,
name
:
"one prefix in prefixlist, one route fil
t
er, only prefix list matches"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"8.8.8.0"
),
24
),
prefix
:
net
.
NewPfx
(
strAddr
(
"8.8.8.0"
),
24
),
prefixLists
:
[]
*
PrefixList
{
prefixLists
:
[]
*
PrefixList
{
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"8.0.0.0"
),
8
)),
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"8.0.0.0"
),
8
)),
...
@@ -96,10 +90,10 @@ func TestMatches(t *testing.T) {
...
@@ -96,10 +90,10 @@ func TestMatches(t *testing.T) {
routeFilters
:
[]
*
RouteFilter
{
routeFilters
:
[]
*
RouteFilter
{
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
},
},
expected
:
tru
e
,
expected
:
fals
e
,
},
},
{
{
name
:
"one prefix in prefixlist, one route fi
t
ler, only route filter matches"
,
name
:
"one prefix in prefixlist, one route fil
t
er, only route filter matches"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefixLists
:
[]
*
PrefixList
{
prefixLists
:
[]
*
PrefixList
{
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"8.0.0.0"
),
8
)),
NewPrefixList
(
net
.
NewPfx
(
strAddr
(
"8.0.0.0"
),
8
)),
...
@@ -107,7 +101,7 @@ func TestMatches(t *testing.T) {
...
@@ -107,7 +101,7 @@ func TestMatches(t *testing.T) {
routeFilters
:
[]
*
RouteFilter
{
routeFilters
:
[]
*
RouteFilter
{
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
NewRouteFilter
(
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
8
),
Longer
()),
},
},
expected
:
tru
e
,
expected
:
fals
e
,
},
},
{
{
name
:
"community matches"
,
name
:
"community matches"
,
...
@@ -123,6 +117,17 @@ func TestMatches(t *testing.T) {
...
@@ -123,6 +117,17 @@ func TestMatches(t *testing.T) {
{
{
name
:
"community does not match"
,
name
:
"community does not match"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
bgpPath
:
&
route
.
BGPPath
{
Communities
:
"(1,2) (3,4) (5,6)"
,
},
communityFilters
:
[]
*
CommunityFilter
{
&
CommunityFilter
{
196608
},
// (3,0)
},
expected
:
false
,
},
{
name
:
"community filter, bgp path is nil"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
communityFilters
:
[]
*
CommunityFilter
{
communityFilters
:
[]
*
CommunityFilter
{
&
CommunityFilter
{
196608
},
// (3,0)
&
CommunityFilter
{
196608
},
// (3,0)
},
},
...
@@ -160,6 +165,20 @@ func TestMatches(t *testing.T) {
...
@@ -160,6 +165,20 @@ func TestMatches(t *testing.T) {
},
},
expected
:
false
,
expected
:
false
,
},
},
{
name
:
"large community filter, bgp path is nil"
,
prefix
:
net
.
NewPfx
(
strAddr
(
"10.0.0.0"
),
24
),
largeCommunityFilters
:
[]
*
LargeCommunityFilter
{
{
&
packet
.
LargeCommunity
{
GlobalAdministrator
:
1
,
DataPart1
:
2
,
DataPart2
:
3
,
},
},
},
expected
:
false
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment