ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 1 | """These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases). |
| 2 | Refer Documentation -- Detailed testing methodology |
| 3 | <Some of test-cases are directly taken from oftest> """ |
| 4 | |
| 5 | "Test Suite 3 --> Detailed Controller to switch messages" |
| 6 | |
| 7 | import logging |
| 8 | |
| 9 | import unittest |
| 10 | import random |
| 11 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 12 | from oftest import config |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 13 | import oftest.controller as controller |
| 14 | import oftest.cstruct as ofp |
| 15 | import oftest.message as message |
| 16 | import oftest.dataplane as dataplane |
| 17 | import oftest.action as action |
| 18 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 19 | import oftest.base_tests as base_tests |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 20 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 21 | from oftest.testutils import * |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 22 | from time import sleep |
| 23 | from FuncUtils import * |
| 24 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 25 | class OverlapChecking(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 26 | |
| 27 | """Verify that if overlap check flag is set in the flow entry and an overlapping flow is inserted then an error |
| 28 | is generated and switch refuses flow entry""" |
| 29 | |
| 30 | def runTest(self): |
| 31 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 32 | logging.info("Running Overlap_Checking test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 33 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 34 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 35 | of_ports.sort() |
| 36 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 37 | |
| 38 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 39 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 40 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 41 | logging.info("Inserting two overlapping flows") |
| 42 | logging.info("Expecting switch to return an error") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 43 | |
| 44 | #Insert a flow F with wildcarded all fields |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 45 | (pkt,match) = wildcard_all(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 46 | |
| 47 | #Verify flow is active |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 48 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 49 | |
| 50 | # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 51 | pkt_matchingress = simple_tcp_packet() |
| 52 | match3 = parse.packet_to_flow_match(pkt_matchingress) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 53 | self.assertTrue(match3 is not None, "Could not generate flow match from pkt") |
| 54 | match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 55 | match3.in_port = of_ports[0] |
| 56 | |
| 57 | msg3 = message.flow_mod() |
| 58 | msg3.command = ofp.OFPFC_ADD |
| 59 | msg3.match = match3 |
| 60 | msg3.flags |= ofp.OFPFF_CHECK_OVERLAP |
| 61 | msg3.cookie = random.randint(0,9007199254740992) |
| 62 | msg3.buffer_id = 0xffffffff |
| 63 | |
| 64 | act3 = action.action_output() |
| 65 | act3.port = of_ports[1] |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 66 | msg3.actions.add(act3) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 67 | self.controller.message_send(msg3) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 68 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 69 | |
| 70 | # Verify Flow does not get inserted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 71 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 72 | |
| 73 | #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane |
| 74 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, |
| 75 | timeout=5) |
| 76 | self.assertTrue(response is not None, |
| 77 | 'Switch did not reply with error message') |
| 78 | self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED, |
| 79 | 'Error message type is not flow mod failed ') |
| 80 | self.assertTrue(response.code==ofp.OFPFMFC_OVERLAP, |
| 81 | 'Error Message code is not overlap') |
| 82 | |
| 83 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 84 | class NoOverlapChecking(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 85 | |
| 86 | """Verify that without overlap check flag set, overlapping flows can be created.""" |
| 87 | |
| 88 | def runTest(self): |
| 89 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 90 | logging.info("Running No_Overlap_Checking test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 91 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 92 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 93 | of_ports.sort() |
| 94 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 95 | |
| 96 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 97 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 98 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 99 | logging.info("Inserting two overlapping flows") |
| 100 | logging.info("Expecting switch to insert the flows without generating errors") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 101 | |
| 102 | #Build a flow F with wildcarded all fields. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 103 | (pkt,match) = wildcard_all(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 104 | |
| 105 | #Verify flow is active |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 106 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 107 | |
| 108 | # Build a overlapping flow F' without check overlap bit set. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 109 | wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 110 | |
| 111 | # Verify Flow gets inserted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 112 | verify_tablestats(self,expect_active=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 113 | |
| 114 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 115 | class IdenticalFlows(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 116 | |
| 117 | """Verify that adding two identical flows overwrites the existing one and clears counters""" |
| 118 | |
| 119 | def runTest(self): |
| 120 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 121 | logging.info("Running Identical_Flows test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 122 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 123 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 124 | of_ports.sort() |
| 125 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 126 | |
| 127 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 128 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 129 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 130 | logging.info("Inserting two identical flows one by one") |
| 131 | logging.info("Expecting switch to overwrite the first flow and clear the counters associated with it ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 132 | |
| 133 | # Create and add flow-1, check on dataplane it is active. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 134 | (pkt,match) = wildcard_all(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 135 | |
| 136 | # Verify active_entries in table_stats_request =1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 137 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 138 | |
| 139 | # Send Packet (to increment counters like byte_count and packet_count) |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 140 | send_packet(self,pkt,of_ports[0],of_ports[1]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 141 | |
| 142 | # Verify Flow counters have incremented |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 143 | verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 144 | |
| 145 | #Send Identical flow |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 146 | (pkt1,match1) = wildcard_all(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 147 | |
| 148 | # Verify active_entries in table_stats_request =1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 149 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 150 | |
| 151 | # Verify Flow counters reset |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 152 | verify_flowstats(self,match,byte_count=0,packet_count=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 153 | |
| 154 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 155 | class EmerFlowTimeout(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 156 | |
| 157 | """Timeout values are not allowed for emergency flows""" |
| 158 | |
| 159 | def runTest(self): |
| 160 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 161 | logging.info("Running Emergency_Flow_Timeout test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 162 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 163 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 164 | of_ports.sort() |
| 165 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 166 | |
| 167 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 168 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 169 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 170 | logging.info("Inserting an emergency flow with timeout values") |
| 171 | logging.info("Expecting switch to generate error ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 172 | |
| 173 | #Insert an emergency flow |
| 174 | pkt = simple_tcp_packet() |
| 175 | match = parse.packet_to_flow_match(pkt) |
| 176 | match.in_port = of_ports[0] |
| 177 | |
| 178 | request = message.flow_mod() |
| 179 | request.match = match |
| 180 | request.command = ofp.OFPFC_ADD |
| 181 | request.flags = request.flags|ofp.OFPFF_EMERG |
| 182 | request.hard_timeout =9 |
| 183 | request.idle_timeout =9 |
| 184 | |
| 185 | act = action.action_output() |
| 186 | act.port = of_ports[1] |
| 187 | |
| 188 | request.actions.add(act) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 189 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 190 | self.controller.message_send(request) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 191 | |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 192 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 193 | |
| 194 | #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane |
| 195 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, |
| 196 | timeout=5) |
| 197 | self.assertTrue(response is not None, |
| 198 | 'Switch did not reply with error message') |
| 199 | self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED, |
| 200 | 'Error message type is not flow mod failed ') |
| 201 | self.assertTrue(response.code==ofp.OFPFMFC_BAD_EMERG_TIMEOUT, |
| 202 | 'Error Message code is not bad emergency timeout') |
| 203 | |
| 204 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 205 | class MissingModifyAdd(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 206 | |
| 207 | """If a modify does not match an existing flow, the flow gets added """ |
| 208 | |
| 209 | def runTest(self): |
| 210 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 211 | logging.info("Running Missing_Modify_Add test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 212 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 213 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 214 | of_ports.sort() |
| 215 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 216 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 217 | logging.info("Inserting a flow-modify that does not match an existing flow") |
| 218 | logging.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 219 | |
| 220 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 221 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 222 | |
| 223 | #Generate a flow-mod,command OFPC_MODIFY |
| 224 | |
| 225 | request = message.flow_mod() |
| 226 | request.command = ofp.OFPFC_MODIFY |
| 227 | request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 228 | request.match.in_port = of_ports[0] |
| 229 | request.cookie = random.randint(0,9007199254740992) |
| 230 | request.buffer_id = 0xffffffff |
| 231 | act3 = action.action_output() |
| 232 | act3.port = of_ports[1] |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 233 | request.actions.add(act3) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 234 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 235 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 236 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 237 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 238 | |
| 239 | #Verify the flow gets added i.e. active_count= 1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 240 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 241 | |
| 242 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 243 | class ModifyAction(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 244 | |
| 245 | """A modified flow preserves counters""" |
| 246 | |
| 247 | def runTest(self): |
| 248 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 249 | logging.info("Running Modify_Action test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 250 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 251 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 252 | of_ports.sort() |
| 253 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 254 | |
| 255 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 256 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 257 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 258 | logging.info("Inserting a Flow and incrementing flow counters. Modifying the flow action") |
| 259 | logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 260 | |
| 261 | #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A , output to of_port[1] |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 262 | (pkt,match) = match_all_except_source_address(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 263 | |
| 264 | #Send Packet matching the flow thus incrementing counters like packet_count,byte_count |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 265 | send_packet(self,pkt,of_ports[0],of_ports[1]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 266 | |
| 267 | #Verify flow counters |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 268 | verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 269 | |
| 270 | #Modify flow- 1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 271 | modify_flow_action(self,of_ports,match) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 272 | |
| 273 | # Send Packet matching the flow-1 i.e ingress_port=port[0] and verify it is recieved on corret dataplane port i.e port[2] |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 274 | send_packet(self,pkt,of_ports[0],of_ports[2]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 275 | |
| 276 | #Verify flow counters are preserved |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 277 | verify_flowstats(self,match,byte_count=(2*len(str(pkt))),packet_count=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 278 | |
| 279 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 280 | class StrictModifyAction(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 281 | |
| 282 | """Strict Modify Flow also changes action preserves counters""" |
| 283 | |
| 284 | def runTest(self): |
| 285 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 286 | logging.info("Running Strict_Modify_Action test") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 287 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 288 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 289 | of_ports.sort() |
| 290 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 291 | |
| 292 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 293 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 294 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 295 | logging.info("Inserting Flows and incrementing flow counters. Strict Modify the flow action ") |
| 296 | logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 297 | |
| 298 | #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 299 | (pkt,match) = match_all_except_source_address(self,of_ports,priority=100) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 300 | |
| 301 | #Create and add flow-2 , Match on ingress_port only, Action A |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 302 | (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=10) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 303 | |
| 304 | # Verify both the flows are active |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 305 | verify_tablestats(self,expect_active=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 306 | |
| 307 | #Send a packet matching the flows, thus incrementing flow-counters (packet matches the flow F-1 with higher priority) |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 308 | send_packet(self,pkt,of_ports[0],of_ports[1]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 309 | |
| 310 | # Verify flow counters of the flow-1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 311 | verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 312 | |
| 313 | # Strict-Modify flow- 1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 314 | strict_modify_flow_action(self,of_ports[2],match,priority=100) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 315 | |
| 316 | # Send Packet matching the flow-1 i.e ingress_port=port[0] and verify it is recieved on corret dataplane port i.e port[2] |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 317 | send_packet(self,pkt,of_ports[0],of_ports[2]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 318 | |
| 319 | # Verify flow counters are preserved |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 320 | verify_flowstats(self,match,byte_count=(2*len(str(pkt))),packet_count=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 321 | |
| 322 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 323 | class DeleteNonexistingFlow(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 324 | |
| 325 | """Request deletion of non-existing flow""" |
| 326 | |
| 327 | def runTest(self): |
| 328 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 329 | logging.info("Delete_NonExisting_Flow test begins") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 330 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 331 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 332 | of_ports.sort() |
| 333 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 334 | |
| 335 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 336 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 337 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 338 | logging.info("Deleting a non-existing flow") |
| 339 | logging.info("Expecting switch to ignore the command , without generating errors") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 340 | |
| 341 | # Issue a delete command |
| 342 | msg = message.flow_mod() |
| 343 | msg.match.wildcards = ofp.OFPFW_ALL |
| 344 | msg.out_port = ofp.OFPP_NONE |
| 345 | msg.command = ofp.OFPFC_DELETE |
| 346 | msg.buffer_id = 0xffffffff |
| 347 | |
| 348 | # Verify no message or error is generated by polling the the control plane |
| 349 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, |
| 350 | timeout=2) |
| 351 | self.assertTrue(response is None, |
| 352 | 'Recieved Error for deleting non-exiting flow ') |
| 353 | |
| 354 | |
| 355 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 356 | class SendFlowRem(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 357 | |
| 358 | """Check deletion of flows happens and generates messages as configured. |
| 359 | If Send Flow removed message Flag is set in the flow entry, the flow deletion of that respective flow should generate the flow removed message, |
| 360 | vice versa also exists """ |
| 361 | |
| 362 | def runTest(self): |
| 363 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 364 | logging.info("Running Send_Flow_Rem test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 365 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 366 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 367 | of_ports.sort() |
| 368 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 369 | |
| 370 | #Clear swicth state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 371 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 372 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 373 | logging.info("Inserting flows F1 and F2 without and with send_flow_removed_message flag set ") |
| 374 | logging.info("Deleting the flows") |
| 375 | logging.info("Expecting flow removed message only for F2") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 376 | |
| 377 | # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 378 | (pkt,match) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 379 | |
| 380 | # Verify flow is inserted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 381 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 382 | |
| 383 | #Delete the flow-1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 384 | nonstrict_delete(self,match,priority=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 385 | |
| 386 | # Verify no flow removed message is generated for the FLOW-1 |
| 387 | |
| 388 | (response1, pkt1) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, |
| 389 | timeout=2) |
| 390 | self.assertTrue(response1 is None, |
| 391 | 'Received flow removed message for the flow with flow_rem flag not set') |
| 392 | |
| 393 | # Insert another flow F' with OFPFF_SEND_FLOW_REM flag set. |
| 394 | msg9 = message.flow_mod() |
| 395 | msg9.match.wildcards = ofp.OFPFW_ALL |
| 396 | msg9.cookie = random.randint(0,9007199254740992) |
| 397 | msg9.buffer_id = 0xffffffff |
| 398 | msg9.idle_timeout = 1 |
| 399 | msg9.flags |= ofp.OFPFF_SEND_FLOW_REM |
| 400 | rv1 = self.controller.message_send(msg9) |
| 401 | self.assertTrue(rv1 != -1, "Error installing flow mod") |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 402 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 403 | |
| 404 | # Delete the flow-2 |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 405 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 406 | |
| 407 | # Verify flow removed message is generated for the FLOW-2 |
| 408 | |
| 409 | (response2, pkt2) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, |
| 410 | timeout=2) |
| 411 | self.assertTrue(response2 is not None, |
| 412 | 'Did not receive flow removed message for this flow') |
| 413 | |
| 414 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 415 | class DeleteEmerFlow(base_tests.SimpleProtocol): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 416 | |
| 417 | """Delete emergency flow and verify no message is generated.An emergency flow deletion will not generate flow-removed messages even if |
| 418 | Send Flow removed message flag was set during the emergency flow entry""" |
| 419 | |
| 420 | def runTest(self): |
| 421 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 422 | logging.info("Running Delete_Emer_Flow") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 423 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 424 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 425 | of_ports.sort() |
| 426 | |
| 427 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 428 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 429 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 430 | logging.info("Inserting a emergency flow with send_flow_removed flag set") |
| 431 | logging.info("Expecting no flow_removed_message on the deletion of the emergency flow") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 432 | |
| 433 | # Insert a flow with emergency bit set. |
| 434 | pkt = simple_tcp_packet() |
| 435 | match = parse.packet_to_flow_match(pkt) |
| 436 | match.in_port = of_ports[0] |
| 437 | request = message.flow_mod() |
| 438 | request.match = match |
| 439 | request.command = ofp.OFPFC_ADD |
| 440 | request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM |
| 441 | act = action.action_output() |
| 442 | act.port = of_ports[1] |
| 443 | request.actions.add(act) |
| 444 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 445 | self.controller.message_send(request) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 446 | |
| 447 | # Delete the emergency flow |
| 448 | |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 449 | nonstrict_delete(self,match) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 450 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM , |
| 451 | timeout=2) |
| 452 | self.assertTrue(response is None, |
| 453 | 'Test Failed ') |
| 454 | |
| 455 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 456 | class StrictVsNonstrict(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 457 | |
| 458 | """Delete and verify strict and non-strict behaviors |
| 459 | This test compares the behavior of delete strict and non-strict""" |
| 460 | |
| 461 | def runTest(self): |
| 462 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 463 | logging.info("Strict_Vs_Nonstrict test begins") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 464 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 465 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 466 | of_ports.sort() |
| 467 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 468 | |
| 469 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 470 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 471 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 472 | logging.info("Inserting a flow with exact match") |
| 473 | logging.info("Issue Strict Delete command , verify it gets deleted") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 474 | |
| 475 | #Insert F with an exact Match |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 476 | (pkt,match) = exact_match(self,of_ports) |
| 477 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 478 | |
| 479 | #Issue Strict Delete Command , verify F gets deleted. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 480 | strict_delete(self,match) |
| 481 | verify_tablestats(self,expect_active=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 482 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 483 | logging.info("Inserting two overlapping flows") |
| 484 | logging.info("Issue Strict Delete command ") |
| 485 | logging.info("Expecting only one flow gets deleted , because Strict Delete matches on wildcards as well") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 486 | |
| 487 | #Insert Flow T with match on all , except one wildcarded ( say src adddress ). |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 488 | (pkt,match) = match_all_except_source_address(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 489 | |
| 490 | #Insert another flow T' with match on ingress_port , wildcarded rest. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 491 | (pkt1,match1) = wildcard_all_except_ingress(self,of_ports) |
| 492 | verify_tablestats(self,expect_active=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 493 | |
| 494 | #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 495 | strict_delete(self,match1) |
| 496 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 497 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 498 | logging.info("Inserting two overlapping flows") |
| 499 | logging.info("Issue Non-Strict Delete command ") |
| 500 | logging.info("Expecting both the flow gets deleted , because wildcards are active") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 501 | |
| 502 | #Insert T and T' again . |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 503 | (pkt,match) = match_all_except_source_address(self,of_ports) |
| 504 | (pkt1,match1) = wildcard_all_except_ingress(self,of_ports) |
| 505 | verify_tablestats(self,expect_active=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 506 | |
| 507 | #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted . |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 508 | nonstrict_delete(self,match1) |
| 509 | verify_tablestats(self,expect_active=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 510 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 511 | logging.info("Inserting three overlapping flows with different priorities") |
| 512 | logging.info("Issue Non-Strict Delete command ") |
| 513 | logging.info("Expecting all the flows to get deleted") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 514 | |
| 515 | #Insert T , add Priority P (say 100 ) |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 516 | (pkt,match) = match_all_except_source_address(self,of_ports,priority=100) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 517 | |
| 518 | #Insert T' add priority (200). |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 519 | (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 520 | |
| 521 | #Insert T' again add priority 300 --> T" . |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 522 | (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300) |
| 523 | verify_tablestats(self,expect_active=3) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 524 | |
| 525 | #Issue Non-Strict Delete and verify all getting deleted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 526 | nonstrict_delete(self,match1,priority=200) |
| 527 | verify_tablestats(self,expect_active=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 528 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 529 | logging.info("Inserting three overlapping flows with different priorities") |
| 530 | logging.info("Issue Strict Delete command ") |
| 531 | logging.info("Expecting only one to get deleted because here priorities & wildcards are being matched") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 532 | |
| 533 | #Issue Strict-Delete and verify only T'' gets deleted. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 534 | (pkt,match) = match_all_except_source_address(self,of_ports,priority=100) |
| 535 | (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200) |
| 536 | (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300) |
| 537 | strict_delete(self,match1,priority=200) |
| 538 | verify_tablestats(self,expect_active=2) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 539 | |
| 540 | |
| 541 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 542 | class Outport1(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 543 | |
| 544 | """Delete flows filtered by action outport.If the out_port field in the delete command contains a value other than OFPP_NONE, |
| 545 | it introduces a constraint when matching. This constraint is that the rule must contain an output action directed at that port.""" |
| 546 | |
| 547 | def runTest(self): |
| 548 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 549 | logging.info("Outport1 test begins") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 550 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 551 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 552 | of_ports.sort() |
| 553 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 554 | |
| 555 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 556 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 557 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 558 | logging.info("Inserting a flow with output action --> of_port[1]") |
| 559 | logging.info("Deleting the flow but with out_port set to of_port[2]") |
| 560 | logging.info("Expecting switch to filter the delete command") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 561 | |
| 562 | #Build and send Flow-1 with action output to of_port[1] |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 563 | (pkt,match) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 564 | |
| 565 | # Verify active_entries in table_stats_request = 1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 566 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 567 | |
| 568 | #Send delete command matching the flow-1 but with contraint out_port = of_port[2] |
| 569 | msg7 = message.flow_mod() |
| 570 | msg7.out_port = of_ports[2] |
| 571 | msg7.command = ofp.OFPFC_DELETE |
| 572 | msg7.buffer_id = 0xffffffff |
| 573 | msg7.match = match |
| 574 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 575 | self.controller.message_send(msg7) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 576 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 577 | |
| 578 | # Verify flow will not get deleted, active_entries in table_stats_request = 1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 579 | verify_tablestats(self,expect_active=1) |
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("Deleting the flow with out_port set to of_port[1]") |
| 582 | logging.info("Expecting switch to delete the flow") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 583 | |
| 584 | #Send Delete command with contraint out_port = of_ports[1] |
| 585 | msg7 = message.flow_mod() |
| 586 | msg7.out_port = of_ports[1] |
| 587 | msg7.command = ofp.OFPFC_DELETE |
| 588 | msg7.buffer_id = 0xffffffff |
| 589 | msg7.match = match |
| 590 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 591 | self.controller.message_send(msg7) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 592 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 593 | |
| 594 | #Verify flow gets deleted. |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 595 | verify_tablestats(self,expect_active=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 596 | |
| 597 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 598 | class IdleTimeout(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 599 | |
| 600 | """ Verify that idle timeout is implemented""" |
| 601 | |
| 602 | def runTest(self): |
| 603 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 604 | logging.info("Running Idle_Timeout test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 605 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 606 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 607 | of_ports.sort() |
| 608 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 609 | |
| 610 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 611 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 612 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 613 | logging.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set") |
| 614 | logging.info("Expecting the flow entry to delete with given idle_timeout") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 615 | |
| 616 | #Insert a flow entry with idle_timeout=1.Send_Flow_Rem flag set |
| 617 | msg9 = message.flow_mod() |
| 618 | msg9.match.wildcards = ofp.OFPFW_ALL |
| 619 | msg9.cookie = random.randint(0,9007199254740992) |
| 620 | msg9.buffer_id = 0xffffffff |
| 621 | msg9.idle_timeout = 1 |
| 622 | msg9.flags |= ofp.OFPFF_SEND_FLOW_REM |
| 623 | rv1 = self.controller.message_send(msg9) |
| 624 | self.assertTrue(rv1 != -1, "Error installing flow mod") |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 625 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 626 | |
| 627 | #Verify flow gets inserted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 628 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 629 | |
| 630 | # Verify flow removed message is recieved. |
| 631 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, |
| 632 | timeout=5) |
| 633 | self.assertTrue(response is not None, |
| 634 | 'Did not receive flow removed message ') |
| 635 | self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason, |
| 636 | 'Flow table entry removal reason is not idle_timeout') |
| 637 | self.assertEqual(1, response.duration_sec, |
| 638 | 'Flow was not alive for 1 sec') |
| 639 | |
| 640 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 641 | class Outport2(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 642 | |
| 643 | """Add, modify flows with outport set. This field is ignored by ADD, MODIFY, and MODIFY STRICT messages.""" |
| 644 | |
| 645 | def runTest(self): |
| 646 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 647 | logging.info("Running Outport2 test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 648 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 649 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 650 | of_ports.sort() |
| 651 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 652 | |
| 653 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 654 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 655 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 656 | logging.info("Adding and modifying flow with out_port fields set") |
| 657 | logging.info("Expecting switch to ignore out_port") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 658 | |
| 659 | # Create and add flow-1,Action A ,output to port of_port[1], out_port set to of_ports[2] |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 660 | (pkt,match) = wildcard_all_except_ingress(self,of_ports) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 661 | |
| 662 | # Verify flow is active |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 663 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 664 | |
| 665 | # Send Packet matching the flow |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 666 | send_packet(self,pkt,of_ports[0],of_ports[1]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 667 | |
| 668 | # Insert Flow-Modify matching flow F-1 ,action A', output to port[2], out_port set to port[3] |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 669 | modify_flow_action(self,of_ports,match) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 670 | |
| 671 | # Again verify active_entries in table_stats_request =1 |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 672 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 673 | |
| 674 | #Verify action is modified |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 675 | send_packet(self,pkt,of_ports[0],of_ports[2]) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 676 | |
| 677 | |
| 678 | |
| 679 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 680 | class HardTimeout(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 681 | |
| 682 | """ Verify that hard timeout is implemented """ |
| 683 | |
| 684 | def runTest(self): |
| 685 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 686 | logging.info("Running Hard_Timeout test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 687 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 688 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 689 | of_ports.sort() |
| 690 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 691 | |
| 692 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 693 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 694 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 695 | logging.info("Inserting flow entry with hard_timeout set. Also send_flow_removed_message flag set") |
| 696 | logging.info("Expecting the flow entry to delete with given hard_timeout") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 697 | |
| 698 | # Insert a flow entry with hardtimeout=1 and send_flow_removed flag set |
| 699 | msg9 = message.flow_mod() |
| 700 | msg9.match.wildcards = ofp.OFPFW_ALL |
| 701 | msg9.cookie = random.randint(0,9007199254740992) |
| 702 | msg9.buffer_id = 0xffffffff |
| 703 | msg9.hard_timeout = 1 |
| 704 | msg9.flags |= ofp.OFPFF_SEND_FLOW_REM |
| 705 | rv1 = self.controller.message_send(msg9) |
| 706 | self.assertTrue(rv1 != -1, "Error installing flow mod") |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 707 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 708 | |
| 709 | #Verify flow gets inserted |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 710 | verify_tablestats(self,expect_active=1) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 711 | |
| 712 | # Verify flow removed message is recieved. |
| 713 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, |
| 714 | timeout=5) |
| 715 | self.assertTrue(response is not None, |
| 716 | 'Did not receive flow removed message ') |
| 717 | self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason, |
| 718 | 'Flow table entry removal reason is not hard_timeout') |
| 719 | self.assertEqual(1, response.duration_sec, |
| 720 | 'Flow was not alive for 1 sec') |
| 721 | |
| 722 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 723 | class FlowTimeout(base_tests.SimpleDataPlane): |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 724 | |
| 725 | """Verify that Flow removed messages are generated as expected |
| 726 | Flow removed messages being generated when flag is set, is already tested in the above tests |
| 727 | So here, we test the vice-versa condition""" |
| 728 | |
| 729 | |
| 730 | def runTest(self): |
| 731 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 732 | logging.info("Running Flow_Timeout test ") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 733 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 734 | of_ports = config["port_map"].keys() |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 735 | of_ports.sort() |
| 736 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 737 | |
| 738 | #Clear switch state |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 739 | delete_all_flows(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 740 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 741 | logging.info("Inserting flow entry with hard_timeout set and send_flow_removed_message flag not set") |
| 742 | logging.info("Expecting the flow entry to delete, but no flow removed message") |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 743 | |
| 744 | # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set |
| 745 | pkt = simple_tcp_packet() |
| 746 | match3 = parse.packet_to_flow_match(pkt) |
| 747 | self.assertTrue(match3 is not None, "Could not generate flow match from pkt") |
| 748 | match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT |
| 749 | match3.in_port = of_ports[0] |
| 750 | msg3 = message.flow_mod() |
| 751 | msg3.out_port = of_ports[2] # ignored by flow add,flow modify |
| 752 | msg3.command = ofp.OFPFC_ADD |
| 753 | msg3.cookie = random.randint(0,9007199254740992) |
| 754 | msg3.buffer_id = 0xffffffff |
| 755 | msg3.hard_timeout = 1 |
| 756 | msg3.buffer_id = 0xffffffff |
| 757 | msg3.match = match3 |
| 758 | act3 = action.action_output() |
| 759 | act3.port = of_ports[1] |
Rich Lane | e30455b | 2013-01-03 16:24:44 -0800 | [diff] [blame] | 760 | msg3.actions.add(act3) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 761 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 762 | self.controller.message_send(msg3) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame^] | 763 | do_barrier(self.controller) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 764 | |
| 765 | #Verify no flow removed message is generated |
| 766 | (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED, |
| 767 | timeout=3) |
| 768 | self.assertTrue(response is None, |
| 769 | 'Recieved flow removed message ') |
| 770 | |
| 771 | # Verify no entries in the table |
ShreyaPandita | 8dab466 | 2012-11-02 13:40:14 -0400 | [diff] [blame] | 772 | verify_tablestats(self,expect_active=0) |
ShreyaPandita | 9306c77 | 2012-09-28 12:21:40 -0400 | [diff] [blame] | 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |