Valmet DNA

Valmet DNA (Metso DNA), the process network of the distributed control systems of Metso and Valmet, added in 11.8.0 (8ffdec1, released by PR #229), the only decoder of that release. On the network the crate was built from, the nodes send UDP datagrams to a multicast group: periodic status telegrams, messages that name a tag, and a beacon. The module is packet_parser::parse::application::protocols::valmet_dna, its error packet_parser::errors::application::valmet_dna::ValmetDnaParseError.

Observed, not specified

The protocol is proprietary: there is no public specification and no public dissector, and tshark has none. The decoder is built on the observation of traffic alone, one capture taken on the mirror port of a process network in operation and anonymized in pcaps_exemple/protocols/valmet_dna/ of the crate, without code or documentation from the vendor. It reads: it rebuilds no control logic and emits nothing. The names of the fields are those of the observation, not those of the vendor. Nothing on this page comes from the vendor either.

What the capture establishes, what the crate infers from it, and what stays unknown:

PointStatus
The magic AB 01, the length equal to the datagram minus two, the two families and their sizesestablished: true of every message of the capture
The node address and the multicast group in the status telegramestablished: equal to the IP source and the IP destination of every telegram
The node number, low byte of the source node 0x80NNestablished: equal on every telegram
The order of the fields of the BCD clockestablished on the original capture, which is not in the corpus (see the clock)
The two counters of the status telegram, the second repeating the first of the previous telegramestablished: checked telegram after telegram; microseconds, since they advance by about 640 000 every 640 ms
The tag length written twice, the tag that ends the datagram, the form :e:<class>:<path>established on the 400 tag messages, 360 of which have the readable form
The destination 0x00FF as "all nodes"inferred: every frame observed carries it, and all are multicast
The convention of the weekdayunknown: one day observed, two conventions fit
87 of the 126 bytes of the status telegram, 56 of the 72 bytes of the tag message header, 16 of the 42 bytes of the beaconnot identified, kept as bytes
What the classes, the beacon's code and counter, and any other family meanunknown

The capture

The corpus capture, valmet-dna-multicast-anon.pcap, is the first twelve seconds of DNA traffic of a 212-second capture made by the maintainer on 2026-11-03. Its 720 UDP datagrams all go to the multicast group 239.0.171.1, whose last two bytes, 171 and 1, are the magic AB 01:

  • 719 on UDP 2517 → 2517: 319 status telegrams of 126 bytes, sent every 640 ms by each of 17 nodes, 0x8008 to 0x802D, 18 or 19 each; and 400 tag messages of 82 to 116 bytes from 14 of those nodes;
  • 1 on UDP 4516 → 4517: the 42-byte beacon, frame 591.

The anonymization renumbered the unicast MAC and IPv4 addresses (the IPv4 ones into 10.0.2.0/24, with the node address inside the payload), substituted the site-specific part of the tags letter by letter and digit by digit, and rewrote the clocks from the timestamp of their frame, rebased to 2020-01-01 00:00:00 UTC. Everything else in the payloads, headers, families, lengths, counters and bytes not identified, is identical byte for byte to the original, according to the folder's SOURCE.md.

Detection: three ports, then a blind probe

As for PTP on UDP, the pipeline gives the datagram a label, "Valmet DNA", and nothing more: the decode is ValmetDnaPacket::try_from, or TimeBeacon::try_from for the beacon, on the transport payload. No port is registered in the protocol's name; 2517, 4516 and 4517 are the ports the capture shows. The crate therefore has three routes, from the most tolerant to the strictest:

WhereProbeAccepts
UDP 2517, 4516 or 4517, on either sideProbeId::ValmetDnaa message with a coherent header, of a known family at its exact size or of an unknown one, or a beacon
a port declared with ParseConfig::decode_as(port, DecodeAsProtocol::ValmetDna)ProbeId::ValmetDnathe same
any other UDP portProbeId::ValmetDnaBlinda message of one of the two known families, at its exact size

In the table of src/parse/dispatch/rules.rs:

#![allow(unused)]
fn main() {
// among the port rules, after BACnet/IP: UDP 2517 for the AB 01 messages,
// 4516 -> 4517 for the beacon, the observed ports. On these ports an unknown
// message family is accepted with its body as bytes; elsewhere, the blind
// probe below only accepts the two known families.
port_rule(ApplicationProtocol::ValmetDna, Guard::Udp, is_valmet_dna_udp_port, ProbeId::ValmetDna),
// ...
// --- blind cascade ---
rule(ApplicationProtocol::Ntp, Guard::Udp, ProbeId::NtpBlind),
rule(ApplicationProtocol::Rtps, Guard::Udp, ProbeId::Rtps),
// Magic AB 01, a length equal to the datagram minus two and a known family
// at its exact size: more than 64 bits of constraint, enough to do without
// the port.
rule(ApplicationProtocol::ValmetDna, Guard::Udp, ProbeId::ValmetDnaBlind),
rule(ApplicationProtocol::Asterix, Guard::Udp, ProbeId::Asterix),
}

with the probes, both on the whole datagram and not on its first PROBE_CAP bytes, since the length must equal the datagram minus two:

#![allow(unused)]
fn main() {
ProbeId::ValmetDna => ValmetDnaPacket::is_port_udp_match(payload),
ProbeId::ValmetDnaBlind => ValmetDnaPacket::is_blind_udp_match(payload),

impl ValmetDnaPacket<'_> {
    pub(crate) fn is_port_udp_match(payload: &[u8]) -> bool {
        ValmetDnaPacket::try_from(payload).is_ok() || TimeBeacon::try_from(payload).is_ok()
    }

    pub(crate) fn is_blind_udp_match(payload: &[u8]) -> bool {
        ValmetDnaPacket::try_from(payload).is_ok_and(|packet| packet.kind.is_some())
    }
}
}

