Implement a required_wildcards setting to allow testing switches that
don't support certain match fields; implement l3-l4 for forcing
wildcarding of all L3 and L4 fields; clean up flow_query test a bit
diff --git a/tests/flow_query.py b/tests/flow_query.py
index 7c04928..6044758 100644
--- a/tests/flow_query.py
+++ b/tests/flow_query.py
@@ -723,8 +723,8 @@
         return self
 
     # Randomize flow cfg
-    def rand(self, fi, valid_wildcards, valid_actions, valid_ports, valid_queues):
-        wildcards_force = test_param_get(fq_config, "wildcards_force", 0)
+    def rand(self, fi, wildcards_force, valid_wildcards, valid_actions, valid_ports,
+             valid_queues):
         if wildcards_force != 0:
             fq_logger.info("Wildcards forced:")
             fq_logger.info(wildcards_to_str(wildcards_force))
@@ -1186,7 +1186,7 @@
     def count(self):
         return len(self.dict)
 
-    def rand(self, sw, fi, num_flows):
+    def rand(self, wildcards_force, sw, fi, num_flows):
         self.clear()
         i = 0
         tbl = 0
@@ -1194,6 +1194,7 @@
         while i < num_flows:
             fc = Flow_Cfg()
             fc.rand(fi, \
+                    wildcards_force, \
                     sw.tbl_stats.stats[tbl].wildcards, \
                     sw.sw_features.actions, \
                     sw.valid_ports, \
@@ -1211,27 +1212,6 @@
                 j = 0
 
 
-error_msgs   = []
-removed_msgs = []
-
-def error_handler(self, msg, rawmsg):
-    fq_logger.info("Got an ERROR message, type=%d, code=%d" \
-                    % (msg.type, msg.code) \
-                    )
-    fq_logger.info("Message header:")
-    fq_logger.info(msg.header.show())
-    global error_msgs
-    error_msgs.append(msg)
-    pass
-
-def removed_handler(self, msg, rawmsg):
-    fq_logger.info("Got a REMOVED message")
-    fq_logger.info("Message header:")
-    fq_logger.info(msg.header.show())
-    global removed_msgs
-    removed_msgs.append(msg)
-    pass
-
 class Switch:
     # Members:
     # controller   - switch's test controller
@@ -1251,14 +1231,30 @@
         self.tbl_stats    = None
         self.flow_stats   = None
         self.flow_tbl     = Flow_Tbl()
+        self.error_msgs   = []
+        self.removed_msgs = []
+
+    def error_handler(self, controller, msg, rawmsg):
+        fq_logger.info("Got an ERROR message, type=%d, code=%d" \
+                          % (msg.type, msg.code) \
+                          )
+        fq_logger.info("Message header:")
+        fq_logger.info(msg.header.show())
+        self.error_msgs.append(msg)
+
+    def removed_handler(self, controller, msg, rawmsg):
+        fq_logger.info("Got a REMOVED message")
+        fq_logger.info("Message header:")
+        fq_logger.info(msg.header.show())
+        self.removed_msgs.append(msg)
 
     def controller_set(self, controller):
         self.controller = controller
         # Register error message handler
-        global error_msgs
-        error_msgs = []
-        controller.register(ofp.OFPT_ERROR, error_handler)
-        controller.register(ofp.OFPT_FLOW_REMOVED, removed_handler)
+        self.error_msgs = []
+        self.removed_msgs = []
+        controller.register(ofp.OFPT_ERROR, self.error_handler)
+        controller.register(ofp.OFPT_FLOW_REMOVED, self.removed_handler)
 
     def features_get(self):
         # Get switch features
@@ -1437,9 +1433,8 @@
 
     def errors_verify(self, num_exp, type = 0, code = 0):
         result = True
-        global error_msgs
         fq_logger.info("Expecting %d error messages" % (num_exp))
-        num_got = len(error_msgs)
+        num_got = len(self.error_msgs)
         fq_logger.info("Got %d error messages" % (num_got))
         if num_got != num_exp:
             fq_logger.error("Incorrect number of error messages received")
@@ -1451,7 +1446,7 @@
                             % (type, code) \
                             )
             f = False
