diff --git a/tools/harness-simulation/README.md b/tools/harness-simulation/README.md index 0471685ae..d7f3a3c7a 100644 --- a/tools/harness-simulation/README.md +++ b/tools/harness-simulation/README.md @@ -10,7 +10,7 @@ Platform developers should modify the THCI implementation and/or the SI implemen ## POSIX Environment Setup -1. Open the JSON format configuration file `tools/harness-simulation/posix/simulation.conf`: +1. Open the JSON format configuration file `tools/harness-simulation/posix/config.yml`: - Edit the value of `ot_path` to the absolute path where the top directory of the OpenThread repository is located. For example, change the value of `ot_path` to `/home//repo/openthread`. - For each entry in `ot_build.ot`, update the value of `number` to be the number of OT FTD simulations needed with the corresponding version. @@ -42,10 +42,10 @@ Platform developers should modify the THCI implementation and/or the SI implemen ```bash $ cd tools/harness-simulation/posix - $ ./launch_testbed.py -c simulation.conf + $ ./launch_testbed.py -c config.yml ``` - This example starts several OT FTD simulations, OTBR simulations, and sniffer simulations and can be discovered on `eth0`. The number of each type of simulation is specified in the configuration file `simulation.conf`. + This example starts several OT FTD simulations, OTBR simulations, and sniffer simulations and can be discovered on `eth0`. The number of each type of simulation is specified in the configuration file `config.yml`. 2. Run the Test Harness. The information field of the device is encoded as `_@`. Choose the desired device as the DUT. diff --git a/tools/harness-simulation/harness/Thread_Harness/simulation/config.py b/tools/harness-simulation/harness/Thread_Harness/simulation/config.py index 63605d0a1..61bc379c7 100644 --- a/tools/harness-simulation/harness/Thread_Harness/simulation/config.py +++ b/tools/harness-simulation/harness/Thread_Harness/simulation/config.py @@ -27,13 +27,13 @@ # POSSIBILITY OF SUCH DAMAGE. # -import json import os +import yaml -CONFIG_PATH = r'%s\GRL\Thread1.2\Thread_Harness\simulation\simulation.conf' % os.environ['systemdrive'] +CONFIG_PATH = r'%s\GRL\Thread1.2\Thread_Harness\simulation\config.yml' % os.environ['systemdrive'] def load_config(): with open(CONFIG_PATH, 'rt') as f: - config = json.load(f) + config = yaml.safe_load(f) return config diff --git a/tools/harness-simulation/harness/install.bat b/tools/harness-simulation/harness/install.bat index 133f1e1f5..38e86fbc2 100644 --- a/tools/harness-simulation/harness/install.bat +++ b/tools/harness-simulation/harness/install.bat @@ -31,7 +31,7 @@ copy /Y ..\..\harness-thci\OpenThread.py %THREADDIR%\Thread_Harness\THCI copy /Y ..\..\harness-thci\OpenThread_BR.py %THREADDIR%\Thread_Harness\THCI copy /Y ..\..\harness-thci\OpenThread.png %THREADDIR%\Web\images copy /Y ..\..\harness-thci\OpenThread_BR.png %THREADDIR%\Web\images -copy /Y ..\posix\simulation.conf %THREADDIR%\Thread_Harness\simulation +copy /Y ..\posix\config.yml %THREADDIR%\Thread_Harness\simulation xcopy /E /Y ..\posix\sniffer_sim\proto %THREADDIR%\Thread_Harness\simulation\Sniffer\proto %THREADDIR%\Python27\python.exe -m pip install --upgrade pip diff --git a/tools/harness-simulation/harness/requirements.txt b/tools/harness-simulation/harness/requirements.txt index 0d1d827d9..179c044ca 100644 --- a/tools/harness-simulation/harness/requirements.txt +++ b/tools/harness-simulation/harness/requirements.txt @@ -1,2 +1,3 @@ grpcio==1.20.1 grpcio-tools==1.20.1 +PyYAML==5.4.1 diff --git a/tools/harness-simulation/posix/config.yml b/tools/harness-simulation/posix/config.yml new file mode 100644 index 000000000..11b29bca5 --- /dev/null +++ b/tools/harness-simulation/posix/config.yml @@ -0,0 +1,91 @@ +ot_path: "/home/pi/repo/openthread" +ot_build: + max_number: 64 + ot: + - tag: OT11 + version: '1.1' + number: 33 + subpath: build/ot11/simulation + cflags: + - "-DOPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS=8" + options: + - "-DOT_REFERENCE_DEVICE=ON" + - "-DOT_COMMISSIONER=ON" + - "-DOT_JOINER=ON" + - tag: OT12 + version: '1.2' + number: 10 + subpath: build/ot12/simulation + cflags: + - "-DOPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS=8" + options: + - "-DOT_REFERENCE_DEVICE=ON" + - "-DOT_DUA=ON" + - "-DOT_MLR=ON" + - "-DOT_COMMISSIONER=ON" + - "-DOT_JOINER=ON" + - "-DOT_CSL_RECEIVER=ON" + - "-DOT_LINK_METRICS_SUBJECT=ON" + - "-DOT_LINK_METRICS_INITIATOR=ON" + - tag: OT13 + version: '1.3' + number: 10 + subpath: build/ot13/simulation + cflags: + - "-DOPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS=8" + options: + - "-DOT_REFERENCE_DEVICE=ON" + - "-DOT_DUA=ON" + - "-DOT_MLR=ON" + - "-DOT_COMMISSIONER=ON" + - "-DOT_JOINER=ON" + - "-DOT_CSL_RECEIVER=ON" + - "-DOT_LINK_METRICS_SUBJECT=ON" + - "-DOT_LINK_METRICS_INITIATOR=ON" + otbr: + - tag: OTBR12 + version: '1.2' + number: 4 + docker_image: otbr-reference-device-1.2 + build_args: + - REFERENCE_DEVICE=1 + - BORDER_ROUTING=0 + - BACKBONE_ROUTER=1 + - NAT64=0 + - WEB_GUI=0 + - REST_API=0 + - OT_COMMISSIONER=1 + options: + - "-DOTBR_DUA_ROUTING=ON" + - "-DOT_DUA=ON" + - "-DOT_MLR=ON" + rcp_subpath: build/ot12/simulation + rcp_options: + - "-DOT_LINK_METRICS_SUBJECT=ON" + - tag: OTBR13 + version: '1.3' + number: 4 + docker_image: otbr-reference-device-1.3 + build_args: + - REFERENCE_DEVICE=1 + - BORDER_ROUTING=1 + - BACKBONE_ROUTER=1 + - NAT64=0 + - WEB_GUI=0 + - REST_API=0 + - EXTERNAL_COMMISSIONER=1 + options: + - "-DOTBR_DUA_ROUTING=ON" + - "-DOT_DUA=ON" + - "-DOT_MLR=ON" + rcp_subpath: build/ot13/simulation + rcp_options: + - "-DOT_LINK_METRICS_SUBJECT=ON" +ssh: + username: pi + password: raspberry + port: 22 +sniffer: + number: 2 + server_port_base: 50051 +discovery_ifname: eth0 diff --git a/tools/harness-simulation/posix/install.sh b/tools/harness-simulation/posix/install.sh index cc23a5bb2..aedba3916 100755 --- a/tools/harness-simulation/posix/install.sh +++ b/tools/harness-simulation/posix/install.sh @@ -34,14 +34,6 @@ OT_DIR="${POSIX_DIR}/../../.." ETC_DIR="${POSIX_DIR}/etc" SNIFFER_DIR="${POSIX_DIR}/sniffer_sim" -CONFIG=${1:-"${POSIX_DIR}/simulation.conf"} -# Use absolute path in case of changing current working directory -if [[ ${CONFIG:0:1} != '/' ]]; then - CONFIG="${POSIX_DIR}/${CONFIG}" -fi - -MAX_NETWORK_SIZE=$(jq -r '.ot_build.max_number' "$CONFIG") - PACKAGES=( "docker.io" "git" @@ -55,6 +47,12 @@ sudo apt install -y "${PACKAGES[@]}" pip3 install -r "${POSIX_DIR}/requirements.txt" python3 -m grpc_tools.protoc -I"${SNIFFER_DIR}" --python_out="${SNIFFER_DIR}" --grpc_python_out="${SNIFFER_DIR}" proto/sniffer.proto +CONFIG_NAME=${1:-"${POSIX_DIR}/config.yml"} +# convert YAML to JSON +CONFIG=$(python3 -c 'import json, sys, yaml; print(json.dumps(yaml.safe_load(open(sys.argv[1]))))' "$CONFIG_NAME") + +MAX_NETWORK_SIZE=$(jq -r '.ot_build.max_number' <<<"$CONFIG") + build_ot() { # SC2155: Declare and assign separately to avoid masking return values @@ -126,7 +124,7 @@ build_otbr() --build-arg OTBR_OPTIONS="${otbr_options[*]}" } -for item in $(jq -c '.ot_build.ot | .[]' "$CONFIG"); do +for item in $(jq -c '.ot_build.ot | .[]' <<<"$CONFIG"); do build_ot "$item" done @@ -144,7 +142,7 @@ git clone https://github.com/openthread/ot-br-posix.git --recurse-submodules --s mkdir -p root/tmp cp "${ETC_DIR}/requirements.txt" root/tmp/requirements.txt - for item in $(jq -c '.ot_build.otbr | .[]' "$CONFIG"); do + for item in $(jq -c '.ot_build.otbr | .[]' <<<"$CONFIG"); do build_otbr "$item" done ) diff --git a/tools/harness-simulation/posix/launch_testbed.py b/tools/harness-simulation/posix/launch_testbed.py index dd49fa3bd..5ca2537ea 100755 --- a/tools/harness-simulation/posix/launch_testbed.py +++ b/tools/harness-simulation/posix/launch_testbed.py @@ -40,6 +40,7 @@ import struct import subprocess import sys from typing import Iterable +import yaml from otbr_sim import otbr_docker @@ -140,7 +141,7 @@ def main(): help='the path of the configuration JSON file') args = parser.parse_args() with open(args.config, 'rt') as f: - config = json.load(f) + config = yaml.safe_load(f) ot_path = config['ot_path'] ot_build = config['ot_build'] diff --git a/tools/harness-simulation/posix/requirements.txt b/tools/harness-simulation/posix/requirements.txt index a6646e7b9..21ed00b55 100644 --- a/tools/harness-simulation/posix/requirements.txt +++ b/tools/harness-simulation/posix/requirements.txt @@ -1,2 +1,3 @@ grpcio grpcio-tools +PyYAML diff --git a/tools/harness-simulation/posix/simulation.conf b/tools/harness-simulation/posix/simulation.conf deleted file mode 100644 index 7c7ab8859..000000000 --- a/tools/harness-simulation/posix/simulation.conf +++ /dev/null @@ -1,120 +0,0 @@ -{ - "ot_path": "/home/pi/repo/openthread", - "ot_build": { - "max_number": 64, - "ot": [ - { - "tag": "OT11", - "version": "1.1", - "number": 33, - "subpath": "build/ot11/simulation", - "cflags": [ - "-DOPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS=8" - ], - "options": [ - "-DOT_REFERENCE_DEVICE=ON", - "-DOT_COMMISSIONER=ON", - "-DOT_JOINER=ON" - ] - }, - { - "tag": "OT12", - "version": "1.2", - "number": 10, - "subpath": "build/ot12/simulation", - "cflags": [ - "-DOPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS=8" - ], - "options": [ - "-DOT_REFERENCE_DEVICE=ON", - "-DOT_DUA=ON", - "-DOT_MLR=ON", - "-DOT_COMMISSIONER=ON", - "-DOT_JOINER=ON", - "-DOT_CSL_RECEIVER=ON", - "-DOT_LINK_METRICS_SUBJECT=ON", - "-DOT_LINK_METRICS_INITIATOR=ON" - ] - }, - { - "tag": "OT13", - "version": "1.3", - "number": 10, - "subpath": "build/ot13/simulation", - "cflags": [ - "-DOPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS=8" - ], - "options": [ - "-DOT_REFERENCE_DEVICE=ON", - "-DOT_DUA=ON", - "-DOT_MLR=ON", - "-DOT_COMMISSIONER=ON", - "-DOT_JOINER=ON", - "-DOT_CSL_RECEIVER=ON", - "-DOT_LINK_METRICS_SUBJECT=ON", - "-DOT_LINK_METRICS_INITIATOR=ON" - ] - } - ], - "otbr": [ - { - "tag": "OTBR12", - "version": "1.2", - "number": 4, - "docker_image": "otbr-reference-device-1.2", - "build_args": [ - "REFERENCE_DEVICE=1", - "BORDER_ROUTING=0", - "BACKBONE_ROUTER=1", - "NAT64=0", - "WEB_GUI=0", - "REST_API=0", - "OT_COMMISSIONER=1" - ], - "options": [ - "-DOTBR_DUA_ROUTING=ON", - "-DOT_DUA=ON", - "-DOT_MLR=ON" - ], - "rcp_subpath": "build/ot12/simulation", - "rcp_options": [ - "-DOT_LINK_METRICS_SUBJECT=ON" - ] - }, - { - "tag": "OTBR13", - "version": "1.3", - "number": 4, - "docker_image": "otbr-reference-device-1.3", - "build_args": [ - "REFERENCE_DEVICE=1", - "BORDER_ROUTING=1", - "BACKBONE_ROUTER=1", - "NAT64=0", - "WEB_GUI=0", - "REST_API=0", - "EXTERNAL_COMMISSIONER=1" - ], - "options": [ - "-DOTBR_DUA_ROUTING=ON", - "-DOT_DUA=ON", - "-DOT_MLR=ON" - ], - "rcp_subpath": "build/ot13/simulation", - "rcp_options": [ - "-DOT_LINK_METRICS_SUBJECT=ON" - ] - } - ] - }, - "ssh": { - "username": "pi", - "password": "raspberry", - "port": 22 - }, - "sniffer": { - "number": 2, - "server_port_base": 50051 - }, - "discovery_ifname": "eth0" -}