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