links

package
v0.54.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLinkMTU = 9500

	LinkDeploymentStateNotDeployed = iota
	// LinkDeploymentStateHalfDeployed is a state in which one of the endpoints
	// of the links finished deploying and the other one is not yet deployed.
	LinkDeploymentStateHalfDeployed
	LinkDeploymentStateFullDeployed
	LinkDeploymentStateRemoved
)
View Source
const (
	LinkEndpointTypeVeth   = "veth"
	LinkEndpointTypeBridge = "bridge"
	LinkEndpointTypeHost   = "host"
)
View Source
const (
	MacVlanModeBridge   = "bridge"
	MacVlanModeVepa     = "vepa"
	MacVlanModePassthru = "passthru"
	MacVlanModePrivate  = "private"
	MacVlanModeSource   = "source"
)
View Source
const (
	// containerlab's reserved OUI.
	ClabOUI = "aa:c1:ab"
)
View Source
const (
	// vxlan port is different from the default port number 4789
	// since 4789 may be filtered by the firewalls or clash with other overlay services.
	VxLANDefaultPort = 14789
)

Variables

This section is empty.

Functions

func CheckBridgeExists

func CheckBridgeExists(ctx context.Context, n Node) error

CheckBridgeExists verifies that the given bridge is present in the network namespace referenced via the provided nspath handle.

func CheckEndpointDoesNotExistYet

func CheckEndpointDoesNotExistYet(ctx context.Context, e Endpoint) error

CheckEndpointDoesNotExistYet verifies that the interface referenced in the provided endpoint does not yet exist in the referenced node.

func CheckEndpointExists

func CheckEndpointExists(ctx context.Context, e Endpoint) error

CheckEndpointExists checks that a certain interface exists in the network namespace of the given node.

func CheckEndpointUniqueness

func CheckEndpointUniqueness(e Endpoint) error

CheckEndpointUniqueness checks that the given endpoint appears only once for the node it is assigned to.

func SetMgmtNetUnderlayingBridge

func SetMgmtNetUnderlayingBridge(bridge string) error

func SetNameMACAndUpInterface

func SetNameMACAndUpInterface(l netlink.Link, endpt Endpoint) func(ns.NetNS) error

SetNameMACAndUpInterface is a helper function that will bind interface name and Mac and return a function that can run in the netns.Do() call for execution in a network namespace.

Types

type Endpoint

type Endpoint interface {
	GetNode() Node
	GetIfaceName() string
	GetRandIfaceName() string
	GetMac() net.HardwareAddr
	String() string
	// GetLink retrieves the link that the endpoint is assigned to
	GetLink() Link
	// Verify verifies that the endpoint is valid and can be deployed
	Verify(context.Context, *VerifyLinkParams) error
	// HasSameNodeAndInterface returns true if an endpoint that implements this interface
	// has the same node and interface name as the given endpoint.
	HasSameNodeAndInterface(ept Endpoint) bool
	Remove(context.Context) error
	// Deploy deploys the endpoint by calling the Deploy method of the link it is assigned to
	// and passing the endpoint as an argument so that the link that consists of A and B endpoints
	// can deploy them independently.
	Deploy(context.Context) error
	// IsNodeless returns true for the endpoints that has no explicit node defined in the topology.
	// E.g. host endpoints, mgmt bridge endpoints.
	// Because there is no node that would deploy this side of the link they should be deployed along
	// with the A side of the veth link.
	IsNodeless() bool
}

Endpoint is the interface that all endpoint types implement. Endpoints like bridge, host, veth and macvlan are the types implementing this interface.

type EndpointBridge

type EndpointBridge struct {
	EndpointGeneric
	// contains filtered or unexported fields
}

func NewEndpointBridge added in v0.46.0

func NewEndpointBridge(eg *EndpointGeneric, isMgmtBridgeEndpoint bool) *EndpointBridge

func (*EndpointBridge) Deploy added in v0.52.0

