The canonical explanation is deeply buried in the RTPS spec (aka “DDS
Interoperability Protocol”), section 9.6.1:
http://www.omg.org/spec/DDSI-RTPS/2.2/PDF/
Four UDP ports are needed. The port numbers are a function of the DDS/RTPS
domain ID, which in ROS 2 is populated with the ROS_DOMAIN_ID environment
variable and defaults to zero.
The expressions and magic numbers are on pages 190-191 of the PDF (document
page numbers 178-179).
Best regards,
Morgan