The blind rule comes right after RTPS and before ASTERIX in the blind cascade, and classify_payload, given UDP and no port (None, None), reaches it there. The beacon has no blind route: off its ports, it needs a declared port. Decode As resolves DecodeAsProtocol::ValmetDna to (ApplicationProtocol::ValmetDna, Guard::Udp, ProbeId::ValmetDna), the probe of the port rule, behind the same UDP guard: a unit test of dispatch/tests.rs checks that a status telegram on TCP 2517 is not Valmet DNA, Decode As included.

Frames 1, 9 and 591 moved to UDP 40000 → 40001: the status telegram and the tag message keep their label, the beacon needs Decode As (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn three_ports_then_a_blind_probe_for_the_two_known_families() {
        let default = ParseConfig::new();
        let declared = ParseConfig::new().decode_as(40_001, DecodeAsProtocol::ValmetDna);
        let label_of = |frame: &[u8], config: &ParseConfig| {
            let flow = parse_with(LinkType::ETHERNET, frame, config).unwrap();
            flow.application.as_ref().map(|application| application.protocol.label())
        };
        let off_port = |frame: &[u8]| {
            let mut moved = frame.to_vec();
            moved[34..38].copy_from_slice(&[0x9c, 0x40, 0x9c, 0x41]); // 40000 -> 40001
            moved
        };
        let status = hex::decode(STATUS_TELEGRAM_HEX).unwrap();
        let tag = hex::decode(TAG_MESSAGE_HEX).unwrap();
        let beacon = hex::decode(BEACON_HEX).unwrap();

        // Frames 1 and 9 moved to UDP 40000 -> 40001: the magic, the length
        // and the exact size of a known family are enough.
        assert_eq!(label_of(&off_port(&status), &default), Some("Valmet DNA"));
        assert_eq!(label_of(&off_port(&tag), &default), Some("Valmet DNA"));
        // `classify_payload`, given the transport and no port, agrees.
        let blind =
            classify_payload(TransportProtocol::Udp, None, None, &status[DATAGRAM..]).unwrap();
        assert_eq!(blind.protocol, ApplicationProtocol::ValmetDna);

        // The beacon is recognized on its ports, or on a declared port.
        assert_eq!(label_of(&beacon, &default), Some("Valmet DNA"));
        assert_eq!(label_of(&off_port(&beacon), &default), Some("Unknown"));
        assert_eq!(label_of(&off_port(&beacon), &declared), Some("Valmet DNA"));
    }
}

The header

The 126-byte status telegram of frame 1 of valmet-dna-multicast-anon.pcap, 32 bits per row: the 12-byte header with the magic AB 01, the source node 0x801D, the destination 0x00FF, the length 124 and the message kind 0x00000FFF, then the fields the crate names, the node address 10.0.2.1, the ten-byte BCD clock with its fraction and its year little-endian (2020-01-01 00:00:00.0000, weekday 3, rewritten by the anonymization), the node number 0x1D, the multicast group 239.0.171.1 and the two microsecond counters 0x540F5BF1 and 0x54059702, with the bytes not identified summarised in between; ValmetDnaPacket keeps the header fields, the body and a StatusTelegram with the named values.

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct ValmetDnaPacket<'a> {
    /// The sending node: 0x80NN on every frame observed, NN the node number.
    pub source_node: u16,
    /// 0x00FF on every frame observed, all multicast.
    pub destination: u16,
    /// The declared length: the datagram minus two.
    pub length: u16,
    /// The message family, as read.
    pub kind_code: u32,
    /// The named family, when MessageKind knows it.
    pub kind: Option<MessageKind>,
    /// Everything after the 12-byte header, as is.
    pub body: &'a [u8],
    pub message: ValmetDnaMessage<'a>,
}

#[non_exhaustive]
pub enum MessageKind {
    /// 0x00000FFF: the periodic status telegram, 126 bytes.
    Status,
    /// 0x001E00D0: the tag message.
    Tag,
}

#[non_exhaustive]
pub enum ValmetDnaMessage<'a> {
    Status(StatusTelegram),
    Tag(TagMessage<'a>),
    /// Unknown family: the body is in ValmetDnaPacket::body.
    Unknown,
}
}
BytesFieldNote
0–1magicAB 01, checked, not kept
2–3source_node0x80NN on every frame of the capture; node_number() returns NN
4–5destination0x00FF on every frame of the capture: "all nodes", likely
6–7lengththe bytes after the magic: the datagram minus two, exactly
8–11kind_codeMessageKind::from_code names 0x00000FFF and 0x001E00D0
12–bodyeverything after the header, the named fields included

Every integer is read big-endian, except the two words of the clock. The family decides the rest: a status telegram, a tag message, or Unknown.

The status telegram

The family 0x00000FFF, 126 bytes exactly, sent by each node every 640 ms: the frame timestamps of the capture, whose gaps the anonymization kept, put two telegrams of a node between 638.8 and 642.3 ms apart.

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct StatusTelegram {
    /// The node's IPv4 address: the IP source on every frame observed.
    pub node_ip: Ipv4Addr,
    /// The node's clock, when its ten bytes form a valid date.
    pub clock: Option<DnaClock>,
    /// The low byte of ValmetDnaPacket::source_node on every frame observed.
    pub node_number: u8,
    /// The network's multicast group: the IP destination.
    pub multicast_group: Ipv4Addr,
    /// A 32-bit counter in microseconds, modulo 2^32.
    pub tick: u32,
    /// The tick of the node's previous telegram.
    pub previous_tick: u32,
}
}
BytesFieldWhat ties it down
0–11headerfamily 0x00000FFF, length 124
12–35not identified
36–39node_ipequal to the IP source of all 319 telegrams
40–41not identified
42–51clocka DnaClock
52–57not identified
58node_numberequal to the low byte of source_node on all 319
59–69not identified
70–73multicast_groupequal to the IP destination
74–105not identified
106–109ticksee the counters
110–113previous_tickthe tick of the node's previous telegram
114–125not identified

