NetFlow and IPFIX sampling and timeouts without missing attacks

How the sampling rate, flow timeouts, and template refresh affect DDoS detection in EdgeWarden, with suggested values by link size.

What you'll tune

Three exporter settings decide whether an attack shows up in EdgeWarden within seconds, half an hour later, or never:

  • Sampling rate: at 1:N, the router takes 1 out of every N packets and skips the other N−1. It sets the smallest attack you can see.
  • Active and inactive timeout: how long a flow sits in the router cache before it is exported. It sets detection latency.
  • Template and options refresh: how often the router resends the template and the sampling rate. It sets how long the numbers stay wrong after a restart.

Prerequisites

  • A router already exporting NetFlow v9 or IPFIX to the collector at 192.0.2.10, port 2055/UDP, from a fixed IP (in this example, the loopback 198.51.100.1).
  • The router registered under Configurações → Rede → Dispositivos (Settings → Network → Devices) with that IP and with SNMP, so you can compare flow volume against the interface counter.
  • A maintenance window: changing the sampling rate shifts every graph for that exporter.

How EdgeWarden compensates for sampling

The collector multiplies bytes and packets by the rate before storing them; the screens never multiply again. A single flow sampled at 1:1000 shows up on the Flows screen already multiplied by 1000. The rate comes from one of three sources:

  1. Announced by the router: NetFlow v9 and IPFIX can send the rate in an Options Template (EdgeWarden reads fields 34, 50, 305, and 306). When present, this value always wins. If the router announces different rates per interface and direction, each flow gets the rate of its own interface.
  2. Entered manually: the device's Taxa de Amostragem de Flow (flow sampling rate) field (1000 = 1:1000). It applies when the router doesn't announce a rate, it is a single value per exporter, and it reloads without restarting the service.
  3. Embedded in sFlow: each sample carries its own rate.

With NetFlow v5, EdgeWarden does not apply the rate automatically. Without the manual entry, a router at 1:1000 shows one thousandth of the real traffic and every threshold becomes meaningless.

Step 1: choose the sampling rate

With 1:N sampling, traffic of P packets per second produces about P/N samples per second. The relative error of the estimate is roughly 1/√n, where n is the number of samples in the window. With the default 10-second analysis cycle:

Traffic toward the targetSamples per cycle at 1:100Samples per cycle at 1:1000
1,000 pps100 (~10% error)10 (~32% error)
10,000 pps1,000 (~3% error)100 (~10% error)
100,000 pps10,000 (~1% error)1,000 (~3% error)

A rule of thumb: to get at least 100 samples per cycle, keep N at or below one tenth of the smallest attack, in pps, that you need to see. To catch 10,000 pps, 1:1000 is enough; for 1,000 pps, you need 1:100 or lower.

Small flows suffer the most. A destination that receives k packets, with k much smaller than N, has roughly a k/N chance of showing up: at 1:1000, a host that receives 50 packets from a scan shows up about one time in 20. That's why carpet bombing, with little traffic per IP, should be handled with block rules (Subnet/Bloco), which sum the whole prefix.

The cost lands on the exporter: a smaller N (denser sampling) means more cache entries, more export packets, and more CPU, especially when flow accounting runs in software. Platforms with hardware flow accounting have their own export limits; check the one for your model. Suggested starting values, assuming an average packet size of 1,000 bytes:

Router peak trafficStarting rateSamples/s at peakSmallest attack with ~100 samples per cycle
up to 1 Gbps1:100~1,2501,000 pps
1 to 10 Gbps1:500~2,5005,000 pps
10 to 100 Gbps1:1000~12,50010,000 pps
above 100 Gbps1:2000 to 1:4000~3,000 to 6,000 per 100 Gbps20,000 to 40,000 pps

The accepted range varies by platform: Junos 1 to 16,000,000 (the MX150 warns below 1000), IOS-XE 2 to 32768 in the general reference, IOS-XR 1 to 65535, and VRP 1 to 65535. Some models accept only part of it.

