-
Notifications
You must be signed in to change notification settings - Fork 57
Direct integration shawn application
Wiselib algorithms (but also data structures or utils) can also be directly integrated in Shawn processors. That means, one can develop his own Shawn processor, but use, for instance, a routing algorithm from Wiselib to send messages to other nodes in the network. This requires a couple of, but not too complicated steps. First, a Wiselib module must be added to Shawn (just check out a folder and enable it via ccmake). Second, the algorithm must be included and defined in the own application. Third and last, the algorithm can be used to support and simplify the own application.
First of all, the Wiselib module must be added to Shawn. Since it is not yet part of the official Shawn release, it must be added as a legacy application (described in Shawn Wiki). Basically, this only requires three steps:
- Create a folder where your Shawn legacy applications should be located (for instance, at
shawn/src/legacyapps
- in parallel to the existingapps
andsys
directories) - Copy legacyapps_init.h and legacyapps.cpp to this newly created folder
- Go to
shawn/buildfiles
, callccmake ../src
, and setCONFIGURE_LEGACYAPPS
toON
. Then press "c", "g", and "q".
Once the legacyapps folder is created, the Wiselib module must be downloaded. Therefore check out {{{ https://svn.itm.uni-luebeck.de/wisebed/wiselib/trunk/shawn_apps/wiselib }}} into the legacyapps folder. Optionally (but recommended) one can also check out {{{ https://svn.itm.uni-luebeck.de/wisebed/wiselib/trunk/shawn_apps/wiselib_examples }}} into legacyapps, because it contains examples of how to integrate Wiselib algorithms into own applications.
Afterward, the directory structure should look as follows: {{{ shawn/src/legacyapps/wiselib (shawn/src/legacyapps/wiselib_examples) }}}
- Next, Shawn must be configured to use the new module(s):
-
- Change to {{{shawn/src/buildfiles}}} and call {{{ccmake ../src}}}
- Press "c"
- Set {{{MODULE_LEGACYAPPS_WISELIB}}} and (optionally) {{{MODULE_LEGACYAPPS_WISELIB_EXAMPLES}}} to {{{ON}}}
- Press "c" again
- Two new options {{{INCLUDE_PATH_WISELIB_STABLE}}} and {{{INCLUDE_PATH_WISELIB_TESTING}}} appear - set to your local Wiselib paths (e.g., {{{/home/wiselib/wiselib.svn/wiselib.stable}}} and {{{/home/wiselib/wiselib.svn/wiselib.testing}}}).
- Press "c", "g", then finally "q"
- Compile Shawn by typing {{{make}}}
When everything compiled successfully, Shawn is ready to integrate Wiselib algorithms.
In the {{{wiselib}}} folder, there is already a simple example of how to integrate a routing algorithm into Shawn: the {{{wiselib_example_processor}}}. Let's have a look into the most important parts.
First of all, the needed parts of the Wiselib must be included. That is, for example: {{{ #!cpp #include "external_interface/shawn/shawn_os.h" #include "external_interface/shawn/shawn_radio.h" #include "external_interface/shawn/shawn_timer.h" #include "external_interface/shawn/shawn_debug.h" #include "internal_interface/routing_table/routing_table_static_array.h" #include "internal_interface/routing_table/routing_table_stl_map.h" #include "algorithms/routing/dsdv/dsdv_routing.h" #include "algorithms/routing/dsr/dsr_routing.h" #include "algorithms/routing/tree/tree_routing.h" #include "algorithms/routing/flooding/flooding_algorithm.h" }}}
After that, the algorithms must be defined as they are going to be used: {{{ #!cpp typedef wiselib::ShawnOsModel Os; typedef wiselib::StaticArrayRoutingTable<Os, Os::Radio, 8, wiselib::DsdvRoutingTableValue<Os, Os::Radio> > DsdvRoutingTable; typedef wiselib::DsdvRouting<Os, DsdvRoutingTable> dsdv_routing_t; }}}
In case an own processor is used, it must be derived from {{{ExtIfaceProcessor}}}: {{{ #!cpp class WiselibExampleProcessor
: public virtual ExtIfaceProcessor
- {
- [...]
}}}
We also need an instance of the algorithm, and the needed external interfaces: {{{ #!cpp
- private:
- dsdv_routing_t dsdv_routing_; ShawnOs os_; Os::Radio wiselib_radio_; Os::Timer wiselib_timer_; Os::Debug wiselib_debug_;
}}}
Once this is done, the own algorithm can be used. The external interfaces can be initialized as follows: {{{ #!cpp
WiselibExampleProcessor:: WiselibExampleProcessor()
- : wiselib_radio_ ( os_ ),
- wiselib_timer_( os_ ), wiselib_debug_( os_ )
}}}
At last, the ShawnOs and DSDV routing must be initialized, and a callback method for received messages is registered: {{{
void WiselibExampleProcessor:: boot( void )
throw()
- {
os_.proc = this;
dsdv_routing_.init( wiselib_radio_, wiselib_timer_, wiselib_debug_ ); dsdv_routing_.reg_recv_callback<WiselibExampleProcessor, &WiselibExampleProcessor::rcv_routing_message>(this); if ( owner().id() != 0 )
dsdv_routing_.send( 0, 0, 0 );[...]
}
void WiselibExampleProcessor:: rcv_routing_message( int from, long len, unsigned char* data)
throw()
- {
- INFO( logger(), "Received at node " << owner().id() << " from " << from << " at "
- << owner().world().simulation_round() );
}
}}}
At last, Shawn must be compiled. Change to {{{shawn/buildfiles}}} and call {{{make}}}. When finished successfully, an executable Shawn binary {{{shawn}}} is in the current directory.
After the code is compiled, it can be run by, for instance, the following configuration file (just call {{{./shawn -f MYCONFIG}}}): {{{ random_seed action=create filename=.rseed
prepare_world edge_model=list comm_model=disk_graph range=3.5 transm_model=stats_chain chain_transm_model name=reliable
routing_algorithm=dsdv rect_world width=80 height=80 count=800 processors=wiselib
simulation max_iterations=25
dump_transmission_stats }}}
Then, debug messages like {{{ Received at node 0 from 6 at 21 }}} should be printed.