Commit Graph

270 Commits (78a720f2b38459f5be1089f01e4b396e6167948a)

Author SHA1 Message Date
Anders Selhammer 1173e774dd Introduce the maxStepsRemoved attribute
Add attribute maxStepsRemoved which is included in IEEE1588-2017 (v2.1)
It is an optional attribute which can decide if an Announce message is
considered in the operation of the BMCA or not.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-09-30 18:39:39 -07:00
Miroslav Lichvar 47971bdd50 port: Fix memory leaks.
In port_management_fill_response() the TLV descriptor leaked when
not responding.

In port_open() the port would leak with the unsupported management clock
type.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-08-12 13:33:06 -07:00
Richard Cochran a2740768b6 Apply ingress and egress latency corrections in P2P one step mode.
When using peer to peer one step mode, the normal time stamp handling
of peer delay request messages is bypassed.  The hardware subtracts
the ingress time stamp from the correction field and then adds the
egress time into the correction of the response.  The configured
latency values are never applied since the hardware has no knowledge
of them.  This patch adds in the correction values in this special
case.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-08-05 21:15:59 -07:00
Richard Cochran b1ce06206f port: Introduce an option to disable mutlicast service.
Some profiles forbid multicast altogther.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:07 -07:00
Richard Cochran b9b18268cd port: Hook into the unicast service logic.
Now that all the pieces are in place, hook the port logic into the
unicast service code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:07 -07:00
Richard Cochran dfa9e65785 fd: Introduce a unicast service timer.
This patch adds a new timer to be used by the server side unicast
negotiation logic.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran f71caedc57 port: Hook into the unicast client logic.
Now that all the pieces are in place, hook the port logic into the unicast
client code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran e8e2be017a Support unicast peer to peer delay mechanism.
There are two aspects.  First, on the receive path, we reply to
unicast peer delay requests in kind.  That is, if the peer sends a
unicast delay request, then reply with unicast, too, since this is
obviously what the peer expects.

Second, if configured, we transmit peer delay requests to the
specified unicast peer address.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran ffdb3f7192 fd: Introduce a unicast request timer.
This patch adds a new timer to be used by the client side unicast
negotiation logic.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:48 -07:00
Richard Cochran f94df4f625 port: Make the sync and announce transmit functions public.
These functions will be needed by the new unicast mode.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:48 -07:00
Richard Cochran 05dce31d81 port: Allow transmission of unicast announce messages.
This will be needed by unicast mode.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:47 -07:00
Richard Cochran ffbafa557b transport: Fix even more callers to pass a proper enumeration value.
All of the callers of transport_peer() use hard coded magic numbers.
This patch fixes them to use the corresponding enumerated values instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:25:34 -07:00
Rafaël Carré ee2a9d4ac9 follow_up_info_append: port argument is unused
Signed-off-by: Rafaël Carré <funman@videolan.org>
2018-06-25 07:24:17 -07:00
Rafaël Carré 3c7fa5dd42 clock_send_notification: msg_len is unused
message length is already included in the msg structure

Signed-off-by: Rafaël Carré <funman@videolan.org>
2018-06-25 07:24:17 -07:00
Michael Walle 6bc77ccf4b Replace memcmp() with pid_eq() and cid_eq()
Consistenly use the pid_eq() and cid_eq() helper functions. Move the
functions into utils.h (making them inline functions) because they are
used in multiple source files.

Signed-off-by: Michael Walle <michael@walle.cc>
2018-06-21 07:18:24 -07:00
Cliff Spradlin via Linuxptp-devel dc0f6427bd port: don't clockcheck timestamps from other domains
ptp4l runs clockcheck on an incoming PTP message before checking its
domain number. If the time on another domain is different, then
clockcheck will trigger spurious synchronization faults.

This patch reorders the logic so that clockcheck only runs on messages
in the same time domain.

Reported-By: Filip Perich <perich@google.com>
Signed-off-by: Cliff Spradlin <cspradlin@google.com>
2018-06-13 21:15:19 -07:00
Richard Cochran ccfeb3b092 msg: Introduce a helper to test for unicast messages.
With increasing unicast support, the code needs to identify unicast
messages more often.  This patch replaces the open coded bit field
tests with a more readable in line helper function call.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-25 15:28:35 -07:00
Richard Cochran 28ddb51567 port: Don't take the interval from unicast sync messages.
According to the standard, unicast Sync messages are to be sent with
the interval field set to 127.  This patch adds a test to avoid
incorrectly adopting that value as a new interval.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-25 07:46:04 -07:00
Richard Cochran 494643d1fb port: Correct log message interval field of unicast Sync messages.
According to the standard, this field is special for unicast messages.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-25 07:46:03 -07:00
Richard Cochran a8b66ce7f2 Fix crash in hybrid E2E mode.
Richard Hill reported an occasional NULL pointer deference in
port_delay_request() when in hybrid mode.

	if (p->hybrid_e2e) {
		struct ptp_message *dst = TAILQ_FIRST(&p->best->messages);
		msg->address = dst->address;
		...
	}

