From 08d4c9f594a9b23af8035133f0fa2532d1b85d6e Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 12 May 2018 11:35:38 -0700 Subject: [PATCH 1/4] rpl-udp example: remove uipbuf tuning of MAC max retries --- examples/rpl-udp/udp-client.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index a10d188ac..1fb030034 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -33,10 +33,7 @@ udp_rx_callback(struct simple_udp_connection *c, uint16_t datalen) { unsigned count = *(unsigned *)data; - /* If tagging of traffic class is enabled tc will print number of - transmission - otherwise it will be 0 */ - LOG_INFO("Received response %u (tc:%d) from ", count, - uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO("Received response %u from ", count); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); } @@ -62,12 +59,6 @@ PROCESS_THREAD(udp_client_process, ev, data) LOG_INFO("Sending request %u to ", count); LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_("\n"); - /* Set the number of transmissions to use for this packet - - this can be used to create more reliable transmissions or - less reliable than the default. Works end-to-end if - UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1. - */ - uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5); simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); count++; } else { From 251a9d187fc09f902e41c8d165e8f4c88c6ce4fd Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 13 May 2018 04:52:47 -0700 Subject: [PATCH 2/4] Added example for uipbuf attributes --- examples/libs/ipv6-uipbuf/Makefile | 5 + examples/libs/ipv6-uipbuf/README.md | 5 + .../libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc | 180 ++++++++++++++++++ examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc | 170 +++++++++++++++++ examples/libs/ipv6-uipbuf/project-conf.h | 37 ++++ examples/libs/ipv6-uipbuf/udp-client.c | 85 +++++++++ examples/libs/ipv6-uipbuf/udp-server.c | 84 ++++++++ 7 files changed, 566 insertions(+) create mode 100644 examples/libs/ipv6-uipbuf/Makefile create mode 100644 examples/libs/ipv6-uipbuf/README.md create mode 100644 examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc create mode 100644 examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc create mode 100644 examples/libs/ipv6-uipbuf/project-conf.h create mode 100644 examples/libs/ipv6-uipbuf/udp-client.c create mode 100644 examples/libs/ipv6-uipbuf/udp-server.c diff --git a/examples/libs/ipv6-uipbuf/Makefile b/examples/libs/ipv6-uipbuf/Makefile new file mode 100644 index 000000000..b7500284e --- /dev/null +++ b/examples/libs/ipv6-uipbuf/Makefile @@ -0,0 +1,5 @@ +CONTIKI_PROJECT = udp-client udp-server +all: $(CONTIKI_PROJECT) + +CONTIKI=../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/libs/ipv6-uipbuf/README.md b/examples/libs/ipv6-uipbuf/README.md new file mode 100644 index 000000000..6f028202e --- /dev/null +++ b/examples/libs/ipv6-uipbuf/README.md @@ -0,0 +1,5 @@ +This example is meant to showcase the capabilities of uipbuf. It currently +focuses only on UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, which lets an application +set a custom max number of MAC transmissions. Optionally, this information +can be passed on over multiple hops, so that the attribute applies along +the full path. This requires setting UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS. diff --git a/examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc new file mode 100644 index 000000000..71adabb74 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc @@ -0,0 +1,180 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + IPv6 uipbuf Example + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype829 + Cooja Mote Type #1 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-server.c + make udp-server.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype405 + Cooja Mote Type #2 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-client.c + make udp-client.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 43.291897546941804 + 7.17470867058031 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype829 + + + + org.contikios.cooja.interfaces.Position + 41.0074953544532 + 42.15996473110367 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype405 + + + + org.contikios.cooja.plugins.SimControl + 229 + 3 + 157 + 11 + 6 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + 1.1719333465234514 0.0 0.0 1.1719333465234514 -4.934308660658031 20.209777273580123 + + 234 + 1 + 257 + 10 + 170 + + + org.contikios.cooja.plugins.LogListener + + App + + + + 1074 + 0 + 713 + 844 + 3 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + + + + 140.4158108891898 + + 1920 + 2 + 384 + 1 + 716 + + + org.contikios.cooja.plugins.RadioLogger + + 407 + + false + false + + 595 + 4 + 706 + 245 + 4 + + diff --git a/examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc new file mode 100644 index 000000000..30fc54e14 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc @@ -0,0 +1,170 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + IPv6 uipbuf Example + generated + 5000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 50.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.mspmote.SkyMoteType + sky1 + Sky Mote Type #sky1 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-server.c + make udp-server.sky TARGET=sky + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-server.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + org.contikios.cooja.mspmote.SkyMoteType + sky2 + Sky Mote Type #sky2 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-client.c + make udp-client.sky TARGET=sky + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-client.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + + + org.contikios.cooja.interfaces.Position + 30.051578821079996 + -64.69428746901113 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspClock + 1.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + org.contikios.cooja.interfaces.Position + 21.31366587648077 + -34.91404431659299 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspClock + 1.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + org.contikios.cooja.plugins.SimControl + 249 + 4 + 184 + 3 + 15 + + + org.contikios.cooja.plugins.Visualizer + + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.AttributeVisualizerSkin + 1.3598488697820064 0.0 0.0 1.3598488697820064 6.142207908179105 118.20877091196155 + + 234 + 1 + 227 + 14 + 210 + + + org.contikios.cooja.plugins.LogListener + + + + + + 1011 + 0 + 556 + 759 + 7 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + + + + 681.712557066089 + + 1804 + 3 + 352 + 0 + 567 + + + org.contikios.cooja.plugins.RadioLogger + + 150 + + false + false + + 500 + 2 + 546 + 259 + 12 + + diff --git a/examples/libs/ipv6-uipbuf/project-conf.h b/examples/libs/ipv6-uipbuf/project-conf.h new file mode 100644 index 000000000..dfbf0d329 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/project-conf.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 copyright holder 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 COPYRIGHT HOLDER 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 + * COPYRIGHT HOLDER 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. + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +/* Include max MAC Tx in the IPv6 Traffic Class field */ +#define UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS 1 + +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/libs/ipv6-uipbuf/udp-client.c b/examples/libs/ipv6-uipbuf/udp-client.c new file mode 100644 index 000000000..bee1cda83 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/udp-client.c @@ -0,0 +1,85 @@ +#include "contiki.h" +#include "net/routing/routing.h" +#include "random.h" +#include "net/netstack.h" +#include "net/ipv6/simple-udp.h" + +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#define WITH_SERVER_REPLY 1 +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +static struct simple_udp_connection udp_conn; + +#define START_INTERVAL (15 * CLOCK_SECOND) +#define SEND_INTERVAL (60 * CLOCK_SECOND) + +static struct simple_udp_connection udp_conn; + +/*---------------------------------------------------------------------------*/ +PROCESS(udp_client_process, "UDP client"); +AUTOSTART_PROCESSES(&udp_client_process); +/*---------------------------------------------------------------------------*/ +static void +udp_rx_callback(struct simple_udp_connection *c, + const uip_ipaddr_t *sender_addr, + uint16_t sender_port, + const uip_ipaddr_t *receiver_addr, + uint16_t receiver_port, + const uint8_t *data, + uint16_t datalen) +{ + unsigned count = *(unsigned *)data; + /* If tagging of traffic class is enabled tc will print number of + transmission - otherwise it will be 0 */ + LOG_INFO("Received response %u (Max MAC Tx: %d) from ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_client_process, ev, data) +{ + static struct etimer periodic_timer; + static unsigned count; + uip_ipaddr_t dest_ipaddr; + + PROCESS_BEGIN(); + + /* Initialize UDP connection */ + simple_udp_register(&udp_conn, UDP_CLIENT_PORT, NULL, + UDP_SERVER_PORT, udp_rx_callback); + + etimer_set(&periodic_timer, random_rand() % SEND_INTERVAL); + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); + + if(NETSTACK_ROUTING.node_is_reachable() && NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) { + /* Set the number of transmissions to use for this packet - + this can be used to create more reliable transmissions or + less reliable than the default. Works end-to-end if + UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1. + */ + uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5); + /* Send to DAG root */ + LOG_INFO("Sending request %u (Max MAC Tx: %d) to ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(&dest_ipaddr); + LOG_INFO_("\n"); + simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); + count++; + } else { + LOG_INFO("Not reachable yet\n"); + } + + /* Add some jitter */ + etimer_set(&periodic_timer, SEND_INTERVAL + - CLOCK_SECOND + (random_rand() % (2 * CLOCK_SECOND))); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/libs/ipv6-uipbuf/udp-server.c b/examples/libs/ipv6-uipbuf/udp-server.c new file mode 100644 index 000000000..288a0cba9 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/udp-server.c @@ -0,0 +1,84 @@ +/* + * 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/routing/routing.h" +#include "net/netstack.h" +#include "net/ipv6/simple-udp.h" + +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#define WITH_SERVER_REPLY 1 +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +static struct simple_udp_connection udp_conn; + +PROCESS(udp_server_process, "UDP server"); +AUTOSTART_PROCESSES(&udp_server_process); +/*---------------------------------------------------------------------------*/ +static void +udp_rx_callback(struct simple_udp_connection *c, + const uip_ipaddr_t *sender_addr, + uint16_t sender_port, + const uip_ipaddr_t *receiver_addr, + uint16_t receiver_port, + const uint8_t *data, + uint16_t datalen) +{ + unsigned count = *(unsigned *)data; + LOG_INFO("Received request %u (Max MAC Tx: %d) from ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); +#if WITH_SERVER_REPLY + LOG_INFO("Sending response %u (Max MAC Tx: %d) to ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); + simple_udp_sendto(&udp_conn, &count, sizeof(count), sender_addr); +#endif /* WITH_SERVER_REPLY */ +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_server_process, ev, data) +{ + PROCESS_BEGIN(); + + /* Initialize DAG root */ + NETSTACK_ROUTING.root_start(); + + /* Initialize UDP connection */ + simple_udp_register(&udp_conn, UDP_SERVER_PORT, NULL, + UDP_CLIENT_PORT, udp_rx_callback); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ From af3f1a05f80465c52b189a9642c473778c129ca7 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 13 May 2018 05:04:03 -0700 Subject: [PATCH 3/4] Link-stats no-ACK penalty: add to actual tx count rather than use a fixed number --- os/net/link-stats.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/os/net/link-stats.c b/os/net/link-stats.c index fbb7677da..8ec372f4e 100644 --- a/os/net/link-stats.c +++ b/os/net/link-stats.c @@ -63,8 +63,8 @@ /* ETX fixed point divisor. 128 is the value used by RPL (RFC 6551 and RFC 6719) */ #define ETX_DIVISOR LINK_STATS_ETX_DIVISOR -/* Number of Tx used to update the ETX EWMA in case of no-ACK */ -#define ETX_NOACK_PENALTY 20 +/* In case of no-ACK, add ETX_NOACK_PENALTY to the real Tx count, as a penalty */ +#define ETX_NOACK_PENALTY 12 /* Initial ETX value */ #define ETX_DEFAULT 2 @@ -156,9 +156,13 @@ link_stats_packet_sent(const linkaddr_t *lladdr, int status, int numtx) stats->last_tx_time = clock_time(); stats->freshness = MIN(stats->freshness + numtx, FRESHNESS_MAX); + /* Add penalty in case of no-ACK */ + if(status == MAC_TX_NOACK) { + numtx += ETX_NOACK_PENALTY; + } + #if LINK_STATS_ETX_FROM_PACKET_COUNT /* Compute ETX from packet and ACK count */ - numtx = (status == MAC_TX_NOACK) ? ETX_NOACK_PENALTY : numtx; /* Halve both counter after TX_COUNT_MAX */ if(stats->tx_count + numtx > TX_COUNT_MAX) { stats->tx_count /= 2; @@ -179,7 +183,7 @@ link_stats_packet_sent(const linkaddr_t *lladdr, int status, int numtx) /* Compute ETX using an EWMA */ /* ETX used for this update */ - packet_etx = ((status == MAC_TX_NOACK) ? ETX_NOACK_PENALTY : numtx) * ETX_DIVISOR; + packet_etx = numtx * ETX_DIVISOR; /* ETX alpha used for this update */ ewma_alpha = link_stats_is_fresh(stats) ? EWMA_ALPHA : EWMA_BOOTSTRAP_ALPHA; From e99f2a73d638b78a034873dddf7d0d0c1fd6570e Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Mon, 14 May 2018 08:32:40 -0700 Subject: [PATCH 4/4] Added CI compile test of example ipv6-uipbuf (platform Zoul) --- tests/03-compile-arm-ports-02/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index db016afaa..defd10a96 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -34,6 +34,7 @@ libs/timers/zoul \ libs/energest/zoul \ libs/trickle-library/zoul \ libs/data-structures/zoul \ +libs/ipv6-uipbuf/zoul \ nullnet/zoul \ slip-radio/zoul \ dev/gpio-hal/zoul:BOARD=remote-reva \