ffi

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidQuery = errors.New("invalid counter query")

ErrInvalidQuery reports a counter query the matcher refused to compile.

View Source
var ErrInvalidTag = errors.New("invalid counter tag")

ErrInvalidTag reports a counter tag the fixed-size C counter_tag fields cannot carry.

View Source
var ErrStillReferenced = errors.New("object still referenced by a live configuration generation")

ErrStillReferenced is reported by a handle Free when a live configuration generation still references the object: the object is intact, the free was refused, and the owner — the module, device or object control plane that knows the type — must remember the handle and free it again once the generations holding it drain.

Functions

func ValidateQuery

func ValidateQuery(query []string) error

ValidateQuery rejects a query a C string cannot carry, such as one with a NUL.

func ValidateTag

func ValidateTag(tag CounterTag) error

ValidateTag rejects a tag the fixed-size C counter_tag fields cannot carry: one with a NUL byte, or a key or value that does not fit.

Types

type Agent

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

func (*Agent) AsRawPtr

func (m *Agent) AsRawPtr() unsafe.Pointer

func (*Agent) BlockAllocatorFreeSize

func (m *Agent) BlockAllocatorFreeSize() uint64

BlockAllocatorFreeSize returns the total free memory in the agent's block allocator.

func (*Agent) CleanUp

func (m *Agent) CleanUp() error

func (*Agent) Close

func (m *Agent) Close() error

func (*Agent) DPConfig

func (m *Agent) DPConfig() *DPConfig

func (*Agent) DeleteFunction

func (m *Agent) DeleteFunction(name string) error

func (*Agent) DeleteModuleConfig

func (m *Agent) DeleteModuleConfig(moduleType, configName string) error

func (*Agent) DeletePipeline

func (m *Agent) DeletePipeline(name string) error

func (*Agent) Extend

func (m *Agent) Extend(size datasize.ByteSize) error

Extend grows the agent's shared memory by the given size.

An agent that draws memory straight from the controlplane pool cannot be grown.

func (*Agent) MemoryLimit

func (m *Agent) MemoryLimit() datasize.ByteSize

MemoryLimit reports the shared memory currently reserved for the agent.

func (*Agent) UpdateDevices

func (m *Agent) UpdateDevices(devices []ShmDeviceConfig) error

UpdateDevices attaches the given pipelines to the given device IDs.

func (*Agent) UpdateFunction

func (m *Agent) UpdateFunction(functionConfig FunctionConfig) error

func (*Agent) UpdateModules

func (m *Agent) UpdateModules(modules []ModuleConfig) error

func (*Agent) UpdatePipeline

func (m *Agent) UpdatePipeline(pipelineConfig PipelineConfig) error

type AgentInfo

type AgentInfo struct {
	Name      string
	Instances []AgentInstanceInfo
}

AgentInfo represents information about a control plane agent.

type AgentInstanceInfo

type AgentInstanceInfo struct {
	PID         uint32
	MemoryLimit uint64
	FreeBytes   uint64
	Gen         uint64
	// MemoryTree is a flat depth-first snapshot of the agent's
	// memory-context tree.
	//
	// Index 0 is the root; each later node references its parent via
	// ParentIdx. Best-effort: a concurrent update may make a node appear or
	// vanish between traversal passes.
	MemoryTree []AgentMemoryNode
}

AgentInstanceInfo contains details about a specific agent instance.

type AgentMemoryNode

type AgentMemoryNode struct {
	Name        string
	ParentIdx   uint32
	BAllocCount uint64
	BFreeCount  uint64
	BAllocSize  uint64
	BFreeSize   uint64
}

AgentMemoryNode is one entry in a flat depth-first snapshot of an agent's memory-context tree.

Copied from shared memory by the C info API; the caller never accesses shared memory directly through this type.

type CPConfig

type CPConfig struct {
	Type string
	Name string
	Gen  uint64
}

CPConfig represents a control plane configuration associated with a module.

type Chain

type Chain struct {
	Name    string
	Weight  uint64
	Modules []ChainModule
}

type ChainConfig

type ChainConfig struct {
	Name    string
	Modules []ChainModuleConfig
}

type ChainModule

type ChainModule struct {
	Type string
	Name string
}

type ChainModuleConfig

type ChainModuleConfig struct {
	Type string
	Name string
}

type CounterGroup

type CounterGroup struct {
	Tags     []CounterTag
	Counters []CounterInfo
}

