gobgp

package
v0.0.0-...-c34bea4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GoBGPIPv6Family is a read-only pointer to a gobgp.Family structure
	// representing IPv6 address family.
	GoBGPIPv6Family = &gobgp.Family{
		Afi:  gobgp.Family_AFI_IP6,
		Safi: gobgp.Family_SAFI_UNICAST,
	}
	// GoBGPIPv4Family is a read-only pointer to a gobgp.Family structure
	// representing IPv4 address family.
	GoBGPIPv4Family = &gobgp.Family{
		Afi:  gobgp.Family_AFI_IP,
		Safi: gobgp.Family_SAFI_UNICAST,
	}
)
View Source
var ConfigReconcilers = [...]ConfigReconcilerFunc{
	preflightReconciler,
	neighborReconciler,
	exportPodCIDRReconciler,
}

ConfigReconcilers is an array of ConfigReconcilerFunc(s) which should be ran in the defined order.

Before adding ConfigReconcilerFunc consider the order in which they run and ensure any dependencies are reconciled first.

Functions

func ReconcileBGPConfig

ReconcileBGPConfig will utilize the current set of ConfigReconcilerFunc(s) to push a BgpServer to its desired configuration.

If any ConfigReconcilerFunc fails so will ReconcileBGPConfig and the caller is left to decide how to handle the possible inconsistent state of the BgpServer left over.

Providing a ServerWithConfig that has a nil `Config` field indicates that this is the first time this BgpServer is being configured, each ConfigReconcilerFunc must be prepared to handle this.

The two CiliumBGPVirtualRouter(s) being compared must have the same local ASN, unless `sc.Config` is nil, or else an error is returned.

On success the provided `newc` will be written to `sc.Config`. The caller should then store `sc` until next reconciliation.

Types

type Advertisement struct {
	Net  *net.IPNet
	Path *gobgp.Path
}

Advertisement is a container object which associates a net.IPNet with a gobgp.Path.

The `Net` field makes comparing this Advertisement with another IPNet encoded prefixes simple.

The `Path` field is a gobgp.Path object which can be forwarded to our server's WithdrawPath method, making withdrawing an advertised route simple.

type BGPRouterManager

type BGPRouterManager struct {
	Servers LocalASNMap
}

BGPRouterManager implements the pkg.bgpv1.agent.BGPRouterManager interface.

This BGPRouterMananger utilizes the gobgp project to implement a BGP routing plane.

Logically, this manager views each CiliumBGPVirtualRouter within a CiliumBGPPeeringPolicy as a BGP router instantiated on its host.

BGP routers are grouped and accessed by their local ASNs, thus this backend mandates that each CiliumBGPPeeringConfig have a unique local ASN and precludes a single host instantiating two routers with the same local ASN.

This manager employs two main data structures to implement its high level business logic.

A reconcilerDiff is used to establish which BgpServers must be created, and removed from the Mananger along with which servers must have their configurations reconciled.

A set of ReconcilerConfigFunc(s), which usages are wrapped by the ReconcileBGPConfig function, reconcile individual features of a CiliumBGPPeeringConfig.

Together, the high-level flow the manager takes is:

  • Instantiate a reconcilerDiff to compute which BgpServers to create, remove, and reconcile
  • Create any BgpServers necessary, run ReconcilerConfigFuncs(s) on each
  • Run each ReconcilerConfigFunc, by way of ReconcileBGPConfig, on any BgpServers marked for reconcile

BgpServers are abstracted by the ServerWithConfig structure which provides a method set for low-level BGP operations.

func NewBGPRouterManager

func NewBGPRouterManager() *BGPRouterManager

NewBGPRouterManager constructs a GoBGP-backed BGPRouterManager.

See NewBGPRouterManager for details.

func (*BGPRouterManager) ConfigurePeers

ConfigurePeers is a declarative API for configuring the BGP peering topology given a desired CiliumBGPPeeringPolicy.

ConfigurePeers will evaluate BGPRouterManager's current state and the desired CiliumBGPPeeringPolicy policy then take the necessary actions to apply the provided policy. For more details see BGPRouterManager's comments.

ConfigurePeers should return only once a subsequent invocation is safe. This method is not thread safe and does not intend to be called concurrently.

type ConfigReconcilerFunc

type ConfigReconcilerFunc func(ctx context.Context, m *BGPRouterManager, sc *ServerWithConfig, newc *v2alpha1api.CiliumBGPVirtualRouter, cstate *agent.ControlPlaneState) error

