ipamcore

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ipamcore provides the core functionality for the IPAM service.

The IPAM is organized like a binary tree, where each node represents a network. In order to optimize the network allocation we use buddy mmory allocation alghorithm to allocate networks like they are memory blocks (https://en.wikipedia.org/wiki/Buddy_memory_allocation). When a network is splitted in two, the left child represents the first half of the network, while the right child represents the second half. The splitting is done until the network is splitted in blocks of the desired size.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ipam

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

Ipam represents the IPAM core structure.

func NewIpam

func NewIpam(pools []netip.Prefix) (*Ipam, error)

NewIpam creates a new IPAM instance.

func (*Ipam) IPAcquire

func (ipam *Ipam) IPAcquire(prefix netip.Prefix) (*netip.Addr, error)

IPAcquire allocates an IP address from the given prefix. It returns the allocated IP address or nil if the IP address is not available.

func (*Ipam) IPAcquireWithAddr

func (ipam *Ipam) IPAcquireWithAddr(prefix netip.Prefix, addr netip.Addr) (*netip.Addr, error)

IPAcquireWithAddr allocates the IP address from the given prefix. It returns the allocated IP address or nil if the IP address is not available.

func (*Ipam) IPIsAllocated

func (ipam *Ipam) IPIsAllocated(prefix netip.Prefix, addr netip.Addr) (bool, error)

IPIsAllocated checks if the IP address is allocated from the given prefix. It returns true if the IP address is allocated, false otherwise.

func (*Ipam) IPRelease

func (ipam *Ipam) IPRelease(prefix netip.Prefix, addr netip.Addr, gracePeriod time.Duration) (*netip.Addr, error)

IPRelease frees the IP address from the given prefix. It returns the freed IP address or nil if the IP address is not found.

func (*Ipam) IPSetCreationTimestamp

func (ipam *Ipam) IPSetCreationTimestamp(addr netip.Addr, prefix netip.Prefix, creationTimestamp time.Time) error

IPSetCreationTimestamp sets the creation timestamp of the IP address with the given address. This function is for testing purposes only.

func (*Ipam) IsPrefixInRoots

func (ipam *Ipam) IsPrefixInRoots(prefix netip.Prefix) bool

IsPrefixInRoots checks if the given prefix is contained in the roots. It returns true if the prefix is contained, false otherwise.

func (*Ipam) ListIPs

func (ipam *Ipam) ListIPs(prefix netip.Prefix) ([]netip.Addr, error)

ListIPs returns the list of allocated IP addresses from the given prefix.

func (*Ipam) ListNetworks

func (ipam *Ipam) ListNetworks() []netip.Prefix

ListNetworks returns the list of allocated networks.

func (*Ipam) NetworkAcquire

func (ipam *Ipam) NetworkAcquire(size int) *netip.Prefix

NetworkAcquire allocates a network of the given size. It returns the allocated network or nil if no network is available.

func (*Ipam) NetworkAcquireWithPrefix

func (ipam *Ipam) NetworkAcquireWithPrefix(prefix netip.Prefix) *netip.Prefix

NetworkAcquireWithPrefix allocates a network with the given prefix. It returns the allocated network or nil if the network is not available.

func (*Ipam) NetworkIsAvailable

func (ipam *Ipam) NetworkIsAvailable(prefix netip.Prefix) bool

NetworkIsAvailable checks if the network with the given prefix is allocated. It returns false if the network is allocated or there is no suitable pool, true otherwise.

func (*Ipam) NetworkRelease

func (ipam *Ipam) NetworkRelease(prefix netip.Prefix, gracePeriod time.Duration) *netip.Prefix

NetworkRelease frees the network with the given prefix. It returns the freed network or nil if the network is not found.

func (*Ipam) NetworkSetLastUpdateTimestamp

func (ipam *Ipam) NetworkSetLastUpdateTimestamp(prefix netip.Prefix, lastUpdateTimestamp time.Time) error

NetworkSetLastUpdateTimestamp sets the last update time of the network with the given prefix. This function is for testing purposes only.

func (*Ipam) ToGraphviz

func (ipam *Ipam) ToGraphviz() error

ToGraphviz generates the Graphviz representation of the IPAM structure.

Jump to

Keyboard shortcuts

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