diff options
Diffstat (limited to 'packet/bmp')
-rw-r--r-- | packet/bmp/bmp.go | 23 | ||||
-rw-r--r-- | packet/bmp/bmp_test.go | 8 |
2 files changed, 15 insertions, 16 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)) } |