controller: accept class in the poll exp_msg parameter
This allows us to poll for e.g. ofp.message.bsn_arp_idle instead of
ofp.OFPT_EXPERIMENTER.
The integer type argument is still supported.
Polling for any message is now deprecated.
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index 0107221..fd11459 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -597,34 +597,28 @@
If an error occurs, (None, None) is returned
"""
- exp_msg_str = "unspecified"
- if exp_msg is not None:
- exp_msg_str = cfg_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)
+ if exp_msg is None:
+ self.logger.warn("DEPRECATED polling for any message class")
+ klass = None
+ elif isinstance(exp_msg, int):
+ klass = cfg_ofp.message.message.subtypes[exp_msg]
+ elif issubclass(exp_msg, cfg_ofp.message.message):
+ klass = exp_msg
else:
- self.logger.debug("Poll for any OF message")
+ raise ValueError("Unexpected exp_msg argument")
+
+ self.logger.debug("Polling for %s", klass.__name__)
# Take the packet from the queue
def grab():
- if len(self.packets) > 0:
- if exp_msg is None:
- self.logger.debug("Looking for any packet")
- (msg, pkt) = self.packets.pop(0)
+ for i in range(len(self.packets)):
+ msg = self.packets[i][0]
+ if klass is None or isinstance(msg, klass):
+ self.logger.debug("Got %s message", msg.__class__.__name__)
+ (msg, pkt) = self.packets.pop(i)
return (msg, pkt)
- else:
- self.logger.debug("Looking for %s", exp_msg_str)
- for i in range(len(self.packets)):
- msg = self.packets[i][0]
- msg_str = cfg_ofp.ofp_type_map.get(msg.type, "unknown (%d)" % msg.type)
- self.logger.debug("Checking packets[%d] %s) against %s", i, msg_str, exp_msg_str)
- if msg.type == exp_msg:
- (msg, pkt) = self.packets.pop(i)
- return (msg, pkt)
# Not found
- self.logger.debug("Packet not in queue")
+ self.logger.debug("%s message not in queue", klass.__name__)
return None
with self.packets_cv:
@@ -632,7 +626,6 @@
if ret != None:
(msg, pkt) = ret
- self.logger.debug("Got message %s" % str(msg))
return (msg, pkt)
else:
return (None, None)