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 fc342e821871667f3d4fe7aab18e5d50e225674a..2c2e15621d8c634564612da83318c30b986fdfc9 100644 --- a/protocols/bgp/server/fsm.go +++ b/protocols/bgp/server/fsm.go @@ -647,7 +647,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) @@ -790,7 +790,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) @@ -815,14 +816,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{ @@ -831,7 +831,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) @@ -840,7 +839,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 8a11cd3a0641c6ff926ddc4459da157d7273db44..0c0bc7d20e11429904134d32d8dcf9e2b0b9b650 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") } }