diff --git a/routingtable/adjRIBIn/adj_rib_in.go b/routingtable/adjRIBIn/adj_rib_in.go index b7216313fb31d2d37d67d0a1dd4ac79a618e3e24..e6dbe668c03faec1aee6f33ff7ba20deb076ae9f 100644 --- a/routingtable/adjRIBIn/adj_rib_in.go +++ b/routingtable/adjRIBIn/adj_rib_in.go @@ -1,6 +1,7 @@ package adjRIBIn import ( + "fmt" "sync" "github.com/bio-routing/bio-rd/routingtable/filter" @@ -129,12 +130,23 @@ func (a *AdjRIBIn) RemovePath(pfx net.Prefix, p *route.Path) bool { return false } + removed := make([]*route.Path, 0) oldPaths := r.Paths() for _, path := range oldPaths { + if a.addPathRX { + fmt.Printf("Add Path RX!\n") + if path.BGPPath.PathIdentifier != p.BGPPath.PathIdentifier { + fmt.Printf("Path ID %v != %v. Ignoring.\n", path.BGPPath.PathIdentifier, p.BGPPath.PathIdentifier) + continue + } + } + + fmt.Printf("Removing: %v => %v\n", pfx, *path.BGPPath) a.rt.RemovePath(pfx, path) + removed = append(removed, path) } - a.removePathsFromClients(pfx, oldPaths) + a.removePathsFromClients(pfx, removed) return true } diff --git a/routingtable/adjRIBIn/adj_rib_in_test.go b/routingtable/adjRIBIn/adj_rib_in_test.go index deec00104931a80f128be6782df70e35407775ae..566939e0fac7950c367139c85d1e8345563c9b48 100644 --- a/routingtable/adjRIBIn/adj_rib_in_test.go +++ b/routingtable/adjRIBIn/adj_rib_in_test.go @@ -17,6 +17,7 @@ func TestAddPath(t *testing.T) { tests := []struct { name string + addPath bool routes []*route.Route removePfx net.Prefix removePath *route.Path @@ -104,10 +105,46 @@ func TestAddPath(t *testing.T) { }, expected: []*route.Route{}, }, + { + 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, + }, + }, + }), + }, + }, } for _, test := range tests { - adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs(), routerID, clusterID) + adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs(), routerID, clusterID, test.addPath) mc := routingtable.NewRTMockClient() adjRIBIn.ClientManager.Register(mc) @@ -130,6 +167,7 @@ func TestAddPath(t *testing.T) { func TestRemovePath(t *testing.T) { tests := []struct { name string + addPath bool routes []*route.Route removePfx net.Prefix removePath *route.Path @@ -137,6 +175,54 @@ func TestRemovePath(t *testing.T) { wantPropagation bool }{ { + 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{ @@ -197,11 +283,11 @@ func TestRemovePath(t *testing.T) { }), }, wantPropagation: false, - }, + },*/ } for _, test := range tests { - adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs(), 1, 2) + adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs(), 1, 2, test.addPath) for _, route := range test.routes { adjRIBIn.AddPath(route.Prefix(), route.Paths()[0]) }