diff --git a/protocols/bgp/server/fsm.go b/protocols/bgp/server/fsm.go index fc342e821871667f3d4fe7aab18e5d50e225674a..f8f20547ce53cbad2fd7d7c02de64a8e80aa1e90 100644 --- a/protocols/bgp/server/fsm.go +++ b/protocols/bgp/server/fsm.go @@ -16,7 +16,6 @@ import ( "github.com/bio-routing/bio-rd/routingtable/adjRIBIn" "github.com/bio-routing/bio-rd/routingtable/adjRIBOut" "github.com/bio-routing/bio-rd/routingtable/adjRIBOutAddPath" - "github.com/bio-routing/bio-rd/routingtable/locRIB" log "github.com/sirupsen/logrus" tomb "gopkg.in/tomb.v2" ) @@ -92,7 +91,7 @@ type FSM struct { adjRIBIn *adjRIBIn.AdjRIBIn adjRIBOut routingtable.RouteTableClient - rib *locRIB.LocRIB + rib routingtable.RouteTableClient updateSender routingtable.RouteTableClient capAddPathSend bool @@ -109,7 +108,7 @@ type msgRecvErr struct { con *net.TCPConn } -func NewFSM(peer *Peer, c config.Peer, rib *locRIB.LocRIB) *FSM { +func NewFSM(peer *Peer, c config.Peer, rib routingtable.RouteTableClient) *FSM { fsm := &FSM{ peer: peer, state: Idle, diff --git a/protocols/bgp/server/peer.go b/protocols/bgp/server/peer.go index bf18c5d5d869c71a33b9e9aa587bbeaaca405f5f..0f4b3514f0d29515b4d07ed96dbca41409db0dfb 100644 --- a/protocols/bgp/server/peer.go +++ b/protocols/bgp/server/peer.go @@ -3,25 +3,23 @@ package server import ( "net" + "github.com/bio-routing/bio-rd/config" "github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/routingtable" - "github.com/bio-routing/bio-rd/routingtable/locRIB" - - "github.com/bio-routing/bio-rd/config" ) type Peer struct { addr net.IP asn uint32 fsm *FSM - rib *locRIB.LocRIB + rib routingtable.RouteTableClient routerID uint32 addPathSend routingtable.ClientOptions addPathRecv bool optOpenParams []packet.OptParam } -func NewPeer(c config.Peer, rib *locRIB.LocRIB) (*Peer, error) { +func NewPeer(c config.Peer, rib routingtable.RouteTableClient) (*Peer, error) { p := &Peer{ addr: c.PeerAddress, asn: c.PeerAS, diff --git a/protocols/bgp/server/server.go b/protocols/bgp/server/server.go index 8a11cd3a0641c6ff926ddc4459da157d7273db44..f50def76491201ff604a098195fb658d08dbb769 100644 --- a/protocols/bgp/server/server.go +++ b/protocols/bgp/server/server.go @@ -8,7 +8,7 @@ import ( "github.com/bio-routing/bio-rd/config" "github.com/bio-routing/bio-rd/protocols/bgp/packet" - "github.com/bio-routing/bio-rd/routingtable/locRIB" + "github.com/bio-routing/bio-rd/routingtable" log "github.com/sirupsen/logrus" ) @@ -84,7 +84,7 @@ func (b *BGPServer) incomingConnectionWorker() { } } -func (b *BGPServer) AddPeer(c config.Peer, rib *locRIB.LocRIB) error { +func (b *BGPServer) AddPeer(c config.Peer, rib routingtable.RouteTableClient) error { if c.LocalAS > uint16max || c.PeerAS > uint16max { return fmt.Errorf("32bit ASNs are not supported yet") } diff --git a/routingtable/adjRIBIn/adj_rib_in_test.go b/routingtable/adjRIBIn/adj_rib_in_test.go index 5659ab805f73b3bf888a08fa8ff6a7dbe8185bdf..a994e0f5e82be4ccef141ce63463b762d055d111 100644 --- a/routingtable/adjRIBIn/adj_rib_in_test.go +++ b/routingtable/adjRIBIn/adj_rib_in_test.go @@ -34,6 +34,10 @@ func (m *RTMockClient) Register(routingtable.RouteTableClient) { return } +func (m *RTMockClient) RegisterWithOptions(routingtable.RouteTableClient, routingtable.ClientOptions) { + return +} + func (m *RTMockClient) Unregister(routingtable.RouteTableClient) { return } diff --git a/routingtable/client_interface.go b/routingtable/client_interface.go index 0800ceec8db1cb3b758b74b3a1d3c8b7aef62acb..e7190c5b6c0bb1829f59cf5faadd0623ef3b395c 100644 --- a/routingtable/client_interface.go +++ b/routingtable/client_interface.go @@ -11,5 +11,6 @@ type RouteTableClient interface { RemovePath(net.Prefix, *route.Path) bool UpdateNewClient(RouteTableClient) error Register(RouteTableClient) + RegisterWithOptions(RouteTableClient, ClientOptions) Unregister(RouteTableClient) } diff --git a/routingtable/client_manager_test.go b/routingtable/client_manager_test.go index af2507855bfac8a5d09551b105d7bfc4ae93dd79..78e2e58c4030a2e25a1b9ae228ef712fc1c67550 100644 --- a/routingtable/client_manager_test.go +++ b/routingtable/client_manager_test.go @@ -25,6 +25,11 @@ func (m MockClient) UpdateNewClient(RouteTableClient) error { func (m MockClient) Register(RouteTableClient) { return } + +func (m MockClient) RegisterWithOptions(RouteTableClient, ClientOptions) { + return +} + func (m MockClient) Unregister(RouteTableClient) { return } diff --git a/routingtable/filter/term_condition.go b/routingtable/filter/term_condition.go index 92c3616a8cc55f21c73696b2f87a1b2a9cfbcbd4..8bc87485d58bd9215d122e4af9792c7c0c1c2b82 100644 --- a/routingtable/filter/term_condition.go +++ b/routingtable/filter/term_condition.go @@ -10,6 +10,13 @@ type TermCondition struct { routeFilters []*RouteFilter } +func NewTermCondition(prefixLists []*PrefixList, routeFilters []*RouteFilter) *TermCondition { + return &TermCondition{ + prefixLists: prefixLists, + routeFilters: routeFilters, + } +} + func (f *TermCondition) Matches(p net.Prefix, pa *route.Path) bool { return f.matchesAnyPrefixList(p) || f.machtchesAnyRouteFilter(p) } diff --git a/routingtable/filter/term_condition_test.go b/routingtable/filter/term_condition_test.go index 876746a240d195ee2a6612636a888a2cf41a9d25..fba97b673bea6901983e6bba509358fe8bf504f3 100644 --- a/routingtable/filter/term_condition_test.go +++ b/routingtable/filter/term_condition_test.go @@ -109,10 +109,10 @@ func TestMatches(t *testing.T) { for _, test := range tests { t.Run(test.name, func(te *testing.T) { - f := &TermCondition{ - prefixLists: test.prefixLists, - routeFilters: test.routeFilters, - } + f := NewTermCondition( + test.prefixLists, + test.routeFilters, + ) assert.Equal(te, test.expected, f.Matches(test.prefix, &route.Path{})) }) diff --git a/routingtable/locRIB/loc_rib.go b/routingtable/locRIB/loc_rib.go index a1701743b1b5d946f958f47e1b163285427a57b0..ff5750c34d226080bea079968becdec410d2704e 100644 --- a/routingtable/locRIB/loc_rib.go +++ b/routingtable/locRIB/loc_rib.go @@ -8,6 +8,7 @@ import ( "github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/routingtable" + "github.com/sirupsen/logrus" ) // LocRIB represents a routing information base @@ -44,6 +45,10 @@ func (a *LocRIB) AddPath(pfx net.Prefix, p *route.Path) error { a.mu.Lock() defer a.mu.Unlock() + logrus.WithFields(map[string]interface{}{ + "Prefix": pfx, + "Route": p, + }).Debug("AddPath to locRIB") routeExisted := false oldRoute := &route.Route{} r := a.rt.Get(pfx) @@ -70,6 +75,10 @@ func (a *LocRIB) RemovePath(pfx net.Prefix, p *route.Path) bool { a.mu.Lock() defer a.mu.Unlock() + logrus.WithFields(map[string]interface{}{ + "Prefix": pfx, + "Route": p, + }).Debug("Remove from locRIB") var oldRoute *route.Route r := a.rt.Get(pfx) if r != nil {