client

package
v0.0.0-...-3e45774 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilterNone   = ""
	FilterMedian = "median"
	FilterMean   = "mean"
)

Supported path delay filters

Variables

This section is empty.

Functions

func LookupNetIP

func LookupNetIP(addr string) (netip.Addr, error)

LookupNetIP returns netip.Addr from addr string, which can be either IP or hostname

func ReqAnnounce

func ReqAnnounce(clockID ptp.ClockIdentity, portID uint16, ts time.Time) *ptp.Announce

ReqAnnounce is a helper to build ptp.Announce It's used for external pingers such as ptping and not required for sptp itself

func ReqDelay

func ReqDelay(clockID ptp.ClockIdentity, portID uint16) *ptp.SyncDelayReq

ReqDelay is a helper to build ptp.SyncDelayReq

Types

type BackoffConfig

type BackoffConfig struct {
	Mode     string
	Step     int
	MaxValue int
}

BackoffConfig describes configuration for backoff in case of unavailable GM

func (*BackoffConfig) Validate

func (c *BackoffConfig) Validate() error

Validate BackoffConfig is sane

type Client

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

Client is a part of PTPNG that talks to only one server

func NewClient

func NewClient(target netip.Addr, targetPort int, clockID ptp.ClockIdentity, eventConn UDPConnWithTS, cfg *Config, stats StatsServer) (*Client, error)

NewClient initializes sptp client

func (*Client) RunOnce

func (c *Client) RunOnce(ctx context.Context, timeout time.Duration) *RunResult

RunOnce produces one client-server exchange

func (*Client) SendAnnounce

func (c *Client) SendAnnounce(p *ptp.Announce) (uint16, error)

SendAnnounce sends an announce message via event socket It's used for external pingers such as ptping and not required for sptp itself

func (*Client) SendEventMsg

func (c *Client) SendEventMsg(p *ptp.SyncDelayReq) (uint16, time.Time, error)

SendEventMsg sends an event message via event socket

type Clock

type Clock interface {
	AdjFreqPPB(freq float64) error
	Step(step time.Duration) error
	FrequencyPPB() (float64, error)
	MaxFreqPPB() (float64, error)
	SetSync() error
}

Clock is the iface for clock device controls

type Config

type Config struct {
	Iface                    string
	Timestamping             timestamp.Timestamp
	MonitoringPort           int
	Interval                 time.Duration
	ExchangeTimeout          time.Duration
	DSCP                     int
	FirstStepThreshold       time.Duration
	Servers                  map[string]int
	MaxClockClass            ptp.ClockClass
	MaxClockAccuracy         ptp.ClockAccuracy
	Measurement              MeasurementConfig
	MetricsAggregationWindow time.Duration
	AttemptsTXTS             int
	TimeoutTXTS              time.Duration
	FreeRunning              bool
	Backoff                  BackoffConfig
	SequenceIDMaskBits       uint
	SequenceIDMaskValue      uint
	ParallelTX               bool
	ListenAddress            string
}

Config specifies SPTP run options

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns Config initialized with default values

func PrepareConfig

func PrepareConfig(cfgPath string, targets []string, iface string, monitoringPort int, interval time.Duration, dscp int) (*Config, error)

PrepareConfig prepares final version of config based on defaults, CLI flags and on-disk config, and validates resulting config

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads config from the file

func (*Config) GenerateMaskAndValue

func (c *Config) GenerateMaskAndValue() (uint16, uint16)

GenerateMaskAndValue returns the mask that must be applied to sequence id and the constant value to use

func (*Config) Validate

func (c *Config) Validate() error

Validate config is sane

type FreeRunningClock

type FreeRunningClock struct{}

FreeRunningClock is a dummy clock that does nothing

func (*FreeRunningClock) AdjFreqPPB

func (c *FreeRunningClock) AdjFreqPPB(_ float64) error

AdjFreqPPB adjusts PHC frequency

func (*FreeRunningClock) FrequencyPPB

func (c *FreeRunningClock) FrequencyPPB() (float64, error)

FrequencyPPB returns current PHC frequency

func (*FreeRunningClock) MaxFreqPPB

func (c *FreeRunningClock) MaxFreqPPB() (float64, error)

MaxFreqPPB returns maximum frequency adjustment supported by PHC

func (*FreeRunningClock) SetSync

func (c *FreeRunningClock) SetSync() error

SetSync sets clock status to TIME_OK

func (*FreeRunningClock) Step

func (c *FreeRunningClock) Step(_ time.Duration) error

Step jumps time on PHC

type JSONStats

type JSONStats struct {
	*Stats
}

JSONStats is what we want to report as stats via http

func NewJSONStats

func NewJSONStats() (*JSONStats, error)

