From ff7df2e716f3361ccad420d7cffa5c580e28b248 Mon Sep 17 00:00:00 2001 From: hnnajh <72513572+hnnajh@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:21:47 -0700 Subject: [PATCH] Plumb Peer DNS-SD advertisement for TCP support into SessionSetup context #30392 (#33481) * Plumb Peer DNS-SD advertisement for TCP support into SessionSetup context * Restyled by clang-format * Fix unit tests * Fix build error * address Boris comments * reflect mdns tcp support in session estabishment * Restyled by clang-format * Update src/app/OperationalSessionSetup.cpp Co-authored-by: Boris Zbarsky * Update src/app/OperationalSessionSetup.cpp Co-authored-by: Boris Zbarsky * fixing minor comments * Restyled by clang-format * add an extra check on tcp support * Restyled by clang-format * add a check on tcp server enablement * add peer info in log * Restyled by clang-format * update log message --------- Co-authored-by: Restyled.io Co-authored-by: Boris Zbarsky --- .../commands/common/RemoteDataModelLogger.cpp | 3 +- .../chip-tool/commands/discover/Commands.h | 3 +- .../commands/common/RemoteDataModelLogger.cpp | 3 +- .../clusters/discovery_commands.py | 3 +- src/app/OperationalSessionSetup.cpp | 29 +++- src/app/OperationalSessionSetup.h | 4 +- ...issionableNodeController-ScriptBinding.cpp | 4 +- .../python/ChipDeviceController-Discovery.cpp | 4 +- .../python/chip/discovery/__init__.py | 3 +- src/controller/python/chip/yaml/runner.py | 3 +- src/lib/address_resolve/AddressResolve.h | 3 +- .../AddressResolve_DefaultImpl.cpp | 5 +- src/lib/address_resolve/tool.cpp | 3 +- src/lib/dnssd/TxtFields.cpp | 11 +- src/lib/dnssd/Types.h | 9 +- .../dnssd/tests/TestIncrementalResolve.cpp | 6 +- src/lib/dnssd/tests/TestTxtFields.cpp | 153 +++++++++++++++--- src/lib/shell/commands/Dns.cpp | 7 +- src/tracing/json/json_tracing.cpp | 5 +- 19 files changed, 205 insertions(+), 56 deletions(-) diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index 9e4f29c5534757..294673512882b3 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp @@ -241,7 +241,8 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat value["rotatingIdLen"] = static_cast(commissionData.rotatingIdLen); value["pairingHint"] = commissionData.pairingHint; value["pairingInstruction"] = commissionData.pairingInstruction; - value["supportsTcp"] = resolutionData.supportsTcp; + value["supportsTcpClient"] = resolutionData.supportsTcpClient; + value["supportsTcpServer"] = resolutionData.supportsTcpServer; value["port"] = resolutionData.port; value["numIPs"] = static_cast(resolutionData.numIPs); diff --git a/examples/chip-tool/commands/discover/Commands.h b/examples/chip-tool/commands/discover/Commands.h index e7a59dbaee9110..d308d4ab75b430 100644 --- a/examples/chip-tool/commands/discover/Commands.h +++ b/examples/chip-tool/commands/discover/Commands.h @@ -53,7 +53,8 @@ class Resolve : public DiscoverCommand, public chip::AddressResolve::NodeListene result.mrpRemoteConfig.mIdleRetransTimeout.count()); ChipLogProgress(chipTool, " MRP retry interval (active): %" PRIu32 "ms", result.mrpRemoteConfig.mActiveRetransTimeout.count()); - ChipLogProgress(chipTool, " Supports TCP: %s", result.supportsTcp ? "yes" : "no"); + ChipLogProgress(chipTool, " Supports TCP Client: %s", result.supportsTcpClient ? "yes" : "no"); + ChipLogProgress(chipTool, " Supports TCP Server: %s", result.supportsTcpServer ? "yes" : "no"); ChipLogProgress(chipTool, " ICD is operating as: %s", result.isICDOperatingAsLIT ? "LIT" : "SIT"); SetCommandExitStatus(CHIP_NO_ERROR); } diff --git a/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp b/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp index c8e9d5a5450703..6334d42506d53f 100644 --- a/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp +++ b/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp @@ -241,7 +241,8 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat value["rotatingIdLen"] = static_cast(commissionData.rotatingIdLen); value["pairingHint"] = commissionData.pairingHint; value["pairingInstruction"] = commissionData.pairingInstruction; - value["supportsTcp"] = resolutionData.supportsTcp; + value["supportsTcpClient"] = resolutionData.supportsTcpClient; + value["supportsTcpServer"] = resolutionData.supportsTcpServer; value["port"] = resolutionData.port; value["numIPs"] = static_cast(resolutionData.numIPs); diff --git a/scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/clusters/discovery_commands.py b/scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/clusters/discovery_commands.py index 17fa4f31e96a48..5cfcb6087cbddb 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/clusters/discovery_commands.py +++ b/scripts/py_matter_yamltests/matter_yamltests/pseudo_clusters/clusters/discovery_commands.py @@ -68,7 +68,8 @@ - + + diff --git a/src/app/OperationalSessionSetup.cpp b/src/app/OperationalSessionSetup.cpp index 5b2f00ed0a3798..156003dec8ffd5 100644 --- a/src/app/OperationalSessionSetup.cpp +++ b/src/app/OperationalSessionSetup.cpp @@ -197,8 +197,10 @@ void OperationalSessionSetup::Connect(Callback::Callback * on Connect(onConnection, nullptr, onSetupFailure, transportPayloadCapability); } -void OperationalSessionSetup::UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config) +void OperationalSessionSetup::UpdateDeviceData(const ResolveResult & result) { + auto & config = result.mrpRemoteConfig; + auto addr = result.address; #if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES // Make sure to clear out our reason for trying the next result first thing, // so it does not stick around in various error cases. @@ -248,7 +250,7 @@ void OperationalSessionSetup::UpdateDeviceData(const Transport::PeerAddress & ad return; } - CHIP_ERROR err = EstablishConnection(config); + CHIP_ERROR err = EstablishConnection(result); LogErrorOnFailure(err); if (err == CHIP_NO_ERROR) { @@ -292,15 +294,26 @@ void OperationalSessionSetup::UpdateDeviceData(const Transport::PeerAddress & ad // Do not touch `this` instance anymore; it has been destroyed in DequeueConnectionCallbacks. } -CHIP_ERROR OperationalSessionSetup::EstablishConnection(const ReliableMessageProtocolConfig & config) +CHIP_ERROR OperationalSessionSetup::EstablishConnection(const ResolveResult & result) { + auto & config = result.mrpRemoteConfig; #if INET_CONFIG_ENABLE_TCP_ENDPOINT - // TODO: Combine LargePayload flag with DNS-SD advertisements from peer. - // Issue #32348. if (mTransportPayloadCapability == TransportPayloadCapability::kLargePayload) { - // Set the transport type for carrying large payloads - mDeviceAddress.SetTransportType(chip::Transport::Type::kTcp); + if (result.supportsTcpServer) + { + // Set the transport type for carrying large payloads + mDeviceAddress.SetTransportType(chip::Transport::Type::kTcp); + } + else + { + // we should not set the large payload while the TCP support is not enabled + ChipLogError( + Discovery, + "LargePayload session requested but peer does not support TCP server, PeerNodeId=" ChipLogFormatScopedNodeId, + ChipLogValueScopedNodeId(mPeerId)); + return CHIP_ERROR_INTERNAL; + } } #endif @@ -627,7 +640,7 @@ void OperationalSessionSetup::PerformAddressUpdate() void OperationalSessionSetup::OnNodeAddressResolved(const PeerId & peerId, const ResolveResult & result) { - UpdateDeviceData(result.address, result.mrpRemoteConfig); + UpdateDeviceData(result); } void OperationalSessionSetup::OnNodeAddressResolutionFailed(const PeerId & peerId, CHIP_ERROR reason) diff --git a/src/app/OperationalSessionSetup.h b/src/app/OperationalSessionSetup.h index 508c778923fd49..343ce77b2ba37f 100644 --- a/src/app/OperationalSessionSetup.h +++ b/src/app/OperationalSessionSetup.h @@ -347,7 +347,7 @@ class DLL_EXPORT OperationalSessionSetup : public SessionEstablishmentDelegate, void MoveToState(State aTargetState); - CHIP_ERROR EstablishConnection(const ReliableMessageProtocolConfig & config); + CHIP_ERROR EstablishConnection(const AddressResolve::ResolveResult & result); /* * This checks to see if an existing CASE session exists to the peer within the SessionManager @@ -419,7 +419,7 @@ class DLL_EXPORT OperationalSessionSetup : public SessionEstablishmentDelegate, /** * This function will set new IP address, port and MRP retransmission intervals of the device. */ - void UpdateDeviceData(const Transport::PeerAddress & addr, const ReliableMessageProtocolConfig & config); + void UpdateDeviceData(const AddressResolve::ResolveResult & result); #if CHIP_DEVICE_CONFIG_ENABLE_AUTOMATIC_CASE_RETRIES /** diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index 157789f5d64136..806bd5b5bb8be4 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -117,7 +117,9 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( { ChipLogProgress(Discovery, "\tMrp Interval active\tNot present"); } - ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); + + ChipLogProgress(Discovery, "\tSupports TCP Client\t\t%d", dnsSdInfo->supportsTcpClient); + ChipLogProgress(Discovery, "\tSupports TCP Server\t\t%d", dnsSdInfo->supportsTcpServer); if (dnsSdInfo->isICDOperatingAsLIT.has_value()) { diff --git a/src/controller/python/ChipDeviceController-Discovery.cpp b/src/controller/python/ChipDeviceController-Discovery.cpp index 46f0729d61243c..7c669603f4ff1d 100644 --- a/src/controller/python/ChipDeviceController-Discovery.cpp +++ b/src/controller/python/ChipDeviceController-Discovery.cpp @@ -142,7 +142,9 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De { jsonVal["mrpRetryActiveThreshold"] = activeThreshold->count(); } - jsonVal["supportsTcp"] = dnsSdInfo->supportsTcp; + + jsonVal["supportsTcpClient"] = dnsSdInfo->supportsTcpClient; + jsonVal["supportsTcpServer"] = dnsSdInfo->supportsTcpServer; { Json::Value addresses; for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) diff --git a/src/controller/python/chip/discovery/__init__.py b/src/controller/python/chip/discovery/__init__.py index a25fb490007824..c818b5e22358ac 100644 --- a/src/controller/python/chip/discovery/__init__.py +++ b/src/controller/python/chip/discovery/__init__.py @@ -92,7 +92,8 @@ class CommissionableNode(): mrpRetryIntervalIdle: int = None mrpRetryIntervalActive: int = None mrpRetryActiveThreshold: int = None - supportsTcp: bool = None + supportsTcpClient: bool = None + supportsTcpServer: bool = None isICDOperatingAsLIT: bool = None addresses: List[str] = None rotatingId: Optional[str] = None diff --git a/src/controller/python/chip/yaml/runner.py b/src/controller/python/chip/yaml/runner.py index 3081dad6248fa9..494e6f964aa33f 100644 --- a/src/controller/python/chip/yaml/runner.py +++ b/src/controller/python/chip/yaml/runner.py @@ -913,7 +913,8 @@ def decode(self, result: _ActionResult): 'mrpRetryIntervalIdle': response.mrpRetryIntervalIdle, 'mrpRetryIntervalActive': response.mrpRetryIntervalActive, 'mrpRetryActiveThreshold': response.mrpRetryActiveThreshold, - 'supportsTcp': response.supportsTcp, + 'supportsTcpClient': response.supportsTcpClient, + 'supportsTcpServer': response.supportsTcpServer, 'isICDOperatingAsLIT': response.isICDOperatingAsLIT, 'addresses': response.addresses, 'rotatingId': response.rotatingId, diff --git a/src/lib/address_resolve/AddressResolve.h b/src/lib/address_resolve/AddressResolve.h index 7dffeed01ed1d8..0d6f8ab719519d 100644 --- a/src/lib/address_resolve/AddressResolve.h +++ b/src/lib/address_resolve/AddressResolve.h @@ -33,7 +33,8 @@ struct ResolveResult { Transport::PeerAddress address; ReliableMessageProtocolConfig mrpRemoteConfig; - bool supportsTcp = false; + bool supportsTcpServer = false; + bool supportsTcpClient = false; bool isICDOperatingAsLIT = false; ResolveResult() : address(Transport::Type::kUdp), mrpRemoteConfig(GetDefaultMRPConfig()) {} diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 5a9651ff76ba3d..e10146f4669793 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -287,8 +287,9 @@ void Resolver::OnOperationalNodeResolved(const Dnssd::ResolvedNodeData & nodeDat result.address.SetPort(nodeData.resolutionData.port); result.address.SetInterface(nodeData.resolutionData.interfaceId); - result.mrpRemoteConfig = nodeData.resolutionData.GetRemoteMRPConfig(); - result.supportsTcp = nodeData.resolutionData.supportsTcp; + result.mrpRemoteConfig = nodeData.resolutionData.GetRemoteMRPConfig(); + result.supportsTcpClient = nodeData.resolutionData.supportsTcpClient; + result.supportsTcpServer = nodeData.resolutionData.supportsTcpServer; if (nodeData.resolutionData.isICDOperatingAsLIT.has_value()) { diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index 8423649ca928a0..53d01b4011806f 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -56,7 +56,8 @@ class PrintOutNodeListener : public chip::AddressResolve::NodeListener result.address.ToString(addr_string); ChipLogProgress(Discovery, "Resolve completed: %s", addr_string); - ChipLogProgress(Discovery, " Supports TCP: %s", result.supportsTcp ? "YES" : "NO"); + ChipLogProgress(Discovery, " Supports TCP Client: %s", result.supportsTcpClient ? "YES" : "NO"); + ChipLogProgress(Discovery, " Supports TCP Server: %s", result.supportsTcpServer ? "YES" : "NO"); ChipLogProgress(Discovery, " MRP IDLE retransmit timeout: %u ms", result.mrpRemoteConfig.mIdleRetransTimeout.count()); ChipLogProgress(Discovery, " MRP ACTIVE retransmit timeout: %u ms", result.mrpRemoteConfig.mActiveRetransTimeout.count()); ChipLogProgress(Discovery, " MRP ACTIVE Threshold time: %u ms", result.mrpRemoteConfig.mActiveThresholdTime.count()); diff --git a/src/lib/dnssd/TxtFields.cpp b/src/lib/dnssd/TxtFields.cpp index 6ac2cfa19e8ece..20ca450b8734b5 100644 --- a/src/lib/dnssd/TxtFields.cpp +++ b/src/lib/dnssd/TxtFields.cpp @@ -38,6 +38,9 @@ namespace Dnssd { namespace Internal { +constexpr uint8_t kTCPClient = 1; +constexpr uint8_t kTCPServer = 2; + namespace { char SafeToLower(uint8_t ch) @@ -276,9 +279,13 @@ void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, CommonRes case TxtFieldKey::kSessionActiveThreshold: nodeData.mrpRetryActiveThreshold = Internal::GetRetryActiveThreshold(value); break; - case TxtFieldKey::kTcpSupported: - nodeData.supportsTcp = Internal::MakeBoolFromAsciiDecimal(value); + case TxtFieldKey::kTcpSupported: { + // bit 0 is reserved and deprecated + uint8_t support = Internal::MakeU8FromAsciiDecimal(value); + nodeData.supportsTcpClient = (support & (1 << Internal::kTCPClient)) != 0; + nodeData.supportsTcpServer = (support & (1 << Internal::kTCPServer)) != 0; break; + } case TxtFieldKey::kLongIdleTimeICD: nodeData.isICDOperatingAsLIT = Internal::MakeOptionalBoolFromAsciiDecimal(value); break; diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index 1b9b19c0ad1bcc..60a265e46e425e 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -90,7 +90,8 @@ struct CommonResolutionData uint16_t port = 0; char hostName[kHostNameMaxLength + 1] = {}; - bool supportsTcp = false; + bool supportsTcpClient = false; + bool supportsTcpServer = false; std::optional isICDOperatingAsLIT; std::optional mrpRetryIntervalIdle; std::optional mrpRetryIntervalActive; @@ -131,7 +132,8 @@ struct CommonResolutionData isICDOperatingAsLIT = std::nullopt; numIPs = 0; port = 0; - supportsTcp = false; + supportsTcpClient = false; + supportsTcpServer = false; interfaceId = Inet::InterfaceId::Null(); for (auto & addr : ipAddress) { @@ -181,7 +183,8 @@ struct CommonResolutionData { ChipLogDetail(Discovery, "\tMrp Active Threshold: not present"); } - ChipLogDetail(Discovery, "\tTCP Supported: %d", supportsTcp); + ChipLogDetail(Discovery, "\tTCP Client Supported: %d", supportsTcpClient); + ChipLogDetail(Discovery, "\tTCP Server Supported: %d", supportsTcpServer); if (isICDOperatingAsLIT.has_value()) { ChipLogDetail(Discovery, "\tThe ICD operates in %s", *isICDOperatingAsLIT ? "LIT" : "SIT"); diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp index 053d0dd96856ee..88e183b91ce2bb 100644 --- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp +++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp @@ -308,7 +308,8 @@ TEST(TestIncrementalResolve, TestParseOperational) EXPECT_FALSE(nodeData.operationalData.hasZeroTTL); EXPECT_EQ(nodeData.resolutionData.numIPs, 1u); EXPECT_EQ(nodeData.resolutionData.port, 0x1234); - EXPECT_FALSE(nodeData.resolutionData.supportsTcp); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle(), std::make_optional(chip::System::Clock::Milliseconds32(23))); @@ -396,7 +397,8 @@ TEST(TestIncrementalResolve, TestParseCommissionable) // validate data as it was passed in EXPECT_EQ(nodeData.numIPs, 2u); EXPECT_EQ(nodeData.port, 0x1234); - EXPECT_FALSE(nodeData.supportsTcp); + EXPECT_FALSE(nodeData.supportsTcpClient); + EXPECT_FALSE(nodeData.supportsTcpServer); EXPECT_EQ(nodeData.GetMrpRetryIntervalActive(), std::make_optional(chip::System::Clock::Milliseconds32(321))); EXPECT_FALSE(nodeData.GetMrpRetryIntervalIdle().has_value()); diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index b80f1c0682ef32..873ce0bc4eb6f0 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -306,7 +306,8 @@ bool NodeDataIsEmpty(const CommissionNodeData & node) if (node.longDiscriminator != 0 || node.vendorId != 0 || node.productId != 0 || node.commissioningMode != 0 || node.deviceType != 0 || node.rotatingIdLen != 0 || node.pairingHint != 0 || node.mrpRetryIntervalIdle.has_value() || node.mrpRetryIntervalActive.has_value() || node.mrpRetryActiveThreshold.has_value() || - node.isICDOperatingAsLIT.has_value() || node.supportsTcp || node.supportsCommissionerGeneratedPasscode != 0) + node.isICDOperatingAsLIT.has_value() || node.supportsTcpServer || node.supportsTcpClient || + node.supportsCommissionerGeneratedPasscode != 0) { return false; } @@ -412,8 +413,8 @@ bool NodeDataIsEmpty(const ResolvedNodeData & nodeData) { return nodeData.operationalData.peerId == PeerId{} && nodeData.resolutionData.numIPs == 0 && nodeData.resolutionData.port == 0 && !nodeData.resolutionData.mrpRetryIntervalIdle.has_value() && - !nodeData.resolutionData.mrpRetryIntervalActive.has_value() && !nodeData.resolutionData.supportsTcp && - !nodeData.resolutionData.isICDOperatingAsLIT.has_value(); + !nodeData.resolutionData.mrpRetryIntervalActive.has_value() && !nodeData.resolutionData.supportsTcpClient && + !nodeData.resolutionData.supportsTcpServer && !nodeData.resolutionData.isICDOperatingAsLIT.has_value(); } void ResetRetryIntervalIdle(DiscoveredNodeData & nodeData) @@ -644,27 +645,80 @@ void DiscoveredTxtFieldTcpSupport() nodeData.Set(); CommonResolutionData & resolutionData = nodeData.Get(); - // True + // Neither TCP Client nor TCP Server are enabled + strcpy(key, "T"); + strcpy(val, "0"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_FALSE(nodeData.Get().supportsTcpServer); + EXPECT_FALSE(nodeData.Get().supportsTcpClient); + + // Neither TCP Client nor TCP Server are enabled - ignoring first bit strcpy(key, "T"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().supportsTcp); + EXPECT_FALSE(nodeData.Get().supportsTcpServer); + EXPECT_FALSE(nodeData.Get().supportsTcpClient); - // Test no other fields were populated - nodeData.Get().supportsTcp = false; - EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); + // Supporting TCP Client only + strcpy(key, "T"); + strcpy(val, "2"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_TRUE(nodeData.Get().supportsTcpClient); + EXPECT_FALSE(nodeData.Get().supportsTcpServer); - // False + // Supporting TCP Client only - ignoring first bit strcpy(key, "T"); - strcpy(val, "0"); + strcpy(val, "3"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().supportsTcp == false); + EXPECT_TRUE(nodeData.Get().supportsTcpClient); + EXPECT_FALSE(nodeData.Get().supportsTcpServer); - // Invalid value, stil false + // Supporting TCP Server only + strcpy(key, "T"); + strcpy(val, "4"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_FALSE(nodeData.Get().supportsTcpClient); + EXPECT_TRUE(nodeData.Get().supportsTcpServer); + + // Supporting TCP Server only - ignoring first bit + strcpy(key, "T"); + strcpy(val, "5"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_FALSE(nodeData.Get().supportsTcpClient); + EXPECT_TRUE(nodeData.Get().supportsTcpServer); + + // Supporting TCP Server and Client + strcpy(key, "T"); + strcpy(val, "6"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_TRUE(nodeData.Get().supportsTcpClient); + EXPECT_TRUE(nodeData.Get().supportsTcpServer); + + // Supporting TCP Server and Client - ignoring first bit + strcpy(key, "T"); + strcpy(val, "7"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_TRUE(nodeData.Get().supportsTcpClient); + EXPECT_TRUE(nodeData.Get().supportsTcpServer); + + // Invalid value, means neither TCP Client or Server are enabled + strcpy(key, "T"); + strcpy(val, "8"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); + EXPECT_FALSE(nodeData.Get().supportsTcpClient); + EXPECT_FALSE(nodeData.Get().supportsTcpServer); + + // Invalid value, means neither TCP Client or Server are enabled strcpy(key, "T"); strcpy(val, "asdf"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().supportsTcp == false); + EXPECT_FALSE(nodeData.Get().supportsTcpClient); + EXPECT_FALSE(nodeData.Get().supportsTcpServer); + + // Test no other fields were populated + nodeData.Get().supportsTcpClient = false; + nodeData.Get().supportsTcpServer = false; + EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); } // Test ICD (ICD operation Mode) @@ -979,27 +1033,80 @@ void TxtFieldTcpSupport() char val[8]; NodeData nodeData; - // True + // Neither TCP Client nor TCP Server are enabled + strcpy(key, "T"); + strcpy(val, "0"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); + + // Neither TCP Client nor TCP Server are enabled - ignoring first bit strcpy(key, "T"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.supportsTcp); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); - // Test no other fields were populated - nodeData.resolutionData.supportsTcp = false; - EXPECT_TRUE(NodeDataIsEmpty(nodeData)); + // Supporting TCP Client only + strcpy(key, "T"); + strcpy(val, "2"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpClient); - // False + // Supporting TCP Client only - ignoring first bit strcpy(key, "T"); - strcpy(val, "0"); + strcpy(val, "3"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_EQ(nodeData.resolutionData.supportsTcp, false); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpClient); - // Invalid value, stil false + // Supporting TCP Server only + strcpy(key, "T"); + strcpy(val, "4"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpServer); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); + + // Supporting TCP Server only - ignoring first bit + strcpy(key, "T"); + strcpy(val, "5"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpServer); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); + + // Supporting TCP Server and Client + strcpy(key, "T"); + strcpy(val, "6"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpServer); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpClient); + + // Supporting TCP Server and Client - ignoring first bit + strcpy(key, "T"); + strcpy(val, "7"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpServer); + EXPECT_TRUE(nodeData.resolutionData.supportsTcpClient); + + // Invalid value, means neither TCP Client or Server are enabled + strcpy(key, "T"); + strcpy(val, "8"); + FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + + // Invalid value, means neither TCP Client or Server are enabled strcpy(key, "T"); strcpy(val, "asdf"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_EQ(nodeData.resolutionData.supportsTcp, false); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpClient); + EXPECT_FALSE(nodeData.resolutionData.supportsTcpServer); + + // Test no other fields were populated + nodeData.resolutionData.supportsTcpServer = false; + nodeData.resolutionData.supportsTcpClient = false; + EXPECT_TRUE(NodeDataIsEmpty(nodeData)); } TEST(TestTxtFields, TxtDiscoveredFieldTcpSupport) diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 50be591ddfeaee..2c7cc02c7a54b2 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -51,7 +51,8 @@ class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public Addr result.address.ToString(addr_string); streamer_printf(streamer_get(), "Resolve completed: %s\r\n", addr_string); - streamer_printf(streamer_get(), " Supports TCP: %s\r\n", result.supportsTcp ? "YES" : "NO"); + streamer_printf(streamer_get(), " Supports TCP Client: %s\r\n", result.supportsTcpClient ? "YES" : "NO"); + streamer_printf(streamer_get(), " Supports TCP Server: %s\r\n", result.supportsTcpServer ? "YES" : "NO"); streamer_printf(streamer_get(), " MRP IDLE retransmit timeout: %u ms\r\n", result.mrpRemoteConfig.mIdleRetransTimeout.count()); streamer_printf(streamer_get(), " MRP ACTIVE retransmit timeout: %u ms\r\n", @@ -134,7 +135,9 @@ class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public Addr { streamer_printf(streamer_get(), " MRP retry active threshold time: %" PRIu32 "ms\r\n", *activeThreshold); } - streamer_printf(streamer_get(), " Supports TCP: %s\r\n", nodeData.supportsTcp ? "yes" : "no"); + + streamer_printf(streamer_get(), " Supports TCP Client: %s\r\n", nodeData.supportsTcpClient ? "yes" : "no"); + streamer_printf(streamer_get(), " Supports TCP Server: %s\r\n", nodeData.supportsTcpServer ? "yes" : "no"); if (nodeData.isICDOperatingAsLIT.has_value()) { diff --git a/src/tracing/json/json_tracing.cpp b/src/tracing/json/json_tracing.cpp index 91b4474388ecd0..4531740b81a193 100644 --- a/src/tracing/json/json_tracing.cpp +++ b/src/tracing/json/json_tracing.cpp @@ -418,8 +418,9 @@ void JsonBackend::LogNodeDiscovered(NodeDiscoveredInfo & info) info.result->address.ToString(address_buff); - result["supports_tcp"] = info.result->supportsTcp; - result["address"] = address_buff; + result["supports_tcp_client"] = info.result->supportsTcpClient; + result["supports_tcp_server"] = info.result->supportsTcpServer; + result["address"] = address_buff; result["mrp"]["idle_retransmit_timeout_ms"] = info.result->mrpRemoteConfig.mIdleRetransTimeout.count(); result["mrp"]["active_retransmit_timeout_ms"] = info.result->mrpRemoteConfig.mActiveRetransTimeout.count();