NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

34
NTP Network Time Protocol Nóirín Plunkett

Transcript of NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Page 1: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

NTPNTP

Network Time Protocol

Nóirín Plunkett

Network Time Protocol

Nóirín Plunkett

Page 2: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

A Short French LessonA Short French Lesson

TAI – Temps Atomique International International Atomic Time

UTC – Temps Universel Coordonné Universal Co-ordinated Time

BIH – Bureau International de l’Heure International Time Bureau

TAI – Temps Atomique International International Atomic Time

UTC – Temps Universel Coordonné Universal Co-ordinated Time

BIH – Bureau International de l’Heure International Time Bureau

Page 3: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

SecondSecond

SI Unit 9,192,631,770 periods of the radiation

corresponding to the transition between the two hyperfine levels of the ground state of the caesium-133 atom

SI Unit 9,192,631,770 periods of the radiation

corresponding to the transition between the two hyperfine levels of the ground state of the caesium-133 atom

Page 4: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Brief History of TimeBrief History of Time

Second defined in 1967 UTC started on 1st January 1972 RFC 778, 1981 - Internet Clock Service RFC 958, 1985 - description of NTP RFC 1059, 1988 - NTPv1, protocol & algorithms RFC 1305, 1992 - NTPv3, formal correctness

principles NTPv4 in use, not yet formalised

Second defined in 1967 UTC started on 1st January 1972 RFC 778, 1981 - Internet Clock Service RFC 958, 1985 - description of NTP RFC 1059, 1988 - NTPv1, protocol & algorithms RFC 1305, 1992 - NTPv3, formal correctness

principles NTPv4 in use, not yet formalised

Page 5: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Real WorldReal World

“Time is what prevents everything from happening at once.” - J.A. Wheeler

Correlating logs of events Cryptographic expiries Air Traffic Control GPS Networking

“Time is what prevents everything from happening at once.” - J.A. Wheeler

Correlating logs of events Cryptographic expiries Air Traffic Control GPS Networking

Page 6: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Atomic TimeAtomic Time

260 atomic clocks in 40 labs contribute to the international time standards contribute to TAI

Radio broadcasts DCF77, Physikalisch-Technische

Bundesanstalt, Braunschweig (77.5kHz) GPS based on US Naval Observatory, DC

260 atomic clocks in 40 labs contribute to the international time standards contribute to TAI

Radio broadcasts DCF77, Physikalisch-Technische

Bundesanstalt, Braunschweig (77.5kHz) GPS based on US Naval Observatory, DC

Page 7: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

NTP and UTCNTP and UTC

NTP is based on UTC NTP has no memory Every leap-second, NTP ‘resets’ itself to the

current UTC value Using a clock synchronised to UTC in 2005

to calculate the time of an event in early 1972 would result in 22 seconds difference

NTP is based on UTC NTP has no memory Every leap-second, NTP ‘resets’ itself to the

current UTC value Using a clock synchronised to UTC in 2005

to calculate the time of an event in early 1972 would result in 22 seconds difference

Page 8: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

What NTP DoesWhat NTP Does Provide most accurate time possible, based on ‘reference

time’ - not just syncing to a common time

Keep in sync with leap seconds

Ignore ‘falsetickers’ - clocks it could use for reference, but which provide an apparently wrong time

Use previous figures to estimate current difference between system time and reference time, in the absence of a network connection

Provide most accurate time possible, based on ‘reference time’ - not just syncing to a common time

Keep in sync with leap seconds

Ignore ‘falsetickers’ - clocks it could use for reference, but which provide an apparently wrong time

Use previous figures to estimate current difference between system time and reference time, in the absence of a network connection

Page 9: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

What NTP Does NotWhat NTP Does Not

Convert NTP timestamps into system time format

Set the hardware clock

Handle time-zones/summer time

Recognise when the system clock is far off and accept apparent ‘falsetickers’ as true

Convert NTP timestamps into system time format

Set the hardware clock

Handle time-zones/summer time

Recognise when the system clock is far off and accept apparent ‘falsetickers’ as true

Page 10: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Some DefinitionsSome Definitions

Reference clock - a device which gives a known accurate time

Accuracy - the difference between the value of a measurement and the actual measurand

Precision - how close two measurements of the same value are

Reference clock - a device which gives a known accurate time

Accuracy - the difference between the value of a measurement and the actual measurand

Precision - how close two measurements of the same value are

Page 11: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Precision vs AccuracyPrecision vs Accuracy

Exp I - Imprecise, inaccurate

Exp II - Imprecise, accurate

Exp III - Precise, inaccurate

Exp IV - Precise, accurate

Exp I - Imprecise, inaccurate

Exp II - Imprecise, accurate

Exp III - Precise, inaccurate

Exp IV - Precise, accurate

(image source)

Page 12: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

NTP PacketNTP Packet

UDP Packet Request

Time of client system clock at sending

Response Time of client system clock at sending Time of receipt at server Time of server system clock at sending

UDP Packet Request

Time of client system clock at sending

Response Time of client system clock at sending Time of receipt at server Time of server system clock at sending

Page 13: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

NTP TimestampNTP Timestamp

64-bit number First 32 bits represent seconds since 00:00,

January 1st, 1900 Next 32 bits represent fractions of a second

Sat, Nov 19 2005 19:27:30.869 c729fb22.de8afc9d 11000111 00101001 11111011 00100010 .

11011110 10001010 11111100 10011101

64-bit number First 32 bits represent seconds since 00:00,

January 1st, 1900 Next 32 bits represent fractions of a second

Sat, Nov 19 2005 19:27:30.869 c729fb22.de8afc9d 11000111 00101001 11111011 00100010 .

11011110 10001010 11111100 10011101

Page 14: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

More DefinitionsMore Definitions

Latency - the time taken for a packet to reach its destination

Round trip time - the time taken between the client sending out a packet, and receiving a response to that packet from the server

Jitter - variability of latency over time

Latency - the time taken for a packet to reach its destination

Round trip time - the time taken between the client sending out a packet, and receiving a response to that packet from the server

Jitter - variability of latency over time

Page 15: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Timestamps in PacketsTimestamps in Packets

Client sends packet - T1

Server receives packet, adds receipt timestamp - T2

Server prepares packet to send to client, adds sending timestamp - T3

Client receives packet - T4

Latency client -> server = (T2-T1) Latency server -> client = (T4-T3)

Client sends packet - T1

Server receives packet, adds receipt timestamp - T2

Server prepares packet to send to client, adds sending timestamp - T3

Client receives packet - T4

Latency client -> server = (T2-T1) Latency server -> client = (T4-T3)

Page 16: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Round Trip TimesRound Trip Times

Actual RTT = (T4-T1)

Network RTT = (T2-T1) + (T4-T3)

Latencies = (T2-T1), (T4-T3)

If latencies are symmetric (within reason), (T1+T4) = (T2+T3)

If (T1+T4) != (T2+T3), our estimate of clock offset is (T1+T4) - (T2+T3)

Actual RTT = (T4-T1)

Network RTT = (T2-T1) + (T4-T3)

Latencies = (T2-T1), (T4-T3)

If latencies are symmetric (within reason), (T1+T4) = (T2+T3)

If (T1+T4) != (T2+T3), our estimate of clock offset is (T1+T4) - (T2+T3)

Page 17: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Truechimers & FalsetickersTruechimers & Falsetickers

Multiple servers providing time estimates If the majority of servers provide a

consistent time - they’re probably right If there are one or two outliers - they’re

probably wrong

Multiple servers providing time estimates If the majority of servers provide a

consistent time - they’re probably right If there are one or two outliers - they’re

probably wrong

Page 18: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

PeeringPeering

Client should peer with multiple servers Client should peer with multiple servers

(image source)

Page 19: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Law of AveragesLaw of Averages

Peering with multiple servers makes for more reliable results Falsetickers will be easier to identify Truechimers will be more useful (because more servers

means we can dismiss borderline true/false)

Assumptions become statistically more reliable Latency symmetry Clock regularity

Peering with multiple servers makes for more reliable results Falsetickers will be easier to identify Truechimers will be more useful (because more servers

means we can dismiss borderline true/false)

Assumptions become statistically more reliable Latency symmetry Clock regularity

Page 20: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Problems with PeeringProblems with Peering

