ippool

package
v1.7.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

ippool.IPPool

It is a red–black tree containing IPv4/IPv6 address networks. IP address represents as two uint64 numbers (high and low 64 bits of 128 bit IPv6 address). Each node of RB tree is bounds of IP range.

Performance

Performance results for IPPool, RoaringBitmap and PrefixPool. Each iteration pulls P2P address pair for pool with 1000 excluded subnets.

BenchmarkIPPool ops ns/op B/op allocs/op
BenchmarkIPPool/IPPool 566 2161121 440206 22007
BenchmarkIPPool/RoaringBitmap 1359 824205 218841 11106
BenchmarkIPPool/PrefixPool 2 1803298500 1001995744 18689007
         
BenchmarkIPPool/IPPool-2 1009 1079308 440223 22008
BenchmarkIPPool/RoaringBitmap-2 2985 351601 218850 11106
BenchmarkIPPool/PrefixPool-2 2 1355259309 1021856016 19835510
         
BenchmarkIPPool/IPPool-4 1126 1005249 440240 22008
BenchmarkIPPool/RoaringBitmap-4 5494 193221 218847 11106
BenchmarkIPPool/PrefixPool-4 2 1365976629 1021857340 19835525
         
BenchmarkIPPool/IPPool-8 1011 1095871 440265 22009
BenchmarkIPPool/RoaringBitmap-8 6398 163107 218842 11106
BenchmarkIPPool/PrefixPool-8 2 1319444212 1012589580 19802446
         
BenchmarkIPPool/IPPool-16 996 1102098 440250 22008
BenchmarkIPPool/RoaringBitmap-16 7626 179327 218851 11106
BenchmarkIPPool/PrefixPool-16 2 1408024424 1012589068 19802437

Documentation

Overview

Package ippool provides service for managing ip addresses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPPool

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

IPPool holds available ip addresses in the structure of red-black tree

func New

func New(ipLength int) *IPPool

New instantiates a ip pool as red-black tree with the specified ip length.

func NewWithNet

func NewWithNet(ipNet *net.IPNet) *IPPool

NewWithNet instantiates a ip pool as red-black tree with the specified ip network

func NewWithNetString

func NewWithNetString(ipNetString string) *IPPool

NewWithNetString instantiates a ip pool as red-black tree with the specified ip network

func (*IPPool) Add

func (tree *IPPool) Add(ip net.IP)

Add - adds ip address to the pool

func (*IPPool) AddNet

func (tree *IPPool) AddNet(ipNet *net.IPNet)

AddNet - adds ip addresses from network to the pool

func (*IPPool) AddNetString

func (tree *IPPool) AddNetString(ipNetString string)

AddNetString - adds ip addresses from network to the pool by string value

func (*IPPool) AddString

func (tree *IPPool) AddString(in string)

AddString - adds ip address to the pool by string value

func (*IPPool) Clear

func (tree *IPPool) Clear()

Clear removes all addresses from the IP pool.

func (*IPPool) Clone

func (tree *IPPool) Clone() *IPPool

Clone - make a clone of the pool

func (*IPPool) Contains

func (tree *IPPool) Contains(ip net.IP) bool

Contains - check the pool contains ip address

func (*IPPool) ContainsNet added in v1.3.0

func (tree *IPPool) ContainsNet(ipNet *net.IPNet) bool

ContainsNet checks that pool contains whole ipNet

func (*IPPool) ContainsNetString added in v1.3.0

func (tree *IPPool) ContainsNetString(ipNetRaw string) bool

ContainsNetString parses ipNetRaw string and checks that pool contains whole ipNet

func (*IPPool) ContainsString

func (tree *IPPool) ContainsString(in string) bool

ContainsString - check the pool contains ip by string value

func (*IPPool) Empty

func (tree *IPPool) Empty() bool

Empty returns true if pool does not contain any nodes

func (*IPPool) Exclude

func (tree *IPPool) Exclude(ipNet *net.IPNet)

Exclude - exclude network from pool

func (*IPPool) ExcludeString

func (tree *IPPool) ExcludeString(ipNetString string)

ExcludeString - exclude network from pool by string value

func (*IPPool) GetPrefixes

func (tree *IPPool) GetPrefixes() []string

GetPrefixes returns the list of saved prefixes

func (*IPPool) Pull

func (tree *IPPool) Pull() (net.IP, error)

Pull - returns next IP address from pool

func (*IPPool) PullIP added in v1.6.0

func (tree *IPPool) PullIP(ip net.IP, exclude ...*IPPool) (*net.IPNet, error)

PullIP - returns requested IP address from the pool

func (*IPPool) PullIPString added in v1.6.0

func (tree *IPPool) PullIPString(ipString string, exclude ...*IPPool) (*net.IPNet, error)

PullIPString - returns requested IP address from the pool by string

func (*IPPool) PullP2PAddrs

func (tree *IPPool) PullP2PAddrs(exclude ...*IPPool) (srcNet, dstNet *net.IPNet, err error)

PullP2PAddrs - returns next IP addresses pair from pool for peer-to-peer connection

type PrefixPool

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

PrefixPool - keeps prefixes for both IPv4 and IPv6 addresses

func NewPool

func NewPool(prefixes ...string) (*PrefixPool, error)

NewPool - Creates new PrefixPool with initial prefixes list

func (*PrefixPool) AddPrefixes

func (pool *PrefixPool) AddPrefixes(prefixes ...string) error

AddPrefixes - adds prefixes to the pool

func (*PrefixPool) ExcludePrefixes

func (pool *PrefixPool) ExcludePrefixes(prefixes ...string) error

ExcludePrefixes - removes prefixes from the pool

func (*PrefixPool) GetPrefixes

func (pool *PrefixPool) GetPrefixes() []string

GetPrefixes - returns the list of saved prefixes

Jump to

Keyboard shortcuts

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