Skip to content

Commit

Permalink
Move contributing ASNs into VRF
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
  • Loading branch information
BarbarossaTM committed Nov 26, 2022
1 parent 15324ad commit 0f2a126
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 225 deletions.
9 changes: 6 additions & 3 deletions protocols/bgp/server/bgp_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/bio-routing/bio-rd/routingtable/adjRIBIn"
"github.com/bio-routing/bio-rd/routingtable/adjRIBOut"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/test/bufconn"
Expand All @@ -30,6 +31,8 @@ func TestDumpRIBInOut(t *testing.T) {
AddPathTX: true,
}

vrf, _ := vrf.New("vrf0", 0)

tests := []struct {
name string
apisrv *BGPAPIServer
Expand Down Expand Up @@ -66,7 +69,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, sessionAttrs),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), vrf, sessionAttrs),
adjRIBOut: adjRIBOut.New(nil, routingtable.SessionAttrs{Type: route.BGPPathType}, filter.NewAcceptAllFilterChain()),
},
},
Expand Down Expand Up @@ -96,7 +99,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, sessionAttrs),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), vrf, sessionAttrs),
adjRIBOut: adjRIBOut.New(nil, routingtable.SessionAttrs{Type: route.BGPPathType, RouteServerClient: true, PeerIP: bnet.IPv4(0).Ptr()}, filter.NewAcceptAllFilterChain()),
},
},
Expand Down Expand Up @@ -156,7 +159,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), sessionAttrs),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), vrf, sessionAttrs),
adjRIBOut: adjRIBOut.New(nil, routingtable.SessionAttrs{Type: route.BGPPathType, RouteServerClient: true, PeerIP: bnet.IPv4(123).Ptr()}, filter.NewAcceptAllFilterChain()),
},
},
Expand Down
20 changes: 11 additions & 9 deletions protocols/bgp/server/fsm_address_family.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/bio-routing/bio-rd/routingtable/adjRIBOut"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/bio-rd/routingtable/vrf"
)

// fsmAddressFamily holds RIBs and the UpdateSender of an peer for an AFI/SAFI combination
Expand All @@ -24,6 +25,7 @@ type fsmAddressFamily struct {
adjRIBIn routingtable.AdjRIBIn
adjRIBOut routingtable.AdjRIBOut
rib *locRIB.LocRIB
vrf *vrf.VRF

importFilterChain filter.Chain
exportFilterChain filter.Chain
Expand All @@ -44,6 +46,7 @@ func newFSMAddressFamily(afi uint16, safi uint8, family *peerAddressFamily, fsm
afi: afi,
safi: safi,
fsm: fsm,
vrf: fsm.peer.vrf,
rib: family.rib,
importFilterChain: family.importFilterChain,
exportFilterChain: family.exportFilterChain,
Expand Down Expand Up @@ -80,21 +83,20 @@ func (f *fsmAddressFamily) dumpRIBIn() []*route.Route {
}

type adjRIBInFactoryI interface {
New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, sessionAttrs routingtable.SessionAttrs) routingtable.AdjRIBIn
New(exportFilterChain filter.Chain, vrf *vrf.VRF, sessionAttrs routingtable.SessionAttrs) routingtable.AdjRIBIn
}

type adjRIBInFactory struct{}

func (a adjRIBInFactory) New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, sessionAttrs routingtable.SessionAttrs) routingtable.AdjRIBIn {
return adjRIBIn.New(exportFilterChain, contributingASNs, sessionAttrs)
func (a adjRIBInFactory) New(exportFilterChain filter.Chain, vrf *vrf.VRF, sessionAttrs routingtable.SessionAttrs) routingtable.AdjRIBIn {
return adjRIBIn.New(exportFilterChain, vrf, sessionAttrs)
}

func (f *fsmAddressFamily) init() {
contributingASNs := f.rib.GetContributingASNs()
sessionAttrs := f.getSessionAttrs()

f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(f.importFilterChain, contributingASNs, sessionAttrs)
contributingASNs.Add(f.fsm.peer.localASN)
f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(f.importFilterChain, f.vrf, sessionAttrs)
f.vrf.AddContributingASN(f.fsm.peer.localASN)

f.adjRIBIn.Register(f.rib)

Expand Down Expand Up @@ -138,7 +140,7 @@ func (f *fsmAddressFamily) getSessionAttrs() routingtable.SessionAttrs {
}

func (f *fsmAddressFamily) bmpInit() {
f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(filter.NewAcceptAllFilterChain(), &routingtable.ContributingASNs{}, f.getSessionAttrs())
f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(filter.NewAcceptAllFilterChain(), f.fsm.peer.vrf, f.getSessionAttrs())

if f.rib != nil {
f.adjRIBIn.Register(f.rib)
Expand All @@ -148,7 +150,7 @@ func (f *fsmAddressFamily) bmpInit() {
}

func (f *fsmAddressFamily) bmpDispose() {
f.rib.GetContributingASNs().Remove(f.fsm.peer.localASN)
f.vrf.RemoveContributingASN(f.fsm.peer.localASN)

f.adjRIBIn.Flush()

Expand All @@ -162,7 +164,7 @@ func (f *fsmAddressFamily) dispose() {
return
}

f.rib.GetContributingASNs().Remove(f.fsm.peer.localASN)
f.vrf.RemoveContributingASN(f.fsm.peer.localASN)
f.adjRIBIn.Unregister(f.rib)
f.rib.Unregister(f.adjRIBOut)
f.adjRIBOut.Unregister(f.updateSender)
Expand Down
8 changes: 5 additions & 3 deletions protocols/bgp/server/fsm_address_family_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/stretchr/testify/assert"

biotesting "github.com/bio-routing/bio-rd/testing"
Expand All @@ -20,6 +21,7 @@ func TestFSMAFIInitDispose(t *testing.T) {
afi: packet.AFIIPv4,
safi: packet.SAFIUnicast,
rib: locRIB.New("inet.0"),
vrf: vrf.NewUntrackedVRF("vrf0", 0),
importFilterChain: filter.NewAcceptAllFilterChain(),
exportFilterChain: filter.NewAcceptAllFilterChain(),
fsm: &FSM{
Expand All @@ -41,8 +43,8 @@ func TestFSMAFIInitDispose(t *testing.T) {

f.init()
assert.NotEqual(t, nil, f.adjRIBIn)
assert.Equal(t, true, f.rib.GetContributingASNs().IsContributingASN(15169))
assert.NotEqual(t, true, f.rib.GetContributingASNs().IsContributingASN(15170))
assert.Equal(t, true, f.vrf.IsContributingASN(15169))
assert.NotEqual(t, true, f.vrf.IsContributingASN(15170))

assert.NotEqual(t, nil, f.adjRIBOut)
assert.NotEqual(t, nil, f.updateSender)
Expand All @@ -57,7 +59,7 @@ func TestFSMAFIInitDispose(t *testing.T) {
f.dispose()

f.updateSender.wg.Wait()
assert.Equal(t, false, f.rib.GetContributingASNs().IsContributingASN(15169))
assert.Equal(t, false, f.vrf.IsContributingASN(15169))
assert.Equal(t, uint64(0), f.rib.ClientCount())
assert.Equal(t, nil, f.adjRIBOut)
assert.Equal(t, false, f.initialized)
Expand Down
3 changes: 3 additions & 0 deletions protocols/bgp/server/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/stretchr/testify/assert"
)

Expand All @@ -23,6 +24,7 @@ func TestFSM255UpdatesIPv4(t *testing.T) {
exportFilterChain: filter.NewAcceptAllFilterChain(),
},
adjRIBInFactory: adjRIBInFactory{},
vrf: vrf.NewUntrackedVRF("vrf0", 0),
})

fsmA.holdTime = time.Second * 180
Expand Down Expand Up @@ -142,6 +144,7 @@ func TestFSM255UpdatesIPv6(t *testing.T) {
exportFilterChain: filter.NewAcceptAllFilterChain(),
},
adjRIBInFactory: adjRIBInFactory{},
vrf: vrf.NewUntrackedVRF("vrf0", 0),
})

fsmA.ipv6Unicast.multiProtocol = true
Expand Down
4 changes: 2 additions & 2 deletions protocols/bgp/server/metrics_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
"testing"
"time"

"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/stretchr/testify/assert"

bnet "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/metrics"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
)

func TestMetrics(t *testing.T) {
vrf, _ := vrf.New("inet.0", 0)
vrf := vrf.NewUntrackedVRF("inet.0", 0)
establishedTime := time.Now()

tests := []struct {
Expand Down
9 changes: 5 additions & 4 deletions routingtable/adjRIBIn/adj_rib_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/bio-routing/bio-rd/util/log"
)

Expand All @@ -17,16 +18,16 @@ type AdjRIBIn struct {
rt *routingtable.RoutingTable
mu sync.RWMutex
exportFilterChain filter.Chain
contributingASNs *routingtable.ContributingASNs
vrf *vrf.VRF
sessionAttrs routingtable.SessionAttrs
}

// New creates a new Adjacency RIB In
func New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, sessionAttrs routingtable.SessionAttrs) *AdjRIBIn {
func New(exportFilterChain filter.Chain, vrf *vrf.VRF, sessionAttrs routingtable.SessionAttrs) *AdjRIBIn {
a := &AdjRIBIn{
rt: routingtable.NewRoutingTable(),
exportFilterChain: exportFilterChain,
contributingASNs: contributingASNs,
vrf: vrf,
sessionAttrs: sessionAttrs,
}
a.clientManager = routingtable.NewClientManager(a)
Expand Down Expand Up @@ -319,7 +320,7 @@ func (a *AdjRIBIn) ourASNsInPath(p *route.Path) bool {

for _, pathSegment := range *p.BGPPath.ASPath {
for _, asn := range pathSegment.ASNs {
if a.contributingASNs.IsContributingASN(asn) {
if a.vrf.IsContributingASN(asn) {
return true
}
}
Expand Down
9 changes: 5 additions & 4 deletions routingtable/adjRIBIn/adj_rib_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -265,7 +266,7 @@ func TestAddPath(t *testing.T) {
ClusterID: clusterID,
AddPathRX: test.addPath,
}
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), sessionAttrs)
adjRIBIn := New(filter.NewAcceptAllFilterChain(), vrf.NewUntrackedVRF("vrf0", 0), sessionAttrs)
mc := routingtable.NewRTMockClient()
adjRIBIn.clientManager.RegisterWithOptions(mc, routingtable.ClientOptions{BestOnly: true})

Expand Down Expand Up @@ -495,7 +496,7 @@ func TestRemovePath(t *testing.T) {
ClusterID: 2,
AddPathRX: test.addPath,
}
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), sessionAttrs)
adjRIBIn := New(filter.NewAcceptAllFilterChain(), vrf.NewUntrackedVRF("vrf0", 0), sessionAttrs)
for _, route := range test.routes {
adjRIBIn.AddPath(route.Prefix().Ptr(), route.Paths()[0])
}
Expand Down Expand Up @@ -523,7 +524,7 @@ func TestRemovePath(t *testing.T) {
}

func TestUnregister(t *testing.T) {
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), routingtable.SessionAttrs{})
adjRIBIn := New(filter.NewAcceptAllFilterChain(), vrf.NewUntrackedVRF("vrf0", 0), routingtable.SessionAttrs{})
mc := routingtable.NewRTMockClient()
adjRIBIn.Register(mc)

Expand Down Expand Up @@ -839,7 +840,7 @@ func TestPeerRoleOTC(t *testing.T) {
}

for _, test := range tests {
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), test.sessionAttrs)
adjRIBIn := New(filter.NewAcceptAllFilterChain(), vrf.NewUntrackedVRF("vrf0", 0), test.sessionAttrs)
mc := routingtable.NewRTMockClient()
adjRIBIn.clientManager.RegisterWithOptions(mc, routingtable.ClientOptions{BestOnly: true})

Expand Down
88 changes: 0 additions & 88 deletions routingtable/contributing_asn_list.go

This file was deleted.

Loading

0 comments on commit 0f2a126

Please sign in to comment.