Thursday, March 12, 2015

Precision Time Protocol PTP - Demystified

As Network Engineers we build highways (maybe Bundesautobahn where there are no speed limits) on top of which various protocols travel. As designers/architects, perhaps it would be beneficial for us to understand what is traveling on the highways we build.

I started to dip my feet into PTP and I realized there is more to PTP than meets the eye. I also realized that I knew very little about its operations so I decided instead of dipping my feet why not just dive right in -- head first. As any curious person would do, I started to read the RFCs and white papers. But before we get into PTP's operation, let's define a handful of key terms.

Key Terms

Grandmaster - Clock source which is elected as the GrandMaster through BMCA (Best Master Clock Algorithm)
Boundary Clock - Clocks that SYNC their own clocks and act as Masters if needed.
Transparent Clock (P2P and E2E) - Clocks that merely pass the PTP messages but actively update the PTP messages with the residence time of the PTP packets in the switch. Residence time is the amount of time spent by the PTP packet on the switch as it traverses the switch.
Ordinary / Slave Clock - Clocks that just listen and adjust their own clock based on Master/Grandmaster clocks
One-Step - In this mode, Follow up messages are not used and therefore not sent by the GM/Master. SYNC message contains the precise timestamp needed for the Slave to calculate offset.
Two-Step - In this mode, Follow up messages are used and therefore sent by the GM/Master and it contains the precise timestamp of when the SYNC message was sent.

PTP Management Messages

Sync
- Contains the TimeStamp of when the packet was sent.
Follow up
- Contains the most accurate TimeStamp of when the SYNC was sent. This message is only needed in Two-Step Mode.
Delay Request - Request sent by the slave to calculate the one-way delay between SLAVE_TO_MASTER.
Delay Response
- Contains the TimeStamp of when the GM/Master received the Delay Request. This can then be used by the Slave to calculate the one-way delay.

PTP Formula


This formula can be written in many ways but the one I use is ( 0.5 (T1 - T2 - T3 + T4) )

How does a PTP Slave sync to the GM (Grandmaster) / Master?



This blogtorial is meant to serve as an introduction to Precision Time Protocol (PTP) and as such omits advanced topics such as how to deal with Asymmetrical delay and so on. If you are interested, read IEEE RFCs to get a deeper understanding about PTP. I will post subsequent articles on PTP - Boundary Clock, and PTP Transparent clocks etc.

Many more articles to come so ....

Please subscribe/comment/+1 if you like my posts as it keeps me motivated to write more and spread the knowledge.

"Don't tell me you don't have time. That's just an excuse made by lazy people who don't want it bad enough. Honestly you make time for what you really want to do. You want to spend time with the ones you love, you'll find the time. You want to study and better your best, you'll find the time. And if you cant find the time, then make the time."