kf

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package kf provides primitives for BPF programs / Network Functions.

Package kf provides primitives for l3afd's network function configs.

Package kf provides primitives for NF process monitoring.

Package kf provides primitives for l3afd's network function configs.

Package kf provides primitives for NF process monitoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySearch

func BinarySearch(names []string, target string) bool

BinarySearch: It is checking a target string exists in sorted slice of strings

func DisableLRO

func DisableLRO(ifaceName string) error

DisableLRO - XDP programs are failing when LRO is enabled, to fix this we use to manually disable. # ethtool -K ens7 lro off # ethtool -k ens7 | grep large-receive-offload large-receive-offload: off

func GetPlatform

func GetPlatform() (string, error)

This method get the Linux distribution Codename. This logic works on ubuntu Here assumption is all edge nodes are running with lsb modules. It returns empty string in case of error

func GetTestExecutableName

func GetTestExecutableName() string

func GetTestExecutablePath

func GetTestExecutablePath() string

func GetTestExecutablePathName

func GetTestExecutablePathName() string

func GetTestNonexecutablePathName

func GetTestNonexecutablePathName() string

func IsProcessRunning

func IsProcessRunning(pid int, name string) (bool, error)

func NewpCheck

func NewpCheck(rc int, chain bool, interval time.Duration) *pCheck

func NewpKFMetrics

func NewpKFMetrics(chain bool, interval int) *kfMetrics

func SetupKFDebug

func SetupKFDebug(ebpfChainDebugAddr string, kfConfigs *NFConfigs)

func StopExternalRunningProcess

func StopExternalRunningProcess(processName string) error

Stop the NF process if running outside l3afd

func ValidatePath

func ValidatePath(filePath string, destination string) (string, error)

func VerifyNMountBPFFS

func VerifyNMountBPFFS() error

VerifyNMountBPFFS - Mounting bpf filesystem

func VerifyNMountTraceFS

func VerifyNMountTraceFS() error

VerifyNMounTraceFS - Mounting trace filesystem

func ViewHandler

func ViewHandler(w http.ResponseWriter, r *http.Request)

Types

type BPF

type BPF struct {
	Program         models.BPFProgram
	Cmd             *exec.Cmd
	FilePath        string                    // Binary file path
	RestartCount    int                       // To track restart count
	PrevMapNamePath string                    // Previous Map name with path to link
	MapNamePath     string                    // Map name with path
	ProgID          int                       // eBPF Program ID
	BpfMaps         map[string]BPFMap         // Config maps passed as map-args, Map name is Key
	MetricsBpfMaps  map[string]*MetricsBPFMap // Metrics map name+key+aggregator is key
	Ctx             context.Context
	Done            chan bool `json:"-"`
	// contains filtered or unexported fields
}

BPF defines run time details for BPFProgram.

func LoadRootProgram

func LoadRootProgram(ifaceName string, direction string, progType string, conf *config.Config) (*BPF, error)

LoadRootProgram - Loading the Root Program for a given interface.

func NewBpfProgram

func NewBpfProgram(ctx context.Context, program models.BPFProgram, conf *config.Config) *BPF

func (*BPF) AddBPFMap

func (b *BPF) AddBPFMap(mapName string) error

Add eBPF map into BPFMaps list

func (*BPF) AddMetricsBPFMap

func (b *BPF) AddMetricsBPFMap(mapName, aggregator string, key, samplesLength int) error

Add eBPF map into BPFMaps list

func (*BPF) GetArtifacts

func (b *BPF) GetArtifacts(conf *config.Config) error

GetArtifacts downloads artifacts from the specified eBPF repo

func (*BPF) GetBPFMap

func (b *BPF) GetBPFMap(mapName string) (*BPFMap, error)

func (*BPF) GetProgID

func (b *BPF) GetProgID() (int, error)

GetProgID - This returns ID of the bpf program

func (*BPF) MonitorMaps

func (b *BPF) MonitorMaps(ifaceName string, intervals int) error

This method to fetch values from bpf maps and publish to metrics

func (*BPF) ProcessTerminate

func (b *BPF) ProcessTerminate() error

ProcessTerminate - Send sigterm to the process

func (*BPF) PutNextProgFDFromID

func (b *BPF) PutNextProgFDFromID(progID int) error

Updating next program FD from program ID

func (*BPF) RemoveNextProgFD

func (b *BPF) RemoveNextProgFD() error

Delete the entry if its last program in the chain. This method is called when sequence of the program changed to last in the chain

func (*BPF) RemovePrevProgFD

func (b *BPF) RemovePrevProgFD() error

Delete the entry if the last element

func (*BPF) RunKFConfigs

func (b *BPF) RunKFConfigs() error

func (*BPF) SetPrLimits

func (b *BPF) SetPrLimits() error

Set process resource limits only non-zero value

func (*BPF) Start

func (b *BPF) Start(ifaceName, direction string, chain bool) error

