JavaScript must be enabled in order for you to see "WP Copy Data Protect" effect. However, it seems JavaScript is either disabled or not supported by your browser. To see full result of "WP Copy Data Protector", enable JavaScript by changing your browser options, then try again.

The usage and introduction about the pktgen


話說最近剛好碰到Survey Pktgen這支Kernel Base Benchmark工具的使用方法,順便將過程在這邊紀錄一下,這支Tool是由瑞士皇家理工大學所開發,它會產生隨機的Packets目的端,可以直接透過Linux的Kernel載入相關的Driver,進而達到網路性能的測試Software的部分可以從這邊取得,至於細部操作的部分,參考這裡及如下:

1) Investigate the above topology(Packet的Flow Order為1->2->3->4)
Customer需要上述的Packet Flow,因此敝人目前作法將Client(RHEL 6.x)內準備一個VM並使用VT-d技術直接將NIC2 Passthrough到VM內,另一方面,SUT的部分透過Bridge的方式將NIC1與NIC2均橋接在一起,以達到Customer's Requirement,但還是會產生Packet的Loss。
原本想透過增加路由或NAT的方式來達成,但頂多只能到SUT的NIC2而作罷(Loop Issue)。

2) Client Side about generating the packet(不限Kernel的Version均可產生)
#uname -a -> Query the version of kernel
#modprobe pktgen
#modinfo | grep -i pktgen -> default is 2.72, the latest is 2.74
#cat /proc/net/pktgen/pgctrl -> Same as above
#ps aux | grep -i pktgen -> Follow cores to produce the corresponding processes
#ls -al /proc/net/pktgen/kptgend_* -> Same as above

3) Stop the irqbalance and reassign the resource of cores(Promote the performance)
#/etc/init.d/irqbalance stop
#cat /proc/interrupts | grep -i eth0 -> 以eth0為Example去查irq的ID
#echo 1 > /proc/irq/<上述irq的ID>/smp_affinity -> ID可能不只一個
上述1的意思如下:
Core's ID -> Binary -> Hex
CPU 0 -> 00000001 -> 1
CPU 1 -> 00000010 -> 2
CPU 2 -> 00000100 -> 4
CPU 3 -> 00001000 -> 8
以此類推,若想將eth0同時綁在CPU0與1上則1+2=3
#taskset 0x00000001 -p -> Bind the CPU0 with the PID
#awk -F: '/eth/ {print $1}' /proc/interrupts|xargs -i cat /proc/irq/{}/smp_affinity -> Query the resource of cores about the network

4) Program the script for the client side(Script的Sample可以從這邊下載,這邊選擇用pktgen.conf-1-1)
#cat REAME.examples
pktgen.conf-1-1 # 1 CPU 1 dev
pktgen.conf-1-2 # 1 CPU 2 dev
pktgen.conf-2-1 # 2 CPU's 1 dev
pktgen.conf-2-2 # 2 CPU's 2 dev
pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.(Multi IPs)
#cat pktgen.conf-1-1 -> ipg的parameter可能會不Support
#! /bin/sh
#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_0
echo "Removing all devices"
pgset "rem_device_all"
echo "Adding eth0"
pgset "add_device eth0"
echo "Setting max_before_softirq 10000"
pgset "max_before_softirq 10000"
# device config
# ipg is inter packet gap. 0 means maximum speed.
CLONE_SKB="clone_skb 1000000"
# NIC adds 4 bytes CRC follow rfc2544
# 64, 128, 256, 512, 1024, 1280, 1518 for ethernet
# 54, 64, 128, 256, 1024, 1518, 2048, 4472 for FDDI
PKT_SIZE="pkt_size 60"
# COUNT 0 means forever
#COUNT="count 0"
COUNT="count 10000000"
IPG="ipg 0"
PGDEV=/proc/net/pktgen/eth0
echo "Configuring $PGDEV"
pgset "$COUNT"
pgset "$CLONE_SKB"
pgset "$PKT_SIZE"
pgset "$IPG"
pgset "dst 192.168.1.3"
pgset "dst_mac xx:xx:xx:xx:xx:xx"
# 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/eth0

