caps

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package caps implements BGP capabilities.

This package can store a set of BGP capabilities in a thread-safe map using the Caps type, and read/write a particular BGP capability representation using implementations of the Cap interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValue    = errors.New("invalid value")
	ErrLength   = errors.New("invalid length")
	ErrTODO     = errors.New("not implemented")
	ErrCapCode  = errors.New("invalid capability code")
	ErrCapValue = errors.New("invalid capability value")
)
View Source
var CodeName = map[Code]string{}
View Source
var CodeValue = _CodeNameToValueMap

NewFuncs maps capability codes to their new func

Functions

func CodeStrings

func CodeStrings() []string

CodeStrings returns a slice of all String values of the enum

Types

type AS4

type AS4 struct {
	ASN uint32
}

AS4 implements CAP_AS4 rfc6793

func (*AS4) FromJSON

func (c *AS4) FromJSON(src []byte) (err error)

func (*AS4) Intersect

func (c *AS4) Intersect(cap2 Cap) Cap

func (*AS4) Marshal

func (c *AS4) Marshal(dst []byte) []byte

func (*AS4) ToJSON

func (c *AS4) ToJSON(dst []byte) []byte

func (*AS4) Unmarshal

func (c *AS4) Unmarshal(buf []byte, caps Caps) error

type Cap

type Cap interface {
	// Unmarshal parses wire representation from src.
	// It must support multiple calls for the same message.
	Unmarshal(src []byte, caps Caps) error

	// Marshal appends wire representation to dst, including code and length.
	// Return nil to skip this capability.
	Marshal(dst []byte) []byte

	// ToJSON appends JSON representation of the value to dst
	ToJSON(dst []byte) []byte

	// FromJSON reads from JSON representation in src
	FromJSON(src []byte) error

	// Intersect returns a new instance that represents its intersection with cap2.
	// This is used during capability negotiation. Return nil if equal or N/A.
	Intersect(cap2 Cap) Cap
}

Cap represents a particular BGP capability

func NewAS4

func NewAS4(cc Code) Cap

func NewCap

func NewCap(cc Code) Cap

NewCap returns a new Cap instance for given code cc

func NewExtNH

func NewExtNH(cc Code) Cap

func NewFqdn added in v0.1.6

func NewFqdn(cc Code) Cap

func NewMP

func NewMP(cc Code) Cap

func NewRaw

func NewRaw(cc Code) Cap

type Caps

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

Caps wraps an xsync map to represent a set of BGP capabilities. It may contain nil values.

Caps is thread-safe for writes, but only after Init() or first modification.

The Cap values stored in Caps are generally *not* thread-safe for writes, so you should overwrite a particular CapCode if you need to modify a Cap stored here in a thread-safe way.

func (*Caps) Clear

func (cps *Caps) Clear()

Clear drops all capabilities.

func (*Caps) Drop

func (cps *Caps) Drop(cc Code)

Drop drops cps[cc].

func (*Caps) Each

func (cps *Caps) Each(cb func(i int, cc Code, cap Cap))

Each executes cb for each non-nil capability in cps, in an ascending order of capability codes.

func (*Caps) FromJSON

func (cps *Caps) FromJSON(src []byte) error

func (*Caps) Get

func (cps *Caps) Get(cc Code) (cap Cap)

Get returns cps[cc] or nil if not possible.

func (*Caps) Has

func (cps *Caps) Has(cc Code) bool

Has returns true iff cps[cc] is set and non-nil

func (*Caps) Init

func (cps *Caps) Init()

Init initializes Caps and makes it fully thread-safe after return. Can be called multiple times for lazy init.

func (*Caps) Len

func (cps *Caps) Len() int

Len returns the number of capabilites

func (*Caps) MarshalJSON

func (cps *Caps) MarshalJSON() (dst []byte, err error)

func (*Caps) Reset

func (cps *Caps) Reset()

Reset resets Caps back to initial state. Thread-unsafe.

func (*Caps) Set

func (cps *Caps) Set(cc Code, value Cap)

Set overwrites cps[cc] with value.

func (*Caps) SetFrom

func (cps *Caps) SetFrom(src Caps)

SetFrom sets all capabilities from src, overwriting cps[cc] for existing capability codes

func (*Caps) String added in v0.2.0

func (cps *Caps) String() string

func (*Caps) ToJSON

func (cps *Caps) ToJSON(dst []byte) []byte

func (*Caps) Use

func (cps *Caps) Use(cc Code) Cap

Use returns cps[cc] if its already there (may be nil). Otherwise, it adds a new instance of cc in cps.

func (*Caps) Valid

func (cps *Caps) Valid() bool

Valid returns true iff Caps has already been initialized

type Code

type Code byte

Code represents BGP capability code

