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 ¶
- Variables
- func AddPathDirStrings() []string
- func CodeStrings() []string
- type AS4
- type AddPath
- func (c *AddPath) Add(as afi.AS, dir AddPathDir)
- func (c *AddPath) Drop(as afi.AS)
- func (c *AddPath) FromJSON(src []byte) (err error)
- func (c *AddPath) Has(as afi.AS, dir AddPathDir) bool
- func (cr *AddPath) Intersect(cap2 Cap) Cap
- func (c *AddPath) Marshal(dst []byte) []byte
- func (c *AddPath) Sorted() (dst []afi.ASV)
- func (c *AddPath) ToJSON(dst []byte) []byte
- func (c *AddPath) Unmarshal(src []byte, caps Caps) error
- type AddPathDir
- type Cap
- type Caps
- func (cps *Caps) AddPathEnabled(as afi.AS, dst dir.Dir) bool
- func (cps *Caps) Clear()
- func (cps *Caps) Drop(cc Code)
- func (cps *Caps) Each(cb func(i int, cc Code, cap Cap))
- func (cps *Caps) FromJSON(src []byte) error
- func (cps *Caps) Get(cc Code) (cap Cap)
- func (cps *Caps) Has(cc Code) bool
- func (cps *Caps) Init()
- func (cps *Caps) Len() int
- func (cps *Caps) MarshalJSON() (dst []byte, err error)
- func (cps *Caps) Reset()
- func (cps *Caps) Set(cc Code, value Cap)
- func (cps *Caps) SetFrom(src Caps)
- func (cps *Caps) String() string
- func (cps *Caps) ToJSON(dst []byte) []byte
- func (cps *Caps) Use(cc Code) Cap
- func (cps *Caps) Valid() bool
- type Code
- type ExtNH
- func (c *ExtNH) Add(as afi.AS, nhf afi.AFI)
- func (c *ExtNH) Drop(as afi.AS, nhf afi.AFI)
- func (c *ExtNH) FromJSON(src []byte) (err error)
- func (c *ExtNH) Has(as afi.AS, nhf afi.AFI) bool
- func (c *ExtNH) Intersect(cap2 Cap) Cap
- func (c *ExtNH) Marshal(dst []byte) []byte
- func (c *ExtNH) Sorted() (dst []afi.ASV)
- func (c *ExtNH) ToJSON(dst []byte) []byte
- func (c *ExtNH) Unmarshal(buf []byte, caps Caps) error
- type Fqdn
- type MP
- func (c *MP) Add(af afi.AFI, sf afi.SAFI)
- func (c *MP) Drop(af afi.AFI, sf afi.SAFI)
- func (c *MP) FromJSON(src []byte) (err error)
- func (c *MP) Has(af afi.AFI, sf afi.SAFI) bool
- func (c *MP) Intersect(cap2 Cap) Cap
- func (c *MP) Marshal(dst []byte) []byte
- func (c *MP) Sorted() (dst []afi.AS)
- func (c *MP) ToJSON(dst []byte) []byte
- func (c *MP) Unmarshal(buf []byte, caps Caps) error
- type NewFunc
- type Raw
Constants ¶
This section is empty.
Variables ¶
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") )
var CodeName = map[Code]string{}
var CodeValue = _CodeNameToValueMap
var NewFuncs = map[Code]NewFunc{ CAP_MP: NewMP, CAP_AS4: NewAS4, CAP_EXTENDED_NEXTHOP: NewExtNH, CAP_FQDN: NewFqdn, CAP_ADDPATH: NewAddPath, }
NewFuncs maps capability codes to their new func
Functions ¶
func AddPathDirStrings ¶ added in v0.4.0
func AddPathDirStrings() []string
AddPathDirStrings returns a slice of all String values of the enum
func CodeStrings ¶
func CodeStrings() []string
CodeStrings returns a slice of all String values of the enum
Types ¶
type AddPath ¶ added in v0.4.0
type AddPath struct {
// Proto maps AFI+SAFI pairs to Send/Receive directions
Proto map[afi.AS]AddPathDir
}
AddPath implements CAP_ADDPATH rfc7911
func (*AddPath) Add ¶ added in v0.4.0
func (c *AddPath) Add(as afi.AS, dir AddPathDir)
Add adds ADD_PATH for AFI+SAIF pair in as, and the Send/Receive value in dir. The value in sr must already be valid.
func (*AddPath) Drop ¶ added in v0.4.0
Drop drops ADD_PATH for AFI+SAFI pair in as, whatever the Send/Receive is.
func (*AddPath) Has ¶ added in v0.4.0
func (c *AddPath) Has(as afi.AS, dir AddPathDir) bool
Has returns true iff ADD_PATH is enabled for AFI+SAFI pair in the dir direction.
func (*AddPath) Intersect ¶ added in v0.4.0
Intersect returns a new instance that represents its intersection with cap2. cr = caps sent from L to R, cl = caps sent from R to L
func (*AddPath) Marshal ¶ added in v0.4.0
Marshal appends wire representation to dst, including code and length. Return nil to skip this capability.
func (*AddPath) Sorted ¶ added in v0.4.0
Sorted returns all valid AFI+SAFI pairs in sorted order, with their Send/Receive encoded as VAL in ASV.
type AddPathDir ¶ added in v0.4.0
type AddPathDir uint8
const ( ADDPATH_RECEIVE AddPathDir = AddPathDir(dir.DIR_L) ADDPATH_SEND AddPathDir = AddPathDir(dir.DIR_R) ADDPATH_BIDIR AddPathDir = AddPathDir(dir.DIR_LR) )
re-use values used in the dir package; assume we're the L side
func AddPathDirString ¶ added in v0.4.0
func AddPathDirString(s string) (AddPathDir, error)
AddPathDirString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func AddPathDirValues ¶ added in v0.4.0
func AddPathDirValues() []AddPathDir
AddPathDirValues returns all values of the enum
func (AddPathDir) IsAAddPathDir ¶ added in v0.4.0
func (i AddPathDir) IsAAddPathDir() bool
IsAAddPathDir returns "true" if the value is listed in the enum definition. "false" otherwise
func (AddPathDir) String ¶ added in v0.4.0
func (i AddPathDir) String() string
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.
// When needed, assume cap2 is what was sent in the L direction.
Intersect(cap2 Cap) Cap
}
Cap represents a particular BGP capability
func NewAddPath ¶ added in v0.4.0
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) AddPathEnabled ¶ added in v0.4.0
AddPathEnabled returns true iff ADD_PATH is enabled in given direction for as
func (*Caps) Each ¶
Each executes cb for each non-nil capability in cps, in an ascending order of capability codes.
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) MarshalJSON ¶
func (*Caps) Reset ¶
func (cps *Caps) Reset()
Reset resets Caps back to initial state. Thread-unsafe.
func (*Caps) SetFrom ¶
SetFrom sets all capabilities from src, overwriting cps[cc] for existing capability codes
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 ¶
CodeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.