Sunday, August 7, 2016

Generate an interfering node in Contiki OS

Objective

To create an interfering node using a sky CM5000 node that has a CC2420 radio. The interference will be created using an unmodulated carrier. I used the paper [1] to get the code and the idea. I strongly recommend you reading the paper [1] if you want to make a serious study of interference in WSN. I tested the code using Contiki v3.0 and lubuntu 16.04.

Step 1: To disable the MAC layer of the node

The first step in order to create an unmodulated carrier (interference) is to disable the MAC layer of Contiki. To that end, you must create a file named project-conf.h. I am going to create that file in the RIME directory because that is where i am working:

/home/YOURUSER/contiki-3.0/examples/rime/project-conf.h

Within project-conf.h you must disable the MAC by selecting the null mac driver and the null rdc driver. If you want more information about the Contiki communication stack please read the information provided by the following link:

http://anrg.usc.edu/contiki/index.php/MAC_protocols_in_ContikiOS

Then, your project-conf.h must look like this:

#define NETSTACK_CONF_MAC     nullmac_driver // Define the MAC driver to use
#define NETSTACK_CONF_RDC     nullrdc_driver // Define the RDC driver to use
In order that Contiki reads the information that your project-conf.h file contains, then you must insert the following line CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" in the Makefile, which is located in the rime directory (where we are working). Consequently, your Makefile must look like this:
CONTIKI = ../..
 
all: example-abc example-mesh example-collect example-trickle example-polite \
     example-rudolph1 example-rudolph2 example-rucb \
     example-runicast example-unicast example-neighbors
 
CONTIKI_WITH_RIME = 1
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
include $(CONTIKI)/Makefile.include
Now, you have disabled the MAC layer of your interfering node. If you load the Rime broadcast example in your node (example-broadcast.c), then you will see the nullmac and the nullrdc configured (see the code below). The following link explains in detail how to create the project-conf.h file, but this example changes the radio channel, not the MAC layer.

http://contiki-iot.blogspot.com.co/2016/07/project-configuration-example.html

Rime started with address 1.0                                                
MAC 01:00:00:00:00:00:00:00 Contiki 3.0 started. Node id is set to 1.        
nullsec nullmac nullrdc, channel check rate 8 Hz, radio channel 20           
Starting 'Broadcast example'

Step 2: To generate an unmodulated carrier

In order to generate an unmodulated carrier i used the idea and the code from the paper [1]. I show you the complete Contiki code:
/*
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the Contiki operating system.
 *
 */

/**
 * \file
 *        Example of an interfering node
 * \author
 *        Sergio Diaz
 */

#include "contiki.h"

#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420.h" // Include the CC2420 library
#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420_const.h" // Include the CC2420 constants 
#include "/home/sink/Desktop/contiki-3.0/core/dev/spi.h" // Include basic SPI macros

/*---------------------------------------------------------------------------*/
PROCESS(unmodulated_carrier, "CC2420 Unmodulated Carrier"); // Declares the process unmodulated_carrier
AUTOSTART_PROCESSES(&unmodulated_carrier); // Load the process on boot

/*---------------------------------------------------------------------------*/
/** 
 * Writes to a register.
 * Note: the SPI_WRITE(0) seems to be needed for getting the
 * write reg working on the Z1 / MSP430X platform
 */
static void
setreg(enum cc2420_register regname, uint16_t value) // Set the register of the cc2420 radio
{
  CC2420_SPI_ENABLE();
  SPI_WRITE_FAST(regname);
  SPI_WRITE_FAST((uint8_t) (value >> 8));
  SPI_WRITE_FAST((uint8_t) (value & 0xff));
  SPI_WAITFORTx_ENDED();
  SPI_WRITE(0);
  CC2420_SPI_DISABLE();
}

/* Sends a strobe */
static void
strobe(enum cc2420_register regname)
{
  CC2420_SPI_ENABLE();
  SPI_WRITE(regname);
  CC2420_SPI_DISABLE();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unmodulated_carrier, ev, data) // Defines the process unmodulated_carrier
{

  PROCESS_BEGIN();  // Says where the process starts

  // Creates an unmodulated carrier
  setreg(CC2420_MANOR, 0x0100);
  setreg(CC2420_TOPTST, 0x0004);
  setreg(CC2420_MDMCTRL1, 0x0508);
  setreg(CC2420_DACTST, 0x1800);
  strobe(CC2420_STXON); 

  PROCESS_END();  //Says where the process ends
}
/*---------------------------------------------------------------------------*/