Start returns the last error seen, but starts bpf program. Here initially prevprogmap entry is removed and passed to the bpf program After starting the user program, will update the kernel progam fd into prevprogram map. This method waits till prog fd entry is updated, else returns error assuming kernel program is not loaded. It also verifies the next program pinned map is created or not.

func (*BPF) Stop

func (b *BPF) Stop(ifaceName, direction string, chain bool) error

Stop returns the last error seen, but stops bpf program. Clean up all map handles. Verify next program pinned map file is removed

func (*BPF) Update

func (b *BPF) Update(ifaceName, direction string) error

Updates the config map_args

func (*BPF) VerifyAndGetArtifacts

func (b *BPF) VerifyAndGetArtifacts(conf *config.Config) error

Check binary already exists

func (*BPF) VerifyMetricsMapsVanish

func (b *BPF) VerifyMetricsMapsVanish() error

VerifyMetricsMapsVanish - checks for all metrics maps references are removed from the kernel

func (*BPF) VerifyPinnedMapExists

func (b *BPF) VerifyPinnedMapExists(chain bool) error

making sure program fd map's pinned file is created

func (*BPF) VerifyPinnedMapVanish

func (b *BPF) VerifyPinnedMapVanish(chain bool) error

VerifyPinnedMapVanish - making sure XDP program fd map's pinned file is removed

func (*BPF) VerifyProcessObject

func (b *BPF) VerifyProcessObject() error

This method to verify cmd and process object is populated or not

type BPFMap

type BPFMap struct {
	Name  string
	MapID ebpf.MapID
	Type  ebpf.MapType

	// BPFProg reference in case of stale map id
	BPFProg *BPF `json:"-"`
}

func (*BPFMap) Update

func (b *BPFMap) Update(value string) error

The update function is used to update eBPF maps, which are used by network functions. Supported types are Array and Hash Multiple values are comma separated Hashmap can be multiple values or single values. If hash map entries then key will be values and value will be set to 1 In case of Array then key will be index starting from 0 and values are stored. for e.g.

HashMap scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
	key => 80 value => 1
	key => 443 value => 1
HashMap scenario 2. --ports="443" value is stored in rl_ports_map BPF map
	key => 443 value => 1
Array scenario 1. --ports="80,443" values are stored in rl_ports_map BPF map
	key => 0 value => 80
	key => 1 value => 443
Array scenario 2. --rate="10000" value is stored in rl_config_map BPF map
	key => 0 value => 10000

type MetricsBPFMap

type MetricsBPFMap struct {
	BPFMap

	Values *ring.Ring
	// contains filtered or unexported fields
}

This stores Metrics map details.

func (*MetricsBPFMap) AvgValue

func (b *MetricsBPFMap) AvgValue() float64

This method calculates the average

func (*MetricsBPFMap) GetValue

func (b *MetricsBPFMap) GetValue() float64

Get value of the map for given key There are 2 aggregators are supported here max-rate - this calculates delta requests / sec and stores absolute value. avg - stores the values in the circular queue We can implement more aggregate function as needed.

func (*MetricsBPFMap) MaxValue

func (b *MetricsBPFMap) MaxValue() float64

This method finds the max value in the circular list

type NFConfigs

type NFConfigs struct {
	HostName string

	//	configs        sync.Map // key: string, val: *models.L3afDNFConfigDetail
	// These holds bpf programs in the list
	// map keys are network iface names index's are seq_id, position in the chain
	// root element will be root program
	IngressXDPBpfs map[string]*list.List
	IngressTCBpfs  map[string]*list.List
	EgressTCBpfs   map[string]*list.List

	HostConfig *config.Config
	// contains filtered or unexported fields
}

func NewNFConfigs

func NewNFConfigs(ctx context.Context, host string, hostConf *config.Config, pMon *pCheck, metricsMon *kfMetrics) (*NFConfigs, error)

func (*NFConfigs) AddAndStartBPF

func (c *NFConfigs) AddAndStartBPF(bpfProg *models.BPFProgram, ifaceName string, direction string) error

func (*NFConfigs) AddProgramWithoutChaining

func (c *NFConfigs) AddProgramWithoutChaining(ifaceName string, bpfProgs *models.BPFPrograms) error

AddProgramWithoutChaining : add eBPF program on given interface when chaining is not enabled

func (*NFConfigs) AddProgramsOnInterface

func (c *NFConfigs) AddProgramsOnInterface(ifaceName, HostName string, bpfProgs *models.BPFPrograms) error

AddProgramsOnInterface: AddProgramsOnInterface will add given ebpf programs on given interface

func (*NFConfigs) AddeBPFPrograms

func (c *NFConfigs) AddeBPFPrograms(bpfProgs []models.L3afBPFPrograms) error

AddeBPFPrograms - Starts eBPF programs on the node if they are not running

func (*NFConfigs) Close

func (c *NFConfigs) Close(ctx context.Context) error

Close stop all the eBPF Programs and delete elements in the list

func (*NFConfigs) DeleteEbpfPrograms

