ipam

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2019 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Overview

Package ipam is a very simple IPAM it administers a single CIDR range, e.g "1000::/124".

The functions are NOT thread safe.

Example
package main

import (
	"fmt"
	"github.com/Nordix/simple-ipam/pkg/ipam"
)

func main() {
	cidr := "1100::/120"
	ipam, _ := ipam.New(cidr)
	fmt.Printf("Unallocated addresses in %s; %d\n", cidr, ipam.Unallocated())
	a, _ := ipam.Allocate()
	fmt.Printf("Allocated; %s\n", a)
	ipam.Free(a)

}
Output:

Unallocated addresses in 1100::/120; 256
Allocated; 1100::

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPAM

type IPAM struct {
	// The original CIDR range
	CIDR net.IPNet
	// contains filtered or unexported fields
}

IPAM holds the ipam state

func New

func New(cidr string) (*IPAM, error)

New creates a new IPAM for the passed CIDR. Error if the passed CIDR is invalid.

func (*IPAM) Allocate

func (i *IPAM) Allocate() (net.IP, error)

Allocate allocates a new address. An error is returned if there is no addresses left.

func (*IPAM) Free

func (i *IPAM) Free(a net.IP)

Free frees an allocated address. To free a non-allocated address is a no-op.

func (*IPAM) Reserve

func (i *IPAM) Reserve(a net.IP) error

Reserve reserves an address. Error if the address is outside the CIDR or if the address is allocated already.

func (*IPAM) ReserveFirstAndLast

func (i *IPAM) ReserveFirstAndLast()

ReserveFirstAndLast reserves the first and last address. These are valid addresses but some programs may refuse to use them. Note that the number of Unallocated addresses may become zero.

func (*IPAM) Unallocated

func (i *IPAM) Unallocated() uint64

Unallocated returns the number of unallocated addresses. If the CIDR host-bits are >=64 math.MaxUint64 is always returned.

Jump to

Keyboard shortcuts

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