Skip to content

Add example run OTNS with OT-BR and Matter accessories.#784

Open
francoismichel wants to merge 7 commits into
openthread:mainfrom
francoismichel:matter-otbr-example
Open

Add example run OTNS with OT-BR and Matter accessories.#784
francoismichel wants to merge 7 commits into
openthread:mainfrom
francoismichel:matter-otbr-example

Conversation

@francoismichel
Copy link
Copy Markdown

Here is an example allowing to run OT-BR in OTNS, routing over the infrastructure interface, and run simulated Matter nodes in the mesh. This allows real processes and real devices to communicate with simulated nodes (including Matter nodes) running in OTNS.

The README contains a tutorial. The Dockerfile currently uses a fork of OT-NS and a fork of Matter and applies a patch to these forks as well. Once these forks and patches get intergrated into the mainline repos, we will update this example accordingly.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The README contains a tutorial. The Dockerfile currently uses a fork of
OT-NS and a fork of Matter and applies a patch to these forks as well.
Once these forks and patches get intergrated into the mainline repos, we
will update this example accordingly.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Docker-based development environment for simulating Thread networks using OTNS, Matter, and OT-BR. It includes a multi-stage Dockerfile, a helper script for cross-platform execution, and detailed documentation. Review feedback identified a critical issue with an invalid Go version that would prevent the build, a potential configuration conflict caused by hardcoding the network interface name in the OTBR setup, and a suggestion to parameterize the Docker image name for better flexibility.

FROM ubuntu:24.04

ARG TARGETARCH
ARG GO_VERSION=1.26.2
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The Go version 1.26.2 is invalid as it has not been released yet (the current stable version is 1.23.x). This will cause the wget command at line 80 to fail, preventing the Docker image from building.

ARG GO_VERSION=1.23.4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francoismichel While I would ignore this comment :) , OTNS is built and tested for Go 1.23 currently. Maybe it doesn't matter much, but Go 1.23 may be sufficient.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing this from https://go.dev/doc/devel/release#go1.26.minor :

go1.26.2 (released 2026-04-07) includes security fixes to the go command, the compiler, and the archive/tar, crypto/tls, crypto/x509, html/template, and os packages, as well as bug fixes to the go command, the go fix command, the compiler, the linker, the runtime, and the net, net/http, and net/url packages. See the Go 1.26.2 milestone on our issue tracker for details

I had to use a recent version of go because the go compiler had errors when cross-compiling from arm64 to amd64 that got fixed in the latest versions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, resolving the comment

Comment on lines +327 to +334
INFRA_IF_NAME=eth0 WEB_GUI=1 NAT64=1 OTBR_MDNS=mDNSResponder ./script/bootstrap

# Stub systemctl so setup doesn't try to start/enable services during docker build
RUN ln -sf /bin/true /usr/local/bin/systemctl

# Run setup to install binaries, DBus config, ot-ctl, etc.
RUN HOME=/root && cd /home/otns/ot-br-posix && \
INFRA_IF_NAME=eth0 WEB_GUI=1 NAT64=1 OTBR_MDNS=mDNSResponder DOCKER=1 FIREWALL=0 ./script/setup
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding INFRA_IF_NAME=eth0 during the OTBR setup phase can cause issues when running the container on Linux hosts with --network host (as configured in run-docker.sh), where the primary network interface might not be named eth0. While the entrypoint script attempts to detect the backbone interface at runtime, the OTBR configuration generated during script/setup (e.g., agent options, firewall rules) may still contain hardcoded references to eth0.

Consider using a BUILD_ARG for the interface name or updating the configuration dynamically in the entrypoint script.


set -e

IMAGE_NAME="framichel/otns-matter"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The IMAGE_NAME is hardcoded to a specific user's Docker Hub namespace (framichel/). For a generic example in the repository, it is better to use a more neutral name or allow it to be overridden via an environment variable.

