decodesflow

Decodes sFlow v5 packets from Ethernet frames, extracting agent information, sample types, sampling statistics, and other data.

Command properties

ItemDescription
Command typeProcessing query
Required permissionNone
License usageN/A
Parallel executionSupported
Distributed executionRuns on Data Node (mapper)

Syntax

decodesflow

Input fields

FieldTypeRequiredDescription
payloadbinaryRequiredEthernet frame data. If the field is not binary type, the record is ignored.

Output fields

FieldTypeDescription
src_ipipaddrSource IP address
src_portintegerSource port number
dst_ipipaddrDestination IP address
dst_portintegerDestination port number
protocolstringTransport protocol: udp
verintegersFlow protocol version: 5
agent_addripaddrsFlow agent IP address
agent_idintegersFlow sub-agent ID
flow_seqlongsFlow packet sequence number
uptimelongAgent system uptime in milliseconds
sample_typestringSample type: flow or counters
sample_seqlongSample sequence number
src_id_typeintegerSource ID type
src_idintegerSource index
sampling_rateintegerSampling rate. Applies to flow samples only.
sample_poollongTotal sampling pool count. Applies to flow samples only.
dropslongNumber of dropped packets. Applies to flow samples only.
input_if_formatintegerInput interface format. Applies to flow expanded samples only.
input_if_valueintegerInput interface value. Applies to flow expanded samples only.
output_if_formatintegerOutput interface format. Applies to flow expanded samples only.
output_if_valueintegerOutput interface value. Applies to flow expanded samples only.
input_if_indexintegerInput interface index. Applies to flow samples only.
output_if_indexintegerOutput interface index. Applies to flow samples only.
flowsarrayList of flow data records. Applies to flow samples only.
countersarrayList of counter data records. Applies to counters samples only.

Error codes

Parse errors

N/A

Runtime errors

N/A

Description

The decodesflow command reads an Ethernet frame from the payload field of each input record and decodes sFlow v5 packets. If the payload field is not binary type, the record is ignored.

The command sequentially parses the IPv4 header and UDP header from the Ethernet frame, then verifies the sFlow v5 magic number (0x00000005) in the UDP payload. Records that are not sFlow v5, not IPv4, or not UDP are ignored.

Because a single sFlow packet can contain multiple samples, one input record may produce multiple output records. Depending on the sample type, flow samples include sampling_rate, sample_pool, drops, and interface information; counters samples include the counters array.

If decoding fails, the record is ignored and processing continues with the next record.

This command supports parallel execution and runs on the Data Node in a distributed environment.

Examples

  1. Decoding sFlow packets from a PCAP file

    pcapfile /opt/logpresso/sflow-capture.pcap
    | decodesflow
    

    Decodes sFlow v5 packets from Ethernet frames read from a PCAP file.

  2. Aggregating sample counts by sFlow agent

    pcapfile /opt/logpresso/sflow-capture.pcap
    | decodesflow
    | stats count by agent_addr
    

    Aggregates sample counts by sFlow agent IP address.

  3. Filtering and querying flow samples only

    pcapfile /opt/logpresso/sflow-capture.pcap
    | decodesflow
    | search sample_type == "flow"
    | fields agent_addr, sample_seq, sampling_rate, drops, src_ip, dst_ip
    

    Filters only flow-type samples from sFlow packets and retrieves key fields.