Skip to content

Commit

Permalink
sample: net: RPL mesh sample over QEMU
Browse files Browse the repository at this point in the history
Create a net sample to setup a multi-node RPL mesh network using QMEU.
To enable this, it was necessary implement a hw filter on IEEE 802.15.4
UART Pipe driver and create a QEMU pipe management on cmake.

This sample use a tool developed on zephyr net-tools repository called
virtual-hub.

Signed-off-by: Pedro Martucci <[email protected]>
  • Loading branch information
pedropaulomartucci authored and jukkar committed Feb 20, 2018
1 parent ede5b8f commit a495b31
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.swo
*~
build
build-*
cscope.*
.dir
outdir
Expand Down Expand Up @@ -37,3 +38,4 @@ tags
.cproject
.xxproject
.envrc
.vscode
46 changes: 44 additions & 2 deletions cmake/emu/qemu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,49 @@ if(CONFIG_NETWORKING)
endif()
endif()

if(QEMU_NET_STACK)
# TO create independent pipes for each QEMU application set QEMU_PIPE_STACK
if(QEMU_PIPE_STACK)
list(APPEND qemu_targets
node
)

if(NOT QEMU_PIPE_ID)
set(QEMU_PIPE_ID 1)
endif()

list(APPEND QEMU_FLAGS
-serial none
)

list(APPEND MORE_FLAGS_FOR_node
-serial pipe:/tmp/hub/ip-stack-node${QEMU_PIPE_ID}
-pidfile qemu-node${QEMU_PIPE_ID}.pid
)

set(PIPE_NODE_IN /tmp/hub/ip-stack-node${QEMU_PIPE_ID}.in)
set(PIPE_NODE_OUT /tmp/hub/ip-stack-node${QEMU_PIPE_ID}.out)

set(pipes
${PIPE_NODE_IN}
${PIPE_NODE_OUT}
)

set(destroy_pipe_commands
COMMAND ${CMAKE_COMMAND} -E remove -f ${pipes}
)

set(create_pipe_commands
COMMAND ${CMAKE_COMMAND} -E make_directory /tmp/hub
COMMAND mkfifo ${PIPE_NODE_IN}
COMMAND mkfifo ${PIPE_NODE_OUT}
)

set(PRE_QEMU_COMMANDS_FOR_node
${destroy_pipe_commands}
${create_pipe_commands}
)

elseif(QEMU_NET_STACK)
list(APPEND qemu_targets
client
server
Expand Down Expand Up @@ -153,7 +195,7 @@ if(QEMU_NET_STACK)
# TODO: Support cleanup of the monitor_15_4 process
)
endif()
endif(QEMU_NET_STACK)
endif(QEMU_PIPE_STACK)

