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/basic.py b/tests/basic.py
index 5312c1a..6e0e4d0 100644
--- a/tests/basic.py
+++ b/tests/basic.py
@@ -91,29 +91,7 @@
logging.info("PKT IN test with %s, port %s" % (pt, of_port))
self.dataplane.send(of_port, str(pkt))
- #@todo Check for unexpected messages?
- count = 0
- while True:
- (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN)
- if not response: # Timeout
- break
- if dataplane.match_exp_pkt(pkt, response.data): # Got match
- break
- if not config["relax"]: # Only one attempt to match
- break
- count += 1
- if count > 10: # Too many tries
- break
-
- self.assertTrue(response is not None,
- 'Packet in message not received on port ' +
- str(of_port))
- if not dataplane.match_exp_pkt(pkt, response.data):
- logging.debug("Sent %s" % format_packet(pkt))
- logging.debug("Resp %s" % format_packet(response.data))
- self.assertTrue(False,
- 'Response packet does not match send packet' +
- ' for port ' + str(of_port))
+ verify_packet_in(self, str(pkt), of_port, ofp.OFPR_NO_MATCH)
class PacketInBroadcastCheck(base_tests.SimpleDataPlane):
"""