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>
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>
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>
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>
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>
Change the rtnl_get_ts_label() function to accept the name of the master
interface and the buffer for the slave interface directly instead of the
struct interface from config.h.
Also, rename the function to rtnl_get_ts_device().
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When using long chains of transparent clocks, the recommended practice is
to measure the rate ratio without adjusting the local clock. Then the
residence times should be corrected to reflect the master's frequency.
This patch expands the clock_rate_ratio() method to provide the estimated
ratio when the clock is free running.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
If the "free_running" option is set, the "no adjust" calculates and
prints an estimation of the phase and frequency offsets to the remote
master. Because the phase estimate requires a delay measurement, this
calculation is not performed without having the delay estimate first.
However, a typical transparent clock application will want to use the
frequency offset to correct the residence times to match the master's
frequency.
This patch adds a call to the "no adjust" routine even if no valid
delay measurement has been made.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>
Instead of using a hard coded algorithm, let the caller provide the
function that performs the comparison. This will allow implementing
alternative algorithms from PTP profiles.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We will want to use this macro in more than one source file. This patch
moves the macro into the common header for possibly undefined code.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Up until now, one step operation was controlled by a combination of
options, namely time_stamping=hardware with twoStepFlag=0. The
introduction of peer to peer one step makes the situation a bit more
complicated.
This patch adds support for setting the one step options directly by
using the "time_stamping" option. The "twoStepFlag" is adjusted
automatically if needed. The legacy behavior for Sync message one
step is preserved.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>
Make the log output a bit more clear by changing how we inform the user
when the local clock is the best master clock. This allows easier
parsing of the log and identifying when the local clock is being
selected as the best clock.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
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>
The NetSync Monitor protocol will require us to report the time stamp of
the last synchronization. This patch adds new the method.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
As part of the NetSync Monitor protocol, the port will need to have
access to the current data set. This patch adds the appropriate
function.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This patch changes the receive message parsing code to place each TLV
into the list. A method is introduced that allows attaching TLVs to
the end of the list.
In addition, msg.last_tlv is converted into a pointer to the last item
in the list. Because of this change, the transmit code that uses this
field now allocates a TLV before using it.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Time values are compared using an inequality test in mmedian.c
Generalise tmv_eq() to tmv_cmp() (by analogy with memcmp()) and
replace existing uses of tmv_eq().
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
Use tmv_dbl() to obtain the floating point value passed to
stats_add_value() rather than relying on the existing implicit cast
from the result of tmv_to_nanoseconds().
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
The code uses a local variable for program flow control in a silly way.
This patch simplifies the logic by using the common switch/case/default
pattern instead.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This option allows the clock to be updated before the path delay is
measured in order to speed up the initial correction of the clock, e.g.
in domains using a very long logMinDelayReqInterval.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The UDS port is not expected to be used by PTP clocks and forwarding of
management messages to the port can be limited to responses.
This prevents ptp4l from printing error messages when a management
request is received from a non-UDS port and the last client which used
the UDS port is no longer listening.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Now the ts label will be either the bond active slave or the interface
name, which is the exactly interface we need to get ts info.
When the link down/up or there is a fail over and ts_label changed, the
phc index may also changed. So we need to check get new ts info and check
clock_required_modes. We will set the link to LINK_DOWN by force if
the new ts_label's timestamp do not support required mode.
If all good, then we set phc index to new one. Also sync clock interval
after switch phc.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Separate required_modes setting from clock_create so we can obtain the
required time stamping flags from other place.
Add enum timestamping in struct clock to store the time stamping mode.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Now that we test the UTC flags in clock_update_slave(), the similar
code in clock_utc_correct() is redundant.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When acting as a slave, we accept the foreign master's advertised
TAI-UTC offset for as long as that master is present. However, when
the master disappears, we fall back to the initial offset value. As a
result of this behavior, when starting with an out of date initial
offset, losing a foreign master causes a sudden UTC offset error (in
phc2sys for example) in the range of whole seconds.
This patch fixes the issue by remembering the UTC offset when assuming
the slave role.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The clock code uses two different variables to store the TAI-UTC
offset. One variable represents the compile time, configuration file,
or command line initial UTC offset, while the other is used when
taking on the GM role and is settable at run time. However, making
this distinction makes no sense. This patch simplifies and clarifies
the code by using a single variable for the offset.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
With rtnl socket we can track link status per port(except UDS port).
We can make sure we get the correct interface and latest status with function
port_link_status().
At the same time we need to set clock sde after link down. But we return
EV_FAULT_DETECTED in port_event(), which will not set clock sde. So we need
to set it in port_link_status().
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
The calls to snprintf() to format /dev/phc%d use the wrong pattern.
That function always properly terminates the string with null.
However, the code passes a hard coded length of 31 to static arrays of
length 32. While this is not a bug, there are two issues here.
First, any (improbable) future increase in the array lengths would
have to also remember to fix up the snprintf() call site as well.
Secondly, the pattern of using buf[N] and then length=N-1 is
appropriate for strncpy(), but is useless for snprintf().
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Petr Kulhavy <brain@jikos.cz>
Having one fewer port may affect the result of the BMCA. This patch
changes the main loop so that a link down event also causes a state
decision event.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Henry Jesuiter <Henry.Jesuiter@alcnetworx.de>
This global function used to return an error code, but now it always
returns zero. This patch converts the function signature to return void
and simplifies the main clock loop by removing the useless test.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Currently UTC offset is defined as a constant - CURRENT_UTC_OFFSET, and if
a leap second is added, that constant is no longer valid. Ptp4l was
updated to read the UTC offset from configuration instead.
Signed-off-by: Viliam Lejcik <viliam.lejcik@kistler.com>
Poll for link up/down events. When a link goes down, the port becomes
faulty until the link goes up again. We keep the fault timer from the
existing fault detection, but a downed link prevents clear the fault.
The new state machine is depicted in this ascii art diagram:
+--------+ Fault +---------+
| |------------>| |
| UP | | FAULT |
| |<------------| |
+--------+ Timeout +---------+
A | /
| | /
Link-Up | | Link-Down /
| | /
| V /
+--------+ / Link-Down
| | /
| DOWN |<--------/
| |
+--------+
If the fault timer occurs in the DOWN state, we simply ignore it.
After all, without the link the port is useless.
There is one case where the new code changes the existing behavior.
If the link quickly does down and then up again while another fault
(and its timer) are active, then we will enter the UP state without
waiting for the fault timer expiration. However, this behavior is
acceptable because when a link goes up, you are starting with a clean
slate.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We use a hash table to remember the mapping. Since our existing hash
table is a simply string hash, we convert the integer index into a decimal
string. Although hashing integers in this way is sub-optimal, the table
will not be used in a performance critical path.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The time stamping setup code needlessly queries the configuration data
base over and over, rather than simply using the local variable
already assigned. This patch replaces the extraneous config_get_int()
calls with the local variable.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We activate on-step mode based on the "time_stamping" and
"twoStepFlag" configuration options. If twoStepFlag is false and HW
time stamping is enabled, we upgrade the time stamping mode variable
to one-step.
The code that tests the options and sets the one-step mode moved from
ptp4l.c into clock.c in commit 9b27664c ("clock: simplify the create
method."). However, that commit inadvertently moved the test after
the place where the time stamping mode is latched in a local variable.
As a result, one-step mode is not activated when configured.
This patch fixes the issue by keeping the local time stamping mode
variable up to date during the one-step test.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>