Documentation ¶
Index ¶
- Constants
- func CheckBridgeExists(n Node) error
- func CheckEndpointDoesNotExistYet(e Endpoint) error
- func CheckEndpointExists(e Endpoint) error
- func CheckEndpointUniqueness(e Endpoint) error
- func SetMgmtNetUnderlayingBridge(bridge string) error
- func SetNameMACAndUpInterface(l netlink.Link, endpt Endpoint) func(ns.NetNS) error
- type Endpoint
- type EndpointBridge
- type EndpointGeneric
- func (e *EndpointGeneric) GetIfaceName() string
- func (e *EndpointGeneric) GetLink() Link
- func (e *EndpointGeneric) GetMac() net.HardwareAddr
- func (e *EndpointGeneric) GetNode() Node
- func (e *EndpointGeneric) GetRandIfaceName() string
- func (e *EndpointGeneric) HasSameNodeAndInterface(ept Endpoint) bool
- func (e *EndpointGeneric) Remove() error
- func (e *EndpointGeneric) String() string
- type EndpointHost
- type EndpointMacVlan
- type EndpointRaw
- type EndpointVeth
- type GenericLinkNode
- func (g *GenericLinkNode) AddEndpoint(e Endpoint)
- func (g *GenericLinkNode) AddLink(l Link)
- func (g *GenericLinkNode) AddLinkToContainer(_ context.Context, link netlink.Link, f func(ns.NetNS) error) error
- func (g *GenericLinkNode) ExecFunction(f func(ns.NetNS) error) error
- func (g *GenericLinkNode) GetEndpoints() []Endpoint
- func (g *GenericLinkNode) GetShortName() string
- func (g *GenericLinkNode) GetState() state.NodeState
- type Link
- type LinkBriefRaw
- type LinkCommonParams
- type LinkDefinition
- type LinkDeploymentState
- type LinkEndpointType
- type LinkHostRaw
- type LinkMacVlan
- type LinkMacVlanRaw
- type LinkMgmtNetRaw
- type LinkType
- type LinkVEth
- type LinkVEthRaw
- type MacVlanMode
- type Node
- type RawLink
- type ResolveParams
- type VerifyLinkParams
Constants ¶
const ( LinkDeploymentStateNotDeployed = iota LinkDeploymentStateDeployed )
const ( LinkEndpointTypeVeth = "veth" LinkEndpointTypeBridge = "bridge" LinkEndpointTypeHost = "host" )
const ( MacVlanModeBridge = "bridge" MacVlanModeVepa = "vepa" MacVlanModePassthru = "passthru" MacVlanModePrivate = "private" MacVlanModeSource = "source" )
const (
// containerlab's reserved OUI.
ClabOUI = "aa:c1:ab"
)
Variables ¶
This section is empty.
Functions ¶
func CheckBridgeExists ¶
CheckBridgeExists verifies that the given bridge is present in the network namespace referenced via the provided nspath handle.
func CheckEndpointDoesNotExistYet ¶
CheckEndpointDoesNotExistYet verifies that the interface referenced in the provided endpoint does not yet exist in the referenced node.
func CheckEndpointExists ¶
CheckEndpointExists checks that a certain interface exists in the network namespace of the given node.
func CheckEndpointUniqueness ¶
CheckEndpointUniqueness checks that the given endpoint appears only once for the node it is assigned to.
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(*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() error }
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
}
func (*EndpointBridge) Verify ¶
func (e *EndpointBridge) Verify(p *VerifyLinkParams) error
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) *EndpointGeneric
func (*EndpointGeneric) GetIfaceName ¶
func (e *EndpointGeneric) GetIfaceName() string
func (*EndpointGeneric) GetLink ¶
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() error
func (*EndpointGeneric) String ¶
func (e *EndpointGeneric) String() string
type EndpointHost ¶
type EndpointHost struct {
EndpointGeneric
}
func (*EndpointHost) Verify ¶
func (e *EndpointHost) Verify(_ *VerifyLinkParams) error
type EndpointMacVlan ¶
type EndpointMacVlan struct {
EndpointGeneric
}
func (*EndpointMacVlan) Verify ¶
func (e *EndpointMacVlan) Verify(_ *VerifyLinkParams) error
Verify verifies the veth based deployment pre-conditions
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 (*EndpointVeth) Verify ¶
func (e *EndpointVeth) Verify(_ *VerifyLinkParams) error
Verify verifies the veth based deployment pre-conditions
type GenericLinkNode ¶
type GenericLinkNode struct {
// contains filtered or unexported fields
}
func (*GenericLinkNode) AddEndpoint ¶
func (g *GenericLinkNode) AddEndpoint(e Endpoint)
func (*GenericLinkNode) AddLink ¶
func (g *GenericLinkNode) AddLink(l Link)
func (*GenericLinkNode) AddLinkToContainer ¶
func (*GenericLinkNode) ExecFunction ¶
func (g *GenericLinkNode) ExecFunction(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 (g *GenericLinkNode) GetState() state.NodeState
type Link ¶
type Link interface { // Deploy deploys the link. Deploy(context.Context) 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 }
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 (l *LinkBriefRaw) GetType() LinkType
func (*LinkBriefRaw) Resolve ¶
func (l *LinkBriefRaw) Resolve(_ *ResolveParams) (Link, error)
func (*LinkBriefRaw) ToTypeSpecificRawLink ¶
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"` }
LinkCommonParams represents the common parameters for all link types.
type LinkDefinition ¶
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 (r *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 Endpoint NodeEndpoint Endpoint Mode MacVlanMode }
func (*LinkMacVlan) GetEndpoints ¶
func (l *LinkMacVlan) GetEndpoints() []Endpoint
func (*LinkMacVlan) GetParentInterfaceMtu ¶
func (l *LinkMacVlan) GetParentInterfaceMtu() (int, error)
func (*LinkMacVlan) GetType ¶
func (l *LinkMacVlan) GetType() LinkType
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 (r *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 (r *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" // 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 (*LinkVEth) GetEndpoints ¶
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 LinkConfig.
type MacVlanMode ¶
type MacVlanMode string
func MacVlanModeParse ¶
func MacVlanModeParse(s string) (MacVlanMode, error)
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 AddLink(l Link) // AddEndpoint adds the Endpoint to the node AddEndpoint(e Endpoint) GetLinkEndpointType() LinkEndpointType GetShortName() string GetEndpoints() []Endpoint ExecFunction(func(ns.NetNS) error) error GetState() state.NodeState }
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 ¶
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 ¶
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