This patch adds a new flag '-t' that enables transparent clock mode.  When
active, the clock will be created as an E2E or P2P TC, depending on the
configured delay mechanism.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 ptp4l.c | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/ptp4l.c b/ptp4l.c
index a87e7e6..f700499 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
@@ -61,6 +61,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"
@@ -73,6 +74,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, print_level;
        struct clock *clock = NULL;
        struct config *cfg;
@@ -88,7 +90,7 @@ int main(int argc, char *argv[])
        /* Process the command line arguments. */
        progname = strrchr(argv[0], '/');
        progname = progname ? 1+progname : argv[0];
-       while (EOF != (c = getopt(argc, argv, "AEP246HSLf:i:p:sl:mqvh"))) {
+       while (EOF != (c = getopt(argc, argv, "AEP246HSLf:i:p:stl:mqvh"))) {
                switch (c) {
                case 'A':
                        if (config_set_int(cfg, "delay_mechanism", DM_AUTO))
@@ -144,6 +146,9 @@ int main(int argc, char *argv[])
                                goto out;
                        }
                        break;
+               case 't':
+                       type = CLOCK_TYPE_E2E;
+                       break;
                case 'l':
                        if (get_arg_val_i(c, optarg, &print_level,
                                          PRINT_LEVEL_MIN, PRINT_LEVEL_MAX))
@@ -195,8 +200,34 @@ int main(int argc, char *argv[])
                goto out;
        }
 
-       clock = clock_create(cfg->n_interfaces > 1 ? CLOCK_TYPE_BOUNDARY :
-                            CLOCK_TYPE_ORDINARY, cfg, req_phc);
+       switch (type) {
+       case CLOCK_TYPE_ORDINARY:
+       case CLOCK_TYPE_BOUNDARY:
+               if (cfg->n_interfaces > 1) {
+                       type = CLOCK_TYPE_BOUNDARY;
+               }
+               break;
+       case CLOCK_TYPE_P2P:
+       case CLOCK_TYPE_E2E:
+               if (cfg->n_interfaces < 2) {
+                       fprintf(stderr, "TC needs at least two interfaces\n");
+                       goto out;
+               }
+               switch (config_get_int(cfg, NULL, "delay_mechanism")) {
+               case DM_AUTO:
+               case DM_E2E:
+                       type = CLOCK_TYPE_E2E;
+                       break;
+               case DM_P2P:
+                       type = CLOCK_TYPE_P2P;
+                       break;
+               }
+               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.1.4


------------------------------------------------------------------------------
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