Various updates to basic test set

Simplified names by removing TestCase from them
Added back FlowStats test case
Added FlowMod test case
diff --git a/tests/basic.py b/tests/basic.py
index 00b1670..820a693 100644
--- a/tests/basic.py
+++ b/tests/basic.py
@@ -29,8 +29,14 @@
 import oftest.dataplane as dataplane
 import oftest.action as action
 
+from testutils import *
+
+#@var basic_port_map Local copy of the configuration map from OF port
+# numbers to OS interfaces
 basic_port_map = None
+#@var basic_logger Local logger object
 basic_logger = None
+#@var basic_config Local copy of global configuration data
 basic_config = None
 
 def test_set_init(config):
@@ -50,18 +56,7 @@
     basic_port_map = config["port_map"]
     basic_config = config
 
-# No longer used
-def suite(test_spec):
-    suite = unittest.TestSuite()
-    suite.addTest(SimpleProtocolTestCase())
-    suite.addTest(SimpleDataPlaneTestCase())
-    suite.addTest(EchoTestCase())
-    suite.addTest(EchoWithDataTestCase())
-    suite.addTest(PacketInTestCase())
-    suite.addTest(PacketOutTestCase())
-    return suite
-
-class SimpleProtocolTestCase(unittest.TestCase):
+class SimpleProtocol(unittest.TestCase):
     """
     Root class for setting up the controller
     """
@@ -98,19 +93,19 @@
         self.assertTrue(self.controller.switch_socket is not None,
                         str(self) + 'No connection to switch')
 
-class SimpleDataPlaneTestCase(SimpleProtocolTestCase):
+class SimpleDataPlane(SimpleProtocol):
     """
     Root class that sets up the controller and dataplane
     """
     def setUp(self):
-        SimpleProtocolTestCase.setUp(self)
+        SimpleProtocol.setUp(self)
         self.dataplane = dataplane.DataPlane()
         for of_port, ifname in basic_port_map.items():
             self.dataplane.port_add(ifname, of_port)
 
     def tearDown(self):
         basic_logger.info("Teardown for simple dataplane test")
-        SimpleProtocolTestCase.tearDown(self)
+        SimpleProtocol.tearDown(self)
         self.dataplane.kill(join_threads=self.clean_shutdown)
         basic_logger.info("Teardown done")
 
@@ -120,7 +115,7 @@
         # self.dataplane.show()
         # Would like an assert that checks the data plane
 
-class EchoTestCase(SimpleProtocolTestCase):
+class Echo(SimpleProtocol):
     """
     Test echo response with no data
     """
@@ -133,7 +128,7 @@
                          'response xid != request xid')
         self.assertEqual(len(response.data), 0, 'response data non-empty')
 
-class EchoWithDataTestCase(SimpleProtocolTestCase):
+class EchoWithData(SimpleProtocol):
     """
     Test echo response with short string data
     """
@@ -148,9 +143,12 @@
         self.assertEqual(request.data, response.data,
                          'response data does not match request')
 
-class PacketInTestCase(SimpleDataPlaneTestCase):
+class PacketIn(SimpleDataPlane):
     """
     Test packet in function
+
+    Send a packet to each dataplane port and verify that a packet
+    in message is received from the controller for each
     """
     def runTest(self):
         # Construct packet to send to dataplane
@@ -158,6 +156,9 @@
         # Poll controller with expect message type packet in
         # For now, a random packet from scapy tutorial
 
+        rc = delete_all_flows(self.controller, basic_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
         for of_port in basic_port_map.keys():
             basic_logger.info("PKT IN test, port " + str(of_port))
             pkt = scapy.Ether()/scapy.IP(dst="www.slashdot.org")/scapy.TCP()/\
@@ -167,17 +168,22 @@
             (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
 
             self.assertTrue(response is not None, 
-                            'Packet in message not received')
+                            'Packet in message not received on port ' + 
+                            str(of_port))
             if str(pkt) != response.data:
                 basic_logger.debug("pkt: "+str(pkt)+"  resp: " +
                                    str(response))
 
             self.assertEqual(str(pkt), response.data,
-                             'Response packet does not match send packet')
+                             'Response packet does not match send packet' +
+                             ' for port ' + str(of_port))
 
-class PacketOutTestCase(SimpleDataPlaneTestCase):
+class PacketOut(SimpleDataPlane):
     """
     Test packet out function
+
+    Send packet out message to controller for each dataplane port and
+    verify the packet appears on the appropriate dataplane port
     """
     def runTest(self):
         # Construct packet to send to dataplane
@@ -210,25 +216,37 @@
             self.assertEqual(str(outpkt), str(pkt),
                              'Response packet does not match send packet')
 
-#class StatsGetTestCase(SimpleProtocolTestCase):
-#    """
-#    Get stats 
-#    """
-#    def runTest(self):
-#        request = message.flow_stats_request()
-#        request.out_port = ofp.OFPP_NONE
-#        request.match.wildcards = ofp.OFPFW_ALL
-#        response, pkt = self.controller.transact(request)
-#        response.show()
+class FlowStatsGet(SimpleProtocol):
+    """
+    Get stats 
 
+    Simply verify stats get transaction
+    """
+    def runTest(self):
+        basic_logger.info("Running StatsGet")
+        request = message.flow_stats_request()
+        request.out_port = ofp.OFPP_NONE
+        request.match.wildcards = ofp.OFPFW_ALL
+        response, pkt = self.controller.transact(request, timeout=2)
+        self.assertTrue(response is not None, "Did not get response")
+
+class FlowMod(SimpleProtocol):
+    """
+    Insert a flow
+
+    Simple verification of a flow mod transaction
+    """
+
+    def runTest(self):
+        basic_logger.info("Running " + str(self))
+        request = message.flow_mod()
+        of_ports = basic_port_map.keys()
+        of_ports.sort()
+        request.out_port = of_ports[0]
+        request.match.wildcards = ofp.OFPFW_ALL
+        request.buffer_id = 0xffffffff
+        rv = self.controller.message_send(request)
+        self.assertTrue(rv != -1, "Did not get response")
+    
 if __name__ == "__main__":
     print "Please run through oft script:  ./oft --test_spec=basic"
-
-#@todo Set up direct execution as script
-#if __name__ == "__main__":
-# TODO set up some config struct
-#    test_set_init(config)
-#    unittest.main()
-
-#    suite = unittest.TestLoader().loadTestsFromTestCase(PacketOutTestCase)
-#    unittest.TextTestRunner(verbosity=2).run(suite)