bfd

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package bfd implements Bidirectional Forwarding Detection as defined in RFC 5880.

See the Session type for more information.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AlreadyRunning is the error returned by session run function when called for twice.
	AlreadyRunning = serrors.New("is running")
)

Functions

This section is empty.

Types

type IntervalGenerator

type IntervalGenerator interface {
	Generate(x, y int) int
}

IntervalGenerator generates integers in [x, y). It panics if x < 0 or if y <= x.

type Metrics

type Metrics struct {
	// PacketsSent reports the total number of BFD packets sent out by the session.
	PacketsSent prometheus.Counter
	// PacketsReceived reports the total number of BFD packets received by the session.
	PacketsReceived prometheus.Counter
	// Up reports 1 if the local session is in state Up, and 0 otherwise. Note that due to the
	// bidirectional detection nature of BFD (the local session will transition to a non-Up state if
	// it detects the remote is not Up), barring some network delays, if the local session is Up the
	// remote session is also Up.
	Up prometheus.Gauge
	// StateChanges reports the total number of state changes of the session.
	StateChanges prometheus.Counter
}

Metrics is used by sessions to report information about internal operation.

type Sender

type Sender interface {
	Send(bfd *layers.BFD) error
}

Sender is used by a BFD session to send out BFD packets.

type Session

type Session struct {
	// Sender is used by the Session to send BFD messages to the other end of the point to point
	// link.
	//
	// Sender must not be nil.
	Sender Sender

	// LocalDiscriminator is the local discriminator for this BFD session, used
	// to uniquely identify it on the local system. It must be nonzero.
	LocalDiscriminator layers.BFDDiscriminator

	// RemoteDiscriminator is the remote discriminator for this BFD session, as chosen
	// by the remote system. If the Session has been bootstrapped via an external
	// mechanism, this should be non-zero. If it is zero, the Session will perform
	// bootstrapping.
	RemoteDiscriminator layers.BFDDiscriminator

	// DesiredMinTxInterval is the desired interval between BFD Control Packets
	// sent by the local system.
	//
	// The interval is relevant up to microsecond granularity; if the duration is not a whole
	// number of microseconds, the duration is rounded down to the next microsecond duration.
	//
	// The microsecond value obtained this way must be at least 1 and at most 2^32 - 1 microseconds.
	// Run will return an error if the interval falls outside this range.
	//
	// Note that this is only a recommendation, as the BFD state machine might choose to use
	// a different interval depending on network conditions (for example, an interval of 1 second if
	// the local session is down).
	DesiredMinTxInterval time.Duration

	// RequiredMinRxInterval is the minimum interval between BFD Control Packets supported by the
	// local system.
	//
	// The interval is relevant up to microsecond granularity; if the duration is not a whole number
	// of microseconds, the duration is rounded down to the next microsecond duration.
	//
	// The microsecond value obtained this way must be at least 1 and at most 2^32 - 1 microseconds.
	// Run will return an error if the interval falls outside this range.
	//
	// TEMPORARY API: The BFD RFC allows for this value to be 0, which means the system does not
	// want to receive any periodic BFD control packets (see section 6.8.1). This behavior is not
	// supported at the moment, and is subject to change.
	RequiredMinRxInterval time.Duration

	// DetectMult is the desired Detection Time multiplier for BFD Control packets on the local
	// system. The negotiated Control packet transmission interval, multiplied by this variable,
	// will be the Detection Time for this session (as seen by the remote system). This value
	// must be non-zero.
	DetectMult layers.BFDDetectMultiplier

	// ReceiveQueueSize is the size of the Session's receive messages queue. The default is 0,
	// but this is often not desirable as writing to the Session's message queue will block
	// until the session is ready to read it.
	ReceiveQueueSize int

	// Metrics is used by the session to report information about internal operation.
	//
	// If a metric is not initialized, it is not reported.
	Metrics Metrics
	// contains filtered or unexported fields
}

Session describes a BFD Version 1 (RFC 5880) Session. Only Asynchronous mode is supported.

Calling Run will start internal timers and cause the Session to start sending out BFD packets.

Diagnostic codes are not supported. The field will always be set to 0, and diagnostic codes received from the remote will be ignored.

The AdminDown state is not supported at the moment. Sessions will never send out packets with a State of 0 (AdminDown).

The Control Plane Independent bit is cleared.

Authentication is not supported. The Authentication Present bit of BFD packets is cleared.

Session does not support the BFD Echo function. Therefore, the Required Min Echo RX field is always set to 0.

func (*Session) Close

func (s *Session) Close() error

func (*Session) IsUp

func (s *Session) IsUp() bool

IsUp returns whether the session is up. It is safe (and almost always the case) to call IsUp while Run is executed.

func (*Session) ReceiveMessage

func (s *Session) ReceiveMessage(msg *layers.BFD)

ReceiveMessage validates a message and enqueues it for processing. Callers pass the message received from the network. The actual processing of the messages is asynchronous; the relevant message content is passed over a channel and the Run method continuously processes packets received on this channel. The caller can safely reuse packet buffer and the layers.BFD object.

The session must be running when calling this function, i.e. Run must have been called.

func (*Session) Run

func (s *Session) Run(ctx context.Context) error

Run initializes the Session's timers and state machine, and starts sending out BFD control packets on the point to point link.

Run must only be called once.

func (*Session) String

func (s *Session) String() string

type Source

type Source interface {
	Intn(n int) int
}

Source is an pseudorandom number generator interface that is satisfied by package math/rand's Rand type.

Directories

Path Synopsis
Package mock_bfd is a generated GoMock package.
Package mock_bfd is a generated GoMock package.

Jump to

Keyboard shortcuts

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