Skip to content
Snippets Groups Projects
Commit b6b2fdcb authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

added local pref modification to filters

parent 9ab336b9
No related branches found
No related tags found
No related merge requests found
package actions
import (
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable/filter"
)
type setLocalPrefAction struct {
pref uint32
}
func NewSetLocalPrefAction(pref uint32) filter.FilterAction {
return &setLocalPrefAction{
pref: pref,
}
}
func (a *setLocalPrefAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) {
if pa.BGPPath == nil {
return pa, false
}
modified := *pa
modified.BGPPath.LocalPref = a.pref
return &modified, false
}
package actions
import (
"testing"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/stretchr/testify/assert"
)
func TestSetLocalPref(t *testing.T) {
tests := []struct {
name string
bgpPath *route.BGPPath
expectedLocalPref uint32
}{
{
name: "BGPPath is nil",
expectedLocalPref: 0,
},
{
name: "modify path",
bgpPath: &route.BGPPath{
LocalPref: 100,
},
expectedLocalPref: 150,
},
}
for _, test := range tests {
t.Run(test.name, func(te *testing.T) {
a := NewSetLocalPrefAction(150)
p, _ := a.Do(net.NewPfx(strAddr("10.0.0.0"), 8), &route.Path{
BGPPath: test.bgpPath,
})
if test.expectedLocalPref > 0 {
assert.Equal(te, test.expectedLocalPref, p.BGPPath.LocalPref)
}
})
}
}
func strAddr(s string) uint32 {
ret, _ := net.StrToAddr(s)
return ret
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment