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