Skip to content

Commit

Permalink
tests/mfex: Improve pcap script for mfex tests.
Browse files Browse the repository at this point in the history
The mfex pcap generation script is improved for varied length
traffic and also removes the hard coded mfex_pcap and instead uses
the script itself to generate complex traffic patterns for testing.

Signed-off-by: Kumar Amber <[email protected]>
Acked-by: Cian Ferriter <[email protected]>
Acked-by: Eelco Chaudron <[email protected]>
Signed-off-by: Ian Stokes <[email protected]>
  • Loading branch information
kamber-intel authored and istokes committed Jun 30, 2022
1 parent 6f24c2b commit e72b056
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 48 deletions.
1 change: 0 additions & 1 deletion tests/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ $(srcdir)/tests/fuzz-regression-list.at: tests/automake.mk

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

OVSDB_CLUSTER_TESTSUITE_AT = \
Expand Down
92 changes: 68 additions & 24 deletions tests/mfex_fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,74 @@
import sys

from scapy.all import RandMAC, RandIP, PcapWriter, RandIP6, RandShort, fuzz
from scapy.all import IPv6, Dot1Q, IP, Ether, UDP, TCP
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 = ""

path = str(sys.argv[1]) + "/pcap/fuzzy.pcap"
pktdump = PcapWriter(path, append=False, sync=True)

for i in range(0, 2000):

# Generate random protocol bases, use a fuzz() over the combined packet
# for full fuzzing.
eth = Ether(src=RandMAC(), dst=RandMAC())
vlan = Dot1Q()
ipv4 = IP(src=RandIP(), dst=RandIP())
ipv6 = IPv6(src=RandIP6(), dst=RandIP6())
udp = UDP(dport=RandShort(), sport=RandShort())
tcp = TCP(dport=RandShort(), sport=RandShort())

# IPv4 packets with fuzzing
pktdump.write(fuzz(eth / ipv4 / udp))
pktdump.write(fuzz(eth / ipv4 / tcp))
pktdump.write(fuzz(eth / vlan / ipv4 / udp))
pktdump.write(fuzz(eth / vlan / ipv4 / tcp))

# IPv6 packets with fuzzing
pktdump.write(fuzz(eth / ipv6 / udp))
pktdump.write(fuzz(eth / ipv6 / tcp))
pktdump.write(fuzz(eth / vlan / ipv6 / udp))
pktdump.write(fuzz(eth / vlan / ipv6 / tcp))
pkt = []

for i in range(0, size):
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))
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))

# 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))

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))
ipv6_addr_src = "2001:0db8:85a3:0000:0000:8a2e:0370:{:04x}" \
.format(i % 0xffff)
ipv6_addr_dst = "3021:ffff:85a3:ffff:0000:8a2e:0480:{:04x}" \
.format(i % 0xffff)
ipv4 = IP(src=ipv4_addr_src, dst=ipv4_addr_dst)
ipv6 = IPv6(src=ipv6_addr_src, dst=ipv6_addr_dst)
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)

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

pktdump.write(pkt)
Binary file removed tests/pcap/mfex_test.pcap
Binary file not shown.
52 changes: 29 additions & 23 deletions tests/system-dpdk.at
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,19 @@ dnl --------------------------------------------------------------------------
dnl Add standard DPDK PHY port
AT_SETUP([OVS-DPDK - MFEX Autovalidator])
AT_KEYWORDS([dpdk])

OVS_DPDK_PRE_CHECK()
OVS_DPDK_START()

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_pcap1,rx_pcap=$srcdir/pcap/mfex_test.pcap,infinite_rx=1], [], [stdout], [stderr])
AT_CHECK([ovs-vsctl show], [], [stdout])

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 show], [], [stdout])

AT_CHECK([ovs-appctl dpif-netdev/dpif-impl-set dpif_avx512], [0], [dnl
DPIF implementation set to dpif_avx512.
])
Expand All @@ -407,7 +409,7 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator.
])

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

dnl Clean up
AT_CHECK([ovs-vsctl del-port br0 p1], [], [stdout], [stderr])
Expand All @@ -419,18 +421,19 @@ dnl --------------------------------------------------------------------------
dnl Add standard DPDK PHY port
AT_SETUP([OVS-DPDK - MFEX Autovalidator Fuzzy])
AT_KEYWORDS([dpdk])
AT_SKIP_IF([! $PYTHON3 -c "import scapy"], [], [])
AT_CHECK([$PYTHON3 $srcdir/mfex_fuzzy.py $srcdir], [], [stdout])
OVS_DPDK_PRE_CHECK()
OVS_DPDK_START()

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_pcap1,rx_pcap=$srcdir/pcap/fuzzy.pcap,infinite_rx=1], [], [stdout], [stderr])
AT_CHECK([ovs-vsctl show], [], [stdout])

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 show], [], [stdout])

AT_CHECK([ovs-appctl dpif-netdev/dpif-impl-set dpif_avx512], [0], [dnl
DPIF implementation set to dpif_avx512.
])
Expand All @@ -439,7 +442,7 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator.
])

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

dnl Clean up
AT_CHECK([ovs-vsctl del-port br0 p1], [], [stdout], [stderr])
Expand All @@ -452,11 +455,14 @@ dnl --------------------------------------------------------------------------
dnl --------------------------------------------------------------------------
AT_SETUP([OVS-DPDK - MFEX Configuration])
AT_KEYWORDS([dpdk])
OVS_DPDK_PRE_CHECK()
AT_SKIP_IF([! $PYTHON3 -c "import scapy"], [], [])
AT_CHECK([$PYTHON3 $srcdir/mfex_fuzzy.py test_traffic.pcap 1], [], [stdout])
OVS_DPDK_START()
AT_CHECK([ovs-vsctl --no-wait set Open_vSwitch . other_config:pmd-cpu-mask=0xC])
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_pcap1,rx_pcap=$srcdir/pcap/mfex_test.pcap,infinite_rx=1], [], [stdout], [stderr])
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 show], [], [stdout])

AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set scalar 1], [2],
Expand Down Expand Up @@ -501,12 +507,12 @@ Error: invalid study_pkt_cnt value: abcd.
ovs-appctl: ovs-vswitchd: server returned an error
])

AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd 3 study], [0], [dnl
Miniflow extract implementation set to study, on pmd thread 3, studying 128 packets.
AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd 0 study], [0], [dnl
Miniflow extract implementation set to study, on pmd thread 0, studying 128 packets.
])

AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd 3 study 512], [0], [dnl
Miniflow extract implementation set to study, on pmd thread 3, studying 512 packets.
AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd 0 study 512], [0], [dnl
Miniflow extract implementation set to study, on pmd thread 0, studying 512 packets.
])

AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set study 512], [0], [dnl
Expand All @@ -517,8 +523,8 @@ AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set study], [0], [dnl
Miniflow extract implementation set to study, studying 128 packets.
])

AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd 3 autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator, on pmd thread 3.
AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd 0 autovalidator], [0], [dnl
Miniflow extract implementation set to autovalidator, on pmd thread 0.
])

AT_CHECK([ovs-appctl dpif-netdev/miniflow-parser-set -pmd zero study], [2],
Expand Down

0 comments on commit e72b056

Please sign in to comment.