CounterGroup is a set of counters that share the same tag set.

func MergeWorkerCounterGroups

func MergeWorkerCounterGroups(
	workerCount int,
	perWorker [][]CounterGroup,
) []CounterGroup

MergeWorkerCounterGroups combines per-worker counter groups into one slice spanning every worker.

A counter is identified by its group's tag set and its name. The first worker carrying it defines its position and its size, every other carrier's snapshot lands in that worker's instance slot, and workers without the counter contribute zero values in theirs. Sizes come from the module's registry and are expected to agree across workers; on disagreement the first worker's size stays and the disagreeing worker's instance remains zero.

type CounterInfo

type CounterInfo struct {
	Name string
	// Values is indexed by instance, then by value index within that instance.
	Values [][]uint64
}

CounterInfo is a snapshot of one dataplane counter sharded across equally sized instances.

func (CounterInfo) InstanceValues

func (m CounterInfo) InstanceValues(instance int) []uint64

InstanceValues returns every value of one instance.

func (CounterInfo) Instances

func (m CounterInfo) Instances() int

Instances returns the number of instances this counter is sharded across.

func (CounterInfo) Size

func (m CounterInfo) Size() int

Size returns the number of values each instance holds.

func (CounterInfo) Value

func (m CounterInfo) Value(instance int, idx int) uint64

Value returns one value of one instance.

type CounterSet

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

CounterSet indexes one batch of counters by name, all sharing the same instance count.

func NewCounterSet

func NewCounterSet(counters []CounterInfo) (*CounterSet, error)

NewCounterSet fails when the counters carry duplicate names or disagree on their instance count.

func (*CounterSet) Err

func (m *CounterSet) Err() error

Err reports every counter that could not be resolved, or nil when all of them resolved.

func (*CounterSet) Instances

func (m *CounterSet) Instances() int

Instances returns the instance count shared by every counter, or zero when the set is empty.

func (*CounterSet) Lookup

func (m *CounterSet) Lookup(name string, size int) MaybeCounter

Lookup names a counter and its required size; zero leaves the size unchecked.

type CounterTag

type CounterTag struct {
	Key   string
	Value string
}

CounterTag is a (key, value) predicate against a counter's tag set. Value semantics follow the C API: an empty string requires the tag to be absent, "*" requires the tag to be present with any value, and any other string requires an exact match.

type DPConfig

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

DPConfig represents a handle to dataplane configuration.

func NewDPConfigFromRaw

func NewDPConfigFromRaw(ptr unsafe.Pointer) *DPConfig

func (*DPConfig) Agents

func (m *DPConfig) Agents() []AgentInfo

Agents returns all agent information from the dataplane.

func (*DPConfig) AllModulePositions

func (m *DPConfig) AllModulePositions(moduleType string) iter.Seq[ModuleReference]

func (*DPConfig) CPConfigs

func (m *DPConfig) CPConfigs() []CPConfig

func (*DPConfig) ChainCounters

func (m *DPConfig) ChainCounters(
	deviceName string,
	pipelineName string,
	functionName string,
	chainName string,
) []CounterInfo

ChainCounters returns the chain's counters, or nil when the read fails.

func (*DPConfig) CountersByTags

func (m *DPConfig) CountersByTags(
	tags []CounterTag,
	query []string,
) ([]CounterGroup, error)

CountersByTags returns counters matching every predicate in tags and at least one pattern in query. A nil or empty tags slice imposes no per-tag constraint. A nil or empty query matches any counter name.

Every worker's counter storage registry is matched independently and the sets are merged: a counter is identified by its group's tag set and its name, and a worker that does not carry it contributes zero values for its instance. Every returned counter therefore spans exactly one value set per dataplane worker.

func (*DPConfig) DeviceCounters

func (m *DPConfig) DeviceCounters(deviceName string) []CounterInfo

DeviceCounters returns the device's counters, or nil when the read fails.

func (*DPConfig) Devices

func (m *DPConfig) Devices() []DeviceInfo

Devices returns all device information from the dataplane.

func (*DPConfig) FunctionCounters

func (m *DPConfig) FunctionCounters(
	deviceName string,
	pipelineName string,
	functionName string,
) []CounterInfo

FunctionCounters returns the function's counters, or nil when the read fails.

func (*DPConfig) Functions

func (m *DPConfig) Functions() []Function

Functions returns all functions configurations from the dataplane.

func (*DPConfig) ModuleCounters

