Documentation ¶
Index ¶
- Constants
- Variables
- func AddVxLanInterface(vxlan VxLAN) (err error)
- func BindIfacesWithTC(if1, if2 string) (err error)
- func CreateDirectory(path string, perm os.FileMode)
- func EthtoolTXOff(name string) error
- func GetLiknsByNamePrefix(prefix string) ([]netlink.Link, error)
- func SetIngressMirror(src, dst string) (err error)
- func StringInSlice(slice []string, val string) (int, bool)
- type CLab
- func (c *CLab) CheckResources() error
- func (c *CLab) CheckTopologyDefinition(ctx context.Context) error
- func (c *CLab) CreateContainer(ctx context.Context, node *Node) (err error)
- func (c *CLab) CreateDockerNet(ctx context.Context) (err error)
- func (c *CLab) CreateLinks(ctx context.Context, workers uint, postdeploy bool)
- func (c *CLab) CreateNode(ctx context.Context, node *Node, certs *Certificates) error
- func (c *CLab) CreateNodeDirStructure(node *Node) (err error)
- func (c *CLab) CreateNodes(ctx context.Context, workers uint)
- func (c *CLab) CreateRootCA() error
- func (c *CLab) CreateVirtualWiring(l *Link) (err error)
- func (c *CLab) DeleteBridge(ctx context.Context) (err error)
- func (c *CLab) DeleteContainer(ctx context.Context, name string) error
- func (c *CLab) DeleteNetnsSymlinks() (err error)
- func (c *CLab) Exec(ctx context.Context, id string, cmd []string) ([]byte, []byte, error)
- func (c *CLab) ExecNotWait(ctx context.Context, id string, cmd []string) error
- func (c *CLab) ExecPostDeployTasks(ctx context.Context, node *Node, lworkers uint) error
- func (c *CLab) GenerateCert(ca string, caKey string, csrJSONTpl *template.Template, input CertInput, ...) (*Certificates, error)
- func (c *CLab) GenerateGraph(topo string) error
- func (c *CLab) GenerateInventories() error
- func (c *CLab) GenerateRootCa(csrRootJsonTpl *template.Template, input CaRootInput) (*Certificates, error)
- func (c *CLab) GetNSPath(ctx context.Context, containerId string) (string, error)
- func (c *CLab) GetTopology(topo string) error
- func (c *CLab) ListContainers(ctx context.Context, labels []string) ([]types.Container, error)
- func (c *CLab) NewEndpoint(e string) *Endpoint
- func (c *CLab) NewLink(l LinkConfig) *Link
- func (c *CLab) NewNode(nodeName string, nodeCfg NodeConfig, idx int) error
- func (c *CLab) ParseTopology() error
- func (c *CLab) PullImageIfRequired(ctx context.Context, imageName string) error
- func (c *CLab) RetrieveNodeCertData(n *Node) (*Certificates, error)
- func (c *CLab) StartContainer(ctx context.Context, id string) error
- func (c *CLab) VerifyContainersUniqueness(ctx context.Context) error
- func (c *CLab) VerifyImages(ctx context.Context) error
- type CaRootInput
- type CertInput
- type Certificates
- type ClabOption
- type Config
- type Directory
- type Endpoint
- type EthtoolValue
- type IFReqData
- type Link
- type LinkConfig
- type Node
- type NodeConfig
- type TopoFile
- type Topology
- type VxLAN
Constants ¶
const ( SIOCETHTOOL = 0x8946 // linux/sockios.h ETHTOOL_GTXCSUM = 0x00000016 // linux/ethtool.h ETHTOOL_STXCSUM = 0x00000017 // linux/ethtool.h IFNAMSIZ = 16 // linux/if.h )
Variables ¶
var DefaultCredentials = map[string][]string{
"vr-sros": {"admin", "admin"},
"vr-vmx": {"admin", "admin@123"},
"vr-xrv9k": {"clab", "clab@123"},
}
DefaultCredentials holds default username and password per each kind
Functions ¶
func AddVxLanInterface ¶
AddVxLanInterface creates VxLan interface by given vxlan object
func BindIfacesWithTC ¶
BindIfacesWithTC creates TC ingress mirred redirection between a pair of interfaces to make them virtually form a kind of a veth pair see https://netdevops.me/2021/transparently-redirecting-packets/frames-between-interfaces/#4-tc-to-the-rescue used https://github.com/redhat-nfvpe/koko/blob/bd156c82bf25837545fb109c69c7b91c3457b318/api/koko_api.go#L224 and https://gist.github.com/mcastelino/7d85f4164ffdaf48242f9281bb1d0f9b#gistcomment-2734521
func CreateDirectory ¶
CreateDirectory creates a directory by a path with a mode/permission specified by perm. If directory exists, the function does not do anything.
func EthtoolTXOff ¶
EthtoolTXOff disables TX checksum offload on specified interface
func GetLiknsByNamePrefix ¶
GetLiknsByNamePrefix returns a list of links whose name matches a prefix
func SetIngressMirror ¶
SetIngressMirror sets TC to mirror ingress from given port as MirrorIngress.
Types ¶
type CLab ¶
type CLab struct { Config *Config TopoFile *TopoFile Nodes map[string]*Node Links map[int]*Link DockerClient *docker.Client Dir *Directory // contains filtered or unexported fields }
func NewContainerLab ¶
func NewContainerLab(opts ...ClabOption) *CLab
NewContainerLab function defines a new container lab
func (*CLab) CheckResources ¶
CheckResources runs container host resources check
func (*CLab) CheckTopologyDefinition ¶
CheckTopologyDefinition runs topology checks and returns any errors found
func (*CLab) CreateContainer ¶
CreateContainer creates a docker container
func (*CLab) CreateDockerNet ¶
CreateDockerNet creates a docker network or reusing if it exists
func (*CLab) CreateLinks ¶
CreateLinks creates links using the specified number of workers `postdeploy` indicates the stage of links creation. `postdeploy=true` means the links routine is called after nodes postdeploy tasks
func (*CLab) CreateNode ¶
func (*CLab) CreateNodeDirStructure ¶
CreateNodeDirStructure create the directory structure and files for the lab nodes
func (*CLab) CreateRootCA ¶
CreateRootCA creates RootCA key/certificate if it is needed by the topology
func (*CLab) CreateVirtualWiring ¶
CreateVirtualWiring creates the virtual topology between the containers
func (*CLab) DeleteBridge ¶
DeleteBridge deletes a docker bridge
func (*CLab) DeleteContainer ¶
DeleteContainer tries to stop a container then remove it
func (*CLab) DeleteNetnsSymlinks ¶
DeleteNetnsSymlinks deletes the symlink file created for each container netns
func (*CLab) Exec ¶
Exec executes cmd on container identified with id and returns stdout, stderr bytes and an error
func (*CLab) ExecNotWait ¶
ExecNotWait executes cmd on container identified with id but doesn't wait for output nor attaches stodout/err
func (*CLab) ExecPostDeployTasks ¶
ExecPostDeployTasks executes tasks that some nodes might require to boot properly after start
func (*CLab) GenerateCert ¶
func (c *CLab) GenerateCert(ca string, caKey string, csrJSONTpl *template.Template, input CertInput, targetPath string) (*Certificates, error)
GenerateCert generates and signs a certificate passed as input and saves the certificate and generated private key by path CA used to sign the cert is passed as ca and caKey file paths
func (*CLab) GenerateGraph ¶
GenerateGraph generates a graph of the lab topology
func (*CLab) GenerateInventories ¶
GenerateInventories generate various inventory files and writes it to a lab location
func (*CLab) GenerateRootCa ¶
func (c *CLab) GenerateRootCa(csrRootJsonTpl *template.Template, input CaRootInput) (*Certificates, error)
GenerateRootCa function
func (*CLab) GetNSPath ¶
GetNSPath inspects a container by its name/id and returns an netns path using the pid of a container
func (*CLab) GetTopology ¶
GetTopology parses the topology file into c.Conf structure as well as populates the TopoFile structure with the topology file related information
func (*CLab) ListContainers ¶
ListContainers lists all containers with labels []string
func (*CLab) NewEndpoint ¶
NewEndpoint initializes a new endpoint object
func (*CLab) NewLink ¶
func (c *CLab) NewLink(l LinkConfig) *Link
NewLink initializes a new link object
func (*CLab) NewNode ¶
func (c *CLab) NewNode(nodeName string, nodeCfg NodeConfig, idx int) error
NewNode initializes a new node object
func (*CLab) ParseTopology ¶
ParseTopology parses the lab topology
func (*CLab) PullImageIfRequired ¶
func (*CLab) RetrieveNodeCertData ¶
func (c *CLab) RetrieveNodeCertData(n *Node) (*Certificates, error)
RetrieveNodeCertData reads the node private key and certificate by the well known paths if either of those files doesn't exist, an error is returned
func (*CLab) StartContainer ¶
StartContainer starts a docker container
func (*CLab) VerifyContainersUniqueness ¶
VerifyContainersUniqueness ensures that nodes defined in the topology do not have names of the existing containers
type CaRootInput ¶
type CaRootInput struct { CommonName string Country string Locality string Organization string OrganizationUnit string Expiry string Prefix string Names map[string]string // Not used right now // prefix for certificate/key file name NamePrefix string }
CaRootInput struct
type CertInput ¶
type CertInput struct { Hosts []string CommonName string Country string Locality string Organization string OrganizationUnit string Expiry string Name string LongName string Fqdn string Prefix string }
CertInput struct
type Certificates ¶
type ClabOption ¶
type ClabOption func(c *CLab)
func WithDebug ¶
func WithDebug(d bool) ClabOption
func WithEnvDockerClient ¶
func WithEnvDockerClient() ClabOption
func WithGracefulShutdown ¶
func WithGracefulShutdown(gracefulShutdown bool) ClabOption
func WithTimeout ¶
func WithTimeout(dur time.Duration) ClabOption
func WithTopoFile ¶
func WithTopoFile(file string) ClabOption
type Config ¶
type Config struct { Name string `json:"name,omitempty"` Mgmt mgmtNet `json:"mgmt,omitempty"` Topology Topology `json:"topology,omitempty"` ConfigPath string `yaml:"config_path,omitempty"` }
Config defines lab configuration as it is provided in the YAML file
type EthtoolValue ¶
linux/ethtool.h 'struct ethtool_value'
type LinkConfig ¶
type Node ¶
type Node struct { ShortName string LongName string Fqdn string LabDir string // LabDir is a directory related to the node, it contains config items and/or other persistent state Index int Group string Kind string // path to config template file that is used for config generation Config string ResConfig string // path to config file that is actually mounted to the container and is a result of templation NodeType string Position string License string Image string Topology string Sysctls map[string]string User string Entrypoint string Cmd string Env map[string]string Binds []string // Bind mounts strings (src:dest:options) PortBindings nat.PortMap // PortBindings define the bindings between the container ports and host ports PortSet nat.PortSet // PortSet define the ports that should be exposed on a container // container networking mode. if set to `host` the host networking will be used for this node, else bridged network NetworkMode string MgmtNet string // name of the docker network this node is connected to with its first interface MgmtIPv4Address string MgmtIPv4PrefixLength int MgmtIPv6Address string MgmtIPv6PrefixLength int ContainerID string TLSCert string TLSKey string TLSAnchor string NSPath string // network namespace path for this node Publish []string //list of ports to publish with mysocketctl // container labels Labels map[string]string }
Node is a struct that contains the information of a container element
type NodeConfig ¶
type NodeConfig struct { Kind string `yaml:"kind,omitempty"` Group string `yaml:"group,omitempty"` Type string `yaml:"type,omitempty"` Config string `yaml:"config,omitempty"` Image string `yaml:"image,omitempty"` License string `yaml:"license,omitempty"` Position string `yaml:"position,omitempty"` Cmd string `yaml:"cmd,omitempty"` // list of bind mount compatible strings Binds []string `yaml:"binds,omitempty"` // list of port bindings Ports []string `yaml:"ports,omitempty"` // user-defined IPv4 address in the management network MgmtIPv4 string `yaml:"mgmt_ipv4,omitempty"` // user-defined IPv6 address in the management network MgmtIPv6 string `yaml:"mgmt_ipv6,omitempty"` // list of ports to publish with mysocketctl Publish []string `yaml:"publish,omitempty"` // environment variables Env map[string]string `yaml:"env,omitempty"` // linux user used in a container User string `yaml:"user,omitempty"` // container labels Labels map[string]string `yaml:"labels,omitempty"` // container networking mode. if set to `host` the host networking will be used for this node, else bridged network NetworkMode string `yaml:"network-mode,omitempty"` }
NodeConfig represents a configuration a given node can have in the lab definition file
type TopoFile ¶
type TopoFile struct {
// contains filtered or unexported fields
}
TopoFile type is a struct which defines parameters of the topology file
type Topology ¶
type Topology struct { Defaults NodeConfig `yaml:"defaults,omitempty"` Kinds map[string]NodeConfig `yaml:"kinds,omitempty"` Nodes map[string]NodeConfig `yaml:"nodes,omitempty"` Links []LinkConfig `yaml:"links,omitempty"` }
Topology represents a lab topology
type VxLAN ¶
type VxLAN struct { Name string // interface name ParentIf string // parent interface name ID int // VxLan ID Remote net.IP // VxLan destination address MTU int // VxLan Interface MTU (with VxLan encap), used mirroring UDPPort int // VxLan UDP port (src/dest, no range, single value) }
VxLAN is a structure to describe vxlan endpoint adopted from https://github.com/redhat-nfvpe/koko/blob/bd156c82bf25837545fb109c69c7b91c3457b318/api/koko_api.go#L46