From d75123874723d06fdd835f7b2845be688171010b Mon Sep 17 00:00:00 2001 From: nvt-se Date: Fri, 30 Apr 2010 15:52:48 +0000 Subject: [PATCH] Added an example of using UDP over an RPL-enabled IPv6 network --- examples/ipv6/rpl-udp/Makefile | 84 +++++ examples/ipv6/rpl-udp/rpl-udp.csc | 584 +++++++++++++++++++++++++++++ examples/ipv6/rpl-udp/udp-client.c | 176 +++++++++ examples/ipv6/rpl-udp/udp-server.c | 145 +++++++ 4 files changed, 989 insertions(+) create mode 100644 examples/ipv6/rpl-udp/Makefile create mode 100755 examples/ipv6/rpl-udp/rpl-udp.csc create mode 100644 examples/ipv6/rpl-udp/udp-client.c create mode 100644 examples/ipv6/rpl-udp/udp-server.c diff --git a/examples/ipv6/rpl-udp/Makefile b/examples/ipv6/rpl-udp/Makefile new file mode 100644 index 000000000..e23e4179e --- /dev/null +++ b/examples/ipv6/rpl-udp/Makefile @@ -0,0 +1,84 @@ +all: udp-client udp-server + +CONTIKI=../../../../contiki-2.x + +TARGET=sky + +WITH_UIP6=1 +UIP_CONF_IPV6=1 + +ifdef WITH_TCP +include test-tcp/Makefile.test-tcp +endif + +include $(CONTIKI)/Makefile.include + +upload-testbed: + $(MAKE) testbed-log-stop + $(MAKE) udp-client.testbed + $(MAKE) udp-server.testbed NODE=1 + $(MAKE) testbed-reset testbed-log + +download-logs: testbed-log-download + +parse-mote-output: + cat mote-output-* | grep -a "P "| ./scripts/parse-power-data > power-data + cat mote-output-* | grep -a "P "| ./scripts/parse-node-power > node-power-data + cat mote-output-* | ./scripts/parse-prr-data + +parse-logs: + cat testbed-log-dir/*.log | grep -a "P " | ./scripts/parse-power-data > power-data + cat testbed-log-dir/*.log | grep -a "P " | ./scripts/parse-node-power | sort -nr > node-power-data + cat testbed-log-dir/*.log | ./scripts/parse-prr-data + +parse-some-logs: + cat $(foreach L, 7 14 3 0, testbed-log-dir/$(L).log) | grep -a "P " | ./scripts/parse-power-data > power-data + cat $(foreach L, 7 14 3 0, testbed-log-dir/$(L).log) | grep -a "P " | ./scripts/parse-node-power > node-power-data + cat $(foreach L, 7 14 3 0, testbed-log-dir/$(L).log) | ./scripts/parse-prr-data + +parse-simulation: + cat roll-rpl-power-experiment-large.log | grep "P " | ./scripts/parse-power-data > power-data + cat roll-rpl-power-experiment-large.log | grep "P " | ./scripts/parse-node-power | sort -nr > node-power-data + cat roll-rpl-power-experiment-large.log | cut -f 3- -d \ | ./scripts/parse-prr-data + +parse-ongoing-simulation: + cat COOJA.testlog | grep "P " | ./scripts/parse-power-data > power-data + cat COOJA.testlog | grep "P " | ./scripts/parse-node-power > node-power-data + cat COOJA.testlog | cut -f 3- -d \ | ./scripts/parse-prr-data + +plot: + gnuplot scripts/plot-power + +show: + gv power.eps + gv node-power.eps + +graphs: + make parse-logs plot + cp power.eps experimental-power.eps + cp node-power-narrow.eps experimental-node-power.eps + make parse-simulation plot + cp power.eps simulation-power.eps + cp node-power.eps simulation-node-power.eps + +copygraphs: + cp experimental-*.eps simulation-*.eps ~/nes/papers/rpl-poster/figures/ + + +download-show: download-logs parse-logs plot show + + +# ej 61, 106 17 67 39 90 +# bara 36 20 8 59 13 62 + +# Good nodes: 3 7 11 14 0 9 +# 7 (36), 11 (20), 14 (8), 3 (59), 0 (13), 9 (62) + + +LOGMOTES=1 2 3 4 5 + +logmote-%: + make login MOTE=$* > mote-output-$* + +logmotes: + make -j 100 $(foreach M, $(LOGMOTES), logmote-$M) diff --git a/examples/ipv6/rpl-udp/rpl-udp.csc b/examples/ipv6/rpl-udp/rpl-udp.csc new file mode 100755 index 000000000..76ed10599 --- /dev/null +++ b/examples/ipv6/rpl-udp/rpl-udp.csc @@ -0,0 +1,584 @@ + + + [CONTIKI_DIR]/tools/cooja/apps/mrm + [CONTIKI_DIR]/tools/cooja/apps/mspsim + [CONTIKI_DIR]/tools/cooja/apps/avrora + [CONTIKI_DIR]/tools/cooja/apps/mobility + + Data collection network using IPv6 and RPL + 0 + generated + 5000000 + + se.sics.cooja.radiomediums.UDGM + 50.0 + 50.0 + 1.0 + 1.0 + + + 40000 + + + se.sics.cooja.mspmote.SkyMoteType + sky1 + Sky Mote Type #sky1 + [CONTIKI_DIR]/examples/ipv6/rpl-udp/udp-server.c + make udp-server.sky TARGET=sky + [CONTIKI_DIR]/examples/ipv6/rpl-udp/udp-server.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 + [CONTIKI_DIR]/examples/ipv6/rpl-udp/udp-client.c + make udp-client.sky TARGET=sky + [CONTIKI_DIR]/examples/ipv6/rpl-udp/udp-client.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 + 48.435974731198804 + -66.16503914182063 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + se.sics.cooja.interfaces.Position + 4.049356309774755 + 98.28771308774003 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 127.9689727848476 + 91.71883780610729 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 3 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 57.897299848739024 + 92.47229665488265 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 4 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 47.34887596588397 + -30.341495695501195 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 5 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 47.13486576528276 + 32.944481932122315 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 6 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -11.42091423859419 + 17.879870626121914 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 7 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 118.92746659954325 + 57.05973076244069 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 8 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 53.68872892015448 + 59.887319605093715 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 9 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 16.45706316609417 + 23.9075414163248 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 10 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -18.9555027263478 + 75.14274313304935 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 11 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 29.265863595275306 + 85.6911670159044 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 12 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -39.298891643282545 + -3.9704359883635574 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 13 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 66.93880603404335 + -42.39683727590697 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 14 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 94.81678343873172 + 26.921376811426246 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 15 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -43.06618588715935 + 30.68867105530305 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 16 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -34.02467970185502 + -24.313824905298304 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 17 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -28.750467760427494 + 48.01822457713635 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 18 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 124.95513738974614 + 20.140247172447996 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 19 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 15.703604317318808 + -47.6710492173345 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 20 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -40.05235049205791 + 92.47229665488265 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 21 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 121.18784314586934 + -24.313824905298304 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 22 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 88.03565379975346 + -44.657213822233054 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 23 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 24.745110502623138 + -1.7100594420374744 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 24 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 94.06332458995635 + -2.4635182908128352 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 25 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -4.639784599615941 + -9.998106778566445 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 26 + + sky2 + + + + + se.sics.cooja.interfaces.Position + -13.681290784920272 + -50.684884612435944 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 27 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 103.10483077526068 + 96.99304974753483 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 28 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 8.922474678340558 + 59.320107308766765 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 29 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 58.650758697514384 + 2.8106936506146916 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 30 + + sky2 + + + + + se.sics.cooja.interfaces.Position + 90.59867707439 + 67.97632874312737 + 0.0 + + + se.sics.cooja.mspmote.interfaces.MspMoteID + 31 + + sky2 + + + + se.sics.cooja.plugins.SimControl + 259 + 1 + 184 + 0 + 0 + + + se.sics.cooja.plugins.Visualizer + + se.sics.cooja.plugins.skins.MoteTypeVisualizerSkin + se.sics.cooja.plugins.skins.IDVisualizerSkin + se.sics.cooja.plugins.skins.UDGMVisualizerSkin + 1.327212496907238 0.0 0.0 1.327212496907238 84.15798010356802 95.26961226192635 + + 300 + 3 + 300 + 320 + 30 + + + se.sics.cooja.plugins.LogListener + + + + 1280 + 0 + 268 + 0 + 533 + + + se.sics.cooja.plugins.ScriptRunner + + + true + + 600 + 2 + 700 + 665 + 6 + + + diff --git a/examples/ipv6/rpl-udp/udp-client.c b/examples/ipv6/rpl-udp/udp-client.c new file mode 100644 index 000000000..f8090db21 --- /dev/null +++ b/examples/ipv6/rpl-udp/udp-client.c @@ -0,0 +1,176 @@ +/* + * 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 "lib/random.h" +#include "net/rime/ctimer.h" +#include "net/uip.h" +#include "net/uip-ds6.h" +#include "net/uip-udp-packet.h" +#include "node-id.h" + +#include +#include + +#ifndef SERVER_ID +#define SERVER_ID 1 +#endif + +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +#define DEBUG DEBUG_PRINT +#include "net/uip-debug.h" + +#define START_INTERVAL (15 * CLOCK_SECOND) +#define SEND_INTERVAL (60 * CLOCK_SECOND) +#define SEND_TIME (random_rand() % (SEND_INTERVAL)) +#define MAX_PAYLOAD_LEN 30 + +static struct uip_udp_conn *client_conn; +/*---------------------------------------------------------------------------*/ +PROCESS(udp_client_process, "UDP client process"); +AUTOSTART_PROCESSES(&udp_client_process); +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + char *str; + + if(uip_newdata()) { + str = uip_appdata; + str[uip_datalen()] = '\0'; + printf("DATA recv '%s'\n", str); + } +} +/*---------------------------------------------------------------------------*/ +static void +send_packet(void *ptr) +{ + static int seq_id; + char buf[MAX_PAYLOAD_LEN]; + + seq_id++; + PRINTF("DATA send to %d 'Hello %d'\n", + client_conn->ripaddr.u8[15], seq_id); + sprintf(buf, "Hello %d from the client", seq_id); + uip_udp_packet_send(client_conn, buf, strlen(buf)); +} +/*---------------------------------------------------------------------------*/ +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); +} +/*---------------------------------------------------------------------------*/ +static void +set_connection_address(uip_ipaddr_t *ipaddr) +{ +#ifdef IEEE_802154_MAC_ADDRESS + /* Node 1 in the testbed scripts */ + uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; + ieee[7] = SERVER_ID; + uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(ipaddr, (uip_lladdr_t *) ieee); +#else + uip_ip6addr(ipaddr,0xaaaa,0,0,0,0x0212,0x7400 + SERVER_ID, + SERVER_ID,SERVER_ID << 8 | SERVER_ID); +#endif +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_client_process, ev, data) +{ + static struct etimer periodic; + static struct ctimer backoff_timer; + uip_ipaddr_t ipaddr; + + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + PRINTF("UDP client process started\n"); + +#if UIP_CONF_ROUTER + set_global_address(); +#endif + + print_local_addresses(); + + set_connection_address(&ipaddr); + + /* new connection with remote host */ + client_conn = udp_new(&ipaddr, HTONS(UDP_SERVER_PORT), NULL); + udp_bind(client_conn, HTONS(UDP_CLIENT_PORT)); + + PRINTF("Created a connection with the server "); + PRINT6ADDR(&client_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", + HTONS(client_conn->lport), HTONS(client_conn->rport)); + + etimer_set(&periodic, SEND_INTERVAL); + while(1) { + PROCESS_YIELD(); + if(ev == tcpip_event) { + tcpip_handler(); + } + + if(etimer_expired(&periodic)) { + etimer_reset(&periodic); + ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/ipv6/rpl-udp/udp-server.c b/examples/ipv6/rpl-udp/udp-server.c new file mode 100644 index 000000000..6a4f1debb --- /dev/null +++ b/examples/ipv6/rpl-udp/udp-server.c @@ -0,0 +1,145 @@ +/* + * 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 "node-id.h" + +#include "net/netstack.h" +#include "dev/button-sensor.h" +#include +#include +#include +#include + +#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 8765 +#define UDP_SERVER_PORT 5678 + +static struct uip_udp_conn *server_conn; + +uint16_t dag_id[] = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011}; + +PROCESS(udp_server_process, "UDP server process"); +AUTOSTART_PROCESSES(&udp_server_process); +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + char *appdata; + + if(uip_newdata()) { + appdata = (char *)uip_appdata; + appdata[uip_datalen()] = 0; + PRINTF("DATA recv '%s' from ", appdata); + PRINTF("%d", UIP_IP_BUF->srcipaddr.u8[15]); + PRINTF("\n"); + } +} +/*---------------------------------------------------------------------------*/ +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, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); + root_if = uip_ds6_addr_lookup(&ipaddr); + if(root_if != NULL) { + rpl_set_root((uip_ip6addr_t *)dag_id); + 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_MAC.off(1); + + server_conn = udp_new(NULL, HTONS(UDP_CLIENT_PORT), NULL); + udp_bind(server_conn, HTONS(UDP_SERVER_PORT)); + + PRINTF("Created a server connection with remote address "); + PRINT6ADDR(&server_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", HTONS(server_conn->lport), + 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(); +} +/*---------------------------------------------------------------------------*/