Loops NTP prevents loops, through spanning-tree

mechanism

Layers NTP prevents there being more than fourteen

layers, by using strata

Loops NTP prevents loops, through spanning-tree

mechanism

Layers NTP prevents there being more than fourteen

layers, by using strata

Page 21: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

StrataStrata

Radio clock - Stratum 0 Computer running NTP syncing from radio

clock - Stratum 1 Computer syncing from Stratum n NTP

server - Stratum n+1 Server unreachable - Stratum 16

Radio clock - Stratum 0 Computer running NTP syncing from radio

clock - Stratum 1 Computer syncing from Stratum n NTP

server - Stratum n+1 Server unreachable - Stratum 16

Page 22: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Lies, Damn LiesLies, Damn Lies

NTP checks that values are consistent with previous measurements Deals with sudden changes in network/system load

Allows NTP to ‘guess’, in case of network failure If values are very different from previously, but

remain consistent, NTP accepts that local clock may be falseticker

NTP checks that values are consistent with previous measurements Deals with sudden changes in network/system load

Allows NTP to ‘guess’, in case of network failure If values are very different from previously, but

remain consistent, NTP accepts that local clock may be falseticker

Page 23: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

ClocksClocks

Hardware clock - quartz crystal Software clock - interrupt-driven timer

chips Software clock more accurate for judging

interval between two times Both need to be set to correct time

Hardware clock - quartz crystal Software clock - interrupt-driven timer

chips Software clock more accurate for judging

interval between two times Both need to be set to correct time

Page 24: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

ProblemsProblems

Inaccurate time needs to be corrected Massive time changes are undesirable Time travel is undesirable

Skipping seconds is bad Going backwards is not allowed

Best way of balancing all this is to slow down/speed up time This only works with computers, and in the

movies!

Inaccurate time needs to be corrected Massive time changes are undesirable Time travel is undesirable

Skipping seconds is bad Going backwards is not allowed

Best way of balancing all this is to slow down/speed up time This only works with computers, and in the

movies!

Page 25: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

ExceptionsExceptions

On system boot-up, time can be set, regardless of offset from previous time init scripts are aware of this, bootup expects it,

nothing should break

Computers do what they’re told - regardless of what the admin intended If an admin tells the system to update its time, it

updates. Things may break.

On system boot-up, time can be set, regardless of offset from previous time init scripts are aware of this, bootup expects it,

nothing should break

Computers do what they’re told - regardless of what the admin intended If an admin tells the system to update its time, it

updates. Things may break.

Page 26: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Phase Lock LoopsPhase Lock Loops Raises (or lowers) frequency of an oscillator until it matches a

reference frequency Pauses oscillator as necessary to match ref. phase

Raises (or lowers) frequency of an oscillator until it matches a reference frequency

Pauses oscillator as necessary to match ref. phase

Page 27: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

More on PLLMore on PLL

Seconds can be speeded up or slowed down, until they happen as often as reference clock - frequency is matched

NTP can also use this speed change to match the phase - some PLLs will stop the oscillator momentarily to do this

Seconds can be speeded up or slowed down, until they happen as often as reference clock - frequency is matched

NTP can also use this speed change to match the phase - some PLLs will stop the oscillator momentarily to do this

Page 28: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

NTP TrafficNTP Traffic

ntp.maths.tcd.ie

Stratum 1 server, syncing from radio clock

ntp.maths.tcd.ie

Stratum 1 server, syncing from radio clock

Page 29: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Daily PeakDaily Peak

Graph dates from IST - blip occurring at 1am local time

Graph dates from IST - blip occurring at 1am local time

Page 30: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

After IST EndsAfter IST Ends

Peak remains - still at midnight GMT Peak remains - still at midnight GMT

Page 31: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Daylight Savings TimeDaylight Savings Time

NTP is time-zone agnostic NTP is time-zone agnostic

Page 32: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Daylight Savings Time EndsDaylight Savings Time Ends

2005-W43-7 - Daylight Savings Time ends 2005-W43-7 - Daylight Savings Time ends

Page 33: NTP Network Time Protocol Nóirín Plunkett Network Time Protocol Nóirín Plunkett.

Strange HappeningsStrange Happenings