Step 2: tune the active and inactive timeouts

The active timeout exports long-lived flows at fixed intervals. The inactive timeout exports flows that stopped receiving packets. Both matter for detection:

  • An attack with a stable 5-tuple, such as a flood from a few fixed sources, is only reported when the active timeout expires.
  • An attack with spoofed sources and ports creates a new flow for every sampled packet. Those flows carry a single packet and leave through the inactive timeout.

Worst-case latency is the active timeout plus one analysis cycle (10 s by default, configurable down to 1 s). Several vendors default to 30 minutes, which makes detection useless. Use 60 s active and 15 s inactive; drop active to 30 s if the router CPU allows. Below that the gain is small and the load grows. To react in under 1 second, use sFlow or the Packet Sensor.

PlatformActive (default)Inactive (default)Range
Junos (inline J-Flow, IPFIX template)60 s60 s10 to 600 s
IOS-XE (Flexible NetFlow)1800 s15 s1 to 604800 s
IOS-XR1800 s15 splatform dependent
VRP (NE40E/NE8000)30 min on several releasesrelease dependentactive in minutes or, on recent releases, in seconds
RouterOS v730m15sno published range

Step 3: resend templates and the rate often

NetFlow v9 and IPFIX over UDP need the template to decode records. After a collector or router restart, records that arrive before the template are lost, and flows that arrive before the options template have no announced rate. During that gap EdgeWarden uses the manually entered value; without one, traffic shows up divided by the rate and the carpet bomb detector holds off learning its baseline for up to 30 minutes.

The defaults are long: 600 s on IOS-XE and Junos, 1800 s on IOS-XR. Use 60 s. The blocks below show only the settings covered here, on top of the configuration from each vendor guide.

Junos: rate, timeouts, and refresh
set forwarding-options sampling instance ew-sampling input rate 1000
set services flow-monitoring version-ipfix template ew-ipv4 flow-active-timeout 60
set services flow-monitoring version-ipfix template ew-ipv4 flow-inactive-timeout 15
set services flow-monitoring version-ipfix template ew-ipv4 template-refresh-rate seconds 60
set services flow-monitoring version-ipfix template ew-ipv4 option-refresh-rate seconds 60

Repeat the template lines for ew-ipv6. Junos options data includes the sampling interval (field 34).

IOS-XE: sampler, monitor, and exporter
sampler EW-SAMP
 mode random 1 out-of 1000
!
flow monitor EW-MON-V4
 cache timeout active 60
 cache timeout inactive 15
!
flow exporter EW-EXP
 template data timeout 60
 option sampler-table timeout 60
IOS-XR: sampler-map, monitor-map, and exporter-map
sampler-map EW-SAMP
 random 1 out-of 1000
!
flow monitor-map EW-MON-V4
 cache timeout active 60
 cache timeout inactive 15
!
flow exporter-map EW-EXP
 version ipfix
  template data timeout 60
  options sampler-table timeout 60
 !
!
commit

On both Cisco platforms, repeat the timeouts on EW-MON-V6.

VRP8: rate, timeouts, and options sampler
ip netstream sampler fix-packets 1000 inbound
ip netstream sampler fix-packets 1000 outbound
ip netstream timeout active interval-second 60
ip netstream timeout inactive 15
ip netstream export template timeout-rate 1
ip netstream export template option sampler
ip netstream export template option timeout-rate 1
commit

On VRP, interval-second exists on recent NE8000 and NE40E releases; on older releases the active timeout is in minutes (ip netstream timeout active 1). Both timeout-rate values are in minutes. Repeat with ipv6 netstream for IPv6.

RouterOS v7: 1:1000 sampling and timeouts
# 1 packet sampled, 999 skipped
/ip traffic-flow set packet-sampling=yes sampling-interval=1 sampling-space=999 active-flow-timeout=1m inactive-flow-timeout=15s

RouterOS resends the template every 20 packets by default (v9-template-refresh, under /ip traffic-flow target), but its documentation doesn't describe announcing the rate: on MikroTik, the manual entry is mandatory.

Step 4: enter the rate in EdgeWarden

Under Configurações → Rede → Dispositivos, edit the router and set Taxa de Amostragem de Flow to the same N as the router (1000 for 1:1000; 1 for unsampled). Do this even when the router announces the rate: the announced value still wins, and the manual entry covers the gap after a restart until the options template arrives.

The screen shows a detectado (detected; announced rate, v9 and IPFIX only) or manual badge. If the announced value differs from the entry, you'll see the warning cadastro: 1:N (ignorado) (entry ignored).

Changed the rate on the router? Change the entry in the same window. On exporters that don't announce the rate, the old entry multiplies by the wrong value and every threshold for that router becomes meaningless.

Verifying on the router

PlatformCommandWhat to check
Junosshow services accounting flow inline-jflow fpc-slot 0Flows Active Timed Out and Flows Inactive Timed Out increasing
IOS-XEshow flow monitor EW-MON-V4 and show sampler EW-SAMPActive and inactive timeout; sampler rate
IOS-XRshow flow monitor-map EW-MON-V4 and show sampler-map EW-SAMPTimeouts; Random (1 out of 1000 Pkts)
VRPdisplay netstream globalGlobal NetStream settings
RouterOS/ip traffic-flow printpacket-sampling, sampling-space, and timeouts

Verifying on EdgeWarden

EdgeWarden server: export arriving
sudo tcpdump -i any -n -c 5 udp port 2055 and host 198.51.100.1
10:15:02.481233 ens18 In  IP 198.51.100.1.50123 > 192.0.2.10.2055: UDP, length 1380
sudo journalctl -u flowspec-core -f

Then, in the web interface (labels are in Portuguese):

  1. Under Configurações → Rede → Dispositivos, check for the detectado or manual badge and make sure there is no ignored-entry warning.
  2. Within 1 to 2 minutes, flows show up on the Flows screen, already multiplied by the rate.
  3. On the Análise do instante screen, the Fluxo × SNMP nas interfaces (flow vs. SNMP) panel compares flow volume against the SNMP counter. If the flow shows 1/N of SNMP, the rate is missing; if it shows N times, it was applied twice.

Common pitfalls

  • The 30-minute default timeout. It's the most common cause of "the attack only showed up after it ended."
  • Different rates per direction. Some routers sample ingress and egress on the same port at different rates. If the rate is announced per interface, EdgeWarden applies each one; with the manual entry, no single value fits both. Validate against SNMP and treat the mismatched direction as an estimate.
  • Options template turned off. On VRP, without ip netstream export template option sampler the router doesn't announce the rate; on Cisco, the same goes for option sampler-table.
  • Sampling too dense. With a small N, the exporter saturates before the collector does: full cache, export errors, high CPU. Reduce N in steps while watching the CPU. On the server, check for drops with nstat -az | grep -iE "Udp.*(InErrors|RcvbufErrors)".
  • Small attacks going unseen. If you need to see attacks below what the rate allows, use the Packet Sensor instead of pushing the router to its limit.

Next steps

To pick the protocol before tuning the numbers, read NetFlow, IPFIX, or sFlow: which one to choose. The full per-vendor configuration is in the guides for Juniper MX, Huawei NE40E/NE8000, Cisco IOS-XE and IOS-XR, and MikroTik RouterOS v7. If flows don't show up, follow the step-by-step troubleshooting. See Features for how EdgeWarden uses these flows to detect and mitigate attacks.

Related articles

All articles

Want to see these flows in EdgeWarden?

Create your account in the Customer area and generate the demo license: 7 days with every Enterprise feature, on your own server. Then follow the installation guide to bring up the collector.