Skip to content

Commit

Permalink
[Inet] Split off per-implementation parts of InetInterface
Browse files Browse the repository at this point in the history
#### Problem

Part of project-chip#7715 _Virtualize System and Inet interfaces_

#### Change overview

- Convert `InterfaceId`, which is relatively heavily used and stored,
  to be platform-independent. Platform-specific parts move to a
  namespace `PlaformNetworkInterface` (since this includes a type and
  compile-time constant, it can't practically be made an abstract class).
- Convert `InterfaceIterator` and `InterfaceAddressIterator` to use
  abstract base classes, for mockability. At present, the concrete
  implementation is fixed at compile time under the original name.
- Split the three implementations into separate files.

#### Testing

CI; no change to outside functionality.
  • Loading branch information
kpschoedel committed Jan 20, 2022
1 parent fd815cd commit ab0c41b
Show file tree
Hide file tree
Showing 35 changed files with 1,715 additions and 1,298 deletions.
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static bool ParseAddressWithInterface(const char * addressString, Command::Addre
{
struct sockaddr_in6 * addr = reinterpret_cast<struct sockaddr_in6 *>(result->ai_addr);
address->address = ::chip::Inet::IPAddress::FromSockAddr(*addr);
address->interfaceId = ::chip::Inet::InterfaceId(addr->sin6_scope_id);
address->interfaceId = ::chip::Inet::PlatformNetworkInterface::ToInterfaceId(addr->sin6_scope_id);
}
#if INET_CONFIG_ENABLE_IPV4
else if (result->ai_family == AF_INET)
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-mdns/AllInterfaceListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
return true; // not a usable interface
}

char name[chip::Inet::InterfaceId::kMaxIfNameLength];
char name[chip::Inet::PlatformNetworkInterface::kMaxNameLength];
if (mIterator.GetInterfaceName(name, sizeof(name)) != CHIP_NO_ERROR)
{
printf("!!!! FAILED TO GET INTERFACE NAME\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ReportDelegate : public mdns::Minimal::ServerDelegate
info->SrcAddress.ToString(addr, sizeof(addr));

char ifName[64];
VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR);
VerifyOrDie(Inet::PlatformNetworkInterface::GetInterfaceName(info->Interface, ifName, sizeof(ifName)) == CHIP_NO_ERROR);

printf("QUERY from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName);
Report("QUERY: ", data);
Expand All @@ -199,7 +199,7 @@ class ReportDelegate : public mdns::Minimal::ServerDelegate
info->SrcAddress.ToString(addr, sizeof(addr));

char ifName[64];
VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR);
VerifyOrDie(Inet::PlatformNetworkInterface::GetInterfaceName(info->Interface, ifName, sizeof(ifName)) == CHIP_NO_ERROR);

printf("RESPONSE from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName);
Report("RESPONSE: ", data);
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal-mdns/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ReplyDelegate : public mdns::Minimal::ServerDelegate, public mdns::Minimal
info->SrcAddress.ToString(addr, sizeof(addr));

char ifName[64];
VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR);
VerifyOrDie(Inet::PlatformNetworkInterface::GetInterfaceName(info->Interface, ifName, sizeof(ifName)) == CHIP_NO_ERROR);

printf("QUERY from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName);
Report("QUERY: ", data);
Expand All @@ -135,7 +135,7 @@ class ReplyDelegate : public mdns::Minimal::ServerDelegate, public mdns::Minimal
info->SrcAddress.ToString(addr, sizeof(addr));

char ifName[64];
VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR);
VerifyOrDie(Inet::PlatformNetworkInterface::GetInterfaceName(info->Interface, ifName, sizeof(ifName)) == CHIP_NO_ERROR);

printf("RESPONSE from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/discovery/NodeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PythonResolverDelegate : public ResolverDelegate
mSuccessCallback( //
nodeData.mPeerId.GetCompressedFabricId(), //
nodeData.mPeerId.GetNodeId(), //
nodeData.mInterfaceId.GetPlatformInterface(), //
Inet::PlatformNetworkInterface::FromInterfaceId(nodeData.mInterfaceId), //
nodeData.mAddress[0].ToString(ipAddressBuffer, sizeof(ipAddressBuffer)), //
nodeData.mPort //
);
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct ThreadMetrics : public app::Clusters::SoftwareDiagnostics::Structs::Threa

struct NetworkInterface : public app::Clusters::GeneralDiagnostics::Structs::NetworkInterfaceType::Type
{
char Name[Inet::InterfaceId::kMaxIfNameLength];
char Name[Inet::PlatformNetworkInterface::kMaxNameLength];
uint8_t MacAddress[kMaxHardwareAddrSize];
NetworkInterface * Next; /* Pointer to the next structure. */
};
Expand Down
27 changes: 26 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,37 @@ buildconfig_header("inet_buildconfig") {
[ "INET_PLATFORM_CONFIG_INCLUDE=${chip_inet_platform_config_include}" ]
}

defines += [ "INET_TCP_END_POINT_IMPL_CONFIG_FILE=<inet/TCPEndPointImpl${chip_system_config_inet}.h>" ]
defines += [
"INET_INTERFACE_IMPL_CONFIG_FILE=<inet/InetInterfaceImpl${chip_system_config_inet_interface}.h>",
"INET_TCP_END_POINT_IMPL_CONFIG_FILE=<inet/TCPEndPointImpl${chip_system_config_inet}.h>",
]
if (chip_system_config_use_open_thread_udp) {
defines += [
"INET_UDP_END_POINT_IMPL_CONFIG_FILE=<inet/UDPEndPointImpl_OpenThread.h>",
]
} else {
defines += [ "INET_UDP_END_POINT_IMPL_CONFIG_FILE=<inet/UDPEndPointImpl${chip_system_config_inet}.h>" ]
}

if (chip_system_config_inet_interface == "LwIP") {
defines += [
"CHIP_SYSTEM_CONFIG_USE_LWIP=1",
"CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS=0",
"CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF=0",
]
} else if (chip_system_config_inet_interface == "IFAddrs") {
defines += [
"CHIP_SYSTEM_CONFIG_USE_LWIP=0",
"CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS=1",
"CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF=0",
]
} else if (chip_system_config_inet_interface == "Zephyr") {
defines += [
"CHIP_SYSTEM_CONFIG_USE_LWIP=0",
"CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS=0",
"CHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF=1",
]
}
}

source_set("inet_config_header") {
Expand Down Expand Up @@ -97,6 +120,8 @@ static_library("inet") {
"InetFaultInjection.h",
"InetInterface.cpp",
"InetInterface.h",
"InetInterfaceImpl${chip_system_config_inet_interface}.cpp",
"InetInterfaceImpl${chip_system_config_inet_interface}.h",
"InetLayer.h",
"arpa-inet-compatibility.h",
]
Expand Down
Loading

0 comments on commit ab0c41b

Please sign in to comment.