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 20, 2023
1 parent de4cccf commit 0bf9025
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 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 @@ -522,7 +518,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
56 changes: 26 additions & 30 deletions tests/mfex_fuzzy.py → tests/genpkts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,44 @@
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])
size = int(sys.argv[1])
# Traffic option is used to choose between fuzzy or simple packet type.
if len(sys.argv) > 3:
traffic_opt = str(sys.argv[3])
if len(sys.argv) > 2:
traffic_opt = str(sys.argv[2])
else:
traffic_opt = ""

pktdump = PcapWriter(path, append=False, sync=True)

pkt = []

for i in range(0, size):
pkt = []

if traffic_opt == "fuzzy":

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 +64,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))
24 changes: 16 additions & 8 deletions tests/system-dpdk.at
Original file line number Diff line number Diff line change
Expand Up @@ -821,16 +821,16 @@ AT_SETUP([OVS-DPDK - MFEX Autovalidator])
AT_KEYWORDS([dpdk])
OVS_CHECK_GITHUB_ACTION()
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])
AT_SKIP_IF([! $PYTHON3 $srcdir/genpkts.py 2000 > packets])

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 @@ -841,6 +841,10 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator.
])

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 @@ -855,16 +859,16 @@ AT_SETUP([OVS-DPDK - MFEX Autovalidator Fuzzy])
AT_KEYWORDS([dpdk])
OVS_CHECK_GITHUB_ACTION()
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])
AT_SKIP_IF([! $PYTHON3 $srcdir/genpkts.py 2000 fuzzy > packets])

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 @@ -875,6 +879,10 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator.
])

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 @@ -888,11 +896,11 @@ dnl --------------------------------------------------------------------------
AT_SETUP([OVS-DPDK - MFEX Configuration])
AT_KEYWORDS([dpdk])
OVS_DPDK_PRE_CHECK()
OVS_DPDK_START([--no-pci])
OVS_DPDK_START([--no-pci], [--enable-dummy])
AT_CHECK([ovs-vsctl --no-wait set Open_vSwitch . other_config:pmd-cpu-mask=0x1])
dnl Add userspace bridge and attach it to OVS
AT_CHECK([ovs-vsctl add-br br0 -- set bridge br0 datapath_type=netdev])
AT_CHECK([ovs-vsctl add-port br0 p1 -- set Interface p1 type=dpdk options:dpdk-devargs=net_null0,no-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/miniflow-parser-set scalar 1], [2],
Expand Down

0 comments on commit 0bf9025

Please sign in to comment.