func (e *EndpointBridge) Deploy(ctx context.Context) error

func (*EndpointBridge) IsNodeless added in v0.52.0

func (e *EndpointBridge) IsNodeless() bool

func (*EndpointBridge) Verify

type EndpointGeneric

type EndpointGeneric struct {
	Node      Node
	IfaceName string
	// Link is the link this endpoint belongs to.
	Link Link
	MAC  net.HardwareAddr
	// contains filtered or unexported fields
}

EndpointGeneric is the generic endpoint struct that is used by all endpoint types.

func NewEndpointGeneric

func NewEndpointGeneric(node Node, iface string, link Link) *EndpointGeneric

func (*EndpointGeneric) GetIfaceName

func (e *EndpointGeneric) GetIfaceName() string
func (e *EndpointGeneric) GetLink() Link

func (*EndpointGeneric) GetMac

func (e *EndpointGeneric) GetMac() net.HardwareAddr

func (*EndpointGeneric) GetNode

func (e *EndpointGeneric) GetNode() Node

func (*EndpointGeneric) GetRandIfaceName

func (e *EndpointGeneric) GetRandIfaceName() string

func (*EndpointGeneric) HasSameNodeAndInterface

func (e *EndpointGeneric) HasSameNodeAndInterface(ept Endpoint) bool

HasSameNodeAndInterface returns true if the given endpoint has the same node and interface name as the `ept` endpoint.

func (*EndpointGeneric) Remove

func (e *EndpointGeneric) Remove(ctx context.Context) error

func (*EndpointGeneric) String

func (e *EndpointGeneric) String() string

type EndpointHost

type EndpointHost struct {
	EndpointGeneric
}

func NewEndpointHost added in v0.46.0

func NewEndpointHost(eg *EndpointGeneric) *EndpointHost

func (*EndpointHost) Deploy added in v0.52.0

func (e *EndpointHost) Deploy(ctx context.Context) error

func (*EndpointHost) IsNodeless added in v0.52.0

func (e *EndpointHost) IsNodeless() bool

func (*EndpointHost) Verify

func (e *EndpointHost) Verify(ctx context.Context, _ *VerifyLinkParams) error

type EndpointMacVlan

type EndpointMacVlan struct {
	EndpointGeneric
}

func NewEndpointMacVlan added in v0.46.0

func NewEndpointMacVlan(eg *EndpointGeneric) *EndpointMacVlan

func (*EndpointMacVlan) Deploy added in v0.52.0

func (e *EndpointMacVlan) Deploy(ctx context.Context) error

func (*EndpointMacVlan) IsNodeless added in v0.52.0

func (e *EndpointMacVlan) IsNodeless() bool

func (*EndpointMacVlan) Verify

Verify runs verification to check if the endpoint can be deployed.

type EndpointRaw

type EndpointRaw struct {
	Node  string `yaml:"node"`
	Iface string `yaml:"interface"`
	MAC   string `yaml:"mac,omitempty"`
}

EndpointRaw is the raw (string) representation of an endpoint as defined in the topology file for a given link definition.

func NewEndpointRaw

func NewEndpointRaw(node, nodeIf, Mac string) *EndpointRaw

NewEndpointRaw creates a new EndpointRaw struct.

func (*EndpointRaw) Resolve

func (er *EndpointRaw) Resolve(params *ResolveParams, l Link) (Endpoint, error)

Resolve resolves the EndpointRaw into an Endpoint interface that is implemented by a concrete endpoint struct such as EndpointBridge, EndpointHost, EndpointVeth. The type of an endpoint is determined by the node it belongs to. Resolving a raw endpoint adds an associated Link and Node to the endpoint. It also adds the endpoint to the node.

type EndpointVeth

type EndpointVeth struct {
	EndpointGeneric
}

func NewEndpointVeth added in v0.46.0

func NewEndpointVeth(eg *EndpointGeneric) *EndpointVeth

func (*EndpointVeth) Deploy added in v0.52.0

