Skip to content

Commit

Permalink
server: Fix peer down reason code in BMP
Browse files Browse the repository at this point in the history
  • Loading branch information
a16 committed Jan 11, 2019
1 parent 98d8925 commit 61d7a5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
14 changes: 13 additions & 1 deletion pkg/server/bmp.go
Expand Up @@ -277,7 +277,19 @@ func bmpPeerDown(ev *watchEventPeerState, t uint8, policy bool, pd uint64) *bmp.
flags |= bmp.BMP_PEER_FLAG_POST_POLICY
}
ph := bmp.NewBMPPeerHeader(t, flags, pd, ev.PeerAddress.String(), ev.PeerAS, ev.PeerID.String(), float64(ev.Timestamp.Unix()))
return bmp.NewBMPPeerDownNotification(*ph, uint8(ev.StateReason.peerDownReason), ev.StateReason.BGPNotification, ev.StateReason.Data)

reasonCode := bmp.BMP_peerDownByUnknownReason
switch ev.StateReason.Type {
case fsmDying, fsmInvalidMsg, fsmNotificationSent, fsmHoldTimerExpired, fsmIdleTimerExpired, fsmRestartTimerExpired:
reasonCode = bmp.BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION
case fsmAdminDown:
reasonCode = bmp.BMP_PEER_DOWN_REASON_LOCAL_NO_NOTIFICATION
case fsmNotificationRecv, fsmGracefulRestart, fsmHardReset:
reasonCode = bmp.BMP_PEER_DOWN_REASON_REMOTE_BGP_NOTIFICATION
case fsmReadFailed, fsmWriteFailed:
reasonCode = bmp.BMP_PEER_DOWN_REASON_REMOTE_NO_NOTIFICATION
}
return bmp.NewBMPPeerDownNotification(*ph, uint8(reasonCode), ev.StateReason.BGPNotification, ev.StateReason.Data)
}

func bmpPeerRoute(t uint8, policy bool, pd uint64, fourBytesAs bool, peeri *table.PeerInfo, timestamp int64, payload []byte) *bmp.BMPMessage {
Expand Down
23 changes: 0 additions & 23 deletions pkg/server/fsm.go
Expand Up @@ -39,15 +39,6 @@ const (
minConnectRetryInterval = 10
)

type peerDownReason int

const (
peerDownByLocal peerDownReason = iota
peerDownByLocalWithoutNotification
peerDownByRemote
peerDownByRemoteWithoutNotification
)

type fsmStateReasonType uint8

const (
Expand All @@ -70,26 +61,13 @@ const (

type fsmStateReason struct {
Type fsmStateReasonType
peerDownReason peerDownReason
BGPNotification *bgp.BGPMessage
Data []byte
}

func newfsmStateReason(typ fsmStateReasonType, notif *bgp.BGPMessage, data []byte) *fsmStateReason {
var reasonCode peerDownReason
switch typ {
case fsmDying, fsmInvalidMsg, fsmNotificationSent, fsmHoldTimerExpired, fsmIdleTimerExpired, fsmRestartTimerExpired:
reasonCode = peerDownByLocal
case fsmAdminDown:
reasonCode = peerDownByLocalWithoutNotification
case fsmNotificationRecv, fsmGracefulRestart, fsmHardReset:
reasonCode = peerDownByRemote
case fsmReadFailed, fsmWriteFailed:
reasonCode = peerDownByRemoteWithoutNotification
}
return &fsmStateReason{
Type: typ,
peerDownReason: reasonCode,
BGPNotification: notif,
Data: data,
}
Expand Down Expand Up @@ -1892,7 +1870,6 @@ func (h *fsmHandler) loop(ctx context.Context, wg *sync.WaitGroup) error {
reason := fsm.reason
if fsm.h.sentNotification != nil {
reason.Type = fsmNotificationSent
reason.peerDownReason = peerDownByLocal
reason.BGPNotification = fsm.h.sentNotification
}
log.WithFields(log.Fields{
Expand Down

0 comments on commit 61d7a5e

Please sign in to comment.