vlans

package
v0.0.0-...-81ce8a9 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const AliasSep = "//"

AliasSep separates namespace from VLAN alias

View Source
const BlacklistedVLAN = "BLACKLISTED"

BlacklistedVLAN is used to track manually reserved VLANs

View Source
const DisconnectedVLAN = "DISCONNECTED"

DisconnectedVLAN always resolves to VLAN -1

View Source
const VLANStart, VLANEnd = 101, 4096

VLANStart and VLANEnd are the default ranges for VLAN allocation

Variables

View Source
var Default = NewVLANs()
View Source
var ErrOutOfVLANs = errors.New("out of VLANs")
View Source
var ErrUnallocated = errors.New("unallocated")

Functions

func AddAlias

func AddAlias(namespace, alias string, vlan int) error

func Allocate

func Allocate(namespace, s string) (int, bool, error)

func Blacklist

func Blacklist(vlan int)

func Delete

func Delete(namespace, alias string)

func GetAliases

func GetAliases(prefix string) []string

func GetBlacklist

func GetBlacklist() []int

func GetRanges

func GetRanges() map[string]Range

func GetVLAN

func GetVLAN(namespace, alias string) (int, error)

func ParseVLAN

func ParseVLAN(namespace, s string) (int, error)

func PrintVLAN

func PrintVLAN(namespace string, vlan int) string

func SetRange

func SetRange(prefix string, min, max int) error

func Tabular

func Tabular(namespace string) [][]string

Types

type Alias

type Alias struct {
	Namespace string
	Value     string
}

func GetAlias

func GetAlias(vlan int) (Alias, error)

func ParseAlias

func ParseAlias(namespace, alias string) Alias

func (Alias) String

func (a Alias) String() string

type Range

type Range struct {
	Min, Max, Next int
}

type VLANs

type VLANs struct {
	sync.Mutex
	// contains filtered or unexported fields
}

VLANs stores the state for the VLANs that we've allocated so far

func NewVLANs

func NewVLANs() *VLANs

func (*VLANs) AddAlias

func (v *VLANs) AddAlias(namespace, alias string, vlan int) error

AddAlias sets the VLAN for the provided alias.

func (*VLANs) Allocate

func (v *VLANs) Allocate(namespace, alias string) (int, bool, error)

Allocate looks up the VLAN for the provided alias. If one has not already been assigned, it will allocate the next available VLAN. Returns the VLAN and flag for whether the alias was created or not.

func (*VLANs) Blacklist

func (v *VLANs) Blacklist(vlan int)

Blacklist marks a VLAN as manually configured which removes it from the allocation pool. For instance, if a user runs `vm config net 100`, VLAN 100 would be marked as blacklisted.

func (*VLANs) Delete

func (v *VLANs) Delete(namespace, prefix string)

Delete allocation for aliases matching a given namespace. Also clears any ranges set for the given namespace if the prefix is empty.

func (*VLANs) GetAlias

func (v *VLANs) GetAlias(vlan int) (Alias, error)

GetAlias returns the alias for a given VLAN or ErrUnallocated. Note that previously Blacklisted VLANs will return the const BlacklistedVLAN.

func (*VLANs) GetAliases

func (v *VLANs) GetAliases(prefix string) []string

GetAliases returns a list of aliases with the given prefix.

func (*VLANs) GetBlacklist

func (v *VLANs) GetBlacklist() []int

GetBlacklist returns a list of VLANs that have been blacklisted.

func (*VLANs) GetRanges

func (v *VLANs) GetRanges() map[string]Range

GetRanges returns a copy of the ranges currently in use.

func (*VLANs) GetVLAN

func (v *VLANs) GetVLAN(namespace, alias string) (int, error)

GetVLAN returns the VLAN for a given alias or ErrUnallocated.

func (*VLANs) ParseVLAN

func (v *VLANs) ParseVLAN(namespace, s string) (int, error)

ParseVLAN parses s and returns a VLAN. If s can be parsed as an integer, the resulting integer is returned. If s matches an existing alias, that VLAN is returned. Otherwise, returns ErrUnallocated.

func (*VLANs) PrintVLAN

func (v *VLANs) PrintVLAN(namespace string, vlan int) string

PrintVLAN prints the alias for the VLAN, if one is set. Will trim off the namespace prefix if it matches the currently active namespace.

func (*VLANs) SetRange

func (v *VLANs) SetRange(namespace string, min, max int) error

SetRange reserves a range of VLANs for a particular namespace. VLANs are allocated in the range [min, max).

func (*VLANs) Tabular

func (v *VLANs) Tabular(namespace string) [][]string

Jump to

Keyboard shortcuts

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