func (e *EndpointVeth) Deploy(ctx context.Context) error

func (*EndpointVeth) IsNodeless added in v0.52.0

func (e *EndpointVeth) IsNodeless() bool

func (*EndpointVeth) Verify

Verify verifies the veth based deployment pre-conditions.

type EndpointVxlan added in v0.46.0

type EndpointVxlan struct {
	EndpointGeneric
	// contains filtered or unexported fields
}

func NewEndpointVxlan added in v0.46.0

func NewEndpointVxlan(node Node, link Link) *EndpointVxlan

func (*EndpointVxlan) Deploy added in v0.52.0

func (e *EndpointVxlan) Deploy(ctx context.Context) error

func (*EndpointVxlan) IsNodeless added in v0.52.0

func (e *EndpointVxlan) IsNodeless() bool

func (*EndpointVxlan) String added in v0.46.0

func (e *EndpointVxlan) String() string

func (*EndpointVxlan) Verify added in v0.46.0

Verify verifies that the endpoint is valid and can be deployed.

type GenericLinkNode

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

func (*GenericLinkNode) AddEndpoint

func (g *GenericLinkNode) AddEndpoint(e Endpoint)

func (*GenericLinkNode) AddLinkToContainer

func (g *GenericLinkNode) AddLinkToContainer(_ context.Context, link netlink.Link, f func(ns.NetNS) error) error

func (*GenericLinkNode) Delete added in v0.46.0

func (g *GenericLinkNode) Delete(ctx context.Context) error

func (*GenericLinkNode) ExecFunction

func (g *GenericLinkNode) ExecFunction(_ context.Context, f func(ns.NetNS) error) error

func (*GenericLinkNode) GetEndpoints

func (g *GenericLinkNode) GetEndpoints() []Endpoint

func (*GenericLinkNode) GetShortName

func (g *GenericLinkNode) GetShortName() string

func (*GenericLinkNode) GetState

func (*GenericLinkNode) GetState() state.NodeState
type Link interface {
	// Deploy deploys the link. Endpoint is the endpoint that triggers the creation of the link.
	Deploy(context.Context, Endpoint) error
	// Remove removes the link.
	Remove(context.Context) error
	// GetType returns the type of the link.
	GetType() LinkType
	// GetEndpoints returns the endpoints of the link.
	GetEndpoints() []Endpoint
	// GetMTU returns the Link MTU.
	GetMTU() int
}

Link is an interface that all concrete link types must implement. Concrete link types are resolved from raw links and become part of CLab.Links.

type LinkBriefRaw

type LinkBriefRaw struct {
	Endpoints        []string `yaml:"endpoints"`
	LinkCommonParams `yaml:",inline,omitempty"`
}

LinkBriefRaw is the representation of any supported link in a brief format as defined in the topology file.

func (*LinkBriefRaw) GetType

func (*LinkBriefRaw) GetType() LinkType

func (*LinkBriefRaw) Resolve

func (*LinkBriefRaw) Resolve(_ *ResolveParams) (Link, error)
func (l *LinkBriefRaw) ToTypeSpecificRawLink() (RawLink, error)

ToTypeSpecificRawLink resolves the brief link into a concrete RawLink implementation. LinkBrief is only used to have a short version of a link definition in the topology file, with ToRawLink we convert it into one of the supported link types.

type LinkCommonParams

type LinkCommonParams struct {
	MTU             int                    `yaml:"mtu,omitempty"`
	Labels          map[string]string      `yaml:"labels,omitempty"`
	Vars            map[string]interface{} `yaml:"vars,omitempty"`
	DeploymentState LinkDeploymentState
}

LinkCommonParams represents the common parameters for all link types.

func (*LinkCommonParams) GetMTU added in v0.46.0

func (l *LinkCommonParams) GetMTU() int

GetMTU returns the MTU of the link.

type LinkDefinition

type LinkDefinition struct {
	Type string  `yaml:"type,omitempty"`
	Link RawLink `yaml:",inline"`
}

