rib

package
v0.0.0-...-800520f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Overview

Package rib implements a basic RIB for a gRIBI server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcreteIPv4Proto

func ConcreteIPv4Proto(e *aft.Afts_Ipv4Entry) (*aftpb.Afts_Ipv4EntryKey, error)

ConcreteIPv4Proto takes the input Ipv4Entry GoStruct and returns it as a gRIBI Ipv4EntryKey protobuf. It returns an error if the protobuf cannot be marshalled.

func ConcreteIPv6Proto

func ConcreteIPv6Proto(e *aft.Afts_Ipv6Entry) (*aftpb.Afts_Ipv6EntryKey, error)

ConcreteIPv6Proto takes the input Ipv6Entry GoStruct and returns it as a gRIBI Ipv6EntryKey protobuf. It returns an error if the protobuf cannot be marshalled.

func ConcreteMPLSProto

func ConcreteMPLSProto(e *aft.Afts_LabelEntry) (*aftpb.Afts_LabelEntryKey, error)

ConcreteMPLSProto takes the input LabelEntry GoStruct and returns it as a gRIBI LabelEntryKey protobuf. It returns an error if the protobuf cannot be marshalled.

func ConcreteNextHopGroupProto

func ConcreteNextHopGroupProto(e *aft.Afts_NextHopGroup) (*aftpb.Afts_NextHopGroupKey, error)

ConcreteNextHopGroupProto takes the input NextHopGroup GoStruct and returns it as a gRIBI NextHopGroupEntryKey protobuf. It returns an error if the protobuf cannot be marshalled.

func ConcreteNextHopProto

func ConcreteNextHopProto(e *aft.Afts_NextHop) (*aftpb.Afts_NextHopKey, error)

ConcreteNextHopProto takes the input NextHop GoStruct and returns it as a gRIBI NextHopEntryKey protobuf. It returns an error if the protobuf cannot be marshalled.

func DisableRIBCheckFn

func DisableRIBCheckFn() *disableCheckFn

DisableRIBCheckFn specifies that the consistency checking functions should be disabled for the RIB. It is useful for a testing RIB that does not need to have working references.

func NewFake

func NewFake(defaultName string, opt ...RIBOpt) *fakeRIB

NewFake returns a new Fake RIB.

func RIBHolderCheckFn

func RIBHolderCheckFn(f RIBHolderCheckFunc) *ribHolderCheckFn

RIBHolderCheckFn is an option that provides a function f to be run for each RIB change.

Types

type FlushErr

type FlushErr struct {
	Errs []error
}

func (*FlushErr) Error

func (f *FlushErr) Error() string

type OpResult

type OpResult struct {
	// ID is the ID of the operation as specified in the input request.
	ID uint64
	// Op is the operation that was performed.
	Op *spb.AFTOperation
	// Error is an error string detailing any error that occurred.
	Error string
}

OpResult contains the result of an operation (Add, Modify, Delete).

func (*OpResult) String

func (o *OpResult) String() string

String returns the OpResult as a human readable string.

type RIB

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

RIB is a struct that stores a representation of a RIB for a network device.

func FromGetResponses

func FromGetResponses(defaultName string, responses []*spb.GetResponse, opt ...RIBOpt) (*RIB, error)

FromGetResponses returns a RIB from a slice of gRIBI GetResponse messages. The supplied defaultName is used as the default network instance name.

func New

func New(dn string, opt ...RIBOpt) *RIB

New returns a new RIB with the default network instance created with name dn.

func (*RIB) AddEntry

func (r *RIB) AddEntry(ni string, op *spb.AFTOperation) ([]*OpResult, []*OpResult, error)

AddEntry adds the entry described in op to the network instance with name ni. It returns two slices of OpResults:

  • the first ("oks") describes the set of entries that were installed successfully based on this operation.
  • the second ("fails") describes the set of entries that were NOT installed, and encountered fatal errors during the process of installing the entry.

