standardize on -1 for default timeouts
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index d262f9f..88f2c65 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -382,18 +382,14 @@
self.logger.info("Exiting controller thread")
self.shutdown()
- def connect(self, timeout=None):
+ def connect(self, timeout=-1):
"""
Connect to the switch
- @param timeout If None, block until connected. If 0, return
- immedidately. Otherwise, block for up to timeout seconds
+ @param timeout Block for up to timeout seconds. Pass -1 for the default.
@return Boolean, True if connected
"""
- if timeout == 0:
- return self.switch_socket is not None
-
with self.connect_cv:
timed_wait(self.connect_cv, lambda: self.switch_socket, timeout=timeout)
return self.switch_socket is not None
@@ -475,11 +471,7 @@
If an error occurs, (None, None) is returned
"""
- # TODO make this configurable
- if timeout == -1:
- timeout = 1
-
- self.logger.debug("Poll for %s, timeout %fs" % (ofp_type_map[exp_msg], timeout))
+ self.logger.debug("Poll for %s" % ofp_type_map[exp_msg])
# Take the packet from the queue
def grab():
@@ -501,7 +493,7 @@
return None
with self.packets_cv:
- ret = timed_wait(self.packets_cv, grab)
+ ret = timed_wait(self.packets_cv, grab, timeout=timeout)
if ret != None:
(msg, pkt) = ret
@@ -529,10 +521,6 @@
if not zero_xid and msg.header.xid == 0:
msg.header.xid = gen_xid()
- if timeout == -1:
- timeout = self.transact_to
- if timeout == None:
- timeout = 60
self.logger.debug("Running transaction %d" % msg.header.xid)
with self.xid_cv:
@@ -547,7 +535,7 @@
msg.header.xid)
return (None, None)
- self.logger.debug("Waiting %fs for transaction %d" % (timeout, msg.header.xid))
+ self.logger.debug("Waiting for transaction %d" % msg.header.xid)
timed_wait(self.xid_cv, lambda: self.xid_response, timeout=timeout)
if self.xid_response:
diff --git a/src/python/oftest/dataplane.py b/src/python/oftest/dataplane.py
index 6b69589..aa434a7 100644
--- a/src/python/oftest/dataplane.py
+++ b/src/python/oftest/dataplane.py
@@ -334,7 +334,7 @@
pkt, time = port.packets.pop(0)
yield (port, pkt, time)
- def poll(self, port_number=None, timeout=None, exp_pkt=None):
+ def poll(self, port_number=None, timeout=-1, exp_pkt=None):
"""
Poll one or all dataplane ports for a packet
diff --git a/src/python/oftest/ofutils.py b/src/python/oftest/ofutils.py
index 9e59c5d..3fd9df9 100644
--- a/src/python/oftest/ofutils.py
+++ b/src/python/oftest/ofutils.py
@@ -12,18 +12,23 @@
"""
Wait on a condition variable until the given function returns non-None or a timeout expires.
The condition variable must already be acquired.
+The timeout value -1 means use the default timeout.
There is deliberately no support for an infinite timeout.
TODO: get the default timeout from configuration
"""
-def timed_wait(cv, fn, timeout=10):
+def timed_wait(cv, fn, timeout=-1):
+ if timeout == -1:
+ # TODO make this configurable
+ timeout = 5
+
end_time = time.time() + timeout
while True:
- if time.time() > end_time:
- return None
-
val = fn()
if val != None:
return val
remaining_time = end_time - time.time()
cv.wait(remaining_time)
+
+ if time.time() > end_time:
+ return None