diff --git a/main.go b/main.go index 7e19a5aa8d1e0d982435fe12dd8229eecfbb1a35..3e0598bce10567ead6b30ea7f9e1caeebeafdcf3 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) func main() { - fmt.Printf("This is a BGP speaker\n") + logrus.Printf("This is a BGP speaker\n") rib := locRIB.New() b := server.NewBgpServer() diff --git a/protocols/bgp/server/fsm.go b/protocols/bgp/server/fsm.go index f8f20547ce53cbad2fd7d7c02de64a8e80aa1e90..2a9f89dc96eba5d33ae21896452c1abca73249da 100644 --- a/protocols/bgp/server/fsm.go +++ b/protocols/bgp/server/fsm.go @@ -646,7 +646,7 @@ func (fsm *FSM) openConfirm() int { case recvMsg := <-fsm.msgRecvCh: msg, err := packet.Decode(bytes.NewBuffer(recvMsg.msg)) 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) { case packet.BGPError: sendNotification(fsm.con, bgperr.ErrorCode, bgperr.ErrorSubCode) @@ -789,7 +789,8 @@ func (fsm *FSM) established() int { case recvMsg := <-fsm.msgRecvCh: msg, err := packet.Decode(bytes.NewBuffer(recvMsg.msg)) if err != nil { - fmt.Printf("Failed to decode BGP message: %v\n", recvMsg.msg) + log.WithError(err).Errorf("Failed to decode BGP message %v\n", recvMsg.msg) + switch bgperr := err.(type) { case packet.BGPError: sendNotification(fsm.con, bgperr.ErrorCode, bgperr.ErrorSubCode) @@ -814,14 +815,13 @@ func (fsm *FSM) established() int { for r := u.WithdrawnRoutes; r != nil; r = r.Next { 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) } for r := u.NLRI; r != nil; r = r.Next { 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{ Type: route.BGPPathType, BGPPath: &route.BGPPath{ @@ -830,7 +830,6 @@ func (fsm *FSM) established() int { } for pa := u.PathAttributes; pa != nil; pa = pa.Next { - fmt.Printf("TypeCode: %d\n", pa.TypeCode) switch pa.TypeCode { case packet.OriginAttr: path.BGPPath.Origin = pa.Value.(uint8) @@ -839,7 +838,7 @@ func (fsm *FSM) established() int { case packet.MEDAttr: path.BGPPath.MED = pa.Value.(uint32) 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) case packet.ASPathAttr: path.BGPPath.ASPath = pa.ASPathString() diff --git a/protocols/bgp/server/server.go b/protocols/bgp/server/server.go index f50def76491201ff604a098195fb658d08dbb769..a6025140fd62f81d8fa503aeb0c31114a7589f2b 100644 --- a/protocols/bgp/server/server.go +++ b/protocols/bgp/server/server.go @@ -39,7 +39,7 @@ func (b *BGPServer) Start(c *config.Global) error { 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 if c.Listen { @@ -62,8 +62,6 @@ func (b *BGPServer) Start(c *config.Global) error { func (b *BGPServer) incomingConnectionWorker() { for { c := <-b.acceptCh - fmt.Printf("Incoming connection!\n") - fmt.Printf("Connection from: %v\n", c.RemoteAddr()) peerAddr := strings.Split(c.RemoteAddr().String(), ":")[0] if _, ok := b.peers[peerAddr]; !ok { @@ -78,9 +76,9 @@ func (b *BGPServer) incomingConnectionWorker() { "source": c.RemoteAddr(), }).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 - fmt.Printf("DEBUG: Sending done\n") + log.Debug("Sending done") } } diff --git a/routingtable/adjRIBIn/adj_rib_in.go b/routingtable/adjRIBIn/adj_rib_in.go index 1427278bbd5aa6c465c16bf2ac4e1462fd5a34d8..cd4dde58f17e42d9bf75433850dfa39bf2498fbf 100644 --- a/routingtable/adjRIBIn/adj_rib_in.go +++ b/routingtable/adjRIBIn/adj_rib_in.go @@ -6,6 +6,7 @@ import ( "github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/routingtable" + log "github.com/sirupsen/logrus" ) // AdjRIBIn represents an Adjacency RIB In as described in RFC4271 @@ -33,7 +34,11 @@ func (a *AdjRIBIn) UpdateNewClient(client routingtable.RouteTableClient) error { for _, route := range routes { paths := route.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 diff --git a/routingtable/adjRIBOut/adj_rib_out.go b/routingtable/adjRIBOut/adj_rib_out.go index 1ddd93c6e05b835c9952b6e86ba5fe57545ed5e4..51347119a6b360fd2f81283edc18d9225548fdf2 100644 --- a/routingtable/adjRIBOut/adj_rib_out.go +++ b/routingtable/adjRIBOut/adj_rib_out.go @@ -7,6 +7,7 @@ import ( "github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/routingtable" + log "github.com/sirupsen/logrus" ) // 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 { a.removePathsFromClients(pfx, oldPaths) 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 } diff --git a/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go b/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go index 2b4dff95575b2df72036642f40bd69cfedb4e5ab..90f76fcc873643a6d94086b0b84f5bf940b6fa9f 100644 --- a/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go +++ b/routingtable/adjRIBOutAddPath/adj_rib_out_add_path.go @@ -7,6 +7,7 @@ import ( "github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/routingtable" + log "github.com/sirupsen/logrus" ) // 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 { a.rt.AddPath(pfx, p) 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 }