Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request unicast responses for resolving nodes when using minmdns #11635

Merged
merged 22 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1f948d8
Request unicast responses for resolving nodes when using minmdns
andy31415 Nov 10, 2021
fc0bac5
Set unicast answer to true in browse nodes as well
andy31415 Nov 10, 2021
1f9873b
Make unit tests use platform mdns: chip tool and all clusters all nee…
andy31415 Nov 10, 2021
18004e1
Set the chip_mdns value as a string
andy31415 Nov 10, 2021
4152962
Escape quotes for platform mdns build
andy31415 Nov 10, 2021
697dc95
Merge branch 'master' into unicast_mdns_resolve
andy31415 Nov 10, 2021
09d690d
Revert platform mdns usage in tests: avahi does not properly work for…
andy31415 Nov 11, 2021
0c1417d
Merge branch 'master' into unicast_mdns_resolve
andy31415 Nov 11, 2021
17d8283
Add support for using netns namespaces for unit test runs - check to …
andy31415 Nov 11, 2021
f30680d
Do not restyle test_suites.sh
andy31415 Nov 11, 2021
24164f4
Merge branch 'master' into unicast_mdns_resolve
andy31415 Nov 11, 2021
ee6d5ca
Some script cleanup
andy31415 Nov 11, 2021
9736f34
Temporarely run the tests on ipv4 only until I figure out ipv6 multic…
andy31415 Nov 11, 2021
fe6c438
Cleanup netns as a final step, just in case
andy31415 Nov 11, 2021
759c86f
Move cleanup again - cleanup is added again post-netns setup
andy31415 Nov 11, 2021
205e937
Code review comments, enable ipv6 back
andy31415 Nov 11, 2021
0d3dfe3
Add note on why we stop restuling testsuites.sh
andy31415 Nov 12, 2021
1ff5185
Use unshare instead of sudo to run unit tests in namespaces
andy31415 Nov 12, 2021
ea74977
Update remount logic to only apply for unshare environments
andy31415 Nov 12, 2021
506036a
Updated messaging logic
andy31415 Nov 12, 2021
a3ccf5c
Merge branch 'master' into unicast_mdns_resolve
andy31415 Nov 15, 2021
03f4d6a
Added a sleep for IPv6 and a comment as to why
andy31415 Nov 15, 2021
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/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ jobs:
- name: Run Tests
timeout-minutes: 20
run: |
scripts/tests/test_suites.sh
scripts/tests/test_suites.sh -n
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
- name: Run TV Tests
timeout-minutes: 10
run: |
scripts/tests/test_suites.sh -a tv
scripts/tests/test_suites.sh -n -a tv
- name: Uploading core files
uses: actions/upload-artifact@v2
if: ${{ failure() }} && ${{ !env.ACT }}
Expand Down
1 change: 1 addition & 0 deletions .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exclude:
- "third_party/nanopb/repo/**/*"
- "src/android/CHIPTool/gradlew" # gradle wrapper generated file
- "third_party/android_deps/gradlew" # gradle wrapper generated file
- "scripts/tests/test_suites.sh"
andy31415 marked this conversation as resolved.
Show resolved Hide resolved


changed_paths:
Expand Down
109 changes: 98 additions & 11 deletions scripts/tests/test_suites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ declare -i iterations=2
declare -i delay=0
declare -i node_id=0x12344321
declare -i background_pid=0
declare -i use_netns=0
declare -i pre_clean_netns=0
declare test_case_wrapper=()

usage() {
Expand All @@ -38,22 +40,103 @@ usage() {
echo " -s CASE_NAME: runs single test case name (e.g. Test_TC_OO_2_2"
echo " for Test_TC_OO_2_2.yaml) (by default, all are run)"
echo " -w COMMAND: prefix all instantiations with a command (e.g. valgrind) (default: '')"
echo " -n Use linux netns to isolate app and tool executables"
echo " -c execute a netns cleanup and exit"
echo ""
exit 0
}

declare privileged_run=""

if [[ $(whoami) != "root" ]]; then
privileged_run='sudo'
fi

declare app_run_prefix=""
declare tool_run_prefix=""
declare rm_run_prefix=""

netns_setup() {
# 2 virtual hosts: for app and for the tool
${privileged_run} ip netns add app
${privileged_run} ip netns add tool

# create links for switch to net connections
${privileged_run} ip link add eth-app type veth peer name eth-app-switch
${privileged_run} ip link add eth-tool type veth peer name eth-tool-switch

# link the connections together
${privileged_run} ip link set eth-app netns app
${privileged_run} ip link set eth-tool netns tool

${privileged_run} ip link add name br1 type bridge
${privileged_run} ip link set br1 up
${privileged_run} ip link set eth-app-switch master br1
${privileged_run} ip link set eth-tool-switch master br1

# mark connections up
${privileged_run} ip netns exec app ip addr add 10.10.10.1/24 dev eth-app
${privileged_run} ip netns exec app ip link set dev eth-app up
${privileged_run} ip netns exec app ip link set dev lo up
${privileged_run} ip link set dev eth-app-switch up

${privileged_run} ip netns exec tool ip addr add 10.10.10.2/24 dev eth-tool
${privileged_run} ip netns exec tool ip link set dev eth-tool up
${privileged_run} ip netns exec tool ip link set dev lo up
${privileged_run} ip link set dev eth-tool-switch up

# Force IPv6 to use ULAs that we control
${privileged_run} ip netns exec tool ip -6 addr flush eth-tool
${privileged_run} ip netns exec app ip -6 addr flush eth-app
${privileged_run} ip netns exec tool ip -6 a add fd00:0:1:1::2/64 dev eth-tool
${privileged_run} ip netns exec app ip -6 a add fd00:0:1:1::3/64 dev eth-app
}

netns_cleanup() {
${privileged_run} ip netns del app || true
${privileged_run} ip netns del tool || true
${privileged_run} ip link del br1 || true

# attempt to delete orphaned items just in case
${privileged_run} ip link del eth-tool || true
${privileged_run} ip link del eth-tool-switch || true
${privileged_run} ip link del eth-app || true
${privileged_run} ip link del eth-app-switch || true
}

# read shell arguments
while getopts a:d:i:hs:w: flag; do
while getopts a:d:i:hs:w:nc flag; do
case "$flag" in
a) application=$OPTARG ;;
d) delay=$OPTARG ;;
h) usage ;;
i) iterations=$OPTARG ;;
s) single_case=$OPTARG ;;
w) test_case_wrapper=("$OPTARG") ;;
a) application=$OPTARG ;;
d) delay=$OPTARG ;;
h) usage ;;
i) iterations=$OPTARG ;;
s) single_case=$OPTARG ;;
w) test_case_wrapper=("$OPTARG") ;;
n) use_netns=1 ;;
c) pre_clean_netns=1 ;;
esac
done

if [[ $pre_clean_netns != 0 ]]; then
echo "Cleaning network namespaces"
netns_cleanup
exit 0
fi

if [[ $use_netns != 0 ]]; then
echo "Using network namespaces"
netns_setup

app_run_prefix="${privileged_run} ip netns exec app"
tool_run_prefix="${privileged_run} ip netns exec tool"

# APPs run privileged
rm_run_prefix="${privileged_run}"

trap netns_cleanup EXIT
fi

if [[ $application == "tv" ]]; then
declare test_filenames="${single_case-TV_*}.yaml"
cp examples/tv-app/linux/include/endpoint-configuration/chip_tv_config.ini /tmp/chip_tv_config.ini
Expand All @@ -77,6 +160,10 @@ cleanup() {
# In case we died on a failure before we cleaned up our background task.
kill -9 "$background_pid" || true
fi

if [[ $use_netns != 0 ]]; then
netns_cleanup
fi
}
trap cleanup EXIT

Expand All @@ -98,7 +185,7 @@ for j in "${iter_array[@]}"; do
for i in "${test_array[@]}"; do
echo " ===== Running test: $i"
echo " * Starting cluster server"
rm -rf /tmp/chip_tool_config.ini
${rm_run_prefix} rm -rf /tmp/chip_tool_config.ini
# This part is a little complicated. We want to
# 1) Start chip-app in the background
# 2) Pipe its output through tee so we can wait until it's ready for a
Expand All @@ -123,7 +210,7 @@ for j in "${iter_array[@]}"; do
touch "$chip_tool_log_file"
rm -rf /tmp/pid
(
stdbuf -o0 "${test_case_wrapper[@]}" out/debug/standalone/chip-"$application"-app &
${app_run_prefix} stdbuf -o0 "${test_case_wrapper[@]}" out/debug/standalone/chip-"$application"-app &
echo $! >&3
) 3>/tmp/pid | tee "$application_log_file" &
while ! grep -q "Server Listening" "$application_log_file"; do
Expand All @@ -141,9 +228,9 @@ for j in "${iter_array[@]}"; do
cat <(timeout 1 dns-sd -B _matterc._udp)
fi
echo " * Pairing to device"
"${test_case_wrapper[@]}" out/debug/standalone/chip-tool pairing qrcode "$node_id" MT:D8XA0CQM00KA0648G00 | tee "$pairing_log_file"
${tool_run_prefix} "${test_case_wrapper[@]}" out/debug/standalone/chip-tool pairing qrcode "$node_id" MT:D8XA0CQM00KA0648G00 | tee "$pairing_log_file"
echo " * Starting test run: $i"
"${test_case_wrapper[@]}" out/debug/standalone/chip-tool tests "$i" "$node_id" "$delay" | tee "$chip_tool_log_file"
${tool_run_prefix} "${test_case_wrapper[@]}" out/debug/standalone/chip-tool tests "$i" "$node_id" "$delay" | tee "$chip_tool_log_file"
# Prevent cleanup trying to kill a process we already killed.
temp_background_pid=$background_pid
background_pid=0
Expand Down
9 changes: 4 additions & 5 deletions src/lib/dnssd/Resolver_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ CHIP_ERROR MinMdnsResolver::SendQuery(mdns::Minimal::FullQName qname, mdns::Mini

mdns::Minimal::Query query(qname);
query.SetType(type).SetClass(mdns::Minimal::QClass::IN);
// TODO(cecille): Not sure why unicast response isn't working - fix.
query.SetAnswerViaUnicast(false);
query.SetAnswerViaUnicast(true);

builder.AddQuery(query);

Expand Down Expand Up @@ -555,9 +554,9 @@ CHIP_ERROR MinMdnsResolver::SendPendingResolveQueries()
Query query(instanceQName);

query
.SetClass(QClass::IN) //
.SetType(QType::ANY) //
.SetAnswerViaUnicast(false) //
.SetClass(QClass::IN) //
.SetType(QType::ANY) //
.SetAnswerViaUnicast(true) //
;

// NOTE: type above is NOT A or AAAA because the name searched for is
Expand Down