tossim: accurate and scalable simulation of entire tinyos ... · 11/7/03 sensys 2003 37 concluding...
TRANSCRIPT
TOSSIM: Accurate and Scalable Simulation of Entire TinyOS
Applications
Philip Levis UC Berkeley
Intel Berkeley
Nelson Lee UC Berkeley
Stanford
Matt Welsh Harvard
University
David Culler UC Berkeley
Intel Berkeley
11/7/03 SenSys 2003 1
A Lesson from History
• Simulation can provide – The ability to inexpensively explore ideas – A controlled environment – Support for extensive observation
• Examples – SimOS – SimpleScalar – ns-2
• Accelerated research in their domains
But…
Capturing the essential elements of their domains was
critical to the utility of these simulators.
11/7/03 SenSys 2003 4
Mote Sensor Network Domain?
33m: 111 32m: 110
30m: 109,108,107
20m: 106,105,104
10m: 103, 102, 101
• Many tiny devices • Embedment • Non-deterministic • Application-specific • System interactions
11/7/03 SenSys 2003 5
What Do We Need to Capture?
• Bridging – Implementations, not just algorithms
• Completeness – Spectrum of low-level protocols to applications – Applications adapt to their environment – Capture the cross-layer interactions
• Fidelity – Capture these interactions at a very fine grain
• Scalability – Examine behavior in dense or large networks
11/7/03 SenSys 2003 6
Our Approach: TOSSIM
• Simulator for TinyOS programs • Compiles directly from TinyOS code
– Executes code from many system layers • Provides a flexible framework for adjusting
fidelity – Based on TinyOS programming model
• Can scale to large numbers
11/7/03 SenSys 2003 7
Outline
• Introduction • TOSSIM architecture • Evaluation • Conclusion
11/7/03 SenSys 2003 8
Outline
• Introduction • TOSSIM architecture • Evaluation • Conclusion
11/7/03 SenSys 2003 9
Standard TinyOS Program (what we start with)
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
Hardware
Component Graph
11/7/03 SenSys 2003 10
TOSSIM Adds Five Things
• Alternative compilation target • Hardware component re-implementations • Discrete event queue • Radio and sensor models • Communication services
11/7/03 SenSys 2003 11
Multiple Component Graphs
Component Graph
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
s
11/7/03 SenSys 2003 12
Compiler Support
• “Simulator” target added to ncc compiler • Rewrites all state declarations and accesses
– Arrays of variables – Index into array based on current node
ncc app.c (avr-gcc)
TinyOS Files
11/7/03 SenSys 2003 13
Compiler Support
• “Simulator” target added to ncc compiler • Rewrites all state declarations and accesses
– Arrays of variables – Index into array based on current node
ncc
app.c (native gcc)
app.c (avr-gcc)
TinyOS Files
11/7/03 SenSys 2003 14
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
Component Graphs
11/7/03 SenSys 2003 15
Component Re-implementations
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM CLOCK
Component Graphs
Component Re-implementations
11/7/03 SenSys 2003 16
Event Queue
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
Component Graphs
Event Queue
CLOCK
ADC Event
Component Re-implementations
11/7/03 SenSys 2003 17
Timer Clock Clock.setRate()
Clock.fire()
outp(interval, OCR0)
INTERRUPT(COMPARE2)
Hardware
Mapping TinyOS into TOSSIM
• TOSSIM events trigger TinyOS components – Each event is for a specific mote and has a time
• TinyOS calls can enqueue TOSSIM events • Hardware-level components re-implemented
– This boundary can change
11/7/03 SenSys 2003 18
Timer Clock Clock.setRate()
INTERRUPT(COMPARE2) Clock.fire()
Event Queue enqueue(clock_event);
Mapping TinyOS into TOSSIM
• TOSSIM events trigger TinyOS components – Each event is for a specific mote and has a time
• TinyOS calls can enqueue TOSSIM events • Hardware-level components re-implemented
– This boundary can change
11/7/03 SenSys 2003 19
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
Component Graphs
Event Queue
CLOCK
ADC Event
Component Re-implementations
11/7/03 SenSys 2003 20
Radio Model
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
Component Graphs
Event Queue
CLOCK
ADC Event
Component Re-implementations
11/7/03 SenSys 2003 21
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
Component Graphs
Event Queue
CLOCK
Sensor Model
ADC Event
Component Re-implementations
Sensor Model
11/7/03 SenSys 2003 22
Radio Model
• Inter-node interaction • Transmit and receive events
– Who can hear whom graph – Receive radio state – Resolution function – Individual radio clocks (based on TinyOS code)
• Standard model: directed graph of bit error rates – Boil complex models to a connectivity graph
• Standard model: signal is the OR of transmissions – All transmissions have uniform strength – Hidden terminal problem
11/7/03 SenSys 2003 23
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
Component Graphs
Event Queue
CLOCK
Sensor Model
ADC Event
Component Re-implementations
11/7/03 SenSys 2003 24
Actuation and Monitoring
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
APP
AM PHOTO TEMP
CRC
BYTE
ADC RFM
Component Graphs
Event Queue
CLOCK
Sensor Model
Communication Services ADC Event
Component Re-implementations
11/7/03 SenSys 2003 25
Actuation and Monitoring
• Programs can actuate and monitor running simulations – Inject events, log messages – Change simulation state (loss rates, sensors)
• Keeps models external to TOSSIM – API to integrate models through sockets – TinyViz application
11/7/03 SenSys 2003 26
TinyViz
11/7/03 SenSys 2003 27
Outline
• Introduction • TOSSIM architecture • Evaluation • Conclusion
11/7/03 SenSys 2003 28
What Do We Need to Capture? (revisited)
• Bridging – Implementations, not just algorithms
• Completeness – Spectrum of low-level protocols to applications – Applications adapt to their environment – Capture the cross-layer interactions
• Fidelity – Capture these interactions at a very fine grain
• Scalability – Examine behavior in dense or large networks
11/7/03 SenSys 2003 29
Evaluation
• Bridging – Compiles directly from TinyOS code
• Fidelity – Mote networking
• Completeness – Complete applications – Unanticipated behavior
• Scalability – Tension between fidelity and scalability
11/7/03 SenSys 2003 30
Fidelity: Mote Networking
• Generated a loss model from empirical data – Map empirical data to TOSSIM loss rates
• Start symbol failure, CRC checks, acknowledgement false negatives/positives
• Ran empirical experiment in TOSSIM Simulated Data
0%20%40%60%80%
100%
0 10 20 30 40 50
Distance (feet)
Loss
Rat
e
Empirical Data
0%20%40%60%80%
100%
0 10 20 30 40 50
Distance (feet)
Loss
Rat
e
11/7/03 SenSys 2003 31
Completeness
• Network interactions – Hidden terminal problem, link asymmetry – Discovered bugs in the Surge application
• System-level race conditions – Network stack for mica: ChannelMonM start
symbol detection and packet transmission • Testing at low levels
– State machine rene stack implementation • Application-level logic driving simulation
– Maté, TinyDB
11/7/03 SenSys 2003 32
Scalability
• 10 virtual seconds • Scales to thousands of nodes • ~30 network active nodes in real time
– 40,000 radio events per second for each mote
0.001
0.01
0.1
1
10
100
1000
10000
1 2 4 8 16 32 64 128
256
512
1024
2048
4096
8192
Motes
Tim
e (s
econ
ds)
BusyQuietInactive
11/7/03 SenSys 2003 33
Scalability Continued
• 30 nodes * 40,000 events = 1.2 million TOSSIM events/second
• Bit-level simulation is the bottleneck – But we can move the re-implementation line…
11/7/03 SenSys 2003 34
Outline
• Introduction • TOSSIM architecture • Evaluation • Conclusion
11/7/03 SenSys 2003 35
Some Cautionary Notes
• Non-preemptive execution – Handlers execute instantaneously
• Signal strength – Results and assumptions
• Independent bit errors • Perfect channel sense • TOSSIM has not been validated
– A basis for comparison, but not the basis
11/7/03 SenSys 2003 36
Extensions (help appreciated!)
• Changing the re-implementation boundary – Packet level simulation – Talking to real motes
• Heterogeneous networks – Additional compiler support – Compelling applications?
• Power modeling – Source annotation for CPU timing – Component power state transitions
11/7/03 SenSys 2003 37
Concluding Thoughts
• Event-driven OS maps to event-driven simulation • TOSSIM as a TinyOS development environment
– Validate with deployment • Simulate at the lowest level
– More than what you think you need – Capture the unanticipated problems
• Capture the mess, but not reality – Model the observed behavior, not the phenomena that
cause that behavior – Do we understand these systems well enough yet?
11/7/03 SenSys 2003 38
Questions
11/7/03 SenSys 2003 39
Backup Slides
11/7/03 SenSys 2003 40
Why Not ns-2?
• Not designed for application interaction • Algorithms, not implementations • Need a TinyOS simulator, not just the
network
11/7/03 SenSys 2003 41
Surge
• Empirically, Surge protocol showed poor performance – Users added TinyDB attribute to monitor protocol – Everything looked fine
• Tested Surge application in TOSSIM – Observed traffic surges – Send queue overflow
• TOSSIM revealed the problem – Cycles + acks + retransmission policy – Lose TinyDB query results indicating the problem
11/7/03 SenSys 2003 42
Surge, Continued
0
4
8
12
16
0
Time (Simulated Seconds)
Qu
eue
Dep
th
0
4
8
12
16
0
Time (Simulated Seconds)
Qu
eue
Dep
th
Fixed Algorithm
Observed Behavior
11/7/03 SenSys 2003 43
Radio Example
A B C
D
1 1
11/7/03 SenSys 2003 44
Radio Example
A B C
D
0 1 1 0
0
11/7/03 SenSys 2003 45
Radio Example
A B C
D
0 1 1 0
0
1
11/7/03 SenSys 2003 46
Radio Example
A B C
D
0 10 11 0
0
1
11/7/03 SenSys 2003 47
Radio Example
A B C
D
0 10 11 0
0
1
0
11/7/03 SenSys 2003 48
Radio Example
A B C
D
01 10 11 01
01
1
0
11/7/03 SenSys 2003 49
Radio Example
A B C
D
01 10 11 01
01
11
0
11/7/03 SenSys 2003 50
Radio Example
A B C
D
01101001011 1010110010 10111100101 01101101011
11111101111
01001001011 01001001011