DPDK 流量bps计算

228 阅读1分钟

简介

大家常见的流量速率bps,具体是怎么计算出来的呢?

Ethernet II 帧格式

一个帧以7个字节的前导码和1个字节的帧开始符作为帧的开始。另外当一个帧发送出去之后,发送方在下次发送帧之前,需要再发送至少12个octet的空闲线路状态码(即帧间距)。

  • 前导码(preamble),长度为7个字节,0和1交替变换的码流。
  • 帧开始符(SFD),长度为1个字节。
  • 帧间距(IPG),长度为12个字节。

image.png image.png

示例

  • RTE_TM_ETH_FRAMING_OVERHEAD 为前导码+帧开始符+帧间距之和,即20个字节。
  • RTE_TM_ETH_FRAMING_OVERHEAD_FCS 为前导码+帧开始符+帧间距+CRC之和,即24个字节。
  • rte_pktmbuf_data_len(m) + 24 即报文长度+24来作为流量字节数统计。
  • 如当前流量字节数为x,一秒后是y,则bps = (y-x)*8。
/**
 * Ethernet framing overhead.
 *
 * Overhead fields per Ethernet frame:
 * 1. Preamble:                                            7 bytes;
 * 2. Start of Frame Delimiter (SFD):                      1 byte;
 * 3. Inter-Frame Gap (IFG):                              12 bytes.
 *
 * One of the typical values for the *pkt_length_adjust* field of the shaper
 * profile.
 *
 * @see struct rte_tm_shaper_params
 */
#define RTE_TM_ETH_FRAMING_OVERHEAD                  20

/**
 * Ethernet framing overhead including the Frame Check Sequence (FCS) field.
 * Useful when FCS is generated and added at the end of the Ethernet frame on
 * Tx side without any SW intervention.
 *
 * One of the typical values for the pkt_length_adjust field of the shaper
 * profile.
 *
 * @see struct rte_tm_shaper_params
 */
#define RTE_TM_ETH_FRAMING_OVERHEAD_FCS              24