ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 1 | |
| 2 | """These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases). |
| 3 | Refer Documentation -- Detailed testing methodology |
| 4 | <Some of test-cases are directly taken from oftest> """ |
| 5 | |
| 6 | "Test Suite 6 ---> Actions " |
| 7 | |
| 8 | |
| 9 | import logging |
| 10 | |
| 11 | import unittest |
| 12 | import random |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 13 | import time |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 14 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 15 | from oftest import config |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 16 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 17 | import ofp |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 18 | import oftest.dataplane as dataplane |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 19 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 20 | import oftest.base_tests as base_tests |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 21 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 22 | from oftest.testutils import * |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 23 | from time import sleep |
| 24 | from FuncUtils import * |
| 25 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 26 | class NoAction(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 27 | |
| 28 | """NoActionDrop : no action added to flow , drops the packet.""" |
| 29 | |
| 30 | def runTest(self): |
| 31 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 32 | logging.info("Running No_Action test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 33 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 34 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 35 | of_ports.sort() |
| 36 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 37 | |
| 38 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 39 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 40 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 41 | logging.info("Install a flow without action") |
| 42 | logging.info("Send packets matching that flow") |
| 43 | logging.info("Expecting switch to drop all packets") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 44 | |
| 45 | # Insert a flow wildcard all without any action |
| 46 | pkt = simple_tcp_packet() |
| 47 | match = parse.packet_to_flow_match(pkt) |
| 48 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 49 | match.wildcards=ofp.OFPFW_ALL |
| 50 | match.in_port = of_ports[0] |
| 51 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 52 | msg = ofp.message.flow_mod() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 53 | msg.out_port = ofp.OFPP_NONE |
| 54 | msg.command = ofp.OFPFC_ADD |
| 55 | msg.buffer_id = 0xffffffff |
| 56 | msg.match = match |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 57 | self.controller.message_send(msg) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 58 | do_barrier(self.controller) |
ShreyaPandita | b46f852 | 2012-09-28 15:12:15 -0400 | [diff] [blame] | 59 | |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 60 | #Sending N packets matching the flow inserted |
| 61 | for pkt_cnt in range(5): |
| 62 | self.dataplane.send(of_ports[0],str(pkt)) |
| 63 | |
| 64 | #Verify packets not recieved on any of the dataplane ports |
ShreyaPandita | 7b9ec98 | 2012-09-28 14:43:08 -0400 | [diff] [blame] | 65 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1,exp_pkt=pkt) |
| 66 | self.assertTrue(rcv_pkt is None, |
ShreyaPandita | d4a42c6 | 2012-09-28 15:35:27 -0400 | [diff] [blame] | 67 | "Packet received on port " + str(rcv_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 68 | |
| 69 | #Verify packets not sent on control plane either |
| 70 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1) |
| 71 | self.assertTrue(response is None, |
| 72 | 'Packets not received on control plane') |
| 73 | |
| 74 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 75 | class Announcement(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 76 | |
| 77 | """Announcement : Get all supported actions by the switch. |
| 78 | Send OFPT_FEATURES_REQUEST to get features supported by sw.""" |
| 79 | |
| 80 | def runTest(self): |
| 81 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 82 | logging.info("Running Announcement test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 83 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 84 | logging.info("Sending Features_Request") |
| 85 | logging.info("Expecting Features Reply with supported actions") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 86 | |
| 87 | # Sending Features_Request |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 88 | request = ofp.message.features_request() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 89 | (reply, pkt) = self.controller.transact(request) |
| 90 | self.assertTrue(reply is not None, "Failed to get any reply") |
| 91 | self.assertEqual(reply.header.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply') |
| 92 | |
| 93 | supported_actions =[] |
| 94 | if(reply.actions &1<<ofp.OFPAT_OUTPUT): |
| 95 | supported_actions.append('OFPAT_OUTPUT') |
| 96 | if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID): |
| 97 | supported_actions.append('OFPAT_SET_VLAN_VID') |
| 98 | if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP): |
| 99 | supported_actions.append('OFPAT_SET_VLAN_PCP') |
| 100 | if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN): |
| 101 | supported_actions.append('OFPAT_STRIP_VLAN') |
| 102 | if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC): |
| 103 | supported_actions.append('OFPAT_SET_DL_SRC') |
| 104 | if(reply.actions &1<<ofp.OFPAT_SET_DL_DST): |
| 105 | supported_actions.append('OFPAT_SET_NW_SRC') |
| 106 | if(reply.actions &1<<ofp.OFPAT_SET_NW_DST): |
| 107 | supported_actions.append('OFPAT_SET_NW_DST') |
| 108 | if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS): |
| 109 | supported_actions.append('OFPAT_SET_NW_TOS') |
| 110 | if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC): |
| 111 | supported_actions.append('OFPAT_SET_TP_SRC') |
| 112 | if(reply.actions &1<<ofp.OFPAT_SET_TP_DST): |
| 113 | supported_actions.append('OFPAT_SET_TP_DST') |
| 114 | if(reply.actions &1<<ofp.OFPAT_VENDOR): |
| 115 | supported_actions.append('OFPAT_VENDOR') |
| 116 | if(reply.actions &1<<ofp.OFPAT_ENQUEUE): |
| 117 | supported_actions.append('OFPAT_ENQUEUE') |
| 118 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 119 | logging.info(supported_actions) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 120 | |
| 121 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 122 | class ForwardAll(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 123 | |
| 124 | """ForwardAll : Packet is sent to all dataplane ports |
| 125 | except ingress port when output action.port = OFPP_ALL""" |
| 126 | |
| 127 | def runTest(self): |
| 128 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 129 | logging.info("Running Forward_All test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 130 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 131 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 132 | of_ports.sort() |
| 133 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 134 | |
| 135 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 136 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 137 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 138 | logging.info("Insert a flow with output action port OFPP_ALL") |
| 139 | logging.info("Send packet matching the flow") |
| 140 | logging.info("Expecting packet on all dataplane ports except ingress_port") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 141 | |
| 142 | #Create a packet |
| 143 | pkt = simple_tcp_packet() |
| 144 | match = parse.packet_to_flow_match(pkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 145 | act = ofp.action.output() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 146 | |
| 147 | #Delete all flows |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 148 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 149 | ingress_port=of_ports[0] |
| 150 | match.in_port = ingress_port |
| 151 | |
| 152 | #Create a flow mod with action.port = OFPP_ALL |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 153 | request = ofp.message.flow_mod() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 154 | request.match = match |
| 155 | request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT |
| 156 | act.port = ofp.OFPP_ALL |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame^] | 157 | request.actions.append(act) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 158 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 159 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 160 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 161 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 162 | |
| 163 | #Send Packet matching the flow |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 164 | logging.info("Sending packet to dp port " + str(ingress_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 165 | self.dataplane.send(ingress_port, str(pkt)) |
| 166 | |
| 167 | #Verifying packets recieved on expected dataplane ports |
| 168 | yes_ports = set(of_ports).difference([ingress_port]) |
| 169 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 170 | self) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 171 | |
| 172 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 173 | class ForwardController(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 174 | |
| 175 | """ForwardController : Packet is sent to controller |
| 176 | output.port = OFPP_CONTROLLER""" |
| 177 | |
| 178 | def runTest(self): |
| 179 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 180 | logging.info("Running Forward_Controller test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 181 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 182 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 183 | of_ports.sort() |
| 184 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 185 | |
| 186 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 187 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 188 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 189 | logging.info("Insert a flow with output action port OFPP_CONTROLLER") |
| 190 | logging.info("Send packet matching the flow") |
| 191 | logging.info("Expecting packet on the control plane") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 192 | |
| 193 | #Create packet |
| 194 | pkt = simple_tcp_packet() |
| 195 | match = parse.packet_to_flow_match(pkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 196 | act = ofp.action.output() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 197 | |
| 198 | for ingress_port in of_ports: |
| 199 | #Delete all flows |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 200 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 201 | |
| 202 | match.in_port = ingress_port |
| 203 | |
| 204 | #Create a flow mod message |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 205 | request = ofp.message.flow_mod() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 206 | request.match = match |
| 207 | act.port = ofp.OFPP_CONTROLLER |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame^] | 208 | request.actions.append(act) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 209 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 210 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 211 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 212 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 213 | |
| 214 | #Send packet matching the flow |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 215 | logging.info("Sending packet to dp port " + str(ingress_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 216 | self.dataplane.send(ingress_port, str(pkt)) |
| 217 | |
| 218 | #Verifying packet recieved on the control plane port |
| 219 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10) |
| 220 | self.assertTrue(response is not None, |
| 221 | 'Packet in message not received by controller') |
| 222 | |
| 223 | |
| 224 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 225 | class ForwardLocal(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 226 | |
| 227 | """ForwardLocal : Packet is sent to OFPP_LOCAL port . |
| 228 | TBD : To verify packet recieved in the local networking stack of switch""" |
| 229 | |
| 230 | def runTest(self): |
| 231 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 232 | logging.info("Running Forward_Local test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 233 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 234 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 235 | of_ports.sort() |
| 236 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 237 | |
| 238 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 239 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 240 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 241 | logging.info("Insert a flow with output action port OFPP_LOCAL") |
| 242 | logging.info("Send packet matching the flow") |
| 243 | logging.info("Expecting packet in the local networking stack of switch") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 244 | |
| 245 | #Clear switch state |
| 246 | pkt = simple_tcp_packet() |
| 247 | match = parse.packet_to_flow_match(pkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 248 | act = ofp.action.output() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 249 | |
| 250 | for ingress_port in of_ports: |
| 251 | #Delete the flows |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 252 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 253 | |
| 254 | match.in_port = ingress_port |
| 255 | #Create flow mod message |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 256 | request = ofp.message.flow_mod() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 257 | request.match = match |
| 258 | act.port = ofp.OFPP_LOCAL |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame^] | 259 | request.actions.append(act) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 260 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 261 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 262 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 263 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 264 | |
| 265 | #Send packet matching the flow |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 266 | logging.info("Sending packet to dp port " + str(ingress_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 267 | self.dataplane.send(ingress_port, str(pkt)) |
| 268 | |
| 269 | #TBD: Verification of packets being recieved. |
| 270 | |
| 271 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 272 | class ForwardFlood(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 273 | |
| 274 | """Forward:Flood : Packet is sent to all dataplane ports |
| 275 | except ingress port when output action.port = OFPP_FLOOD |
| 276 | TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree, |
| 277 | not including the incoming interface. """ |
| 278 | |
| 279 | def runTest(self): |
| 280 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 281 | logging.info("Running Forward_Flood test") |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 282 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 283 | of_ports.sort() |
| 284 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 285 | |
| 286 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 287 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 288 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 289 | logging.info("Insert a flow with output action port OFPP_FORWARD") |
| 290 | logging.info("Send packet matching the flow") |
| 291 | logging.info("Expecting packet on all the ports except the input port") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 292 | |
| 293 | #Create a packet |
| 294 | pkt = simple_tcp_packet() |
| 295 | match = parse.packet_to_flow_match(pkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 296 | act = ofp.action.output() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 297 | |
| 298 | #Delete all flows |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 299 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 300 | ingress_port=of_ports[0] |
| 301 | match.in_port = ingress_port |
| 302 | |
| 303 | #Create a flow mod with action.port = OFPP_ALL |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 304 | request = ofp.message.flow_mod() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 305 | request.match = match |
| 306 | request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT |
| 307 | act.port = ofp.OFPP_FLOOD |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame^] | 308 | request.actions.append(act) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 309 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 310 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 311 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 312 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 313 | |
| 314 | #Send Packet matching the flow |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 315 | logging.info("Sending packet to dp port " + str(ingress_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 316 | self.dataplane.send(ingress_port, str(pkt)) |
| 317 | |
| 318 | #Verifying packets recieved on expected dataplane ports |
| 319 | yes_ports = set(of_ports).difference([ingress_port]) |
| 320 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 321 | self) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 322 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 323 | class ForwardInport(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 324 | |
| 325 | """ ForwardInPort : Packet sent to virtual port IN_PORT |
| 326 | If the output.port = OFPP.INPORT then the packet is sent to the input port itself""" |
| 327 | |
| 328 | def runTest(self): |
| 329 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 330 | logging.info("Running Forward_Inport test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 331 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 332 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 333 | of_ports.sort() |
| 334 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 335 | |
| 336 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 337 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 338 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 339 | logging.info("Insert a flow with output action port OFPP_INPORT") |
| 340 | logging.info("Send packet matching the flow") |
| 341 | logging.info("Expecting packet on the input port") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 342 | |
| 343 | #Create a packet |
| 344 | pkt = simple_tcp_packet() |
| 345 | match = parse.packet_to_flow_match(pkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 346 | act = ofp.action.output() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 347 | |
| 348 | #Delete the flows |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 349 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 350 | ingress_port=of_ports[0] |
| 351 | match.in_port = ingress_port |
| 352 | |
| 353 | # Create a flow mod message |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 354 | request = ofp.message.flow_mod() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 355 | request.match = match |
| 356 | act.port = ofp.OFPP_IN_PORT |
| 357 | |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame^] | 358 | request.actions.append(act) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 359 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 360 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 361 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 362 | |
| 363 | #Send packet matching the flow |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 364 | logging.info("Sending packet to dp port " + str(ingress_port)) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 365 | self.dataplane.send(ingress_port, str(pkt)) |
| 366 | yes_ports = [ingress_port] |
| 367 | |
| 368 | #Verfying packet recieved on expected dataplane ports |
| 369 | receive_pkt_check(self.dataplane, pkt, yes_ports,set(of_ports).difference([ingress_port]), |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 370 | self) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 371 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 372 | class ForwardTable(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 373 | |
| 374 | """ForwardTable : Perform actions in flow table. Only for packet-out messages. |
| 375 | If the output action.port in the packetout message = OFP.TABLE , then |
| 376 | the packet implements the action specified in the matching flow of the FLOW-TABLE""" |
| 377 | |
| 378 | def runTest(self): |
| 379 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 380 | logging.info("Running Forward_Table test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 381 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 382 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 383 | of_ports.sort() |
| 384 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 385 | |
| 386 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 387 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 388 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 389 | logging.info("Insert a flow F with output action port set to some egress_port") |
| 390 | logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE") |
| 391 | logging.info("Expecting packet on the egress_port") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 392 | |
| 393 | #Insert a all wildcarded flow |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 394 | (pkt,match) = wildcard_all(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 395 | |
| 396 | #Create a packet out message |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 397 | pkt_out =ofp.message.packet_out(); |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 398 | pkt_out.data = str(pkt) |
| 399 | pkt_out.in_port = of_ports[0] |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 400 | act = ofp.action.output() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 401 | act.port = ofp.OFPP_TABLE |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame^] | 402 | pkt_out.actions.append(act) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 403 | self.controller.message_send(pkt_out) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 404 | |
| 405 | #Verifying packet out message recieved on the expected dataplane port. |
| 406 | (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1], |
| 407 | exp_pkt=pkt,timeout=3) |
| 408 | self.assertTrue(pkt is not None, 'Packet not received') |
| 409 | |
| 410 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 411 | class AddVlanTag(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 412 | |
| 413 | """AddVlanTag : Adds VLAN Tag to untagged packet.""" |
| 414 | |
| 415 | def runTest(self): |
| 416 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 417 | logging.info("Running Add_vlan_tag test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 418 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 419 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 420 | of_ports.sort() |
| 421 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 422 | |
| 423 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 424 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 425 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 426 | logging.info("Verify if switch supports the action -- set vlan id, if not skip the test") |
| 427 | logging.info("Insert a flow with set vid action") |
| 428 | logging.info("Send packet matching the flow , verify recieved packet has vid set") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 429 | |
| 430 | #Verify set_vlan_id is a supported action |
| 431 | sup_acts = sw_supported_actions(self) |
| 432 | if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID): |
| 433 | skip_message_emit(self, "Add VLAN tag test skipped") |
| 434 | return |
| 435 | |
| 436 | #Create packet to be sent and an expected packet with vid set |
| 437 | new_vid = 2 |
| 438 | len_wo_vid = 100 |
| 439 | len_w_vid = 104 |
| 440 | pkt = simple_tcp_packet(pktlen=len_wo_vid) |
| 441 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 442 | dl_vlan=new_vid,dl_vlan_pcp=0) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 443 | vid_act = ofp.action.set_vlan_vid() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 444 | vid_act.vlan_vid = new_vid |
| 445 | |
| 446 | #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 447 | flow_match_test(self, config["port_map"], pkt=pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 448 | exp_pkt=exp_pkt, action_list=[vid_act]) |
| 449 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 450 | class ModifyVlanTag(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 451 | |
| 452 | """ModifyVlanTag : Modifies VLAN Tag to tagged packet.""" |
| 453 | |
| 454 | def runTest(self): |
| 455 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 456 | logging.info("Running Modify_Vlan_Tag test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 457 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 458 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 459 | of_ports.sort() |
| 460 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 461 | |
| 462 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 463 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 464 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 465 | logging.info("Verify if switch supports the action -- modify vlan id, if not skip the test") |
| 466 | logging.info("Insert a flow with action --set vid ") |
| 467 | logging.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 468 | |
| 469 | #Verify set_vlan_id is a supported action |
| 470 | sup_acts = sw_supported_actions(self) |
| 471 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
| 472 | skip_message_emit(self, "Modify VLAN tag test skipped") |
| 473 | return |
| 474 | |
| 475 | #Create a tagged packet with old_vid to be sent, and expected packet with new_vid |
| 476 | old_vid = 2 |
| 477 | new_vid = 3 |
| 478 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 479 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 480 | vid_act = ofp.action.set_vlan_vid() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 481 | vid_act.vlan_vid = new_vid |
| 482 | |
| 483 | #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet. |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 484 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 485 | action_list=[vid_act]) |
| 486 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 487 | class VlanPrio1(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 488 | |
| 489 | """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet.""" |
| 490 | |
| 491 | def runTest(self): |
| 492 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 493 | logging.info("Running vlan_Prio_1 test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 494 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 495 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 496 | of_ports.sort() |
| 497 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 498 | |
| 499 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 500 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 501 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 502 | logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test") |
| 503 | logging.info("Insert a flow with action -- set vlan priority ") |
| 504 | logging.info("Send untagged packet matching the flow , verify recieved packet has specified VLAN priority and has vid set tO 0 ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 505 | |
| 506 | #Verify set_vlan_priority is a supported action |
| 507 | sup_acts = sw_supported_actions(self) |
| 508 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 509 | skip_message_emit(self, "Set VLAN priority test skipped") |
| 510 | return |
| 511 | |
| 512 | #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set. |
| 513 | vlan_id = 0 |
Rich Lane | 123928c | 2012-10-04 21:28:53 -0700 | [diff] [blame] | 514 | vlan_pcp = 1 |
Dan Talayco | 3bfc822 | 2013-02-13 18:18:57 -0800 | [diff] [blame] | 515 | pktlen = 64 if config["minsize"] < 64 else config["minsize"] |
| 516 | pkt = simple_tcp_packet(pktlen=pktlen) |
| 517 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=vlan_pcp, pktlen=pktlen + 4) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 518 | act = ofp.action.set_vlan_pcp() |
Rich Lane | 123928c | 2012-10-04 21:28:53 -0700 | [diff] [blame] | 519 | act.vlan_pcp = vlan_pcp |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 520 | |
| 521 | #Insert flow with action -- set vLAN priority, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 522 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 523 | action_list=[act]) |
| 524 | |
| 525 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 526 | class VlanPrio2(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 527 | |
| 528 | """ModifyVlanPrio : Modify VLAN priority to tagged packet.""" |
| 529 | |
| 530 | def runTest(self): |
| 531 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 532 | logging.info("Running Vlan_Prio_2 test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 533 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 534 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 535 | of_ports.sort() |
| 536 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 537 | |
| 538 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 539 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 540 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 541 | logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test") |
| 542 | logging.info("Insert a flow with action -- set vlan priority ") |
| 543 | logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 544 | |
| 545 | #Verify set_vlan_priority is a supported action |
| 546 | sup_acts = sw_supported_actions(self,"true") |
| 547 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 548 | skip_message_emit(self, "modify_vlan_prio test skipped") |
| 549 | return |
| 550 | |
| 551 | #Create a tagged packet , and an expected packet with vlan_priority set to specified value |
| 552 | vid = 123 |
| 553 | old_vlan_pcp = 2 |
| 554 | new_vlan_pcp = 3 |
| 555 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 556 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 557 | vid_act = ofp.action.set_vlan_pcp() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 558 | vid_act.vlan_pcp = new_vlan_pcp |
| 559 | |
| 560 | #Insert flow with action -- set vLAN priority, Send tagged packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 561 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 562 | action_list=[vid_act]) |
| 563 | |
| 564 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 565 | class ModifyL2Src(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 566 | |
| 567 | """ModifyL2Src :Modify the source MAC address""" |
| 568 | |
| 569 | def runTest(self): |
| 570 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 571 | logging.info("Running Modify_L2_Src test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 572 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 573 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 574 | of_ports.sort() |
| 575 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 576 | |
| 577 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 578 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 579 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 580 | logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test") |
| 581 | logging.info("Insert a flow with action -- set etherent src address") |
| 582 | logging.info("Send packet matching the flow, verify recieved packet src address rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 583 | |
| 584 | #Verify set_dl_src is a supported action |
| 585 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 586 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
| 587 | skip_message_emit(self, "modify_l2_src test skipped") |
| 588 | return |
| 589 | |
| 590 | #Create packet to be sent and expected packet with dl_src set to specified value |
| 591 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 592 | check_test_params=True) |
| 593 | |
| 594 | #Insert flow with action -- set src address, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 595 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 596 | action_list=acts, max_test=2) |
| 597 | |
| 598 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 599 | class ModifyL2Dst(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 600 | |
| 601 | """ModifyL2SDSt :Modify the dest MAC address""" |
| 602 | |
| 603 | def runTest(self): |
| 604 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 605 | logging.info("Running Modify_L2_Dst test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 606 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 607 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 608 | of_ports.sort() |
| 609 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 610 | |
| 611 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 612 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 613 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 614 | logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test") |
| 615 | logging.info("Insert a flow with action -- set etherent dst address ") |
| 616 | logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 617 | |
| 618 | #Verify set_dl_dst is a supported action |
| 619 | sup_acts = sw_supported_actions(self) |
| 620 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 621 | skip_message_emit(self, "modify_l2_dst test skipped") |
| 622 | return |
| 623 | |
| 624 | #Create packet to be sent and expected packet with dl_src set to specified value |
| 625 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 626 | check_test_params=True) |
| 627 | |
| 628 | #Insert flow with action -- set dst address, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 629 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 630 | action_list=acts, max_test=2) |
| 631 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 632 | class ModifyL3Src(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 633 | |
| 634 | """ModifyL3Src : Modify the source IP address of an IP packet """ |
| 635 | |
| 636 | def runTest(self): |
| 637 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 638 | logging.info("Running Modify_L3_Src test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 639 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 640 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 641 | of_ports.sort() |
| 642 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 643 | |
| 644 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 645 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 646 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 647 | logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test") |
| 648 | logging.info("Insert a flow with action -- set network src address ") |
| 649 | logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 650 | |
| 651 | #Verify set_nw_src is a supported action |
| 652 | sup_acts = sw_supported_actions(self) |
| 653 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
| 654 | skip_message_emit(self, "modify_l3_src test") |
| 655 | return |
| 656 | |
| 657 | #Create packet to be sent and expected packet with nw_src set to specified value |
| 658 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 659 | check_test_params=True) |
| 660 | |
| 661 | #Insert flow with action -- set nw src address, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 662 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 663 | action_list=acts, max_test=2) |
| 664 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 665 | class ModifyL3Dst(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 666 | |
| 667 | """ModifyL3Dst :Modify the dest IP address of an IP packet""" |
| 668 | |
| 669 | def runTest(self): |
| 670 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 671 | logging.info("Running Modify_L3_Dst test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 672 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 673 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 674 | of_ports.sort() |
| 675 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 676 | |
| 677 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 678 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 679 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 680 | logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test") |
| 681 | logging.info("Insert a flow with action -- set network dst address ") |
| 682 | logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 683 | |
| 684 | #Verify set_nw_dst is a supported action |
| 685 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 686 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
| 687 | skip_message_emit(self, "modify_l3_dst test skipped") |
| 688 | return |
| 689 | |
| 690 | #Create packet to be sent and expected packet with nw_dst set to specified value |
| 691 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 692 | check_test_params=True) |
| 693 | |
| 694 | #Insert flow with action -- set nw dst address, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 695 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 696 | action_list=acts, max_test=2) |
| 697 | |
| 698 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 699 | class ModifyL4Src(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 700 | |
| 701 | """ModifyL4Src : Modify the source TCP port of a TCP packet""" |
| 702 | |
| 703 | def runTest(self): |
| 704 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 705 | logging.info("Running Modify_L4_Src test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 706 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 707 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 708 | of_ports.sort() |
| 709 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 710 | |
| 711 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 712 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 713 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 714 | logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test") |
| 715 | logging.info("Insert a flow with action -- set src tcp port") |
| 716 | logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 717 | |
| 718 | #Verify set_tp_src is a supported action |
| 719 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 720 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
| 721 | skip_message_emit(self, "modify_l4_src test skipped") |
| 722 | return |
| 723 | |
| 724 | #Create packet to be sent and expected packet with tcp_src set to specified value |
| 725 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 726 | check_test_params=True) |
| 727 | |
| 728 | #Insert flow with action -- set tcp src port, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 729 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 730 | action_list=acts, max_test=2) |
| 731 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 732 | class ModifyL4Dst(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 733 | |
| 734 | """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """ |
| 735 | |
| 736 | def runTest(self): |
| 737 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 738 | logging.info("Running Modify_L4_Dst test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 739 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 740 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 741 | of_ports.sort() |
| 742 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 743 | |
| 744 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 745 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 746 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 747 | logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test") |
| 748 | logging.info("Insert a flow with action -- set dst tcp port") |
| 749 | logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 750 | |
| 751 | #Verify set_tp_dst is a supported action |
| 752 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 753 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
| 754 | skip_message_emit(self, "ModifyL4Dst test") |
| 755 | return |
| 756 | |
| 757 | #Create packet to be sent and expected packet with tcp_dst set to specified value |
| 758 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 759 | check_test_params=True) |
| 760 | |
| 761 | #Insert flow with action -- set tcp dst port, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 762 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 763 | action_list=acts, max_test=2) |
| 764 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 765 | class ModifyTos(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 766 | |
| 767 | """ModifyTOS :Modify the IP type of service of an IP packet""" |
| 768 | |
| 769 | def runTest(self): |
| 770 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 771 | logging.info("Running Modify_Tos test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 772 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 773 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 774 | of_ports.sort() |
| 775 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 776 | |
| 777 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 778 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 779 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 780 | logging.info("Verify if switch supports the action -- modify_tos, if not skip the test") |
| 781 | logging.info("Insert a flow with action -- set type of service ") |
| 782 | logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 783 | |
| 784 | #Verify set_tos is a supported action |
| 785 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 786 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
| 787 | skip_message_emit(self, "ModifyTOS test") |
| 788 | return |
| 789 | |
| 790 | #Create packet to be sent and expected packet with TOS set to specified value |
| 791 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 792 | check_test_params=True) |
| 793 | |
| 794 | #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 795 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 796 | action_list=acts, max_test=2, egr_count=-1) |