From eed8ed05c84cbdbcaa1b9a7f51008bbfd8eb871c Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Fri, 27 Jul 2012 22:34:34 +0200 Subject: [PATCH] Add an option to assume two step messaging. Some commercial 802.1AS switches do not feel obliged to set the two step flag. When we try to synchronize to their apparent one step sync messages, nothing good happens. This commit adds a global option to work around the issue. Signed-off-by: Richard Cochran --- config.c | 4 ++++ config.h | 1 + msg.h | 7 +++++++ ptp4l.c | 2 ++ 4 files changed, 14 insertions(+) diff --git a/config.c b/config.c index 08e29a2..b8f2bdb 100644 --- a/config.c +++ b/config.c @@ -91,6 +91,10 @@ static void scan_line(char *s, struct config *cfg) pod->transportSpecific = u8 << 4; + } else if (1 == sscanf(s, " assume_two_step %u", &val)) { + + *cfg->assume_two_step = val ? 1 : 0; + } else if (1 == sscanf(s, " tx_timestamp_retries %u", &val)) { if (val > 0) diff --git a/config.h b/config.h index 8fde9c1..fb22341 100644 --- a/config.h +++ b/config.h @@ -25,6 +25,7 @@ struct config { struct defaultDS *dds; struct port_defaults *pod; + int *assume_two_step; int *tx_timestamp_retries; int *rx_timestamp_l2only; double *pi_proportional_const; diff --git a/msg.h b/msg.h index f479e9c..d737ee2 100644 --- a/msg.h +++ b/msg.h @@ -284,6 +284,11 @@ void msg_put(struct ptp_message *m); */ int msg_sots_missing(struct ptp_message *m); +/** + * Work around buggy 802.1AS switches. + */ +extern int assume_two_step; + /** * Test whether a message is one-step message. * @param m Message to test. @@ -291,6 +296,8 @@ int msg_sots_missing(struct ptp_message *m); */ static inline Boolean one_step(struct ptp_message *m) { + if (assume_two_step) + return 0; return !field_is_set(m, 0, TWO_STEP); } diff --git a/ptp4l.c b/ptp4l.c index 52ba480..deadf62 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -30,6 +30,7 @@ #define DEFAULT_PHC "/dev/ptp0" +int assume_two_step; int sk_tx_retries = 2, sk_prefer_layer2 = 0; /*see sk.c*/ double configured_pi_kp, configured_pi_ki; /*see pi.c*/ extern unsigned char ptp_dst_mac[]; /*see raw.c*/ @@ -219,6 +220,7 @@ int main(int argc, char *argv[]) cfg_settings.dds = &ds; cfg_settings.pod = &pod; + cfg_settings.assume_two_step = &assume_two_step; cfg_settings.tx_timestamp_retries = &sk_tx_retries; cfg_settings.rx_timestamp_l2only = &sk_prefer_layer2; cfg_settings.pi_proportional_const = &configured_pi_kp;