This code changes brings in the ability to program delay response timeout
within which, if the upstream master does not send a valid delay response
within the configurable delay response timeout duration, device will move
out of lock state..Default delay_response_timeout is 0 (disabled).

Signed-off-by: Karthikkumar V <kval...@altiostar.com>
Signed-off-by: Ramana Reddy <rre...@altiostar.com>
Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 clock.c             |  3 +++
 config.c            |  1 +
 configs/default.cfg |  1 +
 fsm.c               |  6 ++++++
 fsm.h               |  1 +
 port.c              | 25 ++++++++++++++++++++++++-
 port_private.h      |  2 ++
 ptp4l.8             |  6 ++++++
 util.c              |  1 +
 9 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/clock.c b/clock.c
index 3759b0f..9f3c4d6 100644
--- a/clock.c
+++ b/clock.c
@@ -1631,6 +1631,9 @@ int clock_poll(struct clock *c)
                                if (EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES == 
event) {
                                        c->sde = 1;
                                }
+                               if (EV_DELAY_RESPONSE_TIMEOUT_EXPIRES == event) 
{
+                                       c->sde = 1;
+                               }
                                port_dispatch(p, event, 0);
                                /* Clear any fault after a little while. */
                                if (PS_FAULTY == port_state(p)) {
diff --git a/config.c b/config.c
index eb8b988..55d9752 100644
--- a/config.c
+++ b/config.c
@@ -239,6 +239,7 @@ struct config_item config_tab[] = {
        PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
        PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
        PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu),
+       PORT_ITEM_INT("delay_response_timeout",0,0,UINT8_MAX),
        GLOB_ITEM_INT("dscp_event", 0, 0, 63),
        GLOB_ITEM_INT("dscp_general", 0, 0, 63),
        GLOB_ITEM_INT("domainNumber", 0, 0, 127),
diff --git a/configs/default.cfg b/configs/default.cfg
index d615610..cd383b5 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -30,6 +30,7 @@ logMinPdelayReqInterval       0
 operLogPdelayReqInterval 0
 announceReceiptTimeout 3
 syncReceiptTimeout     0
+delay_response_timeout 0
 delayAsymmetry         0
 fault_reset_interval   4
 neighborPropDelayThresh        20000000
diff --git a/fsm.c b/fsm.c
index ce6efad..3720d96 100644
--- a/fsm.c
+++ b/fsm.c
@@ -210,6 +210,9 @@ enum port_state ptp_fsm(enum port_state state, enum 
fsm_event event, int mdiff)
                case EV_RS_PASSIVE:
                        next = PS_PASSIVE;
                        break;
+               case EV_DELAY_RESPONSE_TIMEOUT_EXPIRES:
+                       next = PS_LISTENING;
+                       break;
                default:
                        break;
                }
