Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
An Introduction to Cooja
This page contains information about the COOJA network simulator for Contiki. To get most out of the information contained here, the reader should have basic Contiki knowledge: how to use the Contiki build system and how to create simple Contiki processes. COOJA is included in Contiki since version 2.0. In the Contiki source tree, COOJA resides in
platform/coojaNative platform with glue drivers for Cooja
Table of Contents
The section gives a high-level overview of sensor network simulations in COOJA. This information is not strictly needed for using COOJA, but may help users to more easily understand problems, limitations, and features in the simulator.
A simulated Contiki Mote in COOJA is an actual compiled and executing Contiki system. The system is controlled and analyzed by COOJA. This is performed by compiling Contiki for the native platform as a shared library, and loading the library into Java using Java Native Interfaces (JNI). Several different Contiki libraries can be compiled and loaded in the same COOJA simulation, representing different kinds of sensor nodes (heterogeneous networks). COOJA controls and analyzes a Contiki system via a few functions. For instance, the simulator informs the Contiki system to handle an event, or fetches the entire Contiki system memory for analysis. This approach gives the simulator full control of simulated systems. Unfortunately, using JNI also has some annoying side-effects. The most significant is the dependency on external tools such as compilers and linkers and their run-time arguments. COOJA was originally developed for Cygwin/Windows and Linux platform, but has later been ported to MacOS.
Java version 1.6 or later is required to run COOJA. We recommend using the latest version from Sun. In addition, the build tool ant is also required for building COOJA. For Windows users, we recommend using Cygwin. Add the Cygwin binaries path (for example c:\cygwin\bin) to your PATH environmental variable. To compile and start COOJA:
cd tools/cooja ant run
COOJA builds and the simulator is started. However, before you can simulate a Contiki system, you need to configure COOJA to correctly interface your toolchain.
- Open menu Settings > External tools paths
(This wizard replaces the old JNI tests in /tools/cooja/examples/jni_tests.) The configuration wizard helps configuring COOJA for using JNI, a challenging task on many systems. The wizard consists of 4 steps and tests compiling, linking, loading libraries, analyzing library memory, and controlling library execution.
- Open menu Settings > Cooja mote configuration wizard
After completing the configuration wizard, we are now ready to create a simulation.
- Open menu File > New simulation, and click Create
- Open menu Motes > Add Motes > Create new mote type > Cooja Mote Type
- Enter a suitable description: "My first hello world mote type"
- Click Browse, and select the Contiki Hello World application: hello-world.c
- Compile the Contiki shared library by clicking Compile
- When the compilation finishes, load the library and create the mote type by clicking Create.
- Enter 10 and click Add motes
- Press Start (or CTRL+S) in the Control Panel plugin to start simulating.
Cooja allows for saving and loading simulation configurations. A simulation configuration contains the simulated modes and mote types, radio medium configuration, active plugins, etc.
Note that only the configuration, not the state of the simulation is saved. Hence, when a simulation is loaded, the simulation will start over from time 0.
To save the current simulation:
- Open menu File > Save simulation as
- Enter suitable name. Configuration files are stored with the file extension .csc
- Open menu File > Open simulation > Browse...
- Select configuration file to load.
A similar functionality as saving and loading simulation, is reloading a simulation. To reload the current simulation:
- Open menu Simulation > Reload simulation > Reload with same random seed
When developing Contiki applications, you should normally keep all your code in a project directory. Your project directory may be a subfolder of Contiki (e.g. examples/myproject), or external to Contiki (e.g. /home/user/mycontikiproject).
COOJA leverages the Contiki project directories by storing any simulation's external file references (such as to Contiki applications) relative to the directory where you save the simulation configuration. If you save a COOJA configuration in your project directory, any references to Contiki code residing in that directory will hence be stored as portable relative paths. This feature enables moving and sharing project directories, for example committing Contiki projects to version control.
Example: Contiki path: /home/user/contiki-2.x Contiki project path: /home/user/mycontikiproject Contiki application: /home/user/mycontikiproject/myapp.c
- Create a COOJA simulation, compile myapp.c and finally save the simulation configuration in the project directory.
The Contiki application path will be stored as "[CONFIG]/myapp.c" i.e. relative to where the configuration file is stored.
It is also possible to quickstart COOJA, instead of starting COOJA from the tools/cooja/ directory.
To quickstart COOJA from a Contiki project directory, /home/user/mycontikiproject/:
make myapp.cooja TARGET=cooja
make mysimconfig.csc TARGET=cooja
- -quickstart=Simulation Load Simulation at startup. This must be the first parameter.
- -nogui=Simulation Run simulation without gui. This must be the first parameter.
- -applet Run as applet. Must be the first parameter.
- -log4j=File Load Log4j-Config from file.
- -contiki=Path Set Contiki path
- -external_tools_config=File Set Cooja config file.
Questions and requests should normally be posted to the main Contiki developers mailing list.