Commit Graph

402 Commits (f0a86e7d8f9ceccedbab94ff5983259eb349df21)

Author SHA1 Message Date
Miroslav Lichvar f0a86e7d8f Update comment in pi.c.
This was missed in commit d8cb9be46a.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:02 +01:00
Miroslav Lichvar 5667ab5d30 Check sample time stamps in drift calculation.
Before calculating the clock drift in the PI servo, make sure
the first sample is older than the second sample to avoid getting
invalid drift or NaN.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:02 +01:00
Miroslav Lichvar a41e9f8c8c Print messages with level below LOG_NOTICE to stderr.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar 158daa697d phc2sys: Use printing facility.
Use pr_* functions to print messages and add -m, -q, -l options to allow
configuration of the printing level and where should be the messages sent.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar 11fa191505 phc2sys: Open PPS device sooner.
Possible error messages should be printed before waiting on ptp4l.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar 7f760ceac8 pmc: Allow commands on command line.
Add a batch mode, where the commands are taken from the command line
instead of the standard input.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar ecbbf4cdb1 Move Unix domain sockets to /var/run.
According to FHS, /var/run is the right place for them.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +01:00
Miroslav Lichvar 09fdc45220 phc2sys: Add option to set step threshold.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-06 19:30:01 +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 f8be779f28 send errors if mgmt tlv length doesn't match action
It's especially important to check that SET messages aren't empty.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-06 18:10:36 +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 89562f06fe Add a coding style document.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-02-06 14:42:12 +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
Geoff Salmon 1e77af6d21 config clock description
Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-04 12:22:11 +01:00
Geoff Salmon 09c2d1a652 adds clock description
Adds struct containing clock description info that will be needed for
USER_DESCRIPTION and CLOCK_DESCRIPTION management messages.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-04 12:22:11 +01:00
Geoff Salmon 68b4678f7b adds static_ptp_text and functions for setting PTPText and static_ptp_text
static_ptp_text is like a PTPText that includes space for the text
which makes it more convenient for ptp texts stored in the clock.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-02-04 12:22:11 +01:00
Miroslav Lichvar 74692bb1b0 phc2sys: include PTP management client.
Add a new option to wait for ptp4l to be in a synchronized state.
Periodically check PORT_DATA_SET and wait until there is a port in
SLAVE, MASTER or GRAND_MASTER state. Also, set the default
synchronization offset according to the currentUtcOffset value from
TIME_PROPERTIES_DATA_SET and the direction of the clock synchronization.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-03 19:08:34 +01:00
Miroslav Lichvar cbc1a70c2c Move some pmc code to separate file.
Move some code which can be shared between PTP management clients to
a new file.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-03 19:08:34 +01:00
Miroslav Lichvar d28f7721de Set program name for print().
The printing facility is used by different programs, allow to set the
program name which prefixes the messages written to stdout.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-02-03 19:08:34 +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
Delio Brignoli eec07ae240 Fix fault-clearing timer being erroneously re-armed
Arm the fault-clearing timer only when an event causes a port to change state
to PS_FAULTY. Previously, if poll() returned because of an fd event other than
the fault-clearing timeout, the fault clearing timer would re-arm for
each port in PS_FAULTY state.

Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
2013-01-30 18:05:38 +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 b9aae07f87 Add another Intel driver into the driver support matrix.
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
Geoff Salmon 533c77115a Check that TLV length is correct when receiving TLVs.
The function, tlv_post_recv, and the functions it calls don't check
the length of the tlv before flipping the byte order of fields. An
attacker (or a really buggy client) can craft a message causing the
byte order of data outside the received message to be flipped.

None of the supported tlvs are large enough to flip bytes outside the
ptp_message struct, which could corrupt the heap. However, it's easy
to mess up the message's refcnt field, leading to memory leaks.

The fix is to check that the tlv length is what is expected when
receiving, and tlv_post_recv needs to return an int to signal when a
tlv is invalid.

Signed-off-by: Geoff Salmon <gsalmon@se-instruments.com>
2013-01-22 21:08:23 +01:00
Richard Cochran d666149e91 Add missing documentation for msg_post_recv.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-01-22 18:31:17 +01:00
Miroslav Lichvar 24a1a6a81e phc2sys: allow PPS loop only with system clock.
The PPS time stamps are always made by the system clock, don't allow
running the PPS loop with other clocks.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-18 07:11:19 +01:00
Miroslav Lichvar c5ce4ef764 phc2sys: read PHC with each PPS sample.
In the PPS loop, instead of setting the system clock from the PHC only
once on start, read PHC with each PPS sample and use the time stamp to
get the whole number of seconds in the offset. This will prevent phc2sys
from losing track of the system clock.

Also, check if the PPS is synchronized to the PHC.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-18 07:11:19 +01:00
Miroslav Lichvar f09b4bb7e3 phc2sys: remove unnecessary clock step with non-PPS loops.
With non-PPS loops let the servo make the inital correction. Move the
code to the PPS loop and change it to use the sample filtering to reduce
the error in the initial correction.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:22 +01:00
Miroslav Lichvar fc1a695493 phc2sys: don't zero clock frequency on start.
Instead of always starting at zero frequency offset, read the currently
stored value on start and pass it to the servo. As the read may silently
fail and return zero, set the clock frequency back to the read value to
make sure it's always equal to the actual frequency of the clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Miroslav Lichvar 2d4b2f1640 phc2sys: move phc loop to its own function.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Miroslav Lichvar 627bc0fdf7 phc2sys: use servo code from ptp4l.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Miroslav Lichvar d8cb9be46a Remove unnecessary states in PI servo.
Step the clock as soon as the second sample is collected.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Miroslav Lichvar af2a4f47fb Modify PI servo to set frequency when jumping.
Similarly to the servo in phc2sys, when clock is stepped, set
immediately also its frequency. This significantly improves the initial
convergence with large frequency offsets.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Miroslav Lichvar ab29608e0b Modify servo_sample() to accept integer values.
Current date stored in nanoseconds doesn't fit in 64-bit double format.
Keep the offset and the time stamp in integer nanoseconds.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Miroslav Lichvar 8a23bf1d66 Fix initial drift calculation in PI servo.
Convert the calculated drift to ppb and also clamp it.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2013-01-16 20:28:21 +01:00
Geoff Salmon d4db76d64c udp6: implement getting physical and protocol addrs 2013-01-14 19:12:18 +01:00
Geoff Salmon c54f8a523b udp: implement getting physical and protocol addrs 2013-01-14 19:12:18 +01:00
Geoff Salmon f3ac2cad65 add sk_interface_addr for getting an interface's IP 2013-01-14 19:12:18 +01:00
Geoff Salmon d6779889cc raw: implement getting physical and protocol addrs 2013-01-14 19:12:18 +01:00
Geoff Salmon e010937783 transport: adds interface for getting type, and physical/protocol address
Needed for CLOCK_DESCRIPTION management TLV.
2013-01-14 19:12:18 +01:00