You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在user_QoS_profiles.xml中配置RTI DDS实现双网卡分收发?

双NIC设备下RTI DDS指定DataWriter发送网卡的解决方案

核心问题分析

全局配置dds.transport.UDPv4.builtin.parent.allow_interfaces会作用于整个DomainParticipant,无法单独为DataWriter指定发送网卡。要实现Endpoint级别的网卡绑定,需要通过自定义Transport配置+DataWriter专属QoS来实现。

方案一:通过XML配置文件实现

1. 配置自定义Transport和DataWriter QoS

在你的RTI DDS配置文件中添加以下内容,替换示例IP为你的实际网卡地址:

<dds>
    <!-- 全局Participant配置,保留UDPv4作为内置Transport但不强制绑定网卡 -->
    <domain_participant_qos>
        <transport_builtin>
            <mask>UDPv4</mask>
        </transport_builtin>
    </domain_participant_qos>

    <!-- 为发布端DataWriter定义专属QoS,绑定自定义Transport -->
    <datawriter_qos name="PublisherNICWriterQoS">
        <transport>
            <user_transports>
                <element>
                    <transport_name>PublisherUDPTransport</transport_name>
                </element>
            </user_transports>
            <builtin_transports>
                <mask>NONE</mask> <!-- 禁用内置Transport,仅使用自定义实例 -->
            </builtin_transports>
        </transport>
    </datawriter_qos>

    <!-- 订阅端DataReader的专属QoS,绑定另一网卡 -->
    <datareader_qos name="SubscriberNICReaderQoS">
        <transport>
            <user_transports>
                <element>
                    <transport_name>SubscriberUDPTransport</transport_name>
                </element>
            </user_transports>
            <builtin_transports>
                <mask>NONE</mask>
            </builtin_transports>
        </transport>
    </datareader_qos>

    <!-- 定义两个自定义UDP Transport,分别绑定不同网卡 -->
    <transport_configuration>
        <!-- 发布端使用的Transport,绑定网卡IP 192.168.1.100 -->
        <transport_plugin name="PublisherUDPTransport" class="dds.transport.UDPv4">
            <property>
                <value>
                    <element>
                        <name>dds.transport.UDPv4.parent.allow_interfaces</name>
                        <value>192.168.1.100</value>
                    </element>
                    <element>
                        <name>dds.transport.UDPv4.parent.deny_interfaces</name>
                        <value>192.168.2.0/24</value>
                    </element>
                </value>
            </property>
        </transport_plugin>

        <!-- 订阅端使用的Transport,绑定网卡IP 192.168.2.100 -->
        <transport_plugin name="SubscriberUDPTransport" class="dds.transport.UDPv4">
            <property>
                <value>
                    <element>
                        <name>dds.transport.UDPv4.parent.allow_interfaces</name>
                        <value>192.168.2.100</value>
                    </element>
                    <element>
                        <name>dds.transport.UDPv4.parent.deny_interfaces</name>
                        <value>192.168.1.0/24</value>
                    </element>
                </value>
            </property>
        </transport_plugin>
    </transport_configuration>
</dds>

2. 代码中加载QoS创建Endpoint

以C++为例,加载配置文件并使用自定义QoS创建DataWriter/DataReader:

#include <dds/pub/ddspub.hpp>
#include <dds/sub/ddssub.hpp>
#include <rti/core/QosProvider.hpp>

// 加载配置文件
rti::core::QosProvider qos_provider("your_config_file.xml");

// 创建发布端DataWriter
dds::pub::DataWriterQos dw_qos = qos_provider.datawriter_qos("PublisherNICWriterQoS");
dds::pub::DataWriter<YourDataType> writer(publisher, topic, dw_qos);

// 创建订阅端DataReader
dds::sub::DataReaderQos dr_qos = qos_provider.datareader_qos("SubscriberNICReaderQoS");
dds::sub::DataReader<YourDataType> reader(subscriber, topic, dr_qos);

方案二:通过代码动态配置(无需XML)

如果不想依赖配置文件,可以直接在代码中创建自定义Transport并绑定到Endpoint:

#include <dds/pub/ddspub.hpp>
#include <rti/transport/UDPv4Transport.hpp>
#include <rti/core/policy/Transport.hpp>

// 配置发布端Transport属性
rti::transport::UDPv4TransportProperty pub_transport_prop;
pub_transport_prop.allow_interfaces({"192.168.1.100"}); // 指定发布网卡IP
pub_transport_prop.deny_interfaces({"192.168.2.0/24"});

// 创建发布端自定义Transport
auto pub_transport = rti::transport::UDPv4Transport::create(pub_transport_prop);

// 配置DataWriter QoS,仅使用自定义Transport
dds::pub::DataWriterQos dw_qos;
dw_qos.transport().user_transports().push_back(pub_transport);
dw_qos.transport().builtin_transports().mask(rti::core::TransportBuiltinMask::NONE);

// 创建DataWriter
dds::pub::DataWriter<YourDataType> writer(publisher, topic, dw_qos);

// 订阅端配置类似,替换网卡IP即可
rti::transport::UDPv4TransportProperty sub_transport_prop;
sub_transport_prop.allow_interfaces({"192.168.2.100"});
sub_transport_prop.deny_interfaces({"192.168.1.0/24"});
auto sub_transport = rti::transport::UDPv4Transport::create(sub_transport_prop);

dds::sub::DataReaderQos dr_qos;
dr_qos.transport().user_transports().push_back(sub_transport);
dr_qos.transport().builtin_transports().mask(rti::core::TransportBuiltinMask::NONE);
dds::sub::DataReader<YourDataType> reader(subscriber, topic, dr_qos);

验证方法

  • 使用RTI自带的rtiddsspy工具指定网卡监听,确认数据流向:
    # 监听发布端网卡
    rtiddsspy -domain 0 -transport UDPv4 -allow-interfaces 192.168.1.100
    # 监听订阅端网卡
    rtiddsspy -domain 0 -transport UDPv4 -allow-interfaces 192.168.2.100
    
  • 用tcpdump或Wireshark抓包,确认数据包从指定网卡发出/接收。

内容的提问来源于stack exchange,提问作者李长江

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 07:57:22