Skip to content

Add nanostack mac tester and testcases #7996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions TEST_APPS/device/nanostack_mac_tester/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Nanostack MAC test application

You can use this application to test the Nanostack RF driver implementations that follow the [Nanostack RF driver porting instructions](https://os.mbed.com/docs/v5.6/reference/contributing-connectivity.html#porting-new-rf-driver-for-6lowpan-stack). The application has a command-line interface that is used to send commands to Nanostack's MAC layer, for example starting PANs, scanning or sending data. The provided tests do not test performance or stability and only indirectly test RF functionalities.

## Table of contents

* [Prerequisites](#prerequisites)
* [Setting up the application](#setting-up-the-application)
* [Application usage](#application-usage)
* [Interactive mode](#interactive-mode)
* [Automated mode](#automated-mode)
* [Testcases](#testcases)
* [Considerations](#considerations)

## Prerequisites

* [Mbed CLI](https://github.com/ARMmbed/mbed-cli).
* Mbed OS target board with build in radio, OR RF shield with Mbed OS driver

## Setting up the application

### Add your RF driver

When using RF shield, you need to configure it to be a default RF driver and instruct Mbed OS that RF driver is present. For example, configuring Atmel RF driver to provide default driver:

```
"target_overrides": {
"*": {
"target.device_has_add": ["802_15_4_RF_PHY"],
"atmel-rf.provide-default": true
```

### Checking platform support

Check that your choice of platform is supported by your choice of toolchain:

```
mbed compile --supported
```

<span class="notes">**Note:** Targets are often abbreviated from the full model names. In the case of `FRDM-K64F` the target is `K64F`.</span>

## Run tests

You can use this application in interactive or automated mode.

### Interactive mode

To set the application to interactive mode:

1. Build the application.
```
mbed test --compile --icetea -t TOOLCHAIN -m TARGET_PLATFORM -DICETEA_MAC_TESTER_ENABLED --test-config NANOSTACK_MAC_TESTER -n address_read_and_write,send_data,send_data_indirect,send_large_payloads,create_and_join_PAN,ED_scan
```
2. Connect your board and copy the compiled application binary from the `BUILD/tests/TARGET_PLATFORM/TOOLCHAIN/TEST_APPS/device/nanostack_mac_tester/` folder to the board.
3. Wait for the device to flash the binary.
4. Open a serial connection with a program such as PuTTY, screen or minicom. The default baudrate is 115200.
5. Press the reset button on the board. The Arm Mbed logo and trace appears in the terminal window.

If the driver registration and SW MAC creation was successful, the application is ready to receive commands.

To start off, type `help` to list all commands available and furthermore `help <command>` to print detailed information about a specific command.

### Automated mode

```
mbed test --clean --compile --run --icetea -t TOOLCHAIN -m TARGET_PLATFORM -DICETEA_MAC_TESTER_ENABLED --test-config NANOSTACK_MAC_TESTER -n address_read_and_write,send_data,send_data_indirect,send_large_payloads,create_and_join_PAN,ED_scan
```

Many of the provided testcases have a `self.channel` variable in the `setUp()` function for setting the RF channel. The default channel is 11. If you wish to run a test on another channel, you will need to change it manually in TEST_APPS/testcases/nanostack_mac_tester/.

Some testcases also use a secondary channel for transmitting and will use the next higher channel for that purpose. If the given channel is 26, the secondary channel will default to 25.

### Test cases

The automated test set runs the following testcases included in the repository under `TEST_APPS/testcases/nanostack_mac_tester/`.
* Create and join PAN
* Direct data transmission(Transmission between two devices)
* Indirect data transmission(Transmission between two devices with one device acting as intermediary)
* ED scan(Energy Density scanning)
* Address read and write
* Large data transmission

### Considerations

* Devices need to be power cycled if they are unresponsive to test framework commands even after resetting.
* Devices can be enclosed in an RF isolation box to improve the consistency of test results.
* Some boards and radio modules come with a PCB trace antenna, instead of an SMD antenna, and need to be spaced further apart to decrease interference.
159 changes: 159 additions & 0 deletions TEST_APPS/device/nanostack_mac_tester/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "rtos.h"
#include "sw_mac.h"
#include "ns_hal_init.h"
#define MBED_CMDLINE_MAX_LINE_LENGTH 250
#include "ns_cmdline.h"

#include "mac_commands.h"

#define HEAP_FOR_MAC_TESTER_SIZE 10000
#define RX_BUFFER_SIZE 512

#define ATMEL 1
#define MCR20 2
#define OTHER 3

#define TRACE_GROUP "Main"
#include "mbed-trace/mbed_trace.h"

#include "NanostackRfPhy.h"

#if !DEVICE_802_15_4_PHY
#error [NOT_SUPPORTED] No 802.15.4 RF driver found for this target
#endif

#ifndef ICETEA_MAC_TESTER_ENABLED
#error [NOT_SUPPORTED] Skipping Nanostack MAC tester application.
#endif

extern mac_api_s *mac_interface;
RawSerial pc(USBTX, USBRX);
osThreadId main_thread;
static CircularBuffer<uint8_t, RX_BUFFER_SIZE> rx_buffer;
static uint8_t ns_heap[HEAP_FOR_MAC_TESTER_SIZE];

static void app_heap_error_handler(heap_fail_t event)
{
tr_error("Heap error (%d), app_heap_error_handler()", event);
switch (event) {
case NS_DYN_MEM_NULL_FREE:
case NS_DYN_MEM_DOUBLE_FREE:
case NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID:
case NS_DYN_MEM_POINTER_NOT_VALID:
case NS_DYN_MEM_HEAP_SECTOR_CORRUPTED:
case NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED:
break;
default:
break;
}
while (1);
}

static void rx_interrupt(void)
{
uint8_t c = pc.getc();
rx_buffer.push(c);
if (main_thread != NULL) {
osSignalSet(main_thread, 1);
}
}

static void handle_rx_data(void)
{
bool exit = false;
uint8_t data;

while (1) {
exit = !rx_buffer.pop(data);
if (exit) {
break;
}
cmd_char_input(data);
}
}


static int mac_prepare(void)
{
NanostackRfPhy &rf_phy = NanostackRfPhy::get_default_instance();
int8_t rf_driver_id = rf_phy.rf_register();
uint8_t rf_eui64[8];

if (rf_driver_id < 0) {
tr_error("Failed to register RF driver.");
return -1;
}
rf_phy.get_mac_address(rf_eui64);
mac_description_storage_size_t mac_description;
mac_description.device_decription_table_size = DEVICE_DESCRIPTOR_TABLE_SIZE; /** MAC Device description list size */
mac_description.key_description_table_size = KEY_DESCRIPTOR_TABLE_SIZE; /** MAC Key description list size */
mac_description.key_lookup_size = LOOKUP_DESCRIPTOR_TABLE_SIZE; /** Key description key lookup list size */
mac_description.key_usage_size = USAGE_DESCRIPTOR_TABLE_SIZE; /** Key description key usage list size */
tr_info("Registered RF driver with id: %hhu, EUI64: %s", rf_driver_id, mbed_trace_array(rf_eui64, 8));
mac_interface = ns_sw_mac_create(rf_driver_id, &mac_description);
if (!mac_interface) {
tr_error("Failed to create SW MAC.");
return -2;
}

return mac_interface->mac_initialize(mac_interface, mac_data_confirm_handler,
mac_data_indication_handler, mac_purge_confirm_handler, mac_mlme_confirm_handler,
mac_mlme_indication_handler, rf_driver_id);
}

static void cmd_ready_cb(int retcode)
{
cmd_next(retcode);
}

static void trace_printer(const char *str)
{
printf("%s\n", str);
cmd_output();
fflush(stdout);
}

int main(void)
{
main_thread = osThreadGetId();
pc.baud(MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
pc.attach(rx_interrupt);
ns_hal_init(ns_heap, HEAP_FOR_MAC_TESTER_SIZE, app_heap_error_handler, NULL);
mbed_trace_init();
mbed_trace_print_function_set(trace_printer);
cmd_init(&default_cmd_response_out);
cmd_set_ready_cb(cmd_ready_cb);
mac_commands_init();

if (mac_prepare() != 0) {
return -1;
}
tr_info("Created driver & SW MAC");

while (true) {
osEvent os_event = Thread::signal_wait(1);
if (os_event.status != osEventSignal) {
osThreadYield();
} else {
handle_rx_data();
}
}
return 0;
}
16 changes: 16 additions & 0 deletions TEST_APPS/device/nanostack_mac_tester/mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"macros": ["MBED_TRACE_LINE_LENGTH=200", "OS_TASKCNT=4", "OS_IDLESTKSIZE=32"],
"target_overrides": {
"*": {
"nanostack.configuration": "lowpan_host",
"platform.stdio-convert-newlines": true,
"platform.stdio-baud-rate": 115200,
"mbed-mesh-api.heap-size": 6000,
"nanostack-hal.event_loop_thread_stack_size": 2000,
"mbed-trace.enable": true,
"nsapi.default-stack": "LWIP",
"target.device_has_add": ["802_15_4_PHY"],
"atmel-rf.provide-default": true
}
}
}
Loading