ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Restrict ROS 2 to Localhost

asked 2019-09-23 08:58:00 -0500

allenh1 gravatar image

I'm wondering if anybody has a method to restrict ROS 2 to use only the localhost for communication? Maybe there is (or at least could be) an environment variable to control this?

While setting ROS_DOMAIN_ID works fine to prevent collisions, it would be nice if this did not have to be set manually for cases where we know that the communication is only going to be within the machine.

edit retag flag offensive close merge delete

Comments

I'm confused what you are trying to achieve? If you want to use intra-process communication have a look at this PR https://github.com/ros2/rclcpp/pull/778 . You can set nodes to use intra-process communication by passing rclcpp::NodeOptions().use_intra_process_comms(true) into the node. I.e.

auto node = std::make_shared<rclcpp::Node>("node_" + std::to_string(n), rclcpp::NodeOptions().use_intra_process_comms(true));

I believe it is also possible to set intra-process communication at a subscriber or publisher level, but I haven't tried this yet.

MCornelis gravatar image MCornelis  ( 2019-09-23 09:25:44 -0500 )edit

Right now it does not support transient(-local) durability so you may have to change your QoS profile to VOLATILE for durability.

static const rclcpp::QoS qos = rclcpp::QoS(1)
                                   .reliability(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT)
                                   .durability(RMW_QOS_POLICY_DURABILITY_VOLATILE);
MCornelis gravatar image MCornelis  ( 2019-09-23 09:28:58 -0500 )edit

Sorry, @MCornelis, I think I could have been more clear in my wording... I'm not referring to intra-process communication, I'm more referring to restricting DDS discovery to only the local subnet.

allenh1 gravatar image allenh1  ( 2019-09-23 10:18:41 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2020-08-10 10:58:19 -0500

Dirk Thomas gravatar image

Since ROS 2 Eloquent you can restrict all communication of an RMW implementation to localhost using the environment variable ROS_LOCALHOST_ONLY(see https://index.ros.org/doc/ros2/Releas...).

edit flag offensive delete link more

Comments

This does not work for me

Hakaishin gravatar image Hakaishin  ( 2022-02-28 06:56:15 -0500 )edit

For me it prevents traffic out to others, but it doesn't prevent discovery and traffic in from others

kmhallen gravatar image kmhallen  ( 2022-09-07 10:31:12 -0500 )edit
0

answered 2019-10-02 09:22:04 -0500

allenh1 gravatar image

Okay, so there's a way to do this it seems. For fastRTPS, you can use the following for DEFAULT_FASTRTPS_PROFILES.xml, and place it in the working directory from where you run your ROS 2 nodes.

<?xml version="1.0" encoding="UTF-8" ?>
<profiles>
  <participant profile_name="participant_profile" is_default_profile="true">
    <rtps>
      <builtin>
        <metatrafficUnicastLocatorList>
          <locator/>
        </metatrafficUnicastLocatorList>
        <initialPeersList>
          <locator>
            <udpv4>
              <address>127.0.0.1</address>
            </udpv4>
          </locator>
        </initialPeersList>
      </builtin>
    </rtps>
  </participant>
</profiles>
edit flag offensive delete link more

Comments

This does not work for me

Hakaishin gravatar image Hakaishin  ( 2022-02-28 06:56:07 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-09-23 08:58:00 -0500

Seen: 4,639 times

Last updated: Aug 10 '20