Support counting pkt-in msgs in controller
Count pkt-in messages as they are received
Allow the message queue to be cleared with new clear_queue fn
Also small bug fix: deref null exp_msg
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index 41ac927..404b185 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -125,6 +125,7 @@
# Protected by the packets_cv lock / condition variable
self.packets = []
self.packets_cv = Condition()
+ self.packet_in_count = 0
# Settings
self.max_pkts = max_pkts
@@ -258,6 +259,10 @@
self.message_send(rep.pack())
continue
+ # Generalize to counters for all packet types?
+ if msg.type == ofp.OFPT_PACKET_IN:
+ self.packet_in_count += 1
+
# Log error messages
if hdr_type == ofp.OFPT_ERROR:
if msg.err_type in ofp.ofp_error_type_map:
@@ -578,7 +583,10 @@
If an error occurs, (None, None) is returned
"""
- exp_msg_str = ofp.ofp_type_map.get(exp_msg, "unknown (%d)" % exp_msg)
+ exp_msg_str = "unspecified"
+ if exp_msg:
+ exp_msg_str = ofp.ofp_type_map.get(exp_msg, "unknown (%d)" %
+ exp_msg)
if exp_msg is not None:
self.logger.debug("Poll for %s", exp_msg_str)
@@ -684,6 +692,16 @@
return 0 # for backwards compatibility
+ def clear_queue(self):
+ """
+ Clear the input queue and report the number of messages
+ that were in it
+ """
+ enqueued_pkts = len(self.packets)
+ with self.packets_cv:
+ self.packets = []
+ return enqueued_pkts
+
def __str__(self):
string = "Controller:\n"
string += " state " + self.dbg_state + "\n"