ouster-lidar / ouster-sdk

Ouster, Inc. sample code
Other
468 stars 440 forks source link

Working with multiple network interfaces #518

Closed marcomaida94 closed 1 year ago

marcomaida94 commented 1 year ago

Describe your question Hello, I am writing an application based on this SDK. I intend to have two clients on the same machine, listening to two different lidars which are plugged to two separate network interfaces. I intend to have a program argument containing a NIC device name or an ip address, and have the Ouster SDK use the specified interface.

As I understand the SDK, this option is currently not supported. The SDK always uses the OS's default interface. I am surprised about this because it seems pretty reasonable to me to have the lidars plugged on a separate network interface.

Even if I manage to have the udp_dest field set up correctly, I still don't see how I can do the initial http requests to the lidars in the first place in order to initiate a connection (e.g. to fetch metadata), and how to tell the SDK to setup the UDP sockets to connect to the correct NIC. The only solution I currently see is forking the library.

Is there something I am missing? I was thinking that perhaps you expect people to solve this problem at the OS-level (e.g. network namespaces).

Platform (please complete the following information):

twslankard commented 1 year ago

Hi @marcomaida94, thanks for your patience.

I suspect you are working with link-local configuration. Is this correct?

In any case, Ouster SDK supports working with multiple network interfaces. However, this functionality depends on the OS's network routing configuration and is most easily accomplished using DHCP rather than link-local networking.

Option 1: separate subnets, DHCP (or static ip) networking

If you have unique subnets assigned to each network interface, and each sensor has an IP address from the subnet corresponding to the network interface to which it is attached, you should be free to use a separate instance of the client for each sensor without issues.

As an example, suppose you have two Ethernet interfaces enp5s0 and enp6s0 with subnets 192.168.100.0/24 and 192.168.101.0/24, and the sensors have the IP addresses 192.168.100.4 and 192.168.101.4. If the network routes are set up properly, you should be able to see something similar to the example below when running ip route to display the routing table:

...
192.168.100.0/24 dev enp5s0 proto kernel scope link src 192.168.100.2 metric 102 
192.168.101.0/24 dev enp6s0 proto kernel scope link src 192.168.101.2 metric 101 
...

Option 2: bridged interface

It's possible that link-local networking can be used with multiple interfaces, though this probably depends on bridging the two interfaces. To create a bridged network from two interfaces, one can add a new "virtual" network using Network Manager (e.g. in Ubuntu and similar Linux) by clicking the Plus (+) sign and selecting Bridge:

image

I imagine it's also possible to serve DHCP on a bridged interface, though I don't have personal experience with this. In any case, I would be curious if this works for your configuration if linked-local networking doesn't work out.)

Please let me know if any of the above can be clarified or if there are additional questions.

marcomaida94 commented 1 year ago

Hello @twslankard,

I got it to work. Thanks for the amazing support!

Marco

twslankard commented 1 year ago

It's a pleasure to help, @marcomaida94. Please let us know if there are any additional questions or issues.

Cheers, Tom