From 93c955a415f39f7f8d2a97a8298a8985d5dadc2f Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Tue, 4 Apr 2017 15:42:35 +0900 Subject: packet/bmp: Obsolete policy argument for BMPPeerHeader According to "draft-evens-grow-bmp-local-rib", the L flag in the Peer Flags is NOT used for the locally sourced routes and the F flag is defined into the same bit. This patch removes "policy" argument and add "flags" argument for BMPPeerHeader and NewBMPPeerHeader in order to distinguish which flag is set (the L flag or the F flag). Then introduce IsPostPolicy() func to show if the L flag is set or not. Signed-off-by: IWASE Yusuke --- packet/bmp/bmp.go | 23 +++++++++++------------ packet/bmp/bmp_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'packet/bmp') 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)) } -- cgit v1.2.3