Example Application: Psfq

  1. Node Configuration
  2. Code Generation
  3. Updating Makefile
  4. Build
  5. Run

PSFQ (Pump Slowly, Fetch Quickly) is a reliable transport protocol suitable for a new class of reliable data applications emerging in wireless sensor networks.

The documentation at original psfq website and README file in the distribution does not help too much, if we want to see the behavior of the code in the simulator. Download psfq distribution from here . Do not overwrite psfq*.nc files in components directory. I had to make minor changes to make it portable to tossim and nesct for dbg messages. Copy the same behavior if you have a recent version of psfq than the one in components directory.

Extract psfq.tar.gz to your src directory. The contents of the src directory should be nesct, tictoc, and psfq. Enter psfq directory than to the tools, then type make.

[root@sinan psfq]# cd tools
[root@sinan tools]# make
gcc -g -Wall -o bs bs.c -lm
gcc -g -Wall -o sf-middleware sf-middleware.c -lm

Enter sensortopo directory and type make again. Wait until the java files get compiled.

[root@sinan tools]# cd sensortopo/
[root@sinan sensortopo]# make
javac -classpath /root/projects/tinyos-1.x/apps/psfq/tools/ TopoGUI.java

Ok, now that psfq pc support tools are ready. Let's proceed to simulation build.
 

  1. Node Configuration

#include "gen/cTOSBase_TinyOSModule.h"
#include "gen/cTOSBase_Main.h"
#include "gen/cPsfq_TinyOSModule.h"
#include "gen/cPsfq_Main.h"

if (getIndex() == 0)
{
   cTOSBase_Main *m = new cTOSBase_Main(this,main,"Main",getIndex());
   m->StdControl_init();
   m->StdControl_start();
}
else
{
   cPsfq_Main *m = new cPsfq_Main(this,main,"Main",getIndex());
   m->StdControl_init();
   m->StdControl_start();
}

 


To start with, PSFQ example expects that all packets coming from UART to go to TOSBase application. TOSBase application is going to relay this message to other nodes using RF. For this reason, we need a multiple application scenario.

Node 0 : TosBase
Rest: Psfq

Given the original source code and support tools, i have seen that if TOSSIM is defined, then bs would compile for the simulator. Nevertheless, this seems to be broken. I also have the impression that Psfq is not maintained anymore. You can omit this flag for now and use original tool.

 

  1. Code Generation

NesCT is going to build all the classes in gen directory. Replace "cp" with "copy" and slash (/) with backslash (\) for windows operating system at the following instructions.

[root@sinan tictoc]# cd components/
[root@sinan components]# cp TosBase.nc ../Application.nc
[root@sinan tictoc]# ./nesct.exe Application.nc
[root@sinan tictoc]# cd components/
[root@sinan components]# cp Psfq.nc ../Application.nc
[root@sinan tictoc]# ./nesct.exe Application.nc

  1. Updating Makefile

  Type makemake.bat/makemake.sh to create new Makefile for Win32/Linux.
  1. Build

Type "make" to build the binary.

[root@sinan tictoc]# make
g++ -c -g -fpermissive -fPIC -DWITH_NETBUILDER -w -DTOSNODES=1000 -DLINUX -DPLATFORM_OMNETPP -I./include -I/root/projects/tinyos-1.x/tos/interfaces -I./include_tos -I/opt/omnetpp-3.2/include simstart.cc
g++ tictoc1_n.o debug.o simstart.o tinyos.o tinyosmain.o tossim.o txc1.o -g -L/opt/omnetpp-3.2/lib -lenvir -lcmdenv -lsim_std -lnedxml -lxml2 -ldl -lstdc++ -lpthread -o tictoc
echo>.tstamp

  1. Run

Edit omnetpp.ini file and change wait-for-sf to true. After enabling this option, the simulation will wait 10 seconds before starting to allow sf to connect.

Start SerialForwarder by running ./bin/sf_sim . For windows, you may need to enter the contents of the file yourself in a console windows (cygwin). The exceptions will be lost once we start the simulator.

