Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail measurement if oscillatord is unavailable #321

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions ptp/c4u/c4u.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,18 @@ func Run(config *Config, rb *clock.RingBuffer, st stats.Stats) error {
log.Errorf("Failed to collect clock data: %v", err)
dataError = true
}
// To avoid stale data always continue to fill the ring buffer
// even with nil values

// If DP is missing - assume the worst
if dp == nil {
dp = &clock.DataPoint{
OscillatorClockClass: clock.ClockClassUncalibrated,
}
}

rb.Write(dp)
// stats
if dp != nil {
st.SetPHCOffsetNS(int64(dp.PHCOffset))
st.SetOscillatorOffsetNS(int64(dp.OscillatorOffset))
} else {
st.SetPHCOffsetNS(0)
st.SetOscillatorOffsetNS(0)
}
st.SetPHCOffsetNS(int64(dp.PHCOffset))
st.SetOscillatorOffsetNS(int64(dp.OscillatorOffset))

w, err := clock.Worst(rb.Data(), config.AccuracyExpr, config.ClassExpr)
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions ptp/c4u/c4u_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,49 @@ func TestRun(t *testing.T) {
require.Equal(t, expected, dc)
}

func TestRunNilDatapoint(t *testing.T) {
// We don't really care about UTCOffset here - just to be the same result as in c4u.Run()
utcoffset, _ := utcoffset.Run()

expected := &server.DynamicConfig{
ClockClass: ptp.ClockClass52,
ClockAccuracy: 254,
DrainInterval: 30 * time.Second,
MaxSubDuration: 1 * time.Hour,
MetricInterval: 1 * time.Minute,
MinSubInterval: 1 * time.Second,
UTCOffset: utcoffset,
}

cfg, err := os.CreateTemp("", "c4u")
require.NoError(t, err)
defer os.Remove(cfg.Name())

c := &Config{
Path: cfg.Name(),
Sample: 3,
Apply: true,
AccuracyExpr: "1",
ClassExpr: "p99(oscillatorclass)",
}

st := stats.NewJSONStats()
rb := clock.NewRingBuffer(2)
dp := &clock.DataPoint{
PHCOffset: time.Microsecond,
OscillatorOffset: time.Microsecond,
OscillatorClockClass: clock.ClockClassHoldover,
}
rb.Write(dp)
err = Run(c, rb, st)
require.NoError(t, err)

dc, err := server.ReadDynamicConfig(c.Path)
require.NoError(t, err)
// must make sure nil entry results in ClockClass = 52
require.Equal(t, expected, dc)
}

func TestEvaluateClockQuality(t *testing.T) {
c := &Config{
LockBaseLine: ptp.ClockAccuracyMicrosecond1,
Expand Down
2 changes: 1 addition & 1 deletion ptp/c4u/clock/oscillatord.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func oscillatord() (*oscillatorState, error) {
}
defer conn.Close()
deadline := time.Now().Add(timeout)
if err := conn.SetDeadline(deadline); err != nil {
if err = conn.SetDeadline(deadline); err != nil {
return nil, err
}

Expand Down