core

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 4 Imported by: 35

Documentation

Overview

Package core contains some generic helper functions for the package github.com/florianl/go-tc. Depending on the actual hardware in use, parameters to filters and qdiscs can vary to achieve the same behaviour.

If PROC_ROOT is set it will be used to lookup packet scheduler information from net/psched.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHandle

func BuildHandle(maj, min uint32) uint32

BuildHandle is a simple helper function to construct the handle for the Tcmsg struct

func Duration2TcTime added in v0.4.2

func Duration2TcTime(d time.Duration) (uint32, error)

Duration2TcTime implements iproute2/tc/q_netem.c:get_ticks(). It converts a given duration into a time value that can be converted to ticks with Time2Tick(). On error it returns syscall.EINVAL.

func FilterInfo added in v0.4.5

func FilterInfo(priority uint16, protocol uint16) uint32

FilterInfo is a simple helper to set the priority and protocol of the filter

func GetClockFactor added in v0.4.7

func GetClockFactor() float64

GetClockFactor returns the current clock factor value.

func GetTickInUSec added in v0.4.7

func GetTickInUSec() float64

GetTickInUSec returns the current tick in microseconds conversion factor.

func InitializeClock added in v0.4.7

func InitializeClock() error

InitializeClock initializes the clock parameters by reading from /proc/net/psched on Linux. On non-Linux platforms, it sets default values (1.0 for both parameters). This function must be called before using any of the timing functions. It returns an error if the clock parameters cannot be read on Linux.

Example

ExampleInitializeClock demonstrates the clock initialization API

// Initialize clock parameters
if err := InitializeClock(); err != nil {
	fmt.Printf("Warning: failed to initialize clock: %v\n", err)
	// You can optionally set fallback values if initialization fails
	SetClockParameters(1.0, 1.0)
}

// Set known values for predictable output
SetClockParameters(1.0, 1.0)

// Now you can use timing functions
ticks := Time2Tick(1000)
fmt.Printf("Time2Tick(1000) = %d\n", ticks)

// You can also get the current clock parameters
clockFactor := GetClockFactor()
tickInUSec := GetTickInUSec()
fmt.Printf("Clock Factor: %.1f, Tick in µs: %.1f\n", clockFactor, tickInUSec)
Output:
Time2Tick(1000) = 1000
Clock Factor: 1.0, Tick in µs: 1.0

func IsClockInitialized added in v0.4.7

func IsClockInitialized() bool

IsClockInitialized returns true if the clock parameters have been initialized.

func Ktime2Time

func Ktime2Time(ktime uint32) uint32

Ktime2Time implements iproute2/tc/tc_core:tc_core_ktime2time().

func SetClockParameters added in v0.4.7

func SetClockParameters(newClockFactor, newTickInUSec float64)

SetClockParameters allows manual configuration of the clock parameters. This is useful for testing or when custom clock values are needed. clockFactor is the clock resolution factor, tickInUSec is the tick to microsecond conversion factor.

func SplitHandle

func SplitHandle(handle uint32) (major, minor uint32)

SplitHandle extracts the major and minor part from a given handle

func Tick2Time

func Tick2Time(tick uint32) uint32

Tick2Time implements iproute2/tc/tc_core:tc_core_tick2time(). It returns a time in usec for a given number of CPU ticks.

func Time2Ktime

func Time2Ktime(time uint32) uint32

Time2Ktime implements iproute2/tc/tc_core:tc_core_time2ktime().

func Time2Tick

func Time2Tick(time uint32) uint32

Time2Tick implements iproute2/tc/tc_core:tc_core_time2tick(). It returns the number of CPU ticks for a given time in usec.

func XmitSize

func XmitSize(rate uint64, ticks uint32) uint32

XmitSize implements iproute2/tc/tc_core:tc_calc_xmitsize(). It returns the size that can be transmitted at a given rate during a given time.

func XmitTime

func XmitTime(rate uint64, size uint32) uint32

XmitTime implements iproute2/tc/tc_core:tc_calc_xmittime(). It returns the time, that is needed to transmit a given size for a given rate.

Types

This section is empty.

Jump to

Keyboard shortcuts

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