Add default timeout for do_barrier
And check the result do_barrier in all calls.
diff --git a/src/python/oftest/controller.py b/src/python/oftest/controller.py
index debff35..70b3aad 100644
--- a/src/python/oftest/controller.py
+++ b/src/python/oftest/controller.py
@@ -111,6 +111,7 @@
self.port = port
self.dbg_state = "init"
self.logger = logging.getLogger("controller")
+ self.barrier_to = 15 # Barrier timeout default value; add to config
# Transaction and message type waiting variables
# xid_cv: Condition variable (semaphore) for packet waiters
@@ -161,7 +162,7 @@
self.parse_errors += 1
return
if hdr.length == 0:
- self.logger.info("Header length is zero")
+ self.logger.error("Header length is zero; out of sync")
self.parse_errors += 1
return
@@ -287,7 +288,8 @@
return False
if len(pkt) == 0:
- self.logger.warning("Zero-length switch read")
+ self.logger.warning("Zero-length switch read; closing cxn")
+ return True
self._pkt_handle(pkt)
else:
@@ -501,7 +503,7 @@
return (msg, pkt)
- def transact(self, msg, timeout=None, zero_xid=False):
+ def transact(self, msg, timeout=-1, zero_xid=False):
"""
Run a message transaction with the switch
@@ -520,15 +522,19 @@
if not zero_xid and msg.header.xid == 0:
msg.header.xid = gen_xid()
+ if timeout == -1:
+ timeout = self.barrier_to
+ self.logger.debug("Running transaction %d" % msg.header.xid)
self.xid_cv.acquire()
if self.xid:
self.xid_cv.release()
self.logger.error("Can only run one transaction at a time")
- return None
+ return (None, None)
self.xid = msg.header.xid
self.xid_response = None
self.message_send(msg.pack())
+ self.logger.debug("Waiting for transaction %d" % msg.header.xid)
self.xid_cv.wait(timeout)
if self.xid_response:
(resp, pkt) = self.xid_response
diff --git a/tests/basic.py b/tests/basic.py
index bf5798e..471fb2a 100644
--- a/tests/basic.py
+++ b/tests/basic.py
@@ -237,7 +237,7 @@
rc = delete_all_flows(self.controller, basic_logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
for of_port in basic_port_map.keys():
for pkt, pt in [
diff --git a/tests/caps.py b/tests/caps.py
index bb85818..4a0e355 100644
--- a/tests/caps.py
+++ b/tests/caps.py
@@ -90,7 +90,7 @@
caps_logger.info("Inserting initial flow")
rv = obj.controller.message_send(request)
obj.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(obj.controller)
+ self.assertEqual(do_barrier(obj.controller), 0, "Barrier failed")
flow_count = 1
caps_logger.info("Table idx: " + str(table_idx))
@@ -99,7 +99,7 @@
while True:
request.match.nw_src += 1
rv = obj.controller.message_send(request)
- do_barrier(obj.controller)
+ self.assertEqual(do_barrier(obj.controller), 0, "Barrier failed")
flow_count += 1
if flow_count % count_check == 0:
response, pkt = obj.controller.transact(tstats, timeout=2)
diff --git a/tests/flow_expire.py b/tests/flow_expire.py
index 53d7181..1d05b6b 100644
--- a/tests/flow_expire.py
+++ b/tests/flow_expire.py
@@ -97,7 +97,7 @@
fe_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
(response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
timeout=test_timeout)
diff --git a/tests/flow_stats.py b/tests/flow_stats.py
index 4d43672..a959102 100644
--- a/tests/flow_stats.py
+++ b/tests/flow_stats.py
@@ -171,7 +171,7 @@
fs_logger.info("Inserting flow")
rv = self.controller.message_send(flow_mod_msg)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
# no packets sent, so zero packet count
self.verifyStats(match, ofp.OFPP_NONE, test_timeout, 0)
@@ -298,7 +298,7 @@
fs_logger.info("Inserting flow2")
rv = self.controller.message_send(flow_mod_msg2)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
num_pkt1s = random.randint(10,30)
fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
@@ -414,7 +414,7 @@
fs_logger.info("Inserting flow2")
rv = self.controller.message_send(flow_mod_msg2)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
num_pkt1s = random.randint(10,30)
fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
diff --git a/tests/pktact.py b/tests/pktact.py
index 724dcba..7b34d12 100644
--- a/tests/pktact.py
+++ b/tests/pktact.py
@@ -160,7 +160,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " +
str(ingress_port))
@@ -243,7 +243,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " +
str(ingress_port))
@@ -300,7 +300,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
@@ -355,7 +355,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
@@ -402,7 +402,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
@@ -454,7 +454,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
@@ -501,7 +501,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
@@ -553,7 +553,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
@@ -609,7 +609,7 @@
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Sending packet to dp port " + str(ingress_port))
pa_logger.info("No flood port is " + str(no_flood_port))
@@ -688,7 +688,7 @@
def _ClearTable(self):
rc = delete_all_flows(self.controller, self.logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
def runTest(self):
@@ -769,7 +769,7 @@
# This *must* be set for DELETE
msg.out_port = ofp.OFPP_NONE
self.controller.message_send(msg)
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
else:
raise Exception("Not initialized")
@@ -1257,7 +1257,7 @@
for f_idx in range(flow_count):
rv = self.controller.message_send(flows[0][f_idx])
self.assertTrue(rv != -1, "Error installing flow %d" % f_idx)
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
pa_logger.info("Installed %d flows" % flow_count)
@@ -1279,7 +1279,8 @@
updates += 1
self.assertTrue(rv != -1, "Error modifying flow %d" %
f_idx)
- do_barrier(self.controller)
+ self.assertEqual(do_barrier(self.controller), 0,
+ "Barrier failed")
end = time.time()
divisor = end - start or (end - start + 1)
diff --git a/tests/testutils.py b/tests/testutils.py
index f1459bf..9c7b81f 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -169,9 +169,16 @@
return pkt
def do_barrier(ctrl):
+ """
+ Do a barrier command
+ Return 0 on success, -1 on error
+ """
b = message.barrier_request()
- ctrl.transact(b)
-
+ (resp, pkt) = ctrl.transact(b, timeout=ctrl.barrier_to)
+ # We'll trust the transaction processing in the controller
+ if not resp:
+ return -1
+ return 0
def port_config_get(controller, port_no, logger):
"""
@@ -475,12 +482,12 @@
parent.logger.debug("Clear flow table")
rc = delete_all_flows(parent.controller, parent.logger)
parent.assertEqual(rc, 0, "Failed to delete all flows")
- do_barrier(parent.controller)
+ parent.assertEqual(do_barrier(parent.controller), 0, "Barrier failed")
parent.logger.debug("Insert flow")
rv = parent.controller.message_send(request)
parent.assertTrue(rv != -1, "Error installing flow mod")
- do_barrier(parent.controller)
+ parent.assertEqual(do_barrier(parent.controller), 0, "Barrier failed")
def flow_match_test_port_pair(parent, ing_port, egr_ports, wildcards=0,
dl_vlan=-1, pkt=None, exp_pkt=None,