mn

package
v0.0.0-...-195614b Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const NetnsRunDir = "/var/run/netns"

NetnsRunDir default netns run dir

Variables

This section is empty.

Functions

func FullPathFor

func FullPathFor(cmd string) string

FullPathFor generated full path for provided command, based on user's PATH environment variable

func HostName

func HostName(n ...int) string

HostName returns generated name, based on user input or random number

func RunCommand

func RunCommand(cmd string, args ...string) (string, error)

RunCommand is just a wrapper for exec.Command() function

func SwitchName

func SwitchName(n ...int) string

SwitchName returns generated name, based on user input or random number

Types

type Cgroup

type Cgroup struct {
	*cgroup.Cgroup
	Name        string
	Controllers []Controller
}

Cgroup structure

func NewCgroup

func NewCgroup(name string) (*Cgroup, error)

NewCgroup initialise Cgroup instance and does following: 1. Init 2. Init Cgroup struct 3. Set controllers 4. Physically create cgroup 5. Set controllers values

func (*Cgroup) CgExecCommand

func (c *Cgroup) CgExecCommand() []string

CgExecCommand prepares cgexec command

func (*Cgroup) Release

func (c *Cgroup) Release()

Release recusively release cgroup

func (*Cgroup) SetControllers

func (c *Cgroup) SetControllers(controllers []Controller) error

SetControllers add controller into Controllers collection

func (*Cgroup) SetParams

func (c *Cgroup) SetParams(controllers []Controller) error

SetParams sets controller parameters

func (*Cgroup) UnmarshalJSON

func (c *Cgroup) UnmarshalJSON(b []byte) error

UnmarshalJSON satisfies Unarshller

type Controller

type Controller struct {
	Name   string
	Params []Set
}

Controller structure

type Host

type Host struct {
	Cgroup *Cgroup
	Name   string

	Links Links
	Procs Procs
	// contains filtered or unexported fields
}

Host structure

func NewHost

func NewHost(name ...string) (*Host, error)

NewHost create host instance

func NewRouter

func NewRouter(name ...string) (*Host, error)

NewRouter creates a host instance with forwarding enabled

func (h *Host) AddLink(l Link) error

AddLink add link into host's links array

func (Host) GetCidr

func (h Host) GetCidr(peer Peer) string

GetCidr getter

func (Host) GetHwAddr

func (h Host) GetHwAddr(peer Peer) string

GetHwAddr getter

func (h Host) GetLinks() Links

GetLinks links getter

func (Host) GetState

func (h Host) GetState(peer Peer) string

GetState getter

func (Host) LinksCount

func (h Host) LinksCount() int

LinksCount getter

func (Host) NetNs

func (h Host) NetNs() *NetNs

NetNs getter

func (Host) NodeName

func (h Host) NodeName() string

NodeName host name getter

func (Host) Release

func (h Host) Release() error

Release does clean up

func (Host) RunCommand

func (h Host) RunCommand(args ...string) (string, error)

RunCommand prepares ip command to run

func (*Host) RunProcess

func (h *Host) RunProcess(args ...string) (*Process, error)

RunProcess Exported wrapper for run process

func (Host) String

func (h Host) String() string

String satisfies stringer interface

func (*Host) UnmarshalJSON

func (h *Host) UnmarshalJSON(b []byte) error

UnmarshalJSON satisfies Mashaller

type Link struct {
	Cidr     string
	HwAddr   string
	Name     string
	NodeName string
	NetNs    string
	State    string
	Routes   []Route
	PeerName string
	Peer     Peer

	ForceRoot bool `json:"-"`
	// contains filtered or unexported fields
}

Link definition

func (Link) ApplyCidr

func (l Link) ApplyCidr() error

ApplyCidr applies CIDR to the link

func (Link) ApplyMac

func (l Link) ApplyMac() error

ApplyMac applies MAC address

func (Link) ApplyRoutes

func (l Link) ApplyRoutes() error

ApplyRoutes adds routing rule to the link

func (Link) Exists

func (l Link) Exists() bool

Exists checks wheter link exist or not

func (Link) IP

func (l Link) IP() string

IP returns IP from link's CIDR

func (Link) MoveToNs

func (l Link) MoveToNs(netns string) error

MoveToNs moves link to another network namespace

func (Link) Release

func (l Link) Release()

Release the link

func (Link) SetCidr

func (l Link) SetCidr() Link

SetCidr sets next CIDR from the pool to the link

func (Link) SetHwAddr

func (l Link) SetHwAddr() Link

SetHwAddr sets MAC address to the link

func (Link) SetName

func (l Link) SetName(n Node, prefix string) Link

SetName sets the name, interface pairs naming rules:

left (host node)          {peer_host}-{prefix}X
right (namespaced node)   ethX

func (Link) SetNetNs

func (l Link) SetNetNs(n Node) Link

SetNetNs sets network name space

func (Link) SetNodeName

func (l Link) SetNodeName(n Node) Link

SetNodeName for link

func (Link) SetPatch

func (l Link) SetPatch() Link

SetPatch sets patch to the link

func (Link) SetPeer

func (l Link) SetPeer(in Link) Link

SetPeer sets peer to the link

func (Link) SetRoute

func (l Link) SetRoute() Link

SetRoute tmp

func (Link) SetState

func (l Link) SetState(s string) Link

SetState sets link state

func (Link) Up

func (l Link) Up() error

Up sets link to on

type Links []Link

Links is a set of Links

func (Links) LinkByPeer

