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