bfd

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 9 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 Controller

type Controller struct {
	// Sessions contains the sessions that the controller should manage. Both bootstrapped and
	// non-bootstrapped sessions are accepted.
	//
	// Passing in a slice of length 0 is allowed, although all BFD messages received by the
	// controller will be discarded in this case.
	//
	// Sessions must have unique local discriminators. If two sessions have the same discriminator,
	// running the controller will return an error.
	//
	// If a session is nil or has a local discriminator of 0, running the controller will return an
	// error.
	//
	// The controller will take ownership of the Sessions passed into it. When the controller is
	// shut down, it will also close all sessions. Callers must not clean up sessions after the
	// controller has been started.
	Sessions []*Session

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

	// Logger to which the controller should send logging entries. If nil, logging is disabled.
	Logger log.Logger
	// contains filtered or unexported fields
}

Controller manages multiple BFD sessions, enforcing discriminator constraints and routing BFD messages to their proper Session.

Routing is done based on local discriminator information. Remote discriminator information is not checked by the controller.

The controller will discard BFD messages if it notices a session is slow to process them.

func (*Controller) Errors

func (c *Controller) Errors() <-chan error

Errors returns a channel on which callers can be informed of fatal errors in BFD Sessions. If an error is reported on the channel, the drainer can assume the corresponding Session has terminated.

Sessions that shut down cleanly will send a nil error on this channel. Callers can thus track how many sessions have finished.

func (*Controller) IsUp

func (c *Controller) IsUp(discriminator layers.BFDDiscriminator) bool

IsUp returns whether the Session identified by the local discriminator is up.

If a session with the local discriminator does not exist, the function returns False.

func (*Controller) Messages

func (c *Controller) Messages() chan<- *layers.BFD

Messages returns a channel on which callers should write BFD packets received from the network. The Run method continuously processes packets received on this channel, and forwards them to the relevant Session based on the value of the Your Discriminator field. If the channel is closed, the Run method cleans up and shuts down.

func (*Controller) Run

func (c *Controller) Run() error

Run processes messages received by the controller.

Run will return an error if the sessions contain inconsistent local discriminator information.

If a session experiences a problem while running, Run will not return. For information on how to watch for such errors, see the Errors method.

Run will continue to execute even if all sessions exited (and will run even though zero sessions are configured). To force Run to finish execution, close the controller's message channel.

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 metrics.Counter
	// PacketsReceived reports the total number of BFD packets received by the session.
	PacketsReceived metrics.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 metrics.Gauge
	// StateChanges reports the total number of state changes of the session.
	StateChanges metrics.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

	// Logger to which the session should send logging entries. If nil, logging is disabled.
	Logger log.Logger

	// 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) 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) Messages

func (s *Session) Messages() chan<- *layers.BFD

Messages returns a channel on which callers should write BFD packets received from the network. The Run method continuously processes packets received on this channel.

Close the channel returned by Messages to shut down the Session. Like closing any other channel, the channel can only be closed once.

func (*Session) Run

func (s *Session) Run() 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