func (ls Links) LinkByPeer(peer Peer) Link

LinkByPeer search link by peer

type NetNs

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

NetNs definition

func NewNetNs

func NewNetNs(name string) (*NetNs, error)

NewNetNs creates a NetNs instance

func (NetNs) Create

func (n NetNs) Create() error

Create network namespace

func (NetNs) Exists

func (n NetNs) Exists() bool

Exists check whether network namespace exists or not

func (NetNs) Name

func (n NetNs) Name() string

Name getter for network namespace

func (NetNs) Release

func (n NetNs) Release() error

Release network namespace

type Node

type Node interface {
	NodeName() string
	NetNs() *NetNs
	LinksCount() int
	GetCidr(peer Peer) string
	GetHwAddr(peer Peer) string
	GetState(peer Peer) string
	Release() error
	AddLink(Link) error
	GetLinks() Links
}

Node interface

type Pair

type Pair struct {
	Left  Link
	Right Link
}

Pair defenition

func NewLink(left, right Node, refs ...Link) Pair

NewLink (n1, n2, [link1 properties, link2 properties]) property which isn't specified will be generated

func (Pair) ByNodeName

func (pr Pair) ByNodeName(n Node) Link

ByNodeName gets Link by nodename

func (Pair) Create

func (pr Pair) Create() error

Create creates link between veth pair

func (Pair) IsPatch

func (pr Pair) IsPatch() bool

IsPatch check wheter it's patch or not

func (Pair) Release

func (pr Pair) Release()

Release pair

func (Pair) Up

func (pr Pair) Up() (Pair, error)

Up sets pair on

type Peer

type Peer struct {
	Name     string
	IfName   string
	NodeName string
}

Peer definition

type Process

type Process struct {
	*os.Process
	Command string
	Args    []string

	Output string
	// contains filtered or unexported fields
}

Process definition

func (Process) GetPid

func (p Process) GetPid() int

GetPid gets process pid

func (Process) Stop

func (p Process) Stop() error

Stop sends Interrupt signal to the process

type Procs

type Procs []*Process

Procs is set of Process instances

func (Procs) GetByPid

func (ps Procs) GetByPid(pid int) *Process

GetByPid gets process by pid

type Route

type Route struct {
	Dst string
	Gw  string
}

Route definition

type Scheme

type Scheme struct {
	Switches []*Switch
	Hosts    []*Host
	// contains filtered or unexported fields
}

Scheme defenition

func NewScheme

func NewScheme() *Scheme

NewScheme creates instance of the scheme

func NewSchemeFromJSON

func NewSchemeFromJSON(fname string) (*Scheme, error)

NewSchemeFromJSON create scheme from json file

func (*Scheme) AddNode

func (s *Scheme) AddNode(n interface{}) *Scheme

AddNode adds node into scheme

func (Scheme) Export

func (s Scheme) Export() string

Export the scheme

func (*Scheme) GetHost

func (s *Scheme) GetHost(name string) (*Host, bool)

GetHost host getter

func (*Scheme) GetNode

func (s *Scheme) GetNode(name string) (Node, bool)

GetNode returns Node depending on type

func (*Scheme) GetSwitch

func (s *Scheme) GetSwitch(name string) (*Switch, bool)

GetSwitch switch getter

func (*Scheme) Nodes

func (s *Scheme) Nodes() chan Node

Nodes iterator

func (Scheme) Recover

func (s Scheme) Recover() error

Recover nodes scheme

func (*Scheme) Release

func (s *Scheme) Release()

Release nodes

func (Scheme) String

func (s Scheme) String() string

Satisfies stringer interface

type Set

type Set struct {
	Key   string
	Value interface{}
}

Set is a basic key/value structure

type Switch

type Switch struct {
	Name       string
	Ports      Links
	Controller string
}

Switch model

func NewSwitch

func NewSwitch(name ...string) (*Switch, error)

NewSwitch is a constructor for Switch model

func (s *Switch) AddLink(l Link) error

AddLink adds link

func (*Switch) AddPatchPort

func (s *Switch) AddPatchPort(l Link) error

AddPatchPort adds type to path

func (*Switch) AddPort

func (s *Switch) AddPort(l Link) error

AddPort adds port to the link

func (*Switch) Create

func (s *Switch) Create() error

Create creates switch

func (*Switch) Exists

func (s *Switch) Exists() bool

Exists methods check whether Switch exists or not

func (Switch) GetCidr

func (s Switch) GetCidr(peer Peer) string

GetCidr Link CIDR by peer getter

func (Switch) GetHwAddr

func (s Switch) GetHwAddr(peer Peer) string

GetHwAddr MAC address by peer getter

func (s Switch) GetLinks() Links

GetLinks ports(links) getter

func (Switch) GetState

func (s Switch) GetState(peer Peer) string

GetState state getter

func (Switch) LinksCount

func (s Switch) LinksCount() int

LinksCount returns count of available links

func (Switch) NetNs

func (s Switch) NetNs() *NetNs

NetNs is a Network namespace getter

func (Switch) NodeName

func (s Switch) NodeName() string

NodeName getter

func (Switch) Release

func (s Switch) Release() error

Release removes bridge

func (*Switch) SetController

func (s *Switch) SetController(addr string) error

SetController sets Controller name and address

func (Switch) String

func (s Switch) String() string

String implements Stringer interface

func (*Switch) UnmarshalJSON

func (s *Switch) UnmarshalJSON(b []byte) error

UnmarshalJSON implements unmarshaller

Jump to

Keyboard shortcuts

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