goebpf_mock

package
v0.0.0-...-fbfc095 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: GPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MockMaps map[string]goebpf.Map

MockMaps is list of cross compiled/linked eBPF maps into GO executable This map will contain all eBPF maps defined in eBPF program

Functions

func CleanupAllMockMaps

func CleanupAllMockMaps()

CleanupAllMockMaps re-creates all mock maps Useful for unittests

Types

type MockMap

type MockMap struct {
	Name       string
	Type       goebpf.MapType
	KeySize    int
	ValueSize  int
	MaxEntries int
	// contains filtered or unexported fields
}

MockMap defines eBPF mockmap and implements Map interface

func (*MockMap) CloneTemplate

func (m *MockMap) CloneTemplate() goebpf.Map

CloneTemplate creates clone of current map

func (*MockMap) Close

func (m *MockMap) Close() error

Close does nothing - just to implement Map interface

func (*MockMap) Create

func (m *MockMap) Create() error

Create creates MockMap

func (*MockMap) Delete

func (m *MockMap) Delete(ikey interface{}) error

Delete deletes element from mock map Valid only for non array map types

func (*MockMap) Destroy

func (m *MockMap) Destroy() error

Destroy destroys mock map

func (*MockMap) GetFd

func (m *MockMap) GetFd() int

GetFd returns mock file descriptor of map

func (*MockMap) GetName

func (m *MockMap) GetName() string

GetName returns mock map name

func (*MockMap) GetNextKey

func (m *MockMap) GetNextKey(ikey interface{}) ([]byte, error)

GetNextKey gets the next key of the provided key

func (*MockMap) GetNextKeyInt

func (m *MockMap) GetNextKeyInt(ikey interface{}) (int, error)

func (*MockMap) GetNextKeyString

func (m *MockMap) GetNextKeyString(ikey interface{}) (string, error)

func (*MockMap) GetNextKeyUint64

func (m *MockMap) GetNextKeyUint64(ikey interface{}) (uint64, error)

func (*MockMap) GetType

func (m *MockMap) GetType() goebpf.MapType

GetType returns mock map type

func (*MockMap) Insert

func (m *MockMap) Insert(ikey interface{}, ivalue interface{}) error

Insert insert new element into mock map. Valid only for non array maps.

func (*MockMap) Lookup

func (m *MockMap) Lookup(ikey interface{}) ([]byte, error)

Lookup is generic implementation for all other Lookups (string, int, etc)

func (*MockMap) LookupInt

func (m *MockMap) LookupInt(ikey interface{}) (int, error)

LookupInt perform lookup and returns int

func (*MockMap) LookupString

func (m *MockMap) LookupString(ikey interface{}) (string, error)

LookupString perform lookup and returns GO string from NULL terminated C string

func (*MockMap) LookupUint64

func (m *MockMap) LookupUint64(ikey interface{}) (uint64, error)

LookupUint64 perform lookup and returns uint64

func (*MockMap) Update

func (m *MockMap) Update(ikey interface{}, ivalue interface{}) error

Update updates existing element in mock map

func (*MockMap) Upsert

func (m *MockMap) Upsert(ikey interface{}, ivalue interface{}) error

Upsert updates existing element in mock map, or inserts one if it did not exist yet

type MockProgram

type MockProgram struct {
	Attached bool
	Fd       int
	License  string
	Name     string
	Section  string
	Size     int
	ProgType goebpf.ProgramType
}

MockProgram is mock implementation for eBPF program

func NewMockProgram

func NewMockProgram(name string, tp goebpf.ProgramType) *MockProgram

NewMockProgram creates new mock program of tp type.

func (*MockProgram) Attach

func (m *MockProgram) Attach(meta interface{}) error

Attach does nothing, only to implement Program interface

func (*MockProgram) Close

func (m *MockProgram) Close() error

Close does nothing, only to implement Program interface

func (*MockProgram) Detach

func (m *MockProgram) Detach() error

Detach does nothing, only to implement Program interface

func (*MockProgram) GetFd

func (m *MockProgram) GetFd() int

GetFd returns mock program fd

func (*MockProgram) GetLicense

func (m *MockProgram) GetLicense() string

GetLicense return program's license

func (*MockProgram) GetName

func (m *MockProgram) GetName() string

GetName return program name

func (*MockProgram) GetSection

func (m *MockProgram) GetSection() string

GetSection returns the section name used by the program

func (*MockProgram) GetSize

func (m *MockProgram) GetSize() int

GetSize returns program size set by user

func (*MockProgram) GetType

func (m *MockProgram) GetType() goebpf.ProgramType

GetType returns program type

func (*MockProgram) Load

func (m *MockProgram) Load() error

Load does nothing, only to implement Program interface

func (*MockProgram) Pin

func (m *MockProgram) Pin(path string) error

Pin does nothing, just returns nil

type MockSystem

type MockSystem struct {
	Programs map[string]goebpf.Program
	Maps     map[string]goebpf.Map

	// ErrorLoadElf specifies return value for LoadElf() method.
	ErrorLoadElf error
}

MockSystem is mock implementation of eBPF system

func NewMockSystem

func NewMockSystem() *MockSystem

NewMockSystem creates mocked eBPF system with: - empty program map - all linked mock maps

func (*MockSystem) GetMapByName

func (m *MockSystem) GetMapByName(name string) goebpf.Map

GetMapByName returns eBPF map by name or nil if not found

func (*MockSystem) GetMaps

func (m *MockSystem) GetMaps() map[string]goebpf.Map

GetMaps returns all linked eBPF maps

func (*MockSystem) GetProgramByName

func (m *MockSystem) GetProgramByName(name string) goebpf.Program

GetProgramByName returns eBPF program by name or nil if not found

func (*MockSystem) GetPrograms

func (m *MockSystem) GetPrograms() map[string]goebpf.Program

GetPrograms returns map of added eBPF programs

func (*MockSystem) Load

func (m *MockSystem) Load(r io.ReaderAt) error

Load does nothing, just a mock for original Load

func (*MockSystem) LoadElf

func (m *MockSystem) LoadElf(path string) error

LoadElf does nothing, just a mock for original LoadElf

Directories

Path Synopsis
Package wrapper is wrapper for "cross compiled" XDP in order to call it right from GO P.S. this should be as part of *_test.go files, however, GO does not support using import "C" from tests...
Package wrapper is wrapper for "cross compiled" XDP in order to call it right from GO P.S. this should be as part of *_test.go files, however, GO does not support using import "C" from tests...

Jump to

Keyboard shortcuts

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