Documentation ¶
Overview ¶
Package mrt supports BGP data in MRT format (RFC6396)
Index ¶
- Constants
- Variables
- func SubStrings() []string
- func TypeStrings() []string
- type Bgp4
- type Mrt
- func (mrt *Mrt) CopyData() *Mrt
- func (mrt *Mrt) FromBytes(raw []byte) (off int, err error)
- func (mrt *Mrt) Length() int
- func (mrt *Mrt) Marshal() error
- func (mrt *Mrt) Parse() error
- func (mrt *Mrt) Reset() *Mrt
- func (mrt *Mrt) Use(typ Type) *Mrt
- func (mrt *Mrt) WriteTo(w io.Writer) (n int64, err error)
- type Reader
- type ReaderStats
- type Sub
- type Type
Constants ¶
const ( // MRT header length HEADLEN = 12 // = timestamp(4) + type(2) + subtype (2) + length (4) // MRT maximum data length MAXLEN = math.MaxUint32 )
const (
// minimum MRT BgpMsg header length
BGPMSG_HEADLEN = 16
)
Variables ¶
var ( ErrShort = errors.New("message too short") ErrLong = errors.New("message too long") ErrLength = errors.New("invalid length") ErrType = errors.New("invalid MRT type") ErrSub = errors.New("invalid MRT subtype") ErrAF = errors.New("invalid Address Family") ErrNoData = errors.New("no message data") ErrNoUpper = errors.New("no upper layer") )
Functions ¶
func SubStrings ¶
func SubStrings() []string
SubStrings returns a slice of all String values of the enum
func TypeStrings ¶
func TypeStrings() []string
TypeStrings returns a slice of all String values of the enum
Types ¶
type Bgp4 ¶ added in v0.2.0
type Bgp4 struct { Mrt *Mrt // parent MRT message PeerAS uint32 // peer AS LocalAS uint32 // local AS Interface uint16 // interface index PeerIP netip.Addr // peer IP address LocalIP netip.Addr // local IP address Data []byte // BGP message, referenced }
Bgp4 represents an MRT BGP4MP_MESSAGE message
func (*Bgp4) FromMsg ¶ added in v0.2.0
FromMsg copies BGP message m into BGP4MP message b4. m must already be marshaled.
func (*Bgp4) Marshal ¶ added in v0.2.0
Marshal marshals b4 to b4.Mrt.Data. Type and Sub must already be set in b4.Mrt parent.
type Mrt ¶
type Mrt struct { Time time.Time // message timestamp Type Type // message type Sub Sub // message subtype Data []byte // message data (referenced or owned), can be nil Upper Type // which of the upper layers is valid? Bgp4 Bgp4 // BGP4MP or BGP4MP_ET // contains filtered or unexported fields }
Mrt represents a bare-bones MRT message (rfc6396/2).
func (*Mrt) FromBytes ¶ added in v0.2.0
FromBytes parses the MRT message in raw. Does not copy. Returns the number of parsed bytes from raw.
func (*Mrt) Marshal ¶ added in v0.2.0
Marshal marshals the upper layer to mrt.Data iff possible and needed.
type Reader ¶
type Reader struct { NoTags bool // ignore message tags? Stats ReaderStats // our stats // contains filtered or unexported fields }
Reader reads MRT-BGP4MP messages into a pipe.Input.
func (*Reader) FromBytes ¶ added in v0.2.0
FromBytes parses the first MRT-BGP4MP message in buf, and references it in m. Does not buffer or copy buf. Can be used concurrently. mrt may be nil
func (*Reader) Write ¶
Write implements io.Writer and reads all MRT-BGP4MP messages from src into br.in. Must not be used concurrently.
type ReaderStats ¶
type ReaderStats struct { Parsed uint64 // parsed messages (total) ParsedBgp uint64 // parsed BGP4MP messages ParsedSkip uint64 // skipped non-BGP4MP messages Short uint64 // data in buffer too short, should retry Garbled uint64 // parse error }
BGP reader statistics
type Sub ¶
type Sub uint16
MRT message subtype, see https://www.iana.org/assignments/mrt/mrt.xhtml
const ( BGP4_STATE_CHANGE Sub = 0 BGP4_STATE_CHANGE_AS4 Sub = 5 BGP4_MESSAGE Sub = 1 BGP4_MESSAGE_LOCAL Sub = 6 BGP4_MESSAGE_ADDPATH Sub = 8 BGP4_MESSAGE_LOCAL_ADDPATH Sub = 10 BGP4_MESSAGE_AS4 Sub = 4 BGP4_MESSAGE_AS4_LOCAL Sub = 7 BGP4_MESSAGE_AS4_ADDPATH Sub = 9 BGP4_MESSAGE_AS4_LOCAL_ADDPATH Sub = 11 )
func SubString ¶
SubString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
type Type ¶
type Type uint16
MRT message type, see https://www.iana.org/assignments/mrt/mrt.xhtml
func TypeString ¶
TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func (Type) IsAType ¶
IsAType returns "true" if the value is listed in the enum definition. "false" otherwise