Skip to content

Direct integration shawn application

Henning Hasemann edited this page Mar 11, 2014 · 6 revisions

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.

Setting up Shawn

The required Wiselib module is already part of Shawn. However, it is possible to add Wiselib examples to Shawn. Therefore, a legacyapps-Folder must be created, which can contain additional modules. The next two sub-sections are optional, but recommended.

Creating Legacyapps (Optional!)

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 existing apps and sys directories)
  • Copy legacyapps_init.h and legacyapps.cpp to this newly created folder
  • Go to shawn/buildfiles, call ccmake ../src, and set CONFIGURE_LEGACYAPPS to ON. Then press "c", "g", and "q".

Download Wiselib examples module into Shawn (Optional!)

Once the legacyapps folder is created, you can add Wiselib Shawn examples. Optionally (but recommended) check out

https://github.com/ibr-alg/wiselib/tree/master/apps/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_examples

Configure Shawn to use Wiselib

Next, Shawn must be configured to use the Wiselib module(s):

  • Change to shawn/src/buildfiles and call ccmake ../src
  • Press "c"
  • Set MODULE_APPS_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.

Code Integration

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:

#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:

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:

class WiselibExampleProcessor
   : public virtual ExtIfaceProcessor
{
   [...]

We also need an instance of the algorithm, and the needed external interfaces:

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:

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() );
}

Compile & Run

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.

Clone this wiki locally