Commit Graph

124 Commits (ed379b402834739d5910d11b6de2f15b564b5dbc)

Author SHA1 Message Date
Miroslav Lichvar ed379b4028 Add clock sanity check.
Check the sanity of the synchronized clock by comparing its uncorrected
frequency with the system monotonic clock. When the measured frequency
offset is larger than the value of the sanity_freq_limit option (20% by
default), a warning message will be printed and the servo will be reset.
Setting the option to zero disables the check.

This is useful to detect when the clock is broken or adjusted by another
program.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-27 08:24:01 +01:00
Miroslav Lichvar ea4201298c Ignore delay_resp messages from foreign masters.
When a new master appears, it will start to respond to our delay_req
messages. Make sure we process only responses from our current master
before switching to the new master.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-10-11 19:44:49 +02:00
Miroslav Lichvar b366b79306 Reset delay timer when switching to P2P delay mechanism.
When ptp4l was configured to use the auto delay mechanism and the first
pdelay request was not received in the slave or uncalibrated state, it
would not make any pdelay requests itself, because there was no delay
timer running.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-09-21 08:15:28 +02:00
Richard Cochran 7b7e046e91 Add an optional extra check on sync and follow up message ordering.
Because of packet reordering that can occur in the network, in the
hardware, or in the networking stack, a follow up message can appear
to arrive in the application before the matching sync message. As this
is a normal occurrence, and the sequenceID message field ensures
proper matching, the ptp4l program accepts out of order packets.

This patch adds an additional check using the software time stamps
from the networking stack to verify that the sync message did arrive
first. This check is only useful if the sequence IDs generated by
the master might possibly be incorrect.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-08-29 11:22:25 +02:00
Richard Cochran f299b6fb07 Announce master ambitions right away.
This patch lets a port send the first announce message one millisecond
after the port state transition, rather than waiting one announce interval.
This change is needed because it is desirable to reconfigure the time
network without delay, especially in P2P mode.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-08-26 18:30:54 +02:00
Richard Cochran c6e046e2a2 Add a configuration file option for the sync receive timeout.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-08-26 18:30:54 +02:00
Richard Cochran 7eef4101c9 Add a timer implementing the sync receive timeout.
This patch adds a new timer for use in 802.1AS-2011 applications. When
running as a slave in gPTP mode, the program must monitor both announce
and sync messages from the master. If either one goes missing, then we
trigger a BMC election. The sync timeout is actually reset by a valid
sync/follow up pair of messages.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-08-26 18:30:54 +02:00
Richard Cochran 329e4a2fff Rename the timer for sending sync messages.
This patch renames the per-port timer in order to make room in the
namespace for a timer that detects a sync message input timeout.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-08-26 14:45:21 +02:00
Richard Cochran 78d3669b06 Inhibit lost link recovery in P2P mode.
The closing and reopening of the transport when in slave only mode is not
necessary if the port is using the peer delay mechanism. In that case, the
port will discover the network error by transmitting a peer delay request.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-08-26 14:42:27 +02:00
Delio Brignoli b268cf048b Do not qualify announce messages with stepsRemoved >= 255
See IEEE1588-2008 section 9.3.2.5 (d)

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-08-23 08:21:00 +02:00
Richard Cochran 7be0698175 Fix bug in unlucky sync/follow up handling.
Ken Ichikawa has identified a situation in which a sync message can be
wrongly associated with a follow up after the sequence counter wraps
around.

   Port is LISTENING
   Sync (seqId 0) : ignored
   Fup  (seqId 0) : ignored
   Sync (seqId 1) : ignored
   Port becomes UNCALIBRATED here
   Fup  (seqId 1) : cached!
   Sync (seqId 2) : cached
   Fup  (seqId 2) : match
   Sync (seqId 3) : cached
   Fup  (seqId 3) : match
   ...
   Sync (seqId 65535) : cached
   Fup  (seqId 65535) : match
   Sync (seqId 0) : cached
   Fup  (seqId 0) : match
   Sync (seqId 1) : match with old Fup!!
   Fup  (seqId 1) : cached!
   Sync (seqId 2) : cached
   Fup  (seqId 2) : match

   Actually, I experienced 65500 secs offset every about 65500 secs.
   I'm thinking this is the cause.

This patch fixes the issue by changing the port code to remember one
sync or one follow up, never both. The previous ad hoc logic has been
replaced with a small state machine that handles the messages in the
proper order.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
2013-08-01 22:21:52 +02:00
Jiri Benc 48f4dcbeb2 ptp4l: flush old cached packets
This patch fixes a bug with time mysteriously jumping back and forth:

