Clock synchronization across network
A local device sends a first packet to a remote device over a network that includes a first time stamp representing a time of transmission of the first packet at the local device based on a local clock. The local device receives from the remote device a second packet containing an acknowledgement for the first packet, further comprising the first time stamp, a second time stamp representing a time of reception of the first packet at the remote device based on a remote clock, and a third time stamp representing a time of transmission of the second packet based on the remote clock. A difference between the local clock and the remote clock can be computed based on the first, second, third time stamps, and a fourth time stamp representing a time of reception of the second packet at the local device based on the local clock.
1 . A method for clock synchronization between a local device and a remote device over a network, the method comprising:
computing a set of local time shift estimates, wherein each local time shift is computed by:
transmitting a first packet from the local device to the remote device, wherein the first packet is a data packet or a control packet;
receiving a second packet containing an acknowledgement for the first packet, the second packet further containing a first time stamp representing a time of transmission of the first packet based on a local clock of the local device, a second time stamp representing a time of reception of the first packet at the remote device based on a remote clock of the remote device, and a third time stamp representing a time of transmission of the second packet based on the remote clock;
determining a fourth time stamp representing a time of reception of the second packet at the local device based on the local clock; and
computing half of a difference between:
a first elapsed time from the first time stamp to the second time stamp; and
a second elapsed time from the third time stamp to the fourth time stamp;
computing a cumulative average local time shift from the set of local time shift estimates;
computing an overall time shift based on an average of the cumulative average local time shift and a cumulative average remote time shift determined by the remote device, wherein the cumulative average local time shift excludes local time shift estimates corresponding to round trip times above a threshold percentile, or corresponding to packet sizes above a threshold packet size; and
synchronizing the local clock to the remote clock based on the overall time shift.
2 . The method of claim 1 , wherein packet transfers between the local device and the remote device are performed using a multi-path transport protocol.
3 . The method of claim 1 , wherein the overall time shift is updated continuously, or at a periodic interval.
4 . The method of claim 1 , wherein the first packet is the data packet with a variable length, and the first elapsed time is adjusted based on a length of the first packet.
5 . A method, comprising:
sending, from a local device, a first packet to a remote device over a network, the first packet including a first time stamp representing a time of transmission of the first packet at the local device based on a local clock of the local device;
receiving, from the remote device, a second packet containing an acknowledgement for the first packet, the second packet further comprising the first time stamp, a second time stamp representing a time of reception of the first packet at the remote device based on a remote clock of the remote device, and a third time stamp representing a time of transmission of the second packet based on the remote clock;
computing a local time shift estimate representing a difference between the local clock and the remote clock based on the first time stamp, the second time stamp, the third time stamp, and a fourth time stamp representing a time of reception of the second packet at the local device based on the local clock; and
determining an overall time shift between the local clock and the remote clock based on a cumulative average local time shift computed from the local time shift estimate and previously computed local time shift estimates, wherein the overall time shift is updated based on a weighted sum of previously determined overall time shifts.
6 . The method of claim 5 , wherein the local time shift estimate is computed further based on a size of the first packet and a reception bandwidth of the remote device.
7 . The method of claim 5 , wherein the local time shift estimate is computed further based on a latency between recording the first time stamp for the first packet and transmitting a first bit of the first packet onto the network.
8 . The method of claim 5 , wherein the overall time shift is determined by averaging the cumulative average local time shift and a cumulative average remote time shift determined by the remote device.
9 . The method of claim 5 , wherein the first packet and the second packet are transmitted over the network using a multi-path transport protocol.
10 . The method of claim 5 , wherein the cumulative average local time shift excludes local time shift estimates corresponding to round trip times above a threshold percentile.
11 . The method of claim 5 , wherein the cumulative average local time shift excludes local time shift estimates corresponding to packet sizes above a threshold packet size.
12 . The method of claim 5 , wherein the overall time shift is determined continuously, or at a periodic interval.
13 . A local network device, comprising:
a time stamp generator configured to:
generate a first time stamp representing a time of transmission of a first packet at the local network device based on a local clock of the local network device;
a transmitter (TX) interface configured to:
send the first packet to a remote network device over a network, the first packet including the first time stamp;
a receiver (RX) interface configured to:
receive a second packet containing an acknowledgement for the first packet from the remote network device, the second packet further comprising the first time stamp, a second time stamp representing a time of reception of the first packet at the remote network device based on a remote clock of the remote network device, and a third time stamp representing a time of transmission of the second packet based on the remote clock,
the time stamp generator further configured to:
generate a fourth time stamp representing a time of reception of the second packet at the local network device based on the local clock; and
a time shift estimator configured to:
compute a local time shift estimate representing a difference between the local clock and the remote clock based on the first time stamp, the second time stamp, the third time stamp, and the fourth time stamp; and
determine an overall time shift between the local clock and the remote clock based on a cumulative average local time shift computed from the local time shift estimate and previously computed local time shift estimates, wherein the cumulative average local time shift excludes local time shift estimates corresponding to round trip times above a threshold percentile, or corresponding to packet sizes above a threshold packet size.
14 . The local network device of claim 13 , wherein the first packet is a data packet, and the time shift estimator computes the local time shift estimate based on a size of the data packet and a data reception bandwidth of the remote network device.
15 . The local network device of claim 13 , wherein the time shift estimator computes the local time shift estimate based on a latency between recording the first time stamp for the first packet and transmitting a first bit of the first packet onto the network.
16 . The local network device of claim 13 , wherein the time shift estimator determines the overall time shift by averaging the cumulative average local time shift and a cumulative average remote time shift determined by the remote network device.
17 . The local network device of claim 13 , wherein the time shift estimator determines the overall time shift continuously, or at a periodic interval.
18 . The local network device of claim 13 , wherein the time shift estimator updates the overall time shift based on a weighted sum of previously determined overall time shifts.
19 . The local network device of claim 13 , wherein the first time stamp is included in a packer header of the first packet.
20 . The local network device of claim 13 , wherein the first, second, and third time stamps are included in a packer header of the second packet.