types

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4Only  = IPFamilyMode("IPv4Only")
	IPv6Only  = IPFamilyMode("IPv6Only")
	DualStack = IPFamilyMode("DualStack")
)
View Source
const (
	Underlay = NetworkType("Underlay")
	Overlay  = NetworkType("Overlay")
)
View Source
const (
	IPStatusUsing    = "Using"
	IPStatusReserved = "Reserved"
)

Variables

View Source
var (
	ErrNoAvailableSubnet      = errors.New("no available subnet")
	ErrNotFoundSubnet         = errors.New("subnet not found")
	ErrNotFoundAssignedIP     = errors.New("assigned ip not found")
	ErrNotAvailableAssignedIP = errors.New("assigned ip is not available")
)
View Source
var (
	ErrNotFoundNetwork = errors.New("network not found")
)

Functions

This section is empty.

Types

type IP

type IP struct {
	Address *net.IPNet
	Gateway net.IP
	NetID   *uint32
	Subnet  string
	Network string

	PodName      string
	PodNamespace string

	Status string
}

func (*IP) IsIPv6

func (i *IP) IsIPv6() bool

func (*IP) String

func (i *IP) String() string

type IPFamilyMode

type IPFamilyMode string

func ParseIPFamilyFromString

func ParseIPFamilyFromString(in string) IPFamilyMode

type IPSet

type IPSet map[string]*IP

func NewIPSet

func NewIPSet() IPSet

func (IPSet) Add

func (s IPSet) Add(ip string, content *IP)

func (IPSet) Count

func (s IPSet) Count() int

func (IPSet) Delete

func (s IPSet) Delete(ip string)

func (IPSet) Get

func (s IPSet) Get(ip string) *IP

func (IPSet) Has

func (s IPSet) Has(ip string) bool

func (IPSet) Update

func (s IPSet) Update(ip, podName, podNamespace, status string)

type IPSlice

type IPSlice struct {
	IPs []string

	IPCount int
	IPIndex int
}

func NewIPSlice

func NewIPSlice() *IPSlice

func (*IPSlice) Add

func (s *IPSlice) Add(ip string, isDefault bool)

func (*IPSlice) Count

func (s *IPSlice) Count() int

func (*IPSlice) Current

func (s *IPSlice) Current() string

func (*IPSlice) Next

func (s *IPSlice) Next() string

type Network

type Network struct {
	// Spec fields
	Name                string
	NetID               *uint32
	LastAllocatedSubnet string
	Type                NetworkType

	Subnets *SubnetSlice
}

func NewNetwork

func NewNetwork(name string, netID *uint32, lastAllocatedSubnet string, networkType NetworkType) *Network

func (*Network) AddSubnet

func (n *Network) AddSubnet(subnet *Subnet, ips IPSet) error

func (*Network) DualStackUsage

func (n *Network) DualStackUsage() ([3]*Usage, map[string]*Usage, error)

func (*Network) GetIPv4Subnet

func (n *Network) GetIPv4Subnet(subnetName string) (sn *Subnet, err error)

func (*Network) GetIPv6Subnet

func (n *Network) GetIPv6Subnet(subnetName string) (sn *Subnet, err error)

func (*Network) GetPairedDualStackSubnets

func (n *Network) GetPairedDualStackSubnets(v4Name, v6Name string) (v4Subnet *Subnet, v6Subnet *Subnet, err error)

func (*Network) GetSubnet

func (n *Network) GetSubnet(subnetName string) (*Subnet, error)

func (*Network) GetSubnetByIP

func (n *Network) GetSubnetByIP(subnetName, ip string) (*Subnet, error)

func (*Network) Usage

func (n *Network) Usage() (*Usage, map[string]*Usage, error)

type NetworkSet

type NetworkSet map[string]*Network

func NewNetworkSet

func NewNetworkSet() NetworkSet

func (NetworkSet) GetNetwork

func (n NetworkSet) GetNetwork(name string) (*Network, error)

func (NetworkSet) GetNetworksByType

func (n NetworkSet) GetNetworksByType(networkType NetworkType) (names []string)

func (NetworkSet) MatchNetworkType

func (n NetworkSet) MatchNetworkType(networkName string, networkType NetworkType) bool

func (NetworkSet) RefreshNetwork

func (n NetworkSet) RefreshNetwork(name string, network *Network)

func (NetworkSet) RemoveNetwork

func (n NetworkSet) RemoveNetwork(name string)

type NetworkType

type NetworkType string

func ParseNetworkTypeFromEnv

func ParseNetworkTypeFromEnv() NetworkType

TODO: remove this defaulting logic if overlay become the general option for more users

func ParseNetworkTypeFromString

