Skip to content

Commit

Permalink
Propagate peer parameters to AdjRIBIn (#341)
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Wilhelm <[email protected]>
  • Loading branch information
Maximilian Wilhelm authored Jul 28, 2022
1 parent 225a40b commit 6ad92e4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
12 changes: 9 additions & 3 deletions protocols/bgp/server/bgp_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import (
)

func TestDumpRIBInOut(t *testing.T) {
peerParams := adjRIBIn.PeerParameters{
RouterID: 0,
ClusterID: 0,
AddPathRX: true,
}

tests := []struct {
name string
apisrv *BGPAPIServer
Expand Down Expand Up @@ -60,7 +66,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, 0, 0, true),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, peerParams),
adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType}, filter.NewAcceptAllFilterChain(), true),
},
},
Expand Down Expand Up @@ -90,7 +96,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, 0, 0, true),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), nil, peerParams),
adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(0).Ptr()}, filter.NewAcceptAllFilterChain(), false),
},
},
Expand Down Expand Up @@ -150,7 +156,7 @@ func TestDumpRIBInOut(t *testing.T) {
fsms: []*FSM{
0: {
ipv4Unicast: &fsmAddressFamily{
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 0, 0, true),
adjRIBIn: adjRIBIn.New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams),
adjRIBOut: adjRIBOut.New(nil, &routingtable.Neighbor{Type: route.BGPPathType, RouteServerClient: true, Address: bnet.IPv4(123).Ptr()}, filter.NewAcceptAllFilterChain(), false),
},
},
Expand Down
3 changes: 2 additions & 1 deletion protocols/bgp/server/bmp_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ func (r *Router) processPeerUpNotification(msg *bmppkt.PeerUpNotification) error
localAddress, _ := bnet.IPFromBytes(msg.LocalAddress[16-addrLen:])

fsm := &FSM{
isBMP: true,
isBMP: true,
bmpRouterAddress: r.address,
peer: &peer{
routerID: sentOpen.BGPIdentifier,
addr: peerAddress.Dedup(),
Expand Down
4 changes: 3 additions & 1 deletion protocols/bgp/server/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ type state interface {
type FSM struct {
counters fsmCounters

isBMP bool
isBMP bool
bmpRouterAddress net.IP

peer *peer
eventCh chan int
con net.Conn
Expand Down
27 changes: 22 additions & 5 deletions protocols/bgp/server/fsm_address_family.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ func (f *fsmAddressFamily) dumpRIBIn() []*route.Route {
}

type adjRIBInFactoryI interface {
New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, routerID uint32, clusterID uint32, addPathRX bool) routingtable.AdjRIBIn
New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, peerParams adjRIBIn.PeerParameters) routingtable.AdjRIBIn
}

type adjRIBInFactory struct{}

func (a adjRIBInFactory) New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, routerID uint32, clusterID uint32, addPathRX bool) routingtable.AdjRIBIn {
return adjRIBIn.New(exportFilterChain, contributingASNs, routerID, clusterID, addPathRX)
func (a adjRIBInFactory) New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, peerParams adjRIBIn.PeerParameters) routingtable.AdjRIBIn {
return adjRIBIn.New(exportFilterChain, contributingASNs, peerParams)
}

func (f *fsmAddressFamily) init(n *routingtable.Neighbor) {
contributingASNs := f.rib.GetContributingASNs()

f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(f.importFilterChain, contributingASNs, f.fsm.peer.routerID, f.fsm.peer.clusterID, f.addPathRX)
f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(f.importFilterChain, contributingASNs, f.peerParameters())
contributingASNs.Add(f.fsm.peer.localASN)

f.adjRIBIn.Register(f.rib)
Expand All @@ -106,8 +106,25 @@ func (f *fsmAddressFamily) init(n *routingtable.Neighbor) {
f.initialized = true
}

func (f *fsmAddressFamily) peerParameters() adjRIBIn.PeerParameters {
rip, _ := bnet.IPFromBytes(f.fsm.bmpRouterAddress)

return adjRIBIn.PeerParameters{
RouterID: f.fsm.peer.routerID,
ClusterID: f.fsm.peer.clusterID,
AddPathRX: f.addPathRX,

// Only relevant for BMP use
RouterIP: rip,
LocalIP: f.fsm.peer.localAddr,
PeerIP: f.fsm.peer.addr,
LocalASN: f.fsm.peer.localASN,
PeerASN: f.fsm.peer.peerASN,
}
}

func (f *fsmAddressFamily) bmpInit() {
f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(filter.NewAcceptAllFilterChain(), &routingtable.ContributingASNs{}, f.fsm.peer.routerID, f.fsm.peer.clusterID, f.addPathRX)
f.adjRIBIn = f.fsm.peer.adjRIBInFactory.New(filter.NewAcceptAllFilterChain(), &routingtable.ContributingASNs{}, f.peerParameters())

if f.rib != nil {
f.adjRIBIn.Register(f.rib)
Expand Down
21 changes: 17 additions & 4 deletions routingtable/adjRIBIn/adj_rib_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,28 @@ type AdjRIBIn struct {
addPathRX bool
}

type PeerParameters struct {
RouterID uint32
ClusterID uint32
AddPathRX bool

// Only relevant for BMP use
RouterIP net.IP
LocalIP *net.IP
PeerIP *net.IP
LocalASN uint32
PeerASN uint32
}

// New creates a new Adjacency RIB In
func New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, routerID uint32, clusterID uint32, addPathRX bool) *AdjRIBIn {
func New(exportFilterChain filter.Chain, contributingASNs *routingtable.ContributingASNs, peerParams PeerParameters) *AdjRIBIn {
a := &AdjRIBIn{
rt: routingtable.NewRoutingTable(),
exportFilterChain: exportFilterChain,
contributingASNs: contributingASNs,
routerID: routerID,
clusterID: clusterID,
addPathRX: addPathRX,
routerID: peerParams.RouterID,
clusterID: peerParams.ClusterID,
addPathRX: peerParams.AddPathRX,
}
a.clientManager = routingtable.NewClientManager(a)
return a
Expand Down
20 changes: 17 additions & 3 deletions routingtable/adjRIBIn/adj_rib_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ func TestAddPath(t *testing.T) {
}

for _, test := range tests {
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), routerID, clusterID, test.addPath)
peerParams := PeerParameters{
RouterID: routerID,
ClusterID: clusterID,
AddPathRX: test.addPath,
}
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams)
mc := routingtable.NewRTMockClient()
adjRIBIn.clientManager.RegisterWithOptions(mc, routingtable.ClientOptions{BestOnly: true})

Expand Down Expand Up @@ -401,7 +406,12 @@ func TestRemovePath(t *testing.T) {
}

for _, test := range tests {
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 1, 2, test.addPath)
peerParams := PeerParameters{
RouterID: 1,
ClusterID: 2,
AddPathRX: test.addPath,
}
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams)
for _, route := range test.routes {
adjRIBIn.AddPath(route.Prefix().Ptr(), route.Paths()[0])
}
Expand Down Expand Up @@ -429,7 +439,11 @@ func TestRemovePath(t *testing.T) {
}

func TestUnregister(t *testing.T) {
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), 0, 0, false)
peerParams := PeerParameters{
RouterID: 0,
ClusterID: 0,
AddPathRX: false}
adjRIBIn := New(filter.NewAcceptAllFilterChain(), routingtable.NewContributingASNs(), peerParams)
mc := routingtable.NewRTMockClient()
adjRIBIn.Register(mc)

Expand Down

0 comments on commit 6ad92e4

Please sign in to comment.