summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-12 22:40:34 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-05-12 22:40:34 +0900
commit3b6fe71343ab742dfdea5aab8cdcb47b6652e096 (patch)
tree7485ce5312e27b72336951c60100341f3a5b28e5 /server
parent43e65c0a13e07e37dcdaa287b858cdd539c55d60 (diff)
server: add logging about peer up/down
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/fsm.go22
-rw-r--r--server/server.go2
2 files changed, 23 insertions, 1 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 42f2005a..0cbdd84e 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -188,6 +188,7 @@ type FSMHandler struct {
incoming chan *fsmMsg
outgoing chan *bgp.BGPMessage
holdTimerResetCh chan bool
+ reason string
}
func NewFSMHandler(fsm *FSM, incoming chan *fsmMsg, outgoing chan *bgp.BGPMessage) *FSMHandler {
@@ -395,6 +396,8 @@ func (h *FSMHandler) recvMessageWithError() error {
if len(h.holdTimerResetCh) == 0 {
h.holdTimerResetCh <- true
}
+ } else if m.Header.Type == bgp.BGP_MSG_NOTIFICATION {
+ h.reason = "Notification received"
}
}
}
@@ -630,6 +633,7 @@ func (h *FSMHandler) sendMessageloop() error {
}).Warn("sent notification")
h.errorCh <- true
+ h.reason = "Notificaiton sent"
conn.Close()
return fmt.Errorf("closed")
} else {
@@ -717,6 +721,7 @@ func (h *FSMHandler) established() bgp.FSMState {
case <-h.errorCh:
h.conn.Close()
h.t.Kill(nil)
+ h.reason = "Peer closed the session"
return bgp.BGP_FSM_IDLE
case <-holdTimer.C:
log.WithFields(log.Fields{
@@ -726,6 +731,7 @@ func (h *FSMHandler) established() bgp.FSMState {
}).Warn("hold timer expired")
m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, 0, nil)
h.outgoing <- m
+ h.reason = "HoldTimer expired"
return bgp.BGP_FSM_IDLE
case <-h.holdTimerResetCh:
if fsm.negotiatedHoldTime != 0 {
@@ -749,6 +755,7 @@ func (h *FSMHandler) established() bgp.FSMState {
func (h *FSMHandler) loop() error {
fsm := h.fsm
nextState := bgp.FSMState(0)
+ oldState := fsm.state
switch fsm.state {
case bgp.BGP_FSM_IDLE:
nextState = h.idle()
@@ -764,6 +771,21 @@ func (h *FSMHandler) loop() error {
nextState = h.established()
}
+ if nextState == bgp.BGP_FSM_ESTABLISHED && oldState == bgp.BGP_FSM_OPENCONFIRM {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": fsm.peerConfig.NeighborAddress,
+ }).Info("Peer Up")
+ }
+
+ if oldState == bgp.BGP_FSM_ESTABLISHED {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": fsm.peerConfig.NeighborAddress,
+ "Reason": h.reason,
+ }).Info("Peer Down")
+ }
+
// zero means that tomb.Dying()
if nextState >= bgp.BGP_FSM_IDLE {
e := &fsmMsg{
diff --git a/server/server.go b/server/server.go
index b2096d49..443a4ba2 100644
--- a/server/server.go
+++ b/server/server.go
@@ -150,7 +150,7 @@ func (server *BgpServer) Serve() {
remoteAddr, _, _ := net.SplitHostPort(conn.RemoteAddr().String())
info, found := server.peerMap[remoteAddr]
if found {
- log.Info("accepted a new passive connection from ", remoteAddr)
+ log.Debug("accepted a new passive connection from ", remoteAddr)
info.peer.PassConn(conn)
} else {
log.Info("can't find configuration for a new passive connection from ", remoteAddr)