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

Merge pull request #30 from hikhvar/feature/tame-logging

Feature: Use logrus everywhere instead of fmt.Printf
parents cb072c17 052e6cd0
Branches
Tags
No related merge requests found
......@@ -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()
......
......@@ -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()
......
......@@ -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")
}
}
......
......@@ -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
......
......@@ -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
}
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment