Skip to content

Commit

Permalink
[Inet][Transport] Multicast Multihoming : Socket implementation (#21351)
Browse files Browse the repository at this point in the history
* Add Multicast Homing for Socket Implementation

* Fix CI

* fix move buffer

* remove debug code
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Nov 30, 2023
1 parent 17a4cb7 commit 4c9dea8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ buildconfig_header("system_buildconfig") {
} else {
defines += [ "CHIP_SYSTEM_LAYER_IMPL_CONFIG_FILE=<system/SystemLayerImpl${chip_system_config_event_loop}.h>" ]
}

if (chip_system_config_use_sockets && current_os != "zephyr") {
defines += [
"CHIP_SYSTEM_CONFIG_MULTICAST_HOMING=${chip_system_config_use_sockets} ",
]
} else {
defines += [ "CHIP_SYSTEM_CONFIG_MULTICAST_HOMING=0 " ]
}
}

config("system_config") {
Expand Down
8 changes: 8 additions & 0 deletions src/system/SystemConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
"FORBIDDEN: CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT && ( CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_LWIP )"
#endif

#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING && !CHIP_SYSTEM_CONFIG_USE_SOCKETS
#error "FORBIDDEN: CHIP_SYSTEM_CONFIG_MULTICAST_HOMING CAN ONLY BE USED WITH SOCKET IMPL"
#endif

#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING && CHIP_SYSTEM_CONFIG_USE_SOCKETS && __ZEPHYR__
#error "FORBIDDEN: CHIP_SYSTEM_CONFIG_MULTICAST_HOMING WAS NOT TESTED WITH ZEPHYR"
#endif

// clang-format off

/**
Expand Down
54 changes: 54 additions & 0 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,60 @@ CHIP_ERROR SessionManager::SendPreparedMessage(const SessionHandle & sessionHand
VerifyOrReturnError(!msgBuf.IsNull(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!msgBuf->HasChainedBuffer(), CHIP_ERROR_INVALID_MESSAGE_LENGTH);

#if CHIP_SYSTEM_CONFIG_MULTICAST_HOMING
if (sessionHandle->GetSessionType() == Transport::Session::SessionType::kGroupOutgoing)
{
chip::Inet::InterfaceIterator interfaceIt;
chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::Null();
chip::Inet::IPAddress addr;
bool interfaceFound = false;

while (interfaceIt.Next())
{
char name[chip::Inet::InterfaceId::kMaxIfNameLength];
interfaceIt.GetInterfaceName(name, chip::Inet::InterfaceId::kMaxIfNameLength);
if (interfaceIt.SupportsMulticast() && interfaceIt.IsUp())
{
interfaceId = interfaceIt.GetInterfaceId();
if (CHIP_NO_ERROR == interfaceId.GetLinkLocalAddr(&addr))
{
ChipLogDetail(Inet, "Interface %s has a link local address", name);

interfaceFound = true;
PacketBufferHandle tempBuf = msgBuf.CloneData();
VerifyOrReturnError(!tempBuf.IsNull(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(!tempBuf->HasChainedBuffer(), CHIP_ERROR_INVALID_MESSAGE_LENGTH);

destination = &(multicastAddress.SetInterface(interfaceId));
if (mTransportMgr != nullptr)
{
CHIP_TRACE_PREPARED_MESSAGE_SENT(destination, &tempBuf);
if (CHIP_NO_ERROR != mTransportMgr->SendMessage(*destination, std::move(tempBuf)))
{
ChipLogError(Inet, "Failed to send Multicast message on interface %s", name);
}
else
{
ChipLogDetail(Inet, "Successfully send Multicast message on interface %s", name);
}
}
}
}
}

if (!interfaceFound)
{
ChipLogError(Inet, "No valid Interface found.. Sending to the default one.. ");
}
else
{
// Always return No error, because we expect some interface to fails and others to always succeed (e.g. lo interface)
return CHIP_NO_ERROR;
}
}

#endif // CHIP_SYSTEM_CONFIG_MULTICAST_HOMING

if (mTransportMgr != nullptr)
{
CHIP_TRACE_PREPARED_MESSAGE_SENT(destination, &msgBuf);
Expand Down

0 comments on commit 4c9dea8

Please sign in to comment.