*unix 系统下,一切皆文件的思想, 在各种命令中展现的淋漓尽致。

在网络协议开发过程中, 需要频繁使用各种pcap文件。
于是, pcap文件就成了网络协议开发的利器。

pcap 可以被tcpdump, wireshark, DPDK,tshark 生成,
pcap 也可以被tcpdump, wireshark, DPDK,tshark , WireEdit, nm_tcpreplay 打开

现需要创建一些虚拟网卡, 各个进程基于这个虚拟网卡进行读写。
一个进程向此网卡写入数据,
一个进程从此网卡读取数据。
链式操作。

模块信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# lsmod | grep dummy
[root@localhost ~]# modprobe dummy
[root@localhost ~]# rmmod dummy
[root@localhost ~]# modinfo dummy
filename: /lib/modules/3.10.0-693.el7.x86_64/kernel/drivers/net/dummy.ko.xz
alias: rtnl-link-dummy
license: GPL
rhelversion: 7.4
srcversion: 731B615EF9DDF6138AA9F45
depends:
intree: Y
vermagic: 3.10.0-693.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: DA:18:7D:CA:7D:BE:53:AB:05:BD:13:BD:0C:4E:21:F4:22:B6:A4:9C
sig_hashalgo: sha256
parm: numdummies:Number of dummy pseudo devices (int)
[root@localhost ~]#

创建网卡:

1
2
3
[root@localhost ~]# ip link add     eth10 type dummy  # create
[root@localhost ~]# ip link delete eth10 # if delete
[root@localhost ~]# ip link set eth10 up;

性能测试:

iperf3 先发包, wireshark抓包, 创建一个 8GB的pcap文件。

1
2
3
4
tcpdump -i eth10 -w  /dev/null -v #窗口1
tcpdump -i eth10 -w /dev/null -v #窗口2
tcpdump -i eth10 -w /dev/null -v #窗口3
tcpdump -i eth10 -w /dev/null -v #窗口4

发包

1
nm_tcpreplay  -i eth10 -M 1800  pcap文件

实测

1发4收, 1500Mb 速率, 没有丢包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@localhost chunli]# ~/tools/nm_tcpreplay/nm_tcpreplay -i eth10 -M 1500  BIG_tcp_send_to_aliyun_ECS_8G_公网流量价值8元.pcap
Actual: 6319011 packets (7899311810 bytes) sent in 41.09 seconds
Rated: 192220752.1 Bps, 1537.76 Mbps, 153765.93 pps
Flows: 2 flows, 0.04 fps, 6319011 flow packets, 0 non-flow
Statistics for network device: eth10
Successful packets: 6319011
Failed packets: 0
Truncated packets: 0
Retried packets (ENOBUFS): 0
Retried packets (EAGAIN): 0
[root@localhost chunli]#


[root@localhost ~]# tcpdump -i eth10 -w /dev/null -v
tcpdump: listening on eth10, link-type EN10MB (Ethernet), capture size 262144 bytes
Got 6319011



[root@localhost ~]# tcpdump -i eth10 -w /dev/null -v
tcpdump: listening on eth10, link-type EN10MB (Ethernet), capture size 262144 bytes
Got 6319011


[root@localhost ~]# tcpdump -i eth10 -w /dev/null -v
tcpdump: listening on eth10, link-type EN10MB (Ethernet), capture size 262144 bytes
Got 6319011


[root@localhost ~]# tcpdump -i eth10 -w /dev/null -v
tcpdump: listening on eth10, link-type EN10MB (Ethernet), capture size 262144 bytes
Got 6319011