-
[TOSSIM] TinyViz 테스트 하기대학원 연구/TinyOS 2009. 1. 15. 17:17
TinyViz: The TOSSIM User Interface TinyViz provides an extensible graphical user interface for debugging, visualizing, and interacting with TOSSIM simulations of TinyOS applications. Using TinyViz, you can easily trace the execution of TinyOS apps, set breakpoints when interesting events occur, visualize radio messages, and manipulate the virtual position and radio connectivity of motes. In addition, TinyViz supports a simple "plugin" API that allows you to write your own TinyViz modules to visualize data in an application-specific way, or interact with the running simulation.
Getting Started To get started, look at the apps/TestTinyViz application, which causes motes to periodically send a message to a random neighbor. There isn't anything interesting about the application itself, but it will allow us to demonstrate the basic features of TinyViz. Go ahead and build the app with make pc.
To compile TinyViz, cd to the tools/java/net/tinyos/sim directory and type make. This will build the TinyOS program as tinyviz.jar, a stand-alone Java JAR file that you can run with the tinyviz script, found in this directory. Place this script on your PATH and you will be able to run tinyvizdirectly from the command line.
Start up TinyViz, running the TestTinyViz app, as follows:
export DBG=usr1 tinyviz -run build/pc/main.exe 30
You will see a window looking something like the following:
On the left is the graphical display of the sensor network. On the right is the control panel where you can interact with a series of plugins that control how TinyViz works.
In the mote window, you can select motes by clicking on them, or select a group of motes by dragging a rectangle around the group. You can move motes around by dragging them around. Selecting motes is meaningful for certain plugins, and other operations, such as toggling the power state of the motes.
The "pause/play" button pauses or resumes the simulation. The "grid button" toggles grid-lines on the display. The "clear" button clears out the display state. The "stop" button kills the simulation. The "delay" slider introduces a delay between the handling of each TOSSIM event, which will slow down the display -- useful in cases where you have a small number of motes and want to watch the simulation operating in "real time". The "On/off" button toggles the power state of the selected motes.
Plugins
A TinyViz plugin is a software module that watches for events coming from the simulation -- such as debug messages, radio messages, and so forth -- and reacts by drawing information on the display, setting simulation parameters, or actuating the simulation itself, for example, by setting the sensor values that simulated motes will read. TinyViz comes with a suite of built-in plugins, in the tools/java/net/tinyos/sim/plugins directory, and you can write your own. Not all plugins are used for all applications -- for example, the Calamari plugin is used mainly for testing the Calamari localization service -- but many of them are generally useful.
Plugins can be selectively enabled or disabled, depending on what information you are interested in seeing during the simulation. You select plugins from the Plugins menu. When a plugin is enabled, its corresponding tab in the right-hand control panel window is active, which may have additional information and controls provided by that plugin. Plugins are designed to be independent of each other so you can enable or disable any group of plugins you like.
The main plugins you are likely to use are:
- Debug messages: Shows a window with all of the debug messages generated by the simulation. You can select debug messages just from the selected group of motes, and also highlight messages that match a certain pattern. Note that the set of debug messages you see are controlled by the value of the DBG environment variable, just as they are when running TOSSIM in a stand-alone setting. So, if you only want to see debug messages of type DBG_USR1 and DBG_AM, start up TinyViz with:
- Set breakpoint: Allows you to set a breakpoint, which will pause the simulation when some condition is met. Right now, the possible conditions are (a) a substring match on a debug message, or (b) a match on the contents of a sent radio message. Multiple breakpoints can be set and they can be enabled or disabled by selecting them in the breakpoints list.
- ADC readings: Shows the most recent value of each ADC channel next to each mote.
- Sent radio packets: Shows a window with all sent radio packets, much like the Debug messages plugin. Note that the Debug messagesplugin also shows this information.
- Radio links: Graphically displays radio message activity. When a mote broadcasts a message, a blue circle will be drawn around it. When a mote sends a message to another mote, a directed arrow will be drawn between the two motes. Note that this shows all message transmissions, regardless of whether they are successful; if a mote attempts to send a message but it is corrupted or lost, the arrow will still be drawn.
- Set location: Makes the virtual location of each mote available to that mote through the Location interface, found inapps/TestTinyViz/Location.nc. This is accomplished by setting the value of three "fake" ADC channels (one each for X, Y, and Z coordinates) on each mote, which the FakeLocation component reads to determine the mote's virtual location. This is meant to act as a stand-in for a real localization service when simulating TinyOS apps.
- Radio model: Sets the bit error rate between motes according to their location and various models of radio connectivity. Enabling this plugin allows you to use realistic connectivity models in your simulations. There are two built-in models: "Empirical" (based on an outdoor trace of packet connectivity with the RFM1000 radios) and "Fixed radius" (all motes within a given fixed distance of each other have perfect connectivity, and no connectivity to other motes). Setting the "scaling factor" in the control panel simply scales the distance parameter of the model. Increasing the scaling factor will decrease the connectivity range of the chosen model. By selecting a mote in the display you can see its connectivity to other motes -- the number shown next to each edge is the probability of a packet getting through. Changing the scaling factor and clicking "update model" will update the model parameters, as will moving motes around in the display.
DBG=usr1,am tinyviz -run build/pc/main.exe 30
Layout of the motes is controlled by the Layout menu, which gives you several options including random, grid-based, or a "grid+random" (grid-based but with a random perturbation) layout. You can also save and load layouts from a file. The location of the motes on the display is used in two ways. First, it is used to determine radio connectivity, when the RadioModelPlugin is enabled. Second, it is used to set the virtual location of the motes, when using the LocationPlugin.
Trying it out
OK, now we're ready to try out the various features.
- Startup TinyViz with DBG=usr1, tinyviz -run build/pc/main.exe 30 if it is not already running.
- Select the Debug messages, Radio links, and Set breakpoint plugins from the Plugins menu, and resume the simulation by clicking the pause/play button.
- Clicking on the Debug messages tab in the control panel will show you all of the debug messages generated by the simulation. Click on a given mote (say, mote 3) then click "Selected motes only" to restrict the display to just that mote.
- Type a phrase (for example, "Received") in the box at the bottom of the control panel, then click "Highlight". This will highlight all messages matching the chosen string - very useful for visually scanning for "interesting" messages.
- Pause the simulation, then click on the "Set breakpoint" tab. Pull down the bar at the top of the control panel (which says "Current breakpoints") and choose "Add debug message breakpoint". In the "Message contains" box, type "Received message", then click "Enable breakpoint". This will add a new breakpoint that pauses the simulation whenever a matching debug message is printed. Click on the pause/play button to resume the simulation. Very soon afterwards, the simulation will pause and the control panel at the bottom of the screen will print something like
- Select "Current breakpoints" from the bar at the top of the control panel. Disable the breakpoint by clicking on it in the breakpoints list, then click "Disable breakpoint".
- Select the Radio model plugin from the Plugins menu and click on the "Radio model" tab in the control panel, then pick "Fixed radius (100.0)" from the list of radio models. Drag the mouse across the mote display to select all motes; you will see a very densely-connected mesh, indicating that nearly every mote has connectivity with all others, due to the large radius of the radio model. Type "4" in the "Distance scaling factor" box, then click "Update model". The radio model will be updated -- which may take some time -- and the resulting connectivity mesh will be much more sparse.
Breakpoint 0 fired: Debug message: [24] DebugMsgEvent [24: TestTinyVizM: Received message from 13]
which simply means that this debug message triggered the breakpoint. Clicking the play button again will resume the simulation, causing the breakpoint to be hit again.
Note that once you restart the simulation, nodes that can no longer communicate (due to no connectivity) will still be sending messages to each other; this is because the TestTinyViz application accumulates a list of nodes to send messages to, but changing the underlying connectivity model does not modify this list. However, if you watch the debug messages from each node, you will notice that nodes are only receiving messages from those nodes they are connected to, as you would expect.
The TinyViz AutoRun feature allows you to "script" the configuration and execution of a TinyOS simulation, by setting parameters in a file that controls TinyViz. This allows you to automatically enable plugins, set breakpoints, run multiple simulations, log data to files, and execute commands both before and after each simulation runs. This is useful when you are using TinyViz as an analysis tool.
Look at the file apps/TestTinyViz/sample.autorun in the TestTinyViz directory. The autorun file specifies one or more simulations to run; a simulation stops either when a specified number of simulated seconds have elapsed (the "numsec" option), when a substring match on a debug message occurs (the "stopstring" option), or when the simulation exits itself (e.g., a crash or deliberate call to exit()). The parameters for each simulation are separated by a blank line. When a parameter is set in the file for one simulation, it will carry forward for subsequent simulations in the file, saving you from having to re-specify parameters for each run.
Here is the sample file:
# This is a sample TinyViz autorun file. To use it, run # tinyviz -autorun sample.autorun # Set the layout layout gridrandom # Enable some plugins plugin DebugMsgPlugin plugin RadioLinkPlugin plugin RadioModelPlugin # Total number of simulated seconds to run numsec 20 # Name of the executable file executable build/pc/main.exe # DBG messages to include dbg usr1 # The radio model and scaling factor to use radiomodel disc100 radioscaling 5 # Number of motes nummotes 10 # Command to run before starting precmd echo "This is a command that will run before the simulation" # File to log all DBG messages to logfile logfile-20.txt # The blank line above indicates that we are starting another simulation # This time run with a different number of motes nummotes 30 logfile logfile-30.txt
The AutoRun file specifies two simulations, one with 20 motes and another with 30. All debug messages are logged to two different logfiles. We enable a few different plugins (specified by the Java class names as they are found in tools/java/net/tinyos/sim/plugins.
To run the simulations with this autorun file, just type:
tinyviz -autorun sample.autorun
TinyViz starts up, enables and configures the appropriate plugins, and automatically runs each simulation for 10 simulated seconds, then exits. You can set up AutoRun to run a series of simulations and then go to lunch -- the data will be waiting for you in your logfiles when you get back.
AutoRun supports a number of features not shown here -- just look at the arConfig class in the tools/java/net/tinyos/sim/AutoRun.javasource file. Note that all options specified in the file that aren't used by AutoRun itself, however they made available to plugins. So, for example, the radiomodeloption is interpreted by the RadioModelPlugin to configure the radio model. You can write your own plugins that are configured through AutoRun in this way.
Writing TinyViz plugins
By far the most useful feature of TinyViz is the ability to write your own plugins to interact with the simulation. Writing plugins is beyond the scope of this document, but we wanted to give you a couple of pointers on where to start. Look at tools/java/net/tinyos/sim/plugins/RadioLinkPlugin.javafor a simple, well-documented plugin implementation. Essentially, plugins must provide a method that receives events from the TOSSIM simulation and the TinyViz framework. Plugins react to events by changing internal state, updating the display, or possibly sending commands back into the simulation. TinyViz delivers events to plugins for initialization, debug messages, radio messages, a change in the location of a mote (e.g., when the user moves it), and when new motes join the simulation. Plugins provide additional methods that are called when the plugin is enabled or disabled, as well as when the mote window is redrawn.
Using RadioLinkPlugin.java as an example, it is straightforward to write your own plugins. Currently, all plugins must be located in the pluginssubdirectory of the TinyViz directory. (In the future we will add support for a "plugin path"). Note that when you modify a plugin you need to recompile the tinyviz.jar file by typing make in the main TinyViz directory (tools/java/net/tinyos/sim); just typing make in the plugins directory is not adequate.
Further Use This tutorial only covers some of the functionality and usefulness of TOSSIM; for example, as TOSSIM simulates the TinyOS networking stack at bit granularity, radio models can simulate some of the difficult issues that arise. Similarly, one can test and debug low-level protocols (such as start symbol detection) in addition to application components and routing protocols. The TOSSIM System Description goes into greater details on these capabilities and presents some information on TOSSIM's implementation.
<출처 : http://www.tinyos.net/tinyos-1.x/doc/tutorial/lesson5.html >