
"""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)