The telegram of node 0x801D, frame 1 of the capture (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn a_status_telegram_carries_its_node_a_clock_and_two_counters() {
        // Frame 1, UDP 2517 -> 2517: the pipeline gives the label, the
        // decoder reads the datagram, borrowed from the frame.
        let raw = hex::decode(STATUS_TELEGRAM_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        assert_eq!(label(&flow), Some("Valmet DNA"));
        let internet = flow.internet.as_ref().unwrap();
        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        assert_eq!(payload.len(), 126);

        // The header: the magic AB 01 (checked, not kept), node 0x801D,
        // destination 0x00FF, a length of 124, the datagram minus two, and
        // the family 0x00000FFF.
        let packet = ValmetDnaPacket::try_from(payload).unwrap();
        assert_eq!((packet.source_node, packet.destination, packet.length), (0x801d, 0x00ff, 124));
        assert_eq!(packet.kind_code, 0x0000_0fff);
        assert_eq!(packet.kind, Some(MessageKind::Status));
        assert_eq!(packet.node_number(), 0x1d);
        assert_eq!(packet.body, &payload[12..]); // everything after the header, as is

        let ValmetDnaMessage::Status(status) = packet.message else {
            panic!("expected a status telegram, got {:?}", packet.message);
        };
        // What the golden test checks on the 319 telegrams of the capture:
        // the node address is the IP source, the group the IP destination,
        // the node number the low byte of the node identifier.
        assert_eq!(status.node_ip, Ipv4Addr::new(10, 0, 2, 1));
        assert_eq!(internet.source, Some(IpAddr::V4(status.node_ip)));
        assert_eq!(status.multicast_group, Ipv4Addr::new(239, 0, 171, 1));
        assert_eq!(internet.destination, Some(IpAddr::V4(status.multicast_group)));
        assert_eq!(status.node_number, 29);
        assert_eq!(status.node_number, packet.node_number());

        // Two 32-bit counters, 640 239 apart over one period of 640 ms:
        // microseconds. `previous_tick` is the `tick` of the node's previous
        // telegram, which the capture does not hold for frame 1.
        assert_eq!((status.tick, status.previous_tick), (0x540f_5bf1, 0x5405_9702));
        assert_eq!(status.tick.wrapping_sub(status.previous_tick), 640_239);

        // The clock, rewritten by the anonymization from the frame's rebased
        // timestamp: 2020-01-01 00:00:00.0000, weekday 3.
        let clock = status.clock.expect("a valid date");
        assert_eq!((clock.year, clock.month, clock.day, clock.weekday), (2020, 1, 1, 3));
        assert_eq!((clock.hour, clock.minute, clock.second, clock.fraction), (0, 0, 0, 0));
        assert_eq!(clock.microseconds_of_day(), 0);
    }
}

The BCD clock

The status telegram and the beacon carry the same ten-byte clock, every digit in BCD, two digits per byte:

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct DnaClock {
    /// Fraction of a second, in units of 100 µs (0 to 9999).
    pub fraction: u16,
    pub second: u8,
    pub minute: u8,
    pub hour: u8,
    pub weekday: u8,
    pub day: u8,
    pub month: u8,
    pub year: u16,
}
}
BytesFieldNote
0–1fractiontwo BCD bytes, low byte first: 86 95 is 9586, in units of 100 µs
2second0 to 59
3minute0 to 59
4hour0 to 23
5weekday0 to 7
6day1 to 31
7month1 to 12
8–9yeartwo BCD bytes, low byte first: 26 20 is 2026; no range

How the order was established. On the original capture, not on the corpus one: the seconds go from 59 to 00 with a carry into the minutes, the fraction advances by 6 400 per telegram, the 640 ms of the period, and the hour and the weekday are those of the day of the capture. The corpus capture cannot show this again. Its clocks were rewritten from the timestamps of the frames, which start at midnight on 2020-01-01 and last twelve seconds: no minute rolls over, and the year is 20 20, which does not show the order of its two bytes. On the original capture, the clocks of the nodes were twenty-nine minutes off the official time, by the same amount on every node: the clock dates the exchanges between nodes, not the outside world.

The weekday was 2 on the day of the original capture, a Tuesday: Monday is 1 (ISO 8601), or Sunday is 0. With a single day observed, the two conventions agree, and the crate does not choose. The rewritten clocks of the corpus say 3, 2020-01-01 being a Wednesday.

DnaClock::from_bytes reads the first ten bytes of its argument and returns None if there are fewer, if a nibble is not a decimal digit, or if a field is out of its range: an unset clock, not a decoding error. A telegram or a beacon with such a clock still decodes, with clock: None. microseconds_of_day() gives the microseconds since midnight, to compare two clocks of the same day.

