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