testutils: add new functions to check for dataplane packets
`receive_pkt_check` and `receive_pkt_verify` had slightly different
functionality and neither were sufficient for complex tests. This change
deprecates them and adds new functions.
The high level `verify_packets` function is sufficient for most tests. When
more complex logic is needed the primitive functions `verify_packet`,
`verify_no_packet`, and `verify_no_other_packets` should be used directly.
All OpenFlow 1.0/1.3 tests are updated to use the new functions. The old
functions are left around for compatibility with out of tree tests.
diff --git a/tests-1.3/actions.py b/tests-1.3/actions.py
index e5b1e3a..4d48fbe 100644
--- a/tests-1.3/actions.py
+++ b/tests-1.3/actions.py
@@ -50,8 +50,7 @@
logging.info("Sending packet, expecting output to port %d", out_port)
self.dataplane.send(in_port, pktstr)
- receive_pkt_check(self.dataplane, pktstr, [out_port],
- set(openflow_ports()) - set([out_port]), self)
+ verify_packets(self, pktstr, [out_port])
class OutputMultiple(base_tests.SimpleDataPlane):
"""
@@ -86,8 +85,7 @@
logging.info("Sending packet, expecting output to ports %r", out_ports)
self.dataplane.send(in_port, pktstr)
- receive_pkt_check(self.dataplane, pktstr, out_ports,
- set(openflow_ports()) - set(out_ports), self)
+ verify_packets(self, pktstr, out_ports)
class BaseModifyPacketTest(base_tests.SimpleDataPlane):
"""
@@ -117,8 +115,8 @@
logging.info("Sending packet, expecting output to port %d", out_port)
self.dataplane.send(in_port, str(pkt))
- receive_pkt_check(self.dataplane, str(exp_pkt), [out_port],
- set(openflow_ports()) - set([out_port]), self)
+ verify_packets(self, str(exp_pkt), [out_port])
+
class PushVlan(BaseModifyPacketTest):
"""
diff --git a/tests-1.3/basic.py b/tests-1.3/basic.py
index eeedec7..21dd130 100644
--- a/tests-1.3/basic.py
+++ b/tests-1.3/basic.py
@@ -73,7 +73,7 @@
pkt = str(simple_tcp_packet())
self.dataplane.send(in_port, pkt)
verify_no_packet_in(self, pkt, None)
- receive_pkt_check(self.dataplane, pkt, [], openflow_ports(), self)
+ verify_packets(self, pkt, [])
class OutputExact(base_tests.SimpleDataPlane):
"""
@@ -115,7 +115,7 @@
continue
logging.info("OutputExact test, ports %d to %d", in_port, out_port)
self.dataplane.send(in_port, pkt)
- receive_pkt_verify(self, [out_port], pkt, in_port)
+ verify_packets(self, pkt, [out_port])
class OutputWildcard(base_tests.SimpleDataPlane):
"""
@@ -154,7 +154,7 @@
continue
logging.info("OutputWildcard test, ports %d to %d", in_port, out_port)
self.dataplane.send(in_port, pkt)
- receive_pkt_verify(self, [out_port], pkt, in_port)
+ verify_packets(self, pkt, [out_port])
class PacketInExact(base_tests.SimpleDataPlane):
"""
@@ -191,6 +191,7 @@
logging.info("PacketInExact test, port %d", of_port)
self.dataplane.send(of_port, pkt)
verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
+ verify_packets(self, pkt, [])
class PacketInWildcard(base_tests.SimpleDataPlane):
"""
@@ -224,6 +225,7 @@
logging.info("PacketInWildcard test, port %d", of_port)
self.dataplane.send(of_port, pkt)
verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
+ verify_packets(self, pkt, [])
class PacketInMiss(base_tests.SimpleDataPlane):
"""
@@ -258,6 +260,7 @@
logging.info("PacketInMiss test, port %d", of_port)
self.dataplane.send(of_port, pkt)
verify_packet_in(self, pkt, of_port, ofp.OFPR_NO_MATCH)
+ verify_packets(self, pkt, [])
class PacketOut(base_tests.SimpleDataPlane):
"""
@@ -278,7 +281,7 @@
logging.info("PacketOut test, port %d", of_port)
self.controller.message_send(msg)
- receive_pkt_verify(self, [of_port], pkt, ofp.OFPP_CONTROLLER)
+ verify_packets(self, pkt, [of_port])
class FlowRemoveAll(base_tests.SimpleProtocol):
"""
diff --git a/tests-1.3/match.py b/tests-1.3/match.py
index c45858f..0b473da 100644
--- a/tests-1.3/match.py
+++ b/tests-1.3/match.py
@@ -73,7 +73,7 @@
logging.info("Sending matching packet %s, expecting output to port %d", repr(name), out_port)
pktstr = str(pkt)
self.dataplane.send(in_port, pktstr)
- receive_pkt_verify(self, [out_port], pktstr, in_port)
+ verify_packets(self, pktstr, [out_port])
for name, pkt in nonmatching.items():
logging.info("Sending non-matching packet %s, expecting packet-in", repr(name))
@@ -132,7 +132,7 @@
logging.info("Sending packet on matching ingress port, expecting output to port %d", out_port)
self.dataplane.send(in_port, pktstr)
- receive_pkt_verify(self, [out_port], pktstr, in_port)
+ verify_packets(self, pktstr, [out_port])
logging.info("Sending packet on non-matching ingress port, expecting packet-in")
self.dataplane.send(bad_port, pktstr)