Skip to content
Snippets Groups Projects
Unverified Commit 5edae50b authored by Daniel Czerwonk's avatar Daniel Czerwonk Committed by GitHub
Browse files

Merge branch 'master' into feature/add-basic-communities

parents c8cab24e 46a2f9bb
No related branches found
No related tags found
No related merge requests found
Showing
with 138 additions and 64 deletions
...@@ -3,19 +3,22 @@ package config ...@@ -3,19 +3,22 @@ package config
import ( import (
"net" "net"
"time"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
) )
type Peer struct { type Peer struct {
AdminEnabled bool AdminEnabled bool
KeepAlive uint16 KeepAlive uint16
HoldTimer uint16 HoldTimer uint16
LocalAddress net.IP LocalAddress net.IP
PeerAddress net.IP PeerAddress net.IP
LocalAS uint32 LocalAS uint32
PeerAS uint32 PeerAS uint32
Passive bool Passive bool
RouterID uint32 RouterID uint32
AddPathSend routingtable.ClientOptions AddPathSend routingtable.ClientOptions
AddPathRecv bool AddPathRecv bool
ReconnectInterval time.Duration
} }
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
) )
func main() { func main() {
fmt.Printf("This is a BGP speaker\n") logrus.Printf("This is a BGP speaker\n")
rib := locRIB.New() rib := locRIB.New()
b := server.NewBgpServer() b := server.NewBgpServer()
......
...@@ -50,6 +50,10 @@ const ( ...@@ -50,6 +50,10 @@ const (
InvalidNetworkField = 10 InvalidNetworkField = 10
MalformedASPath = 11 MalformedASPath = 11
// Notification Msg Subcodes
AdministrativeShutdown = 2
AdministrativeReset = 4
// Attribute Type Codes // Attribute Type Codes
OriginAttr = 1 OriginAttr = 1
ASPathAttr = 2 ASPathAttr = 2
......
...@@ -114,7 +114,7 @@ func decodeNotificationMsg(buf *bytes.Buffer) (*BGPNotification, error) { ...@@ -114,7 +114,7 @@ func decodeNotificationMsg(buf *bytes.Buffer) (*BGPNotification, error) {
return invalidErrCode(msg) return invalidErrCode(msg)
} }
case Cease: case Cease:
if msg.ErrorSubcode != 0 { if !(msg.ErrorSubcode == 0 || msg.ErrorSubcode == AdministrativeShutdown || msg.ErrorSubcode == AdministrativeReset) {
return invalidErrCode(msg) return invalidErrCode(msg)
} }
default: default:
......
...@@ -16,7 +16,6 @@ import ( ...@@ -16,7 +16,6 @@ import (
"github.com/bio-routing/bio-rd/routingtable/adjRIBIn" "github.com/bio-routing/bio-rd/routingtable/adjRIBIn"
"github.com/bio-routing/bio-rd/routingtable/adjRIBOut" "github.com/bio-routing/bio-rd/routingtable/adjRIBOut"
"github.com/bio-routing/bio-rd/routingtable/adjRIBOutAddPath" "github.com/bio-routing/bio-rd/routingtable/adjRIBOutAddPath"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
tomb "gopkg.in/tomb.v2" tomb "gopkg.in/tomb.v2"
) )
...@@ -92,7 +91,7 @@ type FSM struct { ...@@ -92,7 +91,7 @@ type FSM struct {
adjRIBIn *adjRIBIn.AdjRIBIn adjRIBIn *adjRIBIn.AdjRIBIn
adjRIBOut routingtable.RouteTableClient adjRIBOut routingtable.RouteTableClient
rib *locRIB.LocRIB rib routingtable.RouteTableClient
updateSender routingtable.RouteTableClient updateSender routingtable.RouteTableClient
capAddPathSend bool capAddPathSend bool
...@@ -109,7 +108,7 @@ type msgRecvErr struct { ...@@ -109,7 +108,7 @@ type msgRecvErr struct {
con *net.TCPConn 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{ fsm := &FSM{
peer: peer, peer: peer,
state: Idle, state: Idle,
...@@ -647,7 +646,7 @@ func (fsm *FSM) openConfirm() int { ...@@ -647,7 +646,7 @@ func (fsm *FSM) openConfirm() int {
case recvMsg := <-fsm.msgRecvCh: case recvMsg := <-fsm.msgRecvCh:
msg, err := packet.Decode(bytes.NewBuffer(recvMsg.msg)) msg, err := packet.Decode(bytes.NewBuffer(recvMsg.msg))
if err != nil { if err != nil {
fmt.Printf("Failed to decode message: %v\n", recvMsg.msg) log.WithError(err).Errorf("Failed to decode BGP message %v\n", recvMsg.msg)
switch bgperr := err.(type) { switch bgperr := err.(type) {
case packet.BGPError: case packet.BGPError:
sendNotification(fsm.con, bgperr.ErrorCode, bgperr.ErrorSubCode) sendNotification(fsm.con, bgperr.ErrorCode, bgperr.ErrorSubCode)
...@@ -790,7 +789,7 @@ func (fsm *FSM) established() int { ...@@ -790,7 +789,7 @@ func (fsm *FSM) established() int {
case recvMsg := <-fsm.msgRecvCh: case recvMsg := <-fsm.msgRecvCh:
msg, err := packet.Decode(bytes.NewBuffer(recvMsg.msg)) msg, err := packet.Decode(bytes.NewBuffer(recvMsg.msg))
if err != nil { if err != nil {
fmt.Printf("Failed to decode BGP message: %v msg: %v\n", err, recvMsg.msg) log.WithError(err).Errorf("Failed to decode BGP message %v\n", recvMsg.msg)
switch bgperr := err.(type) { switch bgperr := err.(type) {
case packet.BGPError: case packet.BGPError:
sendNotification(fsm.con, bgperr.ErrorCode, bgperr.ErrorSubCode) sendNotification(fsm.con, bgperr.ErrorCode, bgperr.ErrorSubCode)
...@@ -815,14 +814,13 @@ func (fsm *FSM) established() int { ...@@ -815,14 +814,13 @@ func (fsm *FSM) established() int {
for r := u.WithdrawnRoutes; r != nil; r = r.Next { for r := u.WithdrawnRoutes; r != nil; r = r.Next {
pfx := tnet.NewPfx(r.IP, r.Pfxlen) pfx := tnet.NewPfx(r.IP, r.Pfxlen)
fmt.Printf("LPM: Removing prefix %s\n", pfx.String()) log.WithField("Prefix", pfx.String()).Debug("LPM: Removing prefix")
fsm.adjRIBIn.RemovePath(pfx, nil) fsm.adjRIBIn.RemovePath(pfx, nil)
} }
for r := u.NLRI; r != nil; r = r.Next { for r := u.NLRI; r != nil; r = r.Next {
pfx := tnet.NewPfx(r.IP, r.Pfxlen) pfx := tnet.NewPfx(r.IP, r.Pfxlen)
fmt.Printf("LPM: Adding prefix %s\n", pfx.String()) log.WithField("Prefix", pfx.String()).Debug("LPM: Adding prefix")
path := &route.Path{ path := &route.Path{
Type: route.BGPPathType, Type: route.BGPPathType,
BGPPath: &route.BGPPath{ BGPPath: &route.BGPPath{
...@@ -831,7 +829,6 @@ func (fsm *FSM) established() int { ...@@ -831,7 +829,6 @@ func (fsm *FSM) established() int {
} }
for pa := u.PathAttributes; pa != nil; pa = pa.Next { for pa := u.PathAttributes; pa != nil; pa = pa.Next {
fmt.Printf("TypeCode: %d\n", pa.TypeCode)
switch pa.TypeCode { switch pa.TypeCode {
case packet.OriginAttr: case packet.OriginAttr:
path.BGPPath.Origin = pa.Value.(uint8) path.BGPPath.Origin = pa.Value.(uint8)
...@@ -840,7 +837,7 @@ func (fsm *FSM) established() int { ...@@ -840,7 +837,7 @@ func (fsm *FSM) established() int {
case packet.MEDAttr: case packet.MEDAttr:
path.BGPPath.MED = pa.Value.(uint32) path.BGPPath.MED = pa.Value.(uint32)
case packet.NextHopAttr: case packet.NextHopAttr:
fmt.Printf("RECEIVED NEXT_HOP: %d\n", pa.Value.(uint32)) log.WithField("NextHop", pa.Value.(uint32)).Debug("RECEIVED NEXT_HOP")
path.BGPPath.NextHop = pa.Value.(uint32) path.BGPPath.NextHop = pa.Value.(uint32)
case packet.ASPathAttr: case packet.ASPathAttr:
path.BGPPath.ASPath = pa.ASPathString() path.BGPPath.ASPath = pa.ASPathString()
......
...@@ -3,32 +3,36 @@ package server ...@@ -3,32 +3,36 @@ package server
import ( import (
"net" "net"
"github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/bio-rd/config" "time"
) )
type Peer struct { type Peer struct {
addr net.IP addr net.IP
asn uint32 asn uint32
fsm *FSM fsm *FSM
rib *locRIB.LocRIB rib routingtable.RouteTableClient
routerID uint32 routerID uint32
addPathSend routingtable.ClientOptions addPathSend routingtable.ClientOptions
addPathRecv bool addPathRecv bool
optOpenParams []packet.OptParam optOpenParams []packet.OptParam
reconnectInterval time.Duration
} }
func NewPeer(c config.Peer, rib *locRIB.LocRIB) (*Peer, error) { // NewPeer creates a new peer with the given config. If an connection is established, the adjRIBIN of the peer is connected
// to the given rib. To actually connect the peer, call Start() on the returned peer.
func NewPeer(c config.Peer, rib routingtable.RouteTableClient) (*Peer, error) {
p := &Peer{ p := &Peer{
addr: c.PeerAddress, addr: c.PeerAddress,
asn: c.PeerAS, asn: c.PeerAS,
rib: rib, rib: rib,
addPathSend: c.AddPathSend, addPathSend: c.AddPathSend,
addPathRecv: c.AddPathRecv, addPathRecv: c.AddPathRecv,
optOpenParams: make([]packet.OptParam, 0), optOpenParams: make([]packet.OptParam, 0),
reconnectInterval: c.ReconnectInterval,
} }
p.fsm = NewFSM(p, c, rib) p.fsm = NewFSM(p, c, rib)
...@@ -63,19 +67,29 @@ func NewPeer(c config.Peer, rib *locRIB.LocRIB) (*Peer, error) { ...@@ -63,19 +67,29 @@ func NewPeer(c config.Peer, rib *locRIB.LocRIB) (*Peer, error) {
return p, nil return p, nil
} }
// GetAddr returns the IP address of the peer
func (p *Peer) GetAddr() net.IP { func (p *Peer) GetAddr() net.IP {
return p.addr return p.addr
} }
// GetASN returns the configured AS number of the peer
func (p *Peer) GetASN() uint32 { func (p *Peer) GetASN() uint32 {
return p.asn return p.asn
} }
// Start the peers fsm. It starts from the Idle state and will get an ManualStart event. To trigger
// reconnects if the fsm falls back into the Idle state, every reconnectInterval a ManualStart event is send.
// The default value for reconnectInterval is 30 seconds.
func (p *Peer) Start() { func (p *Peer) Start() {
p.fsm.start() p.fsm.start()
if p.reconnectInterval == 0 {
p.reconnectInterval = 30 * time.Second
}
t := time.Tick(p.reconnectInterval)
go func() { go func() {
for { for {
<-t
p.fsm.activate() p.fsm.activate()
} }
}() }()
} }
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/bio-routing/bio-rd/config" "github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/protocols/bgp/packet" "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" log "github.com/sirupsen/logrus"
) )
...@@ -39,7 +39,7 @@ func (b *BGPServer) Start(c *config.Global) error { ...@@ -39,7 +39,7 @@ func (b *BGPServer) Start(c *config.Global) error {
return fmt.Errorf("Failed to load defaults: %v", err) return fmt.Errorf("Failed to load defaults: %v", err)
} }
fmt.Printf("ROUTER ID: %d\n", c.RouterID) log.Infof("ROUTER ID: %d\n", c.RouterID)
b.routerID = c.RouterID b.routerID = c.RouterID
if c.Listen { if c.Listen {
...@@ -62,8 +62,6 @@ func (b *BGPServer) Start(c *config.Global) error { ...@@ -62,8 +62,6 @@ func (b *BGPServer) Start(c *config.Global) error {
func (b *BGPServer) incomingConnectionWorker() { func (b *BGPServer) incomingConnectionWorker() {
for { for {
c := <-b.acceptCh c := <-b.acceptCh
fmt.Printf("Incoming connection!\n")
fmt.Printf("Connection from: %v\n", c.RemoteAddr())
peerAddr := strings.Split(c.RemoteAddr().String(), ":")[0] peerAddr := strings.Split(c.RemoteAddr().String(), ":")[0]
if _, ok := b.peers[peerAddr]; !ok { if _, ok := b.peers[peerAddr]; !ok {
...@@ -78,13 +76,13 @@ func (b *BGPServer) incomingConnectionWorker() { ...@@ -78,13 +76,13 @@ func (b *BGPServer) incomingConnectionWorker() {
"source": c.RemoteAddr(), "source": c.RemoteAddr(),
}).Info("Incoming TCP connection") }).Info("Incoming TCP connection")
fmt.Printf("DEBUG: Sending incoming TCP connection to fsm for peer %s\n", peerAddr) log.WithField("Peer", peerAddr).Debug("Sending incoming TCP connection to fsm for peer")
b.peers[peerAddr].fsm.conCh <- c b.peers[peerAddr].fsm.conCh <- c
fmt.Printf("DEBUG: Sending done\n") log.Debug("Sending done")
} }
} }
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 { if c.LocalAS > uint16max || c.PeerAS > uint16max {
return fmt.Errorf("32bit ASNs are not supported yet") return fmt.Errorf("32bit ASNs are not supported yet")
} }
......
...@@ -15,18 +15,20 @@ import ( ...@@ -15,18 +15,20 @@ import (
// UpdateSender converts table changes into BGP update messages // UpdateSender converts table changes into BGP update messages
type UpdateSender struct { type UpdateSender struct {
routingtable.ClientManager routingtable.ClientManager
fsm *FSM fsm *FSM
iBGP bool
} }
func newUpdateSender(fsm *FSM) *UpdateSender { func newUpdateSender(fsm *FSM) *UpdateSender {
return &UpdateSender{ return &UpdateSender{
fsm: fsm, fsm: fsm,
iBGP: fsm.localASN == fsm.remoteASN,
} }
} }
// AddPath serializes a new path and sends out a BGP update message // AddPath serializes a new path and sends out a BGP update message
func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error { func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", u.fsm.localASN, p.BGPPath.ASPath), " ")) asPathPA, err := packet.ParseASPathStr(asPathString(u.iBGP, u.fsm.localASN, p.BGPPath.ASPath))
if err != nil { if err != nil {
return fmt.Errorf("Unable to parse AS path: %v", err) return fmt.Errorf("Unable to parse AS path: %v", err)
} }
...@@ -41,6 +43,10 @@ func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -41,6 +43,10 @@ func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
Next: &packet.PathAttribute{ Next: &packet.PathAttribute{
TypeCode: packet.NextHopAttr, TypeCode: packet.NextHopAttr,
Value: p.BGPPath.NextHop, Value: p.BGPPath.NextHop,
Next: &packet.PathAttribute{
TypeCode: packet.LocalPrefAttr,
Value: p.BGPPath.LocalPref,
},
}, },
}, },
}, },
...@@ -74,3 +80,12 @@ func (u *UpdateSender) UpdateNewClient(client routingtable.RouteTableClient) err ...@@ -74,3 +80,12 @@ func (u *UpdateSender) UpdateNewClient(client routingtable.RouteTableClient) err
log.Warningf("BGP Update Sender: UpdateNewClient() not supported") log.Warningf("BGP Update Sender: UpdateNewClient() not supported")
return nil return nil
} }
func asPathString(iBGP bool, localASN uint16, asPath string) string {
ret := ""
if iBGP {
ret = ret + fmt.Sprintf("%d ", localASN)
}
ret = ret + asPath
return strings.TrimRight(ret, " ")
}
...@@ -2,7 +2,6 @@ package server ...@@ -2,7 +2,6 @@ package server
import ( import (
"fmt" "fmt"
"strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
...@@ -15,18 +14,20 @@ import ( ...@@ -15,18 +14,20 @@ import (
// UpdateSenderAddPath converts table changes into BGP update messages with add path // UpdateSenderAddPath converts table changes into BGP update messages with add path
type UpdateSenderAddPath struct { type UpdateSenderAddPath struct {
routingtable.ClientManager routingtable.ClientManager
fsm *FSM fsm *FSM
iBGP bool
} }
func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath { func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath {
return &UpdateSenderAddPath{ return &UpdateSenderAddPath{
fsm: fsm, fsm: fsm,
iBGP: fsm.localASN == fsm.remoteASN,
} }
} }
// AddPath serializes a new path and sends out a BGP update message // AddPath serializes a new path and sends out a BGP update message
func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error { func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", u.fsm.localASN, p.BGPPath.ASPath), " ")) asPathPA, err := packet.ParseASPathStr(asPathString(u.iBGP, u.fsm.localASN, p.BGPPath.ASPath))
if err != nil { if err != nil {
return fmt.Errorf("Unable to parse AS path: %v", err) return fmt.Errorf("Unable to parse AS path: %v", err)
} }
...@@ -41,6 +42,10 @@ func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -41,6 +42,10 @@ func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
Next: &packet.PathAttribute{ Next: &packet.PathAttribute{
TypeCode: packet.NextHopAttr, TypeCode: packet.NextHopAttr,
Value: p.BGPPath.NextHop, Value: p.BGPPath.NextHop,
Next: &packet.PathAttribute{
TypeCode: packet.LocalPrefAttr,
Value: p.BGPPath.LocalPref,
},
}, },
}, },
}, },
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
log "github.com/sirupsen/logrus"
) )
// AdjRIBIn represents an Adjacency RIB In as described in RFC4271 // AdjRIBIn represents an Adjacency RIB In as described in RFC4271
...@@ -33,7 +34,11 @@ func (a *AdjRIBIn) UpdateNewClient(client routingtable.RouteTableClient) error { ...@@ -33,7 +34,11 @@ func (a *AdjRIBIn) UpdateNewClient(client routingtable.RouteTableClient) error {
for _, route := range routes { for _, route := range routes {
paths := route.Paths() paths := route.Paths()
for _, path := range paths { for _, path := range paths {
client.AddPath(route.Prefix(), path)
err := client.AddPath(route.Prefix(), path)
if err != nil {
log.WithField("Sender", "AdjRIBOutAddPath").WithError(err).Error("Could not send update to client")
}
} }
} }
return nil return nil
......
...@@ -34,6 +34,10 @@ func (m *RTMockClient) Register(routingtable.RouteTableClient) { ...@@ -34,6 +34,10 @@ func (m *RTMockClient) Register(routingtable.RouteTableClient) {
return return
} }
func (m *RTMockClient) RegisterWithOptions(routingtable.RouteTableClient, routingtable.ClientOptions) {
return
}
func (m *RTMockClient) Unregister(routingtable.RouteTableClient) { func (m *RTMockClient) Unregister(routingtable.RouteTableClient) {
return return
} }
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
log "github.com/sirupsen/logrus"
) )
// AdjRIBOut represents an Adjacency RIB In as described in RFC4271 // AdjRIBOut represents an Adjacency RIB In as described in RFC4271
...@@ -45,7 +46,10 @@ func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -45,7 +46,10 @@ func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error {
a.removePathsFromClients(pfx, oldPaths) a.removePathsFromClients(pfx, oldPaths)
for _, client := range a.ClientManager.Clients() { for _, client := range a.ClientManager.Clients() {
client.AddPath(pfx, p) err := client.AddPath(pfx, p)
if err != nil {
log.WithField("Sender", "AdjRIBOut").WithError(err).Error("Could not send update to client")
}
} }
return nil return nil
} }
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
log "github.com/sirupsen/logrus"
) )
// AdjRIBOutAddPath represents an Adjacency RIB Out with BGP add path // AdjRIBOutAddPath represents an Adjacency RIB Out with BGP add path
...@@ -52,7 +53,10 @@ func (a *AdjRIBOutAddPath) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -52,7 +53,10 @@ func (a *AdjRIBOutAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
a.rt.AddPath(pfx, p) a.rt.AddPath(pfx, p)
for _, client := range a.ClientManager.Clients() { for _, client := range a.ClientManager.Clients() {
client.AddPath(pfx, p) err := client.AddPath(pfx, p)
if err != nil {
log.WithField("Sender", "AdjRIBOutAddPath").WithError(err).Error("Could not send update to client")
}
} }
return nil return nil
} }
......
...@@ -11,5 +11,6 @@ type RouteTableClient interface { ...@@ -11,5 +11,6 @@ type RouteTableClient interface {
RemovePath(net.Prefix, *route.Path) bool RemovePath(net.Prefix, *route.Path) bool
UpdateNewClient(RouteTableClient) error UpdateNewClient(RouteTableClient) error
Register(RouteTableClient) Register(RouteTableClient)
RegisterWithOptions(RouteTableClient, ClientOptions)
Unregister(RouteTableClient) Unregister(RouteTableClient)
} }
...@@ -55,9 +55,8 @@ func (c *ClientManager) Register(client RouteTableClient) { ...@@ -55,9 +55,8 @@ func (c *ClientManager) Register(client RouteTableClient) {
// RegisterWithOptions registers a client with options for updates // RegisterWithOptions registers a client with options for updates
func (c *ClientManager) RegisterWithOptions(client RouteTableClient, opt ClientOptions) { func (c *ClientManager) RegisterWithOptions(client RouteTableClient, opt ClientOptions) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.clients[client] = opt c.clients[client] = opt
c.mu.Unlock()
c.master.UpdateNewClient(client) c.master.UpdateNewClient(client)
} }
......
...@@ -25,6 +25,11 @@ func (m MockClient) UpdateNewClient(RouteTableClient) error { ...@@ -25,6 +25,11 @@ func (m MockClient) UpdateNewClient(RouteTableClient) error {
func (m MockClient) Register(RouteTableClient) { func (m MockClient) Register(RouteTableClient) {
return return
} }
func (m MockClient) RegisterWithOptions(RouteTableClient, ClientOptions) {
return
}
func (m MockClient) Unregister(RouteTableClient) { func (m MockClient) Unregister(RouteTableClient) {
return return
} }
......
...@@ -10,6 +10,13 @@ type TermCondition struct { ...@@ -10,6 +10,13 @@ type TermCondition struct {
routeFilters []*RouteFilter 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 { func (f *TermCondition) Matches(p net.Prefix, pa *route.Path) bool {
return f.matchesAnyPrefixList(p) || f.machtchesAnyRouteFilter(p) return f.matchesAnyPrefixList(p) || f.machtchesAnyRouteFilter(p)
} }
......
...@@ -109,10 +109,10 @@ func TestMatches(t *testing.T) { ...@@ -109,10 +109,10 @@ func TestMatches(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(te *testing.T) { t.Run(test.name, func(te *testing.T) {
f := &TermCondition{ f := NewTermCondition(
prefixLists: test.prefixLists, test.prefixLists,
routeFilters: test.routeFilters, test.routeFilters,
} )
assert.Equal(te, test.expected, f.Matches(test.prefix, &route.Path{})) assert.Equal(te, test.expected, f.Matches(test.prefix, &route.Path{}))
}) })
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
"github.com/sirupsen/logrus"
) )
// LocRIB represents a routing information base // LocRIB represents a routing information base
...@@ -44,6 +45,10 @@ func (a *LocRIB) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -44,6 +45,10 @@ func (a *LocRIB) AddPath(pfx net.Prefix, p *route.Path) error {
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
logrus.WithFields(map[string]interface{}{
"Prefix": pfx,
"Route": p,
}).Debug("AddPath to locRIB")
routeExisted := false routeExisted := false
oldRoute := &route.Route{} oldRoute := &route.Route{}
r := a.rt.Get(pfx) r := a.rt.Get(pfx)
...@@ -70,6 +75,10 @@ func (a *LocRIB) RemovePath(pfx net.Prefix, p *route.Path) bool { ...@@ -70,6 +75,10 @@ func (a *LocRIB) RemovePath(pfx net.Prefix, p *route.Path) bool {
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
logrus.WithFields(map[string]interface{}{
"Prefix": pfx,
"Route": p,
}).Debug("Remove from locRIB")
var oldRoute *route.Route var oldRoute *route.Route
r := a.rt.Get(pfx) r := a.rt.Get(pfx)
if r != nil { if r != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment