Skip to content

Commit

Permalink
Add IP string attribute to NetworkInterface and move implementation t…
Browse files Browse the repository at this point in the history
…o cpp

Signed-off-by: Juan Lopez Fernandez <[email protected]>
  • Loading branch information
juanlofer-eprosima committed Mar 11, 2024
1 parent 102bef5 commit e325698
Show file tree
Hide file tree
Showing 40 changed files with 254 additions and 53 deletions.
23 changes: 7 additions & 16 deletions include/fastdds/rtps/transport/network/NetworkInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,13 @@ struct RTPS_DllAPI NetworkInterface
{
//! Constructor by name
NetworkInterface(
const std::string& name)
: name(name)
{
}
const std::string& name);

//! Constructor by device name and IP address
//! Constructor by device name, IP address string and locator with mask
NetworkInterface(
const std::string& device,
const LocatorWithMask& locator)
: device(device)
, locator(locator)
{
}
const std::string& ip,
const LocatorWithMask& locator);

//! Destructor
virtual ~NetworkInterface() = default;
Expand All @@ -73,18 +67,15 @@ struct RTPS_DllAPI NetworkInterface

//! Comparison operator
bool operator ==(
const NetworkInterface& iface) const
{
return (this->name == iface.name &&
this->device == iface.device &&
this->locator == iface.locator);
}
const NetworkInterface& iface) const;

//! Interface device name or IP address in string format (to be filled by the user)
std::string name;

//! Interface device name
std::string device;
//! IP address in string format (includes scope ID in the IPv6 case)
std::string ip;
//! IP address with network mask
LocatorWithMask locator;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,24 @@ struct RTPS_DllAPI NetworkInterfaceWithFilter : public NetworkInterface
//! Constructor by name and netmask filter
NetworkInterfaceWithFilter(
const std::string& name,
NetmaskFilterKind netmask_filter)
: NetworkInterface(name)
, netmask_filter(netmask_filter)
{
}
NetmaskFilterKind netmask_filter);

//! Constructor by name
NetworkInterfaceWithFilter(
const std::string& name)
: NetworkInterfaceWithFilter(name, NetmaskFilterKind::AUTO)
{
}
const std::string& name);

//! Constructor by device name, IP address and netmask filter
//! Constructor by device name, IP address string, locator with mask and netmask filter
NetworkInterfaceWithFilter(
const std::string& device,
const std::string& ip,
const LocatorWithMask& locator,
NetmaskFilterKind netmask_filter)
: NetworkInterface(device, locator)
, netmask_filter(netmask_filter)
{
}
NetmaskFilterKind netmask_filter);

//! Constructor by device name and IP address
//! Constructor by device name, IP address string and locator with mask
NetworkInterfaceWithFilter(
const std::string& device,
const LocatorWithMask& locator)
: NetworkInterfaceWithFilter(device, locator, NetmaskFilterKind::AUTO)
{
}
const std::string& ip,
const LocatorWithMask& locator);

//! Destructor
virtual ~NetworkInterfaceWithFilter() = default;
Expand All @@ -92,11 +80,7 @@ struct RTPS_DllAPI NetworkInterfaceWithFilter : public NetworkInterface

//! Comparison operator
bool operator ==(
const NetworkInterfaceWithFilter& iface) const
{
return (this->netmask_filter == iface.netmask_filter &&
NetworkInterface::operator ==(iface));
}
const NetworkInterfaceWithFilter& iface) const;

//! Netmask filter configuration
NetmaskFilterKind netmask_filter;
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ set(${PROJECT_NAME}_source_files
rtps/transport/ChainingTransport.cpp
rtps/transport/ChannelResource.cpp
rtps/transport/network/NetmaskFilterKind.cpp
rtps/transport/network/NetworkInterface.cpp
rtps/transport/network/NetworkInterfaceWithFilter.cpp
rtps/transport/PortBasedTransportDescriptor.cpp
rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp
rtps/transport/tcp/RTCPMessageManager.cpp
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/rtps/transport/TCPv4Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TCPv4Transport::TCPv4Transport(
else if (descriptor.interfaceWhiteList.empty() && descriptor.interface_allowlist.empty())
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
else if (!descriptor.interface_allowlist.empty())
{
Expand All @@ -156,7 +156,7 @@ TCPv4Transport::TCPv4Transport(
descriptor.netmask_filter))
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, netmask_filter);
}
else
{
Expand All @@ -176,7 +176,7 @@ TCPv4Transport::TCPv4Transport(
}) != white_end )
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/rtps/transport/TCPv6Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TCPv6Transport::TCPv6Transport(
else if (descriptor.interfaceWhiteList.empty() && descriptor.interface_allowlist.empty())
{
interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
else if (!descriptor.interface_allowlist.empty())
{
Expand All @@ -162,7 +162,7 @@ TCPv6Transport::TCPv6Transport(
descriptor.netmask_filter))
{
interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, netmask_filter);
}
else
{
Expand All @@ -182,7 +182,7 @@ TCPv6Transport::TCPv6Transport(
}) != white_end )
{
interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/rtps/transport/UDPv4Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ UDPv4Transport::UDPv4Transport(
else if (descriptor.interfaceWhiteList.empty() && descriptor.interface_allowlist.empty())
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
else if (!descriptor.interface_allowlist.empty())
{
Expand All @@ -187,7 +187,7 @@ UDPv4Transport::UDPv4Transport(
descriptor.netmask_filter))
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, netmask_filter);
}
else
{
Expand All @@ -207,7 +207,7 @@ UDPv4Transport::UDPv4Transport(
}) != white_end )
{
interface_whitelist_.emplace_back(ip::address_v4::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/rtps/transport/UDPv6Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ UDPv6Transport::UDPv6Transport(
else if (descriptor.interfaceWhiteList.empty() && descriptor.interface_allowlist.empty())
{
interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
else if (!descriptor.interface_allowlist.empty())
{
Expand All @@ -188,7 +188,7 @@ UDPv6Transport::UDPv6Transport(
descriptor.netmask_filter))
{
interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, netmask_filter);
}
else
{
Expand All @@ -208,7 +208,7 @@ UDPv6Transport::UDPv6Transport(
}) != white_end )
{
interface_whitelist_.emplace_back(ip::address_v6::from_string(infoIP.name));
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.masked_locator, descriptor.netmask_filter);
allowed_interfaces_.emplace_back(infoIP.dev, infoIP.name, infoIP.masked_locator, descriptor.netmask_filter);
}
}
}
Expand Down
52 changes: 52 additions & 0 deletions src/cpp/rtps/transport/network/NetworkInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file NetworkInterface.cpp
*/

#include <fastdds/rtps/transport/network/NetworkInterface.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

NetworkInterface::NetworkInterface(
const std::string& name)
: name(name)
{
}

NetworkInterface::NetworkInterface(
const std::string& device,
const std::string& ip,
const LocatorWithMask& locator)
: device(device)
, ip(ip)
, locator(locator)
{
}

bool NetworkInterface::operator ==(
const NetworkInterface& iface) const
{
return (this->name == iface.name &&
this->device == iface.device &&
this->ip == iface.ip &&
this->locator == iface.locator);
}

} // namsepace rtps
} // namespace fastdds
} // namespace eprosima
66 changes: 66 additions & 0 deletions src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file NetworkInterfaceWithFilter.cpp
*/

#include <fastdds/rtps/transport/network/NetworkInterfaceWithFilter.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

NetworkInterfaceWithFilter::NetworkInterfaceWithFilter(
const std::string& name,
NetmaskFilterKind netmask_filter)
: NetworkInterface(name)
, netmask_filter(netmask_filter)
{
}

NetworkInterfaceWithFilter::NetworkInterfaceWithFilter(
const std::string& name)
: NetworkInterfaceWithFilter(name, NetmaskFilterKind::AUTO)
{
}

NetworkInterfaceWithFilter::NetworkInterfaceWithFilter(
const std::string& device,
const std::string& ip,
const LocatorWithMask& locator,
NetmaskFilterKind netmask_filter)
: NetworkInterface(device, ip, locator)
, netmask_filter(netmask_filter)
{
}

NetworkInterfaceWithFilter::NetworkInterfaceWithFilter(
const std::string& device,
const std::string& ip,
const LocatorWithMask& locator)
: NetworkInterfaceWithFilter(device, ip, locator, NetmaskFilterKind::AUTO)
{
}

bool NetworkInterfaceWithFilter::operator ==(
const NetworkInterfaceWithFilter& iface) const
{
return (this->netmask_filter == iface.netmask_filter &&
NetworkInterface::operator ==(iface));
}

} // namsepace rtps
} // namespace fastdds
} // namespace eprosima
2 changes: 2 additions & 0 deletions test/unittest/dds/collections/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ set(LOANABLE_SEQUENCE_TESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp
Expand Down
8 changes: 8 additions & 0 deletions test/unittest/dds/core/condition/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ set(CONDITION_TESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${LOG_SOURCES}
Expand Down Expand Up @@ -64,6 +66,8 @@ set(CONDITION_NOTIFIER_TESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${LOG_SOURCES}
Expand Down Expand Up @@ -94,6 +98,8 @@ set(STATUS_CONDITION_IMPL_TESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${LOG_SOURCES}
Expand Down Expand Up @@ -123,6 +129,8 @@ set(WAITSET_IMPL_TESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${LOG_SOURCES}
Expand Down
2 changes: 2 additions & 0 deletions test/unittest/dds/core/entity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ set(ENTITY_TESTS_SOURCE
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/netmask_filter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/utils/network.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetmaskFilterKind.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterface.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/network/NetworkInterfaceWithFilter.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp
${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp
Expand Down
Loading

0 comments on commit e325698

Please sign in to comment.