You are on page 1of 10

Cooja: A Cross-Level Simulator

for Contiki

Yang Deng

Background

Simulator simplifies software development in controlled


environment

Validate algorithm

Observe communication

Learn system behavior

However, most of the simulators focus on specific level

Application Level: NS2/3, OMNet++

Operating System Level: TOSSIM

Machine Instruction Level: ATEMU

Sometimes, hybrid simulation is needed. Thus, Cooja is


introduced to bridge this gap.

Cooja Overview

COOJA ensures that each simulated node only handles one event

In simulation loop, COOJA ticks every available node

Interfaces are hardware peripherals and enable COOJA to detect and


trigger events; observers-subscribers model is employed
During a node tick, both before and after Contiki code actually
executes, interfaces are allowed to check for new events
At the end of simulation loop the overall time is increased; stop or
pause is allowed at this time
Support different level of simulation, implemented by 3 kinds of
nodes: pure-Java nodes, native nodes, emulated nodes
For emulated nodes, each one is allowed to run for maximum a fixed
period of time; then events are transferred via programming interface
to and from COOJA

Cooja Overview
Node 1
Node 2
Node 3

Pre-tick all sim interfaces


ct

Set memory
Node X

Tick

Node Type

Get memory
Node N

Post-tick all sim interfaces

Increase simulation time


(stop/pause)

re
Di
JNI
AP
I

Java Function

Application Level
Pure-Java Nodes

Call process_run()

Operating System Level


Native Nodes

MSPSim Emulator

Machine Instruction Level


Emulated Nodes

Operating System Level

In native nodes node type acts as a link between a node and loaded
Contiki
COOJA makes JNI calls from Java Runtime to C Runtime
JNI calls contain a few functions: initialize stack, copy and replace
memory, tick the node and get address of variables
Every node stores a copy of data memory (BSS and DATA segment)
but all nodes of the same type share the same program code (TEXT
segment)
Data memory is copied to C Runtime before Contiki code executes
and after that it is fetched back to Java Runtime
Map-file is used to parse the address of variable and function in order
to communicate with C Runtime; also used for debugging
Stack is not copied as correct Contiki code should not use stack as a
storage point between events (due to protothread)

Operating System Level


Cooja

Loaded Contiki

JNI

Memory

Stack
BSS
DATA
TEXT

C Runtime

initialize

Simulated Node B1

Simulated Node A1

Memory Copy

Memory Copy

BSS

BSS

DATA

DATA

Interfaces

Interfaces

get/set memory
get/set memory
Simulated Node BN
tick

Node
Type
B

Node
Type
A

Loaded Contiki
Memory

initialize
get/set memory

Memory Copy

BSS

BSS

DATA

DATA

Interfaces

Interfaces

Stack
BSS

get/set memory

DATA

tick

TEXT

Simulated Node AN

Memory Copy

Java Runtime

JNI

C Runtime

Machine Instruction Level


Emulated Nodes
MSPSim: Java-based instruction level emulator

External hardware is also emulated (TR1001, CC2420)

Command Line Interface and integration programming interface

USART

CC2420

I/O Ports

LEDs

MSP430
Emulator

USB

Button

Working Together

Workflow: Write Same Code, Run Different nodes

Project

Source Code

make target=

Firmware/Bin

Native

Hardware

COOJA
Simulation
Results

Z1

Sky

MicaZ

Corresponding Testbeds
Experimental
Results

ESB

Evaluation
On average, Pure-Java runs 1.7 times faster than native nodes
and 50 times faster than emulated nodes
Pure-Java Nodes

Native Nodes

Emulated Nodes

Level

Application

OS

Instruction

Contiki

No

Yes

Yes

Deployable

No

No

Yes

Speed

Fastest

Fast

Slowest

Memory

Smallest

Small

Largest

Usage

Develop / Validate algorithms

Normal cases

Cycle-accurate emulation

Scalability

>10

>3x10

<100

References

A. Dunkels. Full TCP/IP for 8-bit architectures. In Proceedings of The First International Conference on Mobile
Systems, Applications, and Services (MOBISYS 03), May 2003.
A. Dunkels, B. Gronvall, and T. Voigt. Contiki a lightweight and flexible operating system for tiny networked
sensors. In Workshop on Embedded Networked Sensors, Tampa, Florida, USA, November 2004.
A. Dunkels, F. Osterlind, and Z. He. An adaptive communication architecture for wireless sensor networks. In
Proceedings of the Fifth ACM Conference on Networked Embedded Sensor Systems (SenSys 2007), Sydney,
Australia, November 2007.
J. Eriksson, A. Dunkels, N. Finne, F. Osterlind, and T. Voigt. MSPSim an extensible simulator for MSP430equipped sensor boards. In Proceedings of the European Conference on Wireless Sensor Networks (EWSN),
Poster/Demo session, Delft, The Netherlands, January 2007.
F. Osterlind, A. Dunkels, J. Eriksson, N. Finne, and T. Voigt. Cross-level sensor network simulation with COOJA.
In Proceedings of the First IEEE International Workshop on Practical Issues in Building Sensor Network
Applications (SenseApp 2006), Tampa, Florida, USA, November 2006.
Joakim Eriksson, Fredrik sterlind, Niclas Finne, Nicolas Tsiftes, Adam Dunkels, Thiemo Voigt, Robert Sauter,
and Pedro Jos Marrn. 2009. COOJA/MSPSim: interoperability testing for wireless sensor networks. In
Proceedings of the 2nd International Conference on Simulation Tools and Techniques (Simutools '09).
Nicolas Tsiftes, Joakim Eriksson, Niclas Finne, Fredrik sterlind, Joel Hglund, and Adam Dunkels. 2010. A
framework for low-power IPv6 routing simulation, experimentation, and evaluation. SIGCOMM Comput. Commun.
Rev. 41, 4 (August 2010)
Fredrik sterlind. A sensor Network Simulator for the Contiki OS. SICS Technical Report. February 2006.

You might also like