client

package
v0.0.0-...-1e06781 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 30 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 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 string, 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) SendEventMsg

func (c *Client) SendEventMsg(p ptp.Packet) (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
}

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 InPacket

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

InPacket is input packet data + receive timestamp

func NewInPacket

func NewInPacket(data []byte, ts time.Time) *InPacket

NewInPacket returns a new instance of InPacket

func (*InPacket) Data

func (i *InPacket) Data() []byte

Data returns data

func (*InPacket) TS

func (i *InPacket) TS() time.Time

TS returns timestamp

type JSONStats

type JSONStats struct {
	Stats
}

JSONStats is what we want to report as stats via http

func NewJSONStats

func NewJSONStats() *JSONStats

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
	PathDelayDiscardAbove         time.Duration `yaml:"path_delay_discard_above"`          // discard path delays that are above this threshold
}

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
}

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(freq 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      string
	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
}

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

NewStats created new instance of Stats

func (*Stats) CollectSysStats

func (s *Stats) CollectSysStats() error

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) 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) 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)
	IncRXSync()
	IncRXAnnounce()
	IncRXDelayReq()
	IncTXDelayReq()
	IncUnsupported()
	SetGMStats(stat *gmstats.Stat)
	CollectSysStats() error
}

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 interface {
	ReadFromUDP(b []byte) (int, *net.UDPAddr, error)
	WriteTo(b []byte, addr net.Addr) (int, error)
	Close() error
}

UDPConn describes what functionality we expect from UDP connection

type UDPConnTS

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

UDPConnTS is a wrapper around udp connection and a corresponding fd

func NewUDPConnTS

func NewUDPConnTS(conn *net.UDPConn, connFd int) *UDPConnTS

NewUDPConnTS initialises a new struct UDPConnTS

func (*UDPConnTS) ReadPacketWithRXTimestamp

func (c *UDPConnTS) ReadPacketWithRXTimestamp() ([]byte, unix.Sockaddr, time.Time, error)

ReadPacketWithRXTimestamp reads bytes and a timestamp from underlying fd

func (*UDPConnTS) WriteToWithTS

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

WriteToWithTS writes bytes to addr via underlying UDPConn

type UDPConnWithTS

type UDPConnWithTS interface {
	UDPConn
	WriteToWithTS(b []byte, addr net.Addr) (int, time.Time, error)
	ReadPacketWithRXTimestamp() ([]byte, unix.Sockaddr, time.Time, 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