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