Search code examples
linuxnetwork-programminglinux-kerneldpdk

Can the pktgen tool be used to send different types of network packets on one port?


Recently I am using pktgen to construct a tool for sending network packets to simulate DDoS attacks.The script I currently write can use four ports to send four different types of network packets. The code is as follows

package.path = package.path ..";?.lua;test/?.lua;app/?.lua;"
pktgen.ports_per_page(4);

pktgen.range.dst_mac("all", "start", "0011:2233:4455");
pktgen.range.src_mac("all", "start", "0033:2233:4455");

pktgen.range.dst_ip("all", "start", "10.12.0.1");
pktgen.range.dst_ip("all", "inc", "0.0.0.2");
pktgen.range.dst_ip("all", "min", "10.12.0.1");
pktgen.range.dst_ip("all", "max", "10.12.0.64");

pktgen.range.src_ip("all", "start", "10.13.0.1");
pktgen.range.src_ip("all", "inc", "0.0.0.3");
pktgen.range.src_ip("all", "min", "10.13.0.1");
pktgen.range.src_ip("all", "max", "10.13.0.64");

pktgen.range.dst_port("all", "start", 1234);
pktgen.range.dst_port("all", "inc", 4);
pktgen.range.dst_port("all", "min", 1234);
pktgen.range.dst_port("all", "max", 2345);

pktgen.range.vlan_id("all", "start", 1);
pktgen.range.vlan_id("all", "inc", 0);
pktgen.range.vlan_id("all", "min", 1);
pktgen.range.vlan_id("all", "max", 4094);

pktgen.range.pkt_size("all", "start", 128);
pktgen.range.pkt_size("all", "inc", 2);
pktgen.range.pkt_size("all", "min", 64);
pktgen.range.pkt_size("all", "max", 1518);

pktgen.set_range("all", "on");
pktgen.range.ip_proto("0","tcp");
pktgen.range.ip_proto("1","tcp");
pktgen.range.ip_proto("2","udp");
pktgen.range.ip_proto("3","udp");
pktgen.set("all","rate",100);
pktgen.range.tcp_flags("0","0x2");
pktgen.range.tcp_flags("1","0x10");
pktgen.range.tcp_flags("2","0x5");
pktgen.range.tcp_flags("3","0x7");
pktgen.range.pad_fpath("all","/root/pktgen-3.1.2_work/scripts/payload.txt");

As shown in the code, I used four ports to construct different TCP and UDP network packets.I want to know whether it is possible to send TCP and UDP network packets at the same time using only one port, instead of using at least two ports to achieve.


Solution

  • Yes, you can generate a range of packets TCP/UDP/NON-IP/SCTP with a single physical NIC port. To do the same follow the steps as

    1. create VF ports equal to the various ranges (in your use case 2, that is TCP and UDP).
    2. Insmod with either vfdio-pci or igb_uio
    3. pass the ports to pktgen as 2 DPDK ports.
    4. in main page set the rate to 50% with set all rate 50
    5. Use the range page to set TCP for port 0 and UDP for port 1.