Pktgen detailed tutorial

Source: Internet
Author: User

There are a lot of articles on pktgen on the Internet, but it is always not comprehensive and meticulous. After reading it, I still won't write the pktgen test script. Therefore, this article will elaborate on pktgen in detail, after reading this article, you can write pktgen shell by yourself.

  

#modprobe pktgen

Then you will see the following file in your computer's/proc/net/pktgen:

kpktgend_0  kpktgend_1  kpktgend_2  kpktgend_3  pgctrl

The number of kpktgen _ * is determined based on the number of your CPU. For example, if the number of sub-CPUs of my machine is 4, there are four such files.

Run cat/proc/net/pktgen/pgctrl to view the pktgen version and other information:

#cat /proc/net/pktgen/pgctrl
Packet Generator for packet performance testing. Version: 2.74

  

  1) interrupt affinity

When a thread (kpktgend_x) is used to send (accept) data through a port (ethx), we should bind the interrupt corresponding to this port to a certain CPU, this prevents CPU cache loss due to CPU changes (caused by the operating system. The procedure is as follows:

First, run the following command to view the ethx interrupt. Here we use eth3 as an example.

# cat /proc/interrupts | grep eth3

47: 45836 0 0 0 PCI-MSI-edge eth3-TxRx-0
48: 45836 0 0 0 PCI-MSI-edge eth3-TxRx-1
49: 45836 0 0 0 PCI-MSI-edge eth3-TxRx-2
50: 45836 0 0 0 PCI-MSI-edge eth3-TxRx-3
51: 0 0 0 0 PCI-MSI-edge eth3: lsc

From the above we can see that eth3 uses five interrupt numbers, 47-51. Here we will bind them to CPU0.

# echo 1 /proc/irq/47/smp_affinity# echo 1 /proc/irq/48/smp_affinity# echo 1 /proc/irq/49/smp_affinity# echo 1 /proc/irq/50/smp_affinity# echo 1 /proc/irq/51/smp_affinity

Of course, if you bind them separately, you can share the CPU burden during the big data stream, which may improve the maximum performance, but it is unclear, this should also be related to the multi-queue of the Intel Nic. Further experiments are needed to analyze the problem.

According to Robert's test results, correct interruption affinity binding improves the sending rate by 60%.

  2) clone_skb: limits the memory allocation (clone_skb should only copy the structure of skb and not copy the data zone)

This part has not been understood yet. It should be related to the high-speed cache of the cpu. It should be put first. It does not affect the subsequent experiments.

  3) latency: reduces the transmission rate

After a packet is sent, the unit of delay is ns level, so as to reduce the sending rate. If the delay time is greater than the sending time, you can use this function to send a specific number of data packets per second, that is, the frequency of anset to send data packets.

 

  

 

 1) The experiment topology is as follows:

 

1+-----------+           +-----------+2| Host1     |           |  Host2     |3|       eth1 +-----------+nf0       |4|           |           |           |5|           |           |           |67+-----------+           +-----------+

 

First, let's take a look at the next simple code, which gives you an intuitive understanding of the shell control of pktgen. You can try to see this code first, or skip it directly. First, let's take a look at the following content, then I will check the code again.

 [[ `lsmod | grep pktgen` ==  [[  == =550= > =`cat  | fgrep  [  =  |> =/proc/net/pktgen/echo =/proc/net/pktgen/=/proc/net/pktgen/

 

  2) All pktgen commands are explained as follows:

PktgenCommand

PktgenControl Command

Start

All threads start sending

Stop

Stop

Thread control command

Add_device

Add a port to a thread

Rem_device_all

Delete all ports bound to a thread

Max_before_softirq

Run do_softirq ()

PORT command

Debug

Debugging

Clone_skb

How many copies are performed on each skb? 0 indicates no replication. Dos and other tests must be zero

Clear_counters

Clear the counter. The general program automatically clears the counter.

Pkt_size

The size of the link package (CRC value)

Min_pkt_size

Minimum packet Value

Max_pkt_size

Maximum Value

Flags

Number of packages?

Count

Number of sent data packets. 0 indicates that data packets are sent all the time.

Delay

Latency between two data packets

Dst

Destination IP address

Dst_min

Minimum destination IP address

Dst_max

Maximum Value

Src_min

Minimum source IP address

Src_max

Maximum Value

Dst6

Destination IPv6 address

Src6

Source IPv6 address

Dstmac

Target mac

Srcmac

Source mac

Src_mac_count

Number of source mac, which starts from the mac set by srcmac.

Dst_mac_count

Same as above

Udp_src_min

Minimum source udp port number

Udp_src_max

Maximum source udp port number

Udp_dst_min

Minimum destination udp port number

Udp_dst_max

Maximum destination udp port number

Flows

Number of concurrent streams

Flowlen

Stream Length

Flags

IPSRC_RND

IPDST_RND

TXSIZE_RND

UDPSRC_RND

UDPDST_RND

MACSRC_RND

MACDST_RND

PSRC_RND source IP address random sending

  

 

 > =`cat  | fgrep  [  =  |> 

 

Pktgen. conf-1: When the CPU system binds eth1 eth2 to Thread 0, part of the code is as follows

PGDEV=/proc/net/pktgen/

Pktgen. conf-2: eth1 uses Thread 0 eth2 uses thread 1 to send, part of the code is as follows

PGDEV=/proc/net/pktgen/=/proc/net/pktgen/

Pktgen. conf-3: In a dual CPU system, eth1 eth2 uses Thread 0 to send, part of the code is as follows

PGDEV=/proc/net/pktgen/=/proc/net/pktgen/

Pktgen. conf-4: the script for Dos testing, pay attention to clone_skb 0, part of the code is as follows

PGDEV=/proc/net/pktgen/

Pktgen. conf-5: the script for routing flow testing, also pay attention to clone_skb 0

PGDEV=/proc/net/pktgen/pgset 

Finally, paste a complicated script:

PGDEV=/proc/net/pktgen/=/proc/net/pktgen/ i  2 3 4 5 6 7 8 9 10 11=/proc/net/pktgen/eth=/proc/net/pktgen/-2 /proc/net/pktgen/eth*

Related links:

Linux package tools pktgen tutorial @ cangqiong fantasy

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.