ptp4l[930.687]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[931.687]: master offset         17 s2 freq  +33014 path delay      2728
ptp4l[932.687]: master offset        -74 s2 freq  +32928 path delay      2734
ptp4l[933.687]: master offset          2 s2 freq  +32982 path delay      2734
ptp4l[934.687]: master offset         -3 s2 freq  +32977 path delay      2728
ptp4l[935.687]: master offset         17 s2 freq  +32996 path delay      2729
ptp4l[936.687]: master offset        -10 s2 freq  +32974 path delay      2729
ptp4l[937.687]: master offset         35 s2 freq  +33016 path delay      2727
ptp4l[938.686]: master offset 60001851388 s2 freq +62499999 path delay      2728
ptp4l[939.687]: master offset  -62464938 s2 freq -62431946 path delay      2728

The last follow up message arriving out of order is cached. Before the state
machine changes to UNCALIBRATED, all sync and follow up messages are discarded.
If we get into that state between a sync and follow up message, the latter is
cached. When there's no real roerdering happening, it's kept cached forever.

When we restart the master, it starts numbering the messages from zero again.
The initial synchronization doesn't take always the same amount of time, so it
can happen that we get into UNCALIBRATED a little bit faster than before,
managing to get the sync message with the sequenceId that we missed last time.
As it has the same sequenceId as the cached (old) follow up message, it's
incorrectly assumed those two belong together.

Flush the cache when changing to UNCALIBRATED. Also, do similar thing for other
cached packets.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2013-07-19 16:17:46 +02:00
Richard Cochran a367175b0d Throw a state decision event if the clock quality changes.
Management messages can cause a change in the clock quality. If this
happens, then it is time to run the Best Master Clock algorithm again.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-07-14 21:37:52 +02:00
Richard Cochran 81db403af8 Reset announce timer when port is passive.
Whenever a port enters the passive state, it should act like a slaved
port in one respect. Incoming announce messages from the grand master
are supposed to reset the announce timer. This patch fixes the port
logic to properly maintain the passive state.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Rohrer Hansjoerg <hj.rohrer@mobatime.com>
2013-07-07 18:55:44 +02:00
Miroslav Lichvar fce0aa0a2f Fix compiler warnings with -O2.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-04-05 09:14:29 +02:00
Richard Cochran 9ee5c1fb8e Let a slaved port update the time properties on every announce message.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-04-02 19:28:10 +02:00
Libor Pechacek 0367bb5f1b Distinguish between ignored and malformed packets
When there is a peer speaking PTPv1 in the network we want to silently ignore
the packets instead of flooding system log with error messages.  At the same
time we still want to report malformed packets.  For that we reuse standard
error numbers and do more fine-grained error reporting in packet processing
routines.

Signed-off-by: Libor Pechacek <lpechacek@suse.cz>
2013-03-28 18:48:52 +01:00
Delio Brignoli 789a5c8e37 Add support for FT_BAD_PEER_NETWORK
Handle reception of >=3 sequential multiple pdelay responses from
distinct peers as a fault of type FT_BAD_PEER_NETWORK.

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-20 19:10:22 +01:00
Delio Brignoli b936d35b6d Add support for multiple fault types
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-20 19:10:22 +01:00
Delio Brignoli 455ebe7d22 Rename set_tmo() to set_tmo_log(), add set_tmo_lin()
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-20 19:10:22 +01:00
Delio Brignoli d374ad6bf7 Explicitly detect and handle changes of the peer's port id by resetting asCapable and the port's nrate
This patch also changes port_capable() to reset the port's nrate every time asCapable changes
from true to false.

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-20 19:10:09 +01:00
Delio Brignoli 9650cb687d Log changes to asCapable
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-17 18:50:31 +01:00
Delio Brignoli 3cc285c691 Free peer delay responses and followup messages when sending a new peer delay request
If messages are not freed, it is possible (with purposely crafted traffic) to trigger
a peer delay calculation which will use message's data from the previous round.

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-14 05:17:41 +01:00
Delio Brignoli 4626487ff3 Implement neighborPropDelayThresh check in port_capable()
Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-03-14 05:17:38 +01:00
Richard Cochran 48aa6712a9 Add support for the log peer delay interval management request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-03-04 20:27:12 +01:00
Richard Cochran 9b5e37bbf8 Add support for the delay mechanism management request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-03-04 20:23:32 +01:00
Richard Cochran d30d397c2b Add support for the version number management request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-03-04 20:18:19 +01:00
Richard Cochran 06a65003f4 Add support for the log sync interval management request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-03-04 20:14:05 +01:00
Richard Cochran d2f8bc5e38 Add support for the announce receipt timeout management request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-03-04 20:10:51 +01:00
Richard Cochran 555c42e3d0 Add support for the log announce interval management request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-03-04 20:06:36 +01:00
Geoff Salmon 36a5921e88 support GET CLOCK_DESCRIPTION and USER_DESCRIPTION mgmt messages
Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-25 18:11:03 +01:00
Miroslav Lichvar c547145834 Check shift used in freq_est and stats max_count calculation.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-12 19:59:50 +01:00
Richard Cochran c7098364f2 Make the counters for the frequency and rate estimators unsigned.
These are simple 'up' counters.
There is no need for negative values here.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-09 08:51:19 +01:00
Richard Cochran 6dc1b90306 Send peer delay requests continuously in P2P mode.
When a port makes a transition from one state to another, it resets all of
the message timers. While this is the correct behavior for E2E mode, the
P2P mode requires sending peer delay requests most of the time.

