sixtop: add an example generating 6P frames

This commit is contained in:
Yasuyuki Tanaka 2017-07-10 13:41:51 +09:00
parent 57263042ae
commit cac54874d2
6 changed files with 1105 additions and 0 deletions

View File

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[APPS_DIR]/mrm</project>
<project EXPORT="discard">[APPS_DIR]/mspsim</project>
<project EXPORT="discard">[APPS_DIR]/avrora</project>
<project EXPORT="discard">[APPS_DIR]/serial_socket</project>
<project EXPORT="discard">[APPS_DIR]/collect-view</project>
<project EXPORT="discard">[APPS_DIR]/powertracker</project>
<simulation>
<title>My simulation</title>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
org.contikios.cooja.radiomediums.UDGM
<transmitting_range>50.0</transmitting_range>
<interference_range>100.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
org.contikios.cooja.contikimote.ContikiMoteType
<identifier>mtype639</identifier>
<description>6P node</description>
<source>[CONTIKI_DIR]/examples/6tisch/6p-packet/sixp-node.c</source>
<commands>make sixp-node.cooja TARGET=cooja</commands>
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiMoteID</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRS232</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiBeeper</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiIPAddress</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiRadio</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiButton</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiPIR</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiClock</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiLED</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiCFS</moteinterface>
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiEEPROM</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
<symbols>false</symbols>
</motetype>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>-65.17052901237824</x>
<y>35.68868314082581</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>1</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiEEPROM
<eeprom>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</eeprom>
</interface_config>
<motetype_identifier>mtype639</motetype_identifier>
</mote>
<mote>
<interface_config>
org.contikios.cooja.interfaces.Position
<x>-31.58320760838481</x>
<y>36.12872091616695</y>
<z>0.0</z>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiMoteID
<id>2</id>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiRadio
<bitrate>250.0</bitrate>
</interface_config>
<interface_config>
org.contikios.cooja.contikimote.interfaces.ContikiEEPROM
<eeprom>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</eeprom>
</interface_config>
<motetype_identifier>mtype639</motetype_identifier>
</mote>
</simulation>
<plugin>
org.contikios.cooja.plugins.SimControl
<width>280</width>
<z>1</z>
<height>160</height>
<location_x>400</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.Visualizer
<plugin_config>
<moterelations>true</moterelations>
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.TrafficVisualizerSkin</skin>
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
<viewport>2.463050617589194 0.0 0.0 2.463050617589194 316.15467536891634 50.055049291885666</viewport>
</plugin_config>
<width>400</width>
<z>5</z>
<height>400</height>
<location_x>1</location_x>
<location_y>1</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.LogListener
<plugin_config>
<filter />
<formatted_time />
<coloring />
</plugin_config>
<width>1320</width>
<z>3</z>
<height>240</height>
<location_x>400</location_x>
<location_y>160</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.TimeLine
<plugin_config>
<mote>0</mote>
<mote>1</mote>
<showRadioRXTX />
<showRadioHW />
<showLEDs />
<zoomfactor>500.0</zoomfactor>
</plugin_config>
<width>1720</width>
<z>7</z>
<height>166</height>
<location_x>0</location_x>
<location_y>837</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.Notes
<plugin_config>
<notes>Enter notes here</notes>
<decorations>true</decorations>
</plugin_config>
<width>1040</width>
<z>6</z>
<height>160</height>
<location_x>680</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.ScriptRunner
<plugin_config>
<script>TIMEOUT(100000, log.testOK());
while(true) {
YIELD();
log.log(time + " " + "node-" + id + " "+ msg + "\n");
}</script>
<active>true</active>
</plugin_config>
<width>600</width>
<z>2</z>
<height>700</height>
<location_x>710</location_x>
<location_y>30</location_y>
</plugin>
<plugin>
org.contikios.cooja.plugins.RadioLogger
<plugin_config>
<split>150</split>
<formatted_time />
<showdups>false</showdups>
<hidenodests>false</hidenodests>
<analyzers name="6lowpan-pcap" />
</plugin_config>
<width>500</width>
<z>4</z>
<height>300</height>
<location_x>472</location_x>
<location_y>426</location_y>
</plugin>
</simconf>

View File

@ -0,0 +1,8 @@
CONTIKI_PROJECT = sixp-node.c
PROJECT_SOURCEFILES += test-sf.c
CONTIKI = ../../../
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
MODULES += os/net/mac/tsch os/net/mac/tsch/sixtop
include $(CONTIKI)/Makefile.include

View File