LinkDefinition represents a link definition in the topology file.

func (*LinkDefinition) MarshalYAML

func (r *LinkDefinition) MarshalYAML() (interface{}, error)

MarshalYAML serializes LinkDefinition (e.g when used with generate command). As of now it falls back to converting the LinkConfig into a RawVEthLink, such that the generated LinkConfigs adhere to the new LinkDefinition format instead of the brief one.

func (*LinkDefinition) UnmarshalYAML

func (ld *LinkDefinition) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML deserializes links passed via topology file into LinkDefinition struct. It supports both the brief and specific link type notations.

type LinkDeploymentState

type LinkDeploymentState uint8

type LinkEndpointType

type LinkEndpointType string

type LinkHostRaw

type LinkHostRaw struct {
	LinkCommonParams `yaml:",inline"`
	HostInterface    string       `yaml:"host-interface"`
	Endpoint         *EndpointRaw `yaml:"endpoint"`
}

LinkHostRaw is the raw (string) representation of a host link as defined in the topology file.

func (*LinkHostRaw) GetType

func (*LinkHostRaw) GetType() LinkType

func (*LinkHostRaw) Resolve

func (r *LinkHostRaw) Resolve(params *ResolveParams) (Link, error)

func (*LinkHostRaw) ToLinkBriefRaw

func (r *LinkHostRaw) ToLinkBriefRaw() *LinkBriefRaw

ToLinkBriefRaw converts the raw link into a LinkConfig.

type LinkMacVlan

type LinkMacVlan struct {
	LinkCommonParams
	HostEndpoint *EndpointMacVlan
	NodeEndpoint Endpoint
	Mode         MacVlanMode
}

func (*LinkMacVlan) Deploy

func (l *LinkMacVlan) Deploy(ctx context.Context, _ Endpoint) error

func (*LinkMacVlan) GetEndpoints

func (l *LinkMacVlan) GetEndpoints() []Endpoint

func (*LinkMacVlan) GetParentInterfaceMTU added in v0.46.2

func (l *LinkMacVlan) GetParentInterfaceMTU() (int, error)

func (*LinkMacVlan) GetType

func (*LinkMacVlan) GetType() LinkType

func (*LinkMacVlan) Remove

func (l *LinkMacVlan) Remove(ctx context.Context) error

type LinkMacVlanRaw

type LinkMacVlanRaw struct {
	LinkCommonParams `yaml:",inline"`
	HostInterface    string       `yaml:"host-interface"`
	Endpoint         *EndpointRaw `yaml:"endpoint"`
	Mode             string       `yaml:"mode"`
}

LinkMacVlanRaw is the raw (string) representation of a macvlan link as defined in the topology file.

func (*LinkMacVlanRaw) GetType

func (*LinkMacVlanRaw) GetType() LinkType

func (*LinkMacVlanRaw) Resolve

func (r *LinkMacVlanRaw) Resolve(params *ResolveParams) (Link, error)

func (*LinkMacVlanRaw) ToLinkBriefRaw

func (r *LinkMacVlanRaw) ToLinkBriefRaw() *LinkBriefRaw

ToLinkBriefRaw converts the raw link into a LinkConfig.

type LinkMgmtNetRaw

type LinkMgmtNetRaw struct {
	LinkCommonParams `yaml:",inline"`
	HostInterface    string       `yaml:"host-interface"`
	Endpoint         *EndpointRaw `yaml:"endpoint"`
}

func (*LinkMgmtNetRaw) GetType

func (*LinkMgmtNetRaw) GetType() LinkType

func (*LinkMgmtNetRaw) Resolve

func (r *LinkMgmtNetRaw) Resolve(params *ResolveParams) (Link, error)

func (*LinkMgmtNetRaw) ToLinkBriefRaw

func (r *LinkMgmtNetRaw) ToLinkBriefRaw() *LinkBriefRaw

type LinkType

type LinkType string

LinkType represents the type of a link definition.

