diff --git a/config.c b/config.c index 2315443..a4a6261 100644 --- a/config.c +++ b/config.c @@ -61,7 +61,12 @@ static enum parser_result parse_pod_setting(const char *option, Integer8 i8; UInteger8 u8; - if (!strcmp(option, "logAnnounceInterval")) { + if (!strcmp(option, "delayAsymmetry")) { + if (1 != sscanf(value, "%d", &val)) + return BAD_VALUE; + pod->asymmetry = (Integer64) val << 16; + + } else if (!strcmp(option, "logAnnounceInterval")) { if (1 != sscanf(value, "%hhd", &i8)) return BAD_VALUE; pod->logAnnounceInterval = i8; diff --git a/default.cfg b/default.cfg index 9cf6bbf..ee2700d 100644 --- a/default.cfg +++ b/default.cfg @@ -20,6 +20,7 @@ logSyncInterval 0 logMinDelayReqInterval 0 logMinPdelayReqInterval 0 announceReceiptTimeout 3 +delayAsymmetry 0 # # Run time options # diff --git a/ds.h b/ds.h index e96afaf..514679b 100644 --- a/ds.h +++ b/ds.h @@ -102,6 +102,7 @@ struct portDS { } PACKED; struct port_defaults { + Integer64 asymmetry; Integer8 logAnnounceInterval; Integer8 logSyncInterval; Integer8 logMinDelayReqInterval; diff --git a/gPTP.cfg b/gPTP.cfg index 4295a40..f186e78 100644 --- a/gPTP.cfg +++ b/gPTP.cfg @@ -19,6 +19,7 @@ logAnnounceInterval 1 logSyncInterval -3 logMinPdelayReqInterval 0 announceReceiptTimeout 3 +delayAsymmetry 0 # # Run time options # diff --git a/port.c b/port.c index 15ee8d8..8b03bd9 100644 --- a/port.c +++ b/port.c @@ -588,6 +588,7 @@ static int port_pdelay_request(struct port *p) msg->header.ver = PTP_VERSION; msg->header.messageLength = pdulen; msg->header.domainNumber = clock_domain_number(p->clock); + msg->header.correction = -p->pod.asymmetry; msg->header.sourcePortIdentity = p->portIdentity; msg->header.sequenceId = p->seqnum.delayreq++; msg->header.control = CTL_OTHER; @@ -636,6 +637,7 @@ static int port_delay_request(struct port *p) msg->header.ver = PTP_VERSION; msg->header.messageLength = pdulen; msg->header.domainNumber = clock_domain_number(p->clock); + msg->header.correction = -p->pod.asymmetry; msg->header.sourcePortIdentity = p->portIdentity; msg->header.sequenceId = p->seqnum.delayreq++; msg->header.control = CTL_DELAY_REQ; @@ -1226,11 +1228,9 @@ static void port_peer_delay(struct port *p) if (rsp->header.sequenceId != ntohs(req->header.sequenceId)) return; - // TODO - add asymmetry value to correctionField. - t1 = timespec_to_tmv(req->hwts.ts); t4 = timespec_to_tmv(rsp->hwts.ts); - c1 = correction_to_tmv(rsp->header.correction); + c1 = correction_to_tmv(rsp->header.correction + p->pod.asymmetry); /* Process one-step response immediately. */ if (one_step(rsp)) { @@ -1339,7 +1339,7 @@ static void process_sync(struct port *p, struct ptp_message *m) clock_sync_interval(p->clock, p->log_sync_interval); } - // TODO - add asymmetry value to correctionField. + m->header.correction += p->pod.asymmetry; if (one_step(m)) { port_synchronize(p, m->hwts.ts, m->ts.pdu, diff --git a/ptp4l.8 b/ptp4l.8 index 5636a08..e12542d 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -134,6 +134,12 @@ option. An empty port section can be used to replace the command line option. .SH PORT OPTIONS +.TP +.B delayAsymmetry +The time difference in nanoseconds of the transmit and receive +paths. This value should be positive when the master-to-slave +propagation time is longer and negative when the slave-to-master time +is longer. The default is 0 nanoseconds. .TP .B logAnnounceInterval The mean time interval between Announce messages. A shorter interval makes