This patch adds a new configuation option that enables transparent
clock mode.  When TC mode is specified, the configured delay mechanism
must also match.  The legacy behavior of upgrading a multi-port clock
from OC to BC is preserved.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 config.c    | 10 ++++++++++
 default.cfg |  1 +
 gPTP.cfg    |  1 +
 ptp4l.8     | 15 +++++++++++----
 ptp4l.c     | 44 +++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/config.c b/config.c
index 320cc1b..ba1e59b 100644
--- a/config.c
+++ b/config.c
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "clock.h"
 #include "config.h"
 #include "ether.h"
 #include "hash.h"
@@ -133,6 +134,14 @@ static struct config_enum clock_servo_enu[] = {
        { NULL, 0 },
 };
 
+static struct config_enum clock_type_enu[] = {
+       { "OC",      CLOCK_TYPE_ORDINARY },
+       { "BC",      CLOCK_TYPE_BOUNDARY },
+       { "P2P_TC",  CLOCK_TYPE_P2P      },
+       { "E2E_TC",  CLOCK_TYPE_E2E      },
+       { NULL, 0 },
+};
+
 static struct config_enum delay_filter_enu[] = {
        { "moving_average", FILTER_MOVING_AVERAGE },
        { "moving_median",  FILTER_MOVING_MEDIAN  },
@@ -178,6 +187,7 @@ struct config_item config_tab[] = {
        GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
        GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
        GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
+       GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu),
        PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
        PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
        PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
diff --git a/default.cfg b/default.cfg
index e76aeae..3b7743e 100644
--- a/default.cfg
+++ b/default.cfg
@@ -71,6 +71,7 @@ uds_address           /var/run/ptp4l
 #
 # Default interface options
 #
+clock_type             OC
 network_transport      UDPv4
 delay_mechanism                E2E
 time_stamping          hardware
diff --git a/gPTP.cfg b/gPTP.cfg
index 1e7a33e..9f17377 100644
--- a/gPTP.cfg
+++ b/gPTP.cfg
@@ -67,6 +67,7 @@ uds_address           /var/run/ptp4l
 #
 # Default interface options
 #
+clock_type             OC
 network_transport      L2
 delay_mechanism                P2P
 time_stamping          hardware
diff --git a/ptp4l.8 b/ptp4l.8
index 950e07c..87b3a02 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -1,6 +1,6 @@
-.TH PTP4l 8 "Novemver 2017" "linuxptp"
+.TH PTP4l 8 "March 2018" "linuxptp"
 .SH NAME
-ptp4l - PTP Boundary/Ordinary Clock
+ptp4l - PTP Boundary/Ordinary/Transparent Clock
 
 .SH SYNOPSIS
 .B ptp4l
@@ -23,8 +23,8 @@ ptp4l - PTP Boundary/Ordinary Clock
 .SH DESCRIPTION
 .B ptp4l
 is an implementation of the Precision Time Protocol (PTP) according to IEEE
-standard 1588 for Linux. It implements Boundary Clock (BC) and Ordinary Clock
-(OC).
+standard 1588 for Linux. It implements Boundary Clock (BC), Ordinary Clock
+(OC), and Transparent Clock (TC).
 
 .SH OPTIONS
 .TP
@@ -389,6 +389,13 @@ number is set to the domain number), and "nullf" for a 
servo that
 always dials frequency offset zero (for use in SyncE nodes).
 The default is "pi."
 .TP
+.B clock_type
+Specifies the kind of PTP clock.  Valid values are "OC" for ordinary
+clock, "BC" for boundary clock, "P2P_TC" for peer to peer transparent
+clock, and "E2E_TC" for end to end transparent clock.  An multi-port
+ordinary clock will automatically be configured as a boundary clock.
+The default is "OC".
+.TP
 .B pi_proportional_const
 The proportional constant of the PI controller. When set to 0.0, the
 proportional constant will be set by the following formula from the current
diff --git a/ptp4l.c b/ptp4l.c
index ee31718..9ef8169 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -1,6 +1,6 @@
 /**
  * @file ptp4l.c
- * @brief PTP Boundary Clock main program
+ * @brief PTP Boundary Clock or Transparent Clock main program
  * @note Copyright (C) 2011 Richard Cochran <richardcoch...@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -59,6 +59,7 @@ static void usage(char *progname)
                " -p [dev]  PTP hardware clock device to use, default auto\n"
                "           (ignored for SOFTWARE/LEGACY HW time stamping)\n"
                " -s        slave only mode (overrides configuration file)\n"
+               " -t        transparent clock\n"
                " -l [num]  set the logging level to 'num'\n"
                " -m        print messages to stdout\n"
                " -q        do not print messages to the syslog\n"
@@ -71,6 +72,7 @@ static void usage(char *progname)
 int main(int argc, char *argv[])
 {
        char *config = NULL, *req_phc = NULL, *progname;
+       enum clock_type type = CLOCK_TYPE_ORDINARY;
        int c, err = -1, index, print_level;
        struct clock *clock = NULL;
        struct option *opts;
@@ -201,8 +203,44 @@ int main(int argc, char *argv[])
                goto out;
        }
 
-       clock = clock_create(cfg->n_interfaces > 1 ? CLOCK_TYPE_BOUNDARY :
-                            CLOCK_TYPE_ORDINARY, cfg, req_phc);
+       type = config_get_int(cfg, NULL, "clock_type");
+       switch (type) {
+       case CLOCK_TYPE_ORDINARY:
+               if (cfg->n_interfaces > 1) {
+                       type = CLOCK_TYPE_BOUNDARY;
+               }
+               break;
+       case CLOCK_TYPE_BOUNDARY:
+               if (cfg->n_interfaces < 2) {
+                       fprintf(stderr, "BC needs at least two interfaces\n");
+                       goto out;
+               }
+               break;
+       case CLOCK_TYPE_P2P:
+               if (cfg->n_interfaces < 2) {
+                       fprintf(stderr, "TC needs at least two interfaces\n");
+                       goto out;
+               }
+               if (DM_P2P != config_get_int(cfg, NULL, "delay_mechanism")) {
+                       fprintf(stderr, "P2P_TC needs P2P delay mechanism\n");
+                       goto out;
+               }
+               break;
+       case CLOCK_TYPE_E2E:
+               if (cfg->n_interfaces < 2) {
+                       fprintf(stderr, "TC needs at least two interfaces\n");
+                       goto out;
+               }
+               if (DM_E2E != config_get_int(cfg, NULL, "delay_mechanism")) {
+                       fprintf(stderr, "E2E_TC needs E2E delay mechanism\n");
+                       goto out;
+               }
+               break;
+       case CLOCK_TYPE_MANAGEMENT:
+               goto out;
+       }
+
+       clock = clock_create(type, cfg, req_phc);
        if (!clock) {
                fprintf(stderr, "failed to create a clock\n");
                goto out;
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to