Skip to content

Commit

Permalink
tests: define fmt_pkt function to construct packets with scapy
Browse files Browse the repository at this point in the history
Scapy allows to define packets in descriptive form that is easier to
digest and debug.

NOTE: Unlike in the original commit, this backport also installs scapy
via pip in CI.  This is needed to match the behavior we have on the main
branch.

Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com>
Acked-by: Ales Musil <amusil@redhat.com>
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
(cherry picked from commit d8c0d3a)
  • Loading branch information
booxter authored and dceara committed Apr 19, 2023
1 parent 9a695f2 commit b383db8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .ci/linux-prepare.sh
Expand Up @@ -18,4 +18,4 @@ cd sparse && make -j4 HAVE_LLVM= HAVE_SQLITE= install && cd ..
# https://github.com/pypa/pip/issues/10655
pip3 install --disable-pip-version-check --user wheel
pip3 install --disable-pip-version-check --user \
flake8 'hacking>=3.0' sphinx setuptools pyelftools pyOpenSSL
flake8 'hacking>=3.0' scapy sphinx setuptools pyelftools pyOpenSSL
23 changes: 23 additions & 0 deletions tests/ovn-macros.at
Expand Up @@ -775,6 +775,29 @@ ovn_trace_client() {
ovs-appctl -t $target trace "$@" | tee trace | sed '/^# /d'
}

# Receives a string with scapy python code that represents a packet.
# Returns a hex-string that contains bytes that reflect the packet symbolic
# description.
#
# Scapy docs: https://scapy.readthedocs.io/en/latest/usage.html
#
# Example of usage:
#
# packet=$(fmt_pkt "
# Ether(dst='ff:ff:ff:ff:ff:ff', src='50:64:00:00:00:01') /
# IPv6(src='abed::1', dst='ff02::1:ff00:2') /
# ICMPv6ND_NS(tgt='abed::2')
# ")
#
# ovs-appctl netdev-dummy/receive $vif $packet
#
fmt_pkt() {
echo "from scapy.all import *; \
import binascii; \
out = binascii.hexlify(raw($1)); \
print(out.decode())" | $PYTHON3
}

OVS_END_SHELL_HELPERS

m4_define([OVN_POPULATE_ARP], [AT_CHECK(ovn_populate_arp__, [0], [ignore])])
Expand Down

0 comments on commit b383db8

Please sign in to comment.