# netflow — 72-Byte Cisco NetFlow v5 Collector Records (`netflow`)

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

- **Full Protocol Name:** Cisco NetFlow Version 5 Flow Export
- **Keyword:** `netflow`
- **OSI Layer & Transport:** Layer 7 · UDP 2055
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** Cisco NetFlow v5
- **Wireshark Display Filter:** `cflow`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 2055 -> NetFlow v5`

## Overview

Want to verify your flow dashboard lights up when a workstation ships 50 GB outbound without actually saturating a 10G link? One `netflow` packet reports any `packets` and `octets` count you ask for.

Cisco NetFlow v5 (`netflow`) exports summarized IPv4 traffic conversations from routers, switches, and firewalls to bandwidth monitors and NDR collectors (ElastiFlow, Akvorado, SolarWinds, ntopng, PRTG) over **UDP port `2055`**.

Each `netflow` packet in FrameAssembly builds a complete `72`-byte datagram: the 24-byte NetFlow v5 header (`version 5`, `count 1`, uptime, timestamps, sequence) followed by a 48-byte flow record containing `srcip`, `dstip`, `srcport`, `dstport`, IP `proto`, `packets`, and `octets` (byte count).

## Minimal Quickstart (`netflow_quickstart.frasm`)

```frameassembly
host core_rtr  { ip 10.0.0.1 }
host collector { ip 10.0.50.20 }

compile {
    core_rtr -> collector netflow srcip 10.10.1.25 dstip 198.51.100.40 srcport 52410 dstport 443 proto 6 packets 120 octets 164000
}
```

### Automatic Wire Calculations

- Defaults UDP destination port to `2055` and builds the exact 24-byte NetFlow v5 header + 48-byte flow record (`72` UDP payload bytes).
- Populates protocol defaults (`proto 6` TCP, `packets 10`, `octets 1500`) whenever counters are omitted.
- Works over either IPv4 or IPv6 outer exporter-to-collector transport IPs (`ipfix` is available when the exported flow record itself carries IPv6 endpoints).

## Practical Lab Example: Multi-Flow Export: HTTPS Upload Spike, DNS Lookup & ICMP Probe (`netflow_collector_test.frasm`)

Exports three sequential NetFlow v5 records from a border router representing a large HTTPS transfer, a UDP DNS query, and an ICMP ping flow.

```frameassembly
host border_rtr     { ip 172.16.0.1 }
host flow_collector { ip 172.16.100.55 }

compile {
    // 1. Large outbound HTTPS transfer (proto 6 = TCP)
    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 203.0.113.80 srcport 54120 dstport 443 proto 6 packets 8500 octets 12240000 wait 2ms
    // 2. Internal-to-DMZ DNS flow (proto 17 = UDP)
    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 172.16.10.53 srcport 59102 dstport 53 proto 17 packets 2 octets 148 wait 2ms
    // 3. ICMP reachability flow (proto 1 = ICMP)
    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 8.8.8.8 srcport 0 dstport 0 proto 1 packets 4 octets 336
}
```

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

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

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

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

## All `netflow` Keywords & Header Options

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

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `srcip <ipv4> \| dstip <ipv4>` | IPv4 address (e.g. 10.10.1.25) | `Outer host IPv4 (or 10.0.0.1 / 10.0.0.2)` | Sets the exported IPv4 Source and Destination addresses inside the 48-byte NetFlow v5 record. |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `Outer UDP ports or 0 / 80` | Sets the exported flow’s L4 ports inside the NetFlow record (or overrides UDP ports when used at transport level). |
| `proto <0..255>` | IP protocol number (`6` TCP, `17` UDP, `1` ICMP) | `6 (TCP)` | Sets byte 38 (`prot`) of the NetFlow v5 flow record. |
| `packets <number>` | 32-bit packet count | `10` | Sets the `dPkts` 32-bit packet counter for the flow. |
| `octets <number>` | 32-bit byte count | `1500` | Sets the `dOctets` 32-bit Layer 3 byte counter for the flow. |

## Cross-Layer Options Valid with `netflow`

| 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 2055` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### NetFlow v5 Flow Records Only Hold IPv4 Flow Addresses (Use ipfix for IPv6 Flows)

- **Avoid:** `core_rtr -> collector netflow srcip 2001:db8::10 dstip 2001:db8::20`
- **Valid v3.2.2 Syntax:** `core_rtr -> collector ipfix srcip 2001:db8::10 dstip 2001:db8::20`

Classic Cisco NetFlow v5 has fixed 32-bit IPv4 `srcaddr`/`dstaddr` slots. To export IPv6 flow records, use `ipfix` (RFC 7011 / NetFlow v10).

### Byte Count Is Called octets (Not bytes)

- **Avoid:** `core_rtr -> collector netflow packets 50 bytes 64000`
- **Valid v3.2.2 Syntax:** `core_rtr -> collector netflow packets 50 octets 64000`

Following Cisco NetFlow terminology (`dOctets`), specify the byte counter with `octets <number>`.
