{{ :supportukraine.gif|}} ====== PTPd: Time synchronization for (realtime) Linux systems with Tux ====== {{en:tux.png |Hey, my name is "Tux"!}} **Did you ever wonder how you can configure PTPd services on your Linux system?** \\ \\ Hey, my name is "Tux" and this tutorial will show you how you can get //PTPd// up and running to have a reliable time synchronization between all involved ethernet hosts. ---- \\ ===== First thoughts ===== Alternatively to the time synchronization tool //NTP//, which is not useful in a realtime environment, //PTP// was designed. Unlike //NTP//, //PTP// is based on //Multicast// technology (//Master/Slave//) while //NTP// is based on //Client-Server// technology. //PTP// was designed for synchronizing system time between a //PTP// master and one or multiple //PTP// slaves as precise as possible. There do exists two different types of //PTP// applications: hard- **or** software driven applications or even both in a single application. Hardware driven //PTP// applications in general are a lot more reliable than software driven //PTP// applications, especially when used in realtime systems. The disadvantage of hardware driven //PTP// is the requirement for physical hardware that supports //PTP// (dedicated //PTP// clock chip onto master NIC and slaves NIC(s) and optional switches/routers in between). When there is no need for hardware driven //PTP// (for example in test environments) //PTPd// can be used. \\ //PTPd// is a software driven only //PTP// application and therefore it cannot get controlled by dedicated hardware. \\ Advantage: No financial issues but on cost of precision. \\ Beware: //PTPd// is very limited on realtime usability and therefore it should only be used after checking all requirements on the realtime system! For critical realtime applications hardware based //PTP// should always be the first choice. ==== Example of usage ==== {{:en:ptpd01_eng.png?600|}} \\ ===== Start of tutorial ===== ==== Platform independent variants of installation ==== === Ubuntu 14.04 with current version of PTPd from GitHub.com === Download source code files from [[https://github.com/ptpd/ptpd/releases|here]]. Copy source code file into the following directory (replace the following placeholders '''' with corresponding version number according the downloaded file): $ cp ptpd-...tar.gz /opt Navigate into folder ''/opt'': $ cd /opt Extract the ''ptpd-...tar.gz'' file here: $ tar xvzf ptpd-...tar.gz Delete the ''ptpd-...tar.gz'' file: $ rm -rf ptpd-...tar.gz Rename the ''ptpd-..'' folder into ''ptpd'': $ mv "/opt/ptpd-.." /opt/ptpd Navigate into folder ''/opt/ptpd'': $ cd /opt/ptpd Now execute the following commands successively: $ ./configure $ make $ make install Next step is configuring autostart of //PTPd// service on operation system's start. \\ Create a file ''.sh'' inside the ''/usr/local/bin/'' folder... $ vi /usr/local/bin/.sh ...and add the following content (Beware: ''sleep'' is required because of autostart failure if the corresponding networkinterface's drivers are not being loaded fast enough on operating system's start.),... sleep 30 $ sudo /opt/ptpd/src/ptpd2 -M -i $ sudo /opt/ptpd/src/ptpd2 -s -i ...save the file and quit the editor. \\ Now make the file executable: $ chmod +x /usr/local/bin/.sh Now edit the file: $ vi /etc/rc.local __Before__ the already existing entry ''exit 0'' add the following content: /usr/local/bin/.sh exit 0 If there are additional processes required being started via ''rc-.local'' file it is required to separate those processes by an ''&''-symbol. Example: \\ \\ /usr/local/bin/.sh & /usr/local/bin/.sh exit 0 Now save the file and quit the editor. \\ Reboot the system and check if ''ptpd2'' service is running: $ ps -A | grep ptpd2 Beware: When no message appears the service is not running! \\ \\ \\ === Ubuntu 14.04 and 16.04 with PTPd from default repository === == Installation == //pdpd//package installation via default repository: $ apt-get install ptpd Edit the following file... $ vi /etc/default/ptpd ...and change the following default entries according to the following instructions (Beware: case sensitive!) \\ ''START_DAEMON = no'' → change to → ''START_DAEMON = yes'' \\ ''PTPD_OPTS = ""'' → change to → ''PTPD_OPTS = "-M -i "'' \\ ''PTPD_OPTS = ""'' → change to → ''PTPD_OPTS = "-G -h -b "'' \\ ''PTPD_OPTS = ""'' → change to → ''PTPD_OPTS = "-s -i "'' \\ ''PTPD_OPTS = ""'' → change to → ''PTPD_OPTS = "-g -h -b "'' \\ Save the file and quit the editor. \\ Next step is configuring autostart of //PTPd// service on operation system's start. \\ Create a file ''.sh'' inside the ''/usr/local/bin/'' folder... $ vi /usr/local/bin/.sh ...and add the following content (Beware: ''sleep'' is required because of autostart failure if the corresponding networkinterface's drivers are not being loaded fast enough on operating system's start.),... sleep 30 $ sudo ptpd -M -i $ sudo ptpd -G -h -b $ sudo ptpd -s -i $ sudo ptpd -g -h -b ...save the file and quit the editor. \\ Now make the file executable: $ chmod +x /usr/local/bin/.sh Now edit the file: $ vi /etc/rc.local __Before__ the already existing entry ''exit 0'' add the following content: /usr/local/bin/.sh exit 0 If there are additional processes required being started via ''rc-.local'' file it is required to separate processes by an ''&''-symbol. Example: \\ \\ /usr/local/bin/.sh & /usr/local/bin/.sh exit 0 Now save the file and quit the editor. \\ Reboot the system and check if ''ptpd'' service is running: $ service ptpd status As an output message there is a green «light» being generated (there may be a delay of about 10 seconds). As an output message «ptpd is running» is showing up (there may be a delay of about 10 seconds). \\ \\ ==== Troubleshooting and additional information on PTP and PTPd ==== * Whether physical NICs do support hardware driven //PTP// can be checked by executing the following command: $ ethtool -T * Optional: If using a WiFi module as a network interface and it is required to check whether the connection from Linux PC to access point does support //Fast Roaming (802.11 r)// (helpful for realizing uninterruptedly time synchronozation) execute the following commands: $ wpa_cli roam $ wpa_cli scan $ wpa_cli scan_results If for example ''WPA2-PSK+FT'' is being showed then //Fast Roaming// (FT / Fast Transition) is supported. __Beware:__ When //802.11r// is activated on access point it is strongly recommended to activate //802.11k// too (please have a look into the internet for further information ;-)). On top on that, if //FT// is required, access point and NIC drivers for Linux OS must support //FT// technology. * A disconnecton from master to slave and other way around does not affect the //PTPd// runtime service. To be more clear: If //PTP// master is being rebooted the time synchronization will continue after reboot automatically as soon as the //PTP// master has boot up and it's //PTPd// service has started automatically. There is no need for manual restart of //PTP// slave's service. The same for the other way around: When a slave reboots the //PTP// master's service has not to be restarted. \\ \\ * For //PTPd// to operate, it must be run on at least two computers connected through an Ethernet hub or switch or a direct connection. It is possible to have //PTPd// coordinate two (**and only two!**) computers through a routed connection by running //PTPd// on each computer with the ''-u'' argument followed by the IP address of the target computer. \\ \\ * //PTP// can be combined with other time synchronization variants. Example: A //PTP// master can get it's local time periodically by //NTP// (//layer 3//) time server and then distribute it's time via //PTP// to it's slaves. \\ \\ * //PTP// is using //Multicast// by default but can also be configured for //Unicast// operation. \\ ===== End of tutorial ===== \\ \\ Appreciate my work? \\ [[https://www.buymeacoffee.com/fabioU|Buy me a coffee]] {{:buymeacoffee.png|}} or [[https://www.paypal.com/donate/?hosted_button_id=TH8Q3NTJCAJBA|PayPal]] {{:paypal.png|}} \\ \\ **Source(s):** \\ http://ptpd.sourceforge.net/doc.html \\ https://manpages.debian.org/stretch/ptpd/ptpd.8.en.html \\ https://www.youtube.com/watch?v=Forh3XfD_Ec \\ https://de.wikipedia.org/wiki/Precision_Time_Protocol \\ http://www.pdv.reutlingen-university.de/rte/White_paper_ieee1588_de_v1-2.pdf \\ http://manpages.ubuntu.com/manpages/trusty/man8/ptpd.8.html \\ https://gist.github.com/mhaberler/f4809ed2e465912d3534 \\ https://www.endruntechnologies.com/pdf/PTP-1588.pdf \\ https://www.endruntechnologies.com/ptp-ieee-1588-faq.htm \\ https://www.endruntechnologies.com/ptp-slave.htm \\ http://www.en4tel.com/pdfs/NTPandPTP-A-Brief-Comparison.pdf \\ https://www.youtube.com/watch?v=-MK7DcGjjFE \\ https://networkengineering.stackexchange.com/questions/23369/how-to-check-if-a-nic-supports-hardware-timestamps \\ http://linuxptp-users.narkive.com/kYXafDxt/installation-of-linuxptp-on-ubuntu-pc \\ https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/ch-configuring_ptp_using_ptp4l \\ https://www.reddit.com/r/openwrt/comments/515oea/finally_got_80211r_roaming_working/ {{htmlmetatags>metatag-robots=()}}