network

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package network provides network mode abstractions for provisioning.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectPhysicalNICs

func DetectPhysicalNICs() ([]string, error)

DetectPhysicalNICs returns the names of all physical network interfaces, excluding loopback, virtual, bridge, and VXLAN interfaces. In containerlab environments, interfaces may initially appear with temporary names (clab-*) before being renamed to their final names. This function retries briefly when temporary names are detected.

func GetIPMIInfo

func GetIPMIInfo() (mac, ip string, err error)

GetIPMIInfo reads the IPMI MAC and IP from the system.

func WaitForHTTP

func WaitForHTTP(ctx context.Context, target string, timeout time.Duration) error

WaitForHTTP polls target with HTTP HEAD until reachable.

Types

type BondMode

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

BondMode implements the Mode interface by creating an LACP bond from multiple physical NICs. After Setup the bond interface is available as "bond0" for other modes (static/DHCP) to use.

func (*BondMode) Setup

func (b *BondMode) Setup(_ context.Context, cfg *Config) error

Setup creates a bond interface from the configured interfaces.

func (*BondMode) Teardown

func (b *BondMode) Teardown(_ context.Context) error

Teardown removes the bond interface.

func (*BondMode) WaitForConnectivity

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

WaitForConnectivity polls the target URL until reachable or timeout.

type Config

type Config struct {
	// DHCP mode fields.
	Interfaces []string // NICs to configure (default: auto-detect)

	// FRR/EVPN mode fields (from kernel cmdline or /deploy/vars).
	UnderlaySubnet   string // e.g. "192.168.4.0/24"
	UnderlayIP       string // Direct underlay IP (if no subnet)
	OverlaySubnet    string // e.g. "2a01:598:40a:5481::/64"
	IPMISubnet       string // e.g. "172.30.0.0/24"
	IPMIMAC          string // IPMI MAC for IP derivation
	IPMIIP           string // IPMI IP for offset calculation
	ASN              uint32 // BGP ASN for underlay
	ProvisionVNI     uint32 // VXLAN VNI for provision network
	ProvisionIP      string // IP/mask to assign to provision bridge (e.g. "10.100.0.20/24")
	ProvisionGateway string // Gateway VTEP IP for VXLAN BUM flooding
	DNSResolvers     string // Comma-separated DNS servers

	// Optional FRR onefabric mode fields.
	DCGWIPs          string // Data Center Gateway IPs (comma-sep)
	LeafASN          uint32 // Leaf switch AS
	LocalASN         uint32 // Local AS for leaf connections
	OverlayAggregate string // Route aggregate for overlay
	VPNRT            string // VPN route target for EVPN

	// Static networking fields.
	StaticIP      string // IP/mask to assign (e.g. "10.0.0.5/24")
	StaticGateway string // Default gateway IP
	StaticIface   string // Interface name (default: auto-detect first physical NIC)

	// LACP bonding fields.
	BondInterfaces string // Comma-separated NICs to bond (e.g. "eth0,eth1")
	BondMode       string // Bonding mode (default: "802.3ad" for LACP)

	// BGP/BFD tuning fields.
	VRFTableID    uint32 // Routing table ID for VRF (default: 1)
	BGPKeepalive  uint32 // BGP keepalive interval in seconds (0 = FRR default)
	BGPHold       uint32 // BGP hold timer in seconds (0 = FRR default)
	BFDTransmitMS uint32 // BFD transmit interval in ms (default: 300)
	BFDReceiveMS  uint32 // BFD receive interval in ms (default: 300)

	// BGP peering mode (GoBGP).
	BGPPeerMode  PeerMode // Unnumbered (default), dual, or numbered
	BGPNeighbors string   // Comma-separated numbered peer IPs
	BGPRemoteASN uint32   // Remote ASN for numbered peers (0 = iBGP)

	// Common fields.
	BridgeName  string // Default: "br.provision"
	VRFName     string // Default: empty (no VRF isolation); set explicitly if needed
	MTU         int    // Default: 9000
	NetworkMode string // "gobgp" to use in-process GoBGP instead of FRR

	// EVPN L2 overlay (Type-2/3 route processing) — disabled by default.
	EVPNL2Enabled bool // Enable L2 overlay route handling

	// VLAN configuration.
	VLANs []VLANConfig // 802.1Q VLAN interfaces to create before network mode setup
}

Config holds all parameters needed for network setup.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults fills in default values for unset fields.

func (*Config) IsBondMode

func (c *Config) IsBondMode() bool

IsBondMode returns true if LACP bonding interfaces are configured.

