blob: 25fc6830c12e5f55f1ac851620126215259699c4 [file] [log] [blame]
ShreyaPandita9306c772012-09-28 12:21:40 -04001"""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
7import logging
8
9import unittest
10import random
11
Rich Lane477f4812012-10-04 22:49:00 -070012from oftest import config
ShreyaPandita9306c772012-09-28 12:21:40 -040013import oftest.controller as controller
14import oftest.cstruct as ofp
15import oftest.message as message
16import oftest.dataplane as dataplane
17import oftest.action as action
18import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070019import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040020
Rich Laneda3b5ad2012-10-03 09:05:32 -070021from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040022from time import sleep
23from FuncUtils import *
24
Rich Laneb90a1c42012-10-05 09:16:05 -070025class OverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040026
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 Lane9a003812012-10-04 17:17:59 -070032 logging.info("Running Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040033
Rich Lane477f4812012-10-04 22:49:00 -070034 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040035 of_ports.sort()
36 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
37
38 #Clear Switch State
Rich Lane9a003812012-10-04 17:17:59 -070039 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040040 self.assertEqual(rc, 0, "Failed to delete all flows")
41
Rich Lane9a003812012-10-04 17:17:59 -070042 logging.info("Inserting two overlapping flows")
43 logging.info("Expecting switch to return an error")
ShreyaPandita9306c772012-09-28 12:21:40 -040044
45 #Insert a flow F with wildcarded all fields
ShreyaPandita8dab4662012-11-02 13:40:14 -040046 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -040047
48 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -040049 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040050
51 # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set
ShreyaPandita8dab4662012-11-02 13:40:14 -040052 pkt_matchingress = simple_tcp_packet()
53 match3 = parse.packet_to_flow_match(pkt_matchingress)
ShreyaPandita9306c772012-09-28 12:21:40 -040054 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 Lanee30455b2013-01-03 16:24:44 -080067 msg3.actions.add(act3)
68 msg3.actions.add(1)
ShreyaPandita9306c772012-09-28 12:21:40 -040069 rv = self.controller.message_send(msg3)
70 self.assertTrue(rv != -1, "Error installing flow mod")
71 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
72
73 # Verify Flow does not get inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -040074 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040075
76 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
77 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
78 timeout=5)
79 self.assertTrue(response is not None,
80 'Switch did not reply with error message')
81 self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED,
82 'Error message type is not flow mod failed ')
83 self.assertTrue(response.code==ofp.OFPFMFC_OVERLAP,
84 'Error Message code is not overlap')
85
86
Rich Laneb90a1c42012-10-05 09:16:05 -070087class NoOverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040088
89 """Verify that without overlap check flag set, overlapping flows can be created."""
90
91 def runTest(self):
92
Rich Lane9a003812012-10-04 17:17:59 -070093 logging.info("Running No_Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040094
Rich Lane477f4812012-10-04 22:49:00 -070095 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040096 of_ports.sort()
97 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
98
99 #Clear Switch State
Rich Lane9a003812012-10-04 17:17:59 -0700100 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400101 self.assertEqual(rc, 0, "Failed to delete all flows")
102
Rich Lane9a003812012-10-04 17:17:59 -0700103 logging.info("Inserting two overlapping flows")
104 logging.info("Expecting switch to insert the flows without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400105
106 #Build a flow F with wildcarded all fields.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400107 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400108
109 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400110 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400111
112 # Build a overlapping flow F' without check overlap bit set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400113 wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400114
115 # Verify Flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400116 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400117
118
Rich Laneb90a1c42012-10-05 09:16:05 -0700119class IdenticalFlows(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400120
121 """Verify that adding two identical flows overwrites the existing one and clears counters"""
122
123 def runTest(self):
124
Rich Lane9a003812012-10-04 17:17:59 -0700125 logging.info("Running Identical_Flows test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400126
Rich Lane477f4812012-10-04 22:49:00 -0700127 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400128 of_ports.sort()
129 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
130
131 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700132 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400133 self.assertEqual(rc, 0, "Failed to delete all flows")
134
Rich Lane9a003812012-10-04 17:17:59 -0700135 logging.info("Inserting two identical flows one by one")
136 logging.info("Expecting switch to overwrite the first flow and clear the counters associated with it ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400137
138 # Create and add flow-1, check on dataplane it is active.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400139 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400140
141 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400142 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400143
144 # Send Packet (to increment counters like byte_count and packet_count)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400145 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400146
147 # Verify Flow counters have incremented
ShreyaPandita8dab4662012-11-02 13:40:14 -0400148 verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400149
150 #Send Identical flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400151 (pkt1,match1) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400152
153 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400154 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400155
156 # Verify Flow counters reset
ShreyaPandita8dab4662012-11-02 13:40:14 -0400157 verify_flowstats(self,match,byte_count=0,packet_count=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400158
159
Rich Laneb90a1c42012-10-05 09:16:05 -0700160class EmerFlowTimeout(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400161
162 """Timeout values are not allowed for emergency flows"""
163
164 def runTest(self):
165
Rich Lane9a003812012-10-04 17:17:59 -0700166 logging.info("Running Emergency_Flow_Timeout test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400167
Rich Lane477f4812012-10-04 22:49:00 -0700168 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400169 of_ports.sort()
170 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
171
172 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700173 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400174 self.assertEqual(rc, 0, "Failed to delete all flows")
175
Rich Lane9a003812012-10-04 17:17:59 -0700176 logging.info("Inserting an emergency flow with timeout values")
177 logging.info("Expecting switch to generate error ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400178
179 #Insert an emergency flow
180 pkt = simple_tcp_packet()
181 match = parse.packet_to_flow_match(pkt)
182 match.in_port = of_ports[0]
183
184 request = message.flow_mod()
185 request.match = match
186 request.command = ofp.OFPFC_ADD
187 request.flags = request.flags|ofp.OFPFF_EMERG
188 request.hard_timeout =9
189 request.idle_timeout =9
190
191 act = action.action_output()
192 act.port = of_ports[1]
193
194 request.actions.add(act)
Rich Lane9a003812012-10-04 17:17:59 -0700195 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400196 rv = self.controller.message_send(request)
197 self.assertTrue(rv != -1, "Flow addition did not fail.")
198
199 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
200
201 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
202 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
203 timeout=5)
204 self.assertTrue(response is not None,
205 'Switch did not reply with error message')
206 self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED,
207 'Error message type is not flow mod failed ')
208 self.assertTrue(response.code==ofp.OFPFMFC_BAD_EMERG_TIMEOUT,
209 'Error Message code is not bad emergency timeout')
210
211
Rich Laneb90a1c42012-10-05 09:16:05 -0700212class MissingModifyAdd(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400213
214 """If a modify does not match an existing flow, the flow gets added """
215
216 def runTest(self):
217
Rich Lane9a003812012-10-04 17:17:59 -0700218 logging.info("Running Missing_Modify_Add test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400219
Rich Lane477f4812012-10-04 22:49:00 -0700220 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400221 of_ports.sort()
222 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
223
Rich Lane9a003812012-10-04 17:17:59 -0700224 logging.info("Inserting a flow-modify that does not match an existing flow")
225 logging.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400226
227 #Clear Switch State
Rich Lane9a003812012-10-04 17:17:59 -0700228 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400229 self.assertEqual(rc, 0, "Failed to delete all flows")
230
231 #Generate a flow-mod,command OFPC_MODIFY
232
233 request = message.flow_mod()
234 request.command = ofp.OFPFC_MODIFY
235 request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
236 request.match.in_port = of_ports[0]
237 request.cookie = random.randint(0,9007199254740992)
238 request.buffer_id = 0xffffffff
239 act3 = action.action_output()
240 act3.port = of_ports[1]
Rich Lanee30455b2013-01-03 16:24:44 -0800241 request.actions.add(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400242
Rich Lane9a003812012-10-04 17:17:59 -0700243 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400244 rv = self.controller.message_send(request)
245 self.assertTrue(rv != -1, "Error installing flow mod")
246 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
247
248 #Verify the flow gets added i.e. active_count= 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400249 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400250
251
Rich Laneb90a1c42012-10-05 09:16:05 -0700252class ModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400253
254 """A modified flow preserves counters"""
255
256 def runTest(self):
257
Rich Lane9a003812012-10-04 17:17:59 -0700258 logging.info("Running Modify_Action test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400259
Rich Lane477f4812012-10-04 22:49:00 -0700260 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400261 of_ports.sort()
262 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
263
264 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700265 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400266 self.assertEqual(rc, 0, "Failed to delete all flows")
267
Rich Lane9a003812012-10-04 17:17:59 -0700268 logging.info("Inserting a Flow and incrementing flow counters. Modifying the flow action")
269 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400270
271 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A , output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400272 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400273
274 #Send Packet matching the flow thus incrementing counters like packet_count,byte_count
ShreyaPandita8dab4662012-11-02 13:40:14 -0400275 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400276
277 #Verify flow counters
ShreyaPandita8dab4662012-11-02 13:40:14 -0400278 verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400279
280 #Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400281 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400282
283 # 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]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400284 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400285
286 #Verify flow counters are preserved
ShreyaPandita8dab4662012-11-02 13:40:14 -0400287 verify_flowstats(self,match,byte_count=(2*len(str(pkt))),packet_count=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400288
289
Rich Laneb90a1c42012-10-05 09:16:05 -0700290class StrictModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400291
292 """Strict Modify Flow also changes action preserves counters"""
293
294 def runTest(self):
295
Rich Lane9a003812012-10-04 17:17:59 -0700296 logging.info("Running Strict_Modify_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400297
Rich Lane477f4812012-10-04 22:49:00 -0700298 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400299 of_ports.sort()
300 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
301
302 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700303 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400304 self.assertEqual(rc, 0, "Failed to delete all flows")
305
Rich Lane9a003812012-10-04 17:17:59 -0700306 logging.info("Inserting Flows and incrementing flow counters. Strict Modify the flow action ")
307 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400308
309 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400310 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400311
312 #Create and add flow-2 , Match on ingress_port only, Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400313 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=10)
ShreyaPandita9306c772012-09-28 12:21:40 -0400314
315 # Verify both the flows are active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400316 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400317
318 #Send a packet matching the flows, thus incrementing flow-counters (packet matches the flow F-1 with higher priority)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400319 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400320
321 # Verify flow counters of the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400322 verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400323
324 # Strict-Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400325 strict_modify_flow_action(self,of_ports[2],match,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400326
327 # 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]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400328 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400329
330 # Verify flow counters are preserved
ShreyaPandita8dab4662012-11-02 13:40:14 -0400331 verify_flowstats(self,match,byte_count=(2*len(str(pkt))),packet_count=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400332
333
Rich Laneb90a1c42012-10-05 09:16:05 -0700334class DeleteNonexistingFlow(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400335
336 """Request deletion of non-existing flow"""
337
338 def runTest(self):
339
Rich Lane9a003812012-10-04 17:17:59 -0700340 logging.info("Delete_NonExisting_Flow test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400341
Rich Lane477f4812012-10-04 22:49:00 -0700342 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400343 of_ports.sort()
344 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
345
346 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700347 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400348 self.assertEqual(rc, 0, "Failed to delete all flows")
349
Rich Lane9a003812012-10-04 17:17:59 -0700350 logging.info("Deleting a non-existing flow")
351 logging.info("Expecting switch to ignore the command , without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400352
353 # Issue a delete command
354 msg = message.flow_mod()
355 msg.match.wildcards = ofp.OFPFW_ALL
356 msg.out_port = ofp.OFPP_NONE
357 msg.command = ofp.OFPFC_DELETE
358 msg.buffer_id = 0xffffffff
359
360 # Verify no message or error is generated by polling the the control plane
361 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
362 timeout=2)
363 self.assertTrue(response is None,
364 'Recieved Error for deleting non-exiting flow ')
365
366
367
Rich Laneb90a1c42012-10-05 09:16:05 -0700368class SendFlowRem(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400369
370 """Check deletion of flows happens and generates messages as configured.
371 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,
372 vice versa also exists """
373
374 def runTest(self):
375
Rich Lane9a003812012-10-04 17:17:59 -0700376 logging.info("Running Send_Flow_Rem test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400377
Rich Lane477f4812012-10-04 22:49:00 -0700378 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400379 of_ports.sort()
380 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
381
382 #Clear swicth state
Rich Lane9a003812012-10-04 17:17:59 -0700383 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400384 self.assertEqual(rc, 0, "Failed to delete all flows")
385
Rich Lane9a003812012-10-04 17:17:59 -0700386 logging.info("Inserting flows F1 and F2 without and with send_flow_removed_message flag set ")
387 logging.info("Deleting the flows")
388 logging.info("Expecting flow removed message only for F2")
ShreyaPandita9306c772012-09-28 12:21:40 -0400389
390 # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400391 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400392
393 # Verify flow is inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400394 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400395
396 #Delete the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400397 nonstrict_delete(self,match,priority=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400398
399 # Verify no flow removed message is generated for the FLOW-1
400
401 (response1, pkt1) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
402 timeout=2)
403 self.assertTrue(response1 is None,
404 'Received flow removed message for the flow with flow_rem flag not set')
405
406 # Insert another flow F' with OFPFF_SEND_FLOW_REM flag set.
407 msg9 = message.flow_mod()
408 msg9.match.wildcards = ofp.OFPFW_ALL
409 msg9.cookie = random.randint(0,9007199254740992)
410 msg9.buffer_id = 0xffffffff
411 msg9.idle_timeout = 1
412 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
413 rv1 = self.controller.message_send(msg9)
414 self.assertTrue(rv1 != -1, "Error installing flow mod")
415 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
416
417 # Delete the flow-2
Rich Lane9a003812012-10-04 17:17:59 -0700418 rc2 = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400419 self.assertEqual(rc2, 0, "Failed to delete all flows")
420
421 # Verify flow removed message is generated for the FLOW-2
422
423 (response2, pkt2) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
424 timeout=2)
425 self.assertTrue(response2 is not None,
426 'Did not receive flow removed message for this flow')
427
428
Rich Laneb90a1c42012-10-05 09:16:05 -0700429class DeleteEmerFlow(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400430
431 """Delete emergency flow and verify no message is generated.An emergency flow deletion will not generate flow-removed messages even if
432 Send Flow removed message flag was set during the emergency flow entry"""
433
434 def runTest(self):
435
Rich Lane9a003812012-10-04 17:17:59 -0700436 logging.info("Running Delete_Emer_Flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400437
Rich Lane477f4812012-10-04 22:49:00 -0700438 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400439 of_ports.sort()
440
441 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700442 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400443 self.assertEqual(rc, 0, "Failed to delete all flows")
444
Rich Lane9a003812012-10-04 17:17:59 -0700445 logging.info("Inserting a emergency flow with send_flow_removed flag set")
446 logging.info("Expecting no flow_removed_message on the deletion of the emergency flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400447
448 # Insert a flow with emergency bit set.
449 pkt = simple_tcp_packet()
450 match = parse.packet_to_flow_match(pkt)
451 match.in_port = of_ports[0]
452 request = message.flow_mod()
453 request.match = match
454 request.command = ofp.OFPFC_ADD
455 request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM
456 act = action.action_output()
457 act.port = of_ports[1]
458 request.actions.add(act)
459
460 rv = self.controller.message_send(request)
461 self.assertTrue(rv != -1, "Flow addition failed.")
462
463 # Delete the emergency flow
464
ShreyaPandita8dab4662012-11-02 13:40:14 -0400465 nonstrict_delete(self,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400466 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM ,
467 timeout=2)
468 self.assertTrue(response is None,
469 'Test Failed ')
470
471
Rich Laneb90a1c42012-10-05 09:16:05 -0700472class StrictVsNonstrict(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400473
474 """Delete and verify strict and non-strict behaviors
475 This test compares the behavior of delete strict and non-strict"""
476
477 def runTest(self):
478
Rich Lane9a003812012-10-04 17:17:59 -0700479 logging.info("Strict_Vs_Nonstrict test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400480
Rich Lane477f4812012-10-04 22:49:00 -0700481 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400482 of_ports.sort()
483 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
484
485 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700486 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400487 self.assertEqual(rc, 0, "Failed to delete all flows")
488
Rich Lane9a003812012-10-04 17:17:59 -0700489 logging.info("Inserting a flow with exact match")
490 logging.info("Issue Strict Delete command , verify it gets deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400491
492 #Insert F with an exact Match
ShreyaPandita8dab4662012-11-02 13:40:14 -0400493 (pkt,match) = exact_match(self,of_ports)
494 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400495
496 #Issue Strict Delete Command , verify F gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400497 strict_delete(self,match)
498 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400499
Rich Lane9a003812012-10-04 17:17:59 -0700500 logging.info("Inserting two overlapping flows")
501 logging.info("Issue Strict Delete command ")
502 logging.info("Expecting only one flow gets deleted , because Strict Delete matches on wildcards as well")
ShreyaPandita9306c772012-09-28 12:21:40 -0400503
504 #Insert Flow T with match on all , except one wildcarded ( say src adddress ).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400505 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400506
507 #Insert another flow T' with match on ingress_port , wildcarded rest.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400508 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
509 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400510
511 #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400512 strict_delete(self,match1)
513 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400514
Rich Lane9a003812012-10-04 17:17:59 -0700515 logging.info("Inserting two overlapping flows")
516 logging.info("Issue Non-Strict Delete command ")
517 logging.info("Expecting both the flow gets deleted , because wildcards are active")
ShreyaPandita9306c772012-09-28 12:21:40 -0400518
519 #Insert T and T' again .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400520 (pkt,match) = match_all_except_source_address(self,of_ports)
521 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
522 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400523
524 #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400525 nonstrict_delete(self,match1)
526 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400527
Rich Lane9a003812012-10-04 17:17:59 -0700528 logging.info("Inserting three overlapping flows with different priorities")
529 logging.info("Issue Non-Strict Delete command ")
530 logging.info("Expecting all the flows to get deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400531
532 #Insert T , add Priority P (say 100 )
ShreyaPandita8dab4662012-11-02 13:40:14 -0400533 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400534
535 #Insert T' add priority (200).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400536 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
ShreyaPandita9306c772012-09-28 12:21:40 -0400537
538 #Insert T' again add priority 300 --> T" .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400539 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
540 verify_tablestats(self,expect_active=3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400541
542 #Issue Non-Strict Delete and verify all getting deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400543 nonstrict_delete(self,match1,priority=200)
544 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400545
Rich Lane9a003812012-10-04 17:17:59 -0700546 logging.info("Inserting three overlapping flows with different priorities")
547 logging.info("Issue Strict Delete command ")
548 logging.info("Expecting only one to get deleted because here priorities & wildcards are being matched")
ShreyaPandita9306c772012-09-28 12:21:40 -0400549
550 #Issue Strict-Delete and verify only T'' gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400551 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
552 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
553 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
554 strict_delete(self,match1,priority=200)
555 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400556
557
558
Rich Laneb90a1c42012-10-05 09:16:05 -0700559class Outport1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400560
561 """Delete flows filtered by action outport.If the out_port field in the delete command contains a value other than OFPP_NONE,
562 it introduces a constraint when matching. This constraint is that the rule must contain an output action directed at that port."""
563
564 def runTest(self):
565
Rich Lane9a003812012-10-04 17:17:59 -0700566 logging.info("Outport1 test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400567
Rich Lane477f4812012-10-04 22:49:00 -0700568 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400569 of_ports.sort()
570 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
571
572 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700573 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400574 self.assertEqual(rc, 0, "Failed to delete all flows")
575
Rich Lane9a003812012-10-04 17:17:59 -0700576 logging.info("Inserting a flow with output action --> of_port[1]")
577 logging.info("Deleting the flow but with out_port set to of_port[2]")
578 logging.info("Expecting switch to filter the delete command")
ShreyaPandita9306c772012-09-28 12:21:40 -0400579
580 #Build and send Flow-1 with action output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400581 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400582
583 # Verify active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400584 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400585
586 #Send delete command matching the flow-1 but with contraint out_port = of_port[2]
587 msg7 = message.flow_mod()
588 msg7.out_port = of_ports[2]
589 msg7.command = ofp.OFPFC_DELETE
590 msg7.buffer_id = 0xffffffff
591 msg7.match = match
592
593 rv = self.controller.message_send(msg7)
594 self.assertTrue(rv != -1, "Error installing flow mod")
595 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
596
597 # Verify flow will not get deleted, active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400598 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400599
Rich Lane9a003812012-10-04 17:17:59 -0700600 logging.info("Deleting the flow with out_port set to of_port[1]")
601 logging.info("Expecting switch to delete the flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400602
603 #Send Delete command with contraint out_port = of_ports[1]
604 msg7 = message.flow_mod()
605 msg7.out_port = of_ports[1]
606 msg7.command = ofp.OFPFC_DELETE
607 msg7.buffer_id = 0xffffffff
608 msg7.match = match
609
610 rv = self.controller.message_send(msg7)
611 self.assertTrue(rv != -1, "Error installing flow mod")
612 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
613
614 #Verify flow gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400615 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400616
617
Rich Laneb90a1c42012-10-05 09:16:05 -0700618class IdleTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400619
620 """ Verify that idle timeout is implemented"""
621
622 def runTest(self):
623
Rich Lane9a003812012-10-04 17:17:59 -0700624 logging.info("Running Idle_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400625
Rich Lane477f4812012-10-04 22:49:00 -0700626 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400627 of_ports.sort()
628 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
629
630 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700631 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400632 self.assertEqual(rc, 0, "Failed to delete all flows")
633
Rich Lane9a003812012-10-04 17:17:59 -0700634 logging.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set")
635 logging.info("Expecting the flow entry to delete with given idle_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400636
637 #Insert a flow entry with idle_timeout=1.Send_Flow_Rem flag set
638 msg9 = message.flow_mod()
639 msg9.match.wildcards = ofp.OFPFW_ALL
640 msg9.cookie = random.randint(0,9007199254740992)
641 msg9.buffer_id = 0xffffffff
642 msg9.idle_timeout = 1
643 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
644 rv1 = self.controller.message_send(msg9)
645 self.assertTrue(rv1 != -1, "Error installing flow mod")
646 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
647
648 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400649 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400650
651 # Verify flow removed message is recieved.
652 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
653 timeout=5)
654 self.assertTrue(response is not None,
655 'Did not receive flow removed message ')
656 self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
657 'Flow table entry removal reason is not idle_timeout')
658 self.assertEqual(1, response.duration_sec,
659 'Flow was not alive for 1 sec')
660
661
Rich Laneb90a1c42012-10-05 09:16:05 -0700662class Outport2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400663
664 """Add, modify flows with outport set. This field is ignored by ADD, MODIFY, and MODIFY STRICT messages."""
665
666 def runTest(self):
667
Rich Lane9a003812012-10-04 17:17:59 -0700668 logging.info("Running Outport2 test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400669
Rich Lane477f4812012-10-04 22:49:00 -0700670 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400671 of_ports.sort()
672 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
673
674 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700675 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400676 self.assertEqual(rc, 0, "Failed to delete all flows")
677
Rich Lane9a003812012-10-04 17:17:59 -0700678 logging.info("Adding and modifying flow with out_port fields set")
679 logging.info("Expecting switch to ignore out_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400680
681 # Create and add flow-1,Action A ,output to port of_port[1], out_port set to of_ports[2]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400682 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400683
684 # Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400685 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400686
687 # Send Packet matching the flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400688 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400689
690 # Insert Flow-Modify matching flow F-1 ,action A', output to port[2], out_port set to port[3]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400691 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400692
693 # Again verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400694 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400695
696 #Verify action is modified
ShreyaPandita8dab4662012-11-02 13:40:14 -0400697 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400698
699
700
701
Rich Laneb90a1c42012-10-05 09:16:05 -0700702class HardTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400703
704 """ Verify that hard timeout is implemented """
705
706 def runTest(self):
707
Rich Lane9a003812012-10-04 17:17:59 -0700708 logging.info("Running Hard_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400709
Rich Lane477f4812012-10-04 22:49:00 -0700710 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400711 of_ports.sort()
712 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
713
714 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700715 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400716 self.assertEqual(rc, 0, "Failed to delete all flows")
717
Rich Lane9a003812012-10-04 17:17:59 -0700718 logging.info("Inserting flow entry with hard_timeout set. Also send_flow_removed_message flag set")
719 logging.info("Expecting the flow entry to delete with given hard_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400720
721 # Insert a flow entry with hardtimeout=1 and send_flow_removed flag set
722 msg9 = message.flow_mod()
723 msg9.match.wildcards = ofp.OFPFW_ALL
724 msg9.cookie = random.randint(0,9007199254740992)
725 msg9.buffer_id = 0xffffffff
726 msg9.hard_timeout = 1
727 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
728 rv1 = self.controller.message_send(msg9)
729 self.assertTrue(rv1 != -1, "Error installing flow mod")
730 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
731
732 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400733 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400734
735 # Verify flow removed message is recieved.
736 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
737 timeout=5)
738 self.assertTrue(response is not None,
739 'Did not receive flow removed message ')
740 self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
741 'Flow table entry removal reason is not hard_timeout')
742 self.assertEqual(1, response.duration_sec,
743 'Flow was not alive for 1 sec')
744
745
Rich Laneb90a1c42012-10-05 09:16:05 -0700746class FlowTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400747
748 """Verify that Flow removed messages are generated as expected
749 Flow removed messages being generated when flag is set, is already tested in the above tests
750 So here, we test the vice-versa condition"""
751
752
753 def runTest(self):
754
Rich Lane9a003812012-10-04 17:17:59 -0700755 logging.info("Running Flow_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400756
Rich Lane477f4812012-10-04 22:49:00 -0700757 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400758 of_ports.sort()
759 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
760
761 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700762 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400763 self.assertEqual(rc, 0, "Failed to delete all flows")
764
Rich Lane9a003812012-10-04 17:17:59 -0700765 logging.info("Inserting flow entry with hard_timeout set and send_flow_removed_message flag not set")
766 logging.info("Expecting the flow entry to delete, but no flow removed message")
ShreyaPandita9306c772012-09-28 12:21:40 -0400767
768 # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set
769 pkt = simple_tcp_packet()
770 match3 = parse.packet_to_flow_match(pkt)
771 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
772 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
773 match3.in_port = of_ports[0]
774 msg3 = message.flow_mod()
775 msg3.out_port = of_ports[2] # ignored by flow add,flow modify
776 msg3.command = ofp.OFPFC_ADD
777 msg3.cookie = random.randint(0,9007199254740992)
778 msg3.buffer_id = 0xffffffff
779 msg3.hard_timeout = 1
780 msg3.buffer_id = 0xffffffff
781 msg3.match = match3
782 act3 = action.action_output()
783 act3.port = of_ports[1]
Rich Lanee30455b2013-01-03 16:24:44 -0800784 msg3.actions.add(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400785
786 rv = self.controller.message_send(msg3)
787 self.assertTrue(rv != -1, "Error installing flow mod")
788 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
789
790 #Verify no flow removed message is generated
791 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
792 timeout=3)
793 self.assertTrue(response is None,
794 'Recieved flow removed message ')
795
796 # Verify no entries in the table
ShreyaPandita8dab4662012-11-02 13:40:14 -0400797 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820