Even though all the other timer logic is identical, still making an
exception for P2P mode would make the code even harder to follow. So this
patch introduces two nearly identical helper functions to handle timer
reprogramming during a state transition.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-06 19:27:48 +01:00
Geoff Salmon 3921557672 send NOT_SUPPORTED errors for all unhandled, known management IDs
Now that there are clock/port_management_set functions, the IDs that
GETs are handled for, like DEFUALT_DATA_SET, still need to be in the
case for sending NOT_SUPPORTED errors.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-06 18:10:36 +01:00
Geoff Salmon 507bee9e73 adds stub clock/port_management_set functions
Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-06 18:10:36 +01:00
Geoff Salmon 0e497b9a45 send UNKNOWN_ID error for unknown management TLVs
Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-06 18:10:36 +01:00
Geoff Salmon 1500605ff5 factors out functions for sending mgmt errors from clock and port
Adds port_management_send_error and clock_management_send_error to
avoid repeatedly checking the result of port_managment_send_error and
calling pr_err if it failed. Future patches send more mgmt errors so
this will avoid repeated code.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-06 18:10:35 +01:00
Geoff Salmon d5af4196fc fixes typo port_managment_error -> port_management_error
Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-06 18:10:35 +01:00
Richard Cochran f530ae9333 Hide the grandmaster port state.
There really is no such state, but there probably should have been one.
In any case, we do have one just to make the code simpler, but this should
not appear in the management responses. This patch fixes the issue by
covering over our tracks before sending a response.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-06 13:34:49 +01:00
Richard Cochran 4f866b2761 Merge the branch with the 'asCapable' support.
Conflicts:
	port.c

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-03 18:43:56 +01:00
Richard Cochran 0dbdd9c2cd Stop handling file descriptor events after a port reset.
If the port resets itself after detecting a fault, then the polling events
for that port are no longer valid. This patch fixes a latent bug that
would appear if a fault and another event were to happen simultaneously.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-03 17:58:12 +01:00
Delio Brignoli da594e78d9 Make the fault reset interval a per-port configuration parameter.
A timeout of 15 seconds is not always acceptable, make it configurable.

By popular consensus, instead of using a linear number of seconds, use
the 2^N format for the time interval, just like the other intervals in
the PTP data sets. In addition to numeric values, let the configuration
file support 'ASAP' to have the fault reset immediately.

[RC - moved the handling of special case tmo=0 and added a break out
      of the fd event loop in case the fds have been closed.
    - changed the linear seconds option to log second instead.
    - changed the commit message to reflect the final version. ]

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-03 17:53:33 +01:00
Richard Cochran 285b88ade4 Let a port become 'capable' according to 802.1AS.
This patch implements the capable flag as follows.

1. After calculating the neighbor rate, we are capable.
2. If we miss too many responses, we are incapable.
3. If we get multiple responses, we throw a fault,
   and so we are also incapable.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-01-27 20:58:19 +01:00
Richard Cochran ea833f3d6b Add a default of 'incapable' for 802.1AS mode.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-01-27 20:58:19 +01:00
Richard Cochran ad8a197a0b Add port logic for the 'capable' flag from 802.1AS.
This commit only provides helper functions that will implement the effect
of a port being not capable. We let the port be always 'capable' for now,
until we actually have added the details of that flag.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-01-27 20:58:19 +01:00
Richard Cochran 90f791d881 Introduce a test for running in 802.1AS mode.
We use the follow_up_info to control behavior that is specific to the
802.1AS standard. In several instances, that standard goes against the
1588 standard or requires new run time logic that exceeds what can be
reasonably described as a 1588 profile.

Since we will need a few more run time exceptions in order to support
802.1AS, we introduce a helper function to identify this case, rather
than hard coding a test for follow_up_info, in order to be more clear
about it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-01-27 20:58:19 +01:00
Richard Cochran a1cd223962 Start P2P messages right away when listening after initializing.
Because of an oversight in the event code, a port will not send peer delay
request messages while in the initial listening state. This patch fixes
the issue by expanding this special, initial case.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-01-27 20:58:19 +01:00
Richard Cochran b810153ed5 Add asymmetry correction.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jacob Keller <Jacob.e.keller@intel.com>
2012-12-11 14:36:30 +01:00
Richard Cochran 2aaae0854e Distinguish between get and set management requests.
The code previously treated all supported request as 'get' actions and
ignored the actual action field in the message. This commit makes the
code look at the action field when processing the requests.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-12-04 13:25:50 +01:00