NesC Language Overview History 5 NesC Language Overview 6 TinyOS: Operating System for WSNs 7 Demonstration 8 J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
NesC: Programming Language for Embedded Systems Programming language: a dialect/extension of C static memory allocation only (no malloc/free) whole-program analysis, efficient optimization race condition detection Implementation: pre-processor – output is a C-program, that is compiled using gcc for the specific platform statically linking functions For more details, see [ ? ] J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
NesC — Interfaces commands can be called by other modules think functions events signalled by other modules have to be handled by this module Interface Example interface Send { command error_t send(message_t* msg, uint8_t len); event void sendDone(message_t* msg, error_t error); ... } J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
NesC — Components a NesC application consists of components components provide and use interfaces components can be accessed only via interfaces (cannot call an arbitrary C-function from another module) Figure: NesC Interface J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
NesC — Components modules – implement interfaces configurations – connect modules together via their interfaces ( wiring ) Figure: NesC Configuration J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
NesC — Concurrency — Tasks Define a Task task void task_name() { ... } Post a Task post task_name(); posting a task – the task is placed on an internal task queue which is processed in FIFO order a task runs to completion before the next task is run, i.e. tasks do not preempt each other tasks can be preempted by hardware events J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS: Operating System for WSNs History 5 NesC Language Overview 6 TinyOS: Operating System for WSNs 7 Demonstration 8 J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS written in nesC event-driven architecture no kernel/user space differentiation single shared stack no process or memory management no virtual memory multi-layer abstractions components statically linked together J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS — Functionality hardware abstraction access to sensors access to actuators scheduler (tasks, hardware interrupts) timer radio interface Active Messages (networking) storage (using flash memory on the motes) . . . J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Demonstration History 5 NesC Language Overview 6 TinyOS: Operating System for WSNs 7 Demonstration 8 J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS — Demo — Blink no screen on which we could print “Hello World” let’s blink an led instead using a timer to blink an led 2 source files BlinkC.nc BlinkAppC.nc J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
BlinkC.nc module BlinkC { uses interface Timer<TMilli> as Timer0; uses interface Leds; uses interface Boot; } implementation { event void Boot.booted() { call Timer0.startPeriodic(250); } event void Timer0.fired() { call Leds.led0Toggle(); } } J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
BlinkAppC.nc configuration BlinkAppC { } implementation { components MainC, BlinkC, LedsC; components new TimerMilliC() as Timer0; BlinkC -> MainC.Boot; BlinkC.Timer0 -> Timer0; BlinkC.Leds -> LedsC; } J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS — Demo — Blink in reality using 3 timers 250 ms 500 ms 1000 ms each timer toggling one led the result is a 3-bit counter J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS — Demo — Oscilloscope motes – periodically get a sensor reading and broadcast over the radio BaseStation mote – forward packets between the radio and the serial interface PC - java application reading packets from the serial interface and plotting sensor readings Figure: Oscilloscope Setup J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
TinyOS — Demo — Oscilloscope node ID sensor 7 light 8 light 18 temperature temperature = − 38 . 4 + 0 . 0098 ∗ data J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
References D. Gay, P. Levis, R. von Behren, M. Welsh, E. Brewer, and D. Culler. The nesC Language: A Holistic Approach to Networked Embedded Systems. In PLDI03 . ACM, June 2003. K. R¨ omer and F. Mattern. The Design Space of Wireless Sensor Networks. IEEE Wireless Communications , 11(6):54–61, December 2004. A. Wheeler. Commercial Applications of Wireless Sensor Networks using ZigBee. IEEE Communications Magazine , 45(4):70–77, April 2007. L. D. Nardis and M.-G. Di Benedetto. Overview of the IEEE 802.15.4/4a standards for low data rate Wireless Personal Data Networks. In Proc. of the 4th IEEE Workshop on Positioning, Navigation and Communication 2007 (WPNC’07) , Hannover, March 2007. IEEE. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Part: Distributed Algorithms Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Transition System Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Transition System Definition (transition system) A transition system is a triple S = ( C , → , I ) where C is a set of configurations, → is a binary transition relation on C , and I is a subset of C of initial configurations. Definition (execution) Let S = ( C , → , I ) be a transition system. An execution of S is a maximal sequence E = ( γ 0 , γ 1 , . . . ), where γ 0 ∈ I and γ i → γ i +1 for all i ≥ 0. Notes A transition relation is a subset of C × C . The notation γ → δ is used for ( γ, δ ) ∈→ , J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Transition System Definition (reachability) Configuration δ is reachable from γ , notation γ � δ , if there exists a sequence γ = γ 0 , γ 1 , . . . , γ k = δ with γ i → γ i +1 for all 0 ≤ i < k . Notes A terminal configuration is a configuration γ for which there is no δ such that γ → δ A sequence E ( γ 0 , γ 1 , . . . ) with γ i → γ i +1 for all i is maximal if it is either infinite or ends in a terminal configuration Configuration δ is said to be reachable if it is reachable from an initial configuration. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Local and Distributed Algorithms Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Local Algorithm Definition (local algorithm) The local algorithm of a process is a quintuple ( Z , I , ⊢ i , ⊢ s , ⊢ r ), where Z is a set of states, I is a subset of Z of initial states, ⊢ i is a relation on Z × Z , and ⊢ s and ⊢ r are relations on Z × M × Z . The binary relation ⊢ on Z is defined by ⇒ ( c , d ) ∈⊢ i ∨∃ m ∈ M (( c , m , d ) ∈ ( ⊢ s ∪ ⊢ r )) . c ⊢ d ⇐ Notes Let M be a set of possible messages. We denote the collection of multisets with elements from M with M ( M ). The relations ⊢ i , ⊢ s , and ⊢ r correspond to state transitions related with internal, send, and receive events. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Distributed Algorithm Definition (distributed algorithm) A distributed algorithm for a collection P = { p 1 , . . . , p N } of processes is a collection of local algorithms, one for each process in P . Notes A configuration of a transition system consists of the state of each process and the collection of messages in transit The transitions are the events of the processes, which do not only affect the state of the process, but can also affect (and be affected by) the collection of messages The initial configurations are the configurations where each process is in an initial state and the message collection is empty J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Induced Transition Systems Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Induced Async. Transition System Definition (Induced Async. Transition System) The transition system S = ( C , → , I ) is induced under asynchronous communication by a distributed algorithm for processes p 1 , . . . , p N , where the local algorithm for process p i is ( Z p i , I p i , ⊢ i p i , ⊢ s p i , ⊢ r p i ), is given by (1) C = { ( c p 1 , . . . , c p N , M ) : ( ∀ p ∈ P : c p ∈ Z p ) ∧ M ∈ M ( M ) } (2) → (see next slide) (3) I = { ( c p 1 , . . . , c p N , M ) : ( ∀ p ∈ P : c p ∈ I p ) ∧ M = ∅} J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Induced Async. Transition System Definition (Induced Async. Transition System (cont.)) (2) → = ( � p ∈ P → p ), where the → p are the transitions corresponding to the state changes of process p ; → p i is the set of pairs ( c p 1 , . . . , c p i , . . . , c p N , M 1 ) , ( c p 1 , . . . , c ′ p i , . . . , c p N , M 2 ) for which one of the following three conditions holds: ( c p i , c ′ p i ) ∈⊢ i p i and M 1 = M 2 for some m ∈ M , ( c p i , m , c ′ p i ) ∈⊢ s p i and M 2 = M 1 ∪ { m } for some m ∈ M , ( c p i , m , c ′ p i ) ∈⊢ r p i and M 1 = M 2 ∪ { m } J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Induced Sync. Transition System Definition (Induced Sync. Transition System) The transition system S = ( C , → , I ) is induced under synchronous communication by a distributed algorithm for processes p 1 , . . . , p N , where the local algorithm for process p i is ( Z p i , I p i , ⊢ i p i , ⊢ s p i , ⊢ r p i ), is given by (1) C = { ( c p 1 , . . . , c p N ) : ( ∀ p ∈ P : c p ∈ Z p ) } (2) → (see next slide) (3) I = { ( c p 1 , . . . , c p N ) : ( ∀ p ∈ P : c p ∈ I p ) } J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Induced Sync. Transition System Definition (Induced Sync. Transition System (cont.)) (2) → = ( � p ∈ P → p ) ∪ ( � p , q ∈ P : p � = q → pq ), where → p i is the set of pairs ( c p 1 , . . . , c p i , . . . , c p N ) , ( c p 1 , . . . , c ′ p i , . . . , c p N ) for which ( c p i , c ′ p i ) ∈⊢ i p i → p i p j is the set of pairs ( . . . , c p i , . . . , c p j , . . . )( . . . , c ′ p i , . . . , c ′ p j , . . . ) for which there is a message m ∈ M such that p i ) ∈⊢ s p j ) ∈⊢ r ( c p i , m , c ′ p i and ( c p j , m , c ′ p j J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Events and Causal Order Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Events and Causal Order A transition a is said to occur earlier than transition b if a occures in the sequence of transitions before b An execution E = ( γ 0 , γ 1 , . . . ) can be associated with a sequence of events ¯ E = ( e 0 , e 1 , . . . ), where e i is the event by which the configuration changes from γ i to γ i +1 Events of a distributed execution can sometimes be interchanged without affecting the later configurations of the execution The notion of time as a total order on the events is not suitable and instead the notion of causal dependence is introduced J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Dependence of Events Theorem Let γ be a configuration of a distributed system (with asynchronous message passing) and let e p and e q be events of different processes p and q, both applicable in γ . Then e p is applicable in e q ( γ ) , e q is applicable in e p ( γ ) , and e p ( e q ( γ )) = e q ( e p ( γ )) . Let e p and e q be two events that occur consecutively in an execution. The premise of the theorem applies to these events except in the following two cases: a) p = q or b) e p is a send event, and e q is the corresponding receive event The fact that a particular pair of events cannot be exchanged is expressed by saying that there is a causal relation between these two events J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Causal Order Definition (causal order) Let E be an execution. The relation ≺ , called the causal order, on the events of the execution is the smallest relation that satisfies the following requirements: (1) If e and f are different events of the same process and e occurs before f , then e ≺ f . (2) If s is a send event and r the corresponding receive event, then s ≺ r . (3) ≺ is transitive. Write a � b to denote ( a ≺ b ∨ a = b ) The relation � is a partial order and there may be events a and b for which neither a ≺ b nor b ≺ a holds Such events are said to be concurrent, notation a � b J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Computations and Executions Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Computations The events of an execution can be reordered in any order consistent with the causal order, without affecting the result of the execution Such a reordering of the events gives rise to a different sequence of configurations, but this execution will be regarded as equivalent to the original execution Let E = ( γ 0 , γ 1 , . . . ) be an execution with an associated sequence of events ¯ E = ( e 0 , e 1 , . . . ), and assume f is a permutation of ¯ E The permutation ( f 0 , f 1 , . . . ) of the events of E is consistent with the causal order if f i � f j implies i ≤ j , i.e., if no event is preceded in the sequence by an event it causally precedes J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Equivalent Executions Theorem Let f = ( f 0 , f 1 , . . . ) be a permutation of the events of E that is consistent with the causal order of E. Then f defines a unique execution F starting in the initial configuration of E. F has as many events as E, and if E is finite, the last configuration of F is the same as the last configuration of E. If the conditions of this theorem apply, we say that E and F are equivalent executions, denoted as E ∼ F A global observer, who has access to the actual sequence of events, may distinguish between two equivalent executions The processes, however, cannot distinguish between two equivalent executions J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Computation Definition (computation) A computation of a distributed algorithm is an equivalence class under ∼ of executions of the algorithm. It makes no sense to speak about the configurations of a computation, because different executions of the computation may not have the same configurations It does make sense to speak about the collection of events of a computation, because all executions if the computation consist of the same set of events The causal order of the events is defined for a computation J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Logical Clocks Transition System 9 10 Local and Distributed Algorithms 11 Induced Transition Systems 12 Events and Causal Order 13 Computations and Executions 14 Logical Clocks J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Logical Clocks Definition (clock) A clock is a function Θ from the set of events ¯ E to an ordered set ( X , < ) such that for a , b ∈ ¯ E a ≺ b ⇒ Θ( a ) < Θ( b ) . Definition (lamport clock) A Lamport clock is a clock function Θ L which assigns to every event a the length k of the longest sequence ( e 1 , . . . , e k ) of events satisfying e 1 ≺ e 2 ≺ . . . ≺ e k = a . Note A clock function Θ expresses causal order, but does not necessarily express concurrency J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Lamport Clocks The value of Θ L can be computed as follows: Θ L ( a ) is 0 if a is the first event in a process If a is an internal event or send event, and a ′ the previous event in the same process, then Θ L ( a ) = Θ L ( a ′ ) + 1 If a is a receive event, a ′ the previous event in the same process, and b the send event corresponding to a , then Θ L ( a ) = max(Θ L ( a ′ ) , Θ L ( b )) + 1 The per process clock value may be combined with a process identifier to obtain a globally unique value J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Lamport Clock Example 1 2 5 6 7 P1: e1,1 e1,2 e1,3 e1,4 e1,5 1 2 7 P2: e2,1 e2,2 e2,3 1 3 4 5 6 7 P3: e3,1 e3,2 e3,3 e3,4 e3,5 e3,6 J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Vector Clocks Definition (vector clocks) A vector clock for a set of N processes is a clock function Θ V which is defined by Θ V ( a ) = ( a 1 , . . . , a N ), where a i is the number of events e in process p i for which e ≺ a . Vectors are naturally ordered by the vector order: ( a 1 , . . . a n ) ≤ V ( b 1 , . . . b n ) ⇐ ⇒ ∀ i (1 ≤ i ≤ b ) : a i ≤ b i Vector clocks can express concurrency since concurrent events are labelled with incomparable clock values: a ≺ b ⇐ ⇒ Θ V ( a ) < Θ V ( b ) Vector clocks require more space in the messages, but element compression can reduce message overhead J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Vector Clock Example (1,0,0) (2,0,0) (3,2,3) (4,2,3) (5,2,3) P1: e1,1 e1,2 e1,3 e1,4 e1,5 (0,1,0) (0,2,0) (4,3,3) P2: e2,1 e2,2 e2,3 (0,0,1) (0,2,2) (0,2,3) (0,2,4) (0,2,5) (0,2,6) P3: e3,1 e3,2 e3,3 e3,4 e3,5 e3,6 J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
References L. Lamport. Time, Clocks, and the Ordering of Events in a Distributed System. Communications of the ACM , 21(7), July 1978. M. Raynal. About logical clocks in distributed systems. Operating Systems Review , 26(1):41–48, 1992. G. Tel. Introduction to Distributed Algorithms . Cambridge University Press, 2 edition, 2000. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Part: Clock Synchronization in WSNs 15 Motivation and Introduction 16 Time-Stamp Synchronization (TSS) 17 Reachback Firefly Algorithm (RFA) 18 Reference Broadcast Synchronization (RBS) 19 Flooding Time Synchronization Protocol (FTSP) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Motivation and Introduction 15 Motivation and Introduction 16 Time-Stamp Synchronization (TSS) 17 Reachback Firefly Algorithm (RFA) 18 Reference Broadcast Synchronization (RBS) 19 Flooding Time Synchronization Protocol (FTSP) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Why Clock Synchronization in WSNs? Motivation Time correlated sensor readings or time series data aggregation in the network Coordination of low duty cycles (power up hardware only when necessary) to increase overall network lifetime Transmission scheduling algorithms such as TDMA J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Clock Synchronization in WSNs Approach #1 (external synchronization) All clocks are synchronized to a real time standard such as Coordinated Universal Time (UTC). Approach #2 (internal synchronization) Clocks are relatively synchronized to each other to provide ordering of events. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Special Constraints in WSNs Energy consumption : According to Hill et al., each transmitted bit consumes as much power as executing 800-1000 instructions. One goal is therefore to work with a minimum number of messages. Processing power : Sensor nodes usually use microcontrollers with limited computational power. Memory capacity : Sensor notes have limited amount of data and program memory, making it difficult to fit lengthy algorithms or to maintain larger data sets. Transmission range : The transmission range is a function of transmission power and since energy is a scarce resource, the transmission range of sensor nodes is typically short. Depending on the application scenario, there might also be issues with noise. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Sources of Synchronization Errors Send time : Time spend at the sending node from creating a message until it reaches the network interface. Access time : Time spend getting access to the channel for transmission. Depending on the MAC, the access time can vary widely. Propagation time : Travel time of a message after leaving the sender node until it is received by a receiving node. Typically very small (in the order of nano seconds in LANs). Receive time : Time needed to process an incoming message and to notify the receiving application. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Synchronization Metrics 1 Energy consumption 2 Synchronization precision 3 Scalability to support large networks with many nodes 4 Robustness against failures (self-organization) 5 Synchronization scope (local synchronization for some nodes versus global synchronization of all nodes) 6 Computational complexity 7 Memory requirements (both RAM and ROM) 8 Piggy backing of synchronization message J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Criteria and Classification 1 Master/slave vs. peer-to-peer synchronization 2 Clock correction vs. untethered clocks 3 Internal vs. external synchronization 4 Probabilistic vs. deterministic synchronization bounds 5 Sender to receiver vs. receiver to receiver synchronization 6 Single-hop vs. multi-hop networks 7 Stationary vs. dynamic network topologies J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Time-Stamp Synchronization (TSS) 15 Motivation and Introduction 16 Time-Stamp Synchronization (TSS) 17 Reachback Firefly Algorithm (RFA) 18 Reference Broadcast Synchronization (RBS) 19 Flooding Time Synchronization Protocol (FTSP) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Time-Stamp Synchronization (TSS) Focus on temporal relationships between events ( x happened before y ) Assumption that not all nodes can directly talk to each other . . . J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Time Transformation Time Transformation The real-time time difference ∆ t can be transformed into computer clock time difference ∆ c as follows: (1 − ρ ) ≤ ∆ c ∆ t ≤ (1 + ρ ) (1) The parameter ρ is the bound of the computer clock drift. An equivalent notation is the following: (1 − ρ )∆ t ≤ ∆ c ≤ (1 + ρ )∆ t (2) ∆ c ∆ c (1 + ρ ) ≤ ∆ t ≤ (3) (1 − ρ ) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Time Transformation Example In order to transform a time difference ∆ c from the local time of one node with upper bound ρ 1 to the local time of another node with upper bound ρ 2 , ∆ t is first estimated by the real time interval � ∆ c ∆ c � (1 + ρ 1 ) , (4) (1 − ρ 1 ) which in turn is estimated by the computer time interval � ∆ c (1 − ρ 2 ) � (1 + ρ 1 ) , ∆ c (1 + ρ 2 ) (5) (1 − ρ 1 ) relative to the local time of the second node. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reachback Firefly Algorithm (RFA) 15 Motivation and Introduction 16 Time-Stamp Synchronization (TSS) 17 Reachback Firefly Algorithm (RFA) 18 Reference Broadcast Synchronization (RBS) 19 Flooding Time Synchronization Protocol (FTSP) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broadcast Synchronization (RBS) 15 Motivation and Introduction 16 Time-Stamp Synchronization (TSS) 17 Reachback Firefly Algorithm (RFA) 18 Reference Broadcast Synchronization (RBS) 19 Flooding Time Synchronization Protocol (FTSP) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broadcast Synchronization NIC NIC Sender Sender Receiver Receiver 1 Critical Path Receiver 2 Time Critical Path Idea Exploit the broadcast capability of wireless sensor networks Reduce the critical path by eliminating send time and access time Instead of synchronizing the sender with the receiver, synchronize a set of receivers with each other J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broadcast Synchronization Algorithm Individual nodes broadcast reference beacons to their neighbors (beacons do not include timestamps). Receivers timestamp the arrival of the beacons using their local clocks Receivers exchange their timestamps. The only source of errors are different propagation delays (but usually very small) and receive time errors. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broadcast Synchronization Phase Offsets Errors mainly due to receive time variations since propagation time variation is usually negligible Calculate the offset over a number of received beacons Let m be the number of beacons and let T r , b denote the time of receiver r ’s clock when it receives broadcast b . Then the offset o [ i , j ] of the notes i and j is given by: m o [ i , j ] = 1 � ( T j , k − T i , k ) (6) m k =1 By averaging the time differences, we take care of phase errors. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broadcast Synchronization Clock Skew Clocks typically have a bounded frequency error, i.e., the freqency is not precisely the expected frequency. The frequency of real-world clocks can change but it tends to stay in table over time periods. Short-term instability is primarily due to environmental factors, such as variations in temperature, supply voltage, and shock. Long-term instability results from more subtle effects, such as oscillator aging. Use linear regression to handle clock screw. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broadcast Synchronization Experiment Broacast a reference beacon in a network with 5 motes Every mote has a clock resolution of 2 µ s to timestamp the reception times of incoming broadcasts The following plot shows points ( x , y ) with ( x , y ) = ( T r 1 , k , T r 2 , k − T r 1 , k ) (7) and the best linear fit. The vertical pulses visualize the distance from each point to the best-fit line. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broacast Synchronization Linear fit seems to be a “good enough” approximation for clock screw. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Reference Broacast Synchronization Comparision of RBS and NTP Implemented RBS on a Linux kernel in user space Each regression is based on a window of the 30 most recent pulse reception reports Outliers are automatically rejected based on an adaptive threshold equal to 3 times the median fit error of the set of points not yet rejected Light network load: The 802.11 network had very little background traffic Heavy network load: Two additional machines generated traffic by sending a series of randomly-sized UDP datagrams, each picked uniformly between 500 and 15,000 bytes (IP fragmentation being required for larger packets). The inter-packet delay was 10msec. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
RBS Comparison to NTP RBS outperforms NTP and also a modified version of NTP, which allows a fairer comparison to RBS. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Flooding Time Synchronization Protocol (FTSP) 15 Motivation and Introduction 16 Time-Stamp Synchronization (TSS) 17 Reachback Firefly Algorithm (RFA) 18 Reference Broadcast Synchronization (RBS) 19 Flooding Time Synchronization Protocol (FTSP) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Flooding Time Synchronization Protocol Goals Achieve high precision clock synchronization Support sparse multi-hop network topologies Must run with limited resources (Mica2 / TinyOS) Approach Advanced MAC layer time stamping Linear regression of clock skew Flooding protocol with a dynamically elected root Graceful handling of election / join phases J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Flooding Time Synchronization Protocol Clock Skew Time synchronization error between two motes. After 30 minutes, time synchronization is stopped and the initially small error results in increasing synchronization error over time. J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Flooding Time Synchronization Protocol Linear Regression Distribution of error of linear regression on Mica2 motes: T = 30 s time sync interval results in an average absolute error of 1 . 48 µ s and a maximum absolute error of 6 . 48 µ s T = 300 s time sync interval results in an average absolute error of 2 . 24 µ s and a maximum absolute error of 8 . 64 µ s J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Flooding Time Synchronization Protocol Protocol Idea Every synchronized node periodically broadcasts a synchronization message A node is synchronized if it has collected sufficient reference points Only synchronization messages from an elected synchronization root node are taken into account Message Format The synchronization message contains timeStamp — synchronization timestamp rootID — ID of the synchronization root seqNum — sequence number (assigned by sync. root) J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Flooding Time Synchronization Protocol Protocol Details Nodes must ignore messages which are from an invalid synchronization root or have an old sequence number Nodes must collect sufficient reference points before they are allowed to broadcast Protocol must keep stability when a sync. root fails and a new one is elected with a different clock drift Need to handle partitions and (massive) joins gracefully J¨ urgen Sch¨ onw¨ alder Advanced Distributed Systems
Recommend
More recommend