Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2025, The OTNS Authors.
# Copyright (c) 2020-2026, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Build
run: |
./script/install-deps
./script/install
./script/install-otns

build-nodes:
name: Build Nodes (${{ matrix.os }})
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2025, The OTNS Authors.
# Copyright (c) 2020-2026, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
git diff
exit 1
fi
./script/install
./script/install-otns
- name: Build custom OT node
# FIXME: OT_CMAKE_NINJA_TARGET used to exclude tests, because test_platform.cpp is missing otPlatAssertFail()
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2025, The OTNS Authors.
# Copyright (c) 2020-2026, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -59,5 +59,5 @@ jobs:
- name: Check pretty
run: |
./script/install-deps
./script/install
./script/install-otns
./script/make-pretty check
2 changes: 1 addition & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Running this script will also set up a Python 3 virtual environment (venv) in `.
#### Install OTNS

```bash
./script/install
./script/install-otns
```

This installs `otns` in the Go binary directory of the user (typically `~/go/bin`) and makes the command available in the path. Also, it installs the pyOTNS library in the local Python virtual environment `.venv-otns`. The OT nodes required for running a simulation are not yet installed at this point: this is the next step.
Expand Down
4 changes: 3 additions & 1 deletion ot-rfsim/ot-versions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ Versions are listed below. With each version tag, the directory is listed in whi

- br-ccm - `openthread-ccm` - (In development) A Thread CCM Border Router.

Build scripts: the build scripts to build all of the versions are `../script/build_<version-tag>`. Each of these specific build scripts invokes the general `build` script. The `../script/build_all` builds all commonly used versions.
Build scripts: the build scripts to build all of the versions are `./script/build_<version-tag>`, which are invoked from the `./ot-rfsim` directory. Each of these specific build scripts invokes the general `build` script. The `./script/build_all` builds all commonly used versions.

Note: all build scripts copy the resulting executables to the `./ot-rfsim/ot-versions` directory. Before OTNS will use these executables, they must be copied to the `~/.local/share/otns/bin` directory. This is done by the installation script `./script/install-nodes` which is invoked from the main OTNS repo directory.
18 changes: 6 additions & 12 deletions script/install
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2020-2025, The OTNS Authors.
# Copyright (c) 2020-2026, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand All @@ -25,31 +25,25 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Installs OTNS (without any OT node executables) and pyOTNS.
# Installs OTNS in ~/go/bin, pyOTNS, and all nodes in ~/.local/share/otns

# shellcheck source=script/common.sh
. "$(dirname "$0")"/common.sh

install_otns()
{
go mod tidy
repeat 3 go_install ./cmd/...
echo "otns installed: $(command -v otns)"
./script/install-otns
}

install_pyotns()
install_nodes()
{
activate_python_venv
cd pylibs
python3 -m pip install .
# python3 setup.py install --user --prefix= 2>/dev/null # alternative - fails on macos-14
cd -
./script/install-nodes
}

main()
{
install_pyotns
install_otns
install_nodes
}

main
9 changes: 8 additions & 1 deletion script/install-nodes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2024-2025, The OTNS Authors.
# Copyright (c) 2024-2026, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,9 +31,16 @@
# shellcheck source=script/common.sh
. "$(dirname "$0")"/common.sh

install_nodes_to_local_share()
{
mkdir -p ~/.local/share/otns/bin
cp ./ot-rfsim/ot-versions/* ~/.local/share/otns/bin/
Comment on lines +36 to +37

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

For better compliance with the XDG Base Directory Specification and to improve robustness, consider using the $XDG_DATA_HOME environment variable, which defaults to $HOME/.local/share. This avoids hardcoding the path and respects user configurations. Using a variable also makes the code cleaner by avoiding repetition.

Suggested change
mkdir -p ~/.local/share/otns/bin
cp ./ot-rfsim/ot-versions/* ~/.local/share/otns/bin/
otns_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/otns/bin"
mkdir -p "$otns_data_dir" && cp ./ot-rfsim/ot-versions/* "$otns_data_dir/"

}

main()
{
build_openthread_versions
install_nodes_to_local_share
}

main
55 changes: 55 additions & 0 deletions script/install-otns
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# Copyright (c) 2020-2026, The OTNS Authors.
# 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.

# Installs OTNS (without any OT node executables) and pyOTNS.

# shellcheck source=script/common.sh
. "$(dirname "$0")"/common.sh

install_otns()
{
go mod tidy
repeat 3 go_install ./cmd/...
echo "otns installed: $(command -v otns)"
}

install_pyotns()
{
activate_python_venv
cd pylibs || die "required directory 'pylibs' not found"
python3 -m pip install .
# python3 setup.py install --user --prefix= 2>/dev/null # alternative - fails on macos-14
cd - || die "cd failed"
}

main()
{
install_pyotns
install_otns
}

main
4 changes: 2 additions & 2 deletions script/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2020-2025, The OTNS Authors.
# Copyright (c) 2020-2026, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -80,7 +80,7 @@ install_deps()

install_otns()
{
./script/install
./script/install-otns
}

py_unittests()
Expand Down
4 changes: 2 additions & 2 deletions simulation/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ var DefaultExecutableConfig ExecutableConfig = ExecutableConfig{
Mtd: "ot-cli-mtd",
Br: "ot-cli-ftd_br",
Matter: "ot-matter-node",
SearchPaths: []string{".", "./ot-rfsim/ot-versions", "./build/bin"},
SearchPaths: []string{".", filePathInUserHomeDir(".local/share/otns/bin"), "./ot-rfsim/ot-versions"},
}

func DefaultNodeConfig() NodeConfig {
Expand Down Expand Up @@ -280,7 +280,7 @@ func (cfg *ExecutableConfig) FindExecutable(exeName string) string {
return "./" + exePath
}
}
// if not found, try to relay on OS $PATH to find the executables.
// if not found, try to rely on OS $PATH to find the executables.
return exeName
}

Expand Down
10 changes: 9 additions & 1 deletion simulation/utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2024, The OTNS Authors.
// Copyright (c) 2020-2026, The OTNS Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -37,6 +37,14 @@ import (
"golang.org/x/net/ipv6"
)

func filePathInUserHomeDir(relPath string) string {
home, err := os.UserHomeDir()
if err == nil {
return filepath.Join(home, relPath)
}
return "/tmp/UserHomeDirNotFound"
}
Comment on lines +40 to +46

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 error handling for os.UserHomeDir() can be made clearer. Returning a magic string like /tmp/UserHomeDirNotFound without context can be confusing for future maintenance. It's good practice to add a comment explaining why a fallback path is returned. Also, using a guard clause for the error check would improve readability.

func filePathInUserHomeDir(relPath string) string {
	home, err := os.UserHomeDir()
	if err != nil {
		// os.UserHomeDir() can fail in some environments (e.g. when cross-compiling).
		// Return a path that is unlikely to exist, so the executable search will
		// gracefully fail for this path and continue with other search paths.
		return "/tmp/otns-home-dir-not-found"
	}
	return filepath.Join(home, relPath)
}


func removeAllFiles(globPath string) error {
files, err := filepath.Glob(globPath)
if err != nil {
Expand Down
Loading