testutils: add inspect_packet() and use it when receive_pkt_verify() fails
diff --git a/src/python/oftest/testutils.py b/src/python/oftest/testutils.py
index 76d55f8..8b0b3b6 100644
--- a/src/python/oftest/testutils.py
+++ b/src/python/oftest/testutils.py
@@ -109,9 +109,6 @@
scapy.TCP(sport=tcp_sport, dport=tcp_dport)
pkt = pkt/("D" * (pktlen - len(pkt)))
-
- #print pkt.show()
- #print scapy.Ether(str(pkt)).show()
return pkt
@@ -374,6 +371,8 @@
+ str(exp_pkt).encode('hex'))
logging.debug("Received len " + str(len(rcv_pkt)) + ": "
+ str(rcv_pkt).encode('hex'))
+ logging.debug("Expected packet: " + inspect_packet(scapy.Ether(str(exp_pkt))))
+ logging.debug("Received packet: " + inspect_packet(scapy.Ether(str(rcv_pkt))))
parent.assertEqual(str(exp_pkt), str(rcv_pkt),
"Packet match error on port " + str(check_port))
@@ -902,3 +901,20 @@
def format_packet(pkt):
return "Packet length %d \n%s" % (len(str(pkt)),
hex_dump_buffer(str(pkt)))
+
+def inspect_packet(pkt):
+ """
+ Wrapper around scapy's show() method.
+ @returns A string showing the dissected packet.
+ """
+ from cStringIO import StringIO
+ out = None
+ backup = sys.stdout
+ try:
+ sys.stdout = StringIO()
+ pkt.show2()
+ out = sys.stdout.getvalue()
+ sys.stdout.close()
+ finally:
+ sys.stdout = backup
+ return out