It returns an error if there is a fatal error encountered for the function during operation.

If the input AFT operation is a REPLACE operation, AddEntry ensures that the entry exists within the RIB before replacing it.

The oks slice may have length > 1 (i.e., not just be the input operation) in the case an entry becomes resolvable (per canResolve) *after* this operation has been installed. It will recursively call the internal implementation in order to install all entries that are now resolvable based on the operation provided.

func (*RIB) AddNetworkInstance

func (r *RIB) AddNetworkInstance(name string) error

AddNetworkInstance adds a new network instance with the specified name to the RIB.

func (*RIB) DeleteEntry

func (r *RIB) DeleteEntry(ni string, op *spb.AFTOperation) ([]*OpResult, []*OpResult, error)

DeleteEntry removes the entry specified by op from the network instance ni.

func (*RIB) Flush

func (r *RIB) Flush(networkInstances []string) error

Flush cleanly removes all entries from the specified RIB. A lock on the RIB is held throughout the flush so that no entries can be added during this time.

The order of operations for deletes considers the dependency tree:

  • we remove IPv4 entries first, since these are never referenced counted, and the order of removing them never matters.
  • we check for any backup NHGs, and remove these first - since otherwise we may end up with referenced NHGs. note, we need to consider circular references of backup NHGs, which we may allow today. we remove the backup NHGs.
  • we remove the remaining NHGs.
  • we remove the NHs.

Flush handles updating the reference counts within the RIB.

func (*RIB) KnownNetworkInstances

func (r *RIB) KnownNetworkInstances() []string

KnownNetworkInstances returns the name of all known network instances within the RIB.

func (*RIB) NetworkInstanceRIB

func (r *RIB) NetworkInstanceRIB(s string) (*RIBHolder, bool)

NetworkInstanceRIB returns the RIB for the network instance with name s.

func (*RIB) RIBContents

func (r *RIB) RIBContents() (map[string]*aft.RIB, error)

RIBContents returns the contents of the RIB in a manner that an external caller can interact with. It returns a map, keyed by network instance name, with a deep copy of the RIB contents. Since copying large RIBs may be expensive care should be taken with when it is used. A copy is used since the RIB continues to handle concurrent changes to the contents from multiple sources.

func (*RIB) SetPostChangeHook

func (r *RIB) SetPostChangeHook(fn RIBHookFn)

SetPostChangeHook assigns the supplied hook to all network instance RIBs within the RIB structure.

func (*RIB) SetResolvedEntryHook

func (r *RIB) SetResolvedEntryHook(fn ResolvedEntryFn)

SetResolvedEntryHook asssigns the supplied hook to all network instance RIBs within the RIB structure.

func (*RIB) String

func (r *RIB) String() string

String returns a string representation of the RIB.

type RIBHolder

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

RIBHolder is a container for a set of RIBs.

func NewRIBHolder

func NewRIBHolder(name string, opts ...ribHolderOpt) *RIBHolder

NewRIBHolder returns a new RIB holder for a single network instance.

func (*RIBHolder) AddIPv4

func (r *RIBHolder) AddIPv4(e *aftpb.Afts_Ipv4EntryKey, explicitReplace bool) (bool, *aft.Afts_Ipv4Entry, error)

AddIPv4 adds the IPv4 entry described by e to the RIB. If the explicitReplace argument is set to true, the entry is checked for existence before it is replaced otherwise, replaces are implicit. It returns a bool that indicates whether the entry was installed, a IPv4 entry that represents the replaced entry, and an error which can be considered fatal (i.e., there is no future possibility of this entry becoming valid).)

func (*RIBHolder) AddIPv6

func (r *RIBHolder) AddIPv6(e *aftpb.Afts_Ipv6EntryKey, explicitReplace bool) (bool, *aft.Afts_Ipv6Entry, error)

AddIPv6 adds the IPv6 entry specified by e to the RIB, explicitReplace indicates whether the "add" operation that is being performed is actually an explicit replace of a specific prefix such that an error can be returned.

func (*RIBHolder) AddMPLS

func (r *RIBHolder) AddMPLS(e *aftpb.Afts_LabelEntryKey, explicitReplace bool) (bool, *aft.Afts_LabelEntry, error)

AddMPLS adds the specified label entry described by e to the RIB. If the explicitReplace argument is set to true, it checks whether the entry exists before it is replaced, otherwise replaces are implicit. It returns a bool which indicates whether the entry was added, a second bool that indicates whether the programming was an implicit replace and an error that should be considered fatal by the caller (i.e., there is no possibility that this entry can become valid and be installed in the future).

func (*RIBHolder) AddNextHop

func (r *RIBHolder) AddNextHop(e *aftpb.Afts_NextHopKey, explicitReplace bool) (bool, *aft.Afts_NextHop, error)

AddNextHop adds a new NextHop e to the RIBHolder receiver. If the explicitReplace argument is set to true, AddNextHop verifies that the entry exists within the RIB before replacing it, otherwise replaces are implicit. It returns a boolean indicating whether the NextHop was installed, along with a second boolean that indicates whether this was an implicit replace. If encountered, it returns an error if the group is invalid.

func (*RIBHolder) AddNextHopGroup

func (r *RIBHolder) AddNextHopGroup(e *aftpb.Afts_NextHopGroupKey, explicitReplace bool) (bool, *aft.Afts_NextHopGroup, error)

AddNextHopGroup adds a NextHopGroup e to the RIBHolder receiver. The explicitReplace argument determines whether the operation was an explicit replace, in which case an error is returned if the entry does not exist. It returns a boolean indicating whether the NHG was installed, a second bool indicating whether this was a replace. If encounted it returns an error if the group is invalid.

func (*RIBHolder) DeleteIPv4

func (r *RIBHolder) DeleteIPv4(e *aftpb.Afts_Ipv4EntryKey) (bool, *aft.Afts_Ipv4Entry, error)

DeleteIPv4 removes the IPv4 entry e from the RIB. It returns a boolean indicating whether the entry has been removed, a copy of the entry that was removed and an error if the message cannot be parsed. Per the gRIBI specification, the payload of the entry is not compared.

func (*RIBHolder) DeleteIPv6

func (r *RIBHolder) DeleteIPv6(e *aftpb.Afts_Ipv6EntryKey) (bool, *aft.Afts_Ipv6Entry, error)

DeleteIPv6 deletes the entry specified by e from the RIB, returning the entry that was removed.

func (*RIBHolder) DeleteMPLS

DeleteMPLS removes the MPLS label entry e from the RIB. It returns a boolean indicating whether the entry has been removed, a copy of the entry that was removed, and an error if the message cannot be parsed. Per the gRIBI specification the payload of the entry is not compared the existing entry before deleting it.

func (*RIBHolder) DeleteNextHop

func (r *RIBHolder) DeleteNextHop(e *aftpb.Afts_NextHopKey) (bool, *aft.Afts_NextHop, error)

DeleteNextHop removes the NextHop entry e from the RIB. It returns a boolean indicating whether the entry has been removed, a copy of the group that was removed and an error if the message cannot be parsed. Per the gRIBI specification, the payload of the entry is not compared.

func (*RIBHolder) DeleteNextHopGroup

func (r *RIBHolder) DeleteNextHopGroup(e *aftpb.Afts_NextHopGroupKey) (bool, *aft.Afts_NextHopGroup, error)

DeleteNextHopGroup removes the NextHopGroup entry e from the RIB. It returns a boolean indicating whether the entry has been removed, a copy of the next-hop-group that was removed and an error if the message cannot be parsed. Per the gRIBI specification, the payload of the entry is not compared.

func (*RIBHolder) GetNextHop

func (r *RIBHolder) GetNextHop(index uint64) (*aft.Afts_NextHop, bool)

