network

package
v0.4.31 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIFBLink(name string) *netlink.Ifb

func NewL2TPEndpoint

func NewL2TPEndpoint(netInfo *l2tpNetwork) *l2tpEndpoint

Types

type Action added in v0.4.9

type Action interface {
	// Execute executes this action, returning error if any.
	Execute(ctx context.Context) error
	// Rollback rollbacks this action, returning error if any.
	Rollback() error
}

Action is an abstraction of some action that can be rolled back.

type ActionQueue added in v0.4.9

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

ActionQueue represents a queue of executable actions. Any action that fails triggers cascade previous actions rollback.

func NewActionQueue added in v0.4.9

func NewActionQueue(actions ...Action) *ActionQueue

func (*ActionQueue) Execute added in v0.4.9

func (m *ActionQueue) Execute(ctx context.Context, action Action) (error, error)

Execute executes the given action.

If that action fails a cascade previous actions rollback occurs resulting in a tuple of this's action error and rollback ones if any.

func (*ActionQueue) Rollback added in v0.4.9

func (m *ActionQueue) Rollback() error

type Cleanup

type Cleanup interface {
	Close() error
}

type CreateNetworkRequest added in v0.4.9

type CreateNetworkRequest struct {
	// ID specifies network interface suffix.
	ID               string
	RateLimitEgress  uint64
	RateLimitIngress uint64
}

type DockerNetworkCreateAction added in v0.4.9

type DockerNetworkCreateAction struct {
	DockerClient *client.Client
	Network      *Network
}

func (*DockerNetworkCreateAction) Execute added in v0.4.9

func (*DockerNetworkCreateAction) Rollback added in v0.4.9

func (m *DockerNetworkCreateAction) Rollback() error

type HTBShapingAction added in v0.4.9

type HTBShapingAction struct {
	Network *Network
	// contains filtered or unexported fields
}

func (*HTBShapingAction) Execute added in v0.4.9

func (m *HTBShapingAction) Execute(ctx context.Context) error

func (*HTBShapingAction) Rollback added in v0.4.9

func (m *HTBShapingAction) Rollback() error

type IP4

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

A comparable type for v4 address

func (*IP4) ToCommon

func (i *IP4) ToCommon() net.IP

type IPAMDriver

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

func NewIPAMDriver

func NewIPAMDriver(ctx context.Context, state *l2tpState) *IPAMDriver

func (IPAMDriver) AddNetwork

func (s IPAMDriver) AddNetwork(netID string, netInfo *l2tpNetwork) error

func (IPAMDriver) AddNetworkAlias

func (s IPAMDriver) AddNetworkAlias(netID, alias string) error

func (*IPAMDriver) GetCapabilities

func (d *IPAMDriver) GetCapabilities() (*ipam.CapabilitiesResponse, error)

func (*IPAMDriver) GetDefaultAddressSpaces

func (d *IPAMDriver) GetDefaultAddressSpaces() (*ipam.AddressSpacesResponse, error)

func (IPAMDriver) GetNetwork

func (s IPAMDriver) GetNetwork(netID string) (*l2tpNetwork, error)

func (*IPAMDriver) ReleaseAddress

func (d *IPAMDriver) ReleaseAddress(request *ipam.ReleaseAddressRequest) error

func (*IPAMDriver) ReleasePool

func (d *IPAMDriver) ReleasePool(request *ipam.ReleasePoolRequest) error

func (IPAMDriver) RemoveNetwork

func (s IPAMDriver) RemoveNetwork(netID string) error

func (*IPAMDriver) RequestAddress

func (d *IPAMDriver) RequestAddress(request *ipam.RequestAddressRequest) (*ipam.RequestAddressResponse, error)

func (*IPAMDriver) RequestPool

func (d *IPAMDriver) RequestPool(request *ipam.RequestPoolRequest) (*ipam.RequestPoolResponse, error)

type L2TPCleaner

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

func (*L2TPCleaner) Close

func (t *L2TPCleaner) Close() error

type L2TPConfig

type L2TPConfig struct {
	Enabled        bool   `yaml:"enabled"`
	NetSocketPath  string `required:"false" yaml:"net_socket_path" default:"/run/docker/plugins/l2tp_net.sock"`
	IPAMSocketPath string `required:"false" yaml:"ipam_socket_path" default:"/run/docker/plugins/l2tp_ipam.sock"`
	ConfigDir      string `required:"false" yaml:"config_dir" default:"/tmp/sonm/l2tp/"`
	StatePath      string `required:"false" yaml:"state_path" default:"/tmp/sonm/l2tp/l2tp_network_state"`
}

type L2TPNetworkDriver

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

func NewL2TPDriver

func NewL2TPDriver(ctx context.Context, state *l2tpState) *L2TPNetworkDriver

func (L2TPNetworkDriver) AddNetwork

func (s L2TPNetworkDriver) AddNetwork(netID string, netInfo *l2tpNetwork) error

func (L2TPNetworkDriver) AddNetworkAlias

func (s L2TPNetworkDriver) AddNetworkAlias(netID, alias string) error

func (*L2TPNetworkDriver) AllocateNetwork

func (*L2TPNetworkDriver) CreateEndpoint

func (*L2TPNetworkDriver) CreateNetwork

func (d *L2TPNetworkDriver) CreateNetwork(request *network.CreateNetworkRequest) error

func (*L2TPNetworkDriver) DeleteEndpoint

func (d *L2TPNetworkDriver) DeleteEndpoint(request *network.DeleteEndpointRequest) error

func (*L2TPNetworkDriver) DeleteNetwork

func (d *L2TPNetworkDriver) DeleteNetwork(request *network.DeleteNetworkRequest) error

func (*L2TPNetworkDriver) DiscoverDelete

func (d *L2TPNetworkDriver) DiscoverDelete(request *network.DiscoveryNotification) error

func (*L2TPNetworkDriver) DiscoverNew

func (d *L2TPNetworkDriver) DiscoverNew(request *network.DiscoveryNotification) error

func (*L2TPNetworkDriver) EndpointInfo

func (d *L2TPNetworkDriver) EndpointInfo(request *network.InfoRequest) (*network.InfoResponse, error)

func (*L2TPNetworkDriver) FreeNetwork

func (d *L2TPNetworkDriver) FreeNetwork(request *network.FreeNetworkRequest) error

func (*L2TPNetworkDriver) GetCapabilities

func (d *L2TPNetworkDriver) GetCapabilities() (*network.CapabilitiesResponse, error)

func (L2TPNetworkDriver) GetNetwork

func (s L2TPNetworkDriver) GetNetwork(netID string) (*l2tpNetwork, error)

func (*L2TPNetworkDriver) Join

func (*L2TPNetworkDriver) Leave

func (d *L2TPNetworkDriver) Leave(request *network.LeaveRequest) error

func (*L2TPNetworkDriver) ProgramExternalConnectivity

func (d *L2TPNetworkDriver) ProgramExternalConnectivity(request *network.ProgramExternalConnectivityRequest) error

func (L2TPNetworkDriver) RemoveNetwork

func (s L2TPNetworkDriver) RemoveNetwork(netID string) error

func (*L2TPNetworkDriver) RevokeExternalConnectivity

func (d *L2TPNetworkDriver) RevokeExternalConnectivity(request *network.RevokeExternalConnectivityRequest) error

type L2TPTuner

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

func NewL2TPTuner

func NewL2TPTuner(ctx context.Context, cfg *L2TPConfig) (*L2TPTuner, error)

func (*L2TPTuner) GenerateInvitation

func (t *L2TPTuner) GenerateInvitation(ID string) (*structs.NetworkSpec, error)

func (*L2TPTuner) GetCleaner added in v0.4.6

func (t *L2TPTuner) GetCleaner(ctx context.Context, ID string) (Cleanup, error)

func (*L2TPTuner) Run

func (t *L2TPTuner) Run(ctx context.Context) error

func (*L2TPTuner) Tune

func (*L2TPTuner) Tuned

func (t *L2TPTuner) Tuned(ID string) bool

type Network added in v0.4.9

type Network struct {
	ID               string
	Name             string
	Alias            string
	RateLimitEgress  uint64
	RateLimitIngress uint64
}

type NetworkAliasAction added in v0.4.9

type NetworkAliasAction struct {
	Network *Network
}

NetworkAliasAction represents an action that is capable of creating an alias to the created bridge network.

Must be appended just after creating Docker network.

func (*NetworkAliasAction) Execute added in v0.4.9

func (m *NetworkAliasAction) Execute(ctx context.Context) error

func (*NetworkAliasAction) Rollback added in v0.4.9

func (m *NetworkAliasAction) Rollback() error

type NetworkConfig added in v0.4.21

type NetworkConfig struct {
	// RemoteQOS is an optional QOS server. Used in complex network
	// configurations.
	// You'd likely not want to touch this.
	RemoteQOS string `yaml:"remote_qos"`
}

type NetworkManager added in v0.4.9

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

func NewNetworkManager added in v0.4.9

func NewNetworkManager(options ...Option) (*NetworkManager, error)

NewNetworkManager constructs a new network manager.

Some basic checks are performed during execution of this function, like checking whether the host OS is capable to limit network bandwidth etc.

func (*NetworkManager) Close added in v0.4.9

func (m *NetworkManager) Close() error

func (*NetworkManager) CreateNetwork added in v0.4.9

func (m *NetworkManager) CreateNetwork(ctx context.Context, request *CreateNetworkRequest) (*Network, error)

func (*NetworkManager) Prune added in v0.4.9

func (m *NetworkManager) Prune(ctx context.Context, request *PruneRequest) (*PruneReply, error)

Prune tries to remove all unused networks that look like a SONM networks.

We attach a special tag to Docker networks, so we can identify a network created by us from others.

func (*NetworkManager) RemoveNetwork added in v0.4.9

func (m *NetworkManager) RemoveNetwork(network *Network) error

type NetworkManagerConfig added in v0.4.9

type NetworkManagerConfig struct {
	RemoteManagerAddr string
	DockerClient      *client.Client
	Log               *zap.SugaredLogger
}

type Option added in v0.4.21

type Option func(o *options) error

func WithLog added in v0.4.21

func WithLog(log *zap.SugaredLogger) Option

func WithRemote added in v0.4.21

func WithRemote(uri string) Option

type PruneReply added in v0.4.9

type PruneReply struct {
	// Result contains information about network removing result.
	Result map[string]error
}

type PruneRequest added in v0.4.9

type PruneRequest struct {
	// IDs specify network interface suffixes.
	IDs []string
}

type RemoteHTBShapingAction added in v0.4.21

type RemoteHTBShapingAction struct {
	Client  sonm.QOSClient
	Network *Network
}

func (*RemoteHTBShapingAction) Execute added in v0.4.21

func (m *RemoteHTBShapingAction) Execute(ctx context.Context) error

func (*RemoteHTBShapingAction) Rollback added in v0.4.21

func (m *RemoteHTBShapingAction) Rollback() error

type RemoteNetworkAliasAction added in v0.4.21

type RemoteNetworkAliasAction struct {
	Client  sonm.QOSClient
	Network *Network
}

func (*RemoteNetworkAliasAction) Execute added in v0.4.21

func (*RemoteNetworkAliasAction) Rollback added in v0.4.21

func (m *RemoteNetworkAliasAction) Rollback() error

type RemoteQOS added in v0.4.21

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

func NewRemoteQOS added in v0.4.21

func NewRemoteQOS() (*RemoteQOS, error)

func (*RemoteQOS) AddHTBShaping added in v0.4.21

func (m *RemoteQOS) AddHTBShaping(ctx context.Context, request *sonm.QOSAddHTBShapingRequest) (*sonm.QOSAddHTBShapingResponse, error)

func (*RemoteQOS) Flush added in v0.4.22

func (m *RemoteQOS) Flush(ctx context.Context, request *sonm.QOSFlushRequest) (*sonm.QOSFlushResponse, error)

func (*RemoteQOS) RemoveHTBShaping added in v0.4.21

func (m *RemoteQOS) RemoveHTBShaping(ctx context.Context, request *sonm.QOSRemoveHTBShapingRequest) (*sonm.QOSRemoveHTBShapingResponse, error)

func (*RemoteQOS) SetAlias added in v0.4.21

func (m *RemoteQOS) SetAlias(ctx context.Context, request *sonm.QOSSetAliasRequest) (*sonm.QOSSetAliasResponse, error)

type TBFShapingAction added in v0.4.9

type TBFShapingAction struct {
	Network *Network
	// contains filtered or unexported fields
}

func (*TBFShapingAction) Execute added in v0.4.9

func (m *TBFShapingAction) Execute(ctx context.Context) error

func (*TBFShapingAction) Rollback added in v0.4.9

func (m *TBFShapingAction) Rollback() error

type TincCleaner

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

func (*TincCleaner) Close

func (t *TincCleaner) Close() (err error)

type TincIPAMDriver

type TincIPAMDriver struct {
	*TincNetworkState
	// contains filtered or unexported fields
}

func NewTincIPAMDriver

func NewTincIPAMDriver(ctx context.Context, state *TincNetworkState, config *TincNetworkConfig) (*TincIPAMDriver, error)

func (*TincIPAMDriver) GetCapabilities

func (t *TincIPAMDriver) GetCapabilities() (*ipam.CapabilitiesResponse, error)

func (*TincIPAMDriver) GetDefaultAddressSpaces

func (t *TincIPAMDriver) GetDefaultAddressSpaces() (*ipam.AddressSpacesResponse, error)

func (*TincIPAMDriver) ReleaseAddress

func (t *TincIPAMDriver) ReleaseAddress(request *ipam.ReleaseAddressRequest) error

func (*TincIPAMDriver) ReleasePool

func (t *TincIPAMDriver) ReleasePool(request *ipam.ReleasePoolRequest) error

func (*TincIPAMDriver) RequestAddress

func (*TincIPAMDriver) RequestPool

func (t *TincIPAMDriver) RequestPool(request *ipam.RequestPoolRequest) (*ipam.RequestPoolResponse, error)

type TincNetwork

type TincNetwork struct {
	NodeID       string
	DockerID     string
	Pool         *net.IPNet
	Invitation   string
	EnableBridge bool
	CgroupParent string

	ConfigPath      string
	TincContainerID string
	// contains filtered or unexported fields
}

func (*TincNetwork) Init

func (t *TincNetwork) Init(ctx context.Context) error

func (*TincNetwork) Invite

func (t *TincNetwork) Invite(ctx context.Context, inviteeID string) (string, error)

func (*TincNetwork) Join

func (t *TincNetwork) Join(ctx context.Context) error

func (*TincNetwork) OccupiedIPs

func (t *TincNetwork) OccupiedIPs(ctx context.Context) (map[IP4]struct{}, error)

func (*TincNetwork) Shutdown

func (t *TincNetwork) Shutdown(ctx context.Context) error

func (*TincNetwork) Start

func (t *TincNetwork) Start(ctx context.Context, addr string) error

func (*TincNetwork) Stop

func (t *TincNetwork) Stop(ctx context.Context) error

type TincNetworkConfig

type TincNetworkConfig struct {
	Enabled                  bool   `yaml:"enabled"`
	ConfigDir                string `yaml:"config_dir" default:"/tinc"`
	DockerNetPluginSockPath  string `yaml:"docker_net_plugin_dir" default:"/run/docker/plugins/tinc/tinc.sock"`
	DockerIPAMPluginSockPath string `yaml:"docker_ipam_plugin_dir" default:"/run/docker/plugins/tincipam/tincipam.sock"`
	DockerImage              string `yaml:"docker_image" default:"sonm/tinc"`
	StatePath                string `yaml:"state_path" default:"/var/lib/sonm/tinc_network_state"`
}

type TincNetworkDriver

type TincNetworkDriver struct {
	*TincNetworkState
	// contains filtered or unexported fields
}

func (*TincNetworkDriver) AllocateNetwork

func (*TincNetworkDriver) CreateEndpoint

func (*TincNetworkDriver) CreateNetwork

func (t *TincNetworkDriver) CreateNetwork(request *network.CreateNetworkRequest) error

func (*TincNetworkDriver) DeleteEndpoint

func (t *TincNetworkDriver) DeleteEndpoint(request *network.DeleteEndpointRequest) error

func (*TincNetworkDriver) DeleteNetwork

func (t *TincNetworkDriver) DeleteNetwork(request *network.DeleteNetworkRequest) error

func (*TincNetworkDriver) DiscoverDelete

func (t *TincNetworkDriver) DiscoverDelete(request *network.DiscoveryNotification) error

func (*TincNetworkDriver) DiscoverNew

func (t *TincNetworkDriver) DiscoverNew(request *network.DiscoveryNotification) error

func (*TincNetworkDriver) EndpointInfo

func (t *TincNetworkDriver) EndpointInfo(request *network.InfoRequest) (*network.InfoResponse, error)

func (*TincNetworkDriver) FreeNetwork

func (t *TincNetworkDriver) FreeNetwork(request *network.FreeNetworkRequest) error

func (*TincNetworkDriver) GenerateInvitation

func (t *TincNetworkDriver) GenerateInvitation(NodeID string) (*structs.NetworkSpec, error)

func (*TincNetworkDriver) GetCapabilities

func (t *TincNetworkDriver) GetCapabilities() (*network.CapabilitiesResponse, error)

func (*TincNetworkDriver) HasNetwork

func (t *TincNetworkDriver) HasNetwork(NodeID string) bool

func (*TincNetworkDriver) Join

func (*TincNetworkDriver) Leave

func (t *TincNetworkDriver) Leave(request *network.LeaveRequest) error

func (*TincNetworkDriver) ProgramExternalConnectivity

func (t *TincNetworkDriver) ProgramExternalConnectivity(request *network.ProgramExternalConnectivityRequest) error

func (*TincNetworkDriver) RevokeExternalConnectivity

func (t *TincNetworkDriver) RevokeExternalConnectivity(request *network.RevokeExternalConnectivityRequest) error

type TincNetworkState

type TincNetworkState struct {
	Networks map[string]*TincNetwork
	Pools    map[string]*net.IPNet
	// contains filtered or unexported fields
}

func (*TincNetworkState) InsertTincNetwork

func (t *TincNetworkState) InsertTincNetwork(n *structs.NetworkSpec, cgroupParent string) (*TincNetwork, error)

type TincTuner

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

func NewTincTuner

func NewTincTuner(ctx context.Context, config *TincNetworkConfig) (*TincTuner, error)

func (*TincTuner) GenerateInvitation

func (t *TincTuner) GenerateInvitation(ID string) (*structs.NetworkSpec, error)

func (*TincTuner) GetCleaner added in v0.4.6

func (t *TincTuner) GetCleaner(ctx context.Context, ID string) (Cleanup, error)

func (*TincTuner) Tune

func (*TincTuner) Tuned

func (t *TincTuner) Tuned(ID string) bool

type Tuner

type Tuner interface {
	Tune(ctx context.Context, net *structs.NetworkSpec, hostConfig *container.HostConfig, netConfig *network.NetworkingConfig) (Cleanup, error)
	GenerateInvitation(ID string) (*structs.NetworkSpec, error)
	GetCleaner(ctx context.Context, ID string) (Cleanup, error)
	Tuned(ID string) bool
}

Tuner is responsible for preparing networking and baking proper options in container.HostConfig and network.NetworkingConfig.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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