@ -0,0 +1,4 @@
6P Packet Examples
==================
You can generate a pcap file having 6P packets with `6p-packet.csc`.

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2017, 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_CONF_H_
#define _PROJECT_CONF_H_
#define CONTIKI_WITH_RPL 0
#undef UIP_CONF_IPV6_RPL
#define UIP_CONF_IPV6_RPL 0
#define UIP_CONF_ND6_SEND_RA 0
#if CONTIKI_TARGET_COOJA
#define COOJA_CONF_SIMULATE_TURNAROUND 0
#else
#error "This example is intended to be used for Cooja mote."
#endif /* CONTIKI_TARGET_COOJA */
#define NETSTACK_CONF_MAC tschmac_driver
#define TSCH_CONF_WITH_SIXTOP 1
#define TSCH_LOG_CONF_LEVEL 2
#define TSCH_CONF_AUTOSTART 1
#define TSCH_CONF_DEFAULT_HOPPING_SEQUENCE TSCH_HOPPING_SEQUENCE_1_1
#endif /* _PROJECT_CONF_H_ */

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2017, 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 <lib/assert.h>
#include <sys/node-id.h>
#include <net/mac/tsch/tsch.h>
#include <net/mac/tsch/tsch-queue.h>
#include <net/mac/tsch/sixtop/sixtop.h>
extern const sixtop_sf_t test_sf;
extern int test_sf_start(const linkaddr_t *addr);
PROCESS(sixp_node_process, "6P node");
AUTOSTART_PROCESSES(&sixp_node_process);
#define COORDINATOR_NODE_ID 1
PROCESS_THREAD(sixp_node_process, ev, data)
{
PROCESS_BEGIN();
sixtop_add_sf(&test_sf);
if(node_id == COORDINATOR_NODE_ID) {
tsch_set_coordinator(1);
assert(test_sf_start(NULL) == 0);
} else {
static struct etimer et;
struct tsch_neighbor *peer;
etimer_set(&et, CLOCK_SECOND);
while(tsch_is_associated == 0) {
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);
}
peer = tsch_queue_get_time_source();
assert(test_sf_start((const linkaddr_t *)&peer->addr) == 0);
}
PROCESS_END();
}

View File

