Merge branch 'master' of github.com:/floodlight/oftest
diff --git a/tests/flow_stats.py b/tests/flow_stats.py
index f7a8ad2..91c67a6 100644
--- a/tests/flow_stats.py
+++ b/tests/flow_stats.py
@@ -20,13 +20,13 @@
 from testutils import *
 from time import sleep
 
-#@var port_map Local copy of the configuration map from OF port
+#@var fs_port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
-pa_port_map = None
-#@var pa_logger Local logger object
-pa_logger = None
-#@var pa_config Local copy of global configuration data
-pa_config = None
+fs_port_map = None
+#@var fs_logger Local logger object
+fs_logger = None
+#@var fs_config Local copy of global configuration data
+fs_config = None
 
 # TODO: ovs has problems with VLAN id?
 WILDCARD_VALUES = [ofp.OFPFW_IN_PORT,
@@ -49,14 +49,14 @@
     @param config The configuration dictionary; see oft
     """
 
-    global pa_port_map
-    global pa_logger
-    global pa_config
+    global fs_port_map
+    global fs_logger
+    global fs_config
 
-    pa_logger = logging.getLogger("pkt_act")
-    pa_logger.info("Initializing test set")
-    pa_port_map = config["port_map"]
-    pa_config = config
+    fs_logger = logging.getLogger("flow_stats")
+    fs_logger.info("Initializing test set")
+    fs_port_map = config["port_map"]
+    fs_config = config
 
 class SingleFlowStats(basic.SimpleDataPlane):
     """
@@ -77,13 +77,13 @@
 
         all_packets_received = 0
         for i in range(0,test_timeout):
-            pa_logger.info("Sending stats request")
-            rv = self.controller.message_send(stat_req)
-            self.assertTrue(rv != -1, "Error sending flow stat req")
-            do_barrier(self.controller)
-
-            (response, raw) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
-            self.assertTrue(len(response.stats) == 1, "Did not receive flow stats reply")
+            fs_logger.info("Sending stats request")
+            response, pkt = self.controller.transact(stat_req,
+                                                     timeout=test_timeout)
+            self.assertTrue(response is not None, 
+                            "No response to stats request")
+            self.assertTrue(len(response.stats) == 1,
+                            "Did not receive flow stats reply")
             for obj in response.stats:
                 # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
                 # for now, just clear them so the assert is simpler
@@ -91,7 +91,7 @@
                 #obj.match.pad2 = [0, 0]
                 #self.assertEqual(match, obj.match,
                 #                 "Matches do not match")
-                pa_logger.info("Received " + str(obj.packet_count) + " packets")
+                fs_logger.info("Received " + str(obj.packet_count) + " packets")
                 if obj.packet_count == packet_count:
                     all_packets_received = 1
 
@@ -103,16 +103,16 @@
                         "Packet count does not match number sent")
 
     def runTest(self):
-        global pa_port_map
+        global fs_port_map
 
         # TODO: set from command-line parameter
         test_timeout = 60
 
-        of_ports = pa_port_map.keys()
+        of_ports = fs_port_map.keys()
         of_ports.sort()
         self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
 
-        rc = delete_all_flows(self.controller, pa_logger)
+        rc = delete_all_flows(self.controller, fs_logger)
         self.assertEqual(rc, 0, "Failed to delete all flows")
 
         # build packet
@@ -126,7 +126,7 @@
         # build flow
         ingress_port = of_ports[0];
         egress_port = of_ports[1];
-        pa_logger.info("Ingress " + str(ingress_port) + 
+        fs_logger.info("Ingress " + str(ingress_port) + 
                        " to egress " + str(egress_port))
         match.in_port = ingress_port
         flow_mod_msg = message.flow_mod()
@@ -139,7 +139,7 @@
         self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
        
         # send flow
-        pa_logger.info("Inserting flow")
+        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)
@@ -149,15 +149,15 @@
 
         # send packet N times
         num_sends = random.randint(10,20)
-        pa_logger.info("Sending " + str(num_sends) + " test packets")
+        fs_logger.info("Sending " + str(num_sends) + " test packets")
         for i in range(0,num_sends):
-            pa_logger.info("Sending packet to dp port " + 
+            fs_logger.info("Sending packet to dp port " + 
                            str(ingress_port))
             self.dataplane.send(ingress_port, str(pkt))
             (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=
                                                                 test_timeout)
             self.assertTrue(rcv_pkt is not None, "Did not receive packet")
-            pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
+            fs_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
                             str(rcv_port))
             self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
             for j in range(0,test_timeout):
@@ -204,19 +204,19 @@
         act.port = egress_port
         self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
 