ConfigReconcilerFunc is a function signature for reconciling a particular aspect of an old and new *v2alpha1api.CiliumBGPVirtualRouter

If the `Config` field in `sc` is nil the reconciler should unconditionally perform the reconciliation actions, as no previous configuration is present.

type LocalASNMap

type LocalASNMap map[int]*ServerWithConfig

LocalASNMap maps local ASNs to their associated BgpServers and server configuration info.

type ServerLogger

type ServerLogger struct {
	// contains filtered or unexported fields
}

implement github.com/osrg/gobgp/v3/pkg/log/Logger interface

func NewServerLogger

func NewServerLogger(l *logrus.Logger, asn uint32) *ServerLogger

func (*ServerLogger) Debug

func (l *ServerLogger) Debug(msg string, fields gobgpLog.Fields)

func (*ServerLogger) Error

func (l *ServerLogger) Error(msg string, fields gobgpLog.Fields)

func (*ServerLogger) Fatal

func (l *ServerLogger) Fatal(msg string, fields gobgpLog.Fields)

func (*ServerLogger) GetLevel

func (l *ServerLogger) GetLevel() gobgpLog.LogLevel

func (*ServerLogger) Info

func (l *ServerLogger) Info(msg string, fields gobgpLog.Fields)

func (*ServerLogger) Panic

func (l *ServerLogger) Panic(msg string, fields gobgpLog.Fields)

func (*ServerLogger) SetLevel

func (l *ServerLogger) SetLevel(level gobgpLog.LogLevel)

func (*ServerLogger) Warn

func (l *ServerLogger) Warn(msg string, fields gobgpLog.Fields)

type ServerWithConfig

type ServerWithConfig struct {
	// a gobgp backed BgpServer configured in accordance to the accompanying
	// CiliumBGPVirtualRouter configuration.
	Server *server.BgpServer
	// The CiliumBGPVirtualRouter configuration which drives the configuration
	// of the above BgpServer.
	//
	// If this field is nil it means the above BgpServer has had no
	// configuration applied to it.
	Config *v2alpha1api.CiliumBGPVirtualRouter
	// Holds any announced PodCIDR routes.
	PodCIDRAnnouncements []Advertisement
}

ServerWithConfig is a container for grouping a gobgp BgpServer with the Cilium's BGP control plane related configuration.

It exports a method set for manipulating the BgpServer. However, this struct is a dumb object. The calling code is required to keep the BgpServer's configuration and associated configuration fields in sync.

func NewServerWithConfig

func NewServerWithConfig(ctx context.Context, startReq *gobgp.StartBgpRequest) (*ServerWithConfig, error)

NewServerWithConfig will start an underlying BgpServer utilizing startReq for its initial configuration.

The returned ServerWithConfig has a nil CiliumBGPVirtualRouter config, and is ready to be provided to ReconcileBGPConfig.

Canceling the provided context will kill the BgpServer along with calling the underlying BgpServer's Stop() method.

func (*ServerWithConfig) AddNeighbor

AddNeighbor will add the CiliumBGPNeighbor to the gobgp.BgpServer, creating a BGP peering connection.

func (*ServerWithConfig) AdvertisePath

func (sc *ServerWithConfig) AdvertisePath(ctx context.Context, ip *net.IPNet) (Advertisement, error)

AdvertisePath will advertise the provided IP network to any existing and all subsequently added Neighbors currently peered with this BgpServer.

`ip` can be an ipv4 or ipv6 and this method will handle the differences between MP BGP and BGP.

It is an error to advertise an IPv6 path when no IPv6 address is configured on this Cilium node, selfsame for IPv4.

Nexthop of the path will always set to "0.0.0.0" in IPv4 and "::" in IPv6, so that GoBGP selects appropriate actual nexthop address and advertise it.

An Advertisement is returned which may be passed to WithdrawPath to remove this Advertisement.

func (*ServerWithConfig) RemoveNeighbor

func (sc *ServerWithConfig) RemoveNeighbor(ctx context.Context, n *v2alpha1api.CiliumBGPNeighbor) error

RemoveNeighbor will remove the CiliumBGPNeighbor from the gobgp.BgpServer, disconnecting the BGP peering connection.

func (*ServerWithConfig) WithdrawPath

func (sc *ServerWithConfig) WithdrawPath(ctx context.Context, advert Advertisement) error

WithdrawPath withdraws an Advertisement produced by AdvertisePath from this BgpServer.

Jump to

Keyboard shortcuts

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