if(CONFIG_X86_IAMCU)
list(APPEND PRE_QEMU_COMMANDS
Expand Down
77 changes: 77 additions & 0 deletions samples/net/rpl-mesh-qemu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# RPL Mesh Network over QEMU

Overview
********

This sample uses virtual-hub tool from zephyrproject-rtos/net-tools
to setup a multi-node RPL network on top of QEMU. This way, is possible
to validate different network topologies in virtualized environment.

In this sample, we will build a three node graph connected like a row:

root <-> node1 <-> node2

Requirements
************

First of all, we must clone net-tools repository, and build virtual-hub:
```
cd virtual-hub
mkdir build && cd build
cmake ..
make
```

Building and Running
********************

1. Build and run the RPL root application:
```
cd root
mkdir build && cd build
cmake -DQEMU_PIPE_ID=1 ..
make
make node
```

2. Build and run the first RPL node application:
```
cd node
mkdir build-1 && cd build-1
cmake -DQEMU_PIPE_ID=2 ..
make
make node
```

3. Build and run the second RPL node application:
```
cd node
mkdir build-2 && cd build-2
cmake -DQEMU_PIPE_ID=3 ..
make
make node
```

4. Now we should run the virtual-hub, which will connect
all the pipes according to the csv file:
```
cd virtual-hub/build
./hub ../input.csv
```

5. Wait until the network is fine, you can check it
using net shell on root application:
```
select net
route
```
You should see two routes pointing to both clients application.

Virtual-Hub Notes
*****************

When trying to reboot/drop a node from network you must
also reboot the virtual-hub to keep it working properly.

For more details about how to customize the network, follow the
README instructions from virtual-hub repository.
9 changes: 9 additions & 0 deletions samples/net/rpl-mesh-qemu/node/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(BOARD qemu_cortex_m3)
set(CONF_FILE prj_qemu.conf)

set(QEMU_PIPE_STACK 1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

target_sources(app PRIVATE src/main.c)
60 changes: 60 additions & 0 deletions samples/net/rpl-mesh-qemu/node/prj_qemu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#### Initial Configuration ############################

# Enable basic networking
CONFIG_NETWORKING=y

# 802.15.4 requires random generator
CONFIG_TEST_RANDOM_GENERATOR=y

# Network Interface Buffer Size
CONFIG_NET_PKT_RX_COUNT=40
CONFIG_NET_PKT_TX_COUNT=40

#### Logging Configuration ############################

CONFIG_SYS_LOG=y
CONFIG_NET_LOG=y
CONFIG_SYS_LOG_NET_LEVEL=4
CONFIG_SYS_LOG_SHOW_COLOR=y

#### Network Stack Configuration ######################

# RPL (Routing)
CONFIG_NET_RPL=y
CONFIG_NET_DEBUG_RPL=y
CONFIG_NET_RPL_PROBING=y
CONFIG_NET_RPL_MAX_DAG_PER_INSTANCE=1

# IPv6 (L3)
CONFIG_NET_IPV6=y
CONFIG_NET_DEBUG_IPV6=n
CONFIG_NET_IPV6_ND=n
CONFIG_NET_IPV6_DAD=y
CONFIG_NET_IPV6_MLD=n

# 6LoWPAN (L2 - Adaptation Layer)
CONFIG_NET_6LO=y
CONFIG_NET_DEBUG_6LO=n

# 802.15.4 (L2)
CONFIG_NET_L2_IEEE802154=y
CONFIG_NET_DEBUG_L2_IEEE802154=n
CONFIG_NET_L2_IEEE802154_FRAGMENT=y
CONFIG_NET_DEBUG_L2_IEEE802154_FRAGMENT=n

# 802.15.4 (L1)
CONFIG_IEEE802154_UPIPE=y
CONFIG_SYS_LOG_IEEE802154_DRIVER_LEVEL=2

#### Additional Configuration #########################

# Enabled Shell Extensions
CONFIG_NET_SHELL=y
CONFIG_NET_L2_IEEE802154_SHELL=y
CONFIG_NET_APP_IEEE802154_DEV_NAME="IEEE802154_UPIPE"

# Disable default Ethernet interface
CONFIG_NET_SLIP_TAP=n

# Application Settings
CONFIG_NET_APP_SETTINGS=y
13 changes: 13 additions & 0 deletions samples/net/rpl-mesh-qemu/node/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2017 CPqD Foundation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <misc/printk.h>

void main(void)
{
printk("RPL node running\n");
}
11 changes: 11 additions & 0 deletions samples/net/rpl-mesh-qemu/root/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(BOARD qemu_cortex_m3)
set(CONF_FILE prj_qemu.conf)

set(QEMU_PIPE_STACK 1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/subsys/net/ip)

target_sources(app PRIVATE src/main.c)
69 changes: 69 additions & 0 deletions samples/net/rpl-mesh-qemu/root/prj_qemu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#### Initial Configuration ############################

# Enable basic networking
CONFIG_NETWORKING=y

# 802.15.4 requires random generator
CONFIG_TEST_RANDOM_GENERATOR=y

# Network Interface Buffer Size
CONFIG_NET_PKT_RX_COUNT=40
CONFIG_NET_PKT_TX_COUNT=40

#### Logging Configuration ############################

CONFIG_SYS_LOG=y
CONFIG_NET_LOG=y
CONFIG_SYS_LOG_NET_LEVEL=4
CONFIG_SYS_LOG_SHOW_COLOR=y

#### Network Stack Configuration ######################

# RPL (Routing)
CONFIG_NET_RPL=y
CONFIG_NET_DEBUG_RPL=y
CONFIG_NET_RPL_GROUNDED=y
CONFIG_NET_RPL_MAX_DAG_PER_INSTANCE=1
CONFIG_NET_RPL_PREFIX="2001:db8::1/64"

# IPv6 (L3)
CONFIG_NET_IPV6=y
CONFIG_NET_DEBUG_IPV6=n
CONFIG_NET_IPV6_ND=n
CONFIG_NET_IPV6_DAD=y
CONFIG_NET_IPV6_MLD=n

# 6LoWPAN (L2 - Adaptation Layer)
CONFIG_NET_6LO=y
CONFIG_NET_DEBUG_6LO=n

# 802.15.4 (L2)
CONFIG_NET_L2_IEEE802154=y
CONFIG_NET_DEBUG_L2_IEEE802154=n
CONFIG_NET_L2_IEEE802154_FRAGMENT=y
CONFIG_NET_DEBUG_L2_IEEE802154_FRAGMENT=n

# 802.15.4 (L1)
CONFIG_IEEE802154_UPIPE=y
CONFIG_SYS_LOG_IEEE802154_DRIVER_LEVEL=2

#### Additional Configuration #########################

# Enabled Shell Extensions
CONFIG_NET_SHELL=y
CONFIG_NET_L2_IEEE802154_SHELL=y

# Disable default Ethernet interface
CONFIG_NET_SLIP_TAP=n

# Application Settings
CONFIG_NET_APP_SETTINGS=y
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_APP_IEEE802154_DEV_NAME="IEEE802154_UPIPE"

# MAC Setup
CONFIG_IEEE802154_UPIPE_RANDOM_MAC=n
CONFIG_IEEE802154_UPIPE_MAC4=0xAA
CONFIG_IEEE802154_UPIPE_MAC5=0xAA
CONFIG_IEEE802154_UPIPE_MAC6=0xAA
CONFIG_IEEE802154_UPIPE_MAC7=0xAA
Loading

0 comments on commit a495b31

Please sign in to comment.