diff --git a/regression-tests/25-ieee802154/02-tsch-packet-create.csc b/regression-tests/25-ieee802154/02-tsch-packet-create.csc new file mode 100644 index 000000000..cf7235f82 --- /dev/null +++ b/regression-tests/25-ieee802154/02-tsch-packet-create.csc @@ -0,0 +1,203 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/collect-view + [APPS_DIR]/powertracker + [APPS_DIR]/radiologger-headless + + My simulation + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 0.0 + 0.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype713 + default + [CONTIKI_DIR]/regression-tests/25-ieee802154/code/test-tsch-packet.c + make TARGET=cooja clean + make TEST_CONFIG_TYPE=DEFAULT test-tsch-packet.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 + mtype740 + security on + [CONTIKI_DIR]/regression-tests/25-ieee802154/code/test-tsch-packet.c + make TARGET=cooja clean + make TEST_CONFIG_TYPE=SECURITY_ON test-tsch-packet.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 + mtype399 + all enabled + [CONTIKI_DIR]/regression-tests/25-ieee802154/code/test-tsch-packet.c + make TARGET=cooja clean + make TEST_CONFIG_TYPE=ALL_ENABLED test-tsch-packet.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 + -49.23869609407765 + -36.33693008116223 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype713 + + + + org.contikios.cooja.interfaces.Position + -17.772442808950224 + -36.862574776701464 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype740 + + + + org.contikios.cooja.interfaces.Position + 14.488632230762605 + -35.15143001217301 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype399 + + + + org.contikios.cooja.plugins.SimControl + 280 + 2 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.GridVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.AttributeVisualizerSkin + 3.714690054486387 0.0 0.0 3.714690054486387 248.5428583129116 318.25485368648356 + + 400 + 0 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/regression-tests/25-ieee802154/js/02-tsch-packet-create.js + true + + 495 + 1 + 525 + 185 + 162 + + + diff --git a/regression-tests/25-ieee802154/code/Makefile b/regression-tests/25-ieee802154/code/Makefile index 10f911b9a..5f82fb4a5 100644 --- a/regression-tests/25-ieee802154/code/Makefile +++ b/regression-tests/25-ieee802154/code/Makefile @@ -1,7 +1,21 @@ -all: test-panid-handling +all: test-panid-handling test-tcsh-create-packet -APPS += unit-test -CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" +APPS += unit-test +MODULES += core/net/mac/tsch +CFLAGS += -D PROJECT_CONF_H=\"project-conf.h\" + +WITH_TSCH ?= 0 +TEST_CONFIG_TYPE ?= DEFAULT + +CFLAGS += -D WITH_TSCH=1 + +ifeq ($(TEST_CONFIG_TYPE), SECURITY_ON) +CFLAGS += -D WITH_SECURITY_ON=1 +endif + +ifeq ($(TEST_CONFIG_TYPE), ALL_ENABLED) +CFLAGS += -D WITH_ALL_ENABLED=1 +endif CONTIKI = ../../.. CONTIKI_WITH_IPV6 = 1 diff --git a/regression-tests/25-ieee802154/code/project-conf.h b/regression-tests/25-ieee802154/code/project-conf.h index a8bb49e15..21f67b70f 100644 --- a/regression-tests/25-ieee802154/code/project-conf.h +++ b/regression-tests/25-ieee802154/code/project-conf.h @@ -29,4 +29,13 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _PROJECT_CONF_H_ +#define _PROJECT_CONF_H_ + #define UNIT_TEST_PRINT_FUNCTION test_print_report + +#if WITH_TSCH +#include "project-tsch-conf.h" +#endif + +#endif /* !_PROJECT_CONF_H_ */ diff --git a/regression-tests/25-ieee802154/code/project-tsch-conf.h b/regression-tests/25-ieee802154/code/project-tsch-conf.h new file mode 100644 index 000000000..a3314704a --- /dev/null +++ b/regression-tests/25-ieee802154/code/project-tsch-conf.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016, Yasuyuki Tanaka + * 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 HOLDERS 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_TSCH_CONF_H +#define _PROJECT_TSCH_CONF_H + +#undef FRAME802154_CONF_VERSION +#define FRAME802154_CONF_VERSION FRAME802154_IEEE802154E_2012 + +#undef NETSTACK_CONF_MAC +#define NETSTACK_CONF_MAC tschmac_driver +#undef NETSTACK_CONF_RDC +#define NETSTACK_CONF_RDC nordc_driver +#undef NETSTACK_CONF_FRAMER +#define NETSTACK_CONF_FRAMER framer_802154 + + +#if WITH_SECURITY_ON +#define TEST_CONFIG_TYPE SECURITY_ON + +#undef LLSEC802154_CONF_ENABLED +#define LLSEC802154_CONF_ENABLED 1 +#undef LLSEC802154_CONF_USES_EXPLICIT_KEYS +#define LLSEC802154_CONF_USES_EXPLICIT_KEYS 1 +#undef LLSEC802154_CONF_USES_FRAME_COUNTER +#define LLSEC802154_CONF_USES_FRAME_COUNTER 0 + +#elif WITH_ALL_ENABLED +#define TEST_CONFIG_TYPE ALL_ENABLED + +#undef TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR +#define TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR 1 +#undef TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR +#define TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR 1 +#undef TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING +#define TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING 1 +#undef TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE +#define TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE 1 +#undef TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK +#define TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK 1 + +#endif + + +#endif /* !_PROJECT_TSCH_CONF_H */ diff --git a/regression-tests/25-ieee802154/code/test-tsch-packet.c b/regression-tests/25-ieee802154/code/test-tsch-packet.c new file mode 100644 index 000000000..1a79792b7 --- /dev/null +++ b/regression-tests/25-ieee802154/code/test-tsch-packet.c @@ -0,0 +1,386 @@ +/* + * Copyright (c) 2016, Yasuyuki Tanaka + * 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 HOLDERS 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. + */ + +#include "contiki.h" +#include "unit-test.h" +#include "net/linkaddr.h" +#include "net/mac/tsch/tsch.h" +#include "net/mac/tsch/tsch-asn.h" +#include "net/mac/tsch/tsch-packet.h" +#include "net/mac/tsch/tsch-schedule.h" + +#include +#include + + +#ifndef TEST_CONFIG_TYPE +#define TEST_CONFIG_TYPE DEFAULT +#endif + +typedef enum { SUCCESS, FAILURE } result_t; + +typedef enum { DEFAULT = 0, SECURITY_ON, ALL_ENABLED } config_type_t; + +typedef struct { + size_t len; + uint8_t buf[TSCH_PACKET_MAX_LEN]; +} frame_t; + +#define NODE1 {{ 0xc1, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} +#define NODE2 {{ 0xc1, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }} + +/* + * The following vectors are obtained with + * examples/ipv6/rpl-tsch/rpl-tsch-z1.csc except for the enhanced beacon for + * ALL_ENABLED. The raw frame was generated with rpl-tsch-cooja.csc because + * there is an issue in TSCH Timeslot IE generated by z1 mote. + */ + +typedef struct { + linkaddr_t src; + uint64_t asn; + uint8_t hdr_len; + frame_t frame; +} eb_test_vector_t; + +static const eb_test_vector_t eb_test_vectors[] = { + { /* DEFAULT */ + NODE1, 7, 18, + { 37, { 0x00, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0xcd, 0xab, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc1, + 0x00, 0x3f, 0x11, 0x88, 0x06, 0x1a, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, 0x00, 0x01, + 0xc8, 0x00, 0x01, 0x1b, 0x00 } + } + }, + { /* SECURITY_ON */ + NODE1, 2, 20, + { 43, { 0x08, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0xcd, 0xab, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc1, + 0x69, 0x01, 0x00, 0x3f, 0x11, 0x88, 0x06, 0x1a, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, + 0x00, 0x01, 0xc8, 0x00, 0x01, 0x1b, 0x00, 0x7d, + 0x3e, 0x39, 0x9a, 0x6f, 0x7b } + } + }, + { /* ALL_ENABLED */ + NODE1, 12, 18, + { 85, { 0x00, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0xcd, 0xab, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc1, + 0x00, 0x3f, 0x41, 0x88, 0x06, 0x1a, 0x0c, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x19, 0x1c, 0x01, 0x08, + 0x07, 0x80, 0x00, 0x48, 0x08, 0xfc, 0x03, 0x20, + 0x03, 0xe8, 0x03, 0x98, 0x08, 0x90, 0x01, 0xc0, + 0x00, 0x60, 0x09, 0xa0, 0x10, 0x10, 0x27, 0x10, + 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x0f, 0x19, 0x1a, 0x14, 0x00, + 0x00, 0x0a, 0x1b, 0x01, 0x00, 0x07, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x0f } + } + } +}; + +typedef struct { + linkaddr_t src; + linkaddr_t dest; + uint64_t asn; // used only for the SECURITY_ON case + uint8_t seqno; + uint16_t drift; + uint8_t nack; + frame_t frame; +} eack_test_vector_t; + +static const eack_test_vector_t eack_test_vectors[] = { + { /* DEFAULT */ + NODE1, NODE2, 0, 1, 214, 0, + { 17, { 0x02, 0x2e, 0x01, 0xcd, 0xab, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0c, 0xc1, 0x02, 0x0f, 0xd6, + 0x00 } + } + }, + { /* SECURITY_ON */ + NODE1, NODE2, 108, 1, 214, 0, + { 23, { 0x0a, 0x2e, 0x01, 0xcd, 0xab, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0c, 0xc1, 0x6d, 0x02, 0x02, + 0x0f, 0xd6, 0x00, 0x5e, 0x20, 0x84, 0xda } + } + }, + { /* ALL_ENABLED */ + NODE1, NODE2, 0, 1, 214, 0, + { 25, { 0x02, 0xee, 0x01, 0xcd, 0xab, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0c, 0xc1, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0c, 0xc1, 0x02, 0x0f, 0xd6, + 0x00 } + } + } +}; + +PROCESS(test_process, "tsch-packet-create test"); +AUTOSTART_PROCESSES(&test_process); + +static void +print_hex(const uint8_t *p, size_t len) +{ + int i; + for(i = 0; i < len; i++) { + printf("%02x", p[i]); + } +} + +static void +update_current_asn(uint64_t asn) +{ + tsch_current_asn.ls4b = (uint32_t)(asn & 0xffffffff); + tsch_current_asn.ms1b = (uint8_t)((asn >> 32) & 0xff); +} + +static result_t +test_create_eb(const eb_test_vector_t *v) +{ + uint8_t buf[TSCH_PACKET_MAX_LEN]; + int len; + uint8_t hdr_len; + uint8_t tsch_sync_ie_offset; + + memset(buf, 0, sizeof(buf)); + + linkaddr_copy(&linkaddr_node_addr, &v->src); + update_current_asn(v->asn); + + len = tsch_packet_create_eb(buf, sizeof(buf), + &hdr_len, &tsch_sync_ie_offset); + tsch_packet_update_eb(buf, len, tsch_sync_ie_offset); +#if WITH_SECURITY_ON + len += tsch_security_secure_frame(buf, buf, + hdr_len, len - hdr_len, + &tsch_current_asn); +#endif + + printf("%s: len=%u, hdr_len=%u, buf=", __func__, len, hdr_len); + print_hex(buf, len); + printf("\n"); + + if(len != v->frame.len || + hdr_len != v->hdr_len || + memcmp(buf, v->frame.buf, len) != 0) { + return FAILURE; + } + + return SUCCESS; +} + +static result_t +test_parse_eb(const eb_test_vector_t *v) +{ + frame802154_t frame; + struct ieee802154_ies ies; + uint8_t hdr_len; + int frame_without_mic; + int len; + uint64_t asn; + linkaddr_t src_addr; + +#if WITH_SECURITY_ON + frame_without_mic = 0; + update_current_asn(v->asn); +#else + frame_without_mic = 1; +#endif + + memset(&frame, 0, sizeof(frame)); + memset(&ies, 0, sizeof(ies)); + hdr_len = 0; + + len = tsch_packet_parse_eb(v->frame.buf, v->frame.len, &frame, &ies, &hdr_len, + frame_without_mic); + asn = ((uint64_t)ies.ie_asn.ms1b << 32) + ies.ie_asn.ls4b; + printf("%s: len=%u, hdr_len=%u, asn=%llu\n", __func__, len, hdr_len, asn); + +#if WITH_SECURITY_ON + /* adjust 'len' with the length of MIC which is included in a raw frame */ + len += tsch_security_mic_len(&frame); +#endif + + if(frame.fcf.frame_type != FRAME802154_BEACONFRAME || + frame.fcf.frame_version != FRAME802154_IEEE802154E_2012) { + return FAILURE; + } + + if(len != v->frame.len || + hdr_len != v->hdr_len || + asn != v->asn) { + return FAILURE; + } + + if(frame802154_extract_linkaddr(&frame, &src_addr, NULL) == 0|| + linkaddr_cmp(&src_addr, &v->src) == 0) { + return FAILURE; + } + + return SUCCESS; +} + +static result_t +test_create_eack(const eack_test_vector_t *v) +{ + uint8_t buf[TSCH_PACKET_MAX_LEN]; + int len; +#if WITH_SECURITY_ON + int data_len = 0; +#endif + + memset(buf, 0, sizeof(buf)); + linkaddr_copy(&linkaddr_node_addr, &v->src); + + len = tsch_packet_create_eack(buf, sizeof(buf), + &v->dest, v->seqno, v->drift, v->nack); +#if WITH_SECURITY_ON + update_current_asn(v->asn); + len += tsch_security_secure_frame(buf, buf, + len, data_len, + &tsch_current_asn); +#endif + + printf("%s: len=%u, buf=", __func__, len); + print_hex(buf, len); + printf("\n"); + + if(len != v->frame.len || + memcmp(buf, v->frame.buf, len) != 0) { + return FAILURE; + } + + return SUCCESS; +} + +static result_t +test_parse_eack(const eack_test_vector_t *v) +{ + frame802154_t frame; + struct ieee802154_ies ies; + uint8_t hdr_len; + int len; +#if TSCH_PACKET_EACK_WITH_SRC_ADDR + linkaddr_t src_addr; +#endif +#if TSCH_PACKET_EACK_WITH_DEST_ADDR + linkaddr_t dest_addr; +#endif + +#if WITH_SECURITY_ON + update_current_asn(v->asn); +#endif + + memset(&frame, 0, sizeof(frame)); + memset(&ies, 0, sizeof(ies)); + hdr_len = 0; + + linkaddr_copy(&linkaddr_node_addr, &v->dest); + len = tsch_packet_parse_eack(v->frame.buf, v->frame.len, v->seqno, + &frame, &ies, &hdr_len); + printf("%s: len=%u, seqno=%u, drift=%u, nack=%u\n", + __func__, len, frame.seq, ies.ie_time_correction, ies.ie_is_nack); + +#if WITH_SECURITY_ON + /* adjust 'len' with the length of MIC which is included in a raw frame */ + len += tsch_security_mic_len(&frame); +#endif + + if(frame.fcf.frame_type != FRAME802154_ACKFRAME || + frame.fcf.frame_version != FRAME802154_IEEE802154E_2012) { + return FAILURE; + } + + if(len != v->frame.len || + frame.seq != v->seqno || + ies.ie_time_correction != v->drift || + ies.ie_is_nack != v->nack) { + return FAILURE; + } + +#if TSCH_PACKET_EACK_WITH_SRC_ADDR + if(frame802154_extract_linkaddr(&frame, &src_addr, NULL) == 0|| + linkaddr_cmp(&src_addr, &v->src) == 0) { + return FAILURE; + } +#endif + +#if TSCH_PACKET_EACK_WITH_DEST_ADDR + if(frame802154_extract_linkaddr(&frame, NULL, &dest_addr) == 0|| + linkaddr_cmp(&dest_addr, &v->dest) == 0) { + return FAILURE; + } +#endif + + return SUCCESS; +} + +PROCESS_THREAD(test_process, ev, data) +{ + static struct etimer et; + const eb_test_vector_t *eb_v; + const eack_test_vector_t *eack_v; + + PROCESS_BEGIN(); + + tsch_set_coordinator(1); + +#if WITH_SECURITY_ON + tsch_set_pan_secured(1); +#endif + + etimer_set(&et, CLOCK_SECOND); + + /* wait for minimal schedule installed */ + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + if(tsch_schedule_get_link_by_handle(0) != NULL) { + break; + } + etimer_reset(&et); + } + + eb_v = &eb_test_vectors[TEST_CONFIG_TYPE]; + printf("==check-me== %s\n", + test_create_eb(eb_v) == SUCCESS ? "SUCCEEDED" : "FAILED"); + printf("==check-me== %s\n", + test_parse_eb(eb_v) == SUCCESS ? "SUCCEEDED" : "FAILED"); + + eack_v = &eack_test_vectors[TEST_CONFIG_TYPE]; + printf("==check-me== %s\n", + test_create_eack(eack_v) == SUCCESS ? "SUCCEEDED" : "FAILED"); + printf("==check-me== %s\n", + test_parse_eack(eack_v) == SUCCESS ? "SUCCEEDED" : "FAILED"); + + printf("==check-me== DONE\n"); + + PROCESS_END(); +} diff --git a/regression-tests/25-ieee802154/js/02-tsch-packet-create.js b/regression-tests/25-ieee802154/js/02-tsch-packet-create.js new file mode 100644 index 000000000..d244e13d7 --- /dev/null +++ b/regression-tests/25-ieee802154/js/02-tsch-packet-create.js @@ -0,0 +1,27 @@ +TIMEOUT(10000, log.testFailed()); + +num_of_motes = sim.getMotesCount(); + +while(true) { + YIELD(); + + log.log(time + " node-" + id + ": "+ msg + "\n"); + + if(msg.contains("=check-me=") == false) { + continue; + } + + if(msg.contains("FAILED")) { + log.testFailed(); + break; + } + + if(msg.contains("DONE")) { + num_of_motes -= 1; + if(num_of_motes == 0) { + log.testOK(); + break; + } + } + +}