ftutilities

package
v0.0.0-...-4bd20e7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ftutilities contains utility functions used by functional translators.

Index

Constants

This section is empty.

Variables

View Source
var (
	AristaMACSecMap = &AristaMACSecMapCache{
		data: make(map[string]*TargetMacSecInfo),
	}
)

Global instance of the AristaMACSecMapCache.

View Source
var ValidOrigins = map[string]struct{}{
	"openconfig": {},

	"eos_native": {},

	"Cisco-IOS-XR-controller-optics-oper": {},

	"Cisco-IOS-XR-fabric-plane-health-oper": {},

	"Cisco-IOS-XR-infra-statsd-oper": {},

	"Cisco-IOS-XR-ipv4-arp-oper": {},

	"Cisco-IOS-XR-ipv4-io-oper": {},

	"Cisco-IOS-XR-ipv6-ma-oper": {},

	"Cisco-IOS-XR-ipv6-nd-oper": {},

	"Cisco-IOS-XR-platforms-ofa-oper": {},

	"Cisco-IOS-XR-shellutil-filesystem-oper": {},

	"Cisco-IOS-XR-show-fpd-loc-ng-oper": {},

	"Cisco-IOS-XR-switch-oper": {},

	"Cisco-IOS-XR-qos-ma-oper": {},
}

ValidOrigins is the set of valid origins for gNMI paths. If they occur as the first element of a path or as the first non-empty string in a stringified path, they are used to set the origin.

Functions

func ConfigToState

func ConfigToState(p *gnmipb.Path) *gnmipb.Path

ConfigToState replaces "config" elements with "state" elements.

func Filter

func Filter(notification *gnmipb.Notification, fn func(path *gnmipb.Path, isDelete bool) bool) *gnmipb.Notification

Filter returns a new notification with only the updates that return true from the provided fn.

func FilterStructToState

func FilterStructToState(s ygot.GoStruct, ts int64, origin, target string) (*gnmipb.SubscribeResponse, error)

FilterStructToState converts a ygot struct to a gNMI subscribe response.

func FilterUpdates

func FilterUpdates(update []*gnmipb.Update, fn func(up *gnmipb.Update) bool) []*gnmipb.Update

FilterUpdates returns a slice containing updates that return true from the provided fn.

func ForcePathPrefix

func ForcePathPrefix(s, prefix string) string

ForcePathPrefix adds the prefix to the string if it is not already present, even if the string is empty.

func GNMIPathToSchemaString

func GNMIPathToSchemaString(p *gnmipb.Path, setOCIfOriginMissing bool) string

GNMIPathToSchemaString converts a gNMI path to a string.

func GNMIPathToSchemaStrings

func GNMIPathToSchemaStrings(path *gnmipb.Path, setOCIfOriginMissing bool) []string

GNMIPathToSchemaStrings extracts the schema path and converts it into a slice of strings. Origin is prepended as the first element, if present. setOCOriginIfMissing specifies if that path should include the origin. This is necessary because Arista does not set the origin, and we would have to forcibly set the origin as openConfig.

func Join

func Join(p1, p2 *gnmipb.Path) *gnmipb.Path

Join returns a new gNMI path with the elements of p1 and p2 concatenated. The origin and target of p1 are used, if present, and replaced with the values from p2 otherwise.

func LoadSubscribeResponse

func LoadSubscribeResponse(path string) (*gnmipb.SubscribeResponse, error)

LoadSubscribeResponse loads a subscribe response from a file.

func MatchPath

func MatchPath(path, pattern *gnmipb.Path) bool

MatchPath returns true if path matches against the provided pattern. A wildcard character "*" in the pattern matches all path elements.

func MaybeConvertOptical

func MaybeConvertOptical(portName string, opticsType string) (newPortName string, wanted bool)

MaybeConvertOptical returns the modified port name based on the optics type. Breakout child interfaces are ignored, as telemetry is provided through the parent interface. This is used by CISCOXR WBB devices when using the native path, which is of the form "Optics0/0/0/0" and the openconfig path is of the form "HundredGigE0/0/0/0", etc.

func MustStringMapPaths

func MustStringMapPaths(m map[string][]string) map[string][]*gnmipb.Path

MustStringMapPaths converts each string in the slices, into a list of gnmi Paths. it fails if there is an error.

func PathInList

func PathInList(p *gnmipb.Path, paths []*gnmipb.Path) bool

PathInList returns True if the path is in the list of paths.

func SortByYgotString

func SortByYgotString(s []*gnmipb.Path) func(i, j int) bool

SortByYgotString returns a function to sort gnmi paths by their stringified value.

func StateLeaves

func StateLeaves(up *gnmipb.Update) bool

StateLeaves returns true if one of the path elements has name "state".

func StringMapPaths

func StringMapPaths(stringPathMap map[string][]string) (map[string][]*gnmipb.Path, error)

StringMapPaths converts each string in the slices, into a list of gnmi Paths. The lists are returned with the same keys as the input.

func StringToPath

func StringToPath(s string) (*gnmipb.Path, error)

StringToPath converts a string to a gNMI path, potentially including an origin. The string must be in the format "origin/path/to/element", "/origin/path/to/element", "path/to/element", or "/path/to/element". The origin is only parsed if it is in the ValidOrigins map.

func StripPathPrefix

func StripPathPrefix(s, prefix string) string

StripPathPrefix strips the prefix from the path.

Types

type AristaMACSecMapCache

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

AristaMACSecMapCache is a thread-safe cache for AristaMACSecMap. It stores cached boolean values from distinct native Arista MACsec paths per target/interface/CKN. Although Functional Translators (FTs) are typically stateless, this map is required as an exception to hold values from these multiple source paths, necessary for deriving the single OpenConfig MACsec status. Declaring it here allows access by both the FT logic and the FT registration process, where it is cleared to prevent using stale information between registrations or updates.