Suggested change
IMAGE_NAME="framichel/otns-matter"
IMAGE_NAME="${OTNS_MATTER_IMAGE:-otns-matter}"

@jwhui jwhui requested a review from Vyrastas April 17, 2026 18:36
@@ -0,0 +1,169 @@
# OTNS + Matter + OT-BR Docker Environment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vyrastas , can you help review this README?

@@ -0,0 +1,86 @@
#!/bin/bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add standard OpenThread license header.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b5f6bfc

@@ -0,0 +1,408 @@
# Dockerfile for OTNS + OT-BR + Matter all-clusters-app development environment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add standard OpenThread license header.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b5f6bfc

Copy link
Copy Markdown
Member

@Vyrastas Vyrastas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in reviewing!

docker build -t otns-matter .
```

The build takes a long time (compiling OpenThread, Matter, OT-BR from source).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Long time" is vague, can you provide a rough estimate of what to expect?

Also, you can drop the parentheses and do something like

"Because the build compiles OpenThread, Matter, and OT-BR from source, it may take up to X minutes."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data point: In my case it was ~31 minutes (on a fast network, fast laptop)


## Run

If you haven't built the image in the previous step, it will pull the image from Docker Hub.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you haven't built the image in the previous step, it will pull the image from Docker Hub.
If you didn't build the image in the previous step, running will pull the image from Docker Hub.


## Using OTNS inside the container

The entrypoint auto-detects the backbone interface and prints the recommended
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The entrypoint auto-detects the backbone interface and prints the recommended
The entry point auto-detects the backbone interface and prints the recommended

otns -realtime -listen 0.0.0.0:9000 -otbr-backbone-if eth0
```

Or just type `otns` — the entrypoint sets up an alias with the right flags.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Or just type `otns` — the entrypoint sets up an alias with the right flags.
Or just type `otns` — the entry point sets up an alias with the correct flags.


- **FTD nodes** — regular Thread Full Thread Devices
- **OTBR nodes** — Thread Border Routers (with border routing and SRP server)
- **Matter nodes** — Matter all-clusters-app devices running over Thread
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use code font for instances of all-clusters-app?

- Advertise an OMR prefix in Thread network data
- Run an SRP server and advertise it in Thread network data

(Requires `-otbr-backbone-if` to be set to a valid interface.)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the parentheses and just have a normal sentence here

This requires -otbr-backbone-if to be set...


### 2. Install chip-tool

The chip-tool is used to commission and control Matter accessories. You can either install it from snap or build it from source.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When referring to a binary / command, use code font, so snap should be in code font

The binary will be at `out/linux-x64-chip-tool/chip-tool`.
For arm64 hosts, replace `x64` with `arm64`.

### 3. Commission and control a Matter lightbulb
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 3. Commission and control a Matter lightbulb
### 3. Commission and control a Matter light bulb

4. Add as many other nodes as you want: click on "router" or type `add router`
in the OTNS CLI
5. Monitor the announced services from the Linux VM (outside the container) using `avahi-browse -a`.
Wait until a `_matterc._udp` service shows up, meaning that the Matter node has registered its SRP service on the OTBR node. Once that is donem you can start pairing and controlling the accessory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Wait until a `_matterc._udp` service shows up, meaning that the Matter node has registered its SRP service on the OTBR node. Once that is donem you can start pairing and controlling the accessory.
Wait until a `_matterc._udp` service shows up, meaning that the Matter node has registered its SRP service on the OTBR node. Once that is done you can start pairing and controlling the accessory.

Please also adjust the line breaks here for readability

./chip-tool onoff read on-off 1234 1
```

The `1234` is the node ID (assigned during pairing), it must be different for every matter node. The `1` is the endpoint ID. It is always `1` for every node.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust line breaks for readability please

@EskoDijk
Copy link
Copy Markdown
Contributor

@francoismichel Could we also add early on in the README, something like:
if you got the Docker image as a tar.gz file, then first load it in Docker using

docker load < matter-otbr-example-docker.tar.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants