diff mbox series

[ovs-dev,v2,13/13] tests: Use fmt_pkt in icmp_reply: 1 HVs, 2 LSs, 1 lport/LS, 1 LR.

Message ID 20231114205417.175004-14-mmichels@redhat.com
State Accepted
Headers show
Series Convert some tests to use fmt_pkt. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Mark Michelson Nov. 14, 2023, 8:54 p.m. UTC
Execution time: 3.791s
Execution time on "main" branch: 2.897s

Signed-off-by: Mark Michelson <mmichels@redhat.com>
---
 tests/ovn.at | 66 +++++++++++++++++++++-------------------------------
 1 file changed, 26 insertions(+), 40 deletions(-)
diff mbox series

Patch

diff --git a/tests/ovn.at b/tests/ovn.at
index 27053d5ca..d1e049377 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -7794,6 +7794,7 @@  AT_CLEANUP
 OVN_FOR_EACH_NORTHD([
 AT_SETUP([icmp_reply: 1 HVs, 2 LSs, 1 lport/LS, 1 LR])
 AT_KEYWORDS([router-icmp-reply])
+AT_SKIP_IF([test $HAVE_SCAPY = no])
 ovn_start
 
 # Logical network:
@@ -7851,62 +7852,47 @@  AT_CAPTURE_FILE([sbflows])
 for i in 1 2; do
     : > vif$i.expected
 done
-# test_ipv4_icmp_request INPORT ETH_SRC ETH_DST IPV4_SRC IPV4_DST IP_CHKSUM ICMP_CHKSUM [EXP_IP_CHKSUM EXP_ICMP_CHKSUM]
+# test_ipv4_icmp_request INPORT ETH_SRC ETH_DST IPV4_SRC IPV4_DST
 #
 # Causes a packet to be received on INPORT.  The packet is an ICMPv4
-# request with ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_CHSUM and
-# ICMP_CHKSUM as specified.  If EXP_IP_CHKSUM and EXP_ICMP_CHKSUM are
-# provided, then it should be the ip and icmp checksums of the packet
-# responded; otherwise, no reply is expected.
-# In the absence of an ip checksum calculation helpers, this relies
-# on the caller to provide the checksums for the ip and icmp headers.
-# XXX This should be more systematic.
+# request with ETH_SRC, ETH_DST, IPV4_SRC, and IPV4_DST as specified.
 #
 # INPORT is an lport number, e.g. 11 for vif11.
-# ETH_SRC and ETH_DST are each 12 hex digits.
-# IPV4_SRC and IPV4_DST are each 8 hex digits.
-# IP_CHSUM and ICMP_CHKSUM are each 4 hex digits.
-# EXP_IP_CHSUM and EXP_ICMP_CHKSUM are each 4 hex digits.
+# ETH_SRC and ETH_DST are each MAC address strings.
+# IPV4_SRC and IPV4_DST are each dotted decimal IPv4 address strings.
 test_ipv4_icmp_request() {
-    local inport=$1 eth_src=$2 eth_dst=$3 ipv4_src=$4 ipv4_dst=$5 ip_chksum=$6 icmp_chksum=$7
-    local exp_ip_chksum=$8 exp_icmp_chksum=$9
-    shift; shift; shift; shift; shift; shift; shift
-    shift; shift
-
+    local inport=$1 eth_src=$2 eth_dst=$3 ipv4_src=$4 ipv4_dst=$5
+    shift; shift; shift; shift; shift
     # Use ttl to exercise section 4.2.2.9 of RFC1812
-    local ip_ttl=02
-    local icmp_id=5fbf
-    local icmp_seq=0001
     local icmp_data=$(seq 1 56 | xargs printf "%02x")
-    local icmp_type_code_request=0800
-    local icmp_payload=${icmp_type_code_request}${icmp_chksum}${icmp_id}${icmp_seq}${icmp_data}
-    local packet=${eth_dst}${eth_src}08004500005400004000${ip_ttl}01${ip_chksum}${ipv4_src}${ipv4_dst}${icmp_payload}
+    local packet=$(fmt_pkt "Ether(dst='${eth_dst}', src='${eth_src}')/ \
+                            IP(src='${ipv4_src}', dst='${ipv4_dst}', ttl=0x02)/ \
+                            ICMP(type=8, id=0x5fbf, seq=1)/ \
+                            b'${icmp_data}'")
 
     as hv1 ovs-appctl netdev-dummy/receive vif$inport $packet
-    if test X$exp_icmp_chksum != X; then
-        # Expect to receive the reply, if any. In same port where packet was sent.
-        # Note: src and dst fields are expected to be reversed.
-        local icmp_type_code_response=0000
-        local reply_icmp_ttl=fe
-        local reply_icmp_payload=${icmp_type_code_response}${exp_icmp_chksum}${icmp_id}${icmp_seq}${icmp_data}
-        local reply=${eth_src}${eth_dst}08004500005400004000${reply_icmp_ttl}01${exp_ip_chksum}${ipv4_dst}${ipv4_src}${reply_icmp_payload}
-        echo $reply >> vif$inport.expected
-    fi
+    # Expect to receive the reply, if any. In same port where packet was sent.
+    # Note: src and dst fields are expected to be reversed.
+    local reply=$(fmt_pkt "Ether(dst='${eth_src}', src='${eth_dst}')/ \
+                           IP(src='${ipv4_dst}', dst='${ipv4_src}', ttl=0xfe)/ \
+                           ICMP(type=0, id=0x5fbf, seq=1)/ \
+                           b'${icmp_data}'")
+    echo $reply >> vif$inport.expected
 }
 
 # Send ping packet to router's ip addresses, from each of the 2 logical ports.
-rtr_l1_ip=$(ip_to_hex 192 168 1 1)
-rtr_l2_ip=$(ip_to_hex 172 16 1 1)
-l1_ip=$(ip_to_hex 192 168 1 2)
-l2_ip=$(ip_to_hex 172 16 1 2)
+rtr_l1_ip=192.168.1.1
+rtr_l2_ip=172.16.1.1
+l1_ip=192.168.1.2
+l2_ip=172.16.1.2
 
 # Ping router ip address that is on same subnet as the logical port
-test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l1_ip 0000 8510 03ff 8d10
-test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l2_ip 0000 8510 03ff 8d10
+test_ipv4_icmp_request 1 00:00:00:01:02:03 00:00:00:01:02:f1 $l1_ip $rtr_l1_ip
+test_ipv4_icmp_request 2 00:00:00:01:02:04 00:00:00:01:02:f2 $l2_ip $rtr_l2_ip
 
 # Ping router ip address that is on the other side of the logical ports
-test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l2_ip 0000 8510 03ff 8d10
-test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l1_ip 0000 8510 03ff 8d10
+test_ipv4_icmp_request 1 00:00:00:01:02:03 00:00:00:01:02:f1 $l1_ip $rtr_l2_ip
+test_ipv4_icmp_request 2 00:00:00:01:02:04 00:00:00:01:02:f2 $l2_ip $rtr_l1_ip
 
 
 echo "---------NB dump-----"