DPDK(五):发包工具------pktgen

测试DPDK不可或缺的一个发包工具,一般需要一台实体测试仪,家中环境简单,只能使用软发包工具了,找到一款叫做pktgen,其实也可以自己用pcap或者raw socket实现,看介绍使用pktgen性能很不错,也进行了绑核,不再造轮子了。

        pktgen的原理以及使用可以参考http://www.lenky.info/archives/2012/02/1165。

        看一下我的测试环境,虚拟机环境上三个网卡绑到了同一个网桥上,相当于将三个网卡连上了光纤,分别是eth2、eth3、eth4,如下图所示:

eth2                       eth3                     eth4

  |                               |                           |

  |                               |                          |

 ----------------------------------------------------      veth8

        网卡配置信息如下:

        

root@ubuntu:/home# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:41:a2:1f  
          inet addr:192.168.91.128  Bcast:192.168.91.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe41:a21f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:113 errors:0 dropped:0 overruns:0 frame:0
          TX packets:303 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16138 (16.1 KB)  TX bytes:48250 (48.2 KB)

eth1      Link encap:Ethernet  HWaddr 00:50:56:38:e6:f6  
          inet addr:192.168.174.128  Bcast:192.168.174.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe38:e6f6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5352 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7505 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:347980 (347.9 KB)  TX bytes:12763065 (12.7 MB)

eth2      Link encap:Ethernet  HWaddr 00:50:56:36:8d:e6  
          inet addr:192.168.19.129  Bcast:192.168.19.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe36:8de6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:299 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5313663 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:39253 (39.2 KB)  TX bytes:318866365 (318.8 MB)

eth3      Link encap:Ethernet  HWaddr 00:0c:29:41:a2:3d  
          inet addr:192.168.19.128  Bcast:192.168.19.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe41:a23d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5305660 errors:0 dropped:0 overruns:0 frame:0
          TX packets:125 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:318399640 (318.3 MB)  TX bytes:14485 (14.4 KB)

eth4      Link encap:Ethernet  HWaddr 00:50:56:3c:96:c7  
          inet addr:192.168.19.130  Bcast:192.168.19.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe3c:96c7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:561 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:94079 (94.0 KB)  TX bytes:10020 (10.0 KB)
          Interrupt:19 Base address:0x2000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:68 errors:0 dropped:0 overruns:0 frame:0
          TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:5750 (5.7 KB)  TX bytes:5750 (5.7 KB)

现在我想从eth2发送报文到eth3,最终目标是使用DPDK绑定eth3,然后进行二层转发测试将报文转发到eth4。

配置文件如下( pkggen.conf ):

#!/bin/sh
 
# FileName: pktgen-eth5-eth6.conf
# modprobe pktgen
function pgset(){
    local result
 
    echo $1 > $PGDEV
 
    result=`cat $PGDEV | fgrep "Result: OK:"`
    if [ "$result" = "" ]; then
         cat $PGDEV | fgrep Result:
    fi
}

function pg(){
    echo inject > $PGDEV
    cat $PGDEV
}
 
# Config Start Here -----------------------------------------------------------
 
 
# thread config
# Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly.
 
PGDEV=/proc/net/pktgen/kpktgend_2
  echo "Removing all devices"
 pgset "rem_device_all"
  echo "Adding eth2"
 pgset "add_device eth2"
 
 
# device config
# delay 0 means maximum speed.
 
CLONE_SKB="clone_skb 1000000"
# NIC adds 4 bytes CRC
PKT_SIZE="pkt_size 60"
 
# COUNT 0 means forever
#COUNT="count 0"
COUNT="count 0"
DELAY="delay 0"
 
PGDEV=/proc/net/pktgen/eth2
  echo "Configuring $PGDEV"
 pgset "$COUNT"
 pgset "$CLONE_SKB"
 pgset "$PKT_SIZE"
 pgset "$DELAY"
 pgset "dst 192.168.19.128"
 pgset "dst_mac 00:0c:29:41:a2:3d"
 
 
# Time to run
PGDEV=/proc/net/pktgen/pgctrl
 
 echo "Running... ctrl^C to stop"
 pgset "start"
 echo "Done"
 

# Result can be vieved in /proc/net/pktgen/eth[2]

步骤:
(1)、modprobe pktgen

(2)、sh pkggen.conf 

(3)、tcpdump查看eth3上的报文情况,可以收到报文

root@ubuntu:/opt/code/dpdk-1.8.0/examples# tcpdump -vv  -i  eth3  -c 10
tcpdump: listening on eth3, link-type EN10MB (Ethernet), capture size 262144 bytes
00:37:41.068632 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.068638 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.068640 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.068642 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.068757 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.068762 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.068968 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.184195 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.194487 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
00:37:41.194493 IP (tos 0x0, ttl 32, id 4, offset 0, flags [none], proto UDP (17), length 46)
    192.168.19.129.discard > 192.168.19.128.discard: [no cksum] UDP, length 18
10 packets captured
3525 packets received by filter
3188 packets dropped by kernel

  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值