# ipfix — Self-Templated IPv4 & IPv6 Flow Exports (UDP 4739) (`ipfix`)

> **FrameAssembly v3.2.2** · Protocol 44 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/ipfix

- **Full Protocol Name:** IP Flow Information Export (NetFlow v10)
- **Keyword:** `ipfix`
- **OSI Layer & Transport:** Layer 7 · UDP 4739
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 7011, RFC 7012
- **Wireshark Display Filter:** `cflow.version == 10`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 4739 -> IPFIX`

## Overview

Wireshark hates orphan IPFIX data records with missing templates, so FrameAssembly bundles **Template Set `2` (`256`) + Data Set `256`** inside the same UDP `4739` packet so every single frame dissects immediately!

IP Flow Information Export (`ipfix`, RFC 7011—standardized from NetFlow v9 as Version `10` / `0x000a`) exports flexible IPv4 and IPv6 traffic telemetry on **UDP port `4739`**. A common headache when testing IPFIX collectors or viewing partial captures in Wireshark is missing templates: without the Template Set, collectors cannot decode Data Sets.

FrameAssembly solves that automatically by packing both the **Template Set (`Set ID 2`)** and the matching **Data Set** inside every `ipfix` packet, so Wireshark, ElastiFlow, pmacct, and GoFlow2 decode every field immediately on packet 1.

## Minimal Quickstart (`ipfix_quickstart.frasm`)

```frameassembly
host leaf_sw   { ip 10.30.0.1 }
host collector { ip 10.30.0.100 }

compile {
    leaf_sw -> collector ipfix domainid 100 srcip 10.30.10.25 dstip 198.51.100.50 srcport 51200 dstport 443 proto 6 packets 60 octets 72000
}
```

### Automatic Wire Calculations

- Defaults to UDP destination port `4739` and builds the 16-byte IPFIX Version `0x000a` header with exact total message length and Observation Domain ID.
- Bundles a self-describing Template Set (`Set ID 2`, Template ID `256`) plus the Data Set (`Set ID 256`) in one UDP datagram.
- Automatically switches IANA Information Elements between IPv4 (`sourceIPv4Address 8` / `destinationIPv4Address 12`) and IPv6 (`27` / `28`) based on `srcip` and `dstip`.

## Practical Lab Example: Mixed IPv4 & IPv6 VRF Flow Telemetry to an IPFIX Collector (`ipfix_dualstack_flows.frasm`)

Exports an IPv4 enterprise HTTPS flow (`domainid 10`) followed by an IPv6 service-mesh gRPC flow (`domainid 20`) to UDP port 4739.

```frameassembly
host spine_exporter { ip 172.20.0.1 }
host ipfix_ingest   { ip 172.20.50.10 }

compile {
    // 1. VRF 10 IPv4 flow record
    spine_exporter -> ipfix_ingest ipfix domainid 10 srcip 10.100.4.15 dstip 203.0.113.44 srcport 50112 dstport 443 proto 6 packets 420 octets 512000 wait 3ms
    // 2. VRF 20 IPv6 flow record over the same exporter session
    spine_exporter -> ipfix_ingest ipfix domainid 20 srcip 2001:db8:20::15 dstip 2001:db8:99::5051 srcport 54200 dstport 50051 proto 6 packets 95 octets 84000
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show ipfix_dualstack_flows.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly ipfix_dualstack_flows.frasm ipfix_dualstack_flows.pcap
frameassembly ipfix_dualstack_flows.frasm ipfix_dualstack_flows.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse ipfix_dualstack_flows.pcap ipfix_dualstack_flows_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r ipfix_dualstack_flows.pcap
```

## All `ipfix` Keywords & Header Options

Packet line pattern: `src_host -> dst_host ipfix [domainid <number>] [srcip <ip>] [dstip <ip>] [srcport <0..65535>] [dstport <0..65535>] [proto <0..255>] [packets <number>] [octets <number>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `domainid <number>` | 32-bit Observation Domain ID | `1` | Sets the 4-byte Observation Domain ID in bytes 12..15 of the IPFIX header. |
| `srcip <ip> \| dstip <ip>` | IPv4 or IPv6 address | `Outer host IP` | Sets the exported flow’s source and destination IP addresses (both IPv4 or both IPv6). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `49152 / 80` | Populates `sourceTransportPort` (IE 7) and `destinationTransportPort` (IE 11) in the Data Set. |
| `proto <0..255>` | IP protocol number (`6` TCP, `17` UDP, `58` ICMPv6) | `6 (TCP)` | Populates `protocolIdentifier` (IE 4) in the IPFIX Data Set. |
| `packets <number> \| octets <number>` | Packet and byte counters | `packets 10, octets 1500` | Populates `packetDeltaCount` (IE 2) and `octetDeltaCount` (IE 1) in the Data Set. |

## Cross-Layer Options Valid with `ipfix`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 4739` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### Match Address Families on srcip and dstip

- **Avoid:** `leaf_sw -> collector ipfix srcip 10.0.0.1 dstip 2001:db8::2`
- **Valid v3.2.2 Syntax:** `leaf_sw -> collector ipfix srcip 2001:db8::1 dstip 2001:db8::2`

A single flow record represents either an IPv4 conversation or an IPv6 conversation, so `srcip` and `dstip` must use the same IP version.

### Wireshark Uses the cflow Display Filter for Both NetFlow and IPFIX

- **Valid v3.2.2 Syntax:** `Wireshark filter: cflow.version == 10`

In Wireshark, IPFIX is dissected under the unified `cflow` dissector (`cflow.version == 10`) rather than a filter named `ipfix`.
