summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-22 04:58:46 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-22 04:58:46 -0800
commita5874d6912e2286fa5af5dc452e3d99ebc38c7a5 (patch)
tree77724caffc72447f6b4b0d89de643fa980bbfcfa /server
parent6ecf5e15ceda5e8535727d16a3d04e35cb7f51d0 (diff)
server: use logger instead of stdout
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/fsm.go5
-rw-r--r--server/peer.go8
-rw-r--r--server/server.go16
3 files changed, 13 insertions, 16 deletions
diff --git a/server/fsm.go b/server/fsm.go
index e0e26ce9..9dab59e2 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -16,7 +16,7 @@
package server
import (
- "fmt"
+ log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"github.com/osrg/gobgp/table"
@@ -96,7 +96,7 @@ func (fsm *FSM) StateChanged() chan int {
}
func (fsm *FSM) StateChange(nextState int) {
- fmt.Println("state changed", nextState, fsm.state)
+ log.Debugf("Peer (%v) state changed from %v to %v", fsm.peerConfig.NeighborAddress, nextState, fsm.state)
fsm.state = nextState
}
@@ -393,7 +393,6 @@ func (h *FSMHandler) loop() error {
}
if nextState == bgp.BGP_FSM_ESTABLISHED {
- fmt.Println("new peerinfo")
// everytime we go into BGP_FSM_ESTABLISHED, we create
// a PeerInfo because sourceNum could be incremented
fsm.createPeerInfo()
diff --git a/server/peer.go b/server/peer.go
index 3c852ccf..a28e94b6 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -17,7 +17,7 @@ package server
import (
"encoding/json"
- "fmt"
+ log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
"github.com/osrg/gobgp/table"
@@ -62,7 +62,7 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *mes
func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) {
j, _ := json.Marshal(m)
- fmt.Println(string(j))
+ log.Info(string(j))
// TODO: update state here
if m.Header.Type != bgp.BGP_MSG_UPDATE {
@@ -136,8 +136,8 @@ func (peer *Peer) loop() error {
case nextState := <-peer.fsm.StateChanged():
// waits for all goroutines created for the current state
h.Wait()
- oldState := peer.fsm.state
- peer.fsm.state = nextState
+ oldState := peer.state
+ peer.state = nextState
peer.fsm.StateChange(nextState)
sameState = false
// TODO: check peer's rf
diff --git a/server/server.go b/server/server.go
index bca36afa..01daa23a 100644
--- a/server/server.go
+++ b/server/server.go
@@ -17,6 +17,7 @@ package server
import (
"fmt"
+ log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
"net"
@@ -67,7 +68,7 @@ func (server *BgpServer) Serve() {
l, err := net.ListenTCP("tcp4", addr)
if err != nil {
- fmt.Println(err)
+ log.Fatal(err)
os.Exit(1)
}
@@ -76,7 +77,7 @@ func (server *BgpServer) Serve() {
for {
conn, err := l.Accept()
if err != nil {
- fmt.Println(err)
+ log.Info(err)
continue
}
acceptCh <- conn.(*net.TCPConn)
@@ -89,33 +90,30 @@ func (server *BgpServer) Serve() {
f, _ := l.File()
select {
case conn := <-acceptCh:
- fmt.Println(conn)
remoteAddr := strings.Split(conn.RemoteAddr().String(), ":")[0]
peer, found := server.peerMap[remoteAddr]
if found {
- fmt.Println("found neighbor", remoteAddr)
+ log.Info("accepted a new passive connection for", remoteAddr)
peer.PassConn(conn)
} else {
- fmt.Println("can't found neighbor", remoteAddr)
+ log.Info("can't find configuration for a new passive connection", remoteAddr)
conn.Close()
}
case peer := <-server.addedPeerCh:
- fmt.Println(peer)
addr := peer.NeighborAddress.String()
SetTcpMD5SigSockopts(int(f.Fd()), addr, peer.AuthPassword)
p := NewPeer(server.bgpConfig.Global, peer, broadcastCh)
server.peerMap[peer.NeighborAddress.String()] = p
case peer := <-server.deletedPeerCh:
- fmt.Println(peer)
addr := peer.NeighborAddress.String()
SetTcpMD5SigSockopts(int(f.Fd()), addr, "")
p, found := server.peerMap[addr]
if found {
- fmt.Println("found neighbor", addr)
+ log.Info("Delete a peer configuration for", addr)
p.Stop()
delete(server.peerMap, addr)
} else {
- fmt.Println("can't found neighbor", addr)
+ log.Info("Can't delete a peer configuration for", addr)
}
case restReq := <-server.RestReqCh:
server.handleRest(restReq)