Skip to content
Snippets Groups Projects
Commit 1e4407d2 authored by Maximilian Wilhelm's avatar Maximilian Wilhelm
Browse files

Add tests for AdjRIBOut / iBGP RR client scenario.

parent f08419ab
No related branches found
No related tags found
No related merge requests found
...@@ -498,7 +498,7 @@ func TestBestPathOnlyIBGP(t *testing.T) { ...@@ -498,7 +498,7 @@ func TestBestPathOnlyIBGP(t *testing.T) {
expected: []*route.Route{}, expected: []*route.Route{},
}, },
{ {
name: "Try to add route with NO_EXPORT community set (without success)", name: "Try to add route with NO_ADVERTISE community set (without success)",
routesAdd: []*route.Route{ routesAdd: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{ route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType, Type: route.BGPPathType,
...@@ -532,6 +532,271 @@ func TestBestPathOnlyIBGP(t *testing.T) { ...@@ -532,6 +532,271 @@ func TestBestPathOnlyIBGP(t *testing.T) {
} }
} }
/*
* Test for iBGP Route Reflector client neighbor
*/
func TestBestPathOnlyRRClient(t *testing.T) {
neighborBestOnlyRR := &routingtable.Neighbor{
Type: route.BGPPathType,
LocalAddress: net.IPv4FromOctets(127, 0, 0, 1),
Address: net.IPv4FromOctets(127, 0, 0, 2),
IBGP: true,
LocalASN: 41981,
RouteServerClient: false,
CapAddPathRX: false,
RouteReflectorClient: true,
ClusterID: net.IPv4FromOctets(2, 2, 2, 2).ToUint32(),
}
adjRIBOut := New(neighborBestOnlyRR, filter.NewAcceptAllFilter())
tests := []struct {
name string
routesAdd []*route.Route
routesRemove []*route.Route
expected []*route.Route
expectedCount int64
}{
{
name: "Add an iBGP route (with success)",
routesAdd: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{},
}),
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
Communities: []uint32{},
LargeCommunities: []types.LargeCommunity{},
ASPath: types.ASPath{},
ClusterList: []uint32{
neighborBestOnlyRR.ClusterID,
},
},
}),
},
expectedCount: 1,
},
{
name: "Add an eBGP route (replacing previous iBGP route)",
routesAdd: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
EBGP: true,
ASPath: types.ASPath{
types.ASPathSegment{
Type: types.ASSequence,
ASNs: []uint32{
201701,
},
},
},
ASPathLen: 1,
NextHop: net.IPv4FromOctets(1, 2, 3, 4),
},
}),
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
NextHop: net.IPv4FromOctets(1, 2, 3, 4),
ASPath: types.ASPath{
types.ASPathSegment{
Type: types.ASSequence,
ASNs: []uint32{
201701,
},
},
},
ASPathLen: 1,
Origin: 0,
MED: 0,
EBGP: true,
Communities: []uint32{},
LargeCommunities: []types.LargeCommunity{},
UnknownAttributes: nil,
PathIdentifier: 0,
LocalPref: 0,
Source: net.IP{},
ClusterList: []uint32{
neighborBestOnlyRR.ClusterID,
},
},
}),
},
expectedCount: 1,
},
{
name: "Try to remove slightly different route",
routesRemove: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
NextHop: net.IPv4FromOctets(1, 2, 3, 4),
ASPath: types.ASPath{
types.ASPathSegment{
Type: types.ASSequence,
ASNs: []uint32{
201701,
},
},
},
ASPathLen: 1,
Origin: 0,
MED: 1, // Existing route has MED 0
EBGP: true,
Communities: []uint32{},
LargeCommunities: []types.LargeCommunity{},
UnknownAttributes: nil,
PathIdentifier: 0,
LocalPref: 0,
Source: net.IP{}},
}),
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
NextHop: net.IPv4FromOctets(1, 2, 3, 4),
ASPath: types.ASPath{
types.ASPathSegment{
Type: types.ASSequence,
ASNs: []uint32{
201701,
},
},
},
ASPathLen: 1,
Origin: 0,
MED: 0,
EBGP: true,
Communities: []uint32{},
LargeCommunities: []types.LargeCommunity{},
UnknownAttributes: nil,
PathIdentifier: 0,
LocalPref: 0,
Source: net.IP{},
ClusterList: []uint32{
neighborBestOnlyRR.ClusterID,
},
},
}),
},
expectedCount: 1,
},
{
name: "Remove route added in 2nd step",
routesRemove: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
NextHop: net.IPv4FromOctets(1, 2, 3, 4),
ASPath: types.ASPath{
types.ASPathSegment{
Type: types.ASSequence,
ASNs: []uint32{
201701,
},
},
},
ASPathLen: 1,
Origin: 0,
MED: 0,
EBGP: true,
Communities: []uint32{},
LargeCommunities: []types.LargeCommunity{},
UnknownAttributes: nil,
PathIdentifier: 0,
LocalPref: 0,
Source: net.IP{},
ClusterList: []uint32{
neighborBestOnlyRR.ClusterID,
},
},
}),
},
expected: []*route.Route{},
expectedCount: 0,
},
{
name: "Try to add route with NO_ADVERTISE community set (without success)",
routesAdd: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
Communities: []uint32{
types.WellKnownCommunityNoAdvertise,
},
},
}),
},
expected: []*route.Route{},
expectedCount: 0,
},
{
name: "Try to add route with NO_EXPORT community set (with success)",
routesAdd: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
Communities: []uint32{
types.WellKnownCommunityNoExport,
},
},
}),
},
expected: []*route.Route{
route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
ASPath: types.ASPath{},
ASPathLen: 0,
Origin: 0,
MED: 0,
EBGP: false,
Communities: []uint32{
types.WellKnownCommunityNoExport,
},
LargeCommunities: []types.LargeCommunity{},
UnknownAttributes: nil,
PathIdentifier: 0,
LocalPref: 0,
Source: net.IP{},
ClusterList: []uint32{
neighborBestOnlyRR.ClusterID,
},
},
}),
},
expectedCount: 1,
},
}
for i, test := range tests {
fmt.Printf("Running RR client best only test #%d: %s\n", i+1, test.name)
for _, route := range test.routesAdd {
adjRIBOut.AddPath(route.Prefix(), route.Paths()[0])
}
for _, route := range test.routesRemove {
adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0])
}
assert.Equal(t, test.expected, adjRIBOut.rt.Dump())
actualCount := adjRIBOut.RouteCount()
if test.expectedCount != actualCount {
t.Errorf("Expected route count %d differs from actual route count %d!\n", test.expectedCount, actualCount)
}
}
}
/* /*
* Test for AddPath capabale peer / AdjRIBOut * Test for AddPath capabale peer / AdjRIBOut
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment