summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packet/bmp/bmp.go23
-rw-r--r--packet/bmp/bmp_test.go8
-rw-r--r--server/bmp.go18
3 files changed, 30 insertions, 19 deletions
diff --git a/packet/bmp/bmp.go b/packet/bmp/bmp.go
index 55481bcb..7cf4f5e6 100644
--- a/packet/bmp/bmp.go
+++ b/packet/bmp/bmp.go
@@ -71,27 +71,23 @@ func (h *BMPHeader) Serialize() ([]byte, error) {
type BMPPeerHeader struct {
PeerType uint8
- IsPostPolicy bool
+ Flags uint8
PeerDistinguisher uint64
PeerAddress net.IP
PeerAS uint32
PeerBGPID net.IP
Timestamp float64
- Flags uint8
}
-func NewBMPPeerHeader(t uint8, policy bool, dist uint64, address string, as uint32, id string, stamp float64) *BMPPeerHeader {
+func NewBMPPeerHeader(t uint8, flags uint8, dist uint64, address string, as uint32, id string, stamp float64) *BMPPeerHeader {
h := &BMPPeerHeader{
PeerType: t,
- IsPostPolicy: policy,
+ Flags: flags,
PeerDistinguisher: dist,
PeerAS: as,
PeerBGPID: net.ParseIP(id).To4(),
Timestamp: stamp,
}
- if policy == true {
- h.Flags |= BMP_PEER_FLAG_POST_POLICY
- }
if net.ParseIP(address).To4() != nil {
h.PeerAddress = net.ParseIP(address).To4()
} else {
@@ -101,14 +97,17 @@ func NewBMPPeerHeader(t uint8, policy bool, dist uint64, address string, as uint
return h
}
-func (h *BMPPeerHeader) DecodeFromBytes(data []byte) error {
- h.PeerType = data[0]
- h.Flags = data[1]
+func (h *BMPPeerHeader) IsPostPolicy() bool {
if h.Flags&BMP_PEER_FLAG_POST_POLICY != 0 {
- h.IsPostPolicy = true
+ return true
} else {
- h.IsPostPolicy = false
+ return false
}
+}
+
+func (h *BMPPeerHeader) DecodeFromBytes(data []byte) error {
+ h.PeerType = data[0]
+ h.Flags = data[1]
h.PeerDistinguisher = binary.BigEndian.Uint64(data[2:10])
if h.Flags&BMP_PEER_FLAG_IPV6 != 0 {
h.PeerAddress = net.IP(data[10:26]).To16()
diff --git a/packet/bmp/bmp_test.go b/packet/bmp/bmp_test.go
index dd7391aa..3d7737e0 100644
--- a/packet/bmp/bmp_test.go
+++ b/packet/bmp/bmp_test.go
@@ -48,14 +48,14 @@ func Test_Initiation(t *testing.T) {
func Test_PeerUpNotification(t *testing.T) {
m := bgp.NewTestBGPOpenMessage()
- p0 := NewBMPPeerHeader(0, false, 1000, "10.0.0.1", 70000, "10.0.0.2", 1)
+ p0 := NewBMPPeerHeader(0, 0, 1000, "10.0.0.1", 70000, "10.0.0.2", 1)
verify(t, NewBMPPeerUpNotification(*p0, "10.0.0.3", 10, 100, m, m))
- p1 := NewBMPPeerHeader(0, false, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1)
+ p1 := NewBMPPeerHeader(0, 0, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1)
verify(t, NewBMPPeerUpNotification(*p1, "fe80::6e40:8ff:feab:2c2a", 10, 100, m, m))
}
func Test_PeerDownNotification(t *testing.T) {
- p0 := NewBMPPeerHeader(0, false, 1000, "10.0.0.1", 70000, "10.0.0.2", 1)
+ p0 := NewBMPPeerHeader(0, 0, 1000, "10.0.0.1", 70000, "10.0.0.2", 1)
verify(t, NewBMPPeerDownNotification(*p0, BMP_PEER_DOWN_REASON_UNKNOWN, nil, []byte{0x3, 0xb}))
m := bgp.NewBGPNotificationMessage(1, 2, nil)
verify(t, NewBMPPeerDownNotification(*p0, BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION, m, nil))
@@ -63,7 +63,7 @@ func Test_PeerDownNotification(t *testing.T) {
func Test_RouteMonitoring(t *testing.T) {
m := bgp.NewTestBGPUpdateMessage()
- p0 := NewBMPPeerHeader(0, false, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1)
+ p0 := NewBMPPeerHeader(0, 0, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1)
verify(t, NewBMPRouteMonitoring(*p0, m))
}
diff --git a/server/bmp.go b/server/bmp.go
index 154175c5..6f1a16ee 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -198,17 +198,29 @@ type bmpClient struct {
}
func bmpPeerUp(laddr string, lport, rport uint16, sent, recv *bgp.BGPMessage, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bmp.BMPMessage {
- ph := bmp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
+ 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)
}
func bmpPeerDown(reason uint8, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bmp.BMPMessage {
- ph := bmp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
+ 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{})
}
func bmpPeerRoute(t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64, payload []byte) *bmp.BMPMessage {
- ph := bmp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
+ 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))
m := bmp.NewBMPRouteMonitoring(*ph, nil)
body := m.Body.(*bmp.BMPRouteMonitoring)
body.BGPUpdatePayload = payload