The code assumes that the p->best->messages list can't be empty
because:

    The function, port_delay_request(), is called only when
    FD_DELAY_TIMER expires.  That timer is only set by the function,
    port_set_delay_tmo(), which is called:

    1. from process_delay_resp(), but only when state is UNCALIBRATED
       or SLAVE.

    2. from port_e2e_transition(), but only when state is UNCALIBRATED
       or SLAVE.

    Looking at handle_state_decision_event(), a port can only enter
    UNCALIBRATED or SLAVE when it has a valid foreign master record,
    ie p->best->messages is not null.

    A port also only clears p->best->messages when it leaves
    UNCALIBRATED or SLAVE, at which point the FD_DELAY_TIMER is also
    cleared.

*However* the p->best->messages list *can* be empty if the
FD_ANNOUNCE_TIMER and the FD_DELAY_TIMER expire at the same time.  In
this case, the poll() call indicates events on both file descriptors.
The announce timeout is handled like this:

	case FD_ANNOUNCE_TIMER:
        case FD_SYNC_RX_TIMER:
                if (p->best)
                        fc_clear(p->best);

So then the port_delay_request() call de-references the null
TAILQ_FIRST message pointer.

This patch fixes the issue by re-ordering the timer file descriptors
within the polling list.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Richard Hill <plonta@gmx.de>
2018-05-16 06:44:56 -07:00
Richard Cochran e6af4608c4 config: Add a configuration option for preventing loops in TC mode.
According to 1588, PTP message loops are simply someone else's problem
with respect to transparent clocks.  Since we are running the BMCA for
syntonization anyway, we might as well go ahead and implement the spanning
tree for PTP messages.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran 96716060b1 e2e_tc: Implement an end to end transparent clock.
The E2E TC forwards Announce, Delay_Req, Delay_Resp, Management,
Signaling, and Sync messages, and drops P2P Delay messages.

This implementation tracks the GM using the BMCA in order
to syntonize (or possibly even synchronize) with it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran 6a928ae867 p2p_tc: Implement a peer to peer transparent clock.
The P2P TC forwards Announce, Management, Signaling, and Sync
messages, consumes P2P Delay messages, and drops E2E Delay messages.

This implementation tracks the GM using the BMCA in order
to syntonize (or possibly even synchronize) with it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran a13212fcbb tc: Add the transparent clock implementation.
This patch adds code that sends an event messages received on one port out
all the other ports and calculates the residence time.  The correction,
ingress port, and the original message are remembered in a TC transmit
descriptor.  These descriptors are recycled in a memory pool in a similar
way to the message buffers.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:43 -07:00
Richard Cochran 4cfbb2627f port: Share more helper functions.
The transparent clock code will want to set qualification timeouts and
perform end to end delay measurements.  This patch exposes the needed
methods.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-05-01 07:46:28 -07:00
Richard Cochran 4d69d48f96 telecom: Introduce the masterOnly option.
When masterOnly is true, the port always returns NULL when computing
its best foreign master.  As a result, the port will never enter the
SLAVE state, and the clock will ignore Announce messages received on
that port.

This attribute is specifically called out in G.8275.1 and G.8275.2,
and it is implied by the "master only" mode G.8265.1.  In addition,
this option will probably appear in the next revision of IEEE 1588.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:50:07 -07:00
Richard Cochran 4545fd1150 telecom: Add a configuration option for G.8275.portDS.localPriority.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:14 -07:00
Richard Cochran a8d0eb92c6 telecom: Introduce the local priority attribute into the data set.
The Telecom Profiles G.8275.1 and G.8275.2 have invented a new
per-port and per-clock attribute, not in 1588, called "localPriority".
The use of this attribute is a distinguishing feature of the telecom
data set comparison algorithm.

This patch adds the attribute, hard coded to its default value.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:13 -07:00
Richard Cochran 6f96ebb7b8 Refactor the data set comparison function variable.
There is no need to keep two copies of the data set comparison
function.  This patch adds a method that allows the port code to
obtain the function from the clock code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:10 -07:00
Richard Cochran a1c5e3f2ed transport: Fix callers to pass a proper enumeration value.
The majority of the callers of transport_send() use hard coded magic
numbers.  This patch fixes them to use the corresponding enumerated
values instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-13 22:29:05 -07:00
Anders Selhammer b36142cb51 port: Fix coding style
Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-04-12 19:47:51 -07:00
Miroslav Lichvar 73c4d9a3c7 port: fix buffer overflow in net_sync_resp_append()
The PortAddress structure has no space for the actual address and should
be used only as a pointer to a larger buffer.

The issue was reported by gcc with enabled source fortification.

