gobgp

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package gobgp implements a three-tier BGP network stack using the GoBGP library as a pure-Go replacement for FRR.

Architecture:

  • Tier 1 (Underlay): eBGP peering with leaf switches for VXLAN reachability
  • Tier 2 (Overlay): EVPN Type-5 routes with VXLAN encapsulation
  • Tier 3 (IPMI): Optional L3 path to the BMC (not yet implemented)

Supported BGP session modes (PeerMode):

  • Unnumbered: link-local interface peers (IPv4 + L2VPN-EVPN)
  • Dual: unnumbered underlay (IPv4) + numbered peers (L2VPN-EVPN)
  • Numbered: explicit neighbor IPs only (IPv4 + L2VPN-EVPN), requires DHCP or static underlay for initial connectivity

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ASN               uint32           // Local BGP autonomous system number
	RouterID          string           // BGP router ID (underlay IP)
	ListenPort        int32            // BGP listen port (default: 179)
	ProvisionVNI      int              // VXLAN VNI for provisioning network
	ProvisionIP       string           // IP/mask for provision bridge
	ProvisionGateway  string           // Gateway VTEP IP for VXLAN BUM flooding
	DNSResolvers      string           // Comma-separated DNS servers
	BridgeName        string           // Bridge device name (default: "br.provision")
	VRFName           string           // VRF name (default: empty, same as FRR)
	VRFTableID        uint32           // Routing table ID for VRF (default: 1000)
	MTU               int              // Physical interface MTU (default: 9000)
	KeepaliveInterval uint64           // BGP keepalive seconds (default: 3)
	HoldTime          uint64           // BGP hold timer seconds (default: 9)
	ConnectRetry      uint64           // BGP connect retry seconds (default: 5)
	OverlayIP         string           // Overlay loopback IP (derived or same as RouterID)
	BridgeMAC         string           // Derived MAC for provision bridge
	IPMIMAC           string           // IPMI MAC for bridge MAC derivation
	PeerMode          network.PeerMode // BGP session establishment mode
	NeighborAddrs     []string         // Explicit numbered peer IPs (dual/numbered modes)
	RemoteASN         uint32           // Remote ASN for numbered peers (0 = same ASN → iBGP)
	EnableL2          bool             // Enable L2 EVPN overlay (gate Type-2/3 route handling)
}

Config holds GoBGP three-tier stack configuration.

func NewConfig

func NewConfig(netCfg *network.Config) (*Config, error)

NewConfig creates a GoBGP Config from network configuration. It derives addresses using the shared FRR address-derivation logic and applies GoBGP-specific defaults (aggressive hold timers, no BFD).

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults fills in default values for unset fields. GoBGP uses aggressive hold timers (3s/9s) instead of BFD for fast failover.

func (*Config) IsiBGP

func (c *Config) IsiBGP() bool

IsiBGP returns true when the numbered peers use the same ASN (iBGP).

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that required configuration fields are present.

type OverlayTier

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

OverlayTier manages EVPN Type-5 routes and VXLAN encapsulation. When EnableL2 is set, it also handles Type-2 (MAC/IP) and Type-3 (Inclusive Multicast) routes for L2 overlay use cases.

func NewOverlayTier

func NewOverlayTier(cfg *Config) *OverlayTier

NewOverlayTier creates a new overlay tier.

func (*OverlayTier) CreateVRF

func (o *OverlayTier) CreateVRF() error

CreateVRF creates the VRF interface if VRFName is configured. Called by Stack before underlay setup so that dummy/NICs can be assigned.

func (*OverlayTier) Ready

func (o *OverlayTier) Ready(_ context.Context, _ time.Duration) error

Ready waits until the overlay is operational by checking EVPN route state.

func (*OverlayTier) SetBgpServer

func (o *OverlayTier) SetBgpServer(s *server.BgpServer)

SetBgpServer sets the shared BGP server from the underlay tier.

func (*OverlayTier) Setup

func (o *OverlayTier) Setup(ctx context.Context) error

Setup creates VXLAN, bridge, and advertises the provision subnet as an EVPN Type-5 (IP Prefix) route so the fabric can route to this node. Incoming Type-5 routes from the fabric are installed as kernel routes by watchRoutes. VRF creation is handled by the stack before setup.

func (*OverlayTier) Teardown

func (o *OverlayTier) Teardown(_ context.Context) error

Teardown removes the overlay network resources we created (bridge, vxlan) and removes the overlay loopback IP from lo. VRF is cleaned up separately by Stack.Teardown after underlay detaches.

type Stack

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

Stack composes underlay and overlay tiers into a network.Mode implementation.

func NewStack

func NewStack(cfg *Config) *Stack

NewStack creates a GoBGP stack from the given configuration.

func (*Stack) Setup

func (s *Stack) Setup(ctx context.Context, _ *network.Config) error

Setup initializes the underlay and overlay tiers sequentially. The cfg parameter satisfies the network.Mode interface; the stack uses its own Config parsed at construction time.

func (*Stack) Teardown

func (s *Stack) Teardown(ctx context.Context) error

Teardown tears down the overlay and underlay tiers in reverse order. VRF is deleted last since both tiers may have interfaces enslaved to it.

func (*Stack) WaitForConnectivity

func (s *Stack) WaitForConnectivity(ctx context.Context, target string, timeout time.Duration) error

WaitForConnectivity waits for BGP to establish and then polls the target URL until reachable, consistent with other network modes.

type Tier

type Tier interface {
	// Setup configures the tier's networking resources.
	Setup(ctx context.Context) error
	// Ready waits for the tier to become operational.
	Ready(ctx context.Context, timeout time.Duration) error
	// Teardown removes the tier's networking resources.
	Teardown(ctx context.Context) error
}

Tier represents a single concern in the network stack.

type UnderlayTier

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

UnderlayTier manages BGP peering for VXLAN reachability. Depending on PeerMode it establishes unnumbered (link-local), numbered (explicit IP), or a combination of both session types.

func NewUnderlayTier

func NewUnderlayTier(cfg *Config) *UnderlayTier

NewUnderlayTier creates a new underlay tier.

func (*UnderlayTier) BgpServer

func (u *UnderlayTier) BgpServer() *server.BgpServer

BgpServer returns the shared BGP server for the overlay tier.

func (*UnderlayTier) NICs

func (u *UnderlayTier) NICs() []string

NICs returns the detected physical NICs.

func (*UnderlayTier) Ready

func (u *UnderlayTier) Ready(ctx context.Context, timeout time.Duration) error

Ready waits until at least one BGP peer reaches ESTABLISHED state.

func (*UnderlayTier) Setup

func (u *UnderlayTier) Setup(ctx context.Context) error

Setup creates the underlay loopback, detects NICs (when needed), starts the BGP server, and adds peers according to the configured PeerMode.

func (*UnderlayTier) Teardown

func (u *UnderlayTier) Teardown(_ context.Context) error

Teardown stops the BGP server and removes the underlay dummy interface.

Jump to

Keyboard shortcuts

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