NewJSONStats returns a new JSONStats

func (JSONStats) Start

func (s JSONStats) Start(monitoringport int, interval time.Duration)

Start runs http server and initializes maps

type MeasurementConfig

type MeasurementConfig struct {
	PathDelayFilterLength         int           `yaml:"path_delay_filter_length"`          // over how many last path delays we filter
	PathDelayFilter               string        `yaml:"path_delay_filter"`                 // which filter to use, see supported path delay filters const
	PathDelayDiscardFilterEnabled bool          `yaml:"path_delay_discard_filter_enabled"` // controls filter that allows us to discard anomalously small path delays
	PathDelayDiscardBelow         time.Duration `yaml:"path_delay_discard_below"`          // discard path delays that are below this threshold
	PathDelayDiscardFrom          time.Duration `yaml:"path_delay_discard_from"`           // do not apply discard filter to the values below this threshold
	PathDelayDiscardMultiplier    int           `yaml:"path_delay_discard_multiplier"`     // discard path delays that are above path delay multiplied by this value
}

MeasurementConfig describes configuration for how we measure offset

func (*MeasurementConfig) Validate

func (c *MeasurementConfig) Validate() error

Validate MeasurementConfig is sane

type MeasurementResult

type MeasurementResult struct {
	Delay             time.Duration
	Offset            time.Duration
	S2CDelay          time.Duration
	C2SDelay          time.Duration
	CorrectionFieldRX time.Duration
	CorrectionFieldTX time.Duration
	Timestamp         time.Time
	Announce          ptp.Announce
	T1                time.Time
	T2                time.Time
	T3                time.Time
	T4                time.Time
	BadDelay          bool
}

MeasurementResult is a single measured datapoint

type PHC

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

PHC groups methods for interactions with PHC devices

func NewPHC

func NewPHC(iface string) (*PHC, error)

NewPHC creates new PHC device abstraction from network interface name

func (*PHC) AdjFreqPPB

func (p *PHC) AdjFreqPPB(freqPPB float64) error

AdjFreqPPB adjusts PHC frequency

func (*PHC) FrequencyPPB

func (p *PHC) FrequencyPPB() (float64, error)

FrequencyPPB returns current PHC frequency

func (*PHC) MaxFreqPPB

func (p *PHC) MaxFreqPPB() (float64, error)

MaxFreqPPB returns maximum frequency adjustment supported by PHC

func (*PHC) SetSync

func (p *PHC) SetSync() error

SetSync is a no-op for PHC

func (*PHC) Step

func (p *PHC) Step(step time.Duration) error

Step jumps time on PHC

type RunResult

type RunResult struct {
	Server      netip.Addr
	Measurement *MeasurementResult
	Error       error
}

RunResult is what we return from single client-server interaction

type SPTP

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

SPTP is a Simple Unicast PTP client

func NewSPTP

func NewSPTP(cfg *Config, stats StatsServer) (*SPTP, error)

NewSPTP creates SPTP client

func (*SPTP) Run

func (p *SPTP) Run(ctx context.Context) error

Run makes things run, continuously

func (*SPTP) RunListener

func (p *SPTP) RunListener(ctx context.Context) error

RunListener starts a listener, must be run before any client-server interactions happen

type Servo

type Servo interface {
	SyncInterval(float64)
	Sample(offset int64, localTs uint64) (float64, servo.State)
	SetMaxFreq(float64)
	SetLastFreq(float64)
	MeanFreq() float64
	IsSpike(offset int64) bool
	GetState() servo.State
	UnsetFirstUpdate()
}

Servo abstracts away servo

type Stats

type Stats struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Stats is an implementation of

func NewStats

func NewStats() (*Stats, error)

NewStats created new instance of Stats

func (*Stats) CollectSysStats

func (s *Stats) CollectSysStats()

CollectSysStats gathers cpu, mem, gc statistics

func (*Stats) GetCounters

func (s *Stats) GetCounters() map[string]int64

GetCounters returns an map of counters

func (*Stats) GetGMStats

func (s *Stats) GetGMStats() gmstats.Stats

GetGMStats returns an all gm stats

func (*Stats) IncFiltered

func (s *Stats) IncFiltered()

IncFiltered atomically adds 1 to the rxsync

func (*Stats) IncRXAnnounce

func (s *Stats) IncRXAnnounce()

IncRXAnnounce atomically adds 1 to the rxAnnounce

func (*Stats) IncRXDelayReq

func (s *Stats) IncRXDelayReq()

IncRXDelayReq atomically adds 1 to the rxDelayReq

func (*Stats) IncRXSync

func (s *Stats) IncRXSync()

IncRXSync atomically adds 1 to the rxsync

func (*Stats) IncTXDelayReq

