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 |
Dan Talayco | 3bfc822 | 2013-02-13 18:18:57 -0800 | [diff] [blame^] | 517 | pktlen = 64 if config["minsize"] < 64 else config["minsize"] |
| 518 | pkt = simple_tcp_packet(pktlen=pktlen) |
| 519 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=vlan_pcp, pktlen=pktlen + 4) |
Rich Lane | 123928c | 2012-10-04 21:28:53 -0700 | [diff] [blame] | 520 | act = action.action_set_vlan_pcp() |
| 521 | act.vlan_pcp = vlan_pcp |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 522 | |
| 523 | #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] | 524 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 525 | action_list=[act]) |
| 526 | |
| 527 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 528 | class VlanPrio2(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 529 | |
| 530 | """ModifyVlanPrio : Modify VLAN priority to tagged packet.""" |
| 531 | |
| 532 | def runTest(self): |
| 533 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 534 | logging.info("Running Vlan_Prio_2 test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 535 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 536 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 537 | of_ports.sort() |
| 538 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 539 | |
| 540 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 541 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 542 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 543 | logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test") |
| 544 | logging.info("Insert a flow with action -- set vlan priority ") |
| 545 | 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] | 546 | |
| 547 | #Verify set_vlan_priority is a supported action |
| 548 | sup_acts = sw_supported_actions(self,"true") |
| 549 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 550 | skip_message_emit(self, "modify_vlan_prio test skipped") |
| 551 | return |
| 552 | |
| 553 | #Create a tagged packet , and an expected packet with vlan_priority set to specified value |
| 554 | vid = 123 |
| 555 | old_vlan_pcp = 2 |
| 556 | new_vlan_pcp = 3 |
| 557 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 558 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) |
| 559 | vid_act = action.action_set_vlan_pcp() |
| 560 | vid_act.vlan_pcp = new_vlan_pcp |
| 561 | |
| 562 | #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] | 563 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 564 | action_list=[vid_act]) |
| 565 | |
| 566 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 567 | class ModifyL2Src(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 568 | |
| 569 | """ModifyL2Src :Modify the source MAC address""" |
| 570 | |
| 571 | def runTest(self): |
| 572 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 573 | logging.info("Running Modify_L2_Src test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 574 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 575 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 576 | of_ports.sort() |
| 577 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 578 | |
| 579 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 580 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 581 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 582 | logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test") |
| 583 | logging.info("Insert a flow with action -- set etherent src address") |
| 584 | logging.info("Send packet matching the flow, verify recieved packet src address rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 585 | |
| 586 | #Verify set_dl_src is a supported action |
| 587 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 588 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
| 589 | skip_message_emit(self, "modify_l2_src test skipped") |
| 590 | return |
| 591 | |
| 592 | #Create packet to be sent and expected packet with dl_src set to specified value |
| 593 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 594 | check_test_params=True) |
| 595 | |
| 596 | #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] | 597 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 598 | action_list=acts, max_test=2) |
| 599 | |
| 600 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 601 | class ModifyL2Dst(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 602 | |
| 603 | """ModifyL2SDSt :Modify the dest MAC address""" |
| 604 | |
| 605 | def runTest(self): |
| 606 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 607 | logging.info("Running Modify_L2_Dst test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 608 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 609 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 610 | of_ports.sort() |
| 611 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 612 | |
| 613 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 614 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 615 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 616 | logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test") |
| 617 | logging.info("Insert a flow with action -- set etherent dst address ") |
| 618 | logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 619 | |
| 620 | #Verify set_dl_dst is a supported action |
| 621 | sup_acts = sw_supported_actions(self) |
| 622 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 623 | skip_message_emit(self, "modify_l2_dst test skipped") |
| 624 | return |
| 625 | |
| 626 | #Create packet to be sent and expected packet with dl_src set to specified value |
| 627 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 628 | check_test_params=True) |
| 629 | |
| 630 | #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] | 631 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 632 | action_list=acts, max_test=2) |
| 633 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 634 | class ModifyL3Src(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 635 | |
| 636 | """ModifyL3Src : Modify the source IP address of an IP packet """ |
| 637 | |
| 638 | def runTest(self): |
| 639 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 640 | logging.info("Running Modify_L3_Src test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 641 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 642 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 643 | of_ports.sort() |
| 644 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 645 | |
| 646 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 647 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 648 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 649 | logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test") |
| 650 | logging.info("Insert a flow with action -- set network src address ") |
| 651 | 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] | 652 | |
| 653 | #Verify set_nw_src is a supported action |
| 654 | sup_acts = sw_supported_actions(self) |
| 655 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
| 656 | skip_message_emit(self, "modify_l3_src test") |
| 657 | return |
| 658 | |
| 659 | #Create packet to be sent and expected packet with nw_src set to specified value |
| 660 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 661 | check_test_params=True) |
| 662 | |
| 663 | #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] | 664 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 665 | action_list=acts, max_test=2) |
| 666 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 667 | class ModifyL3Dst(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 668 | |
| 669 | """ModifyL3Dst :Modify the dest IP address of an IP packet""" |
| 670 | |
| 671 | def runTest(self): |
| 672 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 673 | logging.info("Running Modify_L3_Dst test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 674 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 675 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 676 | of_ports.sort() |
| 677 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 678 | |
| 679 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 680 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 681 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 682 | logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test") |
| 683 | logging.info("Insert a flow with action -- set network dst address ") |
| 684 | 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] | 685 | |
| 686 | #Verify set_nw_dst is a supported action |
| 687 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 688 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
| 689 | skip_message_emit(self, "modify_l3_dst test skipped") |
| 690 | return |
| 691 | |
| 692 | #Create packet to be sent and expected packet with nw_dst set to specified value |
| 693 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 694 | check_test_params=True) |
| 695 | |
| 696 | #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] | 697 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 698 | action_list=acts, max_test=2) |
| 699 | |
| 700 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 701 | class ModifyL4Src(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 702 | |
| 703 | """ModifyL4Src : Modify the source TCP port of a TCP packet""" |
| 704 | |
| 705 | def runTest(self): |
| 706 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 707 | logging.info("Running Modify_L4_Src test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 708 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 709 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 710 | of_ports.sort() |
| 711 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 712 | |
| 713 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 714 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 715 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 716 | logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test") |
| 717 | logging.info("Insert a flow with action -- set src tcp port") |
| 718 | 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] | 719 | |
| 720 | #Verify set_tp_src is a supported action |
| 721 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 722 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
| 723 | skip_message_emit(self, "modify_l4_src test skipped") |
| 724 | return |
| 725 | |
| 726 | #Create packet to be sent and expected packet with tcp_src set to specified value |
| 727 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 728 | check_test_params=True) |
| 729 | |
| 730 | #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] | 731 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 732 | action_list=acts, max_test=2) |
| 733 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 734 | class ModifyL4Dst(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 735 | |
| 736 | """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """ |
| 737 | |
| 738 | def runTest(self): |
| 739 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 740 | logging.info("Running Modify_L4_Dst test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 741 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 742 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 743 | of_ports.sort() |
| 744 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 745 | |
| 746 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 747 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 748 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 749 | logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test") |
| 750 | logging.info("Insert a flow with action -- set dst tcp port") |
| 751 | 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] | 752 | |
| 753 | #Verify set_tp_dst is a supported action |
| 754 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 755 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
| 756 | skip_message_emit(self, "ModifyL4Dst test") |
| 757 | return |
| 758 | |
| 759 | #Create packet to be sent and expected packet with tcp_dst set to specified value |
| 760 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 761 | check_test_params=True) |
| 762 | |
| 763 | #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] | 764 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 765 | action_list=acts, max_test=2) |
| 766 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 767 | class ModifyTos(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 768 | |
| 769 | """ModifyTOS :Modify the IP type of service of an IP packet""" |
| 770 | |
| 771 | def runTest(self): |
| 772 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 773 | logging.info("Running Modify_Tos test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 774 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 775 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 776 | of_ports.sort() |
| 777 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 778 | |
| 779 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 780 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 781 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 782 | logging.info("Verify if switch supports the action -- modify_tos, if not skip the test") |
| 783 | logging.info("Insert a flow with action -- set type of service ") |
| 784 | logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 785 | |
| 786 | #Verify set_tos is a supported action |
| 787 | sup_acts = sw_supported_actions(self,use_cache="true") |
| 788 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
| 789 | skip_message_emit(self, "ModifyTOS test") |
| 790 | return |
| 791 | |
| 792 | #Create packet to be sent and expected packet with TOS set to specified value |
| 793 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 794 | check_test_params=True) |
| 795 | |
| 796 | #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] | 797 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 798 | action_list=acts, max_test=2, egr_count=-1) |