From 5444581739edad1612141afadc4820d0032205d3 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Wed, 3 Nov 2010 15:36:38 +0000 Subject: [PATCH] Data collection over RPL/IPv6 --- examples/ipv6/rpl-collect/Makefile | 12 + examples/ipv6/rpl-collect/collect-common.c | 169 ++++++ examples/ipv6/rpl-collect/collect-common.h | 57 ++ .../rpl-collect/collect-tree-dense-noloss.csc | 503 ++++++++++++++++++ .../rpl-collect/collect-tree-sparse-lossy.csc | 501 +++++++++++++++++ examples/ipv6/rpl-collect/udp-sender.c | 236 ++++++++ examples/ipv6/rpl-collect/udp-sink.c | 190 +++++++ 7 files changed, 1668 insertions(+) create mode 100644 examples/ipv6/rpl-collect/Makefile create mode 100644 examples/ipv6/rpl-collect/collect-common.c create mode 100644 examples/ipv6/rpl-collect/collect-common.h create mode 100644 examples/ipv6/rpl-collect/collect-tree-dense-noloss.csc create mode 100644 examples/ipv6/rpl-collect/collect-tree-sparse-lossy.csc create mode 100644 examples/ipv6/rpl-collect/udp-sender.c create mode 100644 examples/ipv6/rpl-collect/udp-sink.c diff --git a/examples/ipv6/rpl-collect/Makefile b/examples/ipv6/rpl-collect/Makefile new file mode 100644 index 000000000..bca710a1a --- /dev/null +++ b/examples/ipv6/rpl-collect/Makefile @@ -0,0 +1,12 @@ +CONTIKI = ../../.. +APPS = powertrace collect-view +CONTIKI_PROJECT = udp-sender udp-sink +PROJECT_SOURCEFILES += collect-common.c + +WITH_UIP6=1 +UIP_CONF_IPV6=1 + +all: $(CONTIKI_PROJECT) + +include $(CONTIKI)/Makefile.include + diff --git a/examples/ipv6/rpl-collect/collect-common.c b/examples/ipv6/rpl-collect/collect-common.c new file mode 100644 index 000000000..9f7755158 --- /dev/null +++ b/examples/ipv6/rpl-collect/collect-common.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2010, 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. + * + * $Id: collect-common.c,v 1.1 2010/11/03 15:36:38 adamdunkels Exp $ + */ + +/** + * \file + * Example of how the collect primitive works. + * \author + * Adam Dunkels + */ + +#include "contiki.h" +#include "lib/random.h" +#include "net/netstack.h" +#include "dev/serial-line.h" +#include "dev/leds.h" +#include "collect-common.h" + +#include +#include + +static unsigned long time_offset; +static int send_active = 1; + +#define PERIOD 60 +#define RANDWAIT 2 + +/*---------------------------------------------------------------------------*/ +PROCESS(collect_common_process, "collect common process"); +AUTOSTART_PROCESSES(&collect_common_process); +/*---------------------------------------------------------------------------*/ +static unsigned long +get_time(void) +{ + return clock_seconds() + time_offset; +} +/*---------------------------------------------------------------------------*/ +static unsigned long +strtolong(const char *data) { + unsigned long value = 0; + int i; + for(i = 0; i < 10 && isdigit(data[i]); i++) { + value = value * 10 + data[i] - '0'; + } + return value; +} +/*---------------------------------------------------------------------------*/ +void +collect_common_set_send_active(int active) +{ + send_active = active; +} +/*---------------------------------------------------------------------------*/ +void +collect_common_recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops, + uint8_t *payload, uint16_t payload_len) +{ + unsigned long time; + uint16_t data; + int i; + + printf("%u", 8 + payload_len / 2); + /* Timestamp. Ignore time synch for now. */ + time = get_time(); + printf(" %lu %lu 0", ((time >> 16) & 0xffff), time & 0xffff); + /* Ignore latency for now */ + printf(" %u %u %u %u", + originator->u8[0] + (originator->u8[1] << 8), seqno, hops, 0); + for(i = 0; i < payload_len / 2; i++) { + memcpy(&data, payload, sizeof(data)); + payload += sizeof(data); + printf(" %u", data); + } + printf("\n"); + leds_blink(); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(collect_common_process, ev, data) +{ + static struct etimer period_timer, wait_timer; + PROCESS_BEGIN(); + + collect_common_net_init(); + + /* Send a packet every 60-62 seconds. */ + etimer_set(&period_timer, CLOCK_SECOND * PERIOD); + while(1) { + PROCESS_WAIT_EVENT(); + if(ev == serial_line_event_message) { + char *line; + line = (char *)data; + if(strncmp(line, "collect", 7) == 0 || + strncmp(line, "gw", 2) == 0) { + collect_common_set_sink(); + } else if(strncmp(line, "net", 3) == 0) { + collect_common_net_print(); + } else if(strncmp(line, "time ", 5) == 0) { + unsigned long tmp; + line += 6; + while(*line == ' ') { + line++; + } + tmp = strtolong(line); + time_offset = clock_seconds() - tmp; + printf("Time offset set to %lu\n", time_offset); + } else if(strncmp(line, "mac ", 4) == 0) { + line +=4; + while(*line == ' ') { + line++; + } + if(*line == '0') { + NETSTACK_RDC.off(1); + printf("mac: turned MAC off (keeping radio on): %s\n", + NETSTACK_RDC.name); + } else { + NETSTACK_RDC.on(); + printf("mac: turned MAC on: %s\n", NETSTACK_RDC.name); + } + + } else if(strncmp(line, "~K", 2) == 0 || + strncmp(line, "killall", 7) == 0) { + /* Ignore stop commands */ + } else { + printf("unhandled command: %s\n", line); + } + } + if(ev == PROCESS_EVENT_TIMER) { + if(data == &period_timer) { + etimer_reset(&period_timer); + etimer_set(&wait_timer, random_rand() % (CLOCK_SECOND * RANDWAIT)); + } else if(data == &wait_timer) { + if(send_active) { + /* Time to send the data */ + collect_common_send(); + } + } + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/ipv6/rpl-collect/collect-common.h b/examples/ipv6/rpl-collect/collect-common.h new file mode 100644 index 000000000..02f0d801e --- /dev/null +++ b/examples/ipv6/rpl-collect/collect-common.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, 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. + * + * $Id: collect-common.h,v 1.1 2010/11/03 15:36:38 adamdunkels Exp $ + */ + +/** + * \file + * Common code between collect client and server + * \author + * Niclas Finne + */ + +#ifndef __COLLECT_COMMON_H__ +#define __COLLECT_COMMON_H__ + +#include "contiki.h" +#include "net/rime/rimeaddr.h" + +void collect_common_net_init(void); +void collect_common_net_print(void); +void collect_common_set_sink(void); +void collect_common_send(void); +void collect_common_recv(const rimeaddr_t *originator, uint8_t seqno, + uint8_t hops, + uint8_t *payload, + uint16_t payload_len); +void collect_common_set_send_active(int active); + +PROCESS_NAME(collect_common_process); + +#endif /* __COLLECT_COMMON_H__ */ diff --git a/examples/ipv6/rpl-collect/collect-tree-dense-noloss.csc b/examples/ipv6/rpl-collect/collect-tree-dense-noloss.csc new file mode 100644 index 000000000..66c23886d --- /dev/null +++ b/examples/ipv6/rpl-collect/collect-tree-dense-noloss.csc @@ -0,0 +1,503 @@ + + + [CONTIKI_DIR]/tools/cooja/apps/mrm + [CONTIKI_DIR]/tools/cooja/apps/mspsim + [CONTIKI_DIR]/tools/cooja/apps/avrora + [CONTIKI_DIR]/tools/cooja/apps/serial_socket + [CONTIKI_DIR]/tools/cooja/apps/collect-view + + My simulation + 0 + 123456 + 1000000 + + se.sics.cooja.radiomediums.UDGM + 100.0 + 120.0 + 1.0 + 1.0 + + + 40000 + + + se.sics.cooja.mspmote.SkyMoteType + sky1 + Sky Mote Type #sky1 + [CONFIG_DIR]/udp-sink.c + make udp-sink.sky TARGET=sky + [CONFIG_DIR]/udp-sink.sky + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.mspmote.interfaces.MspClock + se.sics.cooja.mspmote.interfaces.MspMoteID + se.sics.cooja.mspmote.interfaces.SkyButton + se.sics.cooja.mspmote.interfaces.SkyFlash + se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem + se.sics.cooja.mspmote.interfaces.SkyByteRadio + se.sics.cooja.mspmote.interfaces.MspSerial + se.sics.cooja.mspmote.interfaces.SkyLED + se.sics.cooja.mspmote.interfaces.MspDebugOutput + se.sics.cooja.mspmote.interfaces.SkyTemperature + + + se.sics.cooja.mspmote.SkyMoteType + sky2 + Sky Mote Type #sky2 + [CONFIG_DIR]/udp-sender.c + make udp-sender.sky TARGET=sky + [CONFIG_DIR]/udp-sender.sky + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.mspmote.interfaces.MspClock + se.sics.cooja.mspmote.interfaces.MspMoteID + se.sics.cooja.mspmote.interfaces.SkyButton + se.sics.cooja.mspmote.interfaces.SkyFlash + se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem + se.sics.cooja.mspmote.interfaces.SkyByteRadio + se.sics.cooja.mspmote.interfaces.MspSerial + se.sics.cooja.mspmote.interfaces.SkyLED + se.sics.cooja.mspmote.interfaces.MspDebugOutput + se.sics.cooja.mspmote.interfaces.SkyTemperature + + + + + se.sics.cooja.interfaces.Position + 242.83184008074136 + -88.93434685786869 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + se.sics.cooja.interfaces.Position + 223.5175954004352 + -69.05842098947238 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 250.51864863077387 + -59.2420165357677 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 3 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 294.4736028715864 + -63.23792146675066 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 4 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 188.6638305152632 + -41.28432709660093 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 5 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 222.54731411389315 + -32.869043991280165 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 6 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 273.694897230475 + -29.672320046493798 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 7 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 321.64575640227054 + -33.66822497747676 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 8 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 159.4120162043624 + -2.500166515809672 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 9 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 196.97352255560222 + -0.10262355721989598 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 10 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 252.91619158936365 + 1.495738415173288 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 11 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 301.66623174735577 + -0.10262355721989598 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 12 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 346.4203669743649 + 1.495738415173288 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 13 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 124.24805281171236 + 22.27444405628468 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 14 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 180.1907218454738 + 35.86052082162674 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 15 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 224.14567608628633 + 30.266253918250598 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 16 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 276.0924401890648 + 35.86052082162674 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 17 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 351.2154528915445 + 37.45888279401993 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 18 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 89.08408941906231 + 47.04905462837903 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 19 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 180.1907218454738 + 75.02038914525976 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 20 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 245.7235627135943 + 66.22939829709723 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 21 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 290.4776979406035 + 67.82776026949043 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 22 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 370.3957965602627 + 64.63103632470406 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 23 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 93.07999435004527 + 82.21301802102909 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 24 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 204.16615143137156 + 106.18844760692684 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 25 + + sky2 + + + + se.sics.cooja.plugins.SimControl + 259 + 2 + 184 + 0 + 0 + + + se.sics.cooja.plugins.Visualizer + + se.sics.cooja.plugins.skins.IDVisualizerSkin + se.sics.cooja.plugins.skins.AttributeVisualizerSkin + se.sics.cooja.plugins.skins.UDGMVisualizerSkin + 1.836243522352668 0.0 0.0 1.836243522352668 -93.43273668589363 192.8080782058222 + + 666 + 0 + 510 + 369 + -8 + + + se.sics.cooja.plugins.LogListener + + + + 1347 + 4 + 150 + 0 + 438 + + + se.sics.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + + + + 109 + 500.0 + + 1347 + 3 + 150 + 0 + 588 + + + se.sics.cooja.plugins.collectview.CollectView + 0 + 203 + 1 + 75 + 33 + 188 + + + diff --git a/examples/ipv6/rpl-collect/collect-tree-sparse-lossy.csc b/examples/ipv6/rpl-collect/collect-tree-sparse-lossy.csc new file mode 100644 index 000000000..350497f3b --- /dev/null +++ b/examples/ipv6/rpl-collect/collect-tree-sparse-lossy.csc @@ -0,0 +1,501 @@ + + + [CONTIKI_DIR]/tools/cooja/apps/mrm + [CONTIKI_DIR]/tools/cooja/apps/mspsim + [CONTIKI_DIR]/tools/cooja/apps/avrora + [CONTIKI_DIR]/tools/cooja/apps/serial_socket + [CONTIKI_DIR]/tools/cooja/apps/collect-view + + My simulation + 0 + 123456 + 1000000 + + se.sics.cooja.radiomediums.UDGM + 70.0 + 90.0 + 1.0 + 0.0 + + + 40000 + + + se.sics.cooja.mspmote.SkyMoteType + sky1 + Sky Mote Type #sky1 + [CONFIG_DIR]/udp-sink.c + make udp-sink.sky TARGET=sky + [CONFIG_DIR]/udp-sink.sky + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.mspmote.interfaces.MspClock + se.sics.cooja.mspmote.interfaces.MspMoteID + se.sics.cooja.mspmote.interfaces.SkyButton + se.sics.cooja.mspmote.interfaces.SkyFlash + se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem + se.sics.cooja.mspmote.interfaces.SkyByteRadio + se.sics.cooja.mspmote.interfaces.MspSerial + se.sics.cooja.mspmote.interfaces.SkyLED + se.sics.cooja.mspmote.interfaces.MspDebugOutput + se.sics.cooja.mspmote.interfaces.SkyTemperature + + + se.sics.cooja.mspmote.SkyMoteType + sky2 + Sky Mote Type #sky2 + [CONFIG_DIR]/udp-sender.c + make udp-sender.sky TARGET=sky + [CONFIG_DIR]/udp-sender.sky + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.mspmote.interfaces.MspClock + se.sics.cooja.mspmote.interfaces.MspMoteID + se.sics.cooja.mspmote.interfaces.SkyButton + se.sics.cooja.mspmote.interfaces.SkyFlash + se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem + se.sics.cooja.mspmote.interfaces.SkyByteRadio + se.sics.cooja.mspmote.interfaces.MspSerial + se.sics.cooja.mspmote.interfaces.SkyLED + se.sics.cooja.mspmote.interfaces.MspDebugOutput + se.sics.cooja.mspmote.interfaces.SkyTemperature + + + + + se.sics.cooja.interfaces.Position + 242.83184008074136 + -88.93434685786869 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + se.sics.cooja.interfaces.Position + 205.7645134037647 + -62.438740480554074 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 250.51864863077387 + -59.2420165357677 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 3 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 294.4736028715864 + -63.23792146675066 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 4 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 176.19481691449084 + -35.26658694986995 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 5 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 222.54731411389315 + -32.869043991280165 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 6 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 273.694897230475 + -29.672320046493798 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 7 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 321.64575640227054 + -33.66822497747676 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 8 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 159.4120162043624 + -2.500166515809672 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 9 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 196.97352255560222 + -0.10262355721989598 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 10 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 252.91619158936365 + 1.495738415173288 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 11 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 301.66623174735577 + -0.10262355721989598 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 12 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 346.4203669743649 + 1.495738415173288 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 13 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 124.24805281171236 + 22.27444405628468 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 14 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 180.1907218454738 + 35.86052082162674 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 15 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 224.14567608628633 + 30.266253918250598 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 16 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 276.0924401890648 + 35.86052082162674 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 17 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 351.2154528915445 + 37.45888279401993 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 18 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 89.08408941906231 + 47.04905462837903 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 19 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 180.1907218454738 + 75.02038914525976 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 20 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 245.7235627135943 + 66.22939829709723 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 21 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 290.4776979406035 + 67.82776026949043 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 22 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 370.3957965602627 + 64.63103632470406 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 23 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 93.07999435004527 + 82.21301802102909 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 24 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 204.16615143137156 + 106.18844760692684 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 25 + + sky2 + + + + se.sics.cooja.plugins.SimControl + 259 + 3 + 184 + 0 + 0 + + + se.sics.cooja.plugins.Visualizer + + se.sics.cooja.plugins.skins.IDVisualizerSkin + se.sics.cooja.plugins.skins.AttributeVisualizerSkin + se.sics.cooja.plugins.skins.UDGMVisualizerSkin + 1.836243522352668 0.0 0.0 1.836243522352668 -124.43273668589376 177.8080782058222 + + 610 + 2 + 482 + 420 + -2 + + + se.sics.cooja.plugins.LogListener + + + + 1347 + 4 + 150 + 0 + 438 + + + se.sics.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + + 109 + 500.0 + + 1347 + 0 + 150 + 0 + 588 + + + se.sics.cooja.plugins.collectview.CollectView + 0 + 203 + 1 + 75 + 120 + 120 + + + diff --git a/examples/ipv6/rpl-collect/udp-sender.c b/examples/ipv6/rpl-collect/udp-sender.c new file mode 100644 index 000000000..430e55e29 --- /dev/null +++ b/examples/ipv6/rpl-collect/udp-sender.c @@ -0,0 +1,236 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include "net/uip.h" +#include "net/uip-ds6.h" +#include "net/uip-udp-packet.h" +#include "net/neighbor-info.h" +#include "net/rpl/rpl.h" +#include "dev/serial-line.h" +#if CONTIKI_TARGET_Z1 +#include "dev/uart0.h" +#else +#include "dev/uart1.h" +#endif +#include "collect-common.h" +#include "collect-view.h" + +#include +#include + +#define UDP_CLIENT_PORT 8775 +#define UDP_SERVER_PORT 5688 + +#define DEBUG DEBUG_PRINT +#include "net/uip-debug.h" + +static struct uip_udp_conn *client_conn; +static uip_ipaddr_t server_ipaddr; + +/*---------------------------------------------------------------------------*/ +PROCESS(udp_client_process, "UDP client process"); +AUTOSTART_PROCESSES(&udp_client_process, &collect_common_process); +/*---------------------------------------------------------------------------*/ +void +collect_common_set_sink(void) +{ + /* A udp client can never become sink */ +} +/*---------------------------------------------------------------------------*/ +extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB]; + +void +collect_common_net_print(void) +{ + rpl_dag_t *dag; + int i; + dag = rpl_get_dag(RPL_ANY_INSTANCE); + if(dag->preferred_parent != NULL) { + PRINTF("Preferred parent: "); + PRINT6ADDR(&dag->preferred_parent->addr); + PRINTF("\n"); + } + PRINTF("Route entries:\n"); + for(i = 0; i < UIP_DS6_ROUTE_NB; i++) { + if(uip_ds6_routing_table[i].isused) { + PRINT6ADDR(&uip_ds6_routing_table[i].ipaddr); + PRINTF("\n"); + } + } + PRINTF("---\n"); +} +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + if(uip_newdata()) { + /* Ignore incoming data */ + } +} +/*---------------------------------------------------------------------------*/ +void +collect_common_send(void) +{ + static uint8_t seqno; + struct { + uint8_t seqno; + uint8_t for_alignment; + struct collect_view_data_msg msg; + } msg; + /* struct collect_neighbor *n; */ + uint16_t parent_etx; + uint16_t rtmetric; + uint16_t num_neighbors; + uint16_t beacon_interval; + rpl_parent_t *preferred_parent; + rimeaddr_t parent; + rpl_dag_t *dag; + + if(client_conn == NULL) { + /* Not setup yet */ + return; + } + memset(&msg, 0, sizeof(msg)); + seqno++; + if(seqno == 0) { + /* Wrap to 128 to identify restarts */ + seqno = 128; + } + msg.seqno = seqno; + + rimeaddr_copy(&parent, &rimeaddr_null); + parent_etx = 0; + + dag = rpl_get_dag(RPL_DEFAULT_INSTANCE); + if(dag != NULL) { + preferred_parent = dag->preferred_parent; + if(preferred_parent != NULL) { + uip_ds6_nbr_t *nbr; + nbr = uip_ds6_nbr_lookup(&preferred_parent->addr); + if(nbr != NULL) { + rimeaddr_copy(&parent, (rimeaddr_t *)&nbr->ipaddr.u8[8]); + parent_etx = neighbor_info_get_etx((rimeaddr_t *) &nbr->lladdr) / 2; + } + } + rtmetric = dag->rank; + beacon_interval = (uint16_t) ((2L << dag->dio_intcurrent) / 1000); + num_neighbors = RPL_PARENT_COUNT(dag); + } else { + rtmetric = 0; + beacon_interval = 0; + num_neighbors = 0; + } + + /* num_neighbors = collect_neighbor_list_num(&tc.neighbor_list); */ + collect_view_construct_message(&msg.msg, &parent, + parent_etx, rtmetric, + num_neighbors, beacon_interval); + + uip_udp_packet_sendto(client_conn, &msg, sizeof(msg), + &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT)); +} +/*---------------------------------------------------------------------------*/ +void +collect_common_net_init(void) +{ +#if CONTIKI_TARGET_Z1 + uart0_set_input(serial_line_input_byte); +#else + uart1_set_input(serial_line_input_byte); +#endif + serial_line_init(); +} +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTF("Client IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + /* hack to make address "final" */ + if (state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } +} +/*---------------------------------------------------------------------------*/ +static void +set_global_address(void) +{ + uip_ipaddr_t ipaddr; + + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); + + /* set server address */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); + +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_client_process, ev, data) +{ + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + set_global_address(); + + PRINTF("UDP client process started\n"); + + print_local_addresses(); + + /* new connection with remote host */ + client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); + udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); + + PRINTF("Created a connection with the server "); + PRINT6ADDR(&client_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", + UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); + + while(1) { + PROCESS_YIELD(); + if(ev == tcpip_event) { + tcpip_handler(); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/ipv6/rpl-collect/udp-sink.c b/examples/ipv6/rpl-collect/udp-sink.c new file mode 100644 index 000000000..11a4f7346 --- /dev/null +++ b/examples/ipv6/rpl-collect/udp-sink.c @@ -0,0 +1,190 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" +#include "net/uip.h" +#include "net/rpl/rpl.h" +#include "net/rime/rimeaddr.h" + +#include "net/netstack.h" +#include "dev/button-sensor.h" +#include "dev/serial-line.h" +#if CONTIKI_TARGET_Z1 +#include "dev/uart0.h" +#else +#include "dev/uart1.h" +#endif +#include +#include +#include +#include +#include "collect-common.h" +#include "collect-view.h" + +#define DEBUG DEBUG_PRINT +#include "net/uip-debug.h" + +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) + +#define UDP_CLIENT_PORT 8775 +#define UDP_SERVER_PORT 5688 + +static struct uip_udp_conn *server_conn; + +PROCESS(udp_server_process, "UDP server process"); +AUTOSTART_PROCESSES(&udp_server_process,&collect_common_process); +/*---------------------------------------------------------------------------*/ +void +collect_common_set_sink(void) +{ +} +/*---------------------------------------------------------------------------*/ +void +collect_common_net_print(void) +{ + printf("I am sink!\n"); +} +/*---------------------------------------------------------------------------*/ +void +collect_common_send(void) +{ + /* Server never sends */ +} +/*---------------------------------------------------------------------------*/ +void +collect_common_net_init(void) +{ +#if CONTIKI_TARGET_Z1 + uart0_set_input(serial_line_input_byte); +#else + uart1_set_input(serial_line_input_byte); +#endif + serial_line_init(); + + PRINTF("I am sink!\n"); +} +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + uint8_t *appdata; + rimeaddr_t sender; + uint8_t seqno; + uint8_t hops; + + if(uip_newdata()) { + appdata = (uint8_t *)uip_appdata; + sender.u8[0] = UIP_IP_BUF->srcipaddr.u8[15]; + sender.u8[1] = UIP_IP_BUF->srcipaddr.u8[14]; + seqno = *appdata; + hops = uip_ds6_if.cur_hop_limit - UIP_IP_BUF->ttl + 1; + collect_common_recv(&sender, seqno, hops, + appdata + 2, uip_datalen() - 2); + } +} +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTF("Server IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(state == ADDR_TENTATIVE || state == ADDR_PREFERRED) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + /* hack to make address "final" */ + if (state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_server_process, ev, data) +{ + uip_ipaddr_t ipaddr; + struct uip_ds6_addr *root_if; + + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + SENSORS_ACTIVATE(button_sensor); + + PRINTF("UDP server started\n"); + +#if UIP_CONF_ROUTER + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); + /* uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); */ + uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL); + root_if = uip_ds6_addr_lookup(&ipaddr); + if(root_if != NULL) { + rpl_dag_t *dag; + rpl_set_root((uip_ip6addr_t *)&ipaddr); + dag = rpl_get_dag(RPL_ANY_INSTANCE); + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + rpl_set_prefix(dag, &ipaddr, 64); + PRINTF("created a new RPL dag\n"); + } else { + PRINTF("failed to create a new RPL DAG\n"); + } +#endif /* UIP_CONF_ROUTER */ + + print_local_addresses(); + + /* The data sink runs with a 100% duty cycle in order to ensure high + packet reception rates. */ + NETSTACK_RDC.off(1); + + server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL); + udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT)); + + PRINTF("Created a server connection with remote address "); + PRINT6ADDR(&server_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", UIP_HTONS(server_conn->lport), + UIP_HTONS(server_conn->rport)); + + while(1) { + PROCESS_YIELD(); + if(ev == tcpip_event) { + tcpip_handler(); + } else if (ev == sensors_event && data == &button_sensor) { + PRINTF("Initiaing global repair\n"); + rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE)); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/