Skip to content

Commit f9cb0ab

Browse files
Add support for ethernet locator kind (#5999)
* Refs #23435. Add locator kind for ethernet transport. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Process ethernet locators in `get_mask_and_cost`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Avoid assertion for unknown locators. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Fix `LocatorWithMask::matches`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Serialization of ethernet locators. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Update `IsAddressDefined`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Prepare XML parser for extensions in Fast DDS Pro. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Add ethernet transport details to XSD. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Refactor transport creation in XML parser. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Move `parseXMLOctetVector` from free function to `XMLParser` static method. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Avoid failing with eth specific xml elements. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Compare full address in `IsAddressDefined`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Change ethernet address serialization. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Fix comment. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Update locator tests. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Fix behavior. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Fix link issues. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Add xml validation file for ethernet. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Fix link issues in Mac. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Improve locator test. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23435. Update `versions.md`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent db64a12 commit f9cb0ab

File tree

47 files changed

+825
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+825
-251
lines changed

include/fastdds/rtps/common/Locator.hpp

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <cstring>
2525
#include <iomanip>
2626
#include <sstream>
27+
#include <string>
2728
#include <vector>
2829

2930
#include <fastdds/config.hpp>
@@ -61,6 +62,8 @@ namespace rtps {
6162
#define LOCATOR_KIND_TCPv6 8
6263
/// Shared memory locator kind
6364
#define LOCATOR_KIND_SHM 16 + FASTDDS_VERSION_MAJOR
65+
/// Ethernet locator kind
66+
#define LOCATOR_KIND_ETHERNET 0x02000000
6467

6568
/**
6669
* @brief Class Locator_t, uniquely identifies a communication channel for a particular transport.
@@ -83,6 +86,8 @@ class FASTDDS_EXPORTED_API Locator_t
8386
* LOCATOR_KIND_TCPv6
8487
*
8588
* LOCATOR_KIND_SHM
89+
*
90+
* LOCATOR_KIND_ETHERNET
8691
*/
8792
int32_t kind;
8893
/// Network port
@@ -188,6 +193,19 @@ class FASTDDS_EXPORTED_API Locator_t
188193
LOCATOR_ADDRESS_INVALID(address);
189194
}
190195

196+
/**
197+
* @brief Create a locator with the given parameters.
198+
*
199+
* @param kind Kind of the locator.
200+
* @param address IP Address of the locator as string.
201+
* @param port Port of the locator.
202+
* @return Locator_t object initialized with the given parameters.
203+
*/
204+
static Locator_t create_locator(
205+
int32_t kind,
206+
const std::string& address,
207+
uint32_t port);
208+
191209
};
192210

