Time Synchronization Chapter 9 Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/1 Rating • Area maturity First steps Text book • Practical importance No apps Mission critical • Theoretical importance Not really Must have Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/2 Overview • • • • • Motivation Clock Sources Reference-Broadcast Synchronization (RBS) Time-sync Protocol for Sensor Networks (TPSN) Gradient Clock Synchronization Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/3 2. Time Synchronization in Distributed Systems Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/4 Assumptions • Process can perform three kinds of atomic actions/events – Local computation – Send a single message to a single process – Receive a single message from a single process • Communication model – Point-to-point – Error-free, infinite buffer – Potentially out of order Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/5 Motivation • Many protocols need to impose an ordering among events – If two players open the same treasure chest “almost” at the same time, who should get the treasure? • Physical clocks: – Seems to completely solve the problem – But what about theory of relativity? – Even without theory of relativity – efficiency problems Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/6 Physical Clock Synchronization The relation between clock time and UTC when clocks tick at different rates. Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/7 Classification • Types of Synchronization External Synchronization : Keep as close to UTC as possible Internal Synchronization : Mutual synchronization is important • Types of clocks • Unbounded 0, 1, 2, 3, . . . Bounded 0,1, 2, . . . M-1, 0, 1, . . . • Phase Synchronization Unbounded clocks are not realistic, but are easier to deal with in algorithms. Real clocks are always bounded. Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/8 Terminology c l o c k Š clock 1 clock 2 t drift rate= i m e R R Newtonian time • Drift rate : Max rate two clocks can differ, < 10^-6 for Xtal clocks • Clock skew : Max. Allowed drift • Resynchronization interval R : Depends on clock skew • Challenges • • • • (Drift is unavoidable) Accounting for propagation delay Accounting for processing delay Faulty clocks Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/9 Internal synchronization • A simple averaging algorithm c c- i c+ j • Assume n clocks, at most t are faulty • • Step 1. Read every clock in the system. Step 2. Discard outliers and substitute them by the value of the local clock. Step 3. Update the clock using the average of these values. • c-2 k Some clocks may be faulty. Exhibits 2-faced behavior Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/10 Network Time Protocol (NTP) • Level 1 Tiered architecture Time server Level 0 Level 1 Level 1 • • • • • • Broadcast mode - least accurate Procedure call - medium accuracy Peer-to-peer mode - upper level servers use this for max accuracy Level 2 Level 2 Level 2 The tree can reconfigure itself if some node fails. Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/11 P2P mode of NTP T2 Q T3 • Let Q’s time be ahead of P’s time by . Then • • T2 = T1 + TPQ + T4 = T3 + TQP - • y = TPQ + TQP = T2 +T4 -T1 -T3 (RTT) • = (T2 -T4 -T1 +T3) / 2 - (TPQ - TQP) / 2 • P T1 T4 x Between y/2 and -y/2 So, x- y/2 ≤ ≤ x+ y Ping several times, and obtain the smallest value of y. Use it to calculate Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/12 Cristian’s Algorithm • 1. Client gets data from a time server. • 2. It computes the round trip time (RTT), and compensates for this • delay while adjusting its own clock Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/13 Berkeley Time Protocol (FromTanenbaum 2007) a) The time daemon asks all the other machines for their clockvalues. b) The machines answer The time daemon tells everyone how to adjust their clock. Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/14 Software “Clocks” • Software “clocks” can incur much lower overhead than maintaining (sufficiently accurate) physical clocks • Allows a protocol to infer ordering among events • Goal of software “clocks”: Capture event ordering that are visible to users – But what orderings are visible to users without physical clocks? Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/15 Visible Ordering to Users • • • A B (process order) B C (send-receive order) A C (transitivity) A A?D B?D C?D B user1 (process1) C user2 (process2) user3 (process3) D Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/16 “Happened-Before” Relation • “Happened-before” relation captures the ordering that is visible to users when there is no physical clock – A partial order among events – Process-order, send-receive order, transitivity • First introduced by Lamport – Considered to be the first fundamental result in distributed computing • Goal of software “clock” is to capture the above “happened-before” relation. Formally, a logical clock C is a map from the set of events E to N (the set of natural numbers) with the following constraint: Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/17 1: Logical Clocks • Each event has a single integer as its logical clock value – Each process has a local counter C – Increment C at each “local computation” and “send” event – When sending a message, logical clock value V is attached to the message. At each “receive” event, C = max(C, V) + 1 3 = max(1,2)+1 1 4 = max(3,3)+1 3 4 2 user1 (process1) user2 (process2) user3 (process3) 1 1 3 2 4 5 5 Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/18 Logical Clock Properties • Theorem: – Event s happens before t the logical clock value of s is smaller than the logical clock value of t. • The reverse may not be true 1 2 3 4 user1 (process1) user2 (process2) user3 (process3) 1 1 3 2 4 5 5 Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/19 Lamport’s Logical Clock Algorithm Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/20 2: Vector Clocks • Logical clock: • Vector clock: – Event s happens before event t the vector clock value of s is “smaller” than the vector clock value of t. • Each event has a vector of n integers as its vector clock value – v1 = v2 if all n fields same – v1 v2 if every field in v1 is less than or equal to the corresponding field in v2 – v1 < v2 if v1 v2 and v1 ≠ v2 Relation “<“ here is not a total order Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/21 Vector Clock Protocol • • • Each process i has a local vector C Increment C[i] at each “local computation” and “send” event When sending a message, vector clock value V is attached to the message. At each “receive” event, C = pairwise-max(C, V); C[i]++; C = (0,1,0), V = (0,0,2) pairwise-max(C, V) = (0,1,2) (1,0,0) (2,0,0) (3,0,0) user1 (process1) user2 (process2) user3 (process3) (0,1,0) (0,0,1) (0,2,2) (0,0,2) (2,3,2) (2,3,3) Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/22 Vector Clock Properties • • Event s happens before t vector clock value of s < vector clock value of t: There must be a chain from s to t Event s happens before t vector clock value of s < vector clock value of t – If s and t on same process, done – If s is on p and t is on q, let VS be s’s vector clock and VT be t’s – VS < VT VS[p] ≤ VT[p] Must be a sequence of message from p to q after s and before t p q s t Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/23 Example Application of Vector Clock • Each user has an order placed by a customer – Want all users to know all orders • Each order has a vector clock value I have seen all orders whose vector clock is smaller than (2,3,2): I can avoid linear search for existence testing D1, (1,0,0) (2,0,0) (3,0,0) user1 (process1) user2 (process2) user3 (process3) D2, (0,1,0) D3, (0,0,1) (0,2,2) D1 D3 (0,0,2) (2,3,2) D1, D2, D3 (2,3,3) Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/24 Vector Clock Algorithm Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/25 A sample execution of the vector clock algorithm Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/26 Summary • Goal : Define “time” in a distributed system • Logical clock – “happened before” smaller clock value • Vector clock – “happened before” smaller clock value • Matrix clock – Gives a process knowledge about what other processes know Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/27 Motivation • Time synchronization is essential for many applications – – – – – Coordination of wake-up and sleeping times (energy efficiency) TDMA schedules Ordering of collected sensor data/events Co-operation of multiple sensor nodes Estimation of position information (e.g. shooter detection) • Goals of clock synchronization – Compensate offset between clocks – Compensate drift between clocks Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/28 Properties of Synchronization Algorithms • External versus internal synchronization – External sync: Nodes synchronize with an external clock source (UTC) – Internal sync: Nodes synchronize to a common time – to a leader, to an averaged time, or to anything else • Instant versus periodic synchronization – Periodic synchronization required to compensate clock drift • A-priori versus a-posteriori – A-posteriori clock synchronization triggered by an event • Local versus global synchronization Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/29 Clock Sources • Radio Clock Signal: – Clock signal from a reference source (atomic clock) is transmitted over a longwave radio signal – DCF77 station near Frankfurt, Germany transmits at 77.5 kHz with a transmission range of up to 2000 km – Accuracy limited by the distance to the sender, Frankfurt-Zurich is about 1ms. – Special antenna/receiver hardware required • Global Positioning System (GPS): – Satellites continuously transmit own position and time code – Line of sight between satellite and receiver required – Special antenna/receiver hardware required Clock Devices in Sensor Nodes • Structure – External oscillator with a nominal frequency (e.g. 32 kHz) – Counter register which is incremented with oscillator pulses – Works also when CPU is in sleep state • Accuracy Measured Time – Clock drift: random deviation from the nominal rate dependent on power supply, temperature, etc. – E.g. TinyNodes have a maximum drift of 30-50 ppm at room temperature Oscillator Clock with Drift Perfect Clock This is a drift of up to 50 μs per second or 0.18s per hour Jittering Clock Clock with Offset Actual Time Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/31 Sender/Receiver Synchronization • Round-Trip Time (RTT) based synchronization t2 B T im e a c c o r d in g t o B A n s w e r fr o m B R e q u e s t fr o m A A t1 t3 T im e a c c o r d in g t o A t4 • Receiver synchronizes to the sender‘s clock • Propagation delay and clock offset can be calculated (t 4 t1 ) (t3 t2 ) 2 (t (t + δ)) (t 4 (t3 + δ)) (t 2 t1 ) + (t3 t4 ) θ= 2 1 = 2 2 δ= Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/32 Disturbing Influences on Packet Latency • Influences – – – – – Sending Time S Medium Access Time A Transmission Time T Propagation Time PA,B Reception Time R S A (up to 100ms) (up to 500ms) (tens of milliseconds, depending on size) (microseconds, depending on distance) (up to 100ms) T Timestamp TA PA,B R Timestamp TB Critical path • Asymmetric packet delays due to non-determinism • Solution: timestamp packets at MAC Layer Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/33 Reference-Broadcast Synchronization (RBS) • A sender synchronizes a set of receivers with one another • Point of reference: beacon’s arrival time t2 t2 t S A P R 1 S S S ,A A t t S A P R 3 1 S S S ,B B t2 t ( P P ) ( R R ) 3 S ,A S ,B A B A S t1 B t3 • Only sensitive to the difference in propagation and reception time • Time stamping at the interrupt time when a beacon is received • After a beacon is sent, all receivers exchange their reception times to calculate their clock offset • Post-synchronization possible • Least-square linear regression to tackle clock drifts Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/34 Time-sync Protocol for Sensor Networks (TPSN) • Traditional sender-receiver synchronization (RTT-based) • Initialization phase: Breadth-first-search flooding – Root node at level 0 sends out a level discovery packet – Receiving nodes which have not yet an assigned level set their level to +1 and start a random timer – After the timer is expired, a new level discovery packet will be sent – When a new node is deployed, it sends out a level request packet after a random timeout 0 1 1 1 2 2 2 2 Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/35 Time-sync Protocol for Sensor Networks (TPSN) • Synchronization phase – Root node issues a time sync packet which triggers a random timer at all level 1 nodes – After the timer is expired, the node asks its parent for synchronization using a synchronization pulse – The parent node answers with an acknowledgement – Thus, the requesting node knows the round trip time and can calculate its clock offset – Child nodes receiving a synchronization pulse also start a random timer themselves to trigger their own synchronization 0 Time Sync 1 B Sync pulse A 1 ACK 2 2 2 Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/36 Time-sync Protocol for Sensor Networks (TPSN) t t S A P R 2 1 A A A , B B 0 t t S A P R 4 3 B B B ,A A ( S S ) ( A A ) ( P P ) ( R R ) , B B ,A B A A B A B A 2 • • • • t2 B t1 A 1 t3 t4 1 2 2 2 Time stamping packets at the MAC layer In contrast to RBS, the signal propagation time might be negligible Authors claim that it is “about two times” better than RBS Again, clock drifts are taken into account using periodical synchronization messages • Problem: What happens in a non-tree topology (e.g. ring)?!? – Two neighbors may have exceptionally bad synchronization Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/37 Theoretical Bounds for Clock Synchronization • Network Model: – Each node i has a local clock Li(t) – Network with n nodes, diameter D. – Reliable point-to-point communication with minimal delay µ – Jitter ε is the uncertainty in message delay • Two neighboring nodes u, v cannot distinguish whether message is faster from u to v and slower from v to u, or vice versa. Hence clocks of neighboring nodes can be up to off. v 0 1 2 µ+ µ • • 1 0 1 µ+ u 0 v 3 2 3 u 0 1 2 3 µ 2 3 Hence, two nodes at distance D may have clocks which are D off. This can be achieved by a simple flooding algorithm: Whenever a node receives a new minimum value, it sets its clock to the new value and forwards its new clock value to all its neighbors. Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/38 Gradient Clock Synchronization 1. Global property: Minimize clock skew between any two nodes 2. Local (gradient) property: Small clock skew between two nodes if the distance between the nodes is small. 3. Clock should not be allowed to jump backwards You don’t want new events to be registered earlier than older events. Root node • Example: Ring topology 0 1 1 Small clock skew 2 2 3 3 4 Large clock skew Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/39 Trivial Solution: Let t = 0 at all nodes and times 1. Global property: Minimize clock skew between any two nodes 2. Local (gradient) property: Small clock skew between two nodes if the distance between the nodes is small. 3. Clock should not be allowed to jump backwards • To prevent trivial solution, we need a fourth constraint: 4. Clock should always to move forward. • • Sometimes faster, sometimes slower is OK. But there should be a minimum and a maximum speed. Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/40 Gradient Clock Synchronization • Model – Each node has a hardware clock Hi(∙) with a clock rate hi (t ) L,U where 0 < L < U and U ≥ 1 t – The time of node i at time t is Hi (t ) hi (t )dt 0 – Each node has a logical clock Li(∙) which increases at the rate of Hi(∙) – Employ a synchronization algorithm A to update the local clock with fresh clock values from neighboring nodes (clock cannot run backwards) – Nodes inform their neighboring nodes when local clock is updated Time is 152 Time is 142 Time is 140 Time is 150 ??? Ad Hoc and Sensor Networks – Roger Wattenhofer – 9/41 Goals of this chaper • Understand the importance of time synchronization in WSNs • Understand typical strategies for time synchronization and how they are applied in WSNs SS 05 Hoc and Sensor Networks Roger Wattenhofer42 – 9/42 Ad hoc & sensor Ad networs - Ch 8: –Time Overview • • • • The time synchronization problem Protocols based on sender/receiver synchronization Protocols based on receiver/receiver synchronization Summary SS 05 Hoc and Sensor Networks Roger Wattenhofer43 – 9/43 Ad hoc & sensor Ad networs - Ch 8: –Time Overview • • • • The time synchronization problem Protocols based on sender/receiver synchronization Protocols based on receiver/receiver synchronization Summary SS 05 Hoc and Sensor Networks Roger Wattenhofer44 – 9/44 Ad hoc & sensor Ad networs - Ch 8: –Time Example • • • Goal: estimate angle of arrival of a very distant sound event using an array of acoustic sensors From the figure, can be estimated when x and d are known: d is known a priori, x must be estimated from differences in time of arrival – x = C Dt where C is the speed of sound – For d=1 m and Dt=0.001 we get = 0.336 radians – When Dt is estimated with 500 ms error, the estimates can vary between 0.166 and 0.518 • Morale: a seemingly small error in time synch can lead to significantly different angle estimates SS 05 Hoc and Sensor Networks Roger Wattenhofer45 – 9/45 Ad hoc & sensor Ad networs - Ch 8: –Time The role of time in WSNs • Time synchronization algorithms can be used to better synchronize clocks of sensor nodes • Time synchronization is needed for WSN applications and protocols: – Applications: AOA estimation, beamforming – Protocols: TDMA, protocols with coordinated wakeup, ... – Distributed debugging: timestamping of distributed events is needed to figure out their correct order of appearance • WSN have a direct coupling to the physical world, hence their notion of time should be related to physical time: – physical time = wall clock time, real-time, i.e. one second of a WSN clock should be close to one second of real time – Commonly agreed time scale for real time is UTC, generated from atomic clocks and modified by insertion of leap seconds to keep in synch with astronomical timescales (one rotation of earth) – Other concept: logical time (Lamport), where only the relative ordering of events counts but not their relation to real time SS 05 Hoc and Sensor Networks Roger Wattenhofer46 – 9/46 Ad hoc & sensor Ad networs - Ch 8: –Time Clocks in WSN nodes • Often, a hardware clock is present: – An oscillator generates pulses at a fixed nominal frequency – A counter register is incremented after a fixed number of pulses – Only register content is available to software – Register change rate gives achievable time resolution – Node i’s register value at real time t is Hi(t) – Convention: small letters (like t, t’) denote real physical times, capital letters denote timestamps or anything else visible to nodes • A (node-local) software clock is usually derived as follows: – Li(t) = i Hi(t) + fi (not considering overruns of the counter-register) SS 05 47 Hoc and Sensor Networks Roger Wattenhofer Ad hoc & sensor Ad networs - Ch 8: –Time – 9/47 Synchronization accuracy / agreement • External synchronization: – synchronization with external real time scale like UTC – Nodes i=1, ..., n are accurate at time t within bound when |Li(t) – t|< for all i – Hence, at least one node must have access to the external time scale • Internal synchronization – No external timescale, nodes must agree on common time – Nodes i=1, ..., n agree on time within bound when |Li(t) – Lj(t)|< for all i,j SS 05 Hoc and Sensor Networks Roger Wattenhofer48 – 9/48 Ad hoc & sensor Ad networs - Ch 8: –Time Sources of inaccuracies • Nodes are switched on at random times, phases θi hence can be random • Actual oscillators have random deviations from nominal frequency (drift, skew) – Deviations are specified in ppm (pulses per million), the ppm value counts the additional pulses or lost pulses over the time of one million pulses at nominal rate – The cheaper the oscillators, the larger the average deviation – For sensor nodes values between 1 ppm (one second every 11 days) and 100 ppm (one second every 2.8 hours) are assumed, Berkeley motes have an average drift of 40 ppm • Oscillator frequency depends on time (oscillator aging) and environment (temperature, pressure, supply voltage, ...) – Especially the time-dependent drift rates call for frequent resynchronization, as one-time synchronization is not sufficient – However, stability over tens of minutes is often a reasonable assumption SS 05 Hoc and Sensor Networks Roger Wattenhofer49 – 9/49 Ad hoc & sensor Ad networs - Ch 8: –Time General properties of time synchronization algorithms • Physical time vs. logical time • External vs. internal synchronization • Global vs. local algorithms – Keep all nodes of a WSN synchronized or only a local neighbourhood? • Absolute vs. relative time • Hardware vs. software-based mechanisms – A GPS receiver would be a hardware solution, but often too heavyweight/costly/energy-consuming in WSN nodes, and in addition a line-of-sight to at least four satellites is required • A-priori vs. a-posteriori synchronization – Is time synchronization achieved before or after an interesting event? Post-facto synchronization • Deterministic vs. stochastic precision bounds • Local clock update discipline – Should backward jumps of local clocks be avoided? (Users of make say yes here ....) – Avoid sudden jumps? SS 05 Hoc and Sensor Networks Roger Wattenhofer50 – 9/50 Ad hoc & sensor Ad networs - Ch 8: –Time Performance metrics and fundamental structure • Metrics: – Precision: maximum synchronization error for deterministic algorithms, error mean / stddev / quantiles for stochastic ones – Energy costs, e.g. # of exchanged packets, computational costs – Memory requirements – Fault tolerance: what happens when nodes die? • Fundamental building blocks of time synchronization algorithms: – Resynchronization event detection block: when to trigger a time synchronization round? Periodically? After external event? – Remote clock estimation block: figuring out the other nodes clocks with the help of exchanging packets – Clock correction block: compute adjustments for own local clock based on estimated clocks of other nodes – Synchronization mesh setup block: figure out which node synchronizes with which other nodes SS 05 Hoc and Sensor Networks Roger Wattenhofer51 – 9/51 Ad hoc & sensor Ad networs - Ch 8: –Time Constraints for Time Synchronization in WSNs • • • • • An algorithm should scale to large networks of unreliable nodes Quite diverse precision requirements, from ms to tens of seconds Use of extra hardware (like GPS receivers) is mostly not an option low mobility Often there are no fixed upper bounds on packet delivery times (due to MAC delays, buffering, ...) • Negligible propagation delay between neighboring nodes • Manual node configuration is not an option SS 05 Hoc and Sensor Networks Roger Wattenhofer52 – 9/52 Ad hoc & sensor Ad networs - Ch 8: –Time Post-facto synchronization • Basic idea: – Keeping nodes synchronized all the time incurs substantial energy costs due to need for frequent resynchronization – Especially true for networks which become active only rarely – When a node observes an external event at time t, it stores its local timestamp Li(t), achieves synchronization with neighbor node / sink node and converts Li(t) accordingly • Can be implemented in different ways, to be discussed later SS 05 Hoc and Sensor Networks Roger Wattenhofer53 – 9/53 Ad hoc & sensor Ad networs - Ch 8: –Time Overview • • • • The time synchronization problem Protocols based on sender/receiver synchronization Protocols based on receiver/receiver synchronization Summary SS 05 Hoc and Sensor Networks Roger Wattenhofer54 – 9/54 Ad hoc & sensor Ad networs - Ch 8: –Time Protocols based on sender/receiver synchronization • In this kind of protocols, a receiver synchronizes to the clock of a sender • We have to consider two steps: – Pairwise synchronization: how does a single receiver synchronize to a single sender? – Networkwide synchronization: how to figure out who synchronizes with whom to keep the whole network / parts of it synchronized? • The classical NTP protocol [Mills, RFC 1305] belongs to this class SS 05 Hoc and Sensor Networks Roger Wattenhofer55 – 9/55 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Lightweight Time Synchronization • Overall goal: synchronize the clocks of all sensor nodes / of a subset of nodes to one reference clock (e.g. equipped with GPS receivers) • It allows to synchronize the whole network, parts of it and it also supports post-facto synchronization • It considers only phase shifts and does not try to correct different drift rates • Two components: – pairwise synchronization: based on sender/receiver technique – networkwide synchronization: minimum spanning tree construction with reference node as root SS 05 Hoc and Sensor Networks Roger Wattenhofer56 – 9/56 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization i j Trigger resynchronization Format synch packet Timestamp packet with Hand over packet for transmission Operating system, channel access Start packet transmission Propagation delay Packet transmission time Packet reception interrupt Timestamp with Format synch answer packet Timestamp with Hand over packet for transmission OS, Channel access Start packet transmission Packet reception interrupt Timestamp with SS 05 Hoc and Sensor Networks Roger Wattenhofer57 – 9/57 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization • Node i wants to synchronize its clock to node j’s clock • Timeline: – Node i triggers resynchronization at time t0, formats packet, timestamps it at t1 with Li(t1) and hands it over to transmission (with Li(t1) as payload) – At t2 the first bit appears on the channel, at t3 the receiver receives last bit, packet reception is signaled at t4, and at t5 node j timestamps it with Lj(t5) – Node j formats answer packet, timestamps it at time t6 with Lj(t6) and hands it over for transmission – as payload the timestamps Li(t1), Lj(t5) and Lj(t6) are included – The arrival of the answer packet is signaled at time t7 to node i, and i timestamps it afterwards with Li(t8) • After time t8, node i possesses four values: Li(t1), Lj(t5), Lj(t6) and Li(t8) and wants to estimate its clock offset to node j – but how? SS 05 Hoc and Sensor Networks Roger Wattenhofer58 – 9/58 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization • Assumptions: – Node i’s original aim is to estimate the true offset O=D(t1)=Li(t1) – Lj(t1) – During the whole process the drift is negligible the algorithm in fact estimates D(t5) and assumes D(t5) = D(t1) – Propagation delay t the same in both directions, request and answer packets have duration tp, both parameters are known to i • Approach: – Node i estimates D(t5)=Li(t5)-Lj(t5) and therefore needs to estimate Lj(t5), which is generated “somewhere” between t1 and t8 – When t8 – t1 is very small, we might be willing to approximate O Li(t1) – Lj(t5) or as Li(t8) – Lj(t5) • But we can reduce uncertainty: – after t1 we have at least one propagation delay and packet transmission time (for the request packet) – before t8 we have another propagation delay and packet transmission time (for the response packet) – There passes also time between Lj(t5) and Lj(t6), and Li(t5) must be before this interval SS 05 Hoc and Sensor Networks Roger Wattenhofer59 – 9/59 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization • Under the assumption that the remaining uncertainty is allocated equally to both i and j, node i can estimate Lj(t5) as • This means: SS 05 Hoc and Sensor Networks Roger Wattenhofer60 – 9/60 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization -- Discussion • Node i can figure out the offset to node j based on the known values Li(t1), Lj(t5), Lj(t6), Li(t8) • This exchange takes two packets – if node j should also learn about the offset, a third packet is needed from i to j carrying O • The uncertainty is in the interval I = [Li(t1)+t+tp, Li(t8) - t – tp – (Lj(t6) – Lj(t5)], and by picking the mid-point of the interval as Li(t5), the maximum uncertainty is |I|/2 SS 05 Hoc and Sensor Networks Roger Wattenhofer61 – 9/61 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization -- Discussion • Sources of inaccuracies: – – – – MAC delay interrupt latencies upon receiving packets Delays between packet interrupts and timestamping operation Delay in operating system and protocol stack • Improvements: – Let i timestamp its packet after the MAC delay, immediately before transmitting the first bit – This would remove the uncertainty due to i’s operating system / protocol stack and the MAC delay!! – Let j timestamp receive packets as early as possible, e.g. in the interrupt routine – this removes the delay between packet interrupts and timestamping from the uncertainty, and leaves only interrupt latencies these things are hard to do when COTS hardware is used, but easy when full source code of MAC and direct access to hardware are available SS 05 Hoc and Sensor Networks Roger Wattenhofer62 – 9/62 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Pairwise Synchronization – Error Analysis • • Elson et al measured pairwise differences in timestamping times at a set of receivers when timestamping happens in the interrupt routine (Berkeley motes) Estimated distribution: – normal random variable (rv) with zero mean/stddev of 11.1 ms • • Additional assumption: uncertainty on the transmitter side has same distrib. and is independent Hence: – total uncertainty is a zero-mean normal rv with variance 4 s2 – For a normal rv 99% of all outcomes have maximum distance of 2.3s to mean the maximum synchronization error is with 99% probability smaller than 2.3 * 2 * s SS 05 Hoc and Sensor Networks Roger Wattenhofer63 – 9/63 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Networkwide Synchronization • We are given one reference node R, to which all other nodes / a subset of nodes want to synchronize – R’s direct neighbors (level-1 neighbors) synchronize with R – Two-hop (level-2) neighbors synchronize with level-1 neighbors – .... • This way a spanning tree is created • But one should not allow arbitrary spanning trees: – Consider a node i with hop distance hi to the root node – Assume that: – all synchronization errors are independent – all synch errors are identically normally distributed with zero mean and variance 4s2 – Then node i’s synchronization error is a zero-mean normal rv with variance hi 4 s2 – Hence, a minimum spanning tree minimizes synchronization errors SS 05 Hoc and Sensor Networks Roger Wattenhofer64 – 9/64 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Centralized Multihop LTS • Reference node R triggers construction of a spanning tree, it first synchronizes its neighbors, then the first-level neighbors synchronize second-level neighbors and so on • Different distributed algorithms for construction of spanning tree can be used, e.g. DDFS, Echo algorithm • Communication costs: – Costs for construction of spanning tree – Synchronizing two nodes costs 3 packets, synchronizing n nodes costs 3n packets SS 05 Hoc and Sensor Networks Roger Wattenhofer65 – 9/65 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Distributed Multihop LTS • No explicit construction of spanning tree needed, but each node knows identity of reference node(s) and routes to them • When node 1 wants to synchronize with R, an appropriate request travels to R – following this, 4 synchronizes to R, 3 synchronizes to 4, 2 synchronizes to 3, 1 synchronizes to 2 – By-product: nodes 2, 3, and 4 are synchronized with R 1 2 3 5 4 7 R 8 6 • Minimum spanning tree constructed implicitly: node 1 should know shortest route to the closest reference node SS 05 Hoc and Sensor Networks Roger Wattenhofer66 – 9/66 Ad hoc & sensor Ad networs - Ch 8: –Time LTS – Distributed Multihop LTS -- Variations • When node 5 wants to synchronize with R, it can: – issue its own synchronization request using route over 3, 4 and put additional synchronization burden on them – ask in its local neighborhood whether someone is synchronized or has an ongoing synchronization request and benefit from that later on – Enforce usage of path over 7, 8 (path diversification) to also synchronize these nodes • Discussion: – Simulation shows that distributed multihop LTS needs more packets (between 40% and 100%) when all nodes have to be synchronized, even with optimizations – Distributed multihop LTS allows to synchronize only the minimally required set of nodes post-facto synchronization SS 05 Hoc and Sensor Networks Roger Wattenhofer67 – 9/67 Ad hoc & sensor Ad networs - Ch 8: –Time Other Sender-/Receiver-based Protocols • These protocols work similar to LTS, with some differences in: – Method of spanning tree construction – How and when to take timestamps – How to achieve post-facto synchronization • One variant: TPSN (Timing-Sync Protocol for Sensor Nets) – Pairwise-protocol similar to LTS, but timestamping at node i happens immediately before first bit appears on the medium, and timestamping at node j happens in interrupt routine – Spanning tree construction based on level-discovery protocol: – root issues level_discovery packet with level 0 – neighbors assign themselves level 1 + level value from level_discovery – neighbors wait for some random time before they issue level_discovery packets indicating their own level – Nodes missing level_discovery packets for long time ask their neighborhood SS 05 Hoc and Sensor Networks Roger Wattenhofer68 – 9/68 Ad hoc & sensor Ad networs - Ch 8: –Time Overview • • • • The time synchronization problem Protocols based on sender/receiver synchronization Protocols based on receiver/receiver synchronization Summary SS 05 Hoc and Sensor Networks Roger Wattenhofer69 – 9/69 Ad hoc & sensor Ad networs - Ch 8: –Time Overview • • • • The time synchronization problem Protocols based on sender/receiver synchronization Protocols based on receiver/receiver synchronization Summary SS 05 Hoc and Sensor Networks Roger Wattenhofer70 – 9/70 Ad hoc & sensor Ad networs - Ch 8: –Time Summary • Time synchronization is important for both WSN applications and protocols • Using hardware like GPS receivers is typically not an option, so extra protocols are needed • Post-facto synchronization allows for time-synchronization on demand, otherwise clock drifts would require frequent resynchronization and thus a constant energy drain • Some of the presented protocols take significant advantage of WSN peculiarities like: – small propagation delays – the ability to influence the node firmware to timestamp outgoing packets late, incoming packets early • Of course, there are many, many more schemes .... SS 05 Hoc and Sensor Networks Roger Wattenhofer71 – 9/71 Ad hoc & sensor Ad networs - Ch 8: –Time