// Module included in the following assemblies:
//
// * networking/ptp/configuring-ptp.adoc

:_mod-docs-content-type: PROCEDURE
[id="configuring-linuxptp-services-as-ordinary-clock_{context}"]
= Configuring linuxptp services as an ordinary clock

[role="_abstract"]
You can configure `linuxptp` services (`ptp4l`, `phc2sys`) as ordinary clock by creating a `PtpConfig` custom resource (CR) object.

[NOTE]
====
Use the following example `PtpConfig` CR as the basis to configure `linuxptp` services as an ordinary clock for your particular hardware and environment.
This example CR does not configure PTP fast events.
To configure PTP fast events, set appropriate values for `ptp4lOpts`, `ptp4lConf`, and `ptpClockThreshold`. `ptpClockThreshold` is required only when events are enabled.
See "Configuring the PTP fast event notifications publisher" for more information.
====

.Prerequisites

* Install the OpenShift CLI (`oc`).
* Log in as a user with `cluster-admin` privileges.
* Install the PTP Operator.

.Procedure

. Create the following `PtpConfig` CR, and then save the YAML in the `ordinary-clock-ptp-config.yaml` file.
+
[[ptp-ordinary-clock]]
.Example PTP ordinary clock configuration
[source,yaml]
----
include::snippets/ptp_PtpConfigOrdinaryClock.yaml[]
----
+
.PTP ordinary clock CR configuration options
[cols="1,3" options="header"]
|====
|CR field
|Description

|`name`
|The name of the `PtpConfig` CR.

|`profile`
|Specify an array of one or more `profile` objects. Each profile must be uniquely named.

|`interface`
|Specify the network interface to be used by the `ptp4l` service, for example `ens787f1`.

|`ptp4lOpts`
|Specify system config options for the `ptp4l` service, for example `-2` to select the IEEE 802.3 network transport. The options should not include the network interface name `-i <interface>` and service config file `-f /etc/ptp4l.conf` because the network interface name and the service config file are automatically appended. Append `--summary_interval -4` to use PTP fast events with this interface.

|`phc2sysOpts`
|Specify system config options for the `phc2sys` service. If this field is empty, the PTP Operator does not start the `phc2sys` service. For Intel Columbiaville 800 Series NICs, set `phc2sysOpts` options to `-a -r -m -n 24 -N 8 -R 16`. `-m` prints messages to `stdout`. The `linuxptp-daemon` `DaemonSet` parses the logs and generates Prometheus metrics.

|`ptp4lConf`
|Specify a string that contains the configuration to replace the default `/etc/ptp4l.conf` file. To use the default configuration, leave the field empty.

|`tx_timestamp_timeout`
|For Intel Columbiaville 800 Series NICs, set `tx_timestamp_timeout` to `50`.

|`boundary_clock_jbod`
|For Intel Columbiaville 800 Series NICs, set `boundary_clock_jbod` to `0`.

|`ptpSchedulingPolicy`
|Scheduling policy for `ptp4l` and `phc2sys` processes. Default value is `SCHED_OTHER`. Use `SCHED_FIFO` on systems that support FIFO scheduling.

|`ptpSchedulingPriority`
|Integer value from 1-65 used to set FIFO priority for `ptp4l` and `phc2sys` processes when `ptpSchedulingPolicy` is set to `SCHED_FIFO`. The `ptpSchedulingPriority` field is not used when `ptpSchedulingPolicy` is set to `SCHED_OTHER`.

|`ptpClockThreshold`
|Optional. If `ptpClockThreshold` is not present, default values are used for the `ptpClockThreshold` fields. `ptpClockThreshold` configures how long after the PTP master clock is disconnected before PTP events are triggered. `holdOverTimeout` is the time value in seconds before the PTP clock event state changes to `FREERUN` when the PTP master clock is disconnected. The `maxOffsetThreshold` and `minOffsetThreshold` settings configure offset values in nanoseconds that compare against the values for `CLOCK_REALTIME` (`phc2sys`) or master offset (`ptp4l`). When the `ptp4l` or `phc2sys` offset value is outside this range, the PTP clock state is set to `FREERUN`. When the offset value is within this range, the PTP clock state is set to `LOCKED`.

|`recommend`
|Specify an array of one or more `recommend` objects that define rules on how the `profile` should be applied to nodes.

|`.recommend.profile`
|Specify the `.recommend.profile` object name defined in the `profile` section.

|`.recommend.priority`
|Set `.recommend.priority` to `0` for ordinary clock.

|`.recommend.match`
|Specify `.recommend.match` rules with `nodeLabel` or `nodeName` values.

|`.recommend.match.nodeLabel`
|Set `nodeLabel` with the `key` of the `node.Labels` field from the node object by using the `oc get nodes --show-labels` command.
For example, `node-role.kubernetes.io/worker`.

|`.recommend.match.nodeName`
|Set `nodeName` with the value of the `node.Name` field from the node object by using the `oc get nodes` command.
For example, `compute-1.example.com`.
|====

. Create the `PtpConfig` CR by running the following command:
+
[source,terminal]
----
$ oc create -f ordinary-clock-ptp-config.yaml
----

.Verification

. Check that the `PtpConfig` profile is applied to the node.

.. Get the list of pods in the `openshift-ptp` namespace by running the following command:
+
[source,terminal]
----
$ oc get pods -n openshift-ptp -o wide
----
+
.Example output
[source,terminal]
----
NAME                            READY   STATUS    RESTARTS   AGE   IP               NODE
linuxptp-daemon-4xkbb           1/1     Running   0          43m   10.1.196.24      compute-0.example.com
linuxptp-daemon-tdspf           1/1     Running   0          43m   10.1.196.25      compute-1.example.com
ptp-operator-657bbb64c8-2f8sj   1/1     Running   0          43m   10.129.0.61      control-plane-1.example.com
----

.. Check that the profile is correct. Examine the logs of the `linuxptp` daemon that corresponds to the node you specified in the `PtpConfig` profile. Run the following command:
+
[source,terminal]
----
$ oc logs linuxptp-daemon-4xkbb -n openshift-ptp -c linuxptp-daemon-container
----
+
.Example output
[source,terminal]
----
I1115 09:41:17.117596 4143292 daemon.go:107] in applyNodePTPProfile
I1115 09:41:17.117604 4143292 daemon.go:109] updating NodePTPProfile to:
I1115 09:41:17.117607 4143292 daemon.go:110] ------------------------------------
I1115 09:41:17.117612 4143292 daemon.go:102] Profile Name: profile1
I1115 09:41:17.117616 4143292 daemon.go:102] Interface: ens787f1
I1115 09:41:17.117620 4143292 daemon.go:102] Ptp4lOpts: -2 -s
I1115 09:41:17.117623 4143292 daemon.go:102] Phc2sysOpts: -a -r -n 24
I1115 09:41:17.117626 4143292 daemon.go:116] ------------------------------------
----