[root@sinan tictoc]# ./bin/sf_sim
Listening to tossim-serial
SF enabled, 0 clients, 0 packets read, 0 packets written getenv JNI library not found. Env.getenv will not work
(please consult installation directions in
tinyos-1.x/tools/java/net/tinyos/util/Env.INSTALL)
Platform avrmote
Opening tossim-serial source
Connecting to Tossim event port at localhost:10585
Listening for client connections on port 9001
SF enabled, 0 clients, 0 packets read, 0 packets written java.net.ConnectException: Connection refused

To complicate things, let's use another topology file in ned directory.

[root@sinan tictoc]# cd ned
[root@sinan ned]# cp psfq.ned ../bin/tictoc1.ned

Run tictoc. The simulation screen should like this.

                           

This time I'll set only usr3 debug environment variable. Use "export" keyword for linux and "set" keyword for windows to change environment variable. You should see an output similar to this in TK window.


Allow simulation to run for a while. Go to tools directory of original psfq source code directory (../psfq/tools). Start sensortopo topology monitoring application.

[root@sinan tools]# ./run-sensortopo

 


You may have to resize the window to make the control buttons below to be visible.

Start the base station file inject procedure. we are going to distribute test70 file to the nodes. Download test70 from here and put it to the same directory with tools.

[root@sinan tools]# ./bs test70 -C -M
:c
Enter return to accept the [default]
group [7D]:
Tr [500]:
Tmin [1500]:
Tsimnak [0]:
TTL [2]: 5
report interval [5]:
source file (50 char limit) [test30]:
File ID [1]:
Unicast Mode? [no]: yes
Final Destination [6]: 3
Next Hop [1]:
Start Over as a new session? [no]: yes


Choose i for interactive mode
:i



file: 1120 bytes, 70 loglines
---------------------------------



Then p to start code distribution.

:p
00d:00h:00m:00.011s::sending message:0
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 00 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 A6 35
00d:00h:00m:01.860s::sending message:1
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 01 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 50 E0
00d:00h:00m:03.698s::sending message:2


If you notice, the events take too much of time in the TK window, one way of speeding up the simulation is to build the simulation for command environment. Go back to tictoc directory. Edit your makefile and change the definition of USER_IFLIBS from TK to CMD. Use # for making a line comment. Kill tictoc (Control -C) and bs tool. Leave sf_sim and sensortopo running. Then make again. Copy and run tictoc again.

[root@sinan tictoc]# make
[root@sinan tictoc]# cp tictoc bin
[root@sinan tictoc]# cd bin
[root@sinan bin]# ./tictoc


See the incoming messages at bs screen.

FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 02 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 6B 8E

***************** inject message received **********
00d:00h:00m:05.056s::src:4:dst:65535:fid:01:fsize:30:seq:0:ttl:01
code:01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01
****************************************************


***************** inject message received **********
00d:00h:00m:05.132s::src:1:dst:65535:fid:01:fsize:30:seq:0:ttl:01
code:01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01
****************************************************

00d:00h:00m:05.820s::sending message:3
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 03 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 9D 5B
00d:00h:00m:07.667s::sending message:4:report requested
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 04 00 82 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 D4 C0
00d:00h:00m:09.563s::sending message:5
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 05 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 EB 87
00d:00h:00m:11.411s::sending message:6
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 06 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 D0 E9
00d:00h:00m:13.270s::sending message:7
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 07 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 26 3C
00d:00h:00m:15.153s::sending message:8
FF FF 4D 7D 1D 01 00 00 FF FF 01 1E 00 08 00 02 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 01 00 00 D0 FA


Disable express mode in omnetpp.ini file if you want to see the debug messages in console window. See the logger directory and file contents about how the contents of them change.

A scalar file named omnetpp.sca is used to record statistics about the simulation. Run scalars omnetpp.sca to graph the following output.



                               

 


This project has been supported by Featherlight project at University of Twente, the Netherlands and European Embedded WiseNt project at Yeditepe University.