-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Updates MdnsDiscovery class and affected test scripts to address issues #39737
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
base: master
Are you sure you want to change the base?
Updates MdnsDiscovery class and affected test scripts to address issues #39737
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request updates the mdns class and TC-SC-4.3 test case. The changes include adding new methods for retrieving SRV, TXT, and AAAA records, improving error handling, and refactoring some of the existing code. The code review identified opportunities to improve error handling, logging, and documentation.
PR #39737: Size comparison from 41c7192 to 796d6ec Full report (3 builds for cc32xx, stm32)
|
PR #39737: Size comparison from 06523c2 to 1ec8aa9 Full report (71 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
PR #39737: Size comparison from e3d8447 to 613631c Full report (71 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
PR #39737: Size comparison from 1c3303e to 4e11744 Full report (57 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
PR #39737: Size comparison from 1c3303e to 1fbfb65 Full report (57 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
…aming convention alignment
PR #39737: Size comparison from da00cfb to be87f70 Full report (4 builds for cc32xx, nrfconnect, stm32)
|
PR #39737: Size comparison from da00cfb to aa8ce10 Full report (57 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
PR #39737: Size comparison from da00cfb to f6f089c Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, stm32, telink)
|
logger.info(f"Service record information lookup {rec_types} for '{service_name}' in progress...") | ||
await wait_for(service_listener.updated_event.wait(), SERVICE_LISTENER_TIMEOUT_SEC) | ||
except TimeoutError: | ||
logger.info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code eats the TimeoutError and turns it into a log. It seems like this should be raised since you won't have service info in the call below if this timed out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would ultimately change the return type of for example get_srv_record
which is Optional[MdnsServiceInfo]
, at the moment it returns None, by design.
Failing the test because of not finding a particular service (weather expected or unexpected) is handled by each test script as needed.
So it should stay as is IMO.
A service listener required during mDNS service discovery | ||
""" | ||
|
||
def __init__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you put that as a method on this class so it's clear how callers are intended to use this? Right now it's totally not clear.
|
||
|
||
@dataclass | ||
class SpecialAddressTypes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added clarifying comments to the class
@dataclass
class SpecialAddressTypes:
"""
Represents special categories of IPv6 addresses that can be derived
from or mapped to IPv4. Used to identify and annotate IPv6 addresses
with special handling or semantics.
"""
# IPv6 address derived from a Teredo tunnel (2001::/32 range).
# Used for NAT traversal — wraps IPv4 inside IPv6.
teredo: Optional[str]
# IPv6 address derived from 6to4 tunneling (2002::/16 range).
# Automatically maps an IPv4 into an IPv6 address.
sixtofour: Optional[str]
# Whether the address falls into a reserved IPv6 block
# (e.g., ::/128, ::1/128, ::ffff:0:0/96, etc.).
is_reserved: bool
# An IPv6 address that is explicitly mapped to an IPv4 address
# (::ffff:0:0/96 prefix). Example: ::ffff:192.0.2.128
ipv4_mapped: Optional[str]
To answer the question directly, at the moment those properties aren't being used. But they are part of what is returned by the original ZeroconfIPv6Address object, the quada class groups some of those togetger for easier handling.
This is an example logging of a quada query response:
{
"00155D5436BF.local.": [
{
"address": "fe80::215:5dff:fe54:36bf",
"version": 6,
"interface": "eth0",
"type_info": {
"is_global": false,
"is_link_local": true,
"is_loopback": false,
"is_multicast": false
},
"special_types": {
"teredo": null,
"sixtofour": null,
"is_reserved": false,
"ipv4_mapped": null
},
"meta": {
"max_prefixlen": 128,
"packed": "fe8000000000000002155dfffe5436bf"
}
}
]
}
Spec: | ||
https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/secure_channel/Discovery.adoc#21-operational-instance-name | ||
""" | ||
consts = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while to figure out why you were doing it like this, and I THINK the intent here is to be able to list multiple failure modes in one assert so testers can see all the things that are wrong. But because failed is getting overwritten every time, you don't actually get this behaviour. To make this work, you'd need to have failed start as an empty list and append to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, these functions are good candidates to have their own tests to show this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be addressed in a separate PR
Spec: | ||
https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/secure_channel/Discovery.adoc#16-txt-key-for-vendor-id-and-product-id-vp | ||
""" | ||
constraints = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the same as the above function with just a different name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes in that they both have the same constraints (Vendor ID and Product ID)
I created both so it's a clearer read when using them in test scripts
Do you suggest merging them?
Co-authored-by: C Freeman <cecille@google.com>
Testing
Main Fixes
PTR record info retrieval failure, #37154 and #524
AAAA record info retrieval failure and query request spamming
Ensures mDNS info isn't retrieved from cache
Ensures queries are sent over IPv6 only #536
Main updates
Individual Methods: Implemented individual methods per record type:
get_srv_record
,get_txt_record
,get_quada_records
,get_ptr_records
.Improved AAAA record handling: Switched previous AAAA record query code for Zeroconf out-of-box address resolver. Encapsulates AAAA record data into it's own
QuadaRecord
class.Improved PTR record handling: Removed service info querying for discovered instances since only the PTR info is required. Encapsulates the PTR record data into it's own
PtrRecord
class.Improved logging: Improved logging for
get_all_service_types
method #524Added new method:
get_commissionable_subtypes
Added asserts file: Contains assertions for TXT keys, instance/hostnames, service types, as per the spec. These can be reused wherever needed in the test scripts.
MdnsDiscovery class cross-updates: Updates
TC-SC-4.3
,TC-CADMIN-1.3.4
,TC-CADMIN-1.5
,TC-CADMIN-1.15
,TC-ICDM-5.1
, andcadmin_support.py
to matchMdnsDiscovery
class updates.Documentation
Added documentation for the MdnsDiscovery class to assist with PR review and help understand how the different components fit together, given the size and scope of the codebase.
This is the official documentation.
📃 MdnsDiscovery Class Documentation