counter

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 4 Imported by: 8

Documentation

Overview

Package counter provides generic reference counter objects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntCounter

type IntCounter map[int]int

IntCounter tracks references for integers with an optional limiter.

No threadsafety is provided within this structure, the user is expected to handle concurrent access to this structure if it is used from multiple threads.

func (IntCounter) Add

func (i IntCounter) Add(key int) (changed bool)

Add increments the reference count for the specified integer key.

func (IntCounter) DeepCopy

func (i IntCounter) DeepCopy() IntCounter

DeepCopy makes a new copy of the received IntCounter.

func (IntCounter) Delete

func (i IntCounter) Delete(key int) bool

Delete decrements the reference count for the specified integer key.

func (IntCounter) ToBPFData

func (i IntCounter) ToBPFData() []int

ToBPFData returns the keys as a slice, sorted from high to low.

type PrefixLengthCounter

type PrefixLengthCounter struct {
	lock.RWMutex
	// contains filtered or unexported fields
}

PrefixLengthCounter tracks references to prefix lengths, limited by the maxUniquePrefixes count. Neither of the IPv4 or IPv6 counters nested within may contain more keys than the specified maximum number of unique prefixes.

func DefaultPrefixLengthCounter

func DefaultPrefixLengthCounter(maxUniquePrefixes6, maxUniquePrefixes4 int) *PrefixLengthCounter

DefaultPrefixLengthCounter creates a default prefix length counter that already counts the minimum and maximum prefix lengths for IP hosts and default routes (ie, /32 and /0). As with NewPrefixLengthCounter, inesrtions are limited to the specified maximum number of unique prefix lengths.

func NewPrefixLengthCounter

func NewPrefixLengthCounter(maxUniquePrefixes6, maxUniquePrefixes4 int) *PrefixLengthCounter

NewPrefixLengthCounter returns a new PrefixLengthCounter which limits insertions to the specified maximum number of unique prefix lengths.

func (*PrefixLengthCounter) Add

func (p *PrefixLengthCounter) Add(prefixes []*net.IPNet) (bool, error)

Add increments references to prefix lengths for the specified IPNets to the counter. If the maximum number of unique prefix lengths would be exceeded, returns an error.

Returns true if adding these prefixes results in an increase in the total number of unique prefix lengths in the counter.

func (*PrefixLengthCounter) Delete

func (p *PrefixLengthCounter) Delete(prefixes []*net.IPNet) (changed bool)

Delete reduces references to prefix lengths in the the specified IPNets from the counter. Returns true if removing references to these prefix lengths would result in a decrese in the total number of unique prefix lengths in the counter.

func (*PrefixLengthCounter) ToBPFData

func (p *PrefixLengthCounter) ToBPFData() (s6, s4 []int)

ToBPFData converts the counter into a set of prefix lengths that the BPF datapath can use for LPM lookup.

type StringCounter

type StringCounter map[string]int

StringCounter tracks references for strings.

No threadsafety is provided within this structure, the user is expected to handle concurrent access to this structure if it is used from multiple threads.

func (StringCounter) Add added in v1.7.0

func (s StringCounter) Add(key string) (changed bool)

Add increments the reference count for the specified string key.

func (StringCounter) Delete added in v1.7.0

func (s StringCounter) Delete(key string) bool

Delete decrements the reference count for the specified string key.

Jump to

Keyboard shortcuts

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