blob: 3ca0038d574e60e7f31e07ffa914ae23404ef3b9 [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)
Rich Lane5c3151c2013-01-03 17:15:41 -080068 self.controller.message_send(msg3)
ShreyaPandita9306c772012-09-28 12:21:40 -040069 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
70
71 # Verify Flow does not get inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -040072 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040073
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 Laneb90a1c42012-10-05 09:16:05 -070085class NoOverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040086
87 """Verify that without overlap check flag set, overlapping flows can be created."""
88
89 def runTest(self):
90
Rich Lane9a003812012-10-04 17:17:59 -070091 logging.info("Running No_Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040092
Rich Lane477f4812012-10-04 22:49:00 -070093 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040094 of_ports.sort()
95 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
96
97 #Clear Switch State
Rich Lane9a003812012-10-04 17:17:59 -070098 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040099 self.assertEqual(rc, 0, "Failed to delete all flows")
100
Rich Lane9a003812012-10-04 17:17:59 -0700101 logging.info("Inserting two overlapping flows")
102 logging.info("Expecting switch to insert the flows without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400103
104 #Build a flow F with wildcarded all fields.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400105 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400106
107 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400108 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400109
110 # Build a overlapping flow F' without check overlap bit set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400111 wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400112
113 # Verify Flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400114 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400115
116
Rich Laneb90a1c42012-10-05 09:16:05 -0700117class IdenticalFlows(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400118
119 """Verify that adding two identical flows overwrites the existing one and clears counters"""
120
121 def runTest(self):
122
Rich Lane9a003812012-10-04 17:17:59 -0700123 logging.info("Running Identical_Flows test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400124
Rich Lane477f4812012-10-04 22:49:00 -0700125 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400126 of_ports.sort()
127 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
128
129 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700130 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400131 self.assertEqual(rc, 0, "Failed to delete all flows")
132
Rich Lane9a003812012-10-04 17:17:59 -0700133 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 ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400135
136 # Create and add flow-1, check on dataplane it is active.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400137 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400138
139 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400140 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400141
142 # Send Packet (to increment counters like byte_count and packet_count)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400143 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400144
145 # Verify Flow counters have incremented
ShreyaPandita8dab4662012-11-02 13:40:14 -0400146 verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400147
148 #Send Identical flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400149 (pkt1,match1) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400150
151 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400152 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400153
154 # Verify Flow counters reset
ShreyaPandita8dab4662012-11-02 13:40:14 -0400155 verify_flowstats(self,match,byte_count=0,packet_count=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400156
157
Rich Laneb90a1c42012-10-05 09:16:05 -0700158class EmerFlowTimeout(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400159
160 """Timeout values are not allowed for emergency flows"""
161
162 def runTest(self):
163
Rich Lane9a003812012-10-04 17:17:59 -0700164 logging.info("Running Emergency_Flow_Timeout test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400165
Rich Lane477f4812012-10-04 22:49:00 -0700166 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400167 of_ports.sort()
168 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
169
170 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700171 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400172 self.assertEqual(rc, 0, "Failed to delete all flows")
173
Rich Lane9a003812012-10-04 17:17:59 -0700174 logging.info("Inserting an emergency flow with timeout values")
175 logging.info("Expecting switch to generate error ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400176
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 Lane9a003812012-10-04 17:17:59 -0700193 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800194 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400195
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 Laneb90a1c42012-10-05 09:16:05 -0700209class MissingModifyAdd(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400210
211 """If a modify does not match an existing flow, the flow gets added """
212
213 def runTest(self):
214
Rich Lane9a003812012-10-04 17:17:59 -0700215 logging.info("Running Missing_Modify_Add test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400216
Rich Lane477f4812012-10-04 22:49:00 -0700217 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400218 of_ports.sort()
219 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
220
Rich Lane9a003812012-10-04 17:17:59 -0700221 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 ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400223
224 #Clear Switch State
Rich Lane9a003812012-10-04 17:17:59 -0700225 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400226 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 Lanee30455b2013-01-03 16:24:44 -0800238 request.actions.add(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400239
Rich Lane9a003812012-10-04 17:17:59 -0700240 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800241 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400242 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
243
244 #Verify the flow gets added i.e. active_count= 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400245 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400246
247
Rich Laneb90a1c42012-10-05 09:16:05 -0700248class ModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400249
250 """A modified flow preserves counters"""
251
252 def runTest(self):
253
Rich Lane9a003812012-10-04 17:17:59 -0700254 logging.info("Running Modify_Action test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400255
Rich Lane477f4812012-10-04 22:49:00 -0700256 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400257 of_ports.sort()
258 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
259
260 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700261 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400262 self.assertEqual(rc, 0, "Failed to delete all flows")
263
Rich Lane9a003812012-10-04 17:17:59 -0700264 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400266
267 #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 -0400268 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400269
270 #Send Packet matching the flow thus incrementing counters like packet_count,byte_count
ShreyaPandita8dab4662012-11-02 13:40:14 -0400271 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400272
273 #Verify flow counters
ShreyaPandita8dab4662012-11-02 13:40:14 -0400274 verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400275
276 #Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400277 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400278
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]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400280 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400281
282 #Verify flow counters are preserved
ShreyaPandita8dab4662012-11-02 13:40:14 -0400283 verify_flowstats(self,match,byte_count=(2*len(str(pkt))),packet_count=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400284
285
Rich Laneb90a1c42012-10-05 09:16:05 -0700286class StrictModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400287
288 """Strict Modify Flow also changes action preserves counters"""
289
290 def runTest(self):
291
Rich Lane9a003812012-10-04 17:17:59 -0700292 logging.info("Running Strict_Modify_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400293
Rich Lane477f4812012-10-04 22:49:00 -0700294 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400295 of_ports.sort()
296 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
297
298 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700299 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400300 self.assertEqual(rc, 0, "Failed to delete all flows")
301
Rich Lane9a003812012-10-04 17:17:59 -0700302 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400304
305 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400306 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400307
308 #Create and add flow-2 , Match on ingress_port only, Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400309 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=10)
ShreyaPandita9306c772012-09-28 12:21:40 -0400310
311 # Verify both the flows are active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400312 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400313
314 #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 -0400315 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400316
317 # Verify flow counters of the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400318 verify_flowstats(self,match,byte_count=len(str(pkt)),packet_count=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400319
320 # Strict-Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400321 strict_modify_flow_action(self,of_ports[2],match,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400322
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]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400324 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400325
326 # Verify flow counters are preserved
ShreyaPandita8dab4662012-11-02 13:40:14 -0400327 verify_flowstats(self,match,byte_count=(2*len(str(pkt))),packet_count=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400328
329
Rich Laneb90a1c42012-10-05 09:16:05 -0700330class DeleteNonexistingFlow(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400331
332 """Request deletion of non-existing flow"""
333
334 def runTest(self):
335
Rich Lane9a003812012-10-04 17:17:59 -0700336 logging.info("Delete_NonExisting_Flow test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400337
Rich Lane477f4812012-10-04 22:49:00 -0700338 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400339 of_ports.sort()
340 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
341
342 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700343 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400344 self.assertEqual(rc, 0, "Failed to delete all flows")
345
Rich Lane9a003812012-10-04 17:17:59 -0700346 logging.info("Deleting a non-existing flow")
347 logging.info("Expecting switch to ignore the command , without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400348
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 Laneb90a1c42012-10-05 09:16:05 -0700364class SendFlowRem(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400365
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 Lane9a003812012-10-04 17:17:59 -0700372 logging.info("Running Send_Flow_Rem test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400373
Rich Lane477f4812012-10-04 22:49:00 -0700374 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400375 of_ports.sort()
376 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
377
378 #Clear swicth state
Rich Lane9a003812012-10-04 17:17:59 -0700379 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400380 self.assertEqual(rc, 0, "Failed to delete all flows")
381
Rich Lane9a003812012-10-04 17:17:59 -0700382 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400385
386 # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400387 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400388
389 # Verify flow is inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400390 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400391
392 #Delete the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400393 nonstrict_delete(self,match,priority=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400394
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 Lane9a003812012-10-04 17:17:59 -0700414 rc2 = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400415 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 Laneb90a1c42012-10-05 09:16:05 -0700425class DeleteEmerFlow(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400426
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 Lane9a003812012-10-04 17:17:59 -0700432 logging.info("Running Delete_Emer_Flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400433
Rich Lane477f4812012-10-04 22:49:00 -0700434 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400435 of_ports.sort()
436
437 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700438 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400439 self.assertEqual(rc, 0, "Failed to delete all flows")
440
Rich Lane9a003812012-10-04 17:17:59 -0700441 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400443
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 Lane5c3151c2013-01-03 17:15:41 -0800456 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400457
458 # Delete the emergency flow
459
ShreyaPandita8dab4662012-11-02 13:40:14 -0400460 nonstrict_delete(self,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400461 (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 Laneb90a1c42012-10-05 09:16:05 -0700467class StrictVsNonstrict(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400468
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 Lane9a003812012-10-04 17:17:59 -0700474 logging.info("Strict_Vs_Nonstrict test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400475
Rich Lane477f4812012-10-04 22:49:00 -0700476 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400477 of_ports.sort()
478 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
479
480 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700481 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400482 self.assertEqual(rc, 0, "Failed to delete all flows")
483
Rich Lane9a003812012-10-04 17:17:59 -0700484 logging.info("Inserting a flow with exact match")
485 logging.info("Issue Strict Delete command , verify it gets deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400486
487 #Insert F with an exact Match
ShreyaPandita8dab4662012-11-02 13:40:14 -0400488 (pkt,match) = exact_match(self,of_ports)
489 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400490
491 #Issue Strict Delete Command , verify F gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400492 strict_delete(self,match)
493 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400494
Rich Lane9a003812012-10-04 17:17:59 -0700495 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400498
499 #Insert Flow T with match on all , except one wildcarded ( say src adddress ).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400500 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400501
502 #Insert another flow T' with match on ingress_port , wildcarded rest.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400503 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
504 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400505
506 #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400507 strict_delete(self,match1)
508 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400509
Rich Lane9a003812012-10-04 17:17:59 -0700510 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400513
514 #Insert T and T' again .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400515 (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)
ShreyaPandita9306c772012-09-28 12:21:40 -0400518
519 #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400520 nonstrict_delete(self,match1)
521 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400522
Rich Lane9a003812012-10-04 17:17:59 -0700523 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400526
527 #Insert T , add Priority P (say 100 )
ShreyaPandita8dab4662012-11-02 13:40:14 -0400528 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400529
530 #Insert T' add priority (200).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400531 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
ShreyaPandita9306c772012-09-28 12:21:40 -0400532
533 #Insert T' again add priority 300 --> T" .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400534 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
535 verify_tablestats(self,expect_active=3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400536
537 #Issue Non-Strict Delete and verify all getting deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400538 nonstrict_delete(self,match1,priority=200)
539 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400540
Rich Lane9a003812012-10-04 17:17:59 -0700541 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400544
545 #Issue Strict-Delete and verify only T'' gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400546 (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)
ShreyaPandita9306c772012-09-28 12:21:40 -0400551
552
553
Rich Laneb90a1c42012-10-05 09:16:05 -0700554class Outport1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400555
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 Lane9a003812012-10-04 17:17:59 -0700561 logging.info("Outport1 test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400562
Rich Lane477f4812012-10-04 22:49:00 -0700563 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400564 of_ports.sort()
565 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
566
567 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700568 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400569 self.assertEqual(rc, 0, "Failed to delete all flows")
570
Rich Lane9a003812012-10-04 17:17:59 -0700571 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400574
575 #Build and send Flow-1 with action output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400576 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400577
578 # Verify active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400579 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400580
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 Lane5c3151c2013-01-03 17:15:41 -0800588 self.controller.message_send(msg7)
ShreyaPandita9306c772012-09-28 12:21:40 -0400589 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
590
591 # Verify flow will not get deleted, active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400592 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400593
Rich Lane9a003812012-10-04 17:17:59 -0700594 logging.info("Deleting the flow with out_port set to of_port[1]")
595 logging.info("Expecting switch to delete the flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400596
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 Lane5c3151c2013-01-03 17:15:41 -0800604 self.controller.message_send(msg7)
ShreyaPandita9306c772012-09-28 12:21:40 -0400605 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
606
607 #Verify flow gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400608 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400609
610
Rich Laneb90a1c42012-10-05 09:16:05 -0700611class IdleTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400612
613 """ Verify that idle timeout is implemented"""
614
615 def runTest(self):
616
Rich Lane9a003812012-10-04 17:17:59 -0700617 logging.info("Running Idle_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400618
Rich Lane477f4812012-10-04 22:49:00 -0700619 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400620 of_ports.sort()
621 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
622
623 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700624 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400625 self.assertEqual(rc, 0, "Failed to delete all flows")
626
Rich Lane9a003812012-10-04 17:17:59 -0700627 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400629
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
ShreyaPandita8dab4662012-11-02 13:40:14 -0400642 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400643
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 Laneb90a1c42012-10-05 09:16:05 -0700655class Outport2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400656
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 Lane9a003812012-10-04 17:17:59 -0700661 logging.info("Running Outport2 test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400662
Rich Lane477f4812012-10-04 22:49:00 -0700663 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400664 of_ports.sort()
665 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
666
667 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700668 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400669 self.assertEqual(rc, 0, "Failed to delete all flows")
670
Rich Lane9a003812012-10-04 17:17:59 -0700671 logging.info("Adding and modifying flow with out_port fields set")
672 logging.info("Expecting switch to ignore out_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400673
674 # 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 -0400675 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400676
677 # Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400678 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400679
680 # Send Packet matching the flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400681 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400682
683 # 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 -0400684 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400685
686 # Again verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400687 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400688
689 #Verify action is modified
ShreyaPandita8dab4662012-11-02 13:40:14 -0400690 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400691
692
693
694
Rich Laneb90a1c42012-10-05 09:16:05 -0700695class HardTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400696
697 """ Verify that hard timeout is implemented """
698
699 def runTest(self):
700
Rich Lane9a003812012-10-04 17:17:59 -0700701 logging.info("Running Hard_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400702
Rich Lane477f4812012-10-04 22:49:00 -0700703 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400704 of_ports.sort()
705 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
706
707 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700708 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400709 self.assertEqual(rc, 0, "Failed to delete all flows")
710
Rich Lane9a003812012-10-04 17:17:59 -0700711 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400713
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
ShreyaPandita8dab4662012-11-02 13:40:14 -0400726 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400727
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 Laneb90a1c42012-10-05 09:16:05 -0700739class FlowTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400740
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 Lane9a003812012-10-04 17:17:59 -0700748 logging.info("Running Flow_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400749
Rich Lane477f4812012-10-04 22:49:00 -0700750 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400751 of_ports.sort()
752 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
753
754 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700755 rc = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400756 self.assertEqual(rc, 0, "Failed to delete all flows")
757
Rich Lane9a003812012-10-04 17:17:59 -0700758 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")
ShreyaPandita9306c772012-09-28 12:21:40 -0400760
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 Lanee30455b2013-01-03 16:24:44 -0800777 msg3.actions.add(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400778
Rich Lane5c3151c2013-01-03 17:15:41 -0800779 self.controller.message_send(msg3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400780 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
ShreyaPandita8dab4662012-11-02 13:40:14 -0400789 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812