Skip to content

Commit

Permalink
system-dpdk: Use dummy-pmd port for packet injection.
Browse files Browse the repository at this point in the history
net_pcap is not always available in DPDK (like, in a dev
environment when you forgot to install the libpcap-devel).
On the other hand, OVS already has its own way to inject packets into a
bridge. Let's make use of it.

The generating script outputs a bulk of 8 packets per line (to save some
cpu spent calling ovs-appctl).

Suggested-by: Ilya Maximets <[email protected]>
Reviewed-by: Maxime Coquelin <[email protected]>
Acked-by: Eelco Chaudron <[email protected]>
Signed-off-by: David Marchand <[email protected]>
  • Loading branch information
david-marchand committed Dec 7, 2023
1 parent f43c4d4 commit 0e0c226
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
6 changes: 1 addition & 5 deletions tests/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ $(srcdir)/tests/fuzz-regression-list.at: tests/automake.mk
echo "TEST_FUZZ_REGRESSION([$$basename])"; \
done > $@.tmp && mv $@.tmp $@

EXTRA_DIST += $(MFEX_AUTOVALIDATOR_TESTS)
MFEX_AUTOVALIDATOR_TESTS = \
tests/mfex_fuzzy.py

OVSDB_CLUSTER_TESTSUITE_AT = \
tests/ovsdb-cluster-testsuite.at \
tests/ovsdb-execution.at \
Expand Down Expand Up @@ -523,7 +519,7 @@ tests_test_type_props_SOURCES = tests/test-type-props.c
CHECK_PYFILES = \
tests/appctl.py \
tests/flowgen.py \
tests/mfex_fuzzy.py \
tests/genpkts.py \
tests/ovsdb-monitor-sort.py \
tests/test-daemon.py \
tests/test-dpparse.py \
Expand Down
62 changes: 27 additions & 35 deletions tests/mfex_fuzzy.py → tests/genpkts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,40 @@
from scapy.all import RandMAC, RandIP, PcapWriter, RandIP6, RandShort, fuzz
from scapy.all import IPv6, Dot1Q, IP, Ether, UDP, TCP, random

# Path for the pcap file location.
path = str(sys.argv[1])
# The number of packets generated will be size * 8.
size = int(sys.argv[2])
# Traffic option is used to choose between fuzzy or simple packet type.
if len(sys.argv) > 3:
traffic_opt = str(sys.argv[3])
else:
traffic_opt = ""
if len(sys.argv) < 2:
print('usage: {} packets_count [fuzzy]'.format(sys.argv[0]))
sys.exit(1)

pktdump = PcapWriter(path, append=False, sync=True)
for i in range(0, int(sys.argv[1])):
pkt = []

pkt = []

for i in range(0, size):
if traffic_opt == "fuzzy":
if len(sys.argv) != 2:

eth = Ether(src=RandMAC(), dst=RandMAC())
vlan = Dot1Q()
udp = UDP(dport=RandShort(), sport=RandShort())
ipv4 = IP(src=RandIP(), dst=RandIP(), len=random.randint(0, 100))
ipv6 = IPv6(src=RandIP6(), dst=RandIP6(), plen=random.randint(0, 100))
udp = UDP(dport=RandShort(), sport=RandShort())
tcp = TCP(dport=RandShort(), sport=RandShort(), flags='S',
dataofs=random.randint(0, 15))

# IPv4 packets with fuzzing
pkt.append(fuzz(eth / ipv4 / udp))
pkt.append(fuzz(eth / ipv4 / tcp))
pkt.append(fuzz(eth / vlan / ipv4 / udp))
pkt.append(fuzz(eth / vlan / ipv4 / tcp))
pkt.append(fuzz(eth / ipv4 / udp).build().hex())
pkt.append(fuzz(eth / ipv4 / tcp).build().hex())
pkt.append(fuzz(eth / vlan / ipv4 / udp).build().hex())
pkt.append(fuzz(eth / vlan / ipv4 / tcp).build().hex())

# IPv6 packets with fuzzing
pkt.append(fuzz(eth / ipv6 / udp))
pkt.append(fuzz(eth / ipv6 / tcp))
pkt.append(fuzz(eth / vlan / ipv6 / udp))
pkt.append(fuzz(eth / vlan / ipv6 / tcp))
pkt.append(fuzz(eth / ipv6 / udp).build().hex())
pkt.append(fuzz(eth / ipv6 / tcp).build().hex())
pkt.append(fuzz(eth / vlan / ipv6 / udp).build().hex())
pkt.append(fuzz(eth / vlan / ipv6 / tcp).build().hex())

else:
mac_addr_src = "52:54:00:FF:FF:{:02X}".format(i % 0xff)
mac_addr_dst = "80:FF:FF:FF:FF:{:02X}".format(i % 0xff)
src_port = 200 + (i % 20)
dst_port = 1000 + (i % 20)
eth = Ether(src=mac_addr_src, dst=mac_addr_dst)
vlan = Dot1Q(vlan=(i % 10))
udp = UDP(dport=src_port, sport=dst_port)
# IPv4 address range limits to 255 and IPv6 limit to 65535
ipv4_addr_src = "192.168.150." + str((i % 255))
ipv4_addr_dst = "200.100.198." + str((i % 255))
Expand All @@ -71,18 +60,21 @@
.format(i % 0xffff)
ipv4 = IP(src=ipv4_addr_src, dst=ipv4_addr_dst)
ipv6 = IPv6(src=ipv6_addr_src, dst=ipv6_addr_dst)
src_port = 200 + (i % 20)
dst_port = 1000 + (i % 20)
udp = UDP(dport=src_port, sport=dst_port)
tcp = TCP(dport=src_port, sport=dst_port, flags='S')