5) The explanation about the parameter and command(針對Types分成三個部分)
I.Parameter(Device command for eth)
clone_skb:設定對同樣Packet複製的數量,0代表Single SKB
debug:Enable Debug Mode
pkt_size:設定Packet Size(去除前面CRC的值)
min_pkt_size:設定Packet Size的Minimum(For Range)
max_pkt_size:設定Packet Size的Maximum(For Range)
frags:封包將用多少Fragment所組成
count:發送Packets的數目,0代表持續不間斷至Ctrl-C
delay:加入Delay至hard_start_xmit(),單位nanoseconds
dst:設定Destination IP
dst_min:設定Minimum Destination IP
dst_max:設定Maximum Destination IP(用於Multi IP Flow)
src_min:設定Minimum Source IP
src_max:設定Maximum Source IP
dst6:設定Destination IP for IPv6
src6:設定Source IP for IPv6
dstmac:設定Destination MAC Address
srcmac:設定Source MAC Address
dst_mac_count:設定MAC Number的Range for dstmac
src_mac_count:設定MAC Number的Range for srcmac
flag:設定Flag來決定Behaviour,IPSRC_RND->IP Source為隨機(Min~Max之間)、IPDST_RND->IP Destination為隨機、TXSIZE_RND、UDPDST_RND、UDPDST_RND、MACSRC_RND和MACDST_RND等等
udp_dst_min:設定UDP Destination Port的Mimimum,在小於udp_dst_max內Range做Cycle
udp_dst_max:設定UDP Destination Port的Maximum
udp_src_min:設定UDP Source Port的Mimimum,在小於udp_src_max內Range做Cycle
udp_src_max:設定UDP Source Port的Maximum
clear_counters:清空Counter,一般Process自動清空
flows:定義Flow的數量
flowlen:定義Flow的程度
II.Command for pgctrl
start:開始Injection與Generator with threads
stop:終止Injection與Generator with threads
III.Command for thread for kpktgend_*
add_device:將某個NIC Port加到某個Thread內
rem_device_all:刪除某個Thread內的所有被綁定的NIC Ports
max_before_softirq:定義在最多發送多少的Packets後執行do_softirq()

6) Program the script for the VM(Script的Sample可以從這邊下載,這邊選擇用script-pktgen-rx[Pktgen Receiver])
#cat script-pktgen-rx -> But need to add kernel patch for the file of pgrx
#! /bin/sh
function pgset() {
local result
echo $1 > $PGDEV
}
#Disable autonegotion in the iterface
/bin64/ethtool -A $1 autoneg off rx off tx off
# Reception configuration, maybe replace with pgctrl
PGDEV=/proc/net/pktgen/pgrx
echo "Removing old config"
pgset "rx_reset"
pgset "rx"
# $1 is eth1
echo "Adding rx $1"
pgset "rx $1"
# statistics time -> $2
echo "Setting statistics $2"
pgset "statistics $2"
pgset "display script"
pgset "display human"
# Result can be vieved in /proc/net/pktgen/eth1
#cat /proc/net/pktgen/pgrx

Kernel有Limitation with 3.6-rc2、v.2.6.36~38,可用Ubuntu 13.04(3.8.0-25-generic-參考這裡)、RHEL6+Recompile KernelBifrost/Linux 7.x(3.6.0-Suitable for Intel’s NIC)

7) Moniter and review the current status for pktgening
#mpstat -P 2,3 1 -> Monitor CPU 2&3 per 1 sec
#mpstat -P ALL -> Monitor All CPUs
#sar -n DEV 2 10 -> Monitor Status of NICs about 10 times per 2 secs
#iostat

◎、以上就是Pktgen的使用與簡介,上述Client Side、Reciver與SMP_affinity的部分均可透過Interactive Script簡化執行的Steps,除此之外,另外也有Pktgen-DPDK的部分可以做,這部份就留給看倌們自行玩味了,中間解說的部份參考了LenkyMelon大大的文章RX的部份則是參考迷い庭的文章,先到這,收工囉!

  1. 那…這禮拜之前,有辦法生出BKM嗎 ?

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
This site is protected by WP-CopyRightPro