func (m *DPConfig) ModuleCounters(
	deviceName string,
	pipelineName string,
	functionName string,
	chainName string,
	moduleType string,
	moduleName string,
	counterQuery []string,
) []CounterInfo

ModuleCounters returns the module's predefined counters, optionally filtered by name, or nil when the read fails.

If counterQuery is nil or empty, returns all counters, a refused one none. The module's per-rule counters live on runtime-kind storages; read them through ModuleRuntimeCounters.

func (*DPConfig) ModuleRuntimeCounters

func (m *DPConfig) ModuleRuntimeCounters(
	deviceName string,
	pipelineName string,
	functionName string,
	chainName string,
	moduleType string,
	moduleName string,
	counterQuery []string,
) ([]CounterInfo, error)

ModuleRuntimeCounters returns the module's runtime counters — those expanded from its named counter registries (per-route, per-rule, etc.) — optionally filtered by name.

If counterQuery is nil or empty, returns all runtime counters.

func (*DPConfig) Modules

func (m *DPConfig) Modules() []DPModule

Modules returns a list of dataplane modules available.

func (*DPConfig) NumaIdx

func (m *DPConfig) NumaIdx() uint32

func (*DPConfig) ObjectCounters

func (m *DPConfig) ObjectCounters(
	objectType string,
	objectName string,
) []CounterInfo

ObjectCounters returns the counters of an object identified by its type and name, or nil when the read fails.

func (*DPConfig) PipelineCounters

func (m *DPConfig) PipelineCounters(
	deviceName string,
	pipelineName string,
) []CounterInfo

PipelineCounters returns the pipeline's counters, or nil when the read fails.

func (*DPConfig) Pipelines

func (m *DPConfig) Pipelines() []Pipeline

Pipelines returns all pipeline configurations from the dataplane.

func (*DPConfig) PortCounters

func (m *DPConfig) PortCounters() ([]PortGroup, error)

func (*DPConfig) RawWorkerCounters

func (m *DPConfig) RawWorkerCounters() []CounterInfo

RawWorkerCounters returns the worker counters, or nil when they cannot be read.

The C API snapshots one worker at a time, so every worker is read separately and the per-worker snapshots are merged into one list spanning every worker: worker i's values land in instance slot i of each counter.

func (*DPConfig) WorkerCount

func (m *DPConfig) WorkerCount() uint32

func (*DPConfig) WorkerCounters

func (m *DPConfig) WorkerCounters() ([]WorkerCounter, error)

type DPModule

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

DPModule represents a dataplane module in the YANET configuration.

func (*DPModule) Name

func (m *DPModule) Name() string

Name returns the name of the dataplane module.

The module name uniquely identifies the module in the dataplane.

func (DPModule) String

func (m DPModule) String() string

String implements the Stringer interface for DPModule.

Used in "zap".

type DeviceConfig

type DeviceConfig struct {
	Name   string
	Input  []DevicePipelineConfig
	Output []DevicePipelineConfig
}

type DeviceInfo

type DeviceInfo struct {
	Type            string
	Name            string
	Index           uint32
	InputPipelines  []DevicePipelineInfo
	OutputPipelines []DevicePipelineInfo
}

DeviceInfo represents information about a device.

type DevicePipeline

type DevicePipeline struct {
	Name   string
	Weight uint64
}

type DevicePipelineConfig

type DevicePipelineConfig struct {
	Name   string
	Weight uint64
}

type DevicePipelineInfo

type DevicePipelineInfo struct {
	Name   string
	Weight uint64
}

DevicePipelineInfo represents information about a pipeline in a device.

type Function

type Function struct {
	Name   string
	Chains []Chain
}

type FunctionChainConfig

type FunctionChainConfig struct {
	Chain  ChainConfig
	Weight uint64
}

type FunctionConfig

type FunctionConfig struct {
	Name   string
	Chains []FunctionChainConfig
}

type MaybeCounter

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

MaybeCounter is a lookup that materializes once the caller chooses how absence is reported.

func (MaybeCounter) Require

func (m MaybeCounter) Require() CounterInfo

Require returns zero for an absent counter and records the miss.

type ModuleConfig

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

ModuleConfig is a Go wrapper around a C cp_module pointer, representing a module's shared memory configuration.

Each module package creates its own typed wrapper embedding ModuleConfig, using unsafe.Pointer as a bridge between CGo contexts of different packages.

func NewModuleConfig

