added counters and documentation
diff --git a/tests/FuncUtils.py b/tests/FuncUtils.py
index 5cfcb6a..11ee316 100644
--- a/tests/FuncUtils.py
+++ b/tests/FuncUtils.py
@@ -12,6 +12,7 @@
 import oftest.parse as parse
 import logging
 import types
+
 import oftest.base_tests as base_tests
 from oftest.testutils import *
 from time import sleep
@@ -45,7 +46,35 @@
         self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
 
         return (Pkt_ExactFlow,match)
-        
+
+def Exact_Match_With_Prio(self,of_ports,priority=0):
+    # Generate ExactMatch With Prority flow .
+
+        #Create a simple tcp packet and generate exact flow match from it.
+        Pkt_ExactFlow = simple_tcp_packet()
+        match = parse.packet_to_flow_match(Pkt_ExactFlow)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+        match.in_port = of_ports[0]
+        #match.nw_src = 1
+        match.wildcards=0
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[2]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (Pkt_ExactFlow,match)         
+       
 
 def Match_All_Except_Source_Address(self,of_ports,priority=0):
 # Generate Match_All_Except_Source_Address flow
@@ -74,7 +103,62 @@
         self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
 
         return (Pkt_WildcardSrc,match1)
+
+def Match_Ethernet_Src_Address(self,of_ports,priority=0):
+    #Generate Match_Ethernet_SrC_Address flow
+
+        #Create a simple tcp packet and generate match on ethernet src address flow
+        pkt_MatchSrc = simple_tcp_packet(dl_src='00:01:01:01:01:01')
+        match = parse.packet_to_flow_match(pkt_MatchSrc)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_SRC
         
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchSrc,match)
+      
+def Match_Ethernet_Dst_Address(self,of_ports,priority=0):
+    #Generate Match_Ethernet_Dst_Address flow
+
+        #Create a simple tcp packet and generate match on ethernet dst address flow
+        pkt_MatchDst = simple_tcp_packet(dl_dst='00:01:01:01:01:01')
+        match = parse.packet_to_flow_match(pkt_MatchDst)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_DST
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchDst,match)
+
 def Wildcard_All(self,of_ports,priority=0):
 # Generate a Wildcard_All Flow 
 
@@ -135,7 +219,230 @@
         self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
 
         return (Pkt_MatchIngress,match3)
-    
+
+def Match_Vlan_Id(self,of_ports,priority=0):
+    #Generate Match_Vlan_Id
+
+        #Create a simple tcp packet and generate match on ethernet dst address flow
+        pkt_MatchVlanId = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1)
+        match = parse.packet_to_flow_match(pkt_MatchVlanId)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchVlanId,match)
+
+def Match_Vlan_Pcp(self,of_ports,priority=0):
+    #Generate Match_Vlan_Id
+
+        #Create a simple tcp packet and generate match on ethernet dst address flow
+        pkt_MatchVlanPcp = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=10)
+        match = parse.packet_to_flow_match(pkt_MatchVlanPcp)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_VLAN_PCP 
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchVlanPcp,match)
+
+
+def Match_Mul_L2(self,of_ports,priority=0):
+    #Generate Match_Mul_L2 flow
+
+        #Create a simple eth packet and generate match on ethernet protocol flow
+        pkt_MulL2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02')
+        match = parse.packet_to_flow_match(pkt_MulL2)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE ^ofp.OFPFW_DL_DST ^ofp.OFPFW_DL_SRC
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MulL2,match)
+
+
+def Match_Mul_L4(self,of_ports,priority=0):
+    #Generate Match_Mul_L4 flow
+
+        #Create a simple tcp packet and generate match on tcp protocol flow
+        pkt_MulL4 = simple_tcp_packet(tcp_sport=111,tcp_dport=112)
+        match = parse.packet_to_flow_match(pkt_MulL4)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC ^ofp.OFPFW_TP_DST 
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MulL4,match)  
+
+def Match_Ip_Tos(self,of_ports,priority=0):
+    #Generate a Match on IP Type of service flow
+
+        #Create a simple tcp packet and generate match on Type of service 
+        pkt_IpTos = simple_tcp_packet(ip_tos=3)
+        match = parse.packet_to_flow_match(pkt_IpTos)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_NW_TOS
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_IpTos,match)
+
+def Match_Tcp_Src(self,of_ports,priority=0):
+    #Generate Match_Tcp_Src
+
+        #Create a simple tcp packet and generate match on tcp source port flow
+        pkt_MatchTSrc = simple_tcp_packet(tcp_sport=111)
+        match = parse.packet_to_flow_match(pkt_MatchTSrc)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_SRC  
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchTSrc,match)  
+
+def Match_Tcp_Dst(self,of_ports,priority=0):
+    #Generate Match_Tcp_Dst
+
+        #Create a simple tcp packet and generate match on tcp destination port flow
+        pkt_MatchTDst = simple_tcp_packet(tcp_dport=112)
+        match = parse.packet_to_flow_match(pkt_MatchTDst)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_TP_DST  
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchTDst,match)        
+
+
+
+
+
+def Match_Ethernet_Type(self,of_ports,priority=0):
+    #Generate a Match_Ethernet_Type flow
+
+        #Create a simple tcp packet and generate match on ethernet type flow
+        pkt_MatchType = simple_eth_packet(dl_type=0x88cc)
+        match = parse.packet_to_flow_match(pkt_MatchType)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+
+        match.wildcards = ofp.OFPFW_ALL ^ofp.OFPFW_DL_TYPE
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        if priority != 0 :
+                msg.priority = priority
+
+        act = action.action_output()
+        act.port = of_ports[1]
+        self.assertTrue(msg.actions.add(act), "could not add action")
+
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt_MatchType,match)
+
+   
    
 def Strict_Modify_Flow_Action(self,egress_port,match,priority=0):
 # Strict Modify the flow Action 