GetNextHop gets the next-hop with the specified index from the RIB and returns it. It returns a bool indicating whether the value was found.

func (*RIBHolder) GetNextHopGroup

func (r *RIBHolder) GetNextHopGroup(id uint64) (*aft.Afts_NextHopGroup, bool)

GetNextHopGroup gets the next-hop-group with the specified ID from the RIB and returns it. It returns a bool indicating whether the value was found.

func (*RIBHolder) GetRIB

func (r *RIBHolder) GetRIB(filter map[spb.AFTType]bool, msgCh chan *spb.GetResponse, stopCh chan struct{}) error

GetRIB writes the contents of the RIBs specified in the filter to msgCh. filter is a map, keyed by the gRIBI AFTType enumeration, if the value is set to true, the AFT is written to msgCh, otherwise it is skipped. The contents of the RIB are returned as gRIBI GetResponse messages which are written to the supplied msgCh. stopCh is a channel that indicates that the GetRIB method should stop its work and return immediately.

An error is returned if the RIB cannot be returned.

func (*RIBHolder) IsValid

func (r *RIBHolder) IsValid() bool

IsValid determines whether the specified RIBHolder is valid to be programmed.

func (*RIBHolder) String

func (r *RIBHolder) String() string

String returns a string representation of the RIBHolder.

type RIBHolderCheckFunc

type RIBHolderCheckFunc func(constants.OpType, string, *aft.RIB) (bool, error)

RIBHolderCheckFunc is a function that is used as a check to determine whether a RIB entry is eligible for a particular operation. It takes arguments of:

  • the operation type that is being performed.

  • the network instance within which the operation should be considered.

  • the RIB that describes the candidate changes. In the case that the operation is an ADD or REPLACE the candidate must contain the entry that would be added or replaced. In the case that it is a DELETE, the candidate contains the entry that is to be deleted.

    The candidate contains a single entry.

The check function must return:

  • a bool indicating whether the RIB operation should go ahead (true = proceed).
  • an error that is considered fatal for the entry (i.e., this entry should never be tried again).

type RIBHookFn

RIBHookFn is a function that is used as a hook following a change. It takes:

  • an OpType deterining whether an add, remove, or modify operation was sent.
  • the timestamp in nanoseconds since the unix epoch that a function was performed.
  • a string indicating the name of the network instance
  • a ygot.ValidatedGoStruct containing the entry that has been changed.

type RIBOpt

type RIBOpt interface {
	// contains filtered or unexported methods
}

RIBOpt is an interface that is implemented for options to the RIB.

type ResolvedDetails

type ResolvedDetails interface {
	// contains filtered or unexported methods
}

ResolvedDetails is an interface implemented by any type that is returned as part of the AFT details.

type ResolvedEntryFn

type ResolvedEntryFn func(ribs map[string]*aft.RIB, optype constants.OpType, netinst string, aft constants.AFT, key any, dets ...ResolvedDetails)

ResolvedEntryFn is a function that is called for all entries that can be fully resolved within the RIB. Fully resolved in this case is defined as an input packet match criteria set of next-hops.

It takes arguments of:

  • the set of RIBs that were stored in the RIB as a map keyed by the name of a network instance, with a RIB represented as a ygot-generated AFT struct.
  • the prefix that was impacted.
  • the OpType that the entry was subject to (add/replace/delete).
  • a string indicating the network instance that the operation was within
  • an enumerated value indicating the AFT the operation was within.
  • an any that indicates the impacted AFT entry's key. The function must cast the any to the relevant type.
  • a set of details that the handler function may utilise.

Directories

Path Synopsis
Package reconciler reconciles the contents of two gRIBI RIBs -- the intended RIB is assumed to contain the desired RIB entries, whereas the 'target' RIB is to be programmed.
Package reconciler reconciles the contents of two gRIBI RIBs -- the intended RIB is assumed to contain the desired RIB entries, whereas the 'target' RIB is to be programmed.

Jump to

Keyboard shortcuts

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