From c7d43d84e8bc679b7abcbe7ebe98ea45dfe292cf Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 25 Nov 2021 20:43:51 +0000 Subject: [PATCH] Allow up to 10 ms of negative jitter to be accepted. At the start, give extra weight to positive jitter as more likely to be a real thing. --- nqptp-clock-sources.h | 4 ++-- nqptp-message-handlers.c | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index 0094f3c..4d9a853 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -41,8 +41,8 @@ typedef struct { // information about each clock source typedef struct { - char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46) - int family; // AF_INET or AF_INET6 + char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46) + int family; // AF_INET or AF_INET6 int follow_up_number; int announcements_without_followups; // add 1 for every announce, reset with a followup uint64_t clock_id; diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 87cd6c4..1dd1560 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -232,7 +232,6 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf; - uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]); uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]); uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]); @@ -374,12 +373,14 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, jitter = offset - clock_private_info->previous_offset; - if (jitter > -10000000) { + if (jitter > -10000000) { // we take any positive or a limited negative jitter as a sync event if (jitter < 0) - offset = clock_private_info->previous_offset + jitter/32; + offset = clock_private_info->previous_offset + jitter / 32; + else if (clock_private_info->follow_up_number < (5 * 8)) // at the beginning... + offset = clock_private_info->previous_offset + jitter / 4; else - offset = clock_private_info->previous_offset + jitter/32; + offset = clock_private_info->previous_offset + jitter / 32; clock_private_info->last_sync_time = reception_time; } else { offset = clock_private_info->previous_offset; // forget the present sample... @@ -399,7 +400,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, clock_private_info->previous_offset_time = reception_time; if ((clock_private_info->flags & (1 << clock_is_master)) != 0) { - + update_master_clock_info(clock_private_info->clock_id, (const char *)&clock_private_info->ip, reception_time, offset, clock_private_info->mastership_start_time); debug(3, "clock: %" PRIx64 ", time: %" PRIu64 ", offset: %" PRId64 ", jitter: %+f ms.", -- 2.47.2