@@ -181,10 +488,49 @@
         self.assertTrue(rv != -1, "Error installing flow mod")
         self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
 
+def Enqueue(self,ingress_port,egress_port,egress_queue_id):
+#Generate a flow with enqueue action i.e output to a queue configured on a egress_port
+
+        pkt = simple_tcp_packet()
+        match = packet_to_flow_match(self, pkt)
+        match.wildcards &= ~ofp.OFPFW_IN_PORT
+        self.assertTrue(match is not None, 
+                "Could not generate flow match from pkt")
+
+        match.in_port = ingress_port
+        request = message.flow_mod()
+        request.match = match
+        request.buffer_id = 0xffffffff
+        act = action.action_enqueue()
+        act.port     = egress_port
+        act.queue_id = egress_queue_id
+        self.assertTrue(request.actions.add(act), "Could not add action")
+
+        logging.info("Inserting flow")
+        rv = self.controller.message_send(request)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        return (pkt,match)
+
+
+
 
 ###########################   Verify Stats Functions   ###########################################################################################
 
-def Verify_TableStats(self,active_entries=0,):
+
+def Get_QueueStats(self,port_num,queue_id):
+#Generate Queue Stats request 
+
+    request = message.queue_stats_request()
+    request.port_no  = port_num
+    request.queue_id = queue_id
+    (queue_stats, p) = self.controller.transact(request)
+    self.assertNotEqual(queue_stats, None, "Queue stats request failed")
+
+    return (queue_stats,p)
+
+def Verify_TableStats(self,active_entries=0):
 #Verify Table_Stats
         
         #Send Table_Stats_Request        
@@ -198,32 +544,46 @@
             active_count += stat.active_count
         self.assertTrue(active_entries == active_count,"Incorrect no. of flows in Table")
 
+def Verify_TableStats1(self,current_lookedup,current_matched,expect_lookup,expect_match):
+       
+        stat_req = message.table_stats_request()
+        response, pkt = self.controller.transact(stat_req,
+                                                     timeout=5)
+        self.assertTrue(response is not None, 
+                            "No response to stats request")
+        lookedup = 0
+        matched = 0 
+            
+        for obj in response.stats:
+            lookedup += obj.lookup_count
+            matched += obj.matched_count
+        
+        lookedup_counter = lookedup-current_lookedup
+        matched_counter = matched-current_matched
+        
+        self.assertTrue(lookedup_counter==expect_lookup, "lookup counter is not incremented properly")
+        self.assertTrue(matched_counter==expect_lookup, "matched counter is not incremented properly")
 
 def Verify_FlowStats(self,match,byte_count=0,packet_count=0):
