From ecc4e2c74cc8cbd21ff78c286b635c0fde01ca99 Mon Sep 17 00:00:00 2001 From: Oliver Herms <oliver.herms@exaring.de> Date: Thu, 18 Oct 2018 14:27:55 +0200 Subject: [PATCH] Current state --- routingtable/adjRIBIn/adj_rib_in.go | 14 +++- routingtable/adjRIBIn/adj_rib_in_test.go | 92 +++++++++++++++++++++++- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/routingtable/adjRIBIn/adj_rib_in.go b/routingtable/adjRIBIn/adj_rib_in.go index b7216313..e6dbe668 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 deec0010..566939e0 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]) } -- GitLab