func NewModuleConfig(ptr unsafe.Pointer) ModuleConfig

NewModuleConfig wraps a raw C pointer into a ModuleConfig.

The pointer must originate from a module-specific C constructor that returns a valid cp_module pointer. The caller is responsible for ensuring the pointer's validity and lifetime.

func (ModuleConfig) AsRawPtr

func (m ModuleConfig) AsRawPtr() unsafe.Pointer

AsRawPtr returns the underlying C pointer as unsafe.Pointer for passing across CGo package boundaries.

type ModuleReference

type ModuleReference struct {
	Device     string
	Pipeline   string
	Function   string
	Chain      string
	ModuleType string
	ModuleName string
}

type Pipeline

type Pipeline struct {
	// Name is the name of the pipeline.
	Name string
	// Functions is the list of functions in the pipeline
	Functions []string
}

Pipeline represents a dataplane packet processing pipeline configuration.

type PipelineConfig

type PipelineConfig struct {
	Name      string
	Functions []string
}

TODO: docs

type PortCounter

type PortCounter struct {
	Name  string
	Value uint64
}

type PortGroup

type PortGroup struct {
	PortID   uint16
	PortName string
	Counters []PortCounter
}

type SharedMemory

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

SharedMemory represents a handle to YANET shared memory segment.

func AttachSharedMemory

func AttachSharedMemory(path string) (*SharedMemory, error)

AttachSharedMemory attaches to YANET shared memory segment.

func NewSharedMemoryFromRaw

func NewSharedMemoryFromRaw(ptr unsafe.Pointer) *SharedMemory

NewSharedMemoryFromRaw wraps an opaque C shared-memory handle.

The pointer is the process-local handle the C API hands out, not the segment itself; it must only be used through the C API.

func (*SharedMemory) AgentAttach

func (m *SharedMemory) AgentAttach(
	name string,
	instanceIdx uint32,
	size datasize.ByteSize,
) (*Agent, error)

AgentAttach attaches a module agent to shared memory on the dataplane instance.

func (*SharedMemory) AsRawPtr

func (m *SharedMemory) AsRawPtr() unsafe.Pointer

AsRawPtr returns the opaque C shared-memory handle.

The pointer is the process-local handle, not the segment itself; it must only be used through the C API.

func (*SharedMemory) DPConfig

func (m *SharedMemory) DPConfig(instanceIdx uint32) *DPConfig

DPConfig gets configuration of the dataplane instance from shared memory.

func (*SharedMemory) DataplaneReady

func (m *SharedMemory) DataplaneReady(instanceIdx uint32) bool

DataplaneReady reports whether the dataplane instance has finished initializing its shared memory.

func (*SharedMemory) Detach

func (m *SharedMemory) Detach() error

Detach detaches from YANET shared memory segment.

Every agent attached to the segment must be closed before detaching, because the mapping is unmapped and a later agent operation would fault. The mapping length travels inside the handle, so detaching works at any point after a successful attach, including before the dataplane has written the segment header. The handle is consumed whatever the outcome, so a second call is a no-op.

type ShmDeviceConfig

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

ShmDeviceConfig is a Go wrapper around a C cp_device pointer, representing a device's shared memory configuration.

Device packages (plain, vlan) create their own typed wrappers embedding ShmDeviceConfig.

func NewShmDeviceConfig

func NewShmDeviceConfig(ptr unsafe.Pointer) ShmDeviceConfig

NewShmDeviceConfig wraps a raw C pointer into a ShmDeviceConfig.

The pointer must originate from a device-specific C constructor (e.g. cp_device_plain_new). The caller is responsible for ensuring the pointer's validity and lifetime.

func (ShmDeviceConfig) AsRawPtr

func (m ShmDeviceConfig) AsRawPtr() unsafe.Pointer

AsRawPtr returns the underlying C pointer as unsafe.Pointer for passing across CGo package boundaries.

type WorkerCounter

type WorkerCounter struct {
	WorkerIdx       uint32
	CoreID          uint32
	DeviceID        uint32
	QueueID         uint32
	MaxBurstSize    uint32
	RxBursts        []uint64
	Iterations      uint64
	RxPackets       uint64
	RxBytes         uint64
	TxPackets       uint64
	TxBytes         uint64
	RemoteRxPackets uint64
	RemoteTxPackets uint64
	LocalTxDrops    uint64
	RemoteTxDrops   uint64
	Disposed        uint64
}

Jump to

Keyboard shortcuts

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