testutils: add verify_packet_in and verify_no_packet_in
Checking that the controller received a packet-in message is surprisingly
complicated to do correctly. Because the switch may send unexpected packet-ins
(Linux IP stack on IVS's OFPP_LOCAL, for example) each test needs logic to
match the packet data, in_port, etc to figure out if this is the packet-in
message it's looking for.
This change adds two testutils functions that automate this, and replaces all
the other implementations in tests.
diff --git a/tests/actions.py b/tests/actions.py
index 2791d5a..d25108d 100644
--- a/tests/actions.py
+++ b/tests/actions.py
@@ -66,9 +66,7 @@
"Packet received on port " + str(rcv_port))
#Verify packets not sent on control plane either
- (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1)
- self.assertTrue(response is None,
- 'Packets not received on control plane')
+ verify_no_packet_in(self, str(pkt), of_ports[0])
class Announcement(base_tests.SimpleDataPlane):
@@ -215,9 +213,7 @@
self.dataplane.send(ingress_port, str(pkt))
#Verifying packet recieved on the control plane port
- (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10)
- self.assertTrue(response is not None,
- 'Packet in message not received by controller')
+ verify_packet_in(self, str(pkt), ingress_port, ofp.OFPR_ACTION)