const (
	LinkTypeVEth        LinkType = "veth"
	LinkTypeMgmtNet     LinkType = "mgmt-net"
	LinkTypeMacVLan     LinkType = "macvlan"
	LinkTypeHost        LinkType = "host"
	LinkTypeVxlan       LinkType = "vxlan"
	LinkTypeVxlanStitch LinkType = "vxlan-stitch"

	// LinkTypeBrief is a link definition where link types
	// are encoded in the endpoint definition as string and allow users
	// to quickly type out link endpoints in a yaml file.
	LinkTypeBrief LinkType = "brief"
)

type LinkVEth

type LinkVEth struct {
	LinkCommonParams
	Endpoints []Endpoint
	// contains filtered or unexported fields
}

func NewLinkVEth added in v0.46.0

func NewLinkVEth() *LinkVEth

func (*LinkVEth) Deploy

func (l *LinkVEth) Deploy(ctx context.Context, ep Endpoint) error

Deploy deploys the veth link by creating the A and B sides of the veth pair independently based on the calling endpoint.

func (*LinkVEth) GetEndpoints

func (l *LinkVEth) GetEndpoints() []Endpoint

func (*LinkVEth) GetType

func (*LinkVEth) GetType() LinkType

func (*LinkVEth) Remove

func (l *LinkVEth) Remove(ctx context.Context) error

type LinkVEthRaw

type LinkVEthRaw struct {
	LinkCommonParams `yaml:",inline"`
	Endpoints        []*EndpointRaw `yaml:"endpoints"`
}

LinkVEthRaw is the raw (string) representation of a veth link as defined in the topology file.

func (*LinkVEthRaw) GetType

func (*LinkVEthRaw) GetType() LinkType

func (*LinkVEthRaw) Resolve

func (r *LinkVEthRaw) Resolve(params *ResolveParams) (Link, error)

Resolve resolves the raw veth link definition into a Link interface that is implemented by a concrete LinkVEth struct. Resolving a veth link resolves its endpoints.

func (*LinkVEthRaw) ToLinkBriefRaw

func (r *LinkVEthRaw) ToLinkBriefRaw() *LinkBriefRaw

ToLinkBriefRaw converts the raw link into a LinkBriefRaw.

type LinkVxlan added in v0.46.0

type LinkVxlan struct {
	LinkCommonParams
	// contains filtered or unexported fields
}

func (*LinkVxlan) Deploy added in v0.46.0

func (l *LinkVxlan) Deploy(ctx context.Context, _ Endpoint) error

func (*LinkVxlan) GetEndpoints added in v0.46.0

func (l *LinkVxlan) GetEndpoints() []Endpoint

func (*LinkVxlan) GetType added in v0.46.0

func (*LinkVxlan) GetType() LinkType

func (*LinkVxlan) Remove added in v0.46.0

func (l *LinkVxlan) Remove(ctx context.Context) error

type LinkVxlanRaw added in v0.46.0

type LinkVxlanRaw struct {
	LinkCommonParams `yaml:",inline"`
	Remote           string      `yaml:"remote"`
	VNI              int         `yaml:"vni"`
	Endpoint         EndpointRaw `yaml:"endpoint"`
	UDPPort          int         `yaml:"udp-port,omitempty"`
	ParentInterface  string      `yaml:"parent-interface,omitempty"`

	// we use the same struct for vxlan and vxlan stitch, so we need to differentiate them in the raw format
	LinkType LinkType
}

LinkVxlanRaw is the raw (string) representation of a vxlan link as defined in the topology file.

func (*LinkVxlanRaw) GetType added in v0.46.0

func (*LinkVxlanRaw) GetType() LinkType

func (*LinkVxlanRaw) Resolve added in v0.46.0

func (lr *LinkVxlanRaw) Resolve(params *ResolveParams) (Link, error)

type MacVlanMode

type MacVlanMode string

func MacVlanModeParse

func MacVlanModeParse(s string) (MacVlanMode, error)

