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/default_drop.py b/tests/default_drop.py
index 574593f..975e056 100644
--- a/tests/default_drop.py
+++ b/tests/default_drop.py
@@ -23,21 +23,6 @@
do_barrier(self.controller)
for of_port in config["port_map"].keys():
- pkt = simple_tcp_packet()
- self.dataplane.send(of_port, str(pkt))
- 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 None,
- 'Packet in message received on port ' +
- str(of_port))
+ pkt = str(simple_tcp_packet())
+ self.dataplane.send(of_port, pkt)
+ verify_no_packet_in(self, pkt, of_port)