Skip to content

sFlow traffic (sflow) ​

Sums the packet samples that a router or switch exports as sFlow version 5, each scaled by the device's sampling rate, over a sliding window: how much traffic there is, who the biggest sources, destinations, conversations and services are, and how the traffic splits into TCP, UDP, ICMP and the rest. It can look at the whole device or at one interface of it, and for an interface it also reports the exact byte counters the device sends beside the samples. Every number is a channel, so limits apply.

It listens instead of asking and keeps only per-interval top lists, never the samples; the design, the limits and the memory they need are in architecture. Most of what the netflow sensor says holds here too (intervals, the window, extra_sources, "Who talked", the limits to set); this page says what differs.

What it looks like ​

The page of an sflow sensor in the light theme

The sensor's page after a few polls, for one interface (index 3) of a device that samples one packet in 100: the estimated traffic, the top lists with their shares, and the interface's own counters, which are exact. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.

What is different from NetFlow ​

  • Everything is an estimate. sFlow exports one packet in N, and a sampled packet stands for N packets of its size. Bytes, packets and the tables are multiplied by the rate of the sample they came from, and the sensor's message says sampled 1 in N, so the counts are estimates. A small flow may not be seen at all, and a short window has a wide error: 100 samples in a window are about 10 % off for a typical mix, 1,000 about 3 %. The top lists are those of traffic, which sampling is good at, and not of rare events, which it is not. Keep the window at five minutes or more, and a sampling rate that gives at least some hundreds of samples a window on the busiest interface.
  • There are no flows. A sample is one packet, so there is no flows_per_s channel, and no undecoded (sFlow needs no templates).
  • Counters. A device also sends a counter sample for each interface every few seconds. With an interface set, the sensor adds the difference between consecutive samples to the interval, and reports it as interface_in_bps and interface_out_bps: the interface's own octet counters, exact and not sampled, from the interface's point of view (in is received by the device). They are the check on the estimate: when the two disagree by much, the sampling rate is wrong or the interface is not the one the samples are of. A counter that went down (the device restarted) gives no difference for that sample. Without an interface the counters are not used.
  • The size of a packet is its frame. A sample's size is the length of the frame on the wire, with its Ethernet header, which is what the interface counters count. NetFlow counts the IP packet, a little less.
  • An interface is the sample's input or output interface, as the device writes it (an ifIndex; a VLAN or a "multiple destinations" value is not an interface and matches none).
  • Packet headers are read as far as they were captured. The sample carries the first bytes of the packet; Ethernet, up to two VLAN tags, IPv4, IPv6 (with the common extension headers) and the TCP or UDP ports are read. A header cut short loses the ports, not the packet. A second fragment has no ports. Samples that carry the extracted IPv4 or IPv6 fields instead of a header are read too. Extended records (switch, router, gateway) are skipped.
  • The agent address inside a datagram is not used. The device is the address the datagram came from, as for NetFlow; put another address in extra_sources when the device exports from it.

Channels ​

KeyNameUnitDefault limits
bits_per_sTraffic (estimated)bit/snone
packets_per_sPackets (estimated)packets/snone
top_source_bps, top_source_share_pctTop source, and its share of all trafficbit/s, %none
top_destination_bps, top_destination_share_pctTop destination, and its sharebit/s, %none
top_conversation_bps, top_conversation_share_pctTop conversation, and its sharebit/s, %none
top_service_bps, top_service_share_pctTop service, and its sharebit/s, %none
tcp_bps, udp_bps, icmp_bps, other_bpsTraffic by protocol classbit/snone
active_sourcesDistinct source hosts seen in the busiest intervalhostsnone
interface_in_bps, interface_out_bpsThe interface's byte counters (only with interface)bit/snone
since_last_flow_sTime since the device last sent a datagram the probe could readsnone; unknown before the first
droppedDatagrams dropped by the rate limitnonewarning above 0
lostDatagrams missing from the device's sequence numbersnonewarning above 0
unreadableDatagrams that could not be readnonewarning above 0

active_sources can only count sources that were sampled, so on a lightly loaded device it is a lower bound.

Parameters ​

The same as the netflow sensor: window_secs, interface, direction, extra_sources, sampling_rate and top_n. sampling_rate is rarely needed: every sample carries its own rate. A rate you set replaces what the samples say, for the whole device.

Suggested interval: 60 seconds. No credential.

What is read ​

sFlow version 5 datagrams over UDP, with an IPv4 or IPv6 agent address: flow samples and expanded flow samples (raw packet header records, sampled IPv4 and IPv6 records), counter samples and expanded counter samples (the generic interface counters record). Other record types, enterprise formats, and sFlow version 2 and 4 are skipped or refused (a version other than 5 is counted as unreadable). A datagram carries at most 4,096 samples the collector uses.

What the exporter needs ​

Point the device at the probe's address, UDP port 6343 (PROBEWARD_SFLOW_LISTEN changes it; it is above 1023, so no privilege is needed), let the firewall pass it, and give it a sampling rate and a counter polling interval of 20 to 30 seconds. Examples:

text
# VyOS
set system sflow interface eth0
set system sflow server 192.0.2.1 port 6343
set system sflow sampling-rate 64
set system sflow polling 20

# Linux, with hsflowd (sflow.conf)
sflow { agent = eth0  polling = 20  sampling = 100  collector { ip = 192.0.2.1  udpport = 6343 } pcap { dev = eth0 } }

The VyOS lines are what the lab's router runs; the hsflowd line is written from its documentation and was not run.

A rate that suits the link: 1 in 512 to 1 in 2,000 on a 10 Gbit/s uplink, 1 in 64 to 1 in 256 on a branch router. The cost on the device is its own; the cost on the probe is bounded by the rate limit.

Failures ​

MessageMeaning
cannot listen for sFlow on UDP 0.0.0.0:6343: another program on this host holds it ... (kind config)Another collector has the port. Stop it, or set PROBEWARD_SFLOW_LISTEN.
cannot listen for sFlow on UDP ...: permission denied (kind config)PROBEWARD_SFLOW_LISTEN names a privileged port.
this probe already watches N flow exporters, the most it keeps (kind config)PROBEWARD_FLOW_EXPORTERS is reached.

Nothing else fails a poll. A device that sends nothing is a reading, since_last_flow_s.

Verification ​

  • A real device. A VyOS router (rolling release) with sFlow on its interface, one packet in 64 sampled and counter samples every 20 seconds, exported to a probe listening on port 6343. The samples were read (raw packet headers), scaled, and summed; the sensor's message said sampled 1 in 64; a second sensor for the router's interface read the same samples and the interface's counters, which gave interface_in_bps and interface_out_bps. Traffic was many short TCP connections to the router and pings to it. The live test is crates/probeward-sensors/tests/live_flows.rs.
  • Hand-made datagrams, byte by byte: flow samples from a packet header (Ethernet, a VLAN tag, UDP and TCP, a header cut off after the IP header), sampled IPv4 and IPv6 records, expanded samples with an interface that is a VLAN, counter samples, an unknown sample, a sample count that is larger than the data, a wrong version. Every truncation of a valid datagram, 40,000 mutated ones and 40,000 random ones are read without a panic.
  • Real sockets on loopback: flow samples scaled by their rate, counter samples becoming the interface's octets, a counter that went down giving no difference, and a gap in the datagram sequence counted as lost.
  • Not seen: sFlow from any other make, expanded or IPv6 samples from a real device, VLAN-tagged headers from a real device, extended records, counters of interfaces other than the one the sensor names, a device sampling faster than the rate limit, a remote probe's collector.

The live test and its variables are described on the NetFlow sensor's page.

AGPL-3.0-only