Skip to content

Commit

Permalink
[Inet] Remove InetLayer class
Browse files Browse the repository at this point in the history
#### Problem

After PR project-chip#12291, `InetLayer` merely holds pointers to TCP and
UDP `EndPointManager`. Almost all uses are of `UDPEndPointManager`
only, so `InetLayer` is an unnecessary indirection.

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

#### Change overview

Remove the `InetLayer` class and pass or store `UDPEndPointManager`
and/or `TCPEndPointManager` directly.

(This was not included in project-chip#12291 because it touches a large number
of files with trivial changes.)

#### Testing

CI; no change to external functionality.
  • Loading branch information
kpschoedel committed Dec 7, 2021
1 parent 597a5e4 commit 7ab4af7
Show file tree
Hide file tree
Showing 72 changed files with 253 additions and 276 deletions.
2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class MdnsDebugListModel : public ActionListModel
private:
void DoReinit()
{
CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(&DeviceLayer::InetLayer());
CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(DeviceLayer::UDPEndPointManager());
if (err != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Error initializing: %s", err.AsString());
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/discover/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Resolve : public DiscoverCommand, public chip::Dnssd::ResolverDelegate
/////////// DiscoverCommand Interface /////////
CHIP_ERROR RunCommand(NodeId remoteId, uint64_t fabricId) override
{
ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(&chip::DeviceLayer::InetLayer()));
ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(chip::DeviceLayer::UDPEndPointManager()));
chip::Dnssd::Resolver::Instance().SetResolverDelegate(this);
ChipLogProgress(chipTool, "Dnssd: Searching for NodeId: %" PRIx64 " FabricId: %" PRIx64 " ...", remoteId, fabricId);
return chip::Dnssd::Resolver::Instance().ResolveNodeId(chip::PeerId().SetNodeId(remoteId).SetCompressedFabricId(fabricId),
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-mdns/advertiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int main(int argc, char ** args)
return 1;
}

if (chip::Dnssd::ServiceAdvertiser::Instance().Init(&DeviceLayer::InetLayer()) != CHIP_NO_ERROR)
if (chip::Dnssd::ServiceAdvertiser::Instance().Init(DeviceLayer::UDPEndPointManager()) != CHIP_NO_ERROR)
{
fprintf(stderr, "FAILED to start MDNS advertisement\n");
return 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ int main(int argc, char ** args)

MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4);

err = mdnsServer.Listen(&chip::DeviceLayer::InetLayer(), &allInterfaces, gOptions.listenPort);
err = mdnsServer.Listen(chip::DeviceLayer::UDPEndPointManager(), &allInterfaces, gOptions.listenPort);
if (err != CHIP_NO_ERROR)
{
printf("Server failed to listen on all interfaces: %s\n", chip::ErrorStr(err));
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-mdns/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int main(int argc, char ** args)
{
MdnsExample::AllInterfaces allInterfaces(gOptions.enableIpV4);

if (mdnsServer.Listen(&DeviceLayer::InetLayer(), &allInterfaces, gOptions.listenPort) != CHIP_NO_ERROR)
if (mdnsServer.Listen(DeviceLayer::UDPEndPointManager(), &allInterfaces, gOptions.listenPort) != CHIP_NO_ERROR)
{
printf("Server failed to listen on all interfaces\n");
return 1;
Expand Down
4 changes: 2 additions & 2 deletions examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ void StartPinging(streamer_t * stream, char * destination)
}

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
err = gTCPManager.Init(Transport::TcpListenParameters(&DeviceLayer::InetLayer())
err = gTCPManager.Init(Transport::TcpListenParameters(DeviceLayer::TCPEndPointManager())
.SetAddressType(gDestAddr.Type())
.SetListenPort(gPingArguments.GetEchoPort() + 1));
VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init TCP manager error: %s\n", ErrorStr(err)));
#endif

err = gUDPManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer())
err = gUDPManager.Init(Transport::UdpListenParameters(DeviceLayer::UDPEndPointManager())
.SetAddressType(gDestAddr.Type())
.SetListenPort(gPingArguments.GetEchoPort() + 1));
VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init UDP manager error: %s\n", ErrorStr(err)));
Expand Down
4 changes: 2 additions & 2 deletions examples/shell/shell_common/cmd_send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ void ProcessCommand(streamer_t * stream, char * destination)
}

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
err = gTCPManager.Init(Transport::TcpListenParameters(&DeviceLayer::InetLayer())
err = gTCPManager.Init(Transport::TcpListenParameters(DeviceLayer::TCPEndPointManager())
.SetAddressType(gDestAddr.Type())
.SetListenPort(gSendArguments.GetPort() + 1));
VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init TCP manager error: %s\n", ErrorStr(err)));
#endif

err = gUDPManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer())
err = gUDPManager.Init(Transport::UdpListenParameters(DeviceLayer::UDPEndPointManager())
.SetAddressType(gDestAddr.Type())
.SetListenPort(gSendArguments.GetPort() + 1));
VerifyOrExit(err == CHIP_NO_ERROR, streamer_printf(stream, "Failed to init UDP manager error: %s\n", ErrorStr(err)));
Expand Down
4 changes: 2 additions & 2 deletions src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool DnssdServer::OnExpiration(System::Clock::Timestamp expirationMs)

ChipLogDetail(Discovery, "OnExpiration - valid time out");

CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(&chip::DeviceLayer::InetLayer());
CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(chip::DeviceLayer::UDPEndPointManager());
if (err != CHIP_NO_ERROR)
{
ChipLogError(Discovery, "Failed to initialize advertiser: %s", chip::ErrorStr(err));
Expand Down Expand Up @@ -410,7 +410,7 @@ void DnssdServer::StartServer(chip::Dnssd::CommissioningMode mode)

DeviceLayer::PlatformMgr().AddEventHandler(OnPlatformEventWrapper, 0);

CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(&chip::DeviceLayer::InetLayer());
CHIP_ERROR err = Dnssd::ServiceAdvertiser::Instance().Init(chip::DeviceLayer::UDPEndPointManager());
if (err != CHIP_NO_ERROR)
{
ChipLogError(Discovery, "Failed to initialize advertiser: %s", chip::ErrorStr(err));
Expand Down
16 changes: 9 additions & 7 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <ble/BLEEndPoint.h>
#include <inet/IPAddress.h>
#include <inet/InetError.h>
#include <inet/InetLayer.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/dnssd/Advertiser.h>
#include <lib/dnssd/ServiceNaming.h>
Expand Down Expand Up @@ -99,16 +98,19 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
SetGroupDataProvider(&mGroupsProvider);

// Init transport before operations with secure session mgr.
err = mTransports.Init(
UdpListenParameters(&DeviceLayer::InetLayer()).SetAddressType(IPAddressType::kIPv6).SetListenPort(mSecuredServicePort)
err = mTransports.Init(UdpListenParameters(DeviceLayer::UDPEndPointManager())
.SetAddressType(IPAddressType::kIPv6)
.SetListenPort(mSecuredServicePort)

#if INET_CONFIG_ENABLE_IPV4
,
UdpListenParameters(&DeviceLayer::InetLayer()).SetAddressType(IPAddressType::kIPv4).SetListenPort(mSecuredServicePort)
,
UdpListenParameters(DeviceLayer::UDPEndPointManager())
.SetAddressType(IPAddressType::kIPv4)
.SetListenPort(mSecuredServicePort)
#endif
#if CONFIG_NETWORK_LAYER_BLE
,
BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer())
,
BleListenParameters(DeviceLayer::ConnectivityMgr().GetBleLayer())
#endif
);

Expand Down
9 changes: 4 additions & 5 deletions src/app/tests/TestOperationalDeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <app/OperationalDeviceProxy.h>
#include <inet/IPAddress.h>
#include <inet/InetLayer.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
Expand All @@ -44,7 +43,7 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite,
TestTransportMgr transportMgr;
SessionManager sessionManager;
ExchangeManager exchangeMgr;
Inet::InetLayer inetLayer;
Inet::UDPEndPointManagerImpl udpEndPointManager;
System::LayerImpl systemLayer;
// Heap-allocate the fairly large FabricTable so we don't end up with a huge
// stack.
Expand All @@ -54,8 +53,8 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite,
SessionIDAllocator idAllocator;

systemLayer.Init();
inetLayer.Init(systemLayer, nullptr);
transportMgr.Init(UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT));
udpEndPointManager.Init(systemLayer);
transportMgr.Init(UdpListenParameters(udpEndPointManager).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT));
sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager);
exchangeMgr.Init(&sessionManager);
messageCounterManager.Init(&exchangeMgr);
Expand All @@ -81,7 +80,7 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite,
sessionManager.Shutdown();
Platform::Delete(fabrics);
transportMgr.Close();
inetLayer.Shutdown();
udpEndPointManager.Shutdown();
systemLayer.Shutdown();
Platform::MemoryShutdown();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ int main(int argc, char * argv[])

InitializeChip();

err = gTransportManager.Init(chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer())
err = gTransportManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager())
.SetAddressType(chip::Inet::IPAddressType::kIPv6)
.SetListenPort(IM_CLIENT_PORT));
SuccessOrExit(err);
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/integration/chip_im_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ int main(int argc, char * argv[])

