Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move contributing ASNs to VRF & add check for all Cluster IDs in the same VRF #396

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions protocols/bgp/server/bgp_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestDumpRIBInOut(t *testing.T) {
AddPathTX: true,
}

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

tests := []struct {
name string
apisrv *BGPAPIServer
Expand Down Expand Up @@ -74,7 +76,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, sessionAttrs),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), v, sessionAttrs),
adjRIBOut: adjRIBOut.New(nil, routingtable.SessionAttrs{Type: route.BGPPathType}, filter.NewAcceptAllFilterChain()),
},
},
Expand Down Expand Up @@ -108,7 +110,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, sessionAttrs),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), v, sessionAttrs),
adjRIBOut: adjRIBOut.New(nil, routingtable.SessionAttrs{Type: route.BGPPathType, RouteServerClient: true, PeerIP: bnet.IPv4(0).Ptr()}, filter.NewAcceptAllFilterChain()),
},
},
Expand Down Expand Up @@ -173,7 +175,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), sessionAttrs),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), v, sessionAttrs),
adjRIBOut: adjRIBOut.New(nil, routingtable.SessionAttrs{Type: route.BGPPathType, RouteServerClient: true, PeerIP: bnet.IPv4(123).Ptr()}, filter.NewAcceptAllFilterChain()),
},
},
Expand Down
25 changes: 16 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 Down Expand Up @@ -80,21 +81,23 @@ 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.fsm.peer.vrf, sessionAttrs)
f.fsm.peer.vrf.AddContributingASN(f.fsm.peer.localASN)
if f.fsm.peer.routeReflectorClient {
f.fsm.peer.vrf.AddContributingClusterID(f.fsm.peer.clusterID)
}

f.adjRIBIn.Register(f.rib)

Expand Down Expand Up @@ -138,7 +141,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())
BarbarossaTM marked this conversation as resolved.
Show resolved Hide resolved

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

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

f.adjRIBIn.Flush()

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

f.rib.GetContributingASNs().Remove(f.fsm.peer.localASN)
f.fsm.peer.vrf.RemoveContributingASN(f.fsm.peer.localASN)
if f.fsm.peer.routeReflectorClient {
f.fsm.peer.vrf.RemoveContributingClusterID(f.fsm.peer.clusterID)
}

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 @@ -27,6 +28,7 @@ func TestFSMAFIInitDispose(t *testing.T) {
routerID: 100,
localASN: 15169,
adjRIBInFactory: adjRIBInFactory{},
vrf: vrf.NewUntrackedVRF("vrf0", 0),
},
con: &biotesting.MockConn{
Buf: bytes.NewBuffer(nil),
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.fsm.peer.vrf.IsContributingASN(15169))
assert.NotEqual(t, true, f.fsm.peer.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.fsm.peer.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
13 changes: 7 additions & 6 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 @@ -295,10 +296,10 @@ func (a *AdjRIBIn) validatePath(p *route.Path) uint8 {
return route.HiddenReasonOurOriginatorID
}

// RFC4456 Sect. 8: Ignore routes which contain our ClusterID in their ClusterList
// RFC4456 Sect. 8: Ignore routes which contains any ClusterID used within this VRF in their ClusterList
if p.BGPPath.ClusterList != nil && len(*p.BGPPath.ClusterList) > 0 {
for _, cid := range *p.BGPPath.ClusterList {
if cid == a.sessionAttrs.ClusterID {
if a.vrf.IsContributingClusterID(cid) {
return route.HiddenReasonClusterLoop
}
}
Expand All @@ -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
11 changes: 7 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,9 @@ func TestAddPath(t *testing.T) {
ClusterID: clusterID,
AddPathRX: test.addPath,
}
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), sessionAttrs)
vrf := vrf.NewUntrackedVRF("vrf0", 0)
vrf.AddContributingClusterID(clusterID)
adjRIBIn := New(filter.NewAcceptAllFilterChain(), vrf, sessionAttrs)
mc := routingtable.NewRTMockClient()
adjRIBIn.clientManager.RegisterWithOptions(mc, routingtable.ClientOptions{BestOnly: true})

Expand Down Expand Up @@ -495,7 +498,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 +526,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 +842,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