-
Notifications
You must be signed in to change notification settings - Fork 2.6k
An Introduction to Cooja
本页包含Contiki的COOJA网络模拟器信息。读者为了更好地明白这里的内容,应该具备以下Contiki基础知识:怎么使用Contiki编译系统、怎么创建简单的Contiki进程。Contiki从2.0版之后中都包含有COOJA。在Contiki源码树下,COOJA位于:
-
tools/cooja模拟器代码 -
platform/cooja包含各种驱动的本地平台
本节对COOJA的传感器网络模拟器做了一个顶层概述。这些信息在使用COOJA时不完全需要,但有助于肚子更容易理解模拟器的问题,局限性和特性。
COOJA中的模拟的Contiki Mote是实际被编译且正在执行的Contiki系统。通过将Contiki编译为本地平台的共享库,然后使用Java本地接口(JNI)将库加载到Java中就实现了这样的功能。不同的Contiki库可以被编译和加载到同一个模拟器中,代表不同种类的传感器节点(异构网络)。 COOJA只通过很少的功能就能实现控制和分析Contiki系统。例如,模拟器通知Contiki系统去处理事件,或者分析获取到的Contiki系统的完整内存。这些方法使模拟器能完全控制被模拟的系统。不幸的是,使用JNI也有一些恼人的副作用。最大的问题是依赖于外部工具,例如编译器、链接器和运行时参数。COOJA最初被开发用于Cygwin/Windows和Linux平台,后来被移植到MacOS。
COOJA运行时需要Java 1.6或者之后的版本。我们推荐使用Sun的最新版本。此外,编译工具ant被用于编译COOJA。对于Windows用户,我们推荐使用Cygwin,且需要将Cygwin二进制路径(比如c:\cygwin\bin)添加到哦你的PATH环境变量中。 编译和开始COOJA:
cd tools/cooja ant run
COOJA编译和仿真开始了。但是,在仿真Contiki系统前,你需要配置你的COOJA,使其符合你的工具链。
- 打开菜单 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
or
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.