blob: a32251d47c1ac19d9d3d225e656f7ee9a857983d [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
Rich Laned7b0ffa2013-03-08 15:53:42 -080014import ofp
ShreyaPandita9306c772012-09-28 12:21:40 -040015import oftest.dataplane as dataplane
ShreyaPandita9306c772012-09-28 12:21:40 -040016import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070017import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040018
Rich Laneda3b5ad2012-10-03 09:05:32 -070019from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040020from time import sleep
21from FuncUtils import *
22
Rich Laneb90a1c42012-10-05 09:16:05 -070023class OverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040024
25 """Verify that if overlap check flag is set in the flow entry and an overlapping flow is inserted then an error
26 is generated and switch refuses flow entry"""
27
28 def runTest(self):
29
Rich Lane9a003812012-10-04 17:17:59 -070030 logging.info("Running Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040031
Rich Lane477f4812012-10-04 22:49:00 -070032 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040033 of_ports.sort()
34 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
35
36 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080037 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040038
Rich Lane9a003812012-10-04 17:17:59 -070039 logging.info("Inserting two overlapping flows")
40 logging.info("Expecting switch to return an error")
ShreyaPandita9306c772012-09-28 12:21:40 -040041
42 #Insert a flow F with wildcarded all fields
ShreyaPandita8dab4662012-11-02 13:40:14 -040043 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -040044
45 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -040046 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040047
48 # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set
ShreyaPandita8dab4662012-11-02 13:40:14 -040049 pkt_matchingress = simple_tcp_packet()
50 match3 = parse.packet_to_flow_match(pkt_matchingress)
ShreyaPandita9306c772012-09-28 12:21:40 -040051 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
52 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
53 match3.in_port = of_ports[0]
54
Rich Laneba3f0e22013-03-11 16:43:57 -070055 msg3 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -040056 msg3.match = match3
57 msg3.flags |= ofp.OFPFF_CHECK_OVERLAP
58 msg3.cookie = random.randint(0,9007199254740992)
59 msg3.buffer_id = 0xffffffff
60
Rich Lane9d3cc6b2013-03-08 16:33:08 -080061 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -040062 act3.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -080063 msg3.actions.append(act3)
Rich Lane5c3151c2013-01-03 17:15:41 -080064 self.controller.message_send(msg3)
Rich Lane3a261d52013-01-03 17:45:08 -080065 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040066
67 # Verify Flow does not get inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -040068 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040069
70 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
71 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
72 timeout=5)
73 self.assertTrue(response is not None,
74 'Switch did not reply with error message')
Rich Lane4e361bb2013-03-11 13:57:31 -070075 self.assertTrue(response.err_type==ofp.OFPET_FLOW_MOD_FAILED,
ShreyaPandita9306c772012-09-28 12:21:40 -040076 'Error message type is not flow mod failed ')
77 self.assertTrue(response.code==ofp.OFPFMFC_OVERLAP,
78 'Error Message code is not overlap')
79
80
Rich Laneb90a1c42012-10-05 09:16:05 -070081class NoOverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040082
83 """Verify that without overlap check flag set, overlapping flows can be created."""
84
85 def runTest(self):
86
Rich Lane9a003812012-10-04 17:17:59 -070087 logging.info("Running No_Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040088
Rich Lane477f4812012-10-04 22:49:00 -070089 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040090 of_ports.sort()
91 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
92
93 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080094 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040095
Rich Lane9a003812012-10-04 17:17:59 -070096 logging.info("Inserting two overlapping flows")
97 logging.info("Expecting switch to insert the flows without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -040098
99 #Build a flow F with wildcarded all fields.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400100 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400101
102 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400103 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400104
105 # Build a overlapping flow F' without check overlap bit set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400106 wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400107
108 # Verify Flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400109 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400110
111
Rich Laneb90a1c42012-10-05 09:16:05 -0700112class IdenticalFlows(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400113
114 """Verify that adding two identical flows overwrites the existing one and clears counters"""
115
116 def runTest(self):
117
Rich Lane9a003812012-10-04 17:17:59 -0700118 logging.info("Running Identical_Flows test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400119
Rich Lane477f4812012-10-04 22:49:00 -0700120 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400121 of_ports.sort()
122 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
123
124 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800125 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400126
Rich Lane9a003812012-10-04 17:17:59 -0700127 logging.info("Inserting two identical flows one by one")
128 logging.info("Expecting switch to overwrite the first flow and clear the counters associated with it ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400129
130 # Create and add flow-1, check on dataplane it is active.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400131 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400132
133 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400134 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400135
136 # Send Packet (to increment counters like byte_count and packet_count)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400137 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400138
139 # Verify Flow counters have incremented
Rich Laneae3428c2013-03-07 14:37:42 -0800140 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400141
142 #Send Identical flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400143 (pkt1,match1) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400144
145 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400146 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400147
148 # Verify Flow counters reset
Rich Laneae3428c2013-03-07 14:37:42 -0800149 verify_flow_stats(self, match, pkts=0, bytes=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400150
151
Rich Laneb90a1c42012-10-05 09:16:05 -0700152class EmerFlowTimeout(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400153
154 """Timeout values are not allowed for emergency flows"""
155
156 def runTest(self):
157
Rich Lane9a003812012-10-04 17:17:59 -0700158 logging.info("Running Emergency_Flow_Timeout test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400159
Rich Lane477f4812012-10-04 22:49:00 -0700160 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400161 of_ports.sort()
162 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
163
164 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800165 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400166
Rich Lane9a003812012-10-04 17:17:59 -0700167 logging.info("Inserting an emergency flow with timeout values")
168 logging.info("Expecting switch to generate error ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400169
170 #Insert an emergency flow
171 pkt = simple_tcp_packet()
172 match = parse.packet_to_flow_match(pkt)
173 match.in_port = of_ports[0]
174
Rich Laneba3f0e22013-03-11 16:43:57 -0700175 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400176 request.match = match
ShreyaPandita9306c772012-09-28 12:21:40 -0400177 request.flags = request.flags|ofp.OFPFF_EMERG
178 request.hard_timeout =9
179 request.idle_timeout =9
180
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800181 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400182 act.port = of_ports[1]
183
Rich Lanec495d9e2013-03-08 17:43:36 -0800184 request.actions.append(act)
Rich Lane9a003812012-10-04 17:17:59 -0700185 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800186 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400187
Rich Lane3a261d52013-01-03 17:45:08 -0800188 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400189
190 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
191 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
192 timeout=5)
193 self.assertTrue(response is not None,
194 'Switch did not reply with error message')
Rich Lane4e361bb2013-03-11 13:57:31 -0700195 self.assertTrue(response.err_type==ofp.OFPET_FLOW_MOD_FAILED,
ShreyaPandita9306c772012-09-28 12:21:40 -0400196 'Error message type is not flow mod failed ')
197 self.assertTrue(response.code==ofp.OFPFMFC_BAD_EMERG_TIMEOUT,
198 'Error Message code is not bad emergency timeout')
199
200
Rich Laneb90a1c42012-10-05 09:16:05 -0700201class MissingModifyAdd(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400202
203 """If a modify does not match an existing flow, the flow gets added """
204
205 def runTest(self):
206
Rich Lane9a003812012-10-04 17:17:59 -0700207 logging.info("Running Missing_Modify_Add test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400208
Rich Lane477f4812012-10-04 22:49:00 -0700209 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400210 of_ports.sort()
211 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
212
Rich Lane9a003812012-10-04 17:17:59 -0700213 logging.info("Inserting a flow-modify that does not match an existing flow")
214 logging.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400215
216 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800217 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400218
219 #Generate a flow-mod,command OFPC_MODIFY
220
Rich Laneba3f0e22013-03-11 16:43:57 -0700221 request = ofp.message.flow_modify()
ShreyaPandita9306c772012-09-28 12:21:40 -0400222 request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
223 request.match.in_port = of_ports[0]
224 request.cookie = random.randint(0,9007199254740992)
225 request.buffer_id = 0xffffffff
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800226 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400227 act3.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -0800228 request.actions.append(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400229
Rich Lane9a003812012-10-04 17:17:59 -0700230 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800231 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800232 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400233
234 #Verify the flow gets added i.e. active_count= 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400235 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400236
237
Rich Laneb90a1c42012-10-05 09:16:05 -0700238class ModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400239
240 """A modified flow preserves counters"""
241
242 def runTest(self):
243
Rich Lane9a003812012-10-04 17:17:59 -0700244 logging.info("Running Modify_Action test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400245
Rich Lane477f4812012-10-04 22:49:00 -0700246 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400247 of_ports.sort()
248 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
249
250 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800251 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400252
Rich Lane9a003812012-10-04 17:17:59 -0700253 logging.info("Inserting a Flow and incrementing flow counters. Modifying the flow action")
254 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400255
256 #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 -0400257 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400258
259 #Send Packet matching the flow thus incrementing counters like packet_count,byte_count
ShreyaPandita8dab4662012-11-02 13:40:14 -0400260 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400261
262 #Verify flow counters
Rich Laneae3428c2013-03-07 14:37:42 -0800263 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400264
265 #Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400266 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400267
268 # 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 -0400269 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400270
271 #Verify flow counters are preserved
Rich Laneae3428c2013-03-07 14:37:42 -0800272 verify_flow_stats(self, match, pkts=2, bytes=len(str(pkt))*2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400273
274
Rich Laneb90a1c42012-10-05 09:16:05 -0700275class StrictModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400276
277 """Strict Modify Flow also changes action preserves counters"""
278
279 def runTest(self):
280
Rich Lane9a003812012-10-04 17:17:59 -0700281 logging.info("Running Strict_Modify_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400282
Rich Lane477f4812012-10-04 22:49:00 -0700283 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400284 of_ports.sort()
285 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
286
287 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800288 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400289
Rich Lane9a003812012-10-04 17:17:59 -0700290 logging.info("Inserting Flows and incrementing flow counters. Strict Modify the flow action ")
291 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400292
293 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400294 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400295
296 #Create and add flow-2 , Match on ingress_port only, Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400297 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=10)
ShreyaPandita9306c772012-09-28 12:21:40 -0400298
299 # Verify both the flows are active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400300 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400301
302 #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 -0400303 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400304
305 # Verify flow counters of the flow-1
Rich Laneae3428c2013-03-07 14:37:42 -0800306 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400307
308 # Strict-Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400309 strict_modify_flow_action(self,of_ports[2],match,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400310
311 # 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 -0400312 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400313
314 # Verify flow counters are preserved
Rich Laneae3428c2013-03-07 14:37:42 -0800315 verify_flow_stats(self, match, pkts=2, bytes=2*len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400316
317
Rich Laneb90a1c42012-10-05 09:16:05 -0700318class DeleteNonexistingFlow(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400319
320 """Request deletion of non-existing flow"""
321
322 def runTest(self):
323
Rich Lane9a003812012-10-04 17:17:59 -0700324 logging.info("Delete_NonExisting_Flow test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400325
Rich Lane477f4812012-10-04 22:49:00 -0700326 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400327 of_ports.sort()
328 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
329
330 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800331 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400332
Rich Lane9a003812012-10-04 17:17:59 -0700333 logging.info("Deleting a non-existing flow")
334 logging.info("Expecting switch to ignore the command , without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400335
336 # Issue a delete command
Rich Laneba3f0e22013-03-11 16:43:57 -0700337 msg = ofp.message.flow_delete()
ShreyaPandita9306c772012-09-28 12:21:40 -0400338 msg.match.wildcards = ofp.OFPFW_ALL
339 msg.out_port = ofp.OFPP_NONE
ShreyaPandita9306c772012-09-28 12:21:40 -0400340 msg.buffer_id = 0xffffffff
341
342 # Verify no message or error is generated by polling the the control plane
343 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
344 timeout=2)
345 self.assertTrue(response is None,
346 'Recieved Error for deleting non-exiting flow ')
347
348
349
Rich Laneb90a1c42012-10-05 09:16:05 -0700350class SendFlowRem(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400351
352 """Check deletion of flows happens and generates messages as configured.
353 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,
354 vice versa also exists """
355
356 def runTest(self):
357
Rich Lane9a003812012-10-04 17:17:59 -0700358 logging.info("Running Send_Flow_Rem test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400359
Rich Lane477f4812012-10-04 22:49:00 -0700360 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400361 of_ports.sort()
362 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
363
364 #Clear swicth state
Rich Lane32bf9482013-01-03 17:26:30 -0800365 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400366
Rich Lane9a003812012-10-04 17:17:59 -0700367 logging.info("Inserting flows F1 and F2 without and with send_flow_removed_message flag set ")
368 logging.info("Deleting the flows")
369 logging.info("Expecting flow removed message only for F2")
ShreyaPandita9306c772012-09-28 12:21:40 -0400370
371 # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400372 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400373
374 # Verify flow is inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400375 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400376
377 #Delete the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400378 nonstrict_delete(self,match,priority=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400379
380 # Verify no flow removed message is generated for the FLOW-1
381
382 (response1, pkt1) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
383 timeout=2)
384 self.assertTrue(response1 is None,
385 'Received flow removed message for the flow with flow_rem flag not set')
386
387 # Insert another flow F' with OFPFF_SEND_FLOW_REM flag set.
Rich Laneba3f0e22013-03-11 16:43:57 -0700388 msg9 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400389 msg9.match.wildcards = ofp.OFPFW_ALL
390 msg9.cookie = random.randint(0,9007199254740992)
391 msg9.buffer_id = 0xffffffff
392 msg9.idle_timeout = 1
393 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
394 rv1 = self.controller.message_send(msg9)
395 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800396 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400397
398 # Delete the flow-2
Rich Lane32bf9482013-01-03 17:26:30 -0800399 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400400
401 # Verify flow removed message is generated for the FLOW-2
402
403 (response2, pkt2) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
404 timeout=2)
405 self.assertTrue(response2 is not None,
406 'Did not receive flow removed message for this flow')
407
408
Rich Laneb90a1c42012-10-05 09:16:05 -0700409class DeleteEmerFlow(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400410
411 """Delete emergency flow and verify no message is generated.An emergency flow deletion will not generate flow-removed messages even if
412 Send Flow removed message flag was set during the emergency flow entry"""
413
414 def runTest(self):
415
Rich Lane9a003812012-10-04 17:17:59 -0700416 logging.info("Running Delete_Emer_Flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400417
Rich Lane477f4812012-10-04 22:49:00 -0700418 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400419 of_ports.sort()
420
421 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800422 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400423
Rich Lane9a003812012-10-04 17:17:59 -0700424 logging.info("Inserting a emergency flow with send_flow_removed flag set")
425 logging.info("Expecting no flow_removed_message on the deletion of the emergency flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400426
427 # Insert a flow with emergency bit set.
428 pkt = simple_tcp_packet()
429 match = parse.packet_to_flow_match(pkt)
430 match.in_port = of_ports[0]
Rich Laneba3f0e22013-03-11 16:43:57 -0700431 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400432 request.match = match
ShreyaPandita9306c772012-09-28 12:21:40 -0400433 request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800434 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400435 act.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -0800436 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400437
Rich Lane5c3151c2013-01-03 17:15:41 -0800438 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400439
440 # Delete the emergency flow
441
ShreyaPandita8dab4662012-11-02 13:40:14 -0400442 nonstrict_delete(self,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400443 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM ,
444 timeout=2)
445 self.assertTrue(response is None,
446 'Test Failed ')
447
448
Rich Laneb90a1c42012-10-05 09:16:05 -0700449class StrictVsNonstrict(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400450
451 """Delete and verify strict and non-strict behaviors
452 This test compares the behavior of delete strict and non-strict"""
453
454 def runTest(self):
455
Rich Lane9a003812012-10-04 17:17:59 -0700456 logging.info("Strict_Vs_Nonstrict test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400457
Rich Lane477f4812012-10-04 22:49:00 -0700458 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400459 of_ports.sort()
460 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
461
462 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800463 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400464
Rich Lane9a003812012-10-04 17:17:59 -0700465 logging.info("Inserting a flow with exact match")
466 logging.info("Issue Strict Delete command , verify it gets deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400467
468 #Insert F with an exact Match
ShreyaPandita8dab4662012-11-02 13:40:14 -0400469 (pkt,match) = exact_match(self,of_ports)
470 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400471
472 #Issue Strict Delete Command , verify F gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400473 strict_delete(self,match)
474 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400475
Rich Lane9a003812012-10-04 17:17:59 -0700476 logging.info("Inserting two overlapping flows")
477 logging.info("Issue Strict Delete command ")
478 logging.info("Expecting only one flow gets deleted , because Strict Delete matches on wildcards as well")
ShreyaPandita9306c772012-09-28 12:21:40 -0400479
480 #Insert Flow T with match on all , except one wildcarded ( say src adddress ).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400481 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400482
483 #Insert another flow T' with match on ingress_port , wildcarded rest.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400484 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
485 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400486
487 #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400488 strict_delete(self,match1)
489 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400490
Rich Lane9a003812012-10-04 17:17:59 -0700491 logging.info("Inserting two overlapping flows")
492 logging.info("Issue Non-Strict Delete command ")
493 logging.info("Expecting both the flow gets deleted , because wildcards are active")
ShreyaPandita9306c772012-09-28 12:21:40 -0400494
495 #Insert T and T' again .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400496 (pkt,match) = match_all_except_source_address(self,of_ports)
497 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
498 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400499
500 #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400501 nonstrict_delete(self,match1)
502 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400503
Rich Lane9a003812012-10-04 17:17:59 -0700504 logging.info("Inserting three overlapping flows with different priorities")
505 logging.info("Issue Non-Strict Delete command ")
506 logging.info("Expecting all the flows to get deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400507
508 #Insert T , add Priority P (say 100 )
ShreyaPandita8dab4662012-11-02 13:40:14 -0400509 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400510
511 #Insert T' add priority (200).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400512 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
ShreyaPandita9306c772012-09-28 12:21:40 -0400513
514 #Insert T' again add priority 300 --> T" .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400515 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
516 verify_tablestats(self,expect_active=3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400517
518 #Issue Non-Strict Delete and verify all getting deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400519 nonstrict_delete(self,match1,priority=200)
520 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400521
Rich Lane9a003812012-10-04 17:17:59 -0700522 logging.info("Inserting three overlapping flows with different priorities")
523 logging.info("Issue Strict Delete command ")
524 logging.info("Expecting only one to get deleted because here priorities & wildcards are being matched")
ShreyaPandita9306c772012-09-28 12:21:40 -0400525
526 #Issue Strict-Delete and verify only T'' gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400527 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
528 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
529 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
530 strict_delete(self,match1,priority=200)
531 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400532
533
534
Rich Laneb90a1c42012-10-05 09:16:05 -0700535class Outport1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400536
537 """Delete flows filtered by action outport.If the out_port field in the delete command contains a value other than OFPP_NONE,
538 it introduces a constraint when matching. This constraint is that the rule must contain an output action directed at that port."""
539
540 def runTest(self):
541
Rich Lane9a003812012-10-04 17:17:59 -0700542 logging.info("Outport1 test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400543
Rich Lane477f4812012-10-04 22:49:00 -0700544 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400545 of_ports.sort()
546 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
547
548 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800549 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400550
Rich Lane9a003812012-10-04 17:17:59 -0700551 logging.info("Inserting a flow with output action --> of_port[1]")
552 logging.info("Deleting the flow but with out_port set to of_port[2]")
553 logging.info("Expecting switch to filter the delete command")
ShreyaPandita9306c772012-09-28 12:21:40 -0400554
555 #Build and send Flow-1 with action output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400556 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400557
558 # Verify active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400559 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400560
561 #Send delete command matching the flow-1 but with contraint out_port = of_port[2]
Rich Laneba3f0e22013-03-11 16:43:57 -0700562 msg7 = ofp.message.flow_delete()
ShreyaPandita9306c772012-09-28 12:21:40 -0400563 msg7.out_port = of_ports[2]
ShreyaPandita9306c772012-09-28 12:21:40 -0400564 msg7.buffer_id = 0xffffffff
565 msg7.match = match
566
Rich Lane5c3151c2013-01-03 17:15:41 -0800567 self.controller.message_send(msg7)
Rich Lane3a261d52013-01-03 17:45:08 -0800568 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400569
570 # Verify flow will not get deleted, active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400571 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400572
Rich Lane9a003812012-10-04 17:17:59 -0700573 logging.info("Deleting the flow with out_port set to of_port[1]")
574 logging.info("Expecting switch to delete the flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400575
576 #Send Delete command with contraint out_port = of_ports[1]
Rich Laneba3f0e22013-03-11 16:43:57 -0700577 msg7 = ofp.message.flow_delete()
ShreyaPandita9306c772012-09-28 12:21:40 -0400578 msg7.out_port = of_ports[1]
ShreyaPandita9306c772012-09-28 12:21:40 -0400579 msg7.buffer_id = 0xffffffff
580 msg7.match = match
581
Rich Lane5c3151c2013-01-03 17:15:41 -0800582 self.controller.message_send(msg7)
Rich Lane3a261d52013-01-03 17:45:08 -0800583 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400584
585 #Verify flow gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400586 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400587
588
Rich Laneb90a1c42012-10-05 09:16:05 -0700589class IdleTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400590
591 """ Verify that idle timeout is implemented"""
592
593 def runTest(self):
594
Rich Lane9a003812012-10-04 17:17:59 -0700595 logging.info("Running Idle_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400596
Rich Lane477f4812012-10-04 22:49:00 -0700597 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400598 of_ports.sort()
599 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
600
601 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800602 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400603
Rich Lane9a003812012-10-04 17:17:59 -0700604 logging.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set")
605 logging.info("Expecting the flow entry to delete with given idle_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400606
607 #Insert a flow entry with idle_timeout=1.Send_Flow_Rem flag set
Rich Laneba3f0e22013-03-11 16:43:57 -0700608 msg9 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400609 msg9.match.wildcards = ofp.OFPFW_ALL
610 msg9.cookie = random.randint(0,9007199254740992)
611 msg9.buffer_id = 0xffffffff
612 msg9.idle_timeout = 1
613 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
614 rv1 = self.controller.message_send(msg9)
615 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800616 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400617
618 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400619 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400620
621 # Verify flow removed message is recieved.
622 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
623 timeout=5)
624 self.assertTrue(response is not None,
625 'Did not receive flow removed message ')
626 self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
627 'Flow table entry removal reason is not idle_timeout')
628 self.assertEqual(1, response.duration_sec,
629 'Flow was not alive for 1 sec')
630
631
Rich Laneb90a1c42012-10-05 09:16:05 -0700632class Outport2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400633
634 """Add, modify flows with outport set. This field is ignored by ADD, MODIFY, and MODIFY STRICT messages."""
635
636 def runTest(self):
637
Rich Lane9a003812012-10-04 17:17:59 -0700638 logging.info("Running Outport2 test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400639
Rich Lane477f4812012-10-04 22:49:00 -0700640 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400641 of_ports.sort()
642 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
643
644 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800645 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400646
Rich Lane9a003812012-10-04 17:17:59 -0700647 logging.info("Adding and modifying flow with out_port fields set")
648 logging.info("Expecting switch to ignore out_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400649
650 # 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 -0400651 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400652
653 # Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400654 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400655
656 # Send Packet matching the flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400657 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400658
659 # 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 -0400660 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400661
662 # Again verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400663 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400664
665 #Verify action is modified
ShreyaPandita8dab4662012-11-02 13:40:14 -0400666 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400667
668
669
670
Rich Laneb90a1c42012-10-05 09:16:05 -0700671class HardTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400672
673 """ Verify that hard timeout is implemented """
674
675 def runTest(self):
676
Rich Lane9a003812012-10-04 17:17:59 -0700677 logging.info("Running Hard_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400678
Rich Lane477f4812012-10-04 22:49:00 -0700679 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400680 of_ports.sort()
681 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
682
683 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800684 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400685
Rich Lane9a003812012-10-04 17:17:59 -0700686 logging.info("Inserting flow entry with hard_timeout set. Also send_flow_removed_message flag set")
687 logging.info("Expecting the flow entry to delete with given hard_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400688
689 # Insert a flow entry with hardtimeout=1 and send_flow_removed flag set
Rich Laneba3f0e22013-03-11 16:43:57 -0700690 msg9 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400691 msg9.match.wildcards = ofp.OFPFW_ALL
692 msg9.cookie = random.randint(0,9007199254740992)
693 msg9.buffer_id = 0xffffffff
694 msg9.hard_timeout = 1
695 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
696 rv1 = self.controller.message_send(msg9)
697 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800698 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400699
700 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400701 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400702
703 # Verify flow removed message is recieved.
704 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
705 timeout=5)
706 self.assertTrue(response is not None,
707 'Did not receive flow removed message ')
708 self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
709 'Flow table entry removal reason is not hard_timeout')
710 self.assertEqual(1, response.duration_sec,
711 'Flow was not alive for 1 sec')
712
713
Rich Laneb90a1c42012-10-05 09:16:05 -0700714class FlowTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400715
716 """Verify that Flow removed messages are generated as expected
717 Flow removed messages being generated when flag is set, is already tested in the above tests
718 So here, we test the vice-versa condition"""
719
720
721 def runTest(self):
722
Rich Lane9a003812012-10-04 17:17:59 -0700723 logging.info("Running Flow_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400724
Rich Lane477f4812012-10-04 22:49:00 -0700725 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400726 of_ports.sort()
727 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
728
729 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800730 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400731
Rich Lane9a003812012-10-04 17:17:59 -0700732 logging.info("Inserting flow entry with hard_timeout set and send_flow_removed_message flag not set")
733 logging.info("Expecting the flow entry to delete, but no flow removed message")
ShreyaPandita9306c772012-09-28 12:21:40 -0400734
735 # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set
736 pkt = simple_tcp_packet()
737 match3 = parse.packet_to_flow_match(pkt)
738 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
739 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
740 match3.in_port = of_ports[0]
Rich Laneba3f0e22013-03-11 16:43:57 -0700741 msg3 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400742 msg3.out_port = of_ports[2] # ignored by flow add,flow modify
ShreyaPandita9306c772012-09-28 12:21:40 -0400743 msg3.cookie = random.randint(0,9007199254740992)
744 msg3.buffer_id = 0xffffffff
745 msg3.hard_timeout = 1
746 msg3.buffer_id = 0xffffffff
747 msg3.match = match3
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800748 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400749 act3.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -0800750 msg3.actions.append(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400751
Rich Lane5c3151c2013-01-03 17:15:41 -0800752 self.controller.message_send(msg3)
Rich Lane3a261d52013-01-03 17:45:08 -0800753 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400754
755 #Verify no flow removed message is generated
756 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
757 timeout=3)
758 self.assertTrue(response is None,
759 'Recieved flow removed message ')
760
761 # Verify no entries in the table
ShreyaPandita8dab4662012-11-02 13:40:14 -0400762 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785