func (*AristaMACSecMapCache) ClearAllTargetMacSecInfo

func (c *AristaMACSecMapCache) ClearAllTargetMacSecInfo()

ClearAllTargetMacSecInfo removes all entries from the cache.

func (*AristaMACSecMapCache) CreateOrUpdateTargetMacSecInfo

func (c *AristaMACSecMapCache) CreateOrUpdateTargetMacSecInfo(targetHostname string) *TargetMacSecInfo

CreateOrUpdateTargetMacSecInfo retrieves an existing TargetMacSecInfo for the given target or creates a new one if it doesn't exist, then stores it in the cache.

func (*AristaMACSecMapCache) DeleteTargetMacSecInfo

func (c *AristaMACSecMapCache) DeleteTargetMacSecInfo(targetHostname string)

DeleteTargetMacSecInfo removes the TargetMacSecInfo for a given target hostname.

func (*AristaMACSecMapCache) RetrieveTargetMacSecInfo

func (c *AristaMACSecMapCache) RetrieveTargetMacSecInfo(targetHostname string) (*TargetMacSecInfo, bool)

RetrieveTargetMacSecInfo fetches the TargetMacSecInfo for a given target hostname. It returns the info and a boolean indicating if the target was found.

func (*AristaMACSecMapCache) SetTargetMacSecInfo

func (c *AristaMACSecMapCache) SetTargetMacSecInfo(targetHostname string, info *TargetMacSecInfo)

SetTargetMacSecInfo adds or updates the TargetMacSecInfo for a given target hostname.

type CKNInfo

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

CKNInfo holds principal and success status for a specific CKN.

type InterfaceMacSecInfo

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

InterfaceMacSecInfo holds MACsec status information for a specific interface.

func (*InterfaceMacSecInfo) CloneStatuses

func (i *InterfaceMacSecInfo) CloneStatuses() map[string]*CKNInfo

CloneStatuses returns a copy of the CKN statuses map.

func (*InterfaceMacSecInfo) CreateOrGetCKN

func (i *InterfaceMacSecInfo) CreateOrGetCKN(ckn string) *CKNInfo

CreateOrGetCKN returns the CKNInfo for the given CKN, creating it if it doesn't exist.

func (*InterfaceMacSecInfo) IntfCPStatus

func (i *InterfaceMacSecInfo) IntfCPStatus() (bool, bool)

IntfCPStatus returns the cpStatus and a boolean indicating if it has been set.

func (*InterfaceMacSecInfo) IntfPrincipal

func (i *InterfaceMacSecInfo) IntfPrincipal(ckn string) (bool, bool)

IntfPrincipal returns the principal status for a given CKN and a boolean indicating if it has been set.

func (*InterfaceMacSecInfo) IntfSuccess

func (i *InterfaceMacSecInfo) IntfSuccess(ckn string) (bool, bool)

IntfSuccess returns the success status for a given CKN and a boolean indicating if it has been set.

func (*InterfaceMacSecInfo) IsComplete

func (i *InterfaceMacSecInfo) IsComplete(ckn string) bool

IsComplete checks if all necessary MACsec CKN status values have been set.

func (*InterfaceMacSecInfo) RemoveCkn

func (i *InterfaceMacSecInfo) RemoveCkn(ckn string)

RemoveCkn removes MACsec information for a specific CKN.

func (*InterfaceMacSecInfo) ResetCPStatus

func (i *InterfaceMacSecInfo) ResetCPStatus()

ResetCPStatus marks the cpStatus as not set and resets its value. This is used when the native source for cpStatus is deleted.

func (*InterfaceMacSecInfo) SetIntfCPStatus

func (i *InterfaceMacSecInfo) SetIntfCPStatus(b bool)

SetIntfCPStatus sets the cpStatus and marks it as set.

func (*InterfaceMacSecInfo) SetIntfPrincipal

func (i *InterfaceMacSecInfo) SetIntfPrincipal(ckn string, b bool)

SetIntfPrincipal sets the principal status for a given CKN and marks it as set.

func (*InterfaceMacSecInfo) SetIntfSuccess

func (i *InterfaceMacSecInfo) SetIntfSuccess(ckn string, b bool)

SetIntfSuccess sets the success status for a given CKN and marks it as set.

type TargetMacSecInfo

type TargetMacSecInfo struct {
	TargetHostname string
	Interfaces     map[string]*InterfaceMacSecInfo // map[InterfaceName]*InterfaceMacSecInfo
	// contains filtered or unexported fields
}

TargetMacSecInfo holds MACsec information for all interfaces on a target.

func NewTargetMacSecInfo

func NewTargetMacSecInfo(targetHostname string) *TargetMacSecInfo

NewTargetMacSecInfo creates a new TargetMacSecInfo for the given target hostname.

func (*TargetMacSecInfo) ClearInterfaceInfo

func (t *TargetMacSecInfo) ClearInterfaceInfo(intf string)

ClearInterfaceInfo removes MACsec information for a specific interface.

func (*TargetMacSecInfo) CreateOrGetInterface

func (t *TargetMacSecInfo) CreateOrGetInterface(interfaceName string) *InterfaceMacSecInfo

CreateOrGetInterface returns the InterfaceMacSecInfo for the given interface name, creating it if it doesn't exist. It also initializes the CKN statuses map if it doesn't exist.

func (*TargetMacSecInfo) InterfaceInfo

func (t *TargetMacSecInfo) InterfaceInfo(intf string) (*InterfaceMacSecInfo, bool)

InterfaceInfo retrieves the MACsec info for a specific interface.

Jump to

Keyboard shortcuts

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