func (MacVlanMode) ToNetlinkMode added in v0.46.2

func (m MacVlanMode) ToNetlinkMode() netlink.MacvlanMode

type Node

type Node interface {
	// AddLinkToContainer adds a link to the node (container).
	// In case of a regular container, it will push the link into the
	// network namespace and then run the function f within the namespace
	// this is to rename the link, set mtu, set the interface up, e.g. see link.SetNameMACAndUpInterface()
	//
	// In case of a bridge node (ovs or regular linux bridge) it will take the interface and make the bridge
	// the master of the interface and bring the interface up.
	AddLinkToContainer(ctx context.Context, link netlink.Link, f func(ns.NetNS) error) error
	// AddEndpoint adds the Endpoint to the node
	AddEndpoint(e Endpoint)
	GetLinkEndpointType() LinkEndpointType
	GetShortName() string
	GetEndpoints() []Endpoint
	ExecFunction(context.Context, func(ns.NetNS) error) error
	GetState() state.NodeState
	Delete(ctx context.Context) error
}

Node interface is an interface that is satisfied by all nodes. It is used a subset of the nodes.Node interface and is used to pass nodes.Nodes to the link resolver without causing a circular dependency.

func GetHostLinkNode

func GetHostLinkNode() Node

GetHostLinkNode returns the host link node singleton.

func GetMgmtBrLinkNode

func GetMgmtBrLinkNode() Node
type RawLink interface {
	Resolve(params *ResolveParams) (Link, error)
	GetType() LinkType
}

RawLink is an interface that all raw link types must implement. Raw link types define the links as they are defined in the topology file and solely a product of unmarshalling. Raw links are later "resolved" to concrete link types (e.g LinkVeth).

type ResolveParams

type ResolveParams struct {
	Nodes          map[string]Node
	MgmtBridgeName string
	// list of node shortnames that user
	// passed as a node filter
	NodesFilter []string
	// for the tools command we need to overwrite the
	// veth interface name on the host side. So this can
	// be set and will thereby overwrite the general interface
	// name generation.
	VxlanIfaceNameOverwrite string
}

ResolveParams is a struct that is passed to the Resolve() function of a raw link to resolve it to a concrete link type. Parameters include all nodes of a topology and the name of the management bridge.

type VerifyLinkParams

type VerifyLinkParams struct {
	RunBridgeExistsCheck bool
}

func NewVerifyLinkParams

func NewVerifyLinkParams() *VerifyLinkParams

type VxlanStitched added in v0.46.0

type VxlanStitched struct {
	LinkCommonParams
	// contains filtered or unexported fields
}

func NewVxlanStitched added in v0.46.0

func NewVxlanStitched(vxlan *LinkVxlan, veth *LinkVEth, vethStitchEp Endpoint) *VxlanStitched

NewVxlanStitched constructs a new VxlanStitched object.

func (*VxlanStitched) Deploy added in v0.46.0

func (l *VxlanStitched) Deploy(ctx context.Context, ep Endpoint) error

Deploy provisions the stitched vxlan link with all its underlaying sub-links.

func (*VxlanStitched) DeployWithExistingVeth added in v0.46.0

func (l *VxlanStitched) DeployWithExistingVeth(ctx context.Context, ep Endpoint) error

DeployWithExistingVeth provisons the stitched vxlan link whilst the veth interface does already exist, hence it is not created as part of this deployment.

func (*VxlanStitched) GetEndpoints added in v0.46.0

func (l *VxlanStitched) GetEndpoints() []Endpoint

GetEndpoints returns the endpoints that are part of the link.

func (*VxlanStitched) GetType added in v0.46.0

func (*VxlanStitched) GetType() LinkType

GetType returns the LinkType enum.

func (*VxlanStitched) Remove added in v0.46.0

func (l *VxlanStitched) Remove(ctx context.Context) error

Remove deprovisions the stitched vxlan link.

Jump to

Keyboard shortcuts

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