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

added actions to manipulate next-hop and local-pref

parent b6b2fdcb
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,7 @@ func TestSetLocalPref(t *testing.T) {
expectedLocalPref uint32
}{
{
name: "BGPPath is nil",
expectedLocalPref: 0,
name: "BGPPath is nil",
},
{
name: "modify path",
......
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 setNextHopAction struct {
addr uint32
}
func NewSetNextHopAction(addr uint32) filter.FilterAction {
return &setNextHopAction{
addr: addr,
}
}
func (a *setNextHopAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) {
if pa.BGPPath == nil {
return pa, false
}
modified := *pa
modified.BGPPath.NextHop = a.addr
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 TestSetNextHopTest(t *testing.T) {
tests := []struct {
name string
bgpPath *route.BGPPath
expected uint32
}{
{
name: "BGPPath is nil",
},
{
name: "modify path",
bgpPath: &route.BGPPath{
NextHop: strAddr("100.64.2.1"),
},
expected: strAddr("100.64.2.1"),
},
}
for _, test := range tests {
t.Run(test.name, func(te *testing.T) {
a := NewSetNextHopAction(strAddr("100.64.2.1"))
p, _ := a.Do(net.NewPfx(strAddr("10.0.0.0"), 8), &route.Path{
BGPPath: test.bgpPath,
})
if test.expected > 0 {
assert.Equal(te, test.expected, p.BGPPath.NextHop)
}
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment