subnets

package
v0.333.2-candidate Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2016 License: Apache-2.0 Imports: 7 Imported by: 6

Documentation

Overview

The subnets package provides a subnet pool from which networks may be dynamically acquired or statically reserved.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInsufficientSubnets is returned by AcquireDynamically if no more subnets can be allocated.
	ErrInsufficientSubnets = errors.New("insufficient subnets remaining in the pool")

	// ErrInsufficientIPs is returned by AcquireDynamically if no more IPs can be allocated.
	ErrInsufficientIPs = errors.New("insufficient IPs remaining in the pool")

	// ErrReleasedUnallocatedNetwork is returned by Release if the subnet is not allocated.
	ErrReleasedUnallocatedSubnet = errors.New("subnet is not allocated")

	// ErrOverlapsExistingSubnet is returned if a recovered subnet overlaps an existing, allocated subnet
	ErrOverlapsExistingSubnet = errors.New("subnet overlaps an existing subnet")

	// ErrInvalidRange is returned by AcquireStatically and by Recover if the subnet range is invalid.
	ErrInvalidRange = errors.New("subnet has invalid range")

	// ErrInvalidIP is returned if a static IP is requested inside a subnet
	// which does not contain that IP
	ErrInvalidIP = errors.New("the requested IP is not within the subnet")

	// ErrIPAlreadyAcquired is returned if a static IP is requested which has already been allocated
	ErrIPAlreadyAcquired = errors.New("the requested IP is already allocated")

	// ErrIpCannotBeNil is returned by Release(..) and Recover(..) if a nil
	// IP address is passed.
	ErrIpCannotBeNil = errors.New("the IP field cannot be empty")

	ErrIPEqualsGateway   = errors.New("a container IP must not equal the gateway IP")
	ErrIPEqualsBroadcast = errors.New("a container IP must not equal the broadcast IP")
)
View Source
var DynamicIPSelector dynamicIPSelector = 0

DynamicIPSelector requests the next available ("dynamic") IP address from a given subnet. Returns an error if no more IP addresses remain in the subnet.

View Source
var DynamicSubnetSelector dynamicSubnetSelector = 0

DynamicSubnetSelector requests the next unallocated ("dynamic") subnet from the dynamic range. Returns an error if there are no remaining subnets in the dynamic range.

Functions

func BroadcastIP

func BroadcastIP(subnet *net.IPNet) net.IP

Returns the broadcast IP of a subnet.

func GatewayIP

func GatewayIP(subnet *net.IPNet) net.IP

Returns the gateway IP of a given subnet, which is always the maximum valid IP

func NetworkIP

func NetworkIP(subnet *net.IPNet) net.IP

Returns the network IP of a subnet.

Types

type IPSelector

type IPSelector interface {
	// Returns an IP address in the given subnet which is not one of the given existing
	// IP addresses. If no such IP address can be found, returns an error.
	SelectIP(subnet *net.IPNet, existing []net.IP) (net.IP, error)
}

IPSelector is a strategy for selecting an IP address in a subnet.

type StaticIPSelector

type StaticIPSelector struct {
	net.IP
}

StaticIPSelector requests a specific ("static") IP address. Returns an error if the IP is already allocated, or if it is outside the given subnet.

func (StaticIPSelector) SelectIP

func (s StaticIPSelector) SelectIP(subnet *net.IPNet, existing []net.IP) (net.IP, error)

type StaticSubnetSelector

type StaticSubnetSelector struct {
	*net.IPNet
}

StaticSubnetSelector requests a specific ("static") subnet. Returns an error if the subnet is already allocated.

func (StaticSubnetSelector) SelectSubnet

func (s StaticSubnetSelector) SelectSubnet(dynamic *net.IPNet, existing []*net.IPNet) (*net.IPNet, error)

type SubnetSelector

type SubnetSelector interface {
	// Returns a subnet based on a dynamic range and some existing statically-allocated
	// subnets. If no suitable subnet can be found, returns an error.
	SelectSubnet(dynamic *net.IPNet, existing []*net.IPNet) (*net.IPNet, error)
}

SubnetSelector is a strategy for selecting a subnet.

type Subnets

type Subnets interface {
	// Allocates an IP address and associates it with a subnet. The subnet is selected by the given SubnetSelector.
	// The IP address is selected by the given IPSelector.
	// Returns a subnet, an IP address, and a boolean which is true if and only if this is the
	// first IP address to be associated with this subnet.
	// If either selector fails, an error is returned.
	Acquire(SubnetSelector, IPSelector, lager.Logger) (*linux_backend.Network, error)

	// Releases an IP address associated with an allocated subnet. If the subnet has no other IP
	// addresses associated with it, it is deallocated.
	// Returns a boolean which is true if and only if the subnet was deallocated.
	// Returns an error if the given combination is not already in the pool.
	Release(*linux_backend.Network, lager.Logger) error

	// Remove an IP address so it appears to be associated with the given subnet.
	Remove(*linux_backend.Network, lager.Logger) error

	// Returns the number of /30 subnets which can be Acquired by a DynamicSubnetSelector.
	Capacity() int
}

Subnets provides a means of allocating subnets and associated IP addresses.

func NewSubnets

func NewSubnets(ipNet *net.IPNet) (Subnets, error)

New creates a Subnets implementation from a dynamic allocation range. All dynamic allocations come from the range, static allocations are prohibited from the dynamic range.

Directories

Path Synopsis
This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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