Added packet-in monitor test case
This test case starts the controller connection with keep-alive.
It then polls the controller to count packet in messages. It
reports the number of messages received about every second.
diff --git a/tests/cxn.py b/tests/cxn.py
index 1a00f1f..13a9771 100644
--- a/tests/cxn.py
+++ b/tests/cxn.py
@@ -121,7 +121,8 @@
def __init__(self, keep_alive=True, cxn_cycles=5,
controller_timeout=-1, hello_timeout=5,
- features_req_timeout=5, disconnected_timeout=3):
+ features_req_timeout=5, disconnected_timeout=3,
+ report_pkts=False):
BaseHandshake.__init__(self)
self.buildControllerList()
self.keep_alive = keep_alive
@@ -135,7 +136,52 @@
or features_req_timeout
self.disconnected_timeout = test_param_get('disconnected_timeout') \
or disconnected_timeout
+ self.report_pkts = report_pkts
+ # These functions provide per-tick processing
+ def periodic_init(self, tick_time):
+ """
+ Assumes tick_time is in seconds, usually 1/10 of a sec
+ """
+ if not self.report_pkts:
+ return
+ self.start_time = time.time()
+ self.last_report = self.start_time
+ self.pkt_in_count = 0 # Total packet in count
+ self.periodic_pkt_in_count = 0 # Packet-ins this cycle
+
+ def periodic_tick(self, con):
+ """
+ Process one tick. Currently this just counts pkt-in msgs
+ """
+ if not self.report_pkts:
+ return
+ if con.cstate != 4:
+ return
+ if self.report_pkts:
+ # Gather packets from control cxn
+ current_time = time.time()
+ new_pkts = con.packet_in_count - self.pkt_in_count
+ self.pkt_in_count = con.packet_in_count
+ self.periodic_pkt_in_count += new_pkts
+ con.clear_queue()
+
+ # Report every second or so
+ if (current_time - self.last_report >= 1):
+ if self.periodic_pkt_in_count:
+ print "%7.2f: pkt/sec last period: %6d. Total %10d." % (
+ current_time - self.start_time,
+ self.periodic_pkt_in_count/(current_time - self.last_report),
+ self.pkt_in_count)
+ self.last_report = current_time
+ self.periodic_pkt_in_count = 0
+
+ def periodic_done(self):
+ if not self.report_pkts:
+ return
+ print "Received %d pkt-ins over %d seconds" % (
+ self.pkt_in_count, time.time() - self.start_time)
+
def runTest(self):
for conspec in self.controller_list:
self.controllerSetup(conspec[0], conspec[1])
@@ -144,6 +190,7 @@
self.controllers[i].keep_alive = self.keep_alive
self.controllers[i].saved_switch_addr = None
tick = 0.1 # time period in seconds at which controllers are handled
+ self.periodic_init(tick)
disconnected_count = 0
cycle = 0
@@ -191,7 +238,7 @@
timeout=0)
if reply is not None:
logging.info(condesc +
- "Features request received from " +
+ "Features reply received from " +
str(con.switch_addr))
con.cstate = 4
con.count = 0
@@ -222,6 +269,7 @@
con.cstate = 0
states.append(con.cstate)
+ self.periodic_tick(con)
logging.debug("Cycle " + str(cycle) +
", states " + str(states) +
@@ -241,6 +289,7 @@
if cycle > self.cxn_cycles:
break
time.sleep(tick)
+ self.periodic_done()
@disabled
class HandshakeAndKeepalive(CompleteHandshake):
@@ -253,6 +302,16 @@
CompleteHandshake.__init__(self, keep_alive=True)
@disabled
+class MonitorPacketIn(CompleteHandshake):
+ """
+ Complete handshake and respond to echo request. As packet-in messages
+ arrive, report the count and pkts/second
+ """
+
+ def __init__(self):
+ CompleteHandshake.__init__(self, keep_alive=True, report_pkts=True)
+
+@disabled
class HandshakeNoEcho(CompleteHandshake):
"""
Complete handshake, but otherwise do nothing, and do not respond to echo.