# IPv4 packets
pkt.append(eth / ipv4 / udp)
pkt.append(eth / ipv4 / tcp)
pkt.append(eth / vlan / ipv4 / udp)
pkt.append(eth / vlan / ipv4 / tcp)
pkt.append((eth / ipv4 / udp).build().hex())
pkt.append((eth / ipv4 / tcp).build().hex())
pkt.append((eth / vlan / ipv4 / udp).build().hex())
pkt.append((eth / vlan / ipv4 / tcp).build().hex())

# IPv6 packets
pkt.append(eth / ipv6 / udp)
pkt.append(eth / ipv6 / tcp)
pkt.append(eth / vlan / ipv6 / udp)
pkt.append(eth / vlan / ipv6 / tcp)
pkt.append((eth / ipv6 / udp).build().hex())
pkt.append((eth / ipv6 / tcp).build().hex())
pkt.append((eth / vlan / ipv6 / udp).build().hex())
pkt.append((eth / vlan / ipv6 / tcp).build().hex())

pktdump.write(pkt)
print(' '.join(pkt))
20 changes: 14 additions & 6 deletions tests/system-dpdk.at
Original file line number Diff line number Diff line change
Expand Up @@ -820,16 +820,15 @@ dnl MFEX Autovalidator
AT_SETUP([OVS-DPDK - MFEX Autovalidator])
AT_KEYWORDS([dpdk])
OVS_DPDK_PRE_CHECK()
OVS_DPDK_START([--no-pci])
OVS_DPDK_START([--no-pci], [--enable-dummy])
AT_CHECK([ovs-vsctl add-br br0 -- set bridge br0 datapath_type=netdev])
AT_SKIP_IF([! ovs-appctl dpif-netdev/miniflow-parser-get | sed 1,4d | grep "True"], [], [dnl
])

AT_SKIP_IF([! $PYTHON3 -c "import scapy"], [], [])
AT_CHECK([$PYTHON3 $srcdir/mfex_fuzzy.py test_traffic.pcap 2000], [], [stdout])

dnl Add userspace bridge and attach it to OVS
AT_CHECK([ovs-vsctl add-port br0 p1 -- set Interface p1 type=dpdk options:dpdk-devargs=net_pcap1,rx_pcap=test_traffic.pcap,infinite_rx=1], [], [stdout], [stderr])
AT_CHECK([ovs-vsctl add-port br0 p1 -- set interface p1 type=dummy-pmd])
AT_CHECK([ovs-vsctl show], [], [stdout])

AT_CHECK([ovs-appctl dpif-netdev/dpif-impl-set dpif_avx512], [0], [dnl
Expand All @@ -840,6 +839,11 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator.
])

AT_SKIP_IF([! $PYTHON3 $srcdir/genpkts.py 2000 > packets])
cat packets | while read line; do
AT_CHECK([ovs-appctl netdev-dummy/receive p1 $line], [0], [ignore])
done

OVS_WAIT_UNTIL([test `ovs-vsctl get interface p1 statistics | grep -oP 'rx_packets=\s*\K\d+'` -ge 16000])

dnl Clean up
Expand All @@ -853,16 +857,15 @@ dnl MFEX Autovalidator Fuzzy
AT_SETUP([OVS-DPDK - MFEX Autovalidator Fuzzy])
AT_KEYWORDS([dpdk])
OVS_DPDK_PRE_CHECK()
OVS_DPDK_START([--no-pci])
OVS_DPDK_START([--no-pci], [--enable-dummy])
AT_CHECK([ovs-vsctl add-br br0 -- set bridge br0 datapath_type=netdev])
AT_SKIP_IF([! ovs-appctl dpif-netdev/miniflow-parser-get | sed 1,4d | grep "True"], [], [dnl
])

AT_SKIP_IF([! $PYTHON3 -c "import scapy"], [], [])
AT_CHECK([$PYTHON3 $srcdir/mfex_fuzzy.py fuzzy.pcap 2000 fuzzy], [], [stdout])

dnl Add userspace bridge and attach it to OVS
AT_CHECK([ovs-vsctl add-port br0 p1 -- set Interface p1 type=dpdk options:dpdk-devargs=net_pcap1,rx_pcap=fuzzy.pcap,infinite_rx=1], [], [stdout], [stderr])
AT_CHECK([ovs-vsctl add-port br0 p1 -- set interface p1 type=dummy-pmd])
AT_CHECK([ovs-vsctl show], [], [stdout])

AT_CHECK([ovs-appctl dpif-netdev/dpif-impl-set dpif_avx512], [0], [dnl
Expand All @@ -873,6 +876,11 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator.
])

AT_SKIP_IF([! $PYTHON3 $srcdir/genpkts.py 2000 fuzzy > packets])
cat packets | while read line; do
AT_CHECK([ovs-appctl netdev-dummy/receive p1 $line], [0], [ignore])
done

OVS_WAIT_UNTIL([test `ovs-vsctl get interface p1 statistics | grep -oP 'rx_packets=\s*\K\d+'` -ge 16000])

dnl Clean up
Expand Down

0 comments on commit 0e0c226

Please sign in to comment.