Documentation
¶
Overview ¶
Package bmp supports BGP Monitoring Protocol (RFC 7854)
Index ¶
- Constants
- Variables
- type Bmp
- type MsgType
- type OpenBmp
- func (o *OpenBmp) CopyData() *OpenBmp
- func (o *OpenBmp) FromBmp(bm *Bmp, m *msg.Msg) error
- func (o *OpenBmp) FromBytes(raw []byte) (int, error)
- func (o *OpenBmp) IsBmpRaw() bool
- func (o *OpenBmp) IsRouterIPv6() bool
- func (o *OpenBmp) IsRouterMessage() bool
- func (o *OpenBmp) Marshal() error
- func (o *OpenBmp) Reset() *OpenBmp
- func (o *OpenBmp) WriteTo(w io.Writer) (int64, error)
- type Peer
- type Reader
- func (br *Reader) FromBytes(buf []byte, bgp_msg *msg.Msg, bmp_msg *Bmp, obmp_msg *OpenBmp) (n int, err error)
- func (br *Reader) ReadFrom(r io.Reader) (n int64, err error)
- func (br *Reader) Write(src []byte) (n int, err error)
- func (br *Reader) WriteFunc(src []byte, cb pipe.CallbackFunc) (n int, err error)
- type ReaderStats
Constants ¶
const ( OPENBMP_MAGIC = "OBMP" OPENBMP_VERSION = 0x01 // protocol version OPENBMP_HEADLEN = 14 // minimum header length to read basic fields OPENBMP_FLAG_V6 = 0x40 // router IP is IPv6 OPENBMP_FLAG_RTYPE = 0x80 // router message (vs collector message) OPENBMP_OBJ_RAW = 12 // object type for BMP_RAW OPENBMP_OBJ_ROUTER = 1 // object type for router OPENBMP_OBJ_PEER = 2 // object type for peer )
OpenBMP header constants
const ( PEER_TYPE_GLOBAL uint8 = 0 // Global Instance Peer PEER_TYPE_RD uint8 = 1 // RD Instance Peer PEER_TYPE_LOCAL uint8 = 2 // Local Instance Peer PEER_TYPE_LOC_RIB uint8 = 3 // Loc-RIB Instance Peer (RFC 9069) )
Peer Types (https://www.iana.org/assignments/bmp-parameters/)
const ( PEER_FLAG_V6 = 0x80 // V flag: IPv6 (1) or IPv4 (0) PEER_FLAG_L = 0x40 // L flag: post-policy (1) or pre-policy (0) PEER_FLAG_A = 0x20 // A flag: legacy 2-byte AS path format (1) or 4-byte AS (0) PEER_FLAG_O = 0x10 // O flag: Adj-RIB-Out (1) or Adj-RIB-In (0) (RFC 8671) )
Peer Flags (RFC 7854 section 4.2, RFC 8671)
const HEADLEN = 6 // version(1) + length(4) + type(1)
BMP common header length (RFC 7854 section 4.1)
const PEER_HEADLEN = 42
Per-Peer header length (RFC 7854 section 4.2)
const VERSION = 3
BMP protocol version
Variables ¶
var ( ErrShort = errors.New("message too short") ErrLength = errors.New("invalid length") ErrVersion = errors.New("invalid BMP version") // OpenBMP errors ErrOpenBmpMagic = errors.New("invalid OpenBMP magic") ErrOpenBmpVersion = errors.New("unsupported OpenBMP version") ErrOpenBmpRowCount = errors.New("invalid OpenBMP row count") // Reader errors ErrNotRouteMonitoring = errors.New("not a Route Monitoring message") ErrNoBgpData = errors.New("no BGP data in message") // Writer errors ErrNoData = errors.New("no data to write") )
Functions ¶
This section is empty.
Types ¶
type Bmp ¶
type Bmp struct {
Version uint8 // BMP version (should be 3)
Length uint32 // Total message length
Type MsgType // Message type
Peer Peer // Per-Peer Header (for types 0,1,2,3)
BgpData []byte // raw BGP message (for Route Monitoring)
// contains filtered or unexported fields
}
Bmp represents a BMP message (RFC 7854)
func (*Bmp) FromBytes ¶
FromBytes parses the BMP message from raw bytes. Does not copy data. Returns the number of bytes consumed.
func (*Bmp) FromMsg ¶ added in v0.16.2
FromMsg populates BMP ROUTE_MONITORING from BGP message m. m must already be marshaled. Extracts peer info from message tags.
func (*Bmp) HasPerPeerHeader ¶
HasPerPeerHeader returns true if this message type has a Per-Peer header
type MsgType ¶
type MsgType uint8
MsgType represents BMP message type (RFC 7854 section 4.1)
const ( MSG_ROUTE_MONITORING MsgType = 0 // Route Monitoring MSG_STATISTICS_REPORT MsgType = 1 // Statistics Report MSG_PEER_DOWN MsgType = 2 // Peer Down Notification MSG_PEER_UP MsgType = 3 // Peer Up Notification MSG_INITIATION MsgType = 4 // Initiation Message MSG_TERMINATION MsgType = 5 // Termination Message MSG_ROUTE_MIRRORING MsgType = 6 // Route Mirroring )
type OpenBmp ¶
type OpenBmp struct {
Version uint8 // protocol version (major.minor encoded: major=byte5, minor=byte6)
Minor uint8 // version minor
HeaderLen uint16 // total header length
DataLen uint32 // BMP message length
Flags uint8 // message flags
ObjType uint8 // object type (12 = BMP_RAW)
// Timestamps from OpenBMP header (not from BMP peer header)
Time time.Time
// Collector info
CollectorHash [16]byte
CollectorName string
// Router info
RouterHash [16]byte
RouterIP netip.Addr
RouterName string
// BMP message data
Data []byte
// contains filtered or unexported fields
}
OpenBmp represents an OpenBMP message header (used by RouteViews Kafka streams). See: https://github.com/SNAS/openbmp and https://www.openbmp.org/api/kafka_message_schema.html
Binary header format v1.7:
OBMP (4 bytes): Magic number Major (1 byte): Version major (should be 1) Minor (1 byte): Version minor (7 for bmp_raw) Header Length (2 bytes BE): Total header length Data Length (4 bytes BE): BMP message length that follows Flags (1 byte): 0x80=router msg, 0x40=IPv6 Object Type (1 byte): 12=BMP_RAW, 1=router, 2=peer, etc. Timestamp sec (4 bytes BE) Timestamp usec (4 bytes BE) Collector Hash (16 bytes): MD5 hash Collector Name Len (2 bytes BE) Collector Name (variable) Router Hash (16 bytes): MD5 hash Router IP (16 bytes): IPv4 (last 4 bytes) or IPv6 Router Name Len (2 bytes BE) Router Name (variable) Row Count (4 bytes): ignored [at offset HeaderLen]: BMP Message (DataLen bytes)
func (*OpenBmp) FromBmp ¶ added in v0.16.2
FromBmp wraps marshaled BMP message for OpenBMP output. bm must already be marshaled. Extracts collector/router from message tags.
func (*OpenBmp) FromBytes ¶
FromBytes parses the OpenBMP message from raw bytes. Does not copy data. Returns the number of bytes consumed.
func (*OpenBmp) IsRouterIPv6 ¶
IsRouterIPv6 returns true if the router IP is IPv6
func (*OpenBmp) IsRouterMessage ¶
IsRouterMessage returns true if this is a router message (vs collector)
type Peer ¶
type Peer struct {
Type uint8 // Peer Type (0=Global, 1=RD, 2=Local, 3=Loc-RIB)
Flags uint8 // Peer Flags
RD uint64 // Peer Distinguisher (Route Distinguisher for type 1)
Address netip.Addr // Peer IP Address
AS uint32 // Peer AS Number
ID uint32 // Peer BGP ID
Time time.Time // Timestamp
}
Peer represents BMP Per-Peer Header (RFC 7854 section 4.2)
func (*Peer) FromBytes ¶
FromBytes parses the Per-Peer header from raw bytes. Returns the number of bytes consumed.
func (*Peer) IsAdjRibOut ¶
IsAdjRibOut returns true if this is Adj-RIB-Out data (RFC 8671)
func (*Peer) IsPostPolicy ¶
IsPostPolicy returns true if this is post-policy data
type Reader ¶
type Reader struct {
OpenBMP bool // true if reading OpenBMP-wrapped format
NoTags bool // ignore message tags?
Stats ReaderStats // our stats
// contains filtered or unexported fields
}
Reader reads BMP messages into a pipe.Input. Supports both raw BMP and OpenBMP-wrapped formats.
func (*Reader) FromBytes ¶
func (br *Reader) FromBytes(buf []byte, bgp_msg *msg.Msg, bmp_msg *Bmp, obmp_msg *OpenBmp) (n int, err error)
FromBytes parses the first BMP message in buf and references it in bgp_msg. References bytes in buf. Can be used concurrently. bmp_msg and obmp_msg may be nil, in which case new instances are created.
func (*Reader) Write ¶
Write implements io.Writer and reads all BMP messages from src into the target Input. Must not be used concurrently.
type ReaderStats ¶
type ReaderStats struct {
Parsed uint64 // parsed messages (total)
ParsedBgp uint64 // parsed BGP messages from BMP
ParsedSkip uint64 // skipped non-Route-Monitoring messages
Short uint64 // data in buffer too short, should retry
Garbled uint64 // parse error
}
ReaderStats holds reader statistics