Hi All, Our website moved to a new URL. Please bookmark the new link: https://ns2bloggers.blogspot.com/

Wednesday 18 November 2015

SETTING UP TINYOS AND NS2 IN UBUNTU-BASED SYSTEMS

TinyOS is an open source software component-based operating system and platform targeting wireless sensor networks (WSNs). TinyOS is an embedded operating system written in the nesC programming language as a set of cooperating tasks and processes. It is intended to be incorporated into smartdust. TinyOS started as a collaboration between the University of California, Berkeley in co-operation with Intel Research and Crossbow Technology, and has since grown to be an international consortium, the TinyOS Alliance.

INSTALL TINY OS

To get a copy of TinyOs and its dependencies.
sudo apt-add-repository "deb http://tinyos.stanford.edu/tinyos/dists/ubuntu natty main"
apt-get update
apt-get install tinyos-2.1.2 python-dev automake subversion g++

Now we have the dependencies we can get a more up-to-date version.
cd ~
mkdir -p local/src
cd local/src
svn checkout http://tinyos-main.googlecode.com/svn/trunk/ tinyos-2.x

cd tinyos-2.x/tools
./Bootstrap
./configure --prefix=$HOME/local
make all
make install

Add to bottom of .profile
export PATH=$HOME/local/bin:$PATH
export TOSROOT=$HOME/local/src/tinyos-2.x
export TOSDIR=$TOSROOT/tos
export MAKERULES=$TOSROOT/support/make/Makerules
export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.
export PYTHONPATH=.:$TOSROOT/support/sdk/python:$PYTHONPATH
export PATH=$TOSROOT/support/sdk/c:$PATH
export MOTECOM=serial@/dev/ttyUSB0:115200

For AODV
Extract system and interfaces from NST-AODV.tar.gz into ~/local/src/tinyos-2.x/tos
Extract libraries into ~/local/src/tinyos-2.x/tos/system

Copy over modified files
To reject packets with failed CRC errors
Modify $TOSROOT/support/sdk/python/tos.py
if crc != packet_crc:
    print "Warning: wrong CRC! %x != %x %s" % (crc, packet_crc, ["%2x" % i for i in packet])
    return None

For permission to write to the USB port
sudo usermod -a -G dialout USERNAME

Errors

Fatal error: Python.h
If you get /opt/tinyos-2.1.1/tos/lib/tossim/tossim_wrap.cxx:139:20: fatal error: Python.h: No such file or directory compilation terminated.
Change PYTHON_VERION from 2.5 to 2.7 in /opt/tinyos-2.1.1/support/make/sim.extra

No permissions to write to the USB port
Either just chmod 777 the USB port, however this needs to be done each time the device is plugged in or you can add the current user to the dialout group.

NST-AODV
In AODV.h put "#include <message.h>"
Make sure the code you are compiling has "component PrintfC"

Contiki

Install guide

Summary of https://github.com/g-oikonomou/contiki-sensinode/wiki/Prepare-your-System
Grab the latest tarball of the SDCC source from http://sourceforge.net/projects/sdcc/files/snapshot_builds/sdcc-src/ and extract the folder somewhere. Now do the following.
cd SDCC
wget https://github.com/g-oikonomou/contiki-sensinode/wiki/contiki-sdcc.patch
patch -p0 < contiki-sdcc.patch
sudo apt-get install libboost-graph-dev flex bison
./configure --disable-gbz80-port --disable-z80-port --disable-ds390-port --disable-ds400-port --disable-pic14-port --disable-pic16-port --disable-hc08-port --disable-r2k-port --disable-z180-port --disable-sdcdb --disable-ucsim
make
sudo make install
cd ..
git clone https://github.com/g-oikonomou/contiki-sensinode.git
cd contiki-sensinode/examples/cc2530dk/
make

All done!

NS-2

I have currently implemented a Ns-2 application, aimed to connect Ns-2 which is written in C++ and Tcl to Python in order to provide a simple way to develop scenarios.

Ubuntu 10.10 Installation
If it cant find sources add 'deb-src http://uk.archive.ubuntu.com/ubuntu/ oneiric universe' to '/etc/apt/sources.list'.
sudo apt-get build-dep ns2
apt-get source ns2
cd ns2-2.35~RC6
gedit ./common/mobilenode.cc
gedit Makefile.in
./configure
make

Self-Defined Packets
Some programming tips for applications which are defining their own packet structures is to include 'agent_->set_pkttype(PT_CBR);' into the body of the application. I think this is only needed if the underlying agent is UDP, as this will tag all the packet types as UDP, which are classified as non-data packets, and thus will not cause routing protocols such as AODV to attempt route recovery.
802.15.4 Broadcast Bug
Another interesting bug that I found was when causing 20 nodes in the same proximity to broadcast at the exact same instant, whilst using the 802.15.4 physical layer.
This causes a 'Program received signal SIGFPE, Arithmetic exception' error, which is at 'lq = (int)(tmpf * 128);' in 'wpan/p802_15_4phy.cc:499'.
The line before this calculates tmpf which is 'tmpf = p->txinfo_.RxPr/RXThresh_;', with RxPr being in watts (according to here).
Normally this is around 0.000192w, but in this case jumps to 0.281838w, which then causes an error when later cast to an integer. This could perhaps be fixed by checking the overflow condition first, however simply removing the highly unlikely simultaneous broadcasting should do the trick.
802.15.4 AODV Sending Limit
So all seems well, however after some time my simulations just stopped receiving packets. This was interesting as it's the same sequence of data being sent at the same time intervals every period. After some investigation I found a way to make the simulation work, but I'm not sure of the side effects.
In p802_15_4phy.cc, on line 509 do a check to see if HDR_LRWPAN(p)->rxTotPower == 0 and if it is set lq2 to 255. This is due to the following step sometimes causing a division by 0 error on this line.
In the same file, on line 772 override the "else if (p != rxPkt)" by putting && false in the if, or similar. According to the comment this section checks if the packet is corrupted or un-detectable, so this modification will most likely have side effects, but for now it works.
Other Fixes
For the random TCL error below when using 802.11 comment out 'tcl.evalf("%s reset-state", str);' at common/mobilenode.cc:205
_o1725 off
ns: _o1728 reset-state: 
(_o1728 cmd line 1)
invoked from within
"_o1728 cmd reset-state"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o1728" line 2)
(SplitObject unknown line 2)
invoked from within
"_o1728 reset-state"
Still working on the remaining 802.15.4 errors.
Quick install guide
apt-get source ns2
apt-get package-dep ns2
gedit ns.../common/mobilenode.cc
gedit Makefile.in
./configure
make

For More: Click here
For TinyOS Programming, Click here