Discussion Thread

The issue is that there's no hard definition for latency (Do you want median? Geometric mean? The time that the last packet took to arrive? Do you need round-trip latency or latency from just A->B? etc.,)

In either case, calculating round-trip latency is simple enough: a basic ping captures that well.

Let timeToB = the time it takes for device A's bits to reach device B.

Let timeToA = the time it takes for B to respond back.

Let RTT = timeToB + timeToA.

Calculate RTT by looking at the time, sending a ping from A to B, then when the packet comes back, subtracting current time from the time you sent the first packet. This is trivial enough and you probably didn't need that explained.

timeToB should approximate timeToA and so RTT/2 should approximate both values--but let's assume that that's not the case. (Note: NTP assumes this is a mostly valid assumption, so it's probably safe to assume. Regardless...)

If it's not the case, you NEED a central server as a point of reference. You say you don't have one, but that's (probably) not entirely true; assuming this is going over a traditional network, you have to have a router of some sort.

The IPv4 specification includes, for ICMP, an option to enable timestamp recording. If the routers in your environment properly support recording timestamps, you can solve for timeToB and timeToA.

To find timeToB, store node A's time and send an ICMP with timestamp recording to the router and get the receive timestamp back. The round trip latency to the router is thus timeOfRouterPong_A - timeOfRouterPing_A. The latency from A to the router is receiveTime_A - timeOfRouterPing_A - clockErrorFromNodeAToRouter_A.

We want to find timeToB. timeToB = the latencies of a->router + router->B

That gives us timeToB = receiveTime_A - timeOfRouterPing_A + clockErrorFromNodeAToRouter_A + receiveTime_B - timeOfRouterPing_B + clockErrorFromNodeAToRouter_B.

We need to solve for clockErrorFromNodeAToRouter_A and clockErrorFromNodeAToRouter_B to get timeToB. This is been left as an exercise for the reader is easier than it sounds.

You take the RTT

clockErrorFromNodeAToRouter_A is just equal to

To get clockErrorFromNodeAToRouter_A and clockErrorFromNodeAToRouter_B, we just need to send some packets that make the router's time differences clear.

Sorry if the explanation is confusing :P

/r/neoliberal Thread Parent