utils

package
v0.0.0-...-a2207f8 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package utils holds utilities for opi-gateway-evpn-cni

Index

Constants

This section is empty.

Variables

View Source
var (

	// NetDirectory sysfs net directory
	NetDirectory = "/sys/class/net"
	// SysBusPci is sysfs pci device directory for host
	SysBusPci = "/sys/bus/pci/devices"
	// ContainerSysBusPci is sysfs pci device directory for containers
	ContainerSysBusPci = "/root/sys/bus/pci/devices"
	// SysV4ArpNotify is the sysfs IPv4 ARP Notify directory
	SysV4ArpNotify = "/proc/sys/net/ipv4/conf/"
	// SysV6NdiscNotify is the sysfs IPv6 Neighbor Discovery Notify directory
	SysV6NdiscNotify = "/proc/sys/net/ipv6/conf/"
	// UserspaceDrivers is a list of driver names that don't have netlink representation for their devices
	UserspaceDrivers = []string{"vfio-pci", "uio_pci_generic", "igb_uio"}
)

Functions

func AnnounceIPs

func AnnounceIPs(ifName string, ipConfigs []*current.IPConfig) error

AnnounceIPs sends either a GARP or Unsolicited NA depending on the IP address type (IPv4 vs. IPv6 respectively) configured on the interface.

func CleanCachedNetConf

func CleanCachedNetConf(cRefPath string) error

CleanCachedNetConf removed cached NetConf from disk

func EnableArpAndNdiscNotify

func EnableArpAndNdiscNotify(ifName string) error

EnableArpAndNdiscNotify enables IPv4 arp_notify and IPv6 ndisc_notify for netdev

func GetContainerNetDevFromPci

func GetContainerNetDevFromPci(netNSPath, pciAddress string) ([]string, error)

GetContainerNetDevFromPci returns a list of netdevices from PCI address that is attached to container

func GetPciAddress

func GetPciAddress(ifName string, vf int) (string, error)

GetPciAddress takes in a interface(ifName) and VF id and returns its pci addr as string

func GetPfName

func GetPfName(vf string) (string, error)

GetPfName returns PF net device name of a given VF pci address

func GetSharedPF

func GetSharedPF(ifName string) (string, error)

GetSharedPF takes in VF name(ifName) as string and returns the other VF name that shares same PCI address as string

func GetSriovNumVfs

func GetSriovNumVfs(ifName string) (int, error)

GetSriovNumVfs takes in a PF name(ifName) as string and returns number of VF configured as int

func GetVFLinkNames

func GetVFLinkNames(pciAddr string) (string, error)

GetVFLinkNames returns VF's network interface name given it's PCI addr

func GetVFLinkNamesFromVFID

func GetVFLinkNamesFromVFID(pfName string, vfID int) ([]string, error)

GetVFLinkNamesFromVFID returns VF's network interface name given it's PF name as string and VF id as int

func GetVfid

func GetVfid(addr string, pfName string) (int, error)

GetVfid takes in VF's PCI address(addr) and pfName as string and returns VF's ID as int

func HasDpdkDriver

func HasDpdkDriver(pciAddr string) (bool, error)

HasDpdkDriver checks if a device is attached to dpdk supported driver

func IsIPv4

func IsIPv4(ip net.IP) bool

IsIPv4 checks if a net.IP is an IPv4 address.

func IsIPv6

func IsIPv6(ip net.IP) bool

IsIPv6 checks if a net.IP is an IPv6 address.

func IsValidMACAddress

func IsValidMACAddress(addr net.HardwareAddr) bool

IsValidMACAddress checks if net.HardwareAddr is a valid MAC address.

func PathExists

func PathExists(path string) (bool, error)

PathExists checks if a file exists on a specified path

func ReadScratchNetConf

func ReadScratchNetConf(cRefPath string) ([]byte, error)

ReadScratchNetConf takes in container ID, Pod interface name and data dir as string and returns a pointer to Conf

func RetrieveMacFromPci

func RetrieveMacFromPci(pciAddr string, pciToMacFile string) (string, error)

RetrieveMacFromPci gets the Mac address from the PCI address of the VF by reading a config file where the mapping is located.

func Retry

func Retry(retries int, sleep time.Duration, f func() error) error

Retry retries a given function until no return error; times out after retries*sleep

func SaveNetConf

func SaveNetConf(cid, dataDir, podIfName string, conf interface{}) error

SaveNetConf takes in container ID, data dir and Pod interface name as string and a json encoded struct Conf and save this Conf in data dir

func SendGratuitousArp

func SendGratuitousArp(srcIP net.IP, linkObj netlink.Link) error

SendGratuitousArp sends a gratuitous ARP packet with the provided source IP over the provided interface.

func SendUnsolicitedNeighborAdvertisement

func SendUnsolicitedNeighborAdvertisement(srcIP net.IP, linkObj netlink.Link) error

SendUnsolicitedNeighborAdvertisement sends an unsolicited neighbor advertisement packet with the provided source IP over the provided interface.

Types

type PCIAllocation

type PCIAllocation interface {
	SaveAllocatedPCI(string, string) error
	DeleteAllocatedPCI(string) error
	IsAllocated(string) error
}

PCIAllocation holds functions for managing PCI devices

type PCIAllocator

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

PCIAllocator implements PCIAllocation interface

func NewPCIAllocator

func NewPCIAllocator(dataDir string) *PCIAllocator

NewPCIAllocator returns a new PCI allocator it will use the <dataDir>/pci folder to store the information about allocated PCI addresses

func (*PCIAllocator) DeleteAllocatedPCI

func (p *PCIAllocator) DeleteAllocatedPCI(pciAddress string) error

DeleteAllocatedPCI Remove the allocated PCI file return error if the file doesn't exist

func (*PCIAllocator) IsAllocated

func (p *PCIAllocator) IsAllocated(pciAddress string) (bool, error)

IsAllocated checks if the PCI address file exist if it exists we also check the network namespace still exist if not we delete the allocation The function will return an error if the pci is still allocated to a running pod

func (*PCIAllocator) SaveAllocatedPCI

func (p *PCIAllocator) SaveAllocatedPCI(pciAddress, ns string) error

SaveAllocatedPCI creates a file with the pci address as a name and the network namespace as the content return error if the file was not created

Jump to

Keyboard shortcuts

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