I tested the interfering node in the following set up. I have three nodes: a sink, a temperature node and an interfering node. The temperature node sends its data to the sink via radio, then i observe in the sink that the messages arrive without problem. Then, i turn the interfering node on and i suddenly observe that no more packets arrive. If i turn the interfering node off then the packets arrive again with no problem. Consequently, the interfering node introduces noise in the communication between the sink and the temperature node. This noise (an unmodulated carrier) is so strong that no more packets arrive to the sink. If you want a more sophisticated interfering node i strongly recommend you to read the paper [2] and make my tutorial named Generate an improved interfering node in Contiki OS located in the following link.

http://contiki-iot.blogspot.com.co/2016/08/generate-improved-interfering-node-in.html

Reset the CC2420 to normal behaviour

When you are done using your interfering node, then you must reset the CC2420's register to normal behaviour. To that end, you must run the following code in your node:
/*
 * Copyright (c) 2007, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the Contiki operating system.
 *
 */

/**
 * \file
 *        Example of an interfering node
 * \author
 *        Sergio Diaz
 */

#include "contiki.h"

#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420.h" // Include the CC2420 library
#include "/home/sink/Desktop/contiki-3.0/dev/cc2420/cc2420_const.h" // Include the CC2420 constants 
#include "/home/sink/Desktop/contiki-3.0/core/dev/spi.h" // Include basic SPI macros

/*---------------------------------------------------------------------------*/
PROCESS(reset_cc2420_registers, "CC2420 Reset Registers"); // Declares the process reset_cc2420_registers
AUTOSTART_PROCESSES(&reset_cc2420_registers); // Load the process on boot

/*---------------------------------------------------------------------------*/
/** 
 * Writes to a register.
 * Note: the SPI_WRITE(0) seems to be needed for getting the
 * write reg working on the Z1 / MSP430X platform
 */
static void
setreg(enum cc2420_register regname, uint16_t value) // Set the register of the cc2420 radio
{
  CC2420_SPI_ENABLE();
  SPI_WRITE_FAST(regname);
  SPI_WRITE_FAST((uint8_t) (value >> 8));
  SPI_WRITE_FAST((uint8_t) (value & 0xff));
  SPI_WAITFORTx_ENDED();
  SPI_WRITE(0);
  CC2420_SPI_DISABLE();
}

/* Sends a strobe */
static void
strobe(enum cc2420_register regname)
{
  CC2420_SPI_ENABLE();
  SPI_WRITE(regname);
  CC2420_SPI_DISABLE();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(reset_cc2420_registers, ev, data) // Defines the process reset_cc2420_registers
{

  PROCESS_BEGIN();  // Says where the process starts

  // Reset CC2420's register to normal behaviour
   setreg(CC2420_MANOR, 0x0000);
   setreg(CC2420_TOPTST, 0x0010);
   setreg(CC2420_MDMCTRL1, 0x0500);
   setreg(CC2420_DACTST, 0x0000);
   strobe(CC2420_STXON);

  PROCESS_END();  //Says where the process ends
}
/*---------------------------------------------------------------------------*/


Video

I created an unmodulated carrier at channel 20 and to visualize the signal i am using the rssi-scanner provided by Contiki. When i press the restart button of the sky mote the carrier at channel 20 disappears, then it appears when the program starts running again.

References

Notice that the author from papers [1] and [2] is the same guy (Carlo Alberto Boano ).

[1] C. A. Boano, Z. He, Y. Li, T. Voigt, M. Zúñniga and A. Willig, "Controllable radio interference for experimental and testing purposes in Wireless Sensor Networks," 2009 IEEE 34th Conference on Local Computer Networks, Zurich, 2009, pp. 865-872.

[2] Boano, Carlo Alberto; Voigt, Thiemo; Tsiftes, Nicolas; Mottola, Luca; Römer, Kay; Zúñiga, Marco Antonio. Making Sensornet MAC Protocols Robust against Interference. Proceedings of the Wireless Sensor Networks: 7th European Conference - EWSN, Coimbra, Portugal, February 17-19, 2010, pp. 272-288.

No comments:

Post a Comment