func (*Config) IsFRRMode

func (c *Config) IsFRRMode() bool

IsFRRMode returns true if the config has enough parameters for FRR/EVPN.

func (*Config) IsGoBGPMode

func (c *Config) IsGoBGPMode() bool

IsGoBGPMode returns true if GoBGP mode is explicitly requested.

func (*Config) IsStaticMode

func (c *Config) IsStaticMode() bool

IsStaticMode returns true if static IP configuration is provided.

func (*Config) IsVLANMode

func (c *Config) IsVLANMode() bool

IsVLANMode returns true if any VLAN interfaces are configured.

type DHCPMode

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

DHCPMode implements the Mode interface using DHCP on all physical interfaces.

func NewDHCPMode

func NewDHCPMode() *DHCPMode

NewDHCPMode creates a DHCPMode with a component logger.

func (*DHCPMode) Setup

func (d *DHCPMode) Setup(ctx context.Context, _ *Config) error

Setup tries DHCP on each physical interface until one gets a lease.

func (*DHCPMode) Teardown

func (d *DHCPMode) Teardown(_ context.Context) error

Teardown stops the DHCP client.

func (*DHCPMode) WaitForConnectivity

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

WaitForConnectivity polls the target URL until reachable or timeout.

type Mode

type Mode interface {
	// Setup configures all networking (interfaces, routing, etc.)
	Setup(ctx context.Context, cfg *Config) error
	// WaitForConnectivity blocks until network is reachable.
	WaitForConnectivity(ctx context.Context, target string, timeout time.Duration) error
	// Teardown cleans up network configuration.
	Teardown(ctx context.Context) error
}

Mode configures network connectivity in the ramdisk.

type PeerMode

type PeerMode string

PeerMode controls how BGP neighbor sessions are established.

const (
	// PeerModeUnnumbered uses link-local interface peers for both IPv4 unicast
	// and L2VPN-EVPN address families.  This is the default for leaf-peered
	// datacenter fabrics running BGP unnumbered.
	PeerModeUnnumbered PeerMode = "unnumbered"

	// PeerModeDual combines unnumbered interface peers (IPv4 unicast only) with
	// numbered peers for L2VPN-EVPN.  Typical use case: fabric underlay via
	// unnumbered, EVPN via iBGP to route reflectors.
	PeerModeDual PeerMode = "dual"

	// PeerModeNumbered uses explicit neighbor IPs for all BGP sessions.  The
	// machine must already have underlay reachability (e.g. via DHCP or static
	// IP).  All configured address families are negotiated over the numbered
	// sessions.
	PeerModeNumbered PeerMode = "numbered"
)

func ParsePeerMode

func ParsePeerMode(s string) PeerMode

ParsePeerMode converts a string to a PeerMode, defaulting to unnumbered.

type StaticMode

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

StaticMode implements the Mode interface using static IP configuration.

func (*StaticMode) Setup

func (s *StaticMode) Setup(_ context.Context, cfg *Config) error

Setup configures static IP, gateway, and DNS on the specified interface.

func (*StaticMode) Teardown

func (s *StaticMode) Teardown(_ context.Context) error

Teardown removes the static IP configuration.

func (*StaticMode) WaitForConnectivity

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

WaitForConnectivity polls the target URL until reachable or timeout.

type VLANConfig

type VLANConfig struct {
	ID      int    // VLAN identifier (1-4094)
	Parent  string // Physical parent interface (e.g. "eno1")
	Address string // Static IP/CIDR (e.g. "10.200.0.42/24"); empty = DHCP
	Gateway string // Default gateway IP (optional)
}

VLANConfig holds configuration for a single 802.1Q VLAN interface.

func ParseVLANs

func ParseVLANs(spec string) ([]VLANConfig, error)

ParseVLANs parses a comma-separated VLAN specification string into a slice of VLANConfig. Each entry has the format:

ID:parent[:address[:gateway]]

Examples:

"200:eno1:10.200.0.42/24"
"200:eno1:10.200.0.42/24,300:eno2"
"200:eno1:10.200.0.42/24:10.200.0.1"

Directories

Path Synopsis
Package gobgp implements a three-tier BGP network stack using the GoBGP library as a pure-Go replacement for FRR.
Package gobgp implements a three-tier BGP network stack using the GoBGP library as a pure-Go replacement for FRR.
Package lldp provides LLDP frame listening for switch topology discovery.
Package lldp provides LLDP frame listening for switch topology discovery.
Package vlan provides VLAN configuration and validation.
Package vlan provides VLAN configuration and validation.

Jump to

Keyboard shortcuts

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