-            for e in error_msgs:
+            for e in self.error_msgs:
                 if e.type == type and e.code == code:
                     fq_logger.info("Got it")
                     f = True
@@ -1465,9 +1460,8 @@
 
     def removed_verify(self, num_exp):
         result = True
-        global removed_msgs
         fq_logger.info("Expecting %d removed messages" % (num_exp))
-        num_got = len(removed_msgs)
+        num_got = len(self.removed_msgs)
         fq_logger.info("Got %d removed messages" % (num_got))
         if num_got != num_exp:
             fq_logger.error("Incorrect number of removed messages received")
@@ -1642,7 +1636,7 @@
         # Create a flow table
 
         ft = Flow_Tbl()
-        ft.rand(sw, fi, num_flows)
+        ft.rand(required_wildcards(self), sw, fi, num_flows)
 
         # Send flow table to switch
 
@@ -1735,6 +1729,7 @@
         while True:
             fc = Flow_Cfg()
             fc.rand(fi, \
+                    required_wildcards(self), \
                     sw.tbl_stats.stats[0].wildcards, \
                     sw.sw_features.actions, \
                     sw.valid_ports, \
@@ -1852,7 +1847,7 @@
         # Create a flow table, to switch's capacity
 
         ft = Flow_Tbl()
-        ft.rand(sw, fi, num_flows)
+        ft.rand(required_wildcards(self), sw, fi, num_flows)
 
         # Send flow table to switch
 
@@ -1879,6 +1874,7 @@
         while True:
             fc = Flow_Cfg()
             fc.rand(fi, \
+                    required_wildcards(self), \
                     sw.tbl_stats.stats[0].wildcards, \
                     sw.sw_features.actions, \
                     sw.valid_ports, \
@@ -1973,6 +1969,7 @@
 
         fc = Flow_Cfg()
         fc.rand(fi, \
+                required_wildcards(self), \
                 sw.tbl_stats.stats[0].wildcards, \
                 sw.sw_features.actions, \
                 sw.valid_ports, \
@@ -2093,6 +2090,7 @@
         fc = Flow_Cfg()
         while True:
             fc.rand(fi, \
+                    required_wildcards(self), \
                     sw.tbl_stats.stats[0].wildcards, \
                     sw.sw_features.actions, \
                     sw.valid_ports, \
@@ -2216,6 +2214,7 @@
 
         fc = Flow_Cfg()
         fc.rand(fi, \
+                required_wildcards(self), \
                 sw.tbl_stats.stats[0].wildcards, \
                 sw.sw_features.actions, \
                 sw.valid_ports, \
@@ -2340,7 +2339,7 @@
         # Dream up some flows
 
         ft = Flow_Tbl()
-        ft.rand(sw, fi, num_flows)
+        ft.rand(required_wildcards(self), sw, fi, num_flows)
 
         # Send flow table to switch
 
@@ -2487,6 +2486,7 @@
 
         fc = Flow_Cfg()
         fc.rand(fi, \
+                required_wildcards(self), \
                 sw.tbl_stats.stats[0].wildcards, \
                 sw.sw_features.actions, \
                 sw.valid_ports, \
@@ -2577,6 +2577,7 @@
 
         fc = Flow_Cfg()
         fc.rand(fi, \
+                required_wildcards(self), \
                 sw.tbl_stats.stats[0].wildcards, \
                 sw.sw_features.actions, \
                 sw.valid_ports, \
@@ -2688,6 +2689,7 @@
 
         fc = Flow_Cfg()
         fc.rand(fi, \
+                required_wildcards(self), \
                 sw.tbl_stats.stats[0].wildcards, \
                 sw.sw_features.actions, \
                 sw.valid_ports, \
@@ -2809,7 +2811,7 @@
         # Dream up some flows
 
         ft = Flow_Tbl()
-        ft.rand(sw, fi, num_flows)
+        ft.rand(required_wildcards(self), sw, fi, num_flows)
 
         # Send flow table to switch
 
@@ -2962,6 +2964,7 @@
 
         fc = Flow_Cfg()
         fc.rand(fi, \
+                required_wildcards(self), \
                 sw.tbl_stats.stats[0].wildcards, \
                 sw.sw_features.actions, \
                 sw.valid_ports, \