The clock of the beacon, the vector of the crate's unit test for the year, and an unset clock (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn the_clock_is_ten_bcd_bytes_with_two_little_endian_words() {
        // The beacon of frame 591 carries the clock at offset 28 of its
        // datagram.
        let raw = hex::decode(BEACON_HEX).unwrap();
        let bytes = &raw[DATAGRAM + 28..DATAGRAM + 38];
        assert_eq!(bytes, [0x86, 0x95, 0x09, 0x00, 0x00, 0x03, 0x01, 0x01, 0x20, 0x20]);
        let clock = DnaClock::from_bytes(bytes).unwrap();
        // The fraction is a word, low byte first: 86 then 95 is 9586, in
        // units of 100 us. Then second, minute, hour, weekday, day and
        // month, one BCD byte each, and the year, low byte first.
        assert_eq!(clock.fraction, 9586);
        assert_eq!((clock.second, clock.minute, clock.hour), (9, 0, 0));
        assert_eq!((clock.weekday, clock.day, clock.month, clock.year), (3, 1, 1, 2020));
        assert_eq!(clock.microseconds_of_day(), 9_958_600);

        // Every clock of the capture has the year 20 20, which cannot show
        // the order of its two bytes. The vector of the crate's own unit
        // test does: 26 20 is 2026.
        let unit_test = [0x70, 0x08, 0x37, 0x52, 0x10, 0x02, 0x03, 0x11, 0x26, 0x20];
        let clock = DnaClock::from_bytes(&unit_test).unwrap();
        assert_eq!((clock.year, clock.month, clock.day, clock.weekday), (2026, 11, 3, 2));
        assert_eq!((clock.hour, clock.minute, clock.second, clock.fraction), (10, 52, 37, 870));

        // A nibble above 9, a field out of range or fewer than ten bytes is
        // not a clock.
        let mut not_bcd = unit_test;
        not_bcd[2] = 0x3a;
        assert_eq!(DnaClock::from_bytes(&not_bcd), None);
        assert_eq!(DnaClock::from_bytes(&[0; 10]), None); // day 0, month 0
        assert_eq!(DnaClock::from_bytes(&unit_test[..9]), None);

        // In a telegram, an invalid clock is `None`, not a refusal: frame 1
        // with ten zero bytes in place of its clock still decodes.
        let status = hex::decode(STATUS_TELEGRAM_HEX).unwrap();
        let mut unset = status[DATAGRAM..].to_vec();
        unset[42..52].fill(0);
        let packet = ValmetDnaPacket::try_from(unset.as_slice()).unwrap();
        let ValmetDnaMessage::Status(telegram) = packet.message else {
            panic!("expected a status telegram, got {:?}", packet.message);
        };
        assert_eq!(telegram.clock, None);
    }
}

The two counters

tick and previous_tick are two 32-bit counters, read big-endian. previous_tick repeats the tick of the same node's previous telegram: the golden test checks it on the 302 telegrams of the capture that have a predecessor. From one telegram to the next, tick advances by about 640 000, 639 111 to 642 481 on the capture, over a period of 640 ms: microseconds, modulo 2³². The crate does not interpret them further; what they count from is not known.

The tag message

The family 0x001E00D0: a fixed 72-byte header, then a tag that ends the datagram.

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct TagMessage<'a> {
    /// The declared tag length, equal to tag.len().
    pub tag_length: u16,
    /// The tag, as is: `:e:<class>:<path>` when it is readable, ten bytes
    /// that are not text otherwise.
    pub tag: &'a [u8],
}

impl<'a> TagMessage<'a> {
    pub fn tag_text(&self) -> Option<&'a str>;  // the tag, when it is valid UTF-8
    pub fn class(&self) -> Option<&'a str>;     // <class> of `:e:<class>:<path>`
    pub fn path(&self) -> Option<&'a str>;      // <path> of the same form
}
}
BytesFieldNote
0–11headerfamily 0x001E00D0
12–27not identified
28–29tag_length
30–69not identified
70–71the tag length, againmust equal the first
72–tagtag_length bytes, up to the end of the datagram

The decoder checks that the datagram holds the 72 bytes of the header, that the two lengths are equal, and that 72 plus the tag length is the datagram; the tag is borrowed, not copied. An empty tag, two zero lengths in 72 bytes, is accepted.

The tags of the capture start with :e:. 360 of the 400 are readable text of the form :e:<class>:<path>, with a class of two letters: di 286 times, pr 57, sn 9, hw 6 and li 2. class() and path() answer when the text starts with :e:, has a non-empty class and a colon after it; the path may be empty. The 40 others are ten bytes that are not UTF-8: frame 2, in the crate's unit tests, is :e:A2, then 0xC1, 1, a NUL and 0xFE 0xFF; tag_text, class and path are None for them, and tag keeps the bytes. The crate calls the two letters a class, after their place in the tag; what they mean is not known. In the corpus, the path is the anonymized one: the marker, the class, the delimiters and the length are the original ones, the letters and digits of the path are not.

A tag of class di sent by node 0x8028, frame 9 of the capture (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn a_tag_message_borrows_its_tag_and_splits_the_readable_form() {
        // Frame 9: 115 bytes, the fixed 72-byte header and a 43-byte tag.
        let raw = hex::decode(TAG_MESSAGE_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        assert_eq!(label(&flow), Some("Valmet DNA"));
        let payload = flow.transport.as_ref().unwrap().payload.unwrap();
        assert_eq!(payload.len(), 115);

        let packet = ValmetDnaPacket::try_from(payload).unwrap();
        assert_eq!((packet.source_node, packet.destination, packet.length), (0x8028, 0x00ff, 113));
        assert_eq!(packet.kind_code, 0x001e_00d0);
        assert_eq!(packet.kind, Some(MessageKind::Tag));
        let ValmetDnaMessage::Tag(tag) = packet.message else {
            panic!("expected a tag message, got {:?}", packet.message);
        };

        // The tag length is written twice, at offsets 28 and 70; the tag
        // starts at 72 and ends with the datagram. It is borrowed, not copied.
        assert_eq!(payload[28..30], [0x00, 0x2b]);
        assert_eq!(payload[70..72], [0x00, 0x2b]);
        assert_eq!(tag.tag_length, 43);
        assert!(std::ptr::eq(tag.tag, &payload[72..]));

        // The readable form `:e:<class>:<path>`. The anonymization kept the
        // marker, the class and the delimiters, and substituted the path
        // letter by letter and digit by digit.
        assert_eq!(tag.tag_text(), Some(":e:di:AK05:nris05:oigwxj026:oixwge(2):awcrs"));
        assert_eq!(tag.class(), Some("di"));
        assert_eq!(tag.path(), Some("AK05:nris05:oigwxj026:oixwge(2):awcrs"));
    }
}

Unknown families

A message whose header is coherent, magic and length, but whose family is neither 0x00000FFF nor 0x001E00D0, decodes with kind: None and message: ValmetDnaMessage::Unknown; its bytes are in body, as they are in every message. The port rule and Decode As accept it, the blind probe does not: off the ports, a magic and a length alone are not enough. The capture has no such message: its 719 AB 01 messages are of the two known families.

Frame 1 with the family 0x00000FFE, on its port and moved (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn an_unknown_family_is_kept_as_bytes_on_the_ports_only() {
        let label_of = |frame: &[u8], config: &ParseConfig| {
            let flow = parse_with(LinkType::ETHERNET, frame, config).unwrap();
            flow.application.as_ref().map(|application| application.protocol.label())
        };
        // Frame 1 with the family 0x00000FFE, which the capture does not show.
        let mut unknown = hex::decode(STATUS_TELEGRAM_HEX).unwrap();
        unknown[DATAGRAM + 11] = 0xfe;

        let packet = ValmetDnaPacket::try_from(&unknown[DATAGRAM..]).unwrap();
        assert_eq!((packet.kind_code, packet.kind), (0x0000_0ffe, None));
        assert_eq!(packet.message, ValmetDnaMessage::Unknown);
        assert_eq!(packet.body, &unknown[DATAGRAM + 12..]); // the body, as is

        // On UDP 2517 the header is enough; off the ports, the blind probe
        // refuses a family it does not know, and Decode As accepts it again.
        let default = ParseConfig::new();
        let declared = ParseConfig::new().decode_as(40_001, DecodeAsProtocol::ValmetDna);
        let mut moved = unknown.clone();
        moved[34..38].copy_from_slice(&[0x9c, 0x40, 0x9c, 0x41]); // 40000 -> 40001
        assert_eq!(label_of(&unknown, &default), Some("Valmet DNA"));
        assert_eq!(label_of(&moved, &default), Some("Unknown"));
        assert_eq!(label_of(&moved, &declared), Some("Valmet DNA"));
    }
}

The beacon

On UDP 4516 → 4517, to the same group, a node sends a 42-byte beacon that carries the same clock. It does not start with AB 01, so ValmetDnaPacket::try_from refuses it (InvalidMagic(0)); TimeBeacon::try_from reads it.

#![allow(unused)]
fn main() {
#[non_exhaustive]
pub struct TimeBeacon {
    pub code: u16,
    pub counter: u32,
    /// The same clock as in the status telegrams.
    pub clock: Option<DnaClock>,
    /// The node's IPv4 address: the IP source of the datagram.
    pub node_ip: Ipv4Addr,
}
}
BytesFieldNote
0–3prefixfour zero bytes, checked, not kept
4–5magicAB CC, checked, not kept
6–7code6 in the capture
8–11counter0x23800000 in the capture
12–27not identified
28–37clocka DnaClock
38–41node_ipequal to the IP source

The module documentation gives the beacon a period of 30 s; the twelve seconds of the corpus capture hold a single one, frame 591, sent from the address of node 0x802C, so the period cannot be checked there. With one beacon, the code and the counter are kept as read, without a meaning. The beacon is recognized on UDP 2517, 4516 and 4517 and on a declared port, never blind.

Frame 591 (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn the_beacon_of_udp_4516_is_not_an_ab01_message() {
        // Frame 591, UDP 4516 -> 4517: the port rule accepts the beacon.
        let raw = hex::decode(BEACON_HEX).unwrap();
        let flow = parse(LinkType::ETHERNET, &raw).unwrap();
        assert_eq!(label(&flow), Some("Valmet DNA"));
        let transport = flow.transport.as_ref().unwrap();
        assert_eq!((transport.source_port, transport.destination_port), (Some(4516), Some(4517)));
        let payload = transport.payload.unwrap();
        assert_eq!(payload.len(), 42);

        // It does not start with AB 01: it is not a message.
        assert_eq!(ValmetDnaPacket::try_from(payload), Err(ValmetDnaParseError::InvalidMagic(0)));

        // Four zero bytes and AB CC, then a code and a counter, kept as read:
        // a single beacon cannot say what they mean.
        assert_eq!(payload[..6], [0x00, 0x00, 0x00, 0x00, 0xab, 0xcc]);
        let beacon = TimeBeacon::try_from(payload).unwrap();
        assert_eq!((beacon.code, beacon.counter), (6, 0x2380_0000));
        // The node address is the IP source, as in a status telegram.
        assert_eq!(beacon.node_ip, Ipv4Addr::new(10, 0, 2, 9));
        assert_eq!(flow.internet.as_ref().unwrap().source, Some(IpAddr::V4(beacon.node_ip)));
        // The same clock, here 9.9586 s after the rebased start of the capture.
        let clock = beacon.clock.unwrap();
        assert_eq!((clock.second, clock.fraction), (9, 9586));
    }
}

Validations

All of them are ValmetDnaParseError:

ErrorWhen
Truncated { expected, actual }fewer than the 12 bytes of the header, or a tag message shorter than its 72-byte header
InvalidMagic(u16)the first two bytes are not AB 01
LengthMismatch { declared, actual }the declared length plus two is not the size of the datagram
InvalidMessageLength { kind, expected, actual }a status telegram of another size than 126 bytes, or a tag message whose header and tag do not make the datagram
TagLengthMismatch { declared, echo }the tag lengths at offsets 28 and 70 differ
InvalidBeaconLength { actual }a beacon of another size than 42 bytes
InvalidBeaconPrefix(u32)the first four bytes of a beacon are not zero
InvalidBeaconMagic(u16)the next two are not AB CC

A clock that is not a date is not an error: it is clock: None. Like every application decoder, a failure is not a corruption: the datagram goes on to the next rules of the table, and nothing goes to corrupted.

Four refusals, and an altered telegram that stays on UDP 2517 and comes out "Unknown" (tested):

#![allow(unused)]
fn main() {
    #[test]
    fn a_header_or_a_size_out_of_line_is_refused_and_not_a_corruption() {
        let raw = hex::decode(STATUS_TELEGRAM_HEX).unwrap();
        let telegram = &raw[DATAGRAM..];

        // One byte less: the declared length, 124, is no longer the
        // datagram minus two.
        assert_eq!(
            ValmetDnaPacket::try_from(&telegram[..125]),
            Err(ValmetDnaParseError::LengthMismatch { declared: 124, actual: 125 })
        );
        // The same 125 bytes with a coherent length: the header passes, but
        // a status telegram is 126 bytes.
        let mut short = telegram[..125].to_vec();
        short[7] = 123;
        assert_eq!(
            ValmetDnaPacket::try_from(short.as_slice()),
            Err(ValmetDnaParseError::InvalidMessageLength {
                kind: 0x0000_0fff,
                expected: 126,
                actual: 125
            })
        );

        // Frame 9 with its two tag lengths at odds, 43 then 42.
        let tag = hex::decode(TAG_MESSAGE_HEX).unwrap();
        let mut echo = tag[DATAGRAM..].to_vec();
        echo[71] = 42;
        assert_eq!(
            ValmetDnaPacket::try_from(echo.as_slice()),
            Err(ValmetDnaParseError::TagLengthMismatch { declared: 43, echo: 42 })
        );

        // Frame 591 cut by one byte: a beacon is 42 bytes.
        let beacon = hex::decode(BEACON_HEX).unwrap();
        assert_eq!(
            TimeBeacon::try_from(&beacon[DATAGRAM..DATAGRAM + 41]),
            Err(ValmetDnaParseError::InvalidBeaconLength { actual: 41 })
        );

        // A refusal is not a corruption. Frame 1 declaring 125 bytes stays on
        // UDP 2517, goes on to the next rules of the table, and ends "Unknown".
        let mut altered = raw.clone();
        altered[DATAGRAM + 7] = 0x7d;
        let flow = parse(LinkType::ETHERNET, &altered).unwrap();
        assert_eq!(label(&flow), Some("Unknown"));
        assert!(flow.corrupted.is_none());
        let error = ValmetDnaPacket::try_from(&altered[DATAGRAM..]).unwrap_err();
        assert_eq!(
            error.to_string(),
            "Valmet DNA length 125 does not match the 126 bytes of the datagram"
        );
    }
}

Validation without tshark

Without a dissector there is no tshark oracle to compare with. The golden test tests/valmet_dna_golden.rs checks the structure against what the capture carries elsewhere, and against itself over time. Each of the 720 datagrams must be labelled "Valmet DNA" and decode, and:

  • every AB 01 message has a length equal to the datagram minus two, a source node 0x80NN, the destination 0x00FF, and a body of the datagram minus twelve;
  • every status telegram has 126 bytes, the IP source as node_ip, the IP destination as multicast_group, the low byte of its source node as node_number, one address per node, and a valid clock; from one telegram of a node to the next, the clock advances by 630 to 650 ms, tick by 630 000 to 650 000, and previous_tick equals the previous tick;
  • every tag message is 72 bytes plus its tag, the tag starts with :e:, a readable tag has a non-empty path, and a tag that is not text has ten bytes;
  • the beacon has the IP source as node_ip, the code 6, the counter 0x23800000, and comes from the address of node 0x802C.

The test then freezes the counts: 319 status telegrams, 400 tag messages, 1 beacon; the 17 nodes, with 18 or 19 telegrams each; the classes; the 40 tags that are not text; tags of 10 to 44 bytes, sent by 14 nodes. A second test moves frames 1, 9 and 591 off their ports, as in the detection example. The checks are consistency checks: they tie each named field to the IP header, to the message header or to the node's next telegram, and cannot confirm a field against a reference, since there is none.

In the golden histogram of pcaps_exemple/protocols/ (tests/golden_pcaps.rs), "Valmet DNA" went from 0 to 720 with 11.8.0: the 720 datagrams of the new capture, and no frame of the rest of the corpus, where nothing else moved. The fuzz target parse_valmet_dna runs nightly (data validation), on its input and on mutations of frames 1, 9 and 591: no panic, and when a decode succeeds, the length is the input minus two, the body and the tag are borrowed from the input, the clock is within its ranges, and Application::try_from says "Valmet DNA" exactly when the family is known.

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.

  • The bytes not identified stay bytes: 87 of the 126 of the status telegram, 56 of the 72 of the tag message header, 16 of the 42 of the beacon. Those of a message are in body; TimeBeacon does not expose its own, which stay in the transport payload.
  • No meaning is given to the classes of the tags, to the code and the counter of the beacon, or to the families the capture does not show. What a tag message says about its tag, beyond naming it, is not known.
  • The destination 0x00FF reads as "all nodes" only because every frame observed carries it and goes to the multicast group; no other value was observed.
  • The weekday is kept as read, without a convention.
  • One site, one capture: the ports, the group and the families are those of one network. On other ports, the blind probe still recognizes the two known families; anything else needs a declared port.
  • Read-only: the crate builds no message, rebuilds no control logic, and emits nothing.