193211
/**
@@ -210,7 +228,8 @@ inline bool IsAddressDefined(
210228
}
211229
}
212230
}
213-
else if (loc.kind == LOCATOR_KIND_UDPv6 || loc.kind == LOCATOR_KIND_TCPv6)
231+
else if (loc.kind == LOCATOR_KIND_UDPv6 || loc.kind == LOCATOR_KIND_TCPv6 ||
232+
loc.kind == LOCATOR_KIND_SHM || loc.kind == LOCATOR_KIND_ETHERNET)
214233
{
215234
for (uint8_t i = 0; i < 16; ++i)
216235
{
@@ -302,6 +321,7 @@ inline bool operator !=(
302321
* - TCPv4
303322
* - TCPv6
304323
* - SHM
324+
* - ETHERNET
305325
* \c address IP address unless \c kind is SHM
306326
* \c port number
307327
*
@@ -341,6 +361,11 @@ inline std::ostream& operator <<(
341361
output << "SHM:[";
342362
break;
343363
}
364+
case LOCATOR_KIND_ETHERNET:
365+
{
366+
output << "ETH:[";
367+
break;
368+
}
344369
default:
345370
{
346371
output << "Invalid_locator:[_]:0";
@@ -349,24 +374,36 @@ inline std::ostream& operator <<(
349374
}
350375

351376
// Stream address
352-
if (loc.kind == LOCATOR_KIND_UDPv4 || loc.kind == LOCATOR_KIND_TCPv4)
353-
{
354-
output << IPLocator::toIPv4string(loc);
355-
}
356-
else if (loc.kind == LOCATOR_KIND_UDPv6 || loc.kind == LOCATOR_KIND_TCPv6)
357-
{
358-
output << IPLocator::toIPv6string(loc);
359-
}
360-
else if (loc.kind == LOCATOR_KIND_SHM)
377+
switch (loc.kind)
361378
{
362-
if (loc.address[0] == 'M')
363-
{
364-
output << "M";
365-
}
366-
else
367-
{
368-
output << "_";
369-
}
379+
case LOCATOR_KIND_UDPv4:
380+
case LOCATOR_KIND_TCPv4:
381+
output << IPLocator::toIPv4string(loc);
382+
break;
383+
384+
case LOCATOR_KIND_UDPv6:
385+
case LOCATOR_KIND_TCPv6:
386+
output << IPLocator::toIPv6string(loc);
387+
break;
388+
389+
case LOCATOR_KIND_ETHERNET:
390+
output << std::hex << std::setfill('0') << std::setw(2) << (int)loc.address[10];
391+
for (int i = 1; i < 6; ++i)
392+
{
393+
output << ":" << std::hex << std::setfill('0') << std::setw(2) << (int)loc.address[10 + i];
394+
}
395+
break;
396+
397+
case LOCATOR_KIND_SHM:
398+
if (loc.address[0] == 'M')
399+
{
400+
output << "M";
401+
}
402+
else
403+
{
404+
output << "_";
405+
}
406+
break;
370407
}
371408

372409
// Stream port
@@ -392,6 +429,7 @@ inline std::ostream& operator <<(
392429
* - TCPv4
393430
* - TCPv6
394431
* - SHM
432+
* - ETHERNET
395433
* \c address must be either a name which can be resolved by DNS or the IP address unless \c kind is SHM
396434
* \c port number
397435
*
@@ -432,6 +470,10 @@ inline std::istream& operator >>(
432470
{
433471
kind = LOCATOR_KIND_SHM;
434472
}
473+
else if (str_kind == "ETH")
474+
{
475+
kind = LOCATOR_KIND_ETHERNET;
476+
}
435477
else if (str_kind == "TCPv4")
436478
{
437479
kind = LOCATOR_KIND_TCPv4;
@@ -488,14 +530,20 @@ inline std::istream& operator >>(
488530
}
489531
address = *addresses.second.begin();
490532
}
533+
if ((kind == LOCATOR_KIND_SHM) && (address != "M") && (address != "_"))
534+
{
535+
loc.kind = LOCATOR_KIND_INVALID;
536+
EPROSIMA_LOG_WARNING(LOCATOR, "Error deserializing Locator");
537+
return input;
538+
}
491539

492540
// Get char ]:
493541
input >> punct >> punct;
494542

495543
// Get port
496544
input >> port;
497545

498-
IPLocator::createLocator(kind, address, port, loc);
546+
loc = Locator_t::create_locator(kind, address, port);
499547
}
500548
}
501549
catch (std::ios_base::failure& )

resources/xsd/fastdds_profiles.xsd

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,11 @@
944944
├ rtps_dump_file [string] (ONLY available for SHM type)
945945
├ default_reception_threads [threadSettingsType]
946946
├ reception_threads [receptionThreadsListType] (ONLY available for SHM type)
947-
└ dump_thread [threadSettingsType] (ONLY available for SHM type) -->
947+
├ dump_thread [threadSettingsType] (ONLY available for SHM type)
948+
├ eth_interface_name [string] (ONLY available for ETH type)
949+
├ eth_output_port [uint16] (ONLY available for ETH type)
950+
└ eth_priority_mappings [ethernetPriorityMappingsType] (ONLY available for ETH type)
951+
-->
948952
<!-- TODO: How to ensure all elements are declared properly (UDP only, TCP only, etc...)? -->
949953
<xs:complexType name="transportDescriptorType">
950954
<xs:all minOccurs="0">
@@ -957,6 +961,7 @@
957961
<xs:enumeration value="TCPv4"/>
958962
<xs:enumeration value="TCPv6"/>
959963
<xs:enumeration value="SHM"/>
964+
<xs:enumeration value="ETH"/>
960965
</xs:restriction>
961966
</xs:simpleType>
962967
</xs:element>
@@ -1018,6 +1023,9 @@
10181023
<xs:element name="default_reception_threads" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
10191024
<xs:element name="reception_threads" type="receptionThreadsListType" minOccurs="0" maxOccurs="1"/>
10201025
<xs:element name="dump_thread" type="threadSettingsType" minOccurs="0" maxOccurs="1"/>
1026+
<xs:element name="eth_interface_name" type="string" minOccurs="0" maxOccurs="1"/>
1027+
<xs:element name="eth_output_port" type="uint16" minOccurs="0" maxOccurs="1"/>
1028+
<xs:element name="eth_priority_mappings" type="ethernetPriorityMappingsType" minOccurs="0" maxOccurs="1"/>
10211029
</xs:all>
10221030
</xs:complexType>
10231031

@@ -1151,6 +1159,26 @@
11511159
</xs:all>
11521160
</xs:complexType>
11531161

1162+
<!--eth_priority_mappings:
1163+
└ priority [0~*]
1164+
╠ att. value [int32] REQ
1165+
╠ att. source_port [uint16]
1166+
╠ att. pcp [uint8]
1167+
╚ att. vlan_id [uint16]
1168+
-->
1169+
<xs:complexType name="ethernetPriorityMappingsType">
1170+
<xs:sequence minOccurs="0" maxOccurs="unbounded">
1171+
<xs:element name="priority" minOccurs="0" maxOccurs="unbounded">
1172+
<xs:complexType>
1173+
<xs:attribute name="value" type="int32" use="required"/>
1174+
<xs:attribute name="source_port" type="uint16" default="0"/>
1175+
<xs:attribute name="pcp" type="uint8" default="0"/>
1176+
<xs:attribute name="vlan_id" type="uint16" default="0"/>
1177+
</xs:complexType>
1178+
</xs:element>
1179+
</xs:sequence>
1180+
</xs:complexType>
1181+
11541182

11551183
<!--+==================================================================================+-->
11561184

@@ -1171,6 +1199,7 @@
11711199
<xs:element name="udpv6" type="udpv6LocatorType" maxOccurs="unbounded"/>
11721200
<xs:element name="tcpv4" type="tcpv4LocatorType" maxOccurs="unbounded"/>
11731201
<xs:element name="tcpv6" type="tcpv6LocatorType" maxOccurs="unbounded"/>
1202+
<xs:element name="ethernet" type="ethernetLocatorType" maxOccurs="unbounded"/>
11741203
</xs:choice>
11751204
</xs:complexType>
11761205
</xs:element>
@@ -1439,6 +1468,20 @@
14391468
</xs:all>
14401469
</xs:complexType>
14411470

1471+
<!--ethernet Locator:
1472+
├ port [uint16],
1473+
├ pcp [uint8],
1474+
├ vlan_id [uint16],
1475+
└ address [octectVector]-->
1476+
<xs:complexType name="ethernetLocatorType">
1477+
<xs:all>
1478+
<xs:element name="port" type="uint16" minOccurs="0" maxOccurs="1"/>
1479+
<xs:element name="pcp" type="uint8" minOccurs="0" maxOccurs="1"/>
1480+
<xs:element name="vlan_id" type="uint16" minOccurs="0" maxOccurs="1"/>
1481+
<xs:element name="address" type="octectVector" minOccurs="0" maxOccurs="1"/>
1482+
</xs:all>
1483+
</xs:complexType>
1484+
14421485
<!--udpv4 External Locator:
14431486
| att. externality [uint8] (1~255),
14441487
| att. cost [uint8] (0~255),

src/cpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ foreach(MODULE_DIR ${${PROJECT_NAME}_module_dirs})
3636
add_subdirectory(${MODULE_DIR})
3737
endforeach()
3838

39+
list(APPEND ${PROJECT_NAME}_source_files
40+
xmlparser/XMLParserExtras.cpp
41+
)
42+
3943
# Option to enable strict real-time. In this case, several API functions have a real-time behaviour.
4044
# * Publisher::write() - Uses ReliabilityQosPolicy.max_blocking_time
4145
# * Subscriber::takeNextData() - Uses ReliabilityQosPolicy.max_blocking_time

src/cpp/rtps/common/LocatorWithMask.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,25 @@ bool LocatorWithMask::matches(
4949
{
5050
case LOCATOR_KIND_UDPv4:
5151
case LOCATOR_KIND_TCPv4:
52+
// IPv4 address is in the last 4 octets of the 16-octet array
5253
assert(32 >= mask());
5354
return network::address_matches(loc.address + 12, address + 12, mask());
5455

5556
case LOCATOR_KIND_UDPv6:
5657
case LOCATOR_KIND_TCPv6:
5758
case LOCATOR_KIND_SHM:
59+
// IPv6 and SHM address use the full 16-octet array
5860
assert(128 >= mask());
5961
return network::address_matches(loc.address, address, mask());
62+
63+
case LOCATOR_KIND_ETHERNET:
64+
// Ethernet locators match independently of the MAC address (mask 0)
65+
assert(0 == mask());
66+
return true;
67+
68+
default:
69+
// Other kinds of locators would come from custom transports, so we let them always match (mask 0)
70+
return true;
6071
}
6172
}
6273

src/cpp/rtps/network/utils/external_locators.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,17 @@ static void get_mask_and_cost(
8686
mask = 128;
8787
break;
8888

89+
// Ethernet locators match independently of the MAC address (mask 0), and have a cost equivalent to IPv4
90+
case LOCATOR_KIND_ETHERNET:
91+
cost = 1;
92+
mask = 0;
93+
break;
94+
95+
// Other kinds of locators would come from custom transports, so we let them always match (mask 0)
96+
// with the highest cost (255)
8997
default:
90-
assert(false && "Unexpected locator kind");
98+
cost = 255;
99+
mask = 0;
91100
break;
92101
}
93102
}

0 commit comments

Comments
 (0)