summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-03-06 11:58:06 -0800
committerOle Trøan <otroan@employees.org>2019-03-07 22:29:44 +0000
commiteaea421e1fefedc47325f970475c5d48c899433c (patch)
treed325f642804865b6a57bf75f8ba2897bd438a8a2 /test
parentea2450fa2d1e8ba0295ea9861a404796100dad1e (diff)
Tests: Refactor payload_to_info()
All callers of payload_to_info were required to wrap payload with str(). Refactor to call scapy's payload.load for raw payloads or specify the specific fieldname. Change-Id: I1c80599d4df8dc129dbb8274733afaad406d5bcf Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test')
-rw-r--r--test/doc/overview.rst2
-rw-r--r--test/framework.py8
-rw-r--r--test/test_acl_plugin.py4
-rw-r--r--test/test_classifier.py2
-rw-r--r--test/test_classifier_ip6.py2
-rw-r--r--test/test_classify_l2_acl.py2
-rw-r--r--test/test_ip4.py6
-rw-r--r--test/test_ip4_irb.py4
-rw-r--r--test/test_ip4_vrf_multi_instance.py2
-rw-r--r--test/test_ip6.py2
-rw-r--r--test/test_ip6_vrf_multi_instance.py2
-rw-r--r--test/test_ip_ecmp.py2
-rw-r--r--test/test_l2_fib.py2
-rw-r--r--test/test_l2bd.py2
-rw-r--r--test/test_l2bd_multi_instance.py2
-rw-r--r--test/test_l2xc.py2
-rw-r--r--test/test_l2xc_multi_instance.py2
-rw-r--r--test/test_lb.py2
-rw-r--r--test/test_reassembly.py6
-rw-r--r--test/test_srv6.py2
-rw-r--r--test/test_srv6_ad.py4
-rwxr-xr-xtest/test_srv6_as.py4
22 files changed, 34 insertions, 32 deletions
diff --git a/test/doc/overview.rst b/test/doc/overview.rst
index 26d365bb845..2ef942684e9 100644
--- a/test/doc/overview.rst
+++ b/test/doc/overview.rst
@@ -386,7 +386,7 @@ basic IPv4 forwarding.
ip = packet[IP]
udp = packet[UDP]
# convert the payload to packet info object
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
# make sure the indexes match
self.assert_equal(payload_info.src, src_if.sw_if_index,
"source sw_if_index")
diff --git a/test/framework.py b/test/framework.py
index dc7d6107722..778832f401d 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -746,16 +746,18 @@ class VppTestCase(unittest.TestCase):
info.ip, info.proto)
@staticmethod
- def payload_to_info(payload):
+ def payload_to_info(payload, payload_field='load'):
"""
Convert packet payload to _PacketInfo object
:param payload: packet payload
-
+ :type: <class 'scapy.packet.Raw'>
+ :param: payload_field: packet fieldname of payload "load" for
+ <class 'scapy.packet.Raw'>
:returns: _PacketInfo object containing de-serialized data from payload
"""
- numbers = payload.split()
+ numbers = getattr(payload, payload_field).split()
info = _PacketInfo()
info.index = int(numbers[0])
info.src = int(numbers[1])
diff --git a/test/test_acl_plugin.py b/test/test_acl_plugin.py
index ccf495ced1b..fa92513cbb5 100644
--- a/test/test_acl_plugin.py
+++ b/test/test_acl_plugin.py
@@ -380,10 +380,10 @@ class TestACLplugin(VppTestCase):
# Raw data for ICMPv6 are stored in ICMPv6EchoRequest.data
if traffic_type == self.ICMP and ip_type == self.IPV6:
payload_info = self.payload_to_info(
- packet[ICMPv6EchoRequest].data)
+ packet[ICMPv6EchoRequest], 'data')
payload = packet[ICMPv6EchoRequest]
else:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
payload = packet[self.proto_map[payload_info.proto]]
except:
self.logger.error(ppp("Unexpected or invalid packet "
diff --git a/test/test_classifier.py b/test/test_classifier.py
index c0b85468170..f62a76ded6f 100644
--- a/test/test_classifier.py
+++ b/test/test_classifier.py
@@ -141,7 +141,7 @@ class TestClassifier(VppTestCase):
try:
ip_received = packet[IP]
proto_received = packet[proto_l]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug(
diff --git a/test/test_classifier_ip6.py b/test/test_classifier_ip6.py
index 30ad48c8531..2b9b142afb2 100644
--- a/test/test_classifier_ip6.py
+++ b/test/test_classifier_ip6.py
@@ -126,7 +126,7 @@ class TestClassifier(VppTestCase):
try:
ip6_received = packet[IPv6]
proto_received = packet[proto_l]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug(
diff --git a/test/test_classify_l2_acl.py b/test/test_classify_l2_acl.py
index 0795907b76e..a729929681f 100644
--- a/test/test_classify_l2_acl.py
+++ b/test/test_classify_l2_acl.py
@@ -396,7 +396,7 @@ class TestClassifyAcl(VppTestCase):
packet[ICMPv6EchoRequest].data)
payload = packet[ICMPv6EchoRequest]
else:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
payload = packet[self.proto_map[payload_info.proto]]
except:
self.logger.error(ppp("Unexpected or invalid packet "
diff --git a/test/test_ip4.py b/test/test_ip4.py
index b6553dba7c2..492e96a99e3 100644
--- a/test/test_ip4.py
+++ b/test/test_ip4.py
@@ -168,7 +168,7 @@ class TestIPv4(VppTestCase):
try:
ip = packet[IP]
udp = packet[UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug(
@@ -351,8 +351,8 @@ class TestIPv4FibCrud(VppTestCase):
def _find_ip_match(self, find_in, pkt):
for p in find_in:
- if self.payload_to_info(str(p[Raw])) == \
- self.payload_to_info(str(pkt[Raw])):
+ if self.payload_to_info(p[Raw]) == \
+ self.payload_to_info(pkt[Raw]):
if p[IP].src != pkt[IP].src:
break
if p[IP].dst != pkt[IP].dst:
diff --git a/test/test_ip4_irb.py b/test/test_ip4_irb.py
index 8c3830c2d81..9b762aa0248 100644
--- a/test/test_ip4_irb.py
+++ b/test/test_ip4_irb.py
@@ -152,7 +152,7 @@ class TestIpIrb(VppTestCase):
for packet in capture:
ip = packet[IP]
udp = packet[IP][UDP]
- payload_info = self.payload_to_info(str(packet[IP][UDP][Raw]))
+ payload_info = self.payload_to_info(packet[IP][UDP][Raw])
self.assertEqual(payload_info.dst, dst_ip_sw_if_index)
@@ -188,7 +188,7 @@ class TestIpIrb(VppTestCase):
for packet in capture:
ip = packet[IP]
udp = packet[IP][UDP]
- payload_info = self.payload_to_info(str(packet[IP][UDP][Raw]))
+ payload_info = self.payload_to_info(packet[IP][UDP][Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_ip_sw_if_index)
diff --git a/test/test_ip4_vrf_multi_instance.py b/test/test_ip4_vrf_multi_instance.py
index 76a32adf690..71532adf364 100644
--- a/test/test_ip4_vrf_multi_instance.py
+++ b/test/test_ip4_vrf_multi_instance.py
@@ -296,7 +296,7 @@ class TestIp4VrfMultiInst(VppTestCase):
try:
ip = packet[IP]
udp = packet[UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
diff --git a/test/test_ip6.py b/test/test_ip6.py
index 111a71e449a..1d52edb7721 100644
--- a/test/test_ip6.py
+++ b/test/test_ip6.py
@@ -318,7 +318,7 @@ class TestIPv6(TestIPv6ND):
try:
ip = packet[IPv6]
udp = packet[inet6.UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug(
diff --git a/test/test_ip6_vrf_multi_instance.py b/test/test_ip6_vrf_multi_instance.py
index 7284e2e02ed..4b4a9e47a7b 100644
--- a/test/test_ip6_vrf_multi_instance.py
+++ b/test/test_ip6_vrf_multi_instance.py
@@ -309,7 +309,7 @@ class TestIP6VrfMultiInst(VppTestCase):
try:
ip = packet[IPv6]
udp = packet[UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
diff --git a/test/test_ip_ecmp.py b/test/test_ip_ecmp.py
index 17b0a6c79c2..5abaea41e46 100644
--- a/test/test_ip_ecmp.py
+++ b/test/test_ip_ecmp.py
@@ -138,7 +138,7 @@ class TestECMP(VppTestCase):
for packet in capture:
try:
ip_received = packet[ip_l]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
ip_sent = self._packet_infos[packet_index].data[ip_l]
self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
diff --git a/test/test_l2_fib.py b/test/test_l2_fib.py
index ac70c8a726d..58dc37eea23 100644
--- a/test/test_l2_fib.py
+++ b/test/test_l2_fib.py
@@ -299,7 +299,7 @@ class TestL2fib(VppTestCase):
last_info[i.sw_if_index] = None
dst_sw_if_index = pg_if.sw_if_index
for packet in capture:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
try:
ip = packet[IP]
udp = packet[UDP]
diff --git a/test/test_l2bd.py b/test/test_l2bd.py
index 30708a46a03..db831f35405 100644
--- a/test/test_l2bd.py
+++ b/test/test_l2bd.py
@@ -184,7 +184,7 @@ class TestL2bd(VppTestCase):
last_info[i.sw_if_index] = None
dst_sw_if_index = pg_if.sw_if_index
for packet in capture:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
src_sw_if_index = payload_info.src
src_if = None
for ifc in self.pg_interfaces:
diff --git a/test/test_l2bd_multi_instance.py b/test/test_l2bd_multi_instance.py
index 18967149260..ac3662ff5a3 100644
--- a/test/test_l2bd_multi_instance.py
+++ b/test/test_l2bd_multi_instance.py
@@ -263,7 +263,7 @@ class TestL2bdMultiInst(VppTestCase):
try:
ip = packet[IP]
udp = packet[UDP]
- info = self.payload_to_info(str(packet[Raw]))
+ info = self.payload_to_info(packet[Raw])
self.assertEqual(info.dst, dst)
self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
(dst_if.name, info.src, info.index))
diff --git a/test/test_l2xc.py b/test/test_l2xc.py
index 2ec4af9288e..8be93e44faa 100644
--- a/test/test_l2xc.py
+++ b/test/test_l2xc.py
@@ -147,7 +147,7 @@ class TestL2xc(VppTestCase):
try:
ip = packet[IP]
udp = packet[UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
diff --git a/test/test_l2xc_multi_instance.py b/test/test_l2xc_multi_instance.py
index bb26f95906c..6192bd1ad57 100644
--- a/test/test_l2xc_multi_instance.py
+++ b/test/test_l2xc_multi_instance.py
@@ -235,7 +235,7 @@ class TestL2xcMultiInst(VppTestCase):
last_info[i.sw_if_index] = None
dst_sw_if_index = pg_if.sw_if_index
for packet in capture:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
try:
ip = packet[IP]
udp = packet[UDP]
diff --git a/test/test_lb.py b/test/test_lb.py
index 45dab79fd42..86e7cb46ad3 100644
--- a/test/test_lb.py
+++ b/test/test_lb.py
@@ -94,7 +94,7 @@ class TestLB(VppTestCase):
self.assertEqual(gre.flags, 0)
self.assertEqual(gre.version, 0)
inner = IPver(str(gre.payload))
- payload_info = self.payload_to_info(str(inner[Raw]))
+ payload_info = self.payload_to_info(inner[Raw])
self.info = self.packet_infos[payload_info.index]
self.assertEqual(payload_info.src, self.pg0.sw_if_index)
self.assertEqual(str(inner), str(self.info.data[IPver]))
diff --git a/test/test_reassembly.py b/test/test_reassembly.py
index aee67b185cc..8004f362f3d 100644
--- a/test/test_reassembly.py
+++ b/test/test_reassembly.py
@@ -52,7 +52,7 @@ class TestIPReassemblyMixin(object):
self.logger.debug(ppp("Got packet:", packet))
ip = packet[scapy_ip_family]
udp = packet[UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertTrue(
packet_index not in dropped_packet_indexes,
@@ -899,7 +899,7 @@ class TestIPv4ReassemblyLocalNode(VppTestCase):
self.logger.debug(ppp("Got packet:", packet))
ip = packet[IP]
icmp = packet[ICMP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
if packet_index in seen:
raise Exception(ppp("Duplicate packet received", packet))
@@ -997,7 +997,7 @@ class TestFIFReassembly(VppTestCase):
self.logger.debug(ppp("Got packet:", packet))
ip = packet[ip_class]
udp = packet[UDP]
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
packet_index = payload_info.index
self.assertTrue(
packet_index not in dropped_packet_indexes,
diff --git a/test/test_srv6.py b/test/test_srv6.py
index 890e7ffbf3b..2ea9da76088 100644
--- a/test/test_srv6.py
+++ b/test/test_srv6.py
@@ -2080,7 +2080,7 @@ class TestSRv6(VppTestCase):
# but packet[Raw] gives the complete payload
# (incl L2 header) for the T.Encaps L2 case
try:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
except:
# remote L2 header from packet[Raw]:
diff --git a/test/test_srv6_ad.py b/test/test_srv6_ad.py
index 6dafa9f6b3f..728ecd8a796 100644
--- a/test/test_srv6_ad.py
+++ b/test/test_srv6_ad.py
@@ -729,14 +729,14 @@ class TestSRv6(VppTestCase):
# but packet[Raw] gives the complete payload
# (incl L2 header) for the T.Encaps L2 case
try:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
except:
# remote L2 header from packet[Raw]:
# take packet[Raw], convert it to an Ether layer
# and then extract Raw from it
payload_info = self.payload_to_info(
- str(Ether(str(packet[Raw]))[Raw]))
+ Ether(str(packet[Raw]))[Raw])
return payload_info
diff --git a/test/test_srv6_as.py b/test/test_srv6_as.py
index 64ff957da4b..1ff7906e513 100755
--- a/test/test_srv6_as.py
+++ b/test/test_srv6_as.py
@@ -810,14 +810,14 @@ class TestSRv6(VppTestCase):
# but packet[Raw] gives the complete payload
# (incl L2 header) for the T.Encaps L2 case
try:
- payload_info = self.payload_to_info(str(packet[Raw]))
+ payload_info = self.payload_to_info(packet[Raw])
except:
# remote L2 header from packet[Raw]:
# take packet[Raw], convert it to an Ether layer
# and then extract Raw from it
payload_info = self.payload_to_info(
- str(Ether(str(packet[Raw]))[Raw]))
+ Ether(str(packet[Raw]))[Raw])
return payload_info