func (c *NFConfigs) DeleteEbpfPrograms(bpfProgs []models.L3afBPFProgramNames) error

DeleteEbpfPrograms - Delete eBPF programs on the node if they are running

func (*NFConfigs) DeleteProgramsOnInterface

func (c *NFConfigs) DeleteProgramsOnInterface(ifaceName, HostName string, bpfProgs *models.BPFProgramNames) error

DeleteProgramsOnInterface : It will delete ebpf Programs on the given interface

func (*NFConfigs) DeleteProgramsOnInterfaceHelper

func (c *NFConfigs) DeleteProgramsOnInterfaceHelper(e *list.Element, ifaceName string, direction string, bpfList *list.List) error

DeleteProgramsOnInterfaceHelper : helper function for DeleteProgramsOnInterface function

func (*NFConfigs) Deploy

func (c *NFConfigs) Deploy(ifaceName, HostName string, bpfProgs *models.BPFPrograms) error

func (*NFConfigs) DeployeBPFPrograms

func (c *NFConfigs) DeployeBPFPrograms(bpfProgs []models.L3afBPFPrograms) error

DeployeBPFPrograms - Starts eBPF programs on the node if they are not running

func (*NFConfigs) DownloadAndStartBPFProgram

func (c *NFConfigs) DownloadAndStartBPFProgram(element *list.Element, ifaceName, direction string) error

func (*NFConfigs) EBPFPrograms

func (c *NFConfigs) EBPFPrograms(iface string) models.L3afBPFPrograms

EBPFPrograms - Method provides list of eBPF Programs running on iface

func (*NFConfigs) EBPFProgramsAll

func (c *NFConfigs) EBPFProgramsAll() []models.L3afBPFPrograms

EBPFProgramsAll - Method provides list of eBPF Programs running on all ifaces on the host

func (*NFConfigs) InsertAndStartBPFProgram

func (c *NFConfigs) InsertAndStartBPFProgram(bpfProg *models.BPFProgram, ifaceName, direction string) error

InsertAndStartBPFProgram method for tc programs

func (*NFConfigs) KFDetails

func (c *NFConfigs) KFDetails(iface string) []*BPF

KFDetails - Method provides dump of KFs for debug purpose

func (*NFConfigs) LinkBPFPrograms

func (c *NFConfigs) LinkBPFPrograms(leftBPF, rightBPF *BPF) error

Link BPF programs

func (*NFConfigs) MoveToLocation

func (c *NFConfigs) MoveToLocation(element *list.Element, bpfList *list.List) error

func (*NFConfigs) PushBackAndStartBPF

func (c *NFConfigs) PushBackAndStartBPF(bpfProg *models.BPFProgram, ifaceName, direction string) error

This method inserts the element at the end of the list

func (*NFConfigs) RemoveMissingBPFProgramsInConfig

func (c *NFConfigs) RemoveMissingBPFProgramsInConfig(bpfProg models.L3afBPFPrograms, ifaceName, direction string) error

RemoveMissingBPFProgramsInConfig - This method to stop the eBPF programs which are not listed in the config.

func (*NFConfigs) RemoveMissingNetIfacesNBPFProgsInConfig

func (c *NFConfigs) RemoveMissingNetIfacesNBPFProgsInConfig(bpfProgCfgs []models.L3afBPFPrograms) error

RemoveMissingNetIfacesNBPFProgsInConfig - Stops running eBPF programs which are missing in the config

func (*NFConfigs) SaveConfigsToConfigStore

func (c *NFConfigs) SaveConfigsToConfigStore() error

SaveConfigsToConfigStore - Writes configs to persistent store

func (*NFConfigs) StopNRemoveAllBPFPrograms

func (c *NFConfigs) StopNRemoveAllBPFPrograms(ifaceName, direction string) error

Stopping all programs in order

func (*NFConfigs) StopRootProgram

func (c *NFConfigs) StopRootProgram(ifaceName, direction string) error

StopRootProgram -This method stops the root program, removes the root node from the list and reset the list to nil

func (*NFConfigs) VerifyAndStartTCRootProgram

func (c *NFConfigs) VerifyAndStartTCRootProgram(ifaceName, direction string) error

Check for TC root program is running for a interface. If not start it

func (*NFConfigs) VerifyAndStartXDPRootProgram

func (c *NFConfigs) VerifyAndStartXDPRootProgram(ifaceName, direction string) error

Check for XDP programs are not loaded then initialise the array Check for XDP root program is running for a interface. if not loaded it

func (*NFConfigs) VerifyNUpdateBPFProgram

func (c *NFConfigs) VerifyNUpdateBPFProgram(bpfProg *models.BPFProgram, ifaceName, direction string) error

VerifyNUpdateBPFProgram - This method checks the following conditions 1. BPF Program already running with no change 2. BPF Program running but needs to stop (admin_status == disabled) 3. BPF Program running but needs version update 4. BPF Program running but position change (seq_id change) 5. BPF Program not running but needs to start.

Jump to

Keyboard shortcuts

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