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