mrt

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Overview

Package mrt supports BGP data in MRT format (RFC6396)

Index

Constants

View Source
const (
	// MRT header length
	HEADLEN = 12 // = timestamp(4) + type(2) + subtype (2) + length (4)

	// MRT maximum data length
	MAXLEN = math.MaxUint32
)
View Source
const (
	// minimum MRT BgpMsg header length
	BGPMSG_HEADLEN = 16
)

Variables

View Source
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")
)
View Source
var DefaultReaderOptions = ReaderOptions{
	Logger: &log.Logger,
}

Default MRT-BGP reader options

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 BgpMsg

type BgpMsg struct {
	Mrt     *Mrt       // parent MRT message
	PeerAS  uint32     // peer AS
	LocalAS uint32     // local AS
	Iface   uint16     // interface index
	PeerIP  netip.Addr // peer IP address
	LocalIP netip.Addr // local IP address
	Data    []byte     // BGP message, referenced from Mrt
}

BgpMsg represents an MRT BGP4MP message

func (*BgpMsg) Parse

func (bm *BgpMsg) Parse(m *Mrt) error

Parse parses BGP4MP message from MRT message m.

func (*BgpMsg) Reset

func (b *BgpMsg) Reset() *BgpMsg

Reset resets b to initial state, dropping all references

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
	// contains filtered or unexported fields
}

Mrt represents a bare-bones MRT message (rfc6396/2).

func NewMrt

func NewMrt() *Mrt

NewMrt returns new empty message

func (*Mrt) CopyData

func (m *Mrt) CopyData() *Mrt

CopyData copies the referenced data iff needed and makes msg the owner

func (*Mrt) Disown

func (m *Mrt) Disown()

Disown tags msg as not the owner of data.

func (*Mrt) Length

func (m *Mrt) Length() int

Length returns total MRT message length, including header

func (*Mrt) Own

func (m *Mrt) Own()

Own tags msg as the owner of referenced data. Does not copy the data.

func (*Mrt) Parse

func (m *Mrt) Parse(raw []byte) (off int, err error)

Parse parses the MRT message in raw. Does not copy. Returns the number of parsed bytes from raw.

func (*Mrt) Reset

func (m *Mrt) Reset() *Mrt

Reset clears the message

func (*Mrt) SetData

func (m *Mrt) SetData(data []byte) *Mrt

SetData updates the data to reference given value

func (*Mrt) WriteTo

func (m *Mrt) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the MRT message to w, implementing io.WriterTo

type Reader

type Reader struct {
	*zerolog.Logger

	Stats   ReaderStats   // our stats
	Options ReaderOptions // options; do not modify after Attach()
	// contains filtered or unexported fields
}

Reader reads MRT-BGP4MP messages into a pipe.Input.

func NewReader

func NewReader(ctx context.Context) *Reader

NewReader returns a new Reader.

func (*Reader) Attach

func (br *Reader) Attach(p *pipe.Pipe, dst msg.Dir) error

Attach attaches the speaker to given upstream pipe direction. Must not be called more than once.

func (*Reader) ReadFromPath

func (br *Reader) ReadFromPath(fpath string) (n int64, err error)

ReadFromPath opens and reads fpath into br, uncompressing if needed.

func (*Reader) Write

func (br *Reader) Write(src []byte) (n int, err error)

Write implements io.Writer and reads all MRT-BGP4MP messages from src into br.in. Must not be used concurrently.

type ReaderOptions

type ReaderOptions struct {
	Logger *zerolog.Logger // if nil logging is disabled
}

MRT-BGP Reader options

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 (
	BGP4MP_STATE_CHANGE     Sub = 0
	BGP4MP_STATE_CHANGE_AS4 Sub = 5

	BGP4MP_MESSAGE               Sub = 1
	BGP4MP_MESSAGE_LOCAL         Sub = 6
	BGP4MP_MESSAGE_ADDPATH       Sub = 8
	BGP4MP_MESSAGE_LOCAL_ADDPATH Sub = 10

	BGP4MP_MESSAGE_AS4               Sub = 4
	BGP4MP_MESSAGE_AS4_LOCAL         Sub = 7
	BGP4MP_MESSAGE_AS4_ADDPATH       Sub = 9
	BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH Sub = 11
)

from https://www.iana.org/assignments/mrt/mrt.xhtml

func SubString

func SubString(s string) (Sub, error)

SubString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func SubValues

func SubValues() []Sub

SubValues returns all values of the enum

func (Sub) IsASub

func (i Sub) IsASub() bool

IsASub returns "true" if the value is listed in the enum definition. "false" otherwise

func (Sub) String

func (i Sub) String() string

type Type

type Type uint16

MRT message type, see https://www.iana.org/assignments/mrt/mrt.xhtml

const (
	TYPE_INVALID Type = 0

	TYPE_OSPF2    Type = 11
	TYPE_OSPF3    Type = 48
	TYPE_OSPF3_ET Type = 49

	TYPE_TABLE_DUMP  Type = 12
	TYPE_TABLE_DUMP2 Type = 13

	TYPE_BGP4MP    Type = 16
	TYPE_BGP4MP_ET Type = 17

	TYPE_ISIS    Type = 32
	TYPE_ISIS_ET Type = 33
)

func TypeString

func TypeString(s string) (Type, error)

TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TypeValues

func TypeValues() []Type

TypeValues returns all values of the enum

func (Type) IsAType

func (i Type) IsAType() bool

IsAType returns "true" if the value is listed in the enum definition. "false" otherwise

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL