Skip to main content

sFlow报文格式

采样流sFlow(Sampled Flow)是一种基于报文采样的网络流量监控技术,主要用于对网络流量进行统计分析。

报文格式

sFlow通过UDP协议传递统计信息,如所示。

sFlow报文格式
 +------------+------+--------+----------------+
 | Ethernet头 | IP头 | UDP头 | sFlow Datagram |
 +------------+------+--------+----------------+

sFlow Datagram

sFlow Datagram报文头格式
 0                                                31
 +-------------------------------------------------+
 |               Datagram version                 |
 +-------------------------------------------------+
 |               Agent address type               |
 +-------------------------------------------------+
 |                                                 |
 |                 Agent address                 |
 |                                                 |
 |                                                 |
 +-------------------------------------------------+
 |                   Sub-agent ID                 |
 +-------------------------------------------------+
 |                 Sequence number               |
 +-------------------------------------------------+
 |                     SysUptime                   |
 +-------------------------------------------------+
 |                     NumSamples                 |
 +-------------------------------------------------+
 |                     n samples                   |
 |                         ...                     |
 +-------------------------------------------------+
sFlow Datagram报文头字段解释
字段 长度 含义
Datagram version 4字节 sFlow版本号,目前仅支持版本5。
Agent address type 4字节 设备的IP类型。
Agent address 4/16字节 设备的IP地址,IPv4地址占用4字节,IPv6地址占用16字节。
Sub-agent ID 4字节 子设备ID,不支持分布式场景下默认为0。
Sequence number 4字节 sFlow报文序列号。
SysUptime 4字节 自设备启动时刻到当前时刻经过的时长,单位是毫秒。
NumSamples 4字节 包含的采样数。
n samples - 采样数据报文。

Expanded Flow Sample

sFlow报文共有4种报文头格式,分别为Flow Sample、Expanded Flow Sample、Counter Sample以及Expanded Counter Sample,目前路由器设备仅支持Expanded Flow Sample。

Expanded Flow Sample报文头格式
 0                                                31
 +-------------------------------------------------+
 |           Enterprise         |sFlow sample type|
 +-------------------------------------------------+
 |               Sample length (byte)             |
 +-------------------------------------------------+
 |                 Sequence number                 |
 +-------------------------------------------------+
 |                 Source ID type                 |
 +-------------------------------------------------+
 |                 Source ID Index               |
 +-------------------------------------------------+
 |                   Sampling rate                 |
 +-------------------------------------------------+
 |                   Sample pool                 |
 +-------------------------------------------------+
 |                   Dropped packets               |
 +-------------------------------------------------+
 |               Input interface format           |
 +-------------------------------------------------+
 |               Input interface value             |
 +-------------------------------------------------+
 |               Output interface format           |
 +-------------------------------------------------+
 |               Output interface value           |
 +-------------------------------------------------+
 |                   Flow record                 |
 +-------------------------------------------------+
 |                     n records                 |
 |                         ...                     |
 +-------------------------------------------------+
Expanded Flow Sample报文头字段解释
字段 长度 含义
Enterprise 20比特 企业位。
sFlow sample type 12比特 sFlow报文类型,Expanded Flow Sample取值为3。
Sample length (byte) 4字节 除了Enterprise、sFlow sample type以及本字段以外的报文长度。
Sequence number 4字节 Expanded Flow Sample报文序列号。
Source ID type 4字节 数据源类型。
Source ID Index 4字节 数据源索引。
Sampling rate 4字节 采样率。
Sample pool 4字节 采样池内的报文数。
Dropped packets 4字节 sFlow缓存队列满后无法入队从而被抛弃的报文数。
Input interface format 4字节 入接口类型。
Input interface value 4字节 入接口值。
Output interface format 4字节 出接口类型。
Output interface value 4字节 出接口值。
Flow record 4字节 包含的记录数。
n records - Expanded Flow Sample报文数据信息。
Expanded Flow Sample报文数据信息
 +-------------------------------------------------+
 |               Raw packet header               |
 +-------------------------------------------------+
 |               Ethernet frame data               |
 +-------------------------------------------------+
 |                   IPv4 data                   |
 +-------------------------------------------------+
 |                   IPv6 data                   |
 +-------------------------------------------------+
 |               Extended switch data             |
 +-------------------------------------------------+
 |               Extended router data             |
 +-------------------------------------------------+
 |               Extended gateway data             |
 +-------------------------------------------------+
Expanded Flow Sample报文字段解释
字段 长度 含义
Raw packet header 72字节 截取原始报文全部或者一部分报文头,包括: Enterprise:企业位。Format:标识位。Flow data length (byte):除了Enterprise、Format以及本字段以外的报文长度。Header protocol:原始数据的MAC协议类型,置为1是Ethernet。Frame Length:原始报文总字节数。Payload removed:截取报文时被忽略的字节数。Original packet length:被截取报文的字节数。Header of sampled packet:截取的报文字段。
Ethernet frame data 32字节 针对Ethernet报文,解析报文的Ethernet头信息,包括: Enterprise、Format以及Flow data length (byte)。Length of MAC Packet:原始报文总字节数(包括Ethernet头及后续报文长度)。Source MAC Address:源MAC地址。Destination MAC Address:目的MAC地址。Ethernet Packet Type:Ethernet报文类型。
IPv4 data 40字节 针对IPv4报文,解析报文的IPv4头信息,包括: Enterprise、Format以及Flow data length (byte)。Length of IP Packet:原始报文总字节数(包括IP头及后续报文长度)。IP Protocol:协议类型,置为6是TCP,置为17是UDP。Source IP address:源IPv4地址。Destination IP address:目的IPv4地址。Source Port:源端口号。Destination Port:目的端口号。TCP Flag:TCP标志位。其它字段:服务类型。
IPv6 data 64字节 与IPv4类似,区别在于源、目的IPv6地址各占用16字节。
Extended switch data 24字节 针对转发的Ethernet报文,记录报文的VLAN转换以及VLAN优先级的转换,包括: Enterprise、Format以及Flow data length (byte)。Incoming 802.1Q VLAN:入方向VLAN LD。Incoming 802.1p priority:入方向VLAN优先级。Outgoing 802.1Q VLAN:出方向VLAN LD。Outgoing 802.1p priority:出方向VLAN优先级。
Extended router data 24字节 针对路由转发的报文,记录报文的路由转发信息,包括: Enterprise、Format以及Flow data length (byte)。Next hop:下一跳IP地址。Next hop source mask:源IP地址的掩码长度。Next hop destination mask:目的IP地址的掩码长度。
Extended gateway data 40字节 针对BGP路由转发的报文,记录报文的BGP路由转发信息,包括: Enterprise、Format以及Flow data length (byte)。Next hop:下一跳IP地址。AS Router:设备的AS编号。AS Source:源AS编号。AS Peer:对端AS编号。AS Destinations:目的AS编号。Gateway Communities:BGP团体列表。localpref:本地优先级。

参考标准

标准 描述
RFC 3176 A Method for Monitoring Traffic in Switched and Routed Networks