InitializeChip();

err = gTransportManager.Init(
chip::Transport::UdpListenParameters(&chip::DeviceLayer::InetLayer()).SetAddressType(chip::Inet::IPAddressType::kIPv6));
err = gTransportManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager())
.SetAddressType(chip::Inet::IPAddressType::kIPv6));
SuccessOrExit(err);

err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager);
Expand Down
1 change: 0 additions & 1 deletion src/app/util/chip-message-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <app/util/chip-message-send.h>

#include <assert.h>
#include <inet/InetLayer.h>
#include <lib/support/logging/CHIPLogging.h>
#include <messaging/ExchangeContext.h>
#include <messaging/ExchangeMgr.h>
Expand Down
2 changes: 1 addition & 1 deletion src/controller/AbstractDnssdDiscoveryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void AbstractDnssdDiscoveryController::OnNodeDiscoveryComplete(const chip::Dnssd
CHIP_ERROR AbstractDnssdDiscoveryController::SetUpNodeDiscovery()
{
#if CONFIG_DEVICE_LAYER
ReturnErrorOnFailure(mResolver->Init(&DeviceLayer::InetLayer()));
ReturnErrorOnFailure(mResolver->Init(DeviceLayer::UDPEndPointManager()));
#endif
mResolver->SetResolverDelegate(this);

Expand Down
24 changes: 12 additions & 12 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params)
VerifyOrReturnError(params.systemState != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

VerifyOrReturnError(params.systemState->SystemLayer() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(params.systemState->InetLayer() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(params.systemState->UDPEndPointManager() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

mStorageDelegate = params.storageDelegate;
#if CONFIG_NETWORK_LAYER_BLE
Expand All @@ -132,7 +132,7 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params)
VerifyOrReturnError(params.systemState->TransportMgr() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
Dnssd::Resolver::Instance().Init(params.systemState->InetLayer());
Dnssd::Resolver::Instance().Init(params.systemState->UDPEndPointManager());
Dnssd::Resolver::Instance().SetResolverDelegate(this);
RegisterDeviceAddressUpdateDelegate(params.deviceAddressUpdateDelegate);
RegisterDeviceDiscoveryDelegate(params.deviceDiscoveryDelegate);
Expand Down Expand Up @@ -585,14 +585,14 @@ void DeviceController::OnNodeIdResolutionFailed(const chip::PeerId & peer, CHIP_
ControllerDeviceInitParams DeviceController::GetControllerDeviceInitParams()
{
return ControllerDeviceInitParams{
.transportMgr = mSystemState->TransportMgr(),
.sessionManager = mSystemState->SessionMgr(),
.exchangeMgr = mSystemState->ExchangeMgr(),
.inetLayer = mSystemState->InetLayer(),
.storageDelegate = mStorageDelegate,
.idAllocator = &mIDAllocator,
.fabricsTable = mSystemState->Fabrics(),
.imDelegate = mSystemState->IMDelegate(),
.transportMgr = mSystemState->TransportMgr(),
.sessionManager = mSystemState->SessionMgr(),
.exchangeMgr = mSystemState->ExchangeMgr(),
.udpEndPointManager = mSystemState->UDPEndPointManager(),
.storageDelegate = mStorageDelegate,
.idAllocator = &mIDAllocator,
.fabricsTable = mSystemState->Fabrics(),
.imDelegate = mSystemState->IMDelegate(),
};
}

Expand Down Expand Up @@ -631,12 +631,12 @@ CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params)

#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable
mUdcTransportMgr = chip::Platform::New<DeviceIPTransportMgr>();
ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(mSystemState->InetLayer())
ReturnErrorOnFailure(mUdcTransportMgr->Init(Transport::UdpListenParameters(mSystemState->UDPEndPointManager())
.SetAddressType(Inet::IPAddressType::kIPv6)
.SetListenPort((uint16_t)(mUdcListenPort))
#if INET_CONFIG_ENABLE_IPV4
,
Transport::UdpListenParameters(mSystemState->InetLayer())
Transport::UdpListenParameters(mSystemState->UDPEndPointManager())
.SetAddressType(Inet::IPAddressType::kIPv4)
.SetListenPort((uint16_t)(mUdcListenPort))
#endif // INET_CONFIG_ENABLE_IPV4
Expand Down
38 changes: 22 additions & 16 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState()
FactoryInitParams params;
if (mSystemState != nullptr)
{
params.systemLayer = mSystemState->SystemLayer();
params.inetLayer = mSystemState->InetLayer();
params.systemLayer = mSystemState->SystemLayer();
params.tcpEndPointManager = mSystemState->TCPEndPointManager();
params.udpEndPointManager = mSystemState->UDPEndPointManager();
#if CONFIG_NETWORK_LAYER_BLE
params.bleLayer = mSystemState->BleLayer();
#endif
Expand All @@ -90,16 +91,18 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
#if CONFIG_DEVICE_LAYER
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().InitChipStack());

stateParams.systemLayer = &DeviceLayer::SystemLayer();
stateParams.inetLayer = &DeviceLayer::InetLayer();
stateParams.systemLayer = &DeviceLayer::SystemLayer();
stateParams.tcpEndPointManager = DeviceLayer::TCPEndPointManager();
stateParams.udpEndPointManager = DeviceLayer::UDPEndPointManager();
#else
stateParams.systemLayer = params.systemLayer;
stateParams.inetLayer = params.inetLayer;
stateParams.systemLayer = params.systemLayer;
stateParams.tcpEndPointManager = params.tcpEndPointManager;
stateParams.udpEndPointManager = params.udpEndPointManager;
ChipLogError(Controller, "Warning: Device Controller Factory should be with a CHIP Device Layer...");
#endif // CONFIG_DEVICE_LAYER

VerifyOrReturnError(stateParams.systemLayer != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(stateParams.inetLayer != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(stateParams.udpEndPointManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

#if CONFIG_NETWORK_LAYER_BLE
#if CONFIG_DEVICE_LAYER
Expand All @@ -112,17 +115,20 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)

stateParams.transportMgr = chip::Platform::New<DeviceTransportMgr>();

ReturnErrorOnFailure(stateParams.transportMgr->Init(
Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv6).SetListenPort(mListenPort)
ReturnErrorOnFailure(stateParams.transportMgr->Init(Transport::UdpListenParameters(stateParams.udpEndPointManager)
.SetAddressType(Inet::IPAddressType::kIPv6)
.SetListenPort(mListenPort)
#if INET_CONFIG_ENABLE_IPV4
,
Transport::UdpListenParameters(stateParams.inetLayer).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(mListenPort)
,
Transport::UdpListenParameters(stateParams.udpEndPointManager)
.SetAddressType(Inet::IPAddressType::kIPv4)
.SetListenPort(mListenPort)
#endif
#if CONFIG_NETWORK_LAYER_BLE
,
Transport::BleListenParameters(stateParams.bleLayer)
,
Transport::BleListenParameters(stateParams.bleLayer)
#endif
));
));

if (params.imDelegate == nullptr)
{
Expand Down Expand Up @@ -254,8 +260,8 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown()
mSessionMgr->Shutdown();
}

mSystemLayer = nullptr;
mInetLayer = nullptr;
mSystemLayer = nullptr;
mUDPEndPointManager = nullptr;

if (mMessageCounterManager != nullptr)
{
Expand Down
9 changes: 5 additions & 4 deletions src/controller/CHIPDeviceControllerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ struct SetupParams
// We're blocked because of the need to support !CHIP_DEVICE_LAYER
struct FactoryInitParams
{
FabricStorage * fabricStorage = nullptr;
System::Layer * systemLayer = nullptr;
Inet::InetLayer * inetLayer = nullptr;
DeviceControllerInteractionModelDelegate * imDelegate = nullptr;
FabricStorage * fabricStorage = nullptr;
System::Layer * systemLayer = nullptr;
Inet::EndPointManager<Inet::TCPEndPoint> * tcpEndPointManager = nullptr;
Inet::EndPointManager<Inet::UDPEndPoint> * udpEndPointManager = nullptr;
DeviceControllerInteractionModelDelegate * imDelegate = nullptr;
#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * bleLayer = nullptr;
#endif
Expand Down
Loading

0 comments on commit 7ab4af7

Please sign in to comment.