Newer
Older
package adjRIBIn
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter"
Maximilian Wilhelm
committed
routerID := net.IPv4FromOctets(1, 1, 1, 1).ToUint32()
clusterID := net.IPv4FromOctets(2, 2, 2, 2).ToUint32()
routes []*route.Route
removePfx net.Prefix
removePath *route.Path
expected []*route.Route
}{
{
name: "Add route",
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 100,
},
}),
},
removePath: nil,
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 100,
},
}),
},
},
{
name: "Overwrite routes",
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 100,
},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 200,
},
}),
},
removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8),
removePath: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 100,
},
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 200,
},
}),
},
},
Maximilian Wilhelm
committed
{
name: "Add route with our RouterID as OriginatorID",
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 111,
Maximilian Wilhelm
committed
},
}),
},
expected: []*route.Route{},
},
{
name: "Add route with our ClusterID within ClusterList",
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 32), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 222,
OriginatorID: 23,
ClusterList: []uint32{
clusterID,
},
},
}),
},
expected: []*route.Route{},
},
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
name: "Add route (with BGP add path)",
addPath: true,
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 100,
},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 200,
},
}),
},
removePfx: net.Prefix{},
removePath: nil,
expected: []*route.Route{
route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{
{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 100,
},
},
{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
LocalPref: 200,
},
},
}),
},
},
adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs(), routerID, clusterID, test.addPath)
mc := routingtable.NewRTMockClient()
adjRIBIn.ClientManager.Register(mc)
for _, route := range test.routes {
adjRIBIn.AddPath(route.Prefix(), route.Paths()[0])
}
Maximilian Wilhelm
committed
if test.removePath != nil {
removePathParams := mc.GetRemovePathParams()
if removePathParams.Pfx != test.removePfx {
t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, removePathParams.Pfx.String(), test.removePfx.String())
}
Maximilian Wilhelm
committed
assert.Equal(t, test.removePath, removePathParams.Path)
}
assert.Equal(t, test.expected, adjRIBIn.rt.Dump())
}
}
func TestRemovePath(t *testing.T) {
tests := []struct {
name string
routes []*route.Route
removePfx net.Prefix
removePath *route.Path
expected []*route.Route
wantPropagation bool
}{
{
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: "Remove an a path from existing route",
addPath: true,
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 100,
},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 200,
},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 300,
},
}),
},
removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8),
removePath: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 200,
},
},
expected: []*route.Route{
route.NewRouteAddPath(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), []*route.Path{
{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 100,
},
},
{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
PathIdentifier: 300,
},
},
}),
},
wantPropagation: true,
},
/*{
name: "Remove an existing route",
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
},
removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8),
removePath: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
},
wantPropagation: true,
},
{
name: "Remove non existing route",
routes: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
},
removePfx: net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8),
removePath: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
},
wantPropagation: false,
adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs(), 1, 2, test.addPath)
for _, route := range test.routes {
adjRIBIn.AddPath(route.Prefix(), route.Paths()[0])
}
mc := routingtable.NewRTMockClient()
adjRIBIn.ClientManager.Register(mc)
adjRIBIn.RemovePath(test.removePfx, test.removePath)
if test.wantPropagation {
removePathParams := mc.GetRemovePathParams()
if removePathParams.Pfx != test.removePfx {
t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, removePathParams.Pfx.String(), test.removePfx.String())
assert.Equal(t, test.removePath, removePathParams.Path)
removePathParams := mc.GetRemovePathParams()
uninitialized := net.Prefix{}
if removePathParams.Pfx != uninitialized {
t.Errorf("Test %q failed: Call to RemovePath propagated unexpectedly", test.name)
}
}
assert.Equal(t, test.expected, adjRIBIn.rt.Dump())
}
}