@ -0,0 +1,784 @@
/*
* Copyright (c) 2017, 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 <lib/assert.h>
#include <net/mac/tsch/tsch-queue.h>
#include <net/mac/tsch/sixtop/sixtop.h>
#include <net/mac/tsch/sixtop/sixp.h>
#include <net/mac/tsch/sixtop/sixp-nbr.h>
#include <net/mac/tsch/sixtop/sixp-trans.h>
#define DEBUG DEBUG_PRINT
#include <net/net-debug.h>
#define SIXP_PKT_BUFLEN 128
static uint8_t sixp_pkt_buf[SIXP_PKT_BUFLEN];
#define TEST_SF_SFID 0x80
#define TEST_SF_TIMEOUT CLOCK_SECOND
PROCESS(test_sf_process, "test-sf initiator process");
static linkaddr_t peer_addr;
static process_event_t test_sf_trans_done;
static enum { TEST_SF_MODE_INITIATOR, TEST_SF_MODE_RESPONDER } test_sf_mode;
static int test_index = 0;
static const sixp_pkt_metadata_t sample_metadata = 0xcafe;
static const uint32_t sample_cell_list1[] = { 0xdeadbeef,
0xcafebabe,
0xbaadf00d };
static const uint32_t sample_cell_list2[] = { 0xbaadcafe,
0xfacefeed,
0xbadcab1e };
static void test_add_2_step(const linkaddr_t *peer_addr);
static void test_add_3_step(const linkaddr_t *peer_addr);
static void test_delete_2_step(const linkaddr_t *peer_addr);
static void test_delete_3_step(const linkaddr_t *peer_addr);
static void test_relocate_2_step(const linkaddr_t *peer_addr);
static void test_count_2_step(const linkaddr_t *peer_addr);
static void test_list_2_step(const linkaddr_t *peer_addr);
static void test_list_2_step_eol(const linkaddr_t *peer_addr);
static void test_clear_2_step_success(const linkaddr_t *peer_addr);
static void test_clear_2_step_error(const linkaddr_t *peer_addr);
static void test_clear_2_step_eol(const linkaddr_t *peer_addr);
static void test_clear_2_step_reset(const linkaddr_t *peer_addr);
static void test_clear_2_step_version(const linkaddr_t *peer_addr);
static void test_clear_2_step_sfid(const linkaddr_t *peer_addr);
static void test_clear_2_step_gen(const linkaddr_t *peer_addr);
static void test_clear_2_step_busy(const linkaddr_t *peer_addr);
static void test_clear_2_step_nores(const linkaddr_t *peer_addr);
static void test_clear_2_step_celllist(const linkaddr_t *peer_addr);
typedef void (*test_func)(const linkaddr_t *peer_addr);
static const test_func test_case[] = {
test_add_2_step,
test_add_3_step,
test_delete_2_step,
test_delete_3_step,
test_relocate_2_step,
test_count_2_step,
test_list_2_step,
test_list_2_step_eol,
test_clear_2_step_success,
test_clear_2_step_error,
test_clear_2_step_eol,
test_clear_2_step_reset,
test_clear_2_step_version,
test_clear_2_step_sfid,
test_clear_2_step_gen,
test_clear_2_step_busy,
test_clear_2_step_nores,
test_clear_2_step_celllist,
};
static void
advance_gen(const linkaddr_t *peer_addr)
{
sixp_nbr_t *nbr;
nbr = sixp_nbr_find(peer_addr);
assert(nbr != NULL);
assert(sixp_nbr_advance_gen(nbr) == 0);
}
static void
set_peer_addr(const linkaddr_t *addr)
{
peer_addr = *addr;
PRINTF("test-sf: set peer addr: ");
PRINTLLADDR((const uip_lladdr_t *)&peer_addr);
PRINTF("\n");
}
int
test_sf_start(const linkaddr_t *addr)
{
if(addr == NULL) {
test_sf_mode = TEST_SF_MODE_RESPONDER;
} else {
test_sf_mode = TEST_SF_MODE_INITIATOR;
set_peer_addr(addr);
test_sf_trans_done = process_alloc_event();
process_start(&test_sf_process, NULL);
}
return 0;
}
static void
init(void)
{
}
static void
input(sixp_pkt_type_t type, sixp_pkt_code_t code,
const uint8_t *body, uint16_t body_len,
const linkaddr_t *src_addr)
{
if(test_index < (sizeof(test_case) / sizeof(test_func))) {
test_case[test_index](src_addr);
}
}
static void
timeout(sixp_pkt_cmd_t cmd, const linkaddr_t *peer_addr)
{
}
static void
test_add_2_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
1,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_cell_list(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) +
sizeof(sixp_pkt_metadata_t) +
sizeof(sample_cell_list1),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(uint32_t), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(uint32_t),
peer_addr,
NULL, NULL, 0);
test_index++;
advance_gen(peer_addr);
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
advance_gen(peer_addr);
}
}
}
static void
test_add_3_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
1,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_ADD,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) +
sizeof(sixp_pkt_metadata_t),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(sample_cell_list1),
peer_addr,
NULL, NULL, 0);
} else if (state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_CONFIRMATION,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(uint32_t), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_CONFIRMATION,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(uint32_t),
peer_addr,
NULL, NULL, 0);
process_post(&test_sf_process, test_sf_trans_done, NULL);
advance_gen(peer_addr);
} else if (state == SIXP_TRANS_STATE_CONFIRMATION_RECEIVED){
test_index++;
advance_gen(peer_addr);
}
}
}
static void
test_delete_2_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
1,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_cell_list(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) +
sizeof(sixp_pkt_metadata_t) +
sizeof(sample_cell_list1),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(uint32_t), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(uint32_t),
peer_addr,
NULL, NULL, 0);
test_index++;
advance_gen(peer_addr);
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
advance_gen(peer_addr);
}
}
}
static void
test_delete_3_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_pkt_set_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
1,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_DELETE,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) +
sizeof(sixp_pkt_metadata_t),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(sample_cell_list1),
peer_addr,
NULL, NULL, 0);
} else if (state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_CONFIRMATION,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(uint32_t), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_CONFIRMATION,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(uint32_t),
peer_addr,
NULL, NULL, 0);
process_post(&test_sf_process, test_sf_trans_done, NULL);
advance_gen(peer_addr);
} else if (state == SIXP_TRANS_STATE_CONFIRMATION_RECEIVED) {
test_index++;
advance_gen(peer_addr);
}
}
}
static void
test_relocate_2_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(
sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_RELOCATE,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_RELOCATE,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_RELOCATE,
3,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_rel_cell_list(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_RELOCATE,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cand_cell_list(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_RELOCATE,
(const uint8_t *)sample_cell_list2,
sizeof(sample_cell_list2), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_RELOCATE,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) +
sizeof(sample_cell_list1) +
sizeof(sample_cell_list2),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list2,
sizeof(uint32_t), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf, sizeof(uint32_t),
peer_addr,
NULL, NULL, 0);
test_index++;
advance_gen(peer_addr);
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
advance_gen(peer_addr);
}
}
}
static void
test_count_2_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(
sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_COUNT,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_COUNT,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_RX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_COUNT,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_total_num_cells(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
0xf0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_total_num_cells_t),
peer_addr,
NULL, NULL, 0);
test_index++;
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
}
}
}
static void
test_list_2_step(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(
sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_RX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_offset(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
0x0f,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_max_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
0xf0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_reserved_t) +
sizeof(sixp_pkt_offset_t) +
sizeof(sixp_pkt_max_num_cells_t),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
(const uint8_t *)sample_cell_list2,
sizeof(sample_cell_list2),
sizeof(sample_cell_list1),
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_SUCCESS,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sample_cell_list1) + sizeof(sample_cell_list2),
peer_addr,
NULL, NULL, 0);
test_index++;
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
}
}
}
static void
test_list_2_step_eol(const linkaddr_t *peer_addr)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(
sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_options(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
SIXP_PKT_CELL_OPTION_TX |
SIXP_PKT_CELL_OPTION_RX |
SIXP_PKT_CELL_OPTION_SHARED,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_offset(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
0x0f,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_max_num_cells(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
0xf0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_LIST,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_reserved_t) +
sizeof(sixp_pkt_offset_t) +
sizeof(sixp_pkt_max_num_cells_t),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_EOL,
(const uint8_t *)sample_cell_list1,
sizeof(sample_cell_list1), 0,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(
sixp_pkt_set_cell_list(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_EOL,
(const uint8_t *)sample_cell_list2,
sizeof(sample_cell_list2),
sizeof(sample_cell_list1),
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_RC_EOL,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sample_cell_list1) + sizeof(sample_cell_list2),
peer_addr,
NULL, NULL, 0);
test_index++;
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
}
}
}
static void
test_clear_2_step(const linkaddr_t *peer_addr, sixp_pkt_rc_t rc)
{
sixp_trans_t *trans = sixp_trans_find(peer_addr);
if(trans == NULL) {
memset(sixp_pkt_buf, 0, sizeof(sixp_pkt_buf));
assert(
sixp_pkt_set_metadata(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_CLEAR,
sample_metadata,
sixp_pkt_buf, sizeof(sixp_pkt_buf)) == 0);
assert(sixp_output(SIXP_PKT_TYPE_REQUEST,
(sixp_pkt_code_t)(uint8_t)SIXP_PKT_CMD_CLEAR,
TEST_SF_SFID, sixp_pkt_buf,
sizeof(sixp_pkt_metadata_t),
peer_addr,
NULL, NULL, 0) == 0);
} else {
sixp_trans_state_t state;
state = sixp_trans_get_state(trans);
if(state == SIXP_TRANS_STATE_REQUEST_RECEIVED) {
sixp_output(SIXP_PKT_TYPE_RESPONSE,
(sixp_pkt_code_t)rc,
TEST_SF_SFID, NULL, 0, peer_addr,
NULL, NULL, 0);
test_index++;
} else if(state == SIXP_TRANS_STATE_RESPONSE_RECEIVED) {
process_post(&test_sf_process, test_sf_trans_done, NULL);
}
}
}
static void
test_clear_2_step_success(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_SUCCESS);
}
static void
test_clear_2_step_error(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_ERROR);
}
static void
test_clear_2_step_eol(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_EOL);
}
static void
test_clear_2_step_reset(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_RESET);
}
static void
test_clear_2_step_version(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_VERSION);
}
static void
test_clear_2_step_sfid(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_SFID);
}
static void
test_clear_2_step_gen(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_GEN);
}
static void
test_clear_2_step_busy(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_BUSY);
}
static void
test_clear_2_step_nores(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_NORES);
}
static void
test_clear_2_step_celllist(const linkaddr_t *peer_addr)
{
test_clear_2_step(peer_addr, SIXP_PKT_RC_CELLLIST);
}
PROCESS_THREAD(test_sf_process, ev, data)
{
static struct etimer et;
PROCESS_BEGIN();
etimer_set(&et, CLOCK_SECOND);
while(1) {
if(test_index == (sizeof(test_case) / sizeof(test_func))) {
break;
} else {
test_case[test_index]((const linkaddr_t *)&peer_addr);
}
PROCESS_WAIT_EVENT_UNTIL(ev == test_sf_trans_done);
PROCESS_YIELD_UNTIL(etimer_expired(&et));
etimer_reset(&et);
test_index++;
}
PRINTF("done\n");
PROCESS_END();
}
const sixtop_sf_t test_sf = {
TEST_SF_SFID,
TEST_SF_TIMEOUT,
init,
input,
timeout
};