RTPS
Real-Time Publish-Subscribe, the wire protocol of DDS (OMG DDSI-RTPS 2.x), added in 11.6.0 (#120) with the defense lot (#125). DDS is the middleware of recent combat system architectures (NGVA, GVA, naval systems) and of ROS 2, and RTPS succeeds GIOP/MIOP in that role. The module is packet_parser::parse::application::protocols::rtps. Since 13.0.0 its submodule dds also reads the DDS layer of a DATA: inline QoS, serialized data and discovery (#317, below).
Detection: a magic, then an exact tiling
An RTPS message fills one UDP datagram. As for PTP on UDP, the pipeline gives the datagram a label, "RTPS", and nothing more: the decode is RtpsPacket::try_from on the transport payload.
The rule is a blind probe, rule(ApplicationProtocol::Rtps, Guard::Udp, ProbeId::Rtps), in the blind cascade of the dispatch table, right after the blind NTP rule and, since 11.8.0, before the blind Valmet DNA rule, then ASTERIX. There is no port guard: Cyclone DDS and Connext Micro send between random unicast ports, which is why the dispatch probes blind (frame 9 below goes from 54020 to 58584, the Connext Micro capture of the corpus to 21914). What identifies RTPS is its first four bytes, then its structure:
#![allow(unused)] fn main() { ProbeId::Rtps => { (payload.starts_with(b"RTPS") || payload.starts_with(b"RTPX")) && RtpsPacket::try_from(payload).is_ok() } }
- the magic is a constant-cost guard, as for GIOP: the decoder only runs on a datagram that starts with
RTPS, or withRTPX, a variant RTI Connext emits; - the decoder reads the whole payload, never a
PROBE_CAPprefix of 18 KiB, which since 11.7.0 only the probes of the four text protocols keep: a 60 KBDATA_FRAGis still RTPS, and the six ofwireshark_15227_reassembly_one_each.pcapng, up to 65 064 bytes of payload, are labelled; - the submessages must tile the datagram exactly; a reserved
submessageId, a body too short for its kind, or a HEADER_EXTENSION out of place or with a wrongmessageLengthrefuses the message.
A refused message is not a corruption: the label is not given, the datagram goes on down the table and usually comes out "Unknown", with nothing in corrupted. RTPS is probed on UDP only, and there is no DecodeAsProtocol variant for it: a rule without a port guard has no port to extend.
Cyclone DDS on the macOS loopback, between two random ports (tested):
#![allow(unused)] fn main() { #[test] fn rtps_is_recognized_by_its_magic_on_any_udp_port() { // Frame 9 of talker-listener-rtps.pcapng: Cyclone DDS on the macOS // loopback (LINKTYPE_NULL), between two random unicast ports. let raw = hex::decode(CYCLONE_FRAME_9_HEX).unwrap(); let flow = parse(LinkType::NULL, &raw).unwrap(); let transport = flow.transport.as_ref().unwrap(); assert_eq!( (transport.source_port, transport.destination_port), (Some(54020), Some(58584)) ); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RTPS"); // The pipeline gives the label; the protocol parser decodes the payload. let payload = transport.payload.unwrap(); let RtpsPacket::Message(message) = RtpsPacket::try_from(payload).unwrap() else { panic!("expected a message, not a ping"); }; assert_eq!(&message.header.magic, b"RTPS"); assert_eq!((message.header.version_major, message.header.version_minor), (2, 1)); assert_eq!(message.header.vendor_id, 0x0110); // Eclipse Cyclone DDS // Four submessages tile the datagram after the 20-byte header, every // one of them little-endian (flag E). let kinds: Vec<SubmessageKind> = message.submessages.iter().map(|s| s.kind).collect(); assert_eq!( kinds, [ SubmessageKind::InfoDestination, SubmessageKind::InfoTimestamp, SubmessageKind::Data, SubmessageKind::Heartbeat, ] ); let bodies: Vec<usize> = message.submessages.iter().map(|s| s.body.len()).collect(); assert_eq!(bodies, [12, 8, 48, 28]); assert_eq!(20 + bodies.iter().map(|len| 4 + len).sum::<usize>(), payload.len()); assert!(message.submessages.iter().all(|s| s.little_endian)); let SubmessageDetails::InfoTimestamp { timestamp: Some(time) } = message.submessages[1].details else { panic!("expected an INFO_TS with a timestamp"); }; assert_eq!(time.seconds, 1_625_943_735); // 2021-07-10 19:02:15 UTC let SubmessageDetails::Data { reader_id, writer_id, writer_sequence_number, serialized_payload, .. } = message.submessages[2].details else { panic!("expected a DATA"); }; // The built-in participant message reader and writer, as tshark names them. assert_eq!((reader_id, writer_id), (0x0002_00c7, 0x0002_00c2)); assert_eq!(writer_sequence_number, 1); assert!(serialized_payload); assert!(matches!( message.submessages[3].details, SubmessageDetails::Heartbeat { first_sequence_number: 1, last_sequence_number: 1, count: 2, .. } )); } }
The message
#![allow(unused)] fn main() { pub enum RtpsPacket<'a> { Message(RtpsMessage<'a>), Ping(RtpsPing), } pub struct RtpsMessage<'a> { pub header: RtpsHeader, pub submessages: Vec<RtpsSubmessage<'a>>, // in wire order } pub struct RtpsHeader { pub magic: [u8; 4], // RTPS, or RTPX (RTI Connext) pub version_major: u8, pub version_minor: u8, pub vendor_id: u16, // 0x0101 RTI Connext, 0x0110 Cyclone DDS... pub guid_prefix: [u8; 12], } }
Every type of the module is #[non_exhaustive]. RtpsPacket::version() returns (major, minor), vendor_id() the vendor, and message() the message, None for a ping.
The header is the 20 bytes of DDSI-RTPS 2.5 §9.4.4:
| Bytes | Field | Note |
|---|---|---|
| 0–3 | magic | RTPS or RTPX; anything else is InvalidMagic |
| 4 | version_major | 2; anything else is UnsupportedVersion: RTPS 1.x, another format, is not decoded |
| 5 | version_minor | not checked: 1 in 230 frames of the corpus, 2 in the CoreDX one |
| 6–7 | vendor_id | big-endian |
| 8–19 | guid_prefix | the twelve bytes, as they are |
The RTI ping
RTI Connext also sends sixteen-byte "pings" to probe a participant: the magic, the version, the vendorId and the text NDDSPING, with neither guidPrefix nor submessage. They are outside the specification, but tshark counts them as RTPS, and so does the crate:
#![allow(unused)] fn main() { pub struct RtpsPing { pub magic: [u8; 4], pub version_major: u8, pub version_minor: u8, pub vendor_id: u16, pub text: [u8; 8], // NDDSPING } }
A payload of exactly 16 bytes ending with NDDSPING is an RtpsPacket::Ping, its magic and version still checked; sixteen bytes without the text are a truncated header, Truncated { expected: 20, actual: 16 }. The corpus has eight pings, seven in RTPS_Discovery.pcapng and one in rtps.pcap, all counted by the golden test; the one of rtps.pcap (tested):
#![allow(unused)] fn main() { #[test] fn the_rti_ping_is_rtps_without_submessages() { // Frame 1 of rtps.pcap: sixteen bytes, magic, version, vendorId, NDDSPING. let raw = hex::decode(RTI_PING_FRAME_1_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RTPS"); let payload = flow.transport.as_ref().unwrap().payload.unwrap(); assert_eq!(payload.len(), 16); let packet = RtpsPacket::try_from(payload).unwrap(); let RtpsPacket::Ping(ping) = &packet else { panic!("expected a ping"); }; assert_eq!(&ping.text, b"NDDSPING"); assert_eq!(packet.vendor_id(), 0x0101); // RTI Connext assert_eq!(packet.version(), (2, 1)); assert!(packet.message().is_none()); } }
Submessages
After the header, the message is a run of submessages, each introduced by four bytes (§9.4.5.1):
| Bytes | Field | Note |
|---|---|---|
| 0 | submessageId | gives kind; a reserved value is ReservedSubmessageId |
| 1 | flags | bit 0x01 is E, the byte order; the other bits depend on the kind |
| 2–3 | octetsToNextHeader | the length of the body, in the byte order of E |
#![allow(unused)] fn main() { pub struct RtpsSubmessage<'a> { pub kind: SubmessageKind, pub id: u8, pub flags: u8, pub little_endian: bool, // flag E pub octets_to_next_header: u16, // as carried by the wire pub body: &'a [u8], // after the four header bytes, zero-copy pub details: SubmessageDetails, } }
Byte order: one flag per submessage
little_endian is flag E, flags & 0x01. Each submessage chooses its own byte order, and the crate reads in it every number of the submessage: octetsToNextHeader, sequence numbers, counts, fragment numbers and sizes, numBits, timestamps. A SequenceNumber_t is a signed high half then an unsigned low half, each in that order, returned as an i64. Three fields do not follow E: the entity ids, kept as the four octets of the EntityId_t read big-endian (0x000003c2 for the built-in publications writer, for instance), the vendorId, big-endian in INFO_SRC as in the header, and the checksum of a HEADER_EXTENSION, big-endian too. All 544 submessages of the corpus set E: only the crate's unit tests, on synthetic bytes, read big-endian ones.
octetsToNextHeader: a length, or zero
The body is octetsToNextHeader bytes long. Zero means that the submessage runs to the end of the message, which only the last one can do, except for PAD and INFO_TS, where zero is an empty body. octets_to_next_header keeps what the wire carries, body what it covers; a length beyond the end of the datagram is SubmessageOverflow. The thirteen zeros of the corpus are the final DATA of the thirteen OpenDDS messages; the first of them (tested):
#![allow(unused)] fn main() { #[test] fn a_zero_octets_to_next_header_runs_to_the_end_of_the_message() { // Frame 1 of wireshark_6449_opendds_messenger.pcap: OpenDDS, an INFO_TS // then a DATA whose octetsToNextHeader is 0. let raw = hex::decode(OPENDDS_FRAME_1_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RTPS"); let payload = flow.transport.as_ref().unwrap().payload.unwrap(); let packet = RtpsPacket::try_from(payload).unwrap(); assert_eq!(packet.vendor_id(), 0x0103); // OpenDDS let message = packet.message().expect("a message, not a ping"); let data = &message.submessages[1]; assert_eq!(data.kind, SubmessageKind::Data); assert_eq!(data.flags, 0x0b); // K, Q and E assert_eq!(data.octets_to_next_header, 0); // as carried by the wire... assert_eq!(data.body.len(), payload.len() - 20 - (4 + 8) - 4); // ...to the end let SubmessageDetails::Data { writer_id, writer_sequence_number, inline_qos, serialized_payload, serialized_key, .. } = data.details else { panic!("expected a DATA"); }; assert_eq!(writer_id, 0x0000_0102); // high = -1, low = 0: `tshark -T fields` prints -4294967296 too. assert_eq!(writer_sequence_number, -4_294_967_296); assert!(inline_qos && serialized_key && !serialized_payload); } }
The sequence number of that DATA has a high half of −1, like those of frames 12 and 13, the two other DATA of the capture that carry a key and no data: −4 294 967 296 as an i64, which is also what tshark -T fields prints, where tshark -V shows the unsigned 18 446 744 069 414 584 320.
Kinds and their fields
SubmessageKind names the identifiers of DDSI-RTPS 2.5, of DDS Security 1.1 and of the vendor range; the HEADER_EXTENSION that RTPS 2.5 adds at 0x00 has been among them since 11.7.0 (#186), and has its own section. SubmessageDetails decodes, for the kinds of the specification, the entity ids, sequence numbers, counters, timestamps and fragmentation fields, once the body has been checked to be long enough for them:
submessageId | SubmessageKind | SubmessageDetails | Minimum body |
|---|---|---|---|
0x00 HEADER_EXTENSION | HeaderExtension | HeaderExtension(RtpsHeaderExtension) | the fields its flags announce, 0 to 40 |
0x15 DATA | Data | Data { reader_id, writer_id, writer_sequence_number, inline_qos, serialized_payload, serialized_key } | 20 |
0x16 DATA_FRAG | DataFrag | DataFrag { reader_id, writer_id, writer_sequence_number, fragment_starting_number, fragments_in_submessage, fragment_size, sample_size } | 32 |
0x07 HEARTBEAT | Heartbeat | Heartbeat { reader_id, writer_id, first_sequence_number, last_sequence_number, count } | 28 |
0x06 ACKNACK | AckNack | AckNack { reader_id, writer_id, bitmap_base, num_bits, count, final_flag } | 24 + bitmap |
0x08 GAP | Gap | Gap { reader_id, writer_id, gap_start, gap_list_base, num_bits } | 28 + bitmap |
0x13 HEARTBEAT_FRAG | HeartbeatFrag | HeartbeatFrag { reader_id, writer_id, writer_sequence_number, last_fragment_number, count } | 24 |
0x12 NACK_FRAG | NackFrag | NackFrag { reader_id, writer_id, writer_sequence_number, fragment_number_base, num_bits, count } | 28 + bitmap |
0x09 INFO_TS | InfoTimestamp | InfoTimestamp { timestamp: Option<RtpsTime> } | 8; nothing with flag I |
0x0e INFO_DST | InfoDestination | InfoDestination { guid_prefix } | 12 |
0x0c INFO_SRC | InfoSource | InfoSource { version_major, version_minor, vendor_id, guid_prefix } | 20 |
0x0d INFO_REPLY_IP4 | InfoReplyIp4 | Opaque | 8 |
0x0f INFO_REPLY | InfoReply | Opaque | 4 |
0x01 PAD | Pad | Opaque | — |
0x30–0x34 | SecureBody, SecurePrefix, SecurePostfix, SecureRtpsPrefix, SecureRtpsPostfix | Opaque | — |
0x80–0xff | VendorSpecific(id) | Opaque | — |
| any other | — | — | ReservedSubmessageId |
The bitmap of a SequenceNumberSet or a FragmentNumberSet is numBits rounded up to 32-bit words, 4 × ⌈numBits / 32⌉ bytes, and the count of an ACKNACK or a NACK_FRAG comes after it: the crate checks that the bitmap fits before reading the count. An RtpsTime is seconds: u32 and fraction: u32, in 2⁻³² s. Of the flags, details exposes Q, D and K of a DATA (inline_qos, serialized_payload, serialized_key), F of an ACKNACK (final_flag) and I of an INFO_TS (timestamp: None); the others stay in flags. What follows the fixed fields stays in body, as raw bytes. For a DATA and a DATA_FRAG, the DDS layer reads the inline QoS and the serialized data from there, on demand.
Nine kinds occur in the corpus, a list the golden test checks; over its 223 messages, INFO_TS appears 159 times, DATA 153, INFO_DST 96, HEARTBEAT 64, ACKNACK 61, DATA_FRAG 6, GAP 3, INFO_SRC once and the vendor submessage 0x80 of CoreDX once. HEADER_EXTENSION, HEARTBEAT_FRAG, NACK_FRAG, PAD, the two INFO_REPLY and the security submessages occur in no capture.
The header extension
RTPS 2.5 adds a submessage that extends the header (§8.3.3.2, §8.3.7 and §9.4.5.2): the length of the message, a send timestamp, two extension fields of 4 and 8 bytes, a checksum and parameters. In 11.6.0 the crate refused it as ReservedSubmessageId { id: 0, offset: 20 }, and the datagram came out "Unknown". Since 11.7.0 its fields are in SubmessageDetails::HeaderExtension:
#![allow(unused)] fn main() { pub struct RtpsHeaderExtension { pub message_length: Option<u32>, // L pub send_timestamp: Option<RtpsTime>, // T pub u_extension: Option<[u8; 4]>, // U pub w_extension: Option<[u8; 8]>, // W pub checksum: Option<RtpsChecksum>, // C1, C2 pub parameters: bool, // P } pub enum RtpsChecksum { Crc32c(u32), // C2 alone Crc64Xz(u64), // C1 alone Md5([u8; 16]), // C1 and C2 } }
Each field is present when its flag is set, in this order on the wire:
| Flag | Bit | Field | Bytes | Read as |
|---|---|---|---|---|
| E | 0x01 | — | — | the byte order of the submessage |
| L | 0x02 | message_length | 4 | u32, in the order of E |
| T | 0x04 | send_timestamp | 8 | RtpsTime, in the order of E |
| U | 0x08 | u_extension | 4 | raw bytes |
| W | 0x10 | w_extension | 8 | raw bytes |
| C2, C1 | 0x20, 0x40 | checksum | 4, 8 or 16 | big-endian whatever E (Table 9.8): CRC-32C, CRC-64/XZ or MD5 |
| P | 0x80 | parameters | the rest of the body | a ParameterList, raw: header_extension_parameters() |
A body shorter than the fields its flags announce is SubmessageTooShort. Bytes after them, without P, are accepted and stay in body. RtpsSubmessage::header_extension_parameters() returns the ParameterList of a HEADER_EXTENSION whose P flag is set, as raw bytes: its parameters, the final PID_SENTINEL included, are neither decoded nor checked. Any other submessage, or no P flag, gives None.
The checksum is not verified: the decoder reads it and keeps it, it does not compute a CRC or an MD5 over the message. Two other things are checked, which tshark 4.6.6 does not check:
- the position: a HEADER_EXTENSION comes right after the header, at offset 20, or not at all (§8.3.3.2, §8.3.7.3); anywhere else it is
MisplacedHeaderExtension { offset }; - the
messageLength, when L is set: one message per UDP datagram (§9.5), so it must equal the length of the datagram, elseHeaderExtensionLengthMismatch { declared, actual }.
No capture of the corpus carries a HEADER_EXTENSION (rtps.sm.id == 0x00: no frame), so the golden test and the histogram did not move. One, put by hand into frame 9 (tested):
#![allow(unused)] fn main() { #[test] fn a_header_extension_right_after_the_header() { // No capture of the corpus carries a HEADER_EXTENSION. This one is put // by hand between the header and the first submessage of frame 9, // little-endian like the rest of the message, with flags L and C2. let raw = hex::decode(CYCLONE_FRAME_9_HEX).unwrap(); let frame_9 = &raw[4 + 20 + 8..]; let mut payload = frame_9[..20].to_vec(); payload.extend_from_slice(&[0x00, 0x23, 8, 0]); // id, flags C2 | L | E, 8 bytes payload.extend_from_slice(&144u32.to_le_bytes()); // messageLength, in the order of E payload.extend_from_slice(&[0xde, 0xad, 0xbe, 0xef]); // a CRC-32C nobody computed payload.extend_from_slice(&frame_9[20..]); assert_eq!(payload.len(), 144); let packet = RtpsPacket::try_from(payload.as_slice()).unwrap(); let message = packet.message().expect("a message, not a ping"); assert_eq!(message.submessages.len(), 5); let extension = &message.submessages[0]; assert_eq!(extension.kind, SubmessageKind::HeaderExtension); let SubmessageDetails::HeaderExtension(fields) = extension.details else { panic!("expected a HEADER_EXTENSION, got {:?}", extension.details); }; assert_eq!(fields.message_length, Some(144)); // the length of the datagram // Read big-endian whatever E, and not verified: the message is accepted. assert_eq!(fields.checksum, Some(RtpsChecksum::Crc32c(0xdead_beef))); assert_eq!(fields.send_timestamp, None); // no flag T assert_eq!((fields.u_extension, fields.w_extension), (None, None)); assert!(!fields.parameters); assert_eq!(extension.header_extension_parameters(), None); assert_eq!(message.submessages[1].kind, SubmessageKind::InfoDestination); // Flag P alone: a ParameterList, here its PID_SENTINEL only, kept raw. let mut payload = frame_9[..20].to_vec(); payload.extend_from_slice(&[0x00, 0x81, 4, 0, 0x01, 0x00, 0x00, 0x00]); payload.extend_from_slice(&frame_9[20..]); let packet = RtpsPacket::try_from(payload.as_slice()).unwrap(); let extension = &packet.message().unwrap().submessages[0]; assert_eq!(extension.header_extension_parameters(), Some(&[0x01, 0x00, 0x00, 0x00][..])); // Every flag but P, on the INFO_DST of frame 9 turned HEADER_EXTENSION: // 4 + 8 + 4 + 8 + 16 bytes of fields, in a body of 12. let mut too_short = frame_9.to_vec(); too_short[20..22].copy_from_slice(&[0x00, 0x7f]); assert_eq!( RtpsPacket::try_from(too_short.as_slice()), Err(RtpsParseError::SubmessageTooShort { id: 0x00, offset: 20, expected: 40, actual: 12, }) ); } }
Validations
The decoder of the message returns nine variants of RtpsParseError, in packet_parser::errors::application::rtps. The five others, added in 13.0.0, come from the DDS layer and never refuse a message.
| Error | When |
|---|---|
Truncated { expected, actual } | fewer than the 20 bytes of the header, or fewer than the four bytes of a submessage header where one must start (expected counts from the start of the message) |
InvalidMagic([u8; 4]) | the first four bytes are neither RTPS nor RTPX |
UnsupportedVersion { major, minor } | the major version is not 2 |
NoSubmessage | a header and nothing after it |
ReservedSubmessageId { id, offset } | an identifier that is neither one of DDSI-RTPS 2.5, HEADER_EXTENSION included, nor 0x30–0x34 (DDS Security), nor 0x80–0xff |
SubmessageOverflow { id, offset, declared, available } | octetsToNextHeader beyond the end of the message |
SubmessageTooShort { id, offset, expected, actual } | a body shorter than its kind requires (entity ids, sequence numbers, bitmap, the fields of a HEADER_EXTENSION) |
MisplacedHeaderExtension { offset } | a HEADER_EXTENSION that is not the first submessage (added in 11.7.0) |
HeaderExtensionLengthMismatch { declared, actual } | a HEADER_EXTENSION whose messageLength is not the length of the datagram (added in 11.7.0) |
The refusal of an unknown identifier departs from the specification: rule 3 of DDSI-RTPS 2.5 §8.3.4.1 asks a receiver to ignore a submessage whose submessageId it does not know and to go on with the next one. The crate refuses the message instead, because the closed table of identifiers is part of the signature its blind probe relies on.
The probe only asks whether the decode succeeds, so any of them means "not RTPS". Each one on the bytes of frame 9, one modification at a time (tested):
#![allow(unused)] fn main() { #[test] fn a_message_that_does_not_tile_its_datagram_is_refused() { // The 132-byte payload of frame 9 of talker-listener-rtps.pcapng, then // one modification at a time. let raw = hex::decode(CYCLONE_FRAME_9_HEX).unwrap(); let payload = &raw[4 + 20 + 8..]; // after LINKTYPE_NULL, IPv4 and UDP assert_eq!(payload.len(), 132); assert_eq!(RtpsPacket::try_from(&payload[..20]), Err(RtpsParseError::NoSubmessage)); let mut other_magic = payload.to_vec(); other_magic[..4].copy_from_slice(b"GIOP"); assert_eq!( RtpsPacket::try_from(other_magic.as_slice()), Err(RtpsParseError::InvalidMagic(*b"GIOP")) ); let mut version_1 = payload.to_vec(); version_1[4] = 1; // RTPS 1.x, another format assert_eq!( RtpsPacket::try_from(version_1.as_slice()), Err(RtpsParseError::UnsupportedVersion { major: 1, minor: 1 }) ); let mut reserved = payload.to_vec(); reserved[20] = 0x02; // the first submessageId assert_eq!( RtpsPacket::try_from(reserved.as_slice()), Err(RtpsParseError::ReservedSubmessageId { id: 0x02, offset: 20 }) ); // 0x00 is the HEADER_EXTENSION of RTPS 2.5: the first submessage or none. let mut misplaced = payload.to_vec(); misplaced[36] = 0x00; // the INFO_TS at offset 36 assert_eq!( RtpsPacket::try_from(misplaced.as_slice()), Err(RtpsParseError::MisplacedHeaderExtension { offset: 36 }) ); let mut wrong_length = payload.to_vec(); wrong_length[20..22].copy_from_slice(&[0x00, 0x03]); // first, with flags L and E wrong_length[24..28].copy_from_slice(&131u32.to_le_bytes()); // its messageLength assert_eq!( RtpsPacket::try_from(wrong_length.as_slice()), Err(RtpsParseError::HeaderExtensionLengthMismatch { declared: 131, actual: 132 }) ); let mut overflow = payload.to_vec(); overflow[22] = 200; // INFO_DST declares 200 bytes instead of 12 assert_eq!( RtpsPacket::try_from(overflow.as_slice()), Err(RtpsParseError::SubmessageOverflow { id: 0x0e, offset: 20, declared: 200, available: 108, }) ); let mut short = payload[..124].to_vec(); short[102] = 20; // the HEARTBEAT at offset 100 keeps 20 of its 28 bytes assert_eq!( RtpsPacket::try_from(short.as_slice()), Err(RtpsParseError::SubmessageTooShort { id: 0x07, offset: 100, expected: 28, actual: 20, }) ); let mut longer = payload.to_vec(); longer.push(0); // one byte cannot hold a submessage header assert_eq!( RtpsPacket::try_from(longer.as_slice()), Err(RtpsParseError::Truncated { expected: 136, actual: 133 }) ); // In the frame, a refused message is not RTPS, and not a corruption // either: the datagram goes on to the next rules. let mut frame = raw.clone(); frame[4 + 20 + 8 + 22] = 200; let flow = parse(LinkType::NULL, &frame).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "Unknown"); assert!(flow.corrupted.is_none()); } }
The DDS layer
RTPS carries DDS. A DATA holds a sample of a topic, sometimes with inline QoS. The DATA of the discovery writers say what a participant announces of itself and of its endpoints. Since 13.0.0 the module rtps::dds reads them (#317).
Detection does not change. The probe and RtpsPacket::try_from stop at the submessages, as above. The DDS layer is decoded on demand, from an RtpsSubmessage, by three methods:
| Method | Gives | None for |
|---|---|---|
inline_qos() | the ParameterList of a DATA or a DATA_FRAG with flag Q | any other submessage; no flag Q |
serialized_payload() | the encapsulation header and the data of a DATA with flag D or K, or of a DATA_FRAG that starts at fragment 1 | any other submessage; a DATA with neither D nor K; a later fragment |
discovery() | the built-in topic and the ParameterList of a DATA from an SPDP or SEDP writer | another writer; a DATA_FRAG; a DATA with neither data nor key |
Each one returns Option<Result<_, RtpsParseError>>. None means that the submessage carries nothing of the kind. Err means that what it carries is malformed: the message stays RTPS, and its frame keeps its label. Every slice they return borrows from body. The types of rtps::dds are #[non_exhaustive], like the others.
Where the data starts
A DATA, like a DATA_FRAG, starts with extraFlags and octetsToInlineQos, two bytes each, before its entity ids and its sequence number. octetsToInlineQos counts from the byte after it. The crate checks that it points between the end of the fixed fields and the end of the body:
| Submessage | Fixed fields | octetsToInlineQos accepted |
|---|---|---|
| DATA | 20 bytes | 16 to body.len() − 4 |
| DATA_FRAG | 32 bytes | 28 to body.len() − 4 |
Any other value is InvalidOctetsToInlineQos. With flag Q, the inline QoS start there, and the data follow their PID_SENTINEL. Without it, the data start there. Frame 3 above carries 16: its data start right after the 20 fixed bytes. SubmessageDetails exposes neither extraFlags nor octetsToInlineQos.
Inline QoS
inline_qos() reads the ParameterList of flag Q, an RtpsParameterList like the data of discovery. Its headers and values are in the byte order of the submessage, flag E. tshark finds inline QoS in 17 frames of the corpus, with two PIDs only:
| PID | Accessor | Frames |
|---|---|---|
0x0070 PID_KEY_HASH | key_hash() | 14 |
0x0071 PID_STATUS_INFO | status_info() | 4 |
The example of the refusals starts with one of them: an RTI Connext participant that leaves.
The serialized payload
serialized_payload() decodes the four-byte encapsulation header, then keeps what follows:
#![allow(unused)] fn main() { pub struct RtpsSerializedPayload<'a> { pub encapsulation: RtpsEncapsulation, // the representation identifier, bytes 0-1 pub options: u16, // the representation options, bytes 2-3 pub data: &'a [u8], // the rest } }
- The header is big-endian, whatever flag E.
optionsis kept as carried.dataruns to the end of the submessage, padding included. For a DATA_FRAG, it stops at the end of the first fragment.RtpsSerializedPayload::parsedoes the same on any bytes.
RtpsEncapsulation names the representation identifiers of DDS-XTypes 1.3 (Table 60):
| Identifier | RtpsEncapsulation | name() | Data |
|---|---|---|---|
0x0000, 0x0001 | CdrBe, CdrLe | CDR_BE, CDR_LE | classic CDR |
0x0002, 0x0003 | PlCdrBe, PlCdrLe | PL_CDR_BE, PL_CDR_LE | a ParameterList, which parameters() decodes |
0x0004 | Xml | XML | XML |
0x0010, 0x0011 | Cdr2Be, Cdr2Le | CDR2_BE, CDR2_LE | XCDR2 |
0x0012, 0x0013 | PlCdr2Be, PlCdr2Le | PL_CDR2_BE, PL_CDR2_LE | XCDR2 of a mutable type: EMHEADERs, not a ParameterList |
0x0014, 0x0015 | DCdr2Be, DCdr2Le | D_CDR2_BE, D_CDR2_LE | XCDR2 of an appendable type: a DHEADER first |
| any other | Other(code) | None | unknown |
code() gives the identifier back. little_endian() gives the byte order of the data: Some(false) for the Be forms, Some(true) for the Le ones, None for XML and Other. is_parameter_list() is true for the two PL_CDR only, and parameters() is None for any other encapsulation.
The DDS oracle of the corpus holds 155 encapsulation headers:
| Encapsulation | Headers |
|---|---|
PL_CDR_LE (0x0003) | 101, the discovery announcements |
CDR_LE (0x0001) | 54 |
| any other | 0 |
Discovery: SPDP and SEDP
discovery() recognizes the writer of a DATA by its entity id (DDSI-RTPS 2.5 §9.3.1.4, and DDS Security 1.1 for the secure writers):
| Writer entity id | RtpsBuiltinTopic | name() |
|---|---|---|
0x000100c2; secure 0xff0101c2 | Participant (SPDP) | DCPSParticipant |
0x000002c2 | Topic (SEDP) | DCPSTopic |
0x000003c2; secure 0xff0003c2 | Publication (SEDP) | DCPSPublication |
0x000004c2; secure 0xff0004c2 | Subscription (SEDP) | DCPSSubscription |
Any other writer gives None, the participant message writer 0x000200c2 of frame 9 among them. RtpsBuiltinTopic::from_writer is the same table, on its own.
#![allow(unused)] fn main() { pub struct RtpsDiscovery<'a> { pub topic: RtpsBuiltinTopic, pub secure: bool, // a DDS Security writer, 0xff...... pub key_only: bool, // flag K without flag D pub encapsulation: RtpsEncapsulation, // PL_CDR, big- or little-endian pub parameters: RtpsParameterList<'a>, } }
- The data must be PL_CDR. Any other encapsulation is
NotAParameterList. - The list is read in the byte order of the encapsulation, not of the submessage.
key_onlymarks a key alone: a participant or an endpoint that leaves.
The ParameterList
Inline QoS and discovery data are both an RtpsParameterList (§9.4.2.11):
#![allow(unused)] fn main() { pub struct RtpsParameterList<'a> { pub bytes: &'a [u8], // the parameters, without the PID_SENTINEL pub little_endian: bool, } pub struct RtpsParameter<'a> { pub id: u16, pub value: &'a [u8], // the length the header announces pub little_endian: bool, // the order of the list } }
The list is checked once, when it is decoded:
- every parameter fits in the list, its header and the value its length announces;
- a PID_SENTINEL ends it;
- the length of the sentinel is ignored, and so is what follows it.
RtpsParameterList::parse does the same on any bytes, and also returns the bytes it consumed, sentinel included. iter() gives the parameters in wire order, without the sentinel. get(id) gives the first one with that id. Two bits of its id are flags (§9.6.2.2.1), and name() names it:
| Method | Bit | Meaning |
|---|---|---|
is_vendor_specific() | 15, 0x8000 | a PID of the implementation that the vendorId names |
must_understand() | 14, 0x4000 | a receiver that does not understand it must ignore the whole submessage |
name() | — | its name in the specification, PID_TOPIC_NAME for instance, one of the 64 it knows; None for a vendor PID or an unknown one |
The crate reports the must-understand bit. It does not act on it.
A parameter reads its own value with string(), u32_value(), guid(), duration() and locator(). The list has fifteen typed accessors. Each one reads the first parameter of its PID, and gives None when it is absent or its value too short:
| Accessor | PID | Returns |
|---|---|---|
topic_name() | 0x0005 PID_TOPIC_NAME | &[u8], a CDR string without its NUL |
type_name() | 0x0007 PID_TYPE_NAME | &[u8] |
entity_name() | 0x0062 PID_ENTITY_NAME | &[u8] |
participant_guid() | 0x0050 PID_PARTICIPANT_GUID | [u8; 16]: guidPrefix, then entity id |
endpoint_guid() | 0x005a PID_ENDPOINT_GUID | [u8; 16] |
key_hash() | 0x0070 PID_KEY_HASH | [u8; 16], the GUID itself for a built-in topic |
status_info() | 0x0071 PID_STATUS_INFO | RtpsStatusInfo, read big-endian: disposed(), unregistered(), filtered() |
domain_id() | 0x000f PID_DOMAIN_ID | u32 |
protocol_version() | 0x0015 PID_PROTOCOL_VERSION | (u8, u8) |
vendor_id() | 0x0016 PID_VENDORID | u16, read big-endian, like the header's |
builtin_endpoint_set() | 0x0058 PID_BUILTIN_ENDPOINT_SET | u32, one bit per built-in endpoint |
participant_lease_duration() | 0x0002 PID_PARTICIPANT_LEASE_DURATION | RtpsDuration |
reliability() | 0x001a PID_RELIABILITY | RtpsReliability { kind, max_blocking_time } |
durability() | 0x001d PID_DURABILITY | RtpsDurabilityKind |
locators() | the six locator PIDs below | an iterator of (RtpsLocatorRole, RtpsLocator), in wire order |
Strings are bytes: nothing checks that they are UTF-8. The other value types:
RtpsDurationisseconds: i32andfraction: u32, in 2⁻³² s.is_infinite()tests DURATION_INFINITE:0x7fffffffseconds and a fraction of0xffffffff.RtpsLocatoriskind: i32,port: u32andaddress: [u8; 16].ipv4()reads the last four bytes of a kind 1 locator,ipv6()the sixteen of a kind 2 one. Other kinds keep their bytes.RtpsReliabilityKindkeeps the values of the wire:BestEffortis 1,Reliable2.max_blocking_timeisNonefor a four-byte value.RtpsDurabilityKindisVolatile,TransientLocal,TransientorPersistent, 0 to 3.- Both kinds have an
Other(u32)for any other value.
The PID of a locator gives its role:
| PID | RtpsLocatorRole | Reaches |
|---|---|---|
0x002f, 0x0030 | Unicast, Multicast | the data of an endpoint |
0x0031, 0x0048 | DefaultUnicast, DefaultMulticast | the data of the participant's endpoints, by default |
0x0032, 0x0033 | MetatrafficUnicast, MetatrafficMulticast | the metatraffic of the participant: discovery, heartbeats, acknowledgements |
Frame 3 of talker-listener-rtps.pcapng is the SPDP announcement of the participant of frame 9, to 239.255.0.1:7400. It names no entity. Two of its eleven parameters, 0x8007 and 0x8019, belong to Cyclone DDS (tested):
#![allow(unused)] fn main() { #[test] fn a_participant_announces_itself_through_spdp() { // Frame 3 of talker-listener-rtps.pcapng: the participant of frame 9 // announces itself to the SPDP multicast group, an INFO_TS then a DATA. let raw = hex::decode(CYCLONE_FRAME_3_HEX).unwrap(); let flow = parse(LinkType::NULL, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RTPS"); let payload = flow.transport.as_ref().unwrap().payload.unwrap(); let packet = RtpsPacket::try_from(payload).unwrap(); let message = packet.message().expect("a message, not a ping"); let data = &message.submessages[1]; assert_eq!(data.kind, SubmessageKind::Data); // Decoded on demand, from the submessage: the writer 0x000100c2 is SPDP's. assert!(data.inline_qos().is_none()); // no flag Q let discovery = data.discovery().expect("an SPDP writer").unwrap(); assert_eq!(discovery.topic, RtpsBuiltinTopic::Participant); assert_eq!(discovery.topic.name(), "DCPSParticipant"); assert_eq!(discovery.encapsulation, RtpsEncapsulation::PlCdrLe); assert!(!discovery.secure && !discovery.key_only); let list = discovery.parameters; let guid = list.participant_guid().unwrap(); assert_eq!(guid[..12], message.header.guid_prefix); // the sender itself assert_eq!(guid[12..], [0x00, 0x00, 0x01, 0xc1]); // ENTITYID_PARTICIPANT assert_eq!(list.vendor_id(), Some(0x0110)); // Cyclone DDS assert_eq!(list.protocol_version(), Some((2, 1))); assert_eq!(list.domain_id(), Some(0)); assert_eq!(list.builtin_endpoint_set(), Some(0x0000_0c3f)); let lease = list.participant_lease_duration().unwrap(); assert_eq!((lease.seconds, lease.fraction), (10, 0)); assert_eq!(list.entity_name(), None); // Cyclone DDS sends none // Where to reach the participant: its data, and its metatraffic. let locators: Vec<(RtpsLocatorRole, Option<Ipv4Addr>, u32)> = list .locators() .map(|(role, locator)| (role, locator.ipv4(), locator.port)) .collect(); let host = Some(Ipv4Addr::new(10, 0, 0, 46)); assert_eq!( locators, [ (RtpsLocatorRole::DefaultUnicast, host, 61_329), (RtpsLocatorRole::MetatrafficUnicast, host, 61_329), ] ); // Every parameter in wire order, the PID_SENTINEL left out. let ids: Vec<u16> = list.iter().map(|parameter| parameter.id).collect(); assert_eq!( ids, [0x002c, 0x0015, 0x0016, 0x0002, 0x0050, 0x0058, 0x000f, 0x0031, 0x0032, 0x8007, 0x8019] ); // Bit 15: two PIDs of Cyclone DDS, which the specification does not name. let vendor: Vec<u16> = list .iter() .filter(|parameter| parameter.is_vendor_specific()) .map(|parameter| parameter.id) .collect(); assert_eq!(vendor, [0x8007, 0x8019]); assert!(list.iter().all(|parameter| !parameter.must_understand())); assert_eq!(list.get(0x8007).unwrap().name(), None); // A PID without an accessor: its value, borrowed. ROS 2 writes its // enclave in PID_USER_DATA, a sequence of 10 octets. let user_data = list.get(0x002c).unwrap(); assert_eq!(user_data.name(), Some("PID_USER_DATA")); assert_eq!(user_data.u32_value(), Some(10)); assert_eq!(&user_data.value[4..14], b"enclave=/;"); } }
A publication, then its first sample
Frame 57 of the same capture is SEDP. The participant announces a writer of the topic rt/chatter, the one of the ROS 2 talker. Its endpoint GUID ends with the entity id 0x00001503. Frame 70 is a DATA of that writer, its first sample. A user writer is not a discovery one: discovery() is None (tested):
#![allow(unused)] fn main() { #[test] fn a_publication_announced_by_sedp_then_its_first_sample() { /// The UDP payload of a LINKTYPE_NULL frame the pipeline labels RTPS. fn datagram(raw: &[u8]) -> &[u8] { let flow = parse(LinkType::NULL, raw).unwrap(); assert_eq!(flow.application.unwrap().protocol.label(), "RTPS"); flow.transport.unwrap().payload.unwrap() } // Frame 57 of talker-listener-rtps.pcapng: the SEDP publications // writer, 0x000003c2, announces a writer of the participant. let raw = hex::decode(CYCLONE_FRAME_57_HEX).unwrap(); let packet = RtpsPacket::try_from(datagram(&raw)).unwrap(); let message = packet.message().unwrap(); let discovery = message.submessages[1].discovery().expect("an SEDP writer").unwrap(); assert_eq!(discovery.topic, RtpsBuiltinTopic::Publication); let list = discovery.parameters; assert_eq!(list.topic_name(), Some(&b"rt/chatter"[..])); assert_eq!(list.type_name(), Some(&b"std_msgs::msg::dds_::String_"[..])); let writer = list.endpoint_guid().unwrap(); assert_eq!(writer[..12], message.header.guid_prefix); assert_eq!(writer[12..], [0x00, 0x00, 0x15, 0x03]); // a user writer, no key let reliability = list.reliability().unwrap(); assert_eq!(reliability.kind, RtpsReliabilityKind::Reliable); assert!(reliability.max_blocking_time.unwrap().is_infinite()); assert_eq!(list.durability(), None); // no PID_DURABILITY in the list // Frame 70: a DATA of that writer. A user writer: no discovery, and // a payload that is not a ParameterList. let raw = hex::decode(CYCLONE_FRAME_70_HEX).unwrap(); let packet = RtpsPacket::try_from(datagram(&raw)).unwrap(); let data = &packet.message().unwrap().submessages[1]; let SubmessageDetails::Data { writer_id, .. } = data.details else { panic!("expected a DATA"); }; assert_eq!(writer_id.to_be_bytes(), writer[12..]); assert_eq!(data.discovery(), None); let payload = data.serialized_payload().expect("flag D").unwrap(); assert_eq!(payload.encapsulation, RtpsEncapsulation::CdrLe); assert_eq!(payload.encapsulation.name(), Some("CDR_LE")); assert_eq!(payload.encapsulation.little_endian(), Some(true)); assert_eq!(payload.options, 0); assert_eq!(payload.parameters(), None); // PL_CDR only // The crate stops at the bytes. The IDL of std_msgs/String reads // them as a CDR string: a u32 length, NUL included, then the text. assert_eq!(payload.data.len(), 20); // to the end of the submessage let length = u32::from_le_bytes(payload.data[..4].try_into().unwrap()) as usize; assert_eq!(&payload.data[4..4 + length], b"Hello World: 1\0"); } }
User data stays bytes
The crate stops at the encapsulation header of a user type. Its data is &[u8]: without the IDL of the type, nothing says how to read it. The example above reads its std_msgs/String by hand, a CDR string, Hello World: 1. The key of a user instance, flag K, stays bytes too. So do the XCDR2 and XML forms, which are named and not decoded.
Refusals of the DDS layer
Five variants were added at the end of RtpsParseError in 13.0.0. Only the DDS layer returns them, never RtpsPacket::try_from:
| Error | When | Returned by |
|---|---|---|
InvalidOctetsToInlineQos { octets_to_inline_qos, body } | octetsToInlineQos points into the fixed fields, or beyond the body | the three methods |
ParameterTruncated { offset, expected, actual } | a parameter header, or the value its length announces, overflows the list; offset counts from the start of the list | the three methods, RtpsParameterList::parse |
ParameterListUnterminated { length } | a list without PID_SENTINEL | the three methods, RtpsParameterList::parse |
SerializedPayloadTooShort { actual } | serialized data shorter than the four bytes of the encapsulation header | serialized_payload(), discovery(), RtpsSerializedPayload::parse |
NotAParameterList { encapsulation } | the data of a discovery writer are not PL_CDR | discovery() |
serialized_payload() and discovery() return the errors of a list too: they read the inline QoS to find where the data start. A refusal here refuses nothing else. The message still decodes, the probe still says RTPS, and the frame is not corrupted.
Frame 29 of rtps.pcap first, an RTI Connext participant that leaves: a DATA of the SPDP writer with inline QoS only. Then each refusal on its bytes, and NotAParameterList on those of frame 70 (tested):
#![allow(unused)] fn main() { #[test] fn inline_qos_and_the_refusals_of_the_dds_layer() { /// The DATA of a message, which must still decode as RTPS. fn data_of(message: &[u8]) -> RtpsSubmessage<'_> { let packet = RtpsPacket::try_from(message).expect("still an RTPS message"); packet.message().unwrap().submessages[1] } // Frame 29 of rtps.pcap: an RTI Connext participant leaves. Its SPDP // writer sends a DATA with flags Q and E, neither data nor key: the // inline QoS alone say which instance, and what happened to it. let raw = hex::decode(RTI_FRAME_29_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RTPS"); let payload = flow.transport.as_ref().unwrap().payload.unwrap(); let data = data_of(payload); assert_eq!(data.flags, 0x03); let qos = data.inline_qos().expect("flag Q").unwrap(); assert!(qos.little_endian); // the byte order of the submessage let key = qos.key_hash().unwrap(); // the GUID of the participant assert_eq!(key[..12], payload[8..20]); // the guidPrefix of the header let status = qos.status_info().unwrap(); assert_eq!(status.flags, 0x03); assert!(status.disposed() && status.unregistered() && !status.filtered()); assert_eq!(data.serialized_payload(), None); // neither D nor K assert_eq!(data.discovery(), None); // The 88-byte message: the DATA at offset 32, its octetsToInlineQos // at 38, the inline QoS from 56 to the end, their PID_SENTINEL at 84. assert_eq!(payload.len(), 88); let mut pointer = payload.to_vec(); pointer[38] = 64; // beyond the 52 bytes of the body assert_eq!( data_of(&pointer).inline_qos(), Some(Err(RtpsParseError::InvalidOctetsToInlineQos { octets_to_inline_qos: 64, body: 52, })) ); let mut unterminated = payload.to_vec(); unterminated[84] = 0x00; // PID_SENTINEL turned PID_PAD, its length 1 kept assert_eq!( data_of(&unterminated).inline_qos(), Some(Err(RtpsParseError::ParameterTruncated { offset: 28, expected: 1, actual: 0 })) ); unterminated[86] = 0x00; // length 0: the list fits, and nothing ends it assert_eq!( data_of(&unterminated).inline_qos(), Some(Err(RtpsParseError::ParameterListUnterminated { length: 32 })) ); let mut no_data = payload.to_vec(); no_data[33] = 0x07; // flag D, and nothing after the inline QoS assert_eq!( data_of(&no_data).serialized_payload(), Some(Err(RtpsParseError::SerializedPayloadTooShort { actual: 0 })) ); assert_eq!( data_of(&no_data).discovery(), Some(Err(RtpsParseError::SerializedPayloadTooShort { actual: 0 })) ); // Frame 70 of talker-listener-rtps.pcapng, its writer id at 44 turned // into SPDP's: a CDR_LE payload is no discovery. let frame_70 = hex::decode(CYCLONE_FRAME_70_HEX).unwrap(); let mut not_a_list = frame_70[4 + 20 + 8..].to_vec(); not_a_list[44..48].copy_from_slice(&[0x00, 0x01, 0x00, 0xc2]); assert_eq!( data_of(¬_a_list).discovery(), Some(Err(RtpsParseError::NotAParameterList { encapsulation: 0x0001 })) ); // None of them refuses the message: the frame is still RTPS, and // nothing is corrupted. let mut frame = raw.clone(); frame[14 + 20 + 8 + 38] = 64; let flow = parse(LinkType::ETHERNET, &frame).unwrap(); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "RTPS"); assert!(flow.corrupted.is_none()); } }
Oracle: 231 frames, six implementations
The golden test tests/rtps_golden.rs runs the eight captures of pcaps_exemple/protocols/rtps/ and compares every frame with tshark 4.6.6 without IP reassembly, frozen by tools/rtps_oracle.sh in tests/data/rtps_tshark_oracle.tsv: version, vendorId, guidPrefix, the sequence of submessages with their octetsToNextHeader, the entity ids and the sequence numbers. Every frame of the oracle must come out "RTPS" and decode identically, every other frame of the folder must not: 231 frames, the 8 pings and the 4 RTPX messages among them. The other 16 frames of the folder are IPv4 fragments of RTPS_Discovery.pcapng, which tshark reassembles and a stateless parser never sees whole. In the golden histogram of pcaps_exemple/protocols/ (tests/golden_pcaps.rs), "RTPS" went from 0 to 231 and "Unknown" from 9 409 to 9 178: no frame of another folder comes out RTPS. The fuzz target parse_rtps runs nightly on the same decoder, and since 13.0.0 on its DDS layer too.
| Capture | RTPS frames | Implementation (vendorId) | Origin |
|---|---|---|---|
talker-listener-rtps.pcapng | 87 | Eclipse Cyclone DDS (0x0110), ROS 2 talker and listener, LINKTYPE_NULL | foxglove/rtps |
RTPS_Discovery.pcapng | 93 | RTI Connext (0x0101), discovery, pings, the RTPX messages | Wireshark wiki |
rtps.pcap | 29 | RTI Connext (0x0101) | nDPI test corpus |
wireshark_15227_reassembly_one_each.pcapng | 6 | RTI Connext (0x0101), DATA_FRAG datagrams of 55 to 65 KB | Wireshark issue 15227 |
wireshark_15868_micro_2_4_11.pcapng | 1 | RTI Connext Micro (0x010a), port 21914 | Wireshark issue 15868 |
wireshark_6449_opendds_messenger.pcap | 13 | OpenDDS (0x0103) | Wireshark issue 6449 |
wireshark_9378_ddsi.pcapng | 1 | OpenSplice (0x0102) | Wireshark issue 9378 |
wireshark_17630_default_multicast_locator.pcapng | 1 | CoreDX (0x0106), RTPS 2.2, a vendor submessage | Wireshark issue 17630 |
Two oracle details: tshark lists the identifier of a vendor submessage but not its octetsToNextHeader, so the comparison skips that length; and it prints a sequence number signed with -T fields, which is the form the oracle keeps.
The DDS layer: 137 frames, 101 announcements
The golden test tests/rtps_dds_golden.rs replays the same eight captures against a second oracle: tshark 4.6.9, frozen by tools/rtps_dds_oracle.sh in tests/data/rtps_dds_tshark_oracle.tsv. It holds a row for each frame that carries a parameter or an encapsulation header: 137 frames. Each row lists, in wire order:
- the encapsulation identifiers;
- the PIDs, PID_SENTINEL included;
- the topic, type and entity names;
- the participant and endpoint GUIDs, and the key hashes;
- the kind, port and IPv4 address of the locators;
- the status info, the reliability, the durability and the built-in endpoint set.
The crate rebuilds the same row from inline_qos(), serialized_payload() and discovery(). Every RTPS message of the folder must match its row, or have none.
| Capture | Frames in the DDS oracle |
|---|---|
talker-listener-rtps.pcapng | 57 |
RTPS_Discovery.pcapng | 33 |
rtps.pcap | 28 |
wireshark_6449_opendds_messenger.pcap | 13 |
wireshark_15227_reassembly_one_each.pcapng | 3, the DATA_FRAG of fragment 1 |
wireshark_15868_micro_2_4_11.pcapng | 1 |
wireshark_9378_ddsi.pcapng | 1 |
wireshark_17630_default_multicast_locator.pcapng | 1 |
| total | 137 |
Three oracle details:
- no IP reassembly, as for the first oracle;
rtps.enable_topic_infois off: otherwise tshark adds to user data the topic and type it remembers from discovery, which are not on the wire;- no domain column: the
rtps.domain_idof tshark comes from the port, not from PID_DOMAIN_ID.
A second test checks what tshark does not, on the 101 SPDP and SEDP announcements of five implementations:
| Check | Result |
|---|---|
| built-in topics | 61 DCPSParticipant, 19 DCPSPublication, 21 DCPSSubscription; no DCPSTopic, no secure writer, no key alone |
| PID_VENDORID of the 61 SPDP | RTI Connext 46, Cyclone DDS 11, OpenSplice 2, CoreDX 1, Connext Micro 1 |
| participant GUID | the guidPrefix of the sender, then ENTITYID_PARTICIPANT, 0x000001c1 |
| endpoint GUID | the guidPrefix of the sender, with a topic and a type name: 29 distinct topics |
| lease duration | in all 61 SPDP |
| PID_DOMAIN_ID | from Cyclone DDS only, 11 times, domain 0 |
| key hash of a built-in instance disposed or unregistered | the GUID of the sender, in frame 29 of rtps.pcap |
The sender is the guidPrefix of the header, or that of the last INFO_SRC. The OpenDDS capture carries no discovery.
The fuzz target parse_rtps calls the three methods on every submessage it decodes. When they succeed, every list, value and data slice points into the body of the submessage. The parameters tile their list, and every typed accessor reads without a panic. Three real frames seed its mutations, besides frames 8 and 9 of Cyclone DDS: the SPDP DATA of Connext Micro, frame 29 of rtps.pcap and frame 12 of the OpenDDS capture.
What is left out
The limits every protocol shares, reassembly and checksums among them, are on the Limits page. The ones below are this protocol's own.
- User data: the data of a user type stays bytes after its encapsulation header, and so does its key. XCDR2, its mutable and appendable forms, and XML are named, not decoded. The
extraFlagsandoctetsToInlineQosof a DATA are not exposed. - The ParameterList: fifteen PIDs have a typed accessor; the others give their value as bytes, through
getanditer. The must-understand bit is reported, not acted on. - Discovery is read from a DATA only, not from an announcement cut into DATA_FRAG.
- Names: entity ids and GUID prefixes are numbers and bytes; tshark calls
0x000200c2ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER, the crate does not. Only the discovery writers get a name, that of their built-in topic. - DDS Security: the secure submessages are recognized by their identifier, their bodies stay opaque.
discovery()recognizes the secure discovery writers; no capture has one. - The HEADER_EXTENSION checksum is read, not verified, and its ParameterList stays raw and unchecked.
- Unknown submessages refuse the message, where rule 3 of §8.3.4.1 asks to skip them.
- Reassembly:
DATA_FRAGfragments are not put back together, nor are the IPv4 fragments of a datagram.serialized_payload()of a DATA_FRAG gives the start of the data, from fragment 1 only. One message at a time, as everywhere in the crate. - RTPS 1.x is
UnsupportedVersion, and RTPS is only looked for on UDP.