oft: add --default-negative-timeout command line option
This option controls how long OFTest waits for an event that we don't expect to
occur. It replaces several hardcoded values.
diff --git a/src/python/oftest/ofutils.py b/src/python/oftest/ofutils.py
index 8cf2ae0..f81a2f5 100644
--- a/src/python/oftest/ofutils.py
+++ b/src/python/oftest/ofutils.py
@@ -10,6 +10,7 @@
import logging
default_timeout = None # set by oft
+default_negative_timeout = None # set by oft
def gen_xid():
return random.randrange(1,0xffffffff)
@@ -19,11 +20,9 @@
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=-1):
if timeout == -1:
- # TODO make this configurable
timeout = default_timeout
end_time = time.time() + timeout
diff --git a/src/python/oftest/testutils.py b/src/python/oftest/testutils.py
index 5b2e365..ae16ee1 100644
--- a/src/python/oftest/testutils.py
+++ b/src/python/oftest/testutils.py
@@ -576,11 +576,6 @@
DEPRECATED in favor in verify_packets
"""
- # Wait this long for packets that we don't expect to receive.
- # 100ms is (rarely) too short for positive tests on slow
- # switches but is definitely not too short for a negative test.
- negative_timeout = 0.1
-
exp_pkt_arg = None
if oftest.config["relax"]:
exp_pkt_arg = pkt
@@ -598,7 +593,7 @@
"Received packet does not match expected packet " +
"on port " + str(ofport))
if len(no_ports) > 0:
- time.sleep(negative_timeout)
+ time.sleep(oftest.ofutils.negative_timeout)
for ofport in no_ports:
logging.debug("Negative check for pkt on port " + str(ofport))
(rcv_port, rcv_pkt, pkt_time) = dp.poll(
@@ -1605,7 +1600,7 @@
# Negative test, need to wait a short amount of time before checking we
# didn't receive the message.
- time.sleep(0.5)
+ time.sleep(oftest.ofutils.default_negative_timeout)
# Check every packet_in queued in the controller
while True:
@@ -1648,7 +1643,10 @@
Check that a particular packet is not received
"""
logging.debug("Negative check for pkt on port %r", ofport)
- (rcv_port, rcv_pkt, pkt_time) = test.dataplane.poll(port_number=ofport, exp_pkt=str(pkt), timeout=0.01)
+ (rcv_port, rcv_pkt, pkt_time) = \
+ test.dataplane.poll(
+ port_number=ofport, exp_pkt=str(pkt),
+ timeout=oftest.ofutils.default_negative_timeout)
test.assertTrue(rcv_pkt == None, "Received packet on %r" % ofport)
def verify_no_other_packets(test):
@@ -1660,7 +1658,7 @@
if oftest.config["relax"]:
return
logging.debug("Checking for unexpected packets on all ports")
- (rcv_port, rcv_pkt, pkt_time) = test.dataplane.poll(timeout=0.01)
+ (rcv_port, rcv_pkt, pkt_time) = test.dataplane.poll(timeout=oftest.ofutils.default_negative_timeout)
if rcv_pkt != None:
logging.debug("Received unexpected packet on port %r: %s", rcv_port, format_packet(rcv_pkt))
test.assertTrue(rcv_pkt == None, "Unexpected packet on port %r" % rcv_port)