summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/bmp.go21
-rw-r--r--server/fsm.go11
-rw-r--r--server/server.go14
3 files changed, 29 insertions, 17 deletions
diff --git a/server/bmp.go b/server/bmp.go
index 2e9db698..91507cd3 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -205,17 +205,12 @@ func (b *bmpClient) loop() {
}
}
case *WatchEventPeerState:
- info := &table.PeerInfo{
- Address: msg.PeerAddress,
- AS: msg.PeerAS,
- ID: msg.PeerID,
- }
if msg.State == bgp.BGP_FSM_ESTABLISHED {
- if err := write(bmpPeerUp(msg.LocalAddress.String(), msg.LocalPort, msg.PeerPort, msg.SentOpen, msg.RecvOpen, bmp.BMP_PEER_TYPE_GLOBAL, false, 0, info, msg.Timestamp.Unix())); err != nil {
+ if err := write(bmpPeerUp(msg, bmp.BMP_PEER_TYPE_GLOBAL, false, 0)); err != nil {
return false
}
} else {
- if err := write(bmpPeerDown(bmp.BMP_PEER_DOWN_REASON_UNKNOWN, bmp.BMP_PEER_TYPE_GLOBAL, false, 0, info, msg.Timestamp.Unix())); err != nil {
+ if err := write(bmpPeerDown(msg, bmp.BMP_PEER_TYPE_GLOBAL, false, 0)); err != nil {
return false
}
}
@@ -264,22 +259,22 @@ type bmpClient struct {
ribout ribout
}
-func bmpPeerUp(laddr string, lport, rport uint16, sent, recv *bgp.BGPMessage, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bmp.BMPMessage {
+func bmpPeerUp(ev *WatchEventPeerState, t uint8, policy bool, pd uint64) *bmp.BMPMessage {
var flags uint8 = 0
if policy {
flags |= bmp.BMP_PEER_FLAG_POST_POLICY
}
- ph := bmp.NewBMPPeerHeader(t, flags, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
- return bmp.NewBMPPeerUpNotification(*ph, laddr, lport, rport, sent, recv)
+ ph := bmp.NewBMPPeerHeader(t, flags, pd, ev.PeerAddress.String(), ev.PeerAS, ev.PeerID.String(), float64(ev.Timestamp.Unix()))
+ return bmp.NewBMPPeerUpNotification(*ph, ev.LocalAddress.String(), ev.LocalPort, ev.PeerPort, ev.SentOpen, ev.RecvOpen)
}
-func bmpPeerDown(reason uint8, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bmp.BMPMessage {
+func bmpPeerDown(ev *WatchEventPeerState, t uint8, policy bool, pd uint64) *bmp.BMPMessage {
var flags uint8 = 0
if policy {
flags |= bmp.BMP_PEER_FLAG_POST_POLICY
}
- ph := bmp.NewBMPPeerHeader(t, flags, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
- return bmp.NewBMPPeerDownNotification(*ph, reason, nil, []byte{})
+ 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)
}
func bmpPeerRoute(t uint8, policy bool, pd uint64, fourBytesAs bool, peeri *table.PeerInfo, timestamp int64, payload []byte) *bmp.BMPMessage {
diff --git a/server/fsm.go b/server/fsm.go
index d655f768..10eba37e 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -34,6 +34,17 @@ import (
"github.com/osrg/gobgp/table"
)
+type PeerDownReason int
+
+const (
+ PEER_DOWN_REASON_UNKNOWN PeerDownReason = iota
+ PEER_DOWN_BY_LOCAL
+ PEER_DOWN_BY_LOCAL_WITHOUT_NOTIFICATION
+ PEER_DOWN_BY_REMOTE
+ PEER_DOWN_BY_REMOTE_WITHOUT_NOTIFICATION
+ PEER_DOWN_BY_BMP_CONFIGURATION
+)
+
type FsmStateReason string
const (
diff --git a/server/server.go b/server/server.go
index 82b6ee4b..7692ae4b 100644
--- a/server/server.go
+++ b/server/server.go
@@ -708,12 +708,12 @@ func (server *BgpServer) notifyPostPolicyUpdateWatcher(peer *Peer, pathList []*t
server.notifyWatcher(WATCH_EVENT_TYPE_POST_UPDATE, ev)
}
-func createWatchEventPeerState(peer *Peer) *WatchEventPeerState {
+func newWatchEventPeerState(peer *Peer, m *FsmMsg) *WatchEventPeerState {
_, rport := peer.fsm.RemoteHostPort()
laddr, lport := peer.fsm.LocalHostPort()
sentOpen := buildopen(peer.fsm.gConf, peer.fsm.pConf)
recvOpen := peer.fsm.recvOpen
- return &WatchEventPeerState{
+ e := &WatchEventPeerState{
PeerAS: peer.fsm.peerInfo.AS,
LocalAS: peer.fsm.peerInfo.LocalAS,
PeerAddress: peer.fsm.peerInfo.Address,
@@ -728,12 +728,17 @@ func createWatchEventPeerState(peer *Peer) *WatchEventPeerState {
Timestamp: time.Now(),
PeerInterface: peer.fsm.pConf.Config.NeighborInterface,
}
+
+ if m != nil {
+ e.StateReason = m.StateReason
+ }
+ return e
}
func (server *BgpServer) broadcastPeerState(peer *Peer, oldState bgp.FSMState) {
newState := peer.fsm.state
if oldState == bgp.BGP_FSM_ESTABLISHED || newState == bgp.BGP_FSM_ESTABLISHED {
- server.notifyWatcher(WATCH_EVENT_TYPE_PEER_STATE, createWatchEventPeerState(peer))
+ server.notifyWatcher(WATCH_EVENT_TYPE_PEER_STATE, newWatchEventPeerState(peer))
}
}
@@ -2651,6 +2656,7 @@ type WatchEventPeerState struct {
SentOpen *bgp.BGPMessage
RecvOpen *bgp.BGPMessage
State bgp.FSMState
+ StateReason *FsmStateReason
AdminState AdminState
Timestamp time.Time
PeerInterface string
@@ -2895,7 +2901,7 @@ func (s *BgpServer) Watch(opts ...WatchOption) (w *Watcher) {
if peer.fsm.state != bgp.BGP_FSM_ESTABLISHED {
continue
}
- w.notify(createWatchEventPeerState(peer))
+ w.notify(newWatchEventPeerState(peer))
}
}
if w.opts.initBest && s.active() == nil {