[ RC: Replace magic number with sizeof() macro. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-06 18:41:10 -07:00
Richard Cochran 46acbcee42 port: share init code, peer delay code, and helpers
This patch makes a number of subroutines into global functions in order
to share code with the TC implementations to come.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran d87bb60712 port: export a private interface.
This patch places the internal port data structure into a common header
for use by the original BC and the new TC code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran 866da1044c port: Provide a common method for updating the port state.
When computing the next port state based on a FSM event, much of the logic
will stay the same for OC, BC, and TC nodes.

- handling a fault ASAP
- INITIALIZING state handling
- showing the transition in the log
- sending notifications

This patch moves this common code into a global port method, making it
available to future TC implementations.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran c170405822 port: make the dispatch and event methods variable based on clock type.
This paves the way to allow different implementations for the upcoming
Transparent Clock code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran ec33010f56 port: Make the data set comparison algorithm into a function variable.
This will allow adding alternative algorithms as defined in PTP profiles.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran 4842d2c7ec Introduce peer to peer one step.
The 1588 standard defines one step operation for both Sync and
PDelay_Resp messages.  Up until now, hardware with P2P one step has
been rare, and kernel support was lacking.  This patch adds support of
the mode in anticipation of new kernel and hardware developments.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-27 22:26:32 -07:00
Richard Cochran 510777deca msg: Move the check for missing HW time stamps into caller.
On the transmit path, the port-level code calls msg_sots_missing()
directly, but on receive this check is buried in the message layer.
With the coming addition of peer to peer one step, the ingress check
will need knowledge of the configured time stamping option.  This
patch moves the check in order to accommodate the exceptional case.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-27 22:26:32 -07:00
Anders Selhammer f9db6855fd port: Added TAILQ for sent delay_req
In a ptp unaware network (like the telecom profile for frequency sync
G.8265.1), both the RTD and the PDV can be substantially higher than
in a ptp aware network. To achieve more accurate measurements, the
rate may need to be configured higher to get more data and increase
the chance of lucky packets.
In a combination of a high configured rate of delay_req and high
RTD/PDV in network, the risk that the response from the previously
sent delay_req have not been received before a new delay_req is sent
also become high. In that case, the need of storing more than the
latest sent delay_req arise.

This patch adds a queue for sent delay requests so several request can
be ongoing in parallel. When a delay response is received, a matching
request will be searched for in the queue and after processed removed
from the queue.
The stored delay_req will be removed if older than 5 seconds. Check is
made before a new delay_req is sent or announce receipt tmo expires.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-03-24 14:40:35 -07:00
Anders Selhammer 9320f768e2 port: Fix coding style
We always but braces around 'if' blocks.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-03-24 14:40:35 -07:00
Michael Brown 1e19ce204a port: Remove unnecessary conversions from tmv_t to int64_t
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 73c59e83d9 port: Remove unnecessary ts_to_Timestamp() wrapper
The function ts_to_Timestamp() is now just a wrapper around
tmv_to_Timestamp().  Simplify code by using tmv_to_Timestamp()
directly.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 7f59858d08 msg: Represent hw_timestamp "sw" field as tmv_t
Convert a software timestamp to the internal tmv_t representation at
the earliest possible opportunity, to match the behaviour for hardware
timestamps.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 29a99ad513 msg: Represent hw_timestamp "ts" field as tmv_t
Convert a hardware timestamp to the internal tmv_t representation at
the earliest possible opportunity.  This allows us to:

- eliminate multiple redundant calls to timespec_to_tmv()

- use tmv_add() instead of open-coded manipulation of a struct
  timespec in ts_add()

- use tmv_to_Timestamp() instead of open-coded manipulation of a
  struct timespec and struct Timestamp in ts_to_Timestamp()

- use tmv_is_zero() instead of open-coded manipulation of a struct
  timespec in msg_sots_valid()

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 5a23ccddf6 port: Match calling convention for tmv_to_Timestamp()
The function ts_to_timestamp() currently performs open-coded
manipulation of a struct timespec and struct Timestamp instead of
using the tmv_t abstractions.

Prepare for the removal of this code by matching the calling
convention for tmv_to_Timestamp(): returning a struct Timestamp rather
than accepting a pointer to a struct Timestamp.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown cdceec59fa port: Treat ingressLatency and egressLatency as corrections
The function ts_add() currently performs open-coded manipulation of a
struct timespec instead of using the tmv_t abstractions.

Prepare for the removal of this code by storing ingressLatency and
egressLatency as corrections (matching the behaviour for
delayAsymmetry).

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown c9f3fad780 clock: Remove open-coded conversion of struct timespec
The function clock_check_ts() performs open-coded manipulation of a
struct timespec instead of using the tmv_t abstractions.

Use the existing tmv_t abstractions to convert from struct timespec to
nanoseconds, and modify the prototype of clock_check_ts() to match
that of the underlying clockcheck_sample().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Richard Cochran d89d26d618 Add a configuration file option to enable the NetSync Monitor protocol.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00
Richard Cochran 61e57e9fca port: Implement the NetSync Monitor protocol.
When NSM is enabled on a given port, that port always replies to a NSM
delay request with a delay response, sync, and follow up, regardless
of the current state of the port.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00