-# Verify flow counters : byte_count and packet_count
+    # Verify flow counters : byte_count and packet_count
 
         stat_req = message.flow_stats_request()
         stat_req.match = match
         stat_req.table_id = 0xff
         stat_req.out_port = ofp.OFPP_NONE
-        test_timeout = 10
-        all_packets_received = 0
-        for i in range(0,test_timeout):
-            
-            response, pkt = self.controller.transact(stat_req,
-                                                     timeout=test_timeout)
-            self.assertTrue(response is not None, 
+        response, pkt = self.controller.transact(stat_req,
+                                                     timeout=4)
+        self.assertTrue(response is not None, 
                             "No response to stats request")
-            for obj in response.stats:
-                if ( obj.packet_count == packet_count and obj.byte_count == byte_count ) :
-                    all_packets_received = 1
+        packetcounter=0
+        bytecounter=0
+        for obj in response.stats:
+            packetcounter += obj.packet_count
+            bytecounter += obj.byte_count
 
-            if all_packets_received:
-                break
-            sleep(1)
+        self.assertTrue(packetcounter==packet_count, "packet counter is not incremented properly")
+        self.assertTrue(bytecounter==byte_count, "byte counter is not incremented properly")
 
-        self.assertTrue(all_packets_received,
-                        "Flow counters are incorrect")
 
 def Verify_PortStats(self,in_port,rx_dropped):
 #Verify Port counters like rx_dropped
@@ -234,7 +594,62 @@
         self.assertTrue(resp is not None,"No response received for port stats request")        
         self.assertTrue(resp.rx_dropped == rx_dropped, "Packets not dropped")
 
+def Verify_PortStats1(self,out_port,current_counter,rx_packets):
+#Verify Port counters like rx_packets
 
+        port_stats_req = message.port_stats_request()
+        port_stats_req.port_no = out_port     
+        response,pkt = self.controller.transact(port_stats_req)
+        self.assertTrue(response is not None,"No response received for port stats request") 
+        rxpackets=0
+       
+        for obj in response.stats:
+            rxpackets += obj.rx_packets
+        rx_packet_counter = rxpackets-current_counter    
+        self.assertEqual(rx_packets,rx_packet_counter,"recieved packet counter is not incremented properly")
+
+def Verify_PortStats2(self,out_port,current_counter,tx_packets):
+#Verify Port counters like tx_packets
+
+        port_stats_req = message.port_stats_request()
+        port_stats_req.port_no = out_port     
+        response,pkt = self.controller.transact(port_stats_req)
+        self.assertTrue(response is not None,"No response received for port stats request") 
+        txpackets=0
+       
+        for obj in response.stats:
+            txpackets += obj.tx_packets
+        tx_packet_counter = txpackets-current_counter    
+        self.assertEqual(tx_packets,tx_packet_counter,"Transmitted packet counter is not incremented properly")    
+
+
+def Verify_PortStats3(self,out_port,current_counter,rx_bytes):
+#Verify Port counters like rx_bytes
+
+        port_stats_req = message.port_stats_request()
+        port_stats_req.port_no = out_port     
+        response,pkt = self.controller.transact(port_stats_req)
+        self.assertTrue(response is not None,"No response received for port stats request") 
+        rxbytes=0
+       
+        for obj in response.stats:
+            rxbytes += obj.rx_bytes
+        rx_byte_counter = rxbytes-current_counter    
+        self.assertEqual(rx_bytes,rx_byte_counter,"Recieved byte counter is not incremented properly")   
+
+def Verify_PortStats4(self,out_port,current_counter,tx_bytes):
+#Verify Port counters like tx_bytes
+
+        port_stats_req = message.port_stats_request()
+        port_stats_req.port_no = out_port     
+        response,pkt = self.controller.transact(port_stats_req)
+        self.assertTrue(response is not None,"No response received for port stats request") 
+        txbytes=0
+       
+        for obj in response.stats:
+            txbytes += obj.tx_bytes
+        tx_byte_counter = txbytes-current_counter    
+        self.assertEqual(tx_bytes,tx_byte_counter,"Transmitted byte counter is not incremented properly")  
 
 ############################## Various delete commands #############################################################################################
 
@@ -307,3 +722,5 @@
         cache_supported_actions = reply.actions
     return cache_supported_actions
 
+##############################################################################################################################################################
+