func (s *Stats) IncTXDelayReq()

IncTXDelayReq atomically adds 1 to the txDelayReq

func (*Stats) IncUnsupported

func (s *Stats) IncUnsupported()

IncUnsupported atomically adds 1 to the unsupported

func (*Stats) SetGMStats

func (s *Stats) SetGMStats(stat *gmstats.Stat)

SetGMStats sets GM stats for particular gm

func (*Stats) SetGmsAvailable

func (s *Stats) SetGmsAvailable(gmsAvailable int)

SetGmsAvailable atomically sets the gmsTotal

func (*Stats) SetGmsTotal

func (s *Stats) SetGmsTotal(gmsTotal int)

SetGmsTotal atomically sets the gmsTotal

func (*Stats) SetServoState

func (s *Stats) SetServoState(state int)

SetServoState atomically sets the servoState

func (*Stats) SetTickDuration

func (s *Stats) SetTickDuration(tickDuration time.Duration)

SetTickDuration atomically sets the gmsTotal

type StatsServer

type StatsServer interface {
	SetGmsTotal(gmsTotal int)
	SetGmsAvailable(gmsAvailable int)
	SetTickDuration(tickDuration time.Duration)
	SetServoState(state int)
	IncFiltered()
	IncRXSync()
	IncRXAnnounce()
	IncRXDelayReq()
	IncTXDelayReq()
	IncUnsupported()
	SetGMStats(stat *gmstats.Stat)
	CollectSysStats()
}

StatsServer is a stats server interface

type SysClock

type SysClock struct{}

SysClock groups methods for interacting with system clock

func (*SysClock) AdjFreqPPB

func (c *SysClock) AdjFreqPPB(freqPPB float64) error

AdjFreqPPB adjusts PHC frequency

func (*SysClock) FrequencyPPB

func (c *SysClock) FrequencyPPB() (float64, error)

FrequencyPPB returns current PHC frequency

func (*SysClock) MaxFreqPPB

func (c *SysClock) MaxFreqPPB() (float64, error)

MaxFreqPPB returns maximum frequency adjustment supported by PHC

func (*SysClock) SetSync

func (c *SysClock) SetSync() error

SetSync sets clock status to TIME_OK

func (*SysClock) Step

func (c *SysClock) Step(step time.Duration) error

Step jumps time on PHC

type UDPConn

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

UDPConn is a wrapper around udp connection and a corresponding fd

func NewUDPConn

func NewUDPConn(address net.IP, port int) (*UDPConn, error)

NewUDPConn initialises a new struct UDPConn

func (*UDPConn) Close

func (c *UDPConn) Close() error

Close closes underlying fd

func (*UDPConn) ReadPacketBuf

func (c *UDPConn) ReadPacketBuf(buf []byte) (int, netip.Addr, error)

ReadPacketBuf reads bytes from underlying fd

func (*UDPConn) WriteTo

func (c *UDPConn) WriteTo(b []byte, addr unix.Sockaddr) (int, error)

WriteTo writes bytes to addr via underlying UDPConn

type UDPConnNoTS

type UDPConnNoTS interface {
	WriteTo(b []byte, addr unix.Sockaddr) (int, error)
	ReadPacketBuf(buf []byte) (int, netip.Addr, error)
	Close() error
}

UDPConnNoTS describes what functionality we expect from UDP connection

type UDPConnTS

type UDPConnTS struct {
	UDPConn
	// contains filtered or unexported fields
}

UDPConnTS is a wrapper around udp connection and a corresponding fd

func NewUDPConnTS

func NewUDPConnTS(address net.IP, port int, ts timestamp.Timestamp, iface string, dscpValue int) (*UDPConnTS, error)

NewUDPConnTS initialises a new struct UDPConnTS

func (*UDPConnTS) ReadPacketWithRXTimestampBuf

func (c *UDPConnTS) ReadPacketWithRXTimestampBuf(buf, oob []byte) (int, unix.Sockaddr, time.Time, error)

ReadPacketWithRXTimestampBuf reads bytes and a timestamp from underlying fd

func (*UDPConnTS) WriteToWithTS

func (c *UDPConnTS) WriteToWithTS(b []byte, addr unix.Sockaddr) (int, time.Time, error)

WriteToWithTS writes bytes to addr via underlying UDPConn

type UDPConnWithTS

type UDPConnWithTS interface {
	WriteToWithTS(b []byte, addr unix.Sockaddr) (int, time.Time, error)
	ReadPacketWithRXTimestampBuf(buf, oob []byte) (int, unix.Sockaddr, time.Time, error)
	Close() error
}

UDPConnWithTS describes what functionality we expect from UDP connection that allows us to read TX timestamps

Jump to

Keyboard shortcuts

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