-        pa_logger.info("Ingress " + str(ingress_port) + 
+        fs_logger.info("Ingress " + str(ingress_port) + 
                        " to egress " + str(egress_port))
 
         return flow_mod_msg
 
     def sendPacket(self, pkt, ingress_port, egress_port, test_timeout):
-        pa_logger.info("Sending packet to dp port " + 
+        fs_logger.info("Sending packet to dp port " + 
                        str(ingress_port))
         self.dataplane.send(ingress_port, str(pkt))
         (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=
                                                             test_timeout)
         self.assertTrue(rcv_pkt is not None, "Did not receive packet")
-        pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
+        fs_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
                         str(rcv_port))
         self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
         for j in range(0,test_timeout):
@@ -234,12 +234,11 @@
 
         all_packets_received = 0
         for i in range(0,test_timeout):
-            pa_logger.info("Sending stats request")
-            rv = self.controller.message_send(stat_req)
-            self.assertTrue(rv != -1, "Error sending flow stat req")
-            do_barrier(self.controller)
-
-            (response, raw) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
+            fs_logger.info("Sending stats request")
+            response, pkt = self.controller.transact(stat_req,
+                                                     timeout=test_timeout)
+            self.assertTrue(response is not None,
+                            "No response to stats request")
             self.assertTrue(len(response.stats) >= 1,
                             "Did not receive flow stats reply")
             total_packets = 0
@@ -250,7 +249,7 @@
                 #obj.match.pad2 = [0, 0]
                 #self.assertEqual(match, obj.match,
                 #                 "Matches do not match")
-                pa_logger.info("Received " + str(obj.packet_count) + " packets")
+                fs_logger.info("Received " + str(obj.packet_count) + " packets")
                 total_packets += obj.packet_count
             if total_packets == packet_count:
                 all_packets_received = 1
@@ -261,19 +260,19 @@
                         "Packet count does not match number sent")
 
     def runTest(self):
-        global pa_port_map
+        global fs_port_map
 
         # TODO: set from command-line parameter
         test_timeout = 60
 
-        of_ports = pa_port_map.keys()
+        of_ports = fs_port_map.keys()
         of_ports.sort()
         self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
         ingress_port = of_ports[0];
         egress_port1 = of_ports[1];
         egress_port2 = of_ports[2];
 
-        rc = delete_all_flows(self.controller, pa_logger)
+        rc = delete_all_flows(self.controller, fs_logger)
         self.assertEqual(rc, 0, "Failed to delete all flows")
 
         pkt1 = simple_tcp_packet()
@@ -282,18 +281,18 @@
         pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
         flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
        
-        pa_logger.info("Inserting flow1")
+        fs_logger.info("Inserting flow1")
         rv = self.controller.message_send(flow_mod_msg1)
         self.assertTrue(rv != -1, "Error installing flow mod")
-        pa_logger.info("Inserting flow2")
+        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)
 
         num_pkt1s = random.randint(10,30)
-        pa_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
+        fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
         num_pkt2s = random.randint(10,30)
-        pa_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
+        fs_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
         for i in range(0,num_pkt1s):
             self.sendPacket(pkt1, ingress_port, egress_port1, test_timeout)
         for i in range(0,num_pkt2s):
@@ -337,19 +336,19 @@
         act.port = egress_port
         self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
 
-        pa_logger.info("Ingress " + str(ingress_port) + 
+        fs_logger.info("Ingress " + str(ingress_port) + 
                        " to egress " + str(egress_port))
 
         return flow_mod_msg
 
     def sendPacket(self, pkt, ingress_port, egress_port, test_timeout):
-        pa_logger.info("Sending packet to dp port " + 
+        fs_logger.info("Sending packet to dp port " + 
                        str(ingress_port))
         self.dataplane.send(ingress_port, str(pkt))
         (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=
                                                             test_timeout)
         self.assertTrue(rcv_pkt is not None, "Did not receive packet")
-        pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
+        fs_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
                         str(rcv_port))
         self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
         for j in range(0,test_timeout):
@@ -368,19 +367,18 @@
 
         all_packets_received = 0
         for i in range(0,test_timeout):
-            pa_logger.info("Sending stats request")
-            rv = self.controller.message_send(stat_req)
-            self.assertTrue(rv != -1, "Error sending flow stat req")
-            do_barrier(self.controller)
-
-            (response, raw) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
+            fs_logger.info("Sending stats request")
+            response, pkt = self.controller.transact(stat_req,
+                                                     timeout=test_timeout)
+            self.assertTrue(response is not None, 
+                            "No response to stats request")
             self.assertTrue(len(response.stats) == 1, 
                             "Did not receive flow stats reply")
             for obj in response.stats:
                 self.assertTrue(obj.flow_count == flow_count,
                                 "Flow count " + str(obj.flow_count) +
                                 " does not match expected " + str(flow_count))
-                pa_logger.info("Received " + str(obj.packet_count) + " packets")
+                fs_logger.info("Received " + str(obj.packet_count) + " packets")
                 if obj.packet_count == packet_count:
                     all_packets_received = 1
 
@@ -392,19 +390,19 @@
                         "Packet count does not match number sent")
 
     def runTest(self):
-        global pa_port_map
+        global fs_port_map
 
         # TODO: set from command-line parameter
         test_timeout = 60
 
-        of_ports = pa_port_map.keys()
+        of_ports = fs_port_map.keys()
         of_ports.sort()
         self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
         ingress_port = of_ports[0];
         egress_port1 = of_ports[1];
         egress_port2 = of_ports[2];
 
-        rc = delete_all_flows(self.controller, pa_logger)
+        rc = delete_all_flows(self.controller, fs_logger)
         self.assertEqual(rc, 0, "Failed to delete all flows")
 
         pkt1 = simple_tcp_packet()
@@ -413,18 +411,18 @@
         pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
         flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
        
-        pa_logger.info("Inserting flow1")
+        fs_logger.info("Inserting flow1")
         rv = self.controller.message_send(flow_mod_msg1)
         self.assertTrue(rv != -1, "Error installing flow mod")
-        pa_logger.info("Inserting flow2")
+        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)
 
         num_pkt1s = random.randint(10,30)
-        pa_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
+        fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
         num_pkt2s = random.randint(10,30)
-        pa_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
+        fs_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
         for i in range(0,num_pkt1s):
             self.sendPacket(pkt1, ingress_port, egress_port1, test_timeout)
         for i in range(0,num_pkt2s):