const (
	CAP_UNSPECIFIED            Code = 0
	CAP_MP                     Code = 1
	CAP_ROUTE_REFRESH          Code = 2
	CAP_OUTBOUND_FILTERING     Code = 3
	CAP_EXTENDED_NEXTHOP       Code = 5
	CAP_EXTENDED_MESSAGE       Code = 6
	CAP_BGPSEC                 Code = 7
	CAP_MULTIPLE_LABELS        Code = 8
	CAP_ROLE                   Code = 9
	CAP_GRACEFUL_RESTART       Code = 64
	CAP_AS4                    Code = 65
	CAP_DYNAMIC                Code = 67
	CAP_MULTISESSION           Code = 68
	CAP_ADDPATH                Code = 69
	CAP_ENHANCED_ROUTE_REFRESH Code = 70
	CAP_LLGR                   Code = 71
	CAP_ROUTING_POLICY         Code = 72
	CAP_FQDN                   Code = 73
	CAP_BFD                    Code = 74
	CAP_VERSION                Code = 75
	CAP_PRE_ROUTE_REFRESH      Code = 128
)

capability codes

func CodeString

func CodeString(s string) (Code, error)

CodeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func CodeValues

func CodeValues() []Code

CodeValues returns all values of the enum

func (*Code) FromJSON

func (cc *Code) FromJSON(src string) error

FromJSON() sets ac from JSON in src

func (Code) IsACode

func (i Code) IsACode() bool

IsACode returns "true" if the value is listed in the enum definition. "false" otherwise

func (Code) String

func (i Code) String() string

func (Code) ToJSON

func (cc Code) ToJSON(dst []byte) []byte

ToJSON() appends cc name as a JSON string to dst

type ExtNH

type ExtNH struct {
	Proto map[af.AFV]bool
}

ExtNH implements CAP_EXTENDED_NEXTHOP rfc8950

func (*ExtNH) Add

func (c *ExtNH) Add(afi af.AFI, safi af.SAFI, nhf af.AFI)

func (*ExtNH) Drop

func (c *ExtNH) Drop(afi af.AFI, safi af.SAFI, nhf af.AFI)

func (*ExtNH) FromJSON

func (c *ExtNH) FromJSON(src []byte) (err error)

func (*ExtNH) Has

func (c *ExtNH) Has(afi af.AFI, safi af.SAFI, nhf af.AFI) bool

func (*ExtNH) Intersect

func (c *ExtNH) Intersect(cap2 Cap) Cap

func (*ExtNH) Marshal

func (c *ExtNH) Marshal(dst []byte) []byte

func (*ExtNH) Sorted

func (c *ExtNH) Sorted() (dst []af.AFV)

func (*ExtNH) ToJSON

func (c *ExtNH) ToJSON(dst []byte) []byte

func (*ExtNH) Unmarshal

func (c *ExtNH) Unmarshal(buf []byte, caps Caps) error

type Fqdn added in v0.1.6

type Fqdn struct {
	Host   []byte
	Domain []byte
}

Fqdn implements CAP_FQDN draft-walton-bgp-hostname-capability-00

func (*Fqdn) FromJSON added in v0.1.6

func (c *Fqdn) FromJSON(src []byte) (err error)

func (*Fqdn) Intersect added in v0.1.6

func (c *Fqdn) Intersect(cap2 Cap) Cap

func (*Fqdn) Marshal added in v0.1.6

func (c *Fqdn) Marshal(dst []byte) []byte

func (*Fqdn) ToJSON added in v0.1.6

func (c *Fqdn) ToJSON(dst []byte) []byte

func (*Fqdn) Unmarshal added in v0.1.6

func (c *Fqdn) Unmarshal(buf []byte, caps Caps) error

type MP

type MP struct {
	Proto map[af.AF]bool
}

MP implements CAP_MP rfc4760

func (*MP) Add

func (c *MP) Add(afi af.AFI, safi af.SAFI)

func (*MP) Drop

func (c *MP) Drop(afi af.AFI, safi af.SAFI)

func (*MP) FromJSON

func (c *MP) FromJSON(src []byte) (err error)

func (*MP) Has

func (c *MP) Has(afi af.AFI, safi af.SAFI) bool

func (*MP) Intersect

func (c *MP) Intersect(cap2 Cap) Cap

func (*MP) Marshal

func (c *MP) Marshal(dst []byte) []byte

func (*MP) Sorted

func (c *MP) Sorted() (dst []af.AF)

func (*MP) ToJSON

func (c *MP) ToJSON(dst []byte) []byte

func (*MP) Unmarshal

func (c *MP) Unmarshal(buf []byte, caps Caps) error

type NewFunc

type NewFunc func(cc Code) Cap

NewFunc returns a new instance of capability cc.

type Raw

type Raw struct {
	Code
	Raw [][]byte
}

Raw represents any BGP capability as raw bytes

func (*Raw) FromJSON

func (c *Raw) FromJSON(src []byte) error

func (*Raw) Intersect

func (c *Raw) Intersect(cap2 Cap) Cap

func (*Raw) Marshal

func (c *Raw) Marshal(dst []byte) []byte

func (*Raw) ToJSON

func (c *Raw) ToJSON(dst []byte) []byte

func (*Raw) Unmarshal

func (c *Raw) Unmarshal(buf []byte, caps Caps) error

Jump to

Keyboard shortcuts

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