func ParseNetworkTypeFromString(in string) NetworkType

type Subnet

type Subnet struct {
	// Spec fields
	// `Canonicalize` method will initialize these
	Name            string
	ParentNetwork   string
	NetID           *uint32
	Start           net.IP
	End             net.IP
	CIDR            *net.IPNet
	Gateway         net.IP
	ReservedList    map[string]struct{}
	BlackList       map[string]struct{}
	LastAllocatedIP net.IP
	Private         bool
	IPv6            bool

	// Status fields
	// `Sync` method will initialize these
	AvailableIPs    *IPSlice
	UsingIPs        IPSet
	ReservedIPCount int
}

func NewSubnet

func NewSubnet(
	name, network string, netID *uint32,
	start, end, gateway net.IP, cidr *net.IPNet,
	reservedList, blackList map[string]struct{}, lastAllocated net.IP,
	private, IPv6 bool) *Subnet

func (*Subnet) AllocateNext

func (s *Subnet) AllocateNext(podName, podNamespace string) *IP

func (*Subnet) Assign

func (s *Subnet) Assign(podName, podNamespace, ip string, forced bool) (*IP, error)

func (*Subnet) Canonicalize

func (s *Subnet) Canonicalize() error

Canonicalize takes a given subnet and ensures that all information is consistent, filling out Start, End, and Gateway with sane values if missing

func (*Subnet) Contains

func (s *Subnet) Contains(addr net.IP) bool

Contains checks if a given ip is a valid, allocatable address in a given Range This address should be in CIDR [start,gw) (gw,end], and not in black list.

func (*Subnet) IsAvailable

func (s *Subnet) IsAvailable() bool

func (*Subnet) IsBlackIP

func (s *Subnet) IsBlackIP(ip string) bool

func (*Subnet) IsIPv6

func (s *Subnet) IsIPv6() bool

func (*Subnet) IsReservedIP

func (s *Subnet) IsReservedIP(ip string) bool

func (*Subnet) Overlap

func (s *Subnet) Overlap(s1 *Subnet) bool

Overlap must be called **after** Canonicalize

func (*Subnet) Release

func (s *Subnet) Release(ip string)

func (*Subnet) Sync

func (s *Subnet) Sync(parentNetID *uint32, ipSet IPSet) error

Sync will generate netID, filtered Reserved List, Available IP Slice and Using IP Set based on subnet spec and input

func (*Subnet) Usage

func (s *Subnet) Usage() *Usage

func (*Subnet) UsingIPCount

func (s *Subnet) UsingIPCount() int

UsingIPCount will count the IP which are being used, but the reserved IPs will be excluded

func (*Subnet) Validate

func (s *Subnet) Validate() error

Validate can ensure that all necessary information are valid

type SubnetSlice

type SubnetSlice struct {
	Subnets        []*Subnet
	SubnetIndexMap map[string]int

	SubnetIndex int
	SubnetCount int
}

func NewSubnetSlice

func NewSubnetSlice() *SubnetSlice

func (*SubnetSlice) AddSubnet

func (s *SubnetSlice) AddSubnet(subnet *Subnet, parentNetID *uint32, ips IPSet, isDefault bool) error

func (*SubnetSlice) CurrentSubnet

func (s *SubnetSlice) CurrentSubnet() string

func (*SubnetSlice) DualStackUsage

func (s *SubnetSlice) DualStackUsage() ([3]*Usage, map[string]*Usage, error)

func (*SubnetSlice) GetAvailableIPv4Subnet

func (s *SubnetSlice) GetAvailableIPv4Subnet() (*Subnet, error)

func (*SubnetSlice) GetAvailableIPv6Subnet

func (s *SubnetSlice) GetAvailableIPv6Subnet() (*Subnet, error)

func (*SubnetSlice) GetAvailablePairedDualStackSubnets

func (s *SubnetSlice) GetAvailablePairedDualStackSubnets() (v4Subnet *Subnet, v6Subnet *Subnet, err error)

func (*SubnetSlice) GetAvailableSubnet

func (s *SubnetSlice) GetAvailableSubnet() (*Subnet, error)

func (*SubnetSlice) GetSubnet

func (s *SubnetSlice) GetSubnet(name string) (*Subnet, error)

func (*SubnetSlice) GetSubnetByIP

func (s *SubnetSlice) GetSubnetByIP(ip string) (*Subnet, error)

func (*SubnetSlice) Usage

func (s *SubnetSlice) Usage() (string, map[string]*Usage, error)

type Usage

type Usage struct {
	Total          uint32
	Used           uint32
	Available      uint32
	LastAllocation string
}

func (*Usage) Add

func (u *Usage) Add(in *Usage)

Jump to

Keyboard shortcuts

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