@@ -271,6 +274,7 @@ enum port_state ptp_slave_fsm(enum port_state state, enum 
fsm_event event,
                case EV_RS_MASTER:
                case EV_RS_GRAND_MASTER:
                case EV_RS_PASSIVE:
+               case EV_DELAY_RESPONSE_TIMEOUT_EXPIRES:
                        next = PS_LISTENING;
                        break;
                case EV_RS_SLAVE:
@@ -293,6 +297,7 @@ enum port_state ptp_slave_fsm(enum port_state state, enum 
fsm_event event,
                case EV_RS_MASTER:
                case EV_RS_GRAND_MASTER:
                case EV_RS_PASSIVE:
+               case EV_DELAY_RESPONSE_TIMEOUT_EXPIRES:
                        next = PS_LISTENING;
                        break;
                case EV_MASTER_CLOCK_SELECTED:
@@ -315,6 +320,7 @@ enum port_state ptp_slave_fsm(enum port_state state, enum 
fsm_event event,
                case EV_RS_MASTER:
                case EV_RS_GRAND_MASTER:
                case EV_RS_PASSIVE:
+               case EV_DELAY_RESPONSE_TIMEOUT_EXPIRES:
                        next = PS_LISTENING;
                        break;
                case EV_SYNCHRONIZATION_FAULT:
diff --git a/fsm.h b/fsm.h
index 857af05..236ec60 100644
--- a/fsm.h
+++ b/fsm.h
@@ -53,6 +53,7 @@ enum fsm_event {
        EV_RS_GRAND_MASTER,
        EV_RS_SLAVE,
        EV_RS_PASSIVE,
+       EV_DELAY_RESPONSE_TIMEOUT_EXPIRES,
 };
 
 enum bmca_select {
diff --git a/port.c b/port.c
index c82bdaf..3529070 100644
--- a/port.c
+++ b/port.c
@@ -1732,6 +1732,7 @@ int port_initialize(struct port *p)
        p->operLogPdelayReqInterval = config_get_int(cfg, p->name, 
"operLogPdelayReqInterval");
        p->neighborPropDelayThresh = config_get_int(cfg, p->name, 
"neighborPropDelayThresh");
        p->min_neighbor_prop_delay = config_get_int(cfg, p->name, 
"min_neighbor_prop_delay");
+       p->delay_response_timeout  = config_get_int(cfg, p->name, 
"delay_response_timeout");
 
        if (config_get_int(cfg, p->name, "asCapable") == AS_CAPABLE_TRUE) {
                p->asCapable = ALWAYS_CAPABLE;
@@ -1997,6 +1998,9 @@ void process_delay_resp(struct port *p, struct 
ptp_message *m)
                return;
        }
 
+       /* Valid Delay Response received, reset the counter */
+       p->delay_response_counter = 0;
+
        c3 = correction_to_tmv(m->header.correction);
        t3 = req->hwts.ts;
        t4 = timestamp_to_tmv(m->ts.pdu);
@@ -2680,7 +2684,26 @@ static enum fsm_event bc_event(struct port *p, int 
fd_index)
                pr_debug("%s: delay timeout", p->log_name);
                port_set_delay_tmo(p);
                delay_req_prune(p);
-               return port_delay_request(p) ? EV_FAULT_DETECTED : EV_NONE;
+               if (port_delay_request(p)) {
+                       return EV_FAULT_DETECTED;
+               }
+               /* Successfully send Delay Request,
+                * increment delay response counter
+                */
+               p->delay_response_counter++;
+
+               if (p->delay_response_counter >= p->delay_response_timeout) {
+                       p->delay_response_counter = 0;
+                       if ( (p->delay_response_timeout != 0) &&
+                               (p->state == PS_SLAVE)) {
+                               if (p->best) {
+                                       fc_clear(p->best);
+                               }
+                               pr_err("%s: delay response timeout", 
p->log_name);
+                               return EV_DELAY_RESPONSE_TIMEOUT_EXPIRES;
+                       }
+               }
+               return EV_NONE;
 
        case FD_QUALIFICATION_TIMER:
                pr_debug("%s: qualification timeout", p->log_name);
diff --git a/port_private.h b/port_private.h
index 2a98ef4..5391879 100644
--- a/port_private.h
+++ b/port_private.h
@@ -143,6 +143,8 @@ struct port {
        struct fault_interval flt_interval_pertype[FT_CNT];
        enum fault_type     last_fault_type;
        UInteger8           versionNumber; /* UInteger4 */
+       UInteger8           delay_response_counter;
+       UInteger8           delay_response_timeout;
        struct PortStats    stats;
        /* foreignMasterDS */
        LIST_HEAD(fm, foreign_clock) foreign_masters;
diff --git a/ptp4l.8 b/ptp4l.8
index a0779ef..9e95de3 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -204,6 +204,12 @@ running in gPTP mode according to the 802.1AS-2011 
standard. Setting
 this option to zero will disable the sync message timeout.
 The default is 0 or disabled.
 .TP
+.B delay_response_timeout
+The number of delay response messages that may go missing before
+triggering a Best Master Clock election. Setting this option to
+zero will disable the delay response timeout.
+The default is 0 or disabled.
+.TP
 .B transportSpecific
 The transport specific field. Must be in the range 0 to 255.
 The default is 0.
diff --git a/util.c b/util.c
index 113467d..8c073c5 100644
--- a/util.c
+++ b/util.c
@@ -68,6 +68,7 @@ const char *ev_str[] = {
        "RS_GRAND_MASTER",
        "RS_SLAVE",
        "RS_PASSIVE",
+       "DELAY_RESPONSE_TIMEOUT_EXPIRES",
 };
 
 const char *ts_str(enum timestamp_type ts)
-- 
1.8.3.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to