diff --git a/tests/actions.py b/tests/actions.py
new file mode 100644
index 0000000..49f8b65
--- /dev/null
+++ b/tests/actions.py
@@ -0,0 +1,847 @@
+
+"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
+    Refer Documentation -- Detailed testing methodology 
+    <Some of test-cases are directly taken from oftest> """
+
+"Test Suite 6  ---> Actions "
+
+
+import logging
+
+import unittest
+import random
+
+import oftest.controller as controller
+import oftest.cstruct as ofp
+import oftest.message as message
+import oftest.dataplane as dataplane
+import oftest.action as action
+import oftest.parse as parse
+import basic
+import time
+
+from testutils import *
+from time import sleep
+from FuncUtils import *
+
+ac_port_map = None
+ac_logger = None
+ac_config = None
+of_ports = None
+
+def test_set_init(config):
+    basic.test_set_init(config)
+    
+    global ac_port_map
+    global ac_logger
+    global ac_config
+    global of_ports
+
+    ac_logger = logging.getLogger("Running Actions test-suite")
+    ac_logger.info("Initializing test set")
+    ac_port_map = config["port_map"]
+    ac_config = config
+    
+    of_ports = ac_port_map.keys()
+    of_ports.sort()
+
+   
+
+class NoAction(basic.SimpleDataPlane):
+
+    """NoActionDrop : no action added to flow , drops the packet."""
+
+    def runTest(self):
+        
+        ac_logger.info("Running No_Action test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Install a flow without action")
+        ac_logger.info("Send packets matching that flow")
+        ac_logger.info("Expecting switch to drop all packets")
+
+        # Insert a flow wildcard all without any action 
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        self.assertTrue(match is not None, "Could not generate flow match from pkt")
+        match.wildcards=ofp.OFPFW_ALL
+        match.in_port = of_ports[0]
+        
+        msg = message.flow_mod()
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_ADD
+        msg.buffer_id = 0xffffffff
+        msg.match = match
+        rv = self.controller.message_send(msg)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        
+        #Sending N packets matching the flow inserted
+        for pkt_cnt in range(5):
+            self.dataplane.send(of_ports[0],str(pkt))
+        
+        #Verify packets not recieved on any of the dataplane ports 
+        for any_port in of_ports:
+            (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1, port_number=any_port,exp_pkt=pkt)
+            self.assertTrue(rcv_pkt is None,
+                   "Packet received on port " + str(any_port))
+
+        #Verify packets not sent on control plane either
+        (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1)
+        self.assertTrue(response is None,
+                        'Packets not received on control plane')
+
+
+class Announcement(basic.SimpleDataPlane):
+    
+    """Announcement : Get all supported actions by the switch.
+    Send OFPT_FEATURES_REQUEST to get features supported by sw."""
+
+    def runTest(self):
+
+        ac_logger.info("Running Announcement test")
+
+        ac_logger.info("Sending Features_Request")
+        ac_logger.info("Expecting Features Reply with supported actions")
+
+        # Sending Features_Request
+        request = message.features_request()
+        (reply, pkt) = self.controller.transact(request)
+        self.assertTrue(reply is not None, "Failed to get any reply")
+        self.assertEqual(reply.header.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
+        
+        supported_actions =[]
+        if(reply.actions &1<<ofp.OFPAT_OUTPUT):
+            supported_actions.append('OFPAT_OUTPUT')
+        if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
+            supported_actions.append('OFPAT_SET_VLAN_VID')
+        if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
+            supported_actions.append('OFPAT_SET_VLAN_PCP')
+        if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
+            supported_actions.append('OFPAT_STRIP_VLAN')
+        if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
+            supported_actions.append('OFPAT_SET_DL_SRC')
+        if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
+            supported_actions.append('OFPAT_SET_NW_SRC')
+        if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
+            supported_actions.append('OFPAT_SET_NW_DST')
+        if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
+            supported_actions.append('OFPAT_SET_NW_TOS')
+        if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
+            supported_actions.append('OFPAT_SET_TP_SRC')
+        if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
+            supported_actions.append('OFPAT_SET_TP_DST')
+        if(reply.actions &1<<ofp.OFPAT_VENDOR):
+            supported_actions.append('OFPAT_VENDOR')
+        if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
+            supported_actions.append('OFPAT_ENQUEUE')
+        
+        ac_logger.info(supported_actions)
+        
+
+class ForwardAll(basic.SimpleDataPlane):
+    
+    """ForwardAll : Packet is sent to all dataplane ports
+    except ingress port when output action.port = OFPP_ALL"""
+
+    def runTest(self):
+
+        ac_logger.info("Running Forward_All test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Insert a flow with output action port OFPP_ALL")
+        ac_logger.info("Send packet matching the flow")
+        ac_logger.info("Expecting packet on all dataplane ports except ingress_port")
+        
+        #Create a packet
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        act = action.action_output()
+
+        #Delete all flows 
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        ingress_port=of_ports[0]
+        match.in_port = ingress_port
+
+        #Create a flow mod with action.port = OFPP_ALL
+        request = message.flow_mod()
+        request.match = match
+        request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
+        act.port = ofp.OFPP_ALL
+        request.actions.add(act)
+        
+        ac_logger.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")
+
+        #Send Packet matching the flow
+        ac_logger.info("Sending packet to dp port " + str(ingress_port))
+        self.dataplane.send(ingress_port, str(pkt))
+
+        #Verifying packets recieved on expected dataplane ports
+        yes_ports = set(of_ports).difference([ingress_port])
+        receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
+                      self, ac_logger, ac_config)
+
+
+class ForwardController(basic.SimpleDataPlane):
+    
+    """ForwardController : Packet is sent to controller 
+    output.port = OFPP_CONTROLLER"""
+
+    def runTest(self):
+        
+        ac_logger.info("Running Forward_Controller test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Insert a flow with output action port OFPP_CONTROLLER")
+        ac_logger.info("Send packet matching the flow")
+        ac_logger.info("Expecting packet on the control plane")
+        
+        #Create packet
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        act = action.action_output()
+
+        for ingress_port in of_ports:
+            #Delete all flows 
+            rv = delete_all_flows(self.controller, ac_logger)
+            self.assertEqual(rv, 0, "Failed to delete all flows")
+
+            match.in_port = ingress_port
+            
+            #Create a flow mod message
+            request = message.flow_mod()
+            request.match = match
+            act.port = ofp.OFPP_CONTROLLER
+            request.actions.add(act)
+
+            ac_logger.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")
+            
+            #Send packet matching the flow
+            ac_logger.info("Sending packet to dp port " + str(ingress_port))
+            self.dataplane.send(ingress_port, str(pkt))
+
+            #Verifying packet recieved on the control plane port
+            (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10)
+            self.assertTrue(response is not None,
+                        'Packet in message not received by controller')
+    
+
+
+class ForwardLocal(basic.SimpleDataPlane):
+   
+    """ForwardLocal : Packet is sent to  OFPP_LOCAL port . 
+        TBD : To verify packet recieved in the local networking stack of switch"""
+
+    def runTest(self):
+
+        ac_logger.info("Running Forward_Local test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Insert a flow with output action port OFPP_LOCAL")
+        ac_logger.info("Send packet matching the flow")
+        ac_logger.info("Expecting packet in the local networking stack of switch")
+        
+        #Clear switch state
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        act = action.action_output()
+
+        for ingress_port in of_ports:
+            #Delete the flows
+            rv = delete_all_flows(self.controller, ac_logger)
+            self.assertEqual(rv, 0, "Failed to delete all flows")
+
+            match.in_port = ingress_port
+            #Create flow mod message
+            request = message.flow_mod()
+            request.match = match
+            act.port = ofp.OFPP_LOCAL
+            request.actions.add(act)
+
+            ac_logger.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")
+
+            #Send packet matching the flow
+            ac_logger.info("Sending packet to dp port " + str(ingress_port))
+            self.dataplane.send(ingress_port, str(pkt))
+
+            #TBD: Verification of packets being recieved.
+
+
+class ForwardFlood(basic.SimpleDataPlane):
+    
+    """Forward:Flood : Packet is sent to all dataplane ports
+    except ingress port when output action.port = OFPP_FLOOD 
+    TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
+             not including the incoming interface. """
+    
+    def runTest(self):
+
+        ac_logger.info("Running Forward_Flood test")
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Insert a flow with output action port OFPP_FORWARD")
+        ac_logger.info("Send packet matching the flow")
+        ac_logger.info("Expecting packet on all the ports except the input port")
+        
+        #Create a packet
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        act = action.action_output()
+
+        #Delete all flows 
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        ingress_port=of_ports[0]
+        match.in_port = ingress_port
+
+        #Create a flow mod with action.port = OFPP_ALL
+        request = message.flow_mod()
+        request.match = match
+        request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
+        act.port = ofp.OFPP_FLOOD
+        request.actions.add(act)
+        
+        ac_logger.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")
+
+        #Send Packet matching the flow
+        ac_logger.info("Sending packet to dp port " + str(ingress_port))
+        self.dataplane.send(ingress_port, str(pkt))
+
+        #Verifying packets recieved on expected dataplane ports
+        yes_ports = set(of_ports).difference([ingress_port])
+        receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
+                      self, ac_logger, ac_config)
+
+class ForwardInport(basic.SimpleDataPlane):
+    
+    """ ForwardInPort : Packet sent to virtual port IN_PORT
+    If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
+
+    def runTest(self):
+
+        ac_logger.info("Running Forward_Inport test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Insert a flow with output action port OFPP_INPORT")
+        ac_logger.info("Send packet matching the flow")
+        ac_logger.info("Expecting packet on the input port")
+        
+        #Create a packet
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        act = action.action_output()
+
+        #Delete the flows
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        ingress_port=of_ports[0]
+        match.in_port = ingress_port
+
+        # Create a flow mod message
+        request = message.flow_mod()
+        request.match = match
+        act.port = ofp.OFPP_IN_PORT
+            
+        request.actions.add(act)
+        ac_logger.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")
+
+        #Send packet matching the flow
+        ac_logger.info("Sending packet to dp port " + str(ingress_port))
+        self.dataplane.send(ingress_port, str(pkt))
+        yes_ports = [ingress_port]
+
+        #Verfying packet recieved on expected dataplane ports
+        receive_pkt_check(self.dataplane, pkt, yes_ports,set(of_ports).difference([ingress_port]),
+                            self, ac_logger, ac_config)      
+
+class ForwardTable(basic.SimpleDataPlane):
+   
+    """ForwardTable : Perform actions in flow table. Only for packet-out messages.
+        If the output action.port in the packetout message = OFP.TABLE , then 
+        the packet implements the action specified in the matching flow of the FLOW-TABLE"""
+
+    def runTest(self):
+
+        ac_logger.info("Running Forward_Table test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+        
+        ac_logger.info("Insert a flow F with output action port set to some egress_port")
+        ac_logger.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
+        ac_logger.info("Expecting packet on the egress_port")
+        
+        #Insert a all wildcarded flow
+        (pkt,match) = Wildcard_All(self,of_ports)
+        
+        #Create a packet out message
+        pkt_out =message.packet_out();
+        pkt_out.data = str(pkt)
+        pkt_out.in_port = of_ports[0]
+        act = action.action_output()
+        act.port = ofp.OFPP_TABLE
+        pkt_out.actions.add(act)
+        rv = self.controller.message_send(pkt_out)
+        self.assertTrue(rv == 0, "Error sending out message")
+
+        #Verifying packet out message recieved on the expected dataplane port. 
+        (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
+                                                             exp_pkt=pkt,timeout=3)
+        self.assertTrue(pkt is not None, 'Packet not received')
+
+
+class AddvlanTag(basic.SimpleDataPlane):
+    
+    """AddVlanTag : Adds VLAN Tag to untagged packet."""
+
+    def runTest(self):
+
+        ac_logger.info("Running Add_vlan_tag test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- set vlan id, if not skip the test")
+        ac_logger.info("Insert a flow with set vid action")
+        ac_logger.info("Send packet matching the flow , verify recieved packet has vid set")
+        
+        #Verify set_vlan_id is a supported action
+        sup_acts = sw_supported_actions(self)
+        if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
+           skip_message_emit(self, "Add VLAN tag test skipped")
+           return
+        
+        #Create packet to be sent and an expected packet with vid set
+        new_vid = 2
+        len_wo_vid = 100
+        len_w_vid = 104
+        pkt = simple_tcp_packet(pktlen=len_wo_vid)
+        exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, 
+                                    dl_vlan=new_vid,dl_vlan_pcp=0)
+        vid_act = action.action_set_vlan_vid()
+        vid_act.vlan_vid = new_vid
+
+        #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, 
+                        exp_pkt=exp_pkt, action_list=[vid_act])
+
+class ModifyVlanTag(basic.SimpleDataPlane):
+
+    """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
+    
+    def runTest(self):
+
+        ac_logger.info("Running Modify_Vlan_Tag test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
+        ac_logger.info("Insert a flow with action --set vid ")
+        ac_logger.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
+        
+        #Verify set_vlan_id is a supported action
+        sup_acts = sw_supported_actions(self)
+        if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
+            skip_message_emit(self, "Modify VLAN tag test skipped")
+            return
+
+        #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
+        old_vid = 2
+        new_vid = 3
+        pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid)
+        exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid)
+        vid_act = action.action_set_vlan_vid()
+        vid_act.vlan_vid = new_vid
+        
+        #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
+                        action_list=[vid_act])
+        
+class VlanPrio1(basic.SimpleDataPlane):
+   
+    """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
+    
+    def runTest(self):
+
+        ac_logger.info("Running vlan_Prio_1 test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set vlan priority ")
+        ac_logger.info("Send untagged packet matching the flow , verify recieved packet has specified VLAN priority and has vid set tO 0 ")
+        
+        #Verify set_vlan_priority is a supported action
+        sup_acts = sw_supported_actions(self)
+        if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
+            skip_message_emit(self, "Set VLAN priority test skipped")
+            return
+        
+        #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set. 
+        vlan_id = 0
+        pkt = simple_tcp_packet()
+        exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=0)
+        act = action.action_set_vlan_vid()
+
+        #Insert flow with action -- set vLAN priority, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
+                                action_list=[act])
+
+
+class VlanPrio2(basic.SimpleDataPlane):
+    
+    """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
+    
+    def runTest(self):
+        
+        ac_logger.info("Running Vlan_Prio_2 test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set vlan priority ")
+        ac_logger.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
+        
+        #Verify set_vlan_priority is a supported action
+        sup_acts = sw_supported_actions(self,"true")
+        if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
+            skip_message_emit(self, "modify_vlan_prio test skipped")
+            return
+        
+        #Create a tagged packet , and an expected packet with vlan_priority set to specified value
+        vid          = 123
+        old_vlan_pcp = 2
+        new_vlan_pcp = 3
+        pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp)
+        exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp)
+        vid_act = action.action_set_vlan_pcp()
+        vid_act.vlan_pcp = new_vlan_pcp
+
+        #Insert flow with action -- set vLAN priority, Send tagged packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
+                        action_list=[vid_act])
+
+
+class ModifyL2Src(basic.SimpleDataPlane):
+    
+    """ModifyL2Src :Modify the source MAC address"""
+
+    def runTest(self):
+
+        ac_logger.info("Running Modify_L2_Src test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set etherent src address")
+        ac_logger.info("Send packet matching the flow, verify recieved packet src address rewritten ")
+
+        #Verify set_dl_src is a supported action
+        sup_acts = sw_supported_actions(self,use_cache="true")
+        if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
+            skip_message_emit(self, "modify_l2_src test skipped")
+            return
+
+        #Create packet to be sent and expected packet with dl_src set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set src address, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2)
+
+
+class ModifyL2Dst(basic.SimpleDataPlane):
+    
+    """ModifyL2SDSt :Modify the dest MAC address"""
+
+    def runTest(self):
+
+        ac_logger.info("Running Modify_L2_Dst test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set etherent dst address ")
+        ac_logger.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
+
+        #Verify set_dl_dst is a supported action
+        sup_acts = sw_supported_actions(self)
+        if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
+            skip_message_emit(self, "modify_l2_dst test skipped")
+            return
+
+        #Create packet to be sent and expected packet with dl_src set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set dst address, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2)
+
+class ModifyL3Src(basic.SimpleDataPlane):
+    
+    """ModifyL3Src : Modify the source IP address of an IP packet """
+
+    def runTest(self):
+
+        ac_logger.info("Running Modify_L3_Src test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set network src address ")
+        ac_logger.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
+        
+        #Verify set_nw_src is a supported action
+        sup_acts = sw_supported_actions(self)
+        if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
+            skip_message_emit(self, "modify_l3_src test")
+            return
+
+        #Create packet to be sent and expected packet with nw_src set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set nw src address, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2)
+
+class ModifyL3Dst(basic.SimpleDataPlane):
+    
+    """ModifyL3Dst :Modify the dest IP address of an IP packet"""
+    
+    def runTest(self):
+
+        ac_logger.info("Running Modify_L3_Dst test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set network dst address ")
+        ac_logger.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
+
+        #Verify set_nw_dst is a supported action
+        sup_acts = sw_supported_actions(self,use_cache="true")
+        if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
+            skip_message_emit(self, "modify_l3_dst test skipped")
+            return
+        
+        #Create packet to be sent and expected packet with nw_dst set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set nw dst address, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2)
+
+
+class ModifyL4Src(basic.SimpleDataPlane):
+    
+    """ModifyL4Src : Modify the source TCP port of a TCP packet"""
+    
+    def runTest(self):
+
+        ac_logger.info("Running Modify_L4_Src test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set src tcp port")
+        ac_logger.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
+        
+        #Verify set_tp_src is a supported action
+        sup_acts = sw_supported_actions(self,use_cache="true")
+        if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
+            skip_message_emit(self, "modify_l4_src test skipped")
+            return
+
+        #Create packet to be sent and expected packet with tcp_src set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set tcp src port, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2)
+
+class ModifyL4Dst(basic.SimpleDataPlane):
+    
+    """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
+
+    def runTest(self):
+
+        ac_logger.info("Running Modify_L4_Dst test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set dst tcp port")
+        ac_logger.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
+       
+        #Verify set_tp_dst is a supported action
+        sup_acts = sw_supported_actions(self,use_cache="true")
+        if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
+            skip_message_emit(self, "ModifyL4Dst test")
+            return
+
+        #Create packet to be sent and expected packet with tcp_dst set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set tcp dst port, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2)
+
+class ModifyTos(basic.SimpleDataPlane):
+    
+    """ModifyTOS :Modify the IP type of service of an IP packet"""
+   
+    def runTest(self):
+
+        ac_logger.info("Running Modify_Tos test")
+
+        of_ports = ac_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rv = delete_all_flows(self.controller, ac_logger)
+        self.assertEqual(rv, 0, "Failed to delete all flows")
+
+        ac_logger.info("Verify if switch supports the action -- modify_tos, if not skip the test")
+        ac_logger.info("Insert a flow with action -- set type of service ")
+        ac_logger.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
+       
+        #Verify set_tos is a supported action
+        sup_acts = sw_supported_actions(self,use_cache="true")
+        if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
+            skip_message_emit(self, "ModifyTOS test")
+            return
+
+        #Create packet to be sent and expected packet with TOS set to specified value
+        (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
+                                                check_test_params=True)
+        
+        #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
+        flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt, 
+                        action_list=acts, max_test=2, egr_count=-1)
diff --git a/tests/detailed_contr_sw_messages.py b/tests/detailed_contr_sw_messages.py
new file mode 100644
index 0000000..158f787
--- /dev/null
+++ b/tests/detailed_contr_sw_messages.py
@@ -0,0 +1,837 @@
+"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
+    Refer Documentation -- Detailed testing methodology 
+    <Some of test-cases are directly taken from oftest> """
+
+"Test Suite 3 --> Detailed Controller to switch messages"
+
+import logging
+
+import unittest
+import random
+
+import oftest.controller as controller
+import oftest.cstruct as ofp
+import oftest.message as message
+import oftest.dataplane as dataplane
+import oftest.action as action
+import oftest.parse as parse
+import basic
+
+from testutils import *
+from time import sleep
+from FuncUtils import *
+
+cs_port_map = None
+cs_logger = None
+cs_config = None
+
+def test_set_init(config):
+   
+
+    basic.test_set_init(config)
+
+    global cs_port_map
+    global cs_logger
+    global cs_config
+
+    cs_logger = logging.getLogger("Detailed controller to switch messages")
+    cs_logger.info("Initializing test set")
+    cs_port_map = config["port_map"]
+    cs_config = config
+
+
+class OverlapChecking(basic.SimpleDataPlane):
+    
+    """Verify that if overlap check flag is set in the flow entry and an overlapping flow is inserted then an error 
+        is generated and switch refuses flow entry"""
+    
+    def runTest(self):
+        
+        cs_logger.info("Running Overlap_Checking test")
+       
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear Switch State
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting two overlapping flows")
+        cs_logger.info("Expecting switch to return an error")
+
+        #Insert a flow F with wildcarded all fields
+        (pkt,match) = Wildcard_All(self,of_ports)
+
+        #Verify flow is active  
+        Verify_TableStats(self,active_entries=1)
+        
+        # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set
+        Pkt_MatchIngress = simple_tcp_packet()
+        match3 = parse.packet_to_flow_match(Pkt_MatchIngress)
+        self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
+        match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
+        match3.in_port = of_ports[0]
+
+        msg3 = message.flow_mod()
+        msg3.command = ofp.OFPFC_ADD
+        msg3.match = match3
+        msg3.flags |= ofp.OFPFF_CHECK_OVERLAP
+        msg3.cookie = random.randint(0,9007199254740992)
+        msg3.buffer_id = 0xffffffff
+       
+        act3 = action.action_output()
+        act3.port = of_ports[1]
+        self.assertTrue(msg3.actions.add(act3), "could not add action")
+        rv = self.controller.message_send(msg3)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        # Verify Flow does not get inserted 
+        Verify_TableStats(self,active_entries=1)
+
+        #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
+                                               timeout=5)
+        self.assertTrue(response is not None, 
+                               'Switch did not reply with error message') 
+        self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED, 
+                               'Error message type is not flow mod failed ') 
+        self.assertTrue(response.code==ofp.OFPFMFC_OVERLAP, 
+                               'Error Message code is not overlap')
+
+
+class NoOverlapChecking(basic.SimpleDataPlane):
+
+    """Verify that without overlap check flag set, overlapping flows can be created."""  
+    
+    def runTest(self):
+     
+        cs_logger.info("Running No_Overlap_Checking test")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear Switch State
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting two overlapping flows")
+        cs_logger.info("Expecting switch to insert the flows without generating errors")
+
+        #Build a flow F with wildcarded all fields.
+        (pkt,match) = Wildcard_All(self,of_ports)
+        
+        #Verify flow is active  
+        Verify_TableStats(self,active_entries=1)
+        
+        # Build a overlapping flow F' without check overlap bit set.
+        Wildcard_All_Except_Ingress(self,of_ports)
+
+        # Verify Flow gets inserted 
+        Verify_TableStats(self,active_entries=2)
+
+
+class IdenticalFlows(basic.SimpleDataPlane):
+    
+    """Verify that adding two identical flows overwrites the existing one and clears counters"""
+
+    def runTest(self):
+        
+        cs_logger.info("Running Identical_Flows test ")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting two identical flows one by one")
+        cs_logger.info("Expecting switch to overwrite the first flow and clear the counters associated with it ")
+        
+        # Create and add flow-1, check on dataplane it is active.
+        (pkt,match) = Wildcard_All(self,of_ports)
+
+        # Verify active_entries in table_stats_request =1 
+        Verify_TableStats(self,active_entries=1)
+        
+        # Send Packet (to increment counters like byte_count and packet_count)
+        SendPacket(self,pkt,of_ports[0],of_ports[1])
+
+        # Verify Flow counters have incremented
+        Verify_FlowStats(self,match,byte_count=len(str(pkt)),packet_count=1)
+        
+        #Send Identical flow 
+        (pkt1,match1) = Wildcard_All(self,of_ports)
+
+        # Verify active_entries in table_stats_request =1 
+        Verify_TableStats(self,active_entries=1)
+
+        # Verify Flow counters reset
+        Verify_FlowStats(self,match,byte_count=0,packet_count=0)
+
+   
+class EmerFlowTimeout(basic.SimpleProtocol): 
+
+    """Timeout values are not allowed for emergency flows"""
+
+    def runTest(self):
+
+        cs_logger.info("Running Emergency_Flow_Timeout test")
+        
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting an emergency flow with timeout values")
+        cs_logger.info("Expecting switch to generate error ")
+        
+        #Insert an emergency flow 
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        match.in_port = of_ports[0]
+        
+        request = message.flow_mod()
+        request.match = match
+        request.command = ofp.OFPFC_ADD
+        request.flags = request.flags|ofp.OFPFF_EMERG
+        request.hard_timeout =9
+        request.idle_timeout =9
+        
+        act = action.action_output()
+        act.port = of_ports[1]
+        
+        request.actions.add(act)
+        cs_logger.info("Inserting flow")
+        rv = self.controller.message_send(request)
+        self.assertTrue(rv != -1, "Flow addition did not fail.")
+
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
+                                               timeout=5)
+        self.assertTrue(response is not None, 
+                               'Switch did not reply with error message') 
+        self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED, 
+                               'Error message type is not flow mod failed ') 
+        self.assertTrue(response.code==ofp.OFPFMFC_BAD_EMERG_TIMEOUT, 
+                               'Error Message code is not bad emergency timeout')
+
+
+class MissingModifyAdd(basic.SimpleDataPlane):
+
+    """If a modify does not match an existing flow, the flow gets added """
+    
+    def runTest(self):
+        
+        cs_logger.info("Running Missing_Modify_Add test")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        cs_logger.info("Inserting a flow-modify that does not match an existing flow")
+        cs_logger.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ")
+
+        #Clear Switch State
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        #Generate a flow-mod,command OFPC_MODIFY 
+
+        request = message.flow_mod()
+        request.command = ofp.OFPFC_MODIFY
+        request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
+        request.match.in_port = of_ports[0]
+        request.cookie = random.randint(0,9007199254740992)
+        request.buffer_id = 0xffffffff
+        act3 = action.action_output()
+        act3.port = of_ports[1]
+        self.assertTrue(request.actions.add(act3), "could not add action")
+
+        cs_logger.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") 
+
+        #Verify the flow gets added i.e. active_count= 1
+        Verify_TableStats(self,active_entries=1)
+
+
+class ModifyAction(basic.SimpleDataPlane):
+
+    """A modified flow preserves counters"""
+    
+    def runTest(self):
+        
+        cs_logger.info("Running Modify_Action test ")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting a Flow and incrementing flow counters. Modifying the flow action")
+        cs_logger.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
+           
+        #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A , output to of_port[1]
+        (pkt,match) = Match_All_Except_Source_Address(self,of_ports)
+
+        #Send Packet matching the flow thus incrementing counters like packet_count,byte_count
+        SendPacket(self,pkt,of_ports[0],of_ports[1])
+
+        #Verify flow counters
+        Verify_FlowStats(self,match,byte_count=len(str(pkt)),packet_count=1)
+
+        #Modify flow- 1 
+        Modify_Flow_Action(self,of_ports,match)
+        
+        # Send Packet matching the flow-1 i.e ingress_port=port[0] and verify it is recieved on corret dataplane port i.e port[2]
+        SendPacket(self,pkt,of_ports[0],of_ports[2])
+        
+        #Verify flow counters are preserved
+        Verify_FlowStats(self,match,byte_count=(2*len(str(pkt))),packet_count=2)
+
+
+class StrictModifyAction(basic.SimpleDataPlane):
+
+    """Strict Modify Flow also changes action preserves counters"""
+
+    def runTest(self):
+        
+        cs_logger.info("Running Strict_Modify_Action test")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting Flows and incrementing flow counters. Strict Modify the flow action ")
+        cs_logger.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
+        
+        #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A
+        (pkt,match) = Match_All_Except_Source_Address(self,of_ports,priority=100)
+        
+        #Create and add flow-2 , Match on ingress_port only, Action A
+        (pkt1,match1) = Wildcard_All_Except_Ingress(self,of_ports,priority=10)
+        
+        # Verify both the flows are active
+        Verify_TableStats(self,active_entries=2)
+
+        #Send a packet matching the flows, thus incrementing flow-counters (packet matches the flow F-1 with higher priority)
+        SendPacket(self,pkt,of_ports[0],of_ports[1])
+
+        # Verify flow counters of the flow-1
+        Verify_FlowStats(self,match,byte_count=len(str(pkt)),packet_count=1)
+
+        # Strict-Modify flow- 1 
+        Strict_Modify_Flow_Action(self,of_ports[2],match,priority=100)
+        
+        # Send Packet matching the flow-1 i.e ingress_port=port[0] and verify it is recieved on corret dataplane port i.e port[2]
+        SendPacket(self,pkt,of_ports[0],of_ports[2])
+        
+        # Verify flow counters are preserved
+        Verify_FlowStats(self,match,byte_count=(2*len(str(pkt))),packet_count=2)
+
+
+class DeleteNonexistingFlow(basic.SimpleDataPlane):
+    
+    """Request deletion of non-existing flow"""
+    
+    def runTest(self):
+        
+        cs_logger.info("Delete_NonExisting_Flow test begins")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Deleting a non-existing flow")
+        cs_logger.info("Expecting switch to ignore the command , without generating errors")
+
+        # Issue a delete command 
+        msg = message.flow_mod()
+        msg.match.wildcards = ofp.OFPFW_ALL
+        msg.out_port = ofp.OFPP_NONE
+        msg.command = ofp.OFPFC_DELETE
+        msg.buffer_id = 0xffffffff
+
+        # Verify no message or error is generated by polling the the control plane
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
+                                               timeout=2)
+        self.assertTrue(response is None, 
+                        'Recieved Error for deleting non-exiting flow ')
+
+
+        
+class SendFlowRem(basic.SimpleDataPlane):
+    
+    """Check deletion of flows happens and generates messages as configured.
+    If Send Flow removed message Flag is set in the flow entry, the flow deletion of that respective flow should generate the flow removed message, 
+    vice versa also exists """
+
+    def runTest(self):
+
+        cs_logger.info("Running Send_Flow_Rem test ")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear swicth state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting flows F1 and F2 without and with send_flow_removed_message flag set ")
+        cs_logger.info("Deleting the flows")
+        cs_logger.info("Expecting flow removed message only for F2")
+
+        # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set.
+        (pkt,match) = Wildcard_All_Except_Ingress(self,of_ports)
+
+        # Verify flow is inserted 
+        Verify_TableStats(self,active_entries=1)
+
+        #Delete the flow-1
+        NonStrict_Delete(self,match,priority=0)
+
+        # Verify no flow removed message is generated for the FLOW-1
+
+        (response1, pkt1) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
+                                               timeout=2)
+        self.assertTrue(response1 is None, 
+                        'Received flow removed message for the flow with flow_rem flag not set')
+        
+        # Insert another flow F' with OFPFF_SEND_FLOW_REM flag set.
+        msg9 = message.flow_mod()
+        msg9.match.wildcards = ofp.OFPFW_ALL
+        msg9.cookie = random.randint(0,9007199254740992)
+        msg9.buffer_id = 0xffffffff
+        msg9.idle_timeout = 1
+        msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
+        rv1 = self.controller.message_send(msg9)
+        self.assertTrue(rv1 != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        # Delete the flow-2
+        rc2 = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc2, 0, "Failed to delete all flows")
+
+        # Verify flow removed message is generated for the FLOW-2
+
+        (response2, pkt2) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
+                                               timeout=2)
+        self.assertTrue(response2 is not None, 
+                        'Did not receive flow removed message for this flow')
+
+
+class DeleteEmerFlow(basic.SimpleProtocol):
+
+    """Delete emergency flow and verify no message is generated.An emergency flow deletion will not generate flow-removed messages even if 
+    Send Flow removed message flag was set during the emergency flow entry"""
+
+    def runTest(self):
+
+        cs_logger.info("Running Delete_Emer_Flow")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        
+        #Clear switch state        
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting a emergency flow with send_flow_removed flag set")
+        cs_logger.info("Expecting no flow_removed_message on the deletion of the emergency flow")
+        
+        # Insert a flow with emergency bit set.
+        pkt = simple_tcp_packet()
+        match = parse.packet_to_flow_match(pkt)
+        match.in_port = of_ports[0]
+        request = message.flow_mod()
+        request.match = match
+        request.command = ofp.OFPFC_ADD
+        request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM
+        act = action.action_output()
+        act.port = of_ports[1]
+        request.actions.add(act)
+
+        rv = self.controller.message_send(request)
+        self.assertTrue(rv != -1, "Flow addition failed.")
+        
+        # Delete the emergency flow
+        
+        NonStrict_Delete(self,match)
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM ,
+                                               timeout=2)
+        self.assertTrue(response is None, 
+                        'Test Failed ')
+
+
+class StrictVsNonstrict(basic.SimpleDataPlane):
+
+    """Delete and verify strict and non-strict behaviors
+    This test compares the behavior of delete strict and non-strict"""
+
+    def runTest(self):
+        
+        cs_logger.info("Strict_Vs_Nonstrict test begins")
+        
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+        
+        cs_logger.info("Inserting a flow with exact match")
+        cs_logger.info("Issue Strict Delete command , verify it gets deleted")     
+        
+        #Insert F with an exact Match 
+        (pkt,match) = Exact_Match(self,of_ports)  
+        Verify_TableStats(self,active_entries=1)
+
+        #Issue Strict Delete Command , verify F gets deleted.
+        Strict_Delete(self,match)
+        Verify_TableStats(self,active_entries=0)
+
+        cs_logger.info("Inserting two overlapping flows")
+        cs_logger.info("Issue Strict Delete command ")
+        cs_logger.info("Expecting only one flow gets deleted , because Strict Delete matches on wildcards as well")     
+        
+        #Insert Flow T with match on all , except one wildcarded ( say src adddress ). 
+        (pkt,match) = Match_All_Except_Source_Address(self,of_ports)
+
+        #Insert another flow T' with match on ingress_port , wildcarded rest.  
+        (pkt1,match1) = Wildcard_All_Except_Ingress(self,of_ports)
+        Verify_TableStats(self,active_entries=2)
+
+        #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted
+        Strict_Delete(self,match1)
+        Verify_TableStats(self,active_entries=1) 
+
+        cs_logger.info("Inserting two overlapping flows")
+        cs_logger.info("Issue Non-Strict Delete command ")
+        cs_logger.info("Expecting both the flow gets deleted , because wildcards are active")    
+
+        #Insert T and T' again . 
+        (pkt,match) = Match_All_Except_Source_Address(self,of_ports)
+        (pkt1,match1) = Wildcard_All_Except_Ingress(self,of_ports)
+        Verify_TableStats(self,active_entries=2)
+
+        #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted . 
+        NonStrict_Delete(self,match1)
+        Verify_TableStats(self,active_entries=0)
+
+        cs_logger.info("Inserting three overlapping flows with different priorities")
+        cs_logger.info("Issue Non-Strict Delete command ")
+        cs_logger.info("Expecting all the flows to get deleted")  
+  
+        #Insert T , add Priority P (say 100 ) 
+        (pkt,match) = Match_All_Except_Source_Address(self,of_ports,priority=100)
+
+        #Insert T' add priority (200).
+        (pkt1,match1) = Wildcard_All_Except_Ingress(self,of_ports,priority=200)
+        
+        #Insert T' again add priority 300 --> T" . 
+        (pkt2,match2) = Wildcard_All_Except_Ingress(self,of_ports,priority=300)
+        Verify_TableStats(self,active_entries=3)
+
+        #Issue Non-Strict Delete and verify all getting deleted
+        NonStrict_Delete(self,match1,priority=200)
+        Verify_TableStats(self,active_entries=0)
+
+        cs_logger.info("Inserting three overlapping flows with different priorities")
+        cs_logger.info("Issue Strict Delete command ")
+        cs_logger.info("Expecting only one to get deleted because here priorities & wildcards are being matched")  
+
+        #Issue Strict-Delete and verify only T'' gets deleted. 
+        (pkt,match) = Match_All_Except_Source_Address(self,of_ports,priority=100)
+        (pkt1,match1) = Wildcard_All_Except_Ingress(self,of_ports,priority=200)
+        (pkt2,match2) = Wildcard_All_Except_Ingress(self,of_ports,priority=300)
+        Strict_Delete(self,match1,priority=200)
+        Verify_TableStats(self,active_entries=2)
+
+        
+   
+class Outport1(basic.SimpleDataPlane):
+
+    """Delete flows filtered by action outport.If the out_port field in the delete command contains a value other than OFPP_NONE,
+    it introduces a constraint when matching. This constraint is that the rule must contain an output action directed at that port."""
+
+    def runTest(self):
+        
+        cs_logger.info("Outport1 test begins")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting a flow with output action --> of_port[1]")
+        cs_logger.info("Deleting the flow but with out_port set to of_port[2]")
+        cs_logger.info("Expecting switch to filter the delete command")
+        
+        #Build and send Flow-1 with action output to of_port[1]
+        (pkt,match) = Wildcard_All_Except_Ingress(self,of_ports)
+
+        # Verify active_entries in table_stats_request = 1
+        Verify_TableStats(self,active_entries=1)
+
+        #Send delete command matching the flow-1 but with contraint out_port = of_port[2]
+        msg7 = message.flow_mod()
+        msg7.out_port = of_ports[2]
+        msg7.command = ofp.OFPFC_DELETE
+        msg7.buffer_id = 0xffffffff
+        msg7.match = match
+
+        rv = self.controller.message_send(msg7)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        # Verify flow will not get deleted, active_entries in table_stats_request = 1
+        Verify_TableStats(self,active_entries=1)
+
+        cs_logger.info("Deleting the flow with out_port set to of_port[1]")
+        cs_logger.info("Expecting switch to delete the flow")
+
+        #Send Delete command with contraint out_port = of_ports[1]
+        msg7 = message.flow_mod()
+        msg7.out_port = of_ports[1]
+        msg7.command = ofp.OFPFC_DELETE
+        msg7.buffer_id = 0xffffffff
+        msg7.match = match
+
+        rv = self.controller.message_send(msg7)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+        
+        #Verify flow gets deleted.
+        Verify_TableStats(self,active_entries=0)
+
+
+class IdleTimeout(basic.SimpleDataPlane):
+
+    """ Verify that idle timeout is implemented"""
+
+    def runTest(self):
+        
+        cs_logger.info("Running Idle_Timeout test ")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+        
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set")
+        cs_logger.info("Expecting the flow entry to delete with given idle_timeout")
+
+        #Insert a flow entry with idle_timeout=1.Send_Flow_Rem flag set
+        msg9 = message.flow_mod()
+        msg9.match.wildcards = ofp.OFPFW_ALL
+        msg9.cookie = random.randint(0,9007199254740992)
+        msg9.buffer_id = 0xffffffff
+        msg9.idle_timeout = 1
+        msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
+        rv1 = self.controller.message_send(msg9)
+        self.assertTrue(rv1 != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        #Verify flow gets inserted
+        Verify_TableStats(self,active_entries=1)
+        
+        # Verify flow removed message is recieved.
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
+                                               timeout=5)
+        self.assertTrue(response is not None, 
+                        'Did not receive flow removed message ')
+        self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
+                         'Flow table entry removal reason is not idle_timeout')
+        self.assertEqual(1, response.duration_sec,
+                         'Flow was not alive for 1 sec')
+
+
+class Outport2(basic.SimpleDataPlane):
+
+    """Add, modify flows with outport set. This field is ignored by ADD, MODIFY, and MODIFY STRICT messages."""
+
+    def runTest(self):
+        
+        cs_logger.info("Running Outport2 test ")
+
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Adding and modifying flow with out_port fields set")
+        cs_logger.info("Expecting switch to ignore out_port")
+
+        # Create and add flow-1,Action A ,output to port of_port[1], out_port set to of_ports[2]
+        (pkt,match) = Wildcard_All_Except_Ingress(self,of_ports)
+
+        # Verify flow is active
+        Verify_TableStats(self,active_entries=1)
+        
+        # Send Packet matching the flow
+        SendPacket(self,pkt,of_ports[0],of_ports[1])
+        
+        # Insert Flow-Modify matching flow F-1 ,action A', output to port[2], out_port set to port[3]
+        Modify_Flow_Action(self,of_ports,match)
+
+        # Again verify active_entries in table_stats_request =1 
+        Verify_TableStats(self,active_entries=1)
+
+        #Verify action is modified
+        SendPacket(self,pkt,of_ports[0],of_ports[2])
+
+
+
+
+class HardTimeout(basic.SimpleDataPlane):
+
+    """ Verify that hard timeout is implemented """
+
+    def runTest(self):
+
+        cs_logger.info("Running Hard_Timeout test ")
+        
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting flow entry with hard_timeout set. Also send_flow_removed_message flag set")
+        cs_logger.info("Expecting the flow entry to delete with given hard_timeout")
+
+        # Insert a flow entry with hardtimeout=1 and send_flow_removed flag set
+        msg9 = message.flow_mod()
+        msg9.match.wildcards = ofp.OFPFW_ALL
+        msg9.cookie = random.randint(0,9007199254740992)
+        msg9.buffer_id = 0xffffffff
+        msg9.hard_timeout = 1
+        msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
+        rv1 = self.controller.message_send(msg9)
+        self.assertTrue(rv1 != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        #Verify flow gets inserted
+        Verify_TableStats(self,active_entries=1)
+
+        # Verify flow removed message is recieved.
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
+                                               timeout=5)
+        self.assertTrue(response is not None, 
+                        'Did not receive flow removed message ')
+        self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
+                         'Flow table entry removal reason is not hard_timeout')
+        self.assertEqual(1, response.duration_sec,
+                         'Flow was not alive for 1 sec')
+
+
+class FlowTimeout(basic.SimpleDataPlane):
+  
+    """Verify that Flow removed messages are generated as expected
+    Flow removed messages being generated when flag is set, is already tested in the above tests 
+    So here, we test the vice-versa condition"""
+
+    
+    def runTest(self):
+
+        cs_logger.info("Running Flow_Timeout test ")
+        
+        of_ports = cs_port_map.keys()
+        of_ports.sort()
+        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, cs_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        cs_logger.info("Inserting flow entry with hard_timeout set and send_flow_removed_message flag not set")
+        cs_logger.info("Expecting the flow entry to delete, but no flow removed message")
+
+        # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set
+        pkt = simple_tcp_packet()
+        match3 = parse.packet_to_flow_match(pkt)
+        self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
+        match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
+        match3.in_port = of_ports[0]
+        msg3 = message.flow_mod()
+        msg3.out_port = of_ports[2] # ignored by flow add,flow modify 
+        msg3.command = ofp.OFPFC_ADD
+        msg3.cookie = random.randint(0,9007199254740992)
+        msg3.buffer_id = 0xffffffff
+        msg3.hard_timeout = 1
+        msg3.buffer_id = 0xffffffff
+        msg3.match = match3
+        act3 = action.action_output()
+        act3.port = of_ports[1]
+        self.assertTrue(msg3.actions.add(act3), "could not add action")
+
+        rv = self.controller.message_send(msg3)
+        self.assertTrue(rv != -1, "Error installing flow mod")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        #Verify no flow removed message is generated
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
+                                               timeout=3)
+        self.assertTrue(response is None, 
+                        'Recieved flow removed message ')
+
+        # Verify no entries in the table
+        Verify_TableStats(self,active_entries=0)
+
+
+
+        
+
+
+
+
+       
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/openflow_protocol_messages.py b/tests/openflow_protocol_messages.py
new file mode 100644
index 0000000..2bc934e
--- /dev/null
+++ b/tests/openflow_protocol_messages.py
@@ -0,0 +1,385 @@
+"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
+    Refer Documentation -- Detailed testing methodology 
+    <Some of test-cases are directly taken from oftest> """
+
+"Test Suite 2 --> Openflow Protocol messages"
+
+
+import logging
+
+import unittest
+import random
+
+import oftest.controller as controller
+import oftest.cstruct as ofp
+import oftest.message as message
+import oftest.dataplane as dataplane
+import oftest.action as action
+import oftest.parse as parse
+import basic
+
+from testutils import *
+from time import sleep
+from FuncUtils import *
+
+
+of_port_map = None
+of_logger = None
+of_config = None
+
+def test_set_init(config):
+   
+
+    basic.test_set_init(config)
+
+    global of_port_map
+    global of_logger
+    global of_config
+
+    of_logger = logging.getLogger("Start Openflow_Protocol_Messages Conformance Test-suite")
+    of_logger.info("Initializing test set")
+    of_port_map = config["port_map"]
+    of_config = config
+
+
+class FeaturesRequest(basic.SimpleProtocol): 
+
+    """Verify Features_Request-Reply is implemented 
+    a) Send OFPT_FEATURES_REQUEST
+	b) Verify OFPT_FEATURES_REPLY is received without errors"""
+
+    def runTest(self):
+        of_logger.info("Running Features_Request test")
+        
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+        
+        #Clear switch state
+        rc = delete_all_flows(self.controller, of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+        
+        of_logger.info("Sending Features_Request")
+        of_logger.info("Expecting Features_Reply")
+
+        request = message.features_request()
+        rv = self.controller.message_send(request)
+        self.assertTrue(rv != -1, "Not able to send features request.")
+        
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FEATURES_REPLY,
+                                               timeout=2)
+        self.assertTrue(response is not None, 
+                        'Did not receive Features Reply')
+
+
+class ConfigurationRequest(basic.SimpleProtocol):
+    
+    """Check basic Get Config request is implemented
+    a) Send OFPT_GET_CONFIG_REQUEST
+    b) Verify OFPT_GET_CONFIG_REPLY is received without errors"""
+
+    def runTest(self):
+
+        of_logger.info("Running Configuration_Request test ")
+        
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        of_logger.info("Sending OFPT_GET_CONFIG_REQUEST ")
+        of_logger.info("Expecting OFPT_GET_CONFIG_REPLY ")
+
+        request = message.get_config_request()
+        rv = self.controller.message_send(request)
+        self.assertTrue(rv != -1, " Not able to send get_config request.")
+        
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_GET_CONFIG_REPLY,
+                                               timeout=2)
+        self.assertTrue(response is not None, 
+                        'Did not receive OFPT_GET_CONFIG_REPLY')
+
+class ModifyStateAdd(basic.SimpleProtocol):
+    
+    """Check basic Flow Add request is implemented
+    a) Send  OFPT_FLOW_MOD , command = OFPFC_ADD 
+    c) Send ofp_table_stats request , verify active_count=1 in reply"""
+
+    def runTest(self):
+
+        of_logger.info("Running Modify_State_Add test")
+
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+        
+        #Clear switch state
+        rc = delete_all_flows(self.controller,of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        of_logger.info("Inserting a flow entry")
+        of_logger.info("Expecting active_count=1 in table_stats_reply")
+
+        #Insert a flow entry matching on ingress_port
+        (Pkt,match) = Wildcard_All_Except_Ingress(self,of_ports)
+
+        # Send Table_Stats_Request and verify flow gets inserted.
+        Verify_TableStats(self,active_entries=1)
+
+
+class ModifyStateDelete(basic.SimpleProtocol):
+    
+    """Check Basic Flow Delete request is implemented
+    a) Send OFPT_FLOW_MOD, command = OFPFC_ADD
+    b) Send ofp_table_stats request , verify active_count=1 in reply
+    c) Send OFPT_FLOW_MOD, command = OFPFC_DELETE
+    c) Send ofp_table_stats request , verify active_count=0 in reply"""
+
+    def runTest(self):
+
+        of_logger.info("Running Modify_State_Delete test")
+
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller,of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        of_logger.info("Inserting a flow entry and then deleting it")
+        of_logger.info("Expecting the active_count=0 in table_stats_reply")
+
+        #Insert a flow matching on ingress_port 
+        (Pkt,match) = Wildcard_All_Except_Ingress(self,of_ports)
+
+        #Verify Flow inserted.
+        Verify_TableStats(self,active_entries=1)
+
+        #Delete the flow 
+        NonStrict_Delete(self,match)
+
+        # Send Table_Stats_Request and verify flow deleted.
+        Verify_TableStats(self,active_entries=0)
+
+      
+
+class ModifyStateModify(basic.SimpleDataPlane):
+    
+    """Verify basic Flow Modify request is implemented
+    a) Send OFPT_FLOW_MOD, command = OFPFC_ADD, Action A 
+    b) Send OFPT_FLOW_MOD, command = OFPFC_MODIFY , with output action A'
+    c) Send a packet matching the flow, verify packet implements action A' """
+
+    def runTest(self):
+
+        of_logger.info("Running Modify_State_Modify test")
+
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        of_logger.info("Inserting a flow entry and then modifying it")
+        of_logger.info("Expecting the Test Packet to implement the modified action")
+
+        # Insert a flow matching on ingress_port with action A (output to of_port[1])    
+        (pkt,match) = Wildcard_All_Except_Ingress(self,of_ports)
+  
+        # Modify the flow action (output to of_port[2])
+        Modify_Flow_Action(self,of_ports,match)
+        
+        # Send the Test Packet and verify action implemented is A' (output to of_port[2])
+        SendPacket(self, pkt, of_ports[0],of_ports[2])
+                       
+
+class ReadState(basic.SimpleProtocol):
+    
+    """Test that a basic Read state request (like flow_stats_get request) does not generate an error
+    a) Send OFPT_FLOW_MOD, command = OFPFC_ADD
+    b) Send ofp_flow_stats request
+    b) Verify switch replies without errors"""
+
+    def runTest(self):
+
+        of_logger.info("Running Read_State test")
+
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+
+        #Clear switch state
+        rc = delete_all_flows(self.controller, of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        of_logger.info("Inserting a flow entry and then sending flow_stats request")
+        of_logger.info("Expecting the a flow_stats_reply without errors")
+
+        # Insert a flow with match on ingress_port
+        (pkt,match ) = Wildcard_All_Except_Ingress(self,of_ports)
+        
+        #Verify Flow_Stats request does not generate errors
+        Verify_FlowStats(self,match)
+        
+class SendPacket(basic.SimpleDataPlane):
+    
+    """Test packet out function
+    a) Send packet out message for each dataplane port.
+    b) Verify the packet appears on the appropriate dataplane port"""
+    
+    def runTest(self):
+
+        of_logger.info("Running Send_Packet test")
+
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+       
+        #Clear Switch state
+        rc = delete_all_flows(self.controller, of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+
+        of_logger.info("Sending a packet-out for each dataplane port")
+        of_logger.info("Expecting the packet on appropriate dataplane port")
+
+        for dp_port in of_ports:
+            for outpkt, opt in [
+                (simple_tcp_packet(), "simple TCP packet"),
+                (simple_eth_packet(), "simple Ethernet packet"),
+                (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
+            
+                msg = message.packet_out()
+                msg.data = str(outpkt)
+                act = action.action_output()
+                act.port = dp_port
+                self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
+
+                of_logger.info("PacketOut to: " + str(dp_port))
+                rv = self.controller.message_send(msg)
+                self.assertTrue(rv == 0, "Error sending out message")
+
+                exp_pkt_arg = None
+                exp_port = None
+                if of_config["relax"]:
+                    exp_pkt_arg = outpkt
+                    exp_port = dp_port
+                (of_port, pkt, pkt_time) = self.dataplane.poll(timeout=2, 
+                                                                port_number=exp_port,
+                                                                exp_pkt=exp_pkt_arg)
+                
+                self.assertTrue(pkt is not None, 'Packet not received')
+                of_logger.info("PacketOut: got pkt from " + str(of_port))
+                if of_port is not None:
+                    self.assertEqual(of_port, dp_port, "Unexpected receive port")
+                if not dataplane.match_exp_pkt(outpkt, pkt):
+                    of_logger.debug("Sent %s" % format_packet(outpkt))
+                    of_logger.debug("Resp %s" % format_packet(
+                            str(pkt)[:len(str(outpkt))]))
+                self.assertEqual(str(outpkt), str(pkt)[:len(str(outpkt))],
+                                    'Response packet does not match send packet')
+
+        
+class PacketIn(basic.SimpleDataPlane):
+    
+    """Test basic packet_in function
+    a) Send a simple tcp packet to a dataplane port, without any flow-entry 
+    b) Verify that a packet_in event is sent to the controller"""
+    
+    def runTest(self):
+        
+        of_logger.info("Running Packet_In test")
+
+        of_ports = of_port_map.keys()
+        of_ports.sort()
+        ingress_port = of_ports[0]
+
+        #Clear Switch state
+        rc = delete_all_flows(self.controller, of_logger)
+        self.assertEqual(rc, 0, "Failed to delete all flows")
+        self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+        of_logger.info("Sending a Simple tcp packet a dataplane port")
+        of_logger.info("Expecting a packet_in event on the control plane")
+
+        # Send  packet on dataplane port and verify packet_in event gets generated.
+        pkt = simple_tcp_packet()
+        self.dataplane.send(ingress_port, str(pkt))
+        of_logger.info("Sending packet to dp port " + str(ingress_port) +
+                   ", expecting packet_in on control plane" )
+      
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_PACKET_IN,
+                                               timeout=2)
+        self.assertTrue(response is not None, 
+                               'Packet in event is not sent to the controller') 
+
+
+class Hello(basic.SimpleDataPlane):
+    
+    """Test Hello messages are implemented
+    a) Create Hello messages from controller
+    b) Verify switch also exchanges hello message -- (Poll the control plane)
+    d) Verify the version field in the hello messages is openflow 1.0.0 """
+
+    def runTest(self):
+        
+        of_logger.info("Running Hello test")
+
+        of_logger.info("Sending Hello")
+        of_logger.info("Expecting a Hello on the control plane with version--1.0.0")
+        
+        #Send Hello message
+        request = message.hello()
+        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
+                                               timeout=1)
+        self.assertTrue(response is not None, 
+                               'Switch did not exchange hello message in return') 
+        self.assertTrue(response.header.version == 0x01, 'switch openflow-version field is not 1.0.0')
+
+
+
+class EchoWithoutBody(basic.SimpleProtocol):
+    
+    """Test basic echo-reply is implemented
+    a)  Send echo-request from the controller side, note echo body is empty here.
+    b)  Verify switch responds back with echo-reply with same xid """
+    
+    def runTest(self):
+
+        of_logger.info("Running Echo_Without_Body test")
+
+        of_logger.info("Sending Echo Request")
+        of_logger.info("Expecting a Echo Reply with version--1.0.0 and same xid")
+
+        # Send echo_request
+        request = message.echo_request()
+        (response, pkt) = self.controller.transact(request)
+        self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,'response is not echo_reply')
+        self.assertEqual(request.header.xid, response.header.xid,
+                         'response xid != request xid')
+        self.assertTrue(response.header.version == 0x01, 'switch openflow-version field is not 1.0.1')
+        self.assertEqual(len(response.data), 0, 'response data non-empty')
+
+
+class BarrierRequestReply(basic.SimpleProtocol):
+
+    """ Check basic Barrier request is implemented
+    a) Send OFPT_BARRIER_REQUEST
+    c) Verify OFPT_BARRIER_REPLY is recieved"""
+    
+    def runTest(self):
+
+        of_logger.info("Running Barrier_Request_Reply test")
+
+        of_logger.info("Sending Barrier Request")
+        of_logger.info("Expecting a Barrier Reply with same xid")
+
+        #Send Barrier Request
+        request = message.barrier_request()
+        (response, pkt) = self.controller.transact(request)
+        self.assertEqual(response.header.type, ofp.OFPT_BARRIER_REPLY,'response is not barrier_reply')
+        self.assertEqual(request.header.xid, response.header.xid,
+                         'response xid != request xid')
+
+
+
+
+
