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