summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-03-21 22:01:32 +0100
committerxengineering <me@xengineering.eu>2025-03-21 22:01:32 +0100
commit5f457c4786b270f0918294b09f32c484f165e2ef (patch)
tree2d9aae465a02d0c1d472a4a13cabf7e6971aa992
parentc72b621019ceb103033e289addbb448ad5f4e3b6 (diff)
downloadiot-contact-5f457c4786b270f0918294b09f32c484f165e2ef.tar
iot-contact-5f457c4786b270f0918294b09f32c484f165e2ef.tar.zst
iot-contact-5f457c4786b270f0918294b09f32c484f165e2ef.zip
fw: Add simulate-network.sh
This script can be called with root permissions and without any arguments to provide a virtual network interface `zeth` and an IPv6 router advertisement daemon to provide a realistic network environment without any hardware.
-rw-r--r--fw/radvd.conf16
-rwxr-xr-xfw/simulate-network.sh56
2 files changed, 72 insertions, 0 deletions
diff --git a/fw/radvd.conf b/fw/radvd.conf
new file mode 100644
index 0000000..98c703f
--- /dev/null
+++ b/fw/radvd.conf
@@ -0,0 +1,16 @@
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/.
+
+interface zeth
+{
+ AdvSendAdvert on;
+ MinRtrAdvInterval 3;
+ MaxRtrAdvInterval 10;
+ AdvDefaultPreference low;
+ prefix 2001:db8::/64
+ {
+ AdvOnLink on;
+ AdvAutonomous on;
+ };
+};
diff --git a/fw/simulate-network.sh b/fw/simulate-network.sh
new file mode 100755
index 0000000..7f92dab
--- /dev/null
+++ b/fw/simulate-network.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/.
+
+# This script provides a simulated network environment for a simulated Zephyr
+# firmware.
+#
+# It is based on providing a simulated layer 2 network interface (TAP) and
+# providing required services as Linux processes there. One example is the
+# radvd service which send router advertisements which are required for IPv6
+# stateless address auto configuration (SLAAC).
+#
+# Root rights are required to run this script. Use your preferred privilege
+# escalation program to call this script like this:
+#
+# sudo ./simulate-network.sh
+
+
+set -euf
+
+
+FW="$(dirname "$0")"
+RADVD_CONF="${FW}/radvd.conf"
+
+INTERFACE='zeth'
+LINUX_IP='2001:db8::2'
+NETMASK='64'
+
+radvd_pid=''
+
+
+cleanup() {
+ if test "$radvd_pid" != ""
+ then
+ kill "$radvd_pid"
+ fi
+
+ ip link delete "$INTERFACE"
+}
+
+
+trap cleanup EXIT
+
+set -x
+
+ip tuntap add "$INTERFACE" mode tap
+ip link set dev "$INTERFACE" up
+ip addr add "${LINUX_IP}/${NETMASK}" dev "$INTERFACE"
+
+radvd --nodaemon --config "$RADVD_CONF" > /dev/null 2>&1 &
+radvd_pid="$!"
+
+wait