# Validate NetFlow v5, Dual-Stack IPFIX, sFlow & Nanosecond PTPv2

> **FrameAssembly v3.2.2** · Operational Playbook (Telemetry, VoIP & OT) · Canonical URL: https://frameassembly-lang.dev/use-cases/netflow-ipfix-sflow-ptp-telemetry-pcap

Self-templated IPFIX (zero missing-template blind spots), NetFlow v5, sFlow v5, and sub-microsecond IEEE 1588v2 PTP ready for .pcapng.

- **Category:** Telemetry, VoIP & OT
- **Capture Filename:** `telemetry_ptp_suite.frasm` (10 Ethernet frames)
- **Protocols Exercised:** `netflow`, `ipfix`, `sflow`, `ptp`

## Operational Problem

Testing flow ingestion pipelines (ElastiFlow, Akvorado, pmacct, GoFlow2) and precision timing monitors is notoriously painful: IPFIX collectors drop Data Sets until a periodic Template Set arrives, and classic `.pcap` files round sub-microsecond IEEE 1588v2 PTP hardware timestamps to microseconds.

Capturing live IPFIX (UDP 4739) from a production spine switch often gives you orphan Data Sets that Wireshark (`cflow`) and CI tests cannot decode because Template Set 2 was sent 10 minutes earlier. FrameAssembly packs both Template Set `2` and Data Set `256` inside every `ipfix` packet—switching automatically between IPv4 and 128-bit IPv6 Information Elements.

For broadcast media (SMPTE ST 2110), 5G fronthaul, and trading fabrics, FrameAssembly also pairs Event (`UDP 319`) and General (`UDP 320`) IEEE 1588v2 `ptp` frames with `ns`/`us` post-packet `wait` intervals—preserving exact `1ns` (`IfTsResol = 9`) resolution when exported as `.pcapng`.

## Scenario & Topology: Spine Telemetry Ingest (NetFlow v5 + IPv4/IPv6 IPFIX + sFlow v5) & Two-Step PTPv2 Sync

- **Topology:** `Spine Exporter / Grandmaster (172.20.0.1) <-> Collector & Boundary Clock (172.20.50.10)`

Ten packets exercise your entire observability and timing stack: (1) Cisco `netflow` v5 (UDP 2055) reporting a 12 MB HTTPS transfer; (2) self-templated `ipfix` (UDP 4739) exporting both a VRF-10 IPv4 flow and a VRF-20 IPv6 gRPC flow; (3) XDR-aligned `sflow` v5 packet samples (UDP 6343) across two `seq` numbers; and (4) a complete 5-packet two-step IEEE 1588v2 `ptp` exchange (`announce -> sync -> followup -> delayreq -> delayresp`) spaced at `120us`–`500ns` intervals.

## FrameAssembly Workflow

Emits 10 frames: NetFlow v5, dual-stack self-templated IPFIX, sFlow v5, and a 5-packet sub-microsecond two-step PTPv2 loop (`.pcapng` ready).

### Adapt It for Your Network

1. Point spine_exporter and telemetry_col at your flow collector IPs, and adjust `dstport` if your NetFlow listener uses UDP 9995.
2. Set `domain 127` (SMPTE ST 2059-2), `24`/`44` (ITU-T G.8275 telecom), or `0` (default IEEE 1588) on the `ptp` lines.
3. Export as `.pcapng` (`frameassembly telemetry_ptp_suite.frasm telemetry_ptp_suite.pcapng`) to preserve `wait 500ns` / `120us` nanosecond timestamps.

## Runnable Capture Specification (`telemetry_ptp_suite.frasm`)

```frameassembly
host spine_exporter { ip 172.20.0.1    mac 00:1c:73:d0:00:01 }
host telemetry_col  { ip 172.20.50.10  mac 00:50:56:d0:50:10 }

flow flow_collectors_ingest(exp, col) {
    // 1. Cisco NetFlow v5 (UDP 2055) + Dual-Stack Self-Templated IPFIX (UDP 4739)
    exp -> col netflow srcip 10.20.5.14 dstip 203.0.113.80 srcport 54120 dstport 443 proto 6 packets 8500 octets 12240000 wait 2ms
    exp -> col ipfix domainid 10 srcip 10.100.4.15 dstip 198.51.100.44 srcport 50112 dstport 443 proto 6 packets 420 octets 512000 wait 2ms
    exp -> col ipfix domainid 20 srcip 2001:db8:20::15 dstip 2001:db8:99::5051 srcport 54200 dstport 50051 proto 6 packets 95 octets 84000 wait 2ms

    // 2. Switch sFlow v5 XDR packet sampling on UDP 6343
    exp -> col sflow agentip 172.20.0.1 subagentid 1 seq 101 uptime 450000 samples 1 wait 1ms
    exp -> col sflow agentip 172.20.0.1 subagentid 1 seq 102 uptime 451000 samples 1 wait 2ms
}

flow ptpv2_twostep_nanosecond_sync(gm, slave) {
    // 3. IEEE 1588v2 Two-Step PTP (UDP 320 General + UDP 319 Event) with us/ns precision
    gm -> slave dscp 46 ptp announce domain 127 seqid 500 clockid "ec4670fffe010203" wait 250us
    gm -> slave dscp 46 ptp sync domain 127 seqid 501 clockid "ec4670fffe010203" wait 500ns
    gm -> slave dscp 46 ptp followup domain 127 seqid 501 clockid "ec4670fffe010203" wait 180us
    slave -> gm dscp 46 ptp delayreq domain 127 seqid 88 clockid "005056fffed05010" wait 120us
    gm -> slave dscp 46 ptp delayresp domain 127 seqid 88 clockid "ec4670fffe010203" wait 1ms
}

compile {
    flow_collectors_ingest(spine_exporter, telemetry_col)
    ptpv2_twostep_nanosecond_sync(spine_exporter, telemetry_col)
}
```

## Equivalent CLI Commands

```bash
# 1. Compile to nanosecond-precision .pcapng (preserves wait 500ns / 120us timestamps!)
frameassembly telemetry_ptp_suite.frasm telemetry_ptp_suite.pcapng

# 2. Verify NetFlow/IPFIX (cflow), sFlow v5, and PTPv2 fields in tshark
tshark -r telemetry_ptp_suite.pcapng -Y "cflow || sflow || ptp"

# 3. Replay toward ElastiFlow, Akvorado, GoFlow2, pmacct, or PTP boundary-clock monitors
sudo tcpreplay -i eth0 telemetry_ptp_suite.pcapng
```

## Protocol Reference Links

- [`netflow` — Cisco NetFlow Version 5 Flow Export](https://frameassembly-lang.dev/docs/protocols/netflow) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/netflow.md))
- [`ipfix` — IP Flow Information Export (NetFlow v10)](https://frameassembly-lang.dev/docs/protocols/ipfix) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/ipfix.md))
- [`sflow` — sFlow Version 5 Switched & Routed Packet Sampling](https://frameassembly-lang.dev/docs/protocols/sflow) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/sflow.md))
- [`ptp` — IEEE 1588 Precision Time Protocol v2](https://frameassembly-lang.dev/docs/protocols/ptp) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/ptp.md))
