diff --git a/routingtable/filter/term.go b/routingtable/filter/term.go index 2f8a47a92ee0f652e9cbde2971eb8e4128032ed1..0d546be8bc7ceaf07e12a85453ed5cce741ea3cd 100644 --- a/routingtable/filter/term.go +++ b/routingtable/filter/term.go @@ -11,12 +11,12 @@ type FilterAction interface { // Term matches a path against a list of conditions and performs actions if it matches type Term struct { - from []*From + from []*TermCondition then []FilterAction } // NewTerm creates a new term -func NewTerm(from []*From, then []FilterAction) *Term { +func NewTerm(from []*TermCondition, then []FilterAction) *Term { t := &Term{ from: from, then: then, diff --git a/routingtable/filter/from.go b/routingtable/filter/term_condition.go similarity index 64% rename from routingtable/filter/from.go rename to routingtable/filter/term_condition.go index 612122042cbaaa42f22ea756f7b38332b8e91b2b..92c3616a8cc55f21c73696b2f87a1b2a9cfbcbd4 100644 --- a/routingtable/filter/from.go +++ b/routingtable/filter/term_condition.go @@ -5,16 +5,16 @@ import ( "github.com/bio-routing/bio-rd/route" ) -type From struct { +type TermCondition struct { prefixLists []*PrefixList routeFilters []*RouteFilter } -func (f *From) Matches(p net.Prefix, pa *route.Path) bool { +func (f *TermCondition) Matches(p net.Prefix, pa *route.Path) bool { return f.matchesAnyPrefixList(p) || f.machtchesAnyRouteFilter(p) } -func (t *From) matchesAnyPrefixList(p net.Prefix) bool { +func (t *TermCondition) matchesAnyPrefixList(p net.Prefix) bool { for _, l := range t.prefixLists { if l.Matches(p) { return true @@ -24,7 +24,7 @@ func (t *From) matchesAnyPrefixList(p net.Prefix) bool { return false } -func (t *From) machtchesAnyRouteFilter(p net.Prefix) bool { +func (t *TermCondition) machtchesAnyRouteFilter(p net.Prefix) bool { for _, l := range t.routeFilters { if l.Matches(p) { return true diff --git a/routingtable/filter/from_test.go b/routingtable/filter/term_condition_test.go similarity index 99% rename from routingtable/filter/from_test.go rename to routingtable/filter/term_condition_test.go index acffa60a6e370502470f8449c3db80c732f9ad31..876746a240d195ee2a6612636a888a2cf41a9d25 100644 --- a/routingtable/filter/from_test.go +++ b/routingtable/filter/term_condition_test.go @@ -109,7 +109,7 @@ func TestMatches(t *testing.T) { for _, test := range tests { t.Run(test.name, func(te *testing.T) { - f := &From{ + f := &TermCondition{ prefixLists: test.prefixLists, routeFilters: test.routeFilters, } diff --git a/routingtable/filter/term_test.go b/routingtable/filter/term_test.go index 9720dbe3902d6edcb9c7eff2d04fdce7f83c6045..967480e76cdaa8a81f7594651b83fa8405fe02f9 100644 --- a/routingtable/filter/term_test.go +++ b/routingtable/filter/term_test.go @@ -24,7 +24,7 @@ func TestProcess(t *testing.T) { name string prefix net.Prefix path *route.Path - from []*From + from []*TermCondition then []FilterAction expectReject bool expectModified bool @@ -33,7 +33,7 @@ func TestProcess(t *testing.T) { name: "empty from", prefix: net.NewPfx(strAddr("100.64.0.1"), 8), path: &route.Path{}, - from: []*From{}, + from: []*TermCondition{}, then: []FilterAction{ &actions.AcceptAction{}, }, @@ -44,7 +44,7 @@ func TestProcess(t *testing.T) { name: "from matches", prefix: net.NewPfx(strAddr("100.64.0.1"), 8), path: &route.Path{}, - from: []*From{ + from: []*TermCondition{ { prefixLists: []*PrefixList{ NewPrefixList(net.NewPfx(strAddr("100.64.0.1"), 8)), @@ -61,7 +61,7 @@ func TestProcess(t *testing.T) { name: "from does not match", prefix: net.NewPfx(strAddr("100.64.0.1"), 8), path: &route.Path{}, - from: []*From{ + from: []*TermCondition{ { prefixLists: []*PrefixList{ NewPrefixList(net.NewPfx(0, 32)), @@ -78,7 +78,7 @@ func TestProcess(t *testing.T) { name: "modified", prefix: net.NewPfx(strAddr("100.64.0.1"), 8), path: &route.Path{}, - from: []*From{ + from: []*TermCondition{ { prefixLists: []*PrefixList{ NewPrefixList(net.NewPfx(strAddr("100.64.0.1"), 8)), @@ -95,7 +95,7 @@ func TestProcess(t *testing.T) { name: "modified and accepted (2 actions)", prefix: net.NewPfx(strAddr("100.64.0.1"), 8), path: &route.Path{}, - from: []*From{ + from: []*TermCondition{ { prefixLists: []*PrefixList{ NewPrefixList(net.NewPfx(strAddr("100.64.0.1"), 8)), @@ -113,7 +113,7 @@ func TestProcess(t *testing.T) { name: "one of the prefix filters matches", prefix: net.NewPfx(strAddr("100.64.0.1"), 8), path: &route.Path{}, - from: []*From{ + from: []*TermCondition{ { prefixLists: []*PrefixList{ NewPrefixListWithMatcher